diff --git a/processor/src/main/java/org/mapstruct/ap/AnnotationProcessingException.java b/processor/src/main/java/org/mapstruct/ap/AnnotationProcessingException.java index ec250f2c4..04cd4f657 100644 --- a/processor/src/main/java/org/mapstruct/ap/AnnotationProcessingException.java +++ b/processor/src/main/java/org/mapstruct/ap/AnnotationProcessingException.java @@ -18,12 +18,15 @@ */ package org.mapstruct.ap; +import javax.annotation.processing.Messager; import javax.lang.model.element.AnnotationMirror; import javax.lang.model.element.AnnotationValue; import javax.lang.model.element.Element; /** - * Indicates an error during annotation processing. + * Indicates an error during annotation processing. Should only be thrown in non-recoverable situations such as errors + * due to incomplete compilations etc. Expected errors to be propagated to the user of the annotation processor should + * be raised using the {@link Messager} API instead. * * @author Gunnar Morling */ @@ -34,6 +37,10 @@ public class AnnotationProcessingException extends RuntimeException { private final AnnotationMirror annotationMirror; private final AnnotationValue annotationValue; + public AnnotationProcessingException(String message) { + this( message, null, null, null ); + } + public AnnotationProcessingException(String message, Element element) { this( message, element, null, null ); } diff --git a/processor/src/main/java/org/mapstruct/ap/processor/MethodRetrievalProcessor.java b/processor/src/main/java/org/mapstruct/ap/processor/MethodRetrievalProcessor.java index b5c486cb6..18ec5c3df 100644 --- a/processor/src/main/java/org/mapstruct/ap/processor/MethodRetrievalProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/processor/MethodRetrievalProcessor.java @@ -18,10 +18,13 @@ */ package org.mapstruct.ap.processor; +import static javax.lang.model.util.ElementFilter.methodsIn; + import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; + import javax.annotation.processing.Messager; import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.Modifier; @@ -31,6 +34,7 @@ import javax.lang.model.type.TypeKind; import javax.lang.model.type.TypeMirror; import javax.tools.Diagnostic.Kind; +import org.mapstruct.ap.AnnotationProcessingException; import org.mapstruct.ap.IterableMappingPrism; import org.mapstruct.ap.MapMappingPrism; import org.mapstruct.ap.MapperPrism; @@ -45,8 +49,6 @@ import org.mapstruct.ap.model.source.Method; import org.mapstruct.ap.util.Executables; import org.mapstruct.ap.util.TypeFactory; -import static javax.lang.model.util.ElementFilter.methodsIn; - /** * A {@link ModelElementProcessor} which retrieves a list of {@link Method}s * representing all the mapping methods of the given bean mapper type as well as @@ -88,8 +90,6 @@ public class MethodRetrievalProcessor implements ModelElementProcessor retrieveMethods(TypeElement element, boolean mapperRequiresImplementation) { List methods = new ArrayList(); - MapperPrism mapperPrism = mapperRequiresImplementation ? MapperPrism.getInstanceOn( element ) : null; - for ( ExecutableElement executable : methodsIn( element.getEnclosedElements() ) ) { Method method = getMethod( element, executable, mapperRequiresImplementation ); if ( method != null ) { @@ -99,6 +99,13 @@ public class MethodRetrievalProcessor implements ModelElementProcessor