本文整理汇总了Java中com.intellij.psi.search.GlobalSearchScope类的典型用法代码示例。如果您正苦于以下问题:Java GlobalSearchScope类的具体用法?Java GlobalSearchScope怎么用?Java GlobalSearchScope使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
GlobalSearchScope类属于com.intellij.psi.search包,在下文中一共展示了GlobalSearchScope类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: generate
import com.intellij.psi.search.GlobalSearchScope; //导入依赖的package包/类
@Override
public Set<TSVarExpr> generate(Project project) {
Set<TSVarExpr> items = new HashSet<>();
//Search every file in the project
Collection<VirtualFile> virtualFiles = FileBasedIndex.getInstance().getContainingFiles(FileTypeIndex.NAME, TSFileType.INSTANCE, GlobalSearchScope.projectScope(project));
for (VirtualFile virtualFile : virtualFiles) {
TSFile tsFile = (TSFile) PsiManager.getInstance(project).findFile(virtualFile);
if (tsFile != null) {
Collection<TSAssignExpr> assignments = PsiTreeUtil.findChildrenOfType(tsFile, TSAssignExpr.class);
for (TSAssignExpr assignment : assignments) {
PsiElement first = assignment.getFirstChild();
if (!(first instanceof TSVarExpr))
continue;
if (((TSVarExpr)first).isLocal())
continue;
items.add((TSVarExpr) first);
}
}
ProgressManager.progress("Loading Symbols");
}
return items;
}
示例2: should_process_reference
import com.intellij.psi.search.GlobalSearchScope; //导入依赖的package包/类
@Test
public void should_process_reference() throws Exception {
// given
PsiReference reference1 = mock(PsiReference.class);
PsiReference reference2 = mock(PsiReference.class);
PsiField field = mock(PsiField.class);
ReferencesSearch.SearchParameters searchParameters = mock(ReferencesSearch.SearchParameters.class);
when(searchParameters.getElementToSearch()).thenReturn(field);
when(searchParameters.getEffectiveSearchScope()).thenReturn(mock(GlobalSearchScope.class));
when(scenarioStateReferenceProvider.findReferences(field)).thenReturn(Arrays.asList(reference1, reference2));
when(scenarioStateProvider.isJGivenScenarioState(field)).thenReturn(true);
// when
referenceProvider.processQuery(searchParameters, processor);
// then
verify(processor).process(reference1);
verify(processor).process(reference2);
}
示例3: resolve
import com.intellij.psi.search.GlobalSearchScope; //导入依赖的package包/类
@Nullable
@Override
public PsiElement resolve() {
PsiElement parent = PsiTreeUtil.getParentOfType(myElement, PsiLet.class);
// If name is used in a let definition, it's already the reference
if (parent instanceof PsiLet && ((PsiLet) parent).getNameIdentifier() == myElement) {
return myElement;
}
// Find the name in the index
Collection<PsiLet> elements = StubIndex.getElements(IndexKeys.LETS, m_referenceName, myElement.getProject(), GlobalSearchScope.allScope(myElement.getProject()), PsiLet.class);
if (!elements.isEmpty()) {
// TODO: only let with correct QN
PsiLet let = elements.iterator().next();
return let.getNameIdentifier();
}
return null;
}
示例4: findUsages
import com.intellij.psi.search.GlobalSearchScope; //导入依赖的package包/类
@Nullable
@Override
public List<UsageInfo> findUsages( PsiFile psiFile, PsiDirectory newParent, boolean searchInComments, boolean searchInNonJavaFiles )
{
Module mod = ModuleUtilCore.findModuleForPsiElement( psiFile );
ManModule module = ManProject.getModule( mod );
PsiClass psiClass = findPsiClass( psiFile );
if( psiClass == null )
{
return Collections.emptyList();
}
Query<PsiReference> search = ReferencesSearch.search( psiClass, GlobalSearchScope.moduleWithDependenciesAndLibrariesScope( module.getIjModule() ) );
List<UsageInfo> usages = new ArrayList<>();
for( PsiReference ref: search.findAll() )
{
usages.add( new MoveRenameUsageInfo( ref.getElement(), ref, ref.getRangeInElement().getStartOffset(),
ref.getRangeInElement().getEndOffset(), psiClass,
ref.resolve() == null && !(ref instanceof PsiPolyVariantReference && ((PsiPolyVariantReference)ref).multiResolve( true ).length > 0) ) );
}
return usages;
}
示例5: findPsiClasses
import com.intellij.psi.search.GlobalSearchScope; //导入依赖的package包/类
private void findPsiClasses( @NotNull @NonNls String name, @NotNull GlobalSearchScope scope, Set<PsiClass> psiClasses, ManModule start, ManModule module )
{
for( ITypeManifold tm: module.getTypeManifolds() )
{
for( String fqn: tm.getAllTypeNames() )
{
String simpleName = ClassUtil.extractClassName( fqn );
if( simpleName.equals( name ) )
{
PsiClass psiClass = ManifoldPsiClassCache.instance().getPsiClass( scope, module, fqn );
if( psiClass == null )
{
return;
}
psiClasses.add( psiClass );
}
}
}
for( Dependency d : module.getDependencies() )
{
if( module == start || d.isExported() )
{
findPsiClasses( name, scope, psiClasses, start, (ManModule)d.getModule() );
}
}
}
示例6: getTargetMethods
import com.intellij.psi.search.GlobalSearchScope; //导入依赖的package包/类
@NotNull
private static PsiElement[] getTargetMethods(@NotNull Project project, @NotNull String routeName) {
List<PsiElement> result = new ArrayList<>();
List<RouteStub> values = FileBasedIndex.getInstance().getValues(RouteIndex.KEY, routeName, GlobalSearchScope.allScope(project));
PhpIndex phpIndex = PhpIndex.getInstance(project);
for (RouteStub routeStub : values) {
String fqn = routeStub.getController();
Collection<PhpClass> classesByFQN = phpIndex.getClassesByFQN(fqn);
classesByFQN.forEach(c -> {
if (c.findMethodByName(routeStub.getMethod()) != null) {
result.add(c.findMethodByName(routeStub.getMethod()));
}
});
}
return result.toArray(new PsiElement[result.size()]);
}
示例7: inferType
import com.intellij.psi.search.GlobalSearchScope; //导入依赖的package包/类
@Nullable
public PsiType inferType( PsiTypeElement typeElement )
{
PsiType psiType = null;
final PsiElement parent = typeElement.getParent();
if( (parent instanceof PsiLocalVariable && isVar( (PsiLocalVariable)parent )) ||
(parent instanceof PsiParameter && isVarForEach( (PsiParameter)parent )) )
{
if( parent instanceof PsiLocalVariable )
{
psiType = processLocalVariableInitializer( ((PsiLocalVariable)parent).getInitializer() );
}
else
{
psiType = processForeach( ((PsiParameter)parent).getDeclarationScope() );
}
if( null == psiType )
{
psiType = PsiType.getJavaLangObject( typeElement.getManager(), GlobalSearchScope.allScope( typeElement.getProject() ) );
}
}
return psiType;
}
示例8: getIconDefinitionByIdentifier
import com.intellij.psi.search.GlobalSearchScope; //导入依赖的package包/类
public static Map<VirtualFile, IconStub> getIconDefinitionByIdentifier(@NotNull Project project, String iconIdentifier) {
Set<String> identifiers = new HashSet<>();
identifiers.add(iconIdentifier);
Map<VirtualFile, IconStub> icons = new THashMap<>();
FileBasedIndex.getInstance().getFilesWithKey(KEY, identifiers, virtualFile -> {
FileBasedIndex.getInstance().processValues(KEY, iconIdentifier, virtualFile, (file, value) -> {
icons.put(file, value);
return true;
}, GlobalSearchScope.allScope(project));
return true;
}, GlobalSearchScope.allScope(project));
return icons;
}
示例9: getRemovedConstantsFQNs
import com.intellij.psi.search.GlobalSearchScope; //导入依赖的package包/类
private Set<String> getRemovedConstantsFQNs(ConstantReference element) {
Set<PsiElement> elements = new HashSet<>();
PsiFile[] constantMatcherFiles = FilenameIndex.getFilesByName(element.getProject(), "ConstantMatcher.php", GlobalSearchScope.allScope(element.getProject()));
for (PsiFile file : constantMatcherFiles) {
Collections.addAll(
elements,
PsiTreeUtil.collectElements(file, el -> PlatformPatterns
.psiElement(StringLiteralExpression.class)
.withParent(
PlatformPatterns.psiElement(PhpElementTypes.ARRAY_KEY)
.withAncestor(
4,
PlatformPatterns.psiElement(PhpElementTypes.RETURN)
)
)
.accepts(el)
)
);
}
return elements.stream()
.map(stringLiteral -> "\\" + ((StringLiteralExpression)stringLiteral).getContents())
.collect(Collectors.toSet());
}
示例10: getDeprecatedClassConstants
import com.intellij.psi.search.GlobalSearchScope; //导入依赖的package包/类
private Set<String> getDeprecatedClassConstants(PhpPsiElement element) {
Set<PsiElement> elements = new HashSet<>();
PsiFile[] classConstantMatcherFiles = FilenameIndex.getFilesByName(element.getProject(), "ClassConstantMatcher.php", GlobalSearchScope.allScope(element.getProject()));
for (PsiFile file : classConstantMatcherFiles) {
Collections.addAll(
elements,
PsiTreeUtil.collectElements(file, el -> PlatformPatterns
.psiElement(StringLiteralExpression.class)
.withParent(
PlatformPatterns.psiElement(PhpElementTypes.ARRAY_KEY)
.withAncestor(
4,
PlatformPatterns.psiElement(PhpElementTypes.RETURN)
)
)
.accepts(el)
)
);
}
return elements.stream().map(stringLiteral -> ((StringLiteralExpression)stringLiteral).getContents()).collect(Collectors.toSet());
}
示例11: findUsages
import com.intellij.psi.search.GlobalSearchScope; //导入依赖的package包/类
private static List<UsageInfo> findUsages( PsiElement element, PsiElement ctx )
{
// Module mod = ModuleUtilCore.findModuleForPsiElement( element );
// if( mod == null )
// {
// return Collections.emptyList();
// }
Query<PsiReference> search = ReferencesSearch.search( element, GlobalSearchScope.moduleScope( ModuleUtilCore.findModuleForPsiElement( ctx ) ) );
List<UsageInfo> usages = new ArrayList<>();
for( PsiReference ref : search.findAll() )
{
MoveRenameUsageInfo usageInfo = new MoveRenameUsageInfo( ref.getElement(), ref, ref.getRangeInElement().getStartOffset(),
ref.getRangeInElement().getEndOffset(), element,
ref.resolve() == null && !(ref instanceof PsiPolyVariantReference && ((PsiPolyVariantReference)ref).multiResolve( true ).length > 0) );
usages.add( usageInfo );
}
return usages;
}
示例12: findDefinitionElements
import com.intellij.psi.search.GlobalSearchScope; //导入依赖的package包/类
public static PsiElement[] findDefinitionElements(@NotNull Project project, @NotNull String translationId) {
Set<String> keys = new HashSet<>();
keys.add(translationId);
List<PsiElement> elements = new ArrayList<>();
FileBasedIndex.getInstance().getFilesWithKey(TranslationIndex.KEY, keys, virtualFile -> {
FileBasedIndex.getInstance().processValues(TranslationIndex.KEY, translationId, virtualFile, (file, value) -> {
PsiFile file1 = PsiManager.getInstance(project).findFile(file);
if (file1 != null) {
PsiElement elementAt = file1.findElementAt(value.getTextRange().getStartOffset());
if (elementAt != null) {
elements.add(elementAt.getParent());
}
}
return true;
}, GlobalSearchScope.allScope(project));
return true;
}, GlobalSearchScope.allScope(project));
return elements.toArray(new PsiElement[elements.size()]);
}
示例13: processPackageDirectories
import com.intellij.psi.search.GlobalSearchScope; //导入依赖的package包/类
@Override
public boolean processPackageDirectories(@NotNull PsiPackage psiPackage,
@NotNull final GlobalSearchScope scope,
@NotNull final Processor<PsiDirectory> consumer,
boolean includeLibrarySources) {
//System.out.println( "processDirectories() : " + psiPackage + " : " + scope );
final PsiManager psiManager = PsiManager.getInstance( _project );
return PackageIndex.getInstance( _project )
.getDirsByPackageName(psiPackage.getQualifiedName(), includeLibrarySources)
.forEach(new ReadActionProcessor<VirtualFile>() {
@Override
public boolean processInReadAction(final VirtualFile dir) {
if (!scope.contains(dir)) return true;
PsiDirectory psiDir = psiManager.findDirectory(dir);
return psiDir == null || consumer.process(psiDir);
}
});
}
示例14: findPsiClass
import com.intellij.psi.search.GlobalSearchScope; //导入依赖的package包/类
@Nullable
private PsiClass findPsiClass( PsiFileSystemItem element )
{
Module mod = ModuleUtilCore.findModuleForPsiElement( element );
if( mod == null )
{
return null;
}
ManModule module = ManProject.getModule( mod );
String[] fqns = module.getTypesForFile( FileUtil.toIFile( module.getProject(), element.getVirtualFile() ) );
PsiClass psiClass = null;
for( String fqn: fqns )
{
psiClass = ManifoldPsiClassCache.instance().getPsiClass( GlobalSearchScope.moduleWithDependenciesAndLibrariesScope( module.getIjModule() ), module, fqn );
if( psiClass != null )
{
break;
}
}
return psiClass;
}
示例15: getDefinitionElements
import com.intellij.psi.search.GlobalSearchScope; //导入依赖的package包/类
public static PsiElement[] getDefinitionElements(@NotNull Project project, @NotNull String actionName) {
Set<String> keys = new HashSet<>();
keys.add(actionName);
List<PsiElement> elements = new ArrayList<>();
FileBasedIndex.getInstance().getFilesWithKey(ControllerActionIndex.KEY, keys, virtualFile -> {
FileBasedIndex.getInstance().processValues(ControllerActionIndex.KEY, actionName, virtualFile, (file, value) -> {
PsiFile file1 = PsiManager.getInstance(project).findFile(file);
if (file1 != null) {
PsiElement elementAt = file1.findElementAt(value.getTextRange().getStartOffset());
if (elementAt != null) {
elements.add(elementAt.getParent().getParent());
}
}
return true;
}, GlobalSearchScope.allScope(project));
return true;
}, GlobalSearchScope.allScope(project));
return elements.toArray(new PsiElement[elements.size()]);
}