Java Code Examples for proguard.classfile.Clazz#getString()

The following examples show how to use proguard.classfile.Clazz#getString() . 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: MethodDescriptorShrinker.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
public void visitSignatureAttribute(Clazz clazz, Method method, SignatureAttribute signatureAttribute)
{
    // Compute the new signature.
    String signature    = clazz.getString(signatureAttribute.u2signatureIndex);
    String newSignature = shrinkDescriptor(method, signature);

    // Update the signature.
    signatureAttribute.u2signatureIndex =
        new ConstantPoolEditor((ProgramClass)clazz).addUtf8Constant(newSignature);

    // Update the referenced classes.
    signatureAttribute.referencedClasses =
        shrinkReferencedClasses(method,
                                signature,
                                signatureAttribute.referencedClasses);
}
 
Example 2
Source File: ClassReferenceFixer.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
public void visitAnnotation(Clazz clazz, Annotation annotation)
{
    // Compute the new type name.
    String typeName    = clazz.getString(annotation.u2typeIndex);
    String newTypeName = newDescriptor(typeName,
                                       annotation.referencedClasses);

    if (!typeName.equals(newTypeName))
    {
        // Refer to a new Utf8 entry.
        annotation.u2typeIndex =
            new ConstantPoolEditor((ProgramClass)clazz).addUtf8Constant(newTypeName);
    }

    // Fix the element values.
    annotation.elementValuesAccept(clazz, this);
}
 
Example 3
Source File: ClassReferenceInitializer.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
/**
 * Initializes the referenced method of an element value, if any.
 */
private void initializeElementValue(Clazz clazz, Annotation annotation, ElementValue elementValue)
{
    // See if we have a referenced class.
    if (annotation                      != null &&
        annotation.referencedClasses    != null &&
        elementValue.u2elementNameIndex != 0)
    {
        // See if we can find the method in the referenced class
        // (ignoring the descriptor).
        String name = clazz.getString(elementValue.u2elementNameIndex);

        Clazz referencedClass = annotation.referencedClasses[0];
        elementValue.referencedClass  = referencedClass;
        elementValue.referencedMethod = referencedClass.findMethod(name, null);
    }
}
 
Example 4
Source File: ClassReferenceFixer.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public void visitSignatureAttribute(Clazz clazz, SignatureAttribute signatureAttribute)
{
    // Compute the new signature.
    String signature    = clazz.getString(signatureAttribute.u2signatureIndex);
    String newSignature = newDescriptor(signature,
                                        signatureAttribute.referencedClasses);

    if (!signature.equals(newSignature))
    {
        signatureAttribute.u2signatureIndex =
            new ConstantPoolEditor((ProgramClass)clazz).addUtf8Constant(newSignature);
    }
}
 
Example 5
Source File: DuplicateInitializerFixer.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public void visitSignatureAttribute(Clazz clazz, Method method, SignatureAttribute signatureAttribute)
{
    String descriptor      = method.getDescriptor(clazz);
    int    descriptorIndex = descriptor.indexOf(ClassConstants.INTERNAL_METHOD_ARGUMENTS_CLOSE);
    String signature       = clazz.getString(signatureAttribute.u2signatureIndex);
    int    signatureIndex  = signature.indexOf(ClassConstants.INTERNAL_METHOD_ARGUMENTS_CLOSE);

    String newSignature = signature.substring(0, signatureIndex) +
                          descriptor.charAt(descriptorIndex - 1) +
                          signature.substring(signatureIndex);

    // Update the signature.
    signatureAttribute.u2signatureIndex =
        new ConstantPoolEditor((ProgramClass)clazz).addUtf8Constant(newSignature);
}
 
