diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CIndenterTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CIndenterTest.java index 85622a20f79..17e3b6e18ac 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CIndenterTest.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CIndenterTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2009 Wind River Systems, Inc. and others. + * Copyright (c) 2007, 2010 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 @@ -42,12 +42,14 @@ public class CIndenterTest extends BaseUITestCase { return suite(CIndenterTest.class, "_"); } + @Override protected void setUp() throws Exception { super.setUp(); fDefaultOptions= DefaultCodeFormatterOptions.getDefaultSettings().getMap(); fOptions= new HashMap(); } + @Override protected void tearDown() throws Exception { CCorePlugin.setOptions(new HashMap(fDefaultOptions)); super.tearDown(); @@ -795,4 +797,57 @@ public class CIndenterTest extends BaseUITestCase { fOptions.put(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, CCorePlugin.TAB); assertIndenterResult(); } + + //extern "C" { + // int a; + //} + + //extern "C" { + //int a; + //} + public void testIndentationInsideLinkageSpec_Bug299482() throws Exception { + assertIndenterResult(); + } + + //void t() const + //{ + //} + + //void t() const + //{ + //} + public void testIndentationOfConstMethodBody_Bug298282() throws Exception { + assertIndenterResult(); + } + + //class A { + //int f,g; + //A():f(0) + //{ + //} + //A():f(0),g(0) + //{ + //} + //A():f(0), + //g(0) + //{ + //} + //}; + + //class A { + // int f,g; + // A():f(0) + // { + // } + // A():f(0),g(0) + // { + // } + // A():f(0), + // g(0) + // { + // } + //}; + public void testIndentationOfConstructorBodyWithFieldInitializer_Bug298282() throws Exception { + assertIndenterResult(); + } } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CHeuristicScanner.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CHeuristicScanner.java index 2d632d723ea..09f80650249 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CHeuristicScanner.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CHeuristicScanner.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. + * Copyright (c) 2000, 2010 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 @@ -605,6 +605,8 @@ public final class CHeuristicScanner implements Symbols { return TokenSTRUCT; if ("switch".equals(s)) //$NON-NLS-1$ return TokenSWITCH; + if ("extern".equals(s)) //$NON-NLS-1$ + return TokenEXTERN; break; case 7: if ("default".equals(s)) //$NON-NLS-1$ diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CIndenter.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CIndenter.java index 8c118db7a36..d57a5c6de76 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CIndenter.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CIndenter.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. + * Copyright (c) 2000, 2010 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 @@ -1049,6 +1049,13 @@ public final class CIndenter { case Symbols.TokenTRY: return skipToStatementStart(danglingElse, false); + case Symbols.TokenCONST: + nextToken(); + if (fToken != Symbols.TokenRPAREN) { + return skipToPreviousListItemOrListStart(); + } + // could be const method decl + //$FALL-THROUGH$ case Symbols.TokenRPAREN: if (skipScope(Symbols.TokenLPAREN, Symbols.TokenRPAREN)) { int scope= fPosition; @@ -1756,7 +1763,7 @@ public final class CIndenter { return setFirstElementAlignment(pos, bound); else fIndent= fPrefs.prefArrayIndent; - } else if (isNamespace()) { + } else if (isNamespace() || isLinkageSpec()) { fIndent= fPrefs.prefNamespaceBodyIndent; } else { int typeDeclPos = matchTypeDeclaration(); @@ -1856,16 +1863,30 @@ public final class CIndenter { * @return true if the next elements look like the start of a namespace declaration. */ private boolean isNamespace() { - int pos = fPosition; if (fToken == Symbols.TokenNAMESPACE) { return true; // Anonymous namespace } else if (fToken == Symbols.TokenIDENT) { + int pos = fPosition; + int token = fToken; nextToken(); // Get previous token if (fToken == Symbols.TokenNAMESPACE) { return true; // Named namespace } + fToken = token; + fPosition = pos; + } + return false; + } + + /** + * Returns true if the current token is keyword "extern". + * + * @return true if the next elements look like the start of a linkage spec. + */ + private boolean isLinkageSpec() { + if (fToken == Symbols.TokenEXTERN) { + return true; } - fPosition = pos; return false; } @@ -2062,6 +2083,15 @@ public final class CIndenter { return true; } break; + case Symbols.TokenCOMMA: + nextToken(); + if (fToken == Symbols.TokenRPAREN) { + // field initializer + if (skipScope()) { + return looksLikeMethodDecl(); + } + } + break; case Symbols.TokenCOLON: nextToken(); switch (fToken) { @@ -2073,6 +2103,7 @@ public final class CIndenter { case Symbols.TokenRPAREN: // constructor initializer if (skipScope()) { + pos = fPosition; nextToken(); // optional throw if (fToken == Symbols.TokenTHROW) { @@ -2080,6 +2111,8 @@ public final class CIndenter { if (fToken != Symbols.TokenRPAREN || !skipScope()) { return false; } + } else { + fPosition = pos; } return looksLikeMethodDecl(); } @@ -2143,7 +2176,7 @@ public final class CIndenter { nextToken(); while (fToken == Symbols.TokenOTHER) { // dot of qualification nextToken(); - if (fToken != Symbols.TokenIDENT) // qualificating name + if (fToken != Symbols.TokenIDENT) // qualifying name return false; nextToken(); } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/Symbols.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/Symbols.java index 13408f383d2..2e5b432f436 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/Symbols.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/Symbols.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2007 IBM Corporation and others. + * Copyright (c) 2000, 2010 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 @@ -66,5 +66,6 @@ public interface Symbols { int TokenOPERATOR= 1034; int TokenTHROW= 1035; int TokenCONST= 1036; + int TokenEXTERN= 1037; int TokenIDENT= 2000; }