summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDeepak Azad2012-04-27 04:18:12 (EDT)
committer Dani Megert2012-04-27 04:18:12 (EDT)
commitd296fedb3fe5c10a96cb32ce002d80bf6842bf7f (patch)
tree2a0be6074e048c4bfa17903446a00c251ce80a4e
parent72bb4cf9da730d3b8477085f13dd46651484f909 (diff)
downloadeclipse.jdt.ui-d296fedb3fe5c10a96cb32ce002d80bf6842bf7f.zip
eclipse.jdt.ui-d296fedb3fe5c10a96cb32ce002d80bf6842bf7f.tar.gz
eclipse.jdt.ui-d296fedb3fe5c10a96cb32ce002d80bf6842bf7f.tar.bz2
Fixed bug 372516: [syntax highlighting] bracket highlighting should alsov20120427-0818I20120428-1230I20120428-0800I20120428-0140I20120427-1000I20120427-0800
work if caret is after the last bracket
-rw-r--r--org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/JavaPairMatcherTest.java18
-rw-r--r--org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/JavaPairMatcher.java15
2 files changed, 25 insertions, 8 deletions
diff --git a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/JavaPairMatcherTest.java b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/JavaPairMatcherTest.java
index 832c052..937d71f 100644
--- a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/JavaPairMatcherTest.java
+++ b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/JavaPairMatcherTest.java
@@ -79,10 +79,12 @@ public class JavaPairMatcherTest extends AbstractPairMatcherTest {
public void testBeforeOpeningMatch() {
IRegion match= fPairMatcher.match(fDocument, 2);
- assertNull(match);
+ assertNotNull(match);
+ assertTrue(match.getOffset() == 2 && match.getLength() == 10);
match= fPairMatcher.match(fDocument, 5);
- assertNull(match);
+ assertNotNull(match);
+ assertTrue(match.getOffset() == 5 && match.getLength() == 4);
}
public void testAfterOpeningMatch() {
@@ -108,10 +110,12 @@ public class JavaPairMatcherTest extends AbstractPairMatcherTest {
public void testAfterClosingMatch() {
IRegion match= fPairMatcher.match(fDocument, 12);
- assertNull(match);
+ assertNotNull(match);
+ assertTrue(match.getOffset() == 2 && match.getLength() == 10);
match= fPairMatcher.match(fDocument, 9);
- assertNull(match);
+ assertNotNull(match);
+ assertTrue(match.getOffset() == 5 && match.getLength() == 4);
}
public void testBeforeClosingMatchWithNL() {
@@ -124,7 +128,8 @@ public class JavaPairMatcherTest extends AbstractPairMatcherTest {
public void testAfterClosingMatchWithNL() {
fDocument.set("x(y\ny)x");
IRegion match= fPairMatcher.match(fDocument, 6);
- assertNull(match);
+ assertNotNull(match);
+ assertTrue(match.getOffset() == 1 && match.getLength() == 5);
}
public void testBeforeClosingMatchWithNLAndSingleLineComment() {
@@ -137,7 +142,8 @@ public class JavaPairMatcherTest extends AbstractPairMatcherTest {
public void testAfterClosingMatchWithNLAndSingleLineComment() {
fDocument.set("x\nx(y\nx //(x\ny)x");
IRegion match= fPairMatcher.match(fDocument, 15);
- assertNull(match);
+ assertNotNull(match);
+ assertTrue(match.getOffset() == 3 && match.getLength() == 12);
}
public void testEnclosingMatch() {
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/JavaPairMatcher.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/JavaPairMatcher.java
index de0ccc3..a97c2ec 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/JavaPairMatcher.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/JavaPairMatcher.java
@@ -52,8 +52,19 @@ public final class JavaPairMatcher extends DefaultCharacterPairMatcher implement
*/
private IRegion performMatch(IDocument document, int offset) throws BadLocationException {
if (offset < 0 || document == null) return null;
- final char prevChar= document.getChar(Math.max(offset - 1, 0));
- final char currChar= document.getChar(offset);
+ char prevChar= document.getChar(Math.max(offset - 1, 0));
+ char currChar= (offset != document.getLength()) ? document.getChar(offset) : Character.MIN_VALUE;
+
+ if (prevChar == '>' && currChar != '>') { //https://bugs.eclipse.org/bugs/show_bug.cgi?id=372516
+ offset--;
+ currChar= prevChar;
+ prevChar= document.getChar(Math.max(offset - 1, 0));
+ } else if (currChar == '<' && (prevChar != '>' && prevChar != '<')) {
+ offset++;
+ prevChar= currChar;
+ currChar= document.getChar(offset);
+ }
+
if ((prevChar == '<' || currChar == '>') && !fHighlightAngularBrackets)
return null;
if (prevChar == '<' && isLessThanOperator(document, offset - 1))