Example usage for org.eclipse.jdt.core.dom MarkerAnnotation resolveAnnotationBinding

List of usage examples for org.eclipse.jdt.core.dom MarkerAnnotation resolveAnnotationBinding

Introduction

In this page you can find the example usage for org.eclipse.jdt.core.dom MarkerAnnotation resolveAnnotationBinding.

Prototype

public IAnnotationBinding resolveAnnotationBinding() 

Source Link

Document

Resolves and returns the resolved annotation for this annotation.

Usage

From source file:com.codenvy.ide.ext.java.server.internal.core.util.DOMFinder.java

License:Open Source License

public boolean visit(MarkerAnnotation node) {
    if (found(node, node) && this.resolveBinding)
        this.foundBinding = node.resolveAnnotationBinding();
    return true;//from   w w  w . j  av  a2s.c  om
}

From source file:com.google.devtools.j2objc.types.BindingMapBuilder.java

License:Open Source License

@Override
public boolean visit(MarkerAnnotation node) {
    put(node, node.resolveAnnotationBinding());
    return true;
}

From source file:edu.cmu.cs.crystal.test.AnnotatedTest.java

License:Open Source License

/**
 * Given a compilation unit, returns the type of test that it is, or none if this compilation
 * unit is not a test.// ww  w.j  ava2 s  . c om
 */
public static Option<TestType> findTestType(CompilationUnit comp_unit) {
    final Box<Boolean> is_a_test = Box.box(false);
    final Box<Boolean> is_passing_test = Box.box(false);
    final Box<Integer> failures = Box.box(0);
    final Set<String> analyses = new LinkedHashSet<String>();

    ASTVisitor annotation_visitor = new ASTVisitor() {
        // Visitor will find @PassingTest, @FailingTest, @UseAnalyses

        private Integer intValueFromBinding(IAnnotationBinding binding) {
            for (IMemberValuePairBinding pair : binding.getAllMemberValuePairs()) {
                if ("value".equals(pair.getName())) {
                    return ((Integer) pair.getValue());
                }
            }

            throw new RuntimeException("Anntation had no value field.");
        }

        private Collection<? extends String> stringSetValueFromBinding(IAnnotationBinding binding) {
            for (IMemberValuePairBinding pair : binding.getAllMemberValuePairs()) {
                if ("value".equals(pair.getName())) {
                    Object value = pair.getValue();

                    if (value instanceof String[]) {
                        return Arrays.asList((String[]) value);
                    } else if (value instanceof String) {
                        return Collections.singleton((String) value);
                    } else if (value instanceof Object[]) {
                        List<String> result = new LinkedList<String>();
                        for (Object obj : ((Object[]) value)) {
                            if (obj instanceof String)
                                result.add((String) obj);
                            else
                                throw new RuntimeException("Value was not of expected type.");
                        }
                        return result;
                    } else {
                        throw new RuntimeException("Value was not of expected type.");
                    }

                }
            }

            throw new RuntimeException("Anntation had no value field.");
        }

        @Override
        public boolean visit(MarkerAnnotation node) {
            // A marker annotation looks like, @PassingTest
            String annotation = node.resolveTypeBinding().getQualifiedName();

            if (FailingTest.class.getName().equals(annotation)) {
                is_a_test.setValue(true);
                is_passing_test.setValue(false);
            } else if (PassingTest.class.getName().equals(annotation)) {
                is_a_test.setValue(true);
                is_passing_test.setValue(true);
            }

            return true;
        }

        @Override
        public boolean visit(NormalAnnotation node) {
            // A normal annotation looks like @FailingTest(value=2)
            String annotation = node.resolveTypeBinding().getQualifiedName();

            if (FailingTest.class.getName().equals(annotation)) {
                failures.setValue(intValueFromBinding(node.resolveAnnotationBinding()));
                is_a_test.setValue(true);
                is_passing_test.setValue(false);
            } else if (UseAnalyses.class.getName().equals(annotation)) {
                analyses.addAll(stringSetValueFromBinding(node.resolveAnnotationBinding()));
            }

            return true;
        }

        @Override
        public boolean visit(SingleMemberAnnotation node) {
            // A single member annotation looks like @FailingTest(2)
            String annotation = node.resolveTypeBinding().getQualifiedName();

            if (FailingTest.class.getName().equals(annotation)) {
                failures.setValue(intValueFromBinding(node.resolveAnnotationBinding()));
                is_a_test.setValue(true);
                is_passing_test.setValue(false);
            } else if (UseAnalyses.class.getName().equals(annotation)) {
                analyses.addAll(stringSetValueFromBinding(node.resolveAnnotationBinding()));
            }

            return true;
        }

        @Override
        public boolean visit(AnnotationTypeDeclaration node) {
            visitAnnotations(node);
            // visit only top-level types
            return false;
        }

        @Override
        public boolean visit(EnumDeclaration node) {
            visitAnnotations(node);
            // visit only top-level types
            return false;
        }

        @Override
        public boolean visit(TypeDeclaration node) {
            visitAnnotations(node);
            // visit only top-level types
            return false;
        }

        public void visitAnnotations(AbstractTypeDeclaration node) {
            // manually visit annotations
            for (IExtendedModifier m : (List<IExtendedModifier>) node.modifiers()) {
                if (m instanceof Annotation) {
                    ((Annotation) m).accept(this);
                }
            }
        }
    };

    // visitor mutates state
    comp_unit.accept(annotation_visitor);

    if (is_a_test.getValue() && analyses.isEmpty()) {
        throw new RuntimeException("No analyses specified: " + comp_unit.getJavaElement().getElementName());
    }

    if (is_a_test.getValue())
        return Option.some(new TestType(is_passing_test.getValue(), failures.getValue(), analyses));
    else
        return Option.none();

}

