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

Eliminated unnecessary blank lines in refactored code.

This commit is contained in:
sprigogin 2012-03-26 23:32:20 -04:00
parent 73337a5882
commit 5326d2930a
3 changed files with 49 additions and 49 deletions

View file

@ -12,8 +12,6 @@
*******************************************************************************/
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.IASTCompoundStatement;
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.NodeCommentMap;
import java.util.List;
/**
* ASTWriter main class. Generates source code from <code>IASTNode</code>.
* 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
* before it.
*
*
* @param node The node.
* @return <code>true</code> if the node should be separated by a blank line from the node
* 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
* after it.
*
*
* @param node The node.
* @return <code>true</code> if the node should be separated by a blank line from the node
* 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
* line is normally required before the subsequent node.
*
*
* @param node The 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.
*
*
* @param node1 The first node.
* @param node2 The second node.
* @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)) {
return true;
}
if (requiresTrailingBlankLine(node1)) {
if (node2 != null && requiresTrailingBlankLine(node1)) {
return true;
}

View file

@ -13,8 +13,6 @@
*******************************************************************************/
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.IASTArrayModifier;
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.commenthandler.NodeCommentMap;
import java.util.List;
/**
* Visits all nodes, prints leading comments and handles macro expansions. The
* source code generation is delegated to severals {@code NodeWriter}s.

View file

@ -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
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Institute for Software - initial API and implementation
*******************************************************************************/
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
* to the <code>Scribe</code> class.
*
*
* @see Scribe
* @see IASTStatement
* @author Emanuel Graf IFS
@ -75,10 +75,10 @@ public class StatementWriter extends NodeWriter {
super(scribe, visitor, commentMap);
declWriter = new DeclarationWriter(scribe, visitor, commentMap);
}
/**
* Prints a statement.
*
*
* @param statement the statement
* @param newLine if true print a newline if statement usually have one.
* @return {@link ASTVisitor#PROCESS_SKIP}
@ -108,18 +108,18 @@ public class StatementWriter extends NodeWriter {
newLine = false;
} else if (statement instanceof IASTCaseStatement) {
writeCaseStatement((IASTCaseStatement) statement);
// usually newLine
// usually newLine
} else if (statement instanceof IASTDefaultStatement) {
writeDefaultStatement((IASTDefaultStatement)statement);
} else if (statement instanceof IASTContinueStatement) {
writeContinueStatement((IASTContinueStatement)statement);
// usually newLine
} else if (statement instanceof IASTCompoundStatement) {
writeCompoundStatement((IASTCompoundStatement) statement);
if (compoundNoNewLine) {
newLine = false;
compoundNoNewLine = false;
}
writeCompoundStatement((IASTCompoundStatement) statement);
} else if (statement instanceof IASTBreakStatement) {
writeBreakStatement((IASTBreakStatement) statement);
// usually newLine
@ -127,7 +127,7 @@ public class StatementWriter extends NodeWriter {
writeSwitchStatement((IASTSwitchStatement) statement);
newLine = false;
} else if (statement instanceof IASTIfStatement) {
writeIfStatement((IASTIfStatement) statement);
writeIfStatement((IASTIfStatement) statement);
newLine = false;
} else if (statement instanceof IASTWhileStatement) {
writeWhileStatement((IASTWhileStatement) statement);
@ -149,16 +149,16 @@ public class StatementWriter extends NodeWriter {
newLine = false;
} else if (statement instanceof IASTProblemStatement) {
throw new ProblemRuntimeException((IASTProblemStatement)statement);
}
writeTrailingComments(statement, newLine);
}
writeTrailingComments(statement, newLine);
return ASTVisitor.PROCESS_SKIP;
}
private void writeDoStatement(IASTDoStatement doStatement) {
nextCompoundNoNewLine();
scribe.print(DO);
writeBodyStatement(doStatement.getBody(), true);
scribe.print(DO_WHILE);
@ -186,7 +186,7 @@ public class StatementWriter extends NodeWriter {
scribe.printSemicolon();
}
}
visitNodeIfNotNull(forStatement.getIterationExpression());
scribe.print(')');
scribe.newLines();
@ -220,13 +220,13 @@ public class StatementWriter extends NodeWriter {
} else {
ifStatement.getConditionExpression().accept(visitor);
}
scribe.print(')');
scribe.newLines();
nextCompoundNoNewLine();
IASTStatement elseClause = ifStatement.getElseClause();
writeBodyStatement(ifStatement.getThenClause(), elseClause != null);
if (elseClause != null) {
scribe.print(ELSE);
nextCompoundNoNewLine();
@ -251,7 +251,7 @@ public class StatementWriter extends NodeWriter {
private void writeLabelStatement(IASTLabelStatement labelStatement) {
labelStatement.getName().accept(visitor);
scribe.print(':');
scribe.newLine();
scribe.newLine();
labelStatement.getNestedStatement().accept(visitor);
}
@ -276,7 +276,7 @@ public class StatementWriter extends NodeWriter {
private void writeNullStatement(IASTNullStatement nullStmt) {
scribe.printSemicolon();
}
private void writeDeclarationStatement(IASTDeclarationStatement decStmt) {
decStmt.getDeclaration().accept(visitor);
}
@ -317,7 +317,7 @@ public class StatementWriter extends NodeWriter {
cppWhileStatment.getCondition().accept(visitor);
} else {
writeDeclarationWithoutSemicolon(cppWhileStatment.getConditionDeclaration());
}
}
} else {
whileStatment.getCondition().accept(visitor);
}
@ -329,7 +329,7 @@ public class StatementWriter extends NodeWriter {
private void writeCaseStatement(IASTCaseStatement caseStatement) {
nextCompoundIndentationLevelOneMore();
if (!switchIsNew) {
scribe.decrementIndentationLevel();
}
@ -342,7 +342,7 @@ public class StatementWriter extends NodeWriter {
private void writeSwitchStatement(IASTSwitchStatement switchStatement) {
switchIsNew = true;
scribe.print(SWITCH_BRACKET);
scribe.noNewLines();
if (switchStatement instanceof ICPPASTSwitchStatement) {
@ -359,13 +359,13 @@ public class StatementWriter extends NodeWriter {
scribe.newLines();
nextCompoundNoNewLine();
writeBodyStatement(switchStatement.getBody(), false);
switchIsNew = false;
}
private void writeDefaultStatement(IASTDefaultStatement defaultStatement) {
nextCompoundIndentationLevelOneMore();
if (!switchIsNew) {
scribe.decrementIndentationLevel();
}
@ -373,18 +373,18 @@ public class StatementWriter extends NodeWriter {
scribe.incrementIndentationLevel();
switchIsNew = false;
}
private void writeCompoundStatement(IASTCompoundStatement compoundStatement) {
scribe.printLBrace();
scribe.newLine();
for (IASTStatement statements : getNestedStatements(compoundStatement)) {
statements.accept(visitor);
}
if (hasFreestandingComments(compoundStatement)) {
writeFreestandingComments(compoundStatement);
writeFreestandingComments(compoundStatement);
}
if (decrementIndentationLevelOneMore) {
scribe.decrementIndentationLevel();
decrementIndentationLevelOneMore = false;
@ -394,9 +394,9 @@ public class StatementWriter extends NodeWriter {
protected IASTStatement[] getNestedStatements(IASTCompoundStatement compoundStatement) {
return compoundStatement.getStatements();
}
}
// TODO(sprigogin): Rename second parameter
// TODO(sprigogin): Invert and rename second parameter
protected void writeBodyStatement(IASTStatement statement, boolean isDoStatement) {
if (statement instanceof IASTCompoundStatement) {
//TODO hsr existiert noch eine methode
@ -409,23 +409,23 @@ public class StatementWriter extends NodeWriter {
statement.accept(visitor);
scribe.newLine();
} else {
scribe.incrementIndentationLevel();
scribe.newLine();
scribe.incrementIndentationLevel();
scribe.newLine();
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() {
compoundNoNewLine = true;
}
/**
* Indent one time more at the end (before the closing brackets)
* of a compound statement
* Indent one time more at the end (before the closing brackets)
* of a compound statement
*/
protected void nextCompoundIndentationLevelOneMore() {
decrementIndentationLevelOneMore = true;