com.intellij.usages.rules.UsageInFile Java Examples
The following examples show how to use
com.intellij.usages.rules.UsageInFile.
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: ShowUsagesTableCellRenderer.java From dagger-intellij-plugin with Apache License 2.0 | 6 votes |
private Color getBackgroundColor(boolean isSelected, Usage usage) { Color fileBgColor = null; if (isSelected) { fileBgColor = UIUtil.getListSelectionBackground(); } else { VirtualFile virtualFile = usage instanceof UsageInFile ? ((UsageInFile) usage).getFile() : null; if (virtualFile != null) { Project project = myUsageView.getProject(); PsiFile psiFile = PsiManager.getInstance(project).findFile(virtualFile); if (psiFile != null && psiFile.isValid()) { final Color color = FileColorManager.getInstance(project).getRendererBackground(psiFile); if (color != null) fileBgColor = color; } } } return fileBgColor; }
Example #2
Source File: DirectoryGroupingRule.java From consulo with Apache License 2.0 | 6 votes |
@Override @javax.annotation.Nullable public UsageGroup groupUsage(@Nonnull Usage usage) { if (usage instanceof UsageInFile) { UsageInFile usageInFile = (UsageInFile)usage; VirtualFile file = usageInFile.getFile(); if (file != null) { if (file instanceof VirtualFileWindow) { file = ((VirtualFileWindow)file).getDelegate(); } VirtualFile dir = file.getParent(); if (dir == null) return null; return getGroupForFile(dir); } } return null; }
Example #3
Source File: NonCodeUsageGroupingRule.java From consulo with Apache License 2.0 | 6 votes |
@Override public UsageGroup groupUsage(@Nonnull Usage usage) { if (usage instanceof UsageInFile) { VirtualFile file = ((UsageInFile)usage).getFile(); if (file != null) { if (GeneratedSourcesFilter.isGenerated(myProject, file)) { return UsageInGeneratedCodeGroup.INSTANCE; } } } if (usage instanceof PsiElementUsage) { if (usage instanceof UsageInfo2UsageAdapter) { final UsageInfo usageInfo = ((UsageInfo2UsageAdapter)usage).getUsageInfo(); if (usageInfo.isDynamicUsage()) { return DynamicUsageGroup.INSTANCE; } } if (((PsiElementUsage)usage).isNonCodeUsage()) { return NonCodeUsageGroup.INSTANCE; } else { return CodeUsageGroup.INSTANCE; } } return null; }
Example #4
Source File: ReplaceInProjectManager.java From consulo with Apache License 2.0 | 6 votes |
private boolean ensureUsagesWritable(ReplaceContext replaceContext, Collection<? extends Usage> selectedUsages) { Set<VirtualFile> readOnlyFiles = null; for (final Usage usage : selectedUsages) { final VirtualFile file = ((UsageInFile)usage).getFile(); if (file != null && !file.isWritable()) { if (readOnlyFiles == null) readOnlyFiles = new HashSet<>(); readOnlyFiles.add(file); } } if (readOnlyFiles != null) { ReadonlyStatusHandler.getInstance(myProject).ensureFilesWritable(readOnlyFiles); } if (hasReadOnlyUsages(selectedUsages)) { int result = Messages.showOkCancelDialog(replaceContext.getUsageView().getComponent(), FindBundle.message("find.replace.occurrences.in.read.only.files.prompt"), FindBundle.message("find.replace.occurrences.in.read.only.files.title"), Messages.getWarningIcon()); if (result != Messages.OK) { return false; } } return true; }
Example #5
Source File: ShowUsagesTableCellRenderer.java From consulo with Apache License 2.0 | 6 votes |
private Color getBackgroundColor(boolean isSelected, Usage usage) { Color fileBgColor = null; if (isSelected) { fileBgColor = UIUtil.getListSelectionBackground(); } else { VirtualFile virtualFile = usage instanceof UsageInFile ? ((UsageInFile)usage).getFile() : null; if (virtualFile != null) { Project project = myUsageView.getProject(); PsiFile psiFile = PsiManager.getInstance(project).findFile(virtualFile); if (psiFile != null && psiFile.isValid()) { final Color color = FileColorManager.getInstance(project).getRendererBackground(psiFile); if (color != null) fileBgColor = color; } } } return fileBgColor; }
Example #6
Source File: ShowUsagesTableCellRenderer.java From otto-intellij-plugin with Apache License 2.0 | 6 votes |
private Color getBackgroundColor(boolean isSelected, Usage usage) { Color fileBgColor = null; if (isSelected) { fileBgColor = UIUtil.getListSelectionBackground(); } else { VirtualFile virtualFile = usage instanceof UsageInFile ? ((UsageInFile)usage).getFile() : null; if (virtualFile != null) { Project project = myUsageView.getProject(); PsiFile psiFile = PsiManager.getInstance(project).findFile(virtualFile); if (psiFile != null && psiFile.isValid()) { final Color color = FileColorManager.getInstance(project).getRendererBackground(psiFile); if (color != null) fileBgColor = color; } } } return fileBgColor; }
Example #7
Source File: BuildFileGroupingRule.java From intellij with Apache License 2.0 | 5 votes |
@Override @Nullable public UsageGroup getParentGroupFor(Usage usage, UsageTarget[] targets) { // give the delegate a chance to refuse the usage UsageGroup base = delegate.getParentGroupFor(usage, targets); if (base == null || !(usage instanceof UsageInFile)) { return null; } VirtualFile vf = ((UsageInFile) usage).getFile(); if (vf == null || vf.getFileType() != BuildFileType.INSTANCE) { return base; } return new FileUsageGroup(project, vf) { String name; @Override public void update() { super.update(); if (isValid()) { name = BuildFile.getBuildFileString(project, vf.getPath()); } } @Override public String getPresentableName() { return name; } @Override public String getText(UsageView view) { return name; } }; }
Example #8
Source File: FileGroupingRule.java From consulo with Apache License 2.0 | 5 votes |
@Nullable @Override public UsageGroup getParentGroupFor(@Nonnull Usage usage, @Nonnull UsageTarget[] targets) { VirtualFile virtualFile; if (usage instanceof UsageInFile && (virtualFile = ((UsageInFile)usage).getFile()) != null) { return new FileUsageGroup(myProject, virtualFile); } return null; }
Example #9
Source File: UsageViewManagerImpl.java From consulo with Apache License 2.0 | 5 votes |
public static boolean isInScope(@Nonnull Usage usage, @Nonnull SearchScope searchScope) { PsiElement element = null; VirtualFile file = usage instanceof UsageInFile ? ((UsageInFile)usage).getFile() : usage instanceof PsiElementUsage ? PsiUtilCore.getVirtualFile(element = ((PsiElementUsage)usage).getElement()) : null; if (file != null) { return isFileInScope(file, searchScope); } return element != null && (searchScope instanceof EverythingGlobalScope || searchScope instanceof ProjectScopeImpl || searchScope instanceof ProjectAndLibrariesScope); }
Example #10
Source File: ReplaceInProjectManager.java From consulo with Apache License 2.0 | 4 votes |
private boolean replaceUsages(@Nonnull ReplaceContext replaceContext, @Nonnull Collection<Usage> usages) { if (!ensureUsagesWritable(replaceContext, usages)) { return true; } int[] replacedCount = {0}; final boolean[] success = {true}; success[0] &= ((ApplicationEx)ApplicationManager.getApplication()) .runWriteActionWithCancellableProgressInDispatchThread(FindBundle.message("find.replace.all.confirmation.title"), myProject, null, indicator -> { indicator.setIndeterminate(false); int processed = 0; VirtualFile lastFile = null; for (final Usage usage : usages) { ++processed; indicator.checkCanceled(); indicator.setFraction((float)processed / usages.size()); if (usage instanceof UsageInFile) { VirtualFile virtualFile = ((UsageInFile)usage).getFile(); if (virtualFile != null && !virtualFile.equals(lastFile)) { indicator.setText2(virtualFile.getPresentableUrl()); lastFile = virtualFile; } } ProgressManager.getInstance().executeNonCancelableSection(() -> { try { if (replaceUsage(usage, replaceContext.getFindModel(), replaceContext.getExcludedSetCached(), false)) { replacedCount[0]++; } } catch (FindManager.MalformedReplacementStringException ex) { markAsMalformedReplacement(replaceContext, usage); success[0] = false; } }); } }); replaceContext.getUsageView().removeUsagesBulk(usages); reportNumberReplacedOccurrences(myProject, replacedCount[0]); return success[0]; }
Example #11
Source File: UsageListCellRenderer.java From consulo with Apache License 2.0 | 4 votes |
public static VirtualFile getVirtualFile(final Usage usage) { return usage instanceof UsageInFile ? ((UsageInFile)usage).getFile() : null; }