mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
#510 Adding experimental SPI for letting AST-modifying annotation processors such as Lombok tell us about future modifications
This commit is contained in:
parent
754877cece
commit
5e59f3484c
@ -70,7 +70,7 @@ public class TypeFactory {
|
||||
|
||||
private final Elements elementUtils;
|
||||
private final Types typeUtils;
|
||||
private RoundContext roundContext;
|
||||
private final RoundContext roundContext;
|
||||
|
||||
private final TypeMirror iterableType;
|
||||
private final TypeMirror collectionType;
|
||||
@ -147,11 +147,12 @@ public class TypeFactory {
|
||||
}
|
||||
|
||||
public Type getType(TypeMirror mirror) {
|
||||
|
||||
if ( mirror.getKind() == TypeKind.ERROR ) {
|
||||
throw new AnnotationProcessingException( "Encountered erroneous type " + mirror );
|
||||
}
|
||||
|
||||
if ( !isCleared( mirror ) ) {
|
||||
if ( !canBeProcessed( mirror ) ) {
|
||||
throw new TypeHierarchyErroneousException( mirror );
|
||||
}
|
||||
|
||||
@ -573,12 +574,17 @@ public class TypeFactory {
|
||||
return trimmedClassName;
|
||||
}
|
||||
|
||||
private boolean isCleared(TypeMirror type) {
|
||||
/**
|
||||
* Whether the given type is ready to be processed or not. It can be processed if it is not of kind
|
||||
* {@link TypeKind#ERROR} and all {@link AstModifyingAnnotationProcessor}s (if any) indicated that they've fully
|
||||
* processed the type.
|
||||
*/
|
||||
private boolean canBeProcessed(TypeMirror type) {
|
||||
if ( type.getKind() != TypeKind.DECLARED ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( roundContext.isCleared( type ) ) {
|
||||
if ( roundContext.isReadyForProcessing( type ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -592,7 +598,7 @@ public class TypeFactory {
|
||||
}
|
||||
}
|
||||
|
||||
roundContext.addClearedType( type );
|
||||
roundContext.addTypeReadyForProcessing( type );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -47,18 +47,18 @@ public class RoundContext {
|
||||
/**
|
||||
* Marks the given type as being ready for further processing.
|
||||
*/
|
||||
public void addClearedType(TypeMirror type) {
|
||||
public void addTypeReadyForProcessing(TypeMirror type) {
|
||||
clearedTypes.add( type );
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the given type has been found to be ready for further processing or not. This is the case if the type's
|
||||
* hierarchy is complete (no super-types need to be generated by other procesors) an no processors have signaled the
|
||||
* intention to amend the given type.
|
||||
* hierarchy is complete (no super-types need to be generated by other processors) an no processors have signaled
|
||||
* the intention to amend the given type.
|
||||
*
|
||||
* @see AstModifyingAnnotationProcessor
|
||||
*/
|
||||
public boolean isCleared(TypeMirror type) {
|
||||
public boolean isReadyForProcessing(TypeMirror type) {
|
||||
return clearedTypes.contains( type );
|
||||
}
|
||||
}
|
||||
|
@ -44,7 +44,8 @@ public interface AstModifyingAnnotationProcessor {
|
||||
* given type's structure after this invocation).
|
||||
*
|
||||
* @param type The type of interest
|
||||
* @return {@code true} if this processor has fully processed the given type, {@code false} otherwise.
|
||||
* @return {@code true} if this processor has fully processed the given type (or has no interest in processing this
|
||||
* type altogether), {@code false} otherwise.
|
||||
*/
|
||||
boolean isTypeComplete(TypeMirror type);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user