mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Bug 298282 - Indentation is not correct for braces, when creating C++ const method and start brace is on on new line
This commit is contained in:
parent
e3bc2d6767
commit
3b8ad5a4cd
4 changed files with 99 additions and 8 deletions
|
@ -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<String, String>();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
CCorePlugin.setOptions(new HashMap<String, String>(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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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$
|
||||
|
|
|
@ -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 <code>true</code> 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 <code>true</code> if the current token is keyword "extern".
|
||||
*
|
||||
* @return <code>true</code> 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();
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue