Java Code Examples for proguard.classfile.ClassConstants#CONSTANT_NameAndType

The following examples show how to use proguard.classfile.ClassConstants#CONSTANT_NameAndType . 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 NameAndTypeConstant constant pool entry with the given
 * name and type.
 * @return the constant pool index of the NameAndTypeConstant.
 */
public int addNameAndTypeConstant(String name,
                                  String type)
{
    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_NameAndType)
        {
            NameAndTypeConstant nameAndTypeConstant = (NameAndTypeConstant)constant;
            if (nameAndTypeConstant.getName(targetClass).equals(name) &&
                nameAndTypeConstant.getType(targetClass).equals(type))
            {
                return index;
            }
        }
    }

    return addConstant(new NameAndTypeConstant(addUtf8Constant(name),
                                               addUtf8Constant(type)));
}
 
Example 4
Source File: NameAndTypeConstant.java    From java-n-IDE-for-Android with Apache License 2.0 4 votes vote down vote up
public int getTag()
{
    return ClassConstants.CONSTANT_NameAndType;
}
 
Example 5
Source File: NameAndTypeShrinker.java    From java-n-IDE-for-Android with Apache License 2.0 4 votes vote down vote up
/**
 * Removes all NameAndType entries that are not marked as being used
 * from the given constant pool.
 * @return the new number of entries.
 */
private int shrinkConstantPool(Constant[] constantPool, int length)
{
    // Create a new index map, if necessary.
    if (constantIndexMap == null ||
        constantIndexMap.length < length)
    {
        constantIndexMap = new int[length];
    }

    int     counter = 1;
    boolean isUsed  = false;

    // Shift the used constant pool entries together.
    for (int index = 1; index < length; index++)
    {
        constantIndexMap[index] = counter;

        Constant constant = constantPool[index];

        // Don't update the flag if this is the second half of a long entry.
        if (constant != null)
        {
            isUsed = constant.getTag() != ClassConstants.CONSTANT_NameAndType ||
                     NameAndTypeUsageMarker.isUsed(constant);
        }

        if (isUsed)
        {
            constantPool[counter++] = constant;
        }
    }

    // Clear the remaining constant pool elements.
    for (int index = counter; index < length; index++)
    {
        constantPool[index] = null;
    }

    return counter;
}