-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Symbol solver is unable to resolve inherited inner classes #3946
Comments
@freya022 I'm sorry for this setback but I can't move forward on this if your test case doesn't compile. Moreover, all the test cases run correctly, so it was difficult to anticipate the issue that you observed. This is a special case that can be solved by removing the prefix in the return type "RichPresence.Timestamps" or replacing it with Activity. This is not a satisfactory answer, but it is a workaround that will allow you to avoid encountering this error. |
To be clear, the earlier issue I linked has no issues, and does still pass the test cases, I was just thinking that this new issue could be related to it. Here's the unit test: import com.github.javaparser.StaticJavaParser;
import com.github.javaparser.ast.CompilationUnit;
import com.github.javaparser.ast.body.MethodDeclaration;
import com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest;
import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver;
import org.junit.jupiter.api.Test;
import java.util.List;
import java.util.stream.Collectors;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class Issue3946Test extends AbstractResolutionTest {
@Test
void test() {
String code =
"interface Activity {\n" +
" class Timestamps {}\n" +
" \n" +
" Timestamps getTimestamps();\n" +
"}\n" +
"\n" +
"interface RichPresence extends Activity {}\n" +
"\n" +
"class ActivityImpl implements Activity {\n" +
" public RichPresence.Timestamps getTimestamps() { return timestamps; }\n" +
"}\n" +
"\n" +
"class RichPresenceImpl extends ActivityImpl implements RichPresence { }";
final JavaSymbolSolver solver = new JavaSymbolSolver(new ReflectionTypeSolver(false));
StaticJavaParser.getParserConfiguration().setSymbolResolver(solver);
final CompilationUnit compilationUnit = StaticJavaParser.parse(code);
final List<String> returnTypes = compilationUnit.findAll(MethodDeclaration.class)
.stream()
.map(md -> md.resolve())
.map(rmd -> rmd.getReturnType().describe())
.collect(Collectors.toList());
returnTypes.forEach(type -> assertEquals("Activity.Timestamps", type));
}
} |
Thanks for reporting this new issue. |
To be clear the error was in the code that JP needs to analyze. |
Alright, is the full unit test provided enough? |
Fix: issue #3946 Symbol solver is unable to resolve inherited inner classes
Problem
The symbol solver is unable to resolve the return type of
ActivityImpl#getTimestamps
due to a change introduced in 3.25.1Test code
Exception
Workaround
Stay on 3.25.0
Details
The bug may be similar to the one fixed in 3.25.0+ (#3868)
The text was updated successfully, but these errors were encountered: