From 27b0ccf992cfcfa43a49b1dc817be994a4403fae Mon Sep 17 00:00:00 2001 From: Dmitry Batrak Date: Thu, 8 Dec 2016 14:45:44 +0300 Subject: [PATCH] remove unused code --- .../openapi/editor/impl/CharWidthCache.java | 43 ----- .../openapi/editor/impl/RangeIterator.java | 161 ------------------ .../editor/impl/VisualSizeChangeListener.java | 42 ----- .../impl/softwrap/mapping/EditorPosition.java | 3 - .../mapping/SoftWrapApplianceManager.java | 6 +- .../editor/impl/RangeIteratorTest.java | 158 ----------------- 6 files changed, 2 insertions(+), 411 deletions(-) delete mode 100644 platform/platform-impl/src/com/intellij/openapi/editor/impl/CharWidthCache.java delete mode 100644 platform/platform-impl/src/com/intellij/openapi/editor/impl/RangeIterator.java delete mode 100644 platform/platform-impl/src/com/intellij/openapi/editor/impl/VisualSizeChangeListener.java delete mode 100644 platform/platform-tests/testSrc/com/intellij/openapi/editor/impl/RangeIteratorTest.java diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/CharWidthCache.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/CharWidthCache.java deleted file mode 100644 index 40d80c0fb917..000000000000 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/CharWidthCache.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2000-2014 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.openapi.editor.impl; - -import com.intellij.openapi.editor.Editor; -import com.intellij.openapi.editor.ex.util.EditorUtil; -import com.intellij.util.containers.IntIntHashMap; -import org.intellij.lang.annotations.JdkConstants; - -/** - * @author peter - */ -public class CharWidthCache { - private final Editor myEditor; - private final IntIntHashMap myCache = new IntIntHashMap(); - - public CharWidthCache(Editor editor) { - myEditor = editor; - } - - public int charWidth(char c, @JdkConstants.FontStyle int fontType) { - int key = c + fontType * (Character.MAX_VALUE + 1); - int width = myCache.get(key); - if (width < 0) { - myCache.put(key, width = EditorUtil.charWidth(c, fontType, myEditor)); - } - return width; - } - -} diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/RangeIterator.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/RangeIterator.java deleted file mode 100644 index 9d6ba08e8adc..000000000000 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/RangeIterator.java +++ /dev/null @@ -1,161 +0,0 @@ -/* - * Copyright 2000-2009 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.openapi.editor.impl; - -import com.intellij.openapi.diagnostic.Logger; -import com.intellij.openapi.editor.FoldingModel; -import com.intellij.openapi.editor.highlighter.HighlighterIterator; -import com.intellij.openapi.editor.markup.TextAttributes; -import com.intellij.openapi.util.Condition; -import com.intellij.openapi.util.TextRange; -import gnu.trove.Equality; - -class RangeIterator { - private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.editor.impl.RangeIterator"); - private static final int NO_NEXT = -1; - private int myRangeEnd; - - public interface Gaps { - boolean isGapAt(int offset); - } - - private final HighlighterIterator mySource; - private final Equality myEquality; - private final Gaps myGaps; - private final Condition myFilter; - private boolean mySourceOutOfRange = false; - - private int myStart; - private int myEnd; - private TextAttributes myTextAttributes; - private int myNextExpanded; - - public RangeIterator(Gaps foldingModel, Equality equality, - HighlighterIterator source, Condition filter) { - mySource = source; - myGaps = foldingModel; - myEquality = equality; - myFilter = filter; - } - - public void init(TextRange range) { - int rangeStart = range.getStartOffset(); - myRangeEnd = range.getEndOffset(); - while(!mySource.atEnd()) { - boolean sourceBeforeRange = rangeStart > mySource.getEnd(); - if (!sourceBeforeRange) break; - mySource.advance(); - } - while (!mySource.atEnd() && !checkOutOfRange()) { - if (myFilter.value(mySource.getTextAttributes())) break; - mySource.advance(); - } - - if (mySource.atEnd() || mySourceOutOfRange) myNextExpanded = NO_NEXT; - else { - myNextExpanded = findExpanded(mySource.getStart()); - if (myNextExpanded == NO_NEXT) myStart = NO_NEXT; - } - } - - private boolean checkOutOfRange() { - if (mySourceOutOfRange) return true; - mySourceOutOfRange = mySource.getStart() > myRangeEnd; - return mySourceOutOfRange; - } - - private void doAdvanceFrom(int start) { - myStart = start; - myEnd = myStart; - doAdvance(); - if (mySource.atEnd()) myNextExpanded = NO_NEXT; - else myNextExpanded = findExpanded(Math.max(myEnd, mySource.getStart())); - } - - private void doAdvance() { - myStart = findExpanded(myStart); - myEnd = findFolding(myStart, mySource.getEnd(), true); - myTextAttributes = mySource.getTextAttributes(); - while (myEnd == mySource.getEnd()) { - if (!advanceSource()) return; - if (mySource.getStart() != myEnd) return; - if (!myEquality.equals(myTextAttributes, mySource.getTextAttributes())) return; - myEnd = findFolding(myEnd, mySource.getEnd(), true); - } - } - - private boolean advanceSource() { - if (mySource.atEnd()) return false; - do { - mySource.advance(); - } while (!(mySource.atEnd() || checkOutOfRange() || myFilter.value(mySource.getTextAttributes()))); - return !mySource.atEnd(); - } - - private int findExpanded(int start) { - start = findFolding(start, mySource.getEnd(), false); - while (start == mySource.getEnd()) { - if (!advanceSource()) return NO_NEXT; - start = findFolding(mySource.getStart(), mySource.getEnd(), false); - } - return start; - } - - private int findFolding(int start, int end, boolean collapsed) { - int position = start; - while (position < end) { - if (myGaps.isGapAt(position) == collapsed) break; - else position++; - } - return position; - } - - public int getStart() { - return myStart; - } - - public int getEnd() { - return myEnd; - } - - public TextAttributes getTextAttributes() { - LOG.assertTrue(myFilter.value(myTextAttributes)); - return myTextAttributes; - } - - public void advance() { - doAdvanceFrom(myNextExpanded); - } - - public boolean atEnd() { - return myStart == NO_NEXT || mySourceOutOfRange || - (mySource.atEnd() && (myNextExpanded == NO_NEXT || - myNextExpanded == mySource.getEnd())); - } - - public static class FoldingGaps implements Gaps { - private final FoldingModel myFoldingModel; - - public FoldingGaps(FoldingModel foldingModel) { - myFoldingModel = foldingModel; - } - - @Override - public boolean isGapAt(int offset) { - return myFoldingModel.isOffsetCollapsed(offset); - } - } -} diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/VisualSizeChangeListener.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/VisualSizeChangeListener.java deleted file mode 100644 index a52cc86d7b71..000000000000 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/VisualSizeChangeListener.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2000-2010 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.openapi.editor.impl; - -import gnu.trove.TIntIntHashMap; -import org.jetbrains.annotations.NotNull; - -/** - * Defines callback that receives information about visual size change of component that represents data in lines-based mode. - * - * @author Denis Zhdanov - * @since 12/6/10 11:04 AM - */ -public interface VisualSizeChangeListener { - - /** - * Notifies about new visual widths of the target logical lines. - *

- * Assumes to be called on document change events. - *

- * Note: it is assumed that - * - * @param startLine logical line that contains start offset of the changed region - * @param oldEndLine logical line that contained end offset of the changed region - * @param newEndLine logical line that contains end offset of the changed region - * @param lineWidths container of {@code 'logical line number -> line width in pixels} mappings - */ - void onLineWidthsChange(int startLine, int oldEndLine, int newEndLine, @NotNull TIntIntHashMap lineWidths); -} diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/softwrap/mapping/EditorPosition.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/softwrap/mapping/EditorPosition.java index 8499582c6f20..d0bff1bef0c1 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/softwrap/mapping/EditorPosition.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/softwrap/mapping/EditorPosition.java @@ -23,7 +23,6 @@ class EditorPosition implements Cloneable { public int logicalLine; public int offset; public int x; - public char symbol; private final Editor myEditor; @@ -63,7 +62,6 @@ class EditorPosition implements Cloneable { logicalLine = position.logicalLine; offset = position.offset; x = position.x; - symbol = position.symbol; } @Override @@ -72,7 +70,6 @@ class EditorPosition implements Cloneable { result.logicalLine = logicalLine; result.offset = offset; result.x = x; - result.symbol = symbol; return result; } diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/softwrap/mapping/SoftWrapApplianceManager.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/softwrap/mapping/SoftWrapApplianceManager.java index 126373d5d72e..1735201e1c39 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/softwrap/mapping/SoftWrapApplianceManager.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/softwrap/mapping/SoftWrapApplianceManager.java @@ -504,8 +504,7 @@ public class SoftWrapApplianceManager implements Dumpable { */ private int[] offsetToX(int offset, char c) { if (myOffset2widthInPixels.end > offset - && (myOffset2widthInPixels.anchor + myOffset2widthInPixels.end > offset) - && myContext.currentPosition.symbol != '\t'/*we need to recalculate tabulation width after soft wrap*/) + && (myOffset2widthInPixels.anchor + myOffset2widthInPixels.end > offset)) { int width = myOffset2widthInPixels.data[offset - myOffset2widthInPixels.anchor]; return new int[] {myContext.currentPosition.x + width + myContext.getInlaysWidth(), width}; @@ -1235,8 +1234,7 @@ public class SoftWrapApplianceManager implements Dumpable { public void onNonLineFeedSymbol(char c) { int[] metrics; if (myOffset2widthInPixels.end > myContext.currentPosition.offset - && (myOffset2widthInPixels.anchor + myOffset2widthInPixels.end > myContext.currentPosition.offset) - && myContext.currentPosition.symbol != '\t'/*we need to recalculate tabulation width after soft wrap*/) + && (myOffset2widthInPixels.anchor + myOffset2widthInPixels.end > myContext.currentPosition.offset)) { int width = myOffset2widthInPixels.data[myContext.currentPosition.offset - myOffset2widthInPixels.anchor]; diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/editor/impl/RangeIteratorTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/editor/impl/RangeIteratorTest.java deleted file mode 100644 index 859f2ab77f6e..000000000000 --- a/platform/platform-tests/testSrc/com/intellij/openapi/editor/impl/RangeIteratorTest.java +++ /dev/null @@ -1,158 +0,0 @@ -package com.intellij.openapi.editor.impl; - -import com.intellij.openapi.editor.Document; -import com.intellij.openapi.editor.highlighter.HighlighterIterator; -import com.intellij.openapi.editor.markup.TextAttributes; -import com.intellij.openapi.util.Condition; -import com.intellij.openapi.util.Conditions; -import com.intellij.openapi.util.TextRange; -import com.intellij.psi.tree.IElementType; -import gnu.trove.Equality; -import junit.framework.TestCase; - -public class RangeIteratorTest extends TestCase { - private static final Equality ALL_EQUAL = new DummyEquality(true); - private static final Equality ALL_DIFFERENT = new DummyEquality(false); - private static final RangeIterator.Gaps NO_GAPS = new RangeIterator.Gaps() { - @Override - public boolean isGapAt(int offset) { - return false; - } - }; - private static final RangeIterator.Gaps MY_GAPS = new RangeIterator.Gaps() { - @Override - public boolean isGapAt(int offset) { - return 3 <= offset && offset < 6; - } - }; - private static final Condition ANY = Conditions.alwaysTrue(); - - public void testExpanded() { - RangeIterator iterator = createIterator(ALL_EQUAL, NO_GAPS); - checkPosition(iterator, 2, 4); - iterator.advance(); - checkPosition(iterator, 5, 9); - assertTrue(iterator.atEnd()); - } - - public void testCollapsed() { - RangeIterator iterator = createIterator(ALL_EQUAL, MY_GAPS); - checkPosition(iterator, 2, 3); - iterator.advance(); - checkPosition(iterator, 6, 9); - assertTrue(iterator.atEnd()); - } - - public void testDifferentExpanded() { - RangeIterator iterator = createIterator(ALL_DIFFERENT, NO_GAPS); - checkPosition(iterator, 2, 4); - iterator.advance(); - checkPosition(iterator, 5, 7); - assertFalse(iterator.atEnd()); - iterator.advance(); - checkPosition(iterator, 7, 9); - assertTrue(iterator.atEnd()); - } - - public void testEndInFolding() { - RangeIterator iterator = createIterator(ALL_EQUAL, new int[]{1}, new int[]{5}, MY_GAPS); - checkPosition(iterator, 1, 3); - assertTrue(iterator.atEnd()); - } - - public void testDividedByFolding() { - RangeIterator iterator = createIterator(ALL_EQUAL, new int[]{1}, new int[]{9}, MY_GAPS); - checkPosition(iterator, 1, 3); - iterator.advance(); - checkPosition(iterator, 6, 9); - assertTrue(iterator.atEnd()); - } - - public void testAllFolded() { - RangeIterator iterator = new RangeIterator(MY_GAPS, ALL_EQUAL, - new MyHighlighterIterator(new int[]{4}, new int[]{5}), ANY); - iterator.init(new TextRange(0, Integer.MAX_VALUE)); - assertTrue(iterator.atEnd()); - } - - private void checkPosition(RangeIterator iterator, int start, int end) { - assertEquals(start, iterator.getStart()); - assertEquals(end, iterator.getEnd()); - } - - private RangeIterator createIterator(Equality equality, RangeIterator.Gaps gaps) { - return createIterator(equality, new int[]{2, 5, 7}, new int[]{4, 7, 9}, gaps); - } - - private RangeIterator createIterator(Equality equality, int[] starts, int[] ends, RangeIterator.Gaps gaps) { - RangeIterator iterator = new RangeIterator(gaps, equality, - new MyHighlighterIterator(starts, ends), ANY); - iterator.init(new TextRange(0, Integer.MAX_VALUE)); - iterator.advance(); - return iterator; - } - - private static class MyHighlighterIterator implements HighlighterIterator { - private final int[] myStarts; - private final int[] myEnds; - private int myIndex = 0; - - public MyHighlighterIterator(int[] starts, int[] ends) { - myStarts = starts; - myEnds = ends; - } - - @Override - public TextAttributes getTextAttributes() { - return null; - } - - @Override - public IElementType getTokenType() { - throw new UnsupportedOperationException(); - } - - @Override - public void advance() { - myIndex++; - } - - @Override - public int getEnd() { - return myEnds[myIndex]; - } - - @Override - public int getStart() { - return myStarts[myIndex]; - } - - @Override - public boolean atEnd() { - return myIndex == myStarts.length; - } - - @Override - public Document getDocument() { - throw new UnsupportedOperationException(); - } - - @Override - public void retreat() { - throw new UnsupportedOperationException(); - } - } - - private static class DummyEquality implements Equality { - private final boolean myResult; - - public DummyEquality(boolean result) { - myResult = result; - } - - @Override - public boolean equals(Object o1, Object o2) { - return myResult; - } - } -}