proguard.classfile.editor
Class CodeAttributeComposer

java.lang.Object
  extended by proguard.classfile.util.SimplifiedVisitor
      extended by proguard.classfile.editor.CodeAttributeComposer
All Implemented Interfaces:
StackMapFrameVisitor, VerificationTypeVisitor, AttributeVisitor, ExceptionInfoVisitor, LineNumberInfoVisitor, LocalVariableInfoVisitor, LocalVariableTypeInfoVisitor, InstructionVisitor

public class CodeAttributeComposer
extends SimplifiedVisitor
implements AttributeVisitor, InstructionVisitor, ExceptionInfoVisitor, StackMapFrameVisitor, VerificationTypeVisitor, LineNumberInfoVisitor, LocalVariableInfoVisitor, LocalVariableTypeInfoVisitor

This AttributeVisitor accumulates instructions and exceptions, and then copies them into code attributes that it visits.


Constructor Summary
CodeAttributeComposer()
          Creates a new CodeAttributeComposer that doesn't allow external exception handlers.
CodeAttributeComposer(boolean allowExternalExceptionHandlers)
          Creates a new CodeAttributeComposer that optionally allows external exception handlers.
 
Method Summary
 void appendException(ExceptionInfo exceptionInfo)
          Appends the given exception to the exception table.
 void appendInstruction(int oldInstructionOffset, Instruction instruction)
          Appends the given instruction with the given old offset.
 void appendLabel(int oldInstructionOffset)
          Appends the given label with the given old offset.
 void beginCodeFragment(int maximumCodeFragmentLength)
          Starts a new code fragment.
 void endCodeFragment()
          Wraps up the current code fragment, continuing with the previous one on the stack.
static void main(java.lang.String[] args)
           
 void reset()
          Starts a new code definition.
 void visitAnyAttribute(Clazz clazz, Attribute attribute)
          Visit any type of attribute.
 void visitAnyInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, Instruction instruction)
          Visits any type of Instruction.
 void visitAnyStackMapFrame(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, StackMapFrame stackMapFrame)
          Visits any type of VerificationType.
 void visitAnySwitchInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, SwitchInstruction switchInstruction)
          Visits either type of SwitchInstruction.
 void visitAnyVerificationType(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, VerificationType verificationType)
          Visits any type of VerificationType.
 void visitBranchInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, BranchInstruction branchInstruction)
           
 void visitCodeAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute)
           
 void visitExceptionInfo(Clazz clazz, Method method, CodeAttribute codeAttribute, ExceptionInfo exceptionInfo)
           
 void visitFullFrame(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, FullFrame fullFrame)
           
 void visitLineNumberInfo(Clazz clazz, Method method, CodeAttribute codeAttribute, LineNumberInfo lineNumberInfo)
           
 void visitLineNumberTableAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute, LineNumberTableAttribute lineNumberTableAttribute)
           
 void visitLocalVariableInfo(Clazz clazz, Method method, CodeAttribute codeAttribute, LocalVariableInfo localVariableInfo)
           
 void visitLocalVariableTableAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute, LocalVariableTableAttribute localVariableTableAttribute)
           
 void visitLocalVariableTypeInfo(Clazz clazz, Method method, CodeAttribute codeAttribute, LocalVariableTypeInfo localVariableTypeInfo)
           
 void visitLocalVariableTypeTableAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute, LocalVariableTypeTableAttribute localVariableTypeTableAttribute)
           
 void visitMoreZeroFrame(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, MoreZeroFrame moreZeroFrame)
           
 void visitSameOneFrame(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, SameOneFrame sameOneFrame)
           
 void visitStackMapAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute, StackMapAttribute stackMapAttribute)
           
 void visitStackMapTableAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute, StackMapTableAttribute stackMapTableAttribute)
           
 void visitUninitializedType(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, UninitializedType uninitializedType)
           
 
