Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSergey Prigogin2011-11-01 18:45:38 -0400
committerSergey Prigogin2011-11-07 14:03:01 -0500
commit0177053e2bb663a4b2f7fe8144e6a68887d08daf (patch)
tree2f7f218a4390822b5fbdb7906878a9c9db4232ec /core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite
parentd8d335dbf8d31205be5cfbcbedf1bc049f0eed21 (diff)
downloadorg.eclipse.cdt-0177053e2bb663a4b2f7fe8144e6a68887d08daf.tar.gz
org.eclipse.cdt-0177053e2bb663a4b2f7fe8144e6a68887d08daf.tar.xz
org.eclipse.cdt-0177053e2bb663a4b2f7fe8144e6a68887d08daf.zip
Cosmetics.
Diffstat (limited to 'core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite')
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/ASTWriter.java9
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/DeclSpecWriter.java9
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/DeclaratorWriter.java52
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/NodeWriter.java52
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/StatementWriter.java66
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/ASTModificationHelper.java63
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/ChangeGeneratorWriterVisitor.java6
7 files changed, 105 insertions, 152 deletions
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/ASTWriter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/ASTWriter.java
index 701cfdb6b9..8752230ea2 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/ASTWriter.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/ASTWriter.java
@@ -26,7 +26,6 @@ import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap;
* @author Emanuel Graf
*/
public class ASTWriter {
- private ChangeGeneratorWriterVisitor transformationVisitor;
private ASTModificationStore modificationStore = new ASTModificationStore();
private String givenIndentation = ""; //$NON-NLS-1$
@@ -76,14 +75,12 @@ public class ASTWriter {
*/
public String write(IASTNode rootNode, String fileScope, NodeCommentMap commentMap)
throws ProblemRuntimeException {
- transformationVisitor = new ChangeGeneratorWriterVisitor(modificationStore, givenIndentation,
- fileScope, commentMap);
+ ChangeGeneratorWriterVisitor transformationVisitor = new ChangeGeneratorWriterVisitor(
+ modificationStore, givenIndentation, fileScope, commentMap);
if (rootNode != null) {
rootNode.accept(transformationVisitor);
}
- String str = transformationVisitor.toString();
- transformationVisitor.cleanCache();
- return str;
+ return transformationVisitor.toString();
}
public void setModificationStore(ASTModificationStore modificationStore) {
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/DeclSpecWriter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/DeclSpecWriter.java
index d643b8a317..aa43011f5f 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/DeclSpecWriter.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/DeclSpecWriter.java
@@ -217,14 +217,13 @@ public class DeclSpecWriter extends NodeWriter {
scribe.print('{');
scribe.printSpace();
IASTEnumerator[] enums = enumSpec.getEnumerators();
- for (int i = 0; i< enums.length;++i) {
+ for (int i = 0; i < enums.length; ++i) {
writeEnumerator(enums[i]);
- if (i+1< enums.length) {
+ if (i + 1 < enums.length) {
scribe.print(NodeWriter.COMMA_SPACE);
}
}
scribe.print('}');
-
}
private void writeEnumerator(IASTEnumerator enumerator) {
@@ -246,9 +245,9 @@ public class DeclSpecWriter extends NodeWriter {
ICPPASTBaseSpecifier[] baseSpecifiers = cppComp.getBaseSpecifiers();
if (baseSpecifiers.length > 0) {
scribe.print(SPACE_COLON_SPACE);
- for (int i = 0; i < baseSpecifiers.length;++i) {
+ for (int i = 0; i < baseSpecifiers.length; ++i) {
writeBaseSpecifiers(baseSpecifiers[i]);
- if (i+1 < baseSpecifiers.length) {
+ if (i + 1 < baseSpecifiers.length) {
scribe.print(COMMA_SPACE);
}
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/DeclaratorWriter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/DeclaratorWriter.java
index 53c2655397..2d93ad6b0e 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/DeclaratorWriter.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/DeclaratorWriter.java
@@ -7,8 +7,8 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * Institute for Software - initial API and implementation
- * Markus Schorn (Wind River Systems)
+ * Institute for Software - initial API and implementation
+ * Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.rewrite.astwriter;
@@ -32,23 +32,18 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTReferenceOperator;
import org.eclipse.cdt.core.dom.ast.gnu.c.ICASTKnRFunctionDeclarator;
import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap;
-
/**
- *
* Generates source code of declarator nodes. The actual string operations are delegated
- * to the <code>Scribe</code> class.
+ * to the {@link Scribe} class.
*
- * @see Scribe
* @see IASTDeclarator
* @author Emanuel Graf IFS
- *
*/
public class DeclaratorWriter extends NodeWriter {
-
private static final String AMPERSAND_SPACE = "& "; //$NON-NLS-1$
private static final String AMPERSAND__AMPERSAND_SPACE = "&& "; //$NON-NLS-1$
private static final String STAR_SPACE = "* "; //$NON-NLS-1$
- private static final String PURE_VIRTUAL = " =0"; //$NON-NLS-1$
+ private static final String PURE_VIRTUAL = " = 0"; //$NON-NLS-1$
private static final String MUTABLE = "mutable"; //$NON-NLS-1$
private static final String ARROW_OPERATOR = "->"; //$NON-NLS-1$
@@ -59,17 +54,17 @@ public class DeclaratorWriter extends NodeWriter {
protected void writeDeclarator(IASTDeclarator declarator) {
if (declarator instanceof IASTStandardFunctionDeclarator) {
writeFunctionDeclarator((IASTStandardFunctionDeclarator) declarator);
- }else if (declarator instanceof IASTArrayDeclarator) {
+ } else if (declarator instanceof IASTArrayDeclarator) {
writeArrayDeclarator((IASTArrayDeclarator) declarator);
- }else if (declarator instanceof IASTFieldDeclarator) {
+ } else if (declarator instanceof IASTFieldDeclarator) {
writeFieldDeclarator((IASTFieldDeclarator) declarator);
- }else if (declarator instanceof ICASTKnRFunctionDeclarator) {
+ } else if (declarator instanceof ICASTKnRFunctionDeclarator) {
writeCKnRFunctionDeclarator((ICASTKnRFunctionDeclarator) declarator);
- }else{
+ } else {
writeDefaultDeclarator(declarator);
}
- if(hasTrailingComments(declarator)) {
+ if (hasTrailingComments(declarator)) {
writeTrailingComments(declarator, false);
}
}
@@ -81,7 +76,7 @@ public class DeclaratorWriter extends NodeWriter {
name.accept(visitor);
writeNestedDeclarator(declarator);
IASTInitializer init = getInitializer(declarator);
- if(init!= null) {
+ if (init != null) {
init.accept(visitor);
}
}
@@ -109,7 +104,7 @@ public class DeclaratorWriter extends NodeWriter {
private void writeInitializer(IASTStandardFunctionDeclarator funcDec) {
IASTInitializer init = getInitializer(funcDec);
- if(init != null) {
+ if (init != null) {
init.accept(visitor);
}
}
@@ -123,7 +118,7 @@ public class DeclaratorWriter extends NodeWriter {
private void writeNestedDeclarator(IASTDeclarator funcDec) {
IASTDeclarator nestedDeclarator = funcDec.getNestedDeclarator();
- if(nestedDeclarator != null) {
+ if (nestedDeclarator != null) {
scribe.print('(');
nestedDeclarator.accept(visitor);
scribe.print(')');
@@ -143,7 +138,7 @@ public class DeclaratorWriter extends NodeWriter {
scribe.printSpace();
scribe.print(MUTABLE);
}
- if(funcDec.isPureVirtual()) {
+ if (funcDec.isPureVirtual()) {
scribe.print(PURE_VIRTUAL);
}
writeExceptionSpecification(funcDec, funcDec.getExceptionSpecification());
@@ -167,8 +162,8 @@ public class DeclaratorWriter extends NodeWriter {
protected void writeParameterDeclarations(IASTStandardFunctionDeclarator funcDec, IASTParameterDeclaration[] paraDecls) {
writeNodeList(paraDecls);
- if(funcDec.takesVarArgs()){
- if(paraDecls.length > 0){
+ if (funcDec.takesVarArgs()) {
+ if (paraDecls.length > 0) {
scribe.print(COMMA_SPACE);
}
scribe.print(VAR_ARGS);
@@ -178,15 +173,14 @@ public class DeclaratorWriter extends NodeWriter {
private void writePointer(IASTPointer operator) {
if (operator instanceof ICPPASTPointerToMember) {
ICPPASTPointerToMember pointerToMemberOp = (ICPPASTPointerToMember) operator;
- if(pointerToMemberOp.getName() != null){
+ if (pointerToMemberOp.getName() != null) {
pointerToMemberOp.getName().accept(visitor);
scribe.print(STAR_SPACE);
}
} else {
scribe.print('*');
}
-
-
+
if (operator.isConst()) {
scribe.printStringSpace(CONST);
}
@@ -222,7 +216,7 @@ public class DeclaratorWriter extends NodeWriter {
IASTArrayModifier[] arrMods = arrDecl.getArrayModifiers();
writeArrayModifiers(arrDecl, arrMods);
IASTInitializer initializer = getInitializer(arrDecl);
- if(initializer != null) {
+ if (initializer != null) {
initializer.accept(visitor);
}
}
@@ -255,7 +249,7 @@ public class DeclaratorWriter extends NodeWriter {
scribe.printSpace();
fieldDecl.getBitFieldSize().accept(visitor);
IASTInitializer initializer = getInitializer(fieldDecl);
- if(initializer != null) {
+ if (initializer != null) {
initializer.accept(visitor);
}
}
@@ -267,17 +261,15 @@ public class DeclaratorWriter extends NodeWriter {
scribe.print(')');
scribe.newLine();
writeKnRParameterDeclarations(knrFunct, knrFunct.getParameterDeclarations());
-
-
}
- protected void writeKnRParameterDeclarations(
- ICASTKnRFunctionDeclarator knrFunct, IASTDeclaration[] knrDeclarations) {
+ protected void writeKnRParameterDeclarations(ICASTKnRFunctionDeclarator knrFunct,
+ IASTDeclaration[] knrDeclarations) {
for (int i = 0; i < knrDeclarations.length; ++i) {
scribe.noNewLines();
knrDeclarations[i].accept(visitor);
scribe.newLines();
- if(i + 1 < knrDeclarations.length) {
+ if (i + 1 < knrDeclarations.length) {
scribe.newLine();
}
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/NodeWriter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/NodeWriter.java
index 61a7f24143..5c2b384974 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/NodeWriter.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/NodeWriter.java
@@ -7,7 +7,7 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * Institute for Software - initial API and implementation
+ * Institute for Software - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.rewrite.astwriter;
@@ -21,15 +21,12 @@ import org.eclipse.cdt.core.dom.ast.IASTNodeLocation;
import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap;
/**
- *
* Base class for node writers. This class contains methods and string constants
* used by multiple node writers.
*
* @author Emanuel Graf IFS
- *
*/
public class NodeWriter {
-
protected Scribe scribe;
protected ASTVisitor visitor;
protected NodeCommentMap commentMap;
@@ -72,31 +69,37 @@ public class NodeWriter {
}
protected void writeNodeList(IASTNode[] nodes) {
- for(int i = 0; i < nodes.length; ++i) {
+ for (int i = 0; i < nodes.length; ++i) {
nodes[i].accept(visitor);
- if(i + 1 < nodes.length) {
+ if (i + 1 < nodes.length) {
scribe.print(COMMA_SPACE);
}
}
}
- protected void visitNodeIfNotNull(IASTNode node){
- if(node != null){
+ protected void visitNodeIfNotNull(IASTNode node) {
+ if (node != null) {
node.accept(visitor);
}
}
-
protected void writeTrailingComments(IASTNode node) {
- //default write newLine
+ // Default is to write a new line after trailing comments.
writeTrailingComments(node, true);
}
-
- protected boolean hasTrailingComments(IASTNode node){
- if(getTrailingComments(node).size()>0) {
- return true;
+
+ protected void writeTrailingComments(IASTNode node, boolean newLine) {
+ for (IASTComment comment : getTrailingComments(node)) {
+ scribe.printSpace();
+ scribe.print(comment.getComment());
+ if (newLine) {
+ scribe.newLine();
+ }
}
- return false;
+ }
+
+ protected boolean hasTrailingComments(IASTNode node) {
+ return !getTrailingComments(node).isEmpty();
}
private ArrayList<IASTComment> getTrailingComments(IASTNode node) {
@@ -108,22 +111,9 @@ public class NodeWriter {
}
return trailingComments;
}
-
- protected void writeTrailingComments(IASTNode node, boolean newLine) {
- for(IASTComment comment : getTrailingComments(node)) {
- scribe.printSpace();
- scribe.print(comment.getComment());
- if(newLine) {
- scribe.newLine();
- }
- }
- }
- protected boolean hasFreestandingComments(IASTNode node){
- if(getFreestandingComments(node).size()>0) {
- return true;
- }
- return false;
+ protected boolean hasFreestandingComments(IASTNode node) {
+ return !getFreestandingComments(node).isEmpty();
}
private ArrayList<IASTComment> getFreestandingComments(IASTNode node) {
@@ -137,7 +127,7 @@ public class NodeWriter {
}
protected void writeFreeStandingComments(IASTNode node) {
- for(IASTComment comment : getFreestandingComments(node)) {
+ for (IASTComment comment : getFreestandingComments(node)) {
scribe.print(comment.getComment());
scribe.newLine();
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/StatementWriter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/StatementWriter.java
index 9bae7f9115..fbafe9bf15 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/StatementWriter.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/StatementWriter.java
@@ -7,7 +7,7 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * Institute for Software - initial API and implementation
+ * Institute for Software - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.rewrite.astwriter;
@@ -46,17 +46,14 @@ import org.eclipse.cdt.internal.core.dom.rewrite.util.FileHelper;
import org.eclipse.core.resources.IFile;
/**
- *
* 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
- *
*/
-public class StatementWriter extends NodeWriter{
-
+public class StatementWriter extends NodeWriter {
private static final String DEFAULT = "default:"; //$NON-NLS-1$
private static final String CASE = "case "; //$NON-NLS-1$
private static final String WHILE = "while("; //$NON-NLS-1$
@@ -85,7 +82,7 @@ public class StatementWriter extends NodeWriter{
/**
*
* @param statement
- * @param newLine if true print a newline if statment usually have one.
+ * @param newLine if true print a newline if statement usually have one.
* @return {@link ASTVisitor#PROCESS_SKIP}
*/
protected int writeStatement(IASTStatement statement, boolean newLine) {
@@ -114,14 +111,14 @@ public class StatementWriter extends NodeWriter{
} else if (statement instanceof IASTCaseStatement) {
writeCaseStatement((IASTCaseStatement) statement);
// usually newLine
- }else if (statement instanceof IASTDefaultStatement) {
+ } else if (statement instanceof IASTDefaultStatement) {
writeDefaultStatement((IASTDefaultStatement)statement);
- } else if (statement instanceof IASTContinueStatement){
+ } else if (statement instanceof IASTContinueStatement) {
writeContinueStatement((IASTContinueStatement)statement);
// usually newLine
} else if (statement instanceof IASTCompoundStatement) {
writeCompoundStatement((IASTCompoundStatement) statement);
- if(compoundNoNewLine){
+ if (compoundNoNewLine) {
newLine = false;
compoundNoNewLine = false;
}
@@ -156,13 +153,10 @@ public class StatementWriter extends NodeWriter{
throw new ProblemRuntimeException((IASTProblemStatement)statement);
}
- if(hasTrailingComments(statement)) {
+ if (hasTrailingComments(statement)) {
writeTrailingComments(statement, newLine);
- }
- else{
- if(newLine){
- scribe.newLine();
- }
+ } else if (newLine) {
+ scribe.newLine();
}
return ASTVisitor.PROCESS_SKIP;
@@ -186,15 +180,14 @@ public class StatementWriter extends NodeWriter{
if (forStatment instanceof ICPPASTForStatement) {
ICPPASTForStatement cppForStatment = (ICPPASTForStatement) forStatment;
IASTDeclaration cppConditionDeclaration = cppForStatment.getConditionDeclaration();
- if(cppConditionDeclaration == null) {
+ if (cppConditionDeclaration == null) {
visitNodeIfNotNull(cppForStatment.getConditionExpression());
scribe.printSemicolon();
} else {
cppConditionDeclaration.accept(visitor);
}
-
} else {
- if(forStatment.getConditionExpression() != null) {
+ if (forStatment.getConditionExpression() != null) {
forStatment.getConditionExpression().accept(visitor);
scribe.printSemicolon();
}
@@ -225,7 +218,7 @@ public class StatementWriter extends NodeWriter{
if (ifStatement instanceof ICPPASTIfStatement) {
ICPPASTIfStatement cppIfStatment = (ICPPASTIfStatement) ifStatement;
- if(cppIfStatment.getConditionDeclaration() == null) {
+ if (cppIfStatment.getConditionDeclaration() == null) {
cppIfStatment.getConditionExpression().accept(visitor);
} else {
writeDeclarationWithoutSemicolon(cppIfStatment.getConditionDeclaration());
@@ -238,17 +231,16 @@ public class StatementWriter extends NodeWriter{
scribe.newLines();
nextCompoundNoNewLine();
IASTStatement elseClause = ifStatement.getElseClause();
- writeBodyStatement(ifStatement.getThenClause(), elseClause != null ? true : false);
+ writeBodyStatement(ifStatement.getThenClause(), elseClause != null);
- if(elseClause != null){
+ if (elseClause != null) {
scribe.print(ELSE);
nextCompoundNoNewLine();
writeBodyStatement(elseClause, false);
}
}
- protected void writeDeclarationWithoutSemicolon(
- IASTDeclaration declaration) {
+ protected void writeDeclarationWithoutSemicolon(IASTDeclaration declaration) {
declWriter.writeDeclaration(declaration, false);
}
@@ -279,7 +271,7 @@ public class StatementWriter extends NodeWriter{
scribe.noNewLines();
scribe.print(RETURN);
IASTExpression returnValue = returnStatement.getReturnValue();
- if(returnValue != null){
+ if (returnValue != null) {
scribe.printSpaces(1);
returnValue.accept(visitor);
}
@@ -327,7 +319,7 @@ public class StatementWriter extends NodeWriter{
scribe.noNewLines();
if (whileStatment instanceof ICPPASTWhileStatement) {
ICPPASTWhileStatement cppWhileStatment = (ICPPASTWhileStatement) whileStatment;
- if(cppWhileStatment.getConditionDeclaration() == null) {
+ if (cppWhileStatment.getConditionDeclaration() == null) {
cppWhileStatment.getCondition().accept(visitor);
} else {
writeDeclarationWithoutSemicolon(cppWhileStatment.getConditionDeclaration());
@@ -344,7 +336,7 @@ public class StatementWriter extends NodeWriter{
private void writeCaseStatement(IASTCaseStatement caseStatement) {
nextCompoundIndentationLevelOneMore();
- if(!switchIsNew){
+ if (!switchIsNew) {
scribe.decrementIndentationLevel();
}
scribe.print(CASE);
@@ -361,7 +353,7 @@ public class StatementWriter extends NodeWriter{
scribe.noNewLines();
if (switchStatement instanceof ICPPASTSwitchStatement) {
ICPPASTSwitchStatement cppSwitchStatement = (ICPPASTSwitchStatement) switchStatement;
- if(cppSwitchStatement.getControllerDeclaration() == null) {
+ if (cppSwitchStatement.getControllerDeclaration() == null) {
cppSwitchStatement.getControllerExpression().accept(visitor);
} else {
declWriter.writeDeclaration(cppSwitchStatement.getControllerDeclaration(), false);
@@ -380,7 +372,7 @@ public class StatementWriter extends NodeWriter{
private void writeDefaultStatement(IASTDefaultStatement defaultStatement) {
nextCompoundIndentationLevelOneMore();
- if(!switchIsNew){
+ if (!switchIsNew) {
scribe.decrementIndentationLevel();
}
scribe.print(DEFAULT);
@@ -395,11 +387,11 @@ public class StatementWriter extends NodeWriter{
statements.accept(visitor);
}
- if(hasFreestandingComments(compoundStatement)) {
+ if (hasFreestandingComments(compoundStatement)) {
writeFreeStandingComments(compoundStatement);
}
- if(decrementIndentationLevelOneMore){
+ if (decrementIndentationLevelOneMore) {
scribe.decrementIndentationLevel();
decrementIndentationLevelOneMore = false;
}
@@ -411,14 +403,14 @@ public class StatementWriter extends NodeWriter{
}
protected void writeBodyStatement(IASTStatement statement, boolean isDoStatement) {
- if (statement instanceof IASTCompoundStatement){
+ if (statement instanceof IASTCompoundStatement) {
//TODO hsr existiert noch eine methode
statement.accept(visitor);
- if(!isDoStatement){
+ if (!isDoStatement) {
scribe.newLine();
}
compoundNoNewLine = false;
- } else if (statement instanceof IASTNullStatement){
+ } else if (statement instanceof IASTNullStatement) {
statement.accept(visitor);
scribe.newLine();
} else {
@@ -432,18 +424,16 @@ public class StatementWriter extends NodeWriter{
/**
* Write no new Line after the next Compound-Statement
- *
*/
- protected void nextCompoundNoNewLine(){
+ protected void nextCompoundNoNewLine() {
compoundNoNewLine = true;
}
/**
* Indent one time more at the end (before the closing Brackets)
* of a Compound-Statement
- *
*/
- protected void nextCompoundIndentationLevelOneMore(){
+ protected void nextCompoundIndentationLevelOneMore() {
decrementIndentationLevelOneMore = true;
}
@@ -451,7 +441,7 @@ public class StatementWriter extends NodeWriter{
IFile file = FileHelper.getFileFromNode(statement);
int offset = statement.getFileLocation().getNodeOffset();
int length = statement.getFileLocation().getNodeLength();
- String code =FileContentHelper.getContent(file, offset, length);
+ String code = FileContentHelper.getContent(file, offset, length);
scribe.println(code);
return ASTVisitor.PROCESS_SKIP;
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/ASTModificationHelper.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/ASTModificationHelper.java
index 186f399fb4..df593865e1 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/ASTModificationHelper.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/ASTModificationHelper.java
@@ -7,7 +7,7 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * Institute for Software - initial API and implementation
+ * Institute for Software - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.rewrite.changegenerator;
@@ -28,30 +28,28 @@ import org.eclipse.cdt.internal.core.dom.rewrite.astwriter.ContainerNode;
import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap;
public class ASTModificationHelper {
-
private final ModificationScopeStack modificationStore;
public ASTModificationHelper(ModificationScopeStack stack) {
this.modificationStore = stack;
}
-
- public <T extends IASTNode> T[] createModifiedChildArray(IASTNode parent, T[] unmodifiedChildren, Class<T> clazz, NodeCommentMap commentMap){
+ public <T extends IASTNode> T[] createModifiedChildArray(IASTNode parent, T[] unmodifiedChildren, Class<T> clazz, NodeCommentMap commentMap) {
ArrayList<T> modifiedChildren = new ArrayList<T>(Arrays.asList(unmodifiedChildren));
- for(ASTModification parentModification : modificationsForNode(parent)){
- switch(parentModification.getKind()){
+ for (ASTModification parentModification : modificationsForNode(parent)) {
+ switch (parentModification.getKind()) {
case APPEND_CHILD:
IASTNode newNode = parentModification.getNewNode();
T appendedTNode = cast(newNode, clazz);
if (appendedTNode != null) {
modifiedChildren.add(appendedTNode);
}
- else if (newNode instanceof ContainerNode){
+ else if (newNode instanceof ContainerNode) {
ContainerNode nodeContainer = (ContainerNode) newNode;
- for(IASTNode currentNode : nodeContainer.getNodes()){
+ for (IASTNode currentNode : nodeContainer.getNodes()) {
T tnode= cast(currentNode, clazz);
- if(tnode != null){
+ if (tnode != null) {
modifiedChildren.add(tnode);
}
}
@@ -145,42 +143,35 @@ public class ASTModificationHelper {
@SuppressWarnings("unchecked")
private <T> T cast(IASTNode node, Class<T> clazz) {
- if (clazz.isInstance(node)){
+ if (clazz.isInstance(node)) {
return (T) node;
}
return null;
}
-
- public List<ASTModification> modificationsForNode(
- IASTNode targetNode) {
+ public List<ASTModification> modificationsForNode(IASTNode targetNode) {
List<ASTModification> modificationsForNode;
- if(modificationStore.getModifiedNodes().contains(targetNode)){
+ if (modificationStore.getModifiedNodes().contains(targetNode)) {
modificationsForNode = modificationStore.getModificationsForNode(targetNode);
- }
- else{
+ } else {
modificationsForNode = Collections.emptyList();
}
- return modificationsForNode;
-
+ return modificationsForNode;
}
-
-
+
public IASTInitializer getInitializer(IASTDeclarator decl) {
IASTInitializer initializer = decl.getInitializer();
- if(initializer != null){
- for(ASTModification childModification : modificationsForNode(initializer)){
- switch(childModification.getKind()){
+ if (initializer != null) {
+ for (ASTModification childModification : modificationsForNode(initializer)) {
+ switch (childModification.getKind()) {
case REPLACE:
- if(childModification.getNewNode() instanceof IASTInitializer){
+ if (childModification.getNewNode() instanceof IASTInitializer) {
return (IASTInitializer)childModification.getNewNode();
} else if (childModification.getNewNode() == null) {
return null;
}
throw new UnhandledASTModificationException(childModification);
-
-
case INSERT_BEFORE:
throw new UnhandledASTModificationException(childModification);
@@ -188,13 +179,11 @@ public class ASTModificationHelper {
throw new UnhandledASTModificationException(childModification);
}
}
- }
- else
- {
- for(ASTModification parentModification : modificationsForNode(decl)){
- if(parentModification.getKind() == ModificationKind.APPEND_CHILD){
+ } else {
+ for (ASTModification parentModification : modificationsForNode(decl)) {
+ if (parentModification.getKind() == ModificationKind.APPEND_CHILD) {
IASTNode newNode = parentModification.getNewNode();
- if(newNode instanceof IASTInitializer){
+ if (newNode instanceof IASTInitializer) {
return (IASTInitializer) newNode;
}
}
@@ -203,17 +192,15 @@ public class ASTModificationHelper {
return initializer;
}
-
@SuppressWarnings("unchecked")
public <T extends IASTNode> T getNodeAfterReplacement(T replacedNode) {
List<ASTModification> modifications = modificationsForNode(replacedNode);
- for(ASTModification currentModification : modifications){
- try{
- if(currentModification.getKind() == ModificationKind.REPLACE){
+ for (ASTModification currentModification : modifications) {
+ try {
+ if (currentModification.getKind() == ModificationKind.REPLACE) {
return (T) currentModification.getNewNode();
}
- }
- catch(ClassCastException e){
+ } catch (ClassCastException e) {
throw new UnhandledASTModificationException(currentModification);
}
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/ChangeGeneratorWriterVisitor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/ChangeGeneratorWriterVisitor.java
index c5b9513d1c..72537365b5 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/ChangeGeneratorWriterVisitor.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/ChangeGeneratorWriterVisitor.java
@@ -84,10 +84,8 @@ public class ChangeGeneratorWriterVisitor extends ASTWriterVisitor {
this.fileScope = fileScope;
this.shouldVisitTranslationUnit = true;
this.stack = new ModificationScopeStack(modificationStore);
- declaratorWriter = new ModifiedASTDeclaratorWriter(scribe, this,
- stack, commentMap);
- expWriter = new ModifiedASTExpressionWriter(scribe, this, macroHandler,
- stack, commentMap);
+ declaratorWriter = new ModifiedASTDeclaratorWriter(scribe, this, stack, commentMap);
+ expWriter = new ModifiedASTExpressionWriter(scribe, this, macroHandler, stack, commentMap);
statementWriter = new ModifiedASTStatementWriter(scribe, this, stack, commentMap);
declSpecWriter = new ModifiedASTDeclSpecWriter(scribe, this, stack, commentMap);
declarationWriter = new ModifiedASTDeclarationWriter(scribe, this, stack, commentMap);

Back to the top