Java Code Examples for proguard.classfile.attribute.annotation.Annotation

The following examples show how to use proguard.classfile.attribute.annotation.Annotation. 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 visitEnumConstantElementValue(Clazz clazz, Annotation annotation, EnumConstantElementValue enumConstantElementValue)
{
    if (isReferencedMethodUsed(enumConstantElementValue))
    {
        // Check the referenced classes.
        classUsed = true;
        enumConstantElementValue.referencedClassesAccept(usageMarker);

        if (classUsed)
        {
            // Mark the element value as being used.
            usageMarker.markAsUsed(enumConstantElementValue);

            markConstant(clazz, enumConstantElementValue.u2elementNameIndex);
            markConstant(clazz, enumConstantElementValue.u2typeNameIndex);
            markConstant(clazz, enumConstantElementValue.u2constantNameIndex);
        }
    }
}
 
Example 2
public void visitClassElementValue(Clazz clazz, Annotation annotation, ClassElementValue classElementValue)
{
    if (isReferencedMethodUsed(classElementValue))
    {
        // Check the referenced classes.
        classUsed = true;
        classElementValue.referencedClassesAccept(usageMarker);

        if (classUsed)
        {
            // Mark the element value as being used.
            usageMarker.markAsUsed(classElementValue);

            markConstant(clazz, classElementValue.u2elementNameIndex);
            markConstant(clazz, classElementValue.u2classInfoIndex);
        }
    }
}
 
Example 3
public void visitAnnotationElementValue(Clazz clazz, Annotation annotation, AnnotationElementValue annotationElementValue)
{
    if (isReferencedMethodUsed(annotationElementValue))
    {
        boolean oldAnnotationUsed = annotationUsed;

        // Check and mark the contained annotation.
        annotationUsed = false;
        annotationElementValue.annotationAccept(clazz, this);

        if (annotationUsed)
        {
            // Mark the element value as being used.
            usageMarker.markAsUsed(annotationElementValue);

            markConstant(clazz, annotationElementValue.u2elementNameIndex);
        }

        annotationUsed = oldAnnotationUsed;
    }
}
 
Example 4
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 5
Source Project: java-n-IDE-for-Android   Source File: ProgramClassWriter.java    License: Apache License 2.0 6 votes vote down vote up
public void visitAnyParameterAnnotationsAttribute(Clazz clazz, Method method, ParameterAnnotationsAttribute parameterAnnotationsAttribute)
{
    // Write the parameter annotations.
    dataOutput.writeByte(parameterAnnotationsAttribute.u2parametersCount);

    for (int parameterIndex = 0; parameterIndex < parameterAnnotationsAttribute.u2parametersCount; parameterIndex++)
    {
        // Write the parameter annotations of the given parameter.
        int          u2annotationsCount = parameterAnnotationsAttribute.u2parameterAnnotationsCount[parameterIndex];
        Annotation[] annotations        = parameterAnnotationsAttribute.parameterAnnotations[parameterIndex];

        dataOutput.writeShort(u2annotationsCount);

        for (int index = 0; index < u2annotationsCount; index++)
        {
            Annotation annotation = annotations[index];
            this.visitAnnotation(clazz, annotation);
        }

    }
}
 
