Java Code Examples for proguard.classfile.instruction.visitor.InstructionVisitor

The following examples show how to use proguard.classfile.instruction.visitor.InstructionVisitor. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
public ConfigurationLoggingInstructionSequenceReplacer(InstructionSequenceMatcher instructionSequenceMatcher,
                                                       Constant[]                 patternConstants,
                                                       Instruction[]              patternInstructions,
                                                       Constant[]                 replacementConstants,
                                                       Instruction[]              replacementInstructions,
                                                       BranchTargetFinder         branchTargetFinder,
                                                       CodeAttributeEditor        codeAttributeEditor,
                                                       InstructionVisitor         extraInstructionVisitor    )
{
    super(instructionSequenceMatcher,
          patternConstants,
          patternInstructions,
          replacementConstants,
          replacementInstructions,
          branchTargetFinder,
          codeAttributeEditor,
          extraInstructionVisitor    );
}
 
Example 2
public ConfigurationLoggingInstructionSequenceReplacer(Constant[]          patternConstants,
                                                       Instruction[]       patternInstructions,
                                                       Constant[]          replacementConstants,
                                                       Instruction[]       replacementInstructions,
                                                       BranchTargetFinder  branchTargetFinder,
                                                       CodeAttributeEditor codeAttributeEditor,
                                                       InstructionVisitor  extraInstructionVisitor )
{
    super(patternConstants,
          patternInstructions,
          replacementConstants,
          replacementInstructions,
          branchTargetFinder,
          codeAttributeEditor,
          extraInstructionVisitor );
}
 
Example 3
public void accept(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, InstructionVisitor instructionVisitor)
{
    if (instructionVisitor != CodeAttributeEditor.this)
    {
        throw new UnsupportedOperationException("Unexpected visitor ["+instructionVisitor+"]");
    }

    for (int index = 0; index < instructions.length; index++)
    {
        Instruction instruction = instructions[index];

        instruction.accept(clazz, method, codeAttribute, offset, CodeAttributeEditor.this);

        offset += instruction.length(offset);
    }
}
 
Example 4
/**
 * Creates an array of InstructionSequenceReplacer instances.
 * @param patternConstants        any constants referenced by the pattern
 *                                instruction.
 * @param instructionSequences    the instruction sequences to be replaced,
 *                                with subsequently the sequence pair index,
 *                                the from/to index (0 or 1), and the
 *                                instruction index in the sequence.
 * @param branchTargetFinder      a branch target finder that has been
 *                                initialized to indicate branch targets
 *                                in the visited code.
 * @param codeAttributeEditor     a code editor that can be used for
 *                                accumulating changes to the code.
 * @param extraInstructionVisitor an optional extra visitor for all deleted
 *                                load instructions.
 */
private static InstructionVisitor[] createInstructionSequenceReplacers(Constant[]          patternConstants,
                                                                       Instruction[][][]   instructionSequences,
                                                                       BranchTargetFinder  branchTargetFinder,
                                                                       CodeAttributeEditor codeAttributeEditor,
                                                                       InstructionVisitor extraInstructionVisitor)
{
    InstructionVisitor[] instructionSequenceReplacers =
        new InstructionSequenceReplacer[instructionSequences.length];

    for (int index = 0; index < instructionSequenceReplacers.length; index++)
    {
        Instruction[][] instructionSequencePair = instructionSequences[index];
        instructionSequenceReplacers[index] =
            new InstructionSequenceReplacer(patternConstants,
                                            instructionSequencePair[PATTERN_INDEX],
                                            instructionSequencePair[REPLACEMENT_INDEX],
                                            branchTargetFinder,
                                            codeAttributeEditor,
                                            extraInstructionVisitor);
    }

    return instructionSequenceReplacers;
}
 
Example 5
Source Project: proguard   Source File: CodeAttributeEditor.java    License: GNU General Public License v2.0 6 votes vote down vote up
public void accept(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, InstructionVisitor instructionVisitor)
{
    if (instructionVisitor != CodeAttributeEditor.this)
    {
        throw new UnsupportedOperationException("Unexpected visitor ["+instructionVisitor+"]");
    }

    for (int index = 0; index < instructions.length; index++)
    {
        Instruction instruction = instructions[index];

        instruction.accept(clazz, method, codeAttribute, offset, CodeAttributeEditor.this);

        offset += instruction.length(offset);
    }
}
 
