Search in sources :

Example 16 with DocumentImpl

use of com.intellij.openapi.editor.impl.DocumentImpl in project intellij-community by JetBrains.

the class LightPlatformCodeInsightTestCase method checkResultByText.

/**
   * Same as checkResultByFile but text is provided directly.
   * @param message - this check specific message. Added to text, caret position, selection checking. May be null
   * @param ignoreTrailingSpaces - whether trailing spaces in editor in data file should be stripped prior to comparing.
   */
protected void checkResultByText(final String message, @NotNull String expectedFileText, final boolean ignoreTrailingSpaces, final String filePath) {
    bringRealEditorBack();
    PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
    ApplicationManager.getApplication().runWriteAction(() -> {
        final Document document = EditorFactory.getInstance().createDocument(expectedFileText);
        if (ignoreTrailingSpaces) {
            ((DocumentImpl) document).stripTrailingSpaces(getProject());
        }
        EditorTestUtil.CaretAndSelectionState carets = EditorTestUtil.extractCaretAndSelectionMarkers(document);
        PostprocessReformattingAspect.getInstance(getProject()).doPostponedFormatting();
        String newFileText = document.getText();
        PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
        String fileText1 = myFile.getText();
        String failMessage = getMessage("Text mismatch", message);
        if (filePath != null && !newFileText.equals(fileText1)) {
            throw new FileComparisonFailure(failMessage, newFileText, fileText1, filePath);
        }
        assertEquals(failMessage, newFileText, fileText1);
        EditorTestUtil.verifyCaretAndSelectionState(myEditor, carets, message);
    });
}
Also used : Document(com.intellij.openapi.editor.Document) DocumentImpl(com.intellij.openapi.editor.impl.DocumentImpl) FileComparisonFailure(com.intellij.rt.execution.junit.FileComparisonFailure)

Example 17 with DocumentImpl

use of com.intellij.openapi.editor.impl.DocumentImpl in project intellij-community by JetBrains.

the class MultiHostRegistrarImpl method createDocument.

@NotNull
private static DocumentEx createDocument(@NotNull LightVirtualFile virtualFile) {
    CharSequence content = virtualFile.getContent();
    DocumentImpl document = new DocumentImpl(content, StringUtil.indexOf(content, '\r') >= 0, false);
    FileDocumentManagerImpl.registerDocument(document, virtualFile);
    return document;
}
Also used : DocumentImpl(com.intellij.openapi.editor.impl.DocumentImpl) NotNull(org.jetbrains.annotations.NotNull)

Example 18 with DocumentImpl

use of com.intellij.openapi.editor.impl.DocumentImpl in project intellij-community by JetBrains.

the class EventLog method getStatusText.

private static String getStatusText(DocumentImpl logDoc, AtomicBoolean showMore, List<RangeMarker> lineSeparators, String indent, boolean hasHtml) {
    DocumentImpl statusDoc = new DocumentImpl(logDoc.getImmutableCharSequence(), true);
    List<RangeMarker> statusSeparators = new ArrayList<>();
    for (RangeMarker separator : lineSeparators) {
        if (separator.isValid()) {
            statusSeparators.add(statusDoc.createRangeMarker(separator.getStartOffset(), separator.getEndOffset()));
        }
    }
    removeJavaNewLines(statusDoc, statusSeparators, indent, hasHtml);
    insertNewLineSubstitutors(statusDoc, showMore, statusSeparators);
    return statusDoc.getText();
}
Also used : RangeMarker(com.intellij.openapi.editor.RangeMarker) DocumentImpl(com.intellij.openapi.editor.impl.DocumentImpl)

Example 19 with DocumentImpl

use of com.intellij.openapi.editor.impl.DocumentImpl in project intellij-community by JetBrains.

the class EventLog method formatForLog.

