Java Code Examples for com.sun.javadoc.AnnotationDesc#ElementValuePair

The following examples show how to use com.sun.javadoc.AnnotationDesc#ElementValuePair . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SwaggerPropertiesDoclet.java    From springfox-javadoc with Apache License 2.0 6 votes vote down vote up
private static String processClass(
  ClassDoc classDoc,
  StringBuilder pathRoot) {

    String defaultRequestMethod = null;
    for (AnnotationDesc annotationDesc : classDoc.annotations()) {
        if (REQUEST_MAPPING.equals(annotationDesc.annotationType().qualifiedTypeName())) {
            for (AnnotationDesc.ElementValuePair pair : annotationDesc.elementValues()) {

                if (VALUE.equals(pair.element().name()) || PATH.equals(pair.element().name())) {
                    setRoot(pathRoot, pair);
                }
                if (METHOD.equals(pair.element().name())) {
                    defaultRequestMethod = pair.value().toString();
                }
            }
            break;
        }
    }
    return defaultRequestMethod;
}
 
Example 2
Source File: SwaggerPropertiesDoclet.java    From springfox-javadoc with Apache License 2.0 6 votes vote down vote up
private static String getRequestMethod(
  AnnotationDesc annotationDesc,
  String name,
  String defaultRequestMethod) {

    if (REQUEST_MAPPING.equals(name)) {
        for (AnnotationDesc.ElementValuePair pair : annotationDesc.elementValues()) {
            if (METHOD.equals(pair.element().name())) {
                return resolveRequestMethod(pair, defaultRequestMethod);
            }
        }
    } else if (PUT_MAPPING.equals(name)) {
        return "PUT";
    } else if (POST_MAPPING.equals(name)) {
        return "POST";
    } else if (PATCH_MAPPING.equals(name)) {
        return "PATCH";
    } else if (GET_MAPPING.equals(name)) {
        return "GET";
    } else if (DELETE_MAPPING.equals(name)) {
        return "DELETE";
    }
    return defaultRequestMethod;
}
 
Example 3
Source File: SwaggerPropertiesDoclet.java    From springfox-javadoc with Apache License 2.0 5 votes vote down vote up
private static void setRoot(
  StringBuilder pathRoot,
  AnnotationDesc.ElementValuePair pair) {

    String value = pair.value().toString().replaceAll("\"$|^\"", "");
    if (!value.startsWith("/")) {
        pathRoot.append("/");
    }
    if (value.endsWith("/")) {
        pathRoot.append(value, 0, value.length() - 1);
    } else {
        pathRoot.append(value);
    }
}
 
Example 4
Source File: SwaggerPropertiesDoclet.java    From springfox-javadoc with Apache License 2.0 5 votes vote down vote up
private static void appendPath(
  StringBuilder path,
  AnnotationDesc.ElementValuePair pair) {

    String value = pair.value().toString().replaceAll("\"$|^\"", "");
    if (value.startsWith("/")) {
        path.append(value).append(".");
    } else {
        path.append("/").append(value).append(".");
    }
}
 
Example 5
Source File: SwaggerPropertiesDoclet.java    From springfox-javadoc with Apache License 2.0 5 votes vote down vote up
private static String resolveRequestMethod(
  AnnotationDesc.ElementValuePair pair,
  String defaultRequestMethod) {

    String value = pair.value().toString();
    for (String[] each : REQUEST_MAPPINGS) {
        if (each[0].equals(value)) {
            return each[1];
        }
    }
    return defaultRequestMethod;
}
 
Example 6
Source File: PSItemFieldDoc.java    From PrivacyStreams with Apache License 2.0 5 votes vote down vote up
private PSItemFieldDoc(PSItemDoc psItemDoc, FieldDoc fieldDoc, AnnotationDesc annotation) {
    this.psItemDoc = psItemDoc;
    this.reference = fieldDoc.name();
    this.name = fieldDoc.constantValue().toString();
    this.description = fieldDoc.commentText().replace('\n', ' ');

    for (AnnotationDesc.ElementValuePair elementValuePair : annotation.elementValues()) {
        if ("type".equals(elementValuePair.element().name())) {
            Object typeValue = elementValuePair.value().value();
            this.type = (Type) typeValue;
        }
    }
}
 
