com.intellij.usages.UsageView Java Examples

The following examples show how to use com.intellij.usages.UsageView. 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: CSharpBaseGroupingRule.java    From consulo-csharp with Apache License 2.0 6 votes vote down vote up
@Override
public void calcData(final Key<?> key, final DataSink sink)
{
	T element = myPointer.getElement();
	if(element == null)
	{
		return;
	}
	if(LangDataKeys.PSI_ELEMENT == key)
	{
		sink.put(LangDataKeys.PSI_ELEMENT, element);
	}
	if(UsageView.USAGE_INFO_KEY == key)
	{
		sink.put(UsageView.USAGE_INFO_KEY, new UsageInfo(element));
	}
}
 
Example #2
Source File: Node.java    From consulo with Apache License 2.0 6 votes vote down vote up
final synchronized void update(@Nonnull UsageView view, @Nonnull Consumer<Node> edtNodeChangedQueue) {
  boolean isDataValid = isDataValid();
  boolean isReadOnly = isDataReadOnly();
  String text = getText(view);

  boolean cachedValid = isValid();
  boolean cachedReadOnly = isFlagSet(CACHED_READ_ONLY_MASK);

  if (isDataValid != cachedValid || isReadOnly != cachedReadOnly || myCachedTextHash != text.hashCode()) {
    setFlag(CACHED_INVALID_MASK, !isDataValid);
    setFlag(CACHED_READ_ONLY_MASK, isReadOnly);

    myCachedTextHash = text.hashCode();
    updateNotify();
    edtNodeChangedQueue.consume(this);
  }
  setFlag(UPDATED_MASK, true);
}
 
Example #3
Source File: ShowImplementationsAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void updateInBackground(Editor editor,
                                @Nullable PsiElement element,
                                @Nonnull ImplementationViewComponent component,
                                String title,
                                @Nonnull AbstractPopup popup,
                                @Nonnull Ref<UsageView> usageView) {
  final ImplementationsUpdaterTask updaterTask = SoftReference.dereference(myTaskRef);
  if (updaterTask != null) {
    updaterTask.cancelTask();
  }

  if (element == null) return; //already found
  final ImplementationsUpdaterTask task = new ImplementationsUpdaterTask(element, editor, title, isIncludeAlwaysSelf(), component);
  task.init(popup, new ImplementationViewComponentUpdater(component, isIncludeAlwaysSelf() ? 1 : 0), usageView);

  myTaskRef = new WeakReference<>(task);
  ProgressManager.getInstance().runProcessWithProgressAsynchronously(task, new BackgroundableProcessIndicator(task));
}
 
Example #4
Source File: FindUsagesInFileAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static boolean isEnabled(DataContext dataContext) {
  Project project = dataContext.getData(CommonDataKeys.PROJECT);
  if (project == null) {
    return false;
  }

  Editor editor = dataContext.getData(PlatformDataKeys.EDITOR);
  if (editor == null) {
    UsageTarget[] target = dataContext.getData(UsageView.USAGE_TARGETS_KEY);
    return target != null && target.length > 0;
  }
  else {
    PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
    if (file == null) {
      return false;
    }

    Language language = PsiUtilBase.getLanguageInEditor(editor, project);
    if (language == null) {
      language = file.getLanguage();
    }
    return !(LanguageFindUsages.INSTANCE.forLanguage(language) instanceof EmptyFindUsagesProvider);
  }
}
 
Example #5
Source File: PsiElement2UsageTargetAdapter.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void calcData(final Key<?> key, final DataSink sink) {
  if (key == UsageView.USAGE_INFO_KEY) {
    PsiElement element = getElement();
    if (element != null && element.getTextRange() != null) {
      sink.put(UsageView.USAGE_INFO_KEY, new UsageInfo(element));
    }
  }
  else if (key == UsageView.USAGE_SCOPE) {
    sink.put(UsageView.USAGE_SCOPE, myOptions.searchScope);
  }
}
 
Example #6
Source File: NonCodeUsageGroupingRule.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
@Nonnull
public String getText(UsageView view) {
  if (view == null) {
    return DYNAMIC_CAPTION;
  }
  else {
    final String dynamicCodeUsagesString = view.getPresentation().getDynamicCodeUsagesString();
    return dynamicCodeUsagesString == null ? DYNAMIC_CAPTION : dynamicCodeUsagesString;
  }
}
 
Example #7
Source File: UsageGroupingRuleProviderImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
@Nonnull
public AnAction[] createGroupingActions(UsageView view) {
  final UsageViewImpl impl = (UsageViewImpl)view;
  final JComponent component = impl.getComponent();

  final GroupByModuleTypeAction groupByModuleTypeAction = new GroupByModuleTypeAction(impl);
  groupByModuleTypeAction.registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_D, InputEvent.CTRL_DOWN_MASK)), component, impl);

  final GroupByFileStructureAction groupByFileStructureAction = createGroupByFileStructureAction(impl);

  final GroupByScopeAction groupByScopeAction = new GroupByScopeAction(impl);

  final GroupByPackageAction groupByPackageAction = new GroupByPackageAction(impl);
  groupByPackageAction.registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_P, InputEvent.CTRL_DOWN_MASK)), component, impl);

  if(view.getPresentation().isCodeUsages()) {
    final GroupByUsageTypeAction groupByUsageTypeAction = new GroupByUsageTypeAction(impl);
    groupByUsageTypeAction.registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_T, InputEvent.CTRL_DOWN_MASK)), component, impl);
    return new AnAction[] {
      groupByUsageTypeAction,
      groupByScopeAction,
      groupByModuleTypeAction,
      groupByPackageAction,
      groupByFileStructureAction,
    };
  }
  else {
    return new AnAction[] {
      groupByScopeAction,
      groupByModuleTypeAction,
      groupByPackageAction,
      groupByFileStructureAction,
    };
  }
}
 
Example #8
Source File: BuildFileGroupingRule.java    From intellij with Apache License 2.0 5 votes vote down vote up
@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 #9
Source File: UsageNode.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
protected String getText(@Nonnull final UsageView view) {
  try {
    return getUsage().getPresentation().getPlainText();
  }
  catch(AbstractMethodError e) {
    return Arrays.asList(getUsage().getPresentation().getText()).toString();
  }
}
 
Example #10
Source File: BackgroundUpdaterTaskBase.java    From consulo with Apache License 2.0 5 votes vote down vote up
private boolean tryAppendUsage(@Nonnull T element) {
  final UsageView view = myUsageView.get();
  if (view != null && !((UsageViewImpl)view).isDisposed()) {
    Usage usage = createUsage(element);
    if (usage == null) return false;
    ApplicationManager.getApplication().runReadAction(() -> view.appendUsage(usage));
    return true;
  }
  return false;
}
 
Example #11
Source File: ListBackgroundUpdaterTask.java    From consulo with Apache License 2.0 5 votes vote down vote up
/**
 * @deprecated please use {@link BackgroundUpdaterTask}
 */
@Deprecated
public void init(@Nonnull AbstractPopup popup, @Nonnull Object component, @Nonnull Ref<UsageView> usageView) {
  myPopup = popup;
  if (component instanceof JBList) {
    init((JBPopup)myPopup, new JBListUpdater((JBList)component), usageView);
  }
}
 
Example #12
Source File: UsageViewUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static Set<UsageInfo> getNotExcludedUsageInfos(final UsageView usageView) {
  Set<Usage> excludedUsages = usageView.getExcludedUsages();

  Set<UsageInfo> usageInfos = new LinkedHashSet<UsageInfo>();
  for (Usage usage : usageView.getUsages()) {
    if (usage instanceof UsageInfo2UsageAdapter && !excludedUsages.contains(usage)) {
      UsageInfo usageInfo = ((UsageInfo2UsageAdapter)usage).getUsageInfo();
      usageInfos.add(usageInfo);
    }
  }
  return usageInfos;
}
 
