Top Description Methods
org.codehaus.groovy.vmplugin

public Interface VMPlugin

Known Direct Implementers
org.codehaus.groovy.vmplugin.v5.Java5, org.codehaus.groovy.vmplugin.v8.Java8
Imports
groovy.lang.MetaClass, .MetaMethod, org.codehaus.groovy.ast.AnnotationNode, .ClassNode, .CompileUnit, java.lang.reflect.AccessibleObject, .Method, java.util.Collections, .Map, .Set

Interface to access VM version based actions. This interface is for internal use only!

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

the result of checking
checkAccessible
(Class<?>
callerClass the callerClass to invoke setAccessible
callerClass
,
Class<?>
the type of member owner
declaringClass
,
int
modifiers of member
memberModifiers
,
boolean
whether to allow illegal access
allowIllegalAccess
)

check whether the member can be accessed or not

public boolean

Returns:

the check result
checkCanSetAccessible
(AccessibleObject
the accessible object to check
accessibleObject
,
Class<?>
the callerClass to invoke setAccessible
callerClass
)

Check whether invoking AccessibleObject#setAccessible(boolean) on the accessible object will be completed successfully

public void
public void
public void
configureClassNode(CompileUnit compileUnit, ClassNode classNode)

public default Map<String, Set<String>>

Returns:

the default import classes
getDefaultImportClasses
(String[]
the default import package names, e.g. java.lang.
packageNames
)

Returns the default import classes: class name -> the relevant package names

public Object

Returns:

null in case of jdk<7, otherwise a handle that takes the method call arguments for the invokespecial call
getInvokeSpecialHandle
(Method m, Object receiver)

Returns a handle with bound receiver to invokeSpecial the given method.

public Class<T>[]
public Class<T>[]
public int

Returns:

7 for jdk7, 8 for jdk8, 9 for jdk9 or higher
getVersion
()

Gives the version the plugin is made for

public void
public Object

Returns:

the result of the method call
invokeHandle
(Object
the handle
handle
,
Object[]
arguments for the method call, can be empty but not null
args
)

Invokes a handle produced by #getInvokeSpecialdHandle

public void
public MetaMethod

Returns:

the transformed meta method
transformMetaMethod
(MetaClass
meta class
metaClass
,
MetaMethod
the original meta method
metaMethod
,
Class<?>
caller class, whose method sets accessible for methods
caller
)

transform meta method

public MetaMethod

Returns:

the transformed meta method
transformMetaMethod
(MetaClass
meta class
metaClass
,
MetaMethod
the original meta method
metaMethod
)

transform meta method.

public boolean

Returns:

true if the accessible flag is set to true; false if access cannot be enabled.
trySetAccessible
(AccessibleObject
the accessible object
ao
)

Set the accessible flag for this reflected object to true if possible.

Method Detail

checkAccessibleback to summary
public boolean checkAccessible(Class<?> callerClass, Class<?> declaringClass, int memberModifiers, boolean allowIllegalAccess)

check whether the member can be accessed or not

Parameters
callerClass:Class<?>

callerClass the callerClass to invoke setAccessible

declaringClass:Class<?>

the type of member owner

memberModifiers:int

modifiers of member

allowIllegalAccess:boolean

whether to allow illegal access

Returns:boolean

the result of checking

checkCanSetAccessibleback to summary
public boolean checkCanSetAccessible(AccessibleObject accessibleObject, Class<?> callerClass)

Check whether invoking AccessibleObject#setAccessible(boolean) on the accessible object will be completed successfully

Parameters
accessibleObject:AccessibleObject

the accessible object to check

callerClass:Class<?>

the callerClass to invoke setAccessible

Returns:boolean

the check result

configureAnnotationback to summary
public void configureAnnotation(AnnotationNode an)
configureAnnotationNodeFromDefinitionback to summary
public void configureAnnotationNodeFromDefinition(AnnotationNode definition, AnnotationNode root)
configureClassNodeback to summary
public void configureClassNode(CompileUnit compileUnit, ClassNode classNode)
getDefaultImportClassesback to summary
public default Map<String, Set<String>> getDefaultImportClasses(String[] packageNames)

Returns the default import classes: class name -> the relevant package names

Parameters
packageNames:String[]

the default import package names, e.g. java.lang.

Returns:Map<String, Set<String>>

the default import classes

Since
3.0.2
getInvokeSpecialHandleback to summary
public Object getInvokeSpecialHandle(Method m, Object receiver)

Returns a handle with bound receiver to invokeSpecial the given method. This method will require at least Java 7, but since the source has to compile on older Java versions as well it is not marked to return a MethodHandle and uses Object instead

Returns:Object

null in case of jdk<7, otherwise a handle that takes the method call arguments for the invokespecial call

getPluginDefaultGroovyMethodsback to summary
public Class<T>[] getPluginDefaultGroovyMethods()
getPluginStaticGroovyMethodsback to summary
public Class<T>[] getPluginStaticGroovyMethods()
getVersionback to summary
public int getVersion()

Gives the version the plugin is made for

Returns:int

7 for jdk7, 8 for jdk8, 9 for jdk9 or higher

invalidateCallSitesback to summary
public void invalidateCallSites()
invokeHandleback to summary
public Object invokeHandle(Object handle, Object[] args) throws Throwable

Invokes a handle produced by #getInvokeSpecialdHandle

Parameters
handle:Object

the handle

args:Object[]

arguments for the method call, can be empty but not null

Returns:Object

the result of the method call

setAdditionalClassInformationback to summary
public void setAdditionalClassInformation(ClassNode c)
transformMetaMethodback to summary
public MetaMethod transformMetaMethod(MetaClass metaClass, MetaMethod metaMethod, Class<?> caller)

transform meta method

Parameters
metaClass:MetaClass

meta class

metaMethod:MetaMethod

the original meta method

caller:Class<?>

caller class, whose method sets accessible for methods

Returns:MetaMethod

the transformed meta method

transformMetaMethodback to summary
public MetaMethod transformMetaMethod(MetaClass metaClass, MetaMethod metaMethod)

transform meta method.

Parameters
metaClass:MetaClass

meta class

metaMethod:MetaMethod

the original meta method

Returns:MetaMethod

the transformed meta method

trySetAccessibleback to summary
public boolean trySetAccessible(AccessibleObject ao)

Set the accessible flag for this reflected object to true if possible.

Parameters
ao:AccessibleObject

the accessible object

Returns:boolean

true if the accessible flag is set to true; false if access cannot be enabled.

Exceptions
SecurityException:
if the request is denied by the security manager