Search in sources :

Example 31 with Attachment

use of com.intellij.openapi.diagnostic.Attachment in project intellij-community by JetBrains.

the class GrCastFix method findExpressionToCast.

private static GrExpression findExpressionToCast(ProblemDescriptor descriptor) {
    final PsiElement element = descriptor.getPsiElement();
    final PsiElement parent = element.getParent();
    if (parent instanceof GrVariable) {
        return ((GrVariable) parent).getInitializerGroovy();
    } else if (parent instanceof GrAssignmentExpression) {
        return ((GrAssignmentExpression) parent).getRValue();
    } else if (parent instanceof GrThrowStatement) {
        return ((GrThrowStatement) parent).getException();
    } else if (parent instanceof GrReturnStatement) {
        return ((GrReturnStatement) parent).getReturnValue();
    } else if (element instanceof GrExpression) {
        return (GrExpression) element;
    }
    PsiFile file = element.getContainingFile();
    VirtualFile virtualFile = file.getVirtualFile();
    String url = virtualFile == null ? "" : virtualFile.getPresentableUrl();
    LOG.error("can't find expression to cast at position " + element.getTextRange(), new Attachment(url, file.getText()));
    return null;
}
Also used : GrVariable(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable) VirtualFile(com.intellij.openapi.vfs.VirtualFile) GrAssignmentExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrAssignmentExpression) GrThrowStatement(org.jetbrains.plugins.groovy.lang.psi.api.statements.branch.GrThrowStatement) GrExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression) PsiFile(com.intellij.psi.PsiFile) Attachment(com.intellij.openapi.diagnostic.Attachment) GrReturnStatement(org.jetbrains.plugins.groovy.lang.psi.api.statements.branch.GrReturnStatement) PsiElement(com.intellij.psi.PsiElement)

Example 32 with Attachment

use of com.intellij.openapi.diagnostic.Attachment in project intellij-community by JetBrains.

the class VcsInitialization method waitForCompletion.

void waitForCompletion() {
    LOG.debug("waitForCompletion() status=" + myStatus);
    // have to wait for task completion to avoid running it in background for closed project
    long start = System.currentTimeMillis();
    Status status = null;
    while (System.currentTimeMillis() < start + 10000) {
        synchronized (myLock) {
            if ((status = myStatus) != Status.RUNNING) {
                break;
            }
        }
        TimeoutUtil.sleep(10);
    }
    if (status == Status.RUNNING) {
        LOG.error("Failed to wait for completion of VCS initialization for project " + myProject, new Attachment("thread dump", ThreadDumper.dumpThreadsToString()));
    }
}
Also used : Attachment(com.intellij.openapi.diagnostic.Attachment)

Example 33 with Attachment

use of com.intellij.openapi.diagnostic.Attachment in project intellij-community by JetBrains.

the class ExportTestResultsAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    final Project project = e.getProject();
    LOG.assertTrue(project != null);
    final ExportTestResultsConfiguration config = ExportTestResultsConfiguration.getInstance(project);
    final String name = ExecutionBundle.message("export.test.results.filename", PathUtil.suggestFileName(myRunConfiguration.getName()));
    String filename = name + "." + config.getExportFormat().getDefaultExtension();
    boolean showDialog = true;
    while (showDialog) {
        final ExportTestResultsDialog d = new ExportTestResultsDialog(project, config, filename);
        if (!d.showAndGet()) {
            return;
        }
        filename = d.getFileName();
        showDialog = getOutputFile(config, project, filename).exists() && Messages.showOkCancelDialog(project, ExecutionBundle.message("export.test.results.file.exists.message", filename), ExecutionBundle.message("export.test.results.file.exists.title"), Messages.getQuestionIcon()) != Messages.OK;
    }
    final String filename_ = filename;
    ProgressManager.getInstance().run(new Task.Backgroundable(project, ExecutionBundle.message("export.test.results.task.name"), false, new PerformInBackgroundOption() {

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

        @Override
        public void processSentToBackground() {
        }
    }) {

        @Override
        public void run(@NotNull ProgressIndicator indicator) {
            indicator.setIndeterminate(true);
            final File outputFile = getOutputFile(config, project, filename_);
            final String outputText;
            try {
                outputText = getOutputText(config);
                if (outputText == null) {
                    return;
                }
            } catch (IOException | SAXException | TransformerException ex) {
                LOG.warn(ex);
                showBalloon(project, MessageType.ERROR, ExecutionBundle.message("export.test.results.failed", ex.getMessage()), null);
                return;
            } catch (RuntimeException ex) {
                ExportTestResultsConfiguration c = new ExportTestResultsConfiguration();
                c.setExportFormat(ExportTestResultsConfiguration.ExportFormat.Xml);
                c.setOpenResults(false);
                try {
                    String xml = getOutputText(c);
                    LOG.error(LogMessageEx.createEvent("Failed to export test results", ExceptionUtil.getThrowableText(ex), null, null, new Attachment("dump.xml", xml)));
                } catch (Throwable ignored) {
                    LOG.error("Failed to export test results", ex);
                }
                return;
            }
            final Ref<VirtualFile> result = new Ref<>();
            final Ref<String> error = new Ref<>();
            ApplicationManager.getApplication().invokeAndWait(new Runnable() {

                @Override
                public void run() {
                    result.set(ApplicationManager.getApplication().runWriteAction(new Computable<VirtualFile>() {

                        @Override
                        public VirtualFile compute() {
                            outputFile.getParentFile().mkdirs();
                            final VirtualFile parent = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(outputFile.getParentFile());
                            if (parent == null || !parent.isValid()) {
                                error.set(ExecutionBundle.message("failed.to.create.output.file", outputFile.getPath()));
                                return null;
                            }
                            try {
                                VirtualFile result = parent.findChild(outputFile.getName());
                                if (result == null) {
                                    result = parent.createChildData(this, outputFile.getName());
                                }
                                VfsUtil.saveText(result, outputText);
                                return result;
                            } catch (IOException e) {
                                LOG.warn(e);
                                error.set(e.getMessage());
                                return null;
                            }
                        }
                    }));
                }
            });
            if (!result.isNull()) {
                if (config.isOpenResults()) {
                    openEditorOrBrowser(result.get(), project, config.getExportFormat() == ExportTestResultsConfiguration.ExportFormat.Xml);
                } else {
                    HyperlinkListener listener = new HyperlinkListener() {

                        @Override
                        public void hyperlinkUpdate(HyperlinkEvent e) {
                            if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                                openEditorOrBrowser(result.get(), project, config.getExportFormat() == ExportTestResultsConfiguration.ExportFormat.Xml);
                            }
                        }
                    };
                    showBalloon(project, MessageType.INFO, ExecutionBundle.message("export.test.results.succeeded", outputFile.getName()), listener);
                }
            } else {
                showBalloon(project, MessageType.ERROR, ExecutionBundle.message("export.test.results.failed", error.get()), null);
            }
        }
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) HyperlinkEvent(javax.swing.event.HyperlinkEvent) Attachment(com.intellij.openapi.diagnostic.Attachment) IOException(java.io.IOException) Project(com.intellij.openapi.project.Project) Ref(com.intellij.openapi.util.Ref) HyperlinkListener(javax.swing.event.HyperlinkListener) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) Computable(com.intellij.openapi.util.Computable)

Example 34 with Attachment

use of com.intellij.openapi.diagnostic.Attachment in project intellij-community by JetBrains.

the class SoftWrapApplianceManager method doRecalculateSoftWraps.

