public abstract class AbstractInterruptibleASTTransformation
extends ClassCodeVisitorSupport
implements ASTTransformation, org.objectweb.asm.Opcodes
Base class for AST Transformations which will automatically throw an InterruptedException when some conditions are met.
| Modifiers | Name | Description |
|---|---|---|
protected static String |
CHECK_METHOD_START_MEMBER |
Name of the annotation member that controls a check at method entry. |
protected static String |
THROWN_EXCEPTION_TYPE |
Name of the annotation member that names the exception to throw. |
protected boolean |
applyToAllClasses |
Whether every class in the source unit is visited. |
protected boolean |
applyToAllMembers |
Whether every member is visited. |
protected boolean |
checkOnMethodStart |
Whether to wrap a method body with the interrupt check. |
protected SourceUnit |
source |
Source unit being transformed. |
protected ClassNode |
thrownExceptionType |
Exception constructed by the interrupt check. |
| Type Params | Return Type | Name and description |
|---|---|---|
|
protected abstract Expression |
createCondition()Subclasses should implement this method to set the condition of the interruption statement |
|
protected Statement |
createInterruptStatement()
|
|
protected static boolean |
getBooleanAnnotationParameter(AnnotationNode node, String parameterName, boolean defaultValue)Reads a boolean annotation member. |
|
protected static ClassNode |
getClassAnnotationParameter(AnnotationNode node, String parameterName, ClassNode defaultValue)Reads a class annotation member. |
|
protected abstract String |
getErrorMessage()Subclasses should implement this method to provide good error resolution. |
|
protected SourceUnit |
getSourceUnit() |
|
protected static void |
internalError(String message)Throws a bug error prefixed with Internal error:. |
|
protected void |
setupTransform(AnnotationNode node)Copies checkOnMethodStart, applyToAllMembers,
applyToAllClasses, and thrown from node.
|
|
protected abstract ClassNode |
type()Returns the annotation type this transformation accepts. |
|
public void |
visit(ASTNode[] nodes, SourceUnit source) |
|
public final void |
visitDoWhileLoop(DoWhileStatement doWhileStatement) |
|
public final void |
visitForLoop(ForStatement forStatement) |
|
public final void |
visitWhileLoop(WhileStatement whileStatement) |
|
protected final Statement |
wrapBlock(Statement statement)Takes a statement and wraps it into a block statement which first element is the interruption check statement. |
Name of the annotation member that controls a check at method entry.
Name of the annotation member that names the exception to throw.
Whether every class in the source unit is visited. True only when
the annotation's applyToAllMembers and
applyToAllClasses members are both true. When false, only
the annotated class, or the script class, is visited.
Whether every member is visited. Taken from the annotation, and true when the member is omitted. When false, visit limits itself to the annotated method, field, or declaration and forces applyToAllClasses false.
Whether to wrap a method body with the interrupt check. Taken from the annotation, and true when the member is omitted. Subclasses consult this from their method visitor.
Source unit being transformed. Set at the start of each visit.
Exception constructed by the interrupt check. Taken from the
annotation's thrown member, or InterruptedException
when that member is omitted.
Subclasses should implement this method to set the condition of the interruption statement
Reads a boolean annotation member. A missing member yields
defaultValue. A constant is converted with Groovy's
as Boolean coercion.
Fails with GroovyBugError when the member is present but is not a constant, or cannot be coerced to boolean.
node - annotation to readparameterName - member namedefaultValue - used when the member is absentdefaultValue Reads a class annotation member. A missing member yields
defaultValue. A class expression yields its type.
Fails with GroovyBugError when the member is present but is not a class expression.
node - annotation to readparameterName - member namedefaultValue - used when the member is absentdefaultValueSubclasses should implement this method to provide good error resolution.
Throws a bug error prefixed with Internal error:.
Fails with GroovyBugError always.
message - detail appended to that prefix Copies checkOnMethodStart, applyToAllMembers,
applyToAllClasses, and thrown from node.
Omitted members default to true, true, true, and
InterruptedException. applyToAllClasses is forced
false when applyToAllMembers is false.
node - annotation that triggered this transformationReturns the annotation type this transformation accepts. visit rejects a call whose annotation is a different type.
Takes a statement and wraps it into a block statement which first element is the interruption check statement.
statement - the statement to be wrapped