Java Code Examples for proguard.classfile.Clazz

The following examples show how to use proguard.classfile.Clazz. These examples are extracted from open source projects. 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
public void visitLibraryClass(LibraryClass libraryClass)
{
    // Is this an abstract class or interface?
    if ((libraryClass.getAccessFlags() &
         (ClassConstants.INTERNAL_ACC_INTERFACE |
          ClassConstants.INTERNAL_ACC_ABSTRACT)) != 0)
    {
        // Travel down the hierarchy.
        Clazz[] subClasses = libraryClass.subClasses;
        if (subClasses != null)
        {
            for (int index = 0; index < subClasses.length; index++)
            {
                subClasses[index].accept(this);
            }
        }
    }
    else
    {
        // Visit the class. Don't descend any further.
        libraryClass.accept(classVisitor);
    }
}
 
Example 2
Source Project: java-n-IDE-for-Android   Source File: ClassPrinter.java    License: Apache License 2.0 6 votes vote down vote up
public void visitCodeAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute)
{
    println(visitorInfo(codeAttribute) +
            " Code attribute instructions (code length = "+ codeAttribute.u4codeLength +
            ", locals = "+ codeAttribute.u2maxLocals +
            ", stack = "+ codeAttribute.u2maxStack + "):");

    indent();

    codeAttribute.instructionsAccept(clazz, method, this);

    println("Code attribute exceptions (count = " +
            codeAttribute.u2exceptionTableLength + "):");

    codeAttribute.exceptionsAccept(clazz, method, this);

    println("Code attribute attributes (attribute count = " +
            codeAttribute.u2attributesCount + "):");

    codeAttribute.attributesAccept(clazz, method, this);

    outdent();
}
 
Example 3
public void visitInnerClassesInfo(Clazz clazz, InnerClassesInfo innerClassesInfo)
{
    if (innerClassesInfo.u2innerClassIndex != 0)
    {
        innerClassesInfo.u2innerClassIndex =
            remapConstantIndex(innerClassesInfo.u2innerClassIndex);
    }

    if (innerClassesInfo.u2outerClassIndex != 0)
    {
        innerClassesInfo.u2outerClassIndex =
            remapConstantIndex(innerClassesInfo.u2outerClassIndex);
    }

    if (innerClassesInfo.u2innerNameIndex != 0)
    {
        innerClassesInfo.u2innerNameIndex =
            remapConstantIndex(innerClassesInfo.u2innerNameIndex);
    }
}
 
Example 4
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 5
public void visitProgramField(ProgramClass programClass, ProgramField programField)
{
    Value parameterValue = StoringInvocationUnit.getFieldValue(programField);
    if (parameterValue.computationalType() == Value.TYPE_REFERENCE)
    {
        Clazz referencedClass = parameterValue.referenceValue().getReferencedClass();
        if (programField.referencedClass != referencedClass)
        {
            if (DEBUG)
            {
                System.out.println("MemberDescriptorSpecializer: "+programClass.getName()+"."+programField.getName(programClass)+" "+programField.getDescriptor(programClass));
                System.out.println("  "+programField.referencedClass.getName()+" -> "+referencedClass.getName());
            }

            programField.referencedClass = referencedClass;

            // Visit the field, if required.
            if (extraParameterMemberVisitor != null)
            {
                extraParameterMemberVisitor.visitProgramField(programClass, programField);
            }
        }
    }
}
 
Example 6
public void visitStringConstant(Clazz clazz, StringConstant stringConstant)
{
    StringConstant stringPatternConstant = (StringConstant)patternConstant;

    // Check the UTF-8 constant.
    matchingConstant =
        matchingConstantIndices(clazz,
                                stringConstant.u2stringIndex,
                                stringPatternConstant.u2stringIndex);
}
 
Example 7
/**
 * Deletes the reference popping instruction at the given offset, if
 * it is at the start of a subroutine that doesn't return or a subroutine
 * that is only called from one place.
 */
