com.sun.javadoc.AnnotationTypeDoc Java Examples

The following examples show how to use com.sun.javadoc.AnnotationTypeDoc. 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
/**
 * 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 #2
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 #3
Source File: Parser.java    From xml-doclet with Apache License 2.0 5 votes vote down vote up
/**
 * The entry point into parsing the javadoc.
 * 
 * @param rootDoc
 *            The RootDoc intstance obtained via the doclet API
 * @return The root node, containing everything parsed from javadoc doclet
 */
public Root parseRootDoc(RootDoc rootDoc) {
	Root rootNode = objectFactory.createRoot();

	for (ClassDoc classDoc : rootDoc.classes()) {
		PackageDoc packageDoc = classDoc.containingPackage();

		Package packageNode = packages.get(packageDoc.name());
		if (packageNode == null) {
			packageNode = parsePackage(packageDoc);
			packages.put(packageDoc.name(), packageNode);
			rootNode.getPackage().add(packageNode);
		}

		if (classDoc instanceof AnnotationTypeDoc) {
			packageNode.getAnnotation().add(parseAnnotationTypeDoc((AnnotationTypeDoc) classDoc));
		} else if (classDoc.isEnum()) {
			packageNode.getEnum().add(parseEnum(classDoc));
		} else if (classDoc.isInterface()) {
			packageNode.getInterface().add(parseInterface(classDoc));
		} else {
			packageNode.getClazz().add(parseClass(classDoc));
		}
	}

	return rootNode;
}
 
Example #4
Source File: ProgrammaticWrappingProxyInstaller.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Wrap a annotation type doc.
 *
 * @param source the source
 * @return the wrapper.
 */
public AnnotationTypeDoc[] wrap(AnnotationTypeDoc[] source) {
	if (source == null) {
		return null;
	}
	final List<AnnotationTypeDoc> list = new ArrayList<>();
	for (final AnnotationTypeDoc element : source) {
		if (isIncluded(element)) {
			list.add(wrap(element));
		}
	}
	return Utils.toArray(source, list);
}
 
Example #5
Source File: ProgrammaticWrappingProxyInstaller.java    From sarl with Apache License 2.0 5 votes vote down vote up
@Override
public AnnotationTypeDoc wrap(AnnotationTypeDoc source) {
	if (source == null || source instanceof Proxy<?> || !(source instanceof AnnotationTypeDocImpl)) {
		return source;
	}
	return new AnnotationTypeDocWrapper((AnnotationTypeDocImpl) source);
}
 
Example #6
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 #7
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 #8
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 #9
Source File: RootDocProcessor.java    From big-c with Apache License 2.0 4 votes vote down vote up
@Override
   public Object invoke(Object proxy, Method method, Object[] args)
throws Throwable {
     String methodName = method.getName();
     if (target instanceof Doc) {
if (methodName.equals("isIncluded")) {
  Doc doc = (Doc) target;
  return !exclude(doc) && doc.isIncluded();
}
if (target instanceof RootDoc) {
  if (methodName.equals("classes")) {
    return filter(((RootDoc) target).classes(), ClassDoc.class);
  } else if (methodName.equals("specifiedClasses")) {
    return filter(((RootDoc) target).specifiedClasses(), ClassDoc.class);
  } else if (methodName.equals("specifiedPackages")) {
    return filter(((RootDoc) target).specifiedPackages(), PackageDoc.class);
  }
} else if (target instanceof ClassDoc) {
  if (isFiltered(args)) {
    if (methodName.equals("methods")) {
      return filter(((ClassDoc) target).methods(true), MethodDoc.class);
    } else if (methodName.equals("fields")) {
      return filter(((ClassDoc) target).fields(true), FieldDoc.class);
    } else if (methodName.equals("innerClasses")) {
      return filter(((ClassDoc) target).innerClasses(true),
	  ClassDoc.class);
    } else if (methodName.equals("constructors")) {
      return filter(((ClassDoc) target).constructors(true),
	  ConstructorDoc.class);
    }
  }
} else if (target instanceof PackageDoc) {
  if (methodName.equals("allClasses")) {
    if (isFiltered(args)) {
      return filter(((PackageDoc) target).allClasses(true),
	ClassDoc.class);
    } else {
      return filter(((PackageDoc) target).allClasses(), ClassDoc.class);  
    }
  } else if (methodName.equals("annotationTypes")) {
    return filter(((PackageDoc) target).annotationTypes(),
	AnnotationTypeDoc.class);
  } else if (methodName.equals("enums")) {
    return filter(((PackageDoc) target).enums(),
	ClassDoc.class);
  } else if (methodName.equals("errors")) {
    return filter(((PackageDoc) target).errors(),
	ClassDoc.class);
  } else if (methodName.equals("exceptions")) {
    return filter(((PackageDoc) target).exceptions(),
	ClassDoc.class);
  } else if (methodName.equals("interfaces")) {
    return filter(((PackageDoc) target).interfaces(),
	ClassDoc.class);
  } else if (methodName.equals("ordinaryClasses")) {
    return filter(((PackageDoc) target).ordinaryClasses(),
	ClassDoc.class);
  }
}
     }

     if (args != null) {
if (methodName.equals("compareTo") || methodName.equals("equals")
    || methodName.equals("overrides")
    || methodName.equals("subclassOf")) {
  args[0] = unwrap(args[0]);
}
     }
     try {
return process(method.invoke(target, args), method.getReturnType());
     } catch (InvocationTargetException e) {
throw e.getTargetException();
     }
   }
 