Example 6
/**
 * 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 7
Source Project: java-n-IDE-for-Android   Source File: TargetClassChanger.java    License: Apache License 2.0 6 votes vote down vote up
public void visitAnyElementValue(Clazz clazz, Annotation annotation, ElementValue elementValue)
{
    Clazz referencedClass    = elementValue.referencedClass;
    Clazz newReferencedClass = updateReferencedClass(referencedClass);
    if (referencedClass != newReferencedClass)
    {
        // Change the referenced annotation class.
        elementValue.referencedClass  = newReferencedClass;

        // Change the referenced method.
        elementValue.referencedMethod =
            (Method)updateReferencedMember(elementValue.referencedMethod,
                                           elementValue.getMethodName(clazz),
                                           null,
                                           newReferencedClass);
    }
}
 
Example 8
Source Project: java-n-IDE-for-Android   Source File: AnnotationAdder.java    License: Apache License 2.0 6 votes vote down vote up
public void visitAnnotation(Clazz clazz, Method method, int parameterIndex, Annotation annotation)
{
    Annotation newAnnotation =
        new Annotation(constantAdder.addConstant(clazz, annotation.u2typeIndex),
                       0,
                       annotation.u2elementValuesCount > 0 ?
                           new ElementValue[annotation.u2elementValuesCount] :
                           EMPTY_ELEMENT_VALUES);

    // TODO: Clone array.
    newAnnotation.referencedClasses = annotation.referencedClasses;

    // Add the element values.
    annotation.elementValuesAccept(clazz,
                                   new ElementValueAdder(targetClass,
                                                         newAnnotation,
                                                         false));

    // Add the completed annotation.
    parameterAnnotationsAttributeEditor.addAnnotation(parameterIndex, newAnnotation);
}
 
Example 9
Source Project: java-n-IDE-for-Android   Source File: ClassShrinker.java    License: Apache License 2.0 5 votes vote down vote up
public void visitAnnotation(Clazz clazz, Annotation annotation)
{
    // Shrink the element values array.
    annotation.u2elementValuesCount =
        shrinkArray(annotation.elementValues,
                    annotation.u2elementValuesCount);

    // Shrink the element values themselves.
    annotation.elementValuesAccept(clazz, this);
}
 
Example 10
Source Project: java-n-IDE-for-Android   Source File: ClassShrinker.java    License: Apache License 2.0 5 votes vote down vote up
public void visitArrayElementValue(Clazz clazz, Annotation annotation, ArrayElementValue arrayElementValue)
{
    // Shrink the element values array.
    arrayElementValue.u2elementValuesCount =
        shrinkArray(arrayElementValue.elementValues,
                    arrayElementValue.u2elementValuesCount);

    // Shrink the element values themselves.
    arrayElementValue.elementValuesAccept(clazz, annotation, this);
}
 
Example 11
public void visitConstantElementValue(Clazz clazz, Annotation annotation, ConstantElementValue constantElementValue)
{
    if (isReferencedMethodUsed(constantElementValue))
    {
        // Mark the element value as being used.
        usageMarker.markAsUsed(constantElementValue);

        markConstant(clazz, constantElementValue.u2elementNameIndex);
        markConstant(clazz, constantElementValue.u2constantValueIndex);
    }
}
 
Example 12
public void visitArrayElementValue(Clazz clazz, Annotation annotation, ArrayElementValue arrayElementValue)
{
    if (isReferencedMethodUsed(arrayElementValue))
    {
        // Check and mark the contained element values.
        arrayElementValue.elementValuesAccept(clazz, annotation, this);

        // Mark the element value as being used.
        usageMarker.markAsUsed(arrayElementValue);

        markConstant(clazz, arrayElementValue.u2elementNameIndex);
    }
}
 
Example 13
/**
 * Returns whether the annotation class has been marked as being used.
 */
private boolean isReferencedClassUsed(Annotation annotation)
{
    // Check if the referenced class is being used.
    classUsed = true;
    annotation.referencedClassAccept(this);

    return classUsed;
}
 
Example 14
public void visitAnnotation(Clazz clazz, Member member, Annotation annotation)
{
    if (!member.equals(lastVisitedMember))
    {
        member.accept(clazz, memberVisitor);

        lastVisitedMember = member;
    }
}
 
Example 15
Source Project: bazel   Source File: AnnotationTypeFilter.java    License: Apache License 2.0 5 votes vote down vote up
public void visitAnnotation(Clazz clazz, Method method, Annotation annotation)
{
    if (accepted(annotation.getType(clazz)))
    {
        annotationVisitor.visitAnnotation(clazz, method, annotation);
    }
}
 
Example 16
public void visitAnnotation(Clazz clazz, Field field, Annotation annotation)
{
    if (accepted(annotation.getType(clazz)))
    {
        annotationVisitor.visitAnnotation(clazz, field, annotation);
    }
}
 
Example 17
public void visitAnnotation(Clazz clazz, Member member, Annotation annotation)
{
    if (!member.equals(lastVisitedMember))
    {
        member.accept(clazz, memberVisitor);

        lastVisitedMember = member;
    }
}
 
Example 18
Source Project: java-n-IDE-for-Android   Source File: Utf8UsageMarker.java    License: Apache License 2.0 5 votes vote down vote up
public void visitConstantElementValue(Clazz clazz, Annotation annotation, ConstantElementValue constantElementValue)
{
    if (constantElementValue.u2elementNameIndex != 0)
    {
        markCpUtf8Entry(clazz, constantElementValue.u2elementNameIndex);
    }

    // Only the string constant element value refers to a UTF-8 entry.
    if (constantElementValue.u1tag == ClassConstants.ELEMENT_VALUE_STRING_CONSTANT)
    {
        markCpUtf8Entry(clazz, constantElementValue.u2constantValueIndex);
    }
}
 
Example 19
Source Project: java-n-IDE-for-Android   Source File: ClassPrinter.java    License: Apache License 2.0 5 votes vote down vote up
public void visitEnumConstantElementValue(Clazz clazz, Annotation annotation, EnumConstantElementValue enumConstantElementValue)
{
    println(visitorInfo(enumConstantElementValue) +
            " Enum constant element value [" +
            (enumConstantElementValue.u2elementNameIndex == 0 ? "(default)" :
            clazz.getString(enumConstantElementValue.u2elementNameIndex)) + ", " +
            clazz.getString(enumConstantElementValue.u2typeNameIndex)  + ", " +
            clazz.getString(enumConstantElementValue.u2constantNameIndex) + "]");
}
 