Methods inherited from class proguard.classfile.util.SimplifiedVisitor
visitAnnotation, visitAnnotation, visitAnnotation, visitAnnotation, visitAnnotation, visitAnnotationDefaultAttribute, visitAnnotationElementValue, visitAnyAnnotationsAttribute, visitAnyClass, visitAnyConstant, visitAnyElementValue, visitAnyMember, visitAnyMethodrefConstant, visitAnyParameterAnnotationsAttribute, visitAnyRefConstant, visitArrayElementValue, visitClassConstant, visitClassElementValue, visitConstantElementValue, visitConstantInstruction, visitConstantValueAttribute, visitDeprecatedAttribute, visitDeprecatedAttribute, visitDeprecatedAttribute, visitDeprecatedAttribute, visitDoubleConstant, visitDoubleType, visitEnclosingMethodAttribute, visitEnumConstantElementValue, visitExceptionsAttribute, visitFieldrefConstant, visitFloatConstant, visitFloatType, visitInnerClassesAttribute, visitIntegerConstant, visitIntegerType, visitInterfaceMethodrefConstant, visitLessZeroFrame, visitLibraryClass, visitLibraryField, visitLibraryMember, visitLibraryMethod, visitLongConstant, visitLongType, visitLookUpSwitchInstruction, visitMethodrefConstant, visitNameAndTypeConstant, visitNullType, visitObjectType, visitProgramClass, visitProgramField, visitProgramMember, visitProgramMethod, visitRuntimeInvisibleAnnotationsAttribute, visitRuntimeInvisibleAnnotationsAttribute, visitRuntimeInvisibleAnnotationsAttribute, visitRuntimeInvisibleAnnotationsAttribute, visitRuntimeInvisibleParameterAnnotationsAttribute, visitRuntimeVisibleAnnotationsAttribute, visitRuntimeVisibleAnnotationsAttribute, visitRuntimeVisibleAnnotationsAttribute, visitRuntimeVisibleAnnotationsAttribute, visitRuntimeVisibleParameterAnnotationsAttribute, visitSameZeroFrame, visitSignatureAttribute, visitSignatureAttribute, visitSignatureAttribute, visitSignatureAttribute, visitSimpleInstruction, visitSourceDirAttribute, visitSourceFileAttribute, visitStackDoubleType, visitStackFloatType, visitStackIntegerType, visitStackLongType, visitStackNullType, visitStackObjectType, visitStackTopType, visitStackUninitializedThisType, visitStackUninitializedType, visitStringConstant, visitSyntheticAttribute, visitSyntheticAttribute, visitSyntheticAttribute, visitSyntheticAttribute, visitTableSwitchInstruction, visitTopType, visitUninitializedThisType, visitUnknownAttribute, visitUtf8Constant, visitVariableInstruction, visitVariablesDoubleType, visitVariablesFloatType, visitVariablesIntegerType, visitVariablesLongType, visitVariablesNullType, visitVariablesObjectType, visitVariablesTopType, visitVariablesUninitializedThisType, visitVariablesUninitializedType
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface proguard.classfile.attribute.visitor.AttributeVisitor
visitAnnotationDefaultAttribute, visitConstantValueAttribute, visitDeprecatedAttribute, visitDeprecatedAttribute, visitDeprecatedAttribute, visitEnclosingMethodAttribute, visitExceptionsAttribute, visitInnerClassesAttribute, visitRuntimeInvisibleAnnotationsAttribute, visitRuntimeInvisibleAnnotationsAttribute, visitRuntimeInvisibleAnnotationsAttribute, visitRuntimeInvisibleParameterAnnotationsAttribute, visitRuntimeVisibleAnnotationsAttribute, visitRuntimeVisibleAnnotationsAttribute, visitRuntimeVisibleAnnotationsAttribute, visitRuntimeVisibleParameterAnnotationsAttribute, visitSignatureAttribute, visitSignatureAttribute, visitSignatureAttribute, visitSourceDirAttribute, visitSourceFileAttribute, visitSyntheticAttribute, visitSyntheticAttribute, visitSyntheticAttribute, visitUnknownAttribute
 
Methods inherited from interface proguard.classfile.instruction.visitor.InstructionVisitor
visitConstantInstruction, visitLookUpSwitchInstruction, visitSimpleInstruction, visitTableSwitchInstruction, visitVariableInstruction
 
Methods inherited from interface proguard.classfile.attribute.preverification.visitor.StackMapFrameVisitor
visitLessZeroFrame, visitSameZeroFrame
 
