0

I have setup the JavaSymbolSolver like below:

Instance Variables:

private CombinedTypeSolver combinedTypeSolver = new CombinedTypeSolver();
private JavaSymbolSolver symbolSolver;
private ParserConfiguration parserConfiguration = new 
ParserConfiguration();
private JavaParser parser;
private CompilationUnit compilationUnit = null;
private ParseResult<CompilationUnit> parseResultcompilationUnit = null;

from constructor:

this.combinedTypeSolver.add(new ReflectionTypeSolver());
this.combinedTypeSolver.add((new JavaParserTypeSolver("C:\\Users\\nfountou\\git\\TestingJavaParser\\rsc")));
this.combinedTypeSolver.add((new JavaParserTypeSolver("C:\\Users\\nfountou\\git\\TestingJavaParser")));
this.symbolSolver = new JavaSymbolSolver(this.combinedTypeSolver);

this.parserConfiguration.setSymbolResolver(this.symbolSolver);
this.parser = new JavaParser(parserConfiguration);

FileInputStream in = new FileInputStream(filepath);

this.parseResultcompilationUnit = this.parser.parse(in);

this.compilationUnit = parseResultcompilationUnit.getResult().get();

The test code seems to work fine and I am being able to resolve e.g. class B of class A as can be seen below:

public class A extends B{

}

the problem is that it seems that I cannot resolve anything else and whatever I tried I receive the message below:

Exception in thread "main" java.lang.IllegalStateException: No data of this type found. Use containsData to check for this first.

For example the source code that I am running for resolving e.g an AssignExpr:

ResolvedType declaringType = ((AssignExpr) value).calculateResolvedType();

(where value is an object that holds an AssignExpr node)

Resolving a superclass works fine and returns the right values:

ResolvedClassDeclaration declaringType = ((ClassOrInterfaceType) value).resolve().getTypeDeclaration().asClass();

Any ideas what am I doing wrong?

nfountou
  • 11
  • 4

1 Answers1

1

I found what was the issue... Source code is fine and it passes the configuration to the parser in the right way. The problem was that as I was refactoring code, I created a class and named it "SymbolSolver" which was causing the problem as javaparser uses a class with that specific name... Also another problem was that I was using wrapppedNode Nodes which do not hold the configuration from symbolsolver.

nfountou
  • 11
  • 4