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