com.sun.javadoc.AnnotationDesc Java Examples

The following examples show how to use com.sun.javadoc.AnnotationDesc. 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: Parser.java    From xml-doclet with Apache License 2.0 6 votes vote down vote up
protected Field parseField(FieldDoc fieldDoc) {
	Field fieldNode = objectFactory.createField();
	fieldNode.setType(parseTypeInfo(fieldDoc.type()));
	fieldNode.setName(fieldDoc.name());
	fieldNode.setQualified(fieldDoc.qualifiedName());
	String comment = fieldDoc.commentText();
	if (comment.length() > 0) {
		fieldNode.setComment(comment);
	}
	fieldNode.setScope(parseScope(fieldDoc));
	fieldNode.setFinal(fieldDoc.isFinal());
	fieldNode.setStatic(fieldDoc.isStatic());
	fieldNode.setVolatile(fieldDoc.isVolatile());
	fieldNode.setTransient(fieldDoc.isTransient());
	fieldNode.setConstant(fieldDoc.constantValueExpression());

	for (AnnotationDesc annotationDesc : fieldDoc.annotations()) {
		fieldNode.getAnnotation().add(parseAnnotationDesc(annotationDesc, fieldDoc.qualifiedName()));
	}

	for (Tag tag : fieldDoc.tags()) {
		fieldNode.getTag().add(parseTag(tag));
	}

	return fieldNode;
}
 
Example #2
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 #3
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 #4
Source File: Parser.java    From xml-doclet with Apache License 2.0 6 votes vote down vote up
/**
 * Parses an enum type definition
 * 
 * @param fieldDoc
 * @return
 */
protected EnumConstant parseEnumConstant(FieldDoc fieldDoc) {
	EnumConstant enumConstant = objectFactory.createEnumConstant();
	enumConstant.setName(fieldDoc.name());
	String comment = fieldDoc.commentText();
	if (comment.length() > 0) {
		enumConstant.setComment(comment);
	}

	for (AnnotationDesc annotationDesc : fieldDoc.annotations()) {
		enumConstant.getAnnotation().add(parseAnnotationDesc(annotationDesc, fieldDoc.qualifiedName()));
	}

	for (Tag tag : fieldDoc.tags()) {
		enumConstant.getTag().add(parseTag(tag));
	}

	return enumConstant;
}
 
Example #5
Source File: Parser.java    From xml-doclet with Apache License 2.0 6 votes vote down vote up
/**
 * Parse an annotation.
 * 
 * @param annotationTypeDoc
 *            A AnnotationTypeDoc instance
 * @return the annotation node
 */
protected Annotation parseAnnotationTypeDoc(AnnotationTypeDoc annotationTypeDoc) {
	Annotation annotationNode = objectFactory.createAnnotation();
	annotationNode.setName(annotationTypeDoc.name());
	annotationNode.setQualified(annotationTypeDoc.qualifiedName());
	String comment = annotationTypeDoc.commentText();
	if (comment.length() > 0) {
		annotationNode.setComment(comment);
	}
	annotationNode.setIncluded(annotationTypeDoc.isIncluded());
	annotationNode.setScope(parseScope(annotationTypeDoc));

	for (AnnotationTypeElementDoc annotationTypeElementDoc : annotationTypeDoc.elements()) {
		annotationNode.getElement().add(parseAnnotationTypeElementDoc(annotationTypeElementDoc));
	}

	for (AnnotationDesc annotationDesc : annotationTypeDoc.annotations()) {
		annotationNode.getAnnotation().add(parseAnnotationDesc(annotationDesc, annotationTypeDoc.qualifiedName()));
	}

	for (Tag tag : annotationTypeDoc.tags()) {
		annotationNode.getTag().add(parseTag(tag));
	}

	return annotationNode;
}
 
Example #6
Source File: RootDocProcessor.java    From pom-manipulation-ext with Apache License 2.0 6 votes vote down vote up
private static boolean exclude( Doc doc )
{
    AnnotationDesc[] annotations = null;
    if ( doc instanceof ProgramElementDoc )
    {
        annotations = ( (ProgramElementDoc) doc ).annotations();
    }
    else if ( doc instanceof PackageDoc )
    {
        annotations = ( (PackageDoc) doc ).annotations();
    }
    if ( annotations != null )
    {
        for ( AnnotationDesc annotation : annotations )
        {
            String qualifiedTypeName = annotation.annotationType().qualifiedTypeName();
            if ( qualifiedTypeName.equals( JavadocExclude.class.getCanonicalName() ) )
            {
                return true;
            }
        }
    }
    // nothing above found a reason to exclude
    return false;
}
 
