proguard.classfile.constant.MethodrefConstant Java Examples

The following examples show how to use proguard.classfile.constant.MethodrefConstant. 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
Source File: LibraryClassReader.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
private Constant createConstant()
{
    int u1tag = dataInput.readUnsignedByte();

    switch (u1tag)
    {
        case ClassConstants.CONSTANT_Utf8:               return new Utf8Constant();
        case ClassConstants.CONSTANT_Integer:            return new IntegerConstant();
        case ClassConstants.CONSTANT_Float:              return new FloatConstant();
        case ClassConstants.CONSTANT_Long:               return new LongConstant();
        case ClassConstants.CONSTANT_Double:             return new DoubleConstant();
        case ClassConstants.CONSTANT_String:             return new StringConstant();
        case ClassConstants.CONSTANT_Fieldref:           return new FieldrefConstant();
        case ClassConstants.CONSTANT_Methodref:          return new MethodrefConstant();
        case ClassConstants.CONSTANT_InterfaceMethodref: return new InterfaceMethodrefConstant();
        case ClassConstants.CONSTANT_Class:              return new ClassConstant();
        case ClassConstants.CONSTANT_NameAndType:        return new NameAndTypeConstant();

        default: throw new RuntimeException("Unknown constant type ["+u1tag+"] in constant pool");
    }
}
 
Example #2
Source File: ProgramClassReader.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
private Constant createConstant()
{
    int u1tag = dataInput.readUnsignedByte();

    switch (u1tag)
    {
        case ClassConstants.CONSTANT_Utf8:               return new Utf8Constant();
        case ClassConstants.CONSTANT_Integer:            return new IntegerConstant();
        case ClassConstants.CONSTANT_Float:              return new FloatConstant();
        case ClassConstants.CONSTANT_Long:               return new LongConstant();
        case ClassConstants.CONSTANT_Double:             return new DoubleConstant();
        case ClassConstants.CONSTANT_String:             return new StringConstant();
        case ClassConstants.CONSTANT_Fieldref:           return new FieldrefConstant();
        case ClassConstants.CONSTANT_Methodref:          return new MethodrefConstant();
        case ClassConstants.CONSTANT_InterfaceMethodref: return new InterfaceMethodrefConstant();
        case ClassConstants.CONSTANT_Class:              return new ClassConstant();
        case ClassConstants.CONSTANT_NameAndType:        return new NameAndTypeConstant();

        default: throw new RuntimeException("Unknown constant type ["+u1tag+"] in constant pool");
    }
}
 
Example #3
Source File: ClassDetailVisitor.java    From atlas with Apache License 2.0 5 votes vote down vote up
@Override
public void visitMethodrefConstant(Clazz clazz, MethodrefConstant methodrefConstant) {

    //println("visitMethodrefConstant Methodref [" +
    //            clazz.getClassName(methodrefConstant.u2classIndex) + "." +
    //            clazz.getName(methodrefConstant.u2nameAndTypeIndex) + " " +
    //            clazz.getType(methodrefConstant.u2nameAndTypeIndex) + "]");

    addMethod(clazz.getClassName(methodrefConstant.u2classIndex),
              clazz.getName(methodrefConstant.u2nameAndTypeIndex),
              clazz.getType(methodrefConstant.u2nameAndTypeIndex), false);

}
 
Example #4
Source File: ClassPrinter.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public void visitMethodrefConstant(Clazz clazz, MethodrefConstant methodrefConstant)
{
    println(visitorInfo(methodrefConstant) + " Methodref [" +
            clazz.getClassName(methodrefConstant.u2classIndex)  + "." +
            clazz.getName(methodrefConstant.u2nameAndTypeIndex) + " " +
            clazz.getType(methodrefConstant.u2nameAndTypeIndex) + "]");
}
 
Example #5
Source File: DynamicClassReferenceInitializer.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Checks whether the referenced method is a .class method.
 */
public void visitMethodrefConstant(Clazz clazz, MethodrefConstant methodrefConstant)
{
    String methodType = methodrefConstant.getType(clazz);

    // Do the method's class and type match?
    if (methodType.equals(ClassConstants.INTERNAL_METHOD_TYPE_DOT_CLASS_JAVAC) ||
        methodType.equals(ClassConstants.INTERNAL_METHOD_TYPE_DOT_CLASS_JIKES))
    {
        String methodName = methodrefConstant.getName(clazz);

        // Does the method's name match one of the special names?
        isClassForNameInvocation =
            methodName.equals(ClassConstants.INTERNAL_METHOD_NAME_DOT_CLASS_JAVAC) ||
            methodName.equals(ClassConstants.INTERNAL_METHOD_NAME_DOT_CLASS_JIKES);

        if (isClassForNameInvocation)
        {
            return;
        }

        String className = methodrefConstant.getClassName(clazz);

        // Note that we look for the class by name, since the referenced
        // class has not been initialized yet.
        Clazz referencedClass = programClassPool.getClass(className);
        if (referencedClass != null)
        {
            // Check if the code of the referenced method is .class code.
            // Note that we look for the method by name and type, since the
            // referenced method has not been initialized yet.
            referencedClass.methodAccept(methodName,
                                         methodType,
                                         new AllAttributeVisitor(this));
        }
    }
}
 
Example #6
Source File: ConstantAdder.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
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 #7
Source File: ConstantPoolRemapper.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public void visitMethodrefConstant(Clazz clazz, MethodrefConstant methodrefConstant)
{
    methodrefConstant.u2classIndex =
        remapConstantIndex(methodrefConstant.u2classIndex);
    methodrefConstant.u2nameAndTypeIndex =
        remapConstantIndex(methodrefConstant.u2nameAndTypeIndex);
}
 
