use of com.intellij.pom.Navigatable in project intellij-community by JetBrains.
the class InspectionResultsView method getData.
@Override
public Object getData(String dataId) {
if (PlatformDataKeys.HELP_ID.is(dataId))
return HELP_ID;
if (DATA_KEY.is(dataId))
return this;
if (ExclusionHandler.EXCLUSION_HANDLER.is(dataId))
return myExclusionHandler;
if (myTree == null)
return null;
TreePath[] paths = myTree.getSelectionPaths();
if (paths == null || paths.length == 0)
return null;
if (paths.length > 1) {
if (LangDataKeys.PSI_ELEMENT_ARRAY.is(dataId)) {
return collectPsiElements();
}
return null;
}
TreePath path = paths[0];
InspectionTreeNode selectedNode = (InspectionTreeNode) path.getLastPathComponent();
if (!CommonDataKeys.NAVIGATABLE.is(dataId) && !CommonDataKeys.PSI_ELEMENT.is(dataId)) {
return null;
}
if (selectedNode instanceof RefElementNode) {
final RefElementNode refElementNode = (RefElementNode) selectedNode;
RefEntity refElement = refElementNode.getElement();
if (refElement == null)
return null;
final RefEntity item = refElement.getRefManager().getRefinedElement(refElement);
if (!item.isValid())
return null;
PsiElement psiElement = item instanceof RefElement ? ((RefElement) item).getElement() : null;
if (psiElement == null)
return null;
final CommonProblemDescriptor problem = refElementNode.getDescriptor();
if (problem instanceof ProblemDescriptor) {
PsiElement elementFromDescriptor = ((ProblemDescriptor) problem).getPsiElement();
if (elementFromDescriptor == null && CommonDataKeys.NAVIGATABLE.is(dataId)) {
final InspectionTreeNode node = (InspectionTreeNode) refElementNode.getChildAt(0);
if (node.isValid()) {
return InspectionResultsViewUtil.getNavigatableForInvalidNode((ProblemDescriptionNode) node);
}
} else {
psiElement = elementFromDescriptor;
}
}
if (CommonDataKeys.NAVIGATABLE.is(dataId)) {
return getSelectedNavigatable(problem, psiElement);
} else if (CommonDataKeys.PSI_ELEMENT.is(dataId)) {
return psiElement != null && psiElement.isValid() ? psiElement : null;
}
} else if (selectedNode instanceof ProblemDescriptionNode && CommonDataKeys.NAVIGATABLE.is(dataId)) {
Navigatable navigatable = getSelectedNavigatable(((ProblemDescriptionNode) selectedNode).getDescriptor());
return navigatable == null ? InspectionResultsViewUtil.getNavigatableForInvalidNode((ProblemDescriptionNode) selectedNode) : navigatable;
}
return null;
}
use of com.intellij.pom.Navigatable in project intellij-community by JetBrains.
the class CallHierarchyNodeDescriptor method navigate.
public void navigate(boolean requestFocus) {
if (!myNavigateToReference) {
PsiElement element = getPsiElement();
if (element instanceof Navigatable && ((Navigatable) element).canNavigate()) {
((Navigatable) element).navigate(requestFocus);
}
return;
}
final PsiReference firstReference = myReferences.get(0);
final PsiElement element = firstReference.getElement();
if (element == null)
return;
final PsiElement callElement = element.getParent();
if (callElement instanceof Navigatable && ((Navigatable) callElement).canNavigate()) {
((Navigatable) callElement).navigate(requestFocus);
} else {
final PsiFile psiFile = callElement.getContainingFile();
if (psiFile == null || psiFile.getVirtualFile() == null)
return;
FileEditorManager.getInstance(myProject).openFile(psiFile.getVirtualFile(), requestFocus);
}
Editor editor = PsiUtilBase.findEditor(callElement);
if (editor != null) {
HighlightManager highlightManager = HighlightManager.getInstance(myProject);
EditorColorsManager colorManager = EditorColorsManager.getInstance();
TextAttributes attributes = colorManager.getGlobalScheme().getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES);
ArrayList<RangeHighlighter> highlighters = new ArrayList<>();
for (PsiReference psiReference : myReferences) {
final PsiElement eachElement = psiReference.getElement();
if (eachElement != null) {
final PsiElement eachMethodCall = eachElement.getParent();
if (eachMethodCall != null) {
final TextRange textRange = eachMethodCall.getTextRange();
highlightManager.addRangeHighlight(editor, textRange.getStartOffset(), textRange.getEndOffset(), attributes, false, highlighters);
}
}
}
}
}
use of com.intellij.pom.Navigatable in project intellij-community by JetBrains.
the class CtrlMouseHandler method getInfoAt.
@Nullable
private static Info getInfoAt(@NotNull Project project, @NotNull final Editor editor, @NotNull PsiFile file, int offset, @NotNull BrowseMode browseMode) {
PsiElement targetElement = null;
if (browseMode == BrowseMode.TypeDeclaration) {
try {
targetElement = GotoTypeDeclarationAction.findSymbolType(editor, offset);
} catch (IndexNotReadyException e) {
showDumbModeNotification(project);
}
} else if (browseMode == BrowseMode.Declaration) {
final PsiReference ref = TargetElementUtil.findReference(editor, offset);
final List<PsiElement> resolvedElements = ref == null ? Collections.emptyList() : resolve(ref);
final PsiElement resolvedElement = resolvedElements.size() == 1 ? resolvedElements.get(0) : null;
final PsiElement[] targetElements = GotoDeclarationAction.findTargetElementsNoVS(project, editor, offset, false);
final PsiElement elementAtPointer = file.findElementAt(TargetElementUtil.adjustOffset(file, editor.getDocument(), offset));
if (targetElements != null) {
if (targetElements.length == 0) {
return null;
} else if (targetElements.length == 1) {
if (targetElements[0] != resolvedElement && elementAtPointer != null && targetElements[0].isPhysical()) {
return ref != null ? new InfoSingle(ref, targetElements[0]) : new InfoSingle(elementAtPointer, targetElements[0]);
}
} else {
return elementAtPointer != null ? new InfoMultiple(elementAtPointer) : null;
}
}
if (resolvedElements.size() == 1) {
return new InfoSingle(ref, resolvedElements.get(0));
}
if (resolvedElements.size() > 1) {
return elementAtPointer != null ? new InfoMultiple(elementAtPointer, ref) : null;
}
} else if (browseMode == BrowseMode.Implementation) {
final PsiElement element = TargetElementUtil.getInstance().findTargetElement(editor, ImplementationSearcher.getFlags(), offset);
PsiElement[] targetElements = new ImplementationSearcher() {
@Override
@NotNull
protected PsiElement[] searchDefinitions(final PsiElement element, Editor editor) {
final List<PsiElement> found = new ArrayList<>(2);
DefinitionsScopedSearch.search(element, getSearchScope(element, editor)).forEach(psiElement -> {
found.add(psiElement);
return found.size() != 2;
});
return PsiUtilCore.toPsiElementArray(found);
}
}.searchImplementations(editor, element, offset);
if (targetElements == null) {
return null;
}
if (targetElements.length > 1) {
PsiElement elementAtPointer = file.findElementAt(offset);
if (elementAtPointer != null) {
return new InfoMultiple(elementAtPointer);
}
return null;
}
if (targetElements.length == 1) {
Navigatable descriptor = EditSourceUtil.getDescriptor(targetElements[0]);
if (descriptor == null || !descriptor.canNavigate()) {
return null;
}
targetElement = targetElements[0];
}
}
if (targetElement != null && targetElement.isPhysical()) {
PsiElement elementAtPointer = file.findElementAt(offset);
if (elementAtPointer != null) {
return new InfoSingle(elementAtPointer, targetElement);
}
}
final PsiElement element = GotoDeclarationAction.findElementToShowUsagesOf(editor, offset);
if (element instanceof PsiNameIdentifierOwner) {
PsiElement identifier = ((PsiNameIdentifierOwner) element).getNameIdentifier();
if (identifier != null && identifier.isValid()) {
return new Info(identifier) {
@Override
public void showDocInfo(@NotNull DocumentationManager docManager) {
}
@NotNull
@Override
public DocInfo getInfo() {
String name = UsageViewUtil.getType(element) + " '" + UsageViewUtil.getShortName(element) + "'";
return new DocInfo("Show usages of " + name, null, element);
}
@Override
public boolean isValid(@NotNull Document document) {
return element.isValid();
}
@Override
public boolean isNavigatable() {
return true;
}
};
}
}
return null;
}
use of com.intellij.pom.Navigatable in project intellij-community by JetBrains.
the class BaseRemoteFileEditor method contentLoaded.
protected final void contentLoaded() {
ApplicationManager.getApplication().assertIsDispatchThread();
Navigatable navigatable = myPendingNavigatable;
if (navigatable != null) {
myPendingNavigatable = null;
TextEditor editor = getTextEditor();
assert editor != null;
editor.navigateTo(navigatable);
}
if (myMockTextEditor != null) {
if (!myMockTextEditor.isDisposed()) {
EditorFactory.getInstance().releaseEditor(myMockTextEditor);
}
myMockTextEditor = null;
}
}
use of com.intellij.pom.Navigatable in project intellij-community by JetBrains.
the class UsageViewImpl method initTree.
private void initTree() {
ApplicationManager.getApplication().assertIsDispatchThread();
myTree.setShowsRootHandles(true);
SmartExpander.installOn(myTree);
TreeUtil.installActions(myTree);
EditSourceOnDoubleClickHandler.install(myTree);
myTree.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (KeyEvent.VK_ENTER == e.getKeyCode()) {
TreePath leadSelectionPath = myTree.getLeadSelectionPath();
if (leadSelectionPath == null)
return;
DefaultMutableTreeNode node = (DefaultMutableTreeNode) leadSelectionPath.getLastPathComponent();
if (node instanceof UsageNode) {
final Usage usage = ((UsageNode) node).getUsage();
usage.navigate(false);
usage.highlightInEditor();
} else if (node.isLeaf()) {
Navigatable navigatable = getNavigatableForNode(node);
if (navigatable != null && navigatable.canNavigate()) {
navigatable.navigate(false);
}
}
}
}
});
TreeUtil.selectFirstNode(myTree);
PopupHandler.installPopupHandler(myTree, IdeActions.GROUP_USAGE_VIEW_POPUP, ActionPlaces.USAGE_VIEW_POPUP);
myTree.addTreeExpansionListener(new TreeExpansionListener() {
@Override
public void treeExpanded(TreeExpansionEvent event) {
clearRendererCache();
TreePath path = event.getPath();
Object component = path.getLastPathComponent();
if (component instanceof Node) {
Node node = (Node) component;
if (!expandingAll && node.needsUpdate()) {
checkNodeValidity(node, path);
}
}
}
@Override
public void treeCollapsed(TreeExpansionEvent event) {
clearRendererCache();
}
});
TreeUIHelper.getInstance().installTreeSpeedSearch(myTree, o -> {
Object value = o.getLastPathComponent();
TreeCellRenderer renderer = myTree.getCellRenderer();
if (renderer instanceof UsageViewTreeCellRenderer) {
UsageViewTreeCellRenderer coloredRenderer = (UsageViewTreeCellRenderer) renderer;
return coloredRenderer.getPlainTextForNode(value);
}
return value == null ? null : value.toString();
}, true);
}
Aggregations