Java Code Examples for com.intellij.psi.PsiElement#getUseScope()
The following examples show how to use
com.intellij.psi.PsiElement#getUseScope() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UseScopeTestCase.java From BashSupport with Apache License 2.0 | 6 votes |
@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())); }
Example 2
Source File: ScratchFileServiceImpl.java From consulo with Apache License 2.0 | 5 votes |
@Nullable @Override public SearchScope getAdditionalUseScope(@Nonnull PsiElement element) { SearchScope useScope = element.getUseScope(); if (useScope instanceof LocalSearchScope) return null; return ScratchesSearchScope.getScratchesScope(element.getProject()); }
Example 3
Source File: BaseRefactoringProcessor.java From consulo with Apache License 2.0 | 5 votes |
private Set<UnloadedModuleDescription> computeUnloadedModulesFromUseScope(UsageViewDescriptor descriptor) { if (ModuleManager.getInstance(myProject).getUnloadedModuleDescriptions().isEmpty()) { //optimization return Collections.emptySet(); } Set<UnloadedModuleDescription> unloadedModulesInUseScope = new LinkedHashSet<>(); for (PsiElement element : descriptor.getElements()) { SearchScope useScope = element.getUseScope(); if (useScope instanceof GlobalSearchScope) { unloadedModulesInUseScope.addAll(((GlobalSearchScope)useScope).getUnloadedModulesBelongingToScope()); } } return unloadedModulesInUseScope; }