com.intellij.pom.Navigatable Java Examples

The following examples show how to use com.intellij.pom.Navigatable. 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: NavigatableRule.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public Navigatable getData(@Nonnull DataProvider dataProvider) {
  final Navigatable navigatable = dataProvider.getDataUnchecked(PlatformDataKeys.NAVIGATABLE);
  if (navigatable != null && navigatable instanceof OpenFileDescriptor) {
    final OpenFileDescriptor openFileDescriptor = (OpenFileDescriptor)navigatable;

    if (openFileDescriptor.getFile().isValid()) {
      return openFileDescriptor;
    }
  }
  final PsiElement element = dataProvider.getDataUnchecked(LangDataKeys.PSI_ELEMENT);
  if (element instanceof Navigatable) {
    return (Navigatable)element;
  }
  if (element != null) {
    return EditSourceUtil.getDescriptor(element);
  }

  final Object selection = dataProvider.getDataUnchecked(PlatformDataKeys.SELECTED_ITEM);
  if (selection instanceof Navigatable) {
    return (Navigatable)selection;
  }

  return null;
}
 
Example #2
Source File: NewErrorTreeViewPanel.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void addMessage(int type,
                       @Nonnull String[] text,
                       @Nullable String groupName,
                       @Nonnull Navigatable navigatable,
                       @Nullable String exportTextPrefix,
                       @Nullable String rendererTextPrefix,
                       @Nullable Object data) {
  if (myIsDisposed) {
    return;
  }
  VirtualFile file = data instanceof VirtualFile ? (VirtualFile)data : null;
  if (file == null && navigatable instanceof OpenFileDescriptor) {
    file = ((OpenFileDescriptor)navigatable).getFile();
  }
  final String exportPrefix = exportTextPrefix == null ? "" : exportTextPrefix;
  final String renderPrefix = rendererTextPrefix == null ? "" : rendererTextPrefix;
  final ErrorTreeElementKind kind = ErrorTreeElementKind.convertMessageFromCompilerErrorType(type);
  myErrorViewStructure.addNavigatableMessage(groupName, navigatable, kind, text, data, exportPrefix, renderPrefix, file);
  myBuilder.updateTree();
}
 
Example #3
Source File: ProblemsViewImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@RequiredUIAccess
@Override
public void addMessage(final int type,
                       @Nonnull final String[] text,
                       @Nullable final String groupName,
                       @Nullable final Navigatable navigatable,
                       @Nullable final String exportTextPrefix,
                       @Nullable final String rendererTextPrefix) {
  final TempMessage message = new TempMessage(type, text, groupName, navigatable, exportTextPrefix, rendererTextPrefix);

  myTempMessages.add(message);

  final ProblemsViewPanel panel = myPanel;
  if (panel != null) {
    myViewUpdater.execute(new Runnable() {
      @Override
      public void run() {
        addMessage(panel, message);
      }
    });
  }
}
 
Example #4
Source File: OccurenceNavigatorActionBase.java    From consulo with Apache License 2.0 6 votes vote down vote up
public void actionPerformed(AnActionEvent e) {
  Project project = e.getData(CommonDataKeys.PROJECT);
  if (project == null) return;

  OccurenceNavigator navigator = getNavigator(e.getDataContext());
  if (navigator == null) {
    return;
  }
  if (!hasOccurenceToGo(navigator)) {
    return;
  }
  OccurenceNavigator.OccurenceInfo occurenceInfo = go(navigator);
  if (occurenceInfo == null) {
    return;
  }
  Navigatable descriptor = occurenceInfo.getNavigateable();
  if (descriptor != null && descriptor.canNavigate()) {
    descriptor.navigate(false);
  }
  if(occurenceInfo.getOccurenceNumber()==-1||occurenceInfo.getOccurencesCount()==-1){
    return;
  }
  WindowManager.getInstance().getStatusBar(project).setInfo(
    IdeBundle.message("message.occurrence.N.of.M", occurenceInfo.getOccurenceNumber(), occurenceInfo.getOccurencesCount()));
}
 
