com.intellij.psi.NavigatablePsiElement Java Examples
The following examples show how to use
com.intellij.psi.NavigatablePsiElement.
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: OpenCorrespondingBuildFile.java From intellij with Apache License 2.0 | 6 votes |
/** Returns true if a target or BUILD file could be found and navigated to. */ private static void navigateToTargetOrFile(Project project, VirtualFile vf) { // First, find the parent BUILD file. We don't want to navigate to labels in other packages BlazePackage parentPackage = BuildFileUtils.getBuildFile(project, vf); if (parentPackage == null) { return; } // first, look for a specific target which includes this source file PsiElement target = BuildFileUtils.findBuildTarget(project, parentPackage, new File(vf.getPath())); if (target instanceof NavigatablePsiElement) { ((NavigatablePsiElement) target).navigate(true); return; } OpenFileAction.openFile(parentPackage.buildFile.getFile().getPath(), project); }
Example #2
Source File: PsiElementListNavigator.java From consulo with Apache License 2.0 | 6 votes |
public static void openTargets(MouseEvent e, NavigatablePsiElement[] targets, String title, final String findUsagesTitle, ListCellRenderer listRenderer, @Nullable BackgroundUpdaterTask listUpdaterTask) { JBPopup popup = navigateOrCreatePopup(targets, title, findUsagesTitle, listRenderer, listUpdaterTask); if (popup != null) { RelativePoint point = new RelativePoint(e); if (listUpdaterTask != null) { runActionAndListUpdaterTask(() -> popup.show(point), listUpdaterTask); } else { popup.show(point); } } }
Example #3
Source File: BuckStructureViewElement.java From buck with Apache License 2.0 | 6 votes |
/** Creates a structure view element for the given psi element. */ @Nullable public static BuckStructureViewElement forElement(NavigatablePsiElement element) { if (element instanceof BuckFile) { return new ForFile((BuckFile) element); } else if (element instanceof BuckFunctionDefinitionImpl) { return new ForFunctionDefinition((BuckFunctionDefinitionImpl) element); } else if (element instanceof BuckFunctionTrailerImpl) { return new ForFunctionTrailer((BuckFunctionTrailerImpl) element); } else if (element instanceof BuckLoadArgumentImpl) { return new ForLoadArgument((BuckLoadArgumentImpl) element); } else if (element instanceof BuckExpressionImpl) { return new ForExpression((BuckExpressionImpl) element); } else { return null; } }
Example #4
Source File: CSharpLineMarkerUtil.java From consulo-csharp with Apache License 2.0 | 6 votes |
@RequiredReadAction public static void openTargets(@Nonnull Collection<? extends PsiElement> members, @Nonnull MouseEvent mouseEvent, @Nonnull String text, @Nonnull final Function<PsiElement, PsiElement> map) { NavigatablePsiElement[] navigatablePsiElements = members.toArray(new NavigatablePsiElement[members.size()]); ContainerUtil.sort(navigatablePsiElements, (o1, o2) -> { PsiElement map1 = map.fun(o1); PsiElement map2 = map.fun(o2); if(map1 instanceof PsiNamedElement && map2 instanceof PsiNamedElement) { return Comparing.compare(((PsiNamedElement) map1).getName(), ((PsiNamedElement) map2).getName()); } return 0; }); PsiElementListNavigator.openTargets(mouseEvent, navigatablePsiElements, text, text, new PsiMappedElementListCellRender(map)); }
Example #5
Source File: HaxeGotoSuperHandler.java From intellij-haxe with Apache License 2.0 | 6 votes |
private static void tryNavigateToSuperMethod(Editor editor, HaxeMethod methodDeclaration, List<HaxeNamedComponent> superItems) { final String methodName = methodDeclaration.getName(); if (methodName == null) { return; } final List<HaxeNamedComponent> filteredSuperItems = ContainerUtil.filter(superItems, new Condition<HaxeNamedComponent>() { @Override public boolean value(HaxeNamedComponent component) { return methodName.equals(component.getName()); } }); if (!filteredSuperItems.isEmpty()) { PsiElementListNavigator.openTargets(editor, HaxeResolveUtil.getComponentNames(filteredSuperItems) .toArray(new NavigatablePsiElement[filteredSuperItems.size()]), DaemonBundle.message("navigation.title.super.method", methodName), null, new DefaultPsiElementCellRenderer()); } }
Example #6
Source File: HierarchyBrowserBase.java From consulo with Apache License 2.0 | 5 votes |
private Navigatable getNavigatable(HierarchyNodeDescriptor descriptor) { if (descriptor instanceof Navigatable && descriptor.isValid()) { return (Navigatable)descriptor; } PsiElement element = getElementFromDescriptor(descriptor); if (element instanceof NavigatablePsiElement && element.isValid()) { return (NavigatablePsiElement)element; } return null; }
Example #7
Source File: PsiElementListNavigator.java From consulo with Apache License 2.0 | 5 votes |
/** * @deprecated use {@link #openTargets(MouseEvent, NavigatablePsiElement[], String, String, ListCellRenderer, BackgroundUpdaterTask)} instead */ @Deprecated public static void openTargets(MouseEvent e, NavigatablePsiElement[] targets, String title, final String findUsagesTitle, ListCellRenderer listRenderer, @Nullable ListBackgroundUpdaterTask listUpdaterTask) { openTargets(e, targets, title, findUsagesTitle, listRenderer, (BackgroundUpdaterTask)listUpdaterTask); }
Example #8
Source File: PsiElementListNavigator.java From consulo with Apache License 2.0 | 5 votes |
public NavigateOrPopupHelper(@Nonnull NavigatablePsiElement[] targets, String title) { myTargets = targets; myTitle = title; myTargetsConsumer = selectedElements -> { for (Object element : selectedElements) { PsiElement selected = (PsiElement)element; if (selected.isValid()) { ((NavigatablePsiElement)selected).navigate(true); } } }; }
Example #9
Source File: PsiElementListNavigator.java From consulo with Apache License 2.0 | 5 votes |
/** * listUpdaterTask should be started after alarm is initialized so one-item popup won't blink */ @Nullable public static JBPopup navigateOrCreatePopup(@Nonnull final NavigatablePsiElement[] targets, final String title, final String findUsagesTitle, final ListCellRenderer listRenderer, @Nullable final BackgroundUpdaterTask listUpdaterTask, @Nonnull final Consumer<Object[]> consumer) { return new NavigateOrPopupHelper(targets, title).setFindUsagesTitle(findUsagesTitle).setListRenderer(listRenderer).setListUpdaterTask(listUpdaterTask).setTargetsConsumer(consumer) .navigateOrCreatePopup(); }
Example #10
Source File: PsiElementListNavigator.java From consulo with Apache License 2.0 | 5 votes |
@Nullable public static JBPopup navigateOrCreatePopup(final NavigatablePsiElement[] targets, final String title, final String findUsagesTitle, final ListCellRenderer listRenderer, @Nullable final BackgroundUpdaterTask listUpdaterTask) { return navigateOrCreatePopup(targets, title, findUsagesTitle, listRenderer, listUpdaterTask, selectedElements -> { for (Object element : selectedElements) { PsiElement selected = (PsiElement)element; if (selected.isValid()) { ((NavigatablePsiElement)selected).navigate(true); } } }); }
Example #11
Source File: PsiElementListNavigator.java From consulo with Apache License 2.0 | 5 votes |
public static void openTargets(Editor e, NavigatablePsiElement[] targets, String title, final String findUsagesTitle, ListCellRenderer listRenderer, @Nullable BackgroundUpdaterTask listUpdaterTask) { final JBPopup popup = navigateOrCreatePopup(targets, title, findUsagesTitle, listRenderer, listUpdaterTask); if (popup != null) { if (listUpdaterTask != null) { runActionAndListUpdaterTask(() -> popup.showInBestPositionFor(e), listUpdaterTask); } else { popup.showInBestPositionFor(e); } } }
Example #12
Source File: DefaultGutterIconNavigationHandler.java From consulo with Apache License 2.0 | 5 votes |
@RequiredUIAccess @Override public void navigate(MouseEvent e, T elt) { PsiElementListNavigator.openTargets(e, myReferences.toArray(new NavigatablePsiElement[myReferences.size()]), myTitle, null, createListCellRenderer()); }
Example #13
Source File: ThriftLineMarkerProvider.java From intellij-thrift with Apache License 2.0 | 5 votes |
@Nullable private LineMarkerInfo findImplementationsAndCreateMarker(final ThriftDefinitionName definitionName) { final List<NavigatablePsiElement> implementations = ThriftPsiUtil.findImplementations(definitionName); if (implementations.isEmpty()) { return null; } return new LineMarkerInfo<PsiElement>( definitionName, definitionName.getTextRange(), AllIcons.Gutter.ImplementedMethod, Pass.UPDATE_ALL, new Function<PsiElement, String>() { @Override public String fun(PsiElement element) { return DaemonBundle.message("interface.is.implemented.too.many"); } }, new GutterIconNavigationHandler<PsiElement>() { @Override public void navigate(MouseEvent e, PsiElement elt) { PsiElementListNavigator.openTargets( e, implementations.toArray(new NavigatablePsiElement[implementations.size()]), DaemonBundle.message("navigation.title.implementation.method", definitionName.getText(), implementations.size()), "Implementations of " + definitionName.getText(), new DefaultPsiElementCellRenderer() ); } }, GutterIconRenderer.Alignment.RIGHT ); }
Example #14
Source File: HaxeLineMarkerProvider.java From intellij-haxe with Apache License 2.0 | 5 votes |
@Nullable private static LineMarkerInfo createImplementationMarker(final HaxeClass componentWithDeclarationList, final List<HaxeClass> items) { final HaxeComponentName componentName = componentWithDeclarationList.getComponentName(); if (componentName == null) { return null; } final PsiElement element = componentName.getIdentifier().getFirstChild(); return new LineMarkerInfo<>( element, element.getTextRange(), componentWithDeclarationList instanceof HaxeInterfaceDeclaration ? AllIcons.Gutter.ImplementedMethod : AllIcons.Gutter.OverridenMethod, Pass.UPDATE_ALL, item -> DaemonBundle.message("method.is.implemented.too.many"), new GutterIconNavigationHandler<PsiElement>() { @Override public void navigate(MouseEvent e, PsiElement elt) { PsiElementListNavigator.openTargets( e, HaxeResolveUtil.getComponentNames(items).toArray(new NavigatablePsiElement[items.size()]), DaemonBundle.message("navigation.title.subclass", componentWithDeclarationList.getName(), items.size()), "Subclasses of " + componentWithDeclarationList.getName(), new DefaultPsiElementCellRenderer() ); } }, GutterIconRenderer.Alignment.RIGHT ); }
Example #15
Source File: PathFinder.java From intellij-swagger with MIT License | 5 votes |
public List<? extends PsiNamedElement> findNamedChildren( final String path, final PsiElement psiElement) { Predicate<PsiElement> childFilter = child -> child instanceof NavigatablePsiElement && !(child instanceof JsonStringLiteral); return findChildrenByPathFrom(new PathExpression(path), psiElement, childFilter); }
Example #16
Source File: PathFinder.java From intellij-swagger with MIT License | 5 votes |
public List<? extends PsiNamedElement> findDirectNamedChildren( final String path, final PsiElement psiElement) { Predicate<PsiElement> childFilter = child -> child instanceof NavigatablePsiElement && !(child instanceof JsonStringLiteral) && !(child instanceof YAMLSequence) && !(child instanceof JsonArray); return findChildrenByPathFrom(new PathExpression(path), psiElement, childFilter); }
Example #17
Source File: PathFinder.java From intellij-swagger with MIT License | 5 votes |
private Optional<? extends PsiElement> getChildByName( final PsiElement psiElement, final String name, Predicate<PsiElement> childFilter) { if (ROOT_PATH.equals(name)) { return Optional.of(psiElement); } List<PsiNamedElement> children = Arrays.stream(psiElement.getChildren()) .filter(child -> child instanceof PsiNamedElement) .map(child -> (PsiNamedElement) child) .collect(Collectors.toList()); if (children.isEmpty()) { Optional<PsiElement> navigatablePsiElement = Arrays.stream(psiElement.getChildren()) .filter(child -> child instanceof NavigatablePsiElement) .filter(child -> !(child instanceof JsonStringLiteral)) .findFirst(); return navigatablePsiElement.isPresent() ? getChildByName(navigatablePsiElement.get(), name, childFilter) : Optional.empty(); } final String unescapedName = unescape(name); return children.stream().filter(child -> unescapedName.equals(child.getName())).findFirst(); }
Example #18
Source File: BlazeTargetFilter.java From intellij with Apache License 2.0 | 5 votes |
@Nullable @Override public Result applyFilter(String line, int entireLength) { Matcher matcher = TARGET_PATTERN.matcher(line); List<ResultItem> results = new ArrayList<>(); while (matcher.find()) { String labelString = matcher.group(); String prefix = matcher.group(1); if (prefix != null) { labelString = labelString.substring(prefix.length()); } Label label = LabelUtils.createLabelFromString(null, labelString); if (label == null) { continue; } // for performance reasons, don't resolve until the user clicks the link NonProblemHyperlinkInfo link = project -> { PsiElement psi = BuildReferenceManager.getInstance(project).resolveLabel(label); if (psi instanceof NavigatablePsiElement) { ((NavigatablePsiElement) psi).navigate(true); } }; int offset = entireLength - line.length(); results.add( new ResultItem( matcher.start() + offset, matcher.end() + offset, link, getHighlightAttributes())); } return results.isEmpty() ? null : new Result(results); }
Example #19
Source File: HaxeGotoSuperHandler.java From intellij-haxe with Apache License 2.0 | 5 votes |
@Override public void invoke(@NotNull Project project, @NotNull Editor editor, @NotNull PsiFile file) { final PsiElement at = file.findElementAt(editor.getCaretModel().getOffset()); final HaxeComponentName componentName = PsiTreeUtil.getParentOfType(at, HaxeComponentName.class); final HaxeClass haxeClass = PsiTreeUtil.getParentOfType(at, HaxeClass.class); final HaxeNamedComponent namedComponent = componentName == null ? haxeClass : (HaxeNamedComponent)componentName.getParent(); if (at == null || haxeClass == null || namedComponent == null) return; final List<HaxeClass> supers = HaxeResolveUtil.tyrResolveClassesByQName(haxeClass.getHaxeExtendsList()); supers.addAll(HaxeResolveUtil.tyrResolveClassesByQName(haxeClass.getHaxeImplementsList())); final List<HaxeNamedComponent> superItems = HaxeResolveUtil.findNamedSubComponents(false, supers.toArray(new HaxeClass[supers.size()])); final HaxeComponentType type = HaxeComponentType.typeOf(namedComponent); if (type == HaxeComponentType.METHOD) { final HaxeMethod methodDeclaration = (HaxeMethod)namedComponent; tryNavigateToSuperMethod(editor, methodDeclaration, superItems); } else if (!supers.isEmpty() && namedComponent instanceof HaxeClass) { PsiElementListNavigator.openTargets( editor, HaxeResolveUtil.getComponentNames(supers).toArray(new NavigatablePsiElement[supers.size()]), DaemonBundle.message("navigation.title.subclass", namedComponent.getName(), supers.size()), "Subclasses of " + namedComponent.getName(), new DefaultPsiElementCellRenderer() ); } }
Example #20
Source File: SimpleStructureViewElement.java From intellij-sdk-docs with Apache License 2.0 | 4 votes |
public SimpleStructureViewElement(NavigatablePsiElement element) { this.myElement = element; }
Example #21
Source File: WeaveVisitor.java From mule-intellij-plugins with Apache License 2.0 | 4 votes |
public void visitNavigatablePsiElement(@NotNull NavigatablePsiElement o) { visitElement(o); }
Example #22
Source File: PsiElementListNavigator.java From consulo with Apache License 2.0 | 4 votes |
protected void afterPopupBuilderCreated(@Nonnull IPopupChooserBuilder<NavigatablePsiElement> builder) { // Do nothing by default }
Example #23
Source File: PathFinder.java From intellij-swagger with MIT License | 4 votes |
public Optional<PsiElement> findByPathFrom(final String path, final PsiElement psiElement) { Predicate<PsiElement> childFilter = child -> child instanceof NavigatablePsiElement && !(child instanceof JsonStringLiteral); return findByPathFrom(new PathExpression(path), psiElement, childFilter); }
Example #24
Source File: PsiElementListNavigator.java From consulo with Apache License 2.0 | 4 votes |
public static void openTargets(Editor e, NavigatablePsiElement[] targets, String title, final String findUsagesTitle, ListCellRenderer listRenderer) { openTargets(e, targets, title, findUsagesTitle, listRenderer, null); }
Example #25
Source File: PsiElementListNavigator.java From consulo with Apache License 2.0 | 4 votes |
public static void openTargets(MouseEvent e, NavigatablePsiElement[] targets, String title, final String findUsagesTitle, ListCellRenderer listRenderer) { openTargets(e, targets, title, findUsagesTitle, listRenderer, (BackgroundUpdaterTask)null); }
Example #26
Source File: GLSLStructureViewTreeElement.java From glsl4idea with GNU Lesser General Public License v3.0 | 4 votes |
public void navigate(boolean requestFocus) { if (element instanceof NavigatablePsiElement) { ((NavigatablePsiElement) element).navigate(requestFocus); } }
Example #27
Source File: DefaultGutterIconNavigationHandler.java From consulo with Apache License 2.0 | 4 votes |
public Collection<? extends NavigatablePsiElement> getReferences() { return myReferences; }
Example #28
Source File: DefaultGutterIconNavigationHandler.java From consulo with Apache License 2.0 | 4 votes |
public DefaultGutterIconNavigationHandler(Collection<? extends NavigatablePsiElement> references, String title) { myReferences = references; myTitle = title; }
Example #29
Source File: GLSLStructureViewTreeElement.java From glsl4idea with GNU Lesser General Public License v3.0 | 4 votes |
public boolean canNavigate() { return element instanceof NavigatablePsiElement && ((NavigatablePsiElement) element).canNavigate(); }
Example #30
Source File: BuckAddDependencyIntention.java From buck with Apache License 2.0 | 4 votes |
/** * Implementation of {@link * com.intellij.notification.NotificationListener#hyperlinkUpdate(Notification, HyperlinkEvent)}. */ private void hyperlinkActivated( @NotNull Notification notification, @NotNull HyperlinkEvent event) { String href = event.getDescription(); switch (href) { case "editTarget": if (BuckTargetLocator.getInstance(project) .findElementForTarget(editTarget) .filter(target -> target instanceof NavigatablePsiElement) .map(target -> (NavigatablePsiElement) target) .filter(Navigatable::canNavigate) .map( e -> { e.navigate(true); return true; }) .orElse(false)) { break; } // fallthrough case "editBuildFile": FileEditorManager.getInstance(project).openFile(editBuildFile, true); break; case "editSourceFile": FileEditorManager.getInstance(project).openFile(editSourceFile, true); break; case "importTarget": if (BuckTargetLocator.getInstance(project) .findElementForTarget(importTarget) .filter(target -> target instanceof NavigatablePsiElement) .map(target -> (NavigatablePsiElement) target) .filter(Navigatable::canNavigate) .map( e -> { e.navigate(true); return true; }) .orElse(false)) { break; } // fallthrough case "importBuildFile": FileEditorManager.getInstance(project).openFile(importBuildFile, true); break; case "importSourceFile": FileEditorManager.getInstance(project).openFile(importSourceFile, true); break; } }