本文整理了Java中com.github.javaparser.ast.CompilationUnit.getChildNodesByType()
方法的一些代码示例,展示了CompilationUnit.getChildNodesByType()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。CompilationUnit.getChildNodesByType()
方法的具体详情如下:
包路径:com.github.javaparser.ast.CompilationUnit
类名称:CompilationUnit
方法名:getChildNodesByType
暂无
代码示例来源:origin: YeDaxia/JApiDocs
@Test
public void test_parseGenericClassNode(){
File resultJavaFile = Projects.getTestJavaFile(GenericResult.class);
ParseUtils.compilationUnit(resultJavaFile).getChildNodesByType(MethodDeclaration.class).forEach(md->{
md.getType();
});
ParseUtils.compilationUnit(resultJavaFile).getClassByName("GenericResult")
.ifPresent(classDeclaration -> {
NodeList<TypeParameter> typeParameters = classDeclaration.getTypeParameters();
for(int i = 0, len = typeParameters.size(); i != len; i++){
System.out.println(typeParameters.get(i).getName());
}
});
}
}
代码示例来源:origin: javaparser/javasymbolsolver
@Test
public void testSolvingMethodWitPrimitiveParameterTypeAsUsage() throws ParseException {
String code =
"class Test { "
+ " long l = call(1); "
+ " long call(final long i) { "
+ " return i; "
+ " }"
+ "}";
CompilationUnit cu = JavaParser.parse(code);
MethodCallExpr methodCall = cu.getChildNodesByType(MethodCallExpr.class).get(0);
JavaParserFacade parserFacade = JavaParserFacade.get(new ReflectionTypeSolver());
MethodUsage solvedCall = parserFacade.solveMethodAsUsage(methodCall);
assertEquals("long", solvedCall.getParamType(0).describe());
}
}
内容来源于网络,如有侵权,请联系作者删除!