Search in sources :

Example 1 with AnnotationValue

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

the class ControllerBuilder method initMethods.

/**
    * Initialises the methods in this controller annotated with
    * <code>@RequestMapping</code> in the source class.
    * 
    * @param classDoc the controller's Java documentation object.
    */
private void initMethods(Controller controller, final ClassDoc classDoc) {
    LOG.info(controller.getName());
    // Controller-level $RequestMapping annotation?
    String baseUri = "";
    AnnotationValue urlAnnotation = elementValue(classDoc, RequestMapping.class, "value");
    if (urlAnnotation != null) {
        String[] methodUris = parseValueAnnotation(urlAnnotation);
        // Assume just one...
        baseUri = methodUris[0];
    }
    // Initialise methods
    ArrayList<Method> methods = new ArrayList<Method>();
    for (int i = 0; classDoc.methods(false) != null && i < classDoc.methods(false).length; i++) {
        if (isAnnotated(classDoc.methods(false)[i], RequestMapping.class) && !ignore(classDoc.methods(false)[i])) {
            methods.add(new MethodBuilder().build(new Method(), classDoc.methods(false)[i], baseUri));
        }
    }
    controller.setMethods(methods);
    if (methods.size() == 0) {
        LOG.warn("No methods found with @RequestMapping tag");
    }
}
Also used : ArrayList(java.util.ArrayList) AnnotationValue(com.sun.javadoc.AnnotationValue) Method(com.iggroup.oss.restdoclet.doclet.type.Method) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with AnnotationValue

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

the class MethodBuilder method initProduces.

private void initProduces(Method method, final MethodDoc methodDoc) {
    final AnnotationValue value = elementValue(methodDoc, RequestMapping.class, "produces");
    LOG.debug(method.getName());
    if (value != null) {
        method.setProduces(value.toString().replace("\"", ""));
        LOG.debug("PRODUCES " + method.getProduces());
    }
}
Also used : AnnotationValue(com.sun.javadoc.AnnotationValue)

Example 3 with AnnotationValue

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

the class MethodBuilder method initRequestMethod.

/**
    * Initialises the HTTP request-method this method is mapped to.
    * 
    * @param methodDoc the method's Java documentation object.
    */
private void initRequestMethod(Method method, final MethodDoc methodDoc) {
    final AnnotationValue value = elementValue(methodDoc, RequestMapping.class, "method");
    LOG.debug(method.getName());
    if (value == null) {
        /* default */
        LOG.debug("No method found.... defaulting to GET");
        method.setRequestMethod(RequestMethod.GET.toString());
    } else {
        /*
          * Java 1.6: AnnotationValue.toString() returns qualified classname
          * example:
          * org.springframework.web.bind.annotation.RequestMethod.GET Java
          * 1.5: AnnotationValue.toString() returns simple classname example:
          * GET
          */
        if (value.toString().contains(".")) {
            method.setRequestMethod(value.toString().substring(value.toString().lastIndexOf(".") + 1));
        } else {
            method.setRequestMethod(value.toString());
        }
    }
    LOG.debug(method.getRequestMethod());
}
Also used : AnnotationValue(com.sun.javadoc.AnnotationValue)

Example 4 with AnnotationValue

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

the class MethodBuilder method initHeaders.

private void initHeaders(Method method, final MethodDoc methodDoc) {
    final AnnotationValue value = elementValue(methodDoc, RequestMapping.class, "headers");
    LOG.debug(method.getName());
    if (value != null) {
        method.setHeaders(value.toString().replace("\"", ""));
        LOG.debug("HEADERS " + method.getHeaders());
    }
}
Also used : AnnotationValue(com.sun.javadoc.AnnotationValue)

Example 5 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 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)

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