1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-09-10 12:03:16 +02:00

Fix for 194603: [formatter] deleting whitespaces between words while formatting

This commit is contained in:
Anton Leherbauer 2007-06-29 09:32:52 +00:00
parent 7b01c2bb3f
commit 771a1f3876
3 changed files with 21 additions and 8 deletions

View file

@ -911,7 +911,7 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
declSpec.accept(this);
final List declarators= Arrays.asList(node.getDeclarators());
if (declarators.size() > 0) {
if (scribe.printComment() || isCompositeTypeDeclaration(declSpec)) {
if (scribe.printComment() || peekNextToken() == Token.tIDENTIFIER) {
scribe.space();
}
final ListAlignment align= new ListAlignment(Alignment.M_COMPACT_SPLIT);
@ -930,7 +930,7 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
* @param declSpec
* @return true if the decl specifier is one of 'class', 'struct', 'union' or 'enum'
*/
private boolean isCompositeTypeDeclaration(IASTDeclSpecifier declSpec) {
protected boolean isCompositeTypeDeclaration(IASTDeclSpecifier declSpec) {
return declSpec instanceof IASTCompositeTypeSpecifier || declSpec instanceof ICASTEnumerationSpecifier;
}
@ -1399,6 +1399,9 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
case IASTUnaryExpression.op_bracketedPrimary:
scribe.printNextToken(Token.tLPAREN, scribe.printComment());
operand.accept(this);
if (peekNextToken() != Token.tRPAREN) {
scribe.skipToToken(Token.tRPAREN);
}
scribe.printNextToken(Token.tRPAREN, scribe.printComment());
break;
case IASTUnaryExpression.op_prefixIncr:
@ -1443,12 +1446,7 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
break;
case IASTUnaryExpression.op_sizeof:
scribe.printNextToken(Token.t_sizeof, scribe.printComment());
scribe.printNextToken(Token.tLPAREN, scribe.printComment());
operand.accept(this);
if (peekNextToken() != Token.tRPAREN) {
scribe.skipToToken(Token.tRPAREN);
}
scribe.printNextToken(Token.tRPAREN, scribe.printComment());
break;
default:
formatNode(node);

View file

@ -951,10 +951,13 @@ public class Scribe {
preserveEmptyLines(count - 1, scanner.getCurrentTokenStartPosition());
addDeleteEdit(scanner.getCurrentTokenStartPosition(), scanner.getCurrentTokenEndPosition());
} else if (count != 0 && formatter.preferences.number_of_empty_lines_to_preserve != 0) {
String preservedEmptyLines= getPreserveEmptyLines(count - 1);
addReplaceEdit(scanner.getCurrentTokenStartPosition(), scanner.getCurrentTokenEndPosition(),
getPreserveEmptyLines(count - 1));
preservedEmptyLines);
hasWhitespace= preservedEmptyLines.length() == 0;
} else {
addDeleteEdit(scanner.getCurrentTokenStartPosition(), scanner.getCurrentTokenEndPosition());
hasWhitespace= true;
}
currentTokenStartPosition= scanner.getCurrentPosition();
break;

View file

@ -122,4 +122,16 @@ public class CodeFormatterTest extends BaseUITestCase {
public void testIndentConfusionByCastExpression_Bug191021() throws Exception {
assertFormatterResult();
}
//int
//var;
//int*
//pvar;
//int var;
//int* pvar;
public void testSpaceBetweenTypeAndIdentifier_Bug194603() throws Exception {
assertFormatterResult();
}
}