Search in sources :

Example 1 with ElementAdaptor

use of com.webcohesion.enunciate.javac.decorations.adaptors.ElementAdaptor in project enunciate by stoicflame.

the class AnnotationUtils method getJavaDocTags.

public static List<JavaDoc.JavaDocTagList> getJavaDocTags(String tag, Element el) {
    if (el == null || (el instanceof TypeElement && Object.class.getName().equals(((TypeElement) el).getQualifiedName().toString()))) {
        return Collections.emptyList();
    }
    ArrayList<JavaDoc.JavaDocTagList> allTags = new ArrayList<JavaDoc.JavaDocTagList>();
    JavaDoc.JavaDocTagList tagList = null;
    if (el instanceof ElementAdaptor) {
        tagList = new JavaDoc(((ElementAdaptor) el).getDocComment(), null, null, null).get(tag);
    } else if (el instanceof DecoratedElement) {
        tagList = new JavaDoc(((DecoratedElement) el).getDocComment(), null, null, null).get(tag);
    }
    if (tagList != null && !tagList.isEmpty()) {
        allTags.add(tagList);
    }
    if (el instanceof TypeElement) {
        // include the superclass.
        TypeMirror superclass = ((TypeElement) el).getSuperclass();
        if (superclass instanceof DeclaredType) {
            Element element = ((DeclaredType) superclass).asElement();
            allTags.addAll(getJavaDocTags(tag, element));
        }
    }
    allTags.addAll(getJavaDocTags(tag, el.getEnclosingElement()));
    return allTags;
}
Also used : DecoratedElement(com.webcohesion.enunciate.javac.decorations.element.DecoratedElement) TypeMirror(javax.lang.model.type.TypeMirror) TypeElement(javax.lang.model.element.TypeElement) Element(javax.lang.model.element.Element) TypeElement(javax.lang.model.element.TypeElement) DecoratedElement(com.webcohesion.enunciate.javac.decorations.element.DecoratedElement) ArrayList(java.util.ArrayList) JavaDoc(com.webcohesion.enunciate.javac.javadoc.JavaDoc) ElementAdaptor(com.webcohesion.enunciate.javac.decorations.adaptors.ElementAdaptor) DeclaredType(javax.lang.model.type.DeclaredType)

Example 2 with ElementAdaptor

use of com.webcohesion.enunciate.javac.decorations.adaptors.ElementAdaptor in project enunciate by stoicflame.

the class DecoratedProcessingEnvironment method findSourcePosition.

public SourcePosition findSourcePosition(Element element) {
    while (element instanceof DecoratedElement) {
        element = ((DecoratedElement) element).getDelegate();
    }
    if (element instanceof ElementAdaptor) {
        return ((ElementAdaptor) element).getSourcePosition();
    }
    TreePath path = this.trees.getPath(element);
    if (path != null) {
        CompilationUnitTree cu = path.getCompilationUnit();
        SourcePositions positions = this.trees.getSourcePositions();
        long position = positions.getStartPosition(cu, path.getLeaf());
        long line = cu.getLineMap().getLineNumber(position);
        long column = cu.getLineMap().getColumnNumber(position);
        return new SourcePosition(path, cu.getSourceFile(), position, line, column);
    } else {
        return null;
    }
}
Also used : CompilationUnitTree(com.sun.source.tree.CompilationUnitTree) TreePath(com.sun.source.util.TreePath) DecoratedElement(com.webcohesion.enunciate.javac.decorations.element.DecoratedElement) SourcePositions(com.sun.source.util.SourcePositions) ElementAdaptor(com.webcohesion.enunciate.javac.decorations.adaptors.ElementAdaptor)

Aggregations

ElementAdaptor (com.webcohesion.enunciate.javac.decorations.adaptors.ElementAdaptor)2 DecoratedElement (com.webcohesion.enunciate.javac.decorations.element.DecoratedElement)2 CompilationUnitTree (com.sun.source.tree.CompilationUnitTree)1 SourcePositions (com.sun.source.util.SourcePositions)1 TreePath (com.sun.source.util.TreePath)1 JavaDoc (com.webcohesion.enunciate.javac.javadoc.JavaDoc)1 ArrayList (java.util.ArrayList)1 Element (javax.lang.model.element.Element)1 TypeElement (javax.lang.model.element.TypeElement)1 DeclaredType (javax.lang.model.type.DeclaredType)1 TypeMirror (javax.lang.model.type.TypeMirror)1