Search in sources :

Example 61 with Navigatable

use of com.intellij.pom.Navigatable in project intellij-community by JetBrains.

the class AntCreateTargetFix method applyFix.

public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
    final PsiElement psiElement = descriptor.getPsiElement();
    final PsiFile containingFile = psiElement.getContainingFile();
    Navigatable result = null;
    if (containingFile instanceof XmlFile) {
        final XmlFile xmlFile = (XmlFile) containingFile;
        final XmlTag rootTag = xmlFile.getRootTag();
        if (rootTag != null) {
            final XmlTag propTag = rootTag.createChildTag(TAG_NAME, rootTag.getNamespace(), "", false);
            propTag.setAttribute(NAME_ATTR, myCanonicalText);
            final DomElement contextElement = DomUtil.getDomElement(descriptor.getPsiElement());
            PsiElement generated;
            if (contextElement == null) {
                generated = rootTag.addSubTag(propTag, true);
            } else {
                final AntDomTarget containingTarget = contextElement.getParentOfType(AntDomTarget.class, false);
                final DomElement anchor = containingTarget != null ? containingTarget : contextElement;
                final XmlTag tag = anchor.getXmlTag();
                if (!rootTag.equals(tag)) {
                    generated = tag.getParent().addBefore(propTag, tag);
                } else {
                    generated = rootTag.addSubTag(propTag, true);
                }
            }
            if (generated instanceof XmlTag) {
                result = new OpenFileDescriptor(project, containingFile.getVirtualFile(), ((XmlTag) generated).getValue().getTextRange().getEndOffset());
            }
            if (result == null && generated instanceof Navigatable) {
                result = (Navigatable) generated;
            }
        }
    }
    if (result != null) {
        result.navigate(true);
    }
}
Also used : DomElement(com.intellij.util.xml.DomElement) XmlFile(com.intellij.psi.xml.XmlFile) PsiFile(com.intellij.psi.PsiFile) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) AntDomTarget(com.intellij.lang.ant.dom.AntDomTarget) PsiElement(com.intellij.psi.PsiElement) Navigatable(com.intellij.pom.Navigatable) XmlTag(com.intellij.psi.xml.XmlTag)

Example 62 with Navigatable

use of com.intellij.pom.Navigatable in project intellij-community by JetBrains.

the class NavBarIdeView method selectElement.

@Override
public void selectElement(PsiElement element) {
    myPanel.getModel().updateModel(element);
    if (element instanceof Navigatable) {
        final Navigatable navigatable = (Navigatable) element;
        if (navigatable.canNavigate()) {
            ((Navigatable) element).navigate(true);
        }
    }
    myPanel.hideHint();
}
Also used : Navigatable(com.intellij.pom.Navigatable)

Example 63 with Navigatable

use of com.intellij.pom.Navigatable in project intellij-community by JetBrains.

the class NavBarPanel method getData.

