Skip to content

Commit

Permalink
Fix issue #3614 UnsolvedSymbolException when package declaration cont…
Browse files Browse the repository at this point in the history
…ains comment
  • Loading branch information
jlerbsc committed Aug 18, 2022
1 parent 14e64c1 commit f6e05d1
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@



import static com.github.javaparser.symbolsolver.javaparsermodel.contexts.AbstractJavaParserContext.isQualifiedName;

import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
Expand Down Expand Up @@ -60,6 +58,8 @@
* @author Federico Tomassetti
*/
public class CompilationUnitContext extends AbstractJavaParserContext<CompilationUnit> {

private static final String DEFAULT_PACKAGE = "java.lang";

///
/// Static methods
Expand Down Expand Up @@ -199,7 +199,7 @@ public SymbolReference<ResolvedTypeDeclaration> solveType(String name) {

// Look in current package
if (this.wrappedNode.getPackageDeclaration().isPresent()) {
String qName = this.wrappedNode.getPackageDeclaration().get().getName().toString() + "." + name;
String qName = this.wrappedNode.getPackageDeclaration().get().getNameAsString() + "." + name;
SymbolReference<ResolvedReferenceTypeDeclaration> ref = typeSolver.tryToSolveType(qName);
if (ref != null && ref.isSolved()) {
return SymbolReference.adapt(ref, ResolvedTypeDeclaration.class);
Expand All @@ -225,7 +225,7 @@ public SymbolReference<ResolvedTypeDeclaration> solveType(String name) {
}

// Look in the java.lang package
SymbolReference<ResolvedReferenceTypeDeclaration> ref = typeSolver.tryToSolveType("java.lang." + name);
SymbolReference<ResolvedReferenceTypeDeclaration> ref = typeSolver.tryToSolveType(DEFAULT_PACKAGE+ "." + name);
if (ref != null && ref.isSolved()) {
return SymbolReference.adapt(ref, ResolvedTypeDeclaration.class);
}
Expand Down

0 comments on commit f6e05d1

Please sign in to comment.