List of usage examples for com.intellij.openapi.fileEditor OpenFileDescriptor OpenFileDescriptor
public OpenFileDescriptor(@NotNull Project project, @NotNull VirtualFile file, int logicalLine, int logicalColumn)
From source file:com.facebook.buck.intellij.plugin.build.BuckBuildCommandHandler.java
License:Apache License
/** * Parse a line of the buck command output for: * 1. Calculate the progress.// w ww. jav a 2s. co m * 2. Ignore unused lines, for example "Using buckd.". * 3. Print to console window with different colors. * * @return boolean failed or not */ private boolean parseOutputLine(String line) { for (String ignored : IGNORED_OUTPUT_LINES) { if (line.startsWith(ignored)) { return false; } } // Extract the jobs information and calculate the progress. Matcher matcher = BUILD_PROGRESS_PATTERN.matcher(line); if (matcher.matches()) { double finishedJob = Double.parseDouble(matcher.group(1)); double totalJob = Double.parseDouble(matcher.group(2)); BuckBuildManager.getInstance(project()).setProgress(finishedJob / totalJob); return false; } // Red color. for (Pattern errorPattern : ERROR_PATTERNS) { if (errorPattern.matcher(line).lookingAt()) { BuckToolWindowFactory.outputConsoleMessage(project(), line, ConsoleViewContentType.ERROR_OUTPUT); if (currentErrorMessage == null && line.startsWith(ERROR_PREFIX_FOR_MESSAGE)) { currentErrorMessage = line; } return true; } } // Green color. for (String successPrefix : SUCCESS_PREFIXES) { if (line.startsWith(successPrefix)) { BuckToolWindowFactory.outputConsoleMessage(project(), line, GREEN_OUTPUT); return false; } } // Test if it is a java compile error message with a java file path. Matcher compilerErrorMatcher = SOURCE_FILE_PATTERN.matcher(line); if (compilerErrorMatcher.matches()) { final String sourceFile = compilerErrorMatcher.group(1); final String lineNumber = compilerErrorMatcher.group(3); final String errorMessage = compilerErrorMatcher.group(4); String relativePath = sourceFile.replaceAll(project.getBasePath(), ""); final VirtualFile virtualFile = pathToVirtualFile(relativePath); if (virtualFile == null) { BuckToolWindowFactory.outputConsoleMessage(project(), line, ConsoleViewContentType.ERROR_OUTPUT); } else { BuckToolWindowFactory.outputConsoleHyperlink(project(), relativePath + ":" + lineNumber, new HyperlinkInfo() { @Override public void navigate(Project project) { int lineInteger; try { lineInteger = Integer.parseInt(lineNumber) - 1; } catch (NumberFormatException e) { lineInteger = 0; } OpenSourceUtil.navigate(true, new OpenFileDescriptor(project, virtualFile, lineInteger, 0)); } }); BuckToolWindowFactory.outputConsoleMessage(project(), errorMessage, ConsoleViewContentType.ERROR_OUTPUT); } } else { if (!line.trim().isEmpty()) { BuckToolWindowFactory.outputConsoleMessage(project(), line, ConsoleViewContentType.NORMAL_OUTPUT); } } return false; }
From source file:com.google.idea.blaze.clwb.problemsview.BlazeProblemsViewConsole.java
License:Open Source License
@Override public final void addMessage(IssueOutput issue, @NotNull UUID sessionId) { final VirtualFile file = issue.getFile() != null ? VfsUtil.findFileByIoFile(issue.getFile(), true /* refresh */) : null;/*from ww w.ja v a2 s. co m*/ Navigatable navigatable = issue.getNavigatable(); if (navigatable == null && file != null) { // convert 1-indexed line/column numbers to 0-indexed navigatable = new OpenFileDescriptor(myProject, file, issue.getLine() - 1, issue.getColumn() - 1); } final IssueOutput.Category category = issue.getCategory(); final int type = translateCategory(category); final String[] text = convertMessage(issue); final String groupName = file != null ? file.getPresentableUrl() : category.name(); addMessage(type, text, groupName, navigatable, getExportTextPrefix(issue), getRenderTextPrefix(issue), sessionId); }
From source file:com.intellij.compiler.CompilerMessageImpl.java
License:Apache License
@Override public Navigatable getNavigatable() { if (myNavigatable != null) { return myNavigatable; }//from ww w. ja v a2s . co m final VirtualFile virtualFile = getVirtualFile(); if (virtualFile != null && virtualFile.isValid()) { final int line = getLine() - 1; // editor lines are zero-based if (line >= 0) { return myNavigatable = new OpenFileDescriptor(myProject, virtualFile, line, Math.max(0, getColumn() - 1)); } } return null; }
From source file:com.intellij.compiler.ProblemsView.java
License:Apache License
public final void addMessage(CompilerMessage message) { final VirtualFile file = message.getVirtualFile(); Navigatable navigatable = message.getNavigatable(); if (navigatable == null && file != null) { navigatable = new OpenFileDescriptor(myProject, file, -1, -1); }// w w w .ja v a2 s .co m final CompilerMessageCategory category = message.getCategory(); final int type = CompilerTask.translateCategory(category); final String[] text = convertMessage(message.getMessage()); final String groupName = file != null ? file.getPresentableUrl() : category.getPresentableText(); addMessage(type, text, groupName, navigatable, message.getExportTextPrefix(), message.getRenderTextPrefix()); }
From source file:com.intellij.execution.filters.impl.MultipleFilesHyperlinkInfo.java
License:Apache License
@Nullable @Override//www . j a v a 2 s. co m public OpenFileDescriptor getDescriptor() { VirtualFile file = getPreferredFile(); return file != null ? new OpenFileDescriptor(myProject, file, myLineNumber, 0) : null; }
From source file:com.intellij.execution.stacktrace.MethodLineLocation.java
License:Apache License
public OpenFileDescriptor getOpenFileDescriptor() { final VirtualFile virtualFile = getContainingClass().getContainingFile().getVirtualFile(); return new OpenFileDescriptor(getProject(), virtualFile, myLineNumber, 0); }
From source file:com.intellij.ide.actions.GotoClassAction.java
License:Apache License
@Override public void gotoActionPerformed(AnActionEvent e) { final Project project = e.getData(CommonDataKeys.PROJECT); assert project != null; PsiDocumentManager.getInstance(project).commitAllDocuments(); FeatureUsageTracker.getInstance().triggerFeatureUsed("navigation.popup.class"); final GotoClassModel2 model = new GotoClassModel2(project); showNavigationPopup(e, model, new GotoActionCallback<Language>() { @Override// ww w .java 2s. c o m protected ChooseByNameFilter<Language> createFilter(@NotNull ChooseByNamePopup popup) { return new ChooseByNameLanguageFilter(popup, model, GotoClassSymbolConfiguration.getInstance(project), project); } @Override public void elementChosen(ChooseByNamePopup popup, Object element) { AccessToken token = ReadAction.start(); try { if (element instanceof PsiElement) { final PsiElement psiElement = getElement(((PsiElement) element), popup); final VirtualFile file = PsiUtilCore.getVirtualFile(psiElement); if (popup.getLinePosition() != -1 && file != null) { Navigatable n = new OpenFileDescriptor(project, file, popup.getLinePosition(), popup.getColumnPosition()) .setUseCurrentWindow(popup.isOpenInCurrentWindowRequested()); if (n.canNavigate()) { n.navigate(true); return; } } if (psiElement != null && file != null && popup.getMemberPattern() != null) { NavigationUtil.activateFileWithPsiElement(psiElement, !popup.isOpenInCurrentWindowRequested()); Navigatable member = findMember(popup.getMemberPattern(), psiElement, file); if (member != null) { member.navigate(true); } } NavigationUtil.activateFileWithPsiElement(psiElement, !popup.isOpenInCurrentWindowRequested()); } else { EditSourceUtil.navigate(((NavigationItem) element), true, popup.isOpenInCurrentWindowRequested()); } } finally { token.finish(); } } }, "Classes matching pattern", true); }
From source file:com.intellij.ide.actions.GotoFileAction.java
License:Apache License
@Override public void gotoActionPerformed(AnActionEvent e) { FeatureUsageTracker.getInstance().triggerFeatureUsed("navigation.popup.file"); final Project project = e.getData(CommonDataKeys.PROJECT); final GotoFileModel gotoFileModel = new GotoFileModel(project); GotoActionCallback<FileType> callback = new GotoActionCallback<FileType>() { @Override//from ww w . j av a 2 s .com protected ChooseByNameFilter<FileType> createFilter(@NotNull ChooseByNamePopup popup) { return new GotoFileFilter(popup, gotoFileModel, project); } @Override public void elementChosen(final ChooseByNamePopup popup, final Object element) { if (element == null) return; ApplicationManager.getApplication().invokeLater(new Runnable() { @Override public void run() { Navigatable n = (Navigatable) element; //this is for better cursor position if (element instanceof PsiFile) { VirtualFile vfile = ((PsiFile) element).getVirtualFile(); if (vfile == null) return; n = new OpenFileDescriptor(project, vfile, popup.getLinePosition(), popup.getColumnPosition()) .setUseCurrentWindow(popup.isOpenInCurrentWindowRequested()); } if (!n.canNavigate()) return; n.navigate(true); } }, ModalityState.NON_MODAL); } }; PsiElement context = getPsiContext(e); showNavigationPopup(e, gotoFileModel, callback, "Files matching pattern", true, true, new GotoFileItemProvider(project, context)); }
From source file:com.intellij.ide.errorTreeView.ErrorViewStructure.java
License:Apache License
public void addMessage(@NotNull ErrorTreeElementKind kind, @NotNull String[] text, @Nullable VirtualFile underFileGroup, @Nullable VirtualFile file, int line, int column, @Nullable Object data) {/* www. j av a 2 s . com*/ if (underFileGroup != null || file != null) { if (file == null) line = column = -1; final int guiline = line < 0 ? -1 : line + 1; final int guicolumn = column < 0 ? -1 : column + 1; VirtualFile group = underFileGroup != null ? underFileGroup : file; VirtualFile nav = file != null ? file : underFileGroup; addNavigatableMessage(group.getPresentableUrl(), new OpenFileDescriptor(myProject, nav, line, column), kind, text, data, NewErrorTreeViewPanel.createExportPrefix(guiline), NewErrorTreeViewPanel.createRendererPrefix(guiline, guicolumn), group); } else { addSimpleMessage(kind, text, data); } }
From source file:com.intellij.ide.OpenFileXmlRpcHandler.java
License:Apache License
private static boolean doOpen(final String path, final int line, final int column) { ApplicationManager.getApplication().invokeLater(new Runnable() { @Override//ww w. j a v a2 s . co m public void run() { Pair<VirtualFile, Project> data = new File(path).isAbsolute() ? findByAbsolutePath(path) : findByRelativePath(path); if (data == null) return; FileEditorProvider[] providers = FileEditorProviderManager.getInstance().getProviders(data.second, data.first); if (providers.length == 0) return; OpenFileDescriptor descriptor = new OpenFileDescriptor(data.second, data.first, line, column); FileEditorManager.getInstance(data.second).openTextEditor(descriptor, true); } }); return true; }