Example 6
Source File: ProgramClassReader.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
private Attribute createAttribute(Clazz clazz)
{
    int u2attributeNameIndex = dataInput.readUnsignedShort();
    int u4attributeLength    = dataInput.readInt();
    String attributeName     = clazz.getString(u2attributeNameIndex);
    Attribute attribute =
        attributeName.equals(ClassConstants.ATTR_SourceFile)                           ? (Attribute)new SourceFileAttribute():
        attributeName.equals(ClassConstants.ATTR_SourceDir)                            ? (Attribute)new SourceDirAttribute():
        attributeName.equals(ClassConstants.ATTR_InnerClasses)                         ? (Attribute)new InnerClassesAttribute():
        attributeName.equals(ClassConstants.ATTR_EnclosingMethod)                      ? (Attribute)new EnclosingMethodAttribute():
        attributeName.equals(ClassConstants.ATTR_Deprecated)                           ? (Attribute)new DeprecatedAttribute():
        attributeName.equals(ClassConstants.ATTR_Synthetic)                            ? (Attribute)new SyntheticAttribute():
        attributeName.equals(ClassConstants.ATTR_Signature)                            ? (Attribute)new SignatureAttribute():
        attributeName.equals(ClassConstants.ATTR_ConstantValue)                        ? (Attribute)new ConstantValueAttribute():
        attributeName.equals(ClassConstants.ATTR_Exceptions)                           ? (Attribute)new ExceptionsAttribute():
        attributeName.equals(ClassConstants.ATTR_Code)                                 ? (Attribute)new CodeAttribute():
        attributeName.equals(ClassConstants.ATTR_StackMap)                             ? (Attribute)new StackMapAttribute():
        attributeName.equals(ClassConstants.ATTR_StackMapTable)                        ? (Attribute)new StackMapTableAttribute():
        attributeName.equals(ClassConstants.ATTR_LineNumberTable)                      ? (Attribute)new LineNumberTableAttribute():
        attributeName.equals(ClassConstants.ATTR_LocalVariableTable)                   ? (Attribute)new LocalVariableTableAttribute():
        attributeName.equals(ClassConstants.ATTR_LocalVariableTypeTable)               ? (Attribute)new LocalVariableTypeTableAttribute():
        attributeName.equals(ClassConstants.ATTR_RuntimeVisibleAnnotations)            ? (Attribute)new RuntimeVisibleAnnotationsAttribute():
        attributeName.equals(ClassConstants.ATTR_RuntimeInvisibleAnnotations)          ? (Attribute)new RuntimeInvisibleAnnotationsAttribute():
        attributeName.equals(ClassConstants.ATTR_RuntimeVisibleParameterAnnotations)   ? (Attribute)new RuntimeVisibleParameterAnnotationsAttribute():
        attributeName.equals(ClassConstants.ATTR_RuntimeInvisibleParameterAnnotations) ? (Attribute)new RuntimeInvisibleParameterAnnotationsAttribute():
        attributeName.equals(ClassConstants.ATTR_AnnotationDefault)                    ? (Attribute)new AnnotationDefaultAttribute():
                                                                                         (Attribute)new UnknownAttribute(u4attributeLength);
    attribute.u2attributeNameIndex = u2attributeNameIndex;

    return attribute;
}
 
Example 7
Source File: ClassReferenceFixer.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public void visitClassElementValue(Clazz clazz, Annotation annotation, ClassElementValue classElementValue)
{
    // Compute the new class name.
    String className    = clazz.getString(classElementValue.u2classInfoIndex);
    String newClassName = newDescriptor(className,
                                        classElementValue.referencedClasses);

    if (!className.equals(newClassName))
    {
        // Refer to a new Utf8 entry.
        classElementValue.u2classInfoIndex =
            new ConstantPoolEditor((ProgramClass)clazz).addUtf8Constant(newClassName);
    }
}
 
Example 8
Source File: ClassReferenceFixer.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public void visitEnumConstantElementValue(Clazz clazz, Annotation annotation, EnumConstantElementValue enumConstantElementValue)
{
    // Compute the new type name.
    String typeName    = clazz.getString(enumConstantElementValue.u2typeNameIndex);
    String newTypeName = newDescriptor(typeName,
                                       enumConstantElementValue.referencedClasses);

    if (!typeName.equals(newTypeName))
    {
        // Refer to a new Utf8 entry.
        enumConstantElementValue.u2typeNameIndex =
            new ConstantPoolEditor((ProgramClass)clazz).addUtf8Constant(newTypeName);
    }
}
 
Example 9
Source File: ClassReferenceFixer.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public void visitLocalVariableTypeInfo(Clazz clazz, Method method, CodeAttribute codeAttribute, LocalVariableTypeInfo localVariableTypeInfo)
{
    // Has the signature changed?
    String signature    = clazz.getString(localVariableTypeInfo.u2signatureIndex);
    String newSignature = newDescriptor(signature,
                                        localVariableTypeInfo.referencedClasses);

    if (!signature.equals(newSignature))
    {
        localVariableTypeInfo.u2signatureIndex =
            new ConstantPoolEditor((ProgramClass)clazz).addUtf8Constant(newSignature);
    }
}
 