private void deleteReferencePopInstruction(Clazz       clazz,
                                           int         offset,
                                           Instruction instruction)
{
    if (partialEvaluator.isSubroutineStart(offset) &&
        (!partialEvaluator.isSubroutineReturning(offset) ||
         partialEvaluator.branchOrigins(offset).instructionOffsetCount() == 1))
    {
        if (DEBUG) System.out.println("  Deleting store of subroutine return address "+instruction.toString(offset));

        // A reference value can only be specific if it is null.
        codeAttributeEditor.deleteInstruction(offset);
    }
}
 
Example 8
public void visitAnnotation(Clazz clazz, Field field, Annotation annotation)
{
    if (accepted(annotation.getType(clazz)))
    {
        annotationVisitor.visitAnnotation(clazz, field, annotation);
    }
}
 
Example 9
/**
 * Replaces the integer pushing instruction at the given offset by a simpler
 * push instruction, if possible.
 */
private void replaceIntegerPushInstruction(Clazz       clazz,
                                           int         offset,
                                           Instruction instruction)
{
    replaceIntegerPushInstruction(clazz,
                                  offset,
                                  instruction,
                                  partialEvaluator.getVariablesBefore(offset).size());
}
 
Example 10
Source Project: java-n-IDE-for-Android   Source File: ClassMerger.java    License: Apache License 2.0 5 votes vote down vote up
public static void setTargetClass(Clazz clazz, Clazz targetClass)
{
    ClassOptimizationInfo info = ClassOptimizationInfo.getClassOptimizationInfo(clazz);
    if (info != null)
    {
        info.setTargetClass(targetClass);
    }
}
 
Example 11
Source Project: java-n-IDE-for-Android   Source File: ProgramClassReader.java    License: Apache License 2.0 5 votes vote down vote up
public void visitLocalVariableTypeInfo(Clazz clazz, Method method, CodeAttribute codeAttribute, LocalVariableTypeInfo localVariableTypeInfo)
{
    localVariableTypeInfo.u2startPC        = dataInput.readUnsignedShort();
    localVariableTypeInfo.u2length         = dataInput.readUnsignedShort();
    localVariableTypeInfo.u2nameIndex      = dataInput.readUnsignedShort();
    localVariableTypeInfo.u2signatureIndex = dataInput.readUnsignedShort();
    localVariableTypeInfo.u2index          = dataInput.readUnsignedShort();
}
 
Example 12
public void visitRuntimeInvisibleAnnotationsAttribute(Clazz clazz, Field field, RuntimeInvisibleAnnotationsAttribute runtimeInvisibleAnnotationsAttribute)
{
    if (optionalAttributeVisitor != null)
    {
        runtimeInvisibleAnnotationsAttribute.accept(clazz, field, optionalAttributeVisitor);
    }
}
 
Example 13
Source Project: java-n-IDE-for-Android   Source File: UsageMarker.java    License: Apache License 2.0 5 votes vote down vote up
public void visitUtf8Constant(Clazz clazz, Utf8Constant utf8Constant)
{
    if (shouldBeMarkedAsUsed(utf8Constant))
    {
        markAsUsed(utf8Constant);
    }
}
 
Example 14
public void visitConstantElementValue(Clazz clazz, Annotation annotation, ConstantElementValue constantElementValue)
{
    constantElementValue.u2elementNameIndex =
        remapConstantIndex(constantElementValue.u2elementNameIndex);
    constantElementValue.u2constantValueIndex =
        remapConstantIndex(constantElementValue.u2constantValueIndex);
}
 
Example 15
Source Project: java-n-IDE-for-Android   Source File: ClassMerger.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Returns whether the given class or its subclasses shadow any methods in
 * the given target class.
 */
