Class TraitTypeCheckingExtension
java.lang.Object
org.codehaus.groovy.transform.stc.TypeCheckingExtension
org.codehaus.groovy.transform.stc.AbstractTypeCheckingExtension
org.codehaus.groovy.transform.stc.TraitTypeCheckingExtension
An extension that handles field, super and static method calls within a trait.
- Since:
- 2.3.0
-
Nested Class Summary
Nested classes/interfaces inherited from class org.codehaus.groovy.transform.stc.AbstractTypeCheckingExtension
AbstractTypeCheckingExtension.TypeCheckingScope -
Field Summary
Fields inherited from class org.codehaus.groovy.transform.stc.AbstractTypeCheckingExtension
context, debug, handledFields inherited from class org.codehaus.groovy.transform.stc.TypeCheckingExtension
typeCheckingVisitor -
Constructor Summary
ConstructorsConstructorDescriptionTraitTypeCheckingExtension(StaticTypeCheckingVisitor typeCheckingVisitor) Creates the trait-specific type-checking extension. -
Method Summary
Modifier and TypeMethodDescriptionvoidafterMethodCall(MethodCall call) Checks a call to a private or static trait method from a closure against the delegate of the enclosing closure, if the delegate would be selected for a method of a class or the resolve strategy excludes the owner.handleMissingMethod(ClassNode receiver, String name, ArgumentListExpression argumentList, ClassNode[] argumentTypes, MethodCall call) Resolves trait super calls and helper-backed trait method dispatch.booleanResolves synthetic trait field accessor properties.voidonMethodSelection(Expression expression, MethodNode target) Keeps a call that the trait transformation marked for dynamic dispatch dynamic when the receiver type declares a method that matches it, and likewise keeps a@Virtualstatic accessor read as a property dynamic when the receiver class has a getter of the same name, such asClass.getName().Methods inherited from class org.codehaus.groovy.transform.stc.AbstractTypeCheckingExtension
argTypeMatches, argTypeMatches, argTypesMatches, argTypesMatches, delegatesTo, delegatesTo, delegatesTo, firstArgTypesMatches, firstArgTypesMatches, getArguments, getCurrentScope, getEnclosingBinaryExpression, getEnclosingBinaryExpressionStack, getEnclosingClassNode, getEnclosingClassNodes, getEnclosingClosure, getEnclosingClosureStack, getEnclosingMethod, getEnclosingMethodCall, getEnclosingMethodCalls, getEnclosingMethods, getGeneratedMethods, isAnnotatedBy, isAnnotatedBy, isDynamic, isExtensionMethod, isGenerated, isMethodCall, log, makeDynamic, makeDynamic, makeDynamic, makeDynamic, makeDynamic, makeDynamic, newMethod, newMethod, newMethod, newScope, newScope, popEnclosingBinaryExpression, popEnclosingClassNode, popEnclosingClosure, popEnclosingMethod, popEnclosingMethodCall, popTemporaryTypeInfo, pushEnclosingBinaryExpression, pushEnclosingClassNode, pushEnclosingClosureExpression, pushEnclosingMethod, pushEnclosingMethodCall, pushTemporaryTypeInfo, safeCall, scopeExit, scopeExit, setHandled, unique, withTypeCheckerMethods inherited from class org.codehaus.groovy.transform.stc.TypeCheckingExtension
addStaticTypeError, afterVisitClass, afterVisitMethod, beforeMethodCall, beforeVisitClass, beforeVisitMethod, buildListType, buildMapType, classNodeFor, classNodeFor, existsProperty, existsProperty, extractStaticReceiver, finish, getArgumentTypes, getOptions, getTargetMethod, getType, handleAmbiguousMethods, handleIncompatibleAssignment, handleIncompatibleReturnType, handleUnresolvedAttribute, handleUnresolvedVariableExpression, isStaticMethodCallOnClass, lookupClassNodeFor, parameterizedType, setOptions, setup, storeType
-
Constructor Details
-
TraitTypeCheckingExtension
Creates the trait-specific type-checking extension.
-
-
Method Details
-
handleMissingMethod
public List<MethodNode> handleMissingMethod(ClassNode receiver, String name, ArgumentListExpression argumentList, ClassNode[] argumentTypes, MethodCall call) Resolves trait super calls and helper-backed trait method dispatch.- Overrides:
handleMissingMethodin classTypeCheckingExtension- Parameters:
receiver- the type of the receivername- the name of the called methodargumentList- the list of arguments of the callargumentTypes- the types of the arguments of the callcall- the method call itself, if needed- Returns:
- an empty list if the extension cannot resolve the method, or a list of potential methods if the extension finds candidates. This method must not return null.
-
afterMethodCall
Checks a call to a private or static trait method from a closure against the delegate of the enclosing closure, if the delegate would be selected for a method of a class or the resolve strategy excludes the owner. Statically compiled code keeps the call to the trait helper otherwise. Dynamically compiled code selects the delegate or the trait helper at runtime.- Overrides:
afterMethodCallin classTypeCheckingExtension- Parameters:
call- a method call, either aMethodCallExpression,StaticMethodCallExpression, orConstructorCallExpression
-
handleUnresolvedProperty
Resolves synthetic trait field accessor properties.- Overrides:
handleUnresolvedPropertyin classTypeCheckingExtension- Parameters:
pexp- the unresolved property- Returns:
booleanfalse if this extension doesn't resolve the property, true if it resolves the property.
-
onMethodSelection
Keeps a call that the trait transformation marked for dynamic dispatch dynamic when the receiver type declares a method that matches it, and likewise keeps a@Virtualstatic accessor read as a property dynamic when the receiver class has a getter of the same name, such asClass.getName().- Overrides:
onMethodSelectionin classTypeCheckingExtension- Parameters:
expression- the expression for which a corresponding method has been foundtarget- the method which has been chosen by the type checker
-