Skip to content

Commit

Permalink
Always include super properties of mappings (#1148)
Browse files Browse the repository at this point in the history
  • Loading branch information
radcortez authored Apr 19, 2024
1 parent bd40d1a commit 2327fb8
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -460,10 +460,6 @@ private static void addProperties(
ctor.visitFieldInsn(PUTFIELD, className, memberName, fieldDesc);
}
}

for (ConfigMappingInterface superType : mapping.getSuperTypes()) {
addProperties(cv, ctor, visited, superType, className);
}
}

private static void generateProperty(final MethodVisitor ctor, final Property property) {
Expand Down Expand Up @@ -718,7 +714,7 @@ private static void addToString(final ClassVisitor visitor, final ConfigMappingI
ts.visitLdcInsn(mapping.getInterfaceType().getSimpleName() + "{");
ts.visitMethodInsn(INVOKEVIRTUAL, I_STRING_BUILDER, "append", "(L" + I_STRING + ";)L" + I_STRING_BUILDER + ";", false);

Property[] properties = mapping.getProperties(true);
Property[] properties = mapping.getProperties();
for (int i = 0, propertiesLength = properties.length; i < propertiesLength; i++) {
Property property = properties[i];
if (property.isDefaultMethod()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
import java.lang.reflect.Type;
import java.lang.reflect.WildcardType;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -92,28 +94,16 @@ public ConfigMappingInterface[] getSuperTypes() {
}

public Property[] getProperties() {
return properties;
}

public Property[] getProperties(boolean includeSuper) {
if (includeSuper) {
Map<String, Property> properties = getSuperProperties(this);
for (Property property : this.properties) {
properties.put(property.getMemberName(), property);
}
return properties.values().toArray(new Property[0]);
} else {
return getProperties();
}
Set<Property> properties = getSuperProperties(this);
properties.addAll(Arrays.asList(this.properties));
return properties.toArray(new Property[0]);
}

private static Map<String, Property> getSuperProperties(ConfigMappingInterface type) {
Map<String, Property> properties = new HashMap<>();
private static Set<Property> getSuperProperties(ConfigMappingInterface type) {
Set<Property> properties = new HashSet<>();
for (ConfigMappingInterface superType : type.getSuperTypes()) {
properties.putAll(getSuperProperties(superType));
for (Property property : superType.getProperties()) {
properties.put(property.getMemberName(), property);
}
properties.addAll(getSuperProperties(superType));
properties.addAll(Arrays.asList(superType.getProperties()));
}
return properties;
}
Expand Down Expand Up @@ -170,6 +160,7 @@ public String getPropertyName() {
}

public String getPropertyName(final NamingStrategy namingStrategy) {
// TODO - Transform in a single class that checks isPropertyName?
return hasPropertyName() ? getPropertyName() : namingStrategy.apply(getPropertyName());
}

Expand Down Expand Up @@ -963,7 +954,7 @@ private static void getNested(final Property[] properties, final Set<ConfigMappi
ConfigMappingInterface group = groupProperty.getGroupType();
nested.add(group);
Collections.addAll(nested, group.superTypes);
getNested(group.getProperties(true), nested);
getNested(group.getProperties(), nested);
}

if (property instanceof OptionalProperty) {
Expand All @@ -973,7 +964,7 @@ private static void getNested(final Property[] properties, final Set<ConfigMappi
ConfigMappingInterface group = groupProperty.getGroupType();
nested.add(group);
Collections.addAll(nested, group.superTypes);
getNested(group.getProperties(true), nested);
getNested(group.getProperties(), nested);
} else if (optionalProperty.getNestedProperty() instanceof CollectionProperty) {
CollectionProperty collectionProperty = (CollectionProperty) optionalProperty.getNestedProperty();
getNested(new Property[] { collectionProperty.element }, nested);
Expand All @@ -1000,14 +991,6 @@ static AnnotatedType typeOfParameter(final AnnotatedType type, final int index)
}
}

static Type typeOfParameter(final Type type, final int index) {
if (type instanceof ParameterizedType) {
return ((ParameterizedType) type).getActualTypeArguments()[index];
} else {
return type;
}
}

static Class<?> rawTypeOf(final Type type) {
if (type instanceof Class<?>) {
return (Class<?>) type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ private static void getProperties(
final Map<Class<?>, Map<String, Map<String, Property>>> properties,
final Map<String, Property> groupProperties) {

for (Property property : groupProperty.getGroupType().getProperties(true)) {
for (Property property : groupProperty.getGroupType().getProperties()) {
getProperty(property, namingStrategy, path, properties, groupProperties);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,6 @@ default void validateMappingInterface(
final Object mappingObject,
final List<Problem> problems) {

for (ConfigMappingInterface superType : mappingInterface.getSuperTypes()) {
for (Property property : superType.getProperties()) {
validateProperty(property, currentPath, namingStrategy, mappingObject, false, problems);
}
}

for (Property property : mappingInterface.getProperties()) {
validateProperty(property, currentPath, namingStrategy, mappingObject, false, problems);
}
Expand Down

0 comments on commit 2327fb8

Please sign in to comment.