There is a little problem with JavaParser usage.
I've parsed source code file and get all methods from parsed interface. Each method has a few parameters. I can get types of this parameters as string, but I couldn't get original package name or class name of this type. I always get java parser classes names or packages. But I need original package name. En example if parsed method parameter has type String I wont his class name etc.
P.S parsing action is executing in build.gladle before compile task. Reflection is not possible.
Code:
// Create compilation unit for parsed file
CompilationUnit cu = StaticJavaParser.parse(sourceFile);
// Get ClassOrInterfaceDeclaration optional from the compilation unit for parsed file
Optional<ClassOrInterfaceDeclaration> parsedInterfaceOptional =
cu.getInterfaceByName("InterfaceName");
// Get ClassOrInterfaceDeclaration from optional
ClassOrInterfaceDeclaration parsedInterface = parsedInterfaceOptional.get();
for (MethodDeclaration method : parsedInterface.findAll(MethodDeclaration.class)) {
final NodeList<Parameter> parameters = method.getParameters();
// At this step I already have a list of method parameters(parameters).
// I am iterating through the all method parameters and try to get
// original class name or class or package of the parameter type
for (Parameter parameter : parameters) {
// Trying to get original class of the parameter type
Class parameterTypeOriginalClass = parameter.type...
}
Please help if you know how to do it. Still actual.