Search in sources :

Example 1 with DecoratedElement

use of com.webcohesion.enunciate.javac.decorations.element.DecoratedElement in project enunciate by stoicflame.

the class Styles method gatherStyles.

/**
 * Gather facets.
 *
 * @param declaration The declaration on which to gather facets.
 * @return The facets gathered on the declaration.
 */
public static Set<String> gatherStyles(Element declaration, Map<String, String> annotationStyles) {
    Set<String> bucket = new TreeSet<String>();
    if (declaration != null) {
        com.webcohesion.enunciate.metadata.Style style = declaration.getAnnotation(com.webcohesion.enunciate.metadata.Style.class);
        if (style != null) {
            bucket.add(style.value());
        }
        com.webcohesion.enunciate.metadata.Styles facets = declaration.getAnnotation(com.webcohesion.enunciate.metadata.Styles.class);
        if (facets != null) {
            for (com.webcohesion.enunciate.metadata.Style s : facets.value()) {
                bucket.add(s.value());
            }
        }
        List<? extends AnnotationMirror> annotationMirrors = declaration.getAnnotationMirrors();
        for (AnnotationMirror annotationMirror : annotationMirrors) {
            DeclaredType annotationType = annotationMirror.getAnnotationType();
            if (annotationType != null) {
                Element annotationDeclaration = annotationType.asElement();
                if (annotationDeclaration instanceof TypeElement) {
                    String configuredStyle = annotationStyles.get(((TypeElement) annotationDeclaration).getQualifiedName().toString());
                    if (configuredStyle != null) {
                        bucket.add(configuredStyle);
                    }
                }
                style = annotationDeclaration.getAnnotation(com.webcohesion.enunciate.metadata.Style.class);
                if (style != null) {
                    bucket.add(style.value());
                }
                facets = annotationDeclaration.getAnnotation(com.webcohesion.enunciate.metadata.Styles.class);
                if (facets != null) {
                    for (com.webcohesion.enunciate.metadata.Style s : facets.value()) {
                        bucket.add(s.value());
                    }
                }
            }
        }
        if (declaration instanceof DecoratedElement) {
            JavaDoc.JavaDocTagList styleTags = ((DecoratedElement) declaration).getJavaDoc().get("style");
            if (styleTags != null) {
                for (String styleTag : styleTags) {
                    bucket.add(styleTag);
                }
            }
        }
    }
    return bucket;
}
Also used : DecoratedElement(com.webcohesion.enunciate.javac.decorations.element.DecoratedElement) 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) JavaDoc(com.webcohesion.enunciate.javac.javadoc.JavaDoc) AnnotationMirror(javax.lang.model.element.AnnotationMirror) TreeSet(java.util.TreeSet) DecoratedDeclaredType(com.webcohesion.enunciate.javac.decorations.type.DecoratedDeclaredType) DeclaredType(javax.lang.model.type.DeclaredType)

Example 2 with DecoratedElement

use of com.webcohesion.enunciate.javac.decorations.element.DecoratedElement in project enunciate by stoicflame.

the class DecoratedElements method printElements.

@Override
public void printElements(Writer w, Element... elements) {
    Element[] copy = new Element[elements.length];
    for (int i = 0; i < elements.length; i++) {
        Element e = elements[i];
        while (e instanceof DecoratedElement) {
            e = ((DecoratedElement) e).getDelegate();
        }
        copy[i] = e;
    }
    delegate.printElements(w, copy);
}
Also used : DecoratedElement(com.webcohesion.enunciate.javac.decorations.element.DecoratedElement) DecoratedTypeElement(com.webcohesion.enunciate.javac.decorations.element.DecoratedTypeElement) DecoratedElement(com.webcohesion.enunciate.javac.decorations.element.DecoratedElement) DecoratedExecutableElement(com.webcohesion.enunciate.javac.decorations.element.DecoratedExecutableElement)

Example 3 with DecoratedElement

use of com.webcohesion.enunciate.javac.decorations.element.DecoratedElement in project enunciate by stoicflame.

the class DataTypeExampleImpl method getDocumentationExampleTags.

private JavaDoc.JavaDocTagList getDocumentationExampleTags(Member member) {
    JavaDoc.JavaDocTagList tags = member.getJavaDoc().get("documentationExample");
    if (tags == null || tags.isEmpty()) {
        DecoratedTypeMirror accessorType = member.getBareAccessorType();
        if (accessorType instanceof DecoratedDeclaredType) {
            Element element = ((DecoratedDeclaredType) accessorType).asElement();
            tags = element instanceof DecoratedElement ? ((DecoratedElement) element).getJavaDoc().get("documentationExample") : null;
        }
    }
    return tags;
}
Also used : DecoratedDeclaredType(com.webcohesion.enunciate.javac.decorations.type.DecoratedDeclaredType) DecoratedElement(com.webcohesion.enunciate.javac.decorations.element.DecoratedElement) DecoratedTypeMirror(com.webcohesion.enunciate.javac.decorations.type.DecoratedTypeMirror) TypeElement(javax.lang.model.element.TypeElement) DecoratedElement(com.webcohesion.enunciate.javac.decorations.element.DecoratedElement) Element(javax.lang.model.element.Element) JavaDoc(com.webcohesion.enunciate.javac.javadoc.JavaDoc)

