diff options
author | Paul Pazderski | 2019-08-22 09:50:20 +0000 |
---|---|---|
committer | Paul Pazderski | 2019-11-12 11:28:35 +0000 |
commit | 0ad20a3402532969edd5cab954430b6b6f36f588 (patch) | |
tree | 61dd89ea612f4c4850d1833b52705f6828902987 | |
parent | 3b0243f3a75600c950b60cfc5b17449e5b22c0a2 (diff) | |
download | eclipse.platform.debug-0ad20a3402532969edd5cab954430b6b6f36f588.tar.gz eclipse.platform.debug-0ad20a3402532969edd5cab954430b6b6f36f588.tar.xz eclipse.platform.debug-0ad20a3402532969edd5cab954430b6b6f36f588.zip |
Bug 551935 - Replace usage of deprecated TextUtilities.indexOf with new
MultiStringMatcher
Change-Id: I6ca1bae81e71f12c16e006887c4932c084eb970c
Signed-off-by: Paul Pazderski <paul-eclipse@ppazderski.de>
-rw-r--r-- | org.eclipse.ui.console/src/org/eclipse/ui/internal/console/ConsoleDocumentAdapter.java | 28 | ||||
-rw-r--r-- | org.eclipse.ui.console/src/org/eclipse/ui/internal/console/IOConsolePartitioner.java | 20 |
2 files changed, 27 insertions, 21 deletions
diff --git a/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/ConsoleDocumentAdapter.java b/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/ConsoleDocumentAdapter.java index 64b4616a5..88bc3197c 100644 --- a/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/ConsoleDocumentAdapter.java +++ b/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/ConsoleDocumentAdapter.java @@ -25,8 +25,9 @@ import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.IDocumentAdapter; import org.eclipse.jface.text.IDocumentListener; import org.eclipse.jface.text.IRegion; +import org.eclipse.jface.text.MultiStringMatcher; +import org.eclipse.jface.text.MultiStringMatcher.Match; import org.eclipse.jface.text.Region; -import org.eclipse.jface.text.TextUtilities; import org.eclipse.swt.custom.TextChangeListener; import org.eclipse.swt.custom.TextChangedEvent; import org.eclipse.swt.custom.TextChangingEvent; @@ -80,12 +81,13 @@ public class ConsoleDocumentAdapter implements IDocumentAdapter, IDocumentListen /** Adapted document. */ private IDocument document; /** - * The strings the connected document interprets as line delimiters. + * The matcher to find the legal line delimiters of the connected document in + * some text. <code>null</code> if no document connected. * <p> - * This is usually <code>{ "\r", "\n", "\r\n" }</code>. + * This usually matches <code>{ "\r", "\n", "\r\n" }</code>. * </p> */ - private String[] docLegalLineDelimiters; + private MultiStringMatcher docLegalLineDelimiterMatcher; /** * Number of widget lines in document. If fixed width is disabled it is always @@ -149,12 +151,12 @@ public class ConsoleDocumentAdapter implements IDocumentAdapter, IDocumentListen } document = doc; - docLegalLineDelimiters = null; + docLegalLineDelimiterMatcher = null; updateWidgetOffsets(0); if (doc != null) { doc.addDocumentListener(this); - docLegalLineDelimiters = doc.getLegalLineDelimiters(); + docLegalLineDelimiterMatcher = MultiStringMatcher.create(doc.getLegalLineDelimiters()); } } @@ -441,8 +443,8 @@ public class ConsoleDocumentAdapter implements IDocumentAdapter, IDocumentListen int lastDocLineLengthDiff = -eventLength; int newTextOffset = 0; - int[] result = TextUtilities.indexOf(docLegalLineDelimiters, newText, newTextOffset); - if (result[1] < 0) { + Match newLineMatch = docLegalLineDelimiterMatcher.indexOf(newText, newTextOffset); + if (newLineMatch == null) { // single line insert lastInsertLength = eventOffset - firstWidgetLineOffset + newTextLength; lastDocLineLengthDiff += newTextLength; @@ -456,19 +458,19 @@ public class ConsoleDocumentAdapter implements IDocumentAdapter, IDocumentListen // 3. Last line: everything (including) last line delimiter to end of inserted // text - final int firstInsertLength = result[0]; + final int firstInsertLength = newLineMatch.getOffset(); // newLineCount here is numbers of lines required if text is wrapped -1 because // we start inserting in an existing line and +1 for the first line delimiter we // had found newLineCount = linesIfWrapped(eventOffset - firstWidgetLineOffset + firstInsertLength); while (true) { - newTextOffset = result[0] + docLegalLineDelimiters[result[1]].length(); - result = TextUtilities.indexOf(docLegalLineDelimiters, newText, newTextOffset); - if (result[1] < 0) { + newTextOffset = newLineMatch.getOffset() + newLineMatch.getText().length(); + newLineMatch = docLegalLineDelimiterMatcher.indexOf(newText, newTextOffset); + if (newLineMatch == null) { break; } - final int insertedLineLength = result[0] - newTextOffset; + final int insertedLineLength = newLineMatch.getOffset() - newTextOffset; // new text's middle lines are unaffected from existing content and simply count // as number of lines they need with wrapping newLineCount += linesIfWrapped(insertedLineLength); diff --git a/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/IOConsolePartitioner.java b/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/IOConsolePartitioner.java index ced6e8c1c..79dd58115 100644 --- a/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/IOConsolePartitioner.java +++ b/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/IOConsolePartitioner.java @@ -36,8 +36,9 @@ import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.IDocumentPartitionerExtension; import org.eclipse.jface.text.IRegion; import org.eclipse.jface.text.ITypedRegion; +import org.eclipse.jface.text.MultiStringMatcher; +import org.eclipse.jface.text.MultiStringMatcher.Match; import org.eclipse.jface.text.Region; -import org.eclipse.jface.text.TextUtilities; import org.eclipse.jface.text.TypedRegion; import org.eclipse.swt.custom.StyleRange; import org.eclipse.swt.widgets.Display; @@ -104,8 +105,11 @@ public class IOConsolePartitioner * offset used by updateJob */ private int firstOffset; - /** An array of legal line delimiters. */ - private String[] lld; + /** + * A matcher to search for legal line delimiters in new input. Never + * <code>null</code> but match nothing if no document connected. + */ + private MultiStringMatcher legalLineDelimiterMatcher; private int highWaterMark = -1; private int lowWaterMark = -1; private boolean connected = false; @@ -142,7 +146,7 @@ public class IOConsolePartitioner public void connect(IDocument doc) { document = doc; document.setDocumentPartitioner(this); - lld = document.getLegalLineDelimiters(); + legalLineDelimiterMatcher = MultiStringMatcher.create(document.getLegalLineDelimiters()); partitions = new ArrayList<>(); pendingPartitions = new ArrayList<>(); inputPartitions = new ArrayList<>(); @@ -443,9 +447,9 @@ public class IOConsolePartitioner // process event text in parts split on line delimiters int textOffset = 0; while (textOffset < eventTextLength) { - final int[] result = TextUtilities.indexOf(lld, event.getText(), textOffset); - final boolean foundNewline = result[1] >= 0; - final int newTextOffset = foundNewline ? result[0] + lld[result[1]].length() : eventTextLength; + final Match nextNewline = legalLineDelimiterMatcher.indexOf(event.getText(), textOffset); + final int newTextOffset = nextNewline != null ? nextNewline.getOffset() + nextNewline.getText().length() + : eventTextLength; final int inputLength = newTextOffset - textOffset; if (inputPartition == null || inputPartition.isReadOnly()) { @@ -464,7 +468,7 @@ public class IOConsolePartitioner inputPartition.setLength(inputPartition.getLength() + inputLength); - if (foundNewline) { + if (nextNewline != null) { inputPartitions.sort(CMP_REGION_BY_OFFSET); final StringBuilder inputLine = new StringBuilder(); for (IOConsolePartition p : inputPartitions) { |