Groovy Documentation

org.codehaus.groovy.transform.stc
[Java] Class TypeCheckerPlugin

java.lang.Object
  org.codehaus.groovy.transform.stc.TypeCheckerPlugin

public abstract class TypeCheckerPlugin
extends java.lang.Object

Type checking plugins can be used to extend the type checker capabilities. For example, when a method is not found or a dynamic variable is recognized, a plugin may return the type of the expression.

This is an expert and experimental feature. APIs may change without notice.

Authors:
Cedric Champeau
Since:
2.0.0


Method Summary
java.util.List findMethod(ClassNode receiver, java.lang.String name, ClassNode... args)

This method is called by the type checker whenever it fails to find a method on a receiver.

ClassNode resolveDynamicVariableType(DynamicVariable variable)

This method is called when the type checker finds a dynamic variable which is not supposed to be allowed.

PropertyNode resolveProperty(ClassNode receiver, java.lang.String propertyName)

This method is called when the type checker cannot find a property on a receiver.

protected static Parameter[] toParameterArray(ClassNode[] types)

 
Methods inherited from class java.lang.Object
java.lang.Object#wait(long), java.lang.Object#wait(long, int), java.lang.Object#wait(), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll()
 

Method Detail

findMethod

public java.util.List findMethod(ClassNode receiver, java.lang.String name, ClassNode... args)
This method is called by the type checker whenever it fails to find a method on a receiver. In that case, it delegates the search to the plugin, which may return a list of matching method nodes.

Strictly speaking, it is not required that the returned method nodes correspond to real method nodes. The type checker will normally use the return type of the method node to infer the return type of the call. Therefore, if you create a virtual method node and that you want the type checker to behave correctly, you must ensure, at least, to return a method node with a valid return type. This is important when the return type makes use of generics, for example.

Note that this method can be called several times with the same method name and arguments, but with different receivers. This is the case, for example, when you are in with{} blocks and that a method could potentially be called on different receivers. Be sure to return an empty list if you are not able to determine a method node for the current receiver.

Parameters:
receiver - a class node for with an undefined method is called
name - the name of the method
args - the inferred arguments types of the method.
Returns:
a list of matching method nodes.


resolveDynamicVariableType

public ClassNode resolveDynamicVariableType(DynamicVariable variable)
This method is called when the type checker finds a dynamic variable which is not supposed to be allowed. In that case, a plugin may return a type for the dynamic variable.

This is useful when type checking scripts for which, for example, a binding has been set, and that you know the types of the variables included in the binding.

If the plugin is not able to determine the type of a variable, it is required to return null, which will in turn trigger a compilation error. Any non null type will be considered as the inferred type.

Parameters:
variable - the dynamic variable for which we want the plugin to resolve the type
Returns:
the type of the dynamic variable, or null if the plugin is not able to determine its type.


resolveProperty

public PropertyNode resolveProperty(ClassNode receiver, java.lang.String propertyName)
This method is called when the type checker cannot find a property on a receiver.

This is useful when classes override the getProperty method.

If the plugin is not able to determine the type of a variable, it is required to return null, which will in turn trigger a compilation error. Any non null type will be considered as the inferred type.

Note that this method can be called multiple times with the same property name before you reach a receiver you expect. It is required that you check the receiver type.

It is not required that the returned property node actually exists.

Parameters:
receiver - a class node for which a property wasn't found
propertyName - the name of the property
Returns:
the type of the property or null if the plugin is not able to determine its type.


toParameterArray

protected static Parameter[] toParameterArray(ClassNode[] types)


 

Groovy Documentation