对于以下类型:
public final String name;
public final String signature;
public final String returnType;
public final Type returnFullType; // com.github.javaparser.ast.type.Type
public final String body;
public final String[] modifiers;
public final String[] parameterNames;
public final String[] parameterTypes;
public final Type[] parameterFullTypes; // com.github.javaparser.ast.type.Type
public final String[] exceptions;
public final String jdComment;
public final MethodDeclaration nativeJP_API_reference; // com.github.javaparser.ast.body.MethodDeclaration
Method
这是我自己的混合物类的构造函数:
Method (MethodDeclaration md)
{
NodeList<Modifier> ml = md.getModifiers();
NodeList<Parameter> pl = md.getParameters();
NodeList<ReferenceType> te = md.getThrownExceptions();
this.nativeJP_API_reference = md;
this.name = md.getNameAsString();
this.signature = md.getDeclarationAsString();
this.returnType = md.getType().toString();
this.returnFullType = md.getType();
this.body = md.getBody().isPresent() ? md.getBody().get().toString() : null; // In ConstructorDeclaration, this is an Optional<BlockStmt>, not here!
this.modifiers = new String[ml.size()];
this.parameterNames = new String[pl.size()];
this.parameterTypes = new String[pl.size()];
this.parameterFullTypes = new com.github.javaparser.ast.type.Type[pl.size()];
this.exceptions = new String[te.size()];
this.jdComment = md.hasJavaDocComment() ? md.getJavadocComment().get().toString() : null;
int i = 0;
for (Parameter p : pl)
{
parameterNames[i] = p.getName().toString();
parameterTypes[i] = p.getType().toString();
parameterFullTypes[i] = p.getType();
i++;
}
i = 0;
for (Modifier m : ml) modifiers[i++] = m.toString();
i = 0;
for (ReferenceType r : te) exceptions[i++] = r.toString();;
}