Java Code Examples for proguard.classfile.Clazz#constantPoolEntryAccept()

The following examples show how to use proguard.classfile.Clazz#constantPoolEntryAccept() . 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 void visitAnyMethodrefConstant(Clazz clazz, RefConstant refConstant)
{
    // Remember the referenced class. Note that we're interested in the
    // class of the method reference, not in the class in which the
    // method was actually found, unless it is an array type.
    //
    if (ClassUtil.isInternalArrayType(refConstant.getClassName(clazz)))
    {
        // For an array type, the class will be java.lang.Object.
        referencedClass = refConstant.referencedClass;
    }
    else
    {
        clazz.constantPoolEntryAccept(refConstant.u2classIndex, this);
    }

    // Remember the referenced method.
    referencedMethodClass = refConstant.referencedClass;
    referencedMethod      = refConstant.referencedMember;
}
 
Example 2
public void visitConstantInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, ConstantInstruction constantInstruction)
{
    byte opcode = constantInstruction.opcode;
    // Check for instructions that might cause side effects.
    if (opcode == InstructionConstants.OP_GETSTATIC     ||
        opcode == InstructionConstants.OP_PUTSTATIC     ||
        opcode == InstructionConstants.OP_GETFIELD      ||
        opcode == InstructionConstants.OP_PUTFIELD      ||
        opcode == InstructionConstants.OP_INVOKEVIRTUAL ||
        opcode == InstructionConstants.OP_INVOKESPECIAL ||
        opcode == InstructionConstants.OP_INVOKESTATIC  ||
        opcode == InstructionConstants.OP_INVOKEINTERFACE)
    {
        // Check if the field is write-only or volatile, or if the invoked
        // method is causing any side effects.
        clazz.constantPoolEntryAccept(constantInstruction.constantIndex, this);
    }
}
 
Example 3
public void visitInterfaceMethodrefConstant(Clazz clazz, InterfaceMethodrefConstant interfaceMethodrefConstant)
{
    // First add the referenced class constant, with its own referenced class.
    clazz.constantPoolEntryAccept(interfaceMethodrefConstant.u2classIndex, this);

    // Then add the actual interface method reference constant, with its
    // referenced class and class member.
    constantIndex =
        constantPoolEditor.addInterfaceMethodrefConstant(constantIndex,
                                                         interfaceMethodrefConstant.getName(clazz),
                                                         interfaceMethodrefConstant.getType(clazz),
                                                         interfaceMethodrefConstant.referencedClass,
                                                         interfaceMethodrefConstant.referencedMember);
}
 
Example 4
public void visitConstantInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, ConstantInstruction constantInstruction)
{
    // Mark the instruction.
    instructionMarks[offset] |= INSTRUCTION;

    // Check if this is the first instruction of a subroutine.
    checkSubroutine(offset);

    // Check if the instruction is a 'new' instruction.
    if (constantInstruction.opcode == InstructionConstants.OP_NEW)
    {
        // Push the 'new' instruction offset on the stack.
        recentCreationOffsets[recentCreationOffsetIndex++] = offset;
    }
    else
    {
        // Check if the instruction is an initializer invocation.
        isInitializer = false;
        clazz.constantPoolEntryAccept(constantInstruction.constantIndex, this);
        if (isInitializer)
        {
            // Pop the 'new' instruction offset from the stack.
            int recentCreationOffset = recentCreationOffsets[--recentCreationOffsetIndex];

            // Fill it out in the creation offsets.
            creationOffsets[offset] = recentCreationOffset;

            // Fill out the initialization offsets.
            if (recentCreationOffset == AT_METHOD_ENTRY)
            {
                superInitializationOffset = offset;
            }
            else
            {
                initializationOffsets[recentCreationOffset] = offset;
            }
        }
    }
}
 
Example 5
/**
 * Applies the given constant pool visitor to the class constant of the
 * inner class, if any.
 */
public void innerClassConstantAccept(Clazz clazz, ConstantVisitor constantVisitor)
{
    if (u2innerClassIndex != 0)
    {
        clazz.constantPoolEntryAccept(u2innerClassIndex,
                                             constantVisitor);
    }
}
 
