Search in sources :

Example 6 with IAnnotationBinding

use of org.eclipse.jdt.core.dom.IAnnotationBinding in project che by eclipse.

the class JavadocFinder method addValue.

private void addValue(StringBuffer buf, IJavaElement element, Object value) throws URISyntaxException {
    // Note: To be bug-compatible with Javadoc from Java 5/6/7, we currently don't escape HTML tags in String-valued annotations.
    if (value instanceof ITypeBinding) {
        ITypeBinding typeBinding = (ITypeBinding) value;
        IJavaElement type = typeBinding.getJavaElement();
        if (type == null) {
            buf.append(typeBinding.getName());
        } else {
            String uri = JavaElementLinks.createURI(baseHref, type);
            String name = type.getElementName();
            addLink(buf, uri, name);
        }
        //$NON-NLS-1$
        buf.append(".class");
    } else if (value instanceof IVariableBinding) {
        // only enum constants
        IVariableBinding variableBinding = (IVariableBinding) value;
        IJavaElement variable = variableBinding.getJavaElement();
        String uri = JavaElementLinks.createURI(baseHref, variable);
        String name = variable.getElementName();
        addLink(buf, uri, name);
    } else if (value instanceof IAnnotationBinding) {
        IAnnotationBinding annotationBinding = (IAnnotationBinding) value;
        addAnnotation(buf, element, annotationBinding);
    } else if (value instanceof String) {
        buf.append(ASTNodes.getEscapedStringLiteral((String) value));
    } else if (value instanceof Character) {
        buf.append(ASTNodes.getEscapedCharacterLiteral((Character) value));
    } else if (value instanceof Object[]) {
        Object[] values = (Object[]) value;
        buf.append('{');
        for (int i = 0; i < values.length; i++) {
            if (i > 0) {
                buf.append(JavaElementLabels.COMMA_STRING);
            }
            addValue(buf, element, values[i]);
        }
        buf.append('}');
    } else {
        // primitive types (except char) or null
        buf.append(String.valueOf(value));
    }
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) IAnnotationBinding(org.eclipse.jdt.core.dom.IAnnotationBinding) ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding) IVariableBinding(org.eclipse.jdt.core.dom.IVariableBinding)

Example 7 with IAnnotationBinding

use of org.eclipse.jdt.core.dom.IAnnotationBinding in project che by eclipse.

the class JavadocFinder method getAnnotations.

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;
    }
    IBinding binding = null;
    //TODO
    //getHoveredASTNode(editorInputElement, hoverRegion);
    ASTNode node = null;
    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]);
        //$NON-NLS-1$
        buf.append("<br>");
    }
    return buf.toString();
}
Also used : IAnnotatable(org.eclipse.jdt.core.IAnnotatable) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) IAnnotationBinding(org.eclipse.jdt.core.dom.IAnnotationBinding) IBinding(org.eclipse.jdt.core.dom.IBinding) ASTNode(org.eclipse.jdt.core.dom.ASTNode)

Example 8 with IAnnotationBinding

use of org.eclipse.jdt.core.dom.IAnnotationBinding in project bndtools by bndtools.

the class MemberValuePairLocationRetriever method visit.

/**
     * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.SingleMemberAnnotation)
     */
@Override
public boolean visit(SingleMemberAnnotation node) {
    final IAnnotationBinding annotationBinding = node.resolveAnnotationBinding();
    if (annotationBinding != null) {
        final String nodeName = annotationBinding.getAnnotationType().getQualifiedName();
        boolean match;
        try {
            match = this.annotationNameMatch.test(nodeName);
        } catch (Exception e) {
            match = false;
        }
        if (match) {
            this.locatedSourceRange = new SourceRange(node.getValue().getStartPosition(), node.getValue().getLength());
        }
    }
    return false;
}
Also used : IAnnotationBinding(org.eclipse.jdt.core.dom.IAnnotationBinding) ISourceRange(org.eclipse.jdt.core.ISourceRange) SourceRange(org.eclipse.jdt.core.SourceRange)

Aggregations

IAnnotationBinding (org.eclipse.jdt.core.dom.IAnnotationBinding)8 ITypeBinding (org.eclipse.jdt.core.dom.ITypeBinding)5 ArrayType (org.eclipse.jdt.core.dom.ArrayType)3 Dimension (org.eclipse.jdt.core.dom.Dimension)3 PrimitiveType (org.eclipse.jdt.core.dom.PrimitiveType)3 Type (org.eclipse.jdt.core.dom.Type)3 ArrayList (java.util.ArrayList)2 ASTNode (org.eclipse.jdt.core.dom.ASTNode)2 Annotation (org.eclipse.jdt.core.dom.Annotation)2 ParameterizedType (org.eclipse.jdt.core.dom.ParameterizedType)2 UnionType (org.eclipse.jdt.core.dom.UnionType)2 List (java.util.List)1 IAnnotatable (org.eclipse.jdt.core.IAnnotatable)1 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)1 IJavaElement (org.eclipse.jdt.core.IJavaElement)1 IJavaProject (org.eclipse.jdt.core.IJavaProject)1 IMethod (org.eclipse.jdt.core.IMethod)1 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)1 ISourceRange (org.eclipse.jdt.core.ISourceRange)1 SourceRange (org.eclipse.jdt.core.SourceRange)1