in = annotatable.getAnnotations(); } catch (Exception e) { return out;
public static boolean isHiddenGeneratedElement(IJavaElement element) { // generated elements are annotated with @Generated and they need to be filtered out if (element instanceof IAnnotatable) { try { IAnnotation[] annotations = ((IAnnotatable) element).getAnnotations(); if (annotations.length != 0) { for (IAnnotation annotation : annotations) { if (isSilencedGeneratedAnnotation(annotation)) { return true; } } } } catch (JavaModelException e) { //ignore } } return false; }
/** Replies the annotation with the given qualified name. * * @param element the annoted element. * @param qualifiedName the qualified name of the element. * @return the annotation, or <code>null</code> if the element is not annoted. */ public IAnnotation getAnnotation(IAnnotatable element, String qualifiedName) { if (element != null) { try { final int separator = qualifiedName.lastIndexOf('.'); final String simpleName; if (separator >= 0 && separator < (qualifiedName.length() - 1)) { simpleName = qualifiedName.substring(separator + 1, qualifiedName.length()); } else { simpleName = qualifiedName; } for (final IAnnotation annotation : element.getAnnotations()) { final String name = annotation.getElementName(); if (name.equals(simpleName) || name.equals(qualifiedName)) { return annotation; } } } catch (JavaModelException e) { // } } return null; }
/** * Create an handle for a local variable declaration (may be a local variable or type parameter). */ protected IJavaElement createHandle(Annotation annotation, IAnnotatable parent) { if (parent == null) return null; TypeReference typeRef = annotation.type; char[][] typeName = typeRef.getTypeName(); String name = new String(typeName[typeName.length-1]); try { IAnnotation[] annotations = parent.getAnnotations(); int length = annotations == null ? 0 : annotations.length; for (int i=0; i<length; i++) { if (annotations[i].getElementName().equals(name)) { return annotations[i]; } } } catch (JavaModelException jme) { // skip } return null; } /*
private static 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= getHoveredNodeBinding(element, editorInputElement, hoverRegion); 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, annotations[i], true); buf.append("<br>"); //$NON-NLS-1$ } return buf.toString(); }
String name = new String(typeName[typeName.length-1]); try { IAnnotation[] annotations = parent.getAnnotations(); int length = annotations == null ? 0 : annotations.length; for (int i=0; i<length; i++) {
String name = new String(typeName[typeName.length-1]); try { IAnnotation[] annotations = parent.getAnnotations(); int length = annotations == null ? 0 : annotations.length; for (int i=0; i<length; i++) {
String name = new String(typeName[typeName.length-1]); try { IAnnotation[] annotations = parent.getAnnotations(); int length = annotations == null ? 0 : annotations.length; for (int i=0; i<length; i++) {
String name = new String(typeName[typeName.length-1]); try { IAnnotation[] annotations = parent.getAnnotations(); int length = annotations == null ? 0 : annotations.length; for (int i=0; i<length; i++) {
private Annotation[] convertAnnotations(IAnnotatable element) throws JavaModelException { IAnnotation[] annotations = element.getAnnotations(); int length = annotations.length; Annotation[] astAnnotations = new Annotation[length];
return null; if (((IAnnotatable)element).getAnnotations().length == 0) return null;
private Annotation[] convertAnnotations(IAnnotatable element) throws JavaModelException { IAnnotation[] annotations = element.getAnnotations(); int length = annotations.length; Annotation[] astAnnotations = new Annotation[length];
private Annotation[] convertAnnotations(IAnnotatable element) throws JavaModelException { IAnnotation[] annotations = element.getAnnotations(); int length = annotations.length; Annotation[] astAnnotations = new Annotation[length];
private Annotation[] convertAnnotations(IAnnotatable element) throws JavaModelException { IAnnotation[] annotations = element.getAnnotations(); int length = annotations.length; Annotation[] astAnnotations = new Annotation[length];
private Annotation[] convertAnnotations(IAnnotatable element) throws JavaModelException { IAnnotation[] annotations = element.getAnnotations(); int length = annotations.length; Annotation[] astAnnotations = new Annotation[length];
protected void appendFlags(final IMember member) throws JavaModelException { if (member instanceof IAnnotatable) for (IAnnotation annotation : ((IAnnotatable) member).getAnnotations()) { appendAnnotation(annotation); } int flags= member.getFlags(); final int kind= member.getElementType(); if (kind == IJavaElement.TYPE) { flags&= ~Flags.AccSuper; final IType type= (IType) member; if (!type.isMember()) flags&= ~Flags.AccPrivate; if (Flags.isEnum(flags)) flags&= ~Flags.AccAbstract; } if (Flags.isEnum(flags)) flags&= ~Flags.AccFinal; if (kind == IJavaElement.METHOD) { flags&= ~Flags.AccVarargs; flags&= ~Flags.AccBridge; } if (flags != 0) fBuffer.append(Flags.toString(flags)); }
private Annotation[] convertAnnotations(IAnnotatable element) throws JavaModelException { IAnnotation[] annotations = element.getAnnotations(); int length = annotations.length; Annotation[] astAnnotations = new Annotation[length];
private Annotation[] convertAnnotations(IAnnotatable element) throws JavaModelException { IAnnotation[] annotations = element.getAnnotations(); int length = annotations.length; Annotation[] astAnnotations = new Annotation[length];
protected void appendFlags(final IMember member) throws JavaModelException { if (member instanceof IAnnotatable) for (IAnnotation annotation : ((IAnnotatable) member).getAnnotations()) { appendAnnotation(annotation); } int flags= member.getFlags(); final int kind= member.getElementType(); if (kind == IJavaElement.TYPE) { flags&= ~Flags.AccSuper; final IType type= (IType) member; if (!type.isMember()) flags&= ~Flags.AccPrivate; if (Flags.isEnum(flags)) flags&= ~Flags.AccAbstract; } if (Flags.isEnum(flags)) flags&= ~Flags.AccFinal; if (kind == IJavaElement.METHOD) { flags&= ~Flags.AccVarargs; flags&= ~Flags.AccBridge; } if (flags != 0) fBuffer.append(Flags.toString(flags)); }
@Override protected Position getSourceRange(IType type, IDocument doc, IReference reference) throws CoreException, BadLocationException { IApiMember member = reference.getMember(); if (member != null) { IAnnotatable annotable = findAnnotableElement(type, member, reference, doc); if (annotable != null) { IAnnotation[] annotations = annotable.getAnnotations(); String typename = Signatures.getSimpleTypeName(reference.getResolvedReference().getName()); for (IAnnotation annotation : annotations) { if (annotation.getElementName().equals(typename)) { ISourceRange range = annotation.getNameRange(); if (range != null) { // select the '@' as well - augment offset and // length accordingly return new Position(range.getOffset() - 1, range.getLength() + 1); } else { break; } } } } } return defaultSourcePosition(type, reference); }