Example 6
Source Project: proguard   Source File: JSR310Converter.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create a new JSR310Converter instance.
 */
public JSR310Converter(ClassPool          programClassPool,
                       ClassPool          libraryClassPool,
                       WarningPrinter     warningPrinter,
                       ClassVisitor       modifiedClassVisitor,
                       InstructionVisitor extraInstructionVisitor)
{
    super(programClassPool,
          libraryClassPool,
          warningPrinter,
          modifiedClassVisitor,
          extraInstructionVisitor);

    TypeReplacement[] typeReplacements = new TypeReplacement[]
    {
        // java.time package has been added in Java 8
        replace("java/time/**", "org/threeten/bp/<1>"),
    };

    MethodReplacement[] methodReplacements = new MethodReplacement[]
    {
        // all classes in java.time.** are converted to
        // org.threeeten.bp.**.
        replace("java/time/**",        "**",  "**",
                "org/threeten/bp/<1>", "<1>", "<1>"),
    };

    setTypeReplacements(typeReplacements);
    setMethodReplacements(methodReplacements);
}
 
Example 7
/**
 * Create a new AbstractAPIConverter instance.
 */
AbstractAPIConverter(ClassPool          programClassPool,
                     ClassPool          libraryClassPool,
                     WarningPrinter     warningPrinter,
                     ClassVisitor       modifiedClassVisitor,
                     InstructionVisitor extraInstructionVisitor)
{
    this.programClassPool        = programClassPool;
    this.libraryClassPool        = libraryClassPool;
    this.warningPrinter          = warningPrinter;
    this.modifiedClassVisitor    = modifiedClassVisitor;
    this.extraInstructionVisitor = extraInstructionVisitor;
}
 
Example 8
Source Project: java-n-IDE-for-Android   Source File: CodeAttribute.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Applies the given instruction visitor to all instructions in the
 * specified range of offsets.
 */
public void instructionsAccept(Clazz clazz, Method method, int startOffset, int endOffset, InstructionVisitor instructionVisitor)
{
    int offset = startOffset;

    while (offset < endOffset)
    {
        // Note that the instruction is only volatile.
        Instruction instruction = InstructionFactory.create(code, offset);
        int instructionLength = instruction.length(offset);
        instruction.accept(clazz, method, this, offset, instructionVisitor);
        offset += instructionLength;
    }
}
 
Example 9
/**
 * Creates a new InstructionSequenceReplacer.
 * @param patternConstants        any constants referenced by the pattern
 *                                instruction.
 * @param branchTargetFinder      a branch target finder that has been
 *                                initialized to indicate branch targets
 *                                in the visited code.
 * @param codeAttributeEditor     a code editor that can be used for
 *                                accumulating changes to the code.
 * @param extraInstructionVisitor an optional extra visitor for all deleted
 *                                load instructions.
 */
public InstructionSequenceReplacer(Constant[]          patternConstants,
                                   Instruction[]       patternInstructions,
                                   Instruction[]       replacementInstructions,
                                   BranchTargetFinder  branchTargetFinder,
                                   CodeAttributeEditor codeAttributeEditor,
                                   InstructionVisitor extraInstructionVisitor)
{
    this.instructionSequenceMatcher = new InstructionSequenceMatcher(patternConstants, patternInstructions);
    this.replacementInstructions    = replacementInstructions;
    this.branchTargetFinder         = branchTargetFinder;
    this.codeAttributeEditor        = codeAttributeEditor;
    this.extraInstructionVisitor    = extraInstructionVisitor;
}
 
Example 10
/**
 * Creates a new InstructionSequenceReplacer.
 * @param patternConstants        any constants referenced by the pattern
 *                                instruction.
 * @param branchTargetFinder      a branch target finder that has been
 *                                initialized to indicate branch targets
 *                                in the visited code.
 * @param codeAttributeEditor     a code editor that can be used for
 *                                accumulating changes to the code.
 * @param extraInstructionVisitor an optional extra visitor for all deleted
 *                                load instructions.
 */
