不太确定我是否理解您的问题-您想让班上所有的现场成员吗?如果是这样,您可以这样做:
CompilationUnit cu = JavaParser.parse(javaFile);
for (TypeDeclaration typeDec : cu.getTypes()) {
List members = typeDec.getMembers();
if(members != null) {
for (BodyDeclaration member : members) {
//Check just members that are FieldDeclarations
FieldDeclaration field = (FieldDeclaration) member;
//Print the field's class typr
System.out.println(field.getType());
//Print the field's name
System.out.println(field.getVariables().get(0).getId().getName());
//Print the field's init value, if not null
Object initValue = field.getVariables().get(0).getInit();
if(initValue != null) {
System.out.println(field.getVariables().get(0).getInit().toString());
}
}
}
此代码示例将根据您的情况进行打印:
关键词
浏览器
串
页面标题
“登录”
我希望这确实是您的问题…如果没有,请发表评论.