From source file:edu.uci.ics.sourcerer.extractor.ast.ReferenceExtractorVisitor.java

License:Open Source License

/**
 * This method writes://from   w w  w  .ja  va 2 s.  com
 *<ul>
 *  <li>For any marker annotation use:
 *  <ul>
 *    <li>Annotated by relation to <code>IRelationWriter</code>.</li>
 *  </ul></li>
 *</ul>
 */
@Override
public boolean visit(MarkerAnnotation node) {
    // Get the fqn
    String fqn = null;
    IAnnotationBinding binding = node.resolveAnnotationBinding();
    if (binding == null) {
        fqn = getUnknownFqn(node.getTypeName().getFullyQualifiedName());
    } else {
        ITypeBinding typeBinding = binding.getAnnotationType();
        if (typeBinding == null) {
            fqn = getUnknownFqn(binding.getName());
        } else {
            fqn = getTypeFqn(typeBinding);
        }
    }

    // Write the annotates relation
    relationWriter.writeAnnotatedBy(fqnStack.getFqn(), fqn, getLocation(node));

    return true;
}

From source file:edu.uci.ics.sourcerer.tools.java.extractor.eclipse.ReferenceExtractorVisitor.java

License:Open Source License

/**
 * This method writes:/*from   ww  w . j av a2 s  .c o  m*/
 *<ul>
 *  <li>For any marker annotation use:
 *  <ul>
 *    <li>Annotated by relation to <code>IRelationWriter</code>.</li>
 *  </ul></li>
 *</ul>
 */
@Override
public boolean visit(MarkerAnnotation node) {
    // Get the fqn
    String fqn = null;
    IAnnotationBinding binding = node.resolveAnnotationBinding();
    if (binding == null) {
        fqn = createUnknownFqn(node.getTypeName().getFullyQualifiedName());
    } else {
        ITypeBinding typeBinding = binding.getAnnotationType();
        if (typeBinding == null) {
            fqn = createUnknownFqn(binding.getName());
        } else {
            fqn = getTypeFqn(typeBinding);
        }
    }

    // Write the annotates relation
    relationWriter.writeRelation(Relation.ANNOTATED_BY, fqnStack.getFqn(), fqn, createLocation(node));

    return true;
}

From source file:org.eclipse.jdt.core.dom.ASTConverter.java

License:Open Source License

public MarkerAnnotation convert(org.eclipse.jdt.internal.compiler.ast.MarkerAnnotation annotation) {
    final MarkerAnnotation markerAnnotation = new MarkerAnnotation(this.ast);
    setTypeNameForAnnotation(annotation, markerAnnotation);
    int start = annotation.sourceStart;
    int end = annotation.declarationSourceEnd;
    markerAnnotation.setSourceRange(start, end - start + 1);
    if (this.resolveBindings) {
        recordNodes(markerAnnotation, annotation);
        markerAnnotation.resolveAnnotationBinding();
    }// ww w . j  av a  2  s.  c  om
    return markerAnnotation;
}

From source file:sharpen.core.CSharpBuilder.java

License:Open Source License

private void mapMarkerAnnotation(MarkerAnnotation annotation, CSMember member) {
    final IAnnotationBinding binding = annotation.resolveAnnotationBinding();
    final CSAttribute attribute = new CSAttribute(mappedTypeName(binding.getAnnotationType()));
    member.addAttribute(attribute);/* w  w w  .j a v a 2 s.  c o  m*/
}