1 package com.github.javaparser.symbolsolver; 2 3 import com.github.javaparser.JavaParser; 4 import com.github.javaparser.ParseResult; 5 import com.github.javaparser.ParseStart; 6 import com.github.javaparser.StringProvider; 7 import com.github.javaparser.ast.CompilationUnit; 8 import com.github.javaparser.ast.expr.FieldAccessExpr; 9 import com.github.javaparser.ast.expr.MethodCallExpr; 10 import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration; 11 import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; 12 import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; 13 import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; 14 import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; 15 import org.junit.jupiter.api.Test; 16 17 import static org.junit.jupiter.api.Assertions.assertEquals; 18 19 class Issue1946Test { 20 21 22 @Test issueWithInternalEnumConstantReference()23 void issueWithInternalEnumConstantReference() { 24 String code = "package com.github.javaparser.symbolsolver.testingclasses; class Foo { void foo() { UtilityClass.method(SomeClass.InnerEnum.CONSTANT); } }"; 25 JavaParser jp = new JavaParser(); 26 CombinedTypeSolver typeSolver = new CombinedTypeSolver(new TypeSolver[] { 27 new ReflectionTypeSolver(false) 28 }); 29 jp.getParserConfiguration().setSymbolResolver(new JavaSymbolSolver(typeSolver)); 30 ParseResult<CompilationUnit> pr = jp.parse(ParseStart.COMPILATION_UNIT, new StringProvider(code)); 31 assertEquals(true, pr.isSuccessful()); 32 MethodCallExpr methodCallExpr = pr.getResult().get().findFirst(MethodCallExpr.class).get(); 33 ResolvedMethodDeclaration rmd = methodCallExpr.resolve(); 34 assertEquals("com.github.javaparser.symbolsolver.testingclasses.UtilityClass.method(com.github.javaparser.symbolsolver.testingclasses.SomeClass.InnerEnum)", rmd.getQualifiedSignature()); 35 FieldAccessExpr fieldAccessExpr = methodCallExpr.findFirst(FieldAccessExpr.class).get(); 36 ResolvedValueDeclaration rvd = fieldAccessExpr.resolve(); 37 assertEquals("CONSTANT", rvd.getName()); 38 assertEquals("com.github.javaparser.symbolsolver.testingclasses.SomeClass.InnerEnum", rvd.getType().describe()); 39 } 40 } 41