Example #10
Source File: NoProxyInstaller.java    From sarl with Apache License 2.0 4 votes vote down vote up
@Override
public AnnotationTypeDoc wrap(AnnotationTypeDoc obj) {
	return obj;
}
 
Example #11
Source File: JreProxyInstaller.java    From sarl with Apache License 2.0 4 votes vote down vote up
@Override
public AnnotationTypeDoc wrap(AnnotationTypeDoc obj) {
	return (AnnotationTypeDoc) wrap((Object) obj);
}
 
Example #12
Source File: RootDocProcessor.java    From hadoop with Apache License 2.0 4 votes vote down vote up
@Override
   public Object invoke(Object proxy, Method method, Object[] args)
throws Throwable {
     String methodName = method.getName();
     if (target instanceof Doc) {
if (methodName.equals("isIncluded")) {
  Doc doc = (Doc) target;
  return !exclude(doc) && doc.isIncluded();
}
if (target instanceof RootDoc) {
  if (methodName.equals("classes")) {
    return filter(((RootDoc) target).classes(), ClassDoc.class);
  } else if (methodName.equals("specifiedClasses")) {
    return filter(((RootDoc) target).specifiedClasses(), ClassDoc.class);
  } else if (methodName.equals("specifiedPackages")) {
    return filter(((RootDoc) target).specifiedPackages(), PackageDoc.class);
  }
} else if (target instanceof ClassDoc) {
  if (isFiltered(args)) {
    if (methodName.equals("methods")) {
      return filter(((ClassDoc) target).methods(true), MethodDoc.class);
    } else if (methodName.equals("fields")) {
      return filter(((ClassDoc) target).fields(true), FieldDoc.class);
    } else if (methodName.equals("innerClasses")) {
      return filter(((ClassDoc) target).innerClasses(true),
	  ClassDoc.class);
    } else if (methodName.equals("constructors")) {
      return filter(((ClassDoc) target).constructors(true),
	  ConstructorDoc.class);
    }
  }
} else if (target instanceof PackageDoc) {
  if (methodName.equals("allClasses")) {
    if (isFiltered(args)) {
      return filter(((PackageDoc) target).allClasses(true),
	ClassDoc.class);
    } else {
      return filter(((PackageDoc) target).allClasses(), ClassDoc.class);  
    }
  } else if (methodName.equals("annotationTypes")) {
    return filter(((PackageDoc) target).annotationTypes(),
	AnnotationTypeDoc.class);
  } else if (methodName.equals("enums")) {
    return filter(((PackageDoc) target).enums(),
	ClassDoc.class);
  } else if (methodName.equals("errors")) {
    return filter(((PackageDoc) target).errors(),
	ClassDoc.class);
  } else if (methodName.equals("exceptions")) {
    return filter(((PackageDoc) target).exceptions(),
	ClassDoc.class);
  } else if (methodName.equals("interfaces")) {
    return filter(((PackageDoc) target).interfaces(),
	ClassDoc.class);
  } else if (methodName.equals("ordinaryClasses")) {
    return filter(((PackageDoc) target).ordinaryClasses(),
	ClassDoc.class);
  }
}
     }

     if (args != null) {
if (methodName.equals("compareTo") || methodName.equals("equals")
    || methodName.equals("overrides")
    || methodName.equals("subclassOf")) {
  args[0] = unwrap(args[0]);
}
     }
     try {
return process(method.invoke(target, args), method.getReturnType());
     } catch (InvocationTargetException e) {
throw e.getTargetException();
     }
   }
 
Example #13
Source File: ProgrammaticWrappingProxyInstaller.java    From sarl with Apache License 2.0 4 votes vote down vote up
@Override
public AnnotationTypeDoc asAnnotationTypeDoc() {
	return wrap(this.delegate.asAnnotationTypeDoc());
}
 
Example #14
Source File: ProgrammaticWrappingProxyInstaller.java    From sarl with Apache License 2.0 4 votes vote down vote up
@Override
public AnnotationTypeDoc[] annotationTypes() {
	return wrap(this.delegate.annotationTypes());
}
 
Example #15
Source File: ProgrammaticWrappingProxyInstaller.java    From sarl with Apache License 2.0 4 votes vote down vote up
@Override
public AnnotationTypeDoc asAnnotationTypeDoc() {
	return wrap(this.delegate.asAnnotationTypeDoc());
}
 
Example #16
Source File: SarlWriterFactory.java    From sarl with Apache License 2.0 4 votes vote down vote up
@Override
public AnnotationTypeWriter getAnnotationTypeWriter(AnnotationTypeDoc annotationType, Type prevType, Type nextType)
		throws Exception {
	return new SarlAnnotationTypeWriter(this.configuration, annotationType, prevType, nextType);
}
 
Example #17
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;
}
 
Example #18
Source File: ProxyInstaller.java    From sarl with Apache License 2.0 2 votes vote down vote up
/** Wrap the given annotation type documentation.
 *
 * @param obj the document to filter.
 * @return the filtered {@code obj}.
 */
AnnotationTypeDoc wrap(AnnotationTypeDoc obj);
 
Example #19
Source File: SarlAnnotationTypeWriter.java    From sarl with Apache License 2.0 2 votes vote down vote up
/** Constructor.
 * @param configuration the configuration.
 * @param annotationType the type.
 * @param prevType the previous type.
 * @param nextType the next type.
 * @throws Exception in case of error.
 */
public SarlAnnotationTypeWriter(ConfigurationImpl configuration, AnnotationTypeDoc annotationType, Type prevType,
		Type nextType) throws Exception {
	super(configuration, annotationType, prevType, nextType);
}