How to test with PsiTypeClass.resolve()? Follow
Answered
Hi,
The following line returns null in LightCodeInsightFixtureTestCase, FileEditorManagerTestCase, LightPlatformCodeInsightFixtureTestCase.
PsiClassType.getTypeByName("java.util.List", getProject(), GlobalSearchScope.allScope(getProject())).resolve()
Return empty map:
PsiClassType.getTypeByName("java.util.List", getProject(), lobalSearchScope.allScope(getProject())).resolveGenerics().getSubstitutor().getSubstitutionMap()
Please sign in to leave a comment.
Is mock JDK added to the test module? (ModuleRootManager#getSdk, IdeaTestUtil.getMockJdk18())
Thanks for the hint, but I have no clue how to put everything together :(
What is the base class should be?
public class PsiClassTypeTest extends PlatformTestCase {
public void setUp() throws Exception {
super.setUp();
ModuleRootManager.getInstance(getModule())
.getModifiableModel().setSdk(IdeaTestUtil.getMockJdk18());
}
protected Sdk getTestProjectJdk() {
return IdeaTestUtil.getMockJdk18(); //super.getTestProjectJdk();
}
LightCodeInsightFixtureTestCase is a perfectly suitable base class, but please check if the returned mock jdk has meaningful content (i.e. its path contains the jars that should be in a mock jdk).
Thanks to JesusFreke from irc #idea-users,
Here it's a working test
https://github.com/JesusFreke/smali/blob/master/smalidea/src/test/java/org/jf/smalidea/ClassReferenceTest.java
In short there 2 points: extend ResolveTestCase and override
protected Sdk getTestProjectJdk() {
return JavaAwareProjectJdkTableImpl.getInstanceEx().getInternalJdk();
}
I'm glad that you have it working. I'd still recommend to make use of mock JDK, since it's much smaller and faster to index, and so the test's first startup after index version change would be faster.
I have a similar case and I didn't get it working even when extending ResolveTestCase and overriding getTestProjectJdk().
The test blocks from first post return null in my case.
So I reverted to what I started with. What I am doing:
However, methods are not resolved.
Peter wrote above that we should check JDK real path, for me it is mock JDK - I check it by
. How can I set it / change JDK when I am extending this LightCodeInsightFixtureTestCase?
I would really appreciate help here. The test file which does not work is https://github.com/hermanurikh/concbugs/blob/feature/add_idea_mapping/src/test/java/com/qbutton/concbugs/inspection/deadlock/mapping/PsiToAlgorythmFacadeTest.java , the test method - wait_success.
Just in case someone has the same problems, I managed to get resolve() working with LightCodeInsightFixtureTestCase by using following: