Java Code Examples for proguard.classfile.ClassConstants#CONSTANT_Fieldref

The following examples show how to use proguard.classfile.ClassConstants#CONSTANT_Fieldref . 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: ConstantPoolEditor.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Finds or creates a FieldrefConstant 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 FieldrefConstant.
 */
public int addFieldrefConstant(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_Fieldref)
        {
            FieldrefConstant fieldrefConstant = (FieldrefConstant)constant;
            if (fieldrefConstant.u2classIndex         == classIndex &&
                fieldrefConstant.u2nameAndTypeIndex   == nameAndTypeIndex)
            {
                return index;
            }
        }
    }

    return addConstant(new FieldrefConstant(classIndex,
                                            nameAndTypeIndex,
                                            referencedClass,
                                            referencedMember));
}
 
Example 4
Source File: FieldrefConstant.java    From java-n-IDE-for-Android with Apache License 2.0 4 votes vote down vote up
public int getTag()
{
    return ClassConstants.CONSTANT_Fieldref;
}
 
Example 5
Source File: ClassReferenceInitializer.java    From java-n-IDE-for-Android with Apache License 2.0 4 votes vote down vote up
public void visitAnyRefConstant(Clazz clazz, RefConstant refConstant)
{
    String className = refConstant.getClassName(clazz);

    // Methods for array types should be found in the Object class.
    if (ClassUtil.isInternalArrayType(className))
    {
        className = ClassConstants.INTERNAL_NAME_JAVA_LANG_OBJECT;
    }

    // See if we can find the referenced class.
    // Unresolved references are assumed to refer to library classes
    // that will not change anyway.
    Clazz referencedClass = findClass(clazz.getName(), className);

    if (referencedClass != null)
    {
        String name = refConstant.getName(clazz);
        String type = refConstant.getType(clazz);

        boolean isFieldRef = refConstant.getTag() == ClassConstants.CONSTANT_Fieldref;

        // See if we can find the referenced class member somewhere in the
        // hierarchy.
        refConstant.referencedMember = memberFinder.findMember(clazz,
                                                               referencedClass,
                                                               name,
                                                               type,
                                                               isFieldRef);
        refConstant.referencedClass  = memberFinder.correspondingClass();

        if (refConstant.referencedMember == null)
        {
            // We haven't found the class member anywhere in the hierarchy.
            missingMemberWarningPrinter.print(clazz.getName(),
                                              className,
                                              "Warning: " +
                                              ClassUtil.externalClassName(clazz.getName()) +
                                              ": can't find referenced " +
                                              (isFieldRef ?
                                                  "field '"  + ClassUtil.externalFullFieldDescription(0, name, type) :
                                                  "method '" + ClassUtil.externalFullMethodDescription(className, 0, name, type)) +
                                              "' in class " +
                                              ClassUtil.externalClassName(className));
        }
    }
}