From 8d86fb4a8f34f2fbed491c1297b79c07b9a86fab Mon Sep 17 00:00:00 2001 From: Anton Leherbauer Date: Thu, 28 May 2009 08:22:59 +0000 Subject: [PATCH] Bug 278118 - Code formatter is confused by some arithmetic expressions --- .../formatter/CodeFormatterVisitor.java | 4 +-- .../formatter/scanner/SimpleScanner.java | 5 +++- .../cdt/ui/tests/text/CodeFormatterTest.java | 25 +++++++++++++++++++ 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java index 0ac31c35f2a..afbba7dbb67 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2008 Wind River Systems, Inc. and others. + * Copyright (c) 2006, 2009 Wind River Systems, Inc. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -2133,7 +2133,7 @@ public class CodeFormatterVisitor extends CPPASTVisitor { private int visit(IASTLiteralExpression node) { if (node.getKind() == IASTLiteralExpression.lk_string_literal) { - // handle concatentation of string literals + // handle concatenation of string literals int token; boolean needSpace= false; final int line= scribe.line; 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 b771b1570a8..0fdcc2b1598 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 @@ -314,7 +314,10 @@ public class SimpleScanner { if (!hex) { if (c == '*') { - return newToken(Token.tDOTSTAR); + if (floatingPoint && digits == 0) { + // encountered .* + return newToken(Token.tDOTSTAR); + } } else if (c == '.') { if (floatingPoint && digits == 0) { // encountered .. 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 be37aafb68e..04146e3d5db 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 @@ -1203,4 +1203,29 @@ public class CodeFormatterTest extends BaseUITestCase { assertFormatterResult(original, expected); } + //void f() { + // Canvas1->MoveTo((50 + (24* 20 ) +xoff) *Scale,(200+yoff)*ScaleY); + // Canvas1->LineTo((67+(24*20) +xoff)*Scale,(200+yoff)*ScaleY); + // Canvas1->MoveTo((50+(24*20) +xoff)*Scale,((200+yoff)*ScaleY)-1); + // Canvas1->LineTo((67+(24*20) +xoff)*Scale,((200+yoff)*ScaleY)-1); + // Canvas1->MoveTo((50+(24*20) +xoff)*Scale,((200+yoff)*ScaleY)+1); + // Canvas1->LineTo((67+(24*20) +xoff)*Scale,((200+yoff)*ScaleY)+1); + //} + + //void f() { + // Canvas1->MoveTo((50 + (24 * 20) + xoff) * Scale, (200 + yoff) * ScaleY); + // Canvas1->LineTo((67 + (24 * 20) + xoff) * Scale, (200 + yoff) * ScaleY); + // Canvas1->MoveTo((50 + (24 * 20) + xoff) * Scale, ((200 + yoff) * ScaleY) + // - 1); + // Canvas1->LineTo((67 + (24 * 20) + xoff) * Scale, ((200 + yoff) * ScaleY) + // - 1); + // Canvas1->MoveTo((50 + (24 * 20) + xoff) * Scale, ((200 + yoff) * ScaleY) + // + 1); + // Canvas1->LineTo((67 + (24 * 20) + xoff) * Scale, ((200 + yoff) * ScaleY) + // + 1); + //} + public void testScannerErrorWithIntegerFollowedByStar_Bug278118() throws Exception { + assertFormatterResult(); + } + }