private void doRecalculateSoftWraps(IncrementalCacheUpdateEvent event) {
    myEventBeingProcessed = event;
    notifyListenersOnCacheUpdateStart(event);
    // Preparation.
    myContext.reset();
    myOffset2fontType.clear();
    myOffset2widthInPixels.clear();
    EditorTextRepresentationHelper editorTextRepresentationHelper = SoftWrapModelImpl.getEditorTextRepresentationHelper(myEditor);
    if (editorTextRepresentationHelper instanceof DefaultEditorTextRepresentationHelper) {
        ((DefaultEditorTextRepresentationHelper) editorTextRepresentationHelper).updateContext();
    }
    // Define start of the visual line that holds target range start.
    final int start = event.getStartOffset();
    final LogicalPosition logical = event.getStartLogicalPosition();
    int endOffsetUpperEstimate = getEndOffsetUpperEstimate(event);
    Document document = myEditor.getDocument();
    myContext.text = document.getCharsSequence();
    myContext.tokenStartOffset = start;
    IterationState iterationState = new IterationState(myEditor, start, document.getTextLength(), null, false, false, true, false);
    TextAttributes attributes = iterationState.getMergedAttributes();
    myContext.fontType = attributes.getFontType();
    myContext.rangeEndOffset = event.getMandatoryEndOffset();
    EditorPosition position = new EditorPosition(logical, start, myEditor);
    position.x = start == 0 ? myEditor.getPrefixTextWidthInPixels() : 0;
    int spaceWidth = EditorUtil.getSpaceWidth(myContext.fontType, myEditor);
    int plainSpaceWidth = EditorUtil.getSpaceWidth(Font.PLAIN, myEditor);
    myContext.logicalLineData.update(logical.line, spaceWidth, plainSpaceWidth);
    myContext.currentPosition = position;
    myContext.lineStartPosition = position.clone();
    myContext.fontType2spaceWidth.put(myContext.fontType, spaceWidth);
    myContext.softWrapStartOffset = position.offset;
    myContext.reservedWidthInPixels = myPainter.getMinDrawingWidth(SoftWrapDrawingType.BEFORE_SOFT_WRAP_LINE_FEED);
    SoftWrap softWrapAtStartPosition = myStorage.getSoftWrap(start);
    if (softWrapAtStartPosition != null) {
        myContext.currentPosition.x = softWrapAtStartPosition.getIndentInPixels();
        myContext.softWrapStartOffset++;
    }
    myContext.inlays = myEditor.getInlayModel().getInlineElementsInRange(start, endOffsetUpperEstimate);
    // Perform soft wraps calculation.
    while (!iterationState.atEnd()) {
        FoldRegion currentFold = iterationState.getCurrentFold();
        if (currentFold == null) {
            myContext.tokenEndOffset = iterationState.getEndOffset();
            myContext.nextIsFoldRegion = iterationState.nextIsFoldRegion();
            if (processNonFoldToken()) {
                break;
            }
        } else {
            if (processCollapsedFoldRegion(currentFold)) {
                break;
            }
            // 'myOffset2widthInPixels' contains information necessary to processing soft wraps that lay before the current offset.
            // We do know that soft wraps are not allowed to go backward after processed collapsed fold region, hence, we drop
            // information about processed symbols width.
            myOffset2widthInPixels.clear();
        }
        iterationState.advance();
        attributes = iterationState.getMergedAttributes();
        myContext.fontType = attributes.getFontType();
        myContext.tokenStartOffset = iterationState.getStartOffset();
        myOffset2fontType.fill(myContext.tokenStartOffset, iterationState.getEndOffset(), myContext.fontType);
    }
    if (myContext.delayedSoftWrap != null) {
        myStorage.remove(myContext.delayedSoftWrap);
    }
    event.setActualEndOffset(myContext.currentPosition.offset);
    if (LOG.isDebugEnabled()) {
        LOG.debug("Soft wrap recalculation done: " + event.toString() + ". " + (event.getActualEndOffset() - event.getStartOffset()) + " characters processed");
    }
    if (event.getActualEndOffset() > endOffsetUpperEstimate) {
        LOG.error("Unexpected error at soft wrap recalculation", new Attachment("softWrapModel.txt", myEditor.getSoftWrapModel().toString()));
    }
    notifyListenersOnCacheUpdateEnd(event);
    myEventBeingProcessed = null;
}
Also used : IterationState(com.intellij.openapi.editor.impl.view.IterationState) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) Attachment(com.intellij.openapi.diagnostic.Attachment)

Example 35 with Attachment

use of com.intellij.openapi.diagnostic.Attachment in project intellij-community by JetBrains.

the class EditorCoordinateMapper method logicalToVisualPosition.

