Search in sources :

Example 1 with ReturnDocComment

use of com.webcohesion.enunciate.javac.javadoc.ReturnDocComment in project enunciate by stoicflame.

the class ResourceMethod method loadReturnType.

protected DecoratedTypeMirror loadReturnType() {
    DecoratedTypeMirror returnType;
    TypeHint hintInfo = getAnnotation(TypeHint.class);
    if (hintInfo != null) {
        returnType = (DecoratedTypeMirror) TypeHintUtils.getTypeHint(hintInfo, this.env, getReturnType());
        returnType.setDeferredDocComment(new ReturnDocComment(this));
    } else {
        returnType = (DecoratedTypeMirror) getReturnType();
        // we can use the type argument to get the entity type
        if (returnType.isClass() && returnType.isInstanceOf("com.sun.jersey.api.JResponse")) {
            DecoratedDeclaredType jresponse = (DecoratedDeclaredType) returnType;
            if (!jresponse.getTypeArguments().isEmpty()) {
                DecoratedTypeMirror responseType = (DecoratedTypeMirror) TypeMirrorDecorator.decorate(jresponse.getTypeArguments().get(0), this.env);
                if (responseType.isDeclared()) {
                    responseType.setDeferredDocComment(new ReturnDocComment(this));
                    returnType = responseType;
                }
            }
        } else if ((returnType.isInstanceOf(javax.ws.rs.core.Response.class) || returnType.isInstanceOf(jakarta.ws.rs.core.Response.class)) || returnType.isInstanceOf(java.io.InputStream.class)) {
            // generic response that doesn't have a type hint; we'll just have to assume return type of "object"
            DecoratedDeclaredType objectType = (DecoratedDeclaredType) TypeMirrorDecorator.decorate(this.env.getElementUtils().getTypeElement(Object.class.getName()).asType(), this.env);
            objectType.setDeferredDocComment(new ReturnDocComment(this));
            returnType = objectType;
        }
    }
    final ApiOperation apiOperation = getAnnotation(ApiOperation.class);
    if (apiOperation != null) {
        DecoratedTypeMirror swaggerReturnType = Annotations.mirrorOf(new Callable<Class<?>>() {

            @Override
            public Class<?> call() throws Exception {
                return apiOperation.response();
            }
        }, this.env, Void.class);
        if (swaggerReturnType != null) {
            if (!apiOperation.responseContainer().isEmpty()) {
                swaggerReturnType = (DecoratedTypeMirror) this.env.getTypeUtils().getArrayType(swaggerReturnType);
                swaggerReturnType.setDeferredDocComment(new ReturnDocComment(this));
            }
            returnType = swaggerReturnType;
        }
    }
    DecoratedTypeMirror returnWrapped = JAXDocletUtil.getReturnWrapped(getDocComment(), this.env, getContext().getContext().getLogger());
    if (returnWrapped != null) {
        returnWrapped.setDeferredDocComment(new ReturnWrappedDocComment(this));
        returnType = returnWrapped;
    }
    return returnType;
}
Also used : DecoratedDeclaredType(com.webcohesion.enunciate.javac.decorations.type.DecoratedDeclaredType) DecoratedTypeMirror(com.webcohesion.enunciate.javac.decorations.type.DecoratedTypeMirror) ReturnWrappedDocComment(com.webcohesion.enunciate.modules.jaxrs.model.util.ReturnWrappedDocComment) EnunciateException(com.webcohesion.enunciate.EnunciateException) MirroredTypeException(javax.lang.model.type.MirroredTypeException) ReturnDocComment(com.webcohesion.enunciate.javac.javadoc.ReturnDocComment)

Example 2 with ReturnDocComment

use of com.webcohesion.enunciate.javac.javadoc.ReturnDocComment in project enunciate by stoicflame.

the class DecoratedExecutableElement method getReturnType.

@Override
public TypeMirror getReturnType() {
    if (this.typeMirror == null) {
        this.typeMirror = TypeMirrorDecorator.decorate(delegate.getReturnType(), env);
        ((DecoratedTypeMirror) this.typeMirror).setDeferredDocComment(new ReturnDocComment(this));
    }
    return this.typeMirror;
}
Also used : DecoratedTypeMirror(com.webcohesion.enunciate.javac.decorations.type.DecoratedTypeMirror) ReturnDocComment(com.webcohesion.enunciate.javac.javadoc.ReturnDocComment)

Aggregations

DecoratedTypeMirror (com.webcohesion.enunciate.javac.decorations.type.DecoratedTypeMirror)2 ReturnDocComment (com.webcohesion.enunciate.javac.javadoc.ReturnDocComment)2 EnunciateException (com.webcohesion.enunciate.EnunciateException)1 DecoratedDeclaredType (com.webcohesion.enunciate.javac.decorations.type.DecoratedDeclaredType)1 ReturnWrappedDocComment (com.webcohesion.enunciate.modules.jaxrs.model.util.ReturnWrappedDocComment)1 MirroredTypeException (javax.lang.model.type.MirroredTypeException)1