public InstructionSequenceReplacer(Constant[]          patternConstants,
                                   Instruction[]       patternInstructions,
                                   Instruction[]       replacementInstructions,
                                   BranchTargetFinder  branchTargetFinder,
                                   CodeAttributeEditor codeAttributeEditor,
                                   InstructionVisitor  extraInstructionVisitor)
{
    this.instructionSequenceMatcher = new InstructionSequenceMatcher(patternConstants, patternInstructions);
    this.patternConstants           = patternConstants;
    this.replacementInstructions    = replacementInstructions;
    this.branchTargetFinder         = branchTargetFinder;
    this.codeAttributeEditor        = codeAttributeEditor;
    this.extraInstructionVisitor    = extraInstructionVisitor;
}
 
Example 11
Source Project: bazel   Source File: InstructionSequenceReplacer.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new InstructionSequenceReplacer.
 * @param patternConstants        any constants referenced by the pattern
 *                                instruction.
 * @param branchTargetFinder      a branch target finder that has been
 *                                initialized to indicate branch targets
 *                                in the visited code.
 * @param codeAttributeEditor     a code editor that can be used for
 *                                accumulating changes to the code.
 * @param extraInstructionVisitor an optional extra visitor for all deleted
 *                                load instructions.
 */
public InstructionSequenceReplacer(Constant[]          patternConstants,
                                   Instruction[]       patternInstructions,
                                   Instruction[]       replacementInstructions,
                                   BranchTargetFinder  branchTargetFinder,
                                   CodeAttributeEditor codeAttributeEditor,
                                   InstructionVisitor  extraInstructionVisitor)
{
    this.instructionSequenceMatcher = new InstructionSequenceMatcher(patternConstants, patternInstructions);
    this.patternConstants           = patternConstants;
    this.replacementInstructions    = replacementInstructions;
    this.branchTargetFinder         = branchTargetFinder;
    this.codeAttributeEditor        = codeAttributeEditor;
    this.extraInstructionVisitor    = extraInstructionVisitor;
}
 
Example 12
Source Project: bazel   Source File: CodeAttribute.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Applies the given instruction visitor to all instructions in the
 * specified range of offsets.
 */
public void instructionsAccept(Clazz clazz, Method method, int startOffset, int endOffset, InstructionVisitor instructionVisitor)
{
    int offset = startOffset;

    while (offset < endOffset)
    {
        // Note that the instruction is only volatile.
        Instruction instruction = InstructionFactory.create(code, offset);
        int instructionLength = instruction.length(offset);
        instruction.accept(clazz, method, this, offset, instructionVisitor);
        offset += instructionLength;
    }
}
 
Example 13
/**
 * Returns a filtering version of the given instruction visitor that only
 * visits traced instructions.
 */
public InstructionVisitor tracedInstructionFilter(InstructionVisitor instructionVisitor)
{
    return partialEvaluator.tracedInstructionFilter(instructionVisitor);
}
 
Example 14
/**
 * Returns a filtering version of the given instruction visitor that only
 * visits traced or untraced instructions.
 */
public InstructionVisitor tracedInstructionFilter(boolean            traced,
                                                  InstructionVisitor instructionVisitor)
{
    return partialEvaluator.tracedInstructionFilter(traced, instructionVisitor);
}
 
Example 15
/**
 * Returns a filtering version of the given instruction visitor that only
 * visits necessary instructions.
 */
public InstructionVisitor necessaryInstructionFilter(InstructionVisitor instructionVisitor)
{
    return necessaryInstructionFilter(true, instructionVisitor);
}
 
Example 16
/**
 * Returns a filtering version of the given instruction visitor that only
 * visits necessary or unnecessary instructions.
 */
public InstructionVisitor necessaryInstructionFilter(boolean            necessary,
                                                     InstructionVisitor instructionVisitor)
{
    return new MyNecessaryInstructionFilter(necessary, instructionVisitor);
}
 
Example 17
public MyNecessaryInstructionFilter(boolean            necessary,
                                    InstructionVisitor instructionVisitor)
{
    this.necessary          = necessary;
    this.instructionVisitor = instructionVisitor;
}
 
Example 18
Source Project: bazel   Source File: LookUpSwitchInstruction.java    License: Apache License 2.0 4 votes vote down vote up
public void accept(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, InstructionVisitor instructionVisitor)
{
    instructionVisitor.visitLookUpSwitchInstruction(clazz, method, codeAttribute, offset, this);
}
 
Example 19
Source Project: java-n-IDE-for-Android   Source File: CodeAttribute.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Applies the given instruction visitor to all instructions.
 */
public void instructionsAccept(Clazz clazz, Method method, InstructionVisitor instructionVisitor)
{
    instructionsAccept(clazz, method, 0, u4codeLength, instructionVisitor);
}
 
Example 20
Source Project: java-n-IDE-for-Android   Source File: CodeAttribute.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Applies the given instruction visitor to the instruction at the specified
 * offset.
 */
public void instructionAccept(Clazz clazz, Method method, int offset, InstructionVisitor instructionVisitor)
{
    Instruction instruction = InstructionFactory.create(code, offset);
    instruction.accept(clazz, method, this, offset, instructionVisitor);
}
 
Example 21
Source Project: java-n-IDE-for-Android   Source File: BranchInstruction.java    License: Apache License 2.0 4 votes vote down vote up
public void accept(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, InstructionVisitor instructionVisitor)
{
    instructionVisitor.visitBranchInstruction(clazz, method, codeAttribute, offset, this);
}
 
Example 22
public void accept(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, InstructionVisitor instructionVisitor)
{
    instructionVisitor.visitVariableInstruction(clazz, method, codeAttribute, offset, this);
}
 
Example 23
public void accept(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, InstructionVisitor instructionVisitor)
{
    instructionVisitor.visitConstantInstruction(clazz, method, codeAttribute, offset, this);
}
 
Example 24
public void accept(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, InstructionVisitor instructionVisitor)
{
    instructionVisitor.visitLookUpSwitchInstruction(clazz, method, codeAttribute, offset, this);
}
 
Example 25
public void accept(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, InstructionVisitor instructionVisitor)
{
    instructionVisitor.visitTableSwitchInstruction(clazz, method, codeAttribute, offset, this);
}
 
Example 26
Source Project: java-n-IDE-for-Android   Source File: SimpleInstruction.java    License: Apache License 2.0 4 votes vote down vote up
public void accept(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, InstructionVisitor instructionVisitor)
{
    instructionVisitor.visitSimpleInstruction(clazz, method, codeAttribute, offset, this);
}
 
Example 27
Source Project: proguard   Source File: CodeAttribute.java    License: GNU General Public License v2.0 4 votes vote down vote up
/**
 * Applies the given instruction visitor to all instructions.
 */
public void instructionsAccept(Clazz clazz, Method method, InstructionVisitor instructionVisitor)
{
    instructionsAccept(clazz, method, 0, u4codeLength, instructionVisitor);
}
 
Example 28
Source Project: proguard   Source File: CodeAttribute.java    License: GNU General Public License v2.0 4 votes vote down vote up
/**
 * Applies the given instruction visitor to the instruction at the specified
 * offset.
 */
public void instructionAccept(Clazz clazz, Method method, int offset, InstructionVisitor instructionVisitor)
{
    Instruction instruction = InstructionFactory.create(code, offset);
    instruction.accept(clazz, method, this, offset, instructionVisitor);
}
 
Example 29
Source Project: proguard   Source File: BranchInstruction.java    License: GNU General Public License v2.0 4 votes vote down vote up
public void accept(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, InstructionVisitor instructionVisitor)
{
    instructionVisitor.visitBranchInstruction(clazz, method, codeAttribute, offset, this);
}
 
Example 30
Source Project: proguard   Source File: VariableInstruction.java    License: GNU General Public License v2.0 4 votes vote down vote up
public void accept(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, InstructionVisitor instructionVisitor)
{
    instructionVisitor.visitVariableInstruction(clazz, method, codeAttribute, offset, this);
}