From 6b65aa24109e51c2b3f0a7e5ff6b4b971bcb129d Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Wed, 29 Mar 2017 12:24:45 +0200 Subject: [PATCH] IDEA-CR-19534 remove BaseDocumentAdapterEx to make code more clear --- .../com/intellij/openapi/editor/Document.java | 12 ++-- .../openapi/editor/ex/DocumentEx.java | 16 +++-- .../openapi/editor/impl/FrozenDocument.java | 48 --------------- .../injected/editor/DocumentWindowImpl.java | 9 --- .../openapi/editor/BaseDocumentAdapter.kt | 58 +------------------ .../ui/EditorTextFieldCellRenderer.java | 19 +++++- .../src/com/intellij/mock/MockDocument.java | 38 +++++++++++- 7 files changed, 73 insertions(+), 127 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 edb8b1dd132b..8983c269f166 100644 --- a/platform/core-api/src/com/intellij/openapi/editor/Document.java +++ b/platform/core-api/src/com/intellij/openapi/editor/Document.java @@ -194,23 +194,27 @@ public interface Document extends UserDataHolder { * from the document (the read-only state can be removed by checking the file out * from the version control system, or by clearing the read-only attribute on the file). */ - void fireReadOnlyModificationAttempt(); + default void fireReadOnlyModificationAttempt() { + } /** * Adds a listener for receiving notifications about changes in the document content. * * @param listener the listener instance. */ - void addDocumentListener(@NotNull DocumentListener listener); + default void addDocumentListener(@NotNull DocumentListener listener) { + } - void addDocumentListener(@NotNull DocumentListener listener, @NotNull Disposable parentDisposable); + default void addDocumentListener(@NotNull DocumentListener listener, @NotNull Disposable parentDisposable) { + } /** * Removes a listener for receiving notifications about changes in the document content. * * @param listener the listener instance. */ - void removeDocumentListener(@NotNull DocumentListener listener); + default void removeDocumentListener(@NotNull DocumentListener listener) { + } /** * Creates a range marker which points to the specified range of text in the document and diff --git a/platform/core-impl/src/com/intellij/openapi/editor/ex/DocumentEx.java b/platform/core-impl/src/com/intellij/openapi/editor/ex/DocumentEx.java index 3d6816f8b563..32b5a8980d51 100644 --- a/platform/core-impl/src/com/intellij/openapi/editor/ex/DocumentEx.java +++ b/platform/core-impl/src/com/intellij/openapi/editor/ex/DocumentEx.java @@ -25,16 +25,19 @@ import java.util.Collections; import java.util.List; public interface DocumentEx extends Document { - void setStripTrailingSpacesEnabled(boolean isEnabled); + default void setStripTrailingSpacesEnabled(boolean isEnabled) { + } @NotNull LineIterator createLineIterator(); void setModificationStamp(long modificationStamp); - void addEditReadOnlyListener(@NotNull EditReadOnlyListener listener); + default void addEditReadOnlyListener(@NotNull EditReadOnlyListener listener) { + } - void removeEditReadOnlyListener(@NotNull EditReadOnlyListener listener); + default void removeEditReadOnlyListener(@NotNull EditReadOnlyListener listener) { + } void replaceText(@NotNull CharSequence chars, long newModificationStamp); @@ -72,7 +75,9 @@ public interface DocumentEx extends Document { boolean greedyToRight, int layer); - boolean isInBulkUpdate(); + default boolean isInBulkUpdate() { + return false; + } /** * Enters or exits 'bulk' mode for processing of document changes. Bulk mode should be used when a large number of document changes @@ -83,7 +88,8 @@ public interface DocumentEx extends Document { * or updating folding or soft wrap data, editor position recalculation functions (offset to logical position, logical to visual position, * etc), querying or updating caret position or selection state. */ - void setInBulkUpdate(boolean value); + default void setInBulkUpdate(boolean value) { + } @NotNull default List getGuardedBlocks() { 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 89ba7ec32bf8..e0b2568be6f6 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 @@ -15,12 +15,9 @@ */ package com.intellij.openapi.editor.impl; -import com.intellij.openapi.Disposable; import com.intellij.openapi.editor.RangeMarker; import com.intellij.openapi.editor.event.DocumentEvent; -import com.intellij.openapi.editor.event.DocumentListener; import com.intellij.openapi.editor.ex.DocumentEx; -import com.intellij.openapi.editor.ex.EditReadOnlyListener; import com.intellij.openapi.editor.ex.LineIterator; import com.intellij.openapi.editor.ex.RangeMarkerEx; import com.intellij.openapi.util.Key; @@ -65,11 +62,6 @@ public class FrozenDocument implements DocumentEx { return new FrozenDocument(newText, newLineSet, newStamp, null); } - @Override - public void setStripTrailingSpacesEnabled(boolean isEnabled) { - throw new UnsupportedOperationException(); - } - @NotNull @Override public LineIterator createLineIterator() { @@ -81,16 +73,6 @@ public class FrozenDocument implements DocumentEx { throw new UnsupportedOperationException(); } - @Override - public void addEditReadOnlyListener(@NotNull EditReadOnlyListener listener) { - throw new UnsupportedOperationException(); - } - - @Override - public void removeEditReadOnlyListener(@NotNull EditReadOnlyListener listener) { - throw new UnsupportedOperationException(); - } - @Override public void replaceText(@NotNull CharSequence chars, long newModificationStamp) { throw new UnsupportedOperationException(); @@ -121,16 +103,6 @@ public class FrozenDocument implements DocumentEx { throw new UnsupportedOperationException(); } - @Override - public boolean isInBulkUpdate() { - return false; - } - - @Override - public void setInBulkUpdate(boolean value) { - throw new UnsupportedOperationException(); - } - @Override public boolean processRangeMarkers(@NotNull Processor processor) { return true; @@ -224,26 +196,6 @@ public class FrozenDocument implements DocumentEx { return myStamp; } - @Override - public void fireReadOnlyModificationAttempt() { - throw new UnsupportedOperationException(); - } - - @Override - public void addDocumentListener(@NotNull DocumentListener listener) { - throw new UnsupportedOperationException(); - } - - @Override - public void addDocumentListener(@NotNull DocumentListener listener, @NotNull Disposable parentDisposable) { - throw new UnsupportedOperationException(); - } - - @Override - public void removeDocumentListener(@NotNull DocumentListener listener) { - throw new UnsupportedOperationException(); - } - @NotNull @Override public RangeMarker createRangeMarker(int startOffset, int endOffset) { diff --git a/platform/lang-impl/src/com/intellij/injected/editor/DocumentWindowImpl.java b/platform/lang-impl/src/com/intellij/injected/editor/DocumentWindowImpl.java index e9119b055002..295d31216c7b 100644 --- a/platform/lang-impl/src/com/intellij/injected/editor/DocumentWindowImpl.java +++ b/platform/lang-impl/src/com/intellij/injected/editor/DocumentWindowImpl.java @@ -620,15 +620,6 @@ public class DocumentWindowImpl extends UserDataHolderBase implements Disposable throw new IllegalStateException(); } - @Override - public boolean isInBulkUpdate() { - return false; - } - - @Override - public void setInBulkUpdate(boolean value) { - } - @Override @NotNull public DocumentEx getDelegate() { 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 d18e387984e1..62e94f2f194f 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/BaseDocumentAdapter.kt +++ b/platform/platform-impl/src/com/intellij/openapi/editor/BaseDocumentAdapter.kt @@ -15,15 +15,8 @@ */ package com.intellij.openapi.editor -import com.intellij.openapi.Disposable -import com.intellij.openapi.editor.event.DocumentListener -import com.intellij.openapi.editor.ex.DocumentEx -import com.intellij.openapi.editor.ex.EditReadOnlyListener -import com.intellij.openapi.editor.ex.LineIterator -import com.intellij.openapi.editor.ex.RangeMarkerEx import com.intellij.openapi.util.TextRange import com.intellij.openapi.util.UserDataHolderBase -import com.intellij.util.Processor abstract class BaseDocumentAdapter : UserDataHolderBase(), Document { override fun getLineSeparatorLength(line: Int) = 0 @@ -47,19 +40,7 @@ abstract class BaseDocumentAdapter : UserDataHolderBase(), Document { } override fun isWritable() = false - - override fun fireReadOnlyModificationAttempt() { - } - - override fun addDocumentListener(listener: DocumentListener) { - } - - override fun addDocumentListener(listener: DocumentListener, parentDisposable: Disposable) { - } - - override fun removeDocumentListener(listener: DocumentListener) { - } - + override fun createRangeMarker(startOffset: Int, endOffset: Int): RangeMarker = throw UnsupportedOperationException("Not implemented") override fun createRangeMarker(startOffset: Int, endOffset: Int, surviveOnExternalChange: Boolean): RangeMarker { @@ -77,41 +58,4 @@ abstract class BaseDocumentAdapter : UserDataHolderBase(), Document { override fun getRangeGuard(start: Int, end: Int): RangeMarker? = null override fun createRangeMarker(textRange: TextRange): RangeMarker = throw UnsupportedOperationException("Not implemented") -} - -abstract class BaseDocumentAdapterEx : BaseDocumentAdapter(), DocumentEx { - override fun registerRangeMarker(rangeMarker: RangeMarkerEx, - start: Int, - end: Int, - greedyToLeft: Boolean, - greedyToRight: Boolean, - layer: Int) {} - - override fun processRangeMarkers(processor: Processor) = false - - override fun processRangeMarkersOverlappingWith(start: Int, end: Int, processor: Processor) = false - - override fun removeRangeMarker(rangeMarker: RangeMarkerEx) = false - - override fun setStripTrailingSpacesEnabled(isEnabled: Boolean) {} - - override fun setModificationStamp(modificationStamp: Long) {} - - override fun addEditReadOnlyListener(listener: EditReadOnlyListener) {} - - override fun removeEditReadOnlyListener(listener: EditReadOnlyListener) {} - - override fun replaceText(chars: CharSequence, newModificationStamp: Long) { - throw UnsupportedOperationException("Not implemented") - } - - override fun moveText(srcStart: Int, srcEnd: Int, dstOffset: Int) { - throw UnsupportedOperationException("Not implemented") - } - - override fun isInBulkUpdate() = false - - override fun setInBulkUpdate(value: Boolean) {} - - override fun createLineIterator(): LineIterator = throw UnsupportedOperationException() } \ 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 555cae04b6b2..82db740a0b76 100644 --- a/platform/platform-impl/src/com/intellij/ui/EditorTextFieldCellRenderer.java +++ b/platform/platform-impl/src/com/intellij/ui/EditorTextFieldCellRenderer.java @@ -16,13 +16,14 @@ package com.intellij.ui; import com.intellij.openapi.Disposable; -import com.intellij.openapi.editor.BaseDocumentAdapterEx; +import com.intellij.openapi.editor.BaseDocumentAdapter; import com.intellij.openapi.editor.RangeMarker; import com.intellij.openapi.editor.SelectionModel; import com.intellij.openapi.editor.colors.EditorColors; import com.intellij.openapi.editor.colors.EditorColorsManager; import com.intellij.openapi.editor.colors.EditorColorsScheme; import com.intellij.openapi.editor.colors.impl.DelegateColorScheme; +import com.intellij.openapi.editor.ex.DocumentEx; import com.intellij.openapi.editor.ex.EditorEx; import com.intellij.openapi.editor.ex.LineIterator; import com.intellij.openapi.editor.ex.RangeMarkerEx; @@ -353,13 +354,27 @@ public abstract class EditorTextFieldCellRenderer implements TableCellRenderer, } } - private static class MyDocument extends BaseDocumentAdapterEx { + private static class MyDocument extends BaseDocumentAdapter implements DocumentEx { RangeMarkerTree myRangeMarkers = new RangeMarkerTree(this) { }; char[] myChars = ArrayUtil.EMPTY_CHAR_ARRAY; String myString = ""; LineSet myLineSet = LineSet.createLineSet(myString); + @Override + public void setModificationStamp(long modificationStamp) { + } + + @Override + public void replaceText(@NotNull CharSequence chars, long newModificationStamp) { + throw new UnsupportedOperationException(); + } + + @Override + public void moveText(int srcStart, int srcEnd, int dstOffset) { + throw new UnsupportedOperationException(); + } + @Override public void setText(@NotNull CharSequence text) { String s = StringUtil.convertLineSeparators(text.toString()); diff --git a/platform/testFramework/src/com/intellij/mock/MockDocument.java b/platform/testFramework/src/com/intellij/mock/MockDocument.java index 9f79fd049617..aead72b313b4 100644 --- a/platform/testFramework/src/com/intellij/mock/MockDocument.java +++ b/platform/testFramework/src/com/intellij/mock/MockDocument.java @@ -15,13 +15,17 @@ */ package com.intellij.mock; -import com.intellij.openapi.editor.BaseDocumentAdapterEx; +import com.intellij.openapi.editor.BaseDocumentAdapter; import com.intellij.openapi.editor.RangeMarker; +import com.intellij.openapi.editor.ex.DocumentEx; +import com.intellij.openapi.editor.ex.LineIterator; +import com.intellij.openapi.editor.ex.RangeMarkerEx; import com.intellij.openapi.util.TextRange; import com.intellij.util.LocalTimeCounter; +import com.intellij.util.Processor; import org.jetbrains.annotations.NotNull; -public class MockDocument extends BaseDocumentAdapterEx { +public class MockDocument extends BaseDocumentAdapter implements DocumentEx { private StringBuffer myText = new StringBuffer(); private long myModStamp = LocalTimeCounter.currentTime(); @@ -47,6 +51,11 @@ public class MockDocument extends BaseDocumentAdapterEx { myModStamp = newModificationStamp; } + @Override + public void moveText(int srcStart, int srcEnd, int dstOffset) { + throw new UnsupportedOperationException(); + } + public CharSequence textToCharArray() { return getText(); } @@ -103,6 +112,12 @@ public class MockDocument extends BaseDocumentAdapterEx { return myModStamp; } + @NotNull + @Override + public LineIterator createLineIterator() { + throw new UnsupportedOperationException(); + } + @Override public void setModificationStamp(long modificationStamp) { myModStamp = modificationStamp; @@ -123,4 +138,23 @@ public class MockDocument extends BaseDocumentAdapterEx { 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) { + } + + @Override + public boolean processRangeMarkers(@NotNull Processor processor) { + return false; + } + + @Override + public boolean processRangeMarkersOverlappingWith(int start, int end, @NotNull Processor processor) { + return false; + } + + @Override + public boolean removeRangeMarker(@NotNull RangeMarkerEx rangeMarker) { + return false; + } }