public class MethodWeaver extends EclipseLinkMethodVisitor
Processes all the methods of a class to weave in persistence code such as, lazy value holder, change tracking and fetch groups. For FIELD access, changes references to GETFIELD and PUTFIELD to call weaved get/set methods. For Property access, modifies the getters and setters.
  • Field Details

    • tcw

      protected ClassWeaver tcw
    • methodName

      protected String methodName
    • methodDescriptor

      protected String methodDescriptor
    • methodStarted

      protected boolean methodStarted
      Determines if we are at the first line of a method.
  • Constructor Details

  • Method Details

    • visitInsn

      public void visitInsn(int opcode)
      Overrides:
      visitInsn in class EclipseLinkMethodVisitor
    • visitIntInsn

      public void visitIntInsn(int opcode, int operand)
      Overrides:
      visitIntInsn in class EclipseLinkMethodVisitor
    • visitVarInsn

      public void visitVarInsn(int opcode, int var)
      Overrides:
      visitVarInsn in class EclipseLinkMethodVisitor
    • visitTypeInsn

      public void visitTypeInsn(int opcode, String desc)
      Overrides:
      visitTypeInsn in class EclipseLinkMethodVisitor
    • visitFieldInsn

      public void visitFieldInsn(int opcode, String owner, String name, String desc)
      Overrides:
      visitFieldInsn in class EclipseLinkMethodVisitor
    • visitMethodInsn

      public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean intf)
      Overrides:
      visitMethodInsn in class EclipseLinkMethodVisitor
    • visitJumpInsn

      public void visitJumpInsn(int opcode, Label label)
      Overrides:
      visitJumpInsn in class EclipseLinkMethodVisitor
    • visitLabel

      public void visitLabel(Label label)
      Overrides:
      visitLabel in class EclipseLinkMethodVisitor
    • visitLdcInsn

      public void visitLdcInsn(Object cst)
      Overrides:
      visitLdcInsn in class EclipseLinkMethodVisitor
    • visitIincInsn

      public void visitIincInsn(int var, int increment)
      Overrides:
      visitIincInsn in class EclipseLinkMethodVisitor
    • visitTableSwitchInsn

      public void visitTableSwitchInsn(int min, int max, Label dflt, Label... labels)
      Overrides:
      visitTableSwitchInsn in class EclipseLinkMethodVisitor
    • visitLookupSwitchInsn

      public void visitLookupSwitchInsn(Label dflt, int[] keys, Label[] labels)
      Overrides:
      visitLookupSwitchInsn in class EclipseLinkMethodVisitor
    • visitMultiANewArrayInsn

      public void visitMultiANewArrayInsn(String desc, int dims)
      Overrides:
      visitMultiANewArrayInsn in class EclipseLinkMethodVisitor
    • visitTryCatchBlock

      public void visitTryCatchBlock(Label start, Label end, Label handler, String type)
      Overrides:
      visitTryCatchBlock in class EclipseLinkMethodVisitor
    • visitMaxs

      public void visitMaxs(int maxStack, int maxLocals)
      Overrides:
      visitMaxs in class EclipseLinkMethodVisitor
    • visitLocalVariable

      public void visitLocalVariable(String name, String desc, String signature, Label start, Label end, int index)
      Overrides:
      visitLocalVariable in class EclipseLinkMethodVisitor
    • visitLineNumber

      public void visitLineNumber(int line, Label start)
      Overrides:
      visitLineNumber in class EclipseLinkMethodVisitor
    • visitAttribute

      public void visitAttribute(Attribute attr)
      Overrides:
      visitAttribute in class EclipseLinkMethodVisitor
    • visitAnnotation

      public AnnotationVisitor visitAnnotation(String desc, boolean visible)
      Overrides:
      visitAnnotation in class EclipseLinkMethodVisitor
    • visitEnd

      public void visitEnd()
      Overrides:
      visitEnd in class EclipseLinkMethodVisitor
    • weaveAttributesIfRequired

      public void weaveAttributesIfRequired(int opcode, String owner, String name, String desc)
      Change GETFIELD and PUTFIELD for fields that use attribute access to make use of new convenience methods. A GETFIELD for an attribute named 'variableName' will be replaced by a call to: _persistence_get_variableName() A PUTFIELD for an attribute named 'variableName' will be replaced by a call to: _persistence_set_variableName(variableName)
    • weaveBeginningOfMethodIfRequired

      public void weaveBeginningOfMethodIfRequired()
      Makes modifications to the beginning of a method. 1. Modifies getter method for attributes using property access In a getter method for 'attributeName', the following lines are added at the beginning of the method _persistence_checkFetched("attributeName"); _persistence_initialize_attributeName_vh(); if (!_persistence_attributeName_vh.isInstantiated()) { PropertyChangeListener temp_persistence_listener = _persistence_listener; _persistence_listener = null; setAttributeName((AttributeType)_persistence_attributeName_vh.getValue()); _persistence_listener = temp_persistence_listener; } 2. Modifies setter methods to store old value of attribute If weaving for fetch groups: // if weaving for change tracking: if(_persistence_listener != null) // for Objects AttributeType oldAttribute = getAttribute() // for primitives AttributeWrapperType oldAttribute = new AttributeWrapperType(getAttribute()); e.g. Double oldAttribute = Double.valueOf(getAttribute()); else _persistence_checkFetchedForSet("attributeName"); _persistence_propertyChange("attributeName", oldAttribute, argument); otherwise (not weaving for fetch groups): // for Objects AttributeType oldAttribute = getAttribute() // for primitives AttributeWrapperType oldAttribute = new AttributeWrapperType(getAttribute()); e.g. Double oldAttribute = Double.valueOf(getAttribute()); _persistence_propertyChange("attributeName", oldAttribute, argument); // if not weaving for change tracking, but for fetch groups only: _persistence_checkFetchedForSet("attributeName"); 3. Modifies getter Method for attributes using virtual access add: _persistence_checkFetched(name); 4. Modifies setter Method for attributes using virtual access add code of the following form: Object obj = null; if(_persistence_listener != null){ obj = get(name); } else { _persistence_checkFetchedForSet(name); } _persistence_propertyChange(name, obj, value); _persistence_checkFetchedForSet(name) call will be excluded if weaving of fetch groups is not enabled _persistence_propertyChange(name, obj, value); will be excluded if weaving of change tracking is not enabled
    • weaveEndOfMethodIfRequired

      public void weaveEndOfMethodIfRequired()
      Modifies methods just before the return. In a setter method for a LAZY mapping, for 'attributeName', the following lines are added at the end of the method. _persistence_initialize_attributeName_vh(); _persistence_attributeName_vh.setValue(argument); _persistence_attributeName_vh.setIsCoordinatedWithProperty(true); In a setter method for a non-LAZY mapping, the followings lines are added if change tracking is activated: _persistence_propertyChange("attributeName", oldAttribute, argument); Note: This code will wrap primitives by adding a call to the primitive constructor.