1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Fix for 228997: Eclipse CDT Code style formater bug with const parameter

This commit is contained in:
Anton Leherbauer 2008-04-29 08:36:33 +00:00
parent 784d834751
commit a27ec4031f
3 changed files with 43 additions and 21 deletions

View file

@ -2792,12 +2792,15 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
int nodeEndOffset= fileLocation.getNodeOffset() + fileLocation.getNodeLength();
scribe.restartAtOffset(nodeEndOffset);
}
} else if (scribe.currentAlignmentException == null) {
// print rest of node if any
skipNode(node);
}
continueNode(node.getParent());
}
/**
* Formatting of node continues after completion of a chil node. Establish next skip region.
* Formatting of node continues after completion of a child node. Establish next skip region.
*
* @param node
*/
@ -2851,9 +2854,9 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
private void skipNode(IASTNode node) {
final IASTNodeLocation fileLocation= node.getFileLocation();
if (fileLocation != null) {
if (fileLocation != null && fileLocation.getNodeLength() > 0) {
final int endOffset= fileLocation.getNodeOffset() + fileLocation.getNodeLength();
final int currentOffset= scribe.scanner.getCurrentTokenEndPosition() + 1;
final int currentOffset= scribe.scanner.getCurrentPosition();
final int restLength= endOffset - currentOffset;
if (restLength > 0) {
scribe.printRaw(currentOffset, restLength);
@ -2865,7 +2868,7 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
final IASTNodeLocation fileLocation= node.getFileLocation();
if (fileLocation != null) {
final int startOffset= fileLocation.getNodeOffset();
final int currentOffset= scribe.scanner.getCurrentTokenEndPosition() + 1;
final int currentOffset= scribe.scanner.getCurrentPosition();
final int restLength= startOffset - currentOffset;
if (restLength > 0) {
scribe.printRaw(currentOffset, restLength);
@ -2879,7 +2882,7 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
final int startOffset= fileLocation.getNodeOffset();
final int nextTokenOffset= getNextTokenOffset();
if (nextTokenOffset < startOffset) {
final int currentOffset= scribe.scanner.getCurrentTokenEndPosition() + 1;
final int currentOffset= scribe.scanner.getCurrentPosition();
final int restLength= startOffset - currentOffset;
if (restLength > 0) {
scribe.printRaw(currentOffset, restLength);

View file

@ -47,6 +47,7 @@ public class Scribe {
// Most specific alignment.
public Alignment currentAlignment;
public Alignment memberAlignment;
public AlignmentException currentAlignmentException;
public Token currentToken;
@ -505,14 +506,14 @@ public class Scribe {
relativeDepth++;
}
if (outerMostDepth >= 0) {
throw new AlignmentException(AlignmentException.LINE_TOO_LONG, outerMostDepth);
throwAlignmentException(AlignmentException.LINE_TOO_LONG, outerMostDepth);
}
// look for innermost breakable one
relativeDepth= 0;
targetAlignment= currentAlignment;
while (targetAlignment != null) {
if (targetAlignment.couldBreak()) {
throw new AlignmentException(AlignmentException.LINE_TOO_LONG, relativeDepth);
throwAlignmentException(AlignmentException.LINE_TOO_LONG, relativeDepth);
}
targetAlignment= targetAlignment.enclosing;
relativeDepth++;
@ -520,6 +521,12 @@ public class Scribe {
// did not find any breakable location - proceed
}
private void throwAlignmentException(int kind, int relativeDepth) {
AlignmentException e= new AlignmentException(kind, relativeDepth);
currentAlignmentException= e;
throw e;
}
public void indent() {
if (shouldSkip(scanner.getCurrentPosition())) {
fSkippedIndentations++;
@ -1391,8 +1398,7 @@ public class Scribe {
if (e.relativeDepth > 0) { // if exception targets a distinct context
e.relativeDepth--; // record fact that current context got
// traversed
currentAlignment= currentAlignment.enclosing; // pop
// currentLocation
currentAlignment= currentAlignment.enclosing; // pop currentLocation
throw e; // rethrow
}
// reset scribe/scanner to restart at this given location
@ -1400,6 +1406,7 @@ public class Scribe {
scanner.resetTo(currentAlignment.location.inputOffset, scanner.eofPosition - 1);
// clean alignment chunkKind so it will think it is a new chunk again
currentAlignment.chunkKind= 0;
currentAlignmentException= null;
}
void redoMemberAlignment(AlignmentException e) {
@ -1408,6 +1415,7 @@ public class Scribe {
scanner.resetTo(memberAlignment.location.inputOffset, scanner.eofPosition - 1);
// clean alignment chunkKind so it will think it is a new chunk again
memberAlignment.chunkKind= 0;
currentAlignmentException= null;
}
public void reset() {

View file

@ -37,19 +37,21 @@ import org.eclipse.cdt.internal.formatter.align.Alignment;
*/
public class CodeFormatterTest extends BaseUITestCase {
private Map fOptions;
private Map fDefaultOptions;
private Map<String, String> fOptions;
private Map<String, String> fDefaultOptions;
public static TestSuite suite() {
return suite(CodeFormatterTest.class, "_");
}
@Override
protected void setUp() throws Exception {
super.setUp();
fDefaultOptions= DefaultCodeFormatterOptions.getDefaultSettings().getMap();
fOptions= new HashMap(fDefaultOptions);
fOptions= new HashMap<String, String>(fDefaultOptions);
}
@Override
protected void tearDown() throws Exception {
super.tearDown();
}
@ -625,4 +627,13 @@ public class CodeFormatterTest extends BaseUITestCase {
fOptions= DefaultCodeFormatterOptions.getWhitesmithsSettings().getMap();
assertFormatterResult();
}
//typedef int int_;
//int_ const f(int_ const i);
//typedef int int_;
//int_ const f(int_ const i);
public void testPreserveWhitespaceInParameterDecl_Bug228997() throws Exception {
assertFormatterResult();
}
}