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:
parent
784d834751
commit
a27ec4031f
3 changed files with 43 additions and 21 deletions
|
@ -2792,12 +2792,15 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
|
||||||
int nodeEndOffset= fileLocation.getNodeOffset() + fileLocation.getNodeLength();
|
int nodeEndOffset= fileLocation.getNodeOffset() + fileLocation.getNodeLength();
|
||||||
scribe.restartAtOffset(nodeEndOffset);
|
scribe.restartAtOffset(nodeEndOffset);
|
||||||
}
|
}
|
||||||
|
} else if (scribe.currentAlignmentException == null) {
|
||||||
|
// print rest of node if any
|
||||||
|
skipNode(node);
|
||||||
}
|
}
|
||||||
continueNode(node.getParent());
|
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
|
* @param node
|
||||||
*/
|
*/
|
||||||
|
@ -2851,9 +2854,9 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
|
||||||
|
|
||||||
private void skipNode(IASTNode node) {
|
private void skipNode(IASTNode node) {
|
||||||
final IASTNodeLocation fileLocation= node.getFileLocation();
|
final IASTNodeLocation fileLocation= node.getFileLocation();
|
||||||
if (fileLocation != null) {
|
if (fileLocation != null && fileLocation.getNodeLength() > 0) {
|
||||||
final int endOffset= fileLocation.getNodeOffset() + fileLocation.getNodeLength();
|
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;
|
final int restLength= endOffset - currentOffset;
|
||||||
if (restLength > 0) {
|
if (restLength > 0) {
|
||||||
scribe.printRaw(currentOffset, restLength);
|
scribe.printRaw(currentOffset, restLength);
|
||||||
|
@ -2865,7 +2868,7 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
|
||||||
final IASTNodeLocation fileLocation= node.getFileLocation();
|
final IASTNodeLocation fileLocation= node.getFileLocation();
|
||||||
if (fileLocation != null) {
|
if (fileLocation != null) {
|
||||||
final int startOffset= fileLocation.getNodeOffset();
|
final int startOffset= fileLocation.getNodeOffset();
|
||||||
final int currentOffset= scribe.scanner.getCurrentTokenEndPosition() + 1;
|
final int currentOffset= scribe.scanner.getCurrentPosition();
|
||||||
final int restLength= startOffset - currentOffset;
|
final int restLength= startOffset - currentOffset;
|
||||||
if (restLength > 0) {
|
if (restLength > 0) {
|
||||||
scribe.printRaw(currentOffset, restLength);
|
scribe.printRaw(currentOffset, restLength);
|
||||||
|
@ -2879,7 +2882,7 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
|
||||||
final int startOffset= fileLocation.getNodeOffset();
|
final int startOffset= fileLocation.getNodeOffset();
|
||||||
final int nextTokenOffset= getNextTokenOffset();
|
final int nextTokenOffset= getNextTokenOffset();
|
||||||
if (nextTokenOffset < startOffset) {
|
if (nextTokenOffset < startOffset) {
|
||||||
final int currentOffset= scribe.scanner.getCurrentTokenEndPosition() + 1;
|
final int currentOffset= scribe.scanner.getCurrentPosition();
|
||||||
final int restLength= startOffset - currentOffset;
|
final int restLength= startOffset - currentOffset;
|
||||||
if (restLength > 0) {
|
if (restLength > 0) {
|
||||||
scribe.printRaw(currentOffset, restLength);
|
scribe.printRaw(currentOffset, restLength);
|
||||||
|
|
|
@ -47,6 +47,7 @@ public class Scribe {
|
||||||
// Most specific alignment.
|
// Most specific alignment.
|
||||||
public Alignment currentAlignment;
|
public Alignment currentAlignment;
|
||||||
public Alignment memberAlignment;
|
public Alignment memberAlignment;
|
||||||
|
public AlignmentException currentAlignmentException;
|
||||||
|
|
||||||
public Token currentToken;
|
public Token currentToken;
|
||||||
|
|
||||||
|
@ -505,14 +506,14 @@ public class Scribe {
|
||||||
relativeDepth++;
|
relativeDepth++;
|
||||||
}
|
}
|
||||||
if (outerMostDepth >= 0) {
|
if (outerMostDepth >= 0) {
|
||||||
throw new AlignmentException(AlignmentException.LINE_TOO_LONG, outerMostDepth);
|
throwAlignmentException(AlignmentException.LINE_TOO_LONG, outerMostDepth);
|
||||||
}
|
}
|
||||||
// look for innermost breakable one
|
// look for innermost breakable one
|
||||||
relativeDepth= 0;
|
relativeDepth= 0;
|
||||||
targetAlignment= currentAlignment;
|
targetAlignment= currentAlignment;
|
||||||
while (targetAlignment != null) {
|
while (targetAlignment != null) {
|
||||||
if (targetAlignment.couldBreak()) {
|
if (targetAlignment.couldBreak()) {
|
||||||
throw new AlignmentException(AlignmentException.LINE_TOO_LONG, relativeDepth);
|
throwAlignmentException(AlignmentException.LINE_TOO_LONG, relativeDepth);
|
||||||
}
|
}
|
||||||
targetAlignment= targetAlignment.enclosing;
|
targetAlignment= targetAlignment.enclosing;
|
||||||
relativeDepth++;
|
relativeDepth++;
|
||||||
|
@ -520,6 +521,12 @@ public class Scribe {
|
||||||
// did not find any breakable location - proceed
|
// 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() {
|
public void indent() {
|
||||||
if (shouldSkip(scanner.getCurrentPosition())) {
|
if (shouldSkip(scanner.getCurrentPosition())) {
|
||||||
fSkippedIndentations++;
|
fSkippedIndentations++;
|
||||||
|
@ -1391,8 +1398,7 @@ public class Scribe {
|
||||||
if (e.relativeDepth > 0) { // if exception targets a distinct context
|
if (e.relativeDepth > 0) { // if exception targets a distinct context
|
||||||
e.relativeDepth--; // record fact that current context got
|
e.relativeDepth--; // record fact that current context got
|
||||||
// traversed
|
// traversed
|
||||||
currentAlignment= currentAlignment.enclosing; // pop
|
currentAlignment= currentAlignment.enclosing; // pop currentLocation
|
||||||
// currentLocation
|
|
||||||
throw e; // rethrow
|
throw e; // rethrow
|
||||||
}
|
}
|
||||||
// reset scribe/scanner to restart at this given location
|
// reset scribe/scanner to restart at this given location
|
||||||
|
@ -1400,6 +1406,7 @@ public class Scribe {
|
||||||
scanner.resetTo(currentAlignment.location.inputOffset, scanner.eofPosition - 1);
|
scanner.resetTo(currentAlignment.location.inputOffset, scanner.eofPosition - 1);
|
||||||
// clean alignment chunkKind so it will think it is a new chunk again
|
// clean alignment chunkKind so it will think it is a new chunk again
|
||||||
currentAlignment.chunkKind= 0;
|
currentAlignment.chunkKind= 0;
|
||||||
|
currentAlignmentException= null;
|
||||||
}
|
}
|
||||||
|
|
||||||
void redoMemberAlignment(AlignmentException e) {
|
void redoMemberAlignment(AlignmentException e) {
|
||||||
|
@ -1408,6 +1415,7 @@ public class Scribe {
|
||||||
scanner.resetTo(memberAlignment.location.inputOffset, scanner.eofPosition - 1);
|
scanner.resetTo(memberAlignment.location.inputOffset, scanner.eofPosition - 1);
|
||||||
// clean alignment chunkKind so it will think it is a new chunk again
|
// clean alignment chunkKind so it will think it is a new chunk again
|
||||||
memberAlignment.chunkKind= 0;
|
memberAlignment.chunkKind= 0;
|
||||||
|
currentAlignmentException= null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reset() {
|
public void reset() {
|
||||||
|
|
|
@ -37,19 +37,21 @@ import org.eclipse.cdt.internal.formatter.align.Alignment;
|
||||||
*/
|
*/
|
||||||
public class CodeFormatterTest extends BaseUITestCase {
|
public class CodeFormatterTest extends BaseUITestCase {
|
||||||
|
|
||||||
private Map fOptions;
|
private Map<String, String> fOptions;
|
||||||
private Map fDefaultOptions;
|
private Map<String, String> fDefaultOptions;
|
||||||
|
|
||||||
public static TestSuite suite() {
|
public static TestSuite suite() {
|
||||||
return suite(CodeFormatterTest.class, "_");
|
return suite(CodeFormatterTest.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(fDefaultOptions);
|
fOptions= new HashMap<String, String>(fDefaultOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected void tearDown() throws Exception {
|
protected void tearDown() throws Exception {
|
||||||
super.tearDown();
|
super.tearDown();
|
||||||
}
|
}
|
||||||
|
@ -625,4 +627,13 @@ public class CodeFormatterTest extends BaseUITestCase {
|
||||||
fOptions= DefaultCodeFormatterOptions.getWhitesmithsSettings().getMap();
|
fOptions= DefaultCodeFormatterOptions.getWhitesmithsSettings().getMap();
|
||||||
assertFormatterResult();
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue