Search in sources :

Example 1 with IBinaryAnnotation

use of org.eclipse.jdt.internal.compiler.env.IBinaryAnnotation in project che by eclipse.

the class Util method getAnnotationMemberValue.

public static Object getAnnotationMemberValue(JavaElement parent, MemberValuePair memberValuePair, Object binaryValue) {
    if (binaryValue instanceof Constant) {
        return getAnnotationMemberValue(memberValuePair, (Constant) binaryValue);
    } else if (binaryValue instanceof IBinaryAnnotation) {
        memberValuePair.valueKind = IMemberValuePair.K_ANNOTATION;
        return getAnnotation(parent, (IBinaryAnnotation) binaryValue, memberValuePair.getMemberName());
    } else if (binaryValue instanceof ClassSignature) {
        memberValuePair.valueKind = IMemberValuePair.K_CLASS;
        char[] className = Signature.toCharArray(CharOperation.replaceOnCopy(((ClassSignature) binaryValue).getTypeName(), '/', '.'));
        return new String(className);
    } else if (binaryValue instanceof EnumConstantSignature) {
        memberValuePair.valueKind = IMemberValuePair.K_QUALIFIED_NAME;
        EnumConstantSignature enumConstant = (EnumConstantSignature) binaryValue;
        char[] enumName = Signature.toCharArray(CharOperation.replaceOnCopy(enumConstant.getTypeName(), '/', '.'));
        char[] qualifiedName = CharOperation.concat(enumName, enumConstant.getEnumConstantName(), '.');
        return new String(qualifiedName);
    } else if (binaryValue instanceof Object[]) {
        // modified below by the first call to getMemberValue(...)
        memberValuePair.valueKind = -1;
        Object[] binaryValues = (Object[]) binaryValue;
        int length = binaryValues.length;
        Object[] values = new Object[length];
        for (int i = 0; i < length; i++) {
            int previousValueKind = memberValuePair.valueKind;
            Object value = getAnnotationMemberValue(parent, memberValuePair, binaryValues[i]);
            if (previousValueKind != -1 && memberValuePair.valueKind != previousValueKind) {
                // values are heterogeneous, value kind is thus unknown
                memberValuePair.valueKind = IMemberValuePair.K_UNKNOWN;
            }
            if (value instanceof Annotation) {
                Annotation annotation = (Annotation) value;
                for (int j = 0; j < i; j++) {
                    if (annotation.equals(values[j])) {
                        annotation.occurrenceCount++;
                    }
                }
            }
            values[i] = value;
        }
        if (memberValuePair.valueKind == -1)
            memberValuePair.valueKind = IMemberValuePair.K_UNKNOWN;
        return values;
    } else {
        memberValuePair.valueKind = IMemberValuePair.K_UNKNOWN;
        return null;
    }
}
Also used : Constant(org.eclipse.jdt.internal.compiler.impl.Constant) IBinaryAnnotation(org.eclipse.jdt.internal.compiler.env.IBinaryAnnotation) EnumConstantSignature(org.eclipse.jdt.internal.compiler.env.EnumConstantSignature) ClassSignature(org.eclipse.jdt.internal.compiler.env.ClassSignature) Annotation(org.eclipse.jdt.internal.core.Annotation) IBinaryAnnotation(org.eclipse.jdt.internal.compiler.env.IBinaryAnnotation) IAnnotation(org.eclipse.jdt.core.IAnnotation)

Aggregations

IAnnotation (org.eclipse.jdt.core.IAnnotation)1 ClassSignature (org.eclipse.jdt.internal.compiler.env.ClassSignature)1 EnumConstantSignature (org.eclipse.jdt.internal.compiler.env.EnumConstantSignature)1 IBinaryAnnotation (org.eclipse.jdt.internal.compiler.env.IBinaryAnnotation)1 Constant (org.eclipse.jdt.internal.compiler.impl.Constant)1 Annotation (org.eclipse.jdt.internal.core.Annotation)1