@NotNull
VisualPosition logicalToVisualPosition(@NotNull LogicalPosition pos, boolean beforeSoftWrap) {
    int line = pos.line;
    int column = pos.column;
    int logicalLineCount = myDocument.getLineCount();
    if (line >= logicalLineCount) {
        return new VisualPosition(line - logicalLineCount + myView.getEditor().getVisibleLineCount(), column, pos.leansForward);
    }
    int offset = logicalPositionToOffset(pos);
    int visualLine = offsetToVisualLine(offset, beforeSoftWrap);
    int maxVisualColumn = 0;
    int maxLogicalColumn = 0;
    for (VisualLineFragmentsIterator.Fragment fragment : VisualLineFragmentsIterator.create(myView, offset, beforeSoftWrap)) {
        if (!pos.leansForward && offset == fragment.getVisualLineStartOffset()) {
            return new VisualPosition(visualLine, fragment.getStartVisualColumn());
        }
        if (fragment.isCollapsedFoldRegion()) {
            int startLogicalLine = fragment.getStartLogicalLine();
            int endLogicalLine = fragment.getEndLogicalLine();
            int startLogicalColumn = fragment.getStartLogicalColumn();
            int endLogicalColumn = fragment.getEndLogicalColumn();
            if ((line > startLogicalLine || line == startLogicalLine && (column > startLogicalColumn || column == startLogicalColumn && pos.leansForward)) && (line < endLogicalLine || line == endLogicalLine && column < endLogicalColumn)) {
                return new VisualPosition(visualLine, fragment.getStartVisualColumn(), true);
            }
            if (line == endLogicalLine && column == endLogicalColumn && !pos.leansForward) {
                return new VisualPosition(visualLine, fragment.getEndVisualColumn());
            }
            maxLogicalColumn = startLogicalLine == endLogicalLine ? Math.max(maxLogicalColumn, endLogicalColumn) : endLogicalColumn;
        } else if (fragment.getCurrentInlays() == null) {
            int minColumn = fragment.getMinLogicalColumn();
            int maxColumn = fragment.getMaxLogicalColumn();
            if (line == fragment.getStartLogicalLine() && (column > minColumn && column < maxColumn || column == minColumn && pos.leansForward || column == maxColumn && !pos.leansForward)) {
                return new VisualPosition(visualLine, fragment.logicalToVisualColumn(column), fragment.isRtl() ^ pos.leansForward);
            }
            maxLogicalColumn = Math.max(maxLogicalColumn, maxColumn);
        }
        maxVisualColumn = fragment.getEndVisualColumn();
    }
    int resultColumn = column - maxLogicalColumn + maxVisualColumn;
    if (resultColumn < 0) {
        if (maxVisualColumn > maxLogicalColumn) {
            // guarding against overflow
            resultColumn = Integer.MAX_VALUE;
        } else {
            LOG.error("Error converting " + pos + " to visual position", new Attachment("details.txt", String.format("offset: %d, visual line: %d, max logical column: %d, max visual column: %d", offset, visualLine, maxLogicalColumn, maxVisualColumn)), new Attachment("dump.txt", myView.getEditor().dumpState()));
            resultColumn = 0;
        }
    }
    return new VisualPosition(visualLine, resultColumn, pos.leansForward);
}
Also used : Attachment(com.intellij.openapi.diagnostic.Attachment) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

Attachment (com.intellij.openapi.diagnostic.Attachment)41 VirtualFile (com.intellij.openapi.vfs.VirtualFile)12 NotNull (org.jetbrains.annotations.NotNull)10 Project (com.intellij.openapi.project.Project)6 ArrayList (java.util.ArrayList)6 Document (com.intellij.openapi.editor.Document)5 TextRange (com.intellij.openapi.util.TextRange)4 LogEventException (com.intellij.diagnostic.LogEventException)3 Logger (com.intellij.openapi.diagnostic.Logger)3 PsiElement (com.intellij.psi.PsiElement)3 PsiFile (com.intellij.psi.PsiFile)3 LogMessageEx (com.intellij.diagnostic.LogMessageEx)2 JSQualifiedNamedElement (com.intellij.lang.javascript.psi.ecmal4.JSQualifiedNamedElement)2 Pair (com.intellij.openapi.util.Pair)2 PsiDocumentManager (com.intellij.psi.PsiDocumentManager)2 List (java.util.List)2 NonNls (org.jetbrains.annotations.NonNls)2 HighlightDisplayLevel (com.intellij.codeHighlighting.HighlightDisplayLevel)1 TextEditorHighlightingPass (com.intellij.codeHighlighting.TextEditorHighlightingPass)1 DaemonCodeAnalyzer (com.intellij.codeInsight.daemon.DaemonCodeAnalyzer)1