diff --git a/processor/src/main/java/org/mapstruct/ap/MapperGenerationVisitor.java b/processor/src/main/java/org/mapstruct/ap/MapperGenerationVisitor.java index 2f38a5e6d..c050d948c 100644 --- a/processor/src/main/java/org/mapstruct/ap/MapperGenerationVisitor.java +++ b/processor/src/main/java/org/mapstruct/ap/MapperGenerationVisitor.java @@ -62,6 +62,31 @@ import org.mapstruct.ap.writer.ModelWriter; import static javax.lang.model.util.ElementFilter.methodsIn; +/** + * An {@link ElementVisitor} which generates the implementations for mapper + * interfaces (interfaces annotated with {@code @Mapper}. + *

+ * Implementation notes: + *

+ * The mapper generation happens by building up a model representation of + * the mapper to be generated (a {@link Mapper} object), which is then written + * into a file using the FreeMarker template engine. + *

+ * The model instantiation happens in two phases/passes: The first one retrieves + * the mapping methods of the given interfaces and their configuration (the + * source model). In the second pass the individual methods are + * aggregated into the target model, which contains a {@link BeanMapping} + * each pair of source and target type which has references to forward and + * reverse mapping methods as well as the methods for mapping the element types + * (if it is a collection mapping) and {@link Conversion}s if applicable. + *

+ * For reading annotation attributes, prisms as generated with help of the Hickory tool are used. These + * prisms allow a comfortable access to annotations and their attributes without + * depending on their class objects. + * + * @author Gunnar Morling + */ public class MapperGenerationVisitor extends ElementKindVisitor6 { private static final String IMPLEMENTATION_SUFFIX = "Impl"; @@ -494,8 +519,8 @@ public class MapperGenerationVisitor extends ElementKindVisitor6 { List sourceGetters, List targetSetters) { - Set sourcePropertyNames = getPropertyNames( sourceGetters ); - Set targetPropertyNames = getPropertyNames( targetSetters ); + Set sourcePropertyNames = Executables.getPropertyNames( sourceGetters ); + Set targetPropertyNames = Executables.getPropertyNames( targetSetters ); for ( Mapping mappedProperty : mappings.values() ) { if ( !sourcePropertyNames.contains( mappedProperty.getSourceName() ) ) { @@ -519,16 +544,6 @@ public class MapperGenerationVisitor extends ElementKindVisitor6 { } } - private Set getPropertyNames(List propertyAccessors) { - Set propertyNames = new HashSet(); - - for ( ExecutableElement executableElement : propertyAccessors ) { - propertyNames.add( Executables.getPropertyName( executableElement ) ); - } - - return propertyNames; - } - private Map getMappings(MappingsPrism mappingsAnnotation) { Map mappings = new HashMap(); diff --git a/processor/src/main/java/org/mapstruct/ap/util/Executables.java b/processor/src/main/java/org/mapstruct/ap/util/Executables.java index 8f1d288dc..2c92f8f00 100644 --- a/processor/src/main/java/org/mapstruct/ap/util/Executables.java +++ b/processor/src/main/java/org/mapstruct/ap/util/Executables.java @@ -19,7 +19,10 @@ package org.mapstruct.ap.util; import java.beans.Introspector; +import java.util.HashSet; import java.util.List; +import java.util.Set; +import javax.lang.model.element.Element; import javax.lang.model.element.ExecutableElement; import javax.lang.model.type.TypeKind; @@ -109,4 +112,14 @@ public class Executables { return null; } + + public static Set getPropertyNames(List propertyAccessors) { + Set propertyNames = new HashSet(); + + for ( ExecutableElement executableElement : propertyAccessors ) { + propertyNames.add( Executables.getPropertyName( executableElement ) ); + } + + return propertyNames; + } }