private boolean shadowsAnyMethods(Clazz clazz, Clazz targetClass)
{
    MemberCounter counter = new MemberCounter();

    // Visit all private methods, counting the ones that are shadowing
    // non-private methods in the class hierarchy of the target class.
    clazz.hierarchyAccept(true, false, false, true,
                          new AllMethodVisitor(
                          new MemberAccessFilter(ClassConstants.INTERNAL_ACC_PRIVATE, 0,
                          new MemberNameFilter(new NotMatcher(new FixedStringMatcher(ClassConstants.INTERNAL_METHOD_NAME_INIT)),
                          new SimilarMemberVisitor(targetClass, true, true, true, false,
                          new MemberAccessFilter(0, ClassConstants.INTERNAL_ACC_PRIVATE,
                          counter))))));

    // Visit all static methods, counting the ones that are shadowing
    // non-private methods in the class hierarchy of the target class.
    clazz.hierarchyAccept(true, false, false, true,
                          new AllMethodVisitor(
                          new MemberAccessFilter(ClassConstants.INTERNAL_ACC_STATIC, 0,
                          new MemberNameFilter(new NotMatcher(new FixedStringMatcher(ClassConstants.INTERNAL_METHOD_NAME_CLINIT)),
                          new SimilarMemberVisitor(targetClass, true, true, true, false,
                          new MemberAccessFilter(0, ClassConstants.INTERNAL_ACC_PRIVATE,
                          counter))))));

    return counter.getCount() > 0;
}
 
Example 16
/**
 * Applies the given visitor to the specified bootstrap method info
 * entry.
 */
public void bootstrapMethodEntryAccept(Clazz                      clazz,
                                       int                        bootstrapMethodIndex,
                                       BootstrapMethodInfoVisitor bootstrapMethodInfoVisitor)
{
    // We don't need double dispatching here, since there is only one
    // type of BootstrapMethodInfo.
    bootstrapMethodInfoVisitor.visitBootstrapMethodInfo(clazz, bootstrapMethods[bootstrapMethodIndex]);
}
 
Example 17
Source Project: java-n-IDE-for-Android   Source File: ClassPrinter.java    License: Apache License 2.0 5 votes vote down vote up
public void visitFullFrame(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, FullFrame fullFrame)
{
    print(visitorInfo(fullFrame) +
          " [" + offset  + "]" +
          " Var: ");

    fullFrame.variablesAccept(clazz, method, codeAttribute, offset, this);

    ps.print(", Stack: ");

    fullFrame.stackAccept(clazz, method, codeAttribute, offset, this);

    println();
}
 
Example 18
public void visitConstantValueAttribute(Clazz clazz, Field field, ConstantValueAttribute constantValueAttribute)
{
    if (accepted(clazz, constantValueAttribute))
    {
        constantValueAttribute.accept(clazz, field, attributeVisitor);
    }
}
 
Example 19
public void visitConstantInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, ConstantInstruction constantInstruction)
{
    byte opcode = constantInstruction.opcode;

    // Could this instruction be a .class construct?
    if (opcode == InstructionConstants.OP_LDC ||
        opcode == InstructionConstants.OP_LDC_W)
    {
        clazz.constantPoolEntryAccept(constantInstruction.constantIndex,
                                      this);
    }
}
 
Example 20
Source Project: java-n-IDE-for-Android   Source File: ProgramClassReader.java    License: Apache License 2.0 5 votes vote down vote up
public void visitAnnotationDefaultAttribute(Clazz clazz, Method method, AnnotationDefaultAttribute annotationDefaultAttribute)
{
    // Read the default element value.
    ElementValue elementValue = createElementValue();
    elementValue.accept(clazz, null, this);
    annotationDefaultAttribute.defaultValue = elementValue;
}
 
Example 21
public void visitDeprecatedAttribute(Clazz clazz, DeprecatedAttribute deprecatedAttribute)
{
    if (optionalAttributeVisitor != null)
    {
        deprecatedAttribute.accept(clazz, optionalAttributeVisitor);
    }
}
 