Example 4 with DecoratedElement

use of com.webcohesion.enunciate.javac.decorations.element.DecoratedElement in project enunciate by stoicflame.

the class ComplexTypeExampleImpl method getDocumentationExampleTags.

private JavaDoc.JavaDocTagList getDocumentationExampleTags(Accessor member) {
    JavaDoc.JavaDocTagList tags = member.getJavaDoc().get("documentationExample");
    if (tags == null || tags.isEmpty()) {
        DecoratedTypeMirror accessorType = member.getBareAccessorType();
        if (accessorType instanceof DecoratedDeclaredType) {
            javax.lang.model.element.Element element = ((DecoratedDeclaredType) accessorType).asElement();
            tags = element instanceof DecoratedElement ? ((DecoratedElement) element).getJavaDoc().get("documentationExample") : null;
        }
    }
    return tags;
}
Also used : DecoratedDeclaredType(com.webcohesion.enunciate.javac.decorations.type.DecoratedDeclaredType) DecoratedElement(com.webcohesion.enunciate.javac.decorations.element.DecoratedElement) DecoratedTypeMirror(com.webcohesion.enunciate.javac.decorations.type.DecoratedTypeMirror) JavaDoc(com.webcohesion.enunciate.javac.javadoc.JavaDoc)

Example 5 with DecoratedElement

use of com.webcohesion.enunciate.javac.decorations.element.DecoratedElement in project enunciate by stoicflame.

the class Accessor method getXmlIDAccessor.

/**
 * Gets the xml id accessor for the specified class type (recursively through superclasses).
 *
 * @param classType The class type.
 * @return The xml id accessor.
 */
private DecoratedElement getXmlIDAccessor(DecoratedDeclaredType classType) {
    if (classType == null) {
        return null;
    }
    DecoratedTypeElement declaration = (DecoratedTypeElement) classType.asElement();
    if ((declaration == null) || (Object.class.getName().equals(declaration.getQualifiedName().toString()))) {
        return null;
    }
    for (VariableElement field : ElementFilter.fieldsIn(declaration.getEnclosedElements())) {
        if (field.getAnnotation(XmlID.class) != null) {
            return (DecoratedElement) field;
        }
    }
    for (PropertyElement property : declaration.getProperties()) {
        if (property.getAnnotation(XmlID.class) != null) {
            return property;
        }
    }
    TypeMirror superclass = declaration.getSuperclass();
    if (superclass == null || superclass.getKind() == TypeKind.NONE) {
        return null;
    }
    return getXmlIDAccessor((DecoratedDeclaredType) superclass);
}
Also used : DecoratedTypeElement(com.webcohesion.enunciate.javac.decorations.element.DecoratedTypeElement) DecoratedElement(com.webcohesion.enunciate.javac.decorations.element.DecoratedElement) DecoratedTypeMirror(com.webcohesion.enunciate.javac.decorations.type.DecoratedTypeMirror) VariableElement(javax.lang.model.element.VariableElement) PropertyElement(com.webcohesion.enunciate.javac.decorations.element.PropertyElement)

Aggregations

DecoratedElement (com.webcohesion.enunciate.javac.decorations.element.DecoratedElement)11 Element (javax.lang.model.element.Element)6 TypeElement (javax.lang.model.element.TypeElement)6 JavaDoc (com.webcohesion.enunciate.javac.javadoc.JavaDoc)5 DecoratedDeclaredType (com.webcohesion.enunciate.javac.decorations.type.DecoratedDeclaredType)4 DecoratedTypeMirror (com.webcohesion.enunciate.javac.decorations.type.DecoratedTypeMirror)4 DeclaredType (javax.lang.model.type.DeclaredType)4 DecoratedTypeElement (com.webcohesion.enunciate.javac.decorations.element.DecoratedTypeElement)3 VariableElement (javax.lang.model.element.VariableElement)3 TypeMirror (javax.lang.model.type.TypeMirror)3 ElementAdaptor (com.webcohesion.enunciate.javac.decorations.adaptors.ElementAdaptor)2 ArrayList (java.util.ArrayList)2 ExecutableElement (javax.lang.model.element.ExecutableElement)2 CompilationUnitTree (com.sun.source.tree.CompilationUnitTree)1 SourcePositions (com.sun.source.util.SourcePositions)1 TreePath (com.sun.source.util.TreePath)1 DataType (com.webcohesion.enunciate.api.datatype.DataType)1 Property (com.webcohesion.enunciate.api.datatype.Property)1 Syntax (com.webcohesion.enunciate.api.datatype.Syntax)1 Value (com.webcohesion.enunciate.api.datatype.Value)1