I have a path to a .java class like "./src/module/car.java" and i parse it like this:
File sourceFileCar = new File("./src/module/car.java");
CompilationUnit cuCar = StaticJavaParser.parse(sourceFileCar);
How can I get the class name in the car.java file without knowing it before (cant use cuCar.getClassByName)
To access the parsed file, you have to create a visitor class which extends the VoidVisitorAdapter class.
After created a class, you have to override visit() method which job is to visit nodes in parsed file. In this case, we use ClassOrInterfaceDeclaration as a method parameter to get the class name and pass List for collecting the name.
In the main class, create a visitor object for using visit() which getting compilation object and list as parameters.
The result shows below.
Hope this might solves you question :)