Example 6
public void visitConstantInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, ConstantInstruction constantInstruction)
{
    if (constantInstruction.opcode == InstructionConstants.OP_INVOKESPECIAL)
    {
        invokesSuperMethods = false;

        clazz.constantPoolEntryAccept(constantInstruction.constantIndex, this);

        if (invokesSuperMethods)
        {
            setInvokesSuperMethods(method);
        }
    }
}
 
Example 7
/**
 * Applies the given constant pool visitor to the Utf8 constant of the
 * inner name, if any.
 */
public void innerNameConstantAccept(Clazz clazz, ConstantVisitor constantVisitor)
{
    if (u2innerNameIndex != 0)
    {
        clazz.constantPoolEntryAccept(u2innerNameIndex,
                                             constantVisitor);
    }
}
 
Example 8
public void visitSourceFileAttribute(Clazz clazz, SourceFileAttribute sourceFileAttribute)
{
    println(visitorInfo(sourceFileAttribute) +
            " Source file attribute:");

    indent();
    clazz.constantPoolEntryAccept(sourceFileAttribute.u2sourceFileIndex, this);
    outdent();
}
 
Example 9
public void visitMethodrefConstant(Clazz clazz, MethodrefConstant methodrefConstant)
{
    // First add the referenced class constant, with its own referenced class.
    clazz.constantPoolEntryAccept(methodrefConstant.u2classIndex, this);

    // Then add the actual method reference constant, with its referenced
    // class and class member.
    constantIndex =
        constantPoolEditor.addMethodrefConstant(constantIndex,
                                                methodrefConstant.getName(clazz),
                                                methodrefConstant.getType(clazz),
                                                methodrefConstant.referencedClass,
                                                methodrefConstant.referencedMember);
}
 
Example 10
public void visitConstantInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, ConstantInstruction constantInstruction)
{
    switch (constantInstruction.opcode)
    {
        case InstructionConstants.OP_INVOKEVIRTUAL:
        case InstructionConstants.OP_INVOKESPECIAL:
        case InstructionConstants.OP_INVOKESTATIC:
        case InstructionConstants.OP_INVOKEINTERFACE:
            this.invocationOffset      = offset;
            this.invocationInstruction = constantInstruction;
            clazz.constantPoolEntryAccept(constantInstruction.constantIndex, this);
            break;
    }
}
 
Example 11
public void visitConstantInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, ConstantInstruction constantInstruction)
{
    if (constantInstruction.opcode == InstructionConstants.OP_LDC ||
        constantInstruction.opcode == InstructionConstants.OP_LDC_W)
    {
        clazz.constantPoolEntryAccept(constantInstruction.constantIndex, this);
    }
}
 
Example 12
private boolean matchingConstantIndices(Clazz clazz,
                                        int   constantIndex1,
                                        int   constantIndex2)
{
    if (constantIndex2 >= X)
    {
        // Check the constant index.
        return matchingArguments(constantIndex1, constantIndex2);
    }
    else if ((matchedConstantFlags & (1L << constantIndex2)) == 0)
    {
        // Check the actual constant.
        matchingConstant = false;
        patternConstant  = patternConstants[constantIndex2];

        if (clazz.getTag(constantIndex1) == patternConstant.getTag())
        {
            clazz.constantPoolEntryAccept(constantIndex1, this);

            if (matchingConstant)
            {
                // Store the constant index.
                matchedConstantIndices[constantIndex2] = constantIndex1;
                matchedConstantFlags |= 1L << constantIndex2;
            }
        }

        return matchingConstant;
    }
    else
    {
        // Check a previously stored constant index.
        return matchedConstantIndices[constantIndex2] == constantIndex1;
    }
}
 
Example 13
public void visitAnyRefConstant(Clazz clazz, RefConstant refConstant)
{
    // Check the referenced class.
    clazz.constantPoolEntryAccept(refConstant.u2classIndex, this);

    // Check the referenced class member itself.
    refConstant.referencedClassAccept(this);
    refConstant.referencedMemberAccept(this);
}
 
Example 14
public void visitConstantInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, ConstantInstruction constantInstruction)
{
    byte opcode = constantInstruction.opcode;

    // Could this instruction be a .class construct?
    if (opcode == InstructionConstants.OP_LDC ||
        opcode == InstructionConstants.OP_LDC_W)
    {
        clazz.constantPoolEntryAccept(constantInstruction.constantIndex,
                                      this);
    }
}
 
