mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-21 21:52:10 +02:00
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>
This commit is contained in:
parent
2a075e3ec8
commit
a145e695c0
3 changed files with 33 additions and 17 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
@ -519,19 +519,6 @@ public final class CHeuristicScanner implements Symbols {
|
|||
return TokenOTHER;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
|
|
Loading…
Add table
Reference in a new issue