Java Code Examples for proguard.classfile.ClassConstants#CONSTANT_Long

The following examples show how to use proguard.classfile.ClassConstants#CONSTANT_Long . 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: ConstantPoolEditor.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
/**
 * Finds or creates a LongConstant constant pool entry with the given value.
 * @return the constant pool index of the LongConstant.
 */
public int addLongConstant(long value)
{
    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_Long)
        {
            LongConstant longConstant = (LongConstant)constant;
            if (longConstant.getValue() == value)
            {
                return index;
            }
        }
    }

    return addConstant(new LongConstant(value));
}
 
Example 2
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 3
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 4
Source File: ConstantPoolEditor.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Adds a given constant pool entry to the end of the constant pool/
 * @return the constant pool index for the added entry.
 */
public int addConstant(Constant constant)
{
    int        constantPoolCount = targetClass.u2constantPoolCount;
    Constant[] constantPool      = targetClass.constantPool;

    // Make sure there is enough space for another constant pool entry.
    if (constantPool.length < constantPoolCount+2)
    {
        targetClass.constantPool = new Constant[constantPoolCount+2];
        System.arraycopy(constantPool, 0,
                         targetClass.constantPool, 0,
                         constantPoolCount);
        constantPool = targetClass.constantPool;
    }

    if (DEBUG)
    {
        System.out.println(targetClass.getName()+": adding ["+constant.getClass().getName()+"] at index "+targetClass.u2constantPoolCount);
    }

    // Create a new Utf8Constant for the given string.
    constantPool[targetClass.u2constantPoolCount++] = constant;

    // Long constants and double constants take up two entries in the
    // constant pool.
    int tag = constant.getTag();
    if (tag == ClassConstants.CONSTANT_Long ||
        tag == ClassConstants.CONSTANT_Double)
    {
        constantPool[targetClass.u2constantPoolCount++] = null;
    }

    return constantPoolCount;
}
 
Example 5
Source File: LongConstant.java    From java-n-IDE-for-Android with Apache License 2.0 4 votes vote down vote up
public int getTag()
{
    return ClassConstants.CONSTANT_Long;
}
 
Example 6
Source File: ProgramClassReader.java    From java-n-IDE-for-Android with Apache License 2.0 4 votes vote down vote up
public void visitProgramClass(ProgramClass programClass)
{
    // Read and check the magic number.
    programClass.u4magic = dataInput.readInt();

    ClassUtil.checkMagicNumber(programClass.u4magic);

    // Read and check the version numbers.
    int u2minorVersion = dataInput.readUnsignedShort();
    int u2majorVersion = dataInput.readUnsignedShort();

    programClass.u4version = ClassUtil.internalClassVersion(u2majorVersion,
                                                            u2minorVersion);

    ClassUtil.checkVersionNumbers(programClass.u4version);

    // Read the constant pool. Note that the first entry is not used.
    programClass.u2constantPoolCount = dataInput.readUnsignedShort();

    programClass.constantPool = new Constant[programClass.u2constantPoolCount];
    for (int index = 1; index < programClass.u2constantPoolCount; index++)
    {
        Constant constant = createConstant();
        constant.accept(programClass, this);
        programClass.constantPool[index] = constant;

        // Long constants and double constants take up two entries in the
        // constant pool.
        int tag = constant.getTag();
        if (tag == ClassConstants.CONSTANT_Long ||
            tag == ClassConstants.CONSTANT_Double)
        {
            programClass.constantPool[++index] = null;
        }
    }

    // Read the general class information.
    programClass.u2accessFlags = dataInput.readUnsignedShort();
    programClass.u2thisClass   = dataInput.readUnsignedShort();
    programClass.u2superClass  = dataInput.readUnsignedShort();

    // Read the interfaces.
    programClass.u2interfacesCount = dataInput.readUnsignedShort();

    programClass.u2interfaces = new int[programClass.u2interfacesCount];
    for (int index = 0; index < programClass.u2interfacesCount; index++)
    {
        programClass.u2interfaces[index] = dataInput.readUnsignedShort();
    }

    // Read the fields.
    programClass.u2fieldsCount = dataInput.readUnsignedShort();

    programClass.fields = new ProgramField[programClass.u2fieldsCount];
    for (int index = 0; index < programClass.u2fieldsCount; index++)
    {
        ProgramField programField = new ProgramField();
        this.visitProgramField(programClass, programField);
        programClass.fields[index] = programField;
    }

    // Read the methods.
    programClass.u2methodsCount = dataInput.readUnsignedShort();

    programClass.methods = new ProgramMethod[programClass.u2methodsCount];
    for (int index = 0; index < programClass.u2methodsCount; index++)
    {
        ProgramMethod programMethod = new ProgramMethod();
        this.visitProgramMethod(programClass, programMethod);
        programClass.methods[index] = programMethod;
    }

    // Read the class attributes.
    programClass.u2attributesCount = dataInput.readUnsignedShort();

    programClass.attributes = new Attribute[programClass.u2attributesCount];
    for (int index = 0; index < programClass.u2attributesCount; index++)
    {
        Attribute attribute = createAttribute(programClass);
        attribute.accept(programClass, this);
        programClass.attributes[index] = attribute;
    }
}