IDEA-CR-19534 remove BaseDocumentAdapterEx to make code more clear

This commit is contained in:
Vladimir Krivosheev
2017-03-29 12:25:57 +02:00
parent 8ad5ba1d43
commit 6b65aa2410
7 changed files with 73 additions and 127 deletions
@@ -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
@@ -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<RangeMarker> getGuardedBlocks() {
@@ -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<? super RangeMarker> 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) {
@@ -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() {
@@ -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<in RangeMarker>) = false
override fun processRangeMarkersOverlappingWith(start: Int, end: Int, processor: Processor<in RangeMarker>) = 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()
}
@@ -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<RangeMarkerEx> myRangeMarkers = new RangeMarkerTree<RangeMarkerEx>(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());
@@ -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<? super RangeMarker> processor) {
return false;
}
@Override
public boolean processRangeMarkersOverlappingWith(int start, int end, @NotNull Processor<? super RangeMarker> processor) {
return false;
}
@Override
public boolean removeRangeMarker(@NotNull RangeMarkerEx rangeMarker) {
return false;
}
}