Example #5
Source File: BaseNavigateToSourceAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
@RequiredUIAccess
@Override
public void update(@Nonnull AnActionEvent e) {
  boolean inPopup = ActionPlaces.isPopupPlace(e.getPlace());
  Navigatable target = findTargetForUpdate(e.getDataContext());
  boolean enabled = target != null;
  if (inPopup && !(this instanceof OpenModuleSettingsAction) && OpenModuleSettingsAction.isModuleInProjectViewPopup(e)) {
    e.getPresentation().setVisible(false);
    return;
  }
  //as myFocusEditor is always ignored - Main Menu|View always contains 2 actions with the same name and actually same behaviour
  e.getPresentation().setVisible((enabled || !inPopup) && (myFocusEditor || !(target instanceof NavigatableWithText)));
  e.getPresentation().setEnabled(enabled);

  String navigateActionText = myFocusEditor && target instanceof NavigatableWithText ? ((NavigatableWithText)target).getNavigateActionText(true) : null;
  e.getPresentation().setText(navigateActionText == null ? getTemplatePresentation().getText() : navigateActionText);
}
 
Example #6
Source File: GotoSuperMethodHandler.java    From consulo-csharp with Apache License 2.0 6 votes vote down vote up
@Override
public void invoke(@Nonnull Project project, @Nonnull Editor editor, @Nonnull PsiFile file)
{
	DotNetVirtualImplementOwner virtualImplementOwner = findVirtualImplementOwner(editor, file);
	if(virtualImplementOwner == null)
	{
		return;
	}

	Collection<DotNetVirtualImplementOwner> collection = OverrideUtil.collectOverridingMembers(virtualImplementOwner);

	for(DotNetVirtualImplementOwner owner : collection)
	{
		if(!(owner instanceof DotNetModifierListOwner && ((DotNetModifierListOwner) owner).hasModifier(DotNetModifier.ABSTRACT)))
		{
			((Navigatable)owner).navigate(true);
			return;
		}
	}
	DotNetVirtualImplementOwner firstItem = ContainerUtil.getFirstItem(collection);
	if(firstItem instanceof Navigatable)
	{
		((Navigatable) firstItem).navigate(true);
	}
}
 
Example #7
Source File: IssueOutput.java    From intellij with Apache License 2.0 6 votes vote down vote up
private IssueOutput(
    @Nullable File file,
    int line,
    int column,
    @Nullable Navigatable navigatable,
    @Nullable TextRange consoleHyperlinkRange,
    Category category,
    String message) {
  this.file = file;
  this.line = line;
  this.column = column;
  this.navigatable = navigatable;
  this.consoleHyperlinkRange = consoleHyperlinkRange;
  this.category = category;
  this.message = message;
}
 
Example #8
Source File: BlazeTypescriptSyncPlugin.java    From intellij with Apache License 2.0 6 votes vote down vote up
private void invalidProjectViewError(
    BlazeContext context, BuildSystemProvider buildSystemProvider) {
  String errorNote =
      "For Typescript support you must add both `additional_languages: typescript`"
          + " and the `ts_config_rules` attribute.";
  String documentationUrl =
      buildSystemProvider.getLanguageSupportDocumentationUrl("dynamic-languages-typescript");
  Navigatable navigatable = null;
  if (documentationUrl != null) {
    errorNote += " Click to open the relevant docs.";
    navigatable =
        new NavigatableAdapter() {
          @Override
          public void navigate(boolean requestFocus) {
            BrowserLauncher.getInstance().open(documentationUrl);
          }
        };
  }
  IssueOutput.error(errorNote).navigatable(navigatable).submit(context);
}
 
Example #9
Source File: IssueOutputFilter.java    From intellij with Apache License 2.0 6 votes vote down vote up
private Navigatable openConsoleToHyperlink(HyperlinkInfo link, int originalOffset) {
  return new Navigatable() {
    @Override
    public void navigate(boolean requestFocus) {
      BlazeConsoleView consoleView = BlazeConsoleView.getInstance(project);
      ToolWindow toolWindow =
          ToolWindowManager.getInstance(project).getToolWindow(BlazeConsoleToolWindowFactory.ID);
      toolWindow.activate(() -> consoleView.navigateToHyperlink(link, originalOffset), true);
    }

    @Override
    public boolean canNavigate() {
      return true;
    }

    @Override
    public boolean canNavigateToSource() {
      return true;
    }
  };
}
 
