Search in sources :

Example 6 with AnnotationValue

use of com.sun.javadoc.AnnotationValue 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)

Example 7 with AnnotationValue

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

the class MethodBuilder method initRestParams.

/**
    * Initialises the REST-parameters of this method.
    * 
    * @param method method to initialise
    * @param methodDoc the method's Java documentation object.
    * @param baseUri the controller base uri
    */
private void initRestParams(Method method, final MethodDoc methodDoc, final String baseUri) {
    LOG.debug(method.getName());
    ArrayList<RestParameter> restParams = new ArrayList<RestParameter>();
    for (NameValuePair pair : new RequestMappingParamsParser(elementValue(methodDoc, RequestMapping.class, "params")).parse()) {
        final Predicate predicate = new ParameterNamePredicate(pair.getName());
        if (!CollectionUtils.exists(method.getRequestParams(), predicate)) {
            LOG.debug(pair.getName() + " - " + pair.getValue());
            restParams.add(new RestParameter(pair));
        }
    }
    AnnotationValue urlAnnotation = elementValue(methodDoc, RequestMapping.class, "value");
    if (urlAnnotation != null) {
        Boolean deprecatedMatch = false;
        String[] methodUris = parseValueAnnotation(urlAnnotation);
        String[] deprecatedURIs = DocTypeUtils.getDeprecatedURIs(methodDoc);
        for (final String uri : methodUris) {
            LOG.debug("uri:" + baseUri + uri);
            boolean deprecated = false;
            if (deprecatedURIs != null) {
                for (final String deprecatedUri : deprecatedURIs) {
                    LOG.debug("deprecated:" + deprecatedUri);
                    if (StringUtils.equals(deprecatedUri, uri)) {
                        LOG.debug("=DEPRECATED");
                        deprecated = true;
                        deprecatedMatch = true;
                        break;
                    }
                }
            }
            method.getUris().add(new Uri(baseUri + uri, deprecated));
        }
        if (deprecatedURIs != null && !deprecatedMatch) {
            LOG.warn("Deprecated URI tag on method " + methodDoc.name() + " does not match any service URIs.");
        }
    }
    method.setRestParams(restParams);
}
Also used : NameValuePair(com.iggroup.oss.restdoclet.doclet.util.NameValuePair) ArrayList(java.util.ArrayList) RequestMappingParamsParser(com.iggroup.oss.restdoclet.doclet.util.RequestMappingParamsParser) Uri(com.iggroup.oss.restdoclet.doclet.type.Uri) Predicate(org.apache.commons.collections.Predicate) ParameterNamePredicate(com.iggroup.oss.restdoclet.doclet.util.ParameterNamePredicate) RestParameter(com.iggroup.oss.restdoclet.doclet.type.RestParameter) AnnotationValue(com.sun.javadoc.AnnotationValue) ParameterNamePredicate(com.iggroup.oss.restdoclet.doclet.util.ParameterNamePredicate)

Example 8 with AnnotationValue

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

the class MethodBuilder method initConsumes.

private void initConsumes(Method method, final MethodDoc methodDoc) {
    final AnnotationValue value = elementValue(methodDoc, RequestMapping.class, "consumes");
    LOG.debug(method.getName());
    if (value != null) {
        method.setConsumes(value.toString().replace("\"", ""));
        LOG.debug("CONSUMES " + method.getConsumes());
    }
}
Also used : AnnotationValue(com.sun.javadoc.AnnotationValue)

Aggregations

AnnotationValue (com.sun.javadoc.AnnotationValue)8 ElementValuePair (com.sun.javadoc.AnnotationDesc.ElementValuePair)2 ArrayList (java.util.ArrayList)2 Method (com.iggroup.oss.restdoclet.doclet.type.Method)1 RestParameter (com.iggroup.oss.restdoclet.doclet.type.RestParameter)1 Uri (com.iggroup.oss.restdoclet.doclet.type.Uri)1 NameValuePair (com.iggroup.oss.restdoclet.doclet.util.NameValuePair)1 ParameterNamePredicate (com.iggroup.oss.restdoclet.doclet.util.ParameterNamePredicate)1 RequestMappingParamsParser (com.iggroup.oss.restdoclet.doclet.util.RequestMappingParamsParser)1 Predicate (org.apache.commons.collections.Predicate)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1