Example #7
Source File: Main.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public static boolean start(RootDoc root) {
    for (ClassDoc d : root.classes()) {
        for (AnnotationDesc a : d.annotations()) {
            System.out.println(a.annotationType());
        }
    }
    return true;
}
 
Example #8
Source File: Parser.java    From xml-doclet with Apache License 2.0 5 votes vote down vote up
protected MethodParameter parseMethodParameter(Parameter parameter) {
	MethodParameter parameterMethodNode = objectFactory.createMethodParameter();
	parameterMethodNode.setName(parameter.name());
	parameterMethodNode.setType(parseTypeInfo(parameter.type()));

	for (AnnotationDesc annotationDesc : parameter.annotations()) {
		parameterMethodNode.getAnnotation().add(parseAnnotationDesc(annotationDesc, parameter.typeName()));
	}

	return parameterMethodNode;
}
 
Example #9
Source File: Parser.java    From xml-doclet with Apache License 2.0 5 votes vote down vote up
protected Method parseMethod(MethodDoc methodDoc) {
	Method methodNode = objectFactory.createMethod();

	methodNode.setName(methodDoc.name());
	methodNode.setQualified(methodDoc.qualifiedName());
	String comment = methodDoc.commentText();
	if (comment.length() > 0) {
		methodNode.setComment(comment);
	}
	methodNode.setScope(parseScope(methodDoc));
	methodNode.setAbstract(methodDoc.isAbstract());
	methodNode.setIncluded(methodDoc.isIncluded());
	methodNode.setFinal(methodDoc.isFinal());
	methodNode.setNative(methodDoc.isNative());
	methodNode.setStatic(methodDoc.isStatic());
	methodNode.setSynchronized(methodDoc.isSynchronized());
	methodNode.setVarArgs(methodDoc.isVarArgs());
	methodNode.setSignature(methodDoc.signature());
	methodNode.setReturn(parseTypeInfo(methodDoc.returnType()));

	for (Parameter parameter : methodDoc.parameters()) {
		methodNode.getParameter().add(parseMethodParameter(parameter));
	}

	for (Type exceptionType : methodDoc.thrownExceptionTypes()) {
		methodNode.getException().add(parseTypeInfo(exceptionType));
	}

	for (AnnotationDesc annotationDesc : methodDoc.annotations()) {
		methodNode.getAnnotation().add(parseAnnotationDesc(annotationDesc, methodDoc.qualifiedName()));
	}

	for (Tag tag : methodDoc.tags()) {
		methodNode.getTag().add(parseTag(tag));
	}

	return methodNode;
}
 
Example #10
Source File: Parser.java    From xml-doclet with Apache License 2.0 5 votes vote down vote up
protected Constructor parseConstructor(ConstructorDoc constructorDoc) {
	Constructor constructorNode = objectFactory.createConstructor();

	constructorNode.setName(constructorDoc.name());
	constructorNode.setQualified(constructorDoc.qualifiedName());
	String comment = constructorDoc.commentText();
	if (comment.length() > 0) {
		constructorNode.setComment(comment);
	}
	constructorNode.setScope(parseScope(constructorDoc));
	constructorNode.setIncluded(constructorDoc.isIncluded());
	constructorNode.setFinal(constructorDoc.isFinal());
	constructorNode.setNative(constructorDoc.isNative());
	constructorNode.setStatic(constructorDoc.isStatic());
	constructorNode.setSynchronized(constructorDoc.isSynchronized());
	constructorNode.setVarArgs(constructorDoc.isVarArgs());
	constructorNode.setSignature(constructorDoc.signature());

	for (Parameter parameter : constructorDoc.parameters()) {
		constructorNode.getParameter().add(parseMethodParameter(parameter));
	}

	for (Type exceptionType : constructorDoc.thrownExceptionTypes()) {
		constructorNode.getException().add(parseTypeInfo(exceptionType));
	}

	for (AnnotationDesc annotationDesc : constructorDoc.annotations()) {
		constructorNode.getAnnotation().add(parseAnnotationDesc(annotationDesc, constructorDoc.qualifiedName()));
	}

	for (Tag tag : constructorDoc.tags()) {
		constructorNode.getTag().add(parseTag(tag));
	}

	return constructorNode;
}
 