Example 10
Source File: ClassReferenceFixer.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public void visitLocalVariableInfo(Clazz clazz, Method method, CodeAttribute codeAttribute, LocalVariableInfo localVariableInfo)
{
    // Has the descriptor changed?
    String descriptor    = clazz.getString(localVariableInfo.u2descriptorIndex);
    String newDescriptor = newDescriptor(descriptor,
                                         localVariableInfo.referencedClass);

    if (!descriptor.equals(newDescriptor))
    {
        // Refer to a new Utf8 entry.
        localVariableInfo.u2descriptorIndex =
            new ConstantPoolEditor((ProgramClass)clazz).addUtf8Constant(newDescriptor);
    }
}
 
Example 11
Source File: ClassShrinker.java    From java-n-IDE-for-Android with Apache License 2.0 4 votes vote down vote up
public void visitSignatureAttribute(Clazz clazz, SignatureAttribute  signatureAttribute)
{
    Clazz[] referencedClasses = signatureAttribute.referencedClasses;
    if (referencedClasses != null)
    {
        // Go over the generic definitions, superclass and implemented interfaces.
        String signature = clazz.getString(signatureAttribute.u2signatureIndex);

        InternalTypeEnumeration internalTypeEnumeration =
            new InternalTypeEnumeration(signature);

        StringBuffer newSignatureBuffer = new StringBuffer();

        int referencedClassIndex    = 0;
        int newReferencedClassIndex = 0;

        while (internalTypeEnumeration.hasMoreTypes())
        {
            // Consider the classes referenced by this signature.
            String type       = internalTypeEnumeration.nextType();
            int    classCount = new DescriptorClassEnumeration(type).classCount();

            Clazz referencedClass = referencedClasses[referencedClassIndex];
            if (referencedClass == null ||
                usageMarker.isUsed(referencedClass))
            {
                // Append the superclass or interface.
                newSignatureBuffer.append(type);

                // Copy the referenced classes.
                for (int counter = 0; counter < classCount; counter++)
                {
                    referencedClasses[newReferencedClassIndex++] =
                        referencedClasses[referencedClassIndex++];
                }
            }
            else
            {
                // Skip the referenced classes.
                referencedClassIndex += classCount;
            }
        }

        if (newReferencedClassIndex < referencedClassIndex)
        {
            // Update the signature.
            ((Utf8Constant)((ProgramClass)clazz).constantPool[signatureAttribute.u2signatureIndex]).setString(newSignatureBuffer.toString());

            // Clear the unused entries.
            while (newReferencedClassIndex < referencedClassIndex)
            {
                referencedClasses[newReferencedClassIndex++] = null;
            }
        }
    }
}
 
Example 12
Source File: Annotation.java    From java-n-IDE-for-Android with Apache License 2.0 4 votes vote down vote up
/**
 * Returns the type.
 */
public String getType(Clazz clazz)
{
    return clazz.getString(u2typeIndex);
}
 
Example 13
Source File: ElementValue.java    From java-n-IDE-for-Android with Apache License 2.0 4 votes vote down vote up
/**
 * Returns the element name.
 */
public String getMethodName(Clazz clazz)
{
    return clazz.getString(u2elementNameIndex);
}
 
Example 14
Source File: Attribute.java    From java-n-IDE-for-Android with Apache License 2.0 4 votes vote down vote up
/**
 * Returns the String name of the attribute.
 */
public String getAttributeName(Clazz clazz)
{
    return clazz.getString(u2attributeNameIndex);
}
 
Example 15
Source File: StringConstant.java    From java-n-IDE-for-Android with Apache License 2.0 4 votes vote down vote up
/**
 * Returns the string value.
 */
public String getString(Clazz clazz)
{
    return clazz.getString(u2stringIndex);
}
 
Example 16
Source File: NameAndTypeConstant.java    From java-n-IDE-for-Android with Apache License 2.0 4 votes vote down vote up
/**
 * Returns the type.
 */
public String getType(Clazz clazz)
{
    return clazz.getString(u2descriptorIndex);
}
 
Example 17
Source File: NameAndTypeConstant.java    From java-n-IDE-for-Android with Apache License 2.0 4 votes vote down vote up
/**
 * Returns the name.
 */
public String getName(Clazz clazz)
{
    return clazz.getString(u2nameIndex);
}
 
Example 18
Source File: ClassConstant.java    From java-n-IDE-for-Android with Apache License 2.0 4 votes vote down vote up
/**
 * Returns the name.
 */
public String getName(Clazz clazz)
{
    return clazz.getString(u2nameIndex);
}