@Override
@Nullable
public Object getData(String dataId) {
    if (CommonDataKeys.PROJECT.is(dataId)) {
        return !myProject.isDisposed() ? myProject : null;
    }
    if (LangDataKeys.MODULE.is(dataId)) {
        final Module module = getSelectedElement(Module.class);
        if (module != null && !module.isDisposed())
            return module;
        final PsiElement element = getSelectedElement(PsiElement.class);
        if (element != null) {
            return ModuleUtilCore.findModuleForPsiElement(element);
        }
        return null;
    }
    if (LangDataKeys.MODULE_CONTEXT.is(dataId)) {
        final PsiDirectory directory = getSelectedElement(PsiDirectory.class);
        if (directory != null) {
            final VirtualFile dir = directory.getVirtualFile();
            if (ProjectRootsUtil.isModuleContentRoot(dir, myProject)) {
                return ModuleUtilCore.findModuleForPsiElement(directory);
            }
        }
        return null;
    }
    if (CommonDataKeys.PSI_ELEMENT.is(dataId)) {
        final PsiElement element = getSelectedElement(PsiElement.class);
        return element != null && element.isValid() ? element : null;
    }
    if (LangDataKeys.PSI_ELEMENT_ARRAY.is(dataId)) {
        final List<PsiElement> elements = getSelectedElements(PsiElement.class);
        if (elements == null || elements.isEmpty())
            return null;
        List<PsiElement> result = new ArrayList<>();
        for (PsiElement element : elements) {
            if (element != null && element.isValid()) {
                result.add(element);
            }
        }
        return result.isEmpty() ? null : result.toArray(new PsiElement[result.size()]);
    }
    if (CommonDataKeys.VIRTUAL_FILE_ARRAY.is(dataId)) {
        PsiElement[] psiElements = (PsiElement[]) getData(LangDataKeys.PSI_ELEMENT_ARRAY.getName());
        if (psiElements == null)
            return null;
        Set<VirtualFile> files = new LinkedHashSet<>();
        for (PsiElement element : psiElements) {
            PsiFile file = element.getContainingFile();
            if (file != null) {
                final VirtualFile virtualFile = file.getVirtualFile();
                if (virtualFile != null) {
                    files.add(virtualFile);
                }
            } else if (element instanceof PsiFileSystemItem) {
                files.add(((PsiFileSystemItem) element).getVirtualFile());
            }
        }
        return !files.isEmpty() ? VfsUtilCore.toVirtualFileArray(files) : null;
    }
    if (CommonDataKeys.NAVIGATABLE_ARRAY.is(dataId)) {
        final List<Navigatable> elements = getSelectedElements(Navigatable.class);
        return elements == null || elements.isEmpty() ? null : elements.toArray(new Navigatable[elements.size()]);
    }
    if (PlatformDataKeys.CONTEXT_COMPONENT.is(dataId)) {
        return this;
    }
    if (PlatformDataKeys.CUT_PROVIDER.is(dataId)) {
        return myCopyPasteDelegator.getCutProvider();
    }
    if (PlatformDataKeys.COPY_PROVIDER.is(dataId)) {
        return myCopyPasteDelegator.getCopyProvider();
    }
    if (PlatformDataKeys.PASTE_PROVIDER.is(dataId)) {
        return myCopyPasteDelegator.getPasteProvider();
    }
    if (PlatformDataKeys.DELETE_ELEMENT_PROVIDER.is(dataId)) {
        return getSelectedElement(Module.class) != null ? myDeleteModuleProvider : new DeleteHandler.DefaultDeleteProvider();
    }
    if (LangDataKeys.IDE_VIEW.is(dataId)) {
        return myIdeView;
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) DeleteHandler(com.intellij.ide.util.DeleteHandler) PsiFileSystemItem(com.intellij.psi.PsiFileSystemItem) Navigatable(com.intellij.pom.Navigatable) PsiDirectory(com.intellij.psi.PsiDirectory) PsiFile(com.intellij.psi.PsiFile) Module(com.intellij.openapi.module.Module) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 64 with Navigatable

use of com.intellij.pom.Navigatable in project intellij-community by JetBrains.

the class JUnitOpenSourceAtExceptionTest method testStackTraceParseerAcceptsJavaStacktrace.

public void testStackTraceParseerAcceptsJavaStacktrace() throws Exception {
    myFixture.addClass("abstract class ATest extends junit.framework.TestCase {" + "  public void testMe() {\n" + "    int i = 0;\n" + "    int j = 0;\n" + "    int k = 0;\n" + "    fail();\n" + "  }\n" + "}");
    myFixture.addClass("public class ChildTest extends ATest {}");
    final SMTestProxy testProxy = new SMTestProxy("testMe", false, "java:test://ChildTest.testMe");
    testProxy.setTestFailed("failure", "\tat junit.framework.Assert.fail(Assert.java:57)\n" + "\tat junit.framework.Assert.failNotEquals(Assert.java:329)\n" + "\tat junit.framework.Assert.assertEquals(Assert.java:78)\n" + "\tat junit.framework.Assert.assertEquals(Assert.java:234)\n" + "\tat junit.framework.Assert.assertEquals(Assert.java:241)\n" + "\tat junit.framework.TestCase.assertEquals(TestCase.java:409)\n" + "\tat ATest.testMe(Dummy.java:6)\n", true);
    final Project project = getProject();
    final GlobalSearchScope searchScope = GlobalSearchScope.projectScope(project);
    testProxy.setLocator(JavaTestLocator.INSTANCE);
    final Location location = testProxy.getLocation(project, searchScope);
    assertNotNull(location);
    assertInstanceOf(location, MethodLocation.class);
    final JUnitConfiguration configuration = new JUnitConfiguration("p", getProject(), JUnitConfigurationType.getInstance().getConfigurationFactories()[0]);
    final Navigatable descriptor = testProxy.getDescriptor(location, new JUnitConsoleProperties(configuration, DefaultRunExecutor.getRunExecutorInstance()));
    assertInstanceOf(descriptor, OpenFileDescriptor.class);
    final OpenFileDescriptor fileDescriptor = (OpenFileDescriptor) descriptor;
    final VirtualFile file = fileDescriptor.getFile();
    assertNotNull(file);
    assertEquals(5, fileDescriptor.getLine());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) SMTestProxy(com.intellij.execution.testframework.sm.runner.SMTestProxy) Project(com.intellij.openapi.project.Project) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) JUnitConsoleProperties(com.intellij.execution.junit2.ui.properties.JUnitConsoleProperties) MethodLocation(com.intellij.execution.junit2.info.MethodLocation) Location(com.intellij.execution.Location) Navigatable(com.intellij.pom.Navigatable)

