mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Fix for 193298: [Indenter] Wrong indentation of bit fields
This commit is contained in:
parent
828cb951d5
commit
41bb71eaa4
6 changed files with 101 additions and 32 deletions
|
@ -426,6 +426,7 @@ public class CAutoIndentTest extends TestCase {
|
||||||
public void testBracketWithSemiColonInsertion() throws BadLocationException {
|
public void testBracketWithSemiColonInsertion() throws BadLocationException {
|
||||||
AutoEditTester tester = createAutoEditTester();
|
AutoEditTester tester = createAutoEditTester();
|
||||||
String[] kw= new String[] {"class", "union", "struct", "enum"};
|
String[] kw= new String[] {"class", "union", "struct", "enum"};
|
||||||
|
String[] kw_inh= new String[] {"class", "union", "struct"};
|
||||||
String[] kw_anon= new String[] {"union", "struct", "enum"};
|
String[] kw_anon= new String[] {"union", "struct", "enum"};
|
||||||
|
|
||||||
for(int i=0; i<kw.length; i++) {
|
for(int i=0; i<kw.length; i++) {
|
||||||
|
@ -461,11 +462,11 @@ public class CAutoIndentTest extends TestCase {
|
||||||
// this tests for a sensible behaviour for enums, although the
|
// this tests for a sensible behaviour for enums, although the
|
||||||
// code generated is invalid, its the user entered part that is
|
// code generated is invalid, its the user entered part that is
|
||||||
// the problem
|
// the problem
|
||||||
for(int i=0; i<kw.length; i++) {
|
for(int i=0; i<kw_inh.length; i++) {
|
||||||
tester.reset();
|
tester.reset();
|
||||||
|
|
||||||
tester.type("\n\n\n"+kw[i]+" A\n:\npublic B\n,\npublic C\n{\n"); //$NON-NLS-1$
|
tester.type("\n\n\n"+kw_inh[i]+" A\n:\npublic B\n,\npublic C\n{\n"); //$NON-NLS-1$
|
||||||
assertEquals("\n\n\n"+kw[i]+" A\n:\n\tpublic B\n\t,\n\tpublic C\n\t{\n\t\n\t};", tester.fDoc.get()); //$NON-NLS-1$
|
assertEquals("\n\n\n"+kw_inh[i]+" A\n:\n\tpublic B\n\t,\n\tpublic C\n\t{\n\t\t\n\t};", tester.fDoc.get()); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int i=0; i<kw.length; i++) {
|
for(int i=0; i<kw.length; i++) {
|
||||||
|
|
|
@ -105,14 +105,19 @@ public class CIndenterTest extends BaseUITestCase {
|
||||||
assertIndenterResult();
|
assertIndenterResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
//int x;
|
//struct x {
|
||||||
//
|
// int f1 : 1;
|
||||||
//int y;
|
// int f2 : 1;
|
||||||
|
// int f3 : 1;
|
||||||
|
//}
|
||||||
|
|
||||||
//int x;
|
//struct x {
|
||||||
//
|
// int f1 : 1;
|
||||||
//int y;
|
// int f2 : 1;
|
||||||
public void testIndentationOfEmptyLine_Bug192412() throws Exception {
|
// int f3 : 1;
|
||||||
|
//}
|
||||||
|
public void testIndentationOfBitFields_Bug193298() throws Exception {
|
||||||
assertIndenterResult();
|
assertIndenterResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2000, 2006 IBM Corporation and others.
|
* Copyright (c) 2000, 2007 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
|
||||||
|
|
|
@ -332,6 +332,13 @@ public final class CHeuristicScanner implements Symbols {
|
||||||
return TokenRPAREN;
|
return TokenRPAREN;
|
||||||
case SEMICOLON:
|
case SEMICOLON:
|
||||||
return TokenSEMICOLON;
|
return TokenSEMICOLON;
|
||||||
|
case COLON:
|
||||||
|
switch (peekNextChar()) {
|
||||||
|
case COLON:
|
||||||
|
++fPos;
|
||||||
|
return TokenDOUBLECOLON;
|
||||||
|
}
|
||||||
|
return TokenCOLON;
|
||||||
case COMMA:
|
case COMMA:
|
||||||
return TokenCOMMA;
|
return TokenCOMMA;
|
||||||
case QUESTIONMARK:
|
case QUESTIONMARK:
|
||||||
|
@ -422,6 +429,11 @@ public final class CHeuristicScanner implements Symbols {
|
||||||
case SEMICOLON:
|
case SEMICOLON:
|
||||||
return TokenSEMICOLON;
|
return TokenSEMICOLON;
|
||||||
case COLON:
|
case COLON:
|
||||||
|
switch (peekPreviousChar()) {
|
||||||
|
case COLON:
|
||||||
|
--fPos;
|
||||||
|
return TokenDOUBLECOLON;
|
||||||
|
}
|
||||||
return TokenCOLON;
|
return TokenCOLON;
|
||||||
case COMMA:
|
case COMMA:
|
||||||
return TokenCOMMA;
|
return TokenCOMMA;
|
||||||
|
@ -970,10 +982,7 @@ public final class CHeuristicScanner implements Symbols {
|
||||||
int token= previousToken(start - 1, bound);
|
int token= previousToken(start - 1, bound);
|
||||||
if (token == Symbols.TokenIDENT) { // type name
|
if (token == Symbols.TokenIDENT) { // type name
|
||||||
token= previousToken(getPosition(), bound);
|
token= previousToken(getPosition(), bound);
|
||||||
while (token == Symbols.TokenCOLON) { // colon of qualification
|
while (token == Symbols.TokenDOUBLECOLON) { // qualification
|
||||||
token= previousToken(getPosition(), bound);
|
|
||||||
if (token != Symbols.TokenCOLON) // second colon of qualification
|
|
||||||
return false;
|
|
||||||
token= previousToken(getPosition(), bound);
|
token= previousToken(getPosition(), bound);
|
||||||
if (token != Symbols.TokenIDENT) // qualification name
|
if (token != Symbols.TokenIDENT) // qualification name
|
||||||
return false;
|
return false;
|
||||||
|
@ -1004,12 +1013,9 @@ public final class CHeuristicScanner implements Symbols {
|
||||||
}
|
}
|
||||||
if (token == Symbols.TokenARROW) {
|
if (token == Symbols.TokenARROW) {
|
||||||
return true;
|
return true;
|
||||||
} else if (token == Symbols.TokenCOLON) {
|
} else if (token == Symbols.TokenDOUBLECOLON) {
|
||||||
token= previousToken(getPosition(), bound);
|
|
||||||
if (token == Symbols.TokenCOLON) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -929,10 +929,15 @@ public final class CIndenter {
|
||||||
return fPosition;
|
return fPosition;
|
||||||
|
|
||||||
case Symbols.TokenCOLON:
|
case Symbols.TokenCOLON:
|
||||||
// TODO handle ternary deep indentation
|
pos= fPosition;
|
||||||
|
if (looksLikeCaseStatement()) {
|
||||||
fIndent= fPrefs.prefCaseBlockIndent;
|
fIndent= fPrefs.prefCaseBlockIndent;
|
||||||
return fPosition;
|
return pos;
|
||||||
|
} else {
|
||||||
|
// TODO handle ternary deep indentation
|
||||||
|
fPosition= pos;
|
||||||
|
return skipToStatementStart(danglingElse, false);
|
||||||
|
}
|
||||||
case Symbols.TokenQUESTIONMARK:
|
case Symbols.TokenQUESTIONMARK:
|
||||||
if (fPrefs.prefTernaryDeepAlign) {
|
if (fPrefs.prefTernaryDeepAlign) {
|
||||||
setFirstElementAlignment(fPosition, offset + 1);
|
setFirstElementAlignment(fPosition, offset + 1);
|
||||||
|
@ -990,6 +995,44 @@ public final class CIndenter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test whether the colon at the current position marks a case statement
|
||||||
|
* (or a similar construct increasing the indent).
|
||||||
|
*
|
||||||
|
* @return <code>true</code> if this looks like a case statement
|
||||||
|
*/
|
||||||
|
private boolean looksLikeCaseStatement() {
|
||||||
|
nextToken();
|
||||||
|
switch (fToken) {
|
||||||
|
case Symbols.TokenIDENT:
|
||||||
|
nextToken();
|
||||||
|
while (skipQualifiers()) {
|
||||||
|
nextToken();
|
||||||
|
}
|
||||||
|
switch (fToken) {
|
||||||
|
case Symbols.TokenCASE:
|
||||||
|
case Symbols.TokenCLASS:
|
||||||
|
case Symbols.TokenSTRUCT:
|
||||||
|
case Symbols.TokenUNION:
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case Symbols.TokenOTHER:
|
||||||
|
nextToken();
|
||||||
|
switch (fToken) {
|
||||||
|
case Symbols.TokenCASE:
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
case Symbols.TokenRPAREN: // constructor initializer
|
||||||
|
case Symbols.TokenDEFAULT:
|
||||||
|
case Symbols.TokenPUBLIC:
|
||||||
|
case Symbols.TokenPROTECTED:
|
||||||
|
case Symbols.TokenPRIVATE:
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Skips to the start of a statement that ends at the current position.
|
* Skips to the start of a statement that ends at the current position.
|
||||||
*
|
*
|
||||||
|
@ -1020,6 +1063,8 @@ public final class CIndenter {
|
||||||
|
|
||||||
case Symbols.TokenCLASS:
|
case Symbols.TokenCLASS:
|
||||||
case Symbols.TokenENUM:
|
case Symbols.TokenENUM:
|
||||||
|
case Symbols.TokenSTRUCT:
|
||||||
|
case Symbols.TokenUNION:
|
||||||
isTypeBody= true;
|
isTypeBody= true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -1133,18 +1178,32 @@ public final class CIndenter {
|
||||||
*/
|
*/
|
||||||
private boolean isConditional() {
|
private boolean isConditional() {
|
||||||
while (true) {
|
while (true) {
|
||||||
|
int previous= fToken;
|
||||||
nextToken();
|
nextToken();
|
||||||
switch (fToken) {
|
switch (fToken) {
|
||||||
// search for case labels, which consist of (possibly qualified) identifiers or numbers
|
// search for case labels, which consist of (possibly qualified) identifiers or numbers
|
||||||
case Symbols.TokenIDENT:
|
case Symbols.TokenIDENT:
|
||||||
case Symbols.TokenOTHER: // dots for qualified constants
|
if (previous == Symbols.TokenIDENT) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
case Symbols.TokenDOUBLECOLON:
|
||||||
|
case Symbols.TokenOTHER:
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
case Symbols.TokenQUESTIONMARK:
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case Symbols.TokenSEMICOLON:
|
||||||
|
case Symbols.TokenLBRACE:
|
||||||
|
case Symbols.TokenRBRACE:
|
||||||
case Symbols.TokenCASE:
|
case Symbols.TokenCASE:
|
||||||
case Symbols.TokenDEFAULT:
|
case Symbols.TokenDEFAULT:
|
||||||
case Symbols.TokenPUBLIC:
|
case Symbols.TokenPUBLIC:
|
||||||
case Symbols.TokenPROTECTED:
|
case Symbols.TokenPROTECTED:
|
||||||
case Symbols.TokenPRIVATE:
|
case Symbols.TokenPRIVATE:
|
||||||
|
case Symbols.TokenCLASS:
|
||||||
|
case Symbols.TokenSTRUCT:
|
||||||
|
case Symbols.TokenUNION:
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -1618,15 +1677,12 @@ public final class CIndenter {
|
||||||
* will be an IDENT.
|
* will be an IDENT.
|
||||||
*/
|
*/
|
||||||
private boolean skipQualifiers() {
|
private boolean skipQualifiers() {
|
||||||
if (fToken == Symbols.TokenCOLON) {
|
if (fToken == Symbols.TokenDOUBLECOLON) {
|
||||||
nextToken();
|
|
||||||
if (fToken == Symbols.TokenCOLON) {
|
|
||||||
nextToken();
|
nextToken();
|
||||||
if (fToken == Symbols.TokenIDENT) {
|
if (fToken == Symbols.TokenIDENT) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,6 +36,7 @@ public interface Symbols {
|
||||||
int TokenTILDE= 17;
|
int TokenTILDE= 17;
|
||||||
int TokenSHIFTRIGHT= 18;
|
int TokenSHIFTRIGHT= 18;
|
||||||
int TokenARROW= 19;
|
int TokenARROW= 19;
|
||||||
|
int TokenDOUBLECOLON= 20;
|
||||||
int TokenIF= 109;
|
int TokenIF= 109;
|
||||||
int TokenDO= 1010;
|
int TokenDO= 1010;
|
||||||
int TokenFOR= 1011;
|
int TokenFOR= 1011;
|
||||||
|
|
Loading…
Add table
Reference in a new issue