Example 15
public void invokeMember(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, ConstantInstruction constantInstruction, Stack stack)
{
    int constantIndex = constantInstruction.constantIndex;

    switch (constantInstruction.opcode)
    {
        case InstructionConstants.OP_GETSTATIC:
            isStatic = true;
            isLoad   = true;
            break;

        case InstructionConstants.OP_PUTSTATIC:
            isStatic = true;
            isLoad   = false;
            break;

        case InstructionConstants.OP_GETFIELD:
            isStatic = false;
            isLoad   = true;
            break;

        case InstructionConstants.OP_PUTFIELD:
            isStatic = false;
            isLoad   = false;
            break;

        case InstructionConstants.OP_INVOKESTATIC:
            isStatic = true;
            break;

        case InstructionConstants.OP_INVOKEVIRTUAL:
        case InstructionConstants.OP_INVOKESPECIAL:
        case InstructionConstants.OP_INVOKEINTERFACE:
            isStatic = false;
            break;
    }

    // Pop the parameters and push the return value.
    this.stack = stack;
    clazz.constantPoolEntryAccept(constantIndex, this);
    this.stack = null;
}
 
Example 16
public void visitInterfaceMethodrefConstant(Clazz clazz, InterfaceMethodrefConstant interfaceMethodrefConstant)
{
    // Do we know the referenced interface method?
    Member referencedMember = interfaceMethodrefConstant.referencedMember;
    if (referencedMember != null)
    {
        Clazz referencedClass = interfaceMethodrefConstant.referencedClass;

        // Does it have a new name or type?
        String newName = referencedMember.getName(referencedClass);
        String newType = referencedMember.getDescriptor(referencedClass);

        if (!interfaceMethodrefConstant.getName(clazz).equals(newName) ||
            !interfaceMethodrefConstant.getType(clazz).equals(newType))
        {
            if (DEBUG)
            {
                debug(clazz, interfaceMethodrefConstant, referencedClass, referencedMember);
            }

            // Update the name and type index.
            interfaceMethodrefConstant.u2nameAndTypeIndex =
                new ConstantPoolEditor((ProgramClass)clazz).addNameAndTypeConstant(newName, newType);

            // Remember that the stack sizes of the methods in this class
            // may have changed.
            stackSizesMayHaveChanged = true;
        }

        // Check if this is an interface method.
        isInterfaceMethod = true;
        clazz.constantPoolEntryAccept(interfaceMethodrefConstant.u2classIndex, this);

        // Has the method become a non-interface method?
        if (!isInterfaceMethod)
        {
            if (DEBUG)
            {
                System.out.println("MemberReferenceFixer:");
                System.out.println("  Class file     = "+clazz.getName());
                System.out.println("  Ref class      = "+referencedClass.getName());
                System.out.println("  Ref method     = "+interfaceMethodrefConstant.getName(clazz)+interfaceMethodrefConstant.getType(clazz));
                System.out.println("    -> ordinary method");
            }

            // Replace the interface method reference by a method reference.
            ((ProgramClass)clazz).constantPool[this.constantIndex] =
                new MethodrefConstant(interfaceMethodrefConstant.u2classIndex,
                                      interfaceMethodrefConstant.u2nameAndTypeIndex,
                                      referencedClass,
                                      referencedMember);
        }
    }
}
 
Example 17
/**
 * Marks the given constant pool entry of the given class. This includes
 * visiting any other referenced constant pool entries.
 */
private void markConstant(Clazz clazz, int index)
{
     clazz.constantPoolEntryAccept(index, this);
}
 
Example 18
Source Project: bazel   File: MethodrefTraveler.java    License: Apache License 2.0 4 votes vote down vote up
public void visitMethodHandleConstant(Clazz clazz, MethodHandleConstant methodHandleConstant)
{
    clazz.constantPoolEntryAccept(methodHandleConstant.u2referenceIndex,
                                  methodrefConstantVisitor);
}
 
Example 19
public void visitConstantInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, ConstantInstruction constantInstruction)
{
    invokingMethod = method;

    clazz.constantPoolEntryAccept(constantInstruction.constantIndex, this);
}
 
Example 20
public void visitBootstrapMethodInfo(Clazz clazz, BootstrapMethodInfo bootstrapMethodInfo)
{
    // Check bootstrap method.
    clazz.constantPoolEntryAccept(bootstrapMethodInfo.u2methodHandleIndex,
                                  bootstrapMethodHandleVisitor);
}