Example #11
Source File: Parser.java    From xml-doclet with Apache License 2.0 5 votes vote down vote up
protected Interface parseInterface(ClassDoc classDoc) {

		Interface interfaceNode = objectFactory.createInterface();
		interfaceNode.setName(classDoc.name());
		interfaceNode.setQualified(classDoc.qualifiedName());
		String comment = classDoc.commentText();
		if (comment.length() > 0) {
			interfaceNode.setComment(comment);
		}
		interfaceNode.setIncluded(classDoc.isIncluded());
		interfaceNode.setScope(parseScope(classDoc));

		for (TypeVariable typeVariable : classDoc.typeParameters()) {
			interfaceNode.getGeneric().add(parseTypeParameter(typeVariable));
		}

		for (Type interfaceType : classDoc.interfaceTypes()) {
			interfaceNode.getInterface().add(parseTypeInfo(interfaceType));
		}

		for (MethodDoc method : classDoc.methods()) {
			interfaceNode.getMethod().add(parseMethod(method));
		}

		for (AnnotationDesc annotationDesc : classDoc.annotations()) {
			interfaceNode.getAnnotation().add(parseAnnotationDesc(annotationDesc, classDoc.qualifiedName()));
		}

		for (Tag tag : classDoc.tags()) {
			interfaceNode.getTag().add(parseTag(tag));
		}

		for (FieldDoc field : classDoc.fields()) {
			interfaceNode.getField().add(parseField(field));
		}

		return interfaceNode;
	}
 
Example #12
Source File: Parser.java    From xml-doclet with Apache License 2.0 5 votes vote down vote up
protected Enum parseEnum(ClassDoc classDoc) {
	Enum enumNode = objectFactory.createEnum();
	enumNode.setName(classDoc.name());
	enumNode.setQualified(classDoc.qualifiedName());
	String comment = classDoc.commentText();
	if (comment.length() > 0) {
		enumNode.setComment(comment);
	}
	enumNode.setIncluded(classDoc.isIncluded());
	enumNode.setScope(parseScope(classDoc));

	Type superClassType = classDoc.superclassType();
	if (superClassType != null) {
		enumNode.setClazz(parseTypeInfo(superClassType));
	}

	for (Type interfaceType : classDoc.interfaceTypes()) {
		enumNode.getInterface().add(parseTypeInfo(interfaceType));
	}

	for (FieldDoc field : classDoc.enumConstants()) {
		enumNode.getConstant().add(parseEnumConstant(field));
	}

	for (AnnotationDesc annotationDesc : classDoc.annotations()) {
		enumNode.getAnnotation().add(parseAnnotationDesc(annotationDesc, classDoc.qualifiedName()));
	}

	for (Tag tag : classDoc.tags()) {
		enumNode.getTag().add(parseTag(tag));
	}

	return enumNode;
}
 
Example #13
Source File: Utils.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Replies the SARL element type of the given type.
 *
 * @param type the type.
 * @return the SARL element type, or {@code null} if unknown.
 */
public static Integer getSarlClassification(ProgramElementDoc type) {
	final AnnotationDesc annotation = Utils.findFirst(type.annotations(), it ->
			qualifiedNameEquals(it.annotationType().qualifiedTypeName(), getKeywords().getSarlElementTypeAnnotationName()));
	if (annotation != null) {
		final ElementValuePair[] pairs = annotation.elementValues();
		if (pairs != null && pairs.length > 0) {
			return ((Number) pairs[0].value().value()).intValue();
		}
	}
	return null;
}
 
Example #14
Source File: Utils.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Find the first element into the given array.
 *
 * @param <T> the type of the elements to filter.
 * @param original the original array.
 * @param filter the filtering action.
 * @return the first element.
 */
public static <T extends AnnotationDesc> T findFirst(T[] original, Predicate<T> filter) {
	for (final T element : original) {
		if (filter.test(element)) {
			return element;
		}
	}
	return null;
}
 
Example #15
Source File: Main.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public static boolean start(RootDoc root) {
    for (ClassDoc d : root.classes()) {
        for (AnnotationDesc a : d.annotations()) {
            System.out.println(a.annotationType());
        }
    }
    return true;
}
 