Methods inherited from interface proguard.classfile.attribute.preverification.visitor.VerificationTypeVisitor
visitDoubleType, visitFloatType, visitIntegerType, visitLongType, visitNullType, visitObjectType, visitStackDoubleType, visitStackFloatType, visitStackIntegerType, visitStackLongType, visitStackNullType, visitStackObjectType, visitStackTopType, visitStackUninitializedThisType, visitStackUninitializedType, visitTopType, visitUninitializedThisType, visitVariablesDoubleType, visitVariablesFloatType, visitVariablesIntegerType, visitVariablesLongType, visitVariablesNullType, visitVariablesObjectType, visitVariablesTopType, visitVariablesUninitializedThisType, visitVariablesUninitializedType
 

Constructor Detail

CodeAttributeComposer

public CodeAttributeComposer()
Creates a new CodeAttributeComposer that doesn't allow external exception handlers.


CodeAttributeComposer

public CodeAttributeComposer(boolean allowExternalExceptionHandlers)
Creates a new CodeAttributeComposer that optionally allows external exception handlers.

Method Detail

reset

public void reset()
Starts a new code definition.


beginCodeFragment

public void beginCodeFragment(int maximumCodeFragmentLength)
Starts a new code fragment. Branch instructions that are added are assumed to be relative within such code fragments.

Parameters:
maximumCodeFragmentLength - the maximum length of the code that will be added as part of this fragment.

appendInstruction

public void appendInstruction(int oldInstructionOffset,
                              Instruction instruction)
Appends the given instruction with the given old offset.

Parameters:
oldInstructionOffset - the old offset of the instruction, to which branches and other references in the current code fragment are pointing.
instruction - the instruction to be appended.

appendLabel

public void appendLabel(int oldInstructionOffset)
Appends the given label with the given old offset.

Parameters:
oldInstructionOffset - the old offset of the label, to which branches and other references in the current code fragment are pointing.

appendException

public void appendException(ExceptionInfo exceptionInfo)
Appends the given exception to the exception table.

Parameters:
exceptionInfo - the exception to be appended.

endCodeFragment

public void endCodeFragment()
Wraps up the current code fragment, continuing with the previous one on the stack.


visitAnyAttribute

public void visitAnyAttribute(Clazz clazz,
                              Attribute attribute)
Description copied from class: SimplifiedVisitor
Visit any type of attribute.

Overrides:
visitAnyAttribute in class SimplifiedVisitor

visitCodeAttribute

public void visitCodeAttribute(Clazz clazz,
                               Method method,
                               CodeAttribute codeAttribute)
Specified by:
visitCodeAttribute in interface AttributeVisitor
Overrides:
visitCodeAttribute in class SimplifiedVisitor

visitStackMapAttribute

public void visitStackMapAttribute(Clazz clazz,
                                   Method method,
                                   CodeAttribute codeAttribute,
                                   StackMapAttribute stackMapAttribute)
Specified by:
visitStackMapAttribute in interface AttributeVisitor
Overrides:
visitStackMapAttribute in class SimplifiedVisitor

visitStackMapTableAttribute

public void visitStackMapTableAttribute(Clazz clazz,
                                        Method method,
                                        CodeAttribute codeAttribute,
                                        StackMapTableAttribute stackMapTableAttribute)
Specified by:
visitStackMapTableAttribute in interface AttributeVisitor
Overrides:
visitStackMapTableAttribute in class SimplifiedVisitor

visitLineNumberTableAttribute

public void visitLineNumberTableAttribute(Clazz clazz,
                                          Method method,
                                          CodeAttribute codeAttribute,
                                          LineNumberTableAttribute lineNumberTableAttribute)
Specified by:
visitLineNumberTableAttribute in interface AttributeVisitor
Overrides:
visitLineNumberTableAttribute in class SimplifiedVisitor

visitLocalVariableTableAttribute

public void visitLocalVariableTableAttribute(Clazz clazz,
                                             Method method,
                                             CodeAttribute codeAttribute,
                                             LocalVariableTableAttribute localVariableTableAttribute)
Specified by:
visitLocalVariableTableAttribute in interface AttributeVisitor
Overrides:
visitLocalVariableTableAttribute in class SimplifiedVisitor

visitLocalVariableTypeTableAttribute

public void visitLocalVariableTypeTableAttribute(Clazz clazz,
                                                 Method method,
                                                 CodeAttribute codeAttribute,
                                                 LocalVariableTypeTableAttribute localVariableTypeTableAttribute)
Specified by:
visitLocalVariableTypeTableAttribute in interface AttributeVisitor
Overrides:
visitLocalVariableTypeTableAttribute in class SimplifiedVisitor

visitAnyInstruction

