mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-22 06:02:11 +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.CHeuristicScanner;
|
||||||
import org.eclipse.cdt.internal.ui.text.CIndenter;
|
import org.eclipse.cdt.internal.ui.text.CIndenter;
|
||||||
import org.eclipse.cdt.internal.ui.text.FastCPartitionScanner;
|
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.cdt.ui.text.ICPartitions;
|
||||||
import org.eclipse.jface.text.Document;
|
import org.eclipse.jface.text.Document;
|
||||||
import org.eclipse.jface.text.IDocument;
|
import org.eclipse.jface.text.IDocument;
|
||||||
|
@ -678,4 +679,19 @@ public class CHeuristicScannerTest extends TestCase {
|
||||||
String indent = fScanner.computeIndentation(fDocument.getLength() - 8).toString();
|
String indent = fScanner.computeIndentation(fDocument.getLength() - 8).toString();
|
||||||
Assert.assertEquals(" ", indent);
|
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 {
|
public void testIndentationAfterFunctionHeaderWithReturnTypeTemplateSpecification_Bug537568() throws Exception {
|
||||||
assertIndenterResult();
|
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:
|
case SEMICOLON:
|
||||||
return TokenSEMICOLON;
|
return TokenSEMICOLON;
|
||||||
case COLON:
|
case COLON:
|
||||||
switch (peekNextChar()) {
|
switch (peekPreviousChar()) {
|
||||||
case COLON:
|
case COLON:
|
||||||
++fPos;
|
++fPos;
|
||||||
return TokenDOUBLECOLON;
|
return TokenDOUBLECOLON;
|
||||||
|
@ -360,7 +360,7 @@ public final class CHeuristicScanner implements Symbols {
|
||||||
case EQUAL:
|
case EQUAL:
|
||||||
return TokenEQUAL;
|
return TokenEQUAL;
|
||||||
case LANGLE:
|
case LANGLE:
|
||||||
switch (peekNextChar()) {
|
switch (peekPreviousChar()) {
|
||||||
case LANGLE:
|
case LANGLE:
|
||||||
++fPos;
|
++fPos;
|
||||||
return TokenSHIFTLEFT;
|
return TokenSHIFTLEFT;
|
||||||
|
@ -370,7 +370,7 @@ public final class CHeuristicScanner implements Symbols {
|
||||||
}
|
}
|
||||||
return TokenLESSTHAN;
|
return TokenLESSTHAN;
|
||||||
case RANGLE:
|
case RANGLE:
|
||||||
switch (peekNextChar()) {
|
switch (peekPreviousChar()) {
|
||||||
case RANGLE:
|
case RANGLE:
|
||||||
++fPos;
|
++fPos;
|
||||||
return TokenSHIFTRIGHT;
|
return TokenSHIFTRIGHT;
|
||||||
|
@ -382,7 +382,7 @@ public final class CHeuristicScanner implements Symbols {
|
||||||
case DOT:
|
case DOT:
|
||||||
return TokenDOT;
|
return TokenDOT;
|
||||||
case MINUS:
|
case MINUS:
|
||||||
switch (peekNextChar()) {
|
switch (peekPreviousChar()) {
|
||||||
case RANGLE:
|
case RANGLE:
|
||||||
++fPos;
|
++fPos;
|
||||||
return TokenARROW;
|
return TokenARROW;
|
||||||
|
@ -519,19 +519,6 @@ public final class CHeuristicScanner implements Symbols {
|
||||||
return TokenOTHER;
|
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
|
* @return the previous char without shifting the position
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Add table
Reference in a new issue