@Test private void testTwoStepInclusion(String firstFile, String secondFile) throws Exception { PsiReference reference = configure(); Assert.assertNotNull(reference); PsiFile includeFile = addFile(firstFile); PsiFile include2File = addFile(secondFile); //the var has to resolve to the definition in the included file PsiElement varDef = reference.resolve(); Assert.assertNotNull("Variable is not properly resolved", varDef); boolean defIsInIncludeFile = varDef.getContainingFile().equals(include2File); Assert.assertTrue("The variable must be defined in the include file.", defIsInIncludeFile); GlobalSearchScope resolveScope = reference.getElement().getResolveScope(); Assert.assertTrue("A file must be in its own resolve scope", resolveScope.contains(myFile.getVirtualFile())); Assert.assertTrue("The variable must be resolved to the definition in 'include2.bash'", include2File.equals(varDef.getContainingFile())); Assert.assertTrue("An included file must be in the resolve scope", resolveScope.contains(varDef.getContainingFile().getVirtualFile())); Assert.assertTrue("The included file must be in the resolve scope", resolveScope.contains(include2File.getVirtualFile())); Assert.assertTrue("The included file (second inclusion step) must be in the resolve scope", resolveScope.contains(includeFile.getVirtualFile())); } }
@Test public void testUseScope() throws Exception { PsiReference variableReference = configure(); PsiFile included = addFile("included.bash"); PsiFile notIncluded = addFile("notIncluded.bash"); PsiElement varDef = variableReference.resolve(); Assert.assertNotNull("Var must resolve", varDef); Assert.assertTrue("var def must resolve to the definition in included.bash", included.equals(varDef.getContainingFile())); SearchScope varDefUseScope = varDef.getUseScope(); Assert.assertTrue("Invalid type of scope: " + varDefUseScope, varDefUseScope instanceof GlobalSearchScope); GlobalSearchScope useScope = (GlobalSearchScope) varDefUseScope; Assert.assertTrue("The use scope must contain the original file itself.", useScope.contains(included.getVirtualFile())); //must contain the file which contains the include statement Assert.assertTrue("The use scope must contain the files which include the source file.", useScope.contains(myFile.getVirtualFile())); //must not contain the file which does not include the inspected file Assert.assertFalse("The use scope must not contain any other file.", useScope.contains(notIncluded.getVirtualFile())); } }
@Test public void testSimpleScope() throws Exception { PsiReference reference = configure(); Assert.assertNotNull(reference); PsiFile includeFile = addFile("include.bash"); PsiFile include2File = addFile("include2.bash"); //the var has to resolve to the definition in the included file PsiElement def = reference.resolve(); Assert.assertNotNull("Variable is not properly resolved", def); boolean defIsInIncludeFile = def.getContainingFile().equals(includeFile); if (true) { Assert.assertTrue("The variable is not defined in the include file.", defIsInIncludeFile); } else { Assert.assertFalse("The variable must not be defined in the include file.", defIsInIncludeFile); } Assert.assertFalse("Resolve returned invalid containing file.", def.getContainingFile().equals(myFile)); //the search scope must contain all the included files but nothing else GlobalSearchScope resolveScope = reference.getElement().getResolveScope(); Assert.assertTrue("A file must be in its own resolve scope", resolveScope.contains(myFile.getVirtualFile())); Assert.assertTrue("An included file must be in the resolve scope", resolveScope.contains(def.getContainingFile().getVirtualFile())); //must not be included Assert.assertFalse("An excluded file must not be in the resolve scope", resolveScope.contains(include2File.getVirtualFile())); }