Search in sources :

Example 1 with AnnotationDesc

use of com.sun.javadoc.AnnotationDesc in project jersey by jersey.

the class ResourceDoclet method addParamDocs.

private static void addParamDocs(final MethodDoc methodDoc, final MethodDocType methodDocType, final DocProcessor docProcessor) {
    final Parameter[] parameters = methodDoc.parameters();
    final ParamTag[] paramTags = methodDoc.paramTags();
    /* only use both javadoc and reflection information when the number
         * of params are the same
         */
    if (parameters != null && paramTags != null && parameters.length == paramTags.length) {
        for (int i = 0; i < parameters.length; i++) {
            final Parameter parameter = parameters[i];
            /* TODO: this only works if the params and tags are in the same
                 * order. If the param tags are mixed up, the comments for parameters
                 * will be wrong.
                 */
            final ParamTag paramTag = paramTags[i];
            final ParamDocType paramDocType = new ParamDocType();
            paramDocType.setParamName(paramTag.parameterName());
            paramDocType.setCommentText(paramTag.parameterComment());
            docProcessor.processParamTag(paramTag, parameter, paramDocType);
            final AnnotationDesc[] annotations = parameter.annotations();
            if (annotations != null) {
                for (final AnnotationDesc annotationDesc : annotations) {
                    final AnnotationDocType annotationDocType = new AnnotationDocType();
                    final String typeName = annotationDesc.annotationType().qualifiedName();
                    annotationDocType.setAnnotationTypeName(typeName);
                    for (final ElementValuePair elementValuePair : annotationDesc.elementValues()) {
                        final NamedValueType namedValueType = new NamedValueType();
                        namedValueType.setName(elementValuePair.element().name());
                        namedValueType.setValue(elementValuePair.value().value().toString());
                        annotationDocType.getAttributeDocs().add(namedValueType);
                    }
                    paramDocType.getAnnotationDocs().add(annotationDocType);
                }
            }
            methodDocType.getParamDocs().add(paramDocType);
        }
    }
}
Also used : ParamTag(com.sun.javadoc.ParamTag) ElementValuePair(com.sun.javadoc.AnnotationDesc.ElementValuePair) NamedValueType(org.glassfish.jersey.server.wadl.internal.generators.resourcedoc.model.NamedValueType) Parameter(com.sun.javadoc.Parameter) AnnotationDocType(org.glassfish.jersey.server.wadl.internal.generators.resourcedoc.model.AnnotationDocType) ParamDocType(org.glassfish.jersey.server.wadl.internal.generators.resourcedoc.model.ParamDocType) AnnotationDesc(com.sun.javadoc.AnnotationDesc)

Example 2 with AnnotationDesc

use of com.sun.javadoc.AnnotationDesc in project RESTdoclet by IG-Group.

the class AnnotationUtils method ignore.

/**
    * Check if the element is annotated with the configured
    * RESTDOCLET_IGNORE_ANNOTATION system property
    * 
    * @param element the element to check
    * @return true if the element is annotated with the configured
    *         RESTDOCLET_IGNORE_ANNOTATION property
    */
public static boolean ignore(ProgramElementDoc element) {
    LOG.debug(" IGNORE " + element.name());
    String ignoreAnnotation = System.getProperty(RESTDOCLET_IGNORE_ANNOTATION);
    if (ignoreAnnotation != null && !ignoreAnnotation.isEmpty()) {
        for (final AnnotationDesc annotation : annotations(element)) {
            final String name = annotation.annotationType().qualifiedName();
            LOG.debug(" ? " + name);
            if (StringUtils.equals(ignoreAnnotation, name)) {
                LOG.debug(" Ignoring : " + name);
                return true;
            }
        }
    }
    return false;
}
Also used : AnnotationDesc(com.sun.javadoc.AnnotationDesc)

Example 3 with AnnotationDesc

use of com.sun.javadoc.AnnotationDesc in project RESTdoclet by IG-Group.

the class DocTypeUtils method logType.

/**
    * Log the type information
    * 
    * @param type
    */
private static void logType(final Type type) {
    if (LOG.isDebugEnabled() && type.asClassDoc() != null) {
        LOG.debug(type.asClassDoc().qualifiedTypeName());
        LOG.debug(" - " + type.asClassDoc().commentText());
        for (AnnotationDesc ad : type.asClassDoc().annotations()) {
            LOG.debug(" - " + ad.toString());
        }
    }
}
Also used : AnnotationDesc(com.sun.javadoc.AnnotationDesc)

Example 4 with AnnotationDesc

use of com.sun.javadoc.AnnotationDesc in project Orchid by JavaEden.

the class ClassDocParser method getAnnotationsInfo.

private JSONArray getAnnotationsInfo(ProgramElementDoc classDoc) {
    if (!EdenUtils.isEmpty(classDoc.annotations())) {
        JSONArray array = new JSONArray();
        for (AnnotationDesc i : classDoc.annotations()) {
            if (!i.isSynthesized()) {
                JSONObject object = typeParser.getTypeObject(i.annotationType());
                object.put("values", new JSONObject());
                for (AnnotationDesc.ElementValuePair pair : i.elementValues()) {
                    object.getJSONObject("values").put(pair.element().name(), pair.value().toString());
                }
                array.put(object);
            }
        }
        return array;
    } else {
        return null;
    }
}
Also used : JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) AnnotationDesc(com.sun.javadoc.AnnotationDesc)

Example 5 with AnnotationDesc

use of com.sun.javadoc.AnnotationDesc in project RESTdoclet by IG-Group.

the class DocTypeUtils method getFieldDoc.

/**
    * Return the documentation for a field
    * 
    * @param type
    * @param attributeName
    * @return
    */
private static String getFieldDoc(final Type type, final String attributeName, final String methodComment) {
    LOG.debug("getFieldDoc " + type.simpleTypeName() + " - " + attributeName + " - " + methodComment);
    String fieldComment = "";
    if (type.asClassDoc() != null) {
        for (FieldDoc field : type.asClassDoc().fields(false)) {
            if (field.name().equalsIgnoreCase(attributeName)) {
                fieldComment = field.commentText();
                if (methodComment.length() > fieldComment.length()) {
                    fieldComment = methodComment;
                }
                // see if there are any validation
                // constraints
                AnnotationDesc[] annotations = field.annotations();
                for (AnnotationDesc annotation : annotations) {
                    if (annotation.toString().contains("@javax.validation.constraints.")) {
                        String constraint = annotation.toString().replace("@javax.validation.constraints.", "");
                        fieldComment += "<br>[Rule: " + constraint + "]";
                    }
                }
                break;
            }
        }
    }
    return fieldComment;
}
Also used : FieldDoc(com.sun.javadoc.FieldDoc) AnnotationDesc(com.sun.javadoc.AnnotationDesc)

Aggregations

AnnotationDesc (com.sun.javadoc.AnnotationDesc)5 ElementValuePair (com.sun.javadoc.AnnotationDesc.ElementValuePair)1 FieldDoc (com.sun.javadoc.FieldDoc)1 ParamTag (com.sun.javadoc.ParamTag)1 Parameter (com.sun.javadoc.Parameter)1 AnnotationDocType (org.glassfish.jersey.server.wadl.internal.generators.resourcedoc.model.AnnotationDocType)1 NamedValueType (org.glassfish.jersey.server.wadl.internal.generators.resourcedoc.model.NamedValueType)1 ParamDocType (org.glassfish.jersey.server.wadl.internal.generators.resourcedoc.model.ParamDocType)1 JSONArray (org.json.JSONArray)1 JSONObject (org.json.JSONObject)1