use of com.intellij.usages.UsageTarget in project android by JetBrains.
the class AndroidFindUsagesTest method findUsages.
private static Collection<UsageInfo> findUsages(String fileName, final JavaCodeInsightTestFixture fixture, String newFilePath) throws Throwable {
VirtualFile file = fixture.copyFileToProject(BASE_PATH + fileName, newFilePath);
fixture.configureFromExistingVirtualFile(file);
final UsageTarget[] targets = UsageTargetUtil.findUsageTargets(new DataProvider() {
@Override
public Object getData(@NonNls String dataId) {
return ((EditorEx) fixture.getEditor()).getDataContext().getData(dataId);
}
});
assert targets != null && targets.length > 0 && targets[0] instanceof PsiElementUsageTarget;
return fixture.findUsages(((PsiElementUsageTarget) targets[0]).getElement());
}
use of com.intellij.usages.UsageTarget in project intellij-community by JetBrains.
the class HighlightUsagesHandler method invoke.
public static void invoke(@NotNull final Project project, @NotNull final Editor editor, final PsiFile file) {
PsiDocumentManager.getInstance(project).commitAllDocuments();
final SelectionModel selectionModel = editor.getSelectionModel();
if (file == null && !selectionModel.hasSelection()) {
selectionModel.selectWordAtCaret(false);
}
if (file == null || selectionModel.hasSelection()) {
doRangeHighlighting(editor, project);
return;
}
final HighlightUsagesHandlerBase handler = createCustomHandler(editor, file);
if (handler != null) {
final String featureId = handler.getFeatureId();
if (featureId != null) {
FeatureUsageTracker.getInstance().triggerFeatureUsed(featureId);
}
handler.highlightUsages();
return;
}
DumbService.getInstance(project).withAlternativeResolveEnabled(() -> {
UsageTarget[] usageTargets = getUsageTargets(editor, file);
if (usageTargets == null) {
handleNoUsageTargets(file, editor, selectionModel, project);
return;
}
boolean clearHighlights = isClearHighlights(editor);
for (UsageTarget target : usageTargets) {
target.highlightUsages(file, editor, clearHighlights);
}
});
}
use of com.intellij.usages.UsageTarget in project intellij-community by JetBrains.
the class FindUsagesInFileAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent e) {
DataContext dataContext = e.getDataContext();
final Project project = CommonDataKeys.PROJECT.getData(dataContext);
if (project == null)
return;
PsiDocumentManager.getInstance(project).commitAllDocuments();
Editor editor = CommonDataKeys.EDITOR.getData(dataContext);
UsageTarget[] usageTargets = UsageView.USAGE_TARGETS_KEY.getData(dataContext);
if (usageTargets != null) {
FileEditor fileEditor = PlatformDataKeys.FILE_EDITOR.getData(dataContext);
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"));
}
}
use of com.intellij.usages.UsageTarget in project intellij-community by JetBrains.
the class VirtualFileArrayRule method getData.
@Override
public Object getData(final DataProvider dataProvider) {
// Try to detect multiselection.
Set<VirtualFile> result = null;
FileSystemTree fileSystemTree = FileSystemTree.DATA_KEY.getData(dataProvider);
if (fileSystemTree != null) {
result = addFiles(result, fileSystemTree.getSelectedFiles());
}
Project project = PlatformDataKeys.PROJECT_CONTEXT.getData(dataProvider);
if (project != null && !project.isDisposed()) {
result = addFiles(result, ProjectRootManager.getInstance(project).getContentRoots());
}
Module[] selectedModules = LangDataKeys.MODULE_CONTEXT_ARRAY.getData(dataProvider);
if (selectedModules != null && selectedModules.length > 0) {
for (Module selectedModule : selectedModules) {
result = addFiles(result, ModuleRootManager.getInstance(selectedModule).getContentRoots());
}
}
Module selectedModule = LangDataKeys.MODULE_CONTEXT.getData(dataProvider);
if (selectedModule != null && !selectedModule.isDisposed()) {
result = addFiles(result, ModuleRootManager.getInstance(selectedModule).getContentRoots());
}
PsiElement[] psiElements = LangDataKeys.PSI_ELEMENT_ARRAY.getData(dataProvider);
if (psiElements != null) {
for (PsiElement element : psiElements) {
result = addFilesFromPsiElement(result, element);
}
}
result = addFile(result, CommonDataKeys.VIRTUAL_FILE.getData(dataProvider));
PsiFile psiFile = CommonDataKeys.PSI_FILE.getData(dataProvider);
if (psiFile != null) {
result = addFile(result, psiFile.getVirtualFile());
}
if (result != null) {
return VfsUtilCore.toVirtualFileArray(result);
}
PsiElement elem = CommonDataKeys.PSI_ELEMENT.getData(dataProvider);
if (elem != null) {
result = addFilesFromPsiElement(result, elem);
}
Usage[] usages = UsageView.USAGES_KEY.getData(dataProvider);
UsageTarget[] usageTargets = UsageView.USAGE_TARGETS_KEY.getData(dataProvider);
if (usages != null || usageTargets != null) {
for (VirtualFile file : UsageDataUtil.provideVirtualFileArray(usages, usageTargets)) {
result = addFile(result, file);
}
}
if (result == null) {
final Object[] objects = (Object[]) dataProvider.getData(PlatformDataKeys.SELECTED_ITEMS.getName());
if (objects != null) {
final VirtualFile[] files = new VirtualFile[objects.length];
for (int i = 0, objectsLength = objects.length; i < objectsLength; i++) {
Object object = objects[i];
if (!(object instanceof VirtualFile))
return null;
files[i] = (VirtualFile) object;
}
return files;
}
return null;
} else {
return VfsUtilCore.toVirtualFileArray(result);
}
}
use of com.intellij.usages.UsageTarget in project intellij-community by JetBrains.
the class ThrowsUsageTargetProvider method getTargets.
@Override
@Nullable
public UsageTarget[] getTargets(Editor editor, final PsiFile file) {
if (editor == null || file == null)
return null;
PsiElement element = file.findElementAt(TargetElementUtil.adjustOffset(file, editor.getDocument(), editor.getCaretModel().getOffset()));
if (element == null)
return null;
if (element instanceof PsiKeyword && PsiKeyword.THROWS.equals(element.getText())) {
return new UsageTarget[] { new PsiElement2UsageTargetAdapter(element) };
}
final PsiElement parent = element.getParent();
if (parent instanceof PsiThrowStatement) {
return new UsageTarget[] { new PsiElement2UsageTargetAdapter(parent) };
}
return null;
}
Aggregations