public static LogEntry formatForLog(@NotNull final Notification notification, final String indent) {
    DocumentImpl logDoc = new DocumentImpl("", true);
    AtomicBoolean showMore = new AtomicBoolean(false);
    Map<RangeMarker, HyperlinkInfo> links = new LinkedHashMap<>();
    List<RangeMarker> lineSeparators = new ArrayList<>();
    String title = notification.getTitle();
    String subtitle = notification.getSubtitle();
    if (StringUtil.isNotEmpty(title) && StringUtil.isNotEmpty(subtitle)) {
        title += " (" + subtitle + ")";
    }
    title = truncateLongString(showMore, title);
    String content = truncateLongString(showMore, notification.getContent());
    RangeMarker afterTitle = null;
    boolean hasHtml = parseHtmlContent(addIndents(title, indent), notification, logDoc, showMore, links, lineSeparators);
    if (StringUtil.isNotEmpty(title)) {
        if (StringUtil.isNotEmpty(content)) {
            appendText(logDoc, ": ");
            afterTitle = logDoc.createRangeMarker(logDoc.getTextLength() - 2, logDoc.getTextLength());
        }
    }
    int titleLength = logDoc.getTextLength();
    hasHtml |= parseHtmlContent(addIndents(content, indent), notification, logDoc, showMore, links, lineSeparators);
    List<AnAction> actions = notification.getActions();
    if (!actions.isEmpty()) {
        String text = "<p>" + StringUtil.join(actions, new Function<AnAction, String>() {

            private int index;

            @Override
            public String fun(AnAction action) {
                return "<a href=\"" + index++ + "\">" + action.getTemplatePresentation().getText() + "</a>";
            }
        }, isLongLine(actions) ? "<br>" : "&nbsp;") + "</p>";
        Notification n = new Notification("", "", ".", NotificationType.INFORMATION, new NotificationListener() {

            @Override
            public void hyperlinkUpdate(@NotNull Notification n, @NotNull HyperlinkEvent event) {
                Notification.fire(notification, notification.getActions().get(Integer.parseInt(event.getDescription())));
            }
        });
        if (title.length() > 0 || content.length() > 0) {
            lineSeparators.add(logDoc.createRangeMarker(TextRange.from(logDoc.getTextLength(), 0)));
        }
        hasHtml |= parseHtmlContent(text, n, logDoc, showMore, links, lineSeparators);
    }
    String status = getStatusText(logDoc, showMore, lineSeparators, indent, hasHtml);
    indentNewLines(logDoc, lineSeparators, afterTitle, hasHtml, indent);
    ArrayList<Pair<TextRange, HyperlinkInfo>> list = new ArrayList<>();
    for (RangeMarker marker : links.keySet()) {
        if (!marker.isValid()) {
            showMore.set(true);
            continue;
        }
        list.add(Pair.create(new TextRange(marker.getStartOffset(), marker.getEndOffset()), links.get(marker)));
    }
    if (showMore.get()) {
        String sb = "show balloon";
        if (!logDoc.getText().endsWith(" ")) {
            appendText(logDoc, " ");
        }
        appendText(logDoc, "(" + sb + ")");
        list.add(new Pair<>(TextRange.from(logDoc.getTextLength() - 1 - sb.length(), sb.length()), new ShowBalloon(notification)));
    }
    return new LogEntry(logDoc.getText(), status, list, titleLength);
}
Also used : HyperlinkEvent(javax.swing.event.HyperlinkEvent) RangeMarker(com.intellij.openapi.editor.RangeMarker) DocumentImpl(com.intellij.openapi.editor.impl.DocumentImpl) AnAction(com.intellij.openapi.actionSystem.AnAction) RelativePoint(com.intellij.ui.awt.RelativePoint) LinkedHashMap(com.intellij.util.containers.hash.LinkedHashMap) HyperlinkInfo(com.intellij.execution.filters.HyperlinkInfo) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean)

Example 20 with DocumentImpl

use of com.intellij.openapi.editor.impl.DocumentImpl in project intellij-community by JetBrains.

the class SyntaxInfoConstructionTest method initWithCustomLineSeparators.

private void initWithCustomLineSeparators(final String text) {
    myFixture.configureByText(getTestName(true) + ".java", "");
    final DocumentImpl document = (DocumentImpl) myFixture.getEditor().getDocument();
    document.setAcceptSlashR(true);
    ApplicationManager.getApplication().runWriteAction(() -> document.setText(text));
    myFixture.doHighlighting();
}
Also used : DocumentImpl(com.intellij.openapi.editor.impl.DocumentImpl)

Aggregations

DocumentImpl (com.intellij.openapi.editor.impl.DocumentImpl)28 Document (com.intellij.openapi.editor.Document)12 NotNull (org.jetbrains.annotations.NotNull)6 RangeMarker (com.intellij.openapi.editor.RangeMarker)4 TextRange (com.intellij.openapi.util.TextRange)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 PsiFile (com.intellij.psi.PsiFile)3 FrozenDocument (com.intellij.openapi.editor.impl.FrozenDocument)2 PsiDocumentManager (com.intellij.psi.PsiDocumentManager)2 FileComparisonFailure (com.intellij.rt.execution.junit.FileComparisonFailure)2 RelativePoint (com.intellij.ui.awt.RelativePoint)2 IncorrectOperationException (com.intellij.util.IncorrectOperationException)2 InlayInfo (com.intellij.codeInsight.hints.InlayInfo)1 ResultItem (com.intellij.execution.filters.Filter.ResultItem)1 HyperlinkInfo (com.intellij.execution.filters.HyperlinkInfo)1 DocumentWindow (com.intellij.injected.editor.DocumentWindow)1 JSTestOptions (com.intellij.lang.javascript.JSTestOptions)1 Disposable (com.intellij.openapi.Disposable)1 AnAction (com.intellij.openapi.actionSystem.AnAction)1 Result (com.intellij.openapi.application.Result)1