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));
}
}
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();
}
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;
}
Aggregations