Example 20
Source Project: java-n-IDE-for-Android   Source File: Utf8UsageMarker.java    License: Apache License 2.0 5 votes vote down vote up
public void visitAnnotationElementValue(Clazz clazz, Annotation annotation, AnnotationElementValue annotationElementValue)
{
    if (annotationElementValue.u2elementNameIndex != 0)
    {
        markCpUtf8Entry(clazz, annotationElementValue.u2elementNameIndex);
    }

    // Mark the UTF-8 entries referenced by the annotation.
    annotationElementValue.annotationAccept(clazz, this);
}
 
Example 21
Source Project: java-n-IDE-for-Android   Source File: ClassPrinter.java    License: Apache License 2.0 5 votes vote down vote up
public void visitAnnotationElementValue(Clazz clazz, Annotation annotation, AnnotationElementValue annotationElementValue)
{
    println(visitorInfo(annotationElementValue) +
            " Annotation element value [" +
            (annotationElementValue.u2elementNameIndex == 0 ? "(default)" :
            clazz.getString(annotationElementValue.u2elementNameIndex)) + "]:");

    indent();
    annotationElementValue.annotationAccept(clazz, this);
    outdent();
}
 
Example 22
Source Project: java-n-IDE-for-Android   Source File: ClassPrinter.java    License: Apache License 2.0 5 votes vote down vote up
public void visitArrayElementValue(Clazz clazz, Annotation annotation, ArrayElementValue arrayElementValue)
{
    println(visitorInfo(arrayElementValue) +
            " Array element value [" +
            (arrayElementValue.u2elementNameIndex == 0 ? "(default)" :
            clazz.getString(arrayElementValue.u2elementNameIndex)) + "]:");

    indent();
    arrayElementValue.elementValuesAccept(clazz, annotation, this);
    outdent();
}
 
Example 23
public void visitAnnotation(Clazz clazz, Method method, int parameterIndex, Annotation annotation)
{
    if (accepted(annotation.getType(clazz)))
    {
        annotationVisitor.visitAnnotation(clazz, method, parameterIndex, annotation);
    }
}
 
Example 24
public void visitAnnotation(Clazz clazz, Annotation annotation)
{
    // Let the visitor visit the classes referenced in the annotation.
    annotation.referencedClassesAccept(classVisitor);

    // Visit the element values.
    annotation.elementValuesAccept(clazz, this);
}
 
Example 25
Source Project: java-n-IDE-for-Android   Source File: Utf8UsageMarker.java    License: Apache License 2.0 5 votes vote down vote up
public void visitAnnotation(Clazz clazz, Annotation annotation)
{
    markCpUtf8Entry(clazz, annotation.u2typeIndex);

    // Mark the UTF-8 entries referenced by the element values.
    annotation.elementValuesAccept(clazz, this);
}
 
Example 26
Source Project: bazel   Source File: AnnotationTypeFilter.java    License: Apache License 2.0 5 votes vote down vote up
public void visitAnnotation(Clazz clazz, Method method, CodeAttribute codeAttribute, Annotation annotation)
{
    if (accepted(annotation.getType(clazz)))
    {
        annotationVisitor.visitAnnotation(clazz, method, codeAttribute, annotation);
    }
}
 
Example 27
Source Project: java-n-IDE-for-Android   Source File: TargetClassChanger.java    License: Apache License 2.0 5 votes vote down vote up
public void visitAnnotation(Clazz clazz, Annotation annotation)
{
    // Change the referenced classes.
    updateReferencedClasses(annotation.referencedClasses);

    // Change the references of the element values.
    annotation.elementValuesAccept(clazz, this);
}
 
Example 28
public void visitClassElementValue(Clazz clazz, Annotation annotation, ClassElementValue classElementValue)
{
    initializeElementValue(clazz, annotation, classElementValue);

    classElementValue.referencedClasses =
        findReferencedClasses(clazz.getName(),
                              clazz.getString(classElementValue.u2classInfoIndex));
}
 
Example 29
public void visitAnnotationElementValue(Clazz clazz, Annotation annotation, AnnotationElementValue annotationElementValue)
{
    initializeElementValue(clazz, annotation, annotationElementValue);

    // Initialize the annotation.
    annotationElementValue.annotationAccept(clazz, this);
}
 
Example 30
Source Project: java-n-IDE-for-Android   Source File: Utf8UsageMarker.java    License: Apache License 2.0 5 votes vote down vote up
public void visitClassElementValue(Clazz clazz, Annotation annotation, ClassElementValue classElementValue)
{
    if (classElementValue.u2elementNameIndex != 0)
    {
        markCpUtf8Entry(clazz, classElementValue.u2elementNameIndex);
    }

    markCpUtf8Entry(clazz, classElementValue.u2classInfoIndex);
}