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
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -42,12 +42,14 @@ public class CIndenterTest extends BaseUITestCase {
|
||||||
return suite(CIndenterTest.class, "_");
|
return suite(CIndenterTest.class, "_");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
fDefaultOptions= DefaultCodeFormatterOptions.getDefaultSettings().getMap();
|
fDefaultOptions= DefaultCodeFormatterOptions.getDefaultSettings().getMap();
|
||||||
fOptions= new HashMap<String, String>();
|
fOptions= new HashMap<String, String>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected void tearDown() throws Exception {
|
protected void tearDown() throws Exception {
|
||||||
CCorePlugin.setOptions(new HashMap<String, String>(fDefaultOptions));
|
CCorePlugin.setOptions(new HashMap<String, String>(fDefaultOptions));
|
||||||
super.tearDown();
|
super.tearDown();
|
||||||
|
@ -795,4 +797,57 @@ public class CIndenterTest extends BaseUITestCase {
|
||||||
fOptions.put(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, CCorePlugin.TAB);
|
fOptions.put(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, CCorePlugin.TAB);
|
||||||
assertIndenterResult();
|
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
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -605,6 +605,8 @@ public final class CHeuristicScanner implements Symbols {
|
||||||
return TokenSTRUCT;
|
return TokenSTRUCT;
|
||||||
if ("switch".equals(s)) //$NON-NLS-1$
|
if ("switch".equals(s)) //$NON-NLS-1$
|
||||||
return TokenSWITCH;
|
return TokenSWITCH;
|
||||||
|
if ("extern".equals(s)) //$NON-NLS-1$
|
||||||
|
return TokenEXTERN;
|
||||||
break;
|
break;
|
||||||
case 7:
|
case 7:
|
||||||
if ("default".equals(s)) //$NON-NLS-1$
|
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
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -1049,6 +1049,13 @@ public final class CIndenter {
|
||||||
case Symbols.TokenTRY:
|
case Symbols.TokenTRY:
|
||||||
return skipToStatementStart(danglingElse, false);
|
return skipToStatementStart(danglingElse, false);
|
||||||
|
|
||||||
|
case Symbols.TokenCONST:
|
||||||
|
nextToken();
|
||||||
|
if (fToken != Symbols.TokenRPAREN) {
|
||||||
|
return skipToPreviousListItemOrListStart();
|
||||||
|
}
|
||||||
|
// could be const method decl
|
||||||
|
//$FALL-THROUGH$
|
||||||
case Symbols.TokenRPAREN:
|
case Symbols.TokenRPAREN:
|
||||||
if (skipScope(Symbols.TokenLPAREN, Symbols.TokenRPAREN)) {
|
if (skipScope(Symbols.TokenLPAREN, Symbols.TokenRPAREN)) {
|
||||||
int scope= fPosition;
|
int scope= fPosition;
|
||||||
|
@ -1756,7 +1763,7 @@ public final class CIndenter {
|
||||||
return setFirstElementAlignment(pos, bound);
|
return setFirstElementAlignment(pos, bound);
|
||||||
else
|
else
|
||||||
fIndent= fPrefs.prefArrayIndent;
|
fIndent= fPrefs.prefArrayIndent;
|
||||||
} else if (isNamespace()) {
|
} else if (isNamespace() || isLinkageSpec()) {
|
||||||
fIndent= fPrefs.prefNamespaceBodyIndent;
|
fIndent= fPrefs.prefNamespaceBodyIndent;
|
||||||
} else {
|
} else {
|
||||||
int typeDeclPos = matchTypeDeclaration();
|
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.
|
* @return <code>true</code> if the next elements look like the start of a namespace declaration.
|
||||||
*/
|
*/
|
||||||
private boolean isNamespace() {
|
private boolean isNamespace() {
|
||||||
int pos = fPosition;
|
|
||||||
if (fToken == Symbols.TokenNAMESPACE) {
|
if (fToken == Symbols.TokenNAMESPACE) {
|
||||||
return true; // Anonymous namespace
|
return true; // Anonymous namespace
|
||||||
} else if (fToken == Symbols.TokenIDENT) {
|
} else if (fToken == Symbols.TokenIDENT) {
|
||||||
|
int pos = fPosition;
|
||||||
|
int token = fToken;
|
||||||
nextToken(); // Get previous token
|
nextToken(); // Get previous token
|
||||||
if (fToken == Symbols.TokenNAMESPACE) {
|
if (fToken == Symbols.TokenNAMESPACE) {
|
||||||
return true; // Named namespace
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2062,6 +2083,15 @@ public final class CIndenter {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case Symbols.TokenCOMMA:
|
||||||
|
nextToken();
|
||||||
|
if (fToken == Symbols.TokenRPAREN) {
|
||||||
|
// field initializer
|
||||||
|
if (skipScope()) {
|
||||||
|
return looksLikeMethodDecl();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
case Symbols.TokenCOLON:
|
case Symbols.TokenCOLON:
|
||||||
nextToken();
|
nextToken();
|
||||||
switch (fToken) {
|
switch (fToken) {
|
||||||
|
@ -2073,6 +2103,7 @@ public final class CIndenter {
|
||||||
case Symbols.TokenRPAREN:
|
case Symbols.TokenRPAREN:
|
||||||
// constructor initializer
|
// constructor initializer
|
||||||
if (skipScope()) {
|
if (skipScope()) {
|
||||||
|
pos = fPosition;
|
||||||
nextToken();
|
nextToken();
|
||||||
// optional throw
|
// optional throw
|
||||||
if (fToken == Symbols.TokenTHROW) {
|
if (fToken == Symbols.TokenTHROW) {
|
||||||
|
@ -2080,6 +2111,8 @@ public final class CIndenter {
|
||||||
if (fToken != Symbols.TokenRPAREN || !skipScope()) {
|
if (fToken != Symbols.TokenRPAREN || !skipScope()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
fPosition = pos;
|
||||||
}
|
}
|
||||||
return looksLikeMethodDecl();
|
return looksLikeMethodDecl();
|
||||||
}
|
}
|
||||||
|
@ -2143,7 +2176,7 @@ public final class CIndenter {
|
||||||
nextToken();
|
nextToken();
|
||||||
while (fToken == Symbols.TokenOTHER) { // dot of qualification
|
while (fToken == Symbols.TokenOTHER) { // dot of qualification
|
||||||
nextToken();
|
nextToken();
|
||||||
if (fToken != Symbols.TokenIDENT) // qualificating name
|
if (fToken != Symbols.TokenIDENT) // qualifying name
|
||||||
return false;
|
return false;
|
||||||
nextToken();
|
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
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -66,5 +66,6 @@ public interface Symbols {
|
||||||
int TokenOPERATOR= 1034;
|
int TokenOPERATOR= 1034;
|
||||||
int TokenTHROW= 1035;
|
int TokenTHROW= 1035;
|
||||||
int TokenCONST= 1036;
|
int TokenCONST= 1036;
|
||||||
|
int TokenEXTERN= 1037;
|
||||||
int TokenIDENT= 2000;
|
int TokenIDENT= 2000;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue