I am using
javaparser (https://github.com/javaparser/javaparser) and javasymbolsolver (https://github.com/javaparser/javasymbolsolver).
to parse java source code. I am looking to create a basic report from a .java file to list the method signatures, and would be nice if they included the complete java types.
so is a basic merge of the javaparser 'visit' demo, and javasymbolsolver demo, but I'm running into the wall.
blowing up on 'getType' call, with
Exception in thread "main" java.lang.UnsupportedOperationException: com.github.javaparser.ast.type.ClassOrInterfaceType
at me.tomassetti.symbolsolver.javaparsermodel.JavaParserFacade.getTypeConcrete(JavaParserFacade.java:392)
Here is the (non working) code,
static CombinedTypeSolver combinedTypeSolver;
public static void main(String[] args) throws Exception {
combinedTypeSolver = new CombinedTypeSolver();
combinedTypeSolver.add(new JreTypeSolver());
combinedTypeSolver.add(new JarTypeSolver("C:/source.jar"));
combinedTypeSolver.add(new JavaParserTypeSolver(new File("C:/src")));
FileInputStream in = new FileInputStream("C:/src/source.java");
CompilationUnit cu = JavaParser.parse(in);
new MethodVisitor().visit(cu, null);
}
private static class MethodVisitor extends VoidVisitorAdapter<Void> {
public void visit(MethodDeclaration n, Void arg) {
Node node = n.getType();
System.out.println(node);
TypeUsage typeOfTheNode = JavaParserFacade.get(combinedTypeSolver).getType(node);
super.visit(n, arg);
}
}