proguard.classfile.attribute.annotation.Annotation Java Examples

The following examples show how to use proguard.classfile.attribute.annotation.Annotation. 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: TargetClassChanger.java    From java-n-IDE-for-Android with 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 #2
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 #3
Source File: ProgramClassWriter.java    From java-n-IDE-for-Android with 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 #4
Source File: AnnotationUsageMarker.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
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 #5
Source File: AnnotationUsageMarker.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
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 #6
Source File: AnnotationUsageMarker.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
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 #7
Source File: AnnotationAdder.java    From java-n-IDE-for-Android with 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 #8
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 #9
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 #10
Source File: ElementValuesEditor.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new ElementValuesEditor that will edit element values in the
 * given target annotation.
 */
public ElementValuesEditor(ProgramClass targetClass,
                           Annotation   targetAnnotation,
                           boolean      replaceElementValues)
{
    this.targetClass             = targetClass;
    this.targetAnnotation        = targetAnnotation;
    this.targetArrayElementValue = null;
    this.replaceElementValues    = replaceElementValues;
}
 
Example #11
Source File: ProgramClassReader.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public void visitAnyAnnotationsAttribute(Clazz clazz, AnnotationsAttribute annotationsAttribute)
{
    // Read the annotations.
    annotationsAttribute.u2annotationsCount = dataInput.readUnsignedShort();

    annotationsAttribute.annotations = new Annotation[annotationsAttribute.u2annotationsCount];
    for (int index = 0; index < annotationsAttribute.u2annotationsCount; index++)
    {
        Annotation annotation = new Annotation();
        this.visitAnnotation(clazz, annotation);
        annotationsAttribute.annotations[index] = annotation;
    }
}
 
Example #12
Source File: TargetClassChanger.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)
{
    // Change the referenced annotation class and method.
    visitAnyElementValue(clazz, annotation, classElementValue);

    // Change the referenced classes.
    updateReferencedClasses(classElementValue.referencedClasses);
}
 
Example #13
Source File: Utf8UsageMarker.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)
{
    if (enumConstantElementValue.u2elementNameIndex != 0)
    {
        markCpUtf8Entry(clazz, enumConstantElementValue.u2elementNameIndex);
    }

    markCpUtf8Entry(clazz, enumConstantElementValue.u2typeNameIndex);
    markCpUtf8Entry(clazz, enumConstantElementValue.u2constantNameIndex);
}
 
Example #14
Source File: AnnotationTypeFilter.java    From proguard with GNU General Public License v2.0 5 votes vote down vote up
public void visitAnnotation(Clazz clazz, Field field, Annotation annotation)
{
    if (accepted(annotation.getType(clazz)))
    {
        annotationVisitor.visitAnnotation(clazz, field, annotation);
    }
}
 
Example #15
Source File: AnnotationTypeFilter.java    From bazel with Apache License 2.0 5 votes vote down vote up
public void visitAnnotation(Clazz clazz, Annotation annotation)
{
    if (accepted(annotation.getType(clazz)))
    {
        annotationVisitor.visitAnnotation(clazz, annotation);
    }
}
 
Example #16
Source File: AnnotationToMemberVisitor.java    From bazel with Apache License 2.0 5 votes vote down vote up
public void visitAnnotation(Clazz clazz, Member member, Annotation annotation)
{
    if (!member.equals(lastVisitedMember))
    {
        member.accept(clazz, memberVisitor);

        lastVisitedMember = member;
    }
}
 
Example #17
Source File: ClassShrinker.java    From java-n-IDE-for-Android with 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 #18
Source File: ConstantPoolRemapper.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)
{
    enumConstantElementValue.u2elementNameIndex =
        remapConstantIndex(enumConstantElementValue.u2elementNameIndex);
    enumConstantElementValue.u2typeNameIndex =
        remapConstantIndex(enumConstantElementValue.u2typeNameIndex);
    enumConstantElementValue.u2constantNameIndex =
        remapConstantIndex(enumConstantElementValue.u2constantNameIndex);
}
 
Example #19
Source File: ConstantPoolRemapper.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public void visitConstantElementValue(Clazz clazz, Annotation annotation, ConstantElementValue constantElementValue)
{
    constantElementValue.u2elementNameIndex =
        remapConstantIndex(constantElementValue.u2elementNameIndex);
    constantElementValue.u2constantValueIndex =
        remapConstantIndex(constantElementValue.u2constantValueIndex);
}
 
Example #20
Source File: AnnotationTypeFilter.java    From proguard with GNU General Public License v2.0 5 votes vote down vote up
public void visitAnnotation(Clazz clazz, Annotation annotation)
{
    if (accepted(annotation.getType(clazz)))
    {
        annotationVisitor.visitAnnotation(clazz, annotation);
    }
}
 
Example #21
Source File: ElementValueAdder.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public void visitConstantElementValue(Clazz clazz, Annotation annotation, ConstantElementValue constantElementValue)
{
    // Create a copy of the element value.
    ConstantElementValue newConstantElementValue =
        new ConstantElementValue(constantElementValue.u1tag,
                                 constantElementValue.u2elementNameIndex == 0 ? 0 :
                                 constantAdder.addConstant(clazz, constantElementValue.u2elementNameIndex),
                                 constantAdder.addConstant(clazz, constantElementValue.u2constantValueIndex));

    newConstantElementValue.referencedClass  = constantElementValue.referencedClass;
    newConstantElementValue.referencedMethod = constantElementValue.referencedMethod;

    // Add it to the target.
    addElementValue(newConstantElementValue);
}
 
Example #22
Source File: ProgramClassWriter.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public void visitAnnotation(Clazz clazz, Annotation annotation)
{
    // Write the annotation type.
    dataOutput.writeShort(annotation.u2typeIndex);

    // Write the element value pairs.
    dataOutput.writeShort(annotation.u2elementValuesCount);

    annotation.elementValuesAccept(clazz, this);
}
 
Example #23
Source File: Utf8UsageMarker.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)
{
    if (classElementValue.u2elementNameIndex != 0)
    {
        markCpUtf8Entry(clazz, classElementValue.u2elementNameIndex);
    }

    markCpUtf8Entry(clazz, classElementValue.u2classInfoIndex);
}
 
Example #24
Source File: ClassReferenceInitializer.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public void visitAnnotationElementValue(Clazz clazz, Annotation annotation, AnnotationElementValue annotationElementValue)
{
    initializeElementValue(clazz, annotation, annotationElementValue);

    // Initialize the annotation.
    annotationElementValue.annotationAccept(clazz, this);
}
 
Example #25
Source File: ClassReferenceInitializer.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)
{
    initializeElementValue(clazz, annotation, classElementValue);

    classElementValue.referencedClasses =
        findReferencedClasses(clazz.getName(),
                              clazz.getString(classElementValue.u2classInfoIndex));
}
 
Example #26
Source File: TargetClassChanger.java    From java-n-IDE-for-Android with 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 #27
Source File: AnnotationTypeFilter.java    From bazel with 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 #28
Source File: Utf8UsageMarker.java    From java-n-IDE-for-Android with 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 #29
Source File: ReferencedClassVisitor.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
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 #30
Source File: AnnotationTypeFilter.java    From proguard with GNU General Public License v2.0 5 votes vote down vote up
public void visitAnnotation(Clazz clazz, Method method, int parameterIndex, Annotation annotation)
{
    if (accepted(annotation.getType(clazz)))
    {
        annotationVisitor.visitAnnotation(clazz, method, parameterIndex, annotation);
    }
}