com.intellij.psi.search.searches.ReferencesSearch Java Examples
The following examples show how to use
com.intellij.psi.search.searches.ReferencesSearch.
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: ChangeNamespaceProcessor.java From consulo-csharp with Apache License 2.0 | 6 votes |
@Nonnull @Override @RequiredReadAction protected UsageInfo[] findUsages() { List<UsageInfo> result = new ArrayList<>(); Set<Couple<DotNetNamedElement>> children = CSharpMoveClassesUtil.findTypesAndNamespaces(myDeclaration); for(Couple<DotNetNamedElement> couple : children) { DotNetNamedElement second = couple.getSecond(); for(PsiReference reference : ReferencesSearch.search(second, CSharpClassesMoveProcessor.mapScope(second))) { result.add(new CSharpClassesMoveProcessor.MyUsageInfo(reference.getElement(), couple, reference)); } } return result.toArray(new UsageInfo[result.size()]); }
Example #2
Source File: SpecReferenceSearch.java From intellij-swagger with MIT License | 6 votes |
private void process( final ReferencesSearch.SearchParameters queryParameters, final PsiElement elementToSearch, final Project project) { Optional.ofNullable(((PsiNamedElement) elementToSearch).getName()) .ifPresent( word -> { final String escaped = PathExpressionUtil.escapeJsonPointer(word); if (!escaped.equals(word)) { queryParameters .getOptimizer() .searchWord( escaped, GlobalSearchScope.allScope(project), CASE_SENSITIVE, elementToSearch); } }); }
Example #3
Source File: MoveFilesOrDirectoriesProcessor.java From consulo with Apache License 2.0 | 6 votes |
@Override @Nonnull protected UsageInfo[] findUsages() { ArrayList<UsageInfo> result = new ArrayList<>(); for (int i = 0; i < myElementsToMove.length; i++) { PsiElement element = myElementsToMove[i]; if (mySearchForReferences) { for (PsiReference reference : ReferencesSearch.search(element, GlobalSearchScope.projectScope(myProject))) { result.add(new MyUsageInfo(reference.getElement(), i, reference)); } } findElementUsages(result, element); } return result.toArray(new UsageInfo[result.size()]); }
Example #4
Source File: FileMoveHandler.java From netbeans-mmd-plugin with Apache License 2.0 | 6 votes |
@Nullable @Override public List<UsageInfo> findUsages(final PsiFile psiFile, final PsiDirectory newParent, final boolean searchInComments, final boolean searchInNonJavaFiles) { Query<PsiReference> search = ReferencesSearch.search(psiFile); final List<PsiExtraFileReference> extraFileRefs = new ArrayList<PsiExtraFileReference>(); search.forEach(new Processor<PsiReference>() { @Override public boolean process(PsiReference psiReference) { if (psiReference instanceof PsiExtraFileReference) { extraFileRefs.add((PsiExtraFileReference) psiReference); } return true; } }); if (extraFileRefs.isEmpty()) { return null; } else { final List<UsageInfo> result = new ArrayList<UsageInfo>(extraFileRefs.size()); for (final PsiExtraFileReference e : extraFileRefs) { result.add(new FileUsageInfo(e)); } return result; } }
Example #5
Source File: AdditionalReferenceSearch.java From consulo-csharp with Apache License 2.0 | 6 votes |
@Override public void processQuery(@Nonnull ReferencesSearch.SearchParameters queryParameters, @Nonnull Processor<? super PsiReference> consumer) { PsiElement elementToSearch = queryParameters.getElementToSearch(); PsiElement declaration = elementToSearch.getUserData(CSharpResolveUtil.EXTENSION_METHOD_WRAPPER); if(declaration == null) { declaration = elementToSearch.getUserData(CSharpResolveUtil.ACCESSOR_VALUE_VARIABLE_OWNER); } if(declaration == null) { return; } ReferencesSearch.search(declaration, queryParameters.getEffectiveSearchScope(), queryParameters.isIgnoreAccessScope()).forEach(consumer); }
Example #6
Source File: PsiElement2UsageTargetAdapter.java From consulo with Apache License 2.0 | 6 votes |
@Override public void highlightUsages(@Nonnull PsiFile file, @Nonnull Editor editor, boolean clearHighlights) { PsiElement target = getElement(); if (file instanceof PsiCompiledFile) file = ((PsiCompiledFile)file).getDecompiledPsiFile(); Project project = target.getProject(); final FindUsagesManager findUsagesManager = ((FindManagerImpl)FindManager.getInstance(project)).getFindUsagesManager(); final FindUsagesHandler handler = findUsagesManager.getFindUsagesHandler(target, true); // in case of injected file, use host file to highlight all occurrences of the target in each injected file PsiFile context = InjectedLanguageManager.getInstance(project).getTopLevelFile(file); SearchScope searchScope = new LocalSearchScope(context); Collection<PsiReference> refs = handler == null ? ReferencesSearch.search(target, searchScope, false).findAll() : handler.findReferencesToHighlight(target, searchScope); new HighlightUsagesHandler.DoHighlightRunnable(new ArrayList<>(refs), project, target, editor, context, clearHighlights).run(); }
Example #7
Source File: UseSlf4jAnnotationQuickFix.java From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public void invoke(@NotNull Project project, @NotNull PsiFile file, @NotNull PsiElement startElement, @NotNull PsiElement endElement) { super.invoke(project, file, startElement, endElement); final PsiNamedElement psiNamedElement = elementToRemove.getElement(); if (null != psiNamedElement) { final Collection<PsiReference> all = ReferencesSearch.search(psiNamedElement).findAll(); final String loggerName = getLoggerName(PsiTreeUtil.getParentOfType(psiNamedElement, PsiClass.class)); for (PsiReference psiReference : all) { psiReference.handleElementRename(loggerName); } psiNamedElement.delete(); JavaCodeStyleManager.getInstance(project).removeRedundantImports((PsiJavaFile) file); } }
Example #8
Source File: ExtractSuperBaseProcessor.java From intellij-haxe with Apache License 2.0 | 6 votes |
@NotNull protected UsageInfo[] findUsages() { PsiReference[] refs = ReferencesSearch.search(myClass, GlobalSearchScope.projectScope(myProject), false).toArray(new PsiReference[0]); final ArrayList<UsageInfo> result = new ArrayList<UsageInfo>(); detectTurnToSuperRefs(refs, result); final PsiPackage originalPackage = JavaDirectoryService.getInstance().getPackage(myClass.getContainingFile().getContainingDirectory()); if (Comparing.equal(JavaDirectoryService.getInstance().getPackage(myTargetDirectory), originalPackage)) { result.clear(); } for (final PsiReference ref : refs) { final PsiElement element = ref.getElement(); if (!canTurnToSuper(element) && !RefactoringUtil.inImportStatement(ref, element)) { result.add(new BindToOldUsageInfo(element, ref, myClass)); } } UsageInfo[] usageInfos = result.toArray(new UsageInfo[result.size()]); return UsageViewUtil.removeDuplicatedUsages(usageInfos); }
Example #9
Source File: LatteReferenceSearch.java From intellij-latte with MIT License | 5 votes |
@Override public void processQuery(ReferencesSearch.SearchParameters searchParameters, @NotNull Processor<? super PsiReference> processor) { if (searchParameters.getElementToSearch() instanceof Field) { processField((Field) searchParameters.getElementToSearch(), searchParameters.getScopeDeterminedByUser(), processor); } else if (searchParameters.getElementToSearch() instanceof PhpClass) { processClass((PhpClass) searchParameters.getElementToSearch(), searchParameters.getScopeDeterminedByUser(), processor); } }
Example #10
Source File: DotEnvReferencesSearcher.java From idea-php-dotenv-plugin with MIT License | 5 votes |
@Override public void processQuery(@NotNull ReferencesSearch.SearchParameters queryParameters, @NotNull Processor<? super PsiReference> consumer) { PsiElement refElement = queryParameters.getElementToSearch(); if (!(refElement instanceof DotEnvProperty)) return; addPropertyUsages((DotEnvProperty)refElement, queryParameters.getEffectiveSearchScope(), queryParameters.getOptimizer()); }
Example #11
Source File: CSharpConstructorPlusTypeReferenceSearch.java From consulo-csharp with Apache License 2.0 | 5 votes |
@Override public void processQuery(@Nonnull ReferencesSearch.SearchParameters queryParameters, @Nonnull Processor<? super PsiReference> consumer) { PsiElement elementToSearch = queryParameters.getElementToSearch(); if(elementToSearch instanceof CSharpTypeDeclaration) { String name = AccessRule.read(((CSharpTypeDeclaration) elementToSearch)::getName); if(name == null) { return; } for(DotNetNamedElement member : AccessRule.read(((CSharpTypeDeclaration) elementToSearch)::getMembers)) { if(member instanceof CSharpConstructorDeclaration) { queryParameters.getOptimizer().searchWord(name, queryParameters.getEffectiveSearchScope(), true, member); } } CSharpLightConstructorDeclarationBuilder constructor = AccessRule.read(() -> StructOrGenericParameterConstructorProvider.buildDefaultConstructor((DotNetNamedElement) elementToSearch, name)); queryParameters.getOptimizer().searchWord(name, queryParameters.getEffectiveSearchScope(), true, constructor); } /* else if(elementToSearch instanceof CSharpConstructorDeclaration) { PsiElement parent = elementToSearch.getParent(); if(parent instanceof CSharpTypeDeclaration) { ReferencesSearch.search(parent, queryParameters.getEffectiveSearchScope(), queryParameters.isIgnoreAccessScope()).forEach (consumer); } } */ }
Example #12
Source File: CSharpImplementedReferenceSearch.java From consulo-csharp with Apache License 2.0 | 5 votes |
@Override public void processQuery(@Nonnull ReferencesSearch.SearchParameters queryParameters, @Nonnull Processor<? super PsiReference> consumer) { final PsiElement elementToSearch = queryParameters.getElementToSearch(); if(elementToSearch instanceof CSharpMethodDeclaration) { Collection<DotNetVirtualImplementOwner> targets = ApplicationManager.getApplication().runReadAction(new Computable<Collection<DotNetVirtualImplementOwner>>() { @Override public Collection<DotNetVirtualImplementOwner> compute() { if(((CSharpMethodDeclaration) elementToSearch).hasModifier(DotNetModifier.ABSTRACT)) { return OverrideUtil.collectOverridenMembers((DotNetVirtualImplementOwner) elementToSearch); } return Collections.emptyList(); } }); for(DotNetVirtualImplementOwner target : targets) { if(!ReferencesSearch.search(target, queryParameters.getEffectiveSearchScope()).forEach(consumer)) { return; } } } }
Example #13
Source File: CS0169.java From consulo-csharp with Apache License 2.0 | 5 votes |
@RequiredReadAction @Nullable @Override public HighlightInfoFactory checkImpl(@Nonnull CSharpLanguageVersion languageVersion, @Nonnull CSharpHighlightContext highlightContext, @Nonnull CSharpFieldDeclaration element) { if(!element.hasModifier(CSharpModifier.PRIVATE)) { return null; } PsiElement parent = element.getParent(); if(!(parent instanceof CSharpTypeDeclaration)) { return null; } PsiElement nameIdentifier = element.getNameIdentifier(); if(nameIdentifier == null) { return null; } Query<PsiReference> search = ReferencesSearch.search(element, CSharpCompositeTypeDeclaration.createLocalScope((DotNetTypeDeclaration) parent)); if(search.findFirst() == null) { return newBuilder(nameIdentifier, formatElement(element)); } return null; }
Example #14
Source File: CS0168.java From consulo-csharp with Apache License 2.0 | 5 votes |
@RequiredReadAction static boolean isUnused(@Nonnull CSharpLocalVariable element) { PsiElement nameIdentifier = element.getNameIdentifier(); if(nameIdentifier == null) { return false; } return ReferencesSearch.search(element).findFirst() == null; }
Example #15
Source File: CSharpClassesMoveProcessor.java From consulo-csharp with Apache License 2.0 | 5 votes |
@Override @Nonnull @RequiredReadAction protected UsageInfo[] findUsages() { List<UsageInfo> result = new ArrayList<>(); List<Couple<DotNetNamedElement>> children = new ArrayList<>(); for(PsiElement psiElement : myElementsToMove) { if(psiElement instanceof CSharpFile) { children.addAll(CSharpMoveClassesUtil.findTypesAndNamespaces((CSharpFile) psiElement)); } } for(Couple<DotNetNamedElement> couple : children) { DotNetNamedElement second = couple.getSecond(); for(PsiReference reference : ReferencesSearch.search(second, mapScope(second))) { result.add(new MyUsageInfo(reference.getElement(), couple, reference)); } } return result.toArray(new UsageInfo[result.size()]); }
Example #16
Source File: CSharpChangeSignatureUsageProcessor.java From consulo-csharp with Apache License 2.0 | 5 votes |
@Nonnull @Override public UsageInfo[] findUsages(@Nonnull final ChangeInfo info) { if(!(info instanceof CSharpChangeInfo)) { return UsageInfo.EMPTY_ARRAY; } final List<UsageInfo> list = new ArrayList<UsageInfo>(); final ReadActionProcessor<PsiReference> refProcessor = new ReadActionProcessor<PsiReference>() { @RequiredReadAction @Override public boolean processInReadAction(final PsiReference ref) { final PsiElement resolve = ref.resolve(); if(resolve != info.getMethod()) { return true; } TextRange rangeInElement = ref.getRangeInElement(); list.add(new UsageInfo(ref.getElement(), rangeInElement.getStartOffset(), rangeInElement.getEndOffset(), false)); return true; } }; ReferencesSearch.search(new ReferencesSearch.SearchParameters(info.getMethod(), info.getMethod().getResolveScope(), false)).forEach(refProcessor); return list.toArray(UsageInfo.EMPTY_ARRAY); }
Example #17
Source File: PullUpProcessor.java From intellij-haxe with Apache License 2.0 | 5 votes |
@Override @NotNull protected UsageInfo[] findUsages() { final List<UsageInfo> result = new ArrayList<UsageInfo>(); for (MemberInfo memberInfo : myMembersToMove) { final PsiMember member = memberInfo.getMember(); if (member.hasModifierProperty(PsiModifier.STATIC)) { for (PsiReference reference : ReferencesSearch.search(member)) { result.add(new UsageInfo(reference)); } } } return result.isEmpty() ? UsageInfo.EMPTY_ARRAY : result.toArray(new UsageInfo[result.size()]); }
Example #18
Source File: HaxePullUpHelper.java From intellij-haxe with Apache License 2.0 | 5 votes |
private boolean willBeUsedInSubclass(PsiElement member, PsiClass superclass, PsiClass subclass) { for (PsiReference ref : ReferencesSearch.search(member, new LocalSearchScope(subclass), false)) { PsiElement element = ref.getElement(); if (!RefactoringHierarchyUtil.willBeInTargetClass(element, myMembersToMove, superclass, false)) { return true; } } return false; }
Example #19
Source File: LombokReferenceSearcher.java From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void processQuery(@NotNull ReferencesSearch.SearchParameters queryParameters, @NotNull Processor consumer) { PsiElement refElement = queryParameters.getElementToSearch(); if (refElement instanceof PsiField) { DumbService.getInstance(queryParameters.getProject()).runReadActionInSmartMode(() -> processPsiField((PsiField) refElement, queryParameters.getOptimizer())); } }
Example #20
Source File: IdentifierHighlighterPass.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull private static Couple<Collection<TextRange>> getUsages(@Nonnull PsiElement target, PsiElement psiElement, boolean withDeclarations, boolean detectAccess) { List<TextRange> readRanges = new ArrayList<>(); List<TextRange> writeRanges = new ArrayList<>(); final ReadWriteAccessDetector detector = detectAccess ? ReadWriteAccessDetector.findDetector(target) : null; final FindUsagesManager findUsagesManager = ((FindManagerImpl)FindManager.getInstance(target.getProject())).getFindUsagesManager(); final FindUsagesHandler findUsagesHandler = findUsagesManager.getFindUsagesHandler(target, true); final LocalSearchScope scope = new LocalSearchScope(psiElement); Collection<PsiReference> refs = findUsagesHandler != null ? findUsagesHandler.findReferencesToHighlight(target, scope) : ReferencesSearch.search(target, scope).findAll(); for (PsiReference psiReference : refs) { if (psiReference == null) { LOG.error("Null reference returned, findUsagesHandler=" + findUsagesHandler + "; target=" + target + " of " + target.getClass()); continue; } List<TextRange> destination; if (detector == null || detector.getReferenceAccess(target, psiReference) == ReadWriteAccessDetector.Access.Read) { destination = readRanges; } else { destination = writeRanges; } HighlightUsagesHandler.collectRangesToHighlight(psiReference, destination); } if (withDeclarations) { final TextRange declRange = HighlightUsagesHandler.getNameIdentifierRange(psiElement.getContainingFile(), target); if (declRange != null) { if (detector != null && detector.isDeclarationWriteAccess(target)) { writeRanges.add(declRange); } else { readRanges.add(declRange); } } } return Couple.<Collection<TextRange>>of(readRanges, writeRanges); }
Example #21
Source File: FindUsagesHandler.java From consulo with Apache License 2.0 | 5 votes |
public boolean processElementUsages(@Nonnull final PsiElement element, @Nonnull final Processor<UsageInfo> processor, @Nonnull final FindUsagesOptions options) { final ReadActionProcessor<PsiReference> refProcessor = new ReadActionProcessor<PsiReference>() { @Override public boolean processInReadAction(final PsiReference ref) { TextRange rangeInElement = ref.getRangeInElement(); return processor.process(new UsageInfo(ref.getElement(), rangeInElement.getStartOffset(), rangeInElement.getEndOffset(), false)); } }; final SearchScope scope = options.searchScope; final boolean searchText = options.isSearchForTextOccurrences && scope instanceof GlobalSearchScope; if (options.isUsages) { boolean success = ReferencesSearch.search(new ReferencesSearch.SearchParameters(element, scope, false, options.fastTrack)).forEach(refProcessor); if (!success) return false; } if (searchText) { if (options.fastTrack != null) { options.fastTrack.searchCustom(consumer -> processUsagesInText(element, processor, (GlobalSearchScope)scope)); } else { return processUsagesInText(element, processor, (GlobalSearchScope)scope); } } return true; }
Example #22
Source File: InplaceRefactoring.java From consulo with Apache License 2.0 | 5 votes |
protected Collection<PsiReference> collectRefs(SearchScope referencesSearchScope) { final Query<PsiReference> search = ReferencesSearch.search(myElementToRename, referencesSearchScope, false); final CommonProcessors.CollectProcessor<PsiReference> processor = new CommonProcessors.CollectProcessor<PsiReference>() { @Override protected boolean accept(PsiReference reference) { return acceptReference(reference); } }; search.forEach(processor); return processor.getResults(); }
Example #23
Source File: MemberInplaceRenamer.java From consulo with Apache License 2.0 | 5 votes |
@Override protected Collection<PsiReference> collectRefs(SearchScope referencesSearchScope) { final ArrayList<PsiReference> references = new ArrayList<PsiReference>(super.collectRefs(referencesSearchScope)); final PsiNamedElement variable = getVariable(); if (variable != null) { final PsiElement substituted = getSubstituted(); if (substituted != null && substituted != variable) { references.addAll(ReferencesSearch.search(substituted, referencesSearchScope, false).findAll()); } } return references; }
Example #24
Source File: InlineOptionsDialog.java From consulo with Apache License 2.0 | 5 votes |
protected static int initOccurrencesNumber(PsiNameIdentifierOwner nameIdentifierOwner) { final ProgressManager progressManager = ProgressManager.getInstance(); final PsiSearchHelper searchHelper = PsiSearchHelper.SERVICE.getInstance(nameIdentifierOwner.getProject()); final GlobalSearchScope scope = GlobalSearchScope.projectScope(nameIdentifierOwner.getProject()); final String name = nameIdentifierOwner.getName(); final boolean isCheapToSearch = name != null && searchHelper.isCheapEnoughToSearch(name, scope, null, progressManager.getProgressIndicator()) != PsiSearchHelper.SearchCostResult.TOO_MANY_OCCURRENCES; return isCheapToSearch ? ReferencesSearch.search(nameIdentifierOwner).findAll().size() : - 1; }
Example #25
Source File: CallerChooserBase.java From consulo with Apache License 2.0 | 5 votes |
protected Collection<PsiElement> findElementsToHighlight(M caller, PsiElement callee) { Query<PsiReference> references = ReferencesSearch.search(callee, new LocalSearchScope(caller), false); return ContainerUtil.mapNotNull(references, new Function<PsiReference, PsiElement>() { @Override public PsiElement fun(PsiReference psiReference) { return psiReference.getElement(); } }); }
Example #26
Source File: AbstractInplaceIntroducer.java From consulo with Apache License 2.0 | 5 votes |
@Override protected void addReferenceAtCaret(Collection<PsiReference> refs) { final V variable = getLocalVariable(); if (variable != null) { for (PsiReference reference : ReferencesSearch.search(variable)) { refs.add(reference); } } else { refs.clear(); } }
Example #27
Source File: SafeDeleteProcessor.java From consulo with Apache License 2.0 | 5 votes |
public static void findGenericElementUsages(final PsiElement element, final List<UsageInfo> usages, final PsiElement[] allElementsToDelete) { ReferencesSearch.search(element).forEach(new Processor<PsiReference>() { @Override public boolean process(final PsiReference reference) { final PsiElement refElement = reference.getElement(); if (!isInside(refElement, allElementsToDelete)) { usages.add(new SafeDeleteReferenceSimpleDeleteUsageInfo(refElement, element, false)); } return true; } }); }
Example #28
Source File: ReferenceSearch.java From Intellij-Plugin with Apache License 2.0 | 5 votes |
private void processElements(final ReferencesSearch.SearchParameters searchParameters, final Processor<? super PsiReference> processor) { ApplicationManager.getApplication().runReadAction(() -> { StepCollector collector = helper.getStepCollector(searchParameters.getElementToSearch()); collector.collect(); final List<PsiElement> elements = helper.getPsiElements(collector, searchParameters.getElementToSearch()); for (PsiElement element : elements) processor.process(element.getReference()); }); }
Example #29
Source File: PackageReferenceDiagramDataModel.java From intellij-reference-diagram with Apache License 2.0 | 5 votes |
@NotNull @Override protected Collection<PsiReference> resolveOuterReferences(PsiElement psiElement) { Collection<PsiReference> result = new ArrayList<>(); if (!(psiElement instanceof PsiJavaFile)) { return result; } PsiClass[] classes = ((PsiJavaFile) psiElement).getClasses(); for (PsiClass psiClass : classes) { result.addAll(ReferencesSearch.search(psiClass, GlobalSearchScopes.projectProductionScope(getProject())).findAll()); } return result; }
Example #30
Source File: BashFileRenameProcessor.java From BashSupport with Apache License 2.0 | 5 votes |
/** * Returns references to the given element. If it is a BashPsiElement a special search scope is used to locate the elements referencing the file. * * @param element References to the given element * @return */ @NotNull @Override public Collection<PsiReference> findReferences(PsiElement element) { //fixme fix the custom scope SearchScope scope = (element instanceof BashPsiElement) ? BashElementSharedImpl.getElementUseScope((BashPsiElement) element, element.getProject()) : GlobalSearchScope.projectScope(element.getProject()); Query<PsiReference> search = ReferencesSearch.search(element, scope); return search.findAll(); }