Search in sources :

Example 51 with RangeMarker

use of com.intellij.openapi.editor.RangeMarker in project android by JetBrains.

the class GradleEditorModelUtil method buildSourceBinding.

@Nullable
public static GradleEditorSourceBinding buildSourceBinding(@NotNull Location location, @NotNull Project project) {
    FileDocumentManager fileDocumentManager = FileDocumentManager.getInstance();
    Document document = fileDocumentManager.getDocument(location.file);
    if (document == null) {
        LOG.warn(String.format("Can't obtain a document for file %s for processing location '%s'", location.file, location));
        return null;
    }
    RangeMarker rangeMarker = document.createRangeMarker(location.range);
    return new GradleEditorSourceBinding(project, location.file, rangeMarker);
}
Also used : GradleEditorSourceBinding(com.android.tools.idea.gradle.editor.entity.GradleEditorSourceBinding) FileDocumentManager(com.intellij.openapi.fileEditor.FileDocumentManager) RangeMarker(com.intellij.openapi.editor.RangeMarker) Document(com.intellij.openapi.editor.Document) Nullable(org.jetbrains.annotations.Nullable)

Example 52 with RangeMarker

use of com.intellij.openapi.editor.RangeMarker in project android by JetBrains.

the class GradleEditorParserTestUtil method text.

@NotNull
public static String text(@NotNull GradleEditorSourceBinding binding) {
    VirtualFile file = binding.getFile();
    Document document = FileDocumentManager.getInstance().getDocument(file);
    if (document == null) {
        throw new IllegalStateException(String.format("Can't obtain a document for file %s (descriptor '%s')", file, binding));
    }
    RangeMarker marker = binding.getRangeMarker();
    return document.getCharsSequence().subSequence(marker.getStartOffset(), marker.getEndOffset()).toString();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) RangeMarker(com.intellij.openapi.editor.RangeMarker) Document(com.intellij.openapi.editor.Document) NotNull(org.jetbrains.annotations.NotNull)

Example 53 with RangeMarker

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

the class SmartEnterProcessorWithFixers method doEnter.

protected void doEnter(@NotNull PsiElement atCaret, @NotNull PsiFile psiFile, @NotNull Editor editor, boolean afterCompletion) throws IncorrectOperationException {
    if (myFirstErrorOffset != Integer.MAX_VALUE) {
        editor.getCaretModel().moveToOffset(myFirstErrorOffset);
        reformat(atCaret);
        return;
    }
    final RangeMarker rangeMarker = createRangeMarker(atCaret);
    if (reformatBeforeEnter(atCaret)) {
        reformat(atCaret);
    }
    commit(editor);
    PsiElement actualAtCaret = restoreElementAtCaret(psiFile, atCaret, rangeMarker);
    int endOffset = rangeMarker.getEndOffset();
    rangeMarker.dispose();
    if (actualAtCaret != null) {
        for (FixEnterProcessor enterProcessor : myEnterProcessors) {
            if (enterProcessor.doEnter(actualAtCaret, psiFile, editor, isModified(editor))) {
                return;
            }
        }
    }
    if (!isModified(editor) && !afterCompletion) {
        if (actualAtCaret != null) {
            plainEnter(editor);
        }
    } else {
        editor.getCaretModel().moveToOffset(myFirstErrorOffset == Integer.MAX_VALUE ? (actualAtCaret != null ? actualAtCaret.getTextRange().getEndOffset() : endOffset) : myFirstErrorOffset);
    }
}
Also used : RangeMarker(com.intellij.openapi.editor.RangeMarker) PsiElement(com.intellij.psi.PsiElement)

Example 54 with RangeMarker

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

the class EventLog method insertNewLineSubstitutors.

private static void insertNewLineSubstitutors(Document document, AtomicBoolean showMore, List<RangeMarker> lineSeparators) {
    for (RangeMarker marker : lineSeparators) {
        if (!marker.isValid()) {
            showMore.set(true);
            continue;
        }
        int offset = marker.getStartOffset();
        if (offset == 0 || offset == document.getTextLength()) {
            continue;
        }
        boolean spaceBefore = offset > 0 && Character.isWhitespace(document.getCharsSequence().charAt(offset - 1));
        if (offset < document.getTextLength()) {
            boolean spaceAfter = Character.isWhitespace(document.getCharsSequence().charAt(offset));
            int next = CharArrayUtil.shiftForward(document.getCharsSequence(), offset, " \t");
            if (next < document.getTextLength() && !Character.isLowerCase(document.getCharsSequence().charAt(next))) {
                document.insertString(offset, (spaceBefore ? "" : " ") + "//" + (spaceAfter ? "" : " "));
                continue;
            }
            if (spaceAfter) {
                continue;
            }
        }
        if (spaceBefore) {
            continue;
        }
        document.insertString(offset, " ");
    }
}
Also used : RangeMarker(com.intellij.openapi.editor.RangeMarker) RelativePoint(com.intellij.ui.awt.RelativePoint)

Example 55 with RangeMarker

use of com.intellij.openapi.editor.RangeMarker 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)

Aggregations

RangeMarker (com.intellij.openapi.editor.RangeMarker)111 Document (com.intellij.openapi.editor.Document)33 TextRange (com.intellij.openapi.util.TextRange)20 Project (com.intellij.openapi.project.Project)19 PsiFile (com.intellij.psi.PsiFile)14 PsiElement (com.intellij.psi.PsiElement)13 IncorrectOperationException (com.intellij.util.IncorrectOperationException)13 Editor (com.intellij.openapi.editor.Editor)11 Nullable (org.jetbrains.annotations.Nullable)11 NotNull (org.jetbrains.annotations.NotNull)10 Template (com.intellij.codeInsight.template.Template)8 TemplateBuilderImpl (com.intellij.codeInsight.template.TemplateBuilderImpl)7 TemplateEditingAdapter (com.intellij.codeInsight.template.TemplateEditingAdapter)6 PsiDocumentManager (com.intellij.psi.PsiDocumentManager)6 RangeHighlighterEx (com.intellij.openapi.editor.ex.RangeHighlighterEx)5 THashMap (gnu.trove.THashMap)5 GutterMark (com.intellij.codeInsight.daemon.GutterMark)4 HighlightSeverity (com.intellij.lang.annotation.HighlightSeverity)4 ApplicationManager (com.intellij.openapi.application.ApplicationManager)4 RelativePoint (com.intellij.ui.awt.RelativePoint)4