Example #10
Source File: CommonHelper.java    From yiistorm with MIT License 6 votes vote down vote up
public static PsiElement getFileByClass(String actionClass, Project project) {
    if (actionClass != null) {
        List<PsiElement> elements = PsiPhpHelper.getPsiElementsFromClassName(actionClass, project);
        if (elements.size() > 0) {
            PsiElement element = elements.get(0);
            PsiElement navElement = element.getNavigationElement();
            navElement = TargetElementUtilBase.getInstance().getGotoDeclarationTarget(element, navElement);
            if (navElement instanceof Navigatable) {
                if (((Navigatable) navElement).canNavigate()) {
                    ((Navigatable) navElement).navigate(true);
                }
            } else if (navElement != null) {
                int navOffset = navElement.getTextOffset();
                VirtualFile virtualFile = PsiUtilCore.getVirtualFile(navElement);
                if (virtualFile != null) {
                    new OpenFileDescriptor(project, virtualFile, navOffset).navigate(true);
                }
            }
        }
    }
    return null;
}
 
Example #11
Source File: IdeHelper.java    From yiistorm with MIT License 6 votes vote down vote up
public static void navigateToPsiElement(PsiElement psiElement) {
    Project project = psiElement.getProject();
    PsiElement navElement = psiElement.getNavigationElement();
    navElement = TargetElementUtilBase.getInstance().getGotoDeclarationTarget(psiElement, navElement);
    if (navElement instanceof Navigatable) {
        if (((Navigatable) navElement).canNavigate()) {
            ((Navigatable) navElement).navigate(true);
        }
    } else if (navElement != null) {
        int navOffset = navElement.getTextOffset();
        VirtualFile virtualFile = PsiUtilCore.getVirtualFile(navElement);
        if (virtualFile != null) {
            new OpenFileDescriptor(project, virtualFile, navOffset).navigate(true);
        }
    }
}
 
Example #12
Source File: AbstractProjectViewPane.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public Object getData(@Nonnull Key<?> dataId) {
  Object data = myTreeStructure instanceof AbstractTreeStructureBase ? ((AbstractTreeStructureBase)myTreeStructure).getDataFromProviders(getSelectedNodes(AbstractTreeNode.class), dataId) : null;
  if (data != null) {
    return data;
  }
  if (CommonDataKeys.NAVIGATABLE_ARRAY == dataId) {
    TreePath[] paths = getSelectionPaths();
    if (paths == null) return null;
    final ArrayList<Navigatable> navigatables = new ArrayList<>();
    for (TreePath path : paths) {
      Object node = path.getLastPathComponent();
      Object userObject = TreeUtil.getUserObject(node);
      if (userObject instanceof Navigatable) {
        navigatables.add((Navigatable)userObject);
      }
      else if (node instanceof Navigatable) {
        navigatables.add((Navigatable)node);
      }
    }
    return navigatables.isEmpty() ? null : navigatables.toArray(new Navigatable[0]);
  }
  return null;
}
 
Example #13
Source File: NavBarPanel.java    From consulo with Apache License 2.0 6 votes vote down vote up
protected void doubleClick(final Object object) {
  if (object instanceof Navigatable) {
    Navigatable navigatable = (Navigatable)object;
    if (navigatable.canNavigate()) {
      navigatable.navigate(true);
    }
  }
  else if (object instanceof Module) {
    ProjectView projectView = ProjectView.getInstance(myProject);
    AbstractProjectViewPane projectViewPane = projectView.getProjectViewPaneById(projectView.getCurrentViewId());
    if (projectViewPane != null) {
      projectViewPane.selectModule((Module)object, true);
    }
  }
  else if (object instanceof Project) {
    return;
  }
  hideHint(true);
}
 
Example #14
Source File: NavBarIdeView.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void selectElement(PsiElement element) {
  myPanel.getModel().updateModel(element, null);

  if (element instanceof Navigatable) {
    final Navigatable navigatable = (Navigatable)element;
    if (navigatable.canNavigate()) {
      ((Navigatable)element).navigate(true);
    }
  }
  myPanel.hideHint();
}
 
Example #15
Source File: PsiTreeElementBase.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void navigate(boolean requestFocus) {
  T element = getElement();
  if (element != null) {
    ((Navigatable)element).navigate(requestFocus);
  }
}
 
Example #16
Source File: TwosideDiffViewer.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
protected Navigatable getNavigatable() {
  Navigatable navigatable1 = getCurrentSide().select(getRequest().getContents()).getNavigatable();
  if (navigatable1 != null) return navigatable1;
  return getCurrentSide().other().select(getRequest().getContents()).getNavigatable();
}
 
