mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-21 16:05:25 +02:00
Eliminated unnecessary blank lines in refactored code.
This commit is contained in:
parent
73337a5882
commit
5326d2930a
3 changed files with 49 additions and 49 deletions
|
@ -12,8 +12,6 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.core.dom.rewrite.astwriter;
|
package org.eclipse.cdt.internal.core.dom.rewrite.astwriter;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTASMDeclaration;
|
import org.eclipse.cdt.core.dom.ast.IASTASMDeclaration;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
|
import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||||
|
@ -32,6 +30,8 @@ import org.eclipse.cdt.internal.core.dom.rewrite.changegenerator.ChangeGenerator
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.ASTCommenter;
|
import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.ASTCommenter;
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap;
|
import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ASTWriter main class. Generates source code from <code>IASTNode</code>.
|
* ASTWriter main class. Generates source code from <code>IASTNode</code>.
|
||||||
* Uses a {@link ChangeGeneratorWriterVisitor} to generate the code for the given nodes.
|
* Uses a {@link ChangeGeneratorWriterVisitor} to generate the code for the given nodes.
|
||||||
|
@ -82,7 +82,7 @@ public class ASTWriter {
|
||||||
/**
|
/**
|
||||||
* Returns <code>true</code> if the node should be separated by a blank line from the node
|
* Returns <code>true</code> if the node should be separated by a blank line from the node
|
||||||
* before it.
|
* before it.
|
||||||
*
|
*
|
||||||
* @param node The node.
|
* @param node The node.
|
||||||
* @return <code>true</code> if the node should be separated by a blank line from the node
|
* @return <code>true</code> if the node should be separated by a blank line from the node
|
||||||
* before it.
|
* before it.
|
||||||
|
@ -99,7 +99,7 @@ public class ASTWriter {
|
||||||
/**
|
/**
|
||||||
* Returns <code>true</code> if the node should be separated by a blank line from the node
|
* Returns <code>true</code> if the node should be separated by a blank line from the node
|
||||||
* after it.
|
* after it.
|
||||||
*
|
*
|
||||||
* @param node The node.
|
* @param node The node.
|
||||||
* @return <code>true</code> if the node should be separated by a blank line from the node
|
* @return <code>true</code> if the node should be separated by a blank line from the node
|
||||||
* after it.
|
* after it.
|
||||||
|
@ -126,7 +126,7 @@ public class ASTWriter {
|
||||||
/**
|
/**
|
||||||
* Returns <code>true</code> if there should be no blank line after this node even if a blank
|
* Returns <code>true</code> if there should be no blank line after this node even if a blank
|
||||||
* line is normally required before the subsequent node.
|
* line is normally required before the subsequent node.
|
||||||
*
|
*
|
||||||
* @param node The node.
|
* @param node The node.
|
||||||
* @return <code>true</code> if there should be no blank line after this node.
|
* @return <code>true</code> if there should be no blank line after this node.
|
||||||
*/
|
*/
|
||||||
|
@ -136,7 +136,7 @@ public class ASTWriter {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns <code>true</code> if the two given nodes should be separated by a blank line.
|
* Returns <code>true</code> if the two given nodes should be separated by a blank line.
|
||||||
*
|
*
|
||||||
* @param node1 The first node.
|
* @param node1 The first node.
|
||||||
* @param node2 The second node.
|
* @param node2 The second node.
|
||||||
* @return <code>true</code> if the blank line between the nodes is needed.
|
* @return <code>true</code> if the blank line between the nodes is needed.
|
||||||
|
@ -173,7 +173,7 @@ public class ASTWriter {
|
||||||
if (isFunctionDeclaration(node1) != isFunctionDeclaration(node2)) {
|
if (isFunctionDeclaration(node1) != isFunctionDeclaration(node2)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (requiresTrailingBlankLine(node1)) {
|
if (node2 != null && requiresTrailingBlankLine(node1)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,8 +13,6 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.core.dom.rewrite.astwriter;
|
package org.eclipse.cdt.internal.core.dom.rewrite.astwriter;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTArrayModifier;
|
import org.eclipse.cdt.core.dom.ast.IASTArrayModifier;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTComment;
|
import org.eclipse.cdt.core.dom.ast.IASTComment;
|
||||||
|
@ -36,6 +34,8 @@ import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTCompoundStatementExpression;
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTLiteralNode;
|
import org.eclipse.cdt.internal.core.dom.rewrite.ASTLiteralNode;
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap;
|
import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Visits all nodes, prints leading comments and handles macro expansions. The
|
* Visits all nodes, prints leading comments and handles macro expansions. The
|
||||||
* source code generation is delegated to severals {@code NodeWriter}s.
|
* source code generation is delegated to severals {@code NodeWriter}s.
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2008, 2010 Institute for Software, HSR Hochschule fuer Technik
|
* Copyright (c) 2008, 2010 Institute for Software, HSR Hochschule fuer Technik
|
||||||
* Rapperswil, University of applied sciences and others
|
* Rapperswil, University of applied sciences and others
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Institute for Software - initial API and implementation
|
* Institute for Software - initial API and implementation
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.core.dom.rewrite.astwriter;
|
package org.eclipse.cdt.internal.core.dom.rewrite.astwriter;
|
||||||
|
@ -45,7 +45,7 @@ import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap;
|
||||||
/**
|
/**
|
||||||
* Generates source code of statement nodes. The actual string operations are delegated
|
* Generates source code of statement nodes. The actual string operations are delegated
|
||||||
* to the <code>Scribe</code> class.
|
* to the <code>Scribe</code> class.
|
||||||
*
|
*
|
||||||
* @see Scribe
|
* @see Scribe
|
||||||
* @see IASTStatement
|
* @see IASTStatement
|
||||||
* @author Emanuel Graf IFS
|
* @author Emanuel Graf IFS
|
||||||
|
@ -75,10 +75,10 @@ public class StatementWriter extends NodeWriter {
|
||||||
super(scribe, visitor, commentMap);
|
super(scribe, visitor, commentMap);
|
||||||
declWriter = new DeclarationWriter(scribe, visitor, commentMap);
|
declWriter = new DeclarationWriter(scribe, visitor, commentMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prints a statement.
|
* Prints a statement.
|
||||||
*
|
*
|
||||||
* @param statement the statement
|
* @param statement the statement
|
||||||
* @param newLine if true print a newline if statement usually have one.
|
* @param newLine if true print a newline if statement usually have one.
|
||||||
* @return {@link ASTVisitor#PROCESS_SKIP}
|
* @return {@link ASTVisitor#PROCESS_SKIP}
|
||||||
|
@ -108,18 +108,18 @@ public class StatementWriter extends NodeWriter {
|
||||||
newLine = false;
|
newLine = false;
|
||||||
} else if (statement instanceof IASTCaseStatement) {
|
} else if (statement instanceof IASTCaseStatement) {
|
||||||
writeCaseStatement((IASTCaseStatement) statement);
|
writeCaseStatement((IASTCaseStatement) statement);
|
||||||
// usually newLine
|
// usually newLine
|
||||||
} else if (statement instanceof IASTDefaultStatement) {
|
} else if (statement instanceof IASTDefaultStatement) {
|
||||||
writeDefaultStatement((IASTDefaultStatement)statement);
|
writeDefaultStatement((IASTDefaultStatement)statement);
|
||||||
} else if (statement instanceof IASTContinueStatement) {
|
} else if (statement instanceof IASTContinueStatement) {
|
||||||
writeContinueStatement((IASTContinueStatement)statement);
|
writeContinueStatement((IASTContinueStatement)statement);
|
||||||
// usually newLine
|
// usually newLine
|
||||||
} else if (statement instanceof IASTCompoundStatement) {
|
} else if (statement instanceof IASTCompoundStatement) {
|
||||||
writeCompoundStatement((IASTCompoundStatement) statement);
|
|
||||||
if (compoundNoNewLine) {
|
if (compoundNoNewLine) {
|
||||||
newLine = false;
|
newLine = false;
|
||||||
compoundNoNewLine = false;
|
compoundNoNewLine = false;
|
||||||
}
|
}
|
||||||
|
writeCompoundStatement((IASTCompoundStatement) statement);
|
||||||
} else if (statement instanceof IASTBreakStatement) {
|
} else if (statement instanceof IASTBreakStatement) {
|
||||||
writeBreakStatement((IASTBreakStatement) statement);
|
writeBreakStatement((IASTBreakStatement) statement);
|
||||||
// usually newLine
|
// usually newLine
|
||||||
|
@ -127,7 +127,7 @@ public class StatementWriter extends NodeWriter {
|
||||||
writeSwitchStatement((IASTSwitchStatement) statement);
|
writeSwitchStatement((IASTSwitchStatement) statement);
|
||||||
newLine = false;
|
newLine = false;
|
||||||
} else if (statement instanceof IASTIfStatement) {
|
} else if (statement instanceof IASTIfStatement) {
|
||||||
writeIfStatement((IASTIfStatement) statement);
|
writeIfStatement((IASTIfStatement) statement);
|
||||||
newLine = false;
|
newLine = false;
|
||||||
} else if (statement instanceof IASTWhileStatement) {
|
} else if (statement instanceof IASTWhileStatement) {
|
||||||
writeWhileStatement((IASTWhileStatement) statement);
|
writeWhileStatement((IASTWhileStatement) statement);
|
||||||
|
@ -149,16 +149,16 @@ public class StatementWriter extends NodeWriter {
|
||||||
newLine = false;
|
newLine = false;
|
||||||
} else if (statement instanceof IASTProblemStatement) {
|
} else if (statement instanceof IASTProblemStatement) {
|
||||||
throw new ProblemRuntimeException((IASTProblemStatement)statement);
|
throw new ProblemRuntimeException((IASTProblemStatement)statement);
|
||||||
}
|
}
|
||||||
|
|
||||||
writeTrailingComments(statement, newLine);
|
writeTrailingComments(statement, newLine);
|
||||||
|
|
||||||
return ASTVisitor.PROCESS_SKIP;
|
return ASTVisitor.PROCESS_SKIP;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void writeDoStatement(IASTDoStatement doStatement) {
|
private void writeDoStatement(IASTDoStatement doStatement) {
|
||||||
nextCompoundNoNewLine();
|
nextCompoundNoNewLine();
|
||||||
|
|
||||||
scribe.print(DO);
|
scribe.print(DO);
|
||||||
writeBodyStatement(doStatement.getBody(), true);
|
writeBodyStatement(doStatement.getBody(), true);
|
||||||
scribe.print(DO_WHILE);
|
scribe.print(DO_WHILE);
|
||||||
|
@ -186,7 +186,7 @@ public class StatementWriter extends NodeWriter {
|
||||||
scribe.printSemicolon();
|
scribe.printSemicolon();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
visitNodeIfNotNull(forStatement.getIterationExpression());
|
visitNodeIfNotNull(forStatement.getIterationExpression());
|
||||||
scribe.print(')');
|
scribe.print(')');
|
||||||
scribe.newLines();
|
scribe.newLines();
|
||||||
|
@ -220,13 +220,13 @@ public class StatementWriter extends NodeWriter {
|
||||||
} else {
|
} else {
|
||||||
ifStatement.getConditionExpression().accept(visitor);
|
ifStatement.getConditionExpression().accept(visitor);
|
||||||
}
|
}
|
||||||
|
|
||||||
scribe.print(')');
|
scribe.print(')');
|
||||||
scribe.newLines();
|
scribe.newLines();
|
||||||
nextCompoundNoNewLine();
|
nextCompoundNoNewLine();
|
||||||
IASTStatement elseClause = ifStatement.getElseClause();
|
IASTStatement elseClause = ifStatement.getElseClause();
|
||||||
writeBodyStatement(ifStatement.getThenClause(), elseClause != null);
|
writeBodyStatement(ifStatement.getThenClause(), elseClause != null);
|
||||||
|
|
||||||
if (elseClause != null) {
|
if (elseClause != null) {
|
||||||
scribe.print(ELSE);
|
scribe.print(ELSE);
|
||||||
nextCompoundNoNewLine();
|
nextCompoundNoNewLine();
|
||||||
|
@ -251,7 +251,7 @@ public class StatementWriter extends NodeWriter {
|
||||||
private void writeLabelStatement(IASTLabelStatement labelStatement) {
|
private void writeLabelStatement(IASTLabelStatement labelStatement) {
|
||||||
labelStatement.getName().accept(visitor);
|
labelStatement.getName().accept(visitor);
|
||||||
scribe.print(':');
|
scribe.print(':');
|
||||||
scribe.newLine();
|
scribe.newLine();
|
||||||
labelStatement.getNestedStatement().accept(visitor);
|
labelStatement.getNestedStatement().accept(visitor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -276,7 +276,7 @@ public class StatementWriter extends NodeWriter {
|
||||||
private void writeNullStatement(IASTNullStatement nullStmt) {
|
private void writeNullStatement(IASTNullStatement nullStmt) {
|
||||||
scribe.printSemicolon();
|
scribe.printSemicolon();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void writeDeclarationStatement(IASTDeclarationStatement decStmt) {
|
private void writeDeclarationStatement(IASTDeclarationStatement decStmt) {
|
||||||
decStmt.getDeclaration().accept(visitor);
|
decStmt.getDeclaration().accept(visitor);
|
||||||
}
|
}
|
||||||
|
@ -317,7 +317,7 @@ public class StatementWriter extends NodeWriter {
|
||||||
cppWhileStatment.getCondition().accept(visitor);
|
cppWhileStatment.getCondition().accept(visitor);
|
||||||
} else {
|
} else {
|
||||||
writeDeclarationWithoutSemicolon(cppWhileStatment.getConditionDeclaration());
|
writeDeclarationWithoutSemicolon(cppWhileStatment.getConditionDeclaration());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
whileStatment.getCondition().accept(visitor);
|
whileStatment.getCondition().accept(visitor);
|
||||||
}
|
}
|
||||||
|
@ -329,7 +329,7 @@ public class StatementWriter extends NodeWriter {
|
||||||
|
|
||||||
private void writeCaseStatement(IASTCaseStatement caseStatement) {
|
private void writeCaseStatement(IASTCaseStatement caseStatement) {
|
||||||
nextCompoundIndentationLevelOneMore();
|
nextCompoundIndentationLevelOneMore();
|
||||||
|
|
||||||
if (!switchIsNew) {
|
if (!switchIsNew) {
|
||||||
scribe.decrementIndentationLevel();
|
scribe.decrementIndentationLevel();
|
||||||
}
|
}
|
||||||
|
@ -342,7 +342,7 @@ public class StatementWriter extends NodeWriter {
|
||||||
|
|
||||||
private void writeSwitchStatement(IASTSwitchStatement switchStatement) {
|
private void writeSwitchStatement(IASTSwitchStatement switchStatement) {
|
||||||
switchIsNew = true;
|
switchIsNew = true;
|
||||||
|
|
||||||
scribe.print(SWITCH_BRACKET);
|
scribe.print(SWITCH_BRACKET);
|
||||||
scribe.noNewLines();
|
scribe.noNewLines();
|
||||||
if (switchStatement instanceof ICPPASTSwitchStatement) {
|
if (switchStatement instanceof ICPPASTSwitchStatement) {
|
||||||
|
@ -359,13 +359,13 @@ public class StatementWriter extends NodeWriter {
|
||||||
scribe.newLines();
|
scribe.newLines();
|
||||||
nextCompoundNoNewLine();
|
nextCompoundNoNewLine();
|
||||||
writeBodyStatement(switchStatement.getBody(), false);
|
writeBodyStatement(switchStatement.getBody(), false);
|
||||||
|
|
||||||
switchIsNew = false;
|
switchIsNew = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void writeDefaultStatement(IASTDefaultStatement defaultStatement) {
|
private void writeDefaultStatement(IASTDefaultStatement defaultStatement) {
|
||||||
nextCompoundIndentationLevelOneMore();
|
nextCompoundIndentationLevelOneMore();
|
||||||
|
|
||||||
if (!switchIsNew) {
|
if (!switchIsNew) {
|
||||||
scribe.decrementIndentationLevel();
|
scribe.decrementIndentationLevel();
|
||||||
}
|
}
|
||||||
|
@ -373,18 +373,18 @@ public class StatementWriter extends NodeWriter {
|
||||||
scribe.incrementIndentationLevel();
|
scribe.incrementIndentationLevel();
|
||||||
switchIsNew = false;
|
switchIsNew = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void writeCompoundStatement(IASTCompoundStatement compoundStatement) {
|
private void writeCompoundStatement(IASTCompoundStatement compoundStatement) {
|
||||||
scribe.printLBrace();
|
scribe.printLBrace();
|
||||||
scribe.newLine();
|
scribe.newLine();
|
||||||
for (IASTStatement statements : getNestedStatements(compoundStatement)) {
|
for (IASTStatement statements : getNestedStatements(compoundStatement)) {
|
||||||
statements.accept(visitor);
|
statements.accept(visitor);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasFreestandingComments(compoundStatement)) {
|
if (hasFreestandingComments(compoundStatement)) {
|
||||||
writeFreestandingComments(compoundStatement);
|
writeFreestandingComments(compoundStatement);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (decrementIndentationLevelOneMore) {
|
if (decrementIndentationLevelOneMore) {
|
||||||
scribe.decrementIndentationLevel();
|
scribe.decrementIndentationLevel();
|
||||||
decrementIndentationLevelOneMore = false;
|
decrementIndentationLevelOneMore = false;
|
||||||
|
@ -394,9 +394,9 @@ public class StatementWriter extends NodeWriter {
|
||||||
|
|
||||||
protected IASTStatement[] getNestedStatements(IASTCompoundStatement compoundStatement) {
|
protected IASTStatement[] getNestedStatements(IASTCompoundStatement compoundStatement) {
|
||||||
return compoundStatement.getStatements();
|
return compoundStatement.getStatements();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(sprigogin): Rename second parameter
|
// TODO(sprigogin): Invert and rename second parameter
|
||||||
protected void writeBodyStatement(IASTStatement statement, boolean isDoStatement) {
|
protected void writeBodyStatement(IASTStatement statement, boolean isDoStatement) {
|
||||||
if (statement instanceof IASTCompoundStatement) {
|
if (statement instanceof IASTCompoundStatement) {
|
||||||
//TODO hsr existiert noch eine methode
|
//TODO hsr existiert noch eine methode
|
||||||
|
@ -409,23 +409,23 @@ public class StatementWriter extends NodeWriter {
|
||||||
statement.accept(visitor);
|
statement.accept(visitor);
|
||||||
scribe.newLine();
|
scribe.newLine();
|
||||||
} else {
|
} else {
|
||||||
scribe.incrementIndentationLevel();
|
scribe.incrementIndentationLevel();
|
||||||
scribe.newLine();
|
scribe.newLine();
|
||||||
statement.accept(visitor);
|
statement.accept(visitor);
|
||||||
scribe.decrementIndentationLevel();
|
scribe.decrementIndentationLevel();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write no new Line after the next compound statement
|
* Write no new line after the next compound statement
|
||||||
*/
|
*/
|
||||||
protected void nextCompoundNoNewLine() {
|
protected void nextCompoundNoNewLine() {
|
||||||
compoundNoNewLine = true;
|
compoundNoNewLine = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Indent one time more at the end (before the closing brackets)
|
* Indent one time more at the end (before the closing brackets)
|
||||||
* of a compound statement
|
* of a compound statement
|
||||||
*/
|
*/
|
||||||
protected void nextCompoundIndentationLevelOneMore() {
|
protected void nextCompoundIndentationLevelOneMore() {
|
||||||
decrementIndentationLevelOneMore = true;
|
decrementIndentationLevelOneMore = true;
|
||||||
|
|
Loading…
Add table
Reference in a new issue