Java Code Examples for proguard.classfile.attribute.Attribute#accept()

The following examples show how to use proguard.classfile.attribute.Attribute#accept() . 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: ProgramClassReader.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
public void visitProgramField(ProgramClass programClass, ProgramField programField)
{
    // Read the general field information.
    programField.u2accessFlags     = dataInput.readUnsignedShort();
    programField.u2nameIndex       = dataInput.readUnsignedShort();
    programField.u2descriptorIndex = dataInput.readUnsignedShort();

    // Read the field attributes.
    programField.u2attributesCount = dataInput.readUnsignedShort();

    programField.attributes = new Attribute[programField.u2attributesCount];
    for (int index = 0; index < programField.u2attributesCount; index++)
    {
        Attribute attribute = createAttribute(programClass);
        attribute.accept(programClass, programField, this);
        programField.attributes[index] = attribute;
    }
}
 
Example 2
Source File: ProgramClassReader.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
public void visitProgramMethod(ProgramClass programClass, ProgramMethod programMethod)
{
    // Read the general method information.
    programMethod.u2accessFlags     = dataInput.readUnsignedShort();
    programMethod.u2nameIndex       = dataInput.readUnsignedShort();
    programMethod.u2descriptorIndex = dataInput.readUnsignedShort();

    // Read the method attributes.
    programMethod.u2attributesCount = dataInput.readUnsignedShort();

    programMethod.attributes = new Attribute[programMethod.u2attributesCount];
    for (int index = 0; index < programMethod.u2attributesCount; index++)
    {
        Attribute attribute = createAttribute(programClass);
        attribute.accept(programClass, programMethod, this);
        programMethod.attributes[index] = attribute;
    }
}
 
Example 3
Source File: ProgramClassWriter.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public void visitAnyAttribute(Clazz clazz, Attribute attribute)
{
    // Write the attribute name index.
    dataOutput.writeShort(attribute.u2attributeNameIndex);

    // We'll write the attribute body into an array first, so we can
    // automatically figure out its length.
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();

    // Temporarily replace the current data output.
    RuntimeDataOutput oldDataOutput = dataOutput;
    dataOutput = new RuntimeDataOutput(new DataOutputStream(byteArrayOutputStream));

    // Write the attribute body into the array. Note that the
    // accept method with two dummy null arguments never throws
    // an UnsupportedOperationException.
    attribute.accept(clazz, null, null, attributeBodyWriter);

    // Restore the original data output.
    dataOutput = oldDataOutput;

    // Write the attribute length and body.
    byte[] info = byteArrayOutputStream.toByteArray();

    dataOutput.writeInt(info.length);
    dataOutput.write(info);
}
 
Example 4
Source File: ProgramClassReader.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public void visitCodeAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute)
{
    // Read the stack size and local variable frame size.
    codeAttribute.u2maxStack   = dataInput.readUnsignedShort();
    codeAttribute.u2maxLocals  = dataInput.readUnsignedShort();

    // Read the byte code.
    codeAttribute.u4codeLength = dataInput.readInt();

    byte[] code = new byte[codeAttribute.u4codeLength];
    dataInput.readFully(code);
    codeAttribute.code = code;

    // Read the exceptions.
    codeAttribute.u2exceptionTableLength = dataInput.readUnsignedShort();

    codeAttribute.exceptionTable = new ExceptionInfo[codeAttribute.u2exceptionTableLength];
    for (int index = 0; index < codeAttribute.u2exceptionTableLength; index++)
    {
        ExceptionInfo exceptionInfo = new ExceptionInfo();
        this.visitExceptionInfo(clazz, method, codeAttribute, exceptionInfo);
        codeAttribute.exceptionTable[index] = exceptionInfo;
    }

    // Read the code attributes.
    codeAttribute.u2attributesCount = dataInput.readUnsignedShort();

    codeAttribute.attributes = new Attribute[codeAttribute.u2attributesCount];
    for (int index = 0; index < codeAttribute.u2attributesCount; index++)
    {
        Attribute attribute = createAttribute(clazz);
        attribute.accept(clazz, method, codeAttribute, this);
        codeAttribute.attributes[index] = attribute;
    }
}
 
Example 5
Source File: RetargetedInnerClassAttributeRemover.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public void visitProgramClass(ProgramClass programClass)
{
    int         attributesCount = programClass.u2attributesCount;
    Attribute[] attributes      = programClass.attributes;

    int newAtributesCount = 0;

    // Copy over all non-retargeted attributes.
    for (int index = 0; index < attributesCount; index++)
    {
        Attribute attribute = attributes[index];

        // Check if it's an InnerClasses or EnclosingMethod attribute in
        // a retargeted class or referring to a retargeted class.
        retargeted = false;
        attribute.accept(programClass, this);
        if (!retargeted)
        {
            attributes[newAtributesCount++] = attribute;
        }
    }

    // Clean up any remaining array elements.
    for (int index = newAtributesCount; index < attributesCount; index++)
    {
        attributes[index] = null;
    }

    // Update the number of attribuets.
    programClass.u2attributesCount = newAtributesCount;
}
 
Example 6
Source File: ProgramClass.java    From proguard with GNU General Public License v2.0 5 votes vote down vote up
public void attributeAccept(String name, AttributeVisitor attributeVisitor)
{
    for (int index = 0; index < u2attributesCount; index++)
    {
        Attribute attribute = attributes[index];
        if (attribute.getAttributeName(this).equals(name))
        {
            attribute.accept(this, attributeVisitor);
        }
    }
}
 
Example 7
Source File: ProgramClass.java    From bazel with Apache License 2.0 5 votes vote down vote up
public void attributeAccept(String name, AttributeVisitor attributeVisitor)
{
    for (int index = 0; index < u2attributesCount; index++)
    {
        Attribute attribute = attributes[index];
        if (attribute.getAttributeName(this).equals(name))
        {
            attribute.accept(this, attributeVisitor);
        }
    }
}
 
Example 8
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;
    }
}