1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-28 11:25:35 +02:00

Bug fixes.

This commit is contained in:
Sergey Prigogin 2011-03-01 23:24:26 +00:00
parent eaabdd84c8
commit b4e5df991c
2 changed files with 140 additions and 85 deletions

View file

@ -273,7 +273,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
continuationFormatter.run(); continuationFormatter.run();
} }
} }
public class ClosingParensesisTailFormatter implements Runnable { public class ClosingParensesisTailFormatter implements Runnable {
private final boolean spaceBeforeClosingParen; private final boolean spaceBeforeClosingParen;
private final Runnable continuationFormatter; private final Runnable continuationFormatter;
@ -380,7 +380,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
IStatus getStatus() { IStatus getStatus() {
return fStatus; return fStatus;
} }
private TextEdit failedToFormat(RuntimeException e) { private TextEdit failedToFormat(RuntimeException e) {
if (DEBUG) { if (DEBUG) {
System.out.println("COULD NOT FORMAT: " + e.getMessage()); //$NON-NLS-1$ System.out.println("COULD NOT FORMAT: " + e.getMessage()); //$NON-NLS-1$
@ -466,7 +466,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
scribe.printEndOfTranslationUnit(); scribe.printEndOfTranslationUnit();
return PROCESS_SKIP; return PROCESS_SKIP;
} }
private boolean isFunctionStyleMacroExpansion(IASTPreprocessorMacroExpansion macroExpansion) { private boolean isFunctionStyleMacroExpansion(IASTPreprocessorMacroExpansion macroExpansion) {
IASTName name = macroExpansion.getMacroReference(); IASTName name = macroExpansion.getMacroReference();
IMacroBinding binding = (IMacroBinding) name.resolveBinding(); IMacroBinding binding = (IMacroBinding) name.resolveBinding();
@ -711,7 +711,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
@Override @Override
public int visit(IASTDeclarator node) { public int visit(IASTDeclarator node) {
if (!startNode(node)) { return PROCESS_SKIP; } if (!startNode(node)) { return PROCESS_SKIP; }
try { try {
// common to all declarators // common to all declarators
final IASTPointerOperator[] pointerOperators= node.getPointerOperators(); final IASTPointerOperator[] pointerOperators= node.getPointerOperators();
@ -742,7 +742,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
nestedDecl.accept(this); nestedDecl.accept(this);
scribe.printNextToken(Token.tRPAREN, false); scribe.printNextToken(Token.tRPAREN, false);
} }
if (node instanceof ICPPASTFunctionDeclarator) { if (node instanceof ICPPASTFunctionDeclarator) {
return visit((ICPPASTFunctionDeclarator) node); return visit((ICPPASTFunctionDeclarator) node);
} else if (node instanceof IASTStandardFunctionDeclarator) { } else if (node instanceof IASTStandardFunctionDeclarator) {
@ -754,7 +754,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
} else if (node instanceof IASTArrayDeclarator) { } else if (node instanceof IASTArrayDeclarator) {
visit((IASTArrayDeclarator) node); visit((IASTArrayDeclarator) node);
} }
IASTInitializer initializer= node.getInitializer(); IASTInitializer initializer= node.getInitializer();
if (initializer != null) { if (initializer != null) {
initializer.accept(this); initializer.accept(this);
@ -959,7 +959,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
try { try {
// name // name
enumerator.getName().accept(this); enumerator.getName().accept(this);
// optional value assignment // optional value assignment
final IASTExpression value= enumerator.getValue(); final IASTExpression value= enumerator.getValue();
if (value != null) { if (value != null) {
@ -1019,7 +1019,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
scribe.printNextToken(Token.t_namespace, false); scribe.printNextToken(Token.t_namespace, false);
scribe.space(); scribe.space();
node.getName().accept(this); node.getName().accept(this);
// member declarations // member declarations
IASTDeclaration[] memberDecls= node.getDeclarations(); IASTDeclaration[] memberDecls= node.getDeclarations();
formatLeftCurlyBrace(line, preferences.brace_position_for_namespace_declaration); formatLeftCurlyBrace(line, preferences.brace_position_for_namespace_declaration);
@ -1042,7 +1042,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
return PROCESS_SKIP; return PROCESS_SKIP;
} }
private int visit(ICPPASTLinkageSpecification node) { private int visit(ICPPASTLinkageSpecification node) {
scribe.printComment(); scribe.printComment();
final int line= scribe.line; final int line= scribe.line;
@ -1050,7 +1050,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
scribe.printNextToken(Token.t_extern, false); scribe.printNextToken(Token.t_extern, false);
scribe.space(); scribe.space();
scribe.printNextToken(Token.tSTRING); scribe.printNextToken(Token.tSTRING);
// member declarations // member declarations
IASTDeclaration[] memberDecls= node.getDeclarations(); IASTDeclaration[] memberDecls= node.getDeclarations();
if (memberDecls.length == 1 && peekNextToken() != Token.tLBRACE) { if (memberDecls.length == 1 && peekNextToken() != Token.tLBRACE) {
@ -1179,7 +1179,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
} }
return PROCESS_SKIP; return PROCESS_SKIP;
} }
private int visit(ICPPASTTemplatedTypeTemplateParameter node) { private int visit(ICPPASTTemplatedTypeTemplateParameter node) {
scribe.printNextToken(Token.t_template, scribe.printComment()); scribe.printNextToken(Token.t_template, scribe.printComment());
scribe.printNextToken(Token.tLT, preferences.insert_space_before_opening_angle_bracket_in_template_parameters); scribe.printNextToken(Token.tLT, preferences.insert_space_before_opening_angle_bracket_in_template_parameters);
@ -1211,7 +1211,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
} }
return PROCESS_SKIP; return PROCESS_SKIP;
} }
private int visit(ICPPASTConstructorInitializer node) { private int visit(ICPPASTConstructorInitializer node) {
if (!startNode(node)) { return PROCESS_SKIP; } if (!startNode(node)) { return PROCESS_SKIP; }
try { try {
@ -1238,7 +1238,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
private int visit(IASTFunctionDefinition node) { private int visit(IASTFunctionDefinition node) {
scribe.printComment(); scribe.printComment();
final int line= scribe.line; final int line= scribe.line;
// decl-specifier // decl-specifier
final IASTDeclSpecifier declSpec= node.getDeclSpecifier(); final IASTDeclSpecifier declSpec= node.getDeclSpecifier();
declSpec.accept(this); declSpec.accept(this);
@ -1270,7 +1270,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
scribe.printNextToken(Token.t_try, false); scribe.printNextToken(Token.t_try, false);
scribe.printTrailingComment(); scribe.printTrailingComment();
} }
if (node instanceof ICPPASTFunctionDefinition) { if (node instanceof ICPPASTFunctionDefinition) {
final ICPPASTConstructorChainInitializer[] constructorChain= final ICPPASTConstructorChainInitializer[] constructorChain=
((ICPPASTFunctionDefinition) node).getMemberInitializers(); ((ICPPASTFunctionDefinition) node).getMemberInitializers();
@ -1294,7 +1294,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
scribe.unIndentForContinuation(); scribe.unIndentForContinuation();
} }
} }
if (bodyLeftBraceFormatter != null) { if (bodyLeftBraceFormatter != null) {
scribe.setTailFormatter(null); scribe.setTailFormatter(null);
} }
@ -1366,7 +1366,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
preferences.alignment_for_throws_clause_in_method_declaration, preferences.alignment_for_throws_clause_in_method_declaration,
exceptionSpecification.length, exceptionSpecification.length,
scribe.scanner.getCurrentPosition()); scribe.scanner.getCurrentPosition());
scribe.enterAlignment(alignment); scribe.enterAlignment(alignment);
boolean ok = false; boolean ok = false;
do { do {
@ -1544,8 +1544,9 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
} catch (ASTProblemException e) { } catch (ASTProblemException e) {
scribe.skipToToken(Token.tRBRACKET); scribe.skipToToken(Token.tRBRACKET);
} }
boolean insertSpace= emptyBrackets ? preferences.insert_space_between_empty_brackets boolean insertSpace= emptyBrackets ?
: preferences.insert_space_before_closing_bracket; preferences.insert_space_between_empty_brackets :
preferences.insert_space_before_closing_bracket;
scribe.printNextToken(Token.tRBRACKET, insertSpace); scribe.printNextToken(Token.tRBRACKET, insertSpace);
} }
} }
@ -1586,7 +1587,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
if (preferences.insert_space_after_opening_angle_bracket_in_template_parameters) { if (preferences.insert_space_after_opening_angle_bracket_in_template_parameters) {
scribe.space(); scribe.space();
} }
// template parameters // template parameters
final ICPPASTTemplateParameter[] templateParameters= node.getTemplateParameters(); final ICPPASTTemplateParameter[] templateParameters= node.getTemplateParameters();
if (templateParameters.length > 0) { if (templateParameters.length > 0) {
@ -1619,7 +1620,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
scribe.unIndent(); scribe.unIndent();
} }
} }
return PROCESS_SKIP; return PROCESS_SKIP;
} }
@ -1672,7 +1673,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
if (scribe.printModifiers()) { if (scribe.printModifiers()) {
scribe.space(); scribe.space();
} }
// consider macro expansion // consider macro expansion
if (withinMacroExpansion(node, scribe.scanner.getCurrentPosition())) { if (withinMacroExpansion(node, scribe.scanner.getCurrentPosition())) {
continueNode(node); continueNode(node);
@ -1900,7 +1901,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
scribe.space(); scribe.space();
name.accept(this); name.accept(this);
} }
formatLeftCurlyBrace(line, preferences.brace_position_for_type_declaration); formatLeftCurlyBrace(line, preferences.brace_position_for_type_declaration);
formatOpeningBrace(preferences.brace_position_for_type_declaration, preferences.insert_space_before_opening_brace_in_type_declaration); formatOpeningBrace(preferences.brace_position_for_type_declaration, preferences.insert_space_before_opening_brace_in_type_declaration);
final int braceIndent= scribe.numberOfIndentations; final int braceIndent= scribe.numberOfIndentations;
@ -2081,7 +2082,12 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
} }
private int visit(IASTConditionalExpression node) { private int visit(IASTConditionalExpression node) {
node.getLogicalConditionExpression().accept(this); Runnable tailFormatter = scribe.takeTailFormatter();
try {
node.getLogicalConditionExpression().accept(this);
} finally {
scribe.setTailFormatter(tailFormatter);
}
scribe.printTrailingComment(); scribe.printTrailingComment();
if (preferences.insert_space_before_question_in_conditional) { if (preferences.insert_space_before_question_in_conditional) {
scribe.space(); scribe.space();
@ -2097,23 +2103,33 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
do { do {
try { try {
scribe.alignFragment(alignment, 0); scribe.alignFragment(alignment, 0);
scribe.printNextToken(Token.tQUESTION, false);
if (preferences.insert_space_after_question_in_conditional) {
scribe.space();
}
final IASTExpression positiveExpression = node.getPositiveResultExpression(); final IASTExpression positiveExpression = node.getPositiveResultExpression();
final IASTExpression negativeExpression = node.getNegativeResultExpression();
final IASTExpression nextExpression = positiveExpression != null ?
positiveExpression : negativeExpression;
// In case of macros we may have already passed the question mark position.
if (scribe.scanner.getCurrentPosition() < nextExpression.getFileLocation().getNodeOffset()) {
scribe.printNextToken(Token.tQUESTION, false);
if (preferences.insert_space_after_question_in_conditional) {
scribe.space();
}
}
if (positiveExpression != null) { // gcc-extension allows to omit the positive expression. if (positiveExpression != null) { // gcc-extension allows to omit the positive expression.
positiveExpression.accept(this); positiveExpression.accept(this);
} }
scribe.printTrailingComment(); scribe.printTrailingComment();
scribe.alignFragment(alignment, 1); scribe.alignFragment(alignment, 1);
scribe.printNextToken(Token.tCOLON, preferences.insert_space_before_colon_in_conditional);
if (preferences.insert_space_after_colon_in_conditional) { // In case of macros we may have already passed the colon position.
scribe.space(); if (scribe.scanner.getCurrentPosition() < negativeExpression.getFileLocation().getNodeOffset()) {
scribe.printNextToken(Token.tCOLON, preferences.insert_space_before_colon_in_conditional);
if (preferences.insert_space_after_colon_in_conditional) {
scribe.space();
}
} }
node.getNegativeResultExpression().accept(this);
negativeExpression.accept(this);
ok = true; ok = true;
} catch (AlignmentException e) { } catch (AlignmentException e) {
@ -2125,7 +2141,12 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
} }
private int visit(IASTFunctionCallExpression node) { private int visit(IASTFunctionCallExpression node) {
node.getFunctionNameExpression().accept(this); Runnable tailFormatter = scribe.takeTailFormatter();
try {
node.getFunctionNameExpression().accept(this);
} finally {
scribe.setTailFormatter(tailFormatter);
}
IASTInitializerClause[] paramExpr= node.getArguments(); IASTInitializerClause[] paramExpr= node.getArguments();
if (peekNextToken() == Token.tIDENTIFIER) { if (peekNextToken() == Token.tIDENTIFIER) {
skipNode(node); skipNode(node);
@ -2255,15 +2276,15 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
Alignment.R_OUTERMOST, Alignment.R_OUTERMOST,
1, 1,
scribe.scanner.getCurrentPosition()); scribe.scanner.getCurrentPosition());
scribe.enterAlignment(expressionAlignment); scribe.enterAlignment(expressionAlignment);
boolean ok = false; boolean ok = false;
do { do {
try { try {
scribe.alignFragment(expressionAlignment, 0); scribe.alignFragment(expressionAlignment, 0);
node.getInitializerClause().accept(this); node.getInitializerClause().accept(this);
ok = true; ok = true;
} catch (AlignmentException e) { } catch (AlignmentException e) {
scribe.redoAlignment(e); scribe.redoAlignment(e);
@ -2314,7 +2335,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
scribe.exitAlignment(expressionAlignment, true); scribe.exitAlignment(expressionAlignment, true);
return PROCESS_SKIP; return PROCESS_SKIP;
} }
private int visit(IASTInitializerList node) { private int visit(IASTInitializerList node) {
scribe.printComment(); scribe.printComment();
@ -2455,21 +2476,24 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
scribe.printTrailingComment(); scribe.printTrailingComment();
scribe.alignFragment(expressionAlignment, 1); scribe.alignFragment(expressionAlignment, 1);
// operator // In case of macros we may have already passed the operator position.
final int nextToken= peekNextToken(); if (scribe.scanner.getCurrentPosition() < node.getOperand2().getFileLocation().getNodeOffset()) {
// in case of C++ alternative operators, like 'and', 'not', etc. a space // Operator
boolean forceSpace= Character.isJavaIdentifierStart(peekNextChar()); final int nextToken= peekNextToken();
// In case of C++ alternative operators, like 'and', 'not', etc. a space
boolean forceSpace= Character.isJavaIdentifierStart(peekNextChar());
switch (node.getOperator()) { switch (node.getOperator()) {
case IASTBinaryExpression.op_pmdot: case IASTBinaryExpression.op_pmdot:
case IASTBinaryExpression.op_pmarrow: case IASTBinaryExpression.op_pmarrow:
scribe.printNextToken(nextToken, false); scribe.printNextToken(nextToken, false);
break; break;
default: default:
scribe.printNextToken(nextToken, forceSpace || preferences.insert_space_before_binary_operator); scribe.printNextToken(nextToken, forceSpace || preferences.insert_space_before_binary_operator);
if (forceSpace || preferences.insert_space_after_binary_operator) { if (forceSpace || preferences.insert_space_after_binary_operator) {
scribe.space(); scribe.space();
} }
}
} }
// operand 2 // operand 2
@ -2489,15 +2513,18 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
final IASTExpression op1= node.getOperand1(); final IASTExpression op1= node.getOperand1();
// operand 1 // operand 1
op1.accept(this); op1.accept(this);
// operator
final int nextToken= peekNextToken();
// in case of C++ alternative operators, like 'and', 'not', etc. a space
boolean forceSpace= Character.isJavaIdentifierStart(peekNextChar());
scribe.printNextToken(nextToken, forceSpace || preferences.insert_space_before_assignment_operator); // In case of macros we may have already passed the equal sign position.
if (forceSpace || preferences.insert_space_after_assignment_operator) { if (scribe.scanner.getCurrentPosition() < node.getOperand2().getFileLocation().getNodeOffset()) {
scribe.space(); // Operator
final int nextToken= peekNextToken();
// In case of C++ alternative operators, like 'and', 'not', etc. a space
boolean forceSpace= Character.isJavaIdentifierStart(peekNextChar());
scribe.printNextToken(nextToken, forceSpace || preferences.insert_space_before_assignment_operator);
if (forceSpace || preferences.insert_space_after_assignment_operator) {
scribe.space();
}
} }
Alignment expressionAlignment= scribe.createAlignment( Alignment expressionAlignment= scribe.createAlignment(
@ -2580,7 +2607,12 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
private int visit(IASTFieldReference node) { private int visit(IASTFieldReference node) {
IASTExpression expr= node.getFieldOwner(); IASTExpression expr= node.getFieldOwner();
if (expr != null) { if (expr != null) {
expr.accept(this); Runnable tailFormatter = scribe.takeTailFormatter();
try {
expr.accept(this);
} finally {
scribe.setTailFormatter(tailFormatter);
}
} }
final IASTName fieldName= node.getFieldName(); final IASTName fieldName= node.getFieldName();
if (fieldName != null) { if (fieldName != null) {
@ -2619,25 +2651,30 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
} }
private int visit(IASTArraySubscriptExpression node) { private int visit(IASTArraySubscriptExpression node) {
node.getArrayExpression().accept(this); Runnable tailFormatter = scribe.takeTailFormatter();
try {
scribe.printNextToken(Token.tLBRACKET, preferences.insert_space_before_opening_bracket); node.getArrayExpression().accept(this);
if (preferences.insert_space_after_opening_bracket) {
scribe.space(); scribe.printNextToken(Token.tLBRACKET, preferences.insert_space_before_opening_bracket);
if (preferences.insert_space_after_opening_bracket) {
scribe.space();
}
node.getArgument().accept(this);
scribe.printNextToken(Token.tRBRACKET, preferences.insert_space_before_closing_bracket);
} finally {
scribe.setTailFormatter(tailFormatter);
} }
node.getArgument().accept(this);
scribe.printNextToken(Token.tRBRACKET, preferences.insert_space_before_closing_bracket);
return PROCESS_SKIP; return PROCESS_SKIP;
} }
private int visit(ICASTTypeIdInitializerExpression node) { private int visit(ICASTTypeIdInitializerExpression node) {
scribe.printComment(); scribe.printComment();
final int line= scribe.line; final int line= scribe.line;
node.getTypeId().accept(this); node.getTypeId().accept(this);
final String brace_position= preferences.brace_position_for_initializer_list; final String brace_position= preferences.brace_position_for_initializer_list;
formatLeftCurlyBrace(line, brace_position); formatLeftCurlyBrace(line, brace_position);
formatOpeningBrace(brace_position, preferences.insert_space_before_opening_brace_in_initializer_list); formatOpeningBrace(brace_position, preferences.insert_space_before_opening_brace_in_initializer_list);
@ -2686,7 +2723,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
} }
scribe.printNextToken(Token.t_new); scribe.printNextToken(Token.t_new);
scribe.space(); scribe.space();
// placement // placement
final IASTInitializerClause[] newPlacement= node.getPlacementArguments(); final IASTInitializerClause[] newPlacement= node.getPlacementArguments();
if (newPlacement != null) { if (newPlacement != null) {
@ -2762,13 +2799,13 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
} }
scribe.printNextToken(Token.t_while, preferences.insert_space_after_closing_brace_in_block); scribe.printNextToken(Token.t_while, preferences.insert_space_after_closing_brace_in_block);
scribe.printNextToken(Token.tLPAREN, preferences.insert_space_before_opening_paren_in_while); scribe.printNextToken(Token.tLPAREN, preferences.insert_space_before_opening_paren_in_while);
if (preferences.insert_space_after_opening_paren_in_while) { if (preferences.insert_space_after_opening_paren_in_while) {
scribe.space(); scribe.space();
} }
node.getCondition().accept(this); node.getCondition().accept(this);
scribe.printNextToken(Token.tRPAREN, preferences.insert_space_before_closing_paren_in_while); scribe.printNextToken(Token.tRPAREN, preferences.insert_space_before_closing_paren_in_while);
} }
scribe.printNextToken(Token.tSEMI, preferences.insert_space_before_semicolon); scribe.printNextToken(Token.tSEMI, preferences.insert_space_before_semicolon);
@ -2821,7 +2858,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
2, 2,
scribe.scanner.getCurrentPosition()); scribe.scanner.getCurrentPosition());
scribe.enterAlignment(alignment); scribe.enterAlignment(alignment);
boolean ok = false; boolean ok = false;
do { do {
try { try {
@ -2904,7 +2941,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
return PROCESS_SKIP; return PROCESS_SKIP;
} }
private int visit(ICPPASTRangeBasedForStatement node) { private int visit(ICPPASTRangeBasedForStatement node) {
scribe.printNextToken(Token.t_for); scribe.printNextToken(Token.t_for);
final int line = scribe.line; final int line = scribe.line;
@ -2928,7 +2965,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
if (peekNextToken() == Token.tRPAREN) { if (peekNextToken() == Token.tRPAREN) {
scribe.printNextToken(Token.tRPAREN, preferences.insert_space_before_closing_paren_in_for); scribe.printNextToken(Token.tRPAREN, preferences.insert_space_before_closing_paren_in_for);
} }
formatAction(line, node.getBody(), preferences.brace_position_for_block); formatAction(line, node.getBody(), preferences.brace_position_for_block);
return PROCESS_SKIP; return PROCESS_SKIP;
} }
@ -3355,11 +3392,11 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
private int visit(IASTProblemExpression node) { private int visit(IASTProblemExpression node) {
throw new ASTProblemException(node.getProblem()); throw new ASTProblemException(node.getProblem());
} }
private int visit(IASTProblemDeclaration node) { private int visit(IASTProblemDeclaration node) {
throw new ASTProblemException(node.getProblem()); throw new ASTProblemException(node.getProblem());
} }
private void formatRaw(IASTNode node) { private void formatRaw(IASTNode node) {
scribe.printComment(); scribe.printComment();
skipNode(node); skipNode(node);
@ -3576,7 +3613,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
} }
return false; return false;
} }
private static boolean endsWithMacroExpansion(IASTNode node) { private static boolean endsWithMacroExpansion(IASTNode node) {
IASTNodeLocation[] locations= node.getNodeLocations(); IASTNodeLocation[] locations= node.getNodeLocations();
if (locations.length == 0) { if (locations.length == 0) {

View file

@ -2122,7 +2122,7 @@ public class Scribe {
/* /*
* Returns the tail formatter associated with the current alignment or, if there is no current * Returns the tail formatter associated with the current alignment or, if there is no current
* alignment, with the Scribe itself. * alignment, with the scribe itself.
* @see #tailFormatter * @see #tailFormatter
*/ */
public Runnable getTailFormatter() { public Runnable getTailFormatter() {
@ -2133,9 +2133,27 @@ public class Scribe {
} }
} }
/*
* Returns the tail formatter associated with the current alignment or, if there is no current
* alignment, with the scribe itself. The tail formatter associated with the alignment or
* the scribe is set to {@code null}.
* @see #tailFormatter
*/
public Runnable takeTailFormatter() {
Runnable formatter;
if (currentAlignment != null) {
formatter = currentAlignment.tailFormatter;
currentAlignment.tailFormatter = null;
} else {
formatter = this.tailFormatter;
this.tailFormatter = null;
}
return formatter;
}
/* /*
* Sets the tail formatter associated with the current alignment or, if there is no current * Sets the tail formatter associated with the current alignment or, if there is no current
* alignment, with the Scribe itself. * alignment, with the scribe itself.
* @see #tailFormatter * @see #tailFormatter
*/ */
public void setTailFormatter(Runnable tailFormatter) { public void setTailFormatter(Runnable tailFormatter) {
@ -2148,7 +2166,7 @@ public class Scribe {
/* /*
* Runs the tail formatter associated with the current alignment or, if there is no current * Runs the tail formatter associated with the current alignment or, if there is no current
* alignment, with the Scribe itself. * alignment, with the scribe itself.
* @see #tailFormatter * @see #tailFormatter
*/ */
public void runTailFormatter() { public void runTailFormatter() {