Example #16
Source File: Main.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public static boolean start(RootDoc root) {
    for (ClassDoc d : root.classes()) {
        for (AnnotationDesc a : d.annotations()) {
            System.out.println(a.annotationType());
        }
    }
    return true;
}
 
Example #17
Source File: Main.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static boolean start(RootDoc root) {
    for (ClassDoc d : root.classes()) {
        for (AnnotationDesc a : d.annotations()) {
            System.out.println(a.annotationType());
        }
    }
    return true;
}
 
Example #18
Source File: Main.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static boolean start(RootDoc root) {
    for (ClassDoc d : root.classes()) {
        for (AnnotationDesc a : d.annotations()) {
            System.out.println(a.annotationType());
        }
    }
    return true;
}
 
Example #19
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 #20
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 #21
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 #22
Source File: Main.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static boolean start(RootDoc root) {
    for (ClassDoc d : root.classes()) {
        for (AnnotationDesc a : d.annotations()) {
            System.out.println(a.annotationType());
        }
    }
    return true;
}
 
Example #23
Source File: PSOperatorWrapperDoc.java    From PrivacyStreams with Apache License 2.0 5 votes vote down vote up
public static PSOperatorWrapperDoc build(ClassDoc classDoc) {
    AnnotationDesc[] annotations = classDoc.annotations();
    for (AnnotationDesc annotation : annotations) {
        AnnotationTypeDoc annotationType = annotation.annotationType();
        if (Consts.OPERATOR_WRAPPER_ANNOTATION.equals(annotationType.toString())) {
            return new PSOperatorWrapperDoc(classDoc);
        }
    }
    return null;
}
 
Example #24
Source File: PSPipelineDoc.java    From PrivacyStreams with Apache License 2.0 5 votes vote down vote up
public static PSPipelineDoc build(ClassDoc classDoc, MethodDoc methodDoc) {
    AnnotationDesc[] annotations = methodDoc.annotations();
    for (AnnotationDesc annotation : annotations) {
        AnnotationTypeDoc annotationType = annotation.annotationType();
        if (Consts.TRANSFORMATION_ANNOTATION.equals(annotationType.toString())) {
            return new PSPipelineDoc(classDoc, methodDoc, annotation, TYPE_TRANSFORMATION);
        }
        else if (Consts.ACTION_ANNOTATION.equals(annotationType.toString())) {
            return new PSPipelineDoc(classDoc, methodDoc, annotation, TYPE_ACTION);
        }
    }
    return null;
}
 
Example #25
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 #26
Source File: Main.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public static boolean start(RootDoc root) {
    for (ClassDoc d : root.classes()) {
        for (AnnotationDesc a : d.annotations()) {
            System.out.println(a.annotationType());
        }
    }
    return true;
}
 
Example #27
Source File: Main.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public static boolean start(RootDoc root) {
    for (ClassDoc d : root.classes()) {
        for (AnnotationDesc a : d.annotations()) {
            System.out.println(a.annotationType());
        }
    }
    return true;
}
 
Example #28
Source File: PSItemDoc.java    From PrivacyStreams with Apache License 2.0 5 votes vote down vote up
public static boolean isValidPSItem(ClassDoc classDoc) {
    AnnotationDesc[] annotations = classDoc.annotations();
    for (AnnotationDesc annotation : annotations) {
        AnnotationTypeDoc annotationType = annotation.annotationType();
        if (Consts.ITEM_ANNOTATION.equals(annotationType.toString())) {
            return true;
        }
    }
    return false;
}
 
Example #29
Source File: PSItemFieldDoc.java    From PrivacyStreams with Apache License 2.0 5 votes vote down vote up
public static PSItemFieldDoc build(PSItemDoc psItemDoc, FieldDoc fieldDoc) {
    AnnotationDesc[] annotations = fieldDoc.annotations();
    for (AnnotationDesc annotation : annotations) {
        AnnotationTypeDoc annotationType = annotation.annotationType();
        if (Consts.ITEM_FIELD_ANNOTATION.equals(annotationType.toString())) {
            return new PSItemFieldDoc(psItemDoc, fieldDoc, annotation);
        }
    }
    return null;
}
 
Example #30
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;
}