Example #17
Source File: OpenInEditorAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void update(@Nonnull AnActionEvent e) {
  if (!e.isFromActionToolbar()) {
    e.getPresentation().setEnabledAndVisible(true);
    return;
  }

  DiffRequest request = e.getData(DiffDataKeys.DIFF_REQUEST);
  DiffContext context = e.getData(DiffDataKeys.DIFF_CONTEXT);

  if (DiffUtil.isUserDataFlagSet(DiffUserDataKeys.GO_TO_SOURCE_DISABLE, request, context)) {
    e.getPresentation().setVisible(false);
    e.getPresentation().setEnabled(false);
  }

  if (e.getProject() == null) {
    e.getPresentation().setVisible(true);
    e.getPresentation().setEnabled(false);
    return;
  }

  Navigatable[] navigatables = e.getData(DiffDataKeys.NAVIGATABLE_ARRAY);
  if (navigatables == null || !ContainerUtil.exists(navigatables, Navigatable::canNavigate)) {
    e.getPresentation().setVisible(true);
    e.getPresentation().setEnabled(false);
    return;
  }

  e.getPresentation().setEnabledAndVisible(true);
}
 
Example #18
Source File: DiffNavigatableArrayRule.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public Navigatable[] getData(@Nonnull DataProvider dataProvider) {
  final Navigatable element = dataProvider.getDataUnchecked(DiffDataKeys.NAVIGATABLE);
  if (element == null) {
    return null;
  }

  return new Navigatable[]{element};
}
 
Example #19
Source File: NavigatableMessageElement.java    From consulo with Apache License 2.0 5 votes vote down vote up
public NavigatableMessageElement(@Nonnull ErrorTreeElementKind kind,
                                 @Nullable GroupingElement parent,
                                 String[] message,
                                 Navigatable navigatable,
                                 String exportText,
                                 String rendererTextPrefix) {
  super(kind);
  myParent = parent;
  myMessage = message;
  myNavigatable = navigatable;
  myExportText = exportText;
  myRendererTextPrefix = rendererTextPrefix;
}
 
Example #20
Source File: CommanderPanel.java    From consulo with Apache License 2.0 5 votes vote down vote up
private Navigatable[] getNavigatables() {
  if (myBuilder == null) return null;
  final int[] indices = myList.getSelectedIndices();
  if (indices == null || indices.length == 0) return null;

  final ArrayList<Navigatable> elements = new ArrayList<>();
  for (int index : indices) {
    final Object element = myModel.getElementAt(index);
    if (element instanceof AbstractTreeNode) {
      elements.add((Navigatable)element);
    }
  }

  return elements.toArray(new Navigatable[elements.size()]);
}
 
Example #21
Source File: CSharpLightTypeDeclarationBuilder.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Override
public void navigate(boolean requestFocus)
{
	PsiElement navigationElement = getNavigationElement();
	if(navigationElement instanceof Navigatable)
	{
		((Navigatable) navigationElement).navigate(requestFocus);
		return;
	}

	super.navigate(requestFocus);
}
 
Example #22
Source File: ConstructorInjectToProvidesHandler.java    From dagger-intellij-plugin with Apache License 2.0 5 votes vote down vote up
private boolean navigateToElement(PsiElement element) {
  PsiElement navigationElement = element.getNavigationElement();
  if (navigationElement != null && navigationElement instanceof Navigatable &&
          ((Navigatable) navigationElement).canNavigate()) {
    ((Navigatable) navigationElement).navigate(true);
    return true;
  }
  return false;
}
 
Example #23
Source File: DocumentFragmentContent.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public Navigatable getNavigatable(@Nonnull LineCol position) {
  if (!myRangeMarker.isValid()) return null;
  int offset = position.toOffset(getDocument());
  int originalOffset = offset + myRangeMarker.getStartOffset();
  LineCol originalPosition = LineCol.fromOffset(myOriginal.getDocument(), originalOffset);
  return myOriginal.getNavigatable(originalPosition);
}
 
Example #24
Source File: FileStructureDialog.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public Object getData(@Nonnull Key dataId) {
  Object selectedElement = myCommanderPanel.getSelectedValue();

  if (selectedElement instanceof TreeElement) selectedElement = ((StructureViewTreeElement)selectedElement).getValue();

  if (PlatformDataKeys.NAVIGATABLE == dataId) {
    return selectedElement instanceof Navigatable ? selectedElement : myNavigatable;
  }

  if (OpenFileDescriptor.NAVIGATE_IN_EDITOR == dataId) return myEditor;

  return getDataImpl(dataId);
}
 
