1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 14:42:11 +02:00

Bug 243056 - [Formatter] changes syntax by removing a space

This commit is contained in:
Anton Leherbauer 2008-08-07 08:45:59 +00:00
parent 03b82b0928
commit da70901535
2 changed files with 24 additions and 36 deletions

View file

@ -91,7 +91,6 @@ import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator;
import org.eclipse.cdt.core.dom.ast.c.ICASTArrayModifier;
import org.eclipse.cdt.core.dom.ast.c.ICASTCompositeTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.c.ICASTDesignatedInitializer;
import org.eclipse.cdt.core.dom.ast.c.ICASTPointer;
import org.eclipse.cdt.core.dom.ast.c.ICASTTypeIdInitializerExpression;
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCastExpression;
@ -461,7 +460,7 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
if (preferences.insert_new_line_before_identifier_in_function_declaration) {
scribe.startNewLine();
} else {
// preserve newline if not explicitely requested
// preserve newline if not explicitly requested
if (scribe.preserveNewLine()) {
scribe.space();
}
@ -993,13 +992,12 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
}
declarator.accept(this);
// tletodo
if (node instanceof ICPPASTFunctionWithTryBlock) {
scribe.startNewLine();
scribe.printNextToken(Token.t_try, false);
scribe.printTrailingComment();
}
if (node instanceof ICPPASTFunctionDefinition) {
final ICPPASTConstructorChainInitializer[] constructorChain= ((ICPPASTFunctionDefinition) node).getMemberInitializers();
if (constructorChain != null && constructorChain.length > 0) {
@ -1053,7 +1051,7 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
private int visit(ICPPASTFunctionDeclarator node) {
visit((IASTStandardFunctionDeclarator)node);
skipConstVolatile();
skipConstVolatileRestrict();
final IASTTypeId[] exceptionSpecification= node.getExceptionSpecification();
if (exceptionSpecification != null) {
@ -1061,30 +1059,8 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
formatExceptionSpecification(exceptionSpecification);
}
}
// tletodo
// if (node instanceof ICPPASTFunctionTryBlockDeclarator) {
// scribe.startNewLine();
// scribe.printNextToken(Token.t_try, false);
// scribe.printTrailingComment();
// // for catch handlers @see #visit(IASTFunctionDefinition)
// }
//
// final ICPPASTConstructorChainInitializer[] constructorChain= node.getConstructorChain();
// if (constructorChain != null && constructorChain.length > 0) {
// // TLETODO [formatter] need special constructor chain alignment
// scribe.printNextToken(Token.tCOLON, true);
// scribe.printTrailingComment();
// scribe.startNewLine();
// scribe.indent();
// final ListAlignment align= new ListAlignment(Alignment.M_COMPACT_SPLIT);
// formatList(Arrays.asList(constructorChain), align, false, false);
// scribe.unIndent();
// } else {
// skip the rest (=0)
skipNode(node);
// }
// skip the rest (=0)
skipNode(node);
return PROCESS_SKIP;
}
@ -1133,12 +1109,15 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
}
}
private void skipConstVolatile() {
private boolean skipConstVolatileRestrict() {
boolean skipped= false;
int token= peekNextToken();
while (token == Token.t_const || token == Token.t_volatile) {
while (token == Token.t_const || token == Token.t_volatile || token == Token.t_restrict) {
scribe.printNextToken(token, true);
token= peekNextToken();
skipped= true;
}
return skipped;
}
private int visit(IASTStandardFunctionDeclarator node) {
@ -1166,9 +1145,6 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
}
if (pointer instanceof ICPPASTReferenceOperator) {
scribe.printNextToken(Token.tAMPER, false);
} else if (pointer instanceof ICASTPointer) {
scribe.printNextToken(Token.tSTAR, false);
skipConstVolatile();
} else if (pointer instanceof ICPPASTPointerToMember) {
final ICPPASTPointerToMember ptrToMember= (ICPPASTPointerToMember)pointer;
final IASTName name= ptrToMember.getName();
@ -1176,9 +1152,14 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
name.accept(this);
}
scribe.printNextToken(Token.tSTAR, false);
skipConstVolatile();
if (skipConstVolatileRestrict()) {
scribe.space();
}
} else {
formatRaw(pointer);
scribe.printNextToken(Token.tSTAR, false);
if (skipConstVolatileRestrict()) {
scribe.space();
}
}
}
}

View file

@ -846,4 +846,11 @@ public class CodeFormatterTest extends BaseUITestCase {
assertFormatterResult();
}
//char *b, * const a;
//char *b, * const a;
public void testPreserveSpaceBetweenPointerModifierAndIdentifier_Bug243056() throws Exception {
assertFormatterResult();
}
}