Example usage for org.eclipse.jdt.core.dom IBinding getAnnotations

List of usage examples for org.eclipse.jdt.core.dom IBinding getAnnotations

Introduction

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

Prototype

public IAnnotationBinding[] getAnnotations();

Source Link

Document

Returns the resolved declaration annotations associated with this binding.

Usage

From source file:com.codenvy.ide.ext.java.server.JavadocFinder.java

License:Open Source License

private String getAnnotations(IJavaElement element, ITypeRoot editorInputElement, IRegion hoverRegion)
        throws URISyntaxException, JavaModelException {
    if (!(element instanceof IPackageFragment)) {
        if (!(element instanceof IAnnotatable))
            return null;

        if (((IAnnotatable) element).getAnnotations().length == 0)
            return null;
    }//  ww w  .jav a2 s  . c  o m

    IBinding binding = null;
    //TODO
    ASTNode node = null; //getHoveredASTNode(editorInputElement, hoverRegion);

    if (node == null) {
        //todo use ast ported parser,that uses our java model
        //            ASTParser p = ASTParser.newParser(ASTProvider.SHARED_AST_LEVEL);
        //            p.setProject(element.getJavaProject());
        //            p.setBindingsRecovery(true);
        //            try {
        //                binding = p.createBindings(new IJavaElement[]{element}, null)[0];
        //            } catch (OperationCanceledException e) {
        //                return null;
        //            }

    } else {
        binding = resolveBinding(node);
    }

    if (binding == null)
        return null;

    IAnnotationBinding[] annotations = binding.getAnnotations();
    if (annotations.length == 0)
        return null;

    StringBuffer buf = new StringBuffer();
    for (int i = 0; i < annotations.length; i++) {
        //TODO: skip annotations that don't have an @Documented annotation?
        addAnnotation(buf, element, annotations[i]);
        buf.append("<br>"); //$NON-NLS-1$
    }

    return buf.toString();
}

From source file:com.google.devtools.j2cpp.types.Types.java

License:Open Source License

public static boolean hasAnyAnnotation(IBinding binding, Class<?>[] annotations) {
    for (IAnnotationBinding annotation : binding.getAnnotations()) {
        String name = annotation.getAnnotationType().getQualifiedName();
        for (Class<?> annotationClass : annotations) {
            if (name.equals(annotationClass.getName())) {
                return true;
            }/*from w  w  w  . java 2 s  .  c o m*/
        }
    }
    return false;
}

From source file:com.google.devtools.j2objc.jdt.AbstractBinding.java

License:Apache License

public void addAnnotations(IBinding binding) {
    annotations.addAll(Arrays.asList(binding.getAnnotations()));
}

From source file:com.google.devtools.j2objc.jdt.JdtBinding.java

License:Apache License

JdtBinding(IBinding binding) {
    this.binding = binding;
    if (binding != null) {
        JdtAnnotationBinding[] jdtAnnotations = BindingConverter.wrapBindings(binding.getAnnotations());
        annotations = Lists.newArrayList((IAnnotationBinding[]) jdtAnnotations);
    } else {//ww  w  . j ava2s .co m
        annotations = new ArrayList<>();
    }
}

From source file:com.google.devtools.j2objc.util.BindingUtil.java

License:Apache License

/**
 * Less strict version of the above where we don't care about the annotation's package.
 *//*from   w  w  w  .  j  av a 2 s . c  o m*/
public static boolean hasNamedAnnotation(IBinding binding, String annotationName) {
    for (IAnnotationBinding annotation : binding.getAnnotations()) {
        if (annotation.getName().equals(annotationName)) {
            return true;
        }
    }
    return false;
}

From source file:com.google.devtools.j2objc.util.BindingUtil.java

License:Apache License

public static IAnnotationBinding getAnnotation(IBinding binding, Class<?> annotationClass) {
    for (IAnnotationBinding annotation : binding.getAnnotations()) {
        if (typeEqualsClass(annotation.getAnnotationType(), annotationClass)) {
            return annotation;
        }//  w w w .j  a  v  a  2s . com
    }
    return null;
}

From source file:com.ibm.wala.cast.java.translator.jdt.JDTJava2CAstTranslator.java

License:Open Source License

private Set<CAstAnnotation> handleAnnotations(IBinding binding) {
    IAnnotationBinding[] annotations = binding.getAnnotations();

    if (annotations == null || annotations.length == 0) {
        return null;
    }/*from  w  w  w  . ja  v a 2  s . co m*/

    Set<CAstAnnotation> castAnnotations = HashSetFactory.make();
    for (IAnnotationBinding annotation : annotations) {
        ITypeBinding annotationTypeBinding = annotation.getAnnotationType();
        final CAstType annotationType = fTypeDict.getCAstTypeFor(annotationTypeBinding);
        final Map<String, Object> args = HashMapFactory.make();
        for (IMemberValuePairBinding mvpb : annotation.getAllMemberValuePairs()) {
            String name = mvpb.getName();
            Object value = mvpb.getValue();
            args.put(name, value);
        }
        castAnnotations.add(new CAstAnnotation() {
            @Override
            public CAstType getType() {
                return annotationType;
            }

            @Override
            public Map<String, Object> getArguments() {
                return args;
            }

            @Override
            public String toString() {
                return annotationType.getName() + args;
            }
        });
    }

    return castAnnotations;
}

From source file:nl.han.ica.core.util.ASTUtil.java

public static int getAnnotationsSize(IBinding binding) {
    if (binding.getAnnotations() != null) {
        return binding.getAnnotations().length;
    }/*from w  w w .  j a  va  2 s  .c om*/
    return 0;
}

From source file:org.eclipse.xtext.common.types.access.jdt.JdtBasedTypeFactory.java

License:Open Source License

protected void createAnnotationValues(IBinding annotated, JvmAnnotationTarget result) {
    try {//from w  ww .  ja  va  2  s.  com
        resolveAnnotations.start();
        IAnnotationBinding[] annotationBindings = annotated.getAnnotations();
        if (annotationBindings.length != 0) {
            InternalEList<JvmAnnotationReference> annotations = (InternalEList<JvmAnnotationReference>) result
                    .getAnnotations();
            for (IAnnotationBinding annotation : annotationBindings) {
                annotations.addUnique(createAnnotationReference(annotation));
            }
        }
    } catch (AbortCompilation aborted) {
        if (aborted.problem.getID() == IProblem.IsClassPathCorrect) {
            // ignore
        } else {
            log.info("Couldn't resolve annotations of " + annotated, aborted);
        }
    } finally {
        resolveAnnotations.stop();
    }
}

From source file:org.eclipselabs.nullness.NullAnnotationFinder.java

License:Open Source License

private Boolean getDefaultNonNullState(IBinding binding) {
    IAnnotationBinding[] annotations = binding.getAnnotations();
    for (IAnnotationBinding annotation : annotations) {
        if (isDefaultNonNullAnnotation(getAnnotationTypeName(annotation))) {
            // TODO check the value of 'value'
            return Boolean.TRUE;
        }//from   w ww  . ja  va  2s .  c  o  m
    }
    return null;
}