Example #13
Source File: FindUsagesInFileAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void actionPerformed(AnActionEvent e) {
  DataContext dataContext = e.getDataContext();
  final Project project = dataContext.getData(CommonDataKeys.PROJECT);
  if (project == null) return;
  PsiDocumentManager.getInstance(project).commitAllDocuments();
  Editor editor = dataContext.getData(PlatformDataKeys.EDITOR);

  UsageTarget[] usageTargets = dataContext.getData(UsageView.USAGE_TARGETS_KEY);
  if (usageTargets != null) {
    FileEditor fileEditor = dataContext.getData(PlatformDataKeys.FILE_EDITOR);
    if (fileEditor != null) {
      usageTargets[0].findUsagesInEditor(fileEditor);
    }
  }
  else if (editor == null) {
    Messages.showMessageDialog(
      project,
      FindBundle.message("find.no.usages.at.cursor.error"),
      CommonBundle.getErrorTitle(),
      Messages.getErrorIcon()
    );
  }
  else {
    HintManager.getInstance().showErrorHint(editor, FindBundle.message("find.no.usages.at.cursor.error"));
  }
}
 
Example #14
Source File: ImportUsageFilteringRuleProvider.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
@Nonnull
public AnAction[] createFilteringActions(@Nonnull final UsageView view) {
  if (view.getPresentation().isCodeUsages()) {
    final JComponent component = view.getComponent();
    final ShowImportsAction showImportsAction = new ShowImportsAction(view);
    showImportsAction.registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_I, InputEvent.CTRL_DOWN_MASK)), component, view);
    return new AnAction[] { showImportsAction };
  }
  else {
    return AnAction.EMPTY_ARRAY;
  }
}
 
Example #15
Source File: FindInProjectUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void calcData(@Nonnull Key key, @Nonnull DataSink sink) {
  if (UsageView.USAGE_SCOPE == key) {
    SearchScope scope = getScopeFromModel(myProject, myFindModel);
    sink.put(UsageView.USAGE_SCOPE, scope);
  }
}
 
Example #16
Source File: Unity3dAssetUsageFilteringRuleProvider.java    From consulo-unity3d with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public AnAction[] createFilteringActions(@Nonnull UsageView view)
{
	if(view.getPresentation().isCodeUsages())
	{
		return new AnAction[]{new ShowAssetUsageAction(view)};
	}
	else
	{
		return AnAction.EMPTY_ARRAY;
	}
}
 
Example #17
Source File: CSharpBaseGroupingRule.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public String getText(@Nullable UsageView usageView)
{
	T element = myPointer.getElement();
	if(element == null)
	{
		return "INVALID";
	}
	return LanguageFindUsages.INSTANCE.forKey(CSharpLanguage.INSTANCE).get(0).getNodeText(element, false);
}
 
Example #18
Source File: UsageInfo2ListRule.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
@Nullable
public List<UsageInfo> getData(@Nonnull final DataProvider dataProvider) {
  UsageInfo usageInfo = dataProvider.getDataUnchecked(UsageView.USAGE_INFO_KEY);
  if (usageInfo != null) return Collections.singletonList(usageInfo);
  return null;
}
 
Example #19
Source File: RerunSearchAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@RequiredUIAccess
@Override
public void actionPerformed(@Nonnull AnActionEvent e) {
  UsageView usageView = e.getData(UsageView.USAGE_VIEW_KEY);
  if (usageView instanceof UsageViewImpl) {
    ((UsageViewImpl)usageView).refreshUsages();
  }
}
 
Example #20
Source File: RerunSearchAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@RequiredUIAccess
@Override
public void update(@Nonnull AnActionEvent e) {
  UsageView usageView = e.getData(UsageView.USAGE_VIEW_KEY);
  boolean enabled = usageView instanceof UsageViewImpl && ((UsageViewImpl)usageView).canPerformReRun();
  e.getPresentation().setEnabled(enabled);
}
 
Example #21
Source File: UsageFilteringRuleProviderImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
@Nonnull
public AnAction[] createFilteringActions(@Nonnull UsageView view) {
  if (!view.getPresentation().isCodeUsages()) {
    return AnAction.EMPTY_ARRAY;
  }
  final JComponent component = view.getComponent();

  final ShowReadAccessUsagesAction read = new ShowReadAccessUsagesAction();
  read.registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_R, InputEvent.CTRL_DOWN_MASK)), component, view);

  final ShowWriteAccessUsagesAction write = new ShowWriteAccessUsagesAction();
  write.registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_W, InputEvent.CTRL_DOWN_MASK)), component, view);
  return new AnAction[] {read, write};
}
 
