From 0354993fb1f6790cc1e7d260e80adc5148583a72 Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Fri, 28 Apr 2017 18:40:49 +0200 Subject: [PATCH] IDEA-CR-19534 default implementation of createRangeMarker / getLineSeparatorLength remove isWritable from BaseDocumentAdapter --- .../src/com/intellij/openapi/editor/Document.java | 8 ++++++-- .../intellij/openapi/editor/impl/DocumentImpl.java | 6 ------ .../intellij/openapi/editor/impl/FrozenDocument.java | 6 ------ .../intellij/openapi/editor/BaseDocumentAdapter.kt | 7 ------- .../com/intellij/ui/EditorTextFieldCellRenderer.java | 5 +++++ .../src/com/intellij/mock/MockDocument.java | 11 +++++------ 6 files changed, 16 insertions(+), 27 deletions(-) diff --git a/platform/core-api/src/com/intellij/openapi/editor/Document.java b/platform/core-api/src/com/intellij/openapi/editor/Document.java index 8983c269f166..893a1e2ae81f 100644 --- a/platform/core-api/src/com/intellij/openapi/editor/Document.java +++ b/platform/core-api/src/com/intellij/openapi/editor/Document.java @@ -339,8 +339,12 @@ public interface Document extends UserDataHolder { void setText(@NotNull final CharSequence text); @NotNull - RangeMarker createRangeMarker(@NotNull TextRange textRange); + default RangeMarker createRangeMarker(@NotNull TextRange textRange) { + return createRangeMarker(textRange.getStartOffset(), textRange.getEndOffset()); + } @Contract(pure=true) - int getLineSeparatorLength(int line); + default int getLineSeparatorLength(int line) { + return 0; + } } diff --git a/platform/core-impl/src/com/intellij/openapi/editor/impl/DocumentImpl.java b/platform/core-impl/src/com/intellij/openapi/editor/impl/DocumentImpl.java index ce282b8f4a53..d24eb4ae8b94 100644 --- a/platform/core-impl/src/com/intellij/openapi/editor/impl/DocumentImpl.java +++ b/platform/core-impl/src/com/intellij/openapi/editor/impl/DocumentImpl.java @@ -979,12 +979,6 @@ public class DocumentImpl extends UserDataHolderBase implements DocumentEx { clearLineModificationFlags(); } - @Override - @NotNull - public RangeMarker createRangeMarker(@NotNull final TextRange textRange) { - return createRangeMarker(textRange.getStartOffset(), textRange.getEndOffset()); - } - @Override public final boolean isInBulkUpdate() { return myDoingBulkUpdate; diff --git a/platform/core-impl/src/com/intellij/openapi/editor/impl/FrozenDocument.java b/platform/core-impl/src/com/intellij/openapi/editor/impl/FrozenDocument.java index e0b2568be6f6..aa9bc61895ae 100644 --- a/platform/core-impl/src/com/intellij/openapi/editor/impl/FrozenDocument.java +++ b/platform/core-impl/src/com/intellij/openapi/editor/impl/FrozenDocument.java @@ -251,12 +251,6 @@ public class FrozenDocument implements DocumentEx { throw new UnsupportedOperationException(); } - @NotNull - @Override - public RangeMarker createRangeMarker(@NotNull TextRange textRange) { - throw new UnsupportedOperationException(); - } - @Override public int getLineSeparatorLength(int line) { return getLineSet().getSeparatorLength(line); diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/BaseDocumentAdapter.kt b/platform/platform-impl/src/com/intellij/openapi/editor/BaseDocumentAdapter.kt index 62e94f2f194f..eeac5aef8dbd 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/BaseDocumentAdapter.kt +++ b/platform/platform-impl/src/com/intellij/openapi/editor/BaseDocumentAdapter.kt @@ -15,12 +15,9 @@ */ package com.intellij.openapi.editor -import com.intellij.openapi.util.TextRange import com.intellij.openapi.util.UserDataHolderBase abstract class BaseDocumentAdapter : UserDataHolderBase(), Document { - override fun getLineSeparatorLength(line: Int) = 0 - override fun getModificationStamp() = 0L override fun insertString(offset: Int, s: CharSequence) { @@ -39,8 +36,6 @@ abstract class BaseDocumentAdapter : UserDataHolderBase(), Document { throw UnsupportedOperationException("Not implemented") } - override fun isWritable() = false - override fun createRangeMarker(startOffset: Int, endOffset: Int): RangeMarker = throw UnsupportedOperationException("Not implemented") override fun createRangeMarker(startOffset: Int, endOffset: Int, surviveOnExternalChange: Boolean): RangeMarker { @@ -56,6 +51,4 @@ abstract class BaseDocumentAdapter : UserDataHolderBase(), Document { override fun getOffsetGuard(offset: Int): RangeMarker? = null override fun getRangeGuard(start: Int, end: Int): RangeMarker? = null - - override fun createRangeMarker(textRange: TextRange): RangeMarker = throw UnsupportedOperationException("Not implemented") } \ No newline at end of file diff --git a/platform/platform-impl/src/com/intellij/ui/EditorTextFieldCellRenderer.java b/platform/platform-impl/src/com/intellij/ui/EditorTextFieldCellRenderer.java index 82db740a0b76..b908caa1ebd3 100644 --- a/platform/platform-impl/src/com/intellij/ui/EditorTextFieldCellRenderer.java +++ b/platform/platform-impl/src/com/intellij/ui/EditorTextFieldCellRenderer.java @@ -436,5 +436,10 @@ public abstract class EditorTextFieldCellRenderer implements TableCellRenderer, @Override public int getLineEndOffset(int line) { return myChars.length == 0 ? 0 : myLineSet.getLineEnd(line); } + + @Override + public boolean isWritable() { + return false; + } } } diff --git a/platform/testFramework/src/com/intellij/mock/MockDocument.java b/platform/testFramework/src/com/intellij/mock/MockDocument.java index aead72b313b4..4dc76f90fa9c 100644 --- a/platform/testFramework/src/com/intellij/mock/MockDocument.java +++ b/platform/testFramework/src/com/intellij/mock/MockDocument.java @@ -107,6 +107,11 @@ public class MockDocument extends BaseDocumentAdapter implements DocumentEx { myModStamp = LocalTimeCounter.currentTime(); } + @Override + public boolean isWritable() { + return false; + } + @Override public long getModificationStamp() { return myModStamp; @@ -133,12 +138,6 @@ public class MockDocument extends BaseDocumentAdapter implements DocumentEx { return null; } - @Override - @NotNull - public RangeMarker createRangeMarker(@NotNull final TextRange textRange) { - return createRangeMarker(textRange.getStartOffset(), textRange.getEndOffset()); - } - @Override public void registerRangeMarker(@NotNull RangeMarkerEx rangeMarker, int start, int end, boolean greedyToLeft, boolean greedyToRight, int layer) { }