Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 19 additions & 25 deletions processor/src/main/java/org/mapstruct/ap/MappingProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.ServiceLoader;
import java.util.Set;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -254,33 +255,26 @@ private Set<TypeElement> getAndResetDeferredMappers() {

private Set<TypeElement> getMappers(final Set<? extends TypeElement> annotations,
final RoundEnvironment roundEnvironment) {
Set<TypeElement> mapperTypes = new HashSet<>();

for ( TypeElement annotation : annotations ) {
//Indicates that the annotation's type isn't on the class path of the compiled
//project. Let the compiler deal with that and print an appropriate error.
if ( annotation.getKind() != ElementKind.ANNOTATION_TYPE ) {
continue;
}
return annotations.stream()
.filter( a -> a.getKind().equals( ElementKind.ANNOTATION_TYPE ) )
.map( a -> mapperTypeElements( roundEnvironment, a ) )
.flatMap( Set::stream )
.collect( Collectors.toSet() );
}

try {
Set<? extends Element> annotatedMappers = roundEnvironment.getElementsAnnotatedWith( annotation );
for ( Element mapperElement : annotatedMappers ) {
TypeElement mapperTypeElement = asTypeElement( mapperElement );

// on some JDKs, RoundEnvironment.getElementsAnnotatedWith( ... ) returns types with
// annotations unknown to the compiler, even though they are not declared Mappers
if ( mapperTypeElement != null && MapperGem.instanceOn( mapperTypeElement ) != null ) {
mapperTypes.add( mapperTypeElement );
}
}
}
catch ( Throwable t ) { // whenever that may happen, but just to stay on the save side
handleUncaughtError( annotation, t );
continue;
}
private Set<TypeElement> mapperTypeElements(final RoundEnvironment roundEnvironment, final TypeElement annotation) {
try {
return roundEnvironment.getElementsAnnotatedWith( annotation )
.stream()
.map( this::asTypeElement )
.filter( Objects::nonNull )
.filter( mapper -> Objects.nonNull( MapperGem.instanceOn( mapper ) ) )
.collect( Collectors.toSet() );
}
catch ( Throwable t ) { // whenever that may happen, but just to stay on the save side
handleUncaughtError( annotation, t );
return new HashSet<>();
}
return mapperTypes;
}

private void processMapperElements(Set<TypeElement> mapperElements, RoundContext roundContext) {
Expand Down