Search in sources :

Example 1 with DecoratedTypeElement

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

the class EnunciateJaxbContext method addReferencedTypeDefinitions.

/**
 * Adds the referenced type definitions for the specified local element declaration.
 *
 * @param led The local element declaration.
 */
protected void addReferencedTypeDefinitions(LocalElementDeclaration led, LinkedList<Element> stack) {
    addSeeAlsoTypeDefinitions(led, stack);
    DecoratedTypeElement scope = led.getElementScope();
    if (scope != null && scope.getKind() == ElementKind.CLASS && !isKnownTypeDefinition(scope)) {
        add(createTypeDefinition(scope), stack);
    }
    TypeElement typeElement = null;
    TypeMirror elementType = led.getElementType();
    if (elementType instanceof DeclaredType) {
        Element element = ((DeclaredType) elementType).asElement();
        if (element instanceof TypeElement) {
            typeElement = (TypeElement) element;
        }
    }
    if (scope != null && scope.getKind() == ElementKind.CLASS && !isKnownTypeDefinition(typeElement)) {
        add(createTypeDefinition(typeElement), stack);
    }
}
Also used : DecoratedTypeElement(com.webcohesion.enunciate.javac.decorations.element.DecoratedTypeElement) DecoratedTypeMirror(com.webcohesion.enunciate.javac.decorations.type.DecoratedTypeMirror) TypeElement(javax.lang.model.element.TypeElement) DecoratedTypeElement(com.webcohesion.enunciate.javac.decorations.element.DecoratedTypeElement) TypeElement(javax.lang.model.element.TypeElement) DecoratedTypeElement(com.webcohesion.enunciate.javac.decorations.element.DecoratedTypeElement) ExecutableElement(javax.lang.model.element.ExecutableElement) JAXBElement(javax.xml.bind.JAXBElement) Element(javax.lang.model.element.Element) DecoratedDeclaredType(com.webcohesion.enunciate.javac.decorations.type.DecoratedDeclaredType)

Example 2 with DecoratedTypeElement

use of com.webcohesion.enunciate.javac.decorations.element.DecoratedTypeElement 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)

Example 3 with DecoratedTypeElement

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

the class LocalElementDeclaration method getElementScope.

/**
 * The scope of the local element.
 *
 * @return The scope of the local element.
 */
public DecoratedTypeElement getElementScope() {
    DecoratedTypeElement declaration = null;
    DecoratedTypeMirror typeMirror = Annotations.mirrorOf(new Callable<Class<?>>() {

        @Override
        public Class<?> call() throws Exception {
            return elementDecl.scope();
        }
    }, this.env, XmlElementDecl.GLOBAL.class);
    if (typeMirror != null) {
        declaration = (DecoratedTypeElement) ((DeclaredType) typeMirror).asElement();
    }
    return declaration;
}
Also used : DecoratedTypeElement(com.webcohesion.enunciate.javac.decorations.element.DecoratedTypeElement) DecoratedTypeMirror(com.webcohesion.enunciate.javac.decorations.type.DecoratedTypeMirror) XmlElementDecl(javax.xml.bind.annotation.XmlElementDecl) DeclaredType(javax.lang.model.type.DeclaredType)

Example 4 with DecoratedTypeElement

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

the class LombokDecoration method visitType.

@Override
public Void visitType(TypeElement e, DecoratedProcessingEnvironment env) {
    DecoratedTypeElement typeElement = (DecoratedTypeElement) e;
    List<DecoratedExecutableElement> methods = getLombokMethodDecorations(typeElement, env);
    typeElement.getMethods().addAll(methods);
    return null;
}
Also used : DecoratedTypeElement(com.webcohesion.enunciate.javac.decorations.element.DecoratedTypeElement) DecoratedExecutableElement(com.webcohesion.enunciate.javac.decorations.element.DecoratedExecutableElement)

Example 5 with DecoratedTypeElement

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

the class ApiDocsJavaDocTagHandler method onInlineTag.

@Override
public String onInlineTag(String tagName, String tagText, DecoratedElement context) {
    if ("link".equals(tagName)) {
        JavaDocLink link = JavaDocLink.parse(tagText);
        String classRef = link.getClassName();
        String subelementRef = link.getMemberName();
        String value = link.getLabel();
        // use the current context as the class ref.
        if ("".equals(classRef)) {
            DecoratedElement type = context;
            while (!(type instanceof DecoratedTypeElement)) {
                type = (DecoratedElement) type.getEnclosingElement();
                if (type == null || type instanceof PackageElement) {
                    break;
                }
            }
            if (type instanceof DecoratedTypeElement) {
                classRef = ((DecoratedTypeElement) type).getQualifiedName().toString();
            }
        }
        if (!"".equals(classRef)) {
            if (classRef.indexOf('.') < 0) {
                // if it's a local reference, assume it's in the current package.
                DecoratedElement pckg = context;
                while (!(pckg instanceof DecoratedPackageElement)) {
                    pckg = (DecoratedElement) pckg.getEnclosingElement();
                    if (pckg == null) {
                        break;
                    }
                }
                if (pckg != null) {
                    classRef = ((DecoratedPackageElement) pckg).getQualifiedName() + "." + classRef;
                }
            }
            // now find the reference
            Set<Syntax> syntaxes = this.registry.getSyntaxes(this.context);
            for (Syntax syntax : syntaxes) {
                List<DataType> dataTypes = syntax.findDataTypes(classRef);
                if (dataTypes != null && !dataTypes.isEmpty()) {
                    DataType dataType = dataTypes.get(0);
                    Value dataTypeValue = dataType.findValue(subelementRef);
                    if (dataTypeValue != null) {
                        return "<a href=\"" + dataType.getSlug() + ".html#" + dataTypeValue.getValue() + "\">" + (value != null ? value : dataTypeValue.getValue()) + "</a>";
                    }
                    Property property = dataType.findProperty(subelementRef);
                    if (property != null) {
                        return "<a href=\"" + dataType.getSlug() + ".html#prop-" + property.getName() + "\">" + (value != null ? value : property.getName()) + "</a>";
                    }
                    return "<a href=\"" + dataType.getSlug() + ".html\">" + (value != null ? value : (subelementRef.isEmpty() ? dataType.getLabel() : subelementRef)) + "</a>";
                }
            }
            List<ResourceApi> resourceApis = this.registry.getResourceApis(this.context);
            for (ResourceApi resourceApi : resourceApis) {
                Method method = resourceApi.findMethodFor(classRef, subelementRef);
                if (method != null) {
                    if (value == null) {
                        value = method.getLabel() + " " + method.getResource().getGroup().getLabel();
                    }
                    return "<a href=\"" + method.getResource().getGroup().getSlug() + ".html#" + method.getSlug() + "\">" + value + "</a>";
                } else {
                    ResourceGroup resourceGroup = resourceApi.findResourceGroupFor(classRef);
                    if (resourceGroup != null) {
                        if (value == null) {
                            value = resourceGroup.getLabel();
                        }
                        return "<a href=\"" + resourceGroup.getSlug() + ".html\">" + value + "</a>";
                    }
                }
            }
            List<ServiceApi> serviceApis = this.registry.getServiceApis(this.context);
            for (ServiceApi serviceApi : serviceApis) {
                Operation operation = serviceApi.findOperationFor(classRef, subelementRef);
                if (operation != null) {
                    if (value == null) {
                        value = operation.getName();
                    }
                    return "<a href=\"" + operation.getService().getSlug() + ".html#" + operation.getSlug() + "\">" + value + "</a>";
                } else {
                    Service service = serviceApi.findServiceFor(classRef);
                    if (service != null) {
                        if (value == null) {
                            value = service.getLabel();
                        }
                        return "<a href=\"" + service.getSlug() + ".html\">" + value + "</a>";
                    }
                }
            }
        }
        return value != null ? value : tagText.trim();
    } else if ("code".equals(tagName)) {
        return "<code>" + tagText + "</code>";
    }
    return tagText;
}
Also used : JavaDocLink(com.webcohesion.enunciate.javac.javadoc.JavaDocLink) DecoratedElement(com.webcohesion.enunciate.javac.decorations.element.DecoratedElement) ServiceApi(com.webcohesion.enunciate.api.services.ServiceApi) Service(com.webcohesion.enunciate.api.services.Service) Method(com.webcohesion.enunciate.api.resources.Method) Operation(com.webcohesion.enunciate.api.services.Operation) ResourceApi(com.webcohesion.enunciate.api.resources.ResourceApi) DecoratedTypeElement(com.webcohesion.enunciate.javac.decorations.element.DecoratedTypeElement) Value(com.webcohesion.enunciate.api.datatype.Value) DataType(com.webcohesion.enunciate.api.datatype.DataType) PackageElement(javax.lang.model.element.PackageElement) DecoratedPackageElement(com.webcohesion.enunciate.javac.decorations.element.DecoratedPackageElement) Syntax(com.webcohesion.enunciate.api.datatype.Syntax) DecoratedPackageElement(com.webcohesion.enunciate.javac.decorations.element.DecoratedPackageElement) Property(com.webcohesion.enunciate.api.datatype.Property) ResourceGroup(com.webcohesion.enunciate.api.resources.ResourceGroup)

Aggregations

DecoratedTypeElement (com.webcohesion.enunciate.javac.decorations.element.DecoratedTypeElement)11 DecoratedTypeMirror (com.webcohesion.enunciate.javac.decorations.type.DecoratedTypeMirror)5 EnunciateException (com.webcohesion.enunciate.EnunciateException)3 ClientLibraryArtifact (com.webcohesion.enunciate.artifacts.ClientLibraryArtifact)3 FileArtifact (com.webcohesion.enunciate.artifacts.FileArtifact)3 FacetFilter (com.webcohesion.enunciate.facets.FacetFilter)3 EnunciateJacksonContext (com.webcohesion.enunciate.modules.jackson.EnunciateJacksonContext)3 TypeDefinition (com.webcohesion.enunciate.modules.jackson.model.TypeDefinition)3 EnunciateJackson1Context (com.webcohesion.enunciate.modules.jackson1.EnunciateJackson1Context)3 TemplateException (freemarker.template.TemplateException)3 File (java.io.File)3 IOException (java.io.IOException)3 URL (java.net.URL)3 DecoratedElement (com.webcohesion.enunciate.javac.decorations.element.DecoratedElement)2 PropertyElement (com.webcohesion.enunciate.javac.decorations.element.PropertyElement)2 DecoratedDeclaredType (com.webcohesion.enunciate.javac.decorations.type.DecoratedDeclaredType)2 DeclaredType (javax.lang.model.type.DeclaredType)2 DataType (com.webcohesion.enunciate.api.datatype.DataType)1 Property (com.webcohesion.enunciate.api.datatype.Property)1 Syntax (com.webcohesion.enunciate.api.datatype.Syntax)1