Example #8
Source File: ConstantPoolEditor.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Finds or creates a MethodrefConstant constant pool entry with the given
 * class constant pool entry index and name and type constant pool entry
 * index.
 * @return the constant pool index of the MethodrefConstant.
 */
public int addMethodrefConstant(int    classIndex,
                                int    nameAndTypeIndex,
                                Clazz  referencedClass,
                                Member referencedMember)
{
    int        constantPoolCount = targetClass.u2constantPoolCount;
    Constant[] constantPool      = targetClass.constantPool;

    // Check if the entry already exists.
    for (int index = 1; index < constantPoolCount; index++)
    {
        Constant constant = constantPool[index];

        if (constant != null &&
            constant.getTag() == ClassConstants.CONSTANT_Methodref)
        {
            MethodrefConstant methodrefConstant = (MethodrefConstant)constant;
            if (methodrefConstant.u2classIndex       == classIndex &&
                methodrefConstant.u2nameAndTypeIndex == nameAndTypeIndex)
            {
                return index;
            }
        }
    }

    return addConstant(new MethodrefConstant(classIndex,
                                             nameAndTypeIndex,
                                             referencedClass,
                                             referencedMember));
}
 
Example #9
Source File: WrapperClassUseSimplifier.java    From proguard with GNU General Public License v2.0 5 votes vote down vote up
public void visitMethodrefConstant(Clazz clazz, MethodrefConstant methodrefConstant)
{
    if (methodrefConstant.getName(clazz).equals(ClassConstants.METHOD_NAME_INIT))
    {
        // Is the constant referring to a wrapper class?
        methodrefConstant.referencedClassAccept(this);
    }
}
 
Example #10
Source File: MemberReferenceFixer.java    From java-n-IDE-for-Android with Apache License 2.0 4 votes vote down vote up
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 #11
Source File: AbstractClasslVisitor.java    From atlas with Apache License 2.0 4 votes vote down vote up
@Override
public void visitMethodrefConstant(Clazz clazz, MethodrefConstant methodrefConstant) {
}
 
Example #12
Source File: MethodInliner.java    From java-n-IDE-for-Android with Apache License 2.0 4 votes vote down vote up
public void visitMethodrefConstant(Clazz clazz, MethodrefConstant methodrefConstant)
{
    methodrefConstant.referencedMemberAccept(this);
}
 
Example #13
Source File: BranchTargetFinder.java    From java-n-IDE-for-Android with Apache License 2.0 4 votes vote down vote up
public void visitMethodrefConstant(Clazz clazz, MethodrefConstant methodrefConstant)
{
    isInitializer = methodrefConstant.getName(clazz).equals(ClassConstants.INTERNAL_METHOD_NAME_INIT);
}
 
Example #14
Source File: DuplicateInitializerInvocationFixer.java    From java-n-IDE-for-Android with Apache License 2.0 4 votes vote down vote up
public void visitMethodrefConstant(Clazz clazz, MethodrefConstant methodrefConstant)
{
    // Check the referenced constructor descriptor.
    descriptor = methodrefConstant.getType(clazz);
    methodrefConstant.referencedMemberAccept(this);
}
 
Example #15
Source File: TailRecursionSimplifier.java    From java-n-IDE-for-Android with Apache License 2.0 4 votes vote down vote up
public void visitMethodrefConstant(Clazz clazz, MethodrefConstant methodrefConstant)
{
    recursive = targetMethod.equals(methodrefConstant.referencedMember);
}
 
Example #16
Source File: MemberReferenceFixer.java    From java-n-IDE-for-Android with Apache License 2.0 4 votes vote down vote up
public void visitMethodrefConstant(Clazz clazz, MethodrefConstant methodrefConstant)
{
    // Do we know the referenced method?
    Member referencedMember = methodrefConstant.referencedMember;
    if (referencedMember != null)
    {
        Clazz referencedClass = methodrefConstant.referencedClass;

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

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

            // Update the name and type index.
            methodrefConstant.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 = false;
        clazz.constantPoolEntryAccept(methodrefConstant.u2classIndex, this);

        // Has the method become an 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     = "+methodrefConstant.getName(clazz)+methodrefConstant.getType(clazz));
                System.out.println("    -> interface method");
            }

            // Replace the method reference by an interface method reference.
            ((ProgramClass)clazz).constantPool[this.constantIndex] =
                new InterfaceMethodrefConstant(methodrefConstant.u2classIndex,
                                               methodrefConstant.u2nameAndTypeIndex,
                                               referencedClass,
                                               referencedMember);
        }
    }
}
 
Example #17
Source File: SimplifiedVisitor.java    From java-n-IDE-for-Android with Apache License 2.0 4 votes vote down vote up
public void visitMethodrefConstant(Clazz clazz, MethodrefConstant methodrefConstant)
{
    visitAnyMethodrefConstant(clazz, methodrefConstant);
}
 
Example #18
Source File: ConstantInstruction.java    From java-n-IDE-for-Android with Apache License 2.0 4 votes vote down vote up
public void visitMethodrefConstant(Clazz clazz, MethodrefConstant methodrefConstant)
{
    visitRefConstant(clazz, methodrefConstant);
}
 
Example #19
Source File: ConstantVisitor.java    From java-n-IDE-for-Android with Apache License 2.0 votes vote down vote up
public void visitMethodrefConstant(Clazz clazz, MethodrefConstant methodrefConstant);