Package org.codehaus.groovy.vmplugin

# Interface VMPlugin

All Known Implementing Classes:
  `Java10`, `Java16`, `Java17`, `Java8`, `Java9`

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

- ## Method Summary

  Modifier and Type
  Method
  Description
  `boolean`
  `checkAccessible(Class<?> callerClass, Class<?> declaringClass, int memberModifiers, boolean allowIllegalAccess)`
  check whether the member can be accessed or not
  `boolean`
  `checkCanSetAccessible(AccessibleObject accessibleObject, Class<?> callerClass)`
  Check whether invoking `AccessibleObject.setAccessible(boolean)` on the accessible object will be completed successfully
  `void`
  `configureAnnotation(AnnotationNode node)`
  Copies runtime annotation metadata into the supplied annotation node.
  `default void`
  `configureAnnotationNodeFromDefinition(AnnotationNode definition, AnnotationNode node)`
  Copies values from an annotation definition onto another annotation node.
  `void`
  `configureClassNode(CompileUnit unit, ClassNode node)`
  Configures the supplied class node from its runtime type information.
  `default Map<String,Set<String>>`
  `getDefaultImportClasses(String[] packageNames)`
  Returns the default import classes: class name -> the relevant package names
  `Object`
  `getInvokeSpecialHandle(Method m, Object receiver)`
  Returns a handle with bound receiver to invokeSpecial the given method.
  `static String`
  `getJavaVersion()`
  Deprecated.
  `Class[]`
  `getPluginDefaultGroovyMethods()`
  Returns plugin-specific default Groovy methods.
  `Class[]`
  `getPluginStaticGroovyMethods()`
  Returns plugin-specific static Groovy methods.
  `default List<String>`
  `getRecordComponentNames(Class<?> maybeRecord)`
  Returns the list of record component names or the empty list if the class is not a record or running on a pre16 JDK.
  `int`
  `getVersion()`
  Gives the version the plugin is made for
  `void`
  `invalidateCallSites()`
  Invalidates cached call sites maintained by the plugin.
  `Object`
  `invokeHandle(Object handle, Object[] args)`
  Invokes a handle produced by #getInvokeSpecialdHandle
  `void`
  `setAdditionalClassInformation(ClassNode node)`
  Adds VM-specific metadata to the given class node.
  `MetaMethod`
  `transformMetaMethod(MetaClass metaClass, MetaMethod metaMethod)`
  transform meta method.
  `MetaMethod`
  `transformMetaMethod(MetaClass metaClass, MetaMethod metaMethod, Class<?> caller)`
  transform meta method
  `boolean`
  `trySetAccessible(AccessibleObject ao)`
  Set the `accessible` flag for this reflected object to `true` if possible.

- ## Method Details

  - ### getPluginDefaultGroovyMethods

    Class[] getPluginDefaultGroovyMethods()
    Returns plugin-specific default Groovy methods.
    Returns:
      the default Groovy method classes contributed by this plugin

  - ### getPluginStaticGroovyMethods

    Class[] getPluginStaticGroovyMethods()
    Returns plugin-specific static Groovy methods.
    Returns:
      the static Groovy method classes contributed by this plugin

  - ### setAdditionalClassInformation

    void setAdditionalClassInformation(ClassNode node)
    Adds VM-specific metadata to the given class node.
    Parameters:
      `node` - the class node to enrich

  - ### configureClassNode

    void configureClassNode(CompileUnit unit, ClassNode node)
    Configures the supplied class node from its runtime type information.
    Parameters:
      `unit` - the compile unit that owns the class node
      `node` - the class node to configure

  - ### configureAnnotation

    void configureAnnotation(AnnotationNode node)
    Copies runtime annotation metadata into the supplied annotation node.
    Parameters:
      `node` - the annotation node to configure

  - ### configureAnnotationNodeFromDefinition

    default void configureAnnotationNodeFromDefinition(AnnotationNode definition, AnnotationNode node)
    Copies values from an annotation definition onto another annotation node.
    Parameters:
      `definition` - the source annotation definition
      `node` - the annotation node to update

  - ### invalidateCallSites

    void invalidateCallSites()
    Invalidates cached call sites maintained by the plugin.

  - ### getInvokeSpecialHandle

    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:
      null in case of jdk<7, otherwise a handle that takes the method call arguments for the invokespecial call

  - ### invokeHandle

    Object invokeHandle(Object handle, Object[] args) throws Throwable
    Invokes a handle produced by #getInvokeSpecialdHandle
    Parameters:
      `handle` - the handle
      `args` - arguments for the method call, can be empty but not null
    Returns:
      the result of the method call
    Throws:
      `Throwable`

  - ### getVersion

    int getVersion()
    Gives the version the plugin is made for
    Returns:
      7 for jdk7, 8 for jdk8, 9 for jdk9 or higher

  - ### getJavaVersion

    @Deprecated static String getJavaVersion()
    Deprecated.
    Returns java version, e.g. 1.8, 9, 11, 17
    Returns:
      java version
    Since:
      4.0.0

  - ### checkCanSetAccessible

    boolean checkCanSetAccessible(AccessibleObject accessibleObject, Class<?> callerClass)
    Check whether invoking `AccessibleObject.setAccessible(boolean)` on the accessible object will be completed successfully
    Parameters:
      `accessibleObject` - the accessible object to check
      `callerClass` - the callerClass to invoke `setAccessible`
    Returns:
      the check result

  - ### checkAccessible

    boolean checkAccessible(Class<?> callerClass, Class<?> declaringClass, int memberModifiers, boolean allowIllegalAccess)
    check whether the member can be accessed or not
    Parameters:
      `callerClass` - callerClass the callerClass to invoke `setAccessible`
      `declaringClass` - the type of member owner
      `memberModifiers` - modifiers of member
      `allowIllegalAccess` - whether to allow illegal access
    Returns:
      the result of checking

  - ### trySetAccessible

    boolean trySetAccessible(AccessibleObject ao)
    Set the `accessible` flag for this reflected object to `true` if possible.
    Parameters:
      `ao` - the accessible object
    Returns:
      `true` if the `accessible` flag is set to `true`; `false` if access cannot be enabled.
    Throws:
      `SecurityException` - if the request is denied by the security manager (legacy comment)

  - ### transformMetaMethod

    MetaMethod transformMetaMethod(MetaClass metaClass, MetaMethod metaMethod, Class<?> caller)
    transform meta method
    Parameters:
      `metaClass` - metaclass
      `metaMethod` - the original meta method
      `caller` - caller class, whose method sets accessible for methods
    Returns:
      the transformed meta method

  - ### transformMetaMethod

    MetaMethod transformMetaMethod(MetaClass metaClass, MetaMethod metaMethod)
    transform meta method.
    Parameters:
      `metaClass` - metaclass
      `metaMethod` - the original meta method
    Returns:
      the transformed meta method

  - ### getDefaultImportClasses

    default Map<String,Set<String>> getDefaultImportClasses(String[] packageNames)
    Returns the default import classes: class name -> the relevant package names
    Parameters:
      `packageNames` - the default import package names, e.g. java.lang.
    Returns:
      the default import classes
    Since:
      3.0.2

  - ### getRecordComponentNames

    @Incubating default List<String> getRecordComponentNames(Class<?> maybeRecord)
    Returns the list of record component names or the empty list if the class is not a record or running on a pre16 JDK.
    Parameters:
      `maybeRecord` - the class in question
    Returns:
      the default list of names
    Since:
      4.0.15