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);
}
}
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();
}
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;
}
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());
}
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);
}
Aggregations