com.intellij.usageView.UsageInfo Java Examples
The following examples show how to use
com.intellij.usageView.UsageInfo.
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: SafeDeleteProcessor.java From consulo with Apache License 2.0 | 6 votes |
@Override @Nonnull protected UsageInfo[] findUsages() { List<UsageInfo> usages = Collections.synchronizedList(new ArrayList<UsageInfo>()); for (PsiElement element : myElements) { boolean handled = false; for (SafeDeleteProcessorDelegate delegate : Extensions.getExtensions(SafeDeleteProcessorDelegate.EP_NAME)) { if (delegate.handlesElement(element)) { final NonCodeUsageSearchInfo filter = delegate.findUsages(element, myElements, usages); if (filter != null) { for (PsiElement nonCodeUsageElement : filter.getElementsToSearch()) { addNonCodeUsages(nonCodeUsageElement, usages, filter.getInsideDeletedCondition(), mySearchNonJava, mySearchInCommentsAndStrings); } } handled = true; break; } } if (!handled && element instanceof PsiNamedElement) { findGenericElementUsages(element, usages, myElements); addNonCodeUsages(element, usages, getDefaultInsideDeletedCondition(myElements), mySearchNonJava, mySearchInCommentsAndStrings); } } final UsageInfo[] result = usages.toArray(new UsageInfo[usages.size()]); return UsageViewUtil.removeDuplicatedUsages(result); }
Example #2
Source File: TextOccurrencesUtil.java From consulo with Apache License 2.0 | 6 votes |
public static void addUsagesInStringsAndComments(@Nonnull PsiElement element, @Nonnull String stringToSearch, @Nonnull final Collection<UsageInfo> results, @Nonnull final UsageInfoFactory factory) { final Object lock = new Object(); processUsagesInStringsAndComments(element, stringToSearch, false, new PairProcessor<PsiElement, TextRange>() { @Override public boolean process(PsiElement commentOrLiteral, TextRange textRange) { UsageInfo usageInfo = factory.createUsageInfo(commentOrLiteral, textRange.getStartOffset(), textRange.getEndOffset()); if (usageInfo != null) { synchronized (lock) { results.add(usageInfo); } } return true; } }); }
Example #3
Source File: BaseRefactoringProcessor.java From consulo with Apache License 2.0 | 6 votes |
protected boolean showConflicts(@Nonnull MultiMap<PsiElement, String> conflicts, @Nullable final UsageInfo[] usages) { if (!conflicts.isEmpty() && ApplicationManager.getApplication().isUnitTestMode()) { if (!ConflictsInTestsException.isTestIgnore()) throw new ConflictsInTestsException(conflicts.values()); return true; } if (myPrepareSuccessfulSwingThreadCallback != null && !conflicts.isEmpty()) { final String refactoringId = getRefactoringId(); if (refactoringId != null) { RefactoringEventData conflictUsages = new RefactoringEventData(); conflictUsages.putUserData(RefactoringEventData.CONFLICTS_KEY, conflicts.values()); myProject.getMessageBus().syncPublisher(RefactoringEventListener.REFACTORING_EVENT_TOPIC).conflictsDetected(refactoringId, conflictUsages); } final ConflictsDialog conflictsDialog = prepareConflictsDialog(conflicts, usages); if (!conflictsDialog.showAndGet()) { if (conflictsDialog.isShowConflicts()) prepareSuccessful(); return false; } } prepareSuccessful(); return true; }
Example #4
Source File: RenameFileDirectoryTest.java From azure-devops-intellij with MIT License | 6 votes |
@Test public void testExecute_RenameFileEditRenameChanges() { when(mockPendingChange.getChangeTypes()).thenReturn(ImmutableList.of(ServerStatusType.EDIT, ServerStatusType.RENAME)); when(mockVirtualFile.getPath()).thenReturn(CURRENT_FILE_PATH); when(CommandUtils.getStatusForFiles(any(Project.class), eq(mockServerContext), eq(ImmutableList.of(CURRENT_FILE_PATH)))) .thenReturn(ImmutableList.of(mockPendingChange)); RenameFileDirectory.execute(mockPsiFile, NEW_FILE_NAME, usageInfos, mockListener); verifyStatic(times(1)); CommandUtils.renameFile(eq(mockServerContext), eq(CURRENT_FILE_PATH), eq(NEW_FILE_PATH)); PersistentFS.getInstance().processEvents(any(List.class)); verify(mockListener).elementRenamed(mockPsiFile); verifyStatic(never()); RenameUtil.doRenameGenericNamedElement(any(PsiElement.class), any(String.class), any(UsageInfo[].class), any(RefactoringElementListener.class)); }
Example #5
Source File: ChangeSignatureProcessorBase.java From consulo with Apache License 2.0 | 6 votes |
protected List<UsageInfo> filterUsages(List<UsageInfo> infos) { Map<PsiElement, MoveRenameUsageInfo> moveRenameInfos = new HashMap<PsiElement, MoveRenameUsageInfo>(); Set<PsiElement> usedElements = new HashSet<PsiElement>(); List<UsageInfo> result = new ArrayList<UsageInfo>(infos.size() / 2); for (UsageInfo info : infos) { LOG.assertTrue(info != null, getClass()); PsiElement element = info.getElement(); if (info instanceof MoveRenameUsageInfo) { if (usedElements.contains(element)) continue; moveRenameInfos.put(element, (MoveRenameUsageInfo)info); } else { moveRenameInfos.remove(element); usedElements.add(element); if (!(info instanceof PossiblyIncorrectUsage) || ((PossiblyIncorrectUsage)info).isCorrect()) { result.add(info); } } } result.addAll(moveRenameInfos.values()); return result; }
Example #6
Source File: PsiFragment.java From consulo with Apache License 2.0 | 6 votes |
@Nullable public UsageInfo getUsageInfo() { if (myElementAnchors.length == 1) { final PsiElement element = myElementAnchors[0].retrieve(); if (element == null || !element.isValid()) return null; return new UsageInfo(element); } PsiElement parent = PsiTreeUtil.findCommonParent(getElements()); if (parent == null) return null; int offs = parent.getTextRange().getStartOffset(); final int startOffsetInParent = getStartOffset() - offs; final int endOffsetInParent = getEndOffset() - offs; if (startOffsetInParent < 0) return null; if (endOffsetInParent < startOffsetInParent) return null; return new UsageInfo(parent, startOffsetInParent, endOffsetInParent); }
Example #7
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 #8
Source File: MoveDirectoryWithClassesProcessor.java From consulo with Apache License 2.0 | 6 votes |
@Override protected boolean preprocessUsages(Ref<UsageInfo[]> refUsages) { final MultiMap<PsiElement, String> conflicts = new MultiMap<PsiElement, String>(); for (PsiFile psiFile : myFilesToMove.keySet()) { try { myFilesToMove.get(psiFile).checkMove(psiFile); } catch (IncorrectOperationException e) { conflicts.putValue(psiFile, e.getMessage()); } } for (MoveDirectoryWithClassesHelper helper : MoveDirectoryWithClassesHelper.findAll()) { helper.preprocessUsages(myProject, myFilesToMove.keySet(), refUsages.get(), myTargetDirectory, conflicts); } return showConflicts(conflicts, refUsages.get()); }
Example #9
Source File: HaxeFindUsagesTest.java From intellij-haxe with Apache License 2.0 | 6 votes |
public String prettyUsageMessage(UsageInfo usage) { UsageInfo2UsageAdapter adapter = new UsageInfo2UsageAdapter(usage); StringBuilder builder = new StringBuilder(); VirtualFile vFile = adapter.getFile(); builder.append(null != vFile ? vFile.getName() : "<unknown file>"); builder.append(", line "); builder.append(adapter.getLine() + 1); builder.append(':'); builder.append(adapter.getPresentation().getPlainText()); String tooltip = adapter.getPresentation().getTooltipText(); if (null != tooltip) { builder.append(" {"); builder.append(tooltip); builder.append("} "); } return builder.toString(); }
Example #10
Source File: PushDownProcessor.java From intellij-haxe with Apache License 2.0 | 5 votes |
@Override @NotNull protected UsageInfo[] findUsages() { List<UsageInfo> usageInfos = Arrays.asList(MoveClassesOrPackagesUtil.findUsages(myClass, false, false, null)); final List<UsageInfo> usages = new ArrayList<UsageInfo>(); PsiReference reference; PsiClass psiClass; for (int i = 0; i < usageInfos.size(); i++) { reference = usageInfos.get(i).getReference(); if (reference != null) { psiClass = PsiTreeUtil.getParentOfType((PsiElement)reference, PsiClass.class); if (psiClass != null) { usages.add(new UsageInfo(psiClass)); } } } /* final PsiMethod interfaceMethod = LambdaUtil.getFunctionalInterfaceMethod(myClass); if (interfaceMethod != null && isMoved(interfaceMethod)) { FunctionalExpressionSearch.search(myClass).forEach(new Processor<PsiFunctionalExpression>() { @Override public boolean process(PsiFunctionalExpression expression) { usages.add(new UsageInfo(expression)); return true; } }); }*/ return usages.toArray(new UsageInfo[usages.size()]); }
Example #11
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 #12
Source File: CommonRefactoringUtil.java From consulo with Apache License 2.0 | 5 votes |
public static void sortDepthFirstRightLeftOrder(final UsageInfo[] usages) { Arrays.sort(usages, (usage1, usage2) -> { PsiElement element1 = usage1.getElement(), element2 = usage2.getElement(); if (element1 == element2) return 0; if (element1 == null) return 1; if (element2 == null) return -1; return element2.getTextRange().getStartOffset() - element1.getTextRange().getStartOffset(); }); }
Example #13
Source File: PushDownProcessor.java From intellij-haxe with Apache License 2.0 | 5 votes |
@Override protected void performRefactoring(UsageInfo[] usages) { try { encodeRefs(); if (myCreateClassDlg != null) { //usages.length == 0 final PsiClass psiClass = CreateSubclassAction.createSubclass(myClass, myCreateClassDlg.getTargetDirectory(), myCreateClassDlg.getClassName()); if (psiClass != null) { pushDownToClass(psiClass); } } PsiReference reference; PsiElement resolve; for (UsageInfo usage : usages) { if (usage.getElement() instanceof PsiClass) { final PsiClass targetClass = (PsiClass)usage.getElement(); pushDownToClass(targetClass); } } removeFromTargetClass(); } catch (IncorrectOperationException e) { LOG.error(e); } }
Example #14
Source File: XQueryFindUsageProviderTest.java From intellij-xquery with Apache License 2.0 | 5 votes |
public void testFindFunctionUsages() { Collection<UsageInfo> foundUsages = myFixture.testFindUsages("Function.xq"); assertEquals(1, foundUsages.size()); UsageInfo usageInfo = foundUsages.iterator().next(); assertChildOf(usageInfo.getElement(), XQueryQueryBody.class); assertChildOf(resolved(usageInfo), XQueryFunctionDecl.class); }
Example #15
Source File: UsageFavoriteNodeProvider.java From consulo with Apache License 2.0 | 5 votes |
@Override public String getElementModuleName(Object element) { if (element instanceof UsageInfo) { Module module = ModuleUtil.findModuleForPsiElement(((UsageInfo)element).getElement()); return module != null ? module.getName() : null; } return null; }
Example #16
Source File: CSharpChangeSignatureUsageProcessor.java From consulo-csharp with Apache License 2.0 | 5 votes |
@Override public void registerConflictResolvers(@Nonnull List<ResolveSnapshotProvider.ResolveSnapshot> snapshots, @Nonnull ResolveSnapshotProvider resolveSnapshotProvider, @Nonnull UsageInfo[] usages, @Nonnull ChangeInfo changeInfo) { }
Example #17
Source File: PsiElementUsageGroupBase.java From consulo with Apache License 2.0 | 5 votes |
public void calcData(final Key<?> key, final DataSink sink) { if (!isValid()) return; if (CommonDataKeys.PSI_ELEMENT == key) { sink.put(CommonDataKeys.PSI_ELEMENT, getElement()); } if (UsageView.USAGE_INFO_KEY == key) { T element = getElement(); if (element != null) { sink.put(UsageView.USAGE_INFO_KEY, new UsageInfo(element)); } } }
Example #18
Source File: ChangeNamespaceProcessor.java From consulo-csharp with Apache License 2.0 | 5 votes |
@Override @RequiredWriteAction protected void performRefactoring(@Nonnull UsageInfo[] usages) { myDeclaration.setNamespace(myExpectedNamespace); CSharpClassesMoveProcessor.retargetUsages(usages); }
Example #19
Source File: UsageSerializable.java From consulo with Apache License 2.0 | 5 votes |
@Override public void serializeMe(UsageInfo info, StringBuilder os) throws IOException { //final SmartPsiElementPointer<?> pointer = info.getSmartPointer(); final GenericElementSignatureProvider provider = new GenericElementSignatureProvider(); final String signature = provider.getSignature(info.getElement()); append(os, info.getElement().getContainingFile().getVirtualFile().getPath()); os.append(separator); append(os, signature); os.append(separator); final ProperTextRange rangeInElement = info.getRangeInElement(); if (rangeInElement == null) { append(os, "-1"); os.append(separator); append(os, "-1"); os.append(separator); } else { append(os, String.valueOf(rangeInElement.getStartOffset())); os.append(separator); append(os, String.valueOf(rangeInElement.getEndOffset())); os.append(separator); } append(os, String.valueOf(info.isNonCodeUsage())); os.append(separator); append(os, String.valueOf(info.isDynamicUsage())); os.append(separator); final String text = new UsageInfo2UsageAdapter(info).getPlainText(); append(os, text); os.append(separator); }
Example #20
Source File: SafeDeleteProcessor.java From consulo with Apache License 2.0 | 5 votes |
@Override protected boolean isPreviewUsages(@Nonnull UsageInfo[] usages) { if (myPreviewNonCodeUsages && UsageViewUtil.reportNonRegularUsages(usages, myProject)) { return true; } return super.isPreviewUsages(filterToBeDeleted(usages)); }
Example #21
Source File: SafeDeleteProcessor.java From consulo with Apache License 2.0 | 5 votes |
@Override protected boolean isToBeChanged(@Nonnull UsageInfo usageInfo) { if (usageInfo instanceof SafeDeleteReferenceUsageInfo) { return ((SafeDeleteReferenceUsageInfo)usageInfo).isSafeDelete() && super.isToBeChanged(usageInfo); } return super.isToBeChanged(usageInfo); }
Example #22
Source File: RenameUtil.java From consulo with Apache License 2.0 | 5 votes |
public static void addConflictDescriptions(UsageInfo[] usages, MultiMap<PsiElement, String> conflicts) { for (UsageInfo usage : usages) { if (usage instanceof UnresolvableCollisionUsageInfo) { conflicts.putValue(usage.getElement(), ((UnresolvableCollisionUsageInfo)usage).getDescription()); } } }
Example #23
Source File: ChangeSignatureProcessorBase.java From consulo with Apache License 2.0 | 5 votes |
@Nullable @Override protected RefactoringEventData getAfterData(@Nonnull UsageInfo[] usages) { RefactoringEventData data = new RefactoringEventData(); data.addElement(getChangeInfo().getMethod()); return data; }
Example #24
Source File: MoveDirectoryWithClassesProcessor.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull @Override protected UsageViewDescriptor createUsageViewDescriptor(UsageInfo[] usages) { PsiElement[] elements = new PsiElement[myFilesToMove.size()]; final PsiFile[] classes = PsiUtilCore.toPsiFileArray(myFilesToMove.keySet()); System.arraycopy(classes, 0, elements, 0, classes.length); return new MoveMultipleElementsViewDescriptor(elements, getTargetName()); }
Example #25
Source File: UsageInfo2UsageAdapter.java From consulo with Apache License 2.0 | 5 votes |
@Override public void calcData(final Key<?> key, final DataSink sink) { if (key == UsageView.USAGE_INFO_KEY) { sink.put(UsageView.USAGE_INFO_KEY, getUsageInfo()); } if (key == UsageView.USAGE_INFO_LIST_KEY) { List<UsageInfo> list = Arrays.asList(getMergedInfos()); sink.put(UsageView.USAGE_INFO_LIST_KEY, list); } }
Example #26
Source File: SafeDeleteProcessor.java From consulo with Apache License 2.0 | 5 votes |
private void showUsages(final UsageInfo[] usages) { UsageViewPresentation presentation = new UsageViewPresentation(); presentation.setTabText(RefactoringBundle.message("safe.delete.title")); presentation.setTargetsNodeText(RefactoringBundle.message("attempting.to.delete.targets.node.text")); presentation.setShowReadOnlyStatusAsRed(true); presentation.setShowCancelButton(true); presentation.setCodeUsagesString(RefactoringBundle.message("references.found.in.code")); presentation.setUsagesInGeneratedCodeString(RefactoringBundle.message("references.found.in.generated.code")); presentation.setNonCodeUsagesString(RefactoringBundle.message("occurrences.found.in.comments.strings.and.non.java.files")); presentation.setUsagesString(RefactoringBundle.message("usageView.usagesText")); UsageViewManager manager = UsageViewManager.getInstance(myProject); final UsageView usageView = showUsages(usages, presentation, manager); usageView.addPerformOperationAction(new RerunSafeDelete(myProject, myElements, usageView), RefactoringBundle.message("retry.command"), null, RefactoringBundle.message("rerun.safe.delete")); usageView.addPerformOperationAction(new Runnable() { @Override public void run() { UsageInfo[] preprocessedUsages = usages; for (SafeDeleteProcessorDelegate delegate : Extensions.getExtensions(SafeDeleteProcessorDelegate.EP_NAME)) { preprocessedUsages = delegate.preprocessUsages(myProject, preprocessedUsages); if (preprocessedUsages == null) return; } final UsageInfo[] filteredUsages = UsageViewUtil.removeDuplicatedUsages(preprocessedUsages); execute(filteredUsages); } }, "Delete Anyway", RefactoringBundle.message("usageView.need.reRun"), RefactoringBundle.message("usageView.doAction")); }
Example #27
Source File: XQueryFindUsageProviderTest.java From intellij-xquery with Apache License 2.0 | 5 votes |
public void testFindTwoFunctionUsages() { Collection<UsageInfo> foundUsages = myFixture.testFindUsages("FunctionTwoUsages.xq"); assertEquals(2, foundUsages.size()); UsageInfo usageInfo = foundUsages.iterator().next(); assertChildOf(usageInfo.getElement(), XQueryQueryBody.class); assertChildOf(resolved(usageInfo), XQueryFunctionDecl.class); UsageInfo secondUsageInfo = foundUsages.iterator().next(); assertChildOf(secondUsageInfo.getElement(), XQueryQueryBody.class); assertChildOf(resolved(secondUsageInfo), XQueryFunctionDecl.class); }
Example #28
Source File: BashFindUsagesProviderTest.java From BashSupport with Apache License 2.0 | 5 votes |
@Test public void testFileUsage() throws Exception { PsiElement file = configurePsiAtCaret().getContainingFile(); Collection<UsageInfo> usages = myFixture.findUsages(file); Assert.assertEquals(1, usages.size()); Assert.assertEquals("Bash file", typeNameFor(file)); Assert.assertEquals("fileUsage.bash", descriptiveNameFor(file)); }
Example #29
Source File: MoveFilesOrDirectoriesProcessor.java From consulo with Apache License 2.0 | 5 votes |
@Nullable @Override protected RefactoringEventData getAfterData(@Nonnull UsageInfo[] usages) { RefactoringEventData data = new RefactoringEventData(); data.addElement(myNewParent); return data; }
Example #30
Source File: BashFindUsagesProviderTest.java From BashSupport with Apache License 2.0 | 5 votes |
@Test public void testVarDefUsage() throws Exception { PsiElement element = configurePsiAtCaret(); Collection<UsageInfo> usages = myFixture.findUsages(element); Assert.assertEquals(3, usages.size()); Assert.assertEquals("variable", typeNameFor(element)); Assert.assertEquals("a", descriptiveNameFor(element)); }