Example #22
Source File: ImplementationViewComponent.java    From consulo with Apache License 2.0 4 votes vote down vote up
public UsageView showInUsageView() {
  return FindUtil.showInUsageView(null, collectNonBinaryElements(), myTitle, myEditor.getProject());
}
 
Example #23
Source File: SafeDeleteProcessorDelegateBase.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nullable
public UsageView showUsages(UsageInfo[] usages, UsageViewPresentation presentation, UsageViewManager manager, PsiElement[] elements) {
  return null;
}
 
Example #24
Source File: PreviewUsageAction.java    From consulo with Apache License 2.0 4 votes vote down vote up
PreviewUsageAction(@Nonnull UsageView usageView) {
  super(usageView, UsageViewBundle.message("preview.usages.action.text"), AllIcons.Actions.PreviewDetails);
}
 
Example #25
Source File: UsagePreviewPanel.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public UsageContextPanel create(@Nonnull UsageView usageView) {
  return new UsagePreviewPanel(((UsageViewImpl)usageView).getProject(), usageView.getPresentation(), true);
}
 
Example #26
Source File: UsagePreviewPanel.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isAvailableFor(@Nonnull UsageView usageView) {
  return true;
}
 
Example #27
Source File: UsageTargetsRule.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public Key<UsageTarget[]> getKey() {
  return UsageView.USAGE_TARGETS_KEY;
}
 
Example #28
Source File: BackgroundUpdaterTaskBase.java    From consulo with Apache License 2.0 4 votes vote down vote up
public void init(@Nonnull JBPopup popup, @Nonnull GenericListComponentUpdater<T> updater, @Nonnull Ref<? extends UsageView> usageView) {
  myPopup = popup;
  myUpdater = updater;
  myUsageView = usageView;
}
 
Example #29
Source File: VirtualFileArrayRule.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public VirtualFile[] getData(@Nonnull final DataProvider dataProvider) {
  // Try to detect multiselection.

  Project project = dataProvider.getDataUnchecked(PlatformDataKeys.PROJECT_CONTEXT);
  if (project != null && !project.isDisposed()) {
    return ProjectRootManager.getInstance(project).getContentRoots();
  }

  Module[] selectedModules = dataProvider.getDataUnchecked(LangDataKeys.MODULE_CONTEXT_ARRAY);
  if (selectedModules != null && selectedModules.length > 0) {
    return getFilesFromModules(selectedModules);
  }

  Module selectedModule = dataProvider.getDataUnchecked(LangDataKeys.MODULE_CONTEXT);
  if (selectedModule != null && !selectedModule.isDisposed()) {
    return ModuleRootManager.getInstance(selectedModule).getContentRoots();
  }

  PsiElement[] psiElements = dataProvider.getDataUnchecked(LangDataKeys.PSI_ELEMENT_ARRAY);
  if (psiElements != null && psiElements.length != 0) {
    return getFilesFromPsiElements(psiElements);
  }

  // VirtualFile -> VirtualFile[]
  VirtualFile vFile = dataProvider.getDataUnchecked(PlatformDataKeys.VIRTUAL_FILE);
  if (vFile != null) {
    return new VirtualFile[]{vFile};
  }

  //

  PsiFile psiFile = dataProvider.getDataUnchecked(LangDataKeys.PSI_FILE);
  if (psiFile != null && psiFile.getVirtualFile() != null) {
    return new VirtualFile[]{psiFile.getVirtualFile()};
  }

  PsiElement elem = dataProvider.getDataUnchecked(LangDataKeys.PSI_ELEMENT);
  if (elem != null) {
    return getFilesFromPsiElement(elem);
  }

  Usage[] usages = dataProvider.getDataUnchecked(UsageView.USAGES_KEY);
  UsageTarget[] usageTargets = dataProvider.getDataUnchecked(UsageView.USAGE_TARGETS_KEY);
  if (usages != null || usageTargets != null) {
    return UsageDataUtil.provideVirtualFileArray(usages, usageTargets);
  }

  return null;
}
 
Example #30
Source File: UsageInfo2ListRule.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public Key<List<UsageInfo>> getKey() {
  return UsageView.USAGE_INFO_LIST_KEY;
}