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