Example 22
Source Project: java-n-IDE-for-Android   Source File: UsageMarker.java    License: Apache License 2.0 5 votes vote down vote up
public void visitClassConstant(Clazz clazz, ClassConstant classConstant)
{
    if (shouldBeMarkedAsUsed(classConstant))
    {
        markAsUsed(classConstant);

        markConstant(clazz, classConstant.u2nameIndex);

        // Mark the referenced class itself.
        classConstant.referencedClassAccept(this);
    }
}
 
Example 23
public void visitSourceDirAttribute(Clazz clazz, SourceDirAttribute sourceDirAttribute)
{
    if (optionalAttributeVisitor != null)
    {
        sourceDirAttribute.accept(clazz, optionalAttributeVisitor);
    }
}
 
Example 24
public void visitCodeAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute)
{
    // Recompute the maximum stack size if necessary.
    if (stackSizesMayHaveChanged)
    {
            stackSizeUpdater.visitCodeAttribute(clazz, method, codeAttribute);
    }

    // Fix the nested attributes.
    codeAttribute.attributesAccept(clazz, method, this);
}
 
Example 25
public void visitRuntimeInvisibleAnnotationsAttribute(Clazz clazz, Field field, RuntimeInvisibleAnnotationsAttribute runtimeInvisibleAnnotationsAttribute)
{
    if (accepted(clazz, runtimeInvisibleAnnotationsAttribute))
    {
        runtimeInvisibleAnnotationsAttribute.accept(clazz, field, attributeVisitor);
    }
}
 
Example 26
public void visitDeprecatedAttribute(Clazz clazz, Method method, DeprecatedAttribute deprecatedAttribute)
{
    for (int index = 0; index < attributeVisitors.length; index++)
    {
        attributeVisitors[index].visitDeprecatedAttribute(clazz, method, deprecatedAttribute);
    }
}
 
Example 27
Source Project: java-n-IDE-for-Android   Source File: Utf8UsageMarker.java    License: Apache License 2.0 5 votes vote down vote up
public void visitAnnotationDefaultAttribute(Clazz clazz, Method method, AnnotationDefaultAttribute annotationDefaultAttribute)
{
    markCpUtf8Entry(clazz, annotationDefaultAttribute.u2attributeNameIndex);

    // Mark the UTF-8 entries referenced by the element value.
    annotationDefaultAttribute.defaultValueAccept(clazz, this);
}
 
Example 28
/**
 * Creates a new long value with the given ID.
 */
public IdentifiedReferenceValue(String       type,
                                Clazz        referencedClass,
                                boolean      mayBeNull,
                                ValueFactory valuefactory,
                                int          id)
{
    super(type, referencedClass, mayBeNull);

    this.valuefactory = valuefactory;
    this.id           = id;
}
 
Example 29
Source Project: atlas   Source File: VisitorDTO.java    License: Apache License 2.0 5 votes vote down vote up
public String findRootLibClazz(String className) {
    if (isLibClazz(className)) {
        return className;
    }
    Clazz clazz = currentClassPool.getClass(className);
    //assert clazz!=null;
    if (null == clazz) {
        return "";
    }
    return findRootLibClazz(clazz);
}
 
Example 30
Source Project: java-n-IDE-for-Android   Source File: ConstantPoolEditor.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Finds or creates a InterfaceMethodrefConstant 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 InterfaceMethodrefConstant.
 */
public int addInterfaceMethodrefConstant(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_InterfaceMethodref)
        {
            InterfaceMethodrefConstant methodrefConstant = (InterfaceMethodrefConstant)constant;
            if (methodrefConstant.u2classIndex       == classIndex &&
                methodrefConstant.u2nameAndTypeIndex == nameAndTypeIndex)
            {
                return index;
            }
        }
    }

    return addConstant(new InterfaceMethodrefConstant(classIndex,
                                                      nameAndTypeIndex,
                                                      referencedClass,
                                                      referencedMember));
}