Example 7
Source File: SwaggerPropertiesDoclet.java    From springfox-javadoc with Apache License 2.0 4 votes vote down vote up
private static void processMethod(
  Properties properties,
  MethodDoc methodDoc,
  String defaultRequestMethod,
  String pathRoot,
  boolean exceptionRef) {

    for (AnnotationDesc annotationDesc : methodDoc.annotations()) {
        String annotationType = annotationDesc.annotationType().toString();
        if (isMapping(annotationType)) {
            StringBuilder path = new StringBuilder(pathRoot);
            for (AnnotationDesc.ElementValuePair pair : annotationDesc.elementValues()) {
                if (VALUE.equals(pair.element().name()) || PATH.equals(pair.element().name())) {
                    appendPath(path, pair);
                    break;
                }
            }
            if (!path.substring(path.length() - 1).equals(".")) {
                path.append(".");
            }
            String requestMethod = getRequestMethod(annotationDesc, annotationType, defaultRequestMethod);
            if (requestMethod != null) {
                path.append(requestMethod);
                saveProperty(properties, path.toString() + ".notes", methodDoc.commentText());

                for (ParamTag paramTag : methodDoc.paramTags()) {
                    saveProperty(properties, path.toString() + ".param." + paramTag.parameterName(),
                      paramTag.parameterComment());
                }
                for (Tag tag : methodDoc.tags()) {
                    if (tag.name().equals(RETURN)) {
                        saveProperty(properties, path.toString() + ".return", tag.text());
                        break;
                    }
                }
                if (exceptionRef) {
                    processThrows(properties, methodDoc.throwsTags(), path);
                }
            }
        }
    }
}
 
Example 8
Source File: Parser.java    From xml-doclet with Apache License 2.0 4 votes vote down vote up
/**
 * Parses annotation instances of an annotable program element
 * 
 * @param annotationDesc
 *            annotationDesc
 * @param programElement
 *            programElement
 * @return representation of annotations
 */
protected AnnotationInstance parseAnnotationDesc(AnnotationDesc annotationDesc, String programElement) {
	AnnotationInstance annotationInstanceNode = objectFactory.createAnnotationInstance();

	try {
		AnnotationTypeDoc annotTypeInfo = annotationDesc.annotationType();
		annotationInstanceNode.setName(annotTypeInfo.name());
		annotationInstanceNode.setQualified(annotTypeInfo.qualifiedTypeName());
	} catch (ClassCastException castException) {
		log.error("Unable to obtain type data about an annotation found on: " + programElement);
		log.error("Add to the classpath the class/jar that defines this annotation.");
	}

	for (AnnotationDesc.ElementValuePair elementValuesPair : annotationDesc.elementValues()) {
		AnnotationArgument annotationArgumentNode = objectFactory.createAnnotationArgument();
		annotationArgumentNode.setName(elementValuesPair.element().name());

		Type annotationArgumentType = elementValuesPair.element().returnType();
		annotationArgumentNode.setType(parseTypeInfo(annotationArgumentType));
		annotationArgumentNode.setPrimitive(annotationArgumentType.isPrimitive());
		annotationArgumentNode.setArray(annotationArgumentType.dimension().length() > 0);

		Object objValue = elementValuesPair.value().value();
		if (objValue instanceof AnnotationValue[]) {
			for (AnnotationValue annotationValue : (AnnotationValue[]) objValue) {
			    if (annotationValue.value() instanceof AnnotationDesc) {
                       AnnotationDesc annoDesc = (AnnotationDesc) annotationValue.value();
                       annotationArgumentNode.getAnnotation().add(parseAnnotationDesc(annoDesc, programElement));
                   } else {
                       annotationArgumentNode.getValue().add(annotationValue.value().toString());
                   }
			}
		} else if (objValue instanceof FieldDoc) {
			annotationArgumentNode.getValue().add(((FieldDoc) objValue).name());
		} else if (objValue instanceof ClassDoc) {
			annotationArgumentNode.getValue().add(((ClassDoc) objValue).qualifiedTypeName());
		} else {
			annotationArgumentNode.getValue().add(objValue.toString());
		}
		annotationInstanceNode.getArgument().add(annotationArgumentNode);
	}

	return annotationInstanceNode;
}