From b7b12ba6d881c83af2aede45b954e7e7388c212d Mon Sep 17 00:00:00 2001 From: Anton Leherbauer Date: Mon, 19 May 2008 13:11:52 +0000 Subject: [PATCH] Fix for 232739: [code formatter] Wrong indent after single line comment --- .../formatter/scanner/SimpleScanner.java | 45 +++++++++----- .../cdt/ui/tests/text/CodeFormatterTest.java | 60 +++++++++++++++++++ 2 files changed, 89 insertions(+), 16 deletions(-) diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/scanner/SimpleScanner.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/scanner/SimpleScanner.java index 9c516ec7b36..c4fdbb46e94 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/scanner/SimpleScanner.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/scanner/SimpleScanner.java @@ -231,41 +231,49 @@ public class SimpleScanner { boolean hex = false; boolean floatingPoint = c == '.'; boolean firstCharZero = c == '0'; - + 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(); - + // optional + or - if (c == '+' || c == '-') { 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') { diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java index 7ec005fe15b..0b0da03c3b2 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java @@ -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(); + } + }