diff options
author | Kevin Barnes | 2006-06-19 14:10:05 +0000 |
---|---|---|
committer | Kevin Barnes | 2006-06-19 14:10:05 +0000 |
commit | 10f519aa789ec4c925702bceaf5d9cef73edc586 (patch) | |
tree | 0d704a9ec19dc958cc4a48415d704f06a5f34ff0 /org.eclipse.ui.console/src/org/eclipse/ui/internal | |
parent | 68ea8b9f87b80976f1be951d98e106cadacf53fc (diff) | |
download | eclipse.platform.debug-10f519aa789ec4c925702bceaf5d9cef73edc586.tar.gz eclipse.platform.debug-10f519aa789ec4c925702bceaf5d9cef73edc586.tar.xz eclipse.platform.debug-10f519aa789ec4c925702bceaf5d9cef73edc586.zip |
Bug 90768 - [console] Java Stack Trace Console: Option to format per default
Diffstat (limited to 'org.eclipse.ui.console/src/org/eclipse/ui/internal')
-rw-r--r-- | org.eclipse.ui.console/src/org/eclipse/ui/internal/console/ConsolePatternMatcher.java | 213 |
1 files changed, 107 insertions, 106 deletions
diff --git a/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/ConsolePatternMatcher.java b/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/ConsolePatternMatcher.java index beaa94c9b..b93c63dea 100644 --- a/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/ConsolePatternMatcher.java +++ b/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/ConsolePatternMatcher.java @@ -60,106 +60,107 @@ public class ConsolePatternMatcher implements IDocumentListener { * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor) */ protected IStatus run(IProgressMonitor monitor) { - IDocument doc = fConsole.getDocument(); - String text = null; - int prevBaseOffset = -1; - if (doc != null && !monitor.isCanceled()) { - int endOfSearch = doc.getLength(); - int indexOfLastChar = endOfSearch; - if (indexOfLastChar > 0) { - indexOfLastChar--; - } - int lastLineToSearch = 0; - int offsetOfLastLineToSearch = 0; - try { - lastLineToSearch = doc.getLineOfOffset(indexOfLastChar); - offsetOfLastLineToSearch = doc.getLineOffset(lastLineToSearch); - } catch (BadLocationException e) { - // perhaps the buffer was re-set - return Status.OK_STATUS; - } - for (int i = 0; i < fPatterns.size(); i++) { - if (monitor.isCanceled()) { - break; - } - CompiledPatternMatchListener notifier = (CompiledPatternMatchListener) fPatterns.get(i); - int baseOffset = notifier.end; - int lengthToSearch = endOfSearch - baseOffset; - if (lengthToSearch > 0) { - try { - if (prevBaseOffset != baseOffset) { - // reuse the text string if possible - text = doc.get(baseOffset, lengthToSearch); - } - Matcher reg = notifier.pattern.matcher(text); - Matcher quick = null; - if (notifier.qualifier != null) { - quick = notifier.qualifier.matcher(text); - } - int startOfNextSearch = 0; - int endOfLastMatch = -1; - int lineOfLastMatch = -1; - while ((startOfNextSearch < lengthToSearch) && !monitor.isCanceled()) { - if (quick != null) { - if (quick.find(startOfNextSearch)) { - // start searching on the beginning - // of the line where the potential - // match was found, or after the - // last match on the same line - int matchLine = doc.getLineOfOffset(baseOffset + quick.start()); - if (lineOfLastMatch == matchLine) { - startOfNextSearch = endOfLastMatch; - } else { - startOfNextSearch = doc.getLineOffset(matchLine) - baseOffset; - } - } else { - startOfNextSearch = lengthToSearch; - } - } - if (startOfNextSearch < 0) { - startOfNextSearch = 0; - } - if (startOfNextSearch < lengthToSearch) { - if (reg.find(startOfNextSearch)) { - endOfLastMatch = reg.end(); - lineOfLastMatch = doc.getLineOfOffset(baseOffset + endOfLastMatch - 1); - int regStart = reg.start(); - IPatternMatchListener listener = notifier.listener; - if (listener != null && !monitor.isCanceled()) { - listener.matchFound(new PatternMatchEvent(fConsole, baseOffset + regStart, endOfLastMatch - regStart)); - } - startOfNextSearch = endOfLastMatch; - } else { - startOfNextSearch = lengthToSearch; - } - } - } - // update start of next search to the last line - // searched - // or the end of the last match if it was on the - // line that - // was last searched - if (lastLineToSearch == lineOfLastMatch) { - notifier.end = baseOffset + endOfLastMatch; - } else { - notifier.end = offsetOfLastLineToSearch; - } - } catch (BadLocationException e) { - ConsolePlugin.log(e); - } - } - prevBaseOffset = baseOffset; - } - } - - if (fFinalMatch) { - disconnect(); - fConsole.matcherFinished(); - } else if (fScheduleFinal) { - fFinalMatch = true; - schedule(); - } - + IDocument doc = fConsole.getDocument(); + synchronized (doc) { + String text = null; + int prevBaseOffset = -1; + if (doc != null && !monitor.isCanceled()) { + int endOfSearch = doc.getLength(); + int indexOfLastChar = endOfSearch; + if (indexOfLastChar > 0) { + indexOfLastChar--; + } + int lastLineToSearch = 0; + int offsetOfLastLineToSearch = 0; + try { + lastLineToSearch = doc.getLineOfOffset(indexOfLastChar); + offsetOfLastLineToSearch = doc.getLineOffset(lastLineToSearch); + } catch (BadLocationException e) { + // perhaps the buffer was re-set + return Status.OK_STATUS; + } + for (int i = 0; i < fPatterns.size(); i++) { + if (monitor.isCanceled()) { + break; + } + CompiledPatternMatchListener notifier = (CompiledPatternMatchListener) fPatterns.get(i); + int baseOffset = notifier.end; + int lengthToSearch = endOfSearch - baseOffset; + if (lengthToSearch > 0) { + try { + if (prevBaseOffset != baseOffset) { + // reuse the text string if possible + text = doc.get(baseOffset, lengthToSearch); + } + Matcher reg = notifier.pattern.matcher(text); + Matcher quick = null; + if (notifier.qualifier != null) { + quick = notifier.qualifier.matcher(text); + } + int startOfNextSearch = 0; + int endOfLastMatch = -1; + int lineOfLastMatch = -1; + while ((startOfNextSearch < lengthToSearch) && !monitor.isCanceled()) { + if (quick != null) { + if (quick.find(startOfNextSearch)) { + // start searching on the beginning + // of the line where the potential + // match was found, or after the + // last match on the same line + int matchLine = doc.getLineOfOffset(baseOffset + quick.start()); + if (lineOfLastMatch == matchLine) { + startOfNextSearch = endOfLastMatch; + } else { + startOfNextSearch = doc.getLineOffset(matchLine) - baseOffset; + } + } else { + startOfNextSearch = lengthToSearch; + } + } + if (startOfNextSearch < 0) { + startOfNextSearch = 0; + } + if (startOfNextSearch < lengthToSearch) { + if (reg.find(startOfNextSearch)) { + endOfLastMatch = reg.end(); + lineOfLastMatch = doc.getLineOfOffset(baseOffset + endOfLastMatch - 1); + int regStart = reg.start(); + IPatternMatchListener listener = notifier.listener; + if (listener != null && !monitor.isCanceled()) { + listener.matchFound(new PatternMatchEvent(fConsole, baseOffset + regStart, endOfLastMatch - regStart)); + } + startOfNextSearch = endOfLastMatch; + } else { + startOfNextSearch = lengthToSearch; + } + } + } + // update start of next search to the last line + // searched + // or the end of the last match if it was on the + // line that + // was last searched + if (lastLineToSearch == lineOfLastMatch) { + notifier.end = baseOffset + endOfLastMatch; + } else { + notifier.end = offsetOfLastLineToSearch; + } + } catch (BadLocationException e) { + ConsolePlugin.log(e); + } + } + prevBaseOffset = baseOffset; + } + } + + if (fFinalMatch) { + disconnect(); + fConsole.matcherFinished(); + } else if (fScheduleFinal) { + fFinalMatch = true; + schedule(); + } + } return Status.OK_STATUS; } @@ -195,12 +196,12 @@ public class ConsolePatternMatcher implements IDocumentListener { } /** - * Adds the given pattern match listener to this console. The listener will - * be connected and receive match notifications. - * - * @param matchListener - * the pattern match listener to add - */ + * Adds the given pattern match listener to this console. The listener will + * be connected and receive match notifications. + * + * @param matchListener + * the pattern match listener to add + */ public void addPatternMatchListener(IPatternMatchListener matchListener) { synchronized (fPatterns) { |