mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-08 18:26:01 +02:00
Bug 243056 - [Formatter] changes syntax by removing a space
This commit is contained in:
parent
03b82b0928
commit
da70901535
2 changed files with 24 additions and 36 deletions
|
@ -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.ICASTArrayModifier;
|
||||||
import org.eclipse.cdt.core.dom.ast.c.ICASTCompositeTypeSpecifier;
|
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.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.c.ICASTTypeIdInitializerExpression;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
|
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCastExpression;
|
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) {
|
if (preferences.insert_new_line_before_identifier_in_function_declaration) {
|
||||||
scribe.startNewLine();
|
scribe.startNewLine();
|
||||||
} else {
|
} else {
|
||||||
// preserve newline if not explicitely requested
|
// preserve newline if not explicitly requested
|
||||||
if (scribe.preserveNewLine()) {
|
if (scribe.preserveNewLine()) {
|
||||||
scribe.space();
|
scribe.space();
|
||||||
}
|
}
|
||||||
|
@ -993,7 +992,6 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
|
||||||
}
|
}
|
||||||
declarator.accept(this);
|
declarator.accept(this);
|
||||||
|
|
||||||
// tletodo
|
|
||||||
if (node instanceof ICPPASTFunctionWithTryBlock) {
|
if (node instanceof ICPPASTFunctionWithTryBlock) {
|
||||||
scribe.startNewLine();
|
scribe.startNewLine();
|
||||||
scribe.printNextToken(Token.t_try, false);
|
scribe.printNextToken(Token.t_try, false);
|
||||||
|
@ -1053,7 +1051,7 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
|
||||||
private int visit(ICPPASTFunctionDeclarator node) {
|
private int visit(ICPPASTFunctionDeclarator node) {
|
||||||
visit((IASTStandardFunctionDeclarator)node);
|
visit((IASTStandardFunctionDeclarator)node);
|
||||||
|
|
||||||
skipConstVolatile();
|
skipConstVolatileRestrict();
|
||||||
|
|
||||||
final IASTTypeId[] exceptionSpecification= node.getExceptionSpecification();
|
final IASTTypeId[] exceptionSpecification= node.getExceptionSpecification();
|
||||||
if (exceptionSpecification != null) {
|
if (exceptionSpecification != null) {
|
||||||
|
@ -1061,30 +1059,8 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
|
||||||
formatExceptionSpecification(exceptionSpecification);
|
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)
|
// skip the rest (=0)
|
||||||
skipNode(node);
|
skipNode(node);
|
||||||
// }
|
|
||||||
|
|
||||||
return PROCESS_SKIP;
|
return PROCESS_SKIP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1133,12 +1109,15 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void skipConstVolatile() {
|
private boolean skipConstVolatileRestrict() {
|
||||||
|
boolean skipped= false;
|
||||||
int token= peekNextToken();
|
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);
|
scribe.printNextToken(token, true);
|
||||||
token= peekNextToken();
|
token= peekNextToken();
|
||||||
|
skipped= true;
|
||||||
}
|
}
|
||||||
|
return skipped;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int visit(IASTStandardFunctionDeclarator node) {
|
private int visit(IASTStandardFunctionDeclarator node) {
|
||||||
|
@ -1166,9 +1145,6 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
|
||||||
}
|
}
|
||||||
if (pointer instanceof ICPPASTReferenceOperator) {
|
if (pointer instanceof ICPPASTReferenceOperator) {
|
||||||
scribe.printNextToken(Token.tAMPER, false);
|
scribe.printNextToken(Token.tAMPER, false);
|
||||||
} else if (pointer instanceof ICASTPointer) {
|
|
||||||
scribe.printNextToken(Token.tSTAR, false);
|
|
||||||
skipConstVolatile();
|
|
||||||
} else if (pointer instanceof ICPPASTPointerToMember) {
|
} else if (pointer instanceof ICPPASTPointerToMember) {
|
||||||
final ICPPASTPointerToMember ptrToMember= (ICPPASTPointerToMember)pointer;
|
final ICPPASTPointerToMember ptrToMember= (ICPPASTPointerToMember)pointer;
|
||||||
final IASTName name= ptrToMember.getName();
|
final IASTName name= ptrToMember.getName();
|
||||||
|
@ -1176,9 +1152,14 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
|
||||||
name.accept(this);
|
name.accept(this);
|
||||||
}
|
}
|
||||||
scribe.printNextToken(Token.tSTAR, false);
|
scribe.printNextToken(Token.tSTAR, false);
|
||||||
skipConstVolatile();
|
if (skipConstVolatileRestrict()) {
|
||||||
|
scribe.space();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
formatRaw(pointer);
|
scribe.printNextToken(Token.tSTAR, false);
|
||||||
|
if (skipConstVolatileRestrict()) {
|
||||||
|
scribe.space();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -846,4 +846,11 @@ public class CodeFormatterTest extends BaseUITestCase {
|
||||||
assertFormatterResult();
|
assertFormatterResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//char *b, * const a;
|
||||||
|
|
||||||
|
//char *b, * const a;
|
||||||
|
public void testPreserveSpaceBetweenPointerModifierAndIdentifier_Bug243056() throws Exception {
|
||||||
|
assertFormatterResult();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue