com.gitee.l0km.javadocreader.JavadocParameterNames Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of javadocreader9 Show documentation
Show all versions of javadocreader9 Show documentation
read comments from java source using javadoc
package com.gitee.l0km.javadocreader;
import java.lang.reflect.Member;
import javax.lang.model.element.TypeElement;
import com.gitee.l0km.com4j.base.BaseParameterNames;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* 基于JavaDoc解析类的源码实现获取构造函数或方法的参数名
* @author guyadong
*
*/
public class JavadocParameterNames extends BaseParameterNames {
private final ExtClassDoc extClassDoc;
public JavadocParameterNames(Class> clazz) {
super(clazz);
this.extClassDoc = JavadocReader.read(clazz);
}
public JavadocParameterNames(ExtClassDoc extClassDoc) {
super(toClass(extClassDoc));
this.extClassDoc = extClassDoc;
}
private static Class> toClass(TypeElement classDoc){
try {
return Class.forName(checkNotNull(classDoc,"classDoc is null").getQualifiedName().toString());
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
private static Class> toClass(ExtClassDoc extClassDoc){
return toClass(checkNotNull(extClassDoc,"extClassDoc is null").getClassDoc());
}
@Override
protected String[] doGetParameterNames(Member member) {
if(extClassDoc != null && clazz != null){
TypeElement classDoc = extClassDoc.getClassDoc();
if(classDoc != null){
return extClassDoc.getParamerNames(member);
}
}
return null;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy