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 d7482b19713..b771b1570a8 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 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2008 IBM Corporation and others. + * Copyright (c) 2004, 2009 IBM Corporation 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 @@ -196,7 +196,7 @@ public class SimpleScanner { digit = c - 'A' + 10; break; default: - ungetChar(c); + internalUngetChar(c); return unicode; } fUniversalCharBuffer.append((char) c); @@ -205,16 +205,21 @@ public class SimpleScanner { } while (true); } + private void internalUngetChar(int c) { + fTokenBuffer.deleteCharAt(fTokenBuffer.length() - 1); + fContext.pushUndo(c); + } + protected void ungetChar(int c) { - if (c < 256) { - fTokenBuffer.deleteCharAt(fTokenBuffer.length() - 1); - fContext.pushUndo(c); - } else { + if (c < 256 || c == fTokenBuffer.charAt(fTokenBuffer.length() - 1)) { + internalUngetChar(c); + } else if (fUniversalCharBuffer.length() > 0) { char[] chs = fUniversalCharBuffer.toString().toCharArray(); for (int i = chs.length-1; i >= 0; --i) { - fTokenBuffer.deleteCharAt(fTokenBuffer.length() - 1); - fContext.pushUndo(chs[i]); + internalUngetChar(chs[i]); } + } else { + internalUngetChar(c); } } diff --git a/core/org.eclipse.cdt.ui.tests/.settings/org.eclipse.core.resources.prefs b/core/org.eclipse.cdt.ui.tests/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 00000000000..3c7055fe9e9 --- /dev/null +++ b/core/org.eclipse.cdt.ui.tests/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,3 @@ +#Thu Apr 23 17:28:18 CEST 2009 +eclipse.preferences.version=1 +encoding//ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java=UTF-8 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 e439be50179..622a66b8bc9 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 @@ -1167,7 +1167,7 @@ public class CodeFormatterTest extends BaseUITestCase { public void testFormatterProblemsWithTypename_Bug269590() throws Exception { assertFormatterResult(); } - + //void //foo(); //int* @@ -1180,4 +1180,22 @@ public class CodeFormatterTest extends BaseUITestCase { public void testPreserveNewlineBetweenTypeAndFunctionDeclarator() throws Exception { assertFormatterResult(); } + + //class 大大大大 + //{ + //public: + // 大大大大(); + // virtual ~大大大大(); + //}; + + //class 大大大大 + //{ + //public: + // 大大大大(); + // virtual ~大大大大(); + //}; + public void testFormatGeneratedClass_Bug272006() throws Exception { + assertFormatterResult(); + } + }