Interface PlasticMethod

    • Method Detail

      • getHandle

        MethodHandle getHandle()
        Returns a handle that can be used to invoke a method of a transformed class instance.
      • changeImplementation

        PlasticMethod changeImplementation​(InstructionBuilderCallback callback)
        Clears the instructions for this method, and creates a new empty InstructionBuilder so that the implementation of the method can be specified. This may be considered a kind of last resort when no other approach is sufficient. If the method is currently abstract, it will have its abstract flag cleared. If the method has advice, the advice is not lost but will instead wrap around the new method implementation.
        callback - passed the InstructionBuilder so that an implementation of the method can be created
        this method, for further configuration
      • addAdvice

        PlasticMethod addAdvice​(MethodAdvice advice)
        Adds advice to the method. Adding advice implicitly rewrites the implementation of the method (this occurs inside at the end of the class transformation). When the method is invoked, control will flow through the MethodAdvice in the order they are added. Each piece of advice will receive the MethodInvocation and should invoke MethodInvocation.proceed() to pass control to the next piece of advice (and ultimately, to the actual method invocation). If a method implementation is changed, using changeImplementation(InstructionBuilderCallback), that change will be honored, but the logic will only be invoked at the end of the chain of MethodAdvice. Internally, a new method is created with the same parameters, exceptions, return type and implementation (bytecode) as the advised method, then the advised method's implementation is changed. Note additionally that a recursive method invocation will still invoke the MethodAdvice chain on each recursive call (this is an intended side-effect of copying the exact bytecode of the method implementation.
        advice - advice to add to the method
        this method, for further configuration
      • delegateTo

        PlasticMethod delegateTo​(PlasticField field)
        Changes the implementation of the method to delegate to the provided field. The field must implement the correct interface (or extend the correct class). The original implementation of the method is lost, though (as with changeImplementation(InstructionBuilderCallback)), method advice is retained.
        field - to delegate to
        this method, for further configuration
      • delegateTo

        PlasticMethod delegateTo​(PlasticMethod method)
        Much like delegateTo(PlasticField), but the object to delegate to is dynamically computed by another method of the class. The method should take no parameters and must not return null, or throw any exceptions not compatible with the method being proxied.
        method - to provide the dynamic delegate
        this method, for further configuration
      • getParameters

        Returns access to the parameters of the method and, in particular, the visible annotations on those parameters.
      • isOverride

        boolean isOverride()
        Returns true if the method is an override of a method from the parent class.
        true if the parent class contains a method with the name signature
      • isAbstract

        boolean isAbstract()
        Returns true if the method is abstract.
      • getMethodIdentifier

        String getMethodIdentifier()
        Returns a short identifier for the method that includes the class name, the method name, and the types of all parameters. This is often used when producing debugging output about the method.
        short identifier
        See Also:
      • isVoid

        boolean isVoid()
        Returns true if this method is type void.
        true for void methods.