Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDeepak Azad2012-02-15 13:29:59 +0000
committerDani Megert2012-02-15 13:29:59 +0000
commit27da83b9a695fd137ec84f15c00c478813e3394a (patch)
treeccf11fedec6d03509b5c4488bcbede9d2f73944e
parentb8d0417ed59519a46d28cac812ad3b7393dd83e9 (diff)
downloadeclipse.platform.text-27da83b9a695fd137ec84f15c00c478813e3394a.tar.gz
eclipse.platform.text-27da83b9a695fd137ec84f15c00c478813e3394a.tar.xz
eclipse.platform.text-27da83b9a695fd137ec84f15c00c478813e3394a.zip
Polish fix for bug 366400: [preferences][syntax highlighting]v20120215-1329
New preference to always show enclosing brackets
-rw-r--r--org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/AbstractPairMatcherTest.java110
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/source/DefaultCharacterPairMatcher.java11
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/source/ICharacterPairMatcher.java33
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/source/ICharacterPairMatcherExtension.java11
-rw-r--r--org.eclipse.ui.workbench.texteditor/META-INF/MANIFEST.MF2
-rw-r--r--org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/SourceViewerDecorationSupport.java15
6 files changed, 133 insertions, 49 deletions
diff --git a/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/AbstractPairMatcherTest.java b/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/AbstractPairMatcherTest.java
index 9d2aa062c9b..474363f2db1 100644
--- a/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/AbstractPairMatcherTest.java
+++ b/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/AbstractPairMatcherTest.java
@@ -29,6 +29,7 @@ import org.eclipse.jface.text.rules.SingleLineRule;
import org.eclipse.jface.text.rules.Token;
import org.eclipse.jface.text.source.DefaultCharacterPairMatcher;
import org.eclipse.jface.text.source.ICharacterPairMatcher;
+import org.eclipse.jface.text.source.ICharacterPairMatcherExtension;
/**
* Generic test of simple character pair matchers
@@ -83,6 +84,11 @@ public abstract class AbstractPairMatcherTest extends TestCase {
performMatch(matcher, "(% )#");
performMatch(matcher, "[% ]#");
performMatch(matcher, "{% }#");
+
+ performMatch(matcher, "#( % )#");
+ performMatch(matcher, "#[ % ]#");
+ performMatch(matcher, "#{ % }#");
+
matcher.dispose();
}
@@ -98,6 +104,10 @@ public abstract class AbstractPairMatcherTest extends TestCase {
performMatch("()[]{}", "(% )#");
performMatch("()[]{}", "[% ]#");
performMatch("()[]{}", "{% }#");
+
+ performMatch("()[]{}", "#( % )#");
+ performMatch("()[]{}", "#[ % ]#");
+ performMatch("()[]{}", "#{ % }#");
}
/**
@@ -111,6 +121,10 @@ public abstract class AbstractPairMatcherTest extends TestCase {
performMatch(matcher, "#(())%");
performMatch(matcher, "(%())#");
performMatch(matcher, "((%)#)");
+
+ performMatch(matcher, "#(%)#");
+ performMatch(matcher, "#(%())#");
+
matcher.dispose();
}
@@ -146,6 +160,13 @@ public abstract class AbstractPairMatcherTest extends TestCase {
performMatch(matcher, "|c #( c| ) ( |c )% c|");
performMatch(matcher, "|c (% c| ) ( |c )# c|");
performMatch(matcher, "(% |a ) a| |b ) b| |c ) c| )#");
+
+ performMatch(matcher, "#( % |a a| )#");
+ performMatch(matcher, "|b #( % )# b|");
+ performMatch(matcher, "|c #( % c| ) ( |c )# c|");
+ performMatch(matcher, "|c #( c| ) ( |c % )# c|");
+ performMatch(matcher, "#( % |a ) a| |b ) b| |c ) c| )#");
+
matcher.dispose();
}
@@ -163,6 +184,11 @@ public abstract class AbstractPairMatcherTest extends TestCase {
performMatch(matcher, "|c#(c|)(|c)%c|");
performMatch(matcher, "|c(%c|)(|c)#c|");
performMatch(matcher, "(%|a)a||b)b||c)c|)#");
+
+ performMatch(matcher, "|c#(c|)(|%c)#c|");
+ performMatch(matcher, "|c#(c%|)(|c)#c|");
+ performMatch(matcher, "#(%|a)a||b)b||c)c|)#");
+
matcher.dispose();
}
@@ -181,6 +207,20 @@ public abstract class AbstractPairMatcherTest extends TestCase {
performMatch(matcher, "a(b(%c{d(e)f}g[h]i)#j)k");
performMatch(matcher, "a(b(c#{d(e)f}%g[h]i)j)k");
performMatch(matcher, "a(b(c{%d(e)f}#g[h]i)j)k");
+
+ performMatch(matcher, " ( #( ( ( ) ) ( ) % )# ) ");
+ performMatch(matcher, " ( #( % ( ( ) ) ( ) )# ) ");
+ performMatch(matcher, " ( #( { ( ) } [ ] % )# ) ");
+ performMatch(matcher, " ( #( % { ( ) } [ ] )# ) ");
+ performMatch(matcher, " ( ( #{ ( ) % }# [ ] ) ) ");
+ performMatch(matcher, " ( ( #{ % ( ) }# [ ] ) ) ");
+ performMatch(matcher, "a(b#(c(d(e)f)g(h)i%)#j)k");
+ performMatch(matcher, "a(b#(%c(d(e)f)g(h)i)#j)k");
+ performMatch(matcher, "a(b#(c{d(e)f}g[h]i%)#j)k");
+ performMatch(matcher, "a(b#(%c{d(e)f}g[h]i)#j)k");
+ performMatch(matcher, "a(b(c#{d(e)f%}#g[h]i)j)k");
+ performMatch(matcher, "a(b(c#{%d(e)f}#g[h]i)j)k");
+
matcher.dispose();
}
@@ -220,7 +260,7 @@ public abstract class AbstractPairMatcherTest extends TestCase {
protected void performReaderTest(String testString, int expectedPos, int expectedMatch, String expectedString) {
TestCase t0= createTestCase(testString);
assertEquals(expectedPos, t0.fPos);
- assertEquals(expectedMatch, t0.fMatch);
+ assertEquals(expectedMatch, t0.fMatch2);
assertEquals(expectedString, t0.fString);
}
@@ -233,21 +273,27 @@ public abstract class AbstractPairMatcherTest extends TestCase {
protected void performMatch(final ICharacterPairMatcher matcher, final String testCase) {
final TestCase test= createTestCase(testCase);
matcher.clear();
- final IRegion region= matcher.match(test.getDocument(), test.fPos);
- if (test.fMatch == -1) {
- // if no match point has been specified there should be
- // no match
+ final IRegion region;
+
+ if (test.isEnclosingTestCase()) {
+ assertTrue((matcher instanceof ICharacterPairMatcherExtension));
+ ICharacterPairMatcherExtension matcherExtension= (ICharacterPairMatcherExtension)matcher;
+ region= matcherExtension.findEnclosingPeerCharacters(test.getDocument(), test.fPos);
+ } else {
+ region= matcher.match(test.getDocument(), test.fPos);
+ }
+
+ if (test.fMatch2 == -1) {
+ // if no match point has been specified there should be no match
if (region != null) System.out.println(region.getOffset());
assertNull(region);
} else {
assertNotNull(region);
- final boolean isForward= test.fPos > test.fMatch;
+ final boolean isForward= test.isEnclosingTestCase() ? false : test.fPos > test.fMatch2;
assertEquals(isForward, matcher.getAnchor() == ICharacterPairMatcher.RIGHT);
- // If the match is forward, the cursor is one character
- // after the start of the match, so we need to count one
- // step backwards
- final int offset= isForward ? test.getOffset() : test.getOffset() - 1;
- final int length= (isForward && !fCaretInsideMatchedPair) ? test.getLength() : test.getLength() + 1;
+
+ final int offset= (isForward || test.isEnclosingTestCase()) ? test.getOffset() : test.getOffset() - 1;
+ final int length= ((isForward && !fCaretInsideMatchedPair) || test.isEnclosingTestCase()) ? test.getLength() : test.getLength() + 1;
assertEquals(length, region.getLength());
assertEquals(offset, region.getOffset());
}
@@ -269,7 +315,9 @@ public abstract class AbstractPairMatcherTest extends TestCase {
public TestCase createTestCase(String str) {
int pos= str.indexOf("%");
assertFalse(pos == -1);
- int match= str.indexOf("#");
+ int match1= str.indexOf("#");
+ int match2= str.lastIndexOf("#");
+ boolean enclosingTest= match1 != match2;
if (fCaretInsideMatchedPair) {
if (pos - 1 >= 0) {
@@ -280,23 +328,36 @@ public abstract class AbstractPairMatcherTest extends TestCase {
}
}
- // account for the length of the first position marker,
- // if there is one
- if (match != -1 && match < pos) pos -= 1;
- if (pos < match) match -= 1;
+ // account for the length of marker characters
+ if (!enclosingTest) {
+ if (match1 != -1 && match1 < pos)
+ pos-= 1;
+ if (pos < match1)
+ match1-= 1;
+ } else {
+ pos-= 1;
+ match2-= 2;
+ }
+
final String stripped= str.replaceAll("%", "").replaceAll("#", "");
- return new TestCase(stripped, pos, match);
+ return enclosingTest ? new TestCase(stripped, pos, match1, match2) : new TestCase(stripped, pos, match1);
}
private class TestCase {
public final String fString;
- public final int fPos, fMatch;
+
+ public final int fPos, fMatch1, fMatch2;
public TestCase(String string, int pos, int match) {
+ this(string, pos, pos, match);
+ }
+
+ public TestCase(String string, int pos, int match1, int match2) {
fString= string;
fPos= pos;
- fMatch= match;
+ fMatch1= match1;
+ fMatch2= match2;
}
public IDocument getDocument() {
@@ -304,12 +365,17 @@ public abstract class AbstractPairMatcherTest extends TestCase {
}
public int getLength() {
- return Math.abs(fPos - fMatch);
+ return Math.abs(fMatch1 - fMatch2);
}
public int getOffset() {
- if (fPos > fMatch) return fMatch;
- return fPos;
+ if (fMatch1 > fMatch2)
+ return fMatch2;
+ return fMatch1;
+ }
+
+ public boolean isEnclosingTestCase() {
+ return fPos != fMatch1;
}
}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/DefaultCharacterPairMatcher.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/DefaultCharacterPairMatcher.java
index c329c61f04f..64bd558085b 100644
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/DefaultCharacterPairMatcher.java
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/DefaultCharacterPairMatcher.java
@@ -108,18 +108,17 @@ public class DefaultCharacterPairMatcher implements ICharacterPairMatcher, IChar
}
/**
- * @see org.eclipse.jface.text.source.ICharacterPairMatcherExtension#findEnclosingPeerCharacters(org.eclipse.jface.text.IDocument,
- * int)
+ * @see org.eclipse.jface.text.source.ICharacterPairMatcherExtension#findEnclosingPeerCharacters(org.eclipse.jface.text.IDocument, int)
* @since 3.8
*/
- public IRegion findEnclosingPeerCharacters(IDocument doc, int offset) {
- if (doc == null || offset < 0 || offset > doc.getLength())
+ public IRegion findEnclosingPeerCharacters(IDocument document, int offset) {
+ if (document == null || offset < 0 || offset > document.getLength())
return null;
try {
for (int offset1= offset; offset1 >= 0; offset1--) {
- char prevChar= doc.getChar(Math.max(offset1 - 1, 0));
+ char prevChar= document.getChar(Math.max(offset1 - 1, 0));
if (fPairs.contains(prevChar) && fPairs.isStartCharacter(prevChar)) {
- IRegion match= performMatch(doc, offset1);
+ IRegion match= performMatch(document, offset1);
if (match != null) {
int matchOffset= match.getOffset();
int matchLength= match.getLength();
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/ICharacterPairMatcher.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/ICharacterPairMatcher.java
index b969b8fa4c4..6a7e8d9202a 100644
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/ICharacterPairMatcher.java
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/ICharacterPairMatcher.java
@@ -22,6 +22,20 @@ import org.eclipse.jface.text.IRegion;
* character and if it finds one, delivers the minimal region of the document that contains both
* characters.
*
+ * <p>
+ * In order to provide backward compatibility for clients of <code>ICharacterPairMatcher</code>,
+ * extension interfaces are used to provide a means of evolution. The following extension interface
+ * exists:
+ * <ul>
+ * <li>{@link org.eclipse.jface.text.source.ICharacterPairMatcherExtension} since version 3.8
+ * introducing the concept of enclosing peer characters at a caret offset.</li>
+ * </ul>
+ * </p>
+ * <p>
+ * Clients may implement this interface and its extension interface or use the default
+ * implementation provided by <code>DefaultCharacterPairMatcher</code>.
+ * </p>
+ *
* @see org.eclipse.jface.text.source.ICharacterPairMatcherExtension
* @since 2.1
*/
@@ -50,16 +64,17 @@ public interface ICharacterPairMatcher {
void clear();
/**
- * Starting at the given offset, the matcher chooses a character close to this offset.
- * The matcher then searches for the matching peer character of the chosen character
- * and if it finds one, returns the minimal region of the document that contains both characters.
- * It returns <code>null</code> if there is no peer character.
- *
- * @param iDocument the document to work on
- * @param i the start offset
- * @return the minimal region containing the peer characters
+ * Starting at the given offset, the matcher chooses a character close to this offset. The
+ * matcher then searches for the matching peer character of the chosen character and if it finds
+ * one, returns the minimal region of the document that contains both characters. It returns
+ * <code>null</code> if there is no peer character.
+ *
+ * @param document the document to work on
+ * @param offset the start offset
+ * @return the minimal region containing the peer characters and <code>null</code> if there is
+ * no peer character.
*/
- IRegion match(IDocument iDocument, int i);
+ IRegion match(IDocument document, int offset);
/**
* Returns the anchor for the region of the matching peer characters. The anchor
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/ICharacterPairMatcherExtension.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/ICharacterPairMatcherExtension.java
index f5c114b0bfa..1c03e232317 100644
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/ICharacterPairMatcherExtension.java
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/ICharacterPairMatcherExtension.java
@@ -28,11 +28,10 @@ public interface ICharacterPairMatcherExtension {
* Starting at the given offset, the matcher searches for a pair of enclosing peer characters
* and if it finds one, returns the minimal region of the document that contains the pair.
*
- * It returns <code>null</code> if there is no enclosing pair.
- *
- * @param iDocument the document to work on
- * @param i the start offset
- * @return the minimal region containing the peer characters
+ * @param document the document to work on
+ * @param offset the start offset
+ * @return the minimal region containing the peer characters or <code>null</code> if there is no
+ * enclosing pair
*/
- IRegion findEnclosingPeerCharacters(IDocument iDocument, int i);
+ IRegion findEnclosingPeerCharacters(IDocument document, int offset);
}
diff --git a/org.eclipse.ui.workbench.texteditor/META-INF/MANIFEST.MF b/org.eclipse.ui.workbench.texteditor/META-INF/MANIFEST.MF
index f59ad2c22c3..1867c4340cf 100644
--- a/org.eclipse.ui.workbench.texteditor/META-INF/MANIFEST.MF
+++ b/org.eclipse.ui.workbench.texteditor/META-INF/MANIFEST.MF
@@ -24,7 +24,7 @@ Require-Bundle:
org.eclipse.core.runtime;bundle-version="[3.5.0,4.0.0)",
org.eclipse.compare.core;bundle-version="[3.5.0,4.0.0)",
org.eclipse.core.expressions;bundle-version="[3.4.100,4.0.0)",
- org.eclipse.jface.text;bundle-version="[3.7.0,4.0.0)",
+ org.eclipse.jface.text;bundle-version="[3.8.0,4.0.0)",
org.eclipse.ui;bundle-version="[3.5.0,4.0.0)"
Bundle-RequiredExecutionEnvironment: J2SE-1.4
Import-Package: com.ibm.icu.text
diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/SourceViewerDecorationSupport.java b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/SourceViewerDecorationSupport.java
index 4aa6a76c810..5af718038ed 100644
--- a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/SourceViewerDecorationSupport.java
+++ b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/SourceViewerDecorationSupport.java
@@ -465,13 +465,17 @@ public class SourceViewerDecorationSupport {
/**
* Sets the preference keys for the matching character painter.
+ *
+ * <p>
+ * Use {@link #setMatchingCharacterPainterPreferenceKeys(String, String, String, String)} if
+ * highlighting of character at caret location or enclosing peer characters is required.
+ * </p>
+ *
* @param enableKey the preference key for the matching character painter
- * @param colorKey the preference key for the color used by the matching
- * character painter
+ * @param colorKey the preference key for the color used by the matching character painter
*/
public void setMatchingCharacterPainterPreferenceKeys(String enableKey, String colorKey) {
- fMatchingCharacterPainterEnableKey= enableKey;
- fMatchingCharacterPainterColorKey= colorKey;
+ setMatchingCharacterPainterPreferenceKeys(enableKey, colorKey, null, null);
}
/**
@@ -487,7 +491,8 @@ public class SourceViewerDecorationSupport {
* @since 3.8
*/
public void setMatchingCharacterPainterPreferenceKeys(String enableKey, String colorKey, String highlightCharacterAtCaretLocationKey, String enclosingPeerCharactersKey) {
- setMatchingCharacterPainterPreferenceKeys(enableKey, colorKey);
+ fMatchingCharacterPainterEnableKey= enableKey;
+ fMatchingCharacterPainterColorKey= colorKey;
fMatchingCharacterPainterEnclosingPeerCharactersKey= enclosingPeerCharactersKey;
fMatchingCharacterPainterHighlightCharacterAtCaretLocationKey= highlightCharacterAtCaretLocationKey;
}

Back to the top