Example usage for org.eclipse.jdt.internal.compiler.lookup Binding NO_ELEMENT_VALUE_PAIRS

List of usage examples for org.eclipse.jdt.internal.compiler.lookup Binding NO_ELEMENT_VALUE_PAIRS

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.compiler.lookup Binding NO_ELEMENT_VALUE_PAIRS.

Prototype

ElementValuePair[] NO_ELEMENT_VALUE_PAIRS

To view the source code for org.eclipse.jdt.internal.compiler.lookup Binding NO_ELEMENT_VALUE_PAIRS.

Click Source Link

Usage

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.util.AstConverter.java

License:Open Source License

public static FieldDeclaration createField(FieldBinding fieldBinding, TypeDeclaration roleDeclaration,
        AstGenerator gen) {/* ww w.  j a v  a 2s.  com*/

    if (fieldBinding == null)
        return null;

    FieldDeclaration fieldDeclaration = new FieldDeclaration();
    fieldDeclaration.type = gen.typeReference(fieldBinding.type);

    fieldDeclaration.modifiers = (fieldBinding.modifiers & ~ExtraCompilerModifiers.AccBlankFinal); // this modifier is not used on fieldDecl (AST), overlaps with AccReadOnly
    fieldDeclaration.name = fieldBinding.name;
    if (fieldBinding.copyInheritanceSrc != null)
        fieldDeclaration.copyInheritanceSrc = fieldBinding.copyInheritanceSrc;
    else
        fieldDeclaration.copyInheritanceSrc = fieldBinding;

    AnnotationBinding[] annotBindings = fieldBinding.getAnnotations();
    if (annotBindings != Binding.NO_ANNOTATIONS) {
        ProblemReporter pr = fieldBinding.isStatic() ? roleDeclaration.staticInitializerScope.problemReporter()
                : roleDeclaration.initializerScope.problemReporter();
        Annotation[] annotDecls = new Annotation[annotBindings.length];
        boolean hasAnnotationError = false;
        for (int i = 0; i < annotBindings.length; i++) {
            AnnotationBinding binding = annotBindings[i];
            ElementValuePair[] elementValuePairs = binding.getElementValuePairs();
            char[][] annotTypeName = binding.getAnnotationType().compoundName;
            if (elementValuePairs == Binding.NO_ELEMENT_VALUE_PAIRS) {
                annotDecls[i] = gen.markerAnnotation(annotTypeName);
            } else {
                int numPairs = elementValuePairs.length;
                char[][] names = new char[numPairs][];
                Expression[] values = new Expression[numPairs];
                for (int j = 0; j < names.length; j++) {
                    names[j] = elementValuePairs[j].getName();
                    Object elementValue = elementValuePairs[j].getValue();
                    values[j] = annotationValues(elementValue, gen, pr);
                }
                if (values.length == 0 || values[0] == null) {
                    pr.unexpectedAnnotationStructure(annotTypeName, fieldBinding.name, gen.sourceStart,
                            gen.sourceEnd);
                    hasAnnotationError = true;
                } else if (numPairs == 1 && CharOperation.equals(names[0], TypeConstants.VALUE)) {
                    annotDecls[i] = gen.singleMemberAnnotation(annotTypeName, values[0]);
                } else {
                    annotDecls[i] = gen.normalAnnotation(annotTypeName, names, values);
                }
            }
        }
        if (!hasAnnotationError)
            fieldDeclaration.annotations = annotDecls;
    }

    //field initializations are copied using a RoleInitializationMethod
    return fieldDeclaration;
}