Example #25
Source File: HierarchyBrowserBase.java    From consulo with Apache License 2.0 5 votes vote down vote up
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 #26
Source File: StructureViewComponent.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public Object getData(@Nonnull Key dataId) {
  if (CommonDataKeys.PSI_ELEMENT == dataId) {
    PsiElement element = getSelectedValues().filter(PsiElement.class).single();
    return element != null && element.isValid() ? element : null;
  }
  if (LangDataKeys.PSI_ELEMENT_ARRAY == dataId) {
    return PsiUtilCore.toPsiElementArray(getSelectedValues().filter(PsiElement.class).toList());
  }
  if (PlatformDataKeys.FILE_EDITOR == dataId) {
    return myFileEditor;
  }
  if (PlatformDataKeys.CUT_PROVIDER == dataId) {
    return myCopyPasteDelegator.getCutProvider();
  }
  if (PlatformDataKeys.COPY_PROVIDER == dataId) {
    return myCopyPasteDelegator.getCopyProvider();
  }
  if (PlatformDataKeys.PASTE_PROVIDER == dataId) {
    return myCopyPasteDelegator.getPasteProvider();
  }
  if (CommonDataKeys.NAVIGATABLE == dataId) {
    List<Object> list = JBIterable.of(getTree().getSelectionPaths()).map(TreePath::getLastPathComponent).map(StructureViewComponent::unwrapNavigatable).toList();
    Object[] selectedElements = list.isEmpty() ? null : ArrayUtil.toObjectArray(list);
    if (selectedElements == null || selectedElements.length == 0) return null;
    if (selectedElements[0] instanceof Navigatable) {
      return selectedElements[0];
    }
  }
  if (PlatformDataKeys.HELP_ID == dataId) {
    return getHelpID();
  }
  if (CommonDataKeys.PROJECT == dataId) {
    return myProject;
  }
  return super.getData(dataId);
}
 
Example #27
Source File: CompileContextImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void addMessage(CompilerMessageCategory category,
                       String message,
                       String url,
                       int lineNum,
                       int columnNum,
                       Navigatable navigatable) {
  CompilerMessageImpl msg =
          new CompilerMessageImpl(myProject, category, message, findPresentableFileForMessage(url), lineNum, columnNum, navigatable);
  addMessage(msg);
}
 
Example #28
Source File: CSharpPreprocessorLightVariable.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Override
public void navigate(boolean requestFocus)
{
	if(myModule == null)
	{
		((Navigatable) myTarget).navigate(requestFocus);
	}
	else
	{
		ProjectSettingsService.getInstance(getProject()).openContentEntriesSettings(myModule);
	}
}
 
Example #29
Source File: AndroidSymbolContributor.java    From idea-android-studio-plugin with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void navigate(boolean requestFocus) {
    final Navigatable descriptor = PsiNavigationSupport.getInstance().getDescriptor(this.psiElement);
    if (descriptor != null) {
        descriptor.navigate(requestFocus);
    }
}
 
Example #30
Source File: FileStructureDialog.java    From consulo with Apache License 2.0 5 votes vote down vote up
public FileStructureDialog(StructureViewModel structureViewModel,
                           @Nullable Editor editor,
                           Project project,
                           Navigatable navigatable,
                           @Nonnull final Disposable auxDisposable,
                           final boolean applySortAndFilter) {
  super(project, true);
  myProject = project;
  myEditor = editor;
  myNavigatable = navigatable;
  myBaseTreeModel = structureViewModel;
  if (applySortAndFilter) {
    myTreeActionsOwner = new TreeStructureActionsOwner(myBaseTreeModel);
    myTreeModel = new TreeModelWrapper(structureViewModel, myTreeActionsOwner);
  }
  else {
    myTreeActionsOwner = null;
    myTreeModel = structureViewModel;
  }

  PsiFile psiFile = getPsiFile(project);

  final PsiElement psiElement = getCurrentElement(psiFile);

  //myDialog.setUndecorated(true);
  init();

  if (psiElement != null) {
    if (structureViewModel.shouldEnterElement(psiElement)) {
      myCommanderPanel.getBuilder().enterElement(psiElement, PsiUtilBase.getVirtualFile(psiElement));
    }
    else {
      myCommanderPanel.getBuilder().selectElement(psiElement, PsiUtilBase.getVirtualFile(psiElement));
    }
  }

  Disposer.register(myDisposable, auxDisposable);
}