mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-09 10:46:02 +02:00
Fix for 232739: [code formatter] Wrong indent after single line comment
This commit is contained in:
parent
97faacee3a
commit
b7b12ba6d8
2 changed files with 89 additions and 16 deletions
|
@ -234,35 +234,43 @@ public class SimpleScanner {
|
|||
|
||||
c = getChar();
|
||||
|
||||
if (c == 'x') {
|
||||
if (!firstCharZero && floatingPoint) {
|
||||
ungetChar(c);
|
||||
return newToken(Token.tDOT);
|
||||
}
|
||||
if (firstCharZero && c == 'x') {
|
||||
hex = true;
|
||||
c = getChar();
|
||||
}
|
||||
|
||||
int digits= 0;
|
||||
|
||||
while ((c >= '0' && c <= '9') || (hex && ((c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F')))) {
|
||||
++digits;
|
||||
c = getChar();
|
||||
}
|
||||
|
||||
if (c == '.') {
|
||||
if (floatingPoint || hex) {
|
||||
if (fTokenBuffer.toString().equals("..") && getChar() == '.') //$NON-NLS-1$
|
||||
if (!hex && c == '.') {
|
||||
if (floatingPoint && digits == 0) {
|
||||
// encountered ..
|
||||
if ((c= getChar()) == '.') {
|
||||
return newToken(Token.tELIPSE);
|
||||
} else {
|
||||
ungetChar(c);
|
||||
ungetChar('.');
|
||||
return newToken(Token.tDOT);
|
||||
}
|
||||
}
|
||||
|
||||
floatingPoint = true;
|
||||
c = getChar();
|
||||
while ((c >= '0' && c <= '9')) {
|
||||
++digits;
|
||||
c = getChar();
|
||||
}
|
||||
}
|
||||
|
||||
if (c == 'e' || c == 'E') {
|
||||
if (!floatingPoint)
|
||||
if (!hex && digits > 0 && (c == 'e' || c == 'E')) {
|
||||
if (!floatingPoint) {
|
||||
floatingPoint = true;
|
||||
}
|
||||
|
||||
// exponent type for floating point
|
||||
c = getChar();
|
||||
|
||||
|
@ -282,10 +290,15 @@ public class SimpleScanner {
|
|||
}
|
||||
} else {
|
||||
if (floatingPoint) {
|
||||
//floating-suffix
|
||||
if (c == 'l' || c == 'L' || c == 'f' || c == 'F') {
|
||||
c = getChar();
|
||||
}
|
||||
if (digits > 0) {
|
||||
//floating-suffix
|
||||
if (c == 'l' || c == 'L' || c == 'f' || c == 'F') {
|
||||
c = getChar();
|
||||
}
|
||||
} else {
|
||||
ungetChar(c);
|
||||
return newToken(Token.tDOT);
|
||||
}
|
||||
} else {
|
||||
//integer suffix
|
||||
if (c == 'u' || c == 'U') {
|
||||
|
|
|
@ -646,4 +646,64 @@ public class CodeFormatterTest extends BaseUITestCase {
|
|||
assertFormatterResult();
|
||||
}
|
||||
|
||||
//struct { int l; } s;
|
||||
//void f() {
|
||||
// int x = (s.l -5);
|
||||
// // Comment
|
||||
// for(;;);
|
||||
//}
|
||||
|
||||
//struct {
|
||||
// int l;
|
||||
//} s;
|
||||
//void f() {
|
||||
// int x = (s.l - 5);
|
||||
// // Comment
|
||||
// for (;;)
|
||||
// ;
|
||||
//}
|
||||
public void testIndentAfterDotL_Bug232739() throws Exception {
|
||||
assertFormatterResult();
|
||||
}
|
||||
|
||||
//struct { int e; } s;
|
||||
//void f() {
|
||||
// int x = (s.e -5);
|
||||
// // Comment
|
||||
// for(;;);
|
||||
//}
|
||||
|
||||
//struct {
|
||||
// int e;
|
||||
//} s;
|
||||
//void f() {
|
||||
// int x = (s.e - 5);
|
||||
// // Comment
|
||||
// for (;;)
|
||||
// ;
|
||||
//}
|
||||
public void testIndentAfterDotE_Bug232739() throws Exception {
|
||||
assertFormatterResult();
|
||||
}
|
||||
|
||||
//struct { int f; } s;
|
||||
//void f() {
|
||||
// int x = (s.f -5);
|
||||
// // Comment
|
||||
// for(;;);
|
||||
//}
|
||||
|
||||
//struct {
|
||||
// int f;
|
||||
//} s;
|
||||
//void f() {
|
||||
// int x = (s.f - 5);
|
||||
// // Comment
|
||||
// for (;;)
|
||||
// ;
|
||||
//}
|
||||
public void testIndentAfterDotF_Bug232739() throws Exception {
|
||||
assertFormatterResult();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue