下面列出了怎么用com.sun.javadoc.ConstructorDoc的API类实例代码及写法,或者点击链接到github查看源代码。
/** Wrap a constructor doc.
*
* @param source the source
* @return the wrapper.
*/
public ConstructorDoc wrap(ConstructorDoc source) {
if (source == null || source instanceof Proxy<?> || !(source instanceof ConstructorDocImpl)) {
return source;
}
return new ConstructorDocWrapper((ConstructorDocImpl) source);
}
/** Wrap a constructor doc.
*
* @param source the source
* @return the wrapper.
*/
public ConstructorDoc[] wrap(ConstructorDoc[] source) {
if (source == null) {
return null;
}
final List<ConstructorDoc> list = new ArrayList<>();
for (final ConstructorDoc element : source) {
if (isIncluded(element)) {
list.add(wrap(element));
}
}
return Utils.toArray(source, list);
}
@Override
public Content getSignature(ConstructorDoc constructor) {
final Content pre = new HtmlTree(HtmlTag.PRE);
addAnnotations(constructor, pre);
addModifiers(constructor, pre);
pre.addContent(Utils.keyword(Utils.getKeywords().getNewKeyword()));
final int indent = pre.charCount();
addParameters(constructor, pre, indent);
addTypeParameters(constructor, pre);
addExceptions(constructor, pre, indent);
return pre;
}
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;
}
@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();
}
}
@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();
}
}
@Override
public ConstructorDoc[] constructors() {
return wrap(this.delegate.constructors());
}
@Override
public ConstructorDoc[] constructors(boolean arg0) {
return wrap(this.delegate.constructors(arg0));
}
@Override
public ConstructorDoc findConstructor(String constrName, String[] paramTypes) {
return wrap(this.delegate.findConstructor(constrName, paramTypes));
}
@Override
public ConstructorDoc[] constructors() {
return wrap(this.delegate.constructors());
}
@Override
public ConstructorDoc[] constructors(boolean arg0) {
return wrap(this.delegate.constructors(arg0));
}
@Override
public ConstructorDoc findConstructor(String constrName, String[] paramTypes) {
return wrap(this.delegate.findConstructor(constrName, paramTypes));
}
protected Class parseClass(ClassDoc classDoc) {
Class classNode = objectFactory.createClass();
classNode.setName(classDoc.name());
classNode.setQualified(classDoc.qualifiedName());
String comment = classDoc.commentText();
if (comment.length() > 0) {
classNode.setComment(comment);
}
classNode.setAbstract(classDoc.isAbstract());
classNode.setError(classDoc.isError());
classNode.setException(classDoc.isException());
classNode.setExternalizable(classDoc.isExternalizable());
classNode.setIncluded(classDoc.isIncluded());
classNode.setSerializable(classDoc.isSerializable());
classNode.setScope(parseScope(classDoc));
for (TypeVariable typeVariable : classDoc.typeParameters()) {
classNode.getGeneric().add(parseTypeParameter(typeVariable));
}
Type superClassType = classDoc.superclassType();
if (superClassType != null) {
classNode.setClazz(parseTypeInfo(superClassType));
}
for (Type interfaceType : classDoc.interfaceTypes()) {
classNode.getInterface().add(parseTypeInfo(interfaceType));
}
for (MethodDoc method : classDoc.methods()) {
classNode.getMethod().add(parseMethod(method));
}
for (AnnotationDesc annotationDesc : classDoc.annotations()) {
classNode.getAnnotation().add(parseAnnotationDesc(annotationDesc, classDoc.qualifiedName()));
}
for (ConstructorDoc constructor : classDoc.constructors()) {
classNode.getConstructor().add(parseConstructor(constructor));
}
for (FieldDoc field : classDoc.fields()) {
classNode.getField().add(parseField(field));
}
for (Tag tag : classDoc.tags()) {
classNode.getTag().add(parseTag(tag));
}
return classNode;
}