Search in sources :

Example 1 with ElementValuePair

use of com.sun.javadoc.AnnotationDesc.ElementValuePair 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 ElementValuePair

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

the class AnnotationUtils method elementValue.

/**
    * Gets an element-value pair of an annotation an argument of a method is
    * annotated with.
    * 
    * @param param the argument to check for annotations.
    * @param type the type of annotation to look for.
    * @param elementName the name of the element in the annotation to look for.
    * @return the value of the element in the annotation or <code>null</code>
    *         if the annotation is not found or the name of the element is not
    *         found.
    */
public static AnnotationValue elementValue(final Parameter param, final Class<?> type, final String elementName) {
    AnnotationValue value = null;
    final ElementValuePair[] pairs = elementValues(param, type);
    for (final ElementValuePair pair : pairs) {
        if (StringUtils.equals(elementName, pair.element().name())) {
            value = pair.value();
            break;
        }
    }
    return value;
}
Also used : ElementValuePair(com.sun.javadoc.AnnotationDesc.ElementValuePair) AnnotationValue(com.sun.javadoc.AnnotationValue)

Example 3 with ElementValuePair

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

the class AnnotationUtils method elementValue.

/**
    * Gets an element-value pair of an annotation an element (class or method)
    * is annotated with.
    * 
    * @param element the element to check for annotations.
    * @param type the type of annotation to look for.
    * @param elementName the name of the element in the annotation to look for.
    * @return the value of the element in the annotation or <code>null</code>
    *         if the annotation is not found or the name of the element is not
    *         found.
    */
public static AnnotationValue elementValue(final ProgramElementDoc element, final Class<?> type, final String elementName) {
    AnnotationValue value = null;
    final ElementValuePair[] pairs = elementValues(element, type);
    for (ElementValuePair pair : pairs) {
        if (StringUtils.equals(elementName, pair.element().name())) {
            value = pair.value();
            break;
        }
    }
    return value;
}
Also used : ElementValuePair(com.sun.javadoc.AnnotationDesc.ElementValuePair) AnnotationValue(com.sun.javadoc.AnnotationValue)

Aggregations

ElementValuePair (com.sun.javadoc.AnnotationDesc.ElementValuePair)3 AnnotationValue (com.sun.javadoc.AnnotationValue)2 AnnotationDesc (com.sun.javadoc.AnnotationDesc)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