public void visitAnyInstruction(Clazz clazz,
                                Method method,
                                CodeAttribute codeAttribute,
                                int offset,
                                Instruction instruction)
Description copied from class: SimplifiedVisitor
Visits any type of Instruction.

Overrides:
visitAnyInstruction in class SimplifiedVisitor

visitBranchInstruction

public void visitBranchInstruction(Clazz clazz,
                                   Method method,
                                   CodeAttribute codeAttribute,
                                   int offset,
                                   BranchInstruction branchInstruction)
Specified by:
visitBranchInstruction in interface InstructionVisitor
Overrides:
visitBranchInstruction in class SimplifiedVisitor

visitAnySwitchInstruction

public void visitAnySwitchInstruction(Clazz clazz,
                                      Method method,
                                      CodeAttribute codeAttribute,
                                      int offset,
                                      SwitchInstruction switchInstruction)
Description copied from class: SimplifiedVisitor
Visits either type of SwitchInstruction.

Overrides:
visitAnySwitchInstruction in class SimplifiedVisitor

visitExceptionInfo

public void visitExceptionInfo(Clazz clazz,
                               Method method,
                               CodeAttribute codeAttribute,
                               ExceptionInfo exceptionInfo)
Specified by:
visitExceptionInfo in interface ExceptionInfoVisitor

visitAnyStackMapFrame

public void visitAnyStackMapFrame(Clazz clazz,
                                  Method method,
                                  CodeAttribute codeAttribute,
                                  int offset,
                                  StackMapFrame stackMapFrame)
Description copied from class: SimplifiedVisitor
Visits any type of VerificationType.

Overrides:
visitAnyStackMapFrame in class SimplifiedVisitor

visitSameOneFrame

public void visitSameOneFrame(Clazz clazz,
                              Method method,
                              CodeAttribute codeAttribute,
                              int offset,
                              SameOneFrame sameOneFrame)
Specified by:
visitSameOneFrame in interface StackMapFrameVisitor
Overrides:
visitSameOneFrame in class SimplifiedVisitor

visitMoreZeroFrame

public void visitMoreZeroFrame(Clazz clazz,
                               Method method,
                               CodeAttribute codeAttribute,
                               int offset,
                               MoreZeroFrame moreZeroFrame)
Specified by:
visitMoreZeroFrame in interface StackMapFrameVisitor
Overrides:
visitMoreZeroFrame in class SimplifiedVisitor

visitFullFrame

public void visitFullFrame(Clazz clazz,
                           Method method,
                           CodeAttribute codeAttribute,
                           int offset,
                           FullFrame fullFrame)
Specified by:
visitFullFrame in interface StackMapFrameVisitor
Overrides:
visitFullFrame in class SimplifiedVisitor

visitAnyVerificationType

public void visitAnyVerificationType(Clazz clazz,
                                     Method method,
                                     CodeAttribute codeAttribute,
                                     int offset,
                                     VerificationType verificationType)
Description copied from class: SimplifiedVisitor
Visits any type of VerificationType.

Overrides:
visitAnyVerificationType in class SimplifiedVisitor

visitUninitializedType

public void visitUninitializedType(Clazz clazz,
                                   Method method,
                                   CodeAttribute codeAttribute,
                                   int offset,
                                   UninitializedType uninitializedType)
Specified by:
visitUninitializedType in interface VerificationTypeVisitor
Overrides:
visitUninitializedType in class SimplifiedVisitor

visitLineNumberInfo

public void visitLineNumberInfo(Clazz clazz,
                                Method method,
                                CodeAttribute codeAttribute,
                                LineNumberInfo lineNumberInfo)
Specified by:
visitLineNumberInfo in interface LineNumberInfoVisitor

visitLocalVariableInfo

public void visitLocalVariableInfo(Clazz clazz,
                                   Method method,
                                   CodeAttribute codeAttribute,
                                   LocalVariableInfo localVariableInfo)
Specified by:
visitLocalVariableInfo in interface LocalVariableInfoVisitor

visitLocalVariableTypeInfo

public void visitLocalVariableTypeInfo(Clazz clazz,
                                       Method method,
                                       CodeAttribute codeAttribute,
                                       LocalVariableTypeInfo localVariableTypeInfo)
Specified by:
visitLocalVariableTypeInfo in interface LocalVariableTypeInfoVisitor

main

public static void main(java.lang.String[] args)