#510 Adding experimental SPI for letting AST-modifying annotation processors such as Lombok tell us about future modifications

This commit is contained in:
Gunnar Morling 2017-01-31 22:02:29 +01:00
parent 754877cece
commit 5e59f3484c
3 changed files with 17 additions and 10 deletions

View File

@ -70,7 +70,7 @@ public class TypeFactory {
private final Elements elementUtils; private final Elements elementUtils;
private final Types typeUtils; private final Types typeUtils;
private RoundContext roundContext; private final RoundContext roundContext;
private final TypeMirror iterableType; private final TypeMirror iterableType;
private final TypeMirror collectionType; private final TypeMirror collectionType;
@ -147,11 +147,12 @@ public class TypeFactory {
} }
public Type getType(TypeMirror mirror) { public Type getType(TypeMirror mirror) {
if ( mirror.getKind() == TypeKind.ERROR ) { if ( mirror.getKind() == TypeKind.ERROR ) {
throw new AnnotationProcessingException( "Encountered erroneous type " + mirror ); throw new AnnotationProcessingException( "Encountered erroneous type " + mirror );
} }
if ( !isCleared( mirror ) ) { if ( !canBeProcessed( mirror ) ) {
throw new TypeHierarchyErroneousException( mirror ); throw new TypeHierarchyErroneousException( mirror );
} }
@ -573,12 +574,17 @@ public class TypeFactory {
return trimmedClassName; 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 ) { if ( type.getKind() != TypeKind.DECLARED ) {
return true; return true;
} }
if ( roundContext.isCleared( type ) ) { if ( roundContext.isReadyForProcessing( type ) ) {
return true; return true;
} }
@ -592,7 +598,7 @@ public class TypeFactory {
} }
} }
roundContext.addClearedType( type ); roundContext.addTypeReadyForProcessing( type );
return true; return true;
} }

View File

@ -47,18 +47,18 @@ public class RoundContext {
/** /**
* Marks the given type as being ready for further processing. * Marks the given type as being ready for further processing.
*/ */
public void addClearedType(TypeMirror type) { public void addTypeReadyForProcessing(TypeMirror type) {
clearedTypes.add( 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 * 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 * hierarchy is complete (no super-types need to be generated by other processors) an no processors have signaled
* intention to amend the given type. * the intention to amend the given type.
* *
* @see AstModifyingAnnotationProcessor * @see AstModifyingAnnotationProcessor
*/ */
public boolean isCleared(TypeMirror type) { public boolean isReadyForProcessing(TypeMirror type) {
return clearedTypes.contains( type ); return clearedTypes.contains( type );
} }
} }

View File

@ -44,7 +44,8 @@ public interface AstModifyingAnnotationProcessor {
* given type's structure after this invocation). * given type's structure after this invocation).
* *
* @param type The type of interest * @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); boolean isTypeComplete(TypeMirror type);
} }