Example 65 with Navigatable

use of com.intellij.pom.Navigatable in project intellij-community by JetBrains.

the class SearchEverywhereAction method doNavigate.

private void doNavigate(final int index) {
    final DataManager dataManager = DataManager.getInstance();
    if (dataManager == null)
        return;
    final Project project = CommonDataKeys.PROJECT.getData(dataManager.getDataContext(getField().getTextEditor()));
    assert project != null;
    final SearchListModel model = getModel();
    if (isMoreItem(index)) {
        final String pattern = myPopupField.getText();
        WidgetID wid = null;
        if (index == model.moreIndex.classes)
            wid = WidgetID.CLASSES;
        else if (index == model.moreIndex.files)
            wid = WidgetID.FILES;
        else if (index == model.moreIndex.settings)
            wid = WidgetID.SETTINGS;
        else if (index == model.moreIndex.actions)
            wid = WidgetID.ACTIONS;
        else if (index == model.moreIndex.symbols)
            wid = WidgetID.SYMBOLS;
        else if (index == model.moreIndex.runConfigurations)
            wid = WidgetID.RUN_CONFIGURATIONS;
        if (wid != null) {
            final WidgetID widgetID = wid;
            myCurrentWorker.doWhenProcessed(() -> {
                myCalcThread = new CalcThread(project, pattern, true);
                myPopupActualWidth = 0;
                myCurrentWorker = myCalcThread.insert(index, widgetID);
            });
            return;
        }
    }
    final String pattern = getField().getText();
    final Object value = myList.getSelectedValue();
    saveHistory(project, pattern, value);
    IdeFocusManager focusManager = IdeFocusManager.findInstanceByComponent(getField().getTextEditor());
    if (myPopup != null && myPopup.isVisible()) {
        myPopup.cancel();
    }
    if (value instanceof BooleanOptionDescription) {
        final BooleanOptionDescription option = (BooleanOptionDescription) value;
        option.setOptionState(!option.isOptionEnabled());
        myList.revalidate();
        myList.repaint();
        getGlobalInstance().doWhenFocusSettlesDown(() -> {
            getGlobalInstance().requestFocus(getField(), true);
        });
        return;
    }
    if (value instanceof OptionsTopHitProvider) {
        //noinspection SSBasedInspection
        SwingUtilities.invokeLater(() -> getField().setText("#" + ((OptionsTopHitProvider) value).getId() + " "));
        return;
    }
    Runnable onDone = null;
    AccessToken token = ApplicationManager.getApplication().acquireReadActionLock();
    try {
        if (value instanceof PsiElement) {
            onDone = () -> NavigationUtil.activateFileWithPsiElement((PsiElement) value, true);
            return;
        } else if (isVirtualFile(value)) {
            onDone = () -> OpenSourceUtil.navigate(true, new OpenFileDescriptor(project, (VirtualFile) value));
            return;
        } else if (isActionValue(value) || isSetting(value) || isRunConfiguration(value)) {
            focusManager.requestDefaultFocus(true);
            final Component comp = myContextComponent;
            final AnActionEvent event = myActionEvent;
            IdeFocusManager.getInstance(project).doWhenFocusSettlesDown(() -> {
                Component c = comp;
                if (c == null) {
                    c = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
                }
                if (isRunConfiguration(value)) {
                    ChooseRunConfigurationPopup.ItemWrapper itemWrapper = (ChooseRunConfigurationPopup.ItemWrapper) value;
                    RunnerAndConfigurationSettings settings = ObjectUtils.tryCast(itemWrapper.getValue(), RunnerAndConfigurationSettings.class);
                    if (settings != null) {
                        Executor executor = findExecutor(settings);
                        if (executor != null) {
                            itemWrapper.perform(project, executor, dataManager.getDataContext(c));
                        }
                    }
                } else {
                    GotoActionAction.openOptionOrPerformAction(value, pattern, project, c, event);
                    if (isToolWindowAction(value))
                        return;
                }
            });
            return;
        } else if (value instanceof Navigatable) {
            onDone = () -> OpenSourceUtil.navigate(true, (Navigatable) value);
            return;
        }
    } finally {
        token.finish();
        final ActionCallback callback = onFocusLost();
        if (onDone != null) {
            callback.doWhenDone(onDone);
        }
    }
    focusManager.requestDefaultFocus(true);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) DataManager(com.intellij.ide.DataManager) Navigatable(com.intellij.pom.Navigatable) Project(com.intellij.openapi.project.Project) DefaultRunExecutor(com.intellij.execution.executors.DefaultRunExecutor) Executor(com.intellij.execution.Executor) AccessToken(com.intellij.openapi.application.AccessToken) BooleanOptionDescription(com.intellij.ide.ui.search.BooleanOptionDescription) ChooseRunConfigurationPopup(com.intellij.execution.actions.ChooseRunConfigurationPopup) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) OptionsTopHitProvider(com.intellij.ide.ui.OptionsTopHitProvider) PropertiesComponent(com.intellij.ide.util.PropertiesComponent)

Aggregations

Navigatable (com.intellij.pom.Navigatable)70 VirtualFile (com.intellij.openapi.vfs.VirtualFile)22 OpenFileDescriptor (com.intellij.openapi.fileEditor.OpenFileDescriptor)19 Project (com.intellij.openapi.project.Project)14 Nullable (org.jetbrains.annotations.Nullable)14 PsiElement (com.intellij.psi.PsiElement)11 ArrayList (java.util.ArrayList)9 PsiFile (com.intellij.psi.PsiFile)7 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)7 TreePath (javax.swing.tree.TreePath)7 NotNull (org.jetbrains.annotations.NotNull)6 Editor (com.intellij.openapi.editor.Editor)4 List (java.util.List)4 TextRange (com.intellij.openapi.util.TextRange)3 XmlTag (com.intellij.psi.xml.XmlTag)3 BlazeConsoleView (com.google.idea.blaze.base.console.BlazeConsoleView)2 IssueOutput (com.google.idea.blaze.base.scope.output.IssueOutput)2 DataContext (com.intellij.openapi.actionSystem.DataContext)2 Logger (com.intellij.openapi.diagnostic.Logger)2 Document (com.intellij.openapi.editor.Document)2