Skip to main content
aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorAndrey Mozzhuhin2020-04-13 18:32:45 +0000
committerAndrey Mozzhuhin2020-04-13 18:32:45 +0000
commita145e695c0939c546f33d48e9f95dcdf993e477c (patch)
treec0725eaf87aad56d2bb006673cd5d6e3a315d87e /core
parent2a075e3ec8c77af1b52017d250b967a02a74e6a7 (diff)
downloadorg.eclipse.cdt-a145e695c0939c546f33d48e9f95dcdf993e477c.tar.gz
org.eclipse.cdt-a145e695c0939c546f33d48e9f95dcdf993e477c.tar.xz
org.eclipse.cdt-a145e695c0939c546f33d48e9f95dcdf993e477c.zip
Bug 516393: Fix scan of double char tokens in CHeuristicScanner
Scanning of double char tokens (::, >>, >=, <<, <=, ->) is broken in nextToken(). In each case, peekNextChar() was used to get second character, but scanner position was already on second char and peekPreviousChar() need to be used. Change-Id: Ibd447c7cde8783e8ffe547d5f9bc09d11c1c60a7 Signed-off-by: Andrey Mozzhuhin <amozzhuhin@yandex.ru>
Diffstat (limited to 'core')
-rw-r--r--core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CHeuristicScannerTest.java16
-rw-r--r--core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CIndenterTest.java13
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CHeuristicScanner.java21
3 files changed, 33 insertions, 17 deletions
diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CHeuristicScannerTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CHeuristicScannerTest.java
index b938ae4d856..1e8ada99eb8 100644
--- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CHeuristicScannerTest.java
+++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CHeuristicScannerTest.java
@@ -21,6 +21,7 @@ import org.eclipse.cdt.core.formatter.DefaultCodeFormatterConstants;
import org.eclipse.cdt.internal.ui.text.CHeuristicScanner;
import org.eclipse.cdt.internal.ui.text.CIndenter;
import org.eclipse.cdt.internal.ui.text.FastCPartitionScanner;
+import org.eclipse.cdt.internal.ui.text.Symbols;
import org.eclipse.cdt.ui.text.ICPartitions;
import org.eclipse.jface.text.Document;
import org.eclipse.jface.text.IDocument;
@@ -678,4 +679,19 @@ public class CHeuristicScannerTest extends TestCase {
String indent = fScanner.computeIndentation(fDocument.getLength() - 8).toString();
Assert.assertEquals(" ", indent);
}
+
+ public void testNextTokenDoubleChar() throws Exception {
+ fDocument.set("::");
+ assertEquals(fHeuristicScanner.nextToken(0, fDocument.getLength() - 1), Symbols.TokenDOUBLECOLON);
+ fDocument.set("<<");
+ assertEquals(fHeuristicScanner.nextToken(0, fDocument.getLength() - 1), Symbols.TokenSHIFTLEFT);
+ fDocument.set("<=");
+ assertEquals(fHeuristicScanner.nextToken(0, fDocument.getLength() - 1), Symbols.TokenOTHER);
+ fDocument.set(">>");
+ assertEquals(fHeuristicScanner.nextToken(0, fDocument.getLength() - 1), Symbols.TokenSHIFTRIGHT);
+ fDocument.set(">=");
+ assertEquals(fHeuristicScanner.nextToken(0, fDocument.getLength() - 1), Symbols.TokenOTHER);
+ fDocument.set("->");
+ assertEquals(fHeuristicScanner.nextToken(0, fDocument.getLength() - 1), Symbols.TokenARROW);
+ }
}
diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CIndenterTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CIndenterTest.java
index c0d5ad56c9c..aee44827c18 100644
--- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CIndenterTest.java
+++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CIndenterTest.java
@@ -1054,4 +1054,17 @@ public class CIndenterTest extends BaseUITestCase {
public void testIndentationAfterFunctionHeaderWithReturnTypeTemplateSpecification_Bug537568() throws Exception {
assertIndenterResult();
}
+
+ //MyFunctionCall(::My::Namespace::MyType::Value1,
+ //var1,
+ //::My::Namespace::MyType::Value2,
+ //var2);
+
+ //MyFunctionCall(::My::Namespace::MyType::Value1,
+ // var1,
+ // ::My::Namespace::MyType::Value2,
+ // var2);
+ public void testIndentationAfterArgumentWithQualifier_Bug516393() throws Exception {
+ assertIndenterResult(); // global scope
+ }
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CHeuristicScanner.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CHeuristicScanner.java
index 02f7af3cad5..75f95b6128f 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CHeuristicScanner.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CHeuristicScanner.java
@@ -347,7 +347,7 @@ public final class CHeuristicScanner implements Symbols {
case SEMICOLON:
return TokenSEMICOLON;
case COLON:
- switch (peekNextChar()) {
+ switch (peekPreviousChar()) {
case COLON:
++fPos;
return TokenDOUBLECOLON;
@@ -360,7 +360,7 @@ public final class CHeuristicScanner implements Symbols {
case EQUAL:
return TokenEQUAL;
case LANGLE:
- switch (peekNextChar()) {
+ switch (peekPreviousChar()) {
case LANGLE:
++fPos;
return TokenSHIFTLEFT;
@@ -370,7 +370,7 @@ public final class CHeuristicScanner implements Symbols {
}
return TokenLESSTHAN;
case RANGLE:
- switch (peekNextChar()) {
+ switch (peekPreviousChar()) {
case RANGLE:
++fPos;
return TokenSHIFTRIGHT;
@@ -382,7 +382,7 @@ public final class CHeuristicScanner implements Symbols {
case DOT:
return TokenDOT;
case MINUS:
- switch (peekNextChar()) {
+ switch (peekPreviousChar()) {
case RANGLE:
++fPos;
return TokenARROW;
@@ -520,19 +520,6 @@ public final class CHeuristicScanner implements Symbols {
}
/**
- * @return the next char without shifting the position
- */
- private char peekNextChar() {
- if (fPos + 1 < fDocument.getLength()) {
- try {
- return fDocument.getChar(fPos + 1);
- } catch (BadLocationException exc) {
- }
- }
- return (char) -1;
- }
-
- /**
* @return the previous char without shifting the position
*/
private char peekPreviousChar() {

Back to the top