List of usage examples for com.intellij.openapi.fileEditor OpenFileDescriptor OpenFileDescriptor
public OpenFileDescriptor(@NotNull Project project, @NotNull VirtualFile file, int offset)
From source file:com.intellij.codeInspection.ui.InspectionResultsView.java
License:Apache License
@Nullable private static OpenFileDescriptor getOpenFileDescriptor(final RefElement refElement) { final VirtualFile[] file = new VirtualFile[1]; final int[] offset = new int[1]; ApplicationManager.getApplication().runReadAction(new Runnable() { @Override/* w w w .j av a 2 s.com*/ public void run() { PsiElement psiElement = refElement.getElement(); if (psiElement != null) { final PsiFile containingFile = psiElement.getContainingFile(); if (containingFile != null) { file[0] = containingFile.getVirtualFile(); offset[0] = psiElement.getTextOffset(); } } else { file[0] = null; } } }); if (file[0] != null && file[0].isValid()) { return new OpenFileDescriptor(refElement.getRefManager().getProject(), file[0], offset[0]); } return null; }
From source file:com.intellij.codeInspection.ui.InspectionResultsView.java
License:Apache License
@Nullable private Navigatable getSelectedNavigatable(final CommonProblemDescriptor descriptor, final PsiElement psiElement) { if (descriptor instanceof ProblemDescriptorBase) { Navigatable navigatable = ((ProblemDescriptorBase) descriptor).getNavigatable(); if (navigatable != null) { return navigatable; }//www .j a va 2 s . com } if (psiElement == null || !psiElement.isValid()) return null; PsiFile containingFile = psiElement.getContainingFile(); VirtualFile virtualFile = containingFile == null ? null : containingFile.getVirtualFile(); if (virtualFile != null) { int startOffset = psiElement.getTextOffset(); if (descriptor instanceof ProblemDescriptorBase) { final TextRange textRange = ((ProblemDescriptorBase) descriptor).getTextRangeForNavigation(); if (textRange != null) { if (virtualFile instanceof VirtualFileWindow) { virtualFile = ((VirtualFileWindow) virtualFile).getDelegate(); } startOffset = textRange.getStartOffset(); } } return new OpenFileDescriptor(myProject, virtualFile, startOffset); } return null; }
From source file:com.intellij.diff.contents.FileDocumentContentImpl.java
License:Apache License
@Nullable @Override// w w w . j a va 2 s. c o m public OpenFileDescriptor getOpenFileDescriptor(int offset) { if (myProject == null || myProject.isDefault()) return null; return new OpenFileDescriptor(myProject, myFile, offset); }
From source file:com.intellij.execution.filters.OpenFileHyperlinkInfo.java
License:Apache License
@Override public OpenFileDescriptor getDescriptor() { if (!myFile.isValid()) { return null; }/*w ww. jav a 2 s . co m*/ int line = myDocumentLine; FileDocumentManager.getInstance().getDocument(myFile); // need to load decompiler text LineNumbersMapping mapping = myFile.getUserData(LineNumbersMapping.LINE_NUMBERS_MAPPING_KEY); if (mapping != null) { line = mapping.bytecodeToSource(myDocumentLine + 1) - 1; if (line < 0) { line = myDocumentLine; } } int offset = calculateOffset(myFile, line, myDocumentColumn); if (offset != UNDEFINED_OFFSET) { return new OpenFileDescriptor(myProject, myFile, offset); } // although document position != logical position, it seems better than returning 'null' return new OpenFileDescriptor(myProject, myFile, line, myDocumentColumn); }
From source file:com.intellij.execution.Location.java
License:Apache License
@Nullable public OpenFileDescriptor getOpenFileDescriptor() { VirtualFile virtualFile = getVirtualFile(); if (virtualFile == null) { return null; }/* w ww . j a v a 2 s .c o m*/ return new OpenFileDescriptor(getProject(), virtualFile, getPsiElement().getTextOffset()); }
From source file:com.intellij.execution.testframework.sm.runner.SMTRunnerConsoleProperties.java
License:Apache License
@Nullable protected Navigatable findSuitableNavigatableForLine(@NotNull final Project project, @NotNull final VirtualFile file, final int line) { // lets find first non-ws psi element final Document doc = FileDocumentManager.getInstance().getDocument(file); final PsiFile psi = doc == null ? null : PsiDocumentManager.getInstance(project).getPsiFile(doc); if (psi == null) { return null; }//from w w w.ja v a 2s . c om int offset = doc.getLineStartOffset(line); int endOffset = doc.getLineEndOffset(line); for (int i = offset + 1; i < endOffset; i++) { PsiElement el = psi.findElementAt(i); if (el != null && !(el instanceof PsiWhiteSpace)) { offset = el.getTextOffset(); break; } } return new OpenFileDescriptor(project, file, offset); }
From source file:com.intellij.gwt.i18n.GwtResourceBundleManager.java
License:Apache License
private void addMethod(final PsiClass anInterface, final String key, final PsiExpression[] parameters) throws IncorrectOperationException { PsiFile psiFile = anInterface.getContainingFile(); CodeInsightUtilBase.getInstance().prepareFileForWrite(psiFile); final VirtualFile virtualFile = psiFile.getVirtualFile(); LOG.assertTrue(virtualFile != null); GwtVersion gwtVersion = GwtModuleExtensionUtil.getVersion(anInterface); PsiMethod method = GwtI18nUtil.addMethod(anInterface, key, gwtVersion); if (parameters.length > 0) { TemplateBuilder builder = TemplateBuilderFactory.getInstance().createTemplateBuilder(method); CreateFromUsageUtils.setupMethodParameters(method, builder, parameters[0], PsiSubstitutor.EMPTY, parameters);/*from ww w.j a va2s .c o m*/ method = CodeInsightUtilBase.forcePsiPostprocessAndRestoreElement(method); final OpenFileDescriptor descriptor = new OpenFileDescriptor(myProject, virtualFile, method.getTextRange().getStartOffset()); Document document = PsiDocumentManager.getInstance(myProject).getDocument(psiFile); LOG.assertTrue(document != null); RangeMarker methodRange = document.createRangeMarker(method.getTextRange()); final Editor editor = FileEditorManager.getInstance(myProject).openTextEditor(descriptor, true); final Template template = null;//TODO [VISTALL] TemplateManager.getInstance(myProject).createTemplate() editor.getCaretModel().moveToOffset(methodRange.getStartOffset()); editor.getDocument().deleteString(methodRange.getStartOffset(), methodRange.getEndOffset()); ApplicationManager.getApplication().invokeLater(new Runnable() { @Override public void run() { TemplateManager.getInstance(myProject).startTemplate(editor, template); } }); } }
From source file:com.intellij.ide.hierarchy.HierarchyBrowserBaseEx.java
License:Apache License
public HierarchyBrowserBaseEx(@NotNull Project project, @NotNull PsiElement element) { super(project); setHierarchyBase(element);/*from w w w .j a v a 2 s. c o m*/ myCardLayout = new CardLayout(); myTreePanel = new JPanel(myCardLayout); createTrees(myType2TreeMap); final HierarchyBrowserManager.State state = HierarchyBrowserManager.getInstance(project).getState(); for (String type : myType2TreeMap.keySet()) { myType2ScopeMap.put(type, state.SCOPE != null ? state.SCOPE : SCOPE_ALL); } final Enumeration<String> keys = myType2TreeMap.keys(); while (keys.hasMoreElements()) { final String key = keys.nextElement(); final JTree tree = myType2TreeMap.get(key); myOccurrenceNavigators.put(key, new OccurenceNavigatorSupport(tree) { @Override @Nullable protected Navigatable createDescriptorForNode(DefaultMutableTreeNode node) { final HierarchyNodeDescriptor descriptor = getDescriptor(node); if (descriptor == null) return null; PsiElement psiElement = getOpenFileElementFromDescriptor(descriptor); if (psiElement == null || !psiElement.isValid()) return null; final VirtualFile virtualFile = psiElement.getContainingFile().getVirtualFile(); if (virtualFile == null) return null; return new OpenFileDescriptor(psiElement.getProject(), virtualFile, psiElement.getTextOffset()); } @Override public String getNextOccurenceActionName() { return getNextOccurenceActionNameImpl(); } @Override public String getPreviousOccurenceActionName() { return getPrevOccurenceActionNameImpl(); } }); myTreePanel.add(ScrollPaneFactory.createScrollPane(tree), key); } final JPanel legendPanel = createLegendPanel(); final JPanel contentPanel; if (legendPanel != null) { contentPanel = new JPanel(new BorderLayout()); contentPanel.add(myTreePanel, BorderLayout.CENTER); contentPanel.add(legendPanel, BorderLayout.SOUTH); } else { contentPanel = myTreePanel; } buildUi(createToolbar(getActionPlace(), HELP_ID).getComponent(), contentPanel); }
From source file:com.intellij.ide.impl.SelectInEditorManagerImpl.java
License:Apache License
@Nullable private Editor openEditor(VirtualFile file, int textOffset) { if (file == null || !file.isValid()) { return null; }/*from www . j av a 2 s . c o m*/ OpenFileDescriptor descriptor = new OpenFileDescriptor(myProject, file, textOffset); return FileEditorManager.getInstance(myProject).openTextEditor(descriptor, false); }
From source file:com.intellij.ide.todo.TodoPanel.java
License:Apache License
@Override public Object getData(String dataId) { if (PlatformDataKeys.NAVIGATABLE.is(dataId)) { TreePath path = myTree.getSelectionPath(); if (path == null) { return null; }/*w w w . ja v a2 s .co m*/ DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent(); Object userObject = node.getUserObject(); if (!(userObject instanceof NodeDescriptor)) { return null; } Object element = ((NodeDescriptor) userObject).getElement(); if (!(element instanceof TodoFileNode || element instanceof TodoItemNode)) { // allow user to use F4 only on files an TODOs return null; } TodoItemNode pointer = myTodoTreeBuilder.getFirstPointerForElement(element); if (pointer != null) { return new OpenFileDescriptor(myProject, pointer.getValue().getTodoItem().getFile().getVirtualFile(), pointer.getValue().getRangeMarker().getStartOffset()); } else { return null; } } else if (PlatformDataKeys.VIRTUAL_FILE.is(dataId)) { final PsiFile file = getSelectedFile(); return file != null ? file.getVirtualFile() : null; } else if (LangDataKeys.PSI_ELEMENT.is(dataId)) { return getSelectedElement(); } else if (PlatformDataKeys.VIRTUAL_FILE_ARRAY.is(dataId)) { PsiFile file = getSelectedFile(); if (file != null) { return new VirtualFile[] { file.getVirtualFile() }; } else { return VirtualFile.EMPTY_ARRAY; } } else if (PlatformDataKeys.HELP_ID.is(dataId)) { //noinspection HardCodedStringLiteral return "find.todoList"; } return super.getData(dataId); }