Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--core/org.eclipse.cdt.core.tests/META-INF/MANIFEST.MF3
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/CommentTests.java2
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMLocationMacroTests.java3
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMPreprocessorInformationTest.java2
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/RewriteBaseTest.java116
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/RewriteTester.java215
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/RewriteTests.java31
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/TestHelper.java20
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/TestSourceFile.java88
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/astwriter/ASTWriterTest.java140
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/astwriter/ASTWriterTestSourceFile.java44
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/astwriter/AstWriterTestSuite.java55
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/astwriter/SourceRewriteTester.java167
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/ChangeGeneratorTest.java91
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/ChangeGeneratorTestSuite.java39
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/append/AppendTestSuite.java39
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/append/ArrayModifierTest.java71
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/append/ArraySizeExpressionTest.java64
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/append/CtorChainInitializerTest.java72
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/append/ExceptionTest.java74
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/append/ExpressionTest.java69
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/append/ParameterTest.java79
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/append/ParameterToListTest.java79
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/append/PointerToParameterTest.java72
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/append/PointerToPointerParameterTest.java69
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/insertbefore/ArrayModifierTest.java69
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/insertbefore/ArraySizeExpressionTest.java65
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/insertbefore/CtorChainInitializerTest.java70
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/insertbefore/ExceptionTest.java77
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/insertbefore/ExpressionTest.java71
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/insertbefore/FirstParameterTest.java85
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/insertbefore/InsertBeforeTestSuite.java37
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/insertbefore/PointerParameterTest.java71
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/remove/ArrayModifierTest.java63
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/remove/ArraySizeExpressionTest.java62
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/remove/CtorChainInitializerTest.java64
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/remove/DeclarationTest.java69
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/remove/ExceptionTest.java64
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/remove/ExpressionTest.java66
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/remove/FirstParameterTest.java74
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/remove/LastParameterTest.java70
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/remove/MiddleParameterTest.java72
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/remove/NewInitializerExpressionTest.java65
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/remove/PointerInParameterTest.java74
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/remove/RemoveTestSuite.java43
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/remove/SingleParameterTest.java67
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/remove/StatementTest.java66
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/replace/ArrayModifierTest.java69
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/replace/ArraySizeExpressionTest.java65
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/replace/CtorChainInitializerTest.java70
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/replace/ExceptionTest.java78
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/replace/ExpressionTest.java71
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/replace/IdenticalTest.java59
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/replace/InitializerTest.java69
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/replace/MoveRenameTest.java77
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/replace/MoveTest.java71
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/replace/NameTest.java67
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/replace/NewInitializerExpressionTest.java66
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/replace/PointerInParameterTest.java70
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/replace/ReplaceTestSuite.java42
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/replace/SameNameTest.java67
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/replace/StatementTest.java75
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/comenthandler/CommentHandlingTest.java118
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/comenthandler/CommentHandlingTestSuite.java35
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/comenthandler/NodeCommentMapTest.java102
-rw-r--r--core/org.eclipse.cdt.core.tests/resources/rewrite/ASTWriterCommentedDeclSpecTestSource.awts222
-rw-r--r--core/org.eclipse.cdt.core.tests/resources/rewrite/ASTWriterCommentedDeclarationTestSource.awts168
-rw-r--r--core/org.eclipse.cdt.core.tests/resources/rewrite/ASTWriterCommentedDeclaratorTestSource.awts275
-rw-r--r--core/org.eclipse.cdt.core.tests/resources/rewrite/ASTWriterCommentedNameTestSource.awts86
-rw-r--r--core/org.eclipse.cdt.core.tests/resources/rewrite/ASTWriterCommentedStatementTestSource.awts660
-rw-r--r--core/org.eclipse.cdt.core.tests/resources/rewrite/ASTWriterCommentedTestSource.awts1491
-rw-r--r--core/org.eclipse.cdt.core.tests/resources/rewrite/ASTWriterCommentedTestSource2.awts57
-rw-r--r--core/org.eclipse.cdt.core.tests/resources/rewrite/ASTWriterDeclSpecTestSource.awts164
-rw-r--r--core/org.eclipse.cdt.core.tests/resources/rewrite/ASTWriterDeclarationTestSource.awts109
-rw-r--r--core/org.eclipse.cdt.core.tests/resources/rewrite/ASTWriterDeclaratorTestSource.awts93
-rw-r--r--core/org.eclipse.cdt.core.tests/resources/rewrite/ASTWriterExpressionTestSource.awts185
-rw-r--r--core/org.eclipse.cdt.core.tests/resources/rewrite/ASTWriterInitializerTestSource.awts37
-rw-r--r--core/org.eclipse.cdt.core.tests/resources/rewrite/ASTWriterNameTestSource.awts32
-rw-r--r--core/org.eclipse.cdt.core.tests/resources/rewrite/ASTWriterPreprocessorTestSource.awts94
-rw-r--r--core/org.eclipse.cdt.core.tests/resources/rewrite/ASTWriterStatementTestSource.awts283
-rw-r--r--core/org.eclipse.cdt.core.tests/resources/rewrite/ASTWriterTemplateTestSource.awts12
-rw-r--r--core/org.eclipse.cdt.core.tests/resources/rewrite/CommentHandlingTestSource.rts2886
-rw-r--r--core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java4
-rw-r--r--core/org.eclipse.cdt.core/META-INF/MANIFEST.MF15
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ASTVisitor.java1
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/ASTRewriteAnalyzer.java8
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/ASTWriter.java57
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/ASTWriterVisitor.java243
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/ContainerNode.java63
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/DeclSpecWriter.java411
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/DeclarationWriter.java309
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/DeclaratorWriter.java298
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/ExpressionWriter.java634
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/InitializerWriter.java87
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/MacroExpansionHandler.java81
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/NameWriter.java132
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/NodeWriter.java112
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/ProblemRuntimeException.java29
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/Scribe.java180
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/StatementWriter.java430
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/TemplateParameterWriter.java91
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/ASTModificationHelper.java146
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/CTextFileChange.java223
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/ChangeGenerator.java566
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/ChangeGeneratorWriterVisitor.java378
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/Messages.java31
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/ModifiedASTDeclSpecWriter.java37
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/ModifiedASTDeclaratorWriter.java102
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/ModifiedASTExpressionWriter.java89
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/ModifiedASTStatementWriter.java43
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/UnhandledASTModificationException.java36
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/messages.properties2
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/commenthandler/ASTCommenter.java84
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/commenthandler/ASTCommenterVisitor.java197
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/commenthandler/CommentHandler.java42
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/commenthandler/NodeCommentMap.java116
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/commenthandler/NodeCommenter.java247
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/util/FileContentHelper.java100
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/util/FileHelper.java78
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/util/OffsetHelper.java97
120 files changed, 17078 insertions, 14 deletions
diff --git a/core/org.eclipse.cdt.core.tests/META-INF/MANIFEST.MF b/core/org.eclipse.cdt.core.tests/META-INF/MANIFEST.MF
index 509c38b1905..c93f2c5fc0e 100644
--- a/core/org.eclipse.cdt.core.tests/META-INF/MANIFEST.MF
+++ b/core/org.eclipse.cdt.core.tests/META-INF/MANIFEST.MF
@@ -23,7 +23,8 @@ Require-Bundle: org.eclipse.core.resources,
org.eclipse.ui.ide,
org.eclipse.ui,
org.eclipse.jface.text,
- org.eclipse.core.filesystem
+ org.eclipse.core.filesystem,
+ org.eclipse.ltk.core.refactoring;bundle-version="3.4.0"
Bundle-ActivationPolicy: lazy
Bundle-Vendor: Eclipse.org
Bundle-RequiredExecutionEnvironment: J2SE-1.5
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/CommentTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/CommentTests.java
index ccafed302df..b89c169fe54 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/CommentTests.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/CommentTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007 Institute for Software, HSR Hochschule fuer Technik
+ * Copyright (c) 2008 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
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMLocationMacroTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMLocationMacroTests.java
index 401fea7a0fb..04bd7cb8d2c 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMLocationMacroTests.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMLocationMacroTests.java
@@ -26,6 +26,7 @@ import org.eclipse.cdt.core.dom.ast.IASTPreprocessorFunctionStyleMacroDefinition
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroExpansion;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorObjectStyleMacroDefinition;
+import org.eclipse.cdt.core.dom.ast.IASTPreprocessorStatement;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorUndefStatement;
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
@@ -295,7 +296,7 @@ public class DOMLocationMacroTests extends AST2BaseTest {
assertEquals( firstReferences.length, 2 );
assertEquals( firstReferences[0].getPropertyInParent(), IASTPreprocessorMacroExpansion.EXPANSION_NAME );
assertEquals( firstReferences[0].getParent().getParent(), tu );
- assertEquals( firstReferences[1].getPropertyInParent(), IASTPreprocessorUndefStatement.MACRO_NAME );
+ assertEquals( firstReferences[1].getPropertyInParent(), IASTPreprocessorStatement.MACRO_NAME );
assertTrue( firstReferences[1].getParent() instanceof IASTPreprocessorUndefStatement );
assertEquals( firstDeclarations.length, 1 );
assertSame( ABC1.getName(), firstDeclarations[0] );
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMPreprocessorInformationTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMPreprocessorInformationTest.java
index 030b6ffbf7e..7e992968a13 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMPreprocessorInformationTest.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMPreprocessorInformationTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007 Institute for Software, HSR Hochschule fuer Technik
+ * Copyright (c) 2008 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
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/RewriteBaseTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/RewriteBaseTest.java
new file mode 100644
index 00000000000..8952f7df321
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/RewriteBaseTest.java
@@ -0,0 +1,116 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.core.parser.tests.rewrite;
+
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.util.Map;
+import java.util.TreeMap;
+import java.util.Vector;
+
+import org.eclipse.cdt.core.tests.BaseTestFramework;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.ILogListener;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jface.text.TextSelection;
+
+/**
+ * @author Guido Zgraggen IFS
+ *
+ */
+public abstract class RewriteBaseTest extends BaseTestFramework implements ILogListener{
+ protected static final NullProgressMonitor NULL_PROGRESS_MONITOR = new NullProgressMonitor();
+
+ protected TreeMap<String, TestSourceFile> fileMap = new TreeMap<String, TestSourceFile>();
+ protected String fileWithSelection;
+ protected TextSelection selection;
+
+ protected RewriteBaseTest(String name) {
+ super(name);
+ }
+
+ public RewriteBaseTest(String name, Vector<TestSourceFile> files) {
+ super(name);
+ for (TestSourceFile file : files) {
+ fileMap.put(file.getName(), file);
+ }
+ }
+
+ @Override
+ protected abstract void runTest() throws Throwable;
+
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ for (TestSourceFile testFile : fileMap.values()) {
+ if(testFile.getSource().length() > 0) {
+ importFile(testFile.getName(), testFile.getSource());
+ }
+ }
+ }
+
+ protected void assertEquals(TestSourceFile file, IFile file2) throws Exception {
+ StringBuffer code = getCodeFromIFile(file2);
+ assertEquals(file.getExpectedSource(), TestHelper.unifyNewLines(code.toString()));
+ }
+
+ protected void compareFiles(Map<String,TestSourceFile> testResourceFiles) throws Exception {
+ for (String fileName : testResourceFiles.keySet()) {
+ TestSourceFile file = testResourceFiles.get(fileName);
+ IFile iFile = project.getFile(new Path(fileName));
+ StringBuffer code = getCodeFromIFile(iFile);
+ assertEquals(TestHelper.unifyNewLines(file.getExpectedSource()), TestHelper.unifyNewLines(code.toString()));
+ }
+ }
+
+ protected StringBuffer getCodeFromIFile(IFile file) throws Exception {
+ BufferedReader br = new BufferedReader(new InputStreamReader(file.getContents()));
+ StringBuffer code = new StringBuffer();
+ String line;
+ while((line = br.readLine()) != null) {
+ code.append(line);
+ code.append('\n');
+ }
+ br.close();
+ return code;
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ System.gc();
+ fileManager.closeAllFiles();
+ super.tearDown();
+ }
+
+ public void logging(IStatus status, String plugin) {
+ Throwable ex = status.getException();
+ StringBuffer stackTrace = new StringBuffer();
+ if(ex != null) {
+ stackTrace.append('\n');
+ for(StackTraceElement ste : ex.getStackTrace()) {
+ stackTrace.append(ste.toString());
+ }
+ }
+ fail("Log-Message: " + status.getMessage() + stackTrace.toString()); //$NON-NLS-1$
+ }
+
+ public void setFileWithSelection(String fileWithSelection) {
+ this.fileWithSelection = fileWithSelection;
+ }
+
+ public void setSelection(TextSelection selection) {
+ this.selection = selection;
+ }
+}
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/RewriteTester.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/RewriteTester.java
new file mode 100644
index 00000000000..3ccb632a8ba
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/RewriteTester.java
@@ -0,0 +1,215 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.core.parser.tests.rewrite;
+
+import java.io.BufferedReader;
+import java.io.FileReader;
+import java.io.IOException;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.Vector;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.eclipse.cdt.core.testplugin.CTestPlugin;
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jface.text.TextSelection;
+import org.osgi.framework.Bundle;
+
+/**
+ * @author Emanuel Graf
+ *
+ */
+public class RewriteTester extends TestSuite{
+
+ enum MatcherState{skip, inTest, inSource, inExpectedResult}
+
+ private static final String classRegexp = "//#(.*)\\s*(\\w*)*$"; //$NON-NLS-1$
+ private static final String testRegexp = "//!(.*)\\s*(\\w*)*$"; //$NON-NLS-1$
+ private static final String fileRegexp = "//@(.*)\\s*(\\w*)*$"; //$NON-NLS-1$
+ private static final String resultRegexp = "//=.*$"; //$NON-NLS-1$
+
+ public static Test suite(String name, String file)throws Exception {
+ BufferedReader in = createReader(file);
+
+ ArrayList<RewriteBaseTest> testCases = createTests(in);
+ in.close();
+ return createSuite(testCases, name);
+ }
+
+ protected static BufferedReader createReader(String file) throws IOException {
+ Bundle bundle = CTestPlugin.getDefault().getBundle();
+ Path path = new Path(file);
+ String file2 = FileLocator.toFileURL(FileLocator.find(bundle, path, null)).getFile();
+ return new BufferedReader(new FileReader(file2));
+ }
+
+ private static ArrayList<RewriteBaseTest> createTests(BufferedReader inputReader) throws Exception {
+
+ String line;
+ Vector<TestSourceFile> files = new Vector<TestSourceFile>();
+ TestSourceFile actFile = null;
+ MatcherState matcherState = MatcherState.skip;
+ ArrayList<RewriteBaseTest> testCases = new ArrayList<RewriteBaseTest>();
+ String testName = null;
+ String className = null;
+ boolean bevorFirstTest = true;
+
+ while ((line = inputReader.readLine()) != null){
+
+ if(lineMatchesBeginOfTest(line)) {
+ if(!bevorFirstTest) {
+ RewriteBaseTest test = createTestClass(className, testName, files);
+ testCases.add(test);
+ files = new Vector<TestSourceFile>();
+ className = null;
+ testName = null;
+ }
+ matcherState = MatcherState.inTest;
+ testName = getNameOfTest(line);
+ bevorFirstTest = false;
+ continue;
+ } else if (lineMatchesBeginOfResult(line)) {
+ matcherState = MatcherState.inExpectedResult;
+ continue;
+ }else if (lineMatchesFileName(line)) {
+ matcherState = MatcherState.inSource;
+ actFile = new TestSourceFile(getFileName(line));
+ files.add(actFile);
+ continue;
+ }else if(lineMatchesClassName(line)) {
+ className = getNameOfClass(line);
+ continue;
+ }
+
+ switch(matcherState) {
+ case inSource:
+ if(actFile != null) {
+ actFile.addLineToSource(line);
+ }
+ break;
+ case inExpectedResult:
+ if(actFile != null) {
+ actFile.addLineToExpectedSource(line);
+ }
+ break;
+ default:
+ break;
+ }
+ }
+ RewriteBaseTest test = createTestClass(className, testName, files);
+ testCases.add(test);
+ return testCases;
+ }
+
+
+
+ private static RewriteBaseTest createTestClass(String className, String testName, Vector<TestSourceFile> files) throws Exception {
+
+
+ try {
+ Class<?> refClass = Class.forName(className);
+ Class<?> paratypes[] = new Class[2];
+ paratypes[0] = testName.getClass();
+ paratypes[1] = files.getClass();
+ Constructor<?> ct = refClass.getConstructor(paratypes);
+ Object arglist[] = new Object[2];
+ arglist[0] = testName;
+ arglist[1] = files;
+ RewriteBaseTest test = (RewriteBaseTest) ct.newInstance(arglist);
+ for (TestSourceFile file : files) {
+ TextSelection sel = file.getSelection();
+ if(sel != null) {
+ test.setFileWithSelection(file.getName());
+ test.setSelection(sel);
+ break;
+ }
+ }
+ return test;
+ } catch (ClassNotFoundException e) {
+ throw new Exception("Unknown TestClass. Make sure the test's sourcefile specifies a valid test class.");
+ } catch (SecurityException e) {
+ throw new Exception("Security Exception during Test creation", e);
+ } catch (NoSuchMethodException e) {
+ throw new Exception("Test class does not provied required constructor.");
+ } catch (IllegalArgumentException e) {
+ throw new Exception("IllegalArgumentException during Test creation", e);
+ } catch (InstantiationException e) {
+ throw new Exception("InstantiationException during Test creation", e);
+ } catch (IllegalAccessException e) {
+ throw new Exception("IllegalAccessException during Test creation", e);
+ } catch (InvocationTargetException e) {
+ throw new Exception("InvocationTargetException during Test creation", e);
+ }
+ }
+
+ private static String getFileName(String line) {
+ Matcher matcherBeginOfTest = createMatcherFromString(fileRegexp, line);
+ if(matcherBeginOfTest.find())
+ return matcherBeginOfTest.group(1);
+ else
+ return null;
+ }
+
+ private static String getNameOfClass(String line) {
+ Matcher matcherBeginOfTest = createMatcherFromString(classRegexp, line);
+ if(matcherBeginOfTest.find())
+ return matcherBeginOfTest.group(1);
+ else
+ return null;
+ }
+
+ private static boolean lineMatchesBeginOfTest(String line) {
+ return createMatcherFromString(testRegexp, line).find();
+ }
+
+ private static boolean lineMatchesClassName(String line) {
+ return createMatcherFromString(classRegexp, line).find();
+ }
+
+ private static boolean lineMatchesFileName(String line) {
+ return createMatcherFromString(fileRegexp, line).find();
+ }
+
+ protected static Matcher createMatcherFromString(String pattern, String line) {
+ return Pattern.compile(pattern).matcher(line);
+ }
+
+ private static String getNameOfTest(String line) {
+ Matcher matcherBeginOfTest = createMatcherFromString(testRegexp, line);
+ if(matcherBeginOfTest.find())
+ return matcherBeginOfTest.group(1);
+ else
+ return "Not Named";
+ }
+
+ private static boolean lineMatchesBeginOfResult(String line) {
+ return createMatcherFromString(resultRegexp, line).find();
+ }
+
+ private static TestSuite createSuite(ArrayList<RewriteBaseTest> testCases, String name) {
+ TestSuite suite = new TestSuite(name);
+ Iterator<RewriteBaseTest> it = testCases.iterator();
+ while(it.hasNext()) {
+ RewriteBaseTest subject =it.next();
+ suite.addTest(subject);
+ }
+ return suite;
+ }
+}
+
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/RewriteTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/RewriteTests.java
new file mode 100644
index 00000000000..fe6d7258b52
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/RewriteTests.java
@@ -0,0 +1,31 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.core.parser.tests.rewrite;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.eclipse.cdt.core.parser.tests.rewrite.astwriter.AstWriterTestSuite;
+import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTestSuite;
+import org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTestSuite;
+
+public class RewriteTests extends TestSuite {
+
+ public static Test suite() throws Exception {
+ TestSuite suite = new TestSuite(RewriteTests.class.getName());
+ suite.addTest(AstWriterTestSuite.suite());
+ suite.addTest(CommentHandlingTestSuite.suite());
+ suite.addTest(ChangeGeneratorTestSuite.suite());
+ return suite;
+ }
+
+}
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/TestHelper.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/TestHelper.java
new file mode 100644
index 00000000000..3bd8ac7c0a8
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/TestHelper.java
@@ -0,0 +1,20 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.core.parser.tests.rewrite;
+
+public class TestHelper {
+
+ public static String unifyNewLines(String code) {
+ String replacement = System.getProperty("line.separator"); //$NON-NLS-1$
+ return code.replaceAll("(\n)|(\r\n)", replacement); //$NON-NLS-1$
+ }
+}
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/TestSourceFile.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/TestSourceFile.java
new file mode 100644
index 00000000000..e2d3f4de406
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/TestSourceFile.java
@@ -0,0 +1,88 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.core.parser.tests.rewrite;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.eclipse.jface.text.TextSelection;
+
+/**
+ * @author Emanuel Graf
+ *
+ */
+public class TestSourceFile {
+
+ private static final String REPLACEMENT = ""; //$NON-NLS-1$
+ private String name;
+ private StringBuffer source = new StringBuffer();
+ private StringBuffer expectedSource = new StringBuffer();
+ private String separator = System.getProperty("line.separator"); //$NON-NLS-1$
+ private int selectionStart = -1;
+ private int selectionEnd = -1;
+
+ protected static final String selectionStartRegex = "//\\$"; //$NON-NLS-1$
+ protected static final String selectionEndRegex = "\\$//"; //$NON-NLS-1$
+ protected static final String selectionStartLineRegex = "(.*)(" + selectionStartRegex + ")(.*)"; //$NON-NLS-1$ //$NON-NLS-2$
+ protected static final String selectionEndLineRegex = "(.*)("+ selectionEndRegex + ")(.*)"; //$NON-NLS-1$ //$NON-NLS-2$
+
+ public TestSourceFile(String name) {
+ super();
+ this.name = name;
+ }
+ public String getExpectedSource() {
+ String exp = expectedSource.toString();
+ if(exp.length() == 0) {
+ return getSource();
+ }else {
+ return exp;
+ }
+ }
+ public String getName() {
+ return name;
+ }
+ public String getSource() {
+ return source.toString();
+ }
+
+ public void addLineToSource(String code) {
+ Matcher start = createMatcherFromString(selectionStartLineRegex, code);
+ if(start.matches()) {
+ selectionStart = start.start(2) + source.length();
+ code = code.replaceAll(selectionStartRegex, REPLACEMENT);
+ }
+ Matcher end = createMatcherFromString(selectionEndLineRegex, code);
+ if(end.matches()) {
+ selectionEnd = end.start(2) + source.length();
+ code = code.replaceAll(selectionEndRegex, REPLACEMENT);
+ }
+ source.append(code);
+ source.append(separator);
+ }
+
+ public void addLineToExpectedSource(String code) {
+ expectedSource.append(code);
+ expectedSource.append(separator);
+ }
+
+ public TextSelection getSelection() {
+ if(selectionStart < 0 || selectionEnd <0 ) {
+ return null;
+ }else {
+ return new TextSelection(selectionStart, selectionEnd -selectionStart);
+ }
+ }
+
+ protected static Matcher createMatcherFromString(String pattern, String line) {
+ return Pattern.compile(pattern).matcher(line);
+ }
+}
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/astwriter/ASTWriterTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/astwriter/ASTWriterTest.java
new file mode 100644
index 00000000000..3a535119e40
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/astwriter/ASTWriterTest.java
@@ -0,0 +1,140 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.core.parser.tests.rewrite.astwriter;
+
+import java.util.Map;
+
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
+import org.eclipse.cdt.core.dom.parser.ISourceCodeParser;
+import org.eclipse.cdt.core.dom.parser.c.ANSICParserExtensionConfiguration;
+import org.eclipse.cdt.core.dom.parser.c.GCCParserExtensionConfiguration;
+import org.eclipse.cdt.core.dom.parser.c.ICParserExtensionConfiguration;
+import org.eclipse.cdt.core.dom.parser.cpp.ANSICPPParserExtensionConfiguration;
+import org.eclipse.cdt.core.dom.parser.cpp.GPPParserExtensionConfiguration;
+import org.eclipse.cdt.core.dom.parser.cpp.ICPPParserExtensionConfiguration;
+import org.eclipse.cdt.core.parser.CodeReader;
+import org.eclipse.cdt.core.parser.IParserLogService;
+import org.eclipse.cdt.core.parser.IScanner;
+import org.eclipse.cdt.core.parser.NullLogService;
+import org.eclipse.cdt.core.parser.ParserLanguage;
+import org.eclipse.cdt.core.parser.ParserMode;
+import org.eclipse.cdt.core.parser.ScannerInfo;
+import org.eclipse.cdt.core.parser.tests.ast2.AST2BaseTest;
+import org.eclipse.cdt.core.parser.tests.rewrite.RewriteBaseTest;
+import org.eclipse.cdt.core.parser.tests.rewrite.TestHelper;
+import org.eclipse.cdt.core.parser.tests.rewrite.TestSourceFile;
+import org.eclipse.cdt.internal.core.dom.parser.c.GNUCSourceParser;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.GNUCPPSourceParser;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationMap;
+import org.eclipse.cdt.internal.core.dom.rewrite.astwriter.ASTWriter;
+import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.ASTCommenter;
+import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap;
+import org.eclipse.core.resources.IFile;
+
+/**
+ * @author Guido Zgraggen
+ */
+public class ASTWriterTest extends RewriteBaseTest {
+ private static final IParserLogService NULL_LOG = new NullLogService();
+
+ private IFile file;
+
+ public ASTWriterTest(String name, ASTWriterTestSourceFile file) {
+ super(name);
+ fileMap.put(file.getName(), file);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ for (TestSourceFile testFile : fileMap.values()) {
+ if(testFile.getSource().length() > 0) {
+ file = importFile(testFile.getName(), testFile.getSource());
+ }
+ }
+ }
+
+
+ @Override
+ protected void runTest() throws Throwable {
+ file = project.getFile("ASTWritterTest.h"); //$NON-NLS-1$
+ compareFiles(fileMap);
+ }
+
+ @Override
+ protected void compareFiles(Map<String,TestSourceFile> testResourceFiles) throws Exception {
+ for (String fileName : testResourceFiles.keySet()) {
+ TestSourceFile testFile = testResourceFiles.get(fileName);
+ String code = generateSource(testFile);
+ assertEquals(TestHelper.unifyNewLines(testFile.getExpectedSource()), TestHelper.unifyNewLines(code + System.getProperty("line.separator"))); //$NON-NLS-1$
+ }
+ }
+
+ public String generateSource(TestSourceFile testFile) throws Exception {
+ IASTTranslationUnit unit = getParser(testFile).parse();
+ NodeCommentMap commentMap = ASTCommenter.getCommentedNodeMap(unit);
+ ASTModificationMap map = new ASTModificationMap();
+ map.getModificationsForNode(unit.getDeclarations()[0]);
+ ASTWriter writer = new ASTWriter();
+ return writer.write(unit, null, commentMap);
+ }
+
+ protected ISourceCodeParser getParser(TestSourceFile testFile) throws Exception {
+ CodeReader codeReader = new CodeReader(file.getLocation().toOSString(), file.getContents());
+
+ ScannerInfo scannerInfo = new ScannerInfo();
+ ParserLanguage language = getLanguage(testFile);
+ boolean useGNUExtensions = getGNUExtension(testFile);
+
+ IScanner scanner = AST2BaseTest.createScanner(codeReader, language, ParserMode.COMPLETE_PARSE, scannerInfo, true);
+
+ ISourceCodeParser parser2 = null;
+ if( language == ParserLanguage.CPP ) {
+ ICPPParserExtensionConfiguration config = null;
+ if (useGNUExtensions){
+ config = new GPPParserExtensionConfiguration();
+ } else{
+ config = new ANSICPPParserExtensionConfiguration();
+ }
+ parser2 = new GNUCPPSourceParser(scanner, ParserMode.COMPLETE_PARSE, NULL_LOG, config );
+ } else {
+ ICParserExtensionConfiguration config = null;
+
+ if (useGNUExtensions){
+ config = new GCCParserExtensionConfiguration();
+ } else{
+ config = new ANSICParserExtensionConfiguration();
+ }
+
+ parser2 = new GNUCSourceParser(scanner, ParserMode.COMPLETE_PARSE, NULL_LOG, config );
+ }
+ return parser2;
+ }
+
+ private boolean getGNUExtension(TestSourceFile file) {
+ if(file instanceof ASTWriterTestSourceFile) {
+ return ((ASTWriterTestSourceFile)file).isUseGNUExtensions();
+ }
+ else {
+ return false;
+ }
+ }
+
+ private ParserLanguage getLanguage(TestSourceFile file) {
+ if(file instanceof ASTWriterTestSourceFile) {
+ return ((ASTWriterTestSourceFile)file).getParserLanguage();
+ }
+ else {
+ return ParserLanguage.CPP;
+ }
+ }
+}
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/astwriter/ASTWriterTestSourceFile.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/astwriter/ASTWriterTestSourceFile.java
new file mode 100644
index 00000000000..82024fe01eb
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/astwriter/ASTWriterTestSourceFile.java
@@ -0,0 +1,44 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Institute for Software - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.cdt.core.parser.tests.rewrite.astwriter;
+
+import org.eclipse.cdt.core.parser.ParserLanguage;
+import org.eclipse.cdt.core.parser.tests.rewrite.TestSourceFile;
+
+/**
+ * @author Guido Zgraggen IFS
+ *
+ */
+public class ASTWriterTestSourceFile extends TestSourceFile {
+ private ParserLanguage parserLanguage = ParserLanguage.CPP;
+ private boolean useGNUExtensions = false;
+
+ public ASTWriterTestSourceFile(String name) {
+ super(name);
+ }
+
+ public void setParserLanguage(ParserLanguage lang) {
+ this.parserLanguage = lang;
+ }
+
+ public ParserLanguage getParserLanguage() {
+ return parserLanguage;
+ }
+
+ public boolean isUseGNUExtensions() {
+ return useGNUExtensions;
+ }
+
+ public void setUseGNUExtensions(boolean useGNUExtensions) {
+ this.useGNUExtensions = useGNUExtensions;
+ }
+}
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/astwriter/AstWriterTestSuite.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/astwriter/AstWriterTestSuite.java
new file mode 100644
index 00000000000..65d0aef7877
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/astwriter/AstWriterTestSuite.java
@@ -0,0 +1,55 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2007 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:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.core.parser.tests.rewrite.astwriter;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * @author Emanuel Graf
+ *
+ */
+public class AstWriterTestSuite{
+
+ @SuppressWarnings("nls")
+ public static Test suite() throws Exception {
+ TestSuite suite = new TestSuite("AstWriterTests");
+ suite.addTest(SourceRewriteTester.suite("ExpressionTests", "resources/rewrite/ASTWriterExpressionTestSource.awts"));
+
+ suite.addTest(SourceRewriteTester.suite("DelcSpecifierTests", "resources/rewrite/ASTWriterDeclSpecTestSource.awts"));
+ suite.addTest(SourceRewriteTester.suite("Commented DelcSpecifierTests",
+ "resources/rewrite/ASTWriterCommentedDeclSpecTestSource.awts"));
+
+ suite.addTest(SourceRewriteTester.suite("DeclaratorTests", "resources/rewrite/ASTWriterDeclaratorTestSource.awts"));
+ suite.addTest(SourceRewriteTester.suite("Commented DeclaratorTests",
+ "resources/rewrite/ASTWriterCommentedDeclaratorTestSource.awts"));
+
+ suite.addTest(SourceRewriteTester.suite("StatementsTests", "resources/rewrite/ASTWriterStatementTestSource.awts"));
+ suite.addTest(SourceRewriteTester
+ .suite("Commented StatementsTests", "resources/rewrite/ASTWriterCommentedStatementTestSource.awts"));
+
+ suite.addTest(SourceRewriteTester.suite("NameTests", "resources/rewrite/ASTWriterNameTestSource.awts"));
+ suite.addTest(SourceRewriteTester.suite("Commented NameTests", "resources/rewrite/ASTWriterCommentedNameTestSource.awts"));
+
+ suite.addTest(SourceRewriteTester.suite("InitializerTests", "resources/rewrite/ASTWriterInitializerTestSource.awts"));
+
+ suite.addTest(SourceRewriteTester.suite("DeclarationTests", "resources/rewrite/ASTWriterDeclarationTestSource.awts"));
+ suite.addTest(SourceRewriteTester.suite("Commented DeclarationTests",
+ "resources/rewrite/ASTWriterCommentedDeclarationTestSource.awts"));
+
+ suite.addTest(SourceRewriteTester.suite("TemplatesTests", "resources/rewrite/ASTWriterTemplateTestSource.awts"));
+
+ suite.addTest(SourceRewriteTester.suite("CommentTests", "resources/rewrite/ASTWriterCommentedTestSource.awts"));
+ suite.addTest(SourceRewriteTester.suite("NewCommentTests", "resources/rewrite/ASTWriterCommentedTestSource2.awts"));
+ return suite;
+ }
+}
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/astwriter/SourceRewriteTester.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/astwriter/SourceRewriteTester.java
new file mode 100644
index 00000000000..26ba7fd4f18
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/astwriter/SourceRewriteTester.java
@@ -0,0 +1,167 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.core.parser.tests.rewrite.astwriter;
+
+import java.io.BufferedReader;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.eclipse.cdt.core.parser.ParserLanguage;
+import org.eclipse.cdt.core.parser.tests.rewrite.RewriteBaseTest;
+import org.eclipse.cdt.core.testplugin.CTestPlugin;
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jface.text.TextSelection;
+import org.osgi.framework.Bundle;
+
+public class SourceRewriteTester extends TestSuite {
+
+ private static final String testRegexp = "//!(.*)\\s*(\\w*)*$"; //$NON-NLS-1$
+ private static final String codeTypeRegexp = "//%(C|CPP)( GNU)?$"; //$NON-NLS-1$
+ private static final String resultRegexp = "//=.*$"; //$NON-NLS-1$
+
+ enum MatcherState{skip, inTest, inSource, inExpectedResult}
+
+ protected static BufferedReader createReader(String file) throws IOException {
+ Bundle bundle = CTestPlugin.getDefault().getBundle();
+ Path path = new Path(file);
+ String file2 = FileLocator.toFileURL(FileLocator.find(bundle, path, null)).getFile();
+ return new BufferedReader(new FileReader(file2));
+ }
+
+ public static Test suite(String name, String file)throws Exception {
+ BufferedReader in = createReader(file);
+
+ ArrayList<RewriteBaseTest> testCases = createTests(in);
+ in.close();
+ return createSuite(testCases, name);
+ }
+
+ private static TestSuite createSuite(ArrayList<RewriteBaseTest> testCases, String name) {
+ TestSuite suite = new TestSuite(name);
+ Iterator<RewriteBaseTest> it = testCases.iterator();
+ while(it.hasNext()) {
+ RewriteBaseTest subject =it.next();
+ suite.addTest(subject);
+ }
+ return suite;
+ }
+
+ protected static boolean lineMatchesBeginOfTest(String line) {
+ return createMatcherFromString(testRegexp, line).find();
+ }
+
+ protected static boolean lineMatchesCodeType(String line) {
+ return createMatcherFromString(codeTypeRegexp, line).find();
+ }
+
+ protected static Matcher createMatcherFromString(String pattern, String line) {
+ return Pattern.compile(pattern).matcher(line);
+ }
+
+ protected static String getNameOfTest(String line) {
+ Matcher matcherBeginOfTest = createMatcherFromString(testRegexp, line);
+ if(matcherBeginOfTest.find())
+ return matcherBeginOfTest.group(1);
+ else
+ return "Not Named";
+ }
+
+ protected static boolean lineMatchesBeginOfResult(String line) {
+ return createMatcherFromString(resultRegexp, line).find();
+ }
+
+ private static ArrayList<RewriteBaseTest> createTests(BufferedReader inputReader) throws Exception {
+ String line;
+ ASTWriterTestSourceFile file = null;
+ MatcherState matcherState = MatcherState.skip;
+ ArrayList<RewriteBaseTest> testCases = new ArrayList<RewriteBaseTest>();
+
+ while ((line = inputReader.readLine()) != null){
+ if(lineMatchesBeginOfTest(line)) {
+ matcherState = MatcherState.inTest;
+ file = new ASTWriterTestSourceFile("ASTWritterTest.h"); //$NON-NLS-1$
+ testCases.add(createTestClass(getNameOfTest(line), file));
+ continue;
+ } else if (lineMatchesBeginOfResult(line)) {
+ matcherState = MatcherState.inExpectedResult;
+ continue;
+ }else if (lineMatchesCodeType(line)) {
+ matcherState = MatcherState.inSource;
+ if(file != null) {
+ file.setParserLanguage(getParserLanguage(line));
+ file.setUseGNUExtensions(useGNUExtensions(line));
+ }
+ continue;
+ }
+
+ switch(matcherState) {
+ case inSource:
+ if(file != null) {
+ file.addLineToSource(line);
+ }
+ break;
+ case inExpectedResult:
+ if(file != null) {
+ file.addLineToExpectedSource(line);
+ }
+ break;
+ default:
+ break;
+ }
+ }
+ return testCases;
+ }
+
+ protected static boolean useGNUExtensions(String line) {
+ Matcher matcherBeginOfTest = createMatcherFromString(codeTypeRegexp, line);
+ if(matcherBeginOfTest.find()) {
+ String codeType = matcherBeginOfTest.group(2);
+ if(codeType == null) {
+ return false;
+ }else {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ protected static ParserLanguage getParserLanguage(String line) {
+ Matcher matcherBeginOfTest = createMatcherFromString(codeTypeRegexp, line);
+ if(matcherBeginOfTest.find()) {
+ String codeType = matcherBeginOfTest.group(1);
+ if(codeType.equalsIgnoreCase("CPP")) { //$NON-NLS-1$
+ return ParserLanguage.CPP;
+ }else {
+ return ParserLanguage.C;
+ }
+ }
+ return ParserLanguage.C;
+ }
+
+ private static RewriteBaseTest createTestClass(String testName, ASTWriterTestSourceFile file) throws Exception {
+ ASTWriterTest test = new ASTWriterTest(testName,file);
+ TextSelection sel = file.getSelection();
+ if(sel != null) {
+ test.setFileWithSelection(file.getName());
+ test.setSelection(sel);
+ }
+ return test;
+ }
+}
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/ChangeGeneratorTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/ChangeGeneratorTest.java
new file mode 100644
index 00000000000..95d96c18276
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/ChangeGeneratorTest.java
@@ -0,0 +1,91 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator;
+
+import org.eclipse.cdt.core.CCorePlugin;
+import org.eclipse.cdt.core.dom.CDOM;
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
+import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
+import org.eclipse.cdt.core.index.IIndexManager;
+import org.eclipse.cdt.core.parser.tests.rewrite.TestHelper;
+import org.eclipse.cdt.core.tests.BaseTestFramework;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
+import org.eclipse.cdt.internal.core.dom.rewrite.changegenerator.CTextFileChange;
+import org.eclipse.cdt.internal.core.dom.rewrite.changegenerator.ChangeGenerator;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jface.text.Document;
+import org.eclipse.ltk.core.refactoring.Change;
+import org.eclipse.ltk.core.refactoring.CompositeChange;
+
+public abstract class ChangeGeneratorTest extends BaseTestFramework {
+
+ protected String source;
+ protected String expectedSource;
+
+ public ChangeGeneratorTest() {
+ super();
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ CCorePlugin.getIndexManager().joinIndexer(IIndexManager.FOREVER, new NullProgressMonitor());
+ super.setUp();
+ }
+
+ @Override
+ public void runTest() {
+ final ASTModificationStore modStore = new ASTModificationStore();
+ final ChangeGenerator changegenartor = new ChangeGenerator(modStore);
+ try {
+ importFile("source.h", source); //$NON-NLS-1$
+
+ IASTTranslationUnit unit = CDOM.getInstance().getTranslationUnit(
+ project.getFile(new Path("source.h")), //$NON-NLS-1$
+ CDOM.getInstance().getCodeReaderFactory(
+ CDOM.PARSE_SAVED_RESOURCES),
+ true);
+ CPPASTVisitor visitor = createModificator(modStore);
+
+ unit.accept(visitor);
+
+
+ // assertEquals(expectedSource, changegenartor.write(unit));
+ changegenartor.generateChange(unit);
+ Document doc = new Document(source);
+ for(Change curChange : ((CompositeChange)changegenartor.getChange()).getChildren()){
+ if (curChange instanceof CTextFileChange) {
+ CTextFileChange textChange = (CTextFileChange) curChange;
+ textChange.getEdit().apply(doc);
+ }
+ }
+ assertEquals(TestHelper.unifyNewLines(expectedSource), TestHelper.unifyNewLines(doc.get()));
+ } catch (Exception e) {
+ e.printStackTrace();
+ assertTrue(false);
+ }
+ }
+
+ protected abstract CPPASTVisitor createModificator(ASTModificationStore modStore);
+
+ public ChangeGeneratorTest(String name) {
+ super(name);
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ System.gc();
+ fileManager.closeAllFiles();
+ super.tearDown();
+ }
+
+}
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/ChangeGeneratorTestSuite.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/ChangeGeneratorTestSuite.java
new file mode 100644
index 00000000000..c8c10fa2f61
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/ChangeGeneratorTestSuite.java
@@ -0,0 +1,39 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.append.AppendTestSuite;
+import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.insertbefore.InsertBeforeTestSuite;
+import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.remove.RemoveTestSuite;
+import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.replace.ReplaceTestSuite;
+
+/**
+ * @author Thomas Corbat
+ *
+ */
+public class ChangeGeneratorTestSuite{
+
+ @SuppressWarnings("nls")
+ public static Test suite() throws Exception {
+ TestSuite suite = new TestSuite("ChangeGeneratorTests");
+
+ suite.addTest(ReplaceTestSuite.suite());
+ suite.addTest(RemoveTestSuite.suite());
+ suite.addTest(InsertBeforeTestSuite.suite());
+ suite.addTest(AppendTestSuite.suite());
+
+ return suite;
+ }
+}
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/append/AppendTestSuite.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/append/AppendTestSuite.java
new file mode 100644
index 00000000000..cf83f3b256d
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/append/AppendTestSuite.java
@@ -0,0 +1,39 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.append;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * @author Thomas Corbat
+ *
+ */
+public class AppendTestSuite{
+
+ @SuppressWarnings("nls")
+ public static Test suite() throws Exception {
+ TestSuite suite = new TestSuite("Changegenerator Append Child Tests");
+
+ suite.addTest(ParameterTest.suite());
+ suite.addTest(ParameterToListTest.suite());
+ suite.addTest(PointerToParameterTest.suite());
+ suite.addTest(PointerToPointerParameterTest.suite());
+ suite.addTest(ExceptionTest.suite());
+ suite.addTest(CtorChainInitializerTest.suite());
+ suite.addTest(ArrayModifierTest.suite());
+ suite.addTest(ExpressionTest.suite());
+ suite.addTest(ArraySizeExpressionTest.suite());
+
+ return suite;
+ }
+}
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/append/ArrayModifierTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/append/ArrayModifierTest.java
new file mode 100644
index 00000000000..9f43f94175b
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/append/ArrayModifierTest.java
@@ -0,0 +1,71 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.append;
+
+import junit.framework.Test;
+
+import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator;
+import org.eclipse.cdt.core.dom.ast.IASTArrayModifier;
+import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
+import org.eclipse.cdt.core.dom.ast.IASTExpression;
+import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
+import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTArrayModifier;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTLiteralExpression;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind;
+
+public class ArrayModifierTest extends ChangeGeneratorTest {
+
+ public ArrayModifierTest(){
+ super("Replace Array Modifier"); //$NON-NLS-1$
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+
+
+ source = "int *pi[5];"; //$NON-NLS-1$
+ expectedSource = "int *pi[5][3];"; //$NON-NLS-1$
+ super.setUp();
+ }
+
+ @Override
+ protected CPPASTVisitor createModificator(
+ final ASTModificationStore modStore) {
+ return new CPPASTVisitor() {
+ {
+ shouldVisitDeclarators = true;
+ }
+
+ @Override
+ public int visit(IASTDeclarator declarator) {
+ if (declarator instanceof IASTArrayDeclarator) {
+ IASTArrayDeclarator arrayDeclarator = (IASTArrayDeclarator)declarator;
+ arrayDeclarator.getArrayModifiers();
+ IASTArrayModifier newModifier = new CPPASTArrayModifier();
+ IASTExpression expr = new CPPASTLiteralExpression(0, "3"); //$NON-NLS-1$
+ newModifier.setConstantExpression(expr);
+ ASTModification modification = new ASTModification(ModificationKind.APPEND_CHILD, declarator, newModifier, null);
+ modStore.storeModification(null, modification);
+ }
+ return PROCESS_CONTINUE;
+ }
+ };
+ }
+
+ public static Test suite() {
+ return new ArrayModifierTest();
+
+ }
+}
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/append/ArraySizeExpressionTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/append/ArraySizeExpressionTest.java
new file mode 100644
index 00000000000..36890e2a407
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/append/ArraySizeExpressionTest.java
@@ -0,0 +1,64 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.append;
+
+import junit.framework.Test;
+
+import org.eclipse.cdt.core.dom.ast.IASTExpression;
+import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNewExpression;
+import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTLiteralExpression;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
+
+public class ArraySizeExpressionTest extends ChangeGeneratorTest {
+
+ public ArraySizeExpressionTest(){
+ super("Append Array Size Expression"); //$NON-NLS-1$
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ source = "int *values = new int[6];"; //$NON-NLS-1$
+ expectedSource = "int *values = new int[6][5];"; //$NON-NLS-1$
+ super.setUp();
+ }
+
+
+ @Override
+ protected CPPASTVisitor createModificator(
+ final ASTModificationStore modStore) {
+ return new CPPASTVisitor() {
+ {
+ shouldVisitExpressions = true;
+ }
+
+ @Override
+ public int visit(IASTExpression expression) {
+ if (expression instanceof ICPPASTNewExpression) {
+ ICPPASTNewExpression newExpression = (ICPPASTNewExpression) expression;
+ newExpression.getNewTypeIdArrayExpressions();
+ ASTModification modification = new ASTModification(ASTModification.ModificationKind.APPEND_CHILD, newExpression, new CPPASTLiteralExpression(0, "5"), null); //$NON-NLS-1$
+ modStore.storeModification(null, modification);
+ }
+ return PROCESS_CONTINUE;
+ }
+ };
+ }
+
+ public static Test suite() {
+ return new ArraySizeExpressionTest();
+
+ }
+
+}
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/append/CtorChainInitializerTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/append/CtorChainInitializerTest.java
new file mode 100644
index 00000000000..0ffdf74e0f5
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/append/CtorChainInitializerTest.java
@@ -0,0 +1,72 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.append;
+
+import junit.framework.Test;
+
+import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
+import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer;
+import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTConstructorChainInitializer;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDeclarator;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTIdExpression;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind;
+
+public class CtorChainInitializerTest extends ChangeGeneratorTest {
+
+
+ public CtorChainInitializerTest(){
+ super("Append Ctor Initializer"); //$NON-NLS-1$
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+
+ source = "TestClass::TestClass(int a, int b):beta(b){\n}\n\n"; //$NON-NLS-1$
+ expectedSource = "TestClass::TestClass(int a, int b):beta(b), alpha(a){\n}\n\n"; //$NON-NLS-1$
+ super.setUp();
+ }
+
+ @Override
+ protected CPPASTVisitor createModificator(
+ final ASTModificationStore modStore) {
+ return new CPPASTVisitor() {
+ {
+ shouldVisitDeclarators = true;
+ }
+
+ @Override
+ public int visit(IASTDeclarator declarator) {
+ if (declarator instanceof CPPASTFunctionDeclarator) {
+ CPPASTFunctionDeclarator functionDeclarator = (CPPASTFunctionDeclarator)declarator;
+ CPPASTIdExpression initExpr = new CPPASTIdExpression(new CPPASTName("a".toCharArray())); //$NON-NLS-1$
+ CPPASTName initName = new CPPASTName("alpha".toCharArray()); //$NON-NLS-1$
+ ICPPASTConstructorChainInitializer newInitializer = new CPPASTConstructorChainInitializer(initName, initExpr);
+ ASTModification modification = new ASTModification(ModificationKind.APPEND_CHILD, functionDeclarator, newInitializer, null);
+ modStore.storeModification(null, modification);
+
+ }
+ return PROCESS_CONTINUE;
+ }
+ };
+ }
+
+ public static Test suite() {
+ return new CtorChainInitializerTest();
+
+ }
+
+}
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/append/ExceptionTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/append/ExceptionTest.java
new file mode 100644
index 00000000000..f82e7e024c7
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/append/ExceptionTest.java
@@ -0,0 +1,74 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.append;
+
+import junit.framework.Test;
+
+import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
+import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier;
+import org.eclipse.cdt.core.dom.ast.IASTTypeId;
+import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
+import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTDeclarator;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDeclarator;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTSimpleDeclSpecifier;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTTypeId;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind;
+
+public class ExceptionTest extends ChangeGeneratorTest {
+
+ public ExceptionTest(){
+ super("Append Exception Declaration"); //$NON-NLS-1$
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ source = "void foo(int parameter){\n}\n\n"; //$NON-NLS-1$
+ expectedSource = "void foo(int parameter) throw (int){\n}\n\n"; //$NON-NLS-1$
+ super.setUp();
+ }
+
+ @Override
+ protected CPPASTVisitor createModificator(
+ final ASTModificationStore modStore) {
+ return new CPPASTVisitor() {
+ {
+ shouldVisitDeclarators = true;
+ }
+
+ @Override
+ public int visit(IASTDeclarator declarator) {
+ if (declarator instanceof CPPASTFunctionDeclarator) {
+ IASTTypeId exception = new CPPASTTypeId();
+ CPPASTDeclarator exceptionDeclarator = new CPPASTDeclarator();
+ exceptionDeclarator.setName(new CPPASTName());
+ CPPASTSimpleDeclSpecifier exDeclSpec = new CPPASTSimpleDeclSpecifier();
+ exDeclSpec.setType(IASTSimpleDeclSpecifier.t_int);
+ exception.setDeclSpecifier(exDeclSpec);
+ exception.setAbstractDeclarator(exceptionDeclarator);
+ ASTModification modification = new ASTModification(ModificationKind.APPEND_CHILD, declarator, exception, null);
+ modStore.storeModification(null, modification);
+
+ }
+ return PROCESS_CONTINUE;
+ }
+ };
+ }
+
+ public static Test suite() {
+ return new ExceptionTest();
+
+ }
+}
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/append/ExpressionTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/append/ExpressionTest.java
new file mode 100644
index 00000000000..75f7c3cd92e
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/append/ExpressionTest.java
@@ -0,0 +1,69 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.append;
+
+import junit.framework.Test;
+
+import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression;
+import org.eclipse.cdt.core.dom.ast.IASTExpression;
+import org.eclipse.cdt.core.dom.ast.IASTExpressionList;
+import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
+import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTBinaryExpression;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTIdExpression;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTLiteralExpression;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
+
+
+public class ExpressionTest extends ChangeGeneratorTest {
+
+
+ public ExpressionTest(){
+ super("Append Expression"); //$NON-NLS-1$
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ source = "void main(){int s = 0, c = 0, h = 0;\ns = 3, h = 5;}"; //$NON-NLS-1$
+ expectedSource = "void main(){int s = 0, c = 0, h = 0;\ns = 3, h = 5, c = 9;}"; //$NON-NLS-1$
+ super.setUp();
+ }
+ @Override
+ protected CPPASTVisitor createModificator(
+ final ASTModificationStore modStore) {
+ return new CPPASTVisitor() {
+ {
+ shouldVisitExpressions = true;
+ }
+
+ @Override
+ public int visit(IASTExpression expression) {
+ if (expression instanceof IASTExpressionList) {
+ IASTExpressionList expressionList = (IASTExpressionList) expression;
+ expressionList.getExpressions();
+ CPPASTBinaryExpression binEx = new CPPASTBinaryExpression(IASTBinaryExpression.op_assign, new CPPASTIdExpression(new CPPASTName("c".toCharArray())), new CPPASTLiteralExpression(0, "9")); //$NON-NLS-1$ //$NON-NLS-2$
+ ASTModification modification = new ASTModification(ASTModification.ModificationKind.APPEND_CHILD, expressionList, binEx, null);
+ modStore.storeModification(null, modification);
+ }
+
+ return PROCESS_CONTINUE;
+ }
+
+ };
+ }
+ public static Test suite() {
+ return new ExpressionTest();
+
+ }
+}
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/append/ParameterTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/append/ParameterTest.java
new file mode 100644
index 00000000000..9b8265038dd
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/append/ParameterTest.java
@@ -0,0 +1,79 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.append;
+
+import junit.framework.Test;
+
+import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
+import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier;
+import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
+import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTDeclarator;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDeclarator;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTParameterDeclaration;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTSimpleDeclSpecifier;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind;
+
+
+
+
+
+public class ParameterTest extends ChangeGeneratorTest {
+
+ public ParameterTest(){
+ super("Append Parameter to List"); //$NON-NLS-1$
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ source = "void foo(int existing){\n}\n\n"; //$NON-NLS-1$
+ expectedSource = "void foo(int existing, int newParameter){\n}\n\n"; //$NON-NLS-1$
+ super.setUp();
+ }
+
+ @Override
+ protected CPPASTVisitor createModificator(
+ final ASTModificationStore modStore) {
+ return new CPPASTVisitor() {
+ {
+ shouldVisitDeclarators = true;
+ }
+
+ @Override
+ public int visit(IASTDeclarator declarator) {
+ if (declarator instanceof CPPASTFunctionDeclarator) {
+ CPPASTFunctionDeclarator functionDeclarator = (CPPASTFunctionDeclarator)declarator;
+
+ CPPASTParameterDeclaration insertedParameter = new CPPASTParameterDeclaration();
+ CPPASTDeclarator parameterDeclarator = new CPPASTDeclarator();
+ CPPASTName parameterName = new CPPASTName("newParameter".toCharArray()); //$NON-NLS-1$
+ parameterDeclarator.setName(parameterName);
+ insertedParameter.setDeclarator(parameterDeclarator);
+ CPPASTSimpleDeclSpecifier parameterDeclSpec = new CPPASTSimpleDeclSpecifier();
+ parameterDeclSpec.setType(IASTSimpleDeclSpecifier.t_int);
+ insertedParameter.setDeclSpecifier(parameterDeclSpec);
+ ASTModification modification = new ASTModification(ModificationKind.APPEND_CHILD, functionDeclarator, insertedParameter, null);
+ modStore.storeModification(null, modification);
+ }
+ return PROCESS_CONTINUE;
+ }
+ };
+ }
+
+ public static Test suite() {
+ return new ParameterTest();
+
+ }
+}
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/append/ParameterToListTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/append/ParameterToListTest.java
new file mode 100644
index 00000000000..ddccfe2edf9
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/append/ParameterToListTest.java
@@ -0,0 +1,79 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.append;
+
+import junit.framework.Test;
+
+import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
+import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier;
+import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
+import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTDeclarator;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDeclarator;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTParameterDeclaration;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTSimpleDeclSpecifier;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind;
+
+
+
+
+
+public class ParameterToListTest extends ChangeGeneratorTest {
+
+ public ParameterToListTest(){
+ super("Append Parameter to Empty List"); //$NON-NLS-1$
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ source = "void foo(){\n}\n\n"; //$NON-NLS-1$
+ expectedSource = "void foo(int newParameter){\n}\n\n"; //$NON-NLS-1$
+ super.setUp();
+ }
+
+ @Override
+ protected CPPASTVisitor createModificator(
+ final ASTModificationStore modStore) {
+ return new CPPASTVisitor() {
+ {
+ shouldVisitDeclarators = true;
+ }
+
+ @Override
+ public int visit(IASTDeclarator declarator) {
+ if (declarator instanceof CPPASTFunctionDeclarator) {
+ CPPASTFunctionDeclarator functionDeclarator = (CPPASTFunctionDeclarator)declarator;
+
+ CPPASTParameterDeclaration insertedParameter = new CPPASTParameterDeclaration();
+ CPPASTDeclarator parameterDeclarator = new CPPASTDeclarator();
+ CPPASTName parameterName = new CPPASTName("newParameter".toCharArray()); //$NON-NLS-1$
+ parameterDeclarator.setName(parameterName);
+ insertedParameter.setDeclarator(parameterDeclarator);
+ CPPASTSimpleDeclSpecifier parameterDeclSpec = new CPPASTSimpleDeclSpecifier();
+ parameterDeclSpec.setType(IASTSimpleDeclSpecifier.t_int);
+ insertedParameter.setDeclSpecifier(parameterDeclSpec);
+ ASTModification modification = new ASTModification(ModificationKind.APPEND_CHILD, functionDeclarator, insertedParameter, null);
+ modStore.storeModification(null, modification);
+ }
+ return PROCESS_CONTINUE;
+ }
+ };
+ }
+
+ public static Test suite() {
+ return new ParameterToListTest();
+
+ }
+}
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/append/PointerToParameterTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/append/PointerToParameterTest.java
new file mode 100644
index 00000000000..3f17405547b
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/append/PointerToParameterTest.java
@@ -0,0 +1,72 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.append;
+
+import junit.framework.Test;
+
+import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
+import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
+import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
+import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDeclarator;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTPointer;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind;
+
+public class PointerToParameterTest extends ChangeGeneratorTest {
+
+
+ public PointerToParameterTest(){
+ super("Append Pointer to Parameter"); //$NON-NLS-1$
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ source = "void foo(int parameter){\n}\n\n"; //$NON-NLS-1$
+ expectedSource = "void foo(int *parameter){\n}\n\n"; //$NON-NLS-1$
+ super.setUp();
+ }
+
+
+ @Override
+ protected CPPASTVisitor createModificator(
+ final ASTModificationStore modStore) {
+ return new CPPASTVisitor() {
+ {
+ shouldVisitDeclarators = true;
+ }
+
+ @Override
+ public int visit(IASTDeclarator declarator) {
+ if (declarator instanceof CPPASTFunctionDeclarator) {
+ CPPASTFunctionDeclarator functionDeclarator = (CPPASTFunctionDeclarator)declarator;
+ IASTParameterDeclaration[] parameters = functionDeclarator.getParameters();
+ for(IASTParameterDeclaration curParam : parameters){
+ if(String.valueOf(curParam.getDeclarator().getName().toCharArray()).equals("parameter")){ //$NON-NLS-1$
+ CPPASTPointer addedPointer = new CPPASTPointer();
+ ASTModification modification = new ASTModification(ModificationKind.APPEND_CHILD, curParam.getDeclarator(), addedPointer, null);
+ modStore.storeModification(null, modification);
+ }
+ }
+ }
+ return PROCESS_CONTINUE;
+ }
+
+ };
+ }
+
+ public static Test suite() {
+ return new PointerToParameterTest();
+
+ }
+}
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/append/PointerToPointerParameterTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/append/PointerToPointerParameterTest.java
new file mode 100644
index 00000000000..5312a2df6e4
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/append/PointerToPointerParameterTest.java
@@ -0,0 +1,69 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.append;
+
+import junit.framework.Test;
+
+import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
+import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
+import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
+import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDeclarator;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTPointer;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind;
+
+public class PointerToPointerParameterTest extends ChangeGeneratorTest {
+
+ public PointerToPointerParameterTest(){
+ super("Append Pointer to Pointer Parameter"); //$NON-NLS-1$
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ source = "void foo(int *parameter){\n}\n\n"; //$NON-NLS-1$
+ expectedSource = "void foo(int **parameter){\n}\n\n"; //$NON-NLS-1$
+ super.setUp();
+ }
+
+ @Override
+ protected CPPASTVisitor createModificator(
+ final ASTModificationStore modStore) {
+ return new CPPASTVisitor() {
+ {
+ shouldVisitDeclarators = true;
+ }
+
+ @Override
+ public int visit(IASTDeclarator declarator) {
+ if (declarator instanceof CPPASTFunctionDeclarator) {
+ CPPASTFunctionDeclarator functionDeclarator = (CPPASTFunctionDeclarator)declarator;
+ IASTParameterDeclaration[] parameters = functionDeclarator.getParameters();
+ for(IASTParameterDeclaration curParam : parameters){
+ if(String.valueOf(curParam.getDeclarator().getName().toCharArray()).equals("parameter")){ //$NON-NLS-1$
+ CPPASTPointer addedPointer = new CPPASTPointer();
+ ASTModification modification = new ASTModification(ModificationKind.APPEND_CHILD, curParam.getDeclarator(), addedPointer, null);
+ modStore.storeModification(null, modification);
+ }
+ }
+ }
+ return PROCESS_CONTINUE;
+ }
+ };
+ }
+
+ public static Test suite() {
+ return new PointerToPointerParameterTest();
+
+ }
+}
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/insertbefore/ArrayModifierTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/insertbefore/ArrayModifierTest.java
new file mode 100644
index 00000000000..4a16a9d08ac
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/insertbefore/ArrayModifierTest.java
@@ -0,0 +1,69 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.insertbefore;
+
+import junit.framework.Test;
+
+import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator;
+import org.eclipse.cdt.core.dom.ast.IASTArrayModifier;
+import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
+import org.eclipse.cdt.core.dom.ast.IASTExpression;
+import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
+import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTArrayModifier;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTLiteralExpression;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind;
+
+public class ArrayModifierTest extends ChangeGeneratorTest {
+
+ public ArrayModifierTest(){
+ super("Replace Array Modifier"); //$NON-NLS-1$
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ source = "int *pi[3];"; //$NON-NLS-1$
+ expectedSource = "int *pi[5][3];"; //$NON-NLS-1$
+ super.setUp();
+ }
+
+ @Override
+ protected CPPASTVisitor createModificator(
+ final ASTModificationStore modStore) {
+ return new CPPASTVisitor() {
+ {
+ shouldVisitDeclarators = true;
+ }
+
+ @Override
+ public int visit(IASTDeclarator declarator) {
+ if (declarator instanceof IASTArrayDeclarator) {
+ IASTArrayDeclarator arrayDeclarator = (IASTArrayDeclarator)declarator;
+
+ IASTArrayModifier[] modifiers = arrayDeclarator.getArrayModifiers();
+ IASTArrayModifier newModifier = new CPPASTArrayModifier();
+ IASTExpression expr = new CPPASTLiteralExpression(0, "5"); //$NON-NLS-1$
+ newModifier.setConstantExpression(expr);
+ ASTModification modification = new ASTModification(ModificationKind.INSERT_BEFORE, modifiers[0], newModifier, null);
+ modStore.storeModification(null, modification);
+ }
+ return PROCESS_CONTINUE;
+ }
+ };
+ }
+
+ public static Test suite() {
+ return new ArrayModifierTest();
+ }
+}
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/insertbefore/ArraySizeExpressionTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/insertbefore/ArraySizeExpressionTest.java
new file mode 100644
index 00000000000..caae9c52925
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/insertbefore/ArraySizeExpressionTest.java
@@ -0,0 +1,65 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.insertbefore;
+
+import junit.framework.Test;
+
+import org.eclipse.cdt.core.dom.ast.IASTExpression;
+import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNewExpression;
+import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTLiteralExpression;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
+
+
+
+public class ArraySizeExpressionTest extends ChangeGeneratorTest {
+
+ public ArraySizeExpressionTest(){
+ super("Insert Array Size Expression"); //$NON-NLS-1$
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ source = "int *values = new int[5];"; //$NON-NLS-1$
+ expectedSource = "int *values = new int[6][5];"; //$NON-NLS-1$
+ super.setUp();
+ }
+
+
+ @Override
+ protected CPPASTVisitor createModificator(
+ final ASTModificationStore modStore) {
+ return new CPPASTVisitor() {
+ {
+ shouldVisitExpressions = true;
+ }
+
+ @Override
+ public int visit(IASTExpression expression) {
+ if (expression instanceof ICPPASTNewExpression) {
+ ICPPASTNewExpression newExpression = (ICPPASTNewExpression) expression;
+ IASTExpression[] arraySizeExpressions = newExpression.getNewTypeIdArrayExpressions();
+ ASTModification modification = new ASTModification(ASTModification.ModificationKind.INSERT_BEFORE, arraySizeExpressions[0], new CPPASTLiteralExpression(0, "6"), null); //$NON-NLS-1$
+ modStore.storeModification(null, modification);
+ }
+ return PROCESS_CONTINUE;
+ }
+ };
+ }
+
+ public static Test suite() {
+ return new ArraySizeExpressionTest();
+
+ }
+}
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/insertbefore/CtorChainInitializerTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/insertbefore/CtorChainInitializerTest.java
new file mode 100644
index 00000000000..cbb71d1e050
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/insertbefore/CtorChainInitializerTest.java
@@ -0,0 +1,70 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.insertbefore;
+
+import junit.framework.Test;
+
+import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
+import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer;
+import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTConstructorChainInitializer;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDeclarator;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTIdExpression;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind;
+
+public class CtorChainInitializerTest extends ChangeGeneratorTest {
+
+ public CtorChainInitializerTest(){
+ super("Insert Before Ctor Initializer"); //$NON-NLS-1$
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ source = "TestClass::TestClass(int a, int b):beta(b){\n}\n\n"; //$NON-NLS-1$
+ expectedSource = "TestClass::TestClass(int a, int b):alpha(a), beta(b){\n}\n\n"; //$NON-NLS-1$
+ super.setUp();
+ }
+
+ @Override
+ protected CPPASTVisitor createModificator(
+ final ASTModificationStore modStore) {
+ return new CPPASTVisitor() {
+ {
+ shouldVisitDeclarators = true;
+ }
+
+ @Override
+ public int visit(IASTDeclarator declarator) {
+ if (declarator instanceof CPPASTFunctionDeclarator) {
+ CPPASTFunctionDeclarator functionDeclarator = (CPPASTFunctionDeclarator)declarator;
+ ICPPASTConstructorChainInitializer ctorInitializer = functionDeclarator.getConstructorChain()[0];
+ CPPASTIdExpression initExpr = new CPPASTIdExpression(new CPPASTName("a".toCharArray())); //$NON-NLS-1$
+ CPPASTName initName = new CPPASTName("alpha".toCharArray()); //$NON-NLS-1$
+ ICPPASTConstructorChainInitializer newInitializer = new CPPASTConstructorChainInitializer(initName, initExpr);
+ ASTModification modification = new ASTModification(ModificationKind.INSERT_BEFORE, ctorInitializer, newInitializer, null);
+ modStore.storeModification(null, modification);
+
+ }
+ return PROCESS_CONTINUE;
+ }
+ };
+ }
+
+ public static Test suite() {
+ return new CtorChainInitializerTest();
+
+ }
+}
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/insertbefore/ExceptionTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/insertbefore/ExceptionTest.java
new file mode 100644
index 00000000000..9192543bbfe
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/insertbefore/ExceptionTest.java
@@ -0,0 +1,77 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.insertbefore;
+
+import junit.framework.Test;
+
+import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
+import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier;
+import org.eclipse.cdt.core.dom.ast.IASTTypeId;
+import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
+import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTDeclarator;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDeclarator;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTSimpleDeclSpecifier;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTTypeId;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind;
+
+public class ExceptionTest extends ChangeGeneratorTest {
+
+ public ExceptionTest(){
+ super("Insert Before Exception Declaration"); //$NON-NLS-1$
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ source = "void foo(int parameter) throw (float){\n}\n\n"; //$NON-NLS-1$
+ expectedSource = "void foo(int parameter) throw (int, float){\n}\n\n"; //$NON-NLS-1$
+ super.setUp();
+ }
+
+ @Override
+ protected CPPASTVisitor createModificator(
+ final ASTModificationStore modStore) {
+ return new CPPASTVisitor() {
+ {
+ shouldVisitDeclarators = true;
+ }
+
+ @Override
+ public int visit(IASTDeclarator declarator) {
+ if (declarator instanceof CPPASTFunctionDeclarator) {
+ CPPASTFunctionDeclarator functionDeclarator = (CPPASTFunctionDeclarator)declarator;
+ IASTTypeId existingException = functionDeclarator.getExceptionSpecification()[0];
+
+ IASTTypeId exception = new CPPASTTypeId();
+ CPPASTDeclarator exceptionDeclarator = new CPPASTDeclarator();
+ exceptionDeclarator.setName(new CPPASTName());
+ CPPASTSimpleDeclSpecifier exDeclSpec = new CPPASTSimpleDeclSpecifier();
+ exDeclSpec.setType(IASTSimpleDeclSpecifier.t_int);
+ exception.setDeclSpecifier(exDeclSpec);
+ exception.setAbstractDeclarator(exceptionDeclarator);
+ ASTModification modification = new ASTModification(ModificationKind.INSERT_BEFORE, existingException, exception, null);
+ modStore.storeModification(null, modification);
+
+ }
+ return PROCESS_CONTINUE;
+ }
+ };
+ }
+
+ public static Test suite() {
+ return new ExceptionTest();
+
+ }
+}
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/insertbefore/ExpressionTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/insertbefore/ExpressionTest.java
new file mode 100644
index 00000000000..e5e811ff4e1
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/insertbefore/ExpressionTest.java
@@ -0,0 +1,71 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.insertbefore;
+
+import junit.framework.Test;
+
+import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression;
+import org.eclipse.cdt.core.dom.ast.IASTExpression;
+import org.eclipse.cdt.core.dom.ast.IASTExpressionList;
+import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
+import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTBinaryExpression;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTIdExpression;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTLiteralExpression;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
+
+
+
+
+
+public class ExpressionTest extends ChangeGeneratorTest {
+
+ public ExpressionTest(){
+ super("Insert Expression"); //$NON-NLS-1$
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ source = "void main(){int s = 0, c = 0, h = 0;\ns = 3, h = 5;}"; //$NON-NLS-1$
+ expectedSource = "void main(){int s = 0, c = 0, h = 0;\ns = 3, c = 9, h = 5;}"; //$NON-NLS-1$
+ super.setUp();
+ }
+
+ @Override
+ protected CPPASTVisitor createModificator(
+ final ASTModificationStore modStore) {
+ return new CPPASTVisitor() {
+ {
+ shouldVisitExpressions = true;
+ }
+
+ @Override
+ public int visit(IASTExpression expression) {
+ if (expression instanceof IASTExpressionList) {
+ IASTExpressionList expressionList = (IASTExpressionList) expression;
+ IASTExpression[] expressions = expressionList.getExpressions();
+ CPPASTBinaryExpression binEx = new CPPASTBinaryExpression(IASTBinaryExpression.op_assign, new CPPASTIdExpression(new CPPASTName("c".toCharArray())), new CPPASTLiteralExpression(0, "9")); //$NON-NLS-1$ //$NON-NLS-2$
+ ASTModification modification = new ASTModification(ASTModification.ModificationKind.INSERT_BEFORE, expressions[1], binEx, null);
+ modStore.storeModification(null, modification);
+ }
+ return PROCESS_CONTINUE;
+ }
+ };
+ }
+
+ public static Test suite() {
+ return new ExpressionTest();
+
+ }
+}
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/insertbefore/FirstParameterTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/insertbefore/FirstParameterTest.java
new file mode 100644
index 00000000000..8509f695a09
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/insertbefore/FirstParameterTest.java
@@ -0,0 +1,85 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.insertbefore;
+
+import junit.framework.Test;
+
+import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
+import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
+import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier;
+import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
+import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTDeclarator;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDeclarator;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTParameterDeclaration;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTSimpleDeclSpecifier;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind;
+
+
+
+
+
+public class FirstParameterTest extends ChangeGeneratorTest {
+
+ public FirstParameterTest(){
+ super("Insert Before First Parameter"); //$NON-NLS-1$
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ source = "void foo(int a){\n}\n\n"; //$NON-NLS-1$
+ expectedSource = "void foo(int newParameter, int a){\n}\n\n"; //$NON-NLS-1$
+ super.setUp();
+ }
+
+
+ @Override
+ protected CPPASTVisitor createModificator(
+ final ASTModificationStore modStore) {
+ return new CPPASTVisitor() {
+ {
+ shouldVisitDeclarators = true;
+ }
+
+ @Override
+ public int visit(IASTDeclarator declarator) {
+ if (declarator instanceof CPPASTFunctionDeclarator) {
+ CPPASTFunctionDeclarator functionDeclarator = (CPPASTFunctionDeclarator)declarator;
+ IASTParameterDeclaration[] parameters = functionDeclarator.getParameters();
+ for(IASTParameterDeclaration curParam : parameters){
+ if(String.valueOf(curParam.getDeclarator().getName().toCharArray()).equals("a")){ //$NON-NLS-1$
+ CPPASTParameterDeclaration insertedParameter = new CPPASTParameterDeclaration();
+ CPPASTDeclarator parameterDeclarator = new CPPASTDeclarator();
+ CPPASTName parameterName = new CPPASTName("newParameter".toCharArray()); //$NON-NLS-1$
+ parameterDeclarator.setName(parameterName);
+ insertedParameter.setDeclarator(parameterDeclarator);
+ CPPASTSimpleDeclSpecifier parameterDeclSpec = new CPPASTSimpleDeclSpecifier();
+ parameterDeclSpec.setType(IASTSimpleDeclSpecifier.t_int);
+ insertedParameter.setDeclSpecifier(parameterDeclSpec);
+ ASTModification modification = new ASTModification(ModificationKind.INSERT_BEFORE, curParam, insertedParameter, null);
+ modStore.storeModification(null, modification);
+ }
+ }
+ }
+ return PROCESS_CONTINUE;
+ }
+ };
+ }
+
+ public static Test suite() {
+ return new FirstParameterTest();
+
+ }
+}
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/insertbefore/InsertBeforeTestSuite.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/insertbefore/InsertBeforeTestSuite.java
new file mode 100644
index 00000000000..f4520988731
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/insertbefore/InsertBeforeTestSuite.java
@@ -0,0 +1,37 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.insertbefore;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * @author Thomas Corbat
+ *
+ */
+public class InsertBeforeTestSuite{
+
+ @SuppressWarnings("nls")
+ public static Test suite() throws Exception {
+ TestSuite suite = new TestSuite("Changegenerator InsertBefore Tests");
+
+ suite.addTest(FirstParameterTest.suite());
+ suite.addTest(PointerParameterTest.suite());
+ suite.addTest(ExceptionTest.suite());
+ suite.addTest(CtorChainInitializerTest.suite());
+ suite.addTest(ArrayModifierTest.suite());
+ suite.addTest(ExpressionTest.suite());
+ suite.addTest(ArraySizeExpressionTest.suite());
+
+ return suite;
+ }
+}
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/insertbefore/PointerParameterTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/insertbefore/PointerParameterTest.java
new file mode 100644
index 00000000000..c496ed40c63
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/insertbefore/PointerParameterTest.java
@@ -0,0 +1,71 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.insertbefore;
+
+import junit.framework.Test;
+
+import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
+import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
+import org.eclipse.cdt.core.dom.ast.IASTPointerOperator;
+import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
+import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDeclarator;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTPointer;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind;
+
+public class PointerParameterTest extends ChangeGeneratorTest {
+
+ public PointerParameterTest(){
+ super("Insert Pointer for Parameter"); //$NON-NLS-1$
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ source = "void foo(int *parameter){\n}\n\n"; //$NON-NLS-1$
+ expectedSource = "void foo(int **parameter){\n}\n\n"; //$NON-NLS-1$
+ super.setUp();
+ }
+
+ @Override
+ protected CPPASTVisitor createModificator(
+ final ASTModificationStore modStore) {
+ return new CPPASTVisitor() {
+ {
+ shouldVisitDeclarators = true;
+ }
+
+ @Override
+ public int visit(IASTDeclarator declarator) {
+ if (declarator instanceof CPPASTFunctionDeclarator) {
+ CPPASTFunctionDeclarator functionDeclarator = (CPPASTFunctionDeclarator)declarator;
+ IASTParameterDeclaration[] parameters = functionDeclarator.getParameters();
+ for(IASTParameterDeclaration curParam : parameters){
+ if(String.valueOf(curParam.getDeclarator().getName().toCharArray()).equals("parameter")){ //$NON-NLS-1$
+ IASTPointerOperator pointer = curParam.getDeclarator().getPointerOperators()[0];
+ CPPASTPointer insertedPointer = new CPPASTPointer();
+ ASTModification modification = new ASTModification(ModificationKind.INSERT_BEFORE, pointer, insertedPointer, null);
+ modStore.storeModification(null, modification);
+ }
+ }
+ }
+ return PROCESS_CONTINUE;
+ }
+ };
+ }
+
+ public static Test suite() {
+ return new PointerParameterTest();
+
+ }
+}
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/remove/ArrayModifierTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/remove/ArrayModifierTest.java
new file mode 100644
index 00000000000..05b0d13961f
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/remove/ArrayModifierTest.java
@@ -0,0 +1,63 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.remove;
+
+import junit.framework.Test;
+
+import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator;
+import org.eclipse.cdt.core.dom.ast.IASTArrayModifier;
+import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
+import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
+import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind;
+
+public class ArrayModifierTest extends ChangeGeneratorTest {
+
+ public ArrayModifierTest(){
+ super("Remove Array Modifier"); //$NON-NLS-1$
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ source = "int *pi[3];"; //$NON-NLS-1$
+ expectedSource = "int *pi;"; //$NON-NLS-1$
+ super.setUp();
+ }
+
+ public static Test suite() {
+ return new ArrayModifierTest();
+ }
+
+ @Override
+ protected CPPASTVisitor createModificator(
+ final ASTModificationStore modStore) {
+ return new CPPASTVisitor() {
+ {
+ shouldVisitDeclarators = true;
+ }
+
+ @Override
+ public int visit(IASTDeclarator declarator) {
+ if (declarator instanceof IASTArrayDeclarator) {
+ IASTArrayDeclarator arrayDeclarator = (IASTArrayDeclarator)declarator;
+
+ IASTArrayModifier[] modifiers = arrayDeclarator.getArrayModifiers();
+ ASTModification modification = new ASTModification(ModificationKind.REPLACE, modifiers[0], null, null);
+ modStore.storeModification(null, modification);
+ }
+ return PROCESS_CONTINUE;
+ }
+ };
+ }
+}
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/remove/ArraySizeExpressionTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/remove/ArraySizeExpressionTest.java
new file mode 100644
index 00000000000..a7813073d61
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/remove/ArraySizeExpressionTest.java
@@ -0,0 +1,62 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.remove;
+
+import junit.framework.Test;
+
+import org.eclipse.cdt.core.dom.ast.IASTExpression;
+import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNewExpression;
+import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
+
+
+
+public class ArraySizeExpressionTest extends ChangeGeneratorTest {
+
+ public ArraySizeExpressionTest(){
+ super("Remove Array Size Expression"); //$NON-NLS-1$
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ source = "int *values = new int[5][6];"; //$NON-NLS-1$
+ expectedSource = "int *values = new int[5];"; //$NON-NLS-1$
+ super.setUp();
+ }
+
+ @Override
+ protected CPPASTVisitor createModificator(
+ final ASTModificationStore modStore) {
+ return new CPPASTVisitor() {
+ {
+ shouldVisitExpressions = true;
+ }
+
+ @Override
+ public int visit(IASTExpression expression) {
+ if (expression instanceof ICPPASTNewExpression) {
+ ICPPASTNewExpression newExpression = (ICPPASTNewExpression) expression;
+ IASTExpression[] arraySizeExpressions = newExpression.getNewTypeIdArrayExpressions();
+ ASTModification modification = new ASTModification(ASTModification.ModificationKind.REPLACE, arraySizeExpressions[1], null, null);
+ modStore.storeModification(null, modification);
+ }
+ return PROCESS_CONTINUE;
+ }
+ };
+ }
+
+ public static Test suite() {
+ return new ArraySizeExpressionTest();
+ }
+}
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/remove/CtorChainInitializerTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/remove/CtorChainInitializerTest.java
new file mode 100644
index 00000000000..1b6846d02f5
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/remove/CtorChainInitializerTest.java
@@ -0,0 +1,64 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.remove;
+
+import junit.framework.Test;
+
+import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
+import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer;
+import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDeclarator;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind;
+
+public class CtorChainInitializerTest extends ChangeGeneratorTest {
+
+ public CtorChainInitializerTest(){
+ super("Remove Ctor Initializer"); //$NON-NLS-1$
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ source = "TestClass::TestClass(int a):alpha(a){\n}\n\n"; //$NON-NLS-1$
+ expectedSource = "TestClass::TestClass(int a){\n}\n\n"; //$NON-NLS-1$
+ super.setUp();
+ }
+
+ public static Test suite() {
+ return new CtorChainInitializerTest();
+ }
+
+ @Override
+ protected CPPASTVisitor createModificator(
+ final ASTModificationStore modStore) {
+ return new CPPASTVisitor() {
+ {
+ shouldVisitDeclarators = true;
+ }
+
+ @Override
+ public int visit(IASTDeclarator declarator) {
+ if (declarator instanceof CPPASTFunctionDeclarator) {
+ CPPASTFunctionDeclarator functionDeclarator = (CPPASTFunctionDeclarator)declarator;
+ ICPPASTConstructorChainInitializer[] ctorInitializers = functionDeclarator.getConstructorChain();
+ for(ICPPASTConstructorChainInitializer curInitializer : ctorInitializers){
+ ASTModification modification = new ASTModification(ModificationKind.REPLACE, curInitializer, null, null);
+ modStore.storeModification(null, modification);
+ }
+ }
+ return PROCESS_CONTINUE;
+ }
+ };
+ }
+}
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/remove/DeclarationTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/remove/DeclarationTest.java
new file mode 100644
index 00000000000..c09c55305ee
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/remove/DeclarationTest.java
@@ -0,0 +1,69 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.remove;
+
+import junit.framework.Test;
+
+import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
+import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
+import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTSimpleDeclaration;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
+
+
+
+
+
+public class DeclarationTest extends ChangeGeneratorTest {
+
+ public DeclarationTest(){
+ super("Remove Declaration Node"); //$NON-NLS-1$
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ source = "#ifndef A_H_\n#define A_H_\n\nclass A {\n\nprivate:\n int b;\n int c;\n};\n\n#endif /*A_H_*/\n\n"; //$NON-NLS-1$
+ expectedSource = "#ifndef A_H_\n#define A_H_\n\nclass A {\n\nprivate:\n int b;\n};\n\n#endif /*A_H_*/\n\n"; //$NON-NLS-1$
+ super.setUp();
+ }
+
+ public static Test suite() {
+
+ return new DeclarationTest();
+ }
+
+ @Override
+ protected CPPASTVisitor createModificator(
+ final ASTModificationStore modStore) {
+ return new CPPASTVisitor() {
+ {
+ shouldVisitDeclarations = true;
+ }
+
+ @Override
+ public int visit(IASTDeclaration declaration) {
+ if (declaration instanceof CPPASTSimpleDeclaration) {
+ CPPASTSimpleDeclaration simpleDeclaration = (CPPASTSimpleDeclaration) declaration;
+ if(simpleDeclaration.getDeclarators().length > 0){
+ String name = String.valueOf(simpleDeclaration.getDeclarators()[0].getName().toCharArray());
+ if(name.equals("c")){ //$NON-NLS-1$
+ ASTModification modification = new ASTModification(ASTModification.ModificationKind.REPLACE, declaration, null, null);
+ modStore.storeModification(null, modification);
+ }
+ }
+ }
+ return PROCESS_CONTINUE;
+ }
+ };
+ }
+}
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/remove/ExceptionTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/remove/ExceptionTest.java
new file mode 100644
index 00000000000..1167cb86ec9
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/remove/ExceptionTest.java
@@ -0,0 +1,64 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.remove;
+
+import junit.framework.Test;
+
+import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
+import org.eclipse.cdt.core.dom.ast.IASTTypeId;
+import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
+import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDeclarator;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind;
+
+public class ExceptionTest extends ChangeGeneratorTest {
+
+ public ExceptionTest(){
+ super("Remove Exception Declaration"); //$NON-NLS-1$
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ source = "void foo(int parameter) throw (int){\n}\n\n"; //$NON-NLS-1$
+ expectedSource = "void foo(int parameter){\n}\n\n"; //$NON-NLS-1$
+ super.setUp();
+ }
+
+ public static Test suite() {
+ return new ExceptionTest();
+ }
+
+ @Override
+ protected CPPASTVisitor createModificator(
+ final ASTModificationStore modStore) {
+ return new CPPASTVisitor() {
+ {
+ shouldVisitDeclarators = true;
+ }
+
+ @Override
+ public int visit(IASTDeclarator declarator) {
+ if (declarator instanceof CPPASTFunctionDeclarator) {
+ CPPASTFunctionDeclarator functionDeclarator = (CPPASTFunctionDeclarator)declarator;
+ IASTTypeId[] exceptions = functionDeclarator.getExceptionSpecification();
+ for(IASTTypeId curException : exceptions){
+ ASTModification modification = new ASTModification(ModificationKind.REPLACE, curException, null, null);
+ modStore.storeModification(null, modification);
+ }
+ }
+ return PROCESS_CONTINUE;
+ }
+ };
+ }
+}
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/remove/ExpressionTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/remove/ExpressionTest.java
new file mode 100644
index 00000000000..9283ca3c404
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/remove/ExpressionTest.java
@@ -0,0 +1,66 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.remove;
+
+import junit.framework.Test;
+
+import org.eclipse.cdt.core.dom.ast.IASTExpression;
+import org.eclipse.cdt.core.dom.ast.IASTExpressionList;
+import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
+import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
+
+
+
+
+
+public class ExpressionTest extends ChangeGeneratorTest {
+
+ public ExpressionTest(){
+ super("Remove Expression"); //$NON-NLS-1$
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ source = "void main(){int s = 0, c = 0, h = 0;\ns = 3, c = 4, h = 5;}"; //$NON-NLS-1$
+ expectedSource = "void main(){int s = 0, c = 0, h = 0;\ns = 3, h = 5;}"; //$NON-NLS-1$
+ super.setUp();
+ }
+
+ public static Test suite() {
+ return new ExpressionTest();
+ }
+
+ @Override
+ protected CPPASTVisitor createModificator(
+ final ASTModificationStore modStore) {
+ return new CPPASTVisitor() {
+ {
+ shouldVisitExpressions = true;
+ }
+
+ @Override
+ public int visit(IASTExpression expression) {
+ if (expression instanceof IASTExpressionList) {
+ IASTExpressionList expressionList = (IASTExpressionList) expression;
+ IASTExpression[] expressions = expressionList.getExpressions();
+ ASTModification modification = new ASTModification(ASTModification.ModificationKind.REPLACE, expressions[1], null, null);
+ modStore.storeModification(null, modification);
+ }
+ return PROCESS_CONTINUE;
+ }
+ };
+ }
+
+
+}
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/remove/FirstParameterTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/remove/FirstParameterTest.java
new file mode 100644
index 00000000000..ac28054ffd5
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/remove/FirstParameterTest.java
@@ -0,0 +1,74 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.remove;
+
+import junit.framework.Test;
+
+import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
+import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
+import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
+import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDeclarator;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind;
+
+
+
+
+
+public class FirstParameterTest extends ChangeGeneratorTest {
+
+ public FirstParameterTest(){
+ super("Remove First Parameter Node"); //$NON-NLS-1$
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ source = "void foo(int a, int b, int c){\n}\n\n"; //$NON-NLS-1$
+ expectedSource = "void foo(int b, int c){\n}\n\n"; //$NON-NLS-1$
+ super.setUp();
+ }
+
+ public static Test suite() {
+ return new FirstParameterTest();
+
+ }
+
+ @Override
+ protected CPPASTVisitor createModificator(
+ final ASTModificationStore modStore) {
+ return new CPPASTVisitor() {
+ {
+ shouldVisitDeclarators = true;
+ }
+
+ @Override
+ public int visit(IASTDeclarator declarator) {
+ if (declarator instanceof CPPASTFunctionDeclarator) {
+ CPPASTFunctionDeclarator functionDeclarator = (CPPASTFunctionDeclarator)declarator;
+ IASTParameterDeclaration[] parameters = functionDeclarator.getParameters();
+ for(IASTParameterDeclaration curParam : parameters){
+ if(String.valueOf(curParam.getDeclarator().getName().toCharArray()).equals("a")){ //$NON-NLS-1$
+ ASTModification modification = new ASTModification(ModificationKind.REPLACE, curParam, null, null);
+ modStore.storeModification(null, modification);
+ }
+ }
+ }
+ return PROCESS_CONTINUE;
+ }
+
+ };
+ }
+
+
+}
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/remove/LastParameterTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/remove/LastParameterTest.java
new file mode 100644
index 00000000000..bd900c9f84b
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/remove/LastParameterTest.java
@@ -0,0 +1,70 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.remove;
+
+import junit.framework.Test;
+
+import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
+import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
+import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
+import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDeclarator;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind;
+
+
+
+public class LastParameterTest extends ChangeGeneratorTest {
+
+ public LastParameterTest(){
+ super("Remove Last Parameter Node"); //$NON-NLS-1$
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ source = "void foo(int a, int b, int c){\n}\n\n"; //$NON-NLS-1$
+ expectedSource = "void foo(int a, int b){\n}\n\n"; //$NON-NLS-1$
+ super.setUp();
+ }
+
+ public static Test suite() {
+ return new LastParameterTest();
+ }
+
+ @Override
+ protected CPPASTVisitor createModificator(
+ final ASTModificationStore modStore) {
+ return new CPPASTVisitor() {
+ {
+ shouldVisitDeclarators = true;
+ }
+
+ @Override
+ public int visit(IASTDeclarator declarator) {
+ if (declarator instanceof CPPASTFunctionDeclarator) {
+ CPPASTFunctionDeclarator functionDeclarator = (CPPASTFunctionDeclarator)declarator;
+ IASTParameterDeclaration[] parameters = functionDeclarator.getParameters();
+ for(IASTParameterDeclaration curParam : parameters){
+ if(String.valueOf(curParam.getDeclarator().getName().toCharArray()).equals("c")){ //$NON-NLS-1$
+ ASTModification modification = new ASTModification(ModificationKind.REPLACE, curParam, null, null);
+ modStore.storeModification(null, modification);
+ }
+ }
+ }
+
+
+ return PROCESS_CONTINUE;
+ }
+ };
+ }
+}
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/remove/MiddleParameterTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/remove/MiddleParameterTest.java
new file mode 100644
index 00000000000..80d23a31a11
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/remove/MiddleParameterTest.java
@@ -0,0 +1,72 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.remove;
+
+import junit.framework.Test;
+
+import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
+import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
+import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
+import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDeclarator;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind;
+
+
+
+
+
+public class MiddleParameterTest extends ChangeGeneratorTest {
+
+ public MiddleParameterTest(){
+ super("Remove Middle Parameter Node"); //$NON-NLS-1$
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ source = "void foo(int a, int b, int c){\n}\n\n"; //$NON-NLS-1$
+ expectedSource = "void foo(int a, int c){\n}\n\n"; //$NON-NLS-1$
+ super.setUp();
+ }
+
+
+ public static Test suite() {
+ return new MiddleParameterTest();
+ }
+
+
+ @Override
+ protected CPPASTVisitor createModificator(
+ final ASTModificationStore modStore) {
+ return new CPPASTVisitor() {
+ {
+ shouldVisitDeclarators = true;
+ }
+
+ @Override
+ public int visit(IASTDeclarator declarator) {
+ if (declarator instanceof CPPASTFunctionDeclarator) {
+ CPPASTFunctionDeclarator functionDeclarator = (CPPASTFunctionDeclarator)declarator;
+ IASTParameterDeclaration[] parameters = functionDeclarator.getParameters();
+ for(IASTParameterDeclaration curParam : parameters){
+ if(String.valueOf(curParam.getDeclarator().getName().toCharArray()).equals("b")){ //$NON-NLS-1$
+ ASTModification modification = new ASTModification(ModificationKind.REPLACE, curParam, null, null);
+ modStore.storeModification(null, modification);
+ }
+ }
+ }
+ return PROCESS_CONTINUE;
+ }
+ };
+ }
+}
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/remove/NewInitializerExpressionTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/remove/NewInitializerExpressionTest.java
new file mode 100644
index 00000000000..5b374997a06
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/remove/NewInitializerExpressionTest.java
@@ -0,0 +1,65 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.remove;
+
+import junit.framework.Test;
+
+import org.eclipse.cdt.core.dom.ast.IASTExpression;
+import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNewExpression;
+import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
+
+
+
+
+
+public class NewInitializerExpressionTest extends ChangeGeneratorTest {
+
+ public NewInitializerExpressionTest(){
+ super("Remove New Initializer Expression"); //$NON-NLS-1$
+ }
+
+ @Override
+ public void setUp() throws Exception{
+ source = "int *value = new int(5);"; //$NON-NLS-1$
+ expectedSource = "int *value = new int();"; //$NON-NLS-1$
+ super.setUp();
+ }
+
+ @Override
+ protected CPPASTVisitor createModificator(
+ final ASTModificationStore modStore) {
+ return new CPPASTVisitor() {
+ {
+ shouldVisitExpressions = true;
+ }
+
+ @Override
+ public int visit(IASTExpression expression) {
+ if (expression instanceof ICPPASTNewExpression) {
+ ICPPASTNewExpression newExpression = (ICPPASTNewExpression) expression;
+ ASTModification modification = new ASTModification(ASTModification.ModificationKind.REPLACE, newExpression.getNewInitializer(), null, null);
+ modStore.storeModification(null, modification);
+ }
+ return PROCESS_CONTINUE;
+ }
+ };
+ }
+
+ public static Test suite() {
+ return new NewInitializerExpressionTest();
+
+ }
+
+}
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/remove/PointerInParameterTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/remove/PointerInParameterTest.java
new file mode 100644
index 00000000000..4ba51c164c9
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/remove/PointerInParameterTest.java
@@ -0,0 +1,74 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.remove;
+
+import junit.framework.Test;
+
+import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
+import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
+import org.eclipse.cdt.core.dom.ast.IASTPointerOperator;
+import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
+import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDeclarator;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind;
+
+public class PointerInParameterTest extends ChangeGeneratorTest {
+
+ public PointerInParameterTest(){
+ super("Remove Pointer in Parameter"); //$NON-NLS-1$
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ source = "void foo(int *parameter){\n}\n\n"; //$NON-NLS-1$
+ expectedSource = "void foo(int parameter){\n}\n\n"; //$NON-NLS-1$
+ super.setUp();
+ }
+
+
+ public static Test suite() {
+ return new PointerInParameterTest();
+ }
+
+ @Override
+ protected CPPASTVisitor createModificator(
+ final ASTModificationStore modStore) {
+ return new CPPASTVisitor() {
+ {
+ shouldVisitDeclarators = true;
+ }
+
+ @Override
+ public int visit(IASTDeclarator declarator) {
+ if (declarator instanceof CPPASTFunctionDeclarator) {
+ CPPASTFunctionDeclarator functionDeclarator = (CPPASTFunctionDeclarator)declarator;
+ IASTParameterDeclaration[] parameters = functionDeclarator.getParameters();
+ for(IASTParameterDeclaration curParam : parameters){
+ if(String.valueOf(curParam.getDeclarator().getName().toCharArray()).equals("parameter")){ //$NON-NLS-1$
+ IASTPointerOperator pointer = curParam.getDeclarator().getPointerOperators()[0];
+ ASTModification modification = new ASTModification(ModificationKind.REPLACE, pointer, null, null);
+ modStore.storeModification(null, modification);
+ }
+ }
+ }
+
+
+ return PROCESS_CONTINUE;
+ }
+
+ };
+ }
+
+
+}
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/remove/RemoveTestSuite.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/remove/RemoveTestSuite.java
new file mode 100644
index 00000000000..b124b80d030
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/remove/RemoveTestSuite.java
@@ -0,0 +1,43 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.remove;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * @author Thomas Corbat
+ *
+ */
+public class RemoveTestSuite{
+
+ @SuppressWarnings("nls")
+ public static Test suite() throws Exception {
+ TestSuite suite = new TestSuite("Changegenerator Remove Tests");
+
+ suite.addTest(DeclarationTest.suite());
+ suite.addTest(FirstParameterTest.suite());
+ suite.addTest(MiddleParameterTest.suite());
+ suite.addTest(LastParameterTest.suite());
+ suite.addTest(SingleParameterTest.suite());
+ suite.addTest(PointerInParameterTest.suite());
+ suite.addTest(ExceptionTest.suite());
+ suite.addTest(CtorChainInitializerTest.suite());
+ suite.addTest(ArrayModifierTest.suite());
+ suite.addTest(ExpressionTest.suite());
+ suite.addTest(ArraySizeExpressionTest.suite());
+ suite.addTest(NewInitializerExpressionTest.suite());
+ suite.addTest(StatementTest.suite());
+
+ return suite;
+ }
+}
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/remove/SingleParameterTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/remove/SingleParameterTest.java
new file mode 100644
index 00000000000..1cd12f3379c
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/remove/SingleParameterTest.java
@@ -0,0 +1,67 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.remove;
+
+import junit.framework.Test;
+
+import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
+import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
+import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
+import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDeclarator;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind;
+
+public class SingleParameterTest extends ChangeGeneratorTest {
+
+ public SingleParameterTest(){
+ super("Remove The Only Parameter Node"); //$NON-NLS-1$
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ source = "void foo(int parameter){\n}\n\n"; //$NON-NLS-1$
+ expectedSource = "void foo(){\n}\n\n"; //$NON-NLS-1$
+ super.setUp();
+ }
+
+
+ public static Test suite() {
+ return new SingleParameterTest();
+ }
+
+ @Override
+ protected CPPASTVisitor createModificator(
+ final ASTModificationStore modStore) {
+ return new CPPASTVisitor() {
+ {
+ shouldVisitDeclarators = true;
+ }
+
+ @Override
+ public int visit(IASTDeclarator declarator) {
+ if (declarator instanceof CPPASTFunctionDeclarator) {
+ CPPASTFunctionDeclarator functionDeclarator = (CPPASTFunctionDeclarator)declarator;
+ IASTParameterDeclaration[] parameters = functionDeclarator.getParameters();
+ for(IASTParameterDeclaration curParam : parameters){
+ if(String.valueOf(curParam.getDeclarator().getName().toCharArray()).equals("parameter")){ //$NON-NLS-1$
+ ASTModification modification = new ASTModification(ModificationKind.REPLACE, curParam, null, null);
+ modStore.storeModification(null, modification);
+ }
+ }
+ }
+ return PROCESS_CONTINUE;
+ }
+ };
+ }
+}
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/remove/StatementTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/remove/StatementTest.java
new file mode 100644
index 00000000000..4aeea899f1e
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/remove/StatementTest.java
@@ -0,0 +1,66 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.remove;
+
+import junit.framework.Test;
+
+import org.eclipse.cdt.core.dom.ast.IASTIfStatement;
+import org.eclipse.cdt.core.dom.ast.IASTStatement;
+import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
+import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
+
+
+
+
+
+public class StatementTest extends ChangeGeneratorTest {
+
+ public StatementTest(){
+ super("Remove Then-Statement"); //$NON-NLS-1$
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ source = "int f()\r\n{\r\n\tint i = 0;\r\n\tif(i < 1){\r\n\t\t++i;\r\n\t}\r\n}\r\n"; //$NON-NLS-1$
+ expectedSource = "int f()\r\n{\r\n\tint i = 0;\r\n}\r\n"; //$NON-NLS-1$
+ super.setUp();
+ }
+
+ public static Test suite() {
+ return new StatementTest();
+ }
+
+
+ @Override
+ protected CPPASTVisitor createModificator(
+ final ASTModificationStore modStore) {
+ return new CPPASTVisitor() {
+ {
+ shouldVisitStatements = true;
+ }
+
+ @Override
+ public int visit(IASTStatement statement) {
+ if (statement instanceof IASTIfStatement) {
+ IASTIfStatement ifStatement = (IASTIfStatement) statement;
+
+ ASTModification modification = new ASTModification(ASTModification.ModificationKind.REPLACE, ifStatement, null, null);
+ modStore.storeModification(null, modification);
+ }
+
+ return PROCESS_CONTINUE;
+ }
+ };
+ }
+}
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/replace/ArrayModifierTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/replace/ArrayModifierTest.java
new file mode 100644
index 00000000000..a75f7cedda8
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/replace/ArrayModifierTest.java
@@ -0,0 +1,69 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.replace;
+
+import junit.framework.Test;
+
+import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator;
+import org.eclipse.cdt.core.dom.ast.IASTArrayModifier;
+import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
+import org.eclipse.cdt.core.dom.ast.IASTExpression;
+import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
+import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTArrayModifier;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTLiteralExpression;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind;
+
+public class ArrayModifierTest extends ChangeGeneratorTest {
+
+ public ArrayModifierTest(){
+ super("Replace Array Modifier"); //$NON-NLS-1$
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ source = "int *pi[3];"; //$NON-NLS-1$
+ expectedSource = "int *pi[15];"; //$NON-NLS-1$
+ super.setUp();
+ }
+
+ public static Test suite() {
+ return new ArrayModifierTest();
+ }
+
+
+ @Override
+ protected CPPASTVisitor createModificator(
+ final ASTModificationStore modStore) {
+ return new CPPASTVisitor() {
+ {
+ shouldVisitDeclarators = true;
+ }
+
+ @Override
+ public int visit(IASTDeclarator declarator) {
+ if (declarator instanceof IASTArrayDeclarator) {
+ IASTArrayDeclarator arrayDeclarator = (IASTArrayDeclarator)declarator;
+ IASTArrayModifier[] modifiers = arrayDeclarator.getArrayModifiers();
+ IASTArrayModifier newModifier = new CPPASTArrayModifier();
+ IASTExpression expr = new CPPASTLiteralExpression(0, "15"); //$NON-NLS-1$
+ newModifier.setConstantExpression(expr);
+ ASTModification modification = new ASTModification(ModificationKind.REPLACE, modifiers[0], newModifier, null);
+ modStore.storeModification(null, modification);
+ }
+ return PROCESS_CONTINUE;
+ }
+ };
+ }
+}
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/replace/ArraySizeExpressionTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/replace/ArraySizeExpressionTest.java
new file mode 100644
index 00000000000..215b9f9e61a
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/replace/ArraySizeExpressionTest.java
@@ -0,0 +1,65 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.replace;
+
+import junit.framework.Test;
+
+import org.eclipse.cdt.core.dom.ast.IASTExpression;
+import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNewExpression;
+import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTLiteralExpression;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
+
+
+
+
+
+public class ArraySizeExpressionTest extends ChangeGeneratorTest {
+
+ public ArraySizeExpressionTest(){
+ super("Relpace Array Size Expression"); //$NON-NLS-1$
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ source = "int *values = new int[5][6];"; //$NON-NLS-1$
+ expectedSource = "int *values = new int[5][7];"; //$NON-NLS-1$
+ super.setUp();
+ }
+
+ public static Test suite() {
+ return new ArraySizeExpressionTest();
+ }
+
+ @Override
+ protected CPPASTVisitor createModificator(
+ final ASTModificationStore modStore) {
+ return new CPPASTVisitor() {
+ {
+ shouldVisitExpressions = true;
+ }
+
+ @Override
+ public int visit(IASTExpression expression) {
+ if (expression instanceof ICPPASTNewExpression) {
+ ICPPASTNewExpression newExpression = (ICPPASTNewExpression) expression;
+ IASTExpression[] arraySizeExpressions = newExpression.getNewTypeIdArrayExpressions();
+ ASTModification modification = new ASTModification(ASTModification.ModificationKind.REPLACE, arraySizeExpressions[1], new CPPASTLiteralExpression(0, "7"), null); //$NON-NLS-1$
+ modStore.storeModification(null, modification);
+ }
+ return PROCESS_CONTINUE;
+ }
+ };
+ }
+}
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/replace/CtorChainInitializerTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/replace/CtorChainInitializerTest.java
new file mode 100644
index 00000000000..8db4323f9dc
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/replace/CtorChainInitializerTest.java
@@ -0,0 +1,70 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.replace;
+
+import junit.framework.Test;
+
+import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
+import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer;
+import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTConstructorChainInitializer;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDeclarator;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTIdExpression;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind;
+
+public class CtorChainInitializerTest extends ChangeGeneratorTest {
+
+ public CtorChainInitializerTest(){
+ super("Replace Ctor Initializer"); //$NON-NLS-1$
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ source = "TestClass::TestClass(int a):beta(b){\n}\n\n"; //$NON-NLS-1$
+ expectedSource = "TestClass::TestClass(int a): alpha(a){\n}\n\n"; //$NON-NLS-1$
+ super.setUp();
+ }
+
+ public static Test suite() {
+ return new CtorChainInitializerTest();
+ }
+
+ @Override
+ protected CPPASTVisitor createModificator(
+ final ASTModificationStore modStore) {
+ return new CPPASTVisitor() {
+ {
+ shouldVisitDeclarators = true;
+ }
+
+ @Override
+ public int visit(IASTDeclarator declarator) {
+ if (declarator instanceof CPPASTFunctionDeclarator) {
+ CPPASTFunctionDeclarator functionDeclarator = (CPPASTFunctionDeclarator)declarator;
+ ICPPASTConstructorChainInitializer[] ctorInitializers = functionDeclarator.getConstructorChain();
+ for(ICPPASTConstructorChainInitializer curInitializer : ctorInitializers){
+ CPPASTIdExpression initExpr = new CPPASTIdExpression(new CPPASTName("a".toCharArray())); //$NON-NLS-1$
+ CPPASTName initName = new CPPASTName("alpha".toCharArray()); //$NON-NLS-1$
+ ICPPASTConstructorChainInitializer newInitializer = new CPPASTConstructorChainInitializer(initName, initExpr);
+ ASTModification modification = new ASTModification(ModificationKind.REPLACE, curInitializer, newInitializer, null);
+ modStore.storeModification(null, modification);
+ }
+ }
+ return PROCESS_CONTINUE;
+ }
+ };
+ }
+}
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/replace/ExceptionTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/replace/ExceptionTest.java
new file mode 100644
index 00000000000..131fd1afeb7
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/replace/ExceptionTest.java
@@ -0,0 +1,78 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.replace;
+
+import junit.framework.Test;
+
+import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
+import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier;
+import org.eclipse.cdt.core.dom.ast.IASTTypeId;
+import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
+import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTDeclarator;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDeclarator;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTSimpleDeclSpecifier;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTTypeId;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind;
+
+public class ExceptionTest extends ChangeGeneratorTest {
+
+
+ public ExceptionTest(){
+ super("Remove Exception Declaration"); //$NON-NLS-1$
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ source = "void foo(int parameter) throw (float){\n}\n\n"; //$NON-NLS-1$
+ expectedSource = "void foo(int parameter) throw (int){\n}\n\n"; //$NON-NLS-1$
+ super.setUp();
+ }
+
+ public static Test suite() {
+ return new ExceptionTest();
+ }
+
+ @Override
+ protected CPPASTVisitor createModificator(
+ final ASTModificationStore modStore) {
+ return new CPPASTVisitor() {
+ {
+ shouldVisitDeclarators = true;
+ }
+
+ @Override
+ public int visit(IASTDeclarator declarator) {
+ if (declarator instanceof CPPASTFunctionDeclarator) {
+ CPPASTFunctionDeclarator functionDeclarator = (CPPASTFunctionDeclarator)declarator;
+ IASTTypeId existingException = functionDeclarator.getExceptionSpecification()[0];
+
+ IASTTypeId exception = new CPPASTTypeId();
+ CPPASTDeclarator exceptionDeclarator = new CPPASTDeclarator();
+ exceptionDeclarator.setName(new CPPASTName());
+ CPPASTSimpleDeclSpecifier exDeclSpec = new CPPASTSimpleDeclSpecifier();
+ exDeclSpec.setType(IASTSimpleDeclSpecifier.t_int);
+ exception.setDeclSpecifier(exDeclSpec);
+ exception.setAbstractDeclarator(exceptionDeclarator);
+ ASTModification modification = new ASTModification(ModificationKind.REPLACE, existingException, exception, null);
+ modStore.storeModification(null, modification);
+ }
+ return PROCESS_CONTINUE;
+ }
+ };
+ }
+
+
+}
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/replace/ExpressionTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/replace/ExpressionTest.java
new file mode 100644
index 00000000000..ddf4f69070d
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/replace/ExpressionTest.java
@@ -0,0 +1,71 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.replace;
+
+import junit.framework.Test;
+
+import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression;
+import org.eclipse.cdt.core.dom.ast.IASTExpression;
+import org.eclipse.cdt.core.dom.ast.IASTExpressionList;
+import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
+import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTBinaryExpression;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTIdExpression;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTLiteralExpression;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
+
+
+
+
+
+public class ExpressionTest extends ChangeGeneratorTest {
+
+ public ExpressionTest(){
+ super("Replace Expression"); //$NON-NLS-1$
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ source = "void main(){int s = 0, c = 0, h = 0;\ns = 3, c = 4, h = 5;}"; //$NON-NLS-1$
+ expectedSource = "void main(){int s = 0, c = 0, h = 0;\ns = 3, c = 9, h = 5;}"; //$NON-NLS-1$
+ super.setUp();
+ }
+
+ public static Test suite() {
+ return new ExpressionTest();
+ }
+
+
+ @Override
+ protected CPPASTVisitor createModificator(
+ final ASTModificationStore modStore) {
+ return new CPPASTVisitor() {
+ {
+ shouldVisitExpressions = true;
+ }
+
+ @Override
+ public int visit(IASTExpression expression) {
+ if (expression instanceof IASTExpressionList) {
+ IASTExpressionList expressionList = (IASTExpressionList) expression;
+ IASTExpression[] expressions = expressionList.getExpressions();
+ CPPASTBinaryExpression binEx = new CPPASTBinaryExpression(IASTBinaryExpression.op_assign, new CPPASTIdExpression(new CPPASTName("c".toCharArray())), new CPPASTLiteralExpression(0, "9")); //$NON-NLS-1$ //$NON-NLS-2$
+ ASTModification modification = new ASTModification(ASTModification.ModificationKind.REPLACE, expressions[1], binEx, null);
+ modStore.storeModification(null, modification);
+ }
+ return PROCESS_CONTINUE;
+ }
+ };
+ }
+}
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/replace/IdenticalTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/replace/IdenticalTest.java
new file mode 100644
index 00000000000..6b60c8d6dc8
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/replace/IdenticalTest.java
@@ -0,0 +1,59 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.replace;
+
+import junit.framework.Test;
+
+import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
+import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
+import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
+
+
+
+
+
+public class IdenticalTest extends ChangeGeneratorTest {
+
+ public IdenticalTest(){
+ super("Replace Node Same Node"); //$NON-NLS-1$
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ source = "#ifndef A_H_\n#define A_H_\n\nclass A {\n\nprivate:\n int c;\n};\n\n#endif /*A_H_*/\n\n"; //$NON-NLS-1$
+ expectedSource = "#ifndef A_H_\n#define A_H_\n\nclass A {\n\nprivate:\n int c;\n};\n\n#endif /*A_H_*/\n\n"; //$NON-NLS-1$
+ super.setUp();
+ }
+
+ public static Test suite() {
+ return new IdenticalTest();
+ }
+
+ @Override
+ protected CPPASTVisitor createModificator(
+ final ASTModificationStore modStore) {
+ return new CPPASTVisitor() {
+ {
+ shouldVisitDeclarators = true;
+ }
+
+ @Override
+ public int visit(IASTDeclarator declarator) {
+ ASTModification modification = new ASTModification(ASTModification.ModificationKind.REPLACE, declarator.getName(), declarator.getName(), null);
+ modStore.storeModification(null, modification);
+ return PROCESS_CONTINUE;
+ }
+ };
+ }
+}
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/replace/InitializerTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/replace/InitializerTest.java
new file mode 100644
index 00000000000..b7257f95e6b
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/replace/InitializerTest.java
@@ -0,0 +1,69 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.replace;
+
+import junit.framework.Test;
+
+import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
+import org.eclipse.cdt.core.dom.ast.IASTInitializer;
+import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
+import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTDeclarator;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTInitializerExpression;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTLiteralExpression;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind;
+
+public class InitializerTest extends ChangeGeneratorTest {
+
+ public InitializerTest(){
+ super("Replace Initializer"); //$NON-NLS-1$
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ source = "int hs = 5;"; //$NON-NLS-1$
+ expectedSource = "int hs = 999;"; //$NON-NLS-1$
+ super.setUp();
+ }
+
+ public static Test suite() {
+ return new InitializerTest();
+ }
+
+
+ @Override
+ protected CPPASTVisitor createModificator(
+ final ASTModificationStore modStore) {
+ return new CPPASTVisitor() {
+ {
+ shouldVisitDeclarators = true;
+ }
+
+ @Override
+ public int visit(IASTDeclarator declarator) {
+ if (declarator instanceof CPPASTDeclarator) {
+ CPPASTDeclarator fieldDeclarator = (CPPASTDeclarator)declarator;
+ IASTInitializer initializer = fieldDeclarator.getInitializer();
+
+ CPPASTLiteralExpression litEx = new CPPASTLiteralExpression(0, "999"); //$NON-NLS-1$
+ CPPASTInitializerExpression initExpr = new CPPASTInitializerExpression(litEx);
+
+ ASTModification modification = new ASTModification(ModificationKind.REPLACE, initializer, initExpr, null);
+ modStore.storeModification(null, modification);
+ }
+ return PROCESS_CONTINUE;
+ }
+ };
+ }
+}
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/replace/MoveRenameTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/replace/MoveRenameTest.java
new file mode 100644
index 00000000000..44f497bc6fe
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/replace/MoveRenameTest.java
@@ -0,0 +1,77 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.replace;
+
+import junit.framework.Test;
+
+import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
+import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
+import org.eclipse.cdt.core.dom.ast.IASTName;
+import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
+import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTCompositeTypeSpecifier;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTSimpleDeclaration;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
+
+
+
+
+
+public class MoveRenameTest extends ChangeGeneratorTest {
+
+ public MoveRenameTest(){
+ super("Swap Rename Declarations"); //$NON-NLS-1$
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+
+ source = "#ifndef A_H_\r\n#define A_H_\r\n\r\nclass A {\r\n\r\nprivate:\r\n int b;\r\n int a;\r\n};\r\n\r\n#endif /*A_H_*/\r\n\r\n"; //$NON-NLS-1$
+ expectedSource = "#ifndef A_H_\r\n#define A_H_\r\n\r\nclass A {\r\n\r\nprivate:\r\n int d;\r\n int b;\r\n};\r\n\r\n#endif /*A_H_*/\r\n\r\n"; //$NON-NLS-1$
+ super.setUp();
+ }
+
+
+ public static Test suite() {
+ return new MoveRenameTest();
+ }
+
+ @Override
+ protected CPPASTVisitor createModificator(
+ final ASTModificationStore modStore) {
+ return new CPPASTVisitor() {
+ {
+ shouldVisitDeclSpecifiers = true;
+ }
+
+ @Override
+ public int visit(IASTDeclSpecifier declSpec) {
+ if (declSpec instanceof ICPPASTCompositeTypeSpecifier) {
+ CPPASTCompositeTypeSpecifier classSpecifier = (CPPASTCompositeTypeSpecifier) declSpec;
+ IASTDeclaration[] members = classSpecifier.getMembers();
+ ASTModification swap1 = new ASTModification(ASTModification.ModificationKind.REPLACE, members[1], members[2], null);
+ ASTModification swap2 = new ASTModification(ASTModification.ModificationKind.REPLACE, members[2], members[1], null);
+ IASTName name =((CPPASTSimpleDeclaration)members[2]).getDeclarators()[0].getName();
+ modStore.storeModification(null, swap1);
+ modStore.storeModification(null, swap2);
+ modStore.storeModification(swap1, new ASTModification(ASTModification.ModificationKind.REPLACE, name, new CPPASTName("d".toCharArray()), null)); //$NON-NLS-1$
+ }
+ return super.visit(declSpec);
+ }
+
+ };
+ }
+
+}
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/replace/MoveTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/replace/MoveTest.java
new file mode 100644
index 00000000000..71104ae5302
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/replace/MoveTest.java
@@ -0,0 +1,71 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.replace;
+
+import junit.framework.Test;
+
+import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
+import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
+import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
+import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTCompositeTypeSpecifier;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
+
+
+
+
+
+public class MoveTest extends ChangeGeneratorTest {
+
+ public MoveTest(){
+ super("Swap Declarations"); //$NON-NLS-1$
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ source = "#ifndef A_H_\r\n#define A_H_\r\n\r\nclass A {\r\n\r\nprivate:\r\n int b;\r\n int a;\r\n};\r\n\r\n#endif /*A_H_*/\r\n\r\n"; //$NON-NLS-1$
+ expectedSource = "#ifndef A_H_\r\n#define A_H_\r\n\r\nclass A {\r\n\r\nprivate:\r\n int a;\r\n int b;\r\n};\r\n\r\n#endif /*A_H_*/\r\n\r\n"; //$NON-NLS-1$
+ super.setUp();
+ }
+
+ public static Test suite() {
+ return new MoveTest();
+
+ }
+
+ @Override
+ protected CPPASTVisitor createModificator(
+ final ASTModificationStore modStore) {
+ return new CPPASTVisitor() {
+ {
+ shouldVisitDeclSpecifiers = true;
+ }
+
+ @Override
+ public int visit(IASTDeclSpecifier declSpec) {
+ if (declSpec instanceof ICPPASTCompositeTypeSpecifier) {
+ CPPASTCompositeTypeSpecifier classSpecifier = (CPPASTCompositeTypeSpecifier) declSpec;
+ IASTDeclaration[] members = classSpecifier.getMembers();
+ ASTModification swap1 = new ASTModification(ASTModification.ModificationKind.REPLACE, members[1], members[2], null);
+ ASTModification swap2 = new ASTModification(ASTModification.ModificationKind.REPLACE, members[2], members[1], null);
+ modStore.storeModification(null, swap1);
+ modStore.storeModification(null, swap2);
+ }
+ return super.visit(declSpec);
+ }
+
+ };
+ }
+
+}
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/replace/NameTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/replace/NameTest.java
new file mode 100644
index 00000000000..501e0980df1
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/replace/NameTest.java
@@ -0,0 +1,67 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.replace;
+
+import junit.framework.Test;
+
+import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
+import org.eclipse.cdt.core.dom.ast.IASTName;
+import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
+import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
+
+
+
+
+
+public class NameTest extends ChangeGeneratorTest {
+
+
+ public NameTest(){
+ super("Replace Name Node"); //$NON-NLS-1$
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ source = "#ifndef A_H_\r\n#define A_H_\r\n\r\nclass A {\r\n\r\nprivate:\r\n int c;\r\n};\r\n\r\n#endif /*A_H_*/\r\n\r\n"; //$NON-NLS-1$
+ expectedSource = "#ifndef A_H_\r\n#define A_H_\r\n\r\nclass A {\r\n\r\nprivate:\r\n int b;\r\n};\r\n\r\n#endif /*A_H_*/\r\n\r\n"; //$NON-NLS-1$
+ super.setUp();
+ }
+
+ public static Test suite() {
+ return new NameTest();
+ }
+
+ @Override
+ protected CPPASTVisitor createModificator(
+ final ASTModificationStore modStore) {
+ return new CPPASTVisitor() {
+ {
+ shouldVisitDeclarators = true;
+ }
+
+ @Override
+ public int visit(IASTDeclarator declarator) {
+ char[] newName = new char[]{'b'};
+ IASTName name = new CPPASTName(newName);
+ ASTModification modification = new ASTModification(ASTModification.ModificationKind.REPLACE, declarator.getName(), name, null);
+ modStore.storeModification(null, modification);
+ return PROCESS_CONTINUE;
+ }
+
+ };
+ }
+
+
+}
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/replace/NewInitializerExpressionTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/replace/NewInitializerExpressionTest.java
new file mode 100644
index 00000000000..323a588d7e8
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/replace/NewInitializerExpressionTest.java
@@ -0,0 +1,66 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.replace;
+
+import junit.framework.Test;
+
+import org.eclipse.cdt.core.dom.ast.IASTExpression;
+import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNewExpression;
+import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTLiteralExpression;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
+
+
+
+
+
+public class NewInitializerExpressionTest extends ChangeGeneratorTest {
+
+ public NewInitializerExpressionTest(){
+ super("Replace New Initializer Expression"); //$NON-NLS-1$
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ source = "int *value = new int(5);"; //$NON-NLS-1$
+ expectedSource = "int *value = new int(6);"; //$NON-NLS-1$
+ super.setUp();
+ }
+
+ public static Test suite() {
+ return new NewInitializerExpressionTest();
+ }
+
+ @Override
+ protected CPPASTVisitor createModificator(
+ final ASTModificationStore modStore) {
+ return new CPPASTVisitor() {
+ {
+ shouldVisitExpressions = true;
+ }
+
+ @Override
+ public int visit(IASTExpression expression) {
+ if (expression instanceof ICPPASTNewExpression) {
+ ICPPASTNewExpression newExpression = (ICPPASTNewExpression) expression;
+ ASTModification modification = new ASTModification(ASTModification.ModificationKind.REPLACE, newExpression.getNewInitializer(), new CPPASTLiteralExpression(0, "6"), null); //$NON-NLS-1$
+ modStore.storeModification(null, modification);
+ }
+ return PROCESS_CONTINUE;
+ }
+ };
+ }
+
+
+}
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/replace/PointerInParameterTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/replace/PointerInParameterTest.java
new file mode 100644
index 00000000000..a11276a4828
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/replace/PointerInParameterTest.java
@@ -0,0 +1,70 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.replace;
+
+import junit.framework.Test;
+
+import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
+import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
+import org.eclipse.cdt.core.dom.ast.IASTPointerOperator;
+import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
+import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDeclarator;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTPointer;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind;
+
+public class PointerInParameterTest extends ChangeGeneratorTest {
+
+ public PointerInParameterTest(){
+ super("Replace Pointer for Parameter"); //$NON-NLS-1$
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ source = "void foo(int &parameter){\n}\n\n"; //$NON-NLS-1$
+ expectedSource = "void foo(int *parameter){\n}\n\n"; //$NON-NLS-1$
+ super.setUp();
+ }
+
+ public static Test suite() {
+ return new PointerInParameterTest();
+ }
+
+ @Override
+ protected CPPASTVisitor createModificator(
+ final ASTModificationStore modStore) {
+ return new CPPASTVisitor() {
+ {
+ shouldVisitDeclarators = true;
+ }
+
+ @Override
+ public int visit(IASTDeclarator declarator) {
+ if (declarator instanceof CPPASTFunctionDeclarator) {
+ CPPASTFunctionDeclarator functionDeclarator = (CPPASTFunctionDeclarator)declarator;
+ IASTParameterDeclaration[] parameters = functionDeclarator.getParameters();
+ for(IASTParameterDeclaration curParam : parameters){
+ if(String.valueOf(curParam.getDeclarator().getName().toCharArray()).equals("parameter")){ //$NON-NLS-1$
+ IASTPointerOperator pointer = curParam.getDeclarator().getPointerOperators()[0];
+ CPPASTPointer newPointer = new CPPASTPointer();
+ ASTModification modification = new ASTModification(ModificationKind.REPLACE, pointer, newPointer, null);
+ modStore.storeModification(null, modification);
+ }
+ }
+ }
+ return PROCESS_CONTINUE;
+ }
+ };
+ }
+}
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/replace/ReplaceTestSuite.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/replace/ReplaceTestSuite.java
new file mode 100644
index 00000000000..08fb3b5c4c2
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/replace/ReplaceTestSuite.java
@@ -0,0 +1,42 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.replace;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * @author Thomas Corbat
+ *
+ */
+public class ReplaceTestSuite{
+
+ @SuppressWarnings("nls")
+ public static Test suite() throws Exception {
+ TestSuite suite = new TestSuite("ChangegeneratorReplaceTests");
+
+ suite.addTest(NameTest.suite());
+ suite.addTest(MoveTest.suite());
+ suite.addTest(MoveRenameTest.suite());
+ suite.addTest(SameNameTest.suite());
+ suite.addTest(IdenticalTest.suite());
+ suite.addTest(PointerInParameterTest.suite());
+ suite.addTest(ExceptionTest.suite());
+ suite.addTest(ArrayModifierTest.suite());
+ suite.addTest(InitializerTest.suite());
+ suite.addTest(ExpressionTest.suite());
+ suite.addTest(ArraySizeExpressionTest.suite());
+ suite.addTest(NewInitializerExpressionTest.suite());
+ suite.addTest(StatementTest.suite());
+ return suite;
+ }
+}
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/replace/SameNameTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/replace/SameNameTest.java
new file mode 100644
index 00000000000..3d19b40f4dd
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/replace/SameNameTest.java
@@ -0,0 +1,67 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.replace;
+
+import junit.framework.Test;
+
+import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
+import org.eclipse.cdt.core.dom.ast.IASTName;
+import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
+import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
+
+
+
+
+
+public class SameNameTest extends ChangeGeneratorTest {
+
+ public SameNameTest(){
+ super("Replace Name Node Same Name"); //$NON-NLS-1$
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+
+ source = "#ifndef A_H_\r\n#define A_H_\r\n\r\nclass A {\r\n\r\nprivate:\r\n int c;\r\n};\r\n\r\n#endif /*A_H_*/\r\n\r\n"; //$NON-NLS-1$
+ expectedSource = "#ifndef A_H_\r\n#define A_H_\r\n\r\nclass A {\r\n\r\nprivate:\r\n int c;\r\n};\r\n\r\n#endif /*A_H_*/\r\n\r\n"; //$NON-NLS-1$
+ super.setUp();
+ }
+
+ public static Test suite() {
+ return new SameNameTest();
+ }
+
+ @Override
+ protected CPPASTVisitor createModificator(
+ final ASTModificationStore modStore) {
+ return new CPPASTVisitor() {
+ {
+ shouldVisitDeclarators = true;
+ }
+
+ @Override
+ public int visit(IASTDeclarator declarator) {
+ char[] newName = new char[]{'c'};
+ IASTName name = new CPPASTName(newName);
+ ASTModification modification = new ASTModification(ASTModification.ModificationKind.REPLACE, declarator.getName(), name, null);
+ modStore.storeModification(null, modification);
+ return PROCESS_CONTINUE;
+ }
+
+ };
+ }
+
+
+}
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/replace/StatementTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/replace/StatementTest.java
new file mode 100644
index 00000000000..4b552cb78ab
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/replace/StatementTest.java
@@ -0,0 +1,75 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.replace;
+
+import junit.framework.Test;
+
+import org.eclipse.cdt.core.dom.ast.IASTIfStatement;
+import org.eclipse.cdt.core.dom.ast.IASTStatement;
+import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression;
+import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
+import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTCompoundStatement;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTExpressionStatement;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTIdExpression;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTUnaryExpression;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
+
+
+
+
+
+public class StatementTest extends ChangeGeneratorTest {
+
+ public StatementTest(){
+ super("Replace Then-Statement"); //$NON-NLS-1$
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ source = "int f()\r\n{\r\n\tint i = 0;\r\n\tif(i < 1){\r\n\t\t++i;\r\n\t}\r\n}\r\n"; //$NON-NLS-1$
+ expectedSource = "int f()\r\n{\r\n\tint i = 0;\r\n\tif(i < 1){\r\n\t i++;\r\n\t}\r\n}\r\n"; //$NON-NLS-1$
+ super.setUp();
+ }
+
+ public static Test suite() {
+ return new StatementTest();
+ }
+
+
+ @Override
+ protected CPPASTVisitor createModificator(
+ final ASTModificationStore modStore) {
+ return new CPPASTVisitor() {
+ {
+ shouldVisitStatements = true;
+ }
+
+ @Override
+ public int visit(IASTStatement statement) {
+ if (statement instanceof IASTIfStatement) {
+ IASTIfStatement ifStatement = (IASTIfStatement) statement;
+ CPPASTCompoundStatement compound = new CPPASTCompoundStatement();
+
+ CPPASTExpressionStatement expr = new CPPASTExpressionStatement(new CPPASTUnaryExpression(IASTUnaryExpression.op_postFixIncr, new CPPASTIdExpression(new CPPASTName("i".toCharArray())))); //$NON-NLS-1$
+ compound.addStatement(expr);
+ ASTModification modification = new ASTModification(ASTModification.ModificationKind.REPLACE, ifStatement.getThenClause(), compound, null);
+ modStore.storeModification(null, modification);
+ }
+
+ return PROCESS_CONTINUE;
+ }
+ };
+ }
+}
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/comenthandler/CommentHandlingTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/comenthandler/CommentHandlingTest.java
new file mode 100644
index 00000000000..42337313641
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/comenthandler/CommentHandlingTest.java
@@ -0,0 +1,118 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Institute for Software - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.cdt.core.parser.tests.rewrite.comenthandler;
+
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.TreeSet;
+import java.util.Vector;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.eclipse.cdt.core.CCorePlugin;
+import org.eclipse.cdt.core.dom.ast.IASTComment;
+import org.eclipse.cdt.core.dom.ast.IASTNode;
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
+import org.eclipse.cdt.core.model.ITranslationUnit;
+import org.eclipse.cdt.core.parser.tests.rewrite.RewriteBaseTest;
+import org.eclipse.cdt.core.parser.tests.rewrite.TestSourceFile;
+import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.ASTCommenter;
+import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap;
+import org.eclipse.core.runtime.CoreException;
+
+/**
+ * @author Guido Zgraggen IFS
+ *
+ */
+public class CommentHandlingTest extends RewriteBaseTest {
+
+ private static final String ANY_CHAR_REGEXP = "(.*)"; //$NON-NLS-1$
+ private static String separator = System.getProperty("line.separator"); //$NON-NLS-1$
+
+ private static String LEADING_COMMENT_SEPARATOR = "=>leading"; //$NON-NLS-1$
+ private static String TRAILING_COMMENT_SEPARATOR = "=>trailing"; //$NON-NLS-1$
+ private static String FREESTANDING_COMMENT_SEPARATOR = "=>freestanding"; //$NON-NLS-1$
+
+ public CommentHandlingTest(String name, Vector<TestSourceFile> files) {
+ super(name, files);
+ }
+
+ @Override
+ protected void runTest() throws Throwable {
+
+ if (fileMap.size() > 1) {
+ throw new Exception("To many files for CommentHandlingTest"); //$NON-NLS-1$
+ } else if (fileMap.size() == 0) {
+ throw new Exception("No file for testing"); //$NON-NLS-1$
+ }
+
+ TestSourceFile file = fileMap.values().iterator().next();
+
+ NodeCommentMap nodeMap = ASTCommenter.getCommentedNodeMap(getUnit());
+ Matcher matcher = Pattern.compile(CommentHandlingTest.getSeparatingRegexp(), Pattern.MULTILINE | Pattern.DOTALL).matcher(file.getExpectedSource());
+
+ if (!matcher.find()) {
+ fail("Missing expected section. Expected result code must be of the following format:\n\"=>leading\n...\n=>trailing\n...\n=>freestanding\""); //$NON-NLS-1$
+ }
+ String leadingResult = matcher.group(1);
+ String trailingResult = matcher.group(2);
+ String freestandingResult = matcher.group(3);
+
+ testMap(nodeMap.getLeadingMap(), leadingResult, "Leading test failed."); //$NON-NLS-1$
+ testMap(nodeMap.getTrailingMap(), trailingResult, "Trailing test failed."); //$NON-NLS-1$
+ testMap(nodeMap.getFreestandingMap(), freestandingResult, "Freestanding test failed."); //$NON-NLS-1$
+ }
+
+ private void testMap(HashMap<IASTNode, ArrayList<IASTComment>> map, String expectedResult, String err) {
+ TreeSet<IASTNode> keyTree = new TreeSet<IASTNode>(new NodeOffsetComparator());
+ keyTree.addAll(map.keySet());
+ StringBuilder output = new StringBuilder();
+ for (IASTNode actNode : keyTree) {
+ ArrayList<IASTComment> comments = map.get(actNode);
+
+ output.append(actNode.getRawSignature() + " = "); //$NON-NLS-1$
+ boolean first = true;
+ for (IASTComment actComment : comments) {
+ if (!first) {
+ output.append(" , "); //$NON-NLS-1$
+ }
+ output.append(actComment.getRawSignature());
+ first = false;
+ }
+ output.append(separator);
+ }
+ assertEquals(err, expectedResult.trim(), output.toString().trim());
+ }
+
+ private static String getSeparatingRegexp() {
+ return LEADING_COMMENT_SEPARATOR + ANY_CHAR_REGEXP + TRAILING_COMMENT_SEPARATOR + ANY_CHAR_REGEXP + FREESTANDING_COMMENT_SEPARATOR + ANY_CHAR_REGEXP;
+ }
+
+ // === Nested classes for testing purpose
+ private final class NodeOffsetComparator implements Comparator<IASTNode> {
+ public int compare(IASTNode o1, IASTNode o2) {
+ int offDif = o1.getFileLocation().getNodeOffset() - o2.getFileLocation().getNodeOffset();
+ if (offDif == 0) {
+ return o1.getFileLocation().getNodeLength() - o2.getFileLocation().getNodeLength();
+ }
+ return offDif;
+ }
+ }
+
+
+ private IASTTranslationUnit getUnit() throws CoreException {
+ ITranslationUnit tu = (ITranslationUnit) CCorePlugin.getDefault().getCoreModel().create(project.getFile(fileMap.keySet().iterator().next()));
+ return tu.getAST();
+ }
+
+}
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/comenthandler/CommentHandlingTestSuite.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/comenthandler/CommentHandlingTestSuite.java
new file mode 100644
index 00000000000..0aa0ead6105
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/comenthandler/CommentHandlingTestSuite.java
@@ -0,0 +1,35 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Institute for Software - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.cdt.core.parser.tests.rewrite.comenthandler;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.eclipse.cdt.core.parser.tests.rewrite.RewriteTester;
+
+/**
+ * @author Guido Zgraggen IFS
+ *
+ */
+public class CommentHandlingTestSuite extends TestSuite {
+
+ public static Test suite() throws Exception {
+ TestSuite suite = new TestSuite(CommentHandlingTestSuite.class.getName());
+
+ suite.addTest(RewriteTester.suite("CommentTests", "resources/rewrite/CommentHandlingTestSource.rts")); //$NON-NLS-1$ //$NON-NLS-2$
+
+ suite.addTestSuite(NodeCommentMapTest.class);
+
+ return suite;
+ }
+
+}
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/comenthandler/NodeCommentMapTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/comenthandler/NodeCommentMapTest.java
new file mode 100644
index 00000000000..2d4f334dced
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/comenthandler/NodeCommentMapTest.java
@@ -0,0 +1,102 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Institute for Software - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.cdt.core.parser.tests.rewrite.comenthandler;
+
+import junit.framework.TestCase;
+
+import org.eclipse.cdt.core.dom.ast.IASTComment;
+import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName;
+import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap;
+
+/**
+ * @author Guido Zgraggen IFS
+ *
+ */
+public class NodeCommentMapTest extends TestCase {
+
+ private NodeCommentMap map;
+
+ @Override
+ protected void setUp() throws Exception {
+ map = new NodeCommentMap();
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ map = null;
+ }
+
+ public void testNoComment(){
+ ASTNode node = new CPPASTName();
+
+ assertEquals(0, map.getCommentsForNode(node).size());
+ }
+
+ public void testOneComment(){
+ ASTNode node = new CPPASTName();
+ IASTComment comm = new Comment();
+
+ map.addCommentToNode(node, comm);
+
+ assertEquals(1, map.getCommentsForNode(node).size());
+ assertEquals(comm, map.getCommentsForNode(node).get(0));
+ }
+
+ public void testTwoComment(){
+ ASTNode node = new CPPASTName();
+ IASTComment com1 = new Comment();
+ IASTComment com2 = new Comment();
+
+ map.addCommentToNode(node, com1);
+ map.addCommentToNode(node, com2);
+
+ assertEquals(2, map.getCommentsForNode(node).size());
+ assertEquals(com1, map.getCommentsForNode(node).get(0));
+ assertEquals(com2, map.getCommentsForNode(node).get(1));
+ }
+
+
+ public void testCommentOnDifferentNodes(){
+ ASTNode node1 = new CPPASTName();
+ ASTNode node2 = new CPPASTName();
+ IASTComment com1 = new Comment();
+ IASTComment com2 = new Comment();
+ IASTComment com3 = new Comment();
+
+
+ map.addCommentToNode(node1, com1);
+ map.addCommentToNode(node2, com2);
+ map.addCommentToNode(node1, com3);
+
+ assertEquals(2, map.getCommentsForNode(node1).size());
+ assertEquals(1, map.getCommentsForNode(node2).size());
+ assertEquals(com1, map.getCommentsForNode(node1).get(0));
+ assertEquals(com2, map.getCommentsForNode(node2).get(0));
+ assertEquals(com3, map.getCommentsForNode(node1).get(1));
+ }
+
+
+ //=== InternalComment class for testing
+ private class Comment extends ASTNode implements IASTComment{
+ private char[] comment;
+
+ public char[] getComment() {
+ return comment;
+ }
+ public void setComment(char[] comment) {
+ this.comment = comment;
+ }
+ //not used
+ public boolean isBlockComment() {return false;}
+ }
+}
diff --git a/core/org.eclipse.cdt.core.tests/resources/rewrite/ASTWriterCommentedDeclSpecTestSource.awts b/core/org.eclipse.cdt.core.tests/resources/rewrite/ASTWriterCommentedDeclSpecTestSource.awts
new file mode 100644
index 00000000000..9acaeb840f5
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/resources/rewrite/ASTWriterCommentedDeclSpecTestSource.awts
@@ -0,0 +1,222 @@
+//!Commented DeclSpecifierTest
+//%CPP
+//Test1
+inline int foo()
+{
+ return 1;
+}
+
+//Test2
+const int a = 1;
+//Test3
+volatile int b = 3;
+//Test4
+typedef int *intp;
+//Test5
+extern int b;
+//Test6
+static int c;
+//Test7
+int foo()
+{
+ auto int i = 1;
+ return i;
+}
+
+//Test8
+int bar()
+{
+ register int i = c;
+ return i;
+}
+
+
+//!Commented CompositeTypeSpecifier
+//%CPP
+//Test1
+struct B //Test1
+{
+ int c; //Test3
+ char b; //Test4
+ //Test5
+};
+//Test6
+union D //Test7
+{
+ int i; //Test8
+ int y; //Test9
+ //Test10
+};
+//Test11
+class E //Test12
+{
+ //Test13
+public:
+ int c; //Test14
+ //Test15
+};
+
+//!Commented ElaboratedTypeSpecifier 1
+//%CPP
+//Test1
+class A *A; //Test2
+//Test3
+enum Status{ good, bad}; //Test4
+//Test5
+enum Status stat; //Test6
+//Test7
+union D //Test8
+{
+ int i; //Test9
+ int y; //Test10
+ //Test11
+};
+//Test12
+union D d; //Test13
+
+//!Commented ElaboratedTypeSpecifier 2
+//%CPP
+enum Status{ good, bad};
+enum /*Test*/
+Status stat;
+
+//!Commented EnumeratioSpecifier
+//%CPP
+enum /*Test*/
+Status{ good, bad};
+
+//!NamedTypeSpecifier
+//%CPP
+typedef int INT;
+typedef INT (FOO)(INT);
+
+//!SimpleDeclSpecifier
+//%CPP
+signed short int i;
+unsigned long int y;
+float f;
+void x();
+char c;
+double d;
+
+//!Commented CPPCompositeTypeSpecifier 1
+//%CPP
+//TEST 1
+class TestClass //TEST 2
+{
+ //TEST 3
+}; //TEST 4
+
+//!Commented CPPCompositeTypeSpecifier 2
+//%CPP
+/*TEST 1*/
+class TestClass /*TEST 2*/
+{
+ /*TEST 3*/
+}; /*TEST 4*/
+
+//!Commented CPPCompositeTypeSpecifier 3
+//%CPP
+//TEST 1
+class TestClass2 //TEST 2
+ : public TestClass //TEST 3
+{
+ //TEST 4
+}; //TEST 5
+
+//!Commented CPPCompositeTypeSpecifier 4
+//%CPP
+/*TEST 1*/
+class TestClass2 /*TEST 2*/
+ : public TestClass
+{
+ /*TEST 3*/
+}; /*TEST 4*/
+
+//!Commented CPPCompositeTypeSpecifier 5
+//%CPP
+class TestClass2 /*TEST 1*/
+ : public TestClass
+{
+};
+
+//!Commented CPPCompositeTypeSpecifier 6
+//%CPP
+
+class TestClass2
+ : public TestClass /*TEST 1*/
+{
+};
+
+//=
+class TestClass2 : public TestClass /*TEST 1*/
+{
+};
+
+//!Commented CPPCompositeTypeSpecifier 7
+//%CPP
+class TestClass2 : public TestClass
+{ //TEST 1
+};
+
+//=
+class TestClass2 : public TestClass
+{
+ //TEST 1
+};
+
+//!Commented CPPCompositeTypeSpecifier 8
+//%CPP
+class TestClass2
+ : public TestClass
+{ /*TEST 1*/
+};
+
+//=
+class TestClass2 : public TestClass
+{
+ /*TEST 1*/
+};
+
+//!Commented CPPNamedTypeSpecifier 1
+//%CPP
+template<class T> class A
+{
+ //TEST 1
+ typedef char C; //TEST 2
+};
+
+//!Commented CPPNamedTypeSpecifier 2
+//%CPP
+template<class T> class A
+{
+ /*TEST 1*/
+ typedef char C; /*TEST 2*/
+};
+
+//!Commented SimpleDeclSpecifier 1
+//%CPP
+//TEST 1
+bool b; //TEST 2
+
+//!Commented SimpleDeclSpecifier 2
+//%CPP
+/*TEST 1*/
+wchar_t wc; /*TEST 2*/
+
+//!Commented DeclSpecifier in Definition
+//%CPP
+//comment a
+void tree(int a){ //comment b
+ a = 1; //comment c
+} //comment d
+
+//=
+//comment a
+void tree(int a)
+{
+ //comment b
+ a = 1; //comment c
+} //comment d
+
+
diff --git a/core/org.eclipse.cdt.core.tests/resources/rewrite/ASTWriterCommentedDeclarationTestSource.awts b/core/org.eclipse.cdt.core.tests/resources/rewrite/ASTWriterCommentedDeclarationTestSource.awts
new file mode 100644
index 00000000000..e814662df5b
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/resources/rewrite/ASTWriterCommentedDeclarationTestSource.awts
@@ -0,0 +1,168 @@
+//!Commented ASMDeclarationTest 1
+//%CPP
+//TEST 1
+asm("movl %1, %%eax;"); //TEST 2
+
+//!Commented ASMDeclarationTest 2
+//%CPP
+/*TEST 1*/
+asm("movl %1, %%eax;"); /*TEST 2*/
+
+//!Commented FunctionDefinitionTest 1
+//%CPP
+//TEST 1
+int foo()
+{
+ //inner comment
+ return 1;
+} //TEST 2
+
+
+//!Commented FunctionDefinitionTest 2
+//%CPP
+/*TEST 1*/
+int foo()
+{
+ //inner comment
+ return 1;
+} /*TEST 1*/
+
+
+//!Commented SimpleDeclarationTest 1
+//%CPP
+//TEST 1
+int i = 2, y = 3; //TEST 2
+//TEST 3
+int b = 0; //TEST 4
+
+//!Commented NamespaceAlias 1
+//%CPP
+//TEST 1
+namespace kurz = ziemlichlangernamespace; //TEST 2
+
+//!Commented NamespaceAlias 2
+//%CPP
+/*TEST 1*/
+namespace kurz = ziemlichlangernamespace; /*TEST 2*/
+
+//!Commented TemplateDeclaration 1
+//%CPP
+//TEST 1
+template<class T> class vector //TEST 2
+{
+ //TEST 3
+}; //TEST 4
+
+//!Commented TemplateDeclaration 2
+//%CPP
+/*TEST 1*/
+template<class T> class vector /*TEST 2*/
+{
+ /*TEST 3*/
+}; /*TEST 4*/
+
+//!Commented NestedTemplateDeclaration 1
+//%CPP
+//TEST 1
+template<template <class T> class K> class vector //TEST 2
+{
+ //TEST 3
+}; //TEST 4
+
+//!Commented NestedTemplateDeclaration 2
+//%CPP
+/*TEST 1*/
+template<template <class T> class K> class vector /*TEST 2*/
+{
+ /*TEST 3*/
+}; /*TEST 4*/
+
+//!Commented TemplateSpecialization 1
+//%CPP
+//TEST 1
+template<> class MyQueue<double> //TEST 2
+{
+ //TEST 3
+ std::vector<double> data;
+public:
+ void Add(const double& );
+ void Remove();
+ void Print();
+ //TEST 4
+}; //TEST 5
+
+//!Commented TemplateSpecialization 2
+//%CPP
+/*TEST 1*/
+template<> class MyQueue<double> /*TEST 2*/
+{
+ /*TEST 3*/
+ std::vector<double> data;
+public:
+ void Add(const double& );
+ void Remove();
+ void Print();
+ /*TEST 4*/
+}; /*TEST 5*/
+
+//!Commented UsingDeclaration 1
+//%CPP
+struct A
+{
+ void f();
+ enum E{ e};
+ union
+ {
+ int u;
+ };
+};
+struct B : A
+{
+ //TEST 1
+ using A::f; //TEST 2
+ /*TEST 3*/
+ using typename A::e; /*TEST 4*/
+ using A::u;
+ /*TEST 5*/
+};
+
+//!Commented UsingDirective 1
+//%CPP
+//TEST
+using namespace B; //TEST
+
+
+//!Commented VisibilityLabel 1
+//%CPP
+class A
+{
+ //TEST 1
+public: //TEST 2
+ int hallo();
+ /*TEST 3*/
+protected: /*TEST 4*/
+ int b, c;
+private:
+ int p;
+};
+
+//!Comment BeforeSimpleDeclaration 1
+//%CPP
+//TEST 1
+int i = 2; //TEST 2
+
+//!Comment BeforeSimpleDeclaration 2
+//%CPP
+/*TEST 1*/
+int i = 2; /*TEST 2*/
+
+//!Commented typename qualfier 1
+//%CPP
+//TEST 1
+typename T::A *a6; //TEST 2
+
+//!Commented typename qualfier 2
+//%CPP
+/*TEST 1*/
+typename T::A *a6; /*TEST 2*/
+
diff --git a/core/org.eclipse.cdt.core.tests/resources/rewrite/ASTWriterCommentedDeclaratorTestSource.awts b/core/org.eclipse.cdt.core.tests/resources/rewrite/ASTWriterCommentedDeclaratorTestSource.awts
new file mode 100644
index 00000000000..f436b1da354
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/resources/rewrite/ASTWriterCommentedDeclaratorTestSource.awts
@@ -0,0 +1,275 @@
+//!Commented DeclaratorTest 1
+//%CPP
+//TEST 1
+void foo()
+{
+ //TEST 2
+ struct B
+ {
+ int f();
+ };
+ int (B::* pb)() = &B::f;
+}
+
+
+//!Commented DeclaratorTest 2
+//%CPP
+/*TEST 1*/
+void foo()
+{
+ /*TEST 2*/
+ struct B
+ {
+ int f();
+ };
+ int (B::* pb)() = &B::f;
+}
+
+
+//!Commented CPPFunctionDeclaratorTest 1
+//%CPP
+char & operator [](unsigned int);
+//TEST 1
+TestClass::TestClass(int a) //TEST 2
+{
+ //TEST 3
+} //TEST 4
+
+
+//!Commented CPPFunctionDeclaratorTest 2
+//%CPP
+char & operator [](unsigned int);
+/*TEST 1*/
+TestClass::TestClass(int a) /*TEST 2*/
+{
+ /*TEST 3*/
+} /*TEST 4*/
+
+
+//!Commented CPPFunctionDeclaratorTest 3
+//%CPP
+char & operator [](unsigned int);
+//TEST 1
+TestClass::TestClass(int a)
+:alpha(a) //TEST 2
+{
+ //TEST 3
+} //TEST 4
+
+
+//!Commented CPPFunctionDeclaratorTest 4
+//%CPP
+char & operator [](unsigned int);
+/*TEST 1*/
+TestClass::TestClass(int a)
+:alpha(a) /*TEST 3*/
+{
+ /*TEST 4*/
+} /*TEST 5*/
+
+
+//!Commented ICPPASTFunctionTryBlockDeclarator1
+//%CPP
+void foo()
+{
+ int i = 1;
+ try {
+ i++;
+ }
+ catch(...){
+ }
+}
+
+
+//!Commented ICPPASTFunctionTryBlockDeclarator2
+//%CPP
+void foo()
+{
+ int i = 1;
+ //Test
+ try {
+ i++;
+ }
+ catch(...){
+ }
+}
+
+
+//!Commented ICPPASTFunctionTryBlockDeclarator3
+//%CPP
+void foo()
+{
+ int i = 1;
+ try {
+ //Test
+ i++;
+ }
+ catch(...){
+ }
+}
+
+
+//!Commented ICPPASTFunctionTryBlockDeclarator3b
+//%CPP
+void foo()
+{
+ int i = 1;
+ try //Test
+ {
+ i++;
+ }
+ catch(...){
+ }
+}
+
+
+//!Commented ICPPASTFunctionTryBlockDeclarator4
+//%CPP
+void foo()
+{
+ int i = 1;
+ try {
+ //Test
+ i++;
+ }
+ catch(...){
+ }
+}
+
+
+//!Commented ICPPASTFunctionTryBlockDeclarator5
+//%CPP
+void foo()
+{
+ int i = 1;
+ try {
+ i++; //Test
+ }
+ catch(...){
+ }
+}
+
+
+//!Commented ICPPASTFunctionTryBlockDeclarator6
+//%CPP
+void foo()
+{
+ int i = 1;
+ try {
+ i++;
+ //Test
+ }
+ catch(...){
+ }
+}
+
+
+//!Commented ICPPASTFunctionTryBlockDeclarator7
+//%CPP
+void foo()
+{
+ int i = 1;
+ try {
+ i++;
+ } //Test
+ catch(...){
+ }
+}
+
+
+//!Commented ICPPASTFunctionTryBlockDeclarator8
+//%CPP
+void foo()
+{
+ int i = 1;
+ try {
+ i++;
+ }
+ catch(...){
+ //Test
+ }
+}
+
+
+//!Commented ICPPASTFunctionTryBlockDeclarator9
+//%CPP
+void foo()
+{
+ int i = 1;
+ try {
+ i++;
+ }
+ catch(...){
+ //Test
+ }
+}
+
+
+//!Commented ICPPASTFunctionTryBlockDeclarator11
+//%CPP
+void foo()
+{
+ int i = 1;
+ try {
+ i++;
+ }
+ catch(...){
+ }
+ //Test
+}
+
+
+//!Commented ICPPASTFunctionTryBlockDeclarator12
+//%CPP
+void foo()
+{
+ int i = 1;
+ try {
+ i++;
+ }
+ catch(Overflow oo){
+ }
+ catch(Matherr mm){
+ }
+}
+
+
+//!Commented ICPPASTFunctionTryBlockDeclarator13
+//%CPP
+void foo()
+{
+ int i = 1;
+ try {
+ i++;
+ }
+ catch(Overflow oo){
+ }
+ catch(Matherr mm){
+ //Test
+ }
+}
+
+
+//!Commented ICPPASTFunctionTryBlockDeclarator 14
+//%CPP
+void foo()
+{
+ int f(int);
+ class C
+ {
+ int i;
+ double d;
+ public:
+ C(int, double);
+ };
+ C::C(int ii, double id)
+ try
+ :i(f(ii)), d(id)
+ {
+ }
+ catch(...){
+ }
+
+}
+
+
diff --git a/core/org.eclipse.cdt.core.tests/resources/rewrite/ASTWriterCommentedNameTestSource.awts b/core/org.eclipse.cdt.core.tests/resources/rewrite/ASTWriterCommentedNameTestSource.awts
new file mode 100644
index 00000000000..ecadde2f490
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/resources/rewrite/ASTWriterCommentedNameTestSource.awts
@@ -0,0 +1,86 @@
+//!Commented NameTest1
+//%CPP
+//Test
+Hallo;
+
+//!Commented NameTest2
+//%CPP
+Hallo; //Test
+
+//!Commented NameTest2
+//%CPP
+Hallo /*Test*/;
+
+//!Commented QualifiedName1
+//%CPP
+//TEST
+TestClass::Hallo;
+
+//!Commented QualifiedName1
+//%CPP
+TestClass::Hallo; //TEST
+
+//!Commented QualifiedName1
+//%CPP
+TestClass::Hallo /*Test*/;
+
+//!Commented OperatorName1
+//%CPP
+class Foo
+{
+public:
+ //Test
+ char & operator [](unsigned int);
+};
+
+//!Commented OperatorName2
+//%CPP
+class Foo
+{
+public:
+ char & operator [](unsigned int); //Test
+};
+
+//!Commented ConversionName1
+//%CPP
+class Foo
+{
+public:
+ //Test
+ operator int();
+};
+
+//!Commented ConversionName2
+//%CPP
+class Foo
+{
+public:
+ operator int(); //Test
+};
+
+//!Commented ConversionName3
+//%CPP
+class Foo
+{
+public:
+ operator int() /*Test*/;
+};
+
+//!Commented TemplateID1
+//%CPP
+//Test
+A::B<T> b;
+
+//!Commented TemplateID2
+//%CPP
+A::B<T> b; //Test
+
+//!Commented NestedTemplates1
+//%CPP
+//Test
+vector<vector<int> > vvi;
+
+//!Commented NestedTemplates2
+//%CPP
+vector<vector<int> > vvi; //Test
+
diff --git a/core/org.eclipse.cdt.core.tests/resources/rewrite/ASTWriterCommentedStatementTestSource.awts b/core/org.eclipse.cdt.core.tests/resources/rewrite/ASTWriterCommentedStatementTestSource.awts
new file mode 100644
index 00000000000..9a790cd0c9d
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/resources/rewrite/ASTWriterCommentedStatementTestSource.awts
@@ -0,0 +1,660 @@
+//!Commented BreakStatementTest 1
+//%CPP
+void foo()
+{
+ while(true){
+ //TEST 1
+ break; //TEST 2
+ }
+}
+
+
+//!Commented BreakStatementTest 2
+//%CPP
+void foo()
+{
+ while(true){
+ /*TEST 1*/
+ break; /*TEST 2*/
+ }
+}
+
+
+//!Commented CompoundStatementTest 1
+//%CPP
+void foo()
+{
+ int i = 2;
+ //TEST 1
+ {
+ //TEST 2
+ int a = i;
+ {
+ //TEST 3
+ a++;
+ //TEST 4
+ } //TEST 5
+ //TEST 6
+ } //TEST 7
+}
+
+
+//!Commented CompoundStatementTest 2
+//%CPP
+void foo()
+{
+ int i = 2;
+ /*TEST 1*/
+ {
+ /*TEST 2*/
+ int a = i;
+ {
+ /*TEST 3*/
+ a++;
+ /*TEST 4*/
+ } /*TEST 5*/
+ /*TEST 6*/
+ } /*TEST 7*/
+}
+
+
+//!Commented ContinueStatementTest 1
+//%CPP
+void foo()
+{
+ while(true){
+ //TEST 1
+ continue; //TEST 2
+ }
+}
+
+
+//!Commented ContinueStatementTest 2
+//%CPP
+void foo()
+{
+ while(true){
+ /*TEST 1*/
+ continue; /*TEST 2*/
+ }
+}
+
+
+//!Commented DeclarationStatementTest 1
+//%CPP
+void foo()
+{
+ //TEST 1
+ int i = 2; //TEST 2
+ //TEST 3
+ int a; //TEST 4
+ //TEST 5
+}
+
+
+//!Commented DeclarationStatementTest 2
+//%CPP
+void foo()
+{
+ /*TEST 1*/
+ int i = 2; /*TEST 2*/
+ /*TEST 3*/
+ int a; /*TEST 4*/
+ /*TEST 5*/
+}
+
+
+//!Commented DoStatementTest 1
+//%CPP
+void foo()
+{
+ //TEST 1
+ do{ //TEST 2
+ continue; //TEST 3
+ //TEST 4
+ } while(true); //TEST 5
+}
+
+
+//=
+void foo()
+{
+ //TEST 1
+ do{
+ //TEST 2
+ continue; //TEST 3
+ //TEST 4
+ } while(true); //TEST 5
+}
+
+
+//!Commented DoStatementTest 2
+//%CPP
+void foo()
+{
+ /*TEST 1*/
+ do{ /*TEST 2*/
+ continue; /*TEST 3*/
+ /*TEST 4*/
+ } while(true); /*TEST 5*/
+}
+
+
+//=
+void foo()
+{
+ /*TEST 1*/
+ do{
+ /*TEST 2*/
+ continue; /*TEST 3*/
+ /*TEST 4*/
+ } while(true); /*TEST 5*/
+}
+
+
+//!Commented DoStatementTest 3
+//%CPP
+void foo()
+{
+ do{
+ continue;
+ } while(true); /*TEST 1*/
+}
+
+
+//!Commented ExpressionsStatement1
+//%CPP
+void foo()
+{
+ bar1();
+ //TEST
+ bar2();
+}
+
+
+//!Commented ExpressionsStatement2
+//%CPP
+void foo()
+{
+ //TEST
+ bar1();
+ bar2();
+}
+
+
+//!Commented ExpressionsStatement3
+//%CPP
+void foo()
+{
+ bar1();
+ bar2();
+ //TEST
+}
+
+
+//!Commented ForStatementTest 1
+//%CPP
+void foo()
+{
+ //TEST 1
+ for(int i = 0;i < 1;++i){ //TEST 2
+ break; //TEST 3
+ } //TEST 4
+}
+
+
+//=
+void foo()
+{
+ //TEST 1
+ for(int i = 0;i < 1;++i){
+ //TEST 2
+ break; //TEST 3
+ } //TEST 4
+}
+
+
+//!Commented ForStatementTest 2
+//%CPP
+void foo()
+{
+ /*TEST 1*/
+ for(int i = 0;i < 1;++i){ /*TEST 2*/
+ break; /*TEST 3*/
+ } /*TEST 4*/
+}
+
+
+//=
+void foo()
+{
+ /*TEST 1*/
+ for(int i = 0;i < 1;++i){
+ /*TEST 2*/
+ break; /*TEST 3*/
+ } /*TEST 4*/
+}
+
+
+//!Commented ForStatementTest 3
+//%CPP
+void foo()
+{
+ for(int i = 0;i < 1;++i){
+ break;
+ } /*TEST 4*/
+}
+
+
+//!Commented GotoStatement1
+//%CPP
+void foo()
+{
+ start:
+ bar();
+ //TEST
+ goto start;
+}
+
+
+//!Commented GotoStatement2
+//%CPP
+void foo()
+{
+ start:
+ bar();
+ goto start; //TEST
+}
+
+
+//!Commented GotoStatement3
+//%CPP
+void foo()
+{
+ start:
+ bar();
+ goto /*TEST*/ start;
+}
+
+
+//=
+void foo()
+{
+ start:
+ bar();
+ goto /*TEST*/
+ start;
+}
+
+
+//!Commented GotoStatement4
+//%CPP
+void foo()
+{
+ start:
+ bar();
+ goto //TEST
+ start;
+}
+
+
+//!Commented GotoStatement5
+//%CPP
+void foo()
+{
+ start:
+ bar();
+ goto /*TEST*/
+ start;
+}
+
+
+//!Commented LabelStatement1
+//%CPP
+void foo()
+{
+ //Test
+ start:
+ bar();
+ goto start;
+}
+
+
+//!Commented LabelStatement2
+//%CPP
+void foo()
+{
+ start: //Test
+ bar();
+ goto start;
+}
+
+
+//=
+void foo()
+{
+ start:
+ //Test
+ bar();
+ goto start;
+}
+
+
+//!Commented LabelStatement3
+//%CPP
+void foo()
+{
+ start: /*Test*/
+ bar();
+ goto start;
+}
+
+
+//=
+void foo()
+{
+ start:
+ /*Test*/
+ bar();
+ goto start;
+}
+
+
+//!Commented LabelStatement4
+//%CPP
+void foo()
+{
+ start:
+ //Test
+ bar();
+ goto start;
+}
+
+
+//!Commented LabelStatement5
+//%CPP
+void foo()
+{
+ start:
+ bar(); //Test
+ goto start;
+}
+
+
+//!Commented IfStatementTest 1
+//%CPP
+int f()
+{
+ if(int c = f()){
+ c++;
+ } //TEST 1
+ return i;
+}
+
+
+//!Commented IfStatementTest 2
+//%CPP
+int f()
+{
+ int i = 0;
+ //TEST 1
+ if(i < 1){
+ //TEST 3
+ ++i;
+ //TEST 4
+ }else{
+ //TEST 5
+ --i;
+ //TEST 6
+ } //TEST 7
+ if(int c = f()){
+ c++;
+ } //TEST 8
+ return i;
+}
+
+
+//!Commented IfStatementTest 3
+//%CPP
+int f()
+{
+ int i = 0;
+ /*TEST 1*/
+ if(i < 1){
+ /*TEST 1*/
+ ++i;
+ /*TEST 1*/
+ }else{
+ /*TEST 1*/
+ --i;
+ /*TEST 1*/
+ } /*TEST 1*/
+ if(int c = f()){
+ c++;
+ } /*TEST 1*/
+ return i;
+}
+
+
+//!Commented IfStatementTest 4
+//%CPP
+int g()
+{
+ if(10 > 5) //TEST 1
+ return 1; //TEST 2
+
+ return 0;
+}
+
+//=
+int g()
+{
+ if(10 > 5)
+ //TEST 1
+ return 1; //TEST 2
+
+ return 0;
+}
+
+//!Commented IfStatementTest 5
+//%CPP
+int g()
+{
+ if(10 > 5) /*TEST 1*/
+ return 1; /*TEST 2*/
+
+ return 0;
+}
+
+//=
+int g()
+{
+ if(10 > 5)
+ /*TEST 1*/
+ return 1; /*TEST 2*/
+
+ return 0;
+}
+
+//!NullStatementTest
+//%CPP
+void f()
+{
+ ;
+}
+
+
+//!Commented ReturnStatement1
+//%CPP
+void foo()
+{
+ return; //Test
+}
+
+
+//!Commented ReturnStatement2
+//%CPP
+void foo()
+{
+ return 5; //Test
+}
+
+
+//!Commented ReturnStatement3
+//%CPP
+void foo()
+{
+ //Test
+ return 1 + 1;
+}
+
+
+//!Commented SwitchStatementTest 1
+//%CPP
+void foo()
+{
+ //TEST 1
+ switch (1){
+ //TEST 2
+ case 1: //TEST 3
+ return 1; //TEST 4
+ case 2:
+ return 2;
+ default: //TEST 5
+ return 3;
+ //TEST 6
+ } //TEST 7
+}
+
+
+//!Commented SwitchStatementTest 2
+//%CPP
+void foo()
+{
+ /*TEST 1*/
+ switch (1){ /*TEST 2*/
+ /*TEST 3*/
+ case 1: /*TEST 4*/
+ return 1; /*TEST 5*/
+ case 2:
+ return 2;
+ default: /*TEST 6*/
+ return 3;
+ /*TEST 7*/
+ } /*TEST 8*/
+}
+
+
+//=
+void foo()
+{
+ /*TEST 1*/
+ switch (1){
+ /*TEST 2*/
+ /*TEST 3*/
+ case 1: /*TEST 4*/
+ return 1; /*TEST 5*/
+ case 2:
+ return 2;
+ default: /*TEST 6*/
+ return 3;
+ /*TEST 7*/
+ } /*TEST 8*/
+}
+
+
+//!Commented SwitchStatementTest 3
+//%CPP
+void foo()
+{
+ switch (1){
+ case 1:
+ return 1;
+ case 2:
+ return 2;
+ default:
+ return 3;
+ } /*TEST 8*/
+}
+
+
+//!Commented WhileStatementTest 1
+//%CPP
+void foo()
+{
+ //TEST 1
+ while(true){ //TEST 2
+ //TEST 3
+ break; //TEST 4
+ //TEST 5
+ } //TEST 6
+}
+
+
+//=
+void foo()
+{
+ //TEST 1
+ while(true){
+ //TEST 2
+ //TEST 3
+ break; //TEST 4
+ //TEST 5
+ } //TEST 6
+}
+
+
+//!Commented WhileStatementTest 2
+//%CPP
+void foo()
+{
+ /*TEST 1*/
+ while(true){ /*TEST 2*/
+ /*TEST 3*/
+ break; /*TEST 4*/
+ /*TEST 5*/
+ } /*TEST 6*/
+}
+
+
+//=
+void foo()
+{
+ /*TEST 1*/
+ while(true){
+ /*TEST 2*/
+ /*TEST 3*/
+ break; /*TEST 4*/
+ /*TEST 5*/
+ } /*TEST 6*/
+}
+
+
+//!Commented WhileStatementTest 3
+//%CPP
+void foo()
+{
+ while(true){
+ break;
+ } /*TEST 6*/
+}
+
+
+//!TryBlockStatement
+//%CPP
+int foo()
+{
+ try {
+ int i = 1;
+ try {
+ ++i;
+ return i;
+ }
+ catch(...){
+ }
+ }
+ catch(...){
+ }
+}
+
+
diff --git a/core/org.eclipse.cdt.core.tests/resources/rewrite/ASTWriterCommentedTestSource.awts b/core/org.eclipse.cdt.core.tests/resources/rewrite/ASTWriterCommentedTestSource.awts
new file mode 100644
index 00000000000..24398066303
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/resources/rewrite/ASTWriterCommentedTestSource.awts
@@ -0,0 +1,1491 @@
+//!CommentRecognition000
+//%CPP
+class Klasse0
+{
+public:
+ Klasse1(); /*
+ * Comment
+ */
+ std::string toString();
+private:
+ int i;
+};
+
+//=
+class Klasse0
+{
+public:
+ Klasse1(); /*
+ * Comment
+ */
+ std::string toString();
+private:
+ int i;
+};
+
+//!CommentRecognition00
+//%CPP
+class Klasse0
+{
+public:
+ Klasse1(); //Comment
+ std::string toString();
+private:
+ int i;
+};
+
+//=
+class Klasse0
+{
+public:
+ Klasse1(); //Comment
+ std::string toString();
+private:
+ int i;
+};
+
+//!CommentRecognition0
+//%CPP
+//Comment1
+class Klasse0
+{
+ //Comment2
+public:
+ Klasse1();
+ std::string toString();
+private:
+ int i;
+};
+
+//!DeclarationWithTraillingDoubleComments
+//%CPP
+int foo = bar; //Comment
+//Zweiteilig
+
+//!DeclarationWithLeadingDoubleComments
+//%CPP
+//Comment
+//Zweiteilig
+int foo;
+
+//!DeclarationWithTraillingAndLeadingComments
+//%CPP
+//Comment1
+int foo = bar; //Comment2
+
+//!DeclarationWithTraillingAndLeadingComments
+//%CPP
+//Comment1
+int foo = bar; //Comment2
+
+//!DeclarationWithTraillingComments
+//%CPP
+int foo = bar; //Comment
+
+//!DeclarationWithTraillingComments
+//%CPP
+int foo; //Comment
+
+//!Method witch Trailercomment
+//%CPP
+int foo()
+{
+ return 42;
+ //return the Answer
+}
+
+
+//!Method witch Trailercomment2
+//%CPP
+int foo()
+{
+ return 42; //return the Answer
+}
+
+
+//!Method witch Trailercomment3
+//%CPP
+int foo()
+{
+ //return the Answer
+ return 42;
+}
+
+
+//!ClassCommentTest
+//%CPP
+class comment
+{
+ //hallo
+};
+
+//!Comment1 - von CERP
+//%CPP
+class test
+{
+public:
+ test();
+ /*
+ * Hallo
+ */
+ void lala();
+ //test
+ virtual ~test();
+protected:
+ class test2
+ {
+ public:
+ test2();
+ }; //Komment 1
+ //Komment 2
+ //Komment 3
+};
+
+//!Comment2 - von CERP
+//%CPP
+class test
+{
+public:
+ test();
+ /*
+ * Hallo
+ */
+ void lala();
+ //test
+ virtual ~test();
+protected:
+ class test2
+ {
+ public:
+ test2();
+ }; //Komment 1
+};
+//LALA
+
+//!Comment3 - von CERP
+//%CPP
+//Anfang
+class test
+{
+public:
+ test();
+ /*
+ * Hallo
+ */
+ void lala();
+ //test
+ virtual ~test();
+protected:
+ class test2
+ {
+ public:
+ test2();
+ }; //Komment 1
+};
+
+//!Comment4 - von CERP
+//%CPP
+class test
+{
+ //Klasse...
+public:
+ test();
+ /*
+ * Hallo
+ */
+ void lala();
+ //test
+ virtual ~test();
+protected:
+ class test2
+ {
+ public:
+ test2();
+ }; //Komment 1
+};
+
+//!CommentRecognition1 - von CERP
+//%CPP
+class Klasse1
+{
+ //TEST
+public:
+ Klasse1();
+ std::string toString();
+private:
+ int i;
+};
+
+//!CommentRecognition2 - von CERP
+//%CPP
+class Klasse1
+{
+public: //TEST
+ Klasse1();
+ std::string toString();
+private:
+ int i;
+};
+
+//!CommentRecognition3 - von CERP
+//%CPP
+class Klasse1
+{
+public:
+ //TEST
+ Klasse1();
+ std::string toString();
+private:
+ int i;
+};
+
+//!CommentRecognition4 - von CERP
+//%CPP
+class Klasse1
+{
+public:
+ Klasse1();
+ std::string toString();
+private:
+ int i;
+};
+
+//!CommentRecognition5 - von CERP
+//%CPP
+class Klasse1
+{ //TEST
+public:
+ Klasse1();
+ std::string toString();
+private:
+ int i;
+};
+
+//=
+class Klasse1
+{
+ //TEST
+public:
+ Klasse1();
+ std::string toString();
+private:
+ int i;
+};
+
+//!CommentRecognition6 - von CERP
+//%CPP
+class Klasse1{ //TEST
+public:
+ Klasse1();
+ std::string toString();
+private:
+ int i;
+};
+
+//=
+class Klasse1
+{
+ //TEST
+public:
+ Klasse1();
+ std::string toString();
+private:
+ int i;
+};
+
+//!CommentRecognition7 - von CERP
+//%CPP
+class Klasse1
+{//TEST
+public:
+ Klasse1();
+ std::string toString();
+private:
+ int i;
+};
+
+//=
+class Klasse1
+{
+ //TEST
+public:
+ Klasse1();
+ std::string toString();
+private:
+ int i;
+};
+
+//!CommentRecognition8 - von CERP
+//%CPP
+class Klasse1
+{
+public:
+ Klasse1();
+ std::string toString();
+private:
+ int i;
+ int i = 5; //lala
+};
+
+//!CommentRecognition9 - von CERP
+//%CPP
+class Klasse1
+{
+ /*TEST*/
+public:
+ Klasse1();
+ std::string toString();
+private:
+ int i;
+};
+
+//!CommentRecognition10 - von CERP
+//%CPP
+class Klasse1{ /*TEST*/
+public:
+ Klasse1();
+ std::string toString();
+private:
+ int i;
+};
+
+//=
+class Klasse1
+{
+ /*TEST*/
+public:
+ Klasse1();
+ std::string toString();
+private:
+ int i;
+};
+
+//!CommentRecognition11 - von CERP
+//%CPP
+class Klasse1
+{
+public: /*TEST*/
+ Klasse1();
+ std::string toString();
+private:
+ int i;
+};
+
+//!CommentRecognition11b - von CERP
+//%CPP
+class Klasse1
+{
+public: /*TEST*/ Klasse1();
+ std::string toString();
+private:
+ int i;
+};
+
+//=
+class Klasse1
+{
+public: /*TEST*/
+ Klasse1();
+ std::string toString();
+private:
+ int i;
+};
+
+//!CommentRecognition12 - von CERP
+//%CPP
+class Klasse1
+{
+public:
+ Klasse1();
+ std::string toString();
+private:
+ int i;
+ int i = 5; /*TEST*/
+};
+
+//!CommentRecognition13 - von CERP
+//%CPP
+class Klasse1
+{
+ /*
+ * TEST
+ */
+public:
+ Klasse1();
+ std::string toString();
+private:
+ int i;
+};
+
+//!CommentRecognition14 - von CERP
+//%CPP
+class Klasse1
+{
+public:
+ Klasse1();
+ std::string toString();
+private:
+ int i;
+ int i = 5; /*
+ * TEST
+ */
+};
+
+//!CommentRecognition15 - von CERP
+//%CPP
+class Klasse1
+{
+public: /*
+ * TEST
+ */
+ Klasse1();
+ std::string toString();
+private:
+ int i;
+};
+
+//!CommentRecognition16 - von CERP
+//%CPP
+class Klasse1{ //Test mit
+ //2 Zeilen
+public:
+ Klasse1();
+ std::string toString();
+private:
+ int i;
+};
+
+//=
+class Klasse1
+{
+ //Test mit
+ //2 Zeilen
+public:
+ Klasse1();
+ std::string toString();
+private:
+ int i;
+};
+
+//!CommentRecognition17 - von CERP
+//%CPP
+class Klasse1
+{
+public:
+ Klasse1();
+ std::string toString();
+private:
+ int i;
+ int i = 5; //Test mit
+ //2 Zeilen
+};
+
+//!CommentRecognition18 - von CERP
+//%CPP
+class Klasse1{
+ //Test mit
+ //2 Zeilen
+public:
+ Klasse1();
+ std::string toString();
+private:
+ int i;
+};
+
+//=
+class Klasse1
+{
+ //Test mit
+ //2 Zeilen
+public:
+ Klasse1();
+ std::string toString();
+private:
+ int i;
+};
+
+//!CommentRecognition19 - von CERP
+//%CPP
+class Klasse1
+{
+ //Test mit
+ //2 Zeilen
+public:
+ Klasse1();
+ std::string toString();
+private:
+ int i;
+};
+
+//!CommentRecognition20 - von CERP
+//%CPP
+class Klasse1
+{
+public:
+ Klasse1();
+ std::string toString();
+ inlineMethode()
+ {
+ int i = 0;
+ i++;
+ }
+
+private:
+ int i;
+};
+
+//!CommentRecognition21 - von CERP
+//%CPP
+class Klasse1
+{
+public:
+ Klasse1();
+ std::string toString();
+ inlineMethode()
+ {
+ int i = 0; //TEST
+ i++;
+ }
+
+ int i;
+};
+
+//!CommentRecognition22 - von CERP
+//%CPP
+class Klasse1
+{
+public:
+ Klasse1();
+ std::string toString();
+ inlineMethode()
+ {
+ int i = 0;
+ i++;
+ } //TEST
+
+private:
+ int i;
+};
+
+//!CommentRecognition23 - von CERP
+//%CPP
+class Klasse1
+{
+public:
+ Klasse1();
+ std::string toString();
+ //KommentarDavor
+ inlineMethode()
+ {
+ int i = 0;
+ i++;
+ } //TEST
+
+private:
+ int i;
+};
+
+//!CommentRecognition24 - von CERP
+//%CPP
+class Klasse1
+{
+public:
+ Klasse1();
+ std::string toString();
+ inlineMethode()
+ {
+ int i = 0;
+ i++;
+ }
+
+private:
+ int i;
+}; //SCHLUSS
+
+//!CommentRecognition25 - von CERP
+//%CPP
+class Klasse1
+{
+public:
+ Klasse1();
+ std::string toString();
+ inlineMethode()
+ {
+ int i = 0;
+ i++;
+ }
+
+private:
+ int i;
+}; //SCHLUSS
+//2. teil
+
+//!CommentRecognition26 - von CERP
+//%CPP
+class Klasse1
+{
+public:
+ Klasse1();
+ std::string toString();
+ inlineMethode()
+ {
+ int i = 0;
+ i++;
+ }
+
+private:
+ int i;
+};
+//SCHLUSS
+//2. teil
+
+//!CommentRecognition27 - von CERP
+//%CPP
+class Klasse1
+{
+public:
+ Klasse1();
+ std::string toString();
+ inlineMethode()
+ {
+ int i = 0;
+ i++;
+ }
+
+private:
+ int i;
+}; /*SCHLUSS*/
+
+//!CommentRecognition28 - von CERP
+//%CPP
+class Klasse1
+{
+public:
+ Klasse1();
+ std::string toString();
+ inlineMethode()
+ {
+ int i = 0;
+ i++;
+ }
+
+private:
+ int i;
+};
+/*SCHLUSS*/
+
+//!CommentRecognition29 - von CERP
+//%CPP
+class Klasse1
+{
+public:
+ Klasse1();
+ std::string toString();
+ inlineMethode()
+ {
+ int i = 0;
+ i++;
+ }
+
+private:
+ int i;
+}; /*
+ * SCHLUSS
+ */
+
+//!CommentRecognition30 - von CERP
+//%CPP
+class Klasse1
+{
+public:
+ Klasse1();
+ std::string toString();
+ //TEST
+ inlineMethode()
+ {
+ int i = 0;
+ i++;
+ }
+
+private:
+ int i;
+};
+
+//!CommentRecognition31 - von CERP
+//%CPP
+class Klasse1
+{
+public:
+ Klasse1();
+ std::string toString();
+ /*TEST*/
+ inlineMethode()
+ {
+ int i = 0;
+ i++;
+ }
+
+private:
+ int i;
+};
+
+//!CommentRecognition32 - von CERP
+//%CPP
+//Vorher
+class Klasse1 //Nachher
+{
+public:
+ Klasse1();
+ std::string toString();
+ inlineMethode()
+ {
+ int i = 0;
+ i++;
+ }
+
+private:
+ int i;
+};
+
+//!CommentRecognition33 - von CERP
+//%CPP
+//Vorher
+class Klasse1 /*Nachher*/
+{
+public:
+ Klasse1();
+ std::string toString();
+ inlineMethode()
+ {
+ int i = 0;
+ i++;
+ }
+
+private:
+ int i;
+};
+
+//!CommentRecognition34 - von CERP
+//%CPP
+/*Vorher*/
+class Klasse1
+{
+ /*Nachher*/
+public:
+ Klasse1();
+ std::string toString();
+ inlineMethode()
+ {
+ int i = 0;
+ i++;
+ }
+
+private:
+ int i;
+};
+
+//!CommentRecognition35 - von CERP
+//%CPP
+/*Vorher*/
+class Klasse1
+{
+ //Nachher
+public:
+ Klasse1();
+ std::string toString();
+ inlineMethode()
+ {
+ int i = 0;
+ i++;
+ }
+
+private:
+ int i;
+};
+
+//!CommentRecognition36 - von CERP
+//%CPP
+/*
+ * Vorher
+ */
+class Klasse1
+{
+ //Nachher
+public:
+ Klasse1();
+ std::string toString();
+ inlineMethode()
+ {
+ int i = 0;
+ i++;
+ }
+
+private:
+ int i;
+};
+
+//!CommentRecognition37 - von CERP
+//%CPP
+class Klasse1
+{
+public:
+ Klasse1();
+ std::string toString();
+ inlineMethode()
+ {
+ int i = 0;
+ i++;
+ }
+
+private:
+ int i; //Test
+};
+
+//!CommentRecognition38 - von CERP
+//%CPP
+class Klasse1
+{
+public:
+ Klasse1();
+ std::string toString();
+ inlineMethode()
+ {
+ int i = 0;
+ i++;
+ }
+
+private:
+ int i; /*Test*/
+};
+
+//!CommentRecognition39 - von CERP
+//%CPP
+class Klasse1
+{
+public:
+ Klasse1();
+ std::string toString();
+ inlineMethode()
+ {
+ int i = 0;
+ i++;
+ }
+
+private:
+ int i; /*
+ * Test
+ */
+};
+
+//!CommentRecognition40 - von CERP
+//%CPP
+class Klasse1
+{
+public:
+ Klasse1();
+ std::string toString();
+ inlineMethode()
+ {
+ int i = 0;
+ i++;
+ }
+
+private:
+ int i;
+ /*
+ * Test
+ */
+};
+
+//!CommentRecognition41 - von CERP
+//%CPP
+class Klasse1
+{
+public:
+ Klasse1();
+ std::string toString();
+ inlineMethode()
+ {
+ int i = 0;
+ i++;
+ }
+
+private:
+ //TEST
+ int i;
+};
+
+//!CommentRecognition42 - von CERP
+//%CPP
+class Klasse1
+{
+public:
+ Klasse1();
+ std::string toString();
+ inlineMethode()
+ {
+ int i = 0;
+ i++;
+ }
+
+private:
+ /*TEST*/
+ int i;
+};
+
+//!CommentRecognition43 - von CERP
+//%CPP
+class Klasse1
+{
+private:
+ int i;
+};
+
+//!CommentRecognition44 - von CERP
+//%CPP
+class Klasse1
+{
+private:
+ int i;
+ //TEST
+};
+
+//!CommentRecognition44b - von CERP
+//%CPP
+class Klasse1
+{
+private:
+ int i; //TEST
+};
+
+//!CommentRecognition44c - von CERP
+//%CPP
+class Klasse1
+{
+private:
+ int i;
+ //TEST
+}; //Add
+
+//!CommentRecognition44d - von CERP
+//%CPP
+class Klasse1
+{
+private:
+ int i;
+ //TEST
+} //Add
+;
+
+//!CommentRecognition45 - von CERP
+//%CPP
+class Klasse1
+{
+private:
+ //TEST
+ int i;
+};
+
+//!CommentRecognition46 - von CERP
+//%CPP
+class Klasse1
+{
+ //TEST
+private:
+ int i;
+};
+
+//!CommentRecognition47 - von CERP
+//%CPP
+class Klasse1
+{
+public:
+ Klasse1();
+ std::string toString();
+private: //TEST
+ int i;
+};
+
+//!CommentRecognition48 - von CERP
+//%CPP
+class Klasse1
+{
+ //TEST
+public: /*TEST*/
+ Klasse1();
+ std::string toString();
+private:
+ int i;
+};
+
+//!CommentRecognition48b - von CERP
+//%CPP
+class Klasse1
+{
+ //TEST
+public: /*TEST*/
+ Klasse1();
+ std::string toString();
+private:
+ int i;
+};
+
+//!CommentRecognition49 - von CERP
+//%CPP
+class Klasse1
+{
+public:
+ Klasse1(); //TEST1
+ //TEST2
+ std::string toString();
+private:
+ int i;
+};
+
+//!CommentRecognition50 - von CERP
+//%CPP
+class Klasse1
+{
+public:
+ Klasse1(); /*TEST1*/
+ /*TEST2*/
+ std::string toString();
+private:
+ int i;
+};
+
+//!CommentRecognition51 - von CERP
+//%CPP
+class Klasse1
+{
+public:
+ Klasse1(); //TEST1
+ /*TEST2*/
+ std::string toString();
+private:
+ int i;
+};
+
+//!CommentRecognition52 - von CERP
+//%CPP
+class Klasse1
+{
+public:
+ Klasse1(); /*TEST1*/
+ //TEST2
+ std::string toString();
+private:
+ int i;
+};
+
+//!CommentRecognition53 - von CERP
+//%CPP
+class Klasse1
+{
+public:
+ Klasse1(); /*TEST1*/
+ //TEST3
+ //TEST2
+ std::string toString();
+private:
+ int i;
+};
+
+//!CommentRecognition54 - von CERP
+//%CPP
+class Klasse1
+{
+public:
+ Klasse1(); /*TEST1*/
+ /*TEST3*/
+ //TEST2
+ std::string toString();
+private:
+ int i;
+};
+
+//!CommentRecognition55 - von CERP
+//%CPP
+class Klasse1
+{
+public:
+ Klasse1(); //TEST1
+ /*
+ * TEST3
+ */
+ std::string toString();
+private:
+ int i;
+};
+
+//!CommentRecognition56 - von CERP
+//%CPP
+class Klasse1
+{
+public:
+ Klasse1(); /*
+ * TEST1
+ */
+ //TEST2
+ std::string toString();
+private:
+ int i;
+};
+
+//!CommentRecognition57 - von CERP
+//%CPP
+namespace testNamespace
+{
+ class Klasse1
+ {
+ public:
+ Klasse1();
+ std::string toString();
+ private:
+ int i;
+ };
+}
+
+//!CommentRecognition58 - von CERP
+//%CPP
+//Kommentar
+namespace testNamespace
+{
+
+class Klasse1
+{
+public:
+ Klasse1();
+ std::string toString();
+private:
+ int i;
+};
+
+}
+
+//=
+//Kommentar
+namespace testNamespace
+{
+ class Klasse1
+ {
+ public:
+ Klasse1();
+ std::string toString();
+ private:
+ int i;
+ };
+}
+
+//!CommentRecognition59 - von CERP
+//%CPP
+namespace testNamespace //Kommentar
+{
+ class Klasse1
+ {
+ public:
+ Klasse1();
+ std::string toString();
+ private:
+ int i;
+ };
+}
+
+//!CommentRecognition60 - von CERP
+//%CPP
+/*Kommentar*/
+namespace testNamespace
+{
+ class Klasse1
+ {
+ public:
+ Klasse1();
+ std::string toString();
+ private:
+ int i;
+ };
+}
+
+//!CommentRecognition61 - von CERP
+//%CPP
+namespace testNamespace /*Kommentar*/
+{
+ class Klasse1
+ {
+ public:
+ Klasse1();
+ std::string toString();
+ private:
+ int i;
+ };
+}
+
+//!CommentRecognition62 - von CERP
+//%CPP
+/*
+ * Kommentar
+ */
+namespace testNamespace
+{
+ class Klasse1
+ {
+ public:
+ Klasse1();
+ std::string toString();
+ private:
+ int i;
+ };
+}
+
+//!CommentRecognition63 - von CERP
+//%CPP
+namespace testNamespace /*
+ * Kommentar
+ */
+{
+ class Klasse1
+ {
+ public:
+ Klasse1();
+ std::string toString();
+ private:
+ int i;
+ };
+}
+
+//!CommentRecognition64 - von CERP
+//%CPP
+namespace testNamespace
+{
+ class Klasse1
+ {
+ public:
+ Klasse1();
+ std::string toString();
+ private:
+ int i;
+ };
+} //Kommentar
+
+//!CommentRecognition65 - von CERP
+//%CPP
+namespace testNamespace
+{
+ class Klasse1
+ {
+ public:
+ Klasse1();
+ std::string toString();
+ private:
+ int i;
+ };
+} /*Kommentar*/
+
+//!CommentRecognition66 - von CERP
+//%CPP
+namespace testNamespace
+{
+ class Klasse1
+ {
+ public:
+ Klasse1();
+ std::string toString();
+ private:
+ int i;
+ };
+} /*
+ * Kommentar
+ */
+
+//!CommentRecognition67 - von CERP
+//%CPP
+namespace testNamespace
+{
+ class Klasse1 //TEST
+ {
+ public:
+ Klasse1();
+ std::string toString();
+ private:
+ int i;
+ };
+}
+
+//!CommentRecognition68 - von CERP
+//%CPP
+namespace testNamespace
+{
+ class Klasse1
+ {
+ public:
+ Klasse1();
+ std::string toString();
+ private:
+ int i; //TEST
+ };
+}
+
+//!CommentRecognition69 - von CERP
+//%CPP
+namespace testNamespace
+{
+ class Klasse1
+ {
+ public:
+ Klasse1();
+ std::string toString();
+ private:
+ int i;
+ }; //TEST
+}
+
+//!CommentRecognition100 - von CERP
+//%CPP
+struct Klasse1
+{
+public:
+ Klasse1();
+ std::string toString();
+private:
+ int i;
+};
+
+//!CommentRecognition101 - von CERP
+//%CPP
+//Kommentar
+struct Klasse1
+{
+public:
+ Klasse1();
+ std::string toString();
+private:
+ int i;
+};
+
+//!CommentRecognition102 - von CERP
+//%CPP
+struct Klasse1
+{
+ //Kommentar
+public:
+ Klasse1();
+ std::string toString();
+private:
+ int i;
+};
+
+//!CommentRecognition103 - von CERP
+//%CPP
+struct Klasse1
+{
+ //Kommentar
+private:
+ Klasse1();
+ std::string toString();
+protected:
+ int i;
+};
+
+//!CommentRecognition104 - von CERP
+//%CPP
+/*Davor*/
+struct Klasse1 //Kommentar
+{
+private:
+ Klasse1();
+ std::string toString();
+protected:
+ int i;
+};
+
+//!ImplementationFileCommentRecognition1 - von CERP
+//%CPP
+void Demo::methode1()
+{
+}
+
+void Demo::methode2()
+{
+}
+
+void Demo::methode3()
+{
+}
+
+
+//!ImplementationFileCommentRecognition2 - von CERP
+//%CPP
+//Zuvorderst
+
+
+void Demo::methode1()
+{
+ //Test
+}
+
+void Demo::methode2()
+{
+}
+//Davor
+
+void Demo::methode3()
+{
+} //Danach
+
+//Am Schluss
+//=
+//Zuvorderst
+void Demo::methode1()
+{
+ //Test
+}
+
+void Demo::methode2()
+{
+}
+
+//Davor
+void Demo::methode3()
+{
+} //Danach
+
+//Am Schluss
+
+//!ImplementationFileCommentRecognition3 - von CERP
+//%CPP
+/*Zuvorderst*/
+void Demo::methode1()
+{
+ /*Test*/
+}
+
+void Demo::methode2()
+{
+}
+
+/*Davor*/
+void Demo::methode3()
+{
+} /*Danach*/
+
+
+/*Am Schluss*/
+
+//=
+/*Zuvorderst*/
+void Demo::methode1()
+{
+ /*Test*/
+}
+
+void Demo::methode2()
+{
+}
+
+/*Davor*/
+void Demo::methode3()
+{
+} /*Danach*/
+
+/*Am Schluss*/
+
diff --git a/core/org.eclipse.cdt.core.tests/resources/rewrite/ASTWriterCommentedTestSource2.awts b/core/org.eclipse.cdt.core.tests/resources/rewrite/ASTWriterCommentedTestSource2.awts
new file mode 100644
index 00000000000..f74b82c2e8d
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/resources/rewrite/ASTWriterCommentedTestSource2.awts
@@ -0,0 +1,57 @@
+//!Commented TemplateFunction1
+//%CPP
+template<typename T> int tempFunct(T p)
+{
+ ++p;
+ //Kommentar
+ p + 4;
+ return 0;
+}
+
+
+//!Commented TemplateFunction2
+//%CPP
+//Kommentar
+template<typename T> int tempFunct(T p)
+{
+ ++p;
+ p + 4;
+ return 0;
+}
+
+
+//!Commented ExpressionList1
+//%CPP
+void foo()
+{
+ int i, j, k;
+ //Test
+ i = 1, j = 2, k = 3;
+}
+
+
+//!Commented ExpressionList2
+//%CPP
+void foo()
+{
+ int i, j, k;
+ i = 1, j = 2, k = 3; //Test
+}
+
+
+//!Commented ExpressionList3
+//%CPP
+void foo(){
+ int i, j, k;
+ i = 1, j = 2, k = 3; //Test
+}
+
+
+//=
+void foo()
+{
+ int i, j, k;
+ i = 1, j = 2, k = 3; //Test
+}
+
+
diff --git a/core/org.eclipse.cdt.core.tests/resources/rewrite/ASTWriterDeclSpecTestSource.awts b/core/org.eclipse.cdt.core.tests/resources/rewrite/ASTWriterDeclSpecTestSource.awts
new file mode 100644
index 00000000000..a2592ae218d
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/resources/rewrite/ASTWriterDeclSpecTestSource.awts
@@ -0,0 +1,164 @@
+//!DeclSpecifierTest
+//%CPP
+inline int foo()
+{
+ return 1;
+}
+
+const int a = 1;
+volatile int b = 3;
+typedef int *intp;
+extern int b;
+static int c;
+int foo()
+{
+ auto int i = 1;
+ return i;
+}
+
+int bar()
+{
+ register int i = c;
+ return i;
+}
+
+
+//!CompositeTypeSpecifier
+//%CPP
+struct B
+{
+ int c;
+ char b;
+};
+union D
+{
+ int i;
+ int y;
+};
+class E
+{
+public:
+ int c;
+};
+
+//!ElaboratedTypeSpecifier
+//%CPP
+class A *A;
+enum Status{ good, bad};
+enum Status stat;
+union D
+{
+ int i;
+ int y;
+};
+union D d;
+struct S *S;
+
+//!EnumeratioSpecifier
+//%CPP
+enum Status{ good = 0, bad};
+
+//!NamedTypeSpecifier
+//%CPP
+typedef int INT;
+typedef INT (FOO)(INT);
+
+//!SimpleDeclSpecifier
+//%CPP
+signed short int i;
+unsigned long int y;
+float f;
+void x();
+char c;
+double d;
+
+//!CDeclSpecifer
+//%C
+restrict int i = 1;
+
+//!CCompositeTypeSpecifier
+//%C
+restrict struct B
+{
+ int c;
+ char b;
+};
+restrict union D
+{
+ int i;
+ int y;
+};
+
+//!CElaboratedTypeSpecifier
+//%C
+enum Status{ good, bad};
+restrict enum Status stat;
+union D
+{
+ int i;
+ int y;
+};
+restrict union D d;
+
+//!CEnumeratioSpecifier
+//%C
+restrict enum Status{ good, bad};
+
+//!CSimpleDeclSpecifier
+//%C
+long long int lli;
+_Complex float cf;
+_Bool b;
+
+//!CPPCompositeTypeSpecifier
+//%CPP
+class TestClass
+{
+ explicit TestClass(int);
+ friend int AddToFriend(int x);
+};
+class A
+{
+};
+class TestClass2 : public TestClass, A
+{
+};
+
+//!protected Base Specifiers
+//%CPP
+class TestClass
+{
+ explicit TestClass(int);
+ friend int AddToFriend(int x);
+};
+class TestClass2 : protected TestClass
+{
+};
+
+//!private Base Specifiers
+//%CPP
+class TestClass
+{
+ explicit TestClass(int);
+ friend int AddToFriend(int x);
+};
+class TestClass2 : private TestClass
+{
+};
+
+//!CPPNamedTypeSpecifier
+//%CPP
+template<class T> class A
+{
+ typedef char C;
+};
+
+//!SimpleDeclSpecifier
+//%CPP
+bool b;
+wchar_t wc;
+
+//!ICPPSimpleDeclSpecifier mutable Bug 40
+//%CPP
+mutable int n;
+
diff --git a/core/org.eclipse.cdt.core.tests/resources/rewrite/ASTWriterDeclarationTestSource.awts b/core/org.eclipse.cdt.core.tests/resources/rewrite/ASTWriterDeclarationTestSource.awts
new file mode 100644
index 00000000000..a248d799c97
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/resources/rewrite/ASTWriterDeclarationTestSource.awts
@@ -0,0 +1,109 @@
+//!ASMDeclarationTest
+//%CPP
+asm("movl %1, %%eax;");
+
+//!FunctionDefinitionTest
+//%CPP
+int foo()
+{
+ return 1;
+}
+
+
+//!SimpleDeclarationTest
+//%CPP
+int i = 2, y = 3;
+int b = 0;
+
+//!ExplicitTemplateInstantion
+//%CPP
+template class vector<int>;
+
+//!GPPExplicitTemplateInstantion
+//%CPP GNU
+static template class vector<int>;
+inline template class vector<int>;
+inline template class vector<int>;
+
+//!LinkageSpecification
+//%CPP
+extern "C" typedef void FUNC();
+
+
+//!NamespaceAlias
+//%CPP
+namespace kurz = ziemlichlangernamespace;
+
+//!NamespaceDefinition
+//%CPP
+namespace ziemlichlangernamespace
+{
+}
+
+//!TemplateDeclaration
+//%CPP
+template<class T> class vector
+{
+};
+
+//!NestedTemplateDeclaration
+//%CPP
+template<template <class T> class K> class vector
+{
+};
+
+//!TemplateSpecialization
+//%CPP
+template<> class MyQueue<double>
+{
+ std::vector<double> data;
+public:
+ void Add(const double& );
+ void Remove();
+ void Print();
+};
+
+//!UsingDeclaration
+//%CPP
+struct A
+{
+ void f();
+ enum E{ e};
+ union
+ {
+ int u;
+ };
+};
+struct B : A
+{
+ using A::f;
+ using typename A::e;
+ using A::u;
+};
+
+//!UsingDirective
+//%CPP
+using namespace B;
+
+
+//!VisibilityLabel
+//%CPP
+class A
+{
+public:
+ int hallo();
+protected:
+ int b, c;
+private:
+ int p;
+};
+
+//!CommentBeforeSimpleDeclaration
+//%CPP
+//Comment
+int i = 2;
+
+//!typename qualfier
+//%CPP
+typename T::A *a6;
+
diff --git a/core/org.eclipse.cdt.core.tests/resources/rewrite/ASTWriterDeclaratorTestSource.awts b/core/org.eclipse.cdt.core.tests/resources/rewrite/ASTWriterDeclaratorTestSource.awts
new file mode 100644
index 00000000000..03757761d65
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/resources/rewrite/ASTWriterDeclaratorTestSource.awts
@@ -0,0 +1,93 @@
+//!DeclaratorTest
+//%CPP
+int sd;
+int *ip;
+int hs = 1;
+char & c;
+void foo()
+{
+ struct B
+ {
+ int f();
+ };
+ int (B::* pb)() = &B::f;
+}
+
+
+//!ArrayDeclaratorTest
+//%CPP
+int *pi[3];
+int (*p3i)[3];
+
+//!FieldDeclaratorTest
+//%CPP
+struct Bit
+{
+ int bit : 3;
+};
+
+//!CStandardFunctionDeclaratorTest
+//%C
+int foo();
+int bar(int a, int b);
+int fun(const char *a, ...);
+int fun3(int i, const char *a, ...);
+
+//!CPPStandardFunctionDeclaratorTest
+//%CPP
+int foo();
+int bar(int a, int b);
+int fun(const char *a, ...);
+int fun2(const char *a ...);
+int fun3(int i, const char *a, ...);
+//= ,... is synonymous with ...
+int foo();
+int bar(int a, int b);
+int fun(const char *a, ...);
+int fun2(const char *a, ...);
+int fun3(int i, const char *a, ...);
+
+//!CPPFunctionDeclaratorTest
+//%CPP
+char & operator [](unsigned int);
+TestClass::TestClass(int a)
+:alpha(a)
+{
+}
+
+void undefPar(const char *c) throw (int);
+virtual void pure() =0;
+int getV() const;
+int vol() volatile;
+
+//!ICPPASTFunctionTryBlockDeclarator
+//%CPP
+void foo()
+{
+ int f(int);
+ class C
+ {
+ int i;
+ double d;
+ public:
+ C(int, double);
+ };
+ C::C(int ii, double id)
+ try
+ :i(f(ii)), d(id)
+ {
+ }
+ catch(...){
+ }
+
+}
+
+
+//!CKnRFunctionDeclarator
+//%C GNU
+int foo(a, b)
+int b, a;
+{
+}
+
+
diff --git a/core/org.eclipse.cdt.core.tests/resources/rewrite/ASTWriterExpressionTestSource.awts b/core/org.eclipse.cdt.core.tests/resources/rewrite/ASTWriterExpressionTestSource.awts
new file mode 100644
index 00000000000..594bebbea6c
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/resources/rewrite/ASTWriterExpressionTestSource.awts
@@ -0,0 +1,185 @@
+//!CCastExpression
+//%C
+int i = (int)'A';
+
+//!CPPCastExpression
+//%CPP
+TestClass *i = dynamic_cast<TestClass*>(tc);
+TestClass *i = static_cast<TestClass*>(tc);
+TestClass *i = reinterpret_cast<TestClass*>(tc);
+TestClass *i = const_cast<TestClass*>(tc);
+
+//!ArraySubscrition
+//%C GNU
+int i = arr[0];
+int i = arr[y];
+
+//!CPPBinaryExpression
+//%CPP
+int i = 1 * x;
+int i = 1 / x;
+int i = 1 % x;
+int i = 1 + x;
+int i = 1 - x;
+int i = 1 << x;
+int i = 1 >> x;
+bool b = 1 < x;
+bool b = 1 > x;
+bool b = 1 <= x;
+bool b = 1 >= x;
+int i = 1 & x;
+int i = 1 ^ x;
+int i = 1 | x;
+bool b = 1 && x;
+bool b = 1 || x;
+int i = x;
+void foo()
+{
+ i *= x;
+}
+
+void foo()
+{
+ i /= x;
+}
+
+void foo()
+{
+ 1 %= x;
+}
+
+void foo()
+{
+ 1 += x;
+}
+
+void foo()
+{
+ 1 -= x;
+}
+
+void foo()
+{
+ 1 <<= x;
+}
+
+void foo()
+{
+ 1 >>= x;
+}
+
+void foo()
+{
+ 1 &= x;
+}
+
+void foo()
+{
+ 1 |= x;
+}
+
+bool b = 1 == x;
+bool b = 1 != x;
+int i = a.x;
+int i = a->x;
+
+//!BinaryExpression with MacroExpansions
+//%CPP
+#define ZWO 2
+int i = ZWO + 2;
+int i = 2 + ZWO;
+//= Preprocessor-Direkrive wird nur bei VP-Translationunits geschrieben
+int i = ZWO + 2;
+int i = 2 + ZWO;
+
+//!GPPBinaryExpression
+//%CPP GNU
+int i = 1 <? x;
+int i = 1 >? x;
+
+//!ConditionalExpression
+//%CPP
+int a = 1 < 2 ? 2 : 3;
+
+//!ExpressionList
+//%CPP
+int a = 1, b = 2, c = 3;
+
+//!FieldReference
+//%CPP
+int i = tc->a;
+int y = tc.getI();
+
+//!CPPFieldReference
+//%CPP
+int i = tc->template get_new<int>();
+int y = tc.template get_new<int>();
+
+//!FunctionCall
+//%CPP
+int a = tc.getI();
+
+//!IdExpression
+//%CPP
+int i = a;
+
+//!LiteralExpression
+//%CPP
+int i = 1;
+int i = 'a';
+string s = "abc";
+
+//!CPPLiteralExpression
+//%CPP
+TestClass *tc = this;
+bool b = true;
+bool b = false;
+
+//!UnaryExpression
+//%CPP
+int i = ++a;
+int i = --a;
+int i = +a;
+int i = -a;
+int *b = &a;
+int i = *b;
+int i = ~b;
+bool b = !false;
+int i = sizeof a;
+int i = a--;
+int i = a++;
+int i = (b);
+
+//!CPPUnaryExpression
+//%CPP
+void f()
+{
+ throw "Fehler";
+}
+
+type_info c = typeid (a);
+
+//!TypeIdExpression
+//%CPP
+int d = sizeof (int);
+
+//!CPPTypeIdExpression
+//%CPP
+type_info c = typeid (int);
+
+//!CPPDeleteExpression
+//%CPP
+void f()
+{
+ delete tc;
+}
+
+
+//!CPPNewExpression
+//%CPP
+TestClass *tc = new TestClass();
+
+//!CPPSimpleTypeConstructorExpression
+//%CPP
+int i = int(1);
+
diff --git a/core/org.eclipse.cdt.core.tests/resources/rewrite/ASTWriterInitializerTestSource.awts b/core/org.eclipse.cdt.core.tests/resources/rewrite/ASTWriterInitializerTestSource.awts
new file mode 100644
index 00000000000..b2e76419ffe
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/resources/rewrite/ASTWriterInitializerTestSource.awts
@@ -0,0 +1,37 @@
+//!InitializerExpressionTest
+//%CPP
+int i = 0;
+
+//!InitializerListTest
+//%CPP
+struct A
+{
+ int x;
+ struct B
+ {
+ int i;
+ int j;
+ } b;
+} abs = {1, {2, 3}};
+
+//!DesignatedInitializer
+//%C
+typedef struct
+{
+ int x;
+ int y;
+} Coord;
+Coord xy = {.y = 10, .x = 11};
+
+//!CPPConstructorInitializer
+//%CPP
+int i(3);
+
+//!CArrayDesignator
+//%C
+struct ABC
+{
+ int def[10];
+};
+struct ABC instance = {.def[0] = 9};
+
diff --git a/core/org.eclipse.cdt.core.tests/resources/rewrite/ASTWriterNameTestSource.awts b/core/org.eclipse.cdt.core.tests/resources/rewrite/ASTWriterNameTestSource.awts
new file mode 100644
index 00000000000..76d756e5b7e
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/resources/rewrite/ASTWriterNameTestSource.awts
@@ -0,0 +1,32 @@
+//!NameTest
+//%CPP
+Hallo;
+
+//!QualifiedName
+//%CPP
+TestClass::Hallo;
+
+//!OperatorName
+//%CPP
+class Foo
+{
+public:
+ char & operator [](unsigned int);
+};
+
+//!ConversionName
+//%CPP
+class Foo
+{
+public:
+ operator int();
+};
+
+//!TemplateID
+//%CPP
+A::B<T> b;
+
+//!NestedTemplates
+//%CPP
+vector<vector<int> > vvi;
+
diff --git a/core/org.eclipse.cdt.core.tests/resources/rewrite/ASTWriterPreprocessorTestSource.awts b/core/org.eclipse.cdt.core.tests/resources/rewrite/ASTWriterPreprocessorTestSource.awts
new file mode 100644
index 00000000000..db0cc21aa9d
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/resources/rewrite/ASTWriterPreprocessorTestSource.awts
@@ -0,0 +1,94 @@
+//!DefineObjectStyleMacroWithoutExpansion
+//%CPP
+#define LIFE_THE_UNIVERSE_AND_EVERYTHING
+
+//!DefineObjectStyleMacroWithExpansion
+//%CPP
+#define FOO int i = 1;
+
+//!DefineFunctionStyleMacro
+//%CPP
+#define BAR(a, b) a + b
+
+//!IfElfElseEndif
+//%CPP
+#if 1
+int a;
+#elif 0
+int b;
+#else
+int c;
+#endif
+
+
+//!Ifdef
+//%CPP
+#ifdef LIFE_THE_UNIVERS_AND_EVERYTHING
+#endif
+
+
+//!Ifndef
+//%CPP
+#ifndef LIFE_THE_UNIVERS_AND_EVERYTHING
+#define LIFE_THE_UNIVERS_AND_EVERYTHING
+#endif
+
+
+//!Undef
+//%CPP
+#define FOO
+#undef FOO
+
+//!Pragma
+//%CPP
+#pragma GCC poison printf sprintf fprintf
+
+//!Error
+//%CPP
+#error fehler
+
+//!ObjectMacroExpansion
+//%CPP
+#define FOO 3
+int main()
+{
+ int i = FOO;
+ return i;
+}
+
+
+//!DefineFunctionStyleMacro
+//%CPP
+#define BAR(a, b) a + b
+int i = BAR(1, 2);
+
+//!MacroExpansio2ExpansionsBug
+//%CPP
+#define HALLO(a, b) a + b
+int main()
+{
+ int i = HALLO(45, 2) + HALLO(1, 2);
+ return HALLO(i, i);
+}
+
+
+//!MacroExpansio3ExpansionsBug
+//%CPP
+#define HALLO(a, b) a + b
+int main()
+{
+ int i = HALLO(45, 2) + HALLO(1, 2) + HALLO(1, 2);
+ return HALLO(i, i);
+}
+
+
+//!MacroExpansio4ExpansionsBug
+//%CPP
+#define HALLO(a, b) a + b
+int main()
+{
+ int i = HALLO(45, 2) + HALLO(1, 2) + HALLO(1, 2) + HALLO(1, 2);
+ return HALLO(i, i);
+}
+
+
diff --git a/core/org.eclipse.cdt.core.tests/resources/rewrite/ASTWriterStatementTestSource.awts b/core/org.eclipse.cdt.core.tests/resources/rewrite/ASTWriterStatementTestSource.awts
new file mode 100644
index 00000000000..340a14144b7
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/resources/rewrite/ASTWriterStatementTestSource.awts
@@ -0,0 +1,283 @@
+//!BreakStatementTest
+//%CPP
+void foo()
+{
+ while(true){
+ break;
+ }
+}
+
+
+//!CaseDefaultStatementTest
+//%CPP
+foo()
+{
+ switch (1){
+ case 1:
+ return 1;
+ case 2:
+ return 2;
+ default:
+ return 3;
+ }
+}
+
+
+//!CompoundStatementTest
+//%CPP
+void foo()
+{
+ int i = 2;
+ {
+ int a = i;
+ {
+ a++;
+ }
+ }
+}
+
+
+//!ContinueStatementTest
+//%CPP
+void foo()
+{
+ while(true){
+ continue;
+ }
+}
+
+
+//!DeclarationStatementTest
+//%CPP
+void foo()
+{
+ int i = 2;
+ int a;
+}
+
+
+//!DoStatementTest
+//%CPP
+void foo()
+{
+ do{
+ continue;
+ } while(true);
+}
+
+
+//!ExpressionStatementTest
+//%CPP
+void foo()
+{
+ int i;
+ ++i;
+}
+
+
+//!ForStatementTest
+//%CPP
+void foo()
+{
+ for(int i = 0;i < 1;++i){
+ break;
+ }
+ for(;;){
+ break;
+ }
+ for(;int c = f();){
+ c++;
+ }
+}
+
+
+//!C ForStatement
+//%C
+void foo()
+{
+ int i;
+ for(i = 0;i < 1;++i){
+ }
+}
+
+
+//!Goto&LabelStatementTest
+//%CPP
+int f()
+{
+ badStyle:
+ goto badStyle;
+}
+
+
+//!IfStatementTest
+//%CPP
+int f()
+{
+ int i = 0;
+ if(i < 1){
+ ++i;
+ }else{
+ --i;
+ }
+ if(int c = f()){
+ c++;
+ }
+ return i;
+}
+
+
+//!IfStatementTest
+//%CPP
+int g()
+{
+ if(10 > 5)
+ return 1;
+
+ return 0;
+}
+
+//!C IfStatementTest
+//%C
+int g()
+{
+ if(10 > 5)
+ return 1;
+
+ return 0;
+}
+
+//!NullStatementTest
+//%CPP
+void f()
+{
+ ;
+}
+
+
+//!ReturnStatementTest
+//%CPP
+int f()
+{
+ return 1;
+}
+
+
+//!SwitchStatementTest
+//%CPP
+void foo()
+{
+ switch (1){
+ case 1:
+ return 1;
+ case 2:
+ return 2;
+ default:
+ return 3;
+ }
+}
+
+int foo()
+{
+ switch (int i = f()){
+ case 1:
+ ++i;
+ return 1;
+ case 2:
+ return 2;
+ default:
+ return 3;
+ }
+}
+
+
+//!SwitchStatementTest
+//%C
+void foo()
+{
+ switch (1){
+ case 1:
+ return 1;
+ case 2:
+ return 2;
+ default:
+ return 3;
+ }
+}
+
+
+//!WhileStatementTest
+//%CPP
+void foo()
+{
+ while(true){
+ break;
+ }
+}
+
+void fa()
+{
+ while(int i = f()){
+ ++i;
+ break;
+ }
+}
+
+void fb()
+{
+ while(true);
+
+}
+
+//!C WhileStatementTest
+//%C
+void foo()
+{
+ while(true){
+ break;
+ }
+}
+
+
+//!TryBlockStatement
+//%CPP
+int foo()
+{
+ try {
+ int i = 1;
+ try {
+ ++i;
+ return i;
+ }
+ catch(...){
+ }
+ }
+ catch(...){
+ }
+}
+
+
+//!MixedStatement
+//%CPP
+#define ZWO 2
+int foo()
+{
+ int i = 1;
+ if( i == ZWO)
+ {
+ }
+}
+//=
+int foo()
+{
+ int i = 1;
+ if( i == ZWO)
+ {
+ }
+}
+
+
+//!ArrayDeclarationStatementTest
+//%CPP
+string *newElements = new string[m_capacity];
+
diff --git a/core/org.eclipse.cdt.core.tests/resources/rewrite/ASTWriterTemplateTestSource.awts b/core/org.eclipse.cdt.core.tests/resources/rewrite/ASTWriterTemplateTestSource.awts
new file mode 100644
index 00000000000..c11a70ff3ce
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/resources/rewrite/ASTWriterTemplateTestSource.awts
@@ -0,0 +1,12 @@
+//![temp.names] examples abschnitt 4/1
+//%CPP
+T *p1 = p->template alloc<100>();
+
+//![temp.names] examples abschnitt 4/2, didn't work cause of Bug# 164482
+//%CPP
+template<class T> void f(T *p)
+{
+ T::template adjust<100>();
+}
+
+
diff --git a/core/org.eclipse.cdt.core.tests/resources/rewrite/CommentHandlingTestSource.rts b/core/org.eclipse.cdt.core.tests/resources/rewrite/CommentHandlingTestSource.rts
new file mode 100644
index 00000000000..ddb079255d3
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/resources/rewrite/CommentHandlingTestSource.rts
@@ -0,0 +1,2886 @@
+//!CommentRecognition209 - von ASTWriter GPPExplicitTemplateInstantitation
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse1.h
+//TEST 1
+static template class vector<int>; //TEST 2
+//TEST 3
+inline template class vector<int>; //TEST 4
+//TEST 5
+inline template class vector<int>; //TEST 6
+
+//=
+=>leading
+static template class vector<int>; = //TEST 1
+inline template class vector<int>; = //TEST 3
+inline template class vector<int>; = //TEST 5
+
+=>trailing
+static template class vector<int>; = //TEST 2
+inline template class vector<int>; = //TEST 4
+inline template class vector<int>; = //TEST 6
+
+=>freestanding
+
+//!CommentRecognition210 - von ASTWriter LinkageSpecification
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse1.h
+//TEST 1
+extern "C" typedef void FUNC(); //TEST 2
+
+//=
+=>leading
+extern "C" typedef void FUNC(); = //TEST 1
+
+=>trailing
+extern "C" typedef void FUNC(); = //TEST 2
+
+=>freestanding
+
+//!CommentRecognition212 - von ASTWriter TemplateFunction
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse1.h
+template<typename T> int tempFunct(T p)
+{
+ ++p;
+ p + 4;
+ return 0;
+} //Kommentar
+
+//=
+=>leading
+
+=>trailing
+template<typename T> int tempFunct(T p)
+{
+ ++p;
+ p + 4;
+ return 0;
+} = //Kommentar
+
+=>freestanding
+
+//!CommentRecognition213 - von ASTWriter DeclarationWithTraillingDoubleComments
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse1.h
+int foo = bar; //Comment
+ //Zweiteilig
+//=
+=>leading
+
+=>trailing
+int foo = bar; = //Comment
+
+=>freestanding
+int foo = bar; = //Zweiteilig
+
+//!CommentHandlingTest 1 - von CERP
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@test.h
+class test
+{
+public:
+ test();
+ /*
+ * Hallo
+ */
+ void lala();
+ //test
+ virtual ~test();
+protected:
+ class test2
+ {
+ public:
+ test2();
+ }; //Komment 1
+ //Komment 2
+ //Komment 3
+};
+
+//=
+=>leading
+void lala(); = /*
+ * Hallo
+ */
+virtual ~test(); = //test
+
+=>trailing
+class test2
+ {
+ public:
+ test2();
+ }; = //Komment 1
+
+=>freestanding
+test = //Komment 2 , //Komment 3
+
+//!CommentHandlingTest 2 - von CERP
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@test.h
+class test
+{
+public:
+ virtual ~test();
+ test();
+ void lala();
+protected:
+ class test2
+ {
+ public:
+ test2();
+ };
+};
+//LALA
+
+//=
+=>leading
+
+=>trailing
+
+=>freestanding
+class test
+{
+public:
+ virtual ~test();
+ test();
+ void lala();
+protected:
+ class test2
+ {
+ public:
+ test2();
+ };
+}; = //LALA
+
+//!CommentHandlingTest 3 - von CERP
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@test.h
+//Anfang
+class test
+{
+public:
+ test();
+ void lala();
+ virtual ~test();
+protected:
+ class test2
+ {
+ public:
+ test2();
+ };
+};
+
+//=
+=>leading
+class test
+{
+public:
+ test();
+ void lala();
+ virtual ~test();
+protected:
+ class test2
+ {
+ public:
+ test2();
+ };
+}; = //Anfang
+
+=>trailing
+
+=>freestanding
+
+//!CommentHandlingTest 4 - von CERP
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@test.h
+class test
+{
+ //Klasse...
+public:
+ test();
+ void lala();
+ virtual ~test();
+protected:
+ class test2
+ {
+ public:
+ test2();
+ };
+};
+
+//=
+=>leading
+public: = //Klasse...
+
+=>trailing
+
+=>freestanding
+
+//!CommentRecognition00
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse0.h
+class Klasse0
+{
+public:
+ Klasse1(); //Comment
+ std::string toString();
+private:
+ int i;
+};
+
+//=
+=>leading
+
+=>trailing
+Klasse1(); = //Comment
+
+=>freestanding
+
+//!CommentRecognition0
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse0.h
+//Comment1
+class Klasse0
+{
+ //Comment2
+public:
+ Klasse1();
+ std::string toString();
+private:
+ int i;
+};
+
+//=
+=>leading
+class Klasse0
+{
+ //Comment2
+public:
+ Klasse1();
+ std::string toString();
+private:
+ int i;
+}; = //Comment1
+public: = //Comment2
+
+=>trailing
+
+=>freestanding
+
+//!DeclarationWithTraillingDoubleComments
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse0.h
+int foo = bar; //Comment
+ //Zweiteilig
+
+//=
+=>leading
+
+=>trailing
+int foo = bar; = //Comment
+
+=>freestanding
+int foo = bar; = //Zweiteilig
+
+//!DeclarationWithLeadingDoubleComments
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse0.h
+//Comment
+//Zweiteilig
+int foo;
+
+//=
+=>leading
+int foo; = //Comment , //Zweiteilig
+
+=>trailing
+
+=>freestanding
+
+//!DeclarationWithTraillingAndLeadingComments
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse0.h
+//Comment1
+int foo = bar; //Comment2
+
+//=
+=>leading
+int foo = bar; = //Comment1
+
+=>trailing
+int foo = bar; = //Comment2
+
+=>freestanding
+
+//!DeclarationWithTraillingComments
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse0.h
+int foo = bar; //Comment
+
+//=
+=>leading
+
+=>trailing
+int foo = bar; = //Comment
+
+=>freestanding
+
+//!DeclarationWithTraillingComments
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse0.h
+int foo; //Comment
+
+//=
+=>leading
+
+=>trailing
+int foo; = //Comment
+
+=>freestanding
+
+//!Method with Trailercomment
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse0.h
+int foo ()
+{
+ return 42;
+ //return the Answer
+}
+
+//=
+=>leading
+
+=>trailing
+
+=>freestanding
+{
+ return 42;
+ //return the Answer
+} = //return the Answer
+
+//!Method with Trailercomment2
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse0.h
+int foo()
+{
+ return 42; //return the Answer
+}
+
+//=
+=>leading
+
+=>trailing
+return 42; = //return the Answer
+
+=>freestanding
+
+//!Method with Trailercomment3
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse0.h
+int foo()
+{
+ //return the Answer
+ return 42;
+}
+
+//=
+=>leading
+return 42; = //return the Answer
+
+=>trailing
+
+=>freestanding
+
+//!ClassCommentTest
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse0.h
+class comment
+{
+ //hallo
+};
+
+//=
+=>leading
+
+=>trailing
+
+=>freestanding
+comment = //hallo
+
+//!CommentRecognition1 - von CERP
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse1.h
+class Klasse1
+{
+ //TEST
+public:
+ Klasse1();
+ std::string toString();
+private:
+ int i;
+};
+
+//=
+=>leading
+public: = //TEST
+
+=>trailing
+
+=>freestanding
+
+//!CommentRecognition2 - von CERP
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse1.h
+class Klasse1
+{
+public: //TEST
+ Klasse1();
+ std::string toString();
+private:
+ int i;
+};
+
+//=
+=>leading
+
+=>trailing
+public: = //TEST
+
+=>freestanding
+
+//!CommentRecognition3 - von CERP
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse1.h
+class Klasse1
+{
+public:
+ //TEST
+ Klasse1();
+ std::string toString();
+private:
+ int i;
+};
+
+//=
+=>leading
+Klasse1(); = //TEST
+
+=>trailing
+
+=>freestanding
+
+//!CommentRecognition4 - von CERP
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse1.h
+class Klasse1
+{
+public:
+ Klasse1();
+ std::string toString();
+private:
+ int i;
+};
+
+//=
+=>leading
+
+=>trailing
+
+=>freestanding
+
+//!CommentRecognition5 - von CERP
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse1.h
+class Klasse1
+{ //TEST
+public:
+ Klasse1();
+ std::string toString();
+private:
+ int i;
+};
+
+//=
+=>leading
+public: = //TEST
+
+=>trailing
+
+=>freestanding
+
+//!CommentRecognition6 - von CERP
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse1.h
+class Klasse1{ //TEST
+public:
+ Klasse1();
+ std::string toString();
+private:
+ int i;
+};
+
+//=
+=>leading
+public: = //TEST
+
+=>trailing
+
+=>freestanding
+
+//!CommentRecognition7 - von CERP
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse1.h
+class Klasse1
+{//TEST
+public:
+ Klasse1();
+ std::string toString();
+private:
+ int i;
+};
+
+//=
+=>leading
+public: = //TEST
+
+=>trailing
+
+=>freestanding
+
+//!CommentRecognition8 - von CERP
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse1.h
+class Klasse1
+{
+public:
+ Klasse1();
+ std::string toString();
+private:
+ int i;
+ int i = 5; //lala
+};
+
+//=
+=>leading
+
+=>trailing
+int i = 5; = //lala
+
+=>freestanding
+
+//!CommentRecognition9 - von CERP
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse1.h
+class Klasse1
+{
+ /*TEST*/
+public:
+ Klasse1();
+ std::string toString();
+private:
+ int i;
+};
+
+//=
+=>leading
+public: = /*TEST*/
+
+=>trailing
+
+=>freestanding
+
+//!CommentRecognition10 - von CERP
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse1.h
+class Klasse1{ /*TEST*/
+public:
+ Klasse1();
+ std::string toString();
+private:
+ int i;
+};
+
+//=
+=>leading
+public: = /*TEST*/
+
+=>trailing
+
+=>freestanding
+
+//!CommentRecognition11 - von CERP
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse1.h
+class Klasse1
+{
+public: /*TEST*/
+ Klasse1();
+ std::string toString();
+private:
+ int i;
+};
+
+//=
+=>leading
+
+=>trailing
+public: = /*TEST*/
+
+=>freestanding
+
+//!CommentRecognition11b - von CERP
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse1.h
+class Klasse1
+{
+public: /*TEST*/ Klasse1();
+ std::string toString();
+private:
+ int i;
+};
+
+//=
+=>leading
+
+=>trailing
+public: = /*TEST*/
+
+=>freestanding
+
+//!CommentRecognition12 - von CERP
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse1.h
+class Klasse1
+{
+public:
+ Klasse1();
+ std::string toString();
+private:
+ int i;
+ int i = 5; /*TEST*/
+};
+
+//=
+=>leading
+
+=>trailing
+int i = 5; = /*TEST*/
+
+=>freestanding
+
+//!CommentRecognition13 - von CERP
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse1.h
+class Klasse1
+{
+ /*
+ * TEST
+ */
+public:
+ Klasse1();
+ std::string toString();
+private:
+ int i;
+};
+
+//=
+=>leading
+public: = /*
+ * TEST
+ */
+
+=>trailing
+
+=>freestanding
+
+//!CommentRecognition14 - von CERP
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse1.h
+class Klasse1
+{
+public:
+ Klasse1();
+ std::string toString();
+private:
+ int i;
+ int i = 5; /*
+ * TEST
+ */
+};
+
+//=
+=>leading
+
+=>trailing
+int i = 5; = /*
+ * TEST
+ */
+
+=>freestanding
+
+//!CommentRecognition15 - von CERP
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse1.h
+class Klasse1
+{
+public: /*
+ * TEST
+ */
+ Klasse1();
+ std::string toString();
+private:
+ int i;
+};
+
+//=
+=>leading
+
+=>trailing
+public: = /*
+ * TEST
+ */
+
+=>freestanding
+
+//!CommentRecognition16 - von CERP
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse1.h
+class Klasse1{ //Test mit
+ //2 Zeilen
+public:
+ Klasse1();
+ std::string toString();
+private:
+ int i;
+};
+
+//=
+=>leading
+public: = //Test mit , //2 Zeilen
+
+=>trailing
+
+=>freestanding
+
+//!CommentRecognition17 - von CERP
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse1.h
+class Klasse1
+{
+public:
+ Klasse1();
+ std::string toString();
+private:
+ int i;
+ int i = 5; //Test mit
+ //2 Zeilen
+};
+
+//=
+=>leading
+
+=>trailing
+int i = 5; = //Test mit
+
+=>freestanding
+Klasse1 = //2 Zeilen
+
+//!CommentRecognition18 - von CERP
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse1.h
+class Klasse1{
+ //Test mit
+ //2 Zeilen
+public:
+ Klasse1();
+ std::string toString();
+private:
+ int i;
+};
+
+//=
+=>leading
+public: = //Test mit , //2 Zeilen
+
+=>trailing
+
+=>freestanding
+
+//!CommentRecognition19 - von CERP
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse1.h
+class Klasse1
+{
+ //Test mit
+ //2 Zeilen
+public:
+ Klasse1();
+ std::string toString();
+private:
+ int i;
+};
+
+//=
+=>leading
+public: = //Test mit , //2 Zeilen
+
+=>trailing
+
+=>freestanding
+
+//!CommentRecognition20 - von CERP
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse1.h
+class Klasse1
+{
+public:
+ Klasse1();
+ std::string toString();
+ inlineMethode()
+ {
+ int i = 0;
+ i++;
+ }
+
+private:
+ int i;
+};
+
+//=
+=>leading
+
+=>trailing
+
+=>freestanding
+
+//!CommentRecognition21 - von CERP
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse1.h
+class Klasse1
+{
+public:
+ Klasse1();
+ std::string toString();
+ inlineMethode()
+ {
+ int i = 0; //TEST
+ i++;
+ }
+
+ int i;
+};
+
+//=
+=>leading
+
+=>trailing
+int i = 0; = //TEST
+
+=>freestanding
+
+//!CommentRecognition22 - von CERP
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse1.h
+class Klasse1
+{
+public:
+ Klasse1();
+ std::string toString();
+ inlineMethode()
+ {
+ int i = 0;
+ i++;
+ } //TEST
+
+private:
+ int i;
+};
+
+//=
+=>leading
+
+=>trailing
+{
+ int i = 0;
+ i++;
+ } = //TEST
+
+=>freestanding
+
+//!CommentRecognition23 - von CERP
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse1.h
+class Klasse1
+{
+public:
+ Klasse1();
+ std::string toString();
+ //KommentarDavor
+ inlineMethode()
+ {
+ int i = 0;
+ i++;
+ } //TEST
+
+private:
+ int i;
+};
+
+//=
+=>leading
+inlineMethode()
+ {
+ int i = 0;
+ i++;
+ } = //KommentarDavor
+
+=>trailing
+{
+ int i = 0;
+ i++;
+ } = //TEST
+
+=>freestanding
+
+//!CommentRecognition24 - von CERP
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse1.h
+class Klasse1
+{
+public:
+ Klasse1();
+ std::string toString();
+ inlineMethode()
+ {
+ int i = 0;
+ i++;
+ }
+
+private:
+ int i;
+}; //SCHLUSS
+
+//=
+=>leading
+
+=>trailing
+class Klasse1
+{
+public:
+ Klasse1();
+ std::string toString();
+ inlineMethode()
+ {
+ int i = 0;
+ i++;
+ }
+
+private:
+ int i;
+}; = //SCHLUSS
+
+=>freestanding
+
+//!CommentRecognition25 - von CERP
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse1.h
+class Klasse1
+{
+public:
+ Klasse1();
+ std::string toString();
+ inlineMethode()
+ {
+ int i = 0;
+ i++;
+ }
+
+private:
+ int i;
+}; //SCHLUSS
+ //2. teil
+
+//=
+=>leading
+
+=>trailing
+class Klasse1
+{
+public:
+ Klasse1();
+ std::string toString();
+ inlineMethode()
+ {
+ int i = 0;
+ i++;
+ }
+
+private:
+ int i;
+}; = //SCHLUSS
+
+=>freestanding
+class Klasse1
+{
+public:
+ Klasse1();
+ std::string toString();
+ inlineMethode()
+ {
+ int i = 0;
+ i++;
+ }
+
+private:
+ int i;
+}; = //2. teil
+
+//!CommentRecognition26 - von CERP
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse1.h
+class Klasse1
+{
+public:
+ Klasse1();
+ std::string toString();
+ inlineMethode()
+ {
+ int i = 0;
+ i++;
+ }
+
+private:
+ int i;
+};
+ //SCHLUSS
+ //2. teil
+
+//=
+=>leading
+
+=>trailing
+
+=>freestanding
+class Klasse1
+{
+public:
+ Klasse1();
+ std::string toString();
+ inlineMethode()
+ {
+ int i = 0;
+ i++;
+ }
+
+private:
+ int i;
+}; = //SCHLUSS , //2. teil
+
+//!CommentRecognition27 - von CERP
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse1.h
+class Klasse1
+{
+public:
+ Klasse1();
+ std::string toString();
+ inlineMethode()
+ {
+ int i = 0;
+ i++;
+ }
+
+private:
+ int i;
+}; /*SCHLUSS*/
+
+//=
+=>leading
+
+=>trailing
+class Klasse1
+{
+public:
+ Klasse1();
+ std::string toString();
+ inlineMethode()
+ {
+ int i = 0;
+ i++;
+ }
+
+private:
+ int i;
+}; = /*SCHLUSS*/
+
+=>freestanding
+
+//!CommentRecognition28 - von CERP
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse1.h
+class Klasse1
+{
+public:
+ Klasse1();
+ std::string toString();
+ inlineMethode()
+ {
+ int i = 0;
+ i++;
+ }
+
+private:
+ int i;
+};
+/*SCHLUSS*/
+
+//=
+=>leading
+
+=>trailing
+
+=>freestanding
+class Klasse1
+{
+public:
+ Klasse1();
+ std::string toString();
+ inlineMethode()
+ {
+ int i = 0;
+ i++;
+ }
+
+private:
+ int i;
+}; = /*SCHLUSS*/
+
+//!CommentRecognition29 - von CERP
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse1.h
+class Klasse1
+{
+public:
+ Klasse1();
+ std::string toString();
+ inlineMethode()
+ {
+ int i = 0;
+ i++;
+ }
+
+private:
+ int i;
+}; /*
+ * SCHLUSS
+ */
+
+//=
+=>leading
+
+=>trailing
+class Klasse1
+{
+public:
+ Klasse1();
+ std::string toString();
+ inlineMethode()
+ {
+ int i = 0;
+ i++;
+ }
+
+private:
+ int i;
+}; = /*
+ * SCHLUSS
+ */
+
+=>freestanding
+
+//!CommentRecognition30 - von CERP
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse1.h
+class Klasse1
+{
+public:
+ Klasse1();
+ std::string toString();
+ //TEST
+ inlineMethode()
+ {
+ int i = 0;
+ i++;
+ }
+
+private:
+ int i;
+};
+
+//=
+=>leading
+inlineMethode()
+ {
+ int i = 0;
+ i++;
+ } = //TEST
+
+=>trailing
+
+=>freestanding
+
+//!CommentRecognition31 - von CERP
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse1.h
+class Klasse1
+{
+public:
+ Klasse1();
+ std::string toString();
+ /*TEST*/
+ inlineMethode()
+ {
+ int i = 0;
+ i++;
+ }
+
+private:
+ int i;
+};
+
+//=
+=>leading
+inlineMethode()
+ {
+ int i = 0;
+ i++;
+ } = /*TEST*/
+
+=>trailing
+
+=>freestanding
+
+//!CommentRecognition32 - von CERP
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse1.h
+//Vorher
+class Klasse1 //Nachher
+{
+public:
+ Klasse1();
+ std::string toString();
+ inlineMethode()
+ {
+ int i = 0;
+ i++;
+ }
+
+private:
+ int i;
+};
+
+//=
+=>leading
+class Klasse1 //Nachher
+{
+public:
+ Klasse1();
+ std::string toString();
+ inlineMethode()
+ {
+ int i = 0;
+ i++;
+ }
+
+private:
+ int i;
+}; = //Vorher
+
+=>trailing
+Klasse1 = //Nachher
+
+=>freestanding
+
+//!CommentRecognition33 - von CERP
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse1.h
+//Vorher
+class Klasse1 /*Nachher*/
+{
+public:
+ Klasse1();
+ std::string toString();
+ inlineMethode()
+ {
+ int i = 0;
+ i++;
+ }
+
+private:
+ int i;
+};
+
+//=
+=>leading
+class Klasse1 /*Nachher*/
+{
+public:
+ Klasse1();
+ std::string toString();
+ inlineMethode()
+ {
+ int i = 0;
+ i++;
+ }
+
+private:
+ int i;
+}; = //Vorher
+
+=>trailing
+Klasse1 = /*Nachher*/
+
+=>freestanding
+
+//!CommentRecognition34 - von CERP
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse1.h
+/*Vorher*/
+class Klasse1
+{
+ /*Nachher*/
+public:
+ Klasse1();
+ std::string toString();
+ inlineMethode()
+ {
+ int i = 0;
+ i++;
+ }
+
+private:
+ int i;
+};
+
+//=
+=>leading
+class Klasse1
+{
+ /*Nachher*/
+public:
+ Klasse1();
+ std::string toString();
+ inlineMethode()
+ {
+ int i = 0;
+ i++;
+ }
+
+private:
+ int i;
+}; = /*Vorher*/
+public: = /*Nachher*/
+
+=>trailing
+
+=>freestanding
+
+//!CommentRecognition35 - von CERP
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse1.h
+/*Vorher*/
+class Klasse1
+{
+ //Nachher
+public:
+ Klasse1();
+ std::string toString();
+ inlineMethode()
+ {
+ int i = 0;
+ i++;
+ }
+
+private:
+ int i;
+};
+
+//=
+=>leading
+class Klasse1
+{
+ //Nachher
+public:
+ Klasse1();
+ std::string toString();
+ inlineMethode()
+ {
+ int i = 0;
+ i++;
+ }
+
+private:
+ int i;
+}; = /*Vorher*/
+public: = //Nachher
+
+=>trailing
+
+=>freestanding
+
+//!CommentRecognition36 - von CERP
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse1.h
+/*
+ * Vorher
+ */
+class Klasse1
+{
+ //Nachher
+public:
+ Klasse1();
+ std::string toString();
+ inlineMethode()
+ {
+ int i = 0;
+ i++;
+ }
+
+private:
+ int i;
+};
+
+//=
+=>leading
+class Klasse1
+{
+ //Nachher
+public:
+ Klasse1();
+ std::string toString();
+ inlineMethode()
+ {
+ int i = 0;
+ i++;
+ }
+
+private:
+ int i;
+}; = /*
+ * Vorher
+ */
+public: = //Nachher
+
+=>trailing
+
+=>freestanding
+
+//!CommentRecognition37 - von CERP
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse1.h
+class Klasse1
+{
+public:
+ Klasse1();
+ std::string toString();
+ inlineMethode()
+ {
+ int i = 0;
+ i++;
+ }
+
+private:
+ int i; //Test
+};
+
+//=
+=>leading
+
+=>trailing
+int i; = //Test
+
+=>freestanding
+
+//!CommentRecognition38 - von CERP
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse1.h
+class Klasse1
+{
+public:
+ Klasse1();
+ std::string toString();
+ inlineMethode()
+ {
+ int i = 0;
+ i++;
+ }
+
+private:
+ int i; /*Test*/
+};
+
+//=
+=>leading
+
+=>trailing
+int i; = /*Test*/
+
+=>freestanding
+
+//!CommentRecognition39 - von CERP
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse1.h
+class Klasse1
+{
+public:
+ Klasse1();
+ std::string toString();
+ inlineMethode()
+ {
+ int i = 0;
+ i++;
+ }
+
+private:
+ int i; /*
+ * Test
+ */
+};
+
+//=
+=>leading
+
+=>trailing
+int i; = /*
+ * Test
+ */
+
+=>freestanding
+
+//!CommentRecognition40 - von CERP
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse1.h
+class Klasse1
+{
+public:
+ Klasse1();
+ std::string toString();
+ inlineMethode()
+ {
+ int i = 0;
+ i++;
+ }
+
+private:
+ int i;
+ /*
+ * Test
+ */
+};
+
+//=
+=>leading
+
+=>trailing
+
+=>freestanding
+Klasse1 = /*
+ * Test
+ */
+
+//!CommentRecognition41 - von CERP
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse1.h
+class Klasse1
+{
+public:
+ Klasse1();
+ std::string toString();
+ inlineMethode()
+ {
+ int i = 0;
+ i++;
+ }
+
+private:
+ //TEST
+ int i;
+};
+
+//=
+=>leading
+int i; = //TEST
+
+=>trailing
+
+=>freestanding
+
+//!CommentRecognition42 - von CERP
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse1.h
+class Klasse1
+{
+public:
+ Klasse1();
+ std::string toString();
+ inlineMethode()
+ {
+ int i = 0;
+ i++;
+ }
+
+private:
+ /*TEST*/
+ int i;
+};
+
+//=
+=>leading
+int i; = /*TEST*/
+
+=>trailing
+
+=>freestanding
+
+//!CommentRecognition43 - von CERP
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse1.h
+class Klasse1
+{
+private:
+ int i;
+};
+
+//=
+=>leading
+
+=>trailing
+
+=>freestanding
+
+//!CommentRecognition44 - von CERP
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse1.h
+class Klasse1
+{
+private:
+ int i;
+ //TEST
+};
+
+//=
+=>leading
+
+=>trailing
+
+=>freestanding
+Klasse1 = //TEST
+
+//!CommentRecognition44b - von CERP
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse1.h
+class Klasse1
+{
+private:
+ int i; //TEST
+};
+
+//=
+=>leading
+
+=>trailing
+int i; = //TEST
+
+=>freestanding
+
+//!CommentRecognition44c - von CERP
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse1.h
+class Klasse1
+{
+private:
+ int i;
+ //TEST
+}; //Add
+
+//=
+=>leading
+
+=>trailing
+class Klasse1
+{
+private:
+ int i;
+ //TEST
+}; = //Add
+
+=>freestanding
+Klasse1 = //TEST
+
+//!CommentRecognition45 - von CERP
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse1.h
+class Klasse1
+{
+private:
+ //TEST
+ int i;
+};
+
+//=
+=>leading
+int i; = //TEST
+
+=>trailing
+
+=>freestanding
+
+//!CommentRecognition46 - von CERP
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse1.h
+class Klasse1
+{
+ //TEST
+private:
+ int i;
+};
+
+//=
+=>leading
+private: = //TEST
+
+=>trailing
+
+=>freestanding
+
+//!CommentRecognition47 - von CERP
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse1.h
+class Klasse1
+{
+public:
+ Klasse1();
+ std::string toString();
+private: //TEST
+ int i;
+};
+
+//=
+=>leading
+
+=>trailing
+private: = //TEST
+
+=>freestanding
+
+//!CommentRecognition48 - von CERP
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse1.h
+class Klasse1
+{
+ //TEST
+public: /*TEST*/
+ Klasse1();
+ std::string toString();
+private:
+ int i;
+};
+
+//=
+=>leading
+public: = //TEST
+
+=>trailing
+public: = /*TEST*/
+
+=>freestanding
+
+//!CommentRecognition48b - von CERP
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse1.h
+class Klasse1
+{
+ //TEST
+public: /*TEST*/
+ Klasse1();
+ std::string toString();
+private:
+ int i;
+};
+
+//=
+=>leading
+public: = //TEST
+
+=>trailing
+public: = /*TEST*/
+
+=>freestanding
+
+//!CommentRecognition49 - von CERP
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse1.h
+class Klasse1
+{
+public:
+ Klasse1(); //TEST1
+ //TEST2
+ std::string toString();
+private:
+ int i;
+};
+
+//=
+=>leading
+std::string toString(); = //TEST2
+
+=>trailing
+Klasse1(); = //TEST1
+
+=>freestanding
+
+//!CommentRecognition50 - von CERP
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse1.h
+class Klasse1
+{
+public:
+ Klasse1(); /*TEST1*/
+ /*TEST2*/
+ std::string toString();
+private:
+ int i;
+};
+
+//=
+=>leading
+std::string toString(); = /*TEST2*/
+
+=>trailing
+Klasse1(); = /*TEST1*/
+
+=>freestanding
+
+//!CommentRecognition51 - von CERP
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse1.h
+class Klasse1
+{
+public:
+ Klasse1(); //TEST1
+ /*TEST2*/
+ std::string toString();
+private:
+ int i;
+};
+
+//=
+=>leading
+std::string toString(); = /*TEST2*/
+
+=>trailing
+Klasse1(); = //TEST1
+
+=>freestanding
+
+//!CommentRecognition52 - von CERP
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse1.h
+class Klasse1
+{
+public:
+ Klasse1(); /*TEST1*/
+ //TEST2
+ std::string toString();
+private:
+ int i;
+};
+//=
+=>leading
+std::string toString(); = //TEST2
+
+=>trailing
+Klasse1(); = /*TEST1*/
+
+=>freestanding
+
+//!CommentRecognition53 - von CERP
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse1.h
+class Klasse1
+{
+public:
+ Klasse1(); /*TEST1*/
+ //TEST3
+ //TEST2
+ std::string toString();
+private:
+ int i;
+};
+
+//=
+=>leading
+std::string toString(); = //TEST3 , //TEST2
+
+=>trailing
+Klasse1(); = /*TEST1*/
+
+=>freestanding
+
+//!CommentRecognition54 - von CERP
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse1.h
+class Klasse1
+{
+public:
+ Klasse1(); /*TEST1*/
+ /*TEST3*/
+ //TEST2
+ std::string toString();
+private:
+ int i;
+};
+
+//=
+=>leading
+std::string toString(); = /*TEST3*/ , //TEST2
+
+=>trailing
+Klasse1(); = /*TEST1*/
+
+=>freestanding
+
+//!CommentRecognition55 - von CERP
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse1.h
+class Klasse1
+{
+public:
+ Klasse1(); //TEST1
+ /*
+ * TEST3
+ */
+ std::string toString();
+private:
+ int i;
+};
+
+//=
+=>leading
+std::string toString(); = /*
+ * TEST3
+ */
+
+=>trailing
+Klasse1(); = //TEST1
+
+=>freestanding
+
+//!CommentRecognition56 - von CERP
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse1.h
+class Klasse1
+{
+public:
+ Klasse1(); /*
+ * TEST1
+ */
+ //TEST2
+ std::string toString();
+private:
+ int i;
+};
+
+//=
+=>leading
+std::string toString(); = //TEST2
+
+=>trailing
+Klasse1(); = /*
+ * TEST1
+ */
+
+=>freestanding
+
+//!CommentRecognition57 - von CERP
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse1.h
+namespace testNamespace
+{
+ class Klasse1
+ {
+ public:
+ Klasse1();
+ std::string toString();
+ private:
+ int i;
+ };
+}
+
+//=
+=>leading
+
+=>trailing
+
+=>freestanding
+
+//!CommentRecognition58 - von CERP
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse1.h
+//Kommentar
+namespace testNamespace
+{
+
+class Klasse1
+{
+public:
+ Klasse1();
+ std::string toString();
+private:
+ int i;
+};
+
+}
+
+//=
+=>leading
+namespace testNamespace
+{
+
+class Klasse1
+{
+public:
+ Klasse1();
+ std::string toString();
+private:
+ int i;
+};
+
+} = //Kommentar
+
+=>trailing
+
+=>freestanding
+
+//!CommentRecognition59 - von CERP
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse1.h
+namespace testNamespace //Kommentar
+{
+ class Klasse1
+ {
+ public:
+ Klasse1();
+ std::string toString();
+ private:
+ int i;
+ };
+}
+
+//=
+=>leading
+
+=>trailing
+testNamespace = //Kommentar
+
+=>freestanding
+
+//!CommentRecognition60 - von CERP
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse1.h
+/*Kommentar*/
+namespace testNamespace
+{
+ class Klasse1
+ {
+ public:
+ Klasse1();
+ std::string toString();
+ private:
+ int i;
+ };
+}
+
+//=
+=>leading
+namespace testNamespace
+{
+ class Klasse1
+ {
+ public:
+ Klasse1();
+ std::string toString();
+ private:
+ int i;
+ };
+} = /*Kommentar*/
+
+=>trailing
+
+=>freestanding
+
+//!CommentRecognition61 - von CERP
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse1.h
+namespace testNamespace /*Kommentar*/
+{
+ class Klasse1
+ {
+ public:
+ Klasse1();
+ std::string toString();
+ private:
+ int i;
+ };
+}
+
+//=
+=>leading
+
+=>trailing
+testNamespace = /*Kommentar*/
+
+=>freestanding
+
+//!CommentRecognition62 - von CERP
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse1.h
+/*
+ * Kommentar
+ */
+namespace testNamespace
+{
+ class Klasse1
+ {
+ public:
+ Klasse1();
+ std::string toString();
+ private:
+ int i;
+ };
+}
+
+//=
+=>leading
+namespace testNamespace
+{
+ class Klasse1
+ {
+ public:
+ Klasse1();
+ std::string toString();
+ private:
+ int i;
+ };
+} = /*
+ * Kommentar
+ */
+
+=>trailing
+
+=>freestanding
+
+//!CommentRecognition63 - von CERP
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse1.h
+namespace testNamespace /*
+ * Kommentar
+ */
+{
+ class Klasse1
+ {
+ public:
+ Klasse1();
+ std::string toString();
+ private:
+ int i;
+ };
+}
+
+//=
+=>leading
+
+=>trailing
+testNamespace = /*
+ * Kommentar
+ */
+
+=>freestanding
+
+//!CommentRecognition64 - von CERP
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse1.h
+namespace testNamespace
+{
+ class Klasse1
+ {
+ public:
+ Klasse1();
+ std::string toString();
+ private:
+ int i;
+ };
+} //Kommentar
+
+//=
+=>leading
+
+=>trailing
+namespace testNamespace
+{
+ class Klasse1
+ {
+ public:
+ Klasse1();
+ std::string toString();
+ private:
+ int i;
+ };
+} = //Kommentar
+
+=>freestanding
+
+//!CommentRecognition65 - von CERP
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse1.h
+namespace testNamespace
+{
+ class Klasse1
+ {
+ public:
+ Klasse1();
+ std::string toString();
+ private:
+ int i;
+ };
+} /*Kommentar*/
+
+//=
+=>leading
+
+=>trailing
+namespace testNamespace
+{
+ class Klasse1
+ {
+ public:
+ Klasse1();
+ std::string toString();
+ private:
+ int i;
+ };
+} = /*Kommentar*/
+
+=>freestanding
+
+//!CommentRecognition66 - von CERP
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse1.h
+namespace testNamespace
+{
+ class Klasse1
+ {
+ public:
+ Klasse1();
+ std::string toString();
+ private:
+ int i;
+ };
+} /*
+ * Kommentar
+ */
+
+//=
+=>leading
+
+=>trailing
+namespace testNamespace
+{
+ class Klasse1
+ {
+ public:
+ Klasse1();
+ std::string toString();
+ private:
+ int i;
+ };
+} = /*
+ * Kommentar
+ */
+
+=>freestanding
+
+//!CommentRecognition67 - von CERP
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse1.h
+namespace testNamespace
+{
+ class Klasse1 //TEST
+ {
+ public:
+ Klasse1();
+ std::string toString();
+ private:
+ int i;
+ };
+}
+
+//=
+=>leading
+
+=>trailing
+Klasse1 = //TEST
+
+=>freestanding
+
+//!CommentRecognition68 - von CERP
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse1.h
+namespace testNamespace
+{
+ class Klasse1
+ {
+ public:
+ Klasse1();
+ std::string toString();
+ private:
+ int i; //TEST
+ };
+}
+
+//=
+=>leading
+
+=>trailing
+int i; = //TEST
+
+=>freestanding
+
+//!CommentRecognition69 - von CERP
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse1.h
+namespace testNamespace
+{
+ class Klasse1
+ {
+ public:
+ Klasse1();
+ std::string toString();
+ private:
+ int i;
+ }; //TEST
+}
+
+//=
+=>leading
+
+=>trailing
+class Klasse1
+ {
+ public:
+ Klasse1();
+ std::string toString();
+ private:
+ int i;
+ }; = //TEST
+
+=>freestanding
+
+//!CommentRecognition70 - von CERP
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse1.h
+namespace testNamespace
+{
+ class Klasse1
+ {
+ public:
+ Klasse1();
+ std::string toString();
+ private:
+ int i;
+ };
+ //TEST
+}
+
+//=
+=>leading
+
+=>trailing
+
+=>freestanding
+namespace testNamespace
+{
+ class Klasse1
+ {
+ public:
+ Klasse1();
+ std::string toString();
+ private:
+ int i;
+ };
+ //TEST
+} = //TEST
+
+//!CommentRecognition100
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse1.h
+struct Klasse1
+{
+public:
+ Klasse1();
+ std::string toString();
+private:
+ int i;
+};
+
+//=
+=>leading
+
+=>trailing
+
+=>freestanding
+
+//!CommentRecognition101
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse1.h
+//Kommentar
+struct Klasse1
+{
+public:
+ Klasse1();
+ std::string toString();
+private:
+ int i;
+};
+
+//=
+=>leading
+struct Klasse1
+{
+public:
+ Klasse1();
+ std::string toString();
+private:
+ int i;
+}; = //Kommentar
+
+=>trailing
+
+=>freestanding
+
+//!CommentRecognition102
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse1.h
+struct Klasse1
+{
+ //Kommentar
+public:
+ Klasse1();
+ std::string toString();
+private:
+ int i;
+};
+
+//=
+=>leading
+public: = //Kommentar
+
+=>trailing
+
+=>freestanding
+
+//!CommentRecognition103
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse1.h
+struct Klasse1
+{
+ //Kommentar
+private:
+ Klasse1();
+ std::string toString();
+protected:
+ int i;
+};
+
+//=
+=>leading
+private: = //Kommentar
+
+=>trailing
+
+=>freestanding
+
+//!CommentRecognition104
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse1.h
+/*Davor*/
+struct Klasse1 //Kommentar
+{
+private:
+ Klasse1();
+ std::string toString();
+protected:
+ int i;
+};
+
+//=
+=>leading
+struct Klasse1 //Kommentar
+{
+private:
+ Klasse1();
+ std::string toString();
+protected:
+ int i;
+}; = /*Davor*/
+
+=>trailing
+Klasse1 = //Kommentar
+
+=>freestanding
+
+//!CommentRecognition200 - von ASTWriter
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse1.h
+//comment a
+void tree(int a)
+{
+ //comment b
+ a = 1; //comment c
+} //comment d
+
+//=
+=>leading
+void tree(int a)
+{
+ //comment b
+ a = 1; //comment c
+} = //comment a
+a = 1; = //comment b
+
+=>trailing
+{
+ //comment b
+ a = 1; //comment c
+} = //comment d
+a = 1; = //comment c
+
+=>freestanding
+
+//!CommentRecognition201 - von ASTWriter
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse1.h
+void tree(int a)
+{
+ a = 1;
+} //comment d
+
+//=
+=>leading
+
+=>trailing
+{
+ a = 1;
+} = //comment d
+
+=>freestanding
+
+//!CommentRecognition202 - von ASTWriter DeclarationStatement
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse1.h
+void foo()
+{
+ //TEST 1
+ int i = 2; //TEST 2
+ //TEST 3
+ int a; //TEST 4
+ //TEST 5
+}
+
+//=
+=>leading
+int i = 2; = //TEST 1
+int a; = //TEST 3
+
+=>trailing
+int i = 2; = //TEST 2
+int a; = //TEST 4
+
+=>freestanding
+{
+ //TEST 1
+ int i = 2; //TEST 2
+ //TEST 3
+ int a; //TEST 4
+ //TEST 5
+} = //TEST 5
+
+//!CommentRecognition203 - von ASTWriter ForStatement
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse1.h
+void foo()
+{
+ //TEST 1
+ for(int i = 0;i < 1;++i){
+ //TEST 2
+ break; //TEST 3
+ } //TEST 4
+}
+
+//=
+=>leading
+for(int i = 0;i < 1;++i){
+ //TEST 2
+ break; //TEST 3
+ } = //TEST 1
+break; = //TEST 2
+
+=>trailing
+{
+ //TEST 2
+ break; //TEST 3
+ } = //TEST 4
+break; = //TEST 3
+
+=>freestanding
+
+//!CommentRecognition204 - von ASTWriter LabelStatement
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse1.h
+void foo()
+{
+ start:
+ bar(); //Test
+ goto start;
+}
+
+
+//=
+=>leading
+
+=>trailing
+bar(); = //Test
+
+=>freestanding
+
+//!CommentRecognition205 - von ASTWriter IfStatement
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse1.h
+int f()
+{
+ if(int c = f()){
+ c++;
+ } //TEST 1
+ return i;
+}
+
+//=
+=>leading
+
+=>trailing
+{
+ c++;
+ } = //TEST 1
+
+=>freestanding
+
+//!CommentRecognition206 - von ASTWriter SwitchStatement
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse1.h
+void foo()
+{
+ //TEST 1
+ switch (1){
+ //TEST 2
+ case 1: //TEST 3
+ return 1; //TEST 4
+ case 2:
+ return 2;
+ default: //TEST 5
+ return 3;
+ //TEST 6
+ } //TEST 7
+}
+//=
+=>leading
+switch (1){
+ //TEST 2
+ case 1: //TEST 3
+ return 1; //TEST 4
+ case 2:
+ return 2;
+ default: //TEST 5
+ return 3;
+ //TEST 6
+ } = //TEST 1
+case 1: = //TEST 2
+
+=>trailing
+{
+ //TEST 2
+ case 1: //TEST 3
+ return 1; //TEST 4
+ case 2:
+ return 2;
+ default: //TEST 5
+ return 3;
+ //TEST 6
+ } = //TEST 7
+case 1: = //TEST 3
+return 1; = //TEST 4
+default: = //TEST 5
+
+=>freestanding
+{
+ //TEST 2
+ case 1: //TEST 3
+ return 1; //TEST 4
+ case 2:
+ return 2;
+ default: //TEST 5
+ return 3;
+ //TEST 6
+ } = //TEST 6
+
+//!CommentRecognition207 - von ASTWriter WhileStatement
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse1.h
+void foo()
+{
+ while(true){
+ break;
+ } /*TEST 6*/
+}
+
+//=
+=>leading
+
+=>trailing
+{
+ break;
+ } = /*TEST 6*/
+
+=>freestanding
+
+//!CommentRecognition208 - von ASTWriter ExplicitTemplateInstantiationStatement
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse1.h
+//TEST 1
+template class vector<int>; //TEST 2
+
+//=
+=>leading
+template class vector<int>; = //TEST 1
+
+=>trailing
+template class vector<int>; = //TEST 2
+
+=>freestanding
+
+//!ImplementationFileCommentRecognition1 - von CERP
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse1.h
+void Demo::methode1()
+{
+}
+
+void Demo::methode2()
+{
+}
+
+void Demo::methode3()
+{
+}
+
+//=
+=>leading
+
+=>trailing
+
+=>freestanding
+
+//!ImplementationFileCommentRecognition2 - von CERP
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse1.h
+//Zuvorderst
+
+
+void Demo::methode1()
+{
+ //Test
+}
+
+void Demo::methode2()
+{
+}
+//Davor
+
+void Demo::methode3()
+{
+} //Danach
+
+//Am Schluss
+//=
+=>leading
+void Demo::methode1()
+{
+ //Test
+} = //Zuvorderst
+void Demo::methode3()
+{
+} = //Davor
+
+=>trailing
+{
+} = //Danach
+
+=>freestanding
+{
+ //Test
+} = //Test
+void Demo::methode3()
+{
+} = //Am Schluss
+
+//!ImplementationFileCommentRecognition3 - von CERP
+//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
+//@Klasse1.h
+/*Zuvorderst*/
+void Demo::methode1()
+{
+ /*Test*/
+}
+
+void Demo::methode2()
+{
+}
+
+/*Davor*/
+void Demo::methode3()
+{
+} /*Danach*/
+
+
+/*Am Schluss*/
+
+//=
+=>leading
+void Demo::methode1()
+{
+ /*Test*/
+} = /*Zuvorderst*/
+void Demo::methode3()
+{
+} = /*Davor*/
+
+=>trailing
+{
+} = /*Danach*/
+
+=>freestanding
+{
+ /*Test*/
+} = /*Test*/
+void Demo::methode3()
+{
+} = /*Am Schluss*/
+
diff --git a/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java
index 8836477f7b2..cc6486a9fb5 100644
--- a/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java
+++ b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java
@@ -31,6 +31,7 @@ import org.eclipse.cdt.core.model.tests.BinaryTests;
import org.eclipse.cdt.core.model.tests.ElementDeltaTests;
import org.eclipse.cdt.core.model.tests.WorkingCopyTests;
import org.eclipse.cdt.core.parser.tests.ParserTestSuite;
+import org.eclipse.cdt.core.parser.tests.rewrite.RewriteTests;
import org.eclipse.cdt.core.tests.templateengine.AllTemplateEngineTests;
import org.eclipse.cdt.internal.index.tests.IndexTests;
import org.eclipse.cdt.internal.pdom.tests.PDOMTests;
@@ -57,7 +58,7 @@ public class AutomatedIntegrationSuite extends TestSuite {
super(name);
}
- public static Test suite() {
+ public static Test suite() throws Exception {
final AutomatedIntegrationSuite suite = new AutomatedIntegrationSuite();
// Add all success tests
@@ -71,6 +72,7 @@ public class AutomatedIntegrationSuite extends TestSuite {
suite.addTest(PositionTrackerTests.suite());
suite.addTest(StringBuilderTest.suite());
suite.addTest(AllLanguageTests.suite());
+ suite.addTest(RewriteTests.suite());
// Add in PDOM tests
suite.addTest(PDOMTests.suite());
diff --git a/core/org.eclipse.cdt.core/META-INF/MANIFEST.MF b/core/org.eclipse.cdt.core/META-INF/MANIFEST.MF
index f2d149ea133..61acc88498b 100644
--- a/core/org.eclipse.cdt.core/META-INF/MANIFEST.MF
+++ b/core/org.eclipse.cdt.core/META-INF/MANIFEST.MF
@@ -41,16 +41,19 @@ Export-Package: org.eclipse.cdt.core,
org.eclipse.cdt.core.templateengine.process.processes,
org.eclipse.cdt.internal.core;x-friends:="org.eclipse.cdt.ui",
org.eclipse.cdt.internal.core.browser.util;x-friends:="org.eclipse.cdt.ui",
- org.eclipse.cdt.internal.core.cdtvariables,
+ org.eclipse.cdt.internal.core.cdtvariables;x-internal:=true,
org.eclipse.cdt.internal.core.dom;x-friends:="org.eclipse.cdt.ui,org.eclipse.cdt.refactoring",
org.eclipse.cdt.internal.core.dom.parser;x-friends:="org.eclipse.cdt.refactoring",
org.eclipse.cdt.internal.core.dom.parser.c;x-friends:="org.eclipse.cdt.refactoring",
org.eclipse.cdt.internal.core.dom.parser.cpp;x-friends:="org.eclipse.cdt.ui,org.eclipse.cdt.refactoring",
org.eclipse.cdt.internal.core.dom.rewrite;x-friends:="org.eclipse.cdt.core.tests",
- org.eclipse.cdt.internal.core.envvar,
+ org.eclipse.cdt.internal.core.dom.rewrite.astwriter;x-internal:=true,
+ org.eclipse.cdt.internal.core.dom.rewrite.changegenerator;x-internal:=true,
+ org.eclipse.cdt.internal.core.dom.rewrite.commenthandler;x-internal:=true,
+ org.eclipse.cdt.internal.core.envvar;x-friends:="org.eclipse.cdt.ui",
org.eclipse.cdt.internal.core.index;x-friends:="org.eclipse.cdt.ui",
- org.eclipse.cdt.internal.core.index.provider,
- org.eclipse.cdt.internal.core.language,
+ org.eclipse.cdt.internal.core.index.provider;x-internal:=true,
+ org.eclipse.cdt.internal.core.language;x-friends:="org.eclipse.cdt.ui",
org.eclipse.cdt.internal.core.model;x-friends:="org.eclipse.cdt.ui,org.eclipse.cdt.refactoring",
org.eclipse.cdt.internal.core.model.ext;x-friends:="org.eclipse.cdt.ui",
org.eclipse.cdt.internal.core.parser;x-internal:=true,
@@ -63,13 +66,13 @@ Export-Package: org.eclipse.cdt.core,
org.eclipse.cdt.internal.core.pdom.dom;x-friends:="org.eclipse.cdt.ui",
org.eclipse.cdt.internal.core.pdom.dom.c;x-internal:=true,
org.eclipse.cdt.internal.core.pdom.dom.cpp;x-internal:=true,
- org.eclipse.cdt.internal.core.pdom.export,
+ org.eclipse.cdt.internal.core.pdom.export;x-internal:=true,
org.eclipse.cdt.internal.core.pdom.indexer;x-friends:="org.eclipse.cdt.ui",
org.eclipse.cdt.internal.core.util;x-internal:=true,
org.eclipse.cdt.internal.errorparsers;x-internal:=true,
org.eclipse.cdt.internal.formatter;x-internal:=true,
org.eclipse.cdt.internal.formatter.align;x-internal:=true,
- org.eclipse.cdt.internal.formatter.scanner,
+ org.eclipse.cdt.internal.formatter.scanner;x-internal:=true,
org.eclipse.cdt.utils,
org.eclipse.cdt.utils.cdtvariables,
org.eclipse.cdt.utils.coff,
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ASTVisitor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ASTVisitor.java
index b4608b97e22..5c4a0642c3c 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ASTVisitor.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ASTVisitor.java
@@ -163,6 +163,7 @@ public abstract class ASTVisitor {
return PROCESS_CONTINUE;
}
+ @Deprecated
public int visit( IASTComment comment){
return PROCESS_CONTINUE;
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/ASTRewriteAnalyzer.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/ASTRewriteAnalyzer.java
index 311a1c25cee..b86f09b6a9d 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/ASTRewriteAnalyzer.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/ASTRewriteAnalyzer.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007 Wind River Systems, Inc. and others.
+ * Copyright (c) 2008 Wind River Systems, Inc. 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
@@ -11,12 +11,14 @@
package org.eclipse.cdt.internal.core.dom.rewrite;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
+import org.eclipse.cdt.internal.core.dom.rewrite.changegenerator.ChangeGenerator;
import org.eclipse.ltk.core.refactoring.Change;
public class ASTRewriteAnalyzer {
public static Change rewriteAST(IASTTranslationUnit root, ASTModificationStore modificationStore) {
- throw new UnsupportedOperationException("The rewriter is not yet implemented"); //$NON-NLS-1$
+ ChangeGenerator rewriter = new ChangeGenerator(modificationStore);
+ rewriter.generateChange(root);
+ return rewriter.getChange();
}
-
}
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
new file mode 100644
index 00000000000..6e87a441a4b
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/ASTWriter.java
@@ -0,0 +1,57 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.internal.core.dom.rewrite.astwriter;
+
+import org.eclipse.cdt.core.dom.ast.IASTNode;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
+import org.eclipse.cdt.internal.core.dom.rewrite.changegenerator.ChangeGeneratorWriterVisitor;
+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$
+
+
+ public ASTWriter() {
+ super();
+ }
+
+ public ASTWriter(String givenIndentation) {
+ super();
+ this.givenIndentation = givenIndentation;
+ }
+
+ public String write(IASTNode rootNode) throws ProblemRuntimeException {
+ return write(rootNode, null, new NodeCommentMap());
+ }
+
+ public String write(IASTNode rootNode, String fileScope, NodeCommentMap commentMap) throws ProblemRuntimeException {
+ transformationVisitor = new ChangeGeneratorWriterVisitor(modificationStore, givenIndentation, fileScope, commentMap);
+ rootNode.accept(transformationVisitor);
+ String str = transformationVisitor.toString();
+ transformationVisitor.cleanCache();
+ return str;
+ }
+
+
+
+ public void setModificationStore(ASTModificationStore modificationStore) {
+ this.modificationStore = modificationStore;
+ }
+
+}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/ASTWriterVisitor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/ASTWriterVisitor.java
new file mode 100644
index 00000000000..6ceb7d5be23
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/ASTWriterVisitor.java
@@ -0,0 +1,243 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.internal.core.dom.rewrite.astwriter;
+
+import org.eclipse.cdt.core.dom.ast.ASTVisitor;
+import org.eclipse.cdt.core.dom.ast.IASTComment;
+import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
+import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
+import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
+import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
+import org.eclipse.cdt.core.dom.ast.IASTExpression;
+import org.eclipse.cdt.core.dom.ast.IASTInitializer;
+import org.eclipse.cdt.core.dom.ast.IASTName;
+import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
+import org.eclipse.cdt.core.dom.ast.IASTStatement;
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
+import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateParameter;
+import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTCompoundStatementExpression;
+import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
+import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap;
+
+public class ASTWriterVisitor extends CPPASTVisitor {
+
+ protected Scribe scribe = new Scribe();
+ protected NodeCommentMap commentMap;
+ protected ExpressionWriter expWriter;
+ protected DeclSpecWriter declSpecWriter;
+ protected StatementWriter statementWriter;
+ protected DeclaratorWriter declaratorWriter;
+ protected DeclarationWriter declarationWriter;
+ protected InitializerWriter initializerWriter;
+ protected NameWriter nameWriter;
+ protected TemplateParameterWriter tempParameterWriter;
+ protected MacroExpansionHandler macroHandler;
+ {
+ shouldVisitExpressions = true;
+
+ shouldVisitStatements = true;
+
+ shouldVisitNames = true;
+
+ shouldVisitDeclarations = true;
+
+ shouldVisitDeclSpecifiers = true;
+
+ shouldVisitDeclarators = true;
+
+ shouldVisitInitializers = true;
+
+ shouldVisitBaseSpecifiers = true;
+
+ shouldVisitNamespaces = true;
+
+ shouldVisitTemplateParameters = true;
+
+ shouldVisitParameterDeclarations = true;
+
+ shouldVisitTranslationUnit = true;
+ }
+
+
+
+ public ASTWriterVisitor(NodeCommentMap commentMap) {
+ this("", commentMap); //$NON-NLS-1$
+ }
+
+
+
+ public ASTWriterVisitor(String givenIndentation, NodeCommentMap commentMap) {
+ super();
+ scribe.setGivenIndentation(givenIndentation);
+ init(commentMap);
+ this.commentMap = commentMap;
+
+ }
+
+ private void init(NodeCommentMap commentMap) {
+ macroHandler = new MacroExpansionHandler(scribe);
+ statementWriter = new StatementWriter(scribe,this, commentMap);
+ declaratorWriter = new DeclaratorWriter(scribe,this, commentMap);
+ declarationWriter = new DeclarationWriter(scribe,this, commentMap);
+ declSpecWriter = new DeclSpecWriter(scribe,this, commentMap);
+ expWriter = new ExpressionWriter(scribe,this, macroHandler, commentMap);
+ initializerWriter = new InitializerWriter (scribe,this, commentMap);
+// ppStmtWriter = new PreprocessorStatementWriter(scribe, this, commentMap);
+ nameWriter = new NameWriter(scribe,this, commentMap);
+ tempParameterWriter = new TemplateParameterWriter(scribe, this, commentMap);
+ }
+
+ @Override
+ public String toString(){
+ return scribe.toString();
+ }
+
+ @Override
+ public int leave(IASTTranslationUnit tu) {
+ for(IASTComment comment : commentMap.getFreestandingCommentsForNode(tu)) {
+ scribe.print(comment.getComment());
+ scribe.newLine();
+ }
+ return super.leave(tu);
+ }
+
+ private void writeLeadingComments(ASTNode node) {
+ for(IASTComment comment : commentMap.getLeadingCommentsForNode(node)) {
+ scribe.print(comment.getComment());
+ scribe.newLine();
+ }
+ }
+
+
+ @Override
+ public int visit(IASTName name) {
+ writeLeadingComments((ASTNode) name);
+ if(!macroHandler.checkisMacroExpansionNode(name)) {
+ nameWriter.writeName(name);
+ }
+ return ASTVisitor.PROCESS_SKIP;
+ }
+
+
+
+ @Override
+ public int visit(IASTDeclSpecifier declSpec) {
+ writeLeadingComments((ASTNode) declSpec);
+ declSpecWriter.writeDelcSpec(declSpec);
+ return ASTVisitor.PROCESS_SKIP;
+ }
+
+
+
+ @Override
+ public int visit(IASTExpression expression) {
+ writeLeadingComments((ASTNode) expression);
+ if(!macroHandler.checkisMacroExpansionNode(expression)) {
+ if (expression instanceof IGNUASTCompoundStatementExpression) {
+ IGNUASTCompoundStatementExpression gnuCompStmtExp = (IGNUASTCompoundStatementExpression) expression;
+ gnuCompStmtExp.getCompoundStatement().accept(this);
+ }else {
+ expWriter.writeExpression(expression);
+ }
+ }
+ return ASTVisitor.PROCESS_SKIP;
+ }
+
+
+
+ @Override
+ public int visit(IASTStatement statement) {
+ writeLeadingComments((ASTNode) statement);
+ if(macroHandler.isStatementWithMixedLocation(statement) && !(statement instanceof IASTCompoundStatement)){
+ return statementWriter.writeMixedStatement(statement);
+ }
+ if(macroHandler.checkisMacroExpansionNode(statement)) {
+ return ASTVisitor.PROCESS_SKIP;
+ }
+ return statementWriter.writeStatement(statement, true);
+ }
+
+
+ @Override
+ public int visit(IASTDeclaration declaration) {
+ writeLeadingComments((ASTNode) declaration);
+ if(!macroHandler.checkisMacroExpansionNode(declaration)) {
+ declarationWriter.writeDeclaration(declaration);
+ }
+ return ASTVisitor.PROCESS_SKIP;
+ }
+
+
+
+ @Override
+ public int visit(IASTDeclarator declarator) {
+ writeLeadingComments((ASTNode) declarator);
+ if(!macroHandler.checkisMacroExpansionNode(declarator)) {
+ declaratorWriter.writeDeclarator(declarator);
+ }
+ return ASTVisitor.PROCESS_SKIP;
+ }
+
+
+
+ @Override
+ public int visit(IASTInitializer initializer) {
+ writeLeadingComments((ASTNode) initializer);
+ if(!macroHandler.checkisMacroExpansionNode(initializer)) {
+ initializerWriter.writeInitializer(initializer);
+ }
+ return ASTVisitor.PROCESS_SKIP;
+ }
+
+
+
+ @Override
+ public int visit(IASTParameterDeclaration parameterDeclaration) {
+ writeLeadingComments((ASTNode) parameterDeclaration);
+ if(!macroHandler.checkisMacroExpansionNode(parameterDeclaration)) {
+ parameterDeclaration.getDeclSpecifier().accept(this);
+ IASTDeclarator declarator = parameterDeclaration.getDeclarator();
+ if(declarator.getName().toString().length() != 0){
+ scribe.printSpaces(1);
+ }
+ declarator.accept(this);
+ }
+ return ASTVisitor.PROCESS_SKIP;
+ }
+
+ @Override
+ public int visit(ICPPASTNamespaceDefinition namespace) {
+ writeLeadingComments((ASTNode) namespace);
+ if(!macroHandler.checkisMacroExpansionNode(namespace)) {
+ declarationWriter.writeDeclaration(namespace);
+ }
+ return ASTVisitor.PROCESS_SKIP;
+ }
+
+ @Override
+ public int visit(ICPPASTTemplateParameter parameter) {
+ writeLeadingComments((ASTNode) parameter);
+ if(!macroHandler.checkisMacroExpansionNode(parameter)) {
+ tempParameterWriter.writeTemplateParameter(parameter);
+ }
+ return ASTVisitor.PROCESS_SKIP;
+ }
+
+
+ public void cleanCache() {
+ scribe.cleanCache();
+ macroHandler.reset();
+ }
+
+}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/ContainerNode.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/ContainerNode.java
new file mode 100644
index 00000000000..15b9c3f6f83
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/ContainerNode.java
@@ -0,0 +1,63 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.internal.core.dom.rewrite.astwriter;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.eclipse.cdt.core.dom.ast.ASTVisitor;
+import org.eclipse.cdt.core.dom.ast.IASTNode;
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
+import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
+
+/**
+ * @author Emanuel Graf
+ *
+ */
+public class ContainerNode extends ASTNode {
+
+ private final IASTTranslationUnit tu = null;
+
+ private final ArrayList<IASTNode> nodes = new ArrayList<IASTNode>();
+
+ public ContainerNode(IASTNode... nodes) {
+ for (IASTNode each : nodes) {
+ addNode(each);
+ }
+ }
+
+ public void addNode(IASTNode node) {
+ nodes.add(node);
+ if(node.getParent() == null) {
+ node.setParent(tu);
+ }
+ }
+
+ @Override
+ public boolean accept(ASTVisitor visitor) {
+ boolean ret = true;
+ for (IASTNode node : nodes) {
+ ret = node.accept(visitor);
+ }
+ return ret;
+ }
+
+ public IASTTranslationUnit getTu() {
+ return tu;
+ }
+
+ public List<IASTNode> getNodes(){
+ return Collections.unmodifiableList(nodes);
+ }
+
+}
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
new file mode 100644
index 00000000000..577e823ddcb
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/DeclSpecWriter.java
@@ -0,0 +1,411 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.internal.core.dom.rewrite.astwriter;
+
+import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier;
+import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
+import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
+import org.eclipse.cdt.core.dom.ast.IASTElaboratedTypeSpecifier;
+import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier;
+import org.eclipse.cdt.core.dom.ast.IASTExpression;
+import org.eclipse.cdt.core.dom.ast.IASTNamedTypeSpecifier;
+import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier;
+import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator;
+import org.eclipse.cdt.core.dom.ast.c.ICASTCompositeTypeSpecifier;
+import org.eclipse.cdt.core.dom.ast.c.ICASTDeclSpecifier;
+import org.eclipse.cdt.core.dom.ast.c.ICASTElaboratedTypeSpecifier;
+import org.eclipse.cdt.core.dom.ast.c.ICASTEnumerationSpecifier;
+import org.eclipse.cdt.core.dom.ast.c.ICASTSimpleDeclSpecifier;
+import org.eclipse.cdt.core.dom.ast.c.ICASTTypedefNameSpecifier;
+import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclSpecifier;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTElaboratedTypeSpecifier;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamedTypeSpecifier;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleDeclSpecifier;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier;
+import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap;
+
+/**
+ * @author Emanuel Graf
+ *
+ */
+public class DeclSpecWriter extends NodeWriter {
+ private static final String MUTABLE = "mutable "; //$NON-NLS-1$
+ private static final String _COMPLEX = "_Complex "; //$NON-NLS-1$
+ private static final String LONG_LONG = "long long "; //$NON-NLS-1$
+ private static final String REGISTER = "register "; //$NON-NLS-1$
+ private static final String AUTO = "auto "; //$NON-NLS-1$
+ private static final String TYPEDEF = "typedef "; //$NON-NLS-1$
+ private static final String UNION = "union"; //$NON-NLS-1$
+ private static final String STRUCT = "struct"; //$NON-NLS-1$
+ private static final String CLASS = "class"; //$NON-NLS-1$
+ private static final String FRIEND = "friend "; //$NON-NLS-1$
+ private static final String EXPLICIT = "explicit "; //$NON-NLS-1$
+ private static final String VIRTUAL = "virtual "; //$NON-NLS-1$
+ private static final String UNION_SPACE = "union "; //$NON-NLS-1$
+ private static final String STRUCT_SPACE = "struct "; //$NON-NLS-1$
+ private static final String ENUM = "enum "; //$NON-NLS-1$
+ private static final String _BOOL = "_Bool"; //$NON-NLS-1$
+
+ public DeclSpecWriter(Scribe scribe, CPPASTVisitor visitor, NodeCommentMap commentMap) {
+ super(scribe, visitor, commentMap);
+
+ }
+
+ protected void writeDelcSpec(IASTDeclSpecifier declSpec) {
+// Write general DelcSpec Keywords
+ writeDeclSpec(declSpec);
+ if (declSpec instanceof ICPPASTDeclSpecifier) {
+ writeCPPDeclSpec((ICPPASTDeclSpecifier) declSpec);
+ }else if (declSpec instanceof ICASTDeclSpecifier) {
+ writeCDeclSpec((ICASTDeclSpecifier) declSpec);
+ }
+ }
+
+ private String getCPPSimpleDecSpecifier(ICPPASTSimpleDeclSpecifier simpDeclSpec) {
+ int type = simpDeclSpec.getType();
+ if(type <= IASTSimpleDeclSpecifier.t_last) {
+ return getASTSimpleDecSpecifier(type);
+ }else {
+ switch (type) {
+ case ICPPASTSimpleDeclSpecifier.t_bool:
+ return CPP_BOOL;
+ case ICPPASTSimpleDeclSpecifier.t_wchar_t:
+ return WCHAR_T;
+ default:
+ System.err.println("Unknow Specifiertype: " + type); //$NON-NLS-1$
+ throw new IllegalArgumentException("Unknow Specifiertype: " + type); //$NON-NLS-1$
+ }
+ }
+ }
+
+ private String getCSimpleDecSpecifier(ICASTSimpleDeclSpecifier simpDeclSpec) {
+ int type = simpDeclSpec.getType();
+ if(type <= IASTSimpleDeclSpecifier.t_last) {
+ return getASTSimpleDecSpecifier(type);
+ }else {
+ switch (type) {
+ case ICASTSimpleDeclSpecifier.t_Bool:
+ return _BOOL;
+ default:
+ System.err.println("Unknow Specifiertype: " + type); //$NON-NLS-1$
+ throw new IllegalArgumentException("Unknow Specifiertype: " + type); //$NON-NLS-1$
+ }
+ }
+ }
+
+
+ private String getASTSimpleDecSpecifier(int type) {
+
+ if(type <= IASTSimpleDeclSpecifier.t_last) {
+ switch (type) {
+ case IASTSimpleDeclSpecifier.t_unspecified:
+ return ""; //$NON-NLS-1$
+ case IASTSimpleDeclSpecifier.t_void:
+ return VOID;
+ case IASTSimpleDeclSpecifier.t_char:
+ return CHAR;
+ case IASTSimpleDeclSpecifier.t_int:
+ return INT;
+
+ case IASTSimpleDeclSpecifier.t_float:
+ return FLOAT;
+
+ case IASTSimpleDeclSpecifier.t_double:
+ return DOUBLE;
+ default:
+ System.err.println("Unknow Specifiertype: " + type); //$NON-NLS-1$
+ throw new IllegalArgumentException("Unknow Specifiertype: " + type); //$NON-NLS-1$
+
+ }
+ }
+ System.err.println("Unknow Specifiertype: " + type); //$NON-NLS-1$
+ throw new IllegalArgumentException("Unknow Specifiertype: " + type); //$NON-NLS-1$
+ }
+
+ private void writeCDeclSpec(ICASTDeclSpecifier cDeclSpec) {
+ if(cDeclSpec.isRestrict()) {
+ scribe.print(RESTRICT);
+ }
+
+ if (cDeclSpec instanceof ICASTCompositeTypeSpecifier) {
+ writeCompositeTypeSpecifier((ICASTCompositeTypeSpecifier) cDeclSpec);
+ }else if (cDeclSpec instanceof ICASTEnumerationSpecifier) {
+ writeEnumSpec((ICASTEnumerationSpecifier) cDeclSpec);
+ }else if (cDeclSpec instanceof ICASTElaboratedTypeSpecifier) {
+ writeElaboratedTypeSec((ICASTElaboratedTypeSpecifier) cDeclSpec);
+ }else if (cDeclSpec instanceof ICASTSimpleDeclSpecifier) {
+ writeCSimpleDeclSpec((ICASTSimpleDeclSpecifier) cDeclSpec);
+ }else if (cDeclSpec instanceof ICASTTypedefNameSpecifier) {
+ writeNamedTypeSpecifier((ICASTTypedefNameSpecifier) cDeclSpec);
+ }
+ }
+
+ private void writeNamedTypeSpecifier(ICPPASTNamedTypeSpecifier namedSpc) {
+ if( namedSpc.isTypename() ){
+ scribe.print(TYPENAME);
+ }
+ namedSpc.getName().accept(visitor);
+ }
+
+ private void writeNamedTypeSpecifier(IASTNamedTypeSpecifier namedSpc) {
+ namedSpc.getName().accept(visitor);
+ }
+
+
+
+ private void writeElaboratedTypeSec(IASTElaboratedTypeSpecifier elabType) {
+ scribe.print(getElabTypeString(elabType.getKind()));
+ elabType.getName().accept(visitor);
+ }
+
+
+
+ private String getElabTypeString(int kind) {
+ switch(kind) {
+ case IASTElaboratedTypeSpecifier.k_enum:
+ return ENUM;
+ case IASTElaboratedTypeSpecifier.k_struct:
+ return STRUCT_SPACE;
+ case IASTElaboratedTypeSpecifier.k_union:
+ return UNION_SPACE;
+ case ICPPASTElaboratedTypeSpecifier.k_class:
+ return CLASS_SPACE;
+
+ default:
+ System.err.println("Unknown ElaboratedType: " + kind); //$NON-NLS-1$
+ throw new IllegalArgumentException("Unknown ElaboratedType: " + kind); //$NON-NLS-1$
+ }
+ }
+
+
+
+ private void writeCPPDeclSpec(ICPPASTDeclSpecifier cppDelcSpec) {
+ if (cppDelcSpec.isVirtual()) {
+ scribe.print(VIRTUAL);
+ }
+ if(cppDelcSpec.isExplicit()) {
+ scribe.print(EXPLICIT);
+ }
+ if(cppDelcSpec.isFriend()) {
+ scribe.print(FRIEND);
+ }
+ if(cppDelcSpec.getStorageClass() == ICPPASTDeclSpecifier.sc_mutable) {
+ scribe.print(MUTABLE);
+ }
+
+ if (cppDelcSpec instanceof ICPPASTCompositeTypeSpecifier) {
+ writeCompositeTypeSpecifier((ICPPASTCompositeTypeSpecifier) cppDelcSpec);
+ }else if (cppDelcSpec instanceof IASTEnumerationSpecifier) {
+ writeEnumSpec((IASTEnumerationSpecifier) cppDelcSpec);
+ }else if (cppDelcSpec instanceof ICPPASTElaboratedTypeSpecifier) {
+ writeElaboratedTypeSec((ICPPASTElaboratedTypeSpecifier) cppDelcSpec);
+ }else if (cppDelcSpec instanceof ICPPASTSimpleDeclSpecifier) {
+ writeCPPSimpleDeclSpec((ICPPASTSimpleDeclSpecifier) cppDelcSpec);
+ }else if (cppDelcSpec instanceof ICPPASTNamedTypeSpecifier) {
+ writeNamedTypeSpecifier((ICPPASTNamedTypeSpecifier) cppDelcSpec);
+ }
+ }
+
+
+
+ private void writeEnumSpec(IASTEnumerationSpecifier enumSpec) {
+ scribe.print(ENUM);
+ enumSpec.getName().accept(visitor);
+ scribe.print('{');
+ scribe.printSpace();
+ IASTEnumerator[] enums = enumSpec.getEnumerators();
+ for(int i = 0; i< enums.length;++i) {
+ writeEnumerator(enums[i]);
+ if(i+1< enums.length) {
+ scribe.print(NodeWriter.COMMA_SPACE);
+ }
+ }
+ scribe.print('}');
+
+ }
+
+
+
+ private void writeEnumerator(IASTEnumerator enumerator) {
+ enumerator.getName().accept(visitor);
+
+ IASTExpression value = enumerator.getValue();
+ if(value != null) {
+ scribe.print(EQUALS);
+ value.accept(visitor);
+ }
+ }
+
+
+
+ private void writeCompositeTypeSpecifier(IASTCompositeTypeSpecifier compDeclSpec) {
+ boolean hasTrailingComments = hasTrailingComments(compDeclSpec.getName());
+ scribe.printStringSpace(getCPPCompositeTypeString(compDeclSpec.getKey()));
+ compDeclSpec.getName().accept(visitor);
+ if (compDeclSpec instanceof ICPPASTCompositeTypeSpecifier) {
+ ICPPASTCompositeTypeSpecifier cppComp = (ICPPASTCompositeTypeSpecifier) compDeclSpec;
+ ICPPASTBaseSpecifier[] baseSpecifiers = cppComp.getBaseSpecifiers();
+ if (baseSpecifiers.length > 0) {
+ scribe.print(SPACE_COLON_SPACE);
+ for(int i = 0; i < baseSpecifiers.length;++i) {
+ writeBaseSpecifiers(baseSpecifiers[i]);
+ if(i+1 < baseSpecifiers.length) {
+ scribe.print(COMMA_SPACE);
+ }
+ }
+ hasTrailingComments = hasTrailingComments(baseSpecifiers[baseSpecifiers.length-1].getName());
+ }
+ }
+ if(!hasTrailingComments){
+ scribe.newLine();
+ }
+ scribe.print('{');
+ scribe.newLine();
+ scribe.incrementIndentationLevel();
+ IASTDeclaration[] decls = getMembers(compDeclSpec);
+
+ if(decls.length > 0) {
+ for (IASTDeclaration declaration : decls) {
+ declaration.accept(visitor);
+ }
+ }
+
+ if(hasFreestandingComments(compDeclSpec)) {
+ writeFreeStandingComments(compDeclSpec);
+ }
+ scribe.decrementIndentationLevel();
+ scribe.print('}');
+
+ if(hasTrailingComments(compDeclSpec)) {
+ writeTrailingComments(compDeclSpec);
+ }
+ }
+
+ protected IASTDeclaration[] getMembers(IASTCompositeTypeSpecifier compDeclSpec) {
+ return compDeclSpec.getMembers();
+ }
+
+ private void writeBaseSpecifiers(ICPPASTBaseSpecifier specifier) {
+ switch(specifier.getVisibility()) {
+ case ICPPASTBaseSpecifier.v_public:
+ scribe.printStringSpace(PUBLIC);
+ break;
+ case ICPPASTBaseSpecifier.v_protected:
+ scribe.printStringSpace(PROTECTED);
+ break;
+ case ICPPASTBaseSpecifier.v_private:
+ scribe.printStringSpace(PRIVATE);
+ break;
+ }
+ specifier.getName().accept(visitor);
+ }
+
+
+
+ private String getCPPCompositeTypeString(int key) {
+ if(key <= IASTCompositeTypeSpecifier.k_last) {
+ return getCompositeTypeString(key);
+ }
+ switch (key) {
+ case ICPPASTCompositeTypeSpecifier.k_class:
+ return CLASS;
+ default:
+ System.err.println("Unknow Specifiertype: " + key); //$NON-NLS-1$
+ throw new IllegalArgumentException("Unknow Specifiertype: " + key); //$NON-NLS-1$
+ }
+ }
+
+
+
+ private String getCompositeTypeString(int key) {
+ switch (key) {
+ case IASTCompositeTypeSpecifier.k_struct:
+ return STRUCT;
+ case IASTCompositeTypeSpecifier.k_union:
+ return UNION;
+ default:
+ System.err.println("Unknow Specifiertype: " + key); //$NON-NLS-1$
+ throw new IllegalArgumentException("Unknow Specifiertype: " + key); //$NON-NLS-1$
+ }
+ }
+
+
+
+ private void writeDeclSpec(IASTDeclSpecifier declSpec) {
+ if(declSpec.isInline()) {
+ scribe.print(INLINE);
+ }
+ switch(declSpec.getStorageClass()) {
+ case IASTDeclSpecifier.sc_typedef:
+ scribe.print(TYPEDEF);
+ break;
+ case IASTDeclSpecifier.sc_extern:
+ scribe.print(EXTERN);
+ break;
+ case IASTDeclSpecifier.sc_static:
+ scribe.print(STATIC);
+ break;
+ case IASTDeclSpecifier.sc_auto:
+ scribe.print(AUTO);
+ break;
+ case IASTDeclSpecifier.sc_register:
+ scribe.print(REGISTER);
+ break;
+ }
+ if (declSpec.isConst()) {
+ scribe.printStringSpace(CONST);
+ }
+ if (declSpec.isVolatile()) {
+ scribe.printStringSpace(VOLATILE);
+ }
+
+
+ }
+
+ private void writeCPPSimpleDeclSpec(ICPPASTSimpleDeclSpecifier simpDeclSpec) {
+ printQualifiers(simpDeclSpec);
+ scribe.print(getCPPSimpleDecSpecifier(simpDeclSpec));
+ }
+
+ private void printQualifiers(IASTSimpleDeclSpecifier simpDeclSpec) {
+ if(simpDeclSpec.isSigned()) {
+ scribe.printStringSpace(SIGNED);
+ }else if(simpDeclSpec.isUnsigned()){
+ scribe.printStringSpace(UNSIGNED);
+ }
+
+ if(simpDeclSpec.isShort()) {
+ scribe.printStringSpace(SHORT);
+ }else if(simpDeclSpec.isLong()) {
+ scribe.printStringSpace(LONG);
+ }
+ if (simpDeclSpec instanceof ICASTSimpleDeclSpecifier) {
+ ICASTSimpleDeclSpecifier cSimpDeclSpec = (ICASTSimpleDeclSpecifier) simpDeclSpec;
+ if (cSimpDeclSpec.isLongLong()) {
+ scribe.print(LONG_LONG);
+ }
+ if (cSimpDeclSpec.isComplex()) {
+ scribe.print(_COMPLEX);
+ }
+ }
+ }
+
+
+
+ private void writeCSimpleDeclSpec(ICASTSimpleDeclSpecifier simpDeclSpec) {
+ printQualifiers(simpDeclSpec);
+ scribe.print(getCSimpleDecSpecifier(simpDeclSpec));
+ }
+
+}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/DeclarationWriter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/DeclarationWriter.java
new file mode 100644
index 00000000000..8f772ed4632
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/DeclarationWriter.java
@@ -0,0 +1,309 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.internal.core.dom.rewrite.astwriter;
+
+import org.eclipse.cdt.core.dom.ast.IASTASMDeclaration;
+import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
+import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
+import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
+import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
+import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
+import org.eclipse.cdt.core.dom.ast.IASTProblemDeclaration;
+import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier;
+import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
+import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCatchHandler;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTExplicitTemplateInstantiation;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionTryBlockDeclarator;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLinkageSpecification;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceAlias;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateParameter;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateSpecialization;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDeclaration;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDirective;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTVisiblityLabel;
+import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTExplicitTemplateInstantiation;
+import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguousDeclaration;
+import org.eclipse.cdt.internal.core.dom.parser.IASTDeclarationAmbiguity;
+import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap;
+
+/**
+ * @author Emanuel Graf
+ *
+ */
+public class DeclarationWriter extends NodeWriter{
+
+ private static final String ASM_END = ")"; //$NON-NLS-1$
+ private static final String ASM_START = "asm("; //$NON-NLS-1$
+ private static final String TEMPLATE_DECLARATION = "template<"; //$NON-NLS-1$
+ private static final String EXPORT = "export "; //$NON-NLS-1$
+ private static final String TEMPLATE_SPECIALIZATION = "template <> "; //$NON-NLS-1$
+ private static final String NAMESPACE = "namespace "; //$NON-NLS-1$
+ private static final String USING = "using "; //$NON-NLS-1$
+ private boolean printSemicolon;
+
+ public DeclarationWriter(Scribe scribe, CPPASTVisitor visitor, NodeCommentMap commentMap) {
+ super(scribe, visitor, commentMap);
+ }
+
+ protected void writeDeclaration(IASTDeclaration declaration) throws ProblemRuntimeException{
+ writeDeclaration(declaration, true);
+ }
+
+ protected void writeDeclaration(IASTDeclaration declaration, boolean writeSemicolon) {
+ boolean addNewLine = true;
+ printSemicolon = writeSemicolon;
+ if (declaration instanceof IASTAmbiguousDeclaration) {
+ //Not implemented
+ } else if (declaration instanceof IASTASMDeclaration) {
+ writeASMDeclatation((IASTASMDeclaration) declaration);
+ } else if (declaration instanceof IASTDeclarationAmbiguity) {
+ //There is no class which implements IASTDeclarationAmbiguity
+ } else if (declaration instanceof IASTFunctionDefinition) {
+ writeFunctionDefinition((IASTFunctionDefinition) declaration);
+ } else if (declaration instanceof IASTProblemDeclaration) {
+ throw new ProblemRuntimeException((IASTProblemDeclaration) declaration);
+ } else if (declaration instanceof IASTSimpleDeclaration) {
+ writeSimpleDeclaration((IASTSimpleDeclaration) declaration);
+ } else if (declaration instanceof ICPPASTExplicitTemplateInstantiation) {
+ writeExplicitTemplateInstantiation((ICPPASTExplicitTemplateInstantiation) declaration);
+ addNewLine = false;
+ } else if (declaration instanceof ICPPASTLinkageSpecification) {
+ writeLinkageSpecification((ICPPASTLinkageSpecification) declaration);
+ } else if (declaration instanceof ICPPASTNamespaceAlias) {
+ writeNamespaceAlias((ICPPASTNamespaceAlias) declaration);
+ } else if (declaration instanceof ICPPASTTemplateDeclaration) {
+ writeTemplateDeclaration((ICPPASTTemplateDeclaration) declaration);
+ addNewLine = false;
+ } else if (declaration instanceof ICPPASTTemplateSpecialization) {
+ writeTemplateSpecialization((ICPPASTTemplateSpecialization) declaration);
+ addNewLine = false;
+ } else if (declaration instanceof ICPPASTUsingDeclaration) {
+ writeUsingDeclaration((ICPPASTUsingDeclaration) declaration);
+ } else if (declaration instanceof ICPPASTUsingDirective) {
+ writeUsingDirective((ICPPASTUsingDirective) declaration);
+ } else if (declaration instanceof ICPPASTVisiblityLabel) {
+ writeVisibilityLabel((ICPPASTVisiblityLabel) declaration);
+ }
+
+ if(hasTrailingComments(declaration)) {
+ writeTrailingComments(declaration, addNewLine);
+ }else if(addNewLine){
+ scribe.newLine();
+ }
+ if(hasFreestandingComments(declaration)){
+ writeFreeStandingComments(declaration);
+ }
+
+ if (declaration instanceof ICPPASTUsingDirective) {
+ scribe.newLine();
+ }
+ }
+
+ private void writeVisibilityLabel(ICPPASTVisiblityLabel visiblityLabel) {
+ scribe.decrementIndentationLevel();
+ switch (visiblityLabel.getVisibility()) {
+ case ICPPASTVisiblityLabel.v_private:
+ scribe.print(PRIVATE);
+ scribe.print(':');
+ break;
+ case ICPPASTVisiblityLabel.v_protected:
+ scribe.print(PROTECTED);
+ scribe.print(':');
+ break;
+ case ICPPASTVisiblityLabel.v_public:
+ scribe.print(PUBLIC);
+ scribe.print(':');
+ break;
+ default:
+ return;
+ }
+ scribe.incrementIndentationLevel();
+ }
+
+ private void writeUsingDirective(ICPPASTUsingDirective usingDirective) {
+ scribe.print(USING + NAMESPACE);
+ usingDirective.getQualifiedName().accept(visitor);
+ scribe.printSemicolon();
+ }
+
+ private void writeUsingDeclaration(ICPPASTUsingDeclaration usingDeclaration) {
+ scribe.print(USING);
+ if(usingDeclaration.isTypename()){
+ scribe.print(TYPENAME);
+ }
+ usingDeclaration.getName().accept(visitor);
+ scribe.printSemicolon();
+ }
+
+ private void writeTemplateSpecialization(ICPPASTTemplateSpecialization templateSpecialization) {
+ scribe.print(TEMPLATE_SPECIALIZATION);
+ templateSpecialization.getDeclaration().accept(visitor);
+ }
+
+ private void writeTemplateDeclaration(ICPPASTTemplateDeclaration templateDeclaration) {
+ if(templateDeclaration.isExported()){
+ scribe.print(EXPORT);
+ }
+ scribe.print(TEMPLATE_DECLARATION);
+ ICPPASTTemplateParameter[] paraDecls = templateDeclaration.getTemplateParameters();
+ for(int i = 0; i < paraDecls.length; ++i) {
+ paraDecls[i].accept(visitor);
+ if(i + 1 < paraDecls.length) {
+ scribe.print(',');
+ scribe.printSpaces(1);
+ }
+ }
+ scribe.print('>');
+ scribe.printSpace();
+ templateDeclaration.getDeclaration().accept(visitor);
+ }
+
+ protected void writeDeclaration(ICPPASTNamespaceDefinition declaration){
+ printSemicolon = true;
+ writeNamespaceDefinition(declaration);
+ }
+
+ private void writeNamespaceDefinition(ICPPASTNamespaceDefinition namespaceDefinition) {
+ scribe.print(NAMESPACE);
+ namespaceDefinition.getName().accept(visitor);
+ if(!hasTrailingComments(namespaceDefinition.getName())) {
+ scribe.newLine();
+ }
+ scribe.printLBrace();
+ scribe.newLine();
+ for (IASTDeclaration declarations : namespaceDefinition.getDeclarations()) {
+ declarations.accept(visitor);
+ }
+ if(hasFreestandingComments(namespaceDefinition)) {
+ writeFreeStandingComments(namespaceDefinition);
+ }
+ scribe.printRBrace();
+
+ if(hasTrailingComments(namespaceDefinition)) {
+ writeTrailingComments(namespaceDefinition);
+ }else{
+ scribe.newLine();
+ }
+ }
+
+ private void writeNamespaceAlias(ICPPASTNamespaceAlias namespaceAliasDefinition) {
+ scribe.print(NAMESPACE);
+ namespaceAliasDefinition.getAlias().accept(visitor);
+ scribe.print(EQUALS);
+ namespaceAliasDefinition.getMappingName().accept(visitor);
+ printSemicolon();
+ }
+
+ private void writeLinkageSpecification(ICPPASTLinkageSpecification linkageSpecification) {
+ scribe.print( EXTERN);
+ scribe.print(linkageSpecification.getLiteral());
+ scribe.printSpaces(1);
+
+ IASTDeclaration[] declarations = linkageSpecification.getDeclarations();
+ if(declarations.length > 1){
+ scribe.printLBrace();
+ scribe.decrementIndentationLevel();
+ scribe.newLine();
+ for (IASTDeclaration declaration : declarations) {
+ declaration.accept(visitor);
+ }
+ scribe.printRBrace();
+ scribe.incrementIndentationLevel();
+ } else if(declarations.length > 0) {
+ visitNodeIfNotNull(declarations[0]);
+ }
+ }
+
+ private void writeExplicitTemplateInstantiation(ICPPASTExplicitTemplateInstantiation explicitTemplateInstantiation) {
+ if (explicitTemplateInstantiation instanceof IGPPASTExplicitTemplateInstantiation) {
+ IGPPASTExplicitTemplateInstantiation gppExplicitTemplateInstantiation = (IGPPASTExplicitTemplateInstantiation) explicitTemplateInstantiation;
+ switch(gppExplicitTemplateInstantiation.getModifier()){
+ case IGPPASTExplicitTemplateInstantiation.ti_extern:
+ scribe.print(EXTERN);
+ break;
+ case IGPPASTExplicitTemplateInstantiation.ti_inline:
+ scribe.print(INLINE);
+ break;
+ case IGPPASTExplicitTemplateInstantiation.ti_static:
+ scribe.print(STATIC);
+ break;
+ }
+ }
+
+ scribe.print(TEMPLATE);
+ explicitTemplateInstantiation.getDeclaration().accept(visitor);
+ }
+
+ private void writeASMDeclatation(IASTASMDeclaration asmDeclaration) {
+ scribe.print(ASM_START);
+ scribe.print(asmDeclaration.getAssembly());
+ scribe.print(ASM_END);
+ printSemicolon();
+ }
+
+ private void printSemicolon() {
+ if(printSemicolon) {
+ scribe.printSemicolon();
+ }
+ }
+
+ private void writeFunctionDefinition(IASTFunctionDefinition funcDef) {
+ IASTDeclSpecifier declSpecifier = funcDef.getDeclSpecifier();
+ declSpecifier.accept(visitor);
+ if (declSpecifier instanceof IASTSimpleDeclSpecifier) {
+ IASTSimpleDeclSpecifier simDeclSpec = (IASTSimpleDeclSpecifier) declSpecifier;
+ if(simDeclSpec.getType() != IASTSimpleDeclSpecifier.t_unspecified) {
+ scribe.printSpace();
+ }
+ }else {
+ scribe.printSpace();
+ }
+ IASTFunctionDeclarator declarator = funcDef.getDeclarator();
+ declarator.accept(visitor);
+ scribe.newLine();
+ funcDef.getBody().accept(visitor);
+ if (declarator instanceof ICPPASTFunctionTryBlockDeclarator) {
+ ICPPASTFunctionTryBlockDeclarator tryDeclSpec = (ICPPASTFunctionTryBlockDeclarator) declarator;
+ ICPPASTCatchHandler[] catches = tryDeclSpec.getCatchHandlers();
+ for (ICPPASTCatchHandler handler : catches) {
+ handler.accept(visitor);
+ }
+ }
+ }
+
+ private void writeSimpleDeclaration(IASTSimpleDeclaration simpDec) {
+ IASTDeclSpecifier declSpecifier = simpDec.getDeclSpecifier();
+ IASTDeclarator[] decls = simpDec.getDeclarators();
+
+ declSpecifier.accept(visitor);
+ boolean noSpace = false;
+ if (declSpecifier instanceof IASTSimpleDeclSpecifier) {
+ IASTSimpleDeclSpecifier simpleDeclSpecifier = (IASTSimpleDeclSpecifier) declSpecifier;
+ if(simpleDeclSpecifier.getType() == IASTSimpleDeclSpecifier.t_unspecified) {
+ noSpace = true;
+ }
+ }
+
+ if(decls.length > 0) {
+ if(!noSpace) {
+ scribe.printSpace();
+ }
+ writeNodeList(decls);
+ }
+
+ printSemicolon();
+ }
+
+}
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
new file mode 100644
index 00000000000..9b5e8d3d7a2
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/DeclaratorWriter.java
@@ -0,0 +1,298 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.internal.core.dom.rewrite.astwriter;
+
+import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator;
+import org.eclipse.cdt.core.dom.ast.IASTArrayModifier;
+import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
+import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
+import org.eclipse.cdt.core.dom.ast.IASTFieldDeclarator;
+import org.eclipse.cdt.core.dom.ast.IASTInitializer;
+import org.eclipse.cdt.core.dom.ast.IASTName;
+import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
+import org.eclipse.cdt.core.dom.ast.IASTPointer;
+import org.eclipse.cdt.core.dom.ast.IASTPointerOperator;
+import org.eclipse.cdt.core.dom.ast.IASTStandardFunctionDeclarator;
+import org.eclipse.cdt.core.dom.ast.IASTTypeId;
+import org.eclipse.cdt.core.dom.ast.c.ICASTPointer;
+import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorInitializer;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionTryBlockDeclarator;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTPointerToMember;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTReferenceOperator;
+import org.eclipse.cdt.core.dom.ast.gnu.c.ICASTKnRFunctionDeclarator;
+import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTPointer;
+import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap;
+
+/**
+ * @author Emanuel Graf
+ *
+ */
+public class DeclaratorWriter extends NodeWriter {
+
+ private static final String AMPERSAND_SPACE = "& "; //$NON-NLS-1$
+ private static final String STAR_SPACE = "* "; //$NON-NLS-1$
+ private static final String TRY = "try"; //$NON-NLS-1$
+ private static final String PURE_VIRTUAL = " =0"; //$NON-NLS-1$
+
+ public DeclaratorWriter(Scribe scribe, CPPASTVisitor visitor, NodeCommentMap commentMap) {
+ super(scribe, visitor, commentMap);
+ }
+
+ protected void writeDeclarator(IASTDeclarator declarator) {
+ if (declarator instanceof IASTStandardFunctionDeclarator) {
+ writeFunctionDeclarator((IASTStandardFunctionDeclarator) declarator);
+ }else if (declarator instanceof IASTArrayDeclarator) {
+ writeArrayDeclarator((IASTArrayDeclarator) declarator);
+ }else if (declarator instanceof IASTFieldDeclarator) {
+ writeFieldDeclarator((IASTFieldDeclarator) declarator);
+ }else if (declarator instanceof ICASTKnRFunctionDeclarator) {
+ writeCKnRFunctionDeclarator((ICASTKnRFunctionDeclarator) declarator);
+ }else{
+ writeDefaultDeclarator(declarator);
+ }
+
+ if(hasTrailingComments(declarator)) {
+ writeTrailingComments(declarator, false);
+ }
+ }
+
+ protected void writeDefaultDeclarator(IASTDeclarator declarator) {
+ IASTPointerOperator[] pointOps = declarator.getPointerOperators();
+ writePointerOperators(declarator, pointOps);
+ IASTName name = declarator.getName();
+ name.accept(visitor);
+ IASTInitializer init = getInitializer(declarator);
+ if(init!= null) {
+ if (! (init instanceof ICPPASTConstructorInitializer)) {
+ scribe.print(EQUALS);
+ }
+ init.accept(visitor);
+ }
+ }
+
+ protected void writePointerOperators(IASTDeclarator declarator, IASTPointerOperator[] pointOps) {
+ for (IASTPointerOperator operator : pointOps) {
+ writePointerOp(operator);
+ }
+ }
+
+ private void writeFunctionDeclarator(IASTStandardFunctionDeclarator funcDec) {
+ IASTPointerOperator[] pointOps = funcDec.getPointerOperators();
+ writePointerOperators(funcDec, pointOps);
+ funcDec.getName().accept(visitor);
+ writeNestedDeclarator(funcDec);
+ writeParameters(funcDec);
+ writeInitializer(funcDec);
+ if (funcDec instanceof ICPPASTFunctionDeclarator) {
+ writeCppFunctionDeclarator((ICPPASTFunctionDeclarator) funcDec);
+ }
+ }
+
+ private void writeInitializer(IASTStandardFunctionDeclarator funcDec) {
+ IASTInitializer init = getInitializer(funcDec);
+ if(init != null) {
+ scribe.print(EQUALS);
+ init.accept(visitor);
+ }
+ }
+
+ private void writeParameters(IASTStandardFunctionDeclarator funcDec) {
+ IASTParameterDeclaration[] paraDecls = funcDec.getParameters();
+ scribe.print('(');
+ writeParameterDeclarations(funcDec, paraDecls);
+ scribe.print(')');
+ }
+
+ private void writeNestedDeclarator(IASTDeclarator funcDec) {
+ IASTDeclarator nestedDeclarator = funcDec.getNestedDeclarator();
+ if(nestedDeclarator != null) {
+ scribe.print('(');
+ nestedDeclarator.accept(visitor);
+ scribe.print(')');
+ }
+ }
+
+ private void writeCppFunctionDeclarator(ICPPASTFunctionDeclarator funcDec) {
+ if (funcDec.isConst()) {
+ scribe.printSpace();
+ scribe.print(CONST);
+ }
+ if (funcDec.isVolatile()) {
+ scribe.printSpace();
+ scribe.print(VOLATILE);
+ }
+ if(funcDec.isPureVirtual()) {
+ scribe.print(PURE_VIRTUAL);
+ }
+ writeExceptionSpecification(funcDec, funcDec.getExceptionSpecification());
+ if (funcDec instanceof ICPPASTFunctionTryBlockDeclarator) {
+ scribe.newLine();
+ scribe.print(TRY);
+ }
+ writeCtorChainInitializer(funcDec, funcDec.getConstructorChain());
+ }
+
+ protected void writeCtorChainInitializer(
+ ICPPASTFunctionDeclarator funcDec, ICPPASTConstructorChainInitializer[] ctorInitChain) {
+ if(ctorInitChain.length != 0) {
+ scribe.newLine();
+ scribe.print(':');
+ }
+ for(int i = 0; i < ctorInitChain.length; ++i) {
+ ICPPASTConstructorChainInitializer initializer = ctorInitChain[i];
+ initializer.getMemberInitializerId().accept(visitor);
+ scribe.print('(');
+ initializer.getInitializerValue().accept(visitor);
+ scribe.print(')');
+ if(i+1 < ctorInitChain.length) {
+ scribe.print(COMMA_SPACE);
+ }
+ }
+ }
+
+ protected void writeExceptionSpecification(ICPPASTFunctionDeclarator funcDec, IASTTypeId[] exceptions) {
+ if(exceptions.length != 0) {
+ scribe.printSpace();
+ scribe.print(THROW);
+ scribe.print('(');
+ writeNodeList(exceptions);
+ scribe.print(')');
+ }
+ }
+
+ protected void writeParameterDeclarations(IASTStandardFunctionDeclarator funcDec, IASTParameterDeclaration[] paraDecls) {
+ writeNodeList(paraDecls);
+ if(funcDec.takesVarArgs()){
+ if(paraDecls.length > 0){
+ scribe.print(COMMA_SPACE);
+ }
+ scribe.print(VAR_ARGS);
+ }
+ }
+
+ private void writePointer(IASTPointer operator) {
+ if (operator instanceof ICPPASTPointerToMember) {
+ ICPPASTPointerToMember pointerToMemberOp = (ICPPASTPointerToMember) operator;
+ if(pointerToMemberOp.getName() != null){
+ pointerToMemberOp.getName().accept(visitor);
+ scribe.print(STAR_SPACE);
+ }
+ } else {
+ scribe.print('*');
+ }
+
+
+ if (operator.isConst()) {
+ scribe.printStringSpace(CONST);
+
+ }
+ if (operator.isVolatile()) {
+ scribe.printStringSpace(VOLATILE);
+ }
+ if (operator instanceof ICASTPointer) {
+ ICASTPointer cPoint = (ICASTPointer) operator;
+ if(cPoint.isRestrict()) {
+ scribe.print(RESTRICT);
+ }
+ }
+ if (operator instanceof IGPPASTPointer) {
+ IGPPASTPointer gppPoint = (IGPPASTPointer) operator;
+ if(gppPoint.isRestrict()) {
+ scribe.print(RESTRICT);
+ }
+ }
+ }
+
+ private void writePointerOp(IASTPointerOperator operator) {
+ if (operator instanceof IASTPointer) {
+ IASTPointer pointOp = (IASTPointer) operator;
+ writePointer(pointOp);
+ }else if (operator instanceof ICPPASTReferenceOperator) {
+ scribe.print(AMPERSAND_SPACE);
+ }
+ }
+
+ private void writeArrayDeclarator(IASTArrayDeclarator arrDecl) {
+ IASTPointerOperator[] pointOps = arrDecl.getPointerOperators();
+ writePointerOperators(arrDecl, pointOps);
+ IASTName name = arrDecl.getName();
+ name.accept(visitor);
+
+ writeNestedDeclarator(arrDecl);
+
+ IASTArrayModifier[] arrMods = arrDecl.getArrayModifiers();
+ writeArrayModifiers(arrDecl, arrMods);
+ IASTInitializer initializer = getInitializer(arrDecl);
+ if(initializer != null) {
+ scribe.print(EQUALS);
+ initializer.accept(visitor);
+ }
+ }
+
+ protected IASTInitializer getInitializer(IASTDeclarator decl) {
+ return decl.getInitializer();
+ }
+
+ protected void writeArrayModifiers(IASTArrayDeclarator arrDecl, IASTArrayModifier[] arrMods) {
+ for (IASTArrayModifier modifier : arrMods) {
+ scribe.print('[');
+ modifier.accept(visitor);
+ scribe.print(']');
+ }
+ }
+
+
+ private void writeFieldDeclarator(IASTFieldDeclarator fieldDecl) {
+ IASTPointerOperator[] pointOps = fieldDecl.getPointerOperators();
+ writePointerOperators(fieldDecl, pointOps);
+ fieldDecl.getName().accept(visitor);
+ scribe.printSpace();
+ scribe.print(':');
+ scribe.printSpace();
+ fieldDecl.getBitFieldSize().accept(visitor);
+ IASTInitializer initializer = getInitializer(fieldDecl);
+ if(initializer != null) {
+ scribe.print(EQUALS);
+ initializer.accept(visitor);
+ }
+ }
+
+ private void writeCKnRFunctionDeclarator(ICASTKnRFunctionDeclarator knrFunct) {
+ knrFunct.getName().accept(visitor);
+ scribe.print('(');
+ writeKnRParameterNames(knrFunct, knrFunct.getParameterNames());
+ scribe.print(')');
+ scribe.newLine();
+ writeKnRParameterDeclarations(knrFunct, knrFunct.getParameterDeclarations());
+
+
+ }
+
+ 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) {
+ scribe.newLine();
+ }
+ }
+ }
+
+ protected void writeKnRParameterNames(ICASTKnRFunctionDeclarator knrFunct, IASTName[] parameterNames) {
+ writeNodeList(parameterNames);
+ }
+}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/ExpressionWriter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/ExpressionWriter.java
new file mode 100644
index 00000000000..ea8c206d909
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/ExpressionWriter.java
@@ -0,0 +1,634 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.internal.core.dom.rewrite.astwriter;
+
+import org.eclipse.cdt.core.dom.ast.IASTArraySubscriptExpression;
+import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression;
+import org.eclipse.cdt.core.dom.ast.IASTCastExpression;
+import org.eclipse.cdt.core.dom.ast.IASTConditionalExpression;
+import org.eclipse.cdt.core.dom.ast.IASTExpression;
+import org.eclipse.cdt.core.dom.ast.IASTExpressionList;
+import org.eclipse.cdt.core.dom.ast.IASTFieldReference;
+import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression;
+import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
+import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression;
+import org.eclipse.cdt.core.dom.ast.IASTProblemExpression;
+import org.eclipse.cdt.core.dom.ast.IASTTypeId;
+import org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression;
+import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression;
+import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTBinaryExpression;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCastExpression;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeleteExpression;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFieldReference;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNewExpression;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleTypeConstructorExpression;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTypeIdExpression;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTypenameExpression;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUnaryExpression;
+import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTTypeIdExpression;
+import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTUnaryExpression;
+import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTBinaryExpression;
+import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap;
+
+/**
+ * @author Emanuel Graf
+ *
+ */
+public class ExpressionWriter extends NodeWriter{
+
+ private static final String VECTORED_DELETE_OP = "[] "; //$NON-NLS-1$
+ private static final String DELETE = "delete "; //$NON-NLS-1$
+ private static final String STATIC_CAST_OP = "static_cast<"; //$NON-NLS-1$
+ private static final String REINTERPRET_CAST_OP = "reinterpret_cast<"; //$NON-NLS-1$
+ private static final String DYNAMIC_CAST_OP = "dynamic_cast<"; //$NON-NLS-1$
+ private static final String CONST_CAST_OP = "const_cast<"; //$NON-NLS-1$
+ private static final String CLOSING_CAST_BRACKET_OP = ">"; //$NON-NLS-1$
+ private static final String ARROW = "->"; //$NON-NLS-1$
+ private static final String SPACE_QUESTIONMARK_SPACE = " ? "; //$NON-NLS-1$
+ private static final String NEW = "new "; //$NON-NLS-1$
+ private static final String CLOSING_BRACKET_OP = ")"; //$NON-NLS-1$
+ private static final String TYPEOF_OP = "typeof ("; //$NON-NLS-1$
+ private static final String ALIGNOF_OP = "alignof ("; //$NON-NLS-1$
+ private static final String TYPEID_OP = "typeid ("; //$NON-NLS-1$
+ private static final String OPEN_BRACKET_OP = "("; //$NON-NLS-1$
+ private static final String SIZEOF_OP = "sizeof "; //$NON-NLS-1$
+ private static final String NOT_OP = "!"; //$NON-NLS-1$
+ private static final String TILDE_OP = "~"; //$NON-NLS-1$
+ private static final String AMPERSAND_OP = "&"; //$NON-NLS-1$
+ private static final String STAR_OP = "*"; //$NON-NLS-1$
+ private static final String UNARY_MINUS_OP = "-"; //$NON-NLS-1$
+ private static final String UNARY_PLUS_OP = "+"; //$NON-NLS-1$
+ private static final String INCREMENT_OP = "++"; //$NON-NLS-1$
+ private static final String DECREMENT_OP = "--"; //$NON-NLS-1$
+ private static final String MIN_OP = " <? "; //$NON-NLS-1$
+ private static final String MAX_OP = " >? "; //$NON-NLS-1$
+ private static final String PMARROW_OP = "->*"; //$NON-NLS-1$
+ private static final String PMDOT_OP = ".*"; //$NON-NLS-1$
+ private static final String NOT_EQUALS_OP = " != "; //$NON-NLS-1$
+ private static final String EQUALS_OP = " == "; //$NON-NLS-1$
+ private static final String BINARY_OR_ASSIGN = " |= "; //$NON-NLS-1$
+ private static final String BINARY_XOR_ASSIGN_OP = " ^= "; //$NON-NLS-1$
+ private static final String BINARY_AND_ASSIGN_OP = " &= "; //$NON-NLS-1$
+ private static final String SHIFT_RIGHT_ASSIGN_OP = " >>= "; //$NON-NLS-1$
+ private static final String SHIFT_LEFT_ASSIGN_OP = " <<= "; //$NON-NLS-1$
+ private static final String MINUS_ASSIGN_OP = " -= "; //$NON-NLS-1$
+ private static final String PLUS_ASSIGN_OP = " += "; //$NON-NLS-1$
+ private static final String MODULO_ASSIGN_OP = " %= "; //$NON-NLS-1$
+ private static final String DIVIDE_ASSIGN_OP = " /= "; //$NON-NLS-1$
+ private static final String MULTIPLY_ASSIGN_OP = " *= "; //$NON-NLS-1$
+ private static final String LOGICAL_OR_OP = " || "; //$NON-NLS-1$
+ private static final String LOGICAL_AND_OP = " && "; //$NON-NLS-1$
+ private static final String BINARY_OR_OP = " | "; //$NON-NLS-1$
+ private static final String BINARY_XOR_OP = " ^ "; //$NON-NLS-1$
+ private static final String BINARY_AND_OP = " & "; //$NON-NLS-1$
+ private static final String GREAER_EQUAL_OP = " >= "; //$NON-NLS-1$
+ private static final String LESS_EQUAL_OP = " <= "; //$NON-NLS-1$
+ private static final String GREATER_THAN_OP = " > "; //$NON-NLS-1$
+ private static final String LESS_THAN_OP = " < "; //$NON-NLS-1$
+ private static final String SHIFT_RIGHT_OP = " >> "; //$NON-NLS-1$
+ private static final String SHIFT_LEFT_OP = " << "; //$NON-NLS-1$
+ private static final String MINUS_OP = " - "; //$NON-NLS-1$
+ private static final String PLUS_OP = " + "; //$NON-NLS-1$
+ private static final String MODULO_OP = " % "; //$NON-NLS-1$
+ private static final String DIVIDE_OP = " / "; //$NON-NLS-1$
+ private static final String MULTIPLY_OP = " * "; //$NON-NLS-1$
+ private final MacroExpansionHandler macroHandler;
+
+ public ExpressionWriter(Scribe scribe, CPPASTVisitor visitor, MacroExpansionHandler macroHandler, NodeCommentMap commentMap) {
+ super(scribe, visitor, commentMap);
+ this.macroHandler = macroHandler;
+ }
+
+ protected void writeExpression(IASTExpression expression) {
+ if (expression instanceof IASTBinaryExpression) {
+ writeBinaryExpression((IASTBinaryExpression) expression);
+ } else if (expression instanceof IASTIdExpression) {
+ ((IASTIdExpression) expression).getName().accept(visitor);
+ } else if (expression instanceof IASTLiteralExpression) {
+ writeLiteralExpression((IASTLiteralExpression) expression);
+ } else if (expression instanceof IASTUnaryExpression) {//UnaryExpressions including Cast Expressions
+ writeUnaryExpression((IASTUnaryExpression) expression);
+ } else if (expression instanceof ICPPASTNewExpression) {
+ writeCPPNewExpression((ICPPASTNewExpression) expression);
+ }else if (expression instanceof IASTConditionalExpression) {
+ writeConditionalExpression((IASTConditionalExpression) expression);
+ }else if (expression instanceof IASTArraySubscriptExpression) {
+ writeArraySubscriptExpression((IASTArraySubscriptExpression) expression);
+ }else if (expression instanceof IASTFieldReference) {
+ writeFieldReference((IASTFieldReference) expression);
+ }else if (expression instanceof IASTFunctionCallExpression) {
+ writeFunctionCallExpression((IASTFunctionCallExpression) expression);
+ }else if (expression instanceof IASTExpressionList) {
+ writeExpressionList((IASTExpressionList) expression);
+ }else if (expression instanceof IASTProblemExpression) {
+ throw new ProblemRuntimeException(((IASTProblemExpression) expression));
+ }else if (expression instanceof IASTTypeIdExpression) {
+ writeTypeIdExpression((IASTTypeIdExpression) expression);
+ }else if (expression instanceof ICPPASTDeleteExpression) {
+ writeDeleteExpression((ICPPASTDeleteExpression) expression);
+ }else if (expression instanceof ICPPASTSimpleTypeConstructorExpression) {
+ writeSimpleTypeConstructorExpression((ICPPASTSimpleTypeConstructorExpression) expression);
+ }else if (expression instanceof ICPPASTTypenameExpression) {
+ //No example found for this Node
+ throw new UnsupportedOperationException("You found a example for a TypenameExpression: " + expression.getRawSignature()); //$NON-NLS-1$
+ }
+
+ }
+
+ private String getBinaryExpressionOperator(int operator){
+
+ switch(operator){
+ case IASTBinaryExpression.op_multiply:
+ return MULTIPLY_OP;
+ case IASTBinaryExpression.op_divide:
+ return DIVIDE_OP;
+ case IASTBinaryExpression.op_modulo:
+ return MODULO_OP;
+ case IASTBinaryExpression.op_plus:
+ return PLUS_OP;
+ case IASTBinaryExpression.op_minus:
+ return MINUS_OP;
+ case IASTBinaryExpression.op_shiftLeft:
+ return SHIFT_LEFT_OP;
+ case IASTBinaryExpression.op_shiftRight:
+ return SHIFT_RIGHT_OP;
+ case IASTBinaryExpression.op_lessThan:
+ return LESS_THAN_OP;
+ case IASTBinaryExpression.op_greaterThan:
+ return GREATER_THAN_OP;
+ case IASTBinaryExpression.op_lessEqual:
+ return LESS_EQUAL_OP;
+ case IASTBinaryExpression.op_greaterEqual:
+ return GREAER_EQUAL_OP;
+ case IASTBinaryExpression.op_binaryAnd:
+ return BINARY_AND_OP;
+ case IASTBinaryExpression.op_binaryXor:
+ return BINARY_XOR_OP;
+ case IASTBinaryExpression.op_binaryOr:
+ return BINARY_OR_OP;
+ case IASTBinaryExpression.op_logicalAnd:
+ return LOGICAL_AND_OP;
+ case IASTBinaryExpression.op_logicalOr:
+ return LOGICAL_OR_OP;
+ case IASTBinaryExpression.op_assign:
+ return EQUALS;
+ case IASTBinaryExpression.op_multiplyAssign:
+ return MULTIPLY_ASSIGN_OP;
+ case IASTBinaryExpression.op_divideAssign:
+ return DIVIDE_ASSIGN_OP;
+ case IASTBinaryExpression.op_moduloAssign:
+ return MODULO_ASSIGN_OP;
+ case IASTBinaryExpression.op_plusAssign:
+ return PLUS_ASSIGN_OP;
+ case IASTBinaryExpression.op_minusAssign:
+ return MINUS_ASSIGN_OP;
+ case IASTBinaryExpression.op_shiftLeftAssign:
+ return SHIFT_LEFT_ASSIGN_OP;
+ case IASTBinaryExpression.op_shiftRightAssign:
+ return SHIFT_RIGHT_ASSIGN_OP;
+ case IASTBinaryExpression.op_binaryAndAssign:
+ return BINARY_AND_ASSIGN_OP;
+ case IASTBinaryExpression.op_binaryXorAssign:
+ return BINARY_XOR_ASSIGN_OP;
+ case IASTBinaryExpression.op_binaryOrAssign:
+ return BINARY_OR_ASSIGN;
+ case IASTBinaryExpression.op_equals:
+ return EQUALS_OP;
+ case IASTBinaryExpression.op_notequals:
+ return NOT_EQUALS_OP;
+ case ICPPASTBinaryExpression.op_pmdot:
+ return PMDOT_OP;
+ case ICPPASTBinaryExpression.op_pmarrow:
+ return PMARROW_OP;
+ case IGPPASTBinaryExpression.op_max:
+ return MAX_OP;
+ case IGPPASTBinaryExpression.op_min:
+ return MIN_OP;
+ default:
+ System.err.println("Unknown unaryExpressionType: " + operator); //$NON-NLS-1$
+ throw new IllegalArgumentException("Unknown unaryExpressionType: " + operator); //$NON-NLS-1$
+ }
+
+ }
+
+ private boolean isPrefixExpression(IASTUnaryExpression unExp) {
+ int unaryExpressionType = unExp.getOperator();
+ if (unaryExpressionType <= IASTUnaryExpression.op_last) {
+
+ switch (unaryExpressionType) {
+ case IASTUnaryExpression.op_prefixDecr:
+ case IASTUnaryExpression.op_prefixIncr:
+ case IASTUnaryExpression.op_plus:
+ case IASTUnaryExpression.op_minus:
+ case IASTUnaryExpression.op_star:
+ case IASTUnaryExpression.op_amper:
+ case IASTUnaryExpression.op_tilde:
+ case IASTUnaryExpression.op_not:
+ case IASTUnaryExpression.op_sizeof:
+ case IASTUnaryExpression.op_bracketedPrimary:
+
+ return true;
+
+ default:
+ return false;
+ }
+ }else {
+ if (unExp instanceof ICPPASTUnaryExpression) {
+ switch (unaryExpressionType) {
+ case ICPPASTUnaryExpression.op_throw:
+ case ICPPASTUnaryExpression.op_typeid:
+ return true;
+ default:
+ return false;
+ }
+ }else if (unExp instanceof IGNUASTUnaryExpression) {
+ switch (unaryExpressionType) {
+ case IGNUASTUnaryExpression.op_alignOf:
+ case IGNUASTUnaryExpression.op_typeof:
+ return true;
+ default:
+ return false;
+ }
+ }
+ }
+ return false;
+ }
+
+ private boolean isPostfixExpression(IASTUnaryExpression unExp) {
+ int unaryExpressionType = unExp.getOperator();
+ if (unaryExpressionType <= IASTUnaryExpression.op_last) {
+ switch (unaryExpressionType) {
+ case IASTUnaryExpression.op_postFixDecr:
+ case IASTUnaryExpression.op_postFixIncr:
+ case IASTUnaryExpression.op_bracketedPrimary:
+
+ return true;
+
+ default:
+ return false;
+ }
+ }else {
+ if (unExp instanceof ICPPASTUnaryExpression) {
+ return unaryExpressionType == ICPPASTUnaryExpression.op_typeid;
+ }else if (unExp instanceof IGNUASTUnaryExpression) {
+ switch (unaryExpressionType) {
+ case IGNUASTUnaryExpression.op_alignOf:
+ case IGNUASTUnaryExpression.op_typeof:
+ return true;
+ default:
+ return false;
+ }
+ }
+ }
+ return false;
+ }
+
+ private String getPrefixOperator(IASTUnaryExpression unExp) {
+ int unaryExpressionType = unExp.getOperator();
+ if (unaryExpressionType <= IASTUnaryExpression.op_last) {
+ switch (unaryExpressionType) {
+ case IASTUnaryExpression.op_prefixDecr:
+ return DECREMENT_OP;
+ case IASTUnaryExpression.op_prefixIncr:
+ return INCREMENT_OP;
+ case IASTUnaryExpression.op_plus:
+ return UNARY_PLUS_OP;
+ case IASTUnaryExpression.op_minus:
+ return UNARY_MINUS_OP;
+ case IASTUnaryExpression.op_star:
+ return STAR_OP;
+ case IASTUnaryExpression.op_amper:
+ return AMPERSAND_OP;
+ case IASTUnaryExpression.op_tilde:
+ return TILDE_OP;
+ case IASTUnaryExpression.op_not:
+ return NOT_OP;
+ case IASTUnaryExpression.op_sizeof:
+ return SIZEOF_OP;
+ case IASTUnaryExpression.op_bracketedPrimary:
+ return OPEN_BRACKET_OP;
+ default:
+ System.err.println("Unkwown unaryExpressionType: " + unaryExpressionType); //$NON-NLS-1$
+ throw new IllegalArgumentException("Unkwown unaryExpressionType: " + unaryExpressionType); //$NON-NLS-1$
+ }
+ }else {
+ if (unExp instanceof ICPPASTUnaryExpression) {
+ switch (unaryExpressionType) {
+ case ICPPASTUnaryExpression.op_throw:
+ return THROW;
+ case ICPPASTUnaryExpression.op_typeid:
+ return TYPEID_OP;
+ default:
+ System.err.println("Unkwown unaryExpressionType: " + unaryExpressionType); //$NON-NLS-1$
+ throw new IllegalArgumentException("Unkwown unaryExpressionType: " + unaryExpressionType); //$NON-NLS-1$
+ }
+ }else if (unExp instanceof IGNUASTUnaryExpression) {
+ switch (unaryExpressionType) {
+ case IGNUASTUnaryExpression.op_alignOf:
+ return ALIGNOF_OP;
+ case IGNUASTUnaryExpression.op_typeof:
+ return TYPEOF_OP;
+ default:
+ System.err.println("Unkwown unaryExpressionType: " + unaryExpressionType); //$NON-NLS-1$
+ throw new IllegalArgumentException("Unkwown unaryExpressionType: " + unaryExpressionType); //$NON-NLS-1$
+ }
+ }
+ }
+ System.err.println("Unkwown unaryExpressionType: " + unaryExpressionType); //$NON-NLS-1$
+ throw new IllegalArgumentException("Unkwown unaryExpressionType: " + unaryExpressionType); //$NON-NLS-1$
+ }
+
+ private String getPostfixOperator(IASTUnaryExpression unExp) {
+ int unaryExpressionType = unExp.getOperator();
+ if (unaryExpressionType <= IASTUnaryExpression.op_last) {
+ switch (unaryExpressionType) {
+ case IASTUnaryExpression.op_postFixDecr:
+ return DECREMENT_OP;
+ case IASTUnaryExpression.op_postFixIncr:
+ return INCREMENT_OP;
+ case IASTUnaryExpression.op_bracketedPrimary:
+ return CLOSING_BRACKET_OP;
+ default:
+ System.err.println("Unkwown unaryExpressionType " + unaryExpressionType); //$NON-NLS-1$
+ throw new IllegalArgumentException("Unkwown unaryExpressionType " + unaryExpressionType); //$NON-NLS-1$
+ }
+ }else {
+ if (unExp instanceof ICPPASTUnaryExpression) {
+ switch (unaryExpressionType) {
+ case ICPPASTUnaryExpression.op_typeid:
+ return CLOSING_BRACKET_OP;
+ default:
+ System.err.println("Unkwown unaryExpressionType " + unaryExpressionType); //$NON-NLS-1$
+ throw new IllegalArgumentException("Unkwown unaryExpressionType " + unaryExpressionType); //$NON-NLS-1$
+ }
+ }else if (unExp instanceof IGNUASTUnaryExpression) {
+ switch (unaryExpressionType) {
+ case IGNUASTUnaryExpression.op_alignOf:
+ case IGNUASTUnaryExpression.op_typeof:
+ return CLOSING_BRACKET_OP;
+ default:
+ System.err.println("Unkwown unaryExpressionType " + unaryExpressionType); //$NON-NLS-1$
+ throw new IllegalArgumentException("Unkwown unaryExpressionType " + unaryExpressionType); //$NON-NLS-1$
+ }
+ }
+ }
+ System.err.println("Unkwown unaryExpressionType " + unaryExpressionType); //$NON-NLS-1$
+ throw new IllegalArgumentException("Unkwown unaryExpressionType " + unaryExpressionType); //$NON-NLS-1$
+ }
+
+ private void writeBinaryExpression(IASTBinaryExpression binExp) {
+ IASTExpression operand1 = binExp.getOperand1();
+ if (!macroHandler.checkisMacroExpansionNode(operand1)) {
+ operand1.accept(visitor);
+ }
+ IASTExpression operand2 = binExp.getOperand2();
+ if(macroHandler.checkisMacroExpansionNode(operand2, false)&& macroHandler.macroExpansionAlreadyPrinted(operand2)) {
+ return;
+ }
+ scribe.print(getBinaryExpressionOperator(binExp.getOperator()));
+ operand2.accept(visitor);
+ }
+
+ private void writeCPPNewExpression(ICPPASTNewExpression newExp) {
+ if(newExp.isGlobal()) {
+ scribe.print(COLON_COLON);
+ }
+ scribe.print(NEW);
+ IASTExpression placement = newExp.getNewPlacement();
+ visitNodeIfNotNull(placement);
+
+ IASTTypeId typeId = newExp.getTypeId();
+ visitNodeIfNotNull(typeId);
+
+ IASTExpression[] arraySizeExpressions = getNewTypeIdArrayExpressions(newExp, newExp.getNewTypeIdArrayExpressions());
+ for (IASTExpression expression : arraySizeExpressions) {
+ scribe.print('[');
+ expression.accept(visitor);
+ scribe.print(']');
+ }
+ if (arraySizeExpressions.length == 0 ) {
+ scribe.print('(');
+ IASTExpression initExp = getNewInitializer(newExp);
+ visitNodeIfNotNull(initExp);
+ scribe.print(')');
+ }
+ }
+
+ protected IASTExpression[] getNewTypeIdArrayExpressions(
+ ICPPASTNewExpression newExp, IASTExpression[] expressions) {
+ return newExp.getNewTypeIdArrayExpressions();
+ }
+
+ protected IASTExpression getNewInitializer(ICPPASTNewExpression newExp) {
+ return newExp.getNewInitializer();
+ }
+
+
+
+ private void writeLiteralExpression(IASTLiteralExpression litExp) {
+ scribe.print(litExp.toString());
+ }
+
+ private void writeUnaryExpression(IASTUnaryExpression unExp) {
+ if (unExp instanceof IASTCastExpression) {//Castoperatoren sind auch Un�reoperatoren
+ writeCastExpression((IASTCastExpression) unExp);
+ }else{
+ if(isPrefixExpression(unExp )) {
+ scribe.print(getPrefixOperator(unExp));
+ }
+ unExp.getOperand().accept(visitor);
+ if(isPostfixExpression(unExp)) {
+ scribe.print(getPostfixOperator(unExp));
+ }
+ }
+ }
+
+ private void writeConditionalExpression(IASTConditionalExpression condExp) {
+ condExp.getLogicalConditionExpression().accept(visitor);
+ scribe.print(SPACE_QUESTIONMARK_SPACE);
+ condExp.getPositiveResultExpression().accept(visitor);
+ scribe.print(SPACE_COLON_SPACE);
+ condExp.getNegativeResultExpression().accept(visitor);
+
+ }
+
+ private void writeArraySubscriptExpression(IASTArraySubscriptExpression arrSubExp) {
+ arrSubExp.getArrayExpression().accept(visitor);
+ scribe.print('[');
+ arrSubExp.getSubscriptExpression().accept(visitor);
+ scribe.print(']');
+
+ }
+
+ private void writeFieldReference(IASTFieldReference fieldRef) {
+ fieldRef.getFieldOwner().accept(visitor);
+ if(fieldRef.isPointerDereference()) {
+ scribe.print(ARROW);
+ }else {
+ scribe.print('.');
+ }
+ if (fieldRef instanceof ICPPASTFieldReference) {
+ ICPPASTFieldReference cppFieldRef = (ICPPASTFieldReference) fieldRef;
+ if(cppFieldRef.isTemplate()) {
+ scribe.print(TEMPLATE);
+ }
+ }
+ fieldRef.getFieldName().accept(visitor);
+
+ }
+
+ private void writeFunctionCallExpression(IASTFunctionCallExpression funcCallExp) {
+ funcCallExp.getFunctionNameExpression().accept(visitor);
+ scribe.print('(');
+ IASTExpression parameterExpression = funcCallExp.getParameterExpression();
+ visitNodeIfNotNull(parameterExpression);
+ scribe.print(')');
+
+ }
+
+ private void writeCastExpression(IASTCastExpression castExp) {
+ scribe.print(getCastPrefix(castExp.getOperator()));
+ castExp.getTypeId().accept(visitor);
+ scribe.print(getCastPostfix(castExp.getOperator()));
+ if (castExp instanceof ICPPASTCastExpression) {
+ scribe.print('(');
+ }
+ castExp.getOperand().accept(visitor);
+ if (castExp instanceof ICPPASTCastExpression) {
+ scribe.print(')');
+ }
+ }
+
+ private String getCastPostfix(int castType) {
+ switch (castType) {
+ case IASTCastExpression.op_cast:
+ return CLOSING_BRACKET_OP;
+ case ICPPASTCastExpression.op_const_cast:
+ case ICPPASTCastExpression.op_dynamic_cast:
+ case ICPPASTCastExpression.op_reinterpret_cast:
+ case ICPPASTCastExpression.op_static_cast:
+ return CLOSING_CAST_BRACKET_OP;
+ default:
+ throw new IllegalArgumentException("Unknown Cast Type"); //$NON-NLS-1$
+ }
+ }
+
+ private String getCastPrefix(int castType) {
+ switch (castType) {
+ case IASTCastExpression.op_cast:
+ return OPEN_BRACKET_OP;
+ case ICPPASTCastExpression.op_const_cast:
+ return CONST_CAST_OP;
+ case ICPPASTCastExpression.op_dynamic_cast:
+ return DYNAMIC_CAST_OP;
+ case ICPPASTCastExpression.op_reinterpret_cast:
+ return REINTERPRET_CAST_OP;
+ case ICPPASTCastExpression.op_static_cast:
+ return STATIC_CAST_OP;
+ default:
+ throw new IllegalArgumentException("Unknown Cast Type"); //$NON-NLS-1$
+ }
+ }
+
+ private void writeExpressionList(IASTExpressionList expList) {
+
+ IASTExpression[] expressions = expList.getExpressions();
+ writeExpressions(expList, expressions);
+ }
+
+ protected void writeExpressions(IASTExpressionList expList, IASTExpression[] expressions) {
+ writeNodeList(expressions);
+ }
+
+ private void writeTypeIdExpression(IASTTypeIdExpression typeIdExp) {
+ scribe.print(getTypeIdExp(typeIdExp));
+ typeIdExp.getTypeId().accept(visitor);
+ scribe.print(')');
+ }
+
+ private String getTypeIdExp(IASTTypeIdExpression typeIdExp) {
+ int type = typeIdExp.getOperator();
+ if (type <= IASTTypeIdExpression.op_last) {
+ if(type == IASTTypeIdExpression.op_sizeof) {
+ return SIZEOF_OP + "("; //$NON-NLS-1$
+ }
+ }else {
+ if (typeIdExp instanceof ICPPASTTypeIdExpression) {
+ if(type == ICPPASTTypeIdExpression.op_typeid) {
+ return TYPEID_OP;
+ }
+ }else if (typeIdExp instanceof IGNUASTTypeIdExpression) {
+ switch (type) {//TODO HSR Emanuel: check if there can't be GNUTypeIdExpressions here, see #162470
+ case IGNUASTTypeIdExpression.op_alignof:
+ return ALIGNOF_OP + "("; //$NON-NLS-1$
+ case IGNUASTTypeIdExpression.op_typeof:
+ return TYPEOF_OP;
+ }
+ }
+ }
+ throw new IllegalArgumentException("Unknown TypeId Type"); //$NON-NLS-1$
+ }
+
+ private void writeDeleteExpression(ICPPASTDeleteExpression delExp) {
+ if(delExp.isGlobal()) {
+ scribe.print(COLON_COLON);
+ }
+ scribe.print(DELETE);
+ if(delExp.isVectored()) {
+ scribe.print(VECTORED_DELETE_OP);
+ }
+ delExp.getOperand().accept(visitor);
+ }
+
+ private void writeSimpleTypeConstructorExpression(ICPPASTSimpleTypeConstructorExpression simpTypeCtorExp) {
+ scribe.print(getSimpleTypeString(simpTypeCtorExp.getSimpleType()));
+ scribe.print('(');
+ IASTExpression initalizer = simpTypeCtorExp.getInitialValue();
+ visitNodeIfNotNull(initalizer);
+ scribe.print(')');
+ }
+
+ private String getSimpleTypeString(int typeId) {
+ switch (typeId) {
+
+ case ICPPASTSimpleTypeConstructorExpression.t_void:
+ return VOID;
+ case ICPPASTSimpleTypeConstructorExpression.t_char:
+ return CHAR;
+ case ICPPASTSimpleTypeConstructorExpression.t_int:
+ return INT;
+ case ICPPASTSimpleTypeConstructorExpression.t_float:
+ return FLOAT;
+ case ICPPASTSimpleTypeConstructorExpression.t_double:
+ return DOUBLE;
+ case ICPPASTSimpleTypeConstructorExpression.t_bool:
+ return CPP_BOOL;
+ case ICPPASTSimpleTypeConstructorExpression.t_wchar_t:
+ return WCHAR_T;
+ case ICPPASTSimpleTypeConstructorExpression.t_short:
+ return SHORT;
+ case ICPPASTSimpleTypeConstructorExpression.t_long:
+ return LONG;
+ case ICPPASTSimpleTypeConstructorExpression.t_signed:
+ return SIGNED;
+ case ICPPASTSimpleTypeConstructorExpression.t_unsigned :
+ return UNSIGNED;
+
+ default:
+ System.err.println("Unknown simpleTypeId: " + typeId); //$NON-NLS-1$
+ throw new IllegalArgumentException("Unknown simpleTypeId: " + typeId); //$NON-NLS-1$
+ }
+ }
+
+}
+
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/InitializerWriter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/InitializerWriter.java
new file mode 100644
index 00000000000..ee62b7d8302
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/InitializerWriter.java
@@ -0,0 +1,87 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.internal.core.dom.rewrite.astwriter;
+
+import org.eclipse.cdt.core.dom.ast.IASTInitializer;
+import org.eclipse.cdt.core.dom.ast.IASTInitializerExpression;
+import org.eclipse.cdt.core.dom.ast.IASTInitializerList;
+import org.eclipse.cdt.core.dom.ast.c.ICASTArrayDesignator;
+import org.eclipse.cdt.core.dom.ast.c.ICASTDesignatedInitializer;
+import org.eclipse.cdt.core.dom.ast.c.ICASTDesignator;
+import org.eclipse.cdt.core.dom.ast.c.ICASTFieldDesignator;
+import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorInitializer;
+import org.eclipse.cdt.core.dom.ast.gnu.c.IGCCASTArrayRangeDesignator;
+import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap;
+
+/**
+ * @author Emanuel Graf
+ *
+ */
+public class InitializerWriter extends NodeWriter{
+
+ public InitializerWriter(Scribe scribe, CPPASTVisitor visitor, NodeCommentMap commentMap) {
+ super(scribe, visitor, commentMap);
+ }
+
+ protected void writeInitializer(IASTInitializer initializer) {
+ if (initializer instanceof IASTInitializerExpression) {
+ ((IASTInitializerExpression) initializer).getExpression().accept(visitor);
+ }else if (initializer instanceof IASTInitializerList) {
+ writeInitializerList((IASTInitializerList) initializer);
+ }else if (initializer instanceof ICPPASTConstructorInitializer) {
+ writeConstructorInitializer((ICPPASTConstructorInitializer) initializer);
+ }else if (initializer instanceof ICASTDesignatedInitializer) {
+ writeDesignatedInitializer((ICASTDesignatedInitializer) initializer);
+ }
+ }
+
+ private void writeInitializerList(IASTInitializerList initList) {
+ scribe.printLBrace();
+ IASTInitializer[] inits = initList.getInitializers();
+ writeNodeList(inits);
+ scribe.printRBrace();
+ }
+
+ private void writeConstructorInitializer(ICPPASTConstructorInitializer ctorInit) {
+ scribe.print('(');
+ ctorInit.getExpression().accept(visitor);
+ scribe.print(')');
+ }
+
+ private void writeDesignatedInitializer(ICASTDesignatedInitializer desigInit) {
+ ICASTDesignator[] designators = desigInit.getDesignators();
+ for (ICASTDesignator designator : designators) {
+ writeDesignator(designator);
+ }
+ scribe.print(EQUALS);
+ desigInit.getOperandInitializer().accept(visitor);
+ }
+
+ private void writeDesignator(ICASTDesignator designator) {
+ if (designator instanceof ICASTFieldDesignator) {
+ ICASTFieldDesignator fieldDes = (ICASTFieldDesignator) designator;
+ scribe.print('.');
+ fieldDes.getName().accept(visitor);
+ }else if (designator instanceof ICASTArrayDesignator) {
+ ICASTArrayDesignator arrDes = (ICASTArrayDesignator) designator;
+ scribe.print('[');
+ arrDes.getSubscriptExpression().accept(visitor);
+ scribe.print(']');
+ }else if (designator instanceof IGCCASTArrayRangeDesignator) {
+ //IGCCASTArrayRangeDesignator new_name = (IGCCASTArrayRangeDesignator) designator;
+ //TODO IGCCASTArrayRangeDesignator Bespiel zu parsen bringen
+ throw new UnsupportedOperationException("Writing of GCC ArrayRangeDesignator is not yet implemented"); //$NON-NLS-1$
+ }
+
+ }
+}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/MacroExpansionHandler.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/MacroExpansionHandler.java
new file mode 100644
index 00000000000..12c9b6a0b3c
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/MacroExpansionHandler.java
@@ -0,0 +1,81 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.internal.core.dom.rewrite.astwriter;
+
+import org.eclipse.cdt.core.dom.ast.IASTMacroExpansionLocation;
+import org.eclipse.cdt.core.dom.ast.IASTNode;
+import org.eclipse.cdt.core.dom.ast.IASTNodeLocation;
+import org.eclipse.cdt.core.dom.ast.IASTStatement;
+
+public class MacroExpansionHandler {
+
+ private int lastMacroExpOffset;
+ private final Scribe scribe;
+
+ public MacroExpansionHandler(Scribe scribe) {
+ this.scribe = scribe;
+ }
+
+ protected boolean checkisMacroExpansionNode(IASTNode node) {
+ return checkisMacroExpansionNode(node, true);
+ }
+
+ protected boolean isStatementWithMixedLocation(IASTStatement node) {
+ if(node.getNodeLocations().length > 1) {
+ for (IASTNodeLocation loc : node.getNodeLocations()) {
+ if (loc instanceof IASTMacroExpansionLocation) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ protected boolean macroExpansionAlreadyPrinted(IASTNode node) {
+ IASTNodeLocation[] locs = node.getNodeLocations();
+ if(locs.length ==1) {
+ if (locs[0] instanceof IASTMacroExpansionLocation) {
+ IASTMacroExpansionLocation macroNode = (IASTMacroExpansionLocation) locs[0];
+ if (macroNode.asFileLocation().getNodeOffset() == lastMacroExpOffset) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ protected boolean checkisMacroExpansionNode(IASTNode node, boolean write) {
+ IASTNodeLocation[] locs = node.getNodeLocations();
+ if(locs.length ==1) {
+ if (locs[0] instanceof IASTMacroExpansionLocation) {
+ IASTMacroExpansionLocation macroNode = (IASTMacroExpansionLocation) locs[0];
+
+ if (macroNode.asFileLocation().getNodeOffset() == lastMacroExpOffset) {
+ return true;
+ } else {
+ if (write) {
+ lastMacroExpOffset = macroNode.asFileLocation().getNodeOffset();
+ scribe.print(node.getRawSignature());
+ }
+ return true;
+ }
+
+ }
+ }
+ return false;
+ }
+
+ public void reset(){
+ lastMacroExpOffset = -1;
+ }
+
+}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/NameWriter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/NameWriter.java
new file mode 100644
index 00000000000..67128795336
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/NameWriter.java
@@ -0,0 +1,132 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.internal.core.dom.rewrite.astwriter;
+
+import org.eclipse.cdt.core.dom.ast.IASTName;
+import org.eclipse.cdt.core.dom.ast.IASTNode;
+import org.eclipse.cdt.core.dom.ast.IBinding;
+import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConversionName;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateTypeParameter;
+import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap;
+
+/**
+ * @author Emanuel Graf
+ *
+ */
+public class NameWriter extends NodeWriter {
+
+ private static final String OPERATOR = "operator "; //$NON-NLS-1$
+
+
+ /**
+ * @param scribe
+ * @param visitor
+ */
+ public NameWriter(Scribe scribe, CPPASTVisitor visitor, NodeCommentMap commentMap) {
+ super(scribe, visitor, commentMap);
+ }
+
+ protected void writeName(IASTName name) {
+ if (name instanceof ICPPASTTemplateId) {
+ writeTempalteId((ICPPASTTemplateId) name);
+ } else if (name instanceof ICPPASTConversionName) {
+ scribe.print(OPERATOR);
+ ((ICPPASTConversionName)name).getTypeId().accept(visitor);
+ } else if (name instanceof ICPPASTQualifiedName){
+ writeQualifiedName((ICPPASTQualifiedName) name);
+ } else {
+ scribe.print(name.toString());
+ }
+
+ if(hasTrailingComments(name)) {
+ writeTrailingComments(name);
+ }
+ }
+
+ private void writeTempalteId(ICPPASTTemplateId tempId) {
+ if(needsTemplateQualifier(tempId)) {
+ scribe.print(TEMPLATE);
+ }
+ scribe.print(tempId.getTemplateName().toString());
+ scribe.print('<');
+ IASTNode[] nodes = tempId.getTemplateArguments();
+ for (int i = 0; i < nodes.length; ++i) {
+ nodes[i].accept(visitor);
+ if(i + 1 < nodes.length) {
+ scribe.print(',');
+ }
+ }
+ scribe.print('>');
+ if(isNestedTemplateId(tempId)) {
+ scribe.printSpace();
+ }
+ }
+
+ private boolean needsTemplateQualifier(ICPPASTTemplateId templId){
+ if (templId.getParent() instanceof ICPPASTQualifiedName) {
+ ICPPASTQualifiedName qName = (ICPPASTQualifiedName) templId.getParent();
+ return isDependentName(qName, templId);
+ }
+ return false;
+ }
+
+ private boolean isDependentName(ICPPASTQualifiedName qname, ICPPASTTemplateId tempId) {
+ IASTName[] names = qname.getNames();
+ int i = 0;
+ for(;i < names.length; ++i){
+ if(names[i] == tempId){
+ return isDependentName(qname, tempId, i);
+ }
+ }
+ return false;
+ }
+
+ private boolean isDependentName(ICPPASTQualifiedName qname,
+ ICPPASTTemplateId tempId, int i) {
+ if(i <= 0){
+ return false;
+ }else{
+ if (qname.getNames()[i-1] instanceof ICPPASTTemplateId) {
+ return true;
+ }else{
+ IBinding binding = qname.getNames()[i-1].resolveBinding();
+ if (binding instanceof CPPTemplateTypeParameter) {
+ return true;
+ }
+ }
+ }
+ return isDependentName(qname, tempId, i-1);
+ }
+
+ private boolean isNestedTemplateId(IASTNode node) {
+ while((node = node.getParent()) != null) {
+ if (node instanceof ICPPASTTemplateId) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+
+ private void writeQualifiedName(ICPPASTQualifiedName qname) {
+ IASTName[] nodes = qname.getNames();
+ for (int i = 0; i < nodes.length; ++i) {
+ nodes[i].accept(visitor);
+ if(i + 1 < nodes.length) {
+ scribe.print(COLON_COLON);
+ }
+ }
+ }
+}
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
new file mode 100644
index 00000000000..1a21e652668
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/NodeWriter.java
@@ -0,0 +1,112 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.internal.core.dom.rewrite.astwriter;
+
+import org.eclipse.cdt.core.dom.ast.IASTComment;
+import org.eclipse.cdt.core.dom.ast.IASTNode;
+import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
+import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap;
+
+public class NodeWriter {
+
+ protected Scribe scribe;
+ protected CPPASTVisitor visitor;
+ protected NodeCommentMap commentMap;
+ protected static final String COMMA_SPACE = ", "; //$NON-NLS-1$
+ protected static final String EQUALS = " = "; //$NON-NLS-1$
+ protected static final String RESTRICT = "restrict "; //$NON-NLS-1$
+ protected static final String TYPENAME = "typename "; //$NON-NLS-1$
+ protected static final String PUBLIC = "public"; //$NON-NLS-1$
+ protected static final String PRIVATE = "private"; //$NON-NLS-1$
+ protected static final String PROTECTED = "protected"; //$NON-NLS-1$
+ protected static final String CONST = "const"; //$NON-NLS-1$
+ protected static final String VOLATILE = "volatile"; //$NON-NLS-1$
+ protected static final String INLINE = "inline "; //$NON-NLS-1$
+ protected static final String EXTERN = "extern "; //$NON-NLS-1$
+ protected static final String STATIC = "static "; //$NON-NLS-1$
+ protected static final String THROW = "throw "; //$NON-NLS-1$
+ protected static final String SPACE_COLON_SPACE = " : "; //$NON-NLS-1$
+ protected static final String TEMPLATE = "template "; //$NON-NLS-1$
+ protected static final String DOUBLE = "double"; //$NON-NLS-1$
+ protected static final String FLOAT = "float"; //$NON-NLS-1$
+ protected static final String INT = "int"; //$NON-NLS-1$
+ protected static final String CHAR = "char"; //$NON-NLS-1$
+ protected static final String VOID = "void"; //$NON-NLS-1$
+ protected static final String WCHAR_T = "wchar_t"; //$NON-NLS-1$
+ protected static final String CPP_BOOL = "bool"; //$NON-NLS-1$
+ protected static final String LONG = "long"; //$NON-NLS-1$
+ protected static final String SHORT = "short"; //$NON-NLS-1$
+ protected static final String UNSIGNED = "unsigned"; //$NON-NLS-1$
+ protected static final String SIGNED = "signed"; //$NON-NLS-1$
+ protected static final String CLASS_SPACE = "class "; //$NON-NLS-1$
+ protected static final String VAR_ARGS = "..."; //$NON-NLS-1$
+ protected static final String COLON_COLON = "::"; //$NON-NLS-1$
+
+ public NodeWriter(Scribe scribe, CPPASTVisitor visitor, NodeCommentMap commentMap) {
+ super();
+ this.scribe = scribe;
+ this.visitor = visitor;
+ this.commentMap = commentMap;
+ }
+
+ protected void writeNodeList(IASTNode[] nodes) {
+ for(int i = 0; i < nodes.length; ++i) {
+ nodes[i].accept(visitor);
+ if(i + 1 < nodes.length) {
+ scribe.print(COMMA_SPACE);
+ }
+ }
+ }
+
+ protected void visitNodeIfNotNull(IASTNode node){
+ if(node != null){
+ node.accept(visitor);
+ }
+ }
+
+
+ protected void writeTrailingComments(IASTNode node) {
+ //default write newLine
+ writeTrailingComments(node, true);
+ }
+
+ protected boolean hasTrailingComments(IASTNode node){
+ if(commentMap.getTrailingCommentsForNode(node).size()>0) {
+ return true;
+ }
+ return false;
+ }
+
+ protected void writeTrailingComments(IASTNode node, boolean newLine) {
+ for(IASTComment comment : commentMap.getTrailingCommentsForNode(node)) {
+ scribe.printSpace();
+ scribe.print(comment.getComment());
+ if(newLine) {
+ scribe.newLine();
+ }
+ }
+ }
+
+ protected boolean hasFreestandingComments(IASTNode node){
+ if(commentMap.getFreestandingCommentsForNode(node).size()>0) {
+ return true;
+ }
+ return false;
+ }
+
+ protected void writeFreeStandingComments(IASTNode node) {
+ for(IASTComment comment : commentMap.getFreestandingCommentsForNode(node)) {
+ scribe.print(comment.getComment());
+ scribe.newLine();
+ }
+ }
+}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/ProblemRuntimeException.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/ProblemRuntimeException.java
new file mode 100644
index 00000000000..ce3fa94f5ff
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/ProblemRuntimeException.java
@@ -0,0 +1,29 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.internal.core.dom.rewrite.astwriter;
+
+import org.eclipse.cdt.core.dom.ast.IASTProblemHolder;
+
+public class ProblemRuntimeException extends RuntimeException {
+
+ private static final long serialVersionUID = -3661425564246498786L;
+ private IASTProblemHolder problem;
+
+ public ProblemRuntimeException(IASTProblemHolder statement) {
+ problem = statement;
+ }
+
+ public IASTProblemHolder getProblem(){
+ return problem;
+ }
+
+}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/Scribe.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/Scribe.java
new file mode 100644
index 00000000000..61f19080918
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/Scribe.java
@@ -0,0 +1,180 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.internal.core.dom.rewrite.astwriter;
+
+public class Scribe {
+
+
+ private int indentationLevel = 0;
+ private int indentationSize = 4; //HSR tcorbat: could be a tab character too - this is not a very elegant solution
+ private StringBuffer buffer = new StringBuffer();
+ private boolean isAtLineBeginning = true;
+ private String newLine = System.getProperty("line.separator"); //$NON-NLS-1$
+ private String givenIndentation = null;
+
+ private boolean noNewLine = false;
+ private boolean noSemicolon = false;
+
+ public void newLine(){
+ if(!noNewLine) {
+ isAtLineBeginning = true;
+ buffer.append(getNewline());
+ }
+ }
+
+ private void indent(){
+ if( givenIndentation != null ){
+ buffer.append( givenIndentation );
+ }
+ printSpaces(indentationLevel * indentationSize);
+ }
+
+ private void indentIfNewLine(){
+ if(isAtLineBeginning){
+ isAtLineBeginning = false;
+ indent();
+ }
+ }
+
+ private String getNewline(){
+ return newLine;
+ }
+
+ public void print(String code){
+ indentIfNewLine();
+ buffer.append(code);
+ }
+
+ public void println(String code) {
+ print(code);
+ newLine();
+ }
+
+ public void print(String code, String code2) {
+ print(code);
+ buffer.append(code2);
+ }
+
+ public void println(String code, String code2) {
+ print(code, code2);
+ newLine();
+ }
+
+ public void println(String code , char[] code2) {
+ print(code);
+ buffer.append(code2);
+ newLine();
+ }
+
+ public void printSpaces(int number){
+ indentIfNewLine();
+ for(int i = 0; i < number; ++i){
+ printSpace();
+ }
+ }
+
+ public void noSemicolon() {
+ noSemicolon = true;
+ }
+
+ public void printSemicolon(){
+ if(!noSemicolon) {
+ indentIfNewLine();
+ buffer.append(';');
+ }
+ else {
+ noSemicolon = false;
+ }
+ }
+
+ @Override
+ public String toString(){
+ return buffer.toString();
+ }
+
+ public void print (char code) {
+ indentIfNewLine();
+ buffer.append(code);
+ }
+
+ public void print(char[] code) {
+ indentIfNewLine();
+ buffer.append(code);
+ }
+
+ public void println(char[] code) {
+ print(code);
+ newLine();
+ }
+
+ public void printStringSpace(String code){
+ print(code);
+ printSpace();
+ }
+
+ /**
+ * Prints a { to the Buffer an increases the Indentationlevel.
+ */
+ public void printLBrace() {
+ print('{');
+ ++indentationLevel;
+ }
+
+ /**
+ * Prints a } to the Buffer an decrease the Indentationlevel.
+ */
+ public void printRBrace() {
+ --indentationLevel;
+ print('}');
+ }
+
+ public void incrementIndentationLevel(){
+ ++indentationLevel;
+ }
+
+ public void decrementIndentationLevel(){
+ if(indentationLevel>0) {
+ --indentationLevel;
+ }
+ }
+
+ protected void noNewLines(){
+ noNewLine = true;
+ }
+
+ protected void newLines(){
+ noNewLine = false;
+ }
+
+ public void newLine(int i) {
+ while(i > 0) {
+ newLine();
+ --i;
+ }
+ }
+
+ public void printSpace() {
+ buffer.append(' ');
+ }
+
+ public String getGivenIndentation() {
+ return givenIndentation;
+ }
+
+ public void setGivenIndentation(String givenIndentation) {
+ this.givenIndentation = givenIndentation;
+ }
+
+ public void cleanCache() {
+ buffer = new StringBuffer();
+ }
+}
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
new file mode 100644
index 00000000000..60185ab374a
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/StatementWriter.java
@@ -0,0 +1,430 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.internal.core.dom.rewrite.astwriter;
+
+import org.eclipse.cdt.core.dom.ast.ASTVisitor;
+import org.eclipse.cdt.core.dom.ast.IASTBreakStatement;
+import org.eclipse.cdt.core.dom.ast.IASTCaseStatement;
+import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
+import org.eclipse.cdt.core.dom.ast.IASTContinueStatement;
+import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
+import org.eclipse.cdt.core.dom.ast.IASTDeclarationStatement;
+import org.eclipse.cdt.core.dom.ast.IASTDefaultStatement;
+import org.eclipse.cdt.core.dom.ast.IASTDoStatement;
+import org.eclipse.cdt.core.dom.ast.IASTExpression;
+import org.eclipse.cdt.core.dom.ast.IASTExpressionStatement;
+import org.eclipse.cdt.core.dom.ast.IASTForStatement;
+import org.eclipse.cdt.core.dom.ast.IASTGotoStatement;
+import org.eclipse.cdt.core.dom.ast.IASTIfStatement;
+import org.eclipse.cdt.core.dom.ast.IASTLabelStatement;
+import org.eclipse.cdt.core.dom.ast.IASTNullStatement;
+import org.eclipse.cdt.core.dom.ast.IASTProblemStatement;
+import org.eclipse.cdt.core.dom.ast.IASTReturnStatement;
+import org.eclipse.cdt.core.dom.ast.IASTStatement;
+import org.eclipse.cdt.core.dom.ast.IASTSwitchStatement;
+import org.eclipse.cdt.core.dom.ast.IASTWhileStatement;
+import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCatchHandler;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTForStatement;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTIfStatement;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSwitchStatement;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTryBlockStatement;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTWhileStatement;
+import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguousStatement;
+import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap;
+import org.eclipse.cdt.internal.core.dom.rewrite.util.FileContentHelper;
+import org.eclipse.cdt.internal.core.dom.rewrite.util.FileHelper;
+import org.eclipse.core.resources.IFile;
+
+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$
+ private static final String TRY = "try "; //$NON-NLS-1$
+ private static final String CATCH = "catch("; //$NON-NLS-1$
+ private static final String RETURN = "return"; //$NON-NLS-1$
+ private static final String GOTO = "goto "; //$NON-NLS-1$
+ private static final String CONTINUE = "continue"; //$NON-NLS-1$
+ private static final String BREAK = "break"; //$NON-NLS-1$
+ private static final String ELSE = "else"; //$NON-NLS-1$
+ private static final String IF = "if("; //$NON-NLS-1$
+ private static final String FOR = "for("; //$NON-NLS-1$
+ private static final String DO_WHILE = " while("; //$NON-NLS-1$
+ private static final String DO = "do"; //$NON-NLS-1$
+ private static final String SWITCH_BRACKET = "switch ("; //$NON-NLS-1$
+ private boolean compoundNoNewLine = false;
+ private boolean switchIsNew;
+ private boolean decrementIndentationLevelOneMore = false;
+ private final DeclarationWriter declWriter;
+
+ public StatementWriter(Scribe scribe, CPPASTVisitor visitor, NodeCommentMap commentMap) {
+ super(scribe, visitor, commentMap);
+ declWriter = new DeclarationWriter(scribe, visitor, commentMap);
+ }
+
+ /**
+ *
+ * @param statement
+ * @param newLine if true print a newline if statment usually have one.
+ * @return {@link ASTVisitor#PROCESS_SKIP}
+ */
+ protected int writeStatement(IASTStatement statement, boolean newLine) {
+ if (statement instanceof IASTAmbiguousStatement) {
+ //TODO HSR Leo test
+ statement.accept(visitor);
+ newLine = false;
+ } else if (statement instanceof IASTExpressionStatement) {
+ writeExpressionStatement((IASTExpressionStatement) statement);
+ //usually newLine
+ } else if (statement instanceof IASTDeclarationStatement) {
+ writeDeclarationStatement((IASTDeclarationStatement) statement);
+ newLine = false;
+ } else if (statement instanceof IASTNullStatement) {
+ writeNullStatement((IASTNullStatement)statement);
+// usually newLine
+ } else if (statement instanceof IASTReturnStatement) {
+ writeReturnStatement((IASTReturnStatement)statement);
+// usually newLine
+ } else if (statement instanceof IASTGotoStatement) {
+ writeGotoStatement((IASTGotoStatement) statement);
+// usually newLine
+ } else if (statement instanceof IASTLabelStatement) {
+ writeLabelStatement((IASTLabelStatement) statement);
+ newLine = false;
+ } else if (statement instanceof IASTCaseStatement) {
+ writeCaseStatement((IASTCaseStatement) statement);
+// 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;
+ }
+ } else if (statement instanceof IASTBreakStatement) {
+ writeBreakStatement((IASTBreakStatement) statement);
+// usually newLine
+ } else if (statement instanceof IASTSwitchStatement) {
+ writeSwitchStatement((IASTSwitchStatement) statement);
+ newLine = false;
+ } else if (statement instanceof IASTIfStatement) {
+ writeIfStatement((IASTIfStatement) statement);
+ newLine = false;
+ } else if (statement instanceof IASTWhileStatement) {
+ writeWhileStatement( (IASTWhileStatement) statement );
+ newLine = false;
+ } else if (statement instanceof IASTForStatement) {
+ writeForStatement((IASTForStatement) statement);
+ newLine = false;
+ } else if (statement instanceof IASTDoStatement) {
+ writeDoStatement((IASTDoStatement) statement);
+ newLine = true;
+ } else if (statement instanceof ICPPASTTryBlockStatement) {
+ writeTryBlockStatement((ICPPASTTryBlockStatement) statement);
+ newLine = false;
+ } else if (statement instanceof ICPPASTCatchHandler) {
+ writeCatchHandler((ICPPASTCatchHandler) statement);
+ newLine = false;
+ } else if (statement instanceof IASTProblemStatement) {
+ throw new ProblemRuntimeException((IASTProblemStatement)statement);
+ }
+
+ if(hasTrailingComments(statement)) {
+ writeTrailingComments(statement, newLine);
+ }
+ else{
+ if(newLine){
+ scribe.newLine();
+ }
+ }
+
+ return ASTVisitor.PROCESS_SKIP;
+ }
+
+ private void writeDoStatement(IASTDoStatement doStatement) {
+ nextCompoundNoNewLine();
+
+ scribe.print(DO);
+ writeBodyStatement(doStatement.getBody(), true);
+ scribe.print(DO_WHILE);
+ doStatement.getCondition().accept(visitor);
+ scribe.print(')');
+ scribe.printSemicolon();
+ }
+
+ private void writeForStatement(IASTForStatement forStatment) {
+ scribe.noNewLines();
+ scribe.print(FOR);
+ writeStatement(forStatment.getInitializerStatement(),false);
+ if (forStatment instanceof ICPPASTForStatement) {
+ ICPPASTForStatement cppForStatment = (ICPPASTForStatement) forStatment;
+ IASTDeclaration cppConditionDeclaration = cppForStatment.getConditionDeclaration();
+ if(cppConditionDeclaration == null) {
+ visitNodeIfNotNull(cppForStatment.getConditionExpression());
+ scribe.printSemicolon();
+ } else {
+ cppConditionDeclaration.accept(visitor);
+ }
+
+ } else {
+ if(forStatment.getConditionExpression() != null) {
+ forStatment.getConditionExpression().accept(visitor);
+ scribe.printSemicolon();
+ }
+ }
+
+ visitNodeIfNotNull(forStatment.getIterationExpression());
+ scribe.print(')');
+ scribe.newLines();
+ nextCompoundNoNewLine();
+ writeBodyStatement(forStatment.getBody(), false);
+ }
+
+ private void writeIfStatement(IASTIfStatement ifStatement) {
+ scribe.print(IF);
+ scribe.noNewLines();
+ if (ifStatement instanceof ICPPASTIfStatement) {
+ ICPPASTIfStatement cppIfStatment = (ICPPASTIfStatement) ifStatement;
+
+ if(cppIfStatment.getConditionDeclaration() == null) {
+ cppIfStatment.getConditionExpression().accept(visitor);
+ } else {
+ writeDeclarationWithoutSemicolon(cppIfStatment.getConditionDeclaration());
+ }
+ } else {
+ ifStatement.getConditionExpression().accept(visitor);
+ }
+
+ scribe.print(')');
+ scribe.newLines();
+ nextCompoundNoNewLine();
+ IASTStatement elseClause = ifStatement.getElseClause();
+ writeBodyStatement(ifStatement.getThenClause(), elseClause != null ? true : false);
+
+ if(elseClause != null){
+ scribe.print(ELSE);
+ nextCompoundNoNewLine();
+ writeBodyStatement(elseClause, false);
+ }
+ }
+
+ protected void writeDeclarationWithoutSemicolon(
+ IASTDeclaration declaration) {
+ declWriter.writeDeclaration(declaration, false);
+ }
+
+ private void writeBreakStatement(IASTBreakStatement statement) {
+ scribe.print(BREAK);
+ scribe.printSemicolon();
+ }
+
+ private void writeContinueStatement(IASTContinueStatement statement) {
+ scribe.print(CONTINUE);
+ scribe.printSemicolon();
+ }
+
+ private void writeLabelStatement(IASTLabelStatement labelStatement) {
+ labelStatement.getName().accept(visitor);
+ scribe.print(':');
+ scribe.newLine();
+ labelStatement.getNestedStatement().accept(visitor);
+ }
+
+ private void writeGotoStatement(IASTGotoStatement gotoStatement) {
+ scribe.print(GOTO);
+ gotoStatement.getName().accept(visitor);
+ scribe.printSemicolon();
+ }
+
+ private void writeReturnStatement(IASTReturnStatement returnStatement) {
+ scribe.noNewLines();
+ scribe.print(RETURN);
+ IASTExpression returnValue = returnStatement.getReturnValue();
+ if(returnValue != null){
+ scribe.printSpaces(1);
+ returnValue.accept(visitor);
+ }
+ scribe.newLines();
+ scribe.printSemicolon();
+ }
+
+ private void writeNullStatement(IASTNullStatement nullStmt) {
+ scribe.printSemicolon();
+ }
+
+ private void writeDeclarationStatement(IASTDeclarationStatement decStmt) {
+ decStmt.getDeclaration().accept(visitor);
+ }
+
+ private void writeExpressionStatement(IASTExpressionStatement expStmt) {
+ expStmt.getExpression().accept(visitor);
+ scribe.printSemicolon();
+ }
+
+ private void writeCatchHandler(ICPPASTCatchHandler catchStatement) {
+ scribe.print(CATCH);
+ if (catchStatement.isCatchAll()) {
+ scribe.print(VAR_ARGS);
+ } else {
+ scribe.noSemicolon();
+ scribe.noNewLines();
+ catchStatement.getDeclaration().accept(visitor);
+ scribe.newLines();
+ }
+ scribe.print(')');
+ writeBodyStatement(catchStatement.getCatchBody(), true);
+ }
+
+ private void writeTryBlockStatement(ICPPASTTryBlockStatement tryStatement) {
+ scribe.print(TRY);
+ tryStatement.getTryBody().accept(visitor);
+ for (ICPPASTCatchHandler catchStatement : tryStatement.getCatchHandlers()) {
+ writeStatement(catchStatement, false);
+ }
+ }
+
+ private void writeWhileStatement(IASTWhileStatement whileStatment) {
+ scribe.print(WHILE);
+ scribe.noNewLines();
+ if (whileStatment instanceof ICPPASTWhileStatement) {
+ ICPPASTWhileStatement cppWhileStatment = (ICPPASTWhileStatement) whileStatment;
+ if(cppWhileStatment.getConditionDeclaration() == null) {
+ cppWhileStatment.getCondition().accept(visitor);
+ } else {
+ writeDeclarationWithoutSemicolon(cppWhileStatment.getConditionDeclaration());
+ }
+ } else {
+ whileStatment.getCondition().accept(visitor);
+ }
+ scribe.print(')');
+ scribe.newLines();
+ nextCompoundNoNewLine();
+ writeBodyStatement(whileStatment.getBody(), false);
+ }
+
+ private void writeCaseStatement(IASTCaseStatement caseStatement) {
+ nextCompoundIndentationLevelOneMore();
+
+ if(!switchIsNew){
+ scribe.decrementIndentationLevel();
+ }
+ scribe.print(CASE);
+ caseStatement.getExpression().accept(visitor);
+ scribe.print(':');
+ scribe.incrementIndentationLevel();
+ switchIsNew = false;
+ }
+
+ private void writeSwitchStatement(IASTSwitchStatement switchStatement) {
+ switchIsNew = true;
+
+ scribe.print(SWITCH_BRACKET);
+ scribe.noNewLines();
+ if (switchStatement instanceof ICPPASTSwitchStatement) {
+ ICPPASTSwitchStatement cppSwitchStatement = (ICPPASTSwitchStatement) switchStatement;
+ if(cppSwitchStatement.getControllerDeclaration() == null) {
+ cppSwitchStatement.getControllerExpression().accept(visitor);
+ } else {
+ declWriter.writeDeclaration(cppSwitchStatement.getControllerDeclaration(), false);
+ }
+ } else {
+ switchStatement.getControllerExpression().accept(visitor);
+ }
+ scribe.print(')');
+ scribe.newLines();
+ nextCompoundNoNewLine();
+ writeBodyStatement(switchStatement.getBody(), false);
+
+ switchIsNew = false;
+ }
+
+ private void writeDefaultStatement(IASTDefaultStatement defaultStatement) {
+ nextCompoundIndentationLevelOneMore();
+
+ if(!switchIsNew){
+ scribe.decrementIndentationLevel();
+ }
+ scribe.print(DEFAULT);
+ scribe.incrementIndentationLevel();
+ switchIsNew = false;
+ }
+
+ private void writeCompoundStatement(IASTCompoundStatement compoundStatement) {
+ scribe.printLBrace();
+ scribe.newLine();
+ for (IASTStatement statements : compoundStatement.getStatements()) {
+ statements.accept(visitor);
+ }
+
+ if(hasFreestandingComments(compoundStatement)) {
+ writeFreeStandingComments(compoundStatement);
+ }
+
+ if(decrementIndentationLevelOneMore){
+ scribe.decrementIndentationLevel();
+ decrementIndentationLevelOneMore = false;
+ }
+ scribe.printRBrace();
+ }
+
+ protected void writeBodyStatement(IASTStatement statement, boolean isDoStatement) {
+ if (statement instanceof IASTCompoundStatement){
+ //TODO hsr existiert noch eine methode
+ statement.accept(visitor);
+ if(!isDoStatement){
+ scribe.newLine();
+ }
+ compoundNoNewLine = false;
+ } else if (statement instanceof IASTNullStatement){
+ statement.accept(visitor);
+ scribe.newLine();
+ } else {
+ scribe.incrementIndentationLevel();
+ scribe.newLine();
+ statement.accept(visitor);
+ scribe.decrementIndentationLevel();
+ scribe.newLine();
+ }
+ }
+
+ /**
+ * 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
+ *
+ */
+ protected void nextCompoundIndentationLevelOneMore(){
+ decrementIndentationLevelOneMore = true;
+ }
+
+ protected int writeMixedStatement(IASTStatement statement) {
+ IFile file = FileHelper.getIFilefromIASTNode(statement);
+ int offset = statement.getFileLocation().getNodeOffset();
+ int length = statement.getFileLocation().getNodeLength();
+ 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/astwriter/TemplateParameterWriter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/TemplateParameterWriter.java
new file mode 100644
index 00000000000..967d949a50d
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/TemplateParameterWriter.java
@@ -0,0 +1,91 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.internal.core.dom.rewrite.astwriter;
+
+import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
+import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTParameterDeclaration;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleTypeTemplateParameter;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateParameter;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplatedTypeTemplateParameter;
+import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap;
+
+/**
+ * @author Emanuel Graf
+ *
+ */
+public class TemplateParameterWriter extends NodeWriter {
+
+ private static final String GREATER_THAN_CLASS = "> class"; //$NON-NLS-1$
+ private static final String TEMPLATE_LESS_THAN = "template <"; //$NON-NLS-1$
+
+
+
+ /**
+ * @param scribe
+ * @param visitor
+ */
+ public TemplateParameterWriter(Scribe scribe, CPPASTVisitor visitor, NodeCommentMap commentMap) {
+ super(scribe, visitor, commentMap);
+ }
+
+ protected void writeTemplateParameter(ICPPASTTemplateParameter parameter) {
+ if (parameter instanceof ICPPASTParameterDeclaration) {
+ ((IASTParameterDeclaration)((ICPPASTParameterDeclaration) parameter)).accept(visitor);
+ } else if (parameter instanceof ICPPASTSimpleTypeTemplateParameter) {
+ writeSimpleTypeTemplateParameter((ICPPASTSimpleTypeTemplateParameter) parameter);
+ } else if (parameter instanceof ICPPASTTemplatedTypeTemplateParameter) {
+ writeTemplatedTypeTemplateParameter((ICPPASTTemplatedTypeTemplateParameter) parameter);
+ }
+ }
+
+
+ private void writeTemplatedTypeTemplateParameter(ICPPASTTemplatedTypeTemplateParameter templated) {
+ scribe.print(TEMPLATE_LESS_THAN);
+
+
+ ICPPASTTemplateParameter[] params = templated.getTemplateParameters();
+ writeNodeList(params);
+
+ scribe.print(GREATER_THAN_CLASS);
+
+ if(templated.getName()!=null){
+ scribe.printSpace();
+ templated.getName().accept(visitor);
+ }
+
+ if(templated.getDefaultValue() != null){
+ scribe.print(EQUALS);
+ templated.getDefaultValue().accept(visitor);
+ }
+ }
+
+
+
+ private void writeSimpleTypeTemplateParameter(ICPPASTSimpleTypeTemplateParameter simple) {
+ switch (simple.getParameterType()) {
+ case ICPPASTSimpleTypeTemplateParameter.st_class:
+ scribe.print(CLASS_SPACE);
+ break;
+ case ICPPASTSimpleTypeTemplateParameter.st_typename:
+ scribe.print(TYPENAME);
+ break;
+ }
+
+ visitNodeIfNotNull(simple.getName());
+
+ if(simple.getDefaultType() != null){
+ scribe.print(EQUALS);
+ simple.getDefaultType().accept(visitor);
+ }
+ }
+}
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
new file mode 100644
index 00000000000..9ffbc001c6f
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/ASTModificationHelper.java
@@ -0,0 +1,146 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.internal.core.dom.rewrite.changegenerator;
+
+import java.lang.reflect.Array;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
+import org.eclipse.cdt.core.dom.ast.IASTInitializer;
+import org.eclipse.cdt.core.dom.ast.IASTNode;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationMap;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind;
+import org.eclipse.cdt.internal.core.dom.rewrite.astwriter.ContainerNode;
+
+public class ASTModificationHelper {
+
+ private final ASTModificationStore modificationStore;
+
+ public ASTModificationHelper(ASTModificationStore modificationStore) {
+ this.modificationStore = modificationStore;
+ }
+
+
+ @SuppressWarnings("unchecked")
+ public <T extends IASTNode> T[] createModifiedChildArray(IASTNode parent, T[] unmodifiedChildren){
+ ArrayList<T> modifiedChildren = new ArrayList<T>(Arrays.asList(unmodifiedChildren));
+ for(T currentChild : unmodifiedChildren){
+ for(ASTModification childModification : modificationsForNode(currentChild)){
+ try{
+ T newNode = (T) childModification.getNewNode();
+ switch(childModification.getKind()){
+ case REPLACE:
+ if(childModification.getNewNode() != null){
+ modifiedChildren.add(modifiedChildren.indexOf(childModification.getTargetNode()), newNode);
+ }
+ modifiedChildren.remove(childModification.getTargetNode());
+ break;
+ case INSERT_BEFORE:
+ modifiedChildren.add(modifiedChildren.indexOf(childModification.getTargetNode()), newNode);
+ break;
+ case APPEND_CHILD:
+ throw new UnhandledASTModificationException(childModification);
+
+ }
+ }catch(ClassCastException e){
+ throw new UnhandledASTModificationException(childModification);
+ }
+ }
+ }
+
+ Class<?> componentType = unmodifiedChildren.getClass().getComponentType();
+ for(ASTModification parentModification : modificationsForNode(parent)){
+ if(parentModification.getKind() == ModificationKind.APPEND_CHILD){
+ IASTNode newNode = parentModification.getNewNode();
+ if(componentType.isAssignableFrom(newNode.getClass())){
+ modifiedChildren.add((T) newNode);
+ }
+ else if(newNode instanceof ContainerNode){
+ ContainerNode nodeContainer = (ContainerNode) newNode;
+ for(IASTNode currentNode : nodeContainer.getNodes()){
+ if(componentType.isAssignableFrom(currentNode.getClass())){
+ modifiedChildren.add((T)currentNode);
+ }
+ }
+ }
+ }
+ }
+
+ return modifiedChildren.toArray((T[]) Array.newInstance(componentType, 0));
+ }
+
+ public List<ASTModification> modificationsForNode(
+ IASTNode targetNode) {
+ ASTModificationMap rootModifications = modificationStore.getRootModifications();
+ if(rootModifications == null){
+ rootModifications = new ASTModificationMap();
+ }
+ List<ASTModification> modificationsForNode = rootModifications.getModificationsForNode(targetNode);
+ return modificationsForNode;
+ }
+
+
+ public IASTInitializer getInitializer(IASTDeclarator decl) {
+ IASTInitializer initializer = decl.getInitializer();
+
+ if(initializer != null){
+ for(ASTModification childModification : modificationsForNode(initializer)){
+ switch(childModification.getKind()){
+ case REPLACE:
+ if(childModification.getNewNode() instanceof IASTInitializer){
+ return (IASTInitializer)childModification.getNewNode();
+ }
+ throw new UnhandledASTModificationException(childModification);
+
+ case INSERT_BEFORE:
+ throw new UnhandledASTModificationException(childModification);
+
+ case APPEND_CHILD:
+ throw new UnhandledASTModificationException(childModification);
+ }
+ }
+ }
+ else
+ {
+ for(ASTModification parentModification : modificationsForNode(decl)){
+ if(parentModification.getKind() == ModificationKind.APPEND_CHILD){
+ IASTNode newNode = parentModification.getNewNode();
+ if(newNode instanceof IASTInitializer){
+ return (IASTInitializer) newNode;
+ }
+ }
+ }
+ }
+ 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){
+ return (T) currentModification.getNewNode();
+ }
+ }
+ catch(ClassCastException e){
+ throw new UnhandledASTModificationException(currentModification);
+ }
+ }
+ return replacedNode;
+ }
+}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/CTextFileChange.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/CTextFileChange.java
new file mode 100644
index 00000000000..1c4cf31bb4d
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/CTextFileChange.java
@@ -0,0 +1,223 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.internal.core.dom.rewrite.changegenerator;
+
+import java.util.List;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.ltk.core.refactoring.Change;
+import org.eclipse.ltk.core.refactoring.ChangeDescriptor;
+import org.eclipse.ltk.core.refactoring.RefactoringStatus;
+import org.eclipse.ltk.core.refactoring.TextEditBasedChangeGroup;
+import org.eclipse.ltk.core.refactoring.TextEditChangeGroup;
+import org.eclipse.ltk.core.refactoring.TextFileChange;
+import org.eclipse.text.edits.MalformedTreeException;
+import org.eclipse.text.edits.TextEdit;
+import org.eclipse.text.edits.TextEditGroup;
+
+/**
+ * @author Emanuel Graf
+ *
+ */
+public class CTextFileChange extends Change {
+
+ private TextFileChange change;
+
+ /**
+ * @param name
+ * @param file
+ */
+ public CTextFileChange(String name, IFile file) {
+ change = new TextFileChange(name, file);
+ }
+
+ @Override
+ public Object getModifiedElement() {
+ return change.getModifiedElement();
+ }
+
+ @Override
+ public String getName() {
+ return change.getName();
+ }
+
+ @Override
+ public void initializeValidationData(IProgressMonitor pm) {
+ change.initializeValidationData(pm);
+ }
+
+ @Override
+ public Change perform(IProgressMonitor pm) throws CoreException {
+ return change.perform(pm);
+ }
+
+ public void setEdit(TextEdit edit) {
+ change.setEdit(edit);
+ }
+
+ public TextEdit getEdit() {
+ return change.getEdit();
+ }
+
+ public void addTextEditGroup(TextEditBasedChangeGroup group) {
+ change.addChangeGroup(group);
+ }
+
+ public String getCurrentContent(IProgressMonitor pm) throws CoreException{
+ return change.getCurrentContent(pm);
+ }
+
+ public String getPreviewContent(IProgressMonitor pm) throws CoreException{
+ return change.getPreviewContent(pm);
+ }
+ public String getTextType() {
+ return change.getTextType();
+ }
+
+ public IFile getFile() {
+ return change.getFile();
+ }
+
+ public void addChangeGroup(TextEditBasedChangeGroup group) {
+ change.addChangeGroup(group);
+ }
+
+ public void addEdit(TextEdit edit) throws MalformedTreeException {
+ change.addEdit(edit);
+ }
+
+ public void addTextEditChangeGroup(TextEditChangeGroup group) {
+ change.addTextEditChangeGroup(group);
+ }
+
+ public void addTextEditGroup(TextEditGroup group) {
+ change.addTextEditGroup(group);
+ }
+
+ @Override
+ public void dispose() {
+ change.dispose();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ return change.equals(obj);
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public Object getAdapter(Class adapter) {
+ return change.getAdapter(adapter);
+ }
+
+ @Override
+ public Object[] getAffectedObjects() {
+ return change.getAffectedObjects();
+ }
+
+ public String getCurrentContent(IRegion region, boolean expandRegionToFullLine, int surroundingLines, IProgressMonitor pm) throws CoreException {
+ return change.getCurrentContent(region, expandRegionToFullLine, surroundingLines, pm);
+ }
+
+ public IDocument getCurrentDocument(IProgressMonitor pm) throws CoreException {
+ return change.getCurrentDocument(pm);
+ }
+
+ @Override
+ public ChangeDescriptor getDescriptor() {
+ return change.getDescriptor();
+ }
+
+ public boolean getKeepPreviewEdits() {
+ return change.getKeepPreviewEdits();
+ }
+
+ @Override
+ public Change getParent() {
+ return change.getParent();
+ }
+
+ public String getPreviewContent(TextEditBasedChangeGroup[] changeGroups, IRegion region, boolean expandRegionToFullLine, int surroundingLines, IProgressMonitor pm) throws CoreException {
+ return change.getPreviewContent(changeGroups, region, expandRegionToFullLine, surroundingLines, pm);
+ }
+
+ public String getPreviewContent(TextEditChangeGroup[] changeGroups, IRegion region, boolean expandRegionToFullLine, int surroundingLines, IProgressMonitor pm) throws CoreException {
+ return change.getPreviewContent(changeGroups, region, expandRegionToFullLine, surroundingLines, pm);
+ }
+
+ public IDocument getPreviewDocument(IProgressMonitor pm) throws CoreException {
+ return change.getPreviewDocument(pm);
+ }
+
+ public TextEdit getPreviewEdit(TextEdit original) {
+ return change.getPreviewEdit(original);
+ }
+
+ public TextEdit[] getPreviewEdits(TextEdit[] originals) {
+ return change.getPreviewEdits(originals);
+ }
+
+ public int getSaveMode() {
+ return change.getSaveMode();
+ }
+
+ public TextEditChangeGroup[] getTextEditChangeGroups() {
+ return change.getTextEditChangeGroups();
+ }
+
+ @Override
+ public int hashCode() {
+ return change.hashCode();
+ }
+
+ @SuppressWarnings("unchecked")
+ public boolean hasOneGroupCategory(List groupCategories) {
+ return change.hasOneGroupCategory(groupCategories);
+ }
+
+ @Override
+ public boolean isEnabled() {
+ return change.isEnabled();
+ }
+
+ @Override
+ public RefactoringStatus isValid(IProgressMonitor pm) throws CoreException {
+ return change.isValid(pm);
+ }
+
+ @Override
+ public void setEnabled(boolean enabled) {
+ change.setEnabled(enabled);
+ }
+
+ public void setKeepPreviewEdits(boolean keep) {
+ change.setKeepPreviewEdits(keep);
+ }
+
+ public void setSaveMode(int saveMode) {
+ change.setSaveMode(saveMode);
+ }
+
+ public void setTextType(String type) {
+ change.setTextType(type);
+ }
+
+ @Override
+ public String toString() {
+ return change.toString();
+ }
+
+}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/ChangeGenerator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/ChangeGenerator.java
new file mode 100644
index 00000000000..c792011b218
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/ChangeGenerator.java
@@ -0,0 +1,566 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.internal.core.dom.rewrite.changegenerator;
+
+import java.util.LinkedHashMap;
+import java.util.List;
+
+import org.eclipse.cdt.core.dom.ast.ASTVisitor;
+import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
+import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
+import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
+import org.eclipse.cdt.core.dom.ast.IASTExpression;
+import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
+import org.eclipse.cdt.core.dom.ast.IASTInitializer;
+import org.eclipse.cdt.core.dom.ast.IASTName;
+import org.eclipse.cdt.core.dom.ast.IASTNode;
+import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
+import org.eclipse.cdt.core.dom.ast.IASTStatement;
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
+import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationMap;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
+import org.eclipse.cdt.internal.core.dom.rewrite.astwriter.ASTWriter;
+import org.eclipse.cdt.internal.core.dom.rewrite.astwriter.ProblemRuntimeException;
+import org.eclipse.cdt.internal.core.dom.rewrite.util.FileContentHelper;
+import org.eclipse.cdt.internal.core.dom.rewrite.util.FileHelper;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.ltk.core.refactoring.Change;
+import org.eclipse.ltk.core.refactoring.CompositeChange;
+import org.eclipse.text.edits.DeleteEdit;
+import org.eclipse.text.edits.InsertEdit;
+import org.eclipse.text.edits.MultiTextEdit;
+import org.eclipse.text.edits.ReplaceEdit;
+import org.eclipse.text.edits.TextEditGroup;
+
+public class ChangeGenerator extends CPPASTVisitor {
+
+ private final LinkedHashMap<String, Integer> sourceOffsets = new LinkedHashMap<String, Integer>();
+ public LinkedHashMap<IASTNode, List<ASTModification>> modificationParent = new LinkedHashMap<IASTNode, List<ASTModification>>();
+ private final LinkedHashMap<IFile, MultiTextEdit> changes = new LinkedHashMap<IFile, MultiTextEdit>();
+ private CompositeChange change;
+
+ private final ASTModificationStore modificationStore;
+
+ {
+ shouldVisitExpressions = true;
+
+ shouldVisitStatements = true;
+
+ shouldVisitNames = true;
+
+ shouldVisitDeclarations = true;
+
+ shouldVisitDeclSpecifiers = true;
+
+ shouldVisitDeclarators = true;
+
+ shouldVisitInitializers = true;
+
+ shouldVisitBaseSpecifiers = true;
+
+ shouldVisitNamespaces = true;
+
+ shouldVisitTemplateParameters = true;
+
+ shouldVisitParameterDeclarations = true;
+
+ shouldVisitTranslationUnit = true;
+
+ }
+
+ public ChangeGenerator(ASTModificationStore modificationStore) {
+ this.modificationStore = modificationStore;
+
+ }
+
+ public void generateChange(IASTNode rootNode) throws ProblemRuntimeException {
+ generateChange(rootNode, this);
+ }
+
+ public void generateChange(IASTNode rootNode, CPPASTVisitor pathProvider)
+ throws ProblemRuntimeException {
+ change = new CompositeChange(Messages.ChangeGenerator_compositeChange);
+ initParentModList();
+ rootNode.accept(pathProvider);
+ for (IFile currentFile : changes.keySet()) {
+
+ CTextFileChange subchange = new CTextFileChange(currentFile
+ .getName(), currentFile);
+ subchange.setEdit(changes.get(currentFile));
+ change.add(subchange);
+ }
+ }
+
+ private void initParentModList() {
+ ASTModificationMap rootModifications = modificationStore
+ .getRootModifications();
+ if (rootModifications != null) {
+ for (IASTNode modifiedNode : rootModifications.getModifiedNodes()) {
+ List<ASTModification> modificationsForNode = rootModifications
+ .getModificationsForNode(modifiedNode);
+ modificationParent.put(modifiedNode.getParent(),
+ modificationsForNode);
+ }
+ }
+ }
+
+ @Override
+ public int visit(IASTTranslationUnit translationUnit) {
+ if (hasChangedChild(translationUnit)) {
+
+ synthTreatment(translationUnit);
+ }
+ sourceOffsets.put(translationUnit.getFileLocation().getFileName(),
+ Integer.valueOf(translationUnit.getFileLocation().getNodeOffset()));
+ return super.visit(translationUnit);
+ }
+
+ @Override
+ public int leave(IASTTranslationUnit tu) {
+
+ return super.leave(tu);
+ }
+
+ private int getOffsetForNodeFile(IASTNode rootNode) {
+
+ Integer offset = sourceOffsets.get(rootNode.getFileLocation()
+ .getFileName());
+ return offset == null ? 0 : offset.intValue();
+ }
+
+ @Override
+ public int visit(IASTDeclaration declaration) {
+ if (hasChangedChild(declaration)) {
+ synthTreatment(declaration);
+ return ASTVisitor.PROCESS_SKIP;
+ }
+ return super.visit(declaration);
+ }
+
+ private void synthTreatment(IASTNode synthNode) {
+ synthTreatment(synthNode, null);
+ }
+
+ private void synthTreatment(IASTNode synthNode, String fileScope) {
+
+ String indent = getIndent(synthNode);
+ ASTWriter synthWriter = new ASTWriter(indent);
+ synthWriter.setModificationStore(modificationStore);
+ String synthSource = synthWriter.write(synthNode);
+ reformatSynthCode(synthNode, synthSource); /*XXX resultat wird nicht verwendet?*/
+
+
+ int newOffset = synthNode.getFileLocation().getNodeOffset()
+ + synthNode.getFileLocation().getNodeLength();
+ sourceOffsets.put(synthNode.getFileLocation().getFileName(), Integer.valueOf(newOffset));
+
+ }
+
+ private void synthTreatment(IASTTranslationUnit synthTU) {
+ ASTWriter synthWriter = new ASTWriter();
+ synthWriter.setModificationStore(modificationStore);
+
+ for (ASTModification modification : modificationParent.get(synthTU)) {
+ IASTFileLocation targetLocation = modification.getTargetNode()
+ .getFileLocation();
+ String currentFile = targetLocation.getFileName();
+ IPath implPath = new Path(currentFile);
+ IFile relevantFile = ResourcesPlugin.getWorkspace().getRoot()
+ .getFileForLocation(implPath);
+ MultiTextEdit edit;
+ if (changes.containsKey(relevantFile)) {
+ edit = changes.get(relevantFile);
+ } else {
+ edit = new MultiTextEdit();
+ changes.put(relevantFile, edit);
+ }
+
+ String newNodeCode = synthWriter.write(modification.getNewNode());
+ switch (modification.getKind()) {
+ case REPLACE:
+ edit.addChild(new ReplaceEdit(targetLocation.getNodeOffset(),
+ targetLocation.getNodeLength(), newNodeCode));
+ break;
+ case INSERT_BEFORE:
+ edit.addChild(new InsertEdit(targetLocation.getNodeOffset(),
+ newNodeCode));
+ break;
+ case APPEND_CHILD:
+ edit.addChild(new InsertEdit(targetLocation.getNodeOffset()
+ + targetLocation.getNodeLength(), newNodeCode));
+ break;
+ }
+ }
+ }
+
+ private String reformatSynthCode(IASTNode synthNode, String synthSource) {
+ IFile relevantFile = FileHelper.getIFilefromIASTNode(synthNode);
+ StringBuilder formattedCode = new StringBuilder();
+
+ String originalCode = originalCodeOfNode(synthNode);
+ CodeComparer codeComparer = new CodeComparer(originalCode, synthSource);
+
+ int lastCommonPositionInOriginalCode = codeComparer
+ .getLastCommonPositionInOriginalCode();
+ if (lastCommonPositionInOriginalCode > -1) {
+ formattedCode.append(originalCode.substring(0,
+ lastCommonPositionInOriginalCode + 1));
+ }
+
+ int lastCommonPositionInSynthCode = codeComparer
+ .getLastCommonPositionInSynthCode();
+ int firstPositionOfCommonEndInSynthCode = codeComparer
+ .getFirstPositionOfCommonEndInSynthCode(lastCommonPositionInSynthCode);
+
+ int firstPositionOfCommonEndInOriginalCode = codeComparer
+ .getFirstPositionOfCommonEndInOriginalCode(lastCommonPositionInSynthCode);
+ if (firstPositionOfCommonEndInSynthCode == -1) {
+ formattedCode.append(synthSource
+ .substring(lastCommonPositionInSynthCode + 1));
+ } else {
+ if (lastCommonPositionInSynthCode + 1 < firstPositionOfCommonEndInSynthCode) {
+ formattedCode.append(synthSource.substring(
+ lastCommonPositionInSynthCode + 1,
+ firstPositionOfCommonEndInSynthCode));
+ }
+ }
+
+ if (firstPositionOfCommonEndInOriginalCode > -1) {
+ formattedCode.append(originalCode
+ .substring(firstPositionOfCommonEndInOriginalCode));
+ }
+
+ MultiTextEdit edit;
+ if (changes.containsKey(relevantFile)) {
+ edit = changes.get(relevantFile);
+ } else {
+ edit = new MultiTextEdit();
+ changes.put(relevantFile, edit);
+ }
+
+ codeComparer.createChange(edit, synthNode);
+
+ return formattedCode.toString();
+ }
+
+ public static String originalCodeOfNode(IASTNode node) {
+ if (node.getFileLocation() != null) {
+ IFile sourceFile = FileHelper.getIFilefromIASTNode(node);
+ int nodeOffset = node.getFileLocation().getNodeOffset();
+ int nodeLength = node.getFileLocation().getNodeLength();
+ return FileContentHelper.getContent(sourceFile, nodeOffset,
+ nodeLength);
+ }
+ return null;
+ }
+
+ private String getIndent(IASTNode nextNode) {
+ IASTFileLocation fileLocation = nextNode.getFileLocation();
+ int length = fileLocation.getNodeOffset()
+ - getOffsetForNodeFile(nextNode);
+
+ String originalSource = FileContentHelper.getContent(FileHelper
+ .getIFilefromIASTNode(nextNode),
+ getOffsetForNodeFile(nextNode), length);
+ StringBuilder indent = new StringBuilder(originalSource);
+ indent.reverse();
+ String lastline = indent
+ .substring(0, Math.max(indent.indexOf("\n"), 0)); //$NON-NLS-1$
+ if (lastline.trim().length() == 0) {
+ return lastline;
+ }
+ return ""; //$NON-NLS-1$
+ }
+
+ private boolean hasChangedChild(IASTNode parent) {
+
+ return modificationParent.containsKey(parent);
+ }
+
+ @Override
+ public int visit(IASTDeclarator declarator) {
+ if (hasChangedChild(declarator)) {
+ synthTreatment(declarator);
+ return ASTVisitor.PROCESS_SKIP;
+ }
+ return super.visit(declarator);
+ }
+
+ @Override
+ public int visit(IASTDeclSpecifier declSpec) {
+ if (hasChangedChild(declSpec)) {
+ synthTreatment(declSpec);
+ return ASTVisitor.PROCESS_SKIP;
+ }
+ return super.visit(declSpec);
+ }
+
+ @Override
+ public int visit(IASTExpression expression) {
+ if (hasChangedChild(expression)) {
+ synthTreatment(expression);
+ return ASTVisitor.PROCESS_SKIP;
+ }
+ return super.visit(expression);
+ }
+
+ @Override
+ public int visit(IASTInitializer initializer) {
+ if (hasChangedChild(initializer)) {
+ synthTreatment(initializer);
+ return ASTVisitor.PROCESS_SKIP;
+ }
+ return super.visit(initializer);
+ }
+
+ @Override
+ public int visit(IASTName name) {
+ if (hasChangedChild(name)) {
+ synthTreatment(name);
+ return ASTVisitor.PROCESS_SKIP;
+ }
+ return super.visit(name);
+ }
+
+ @Override
+ public int visit(IASTParameterDeclaration parameterDeclaration) {
+ if (hasChangedChild(parameterDeclaration)) {
+ synthTreatment(parameterDeclaration);
+ return ASTVisitor.PROCESS_SKIP;
+ }
+ return super.visit(parameterDeclaration);
+ }
+
+ @Override
+ public int visit(IASTStatement statement) {
+ if (hasChangedChild(statement)) {
+ synthTreatment(statement);
+ return ASTVisitor.PROCESS_SKIP;
+ }
+ return super.visit(statement);
+ }
+
+ class CodeComparer {
+
+ private final StringBuilder originalCode;
+ private final StringBuilder synthCode;
+
+ public CodeComparer(String originalCode, String synthCode) {
+ this.originalCode = new StringBuilder(originalCode);
+ this.synthCode = new StringBuilder(synthCode);
+ }
+
+ public int getLastCommonPositionInSynthCode() {
+
+ int lastCommonPosition = -1;
+ int originalCodePosition = -1;
+ int synthCodePosition = -1;
+
+ do {
+ lastCommonPosition = synthCodePosition;
+ originalCodePosition = nextInterrestingPosition(originalCode,
+ originalCodePosition);
+ synthCodePosition = nextInterrestingPosition(synthCode,
+ synthCodePosition);
+ } while (originalCodePosition > -1
+ && synthCodePosition > -1
+ && originalCode.charAt(originalCodePosition) == synthCode
+ .charAt(synthCodePosition));
+
+ return lastCommonPosition;
+ }
+
+ public int getLastCommonPositionInOriginalCode() {
+
+ int lastCommonPosition = -1;
+ int originalCodePosition = -1;
+ int synthCodePosition = -1;
+
+ do {
+ lastCommonPosition = originalCodePosition;
+ originalCodePosition = nextInterrestingPosition(originalCode,
+ originalCodePosition);
+ synthCodePosition = nextInterrestingPosition(synthCode,
+ synthCodePosition);
+ } while (originalCodePosition > -1
+ && synthCodePosition > -1
+ && originalCode.charAt(originalCodePosition) == synthCode
+ .charAt(synthCodePosition));
+
+ return lastCommonPosition;
+ }
+
+ public int getFirstPositionOfCommonEndInOriginalCode(int limmit) {
+
+ int lastCommonPosition = -1;
+ int originalCodePosition = -1;
+ int synthCodePosition = -1;
+
+ StringBuilder reverseOriginalCode = new StringBuilder(originalCode)
+ .reverse();
+ StringBuilder reverseSynthCode = new StringBuilder(synthCode)
+ .reverse();
+
+ do {
+ lastCommonPosition = originalCodePosition;
+ originalCodePosition = nextInterrestingPosition(
+ reverseOriginalCode, originalCodePosition);
+ synthCodePosition = nextInterrestingPosition(reverseSynthCode,
+ synthCodePosition);
+ } while (originalCodePosition > -1
+ && synthCodePosition > -1
+ && synthCodePosition < synthCode.length() - limmit
+ && reverseOriginalCode.charAt(originalCodePosition) == reverseSynthCode
+ .charAt(synthCodePosition));
+
+ if (lastCommonPosition < 0
+ || lastCommonPosition >= originalCode.length()) {
+ return -1;
+ }
+
+ return originalCode.length() - lastCommonPosition;
+ }
+
+ public int getFirstPositionOfCommonEndInSynthCode(int limmit) {
+
+ int lastCommonPosition = -1;
+ int originalCodePosition = -1;
+ int synthCodePosition = -1;
+
+ StringBuilder reverseOriginalCode = new StringBuilder(originalCode)
+ .reverse();
+ StringBuilder reverseSynthCode = new StringBuilder(synthCode)
+ .reverse();
+
+ do {
+ lastCommonPosition = synthCodePosition;
+ originalCodePosition = nextInterrestingPosition(
+ reverseOriginalCode, originalCodePosition);
+ synthCodePosition = nextInterrestingPosition(reverseSynthCode,
+ synthCodePosition);
+ } while (originalCodePosition > -1
+ && synthCodePosition > -1
+ && synthCodePosition < synthCode.length() - limmit
+ && reverseOriginalCode.charAt(originalCodePosition) == reverseSynthCode
+ .charAt(synthCodePosition));
+
+ if (lastCommonPosition < 0
+ || lastCommonPosition >= synthCode.length()) {
+ return -1;
+ }
+
+ return synthCode.length() - lastCommonPosition;
+ }
+
+ private int nextInterrestingPosition(StringBuilder code, int position) {
+ do {
+ position++;
+ if (position >= code.length()) {
+ return -1;
+ }
+ } while (isUninterresting(code, position));
+ return position;
+ }
+
+ private boolean isUninterresting(StringBuilder code, int position) {
+ switch (code.charAt(position)) {
+ case ' ':
+ case '\n':
+ case '\r':
+ case '\t':
+ return true;
+
+ default:
+ return false;
+ }
+ }
+
+ protected void createChange(MultiTextEdit edit, IASTNode changedNode) {
+ int changeOffset = changedNode.getFileLocation().getNodeOffset();
+
+ TextEditGroup editGroup = new TextEditGroup(Messages.ChangeGenerator_group);
+ for (ASTModification currentModification : modificationParent
+ .get(changedNode)) {
+ if (currentModification.getAssociatedEditGroup() != null) {
+ editGroup = currentModification.getAssociatedEditGroup();
+ edit.addChildren(editGroup.getTextEdits());
+ break;
+ }
+ }
+
+ createChange(edit, changeOffset);
+ }
+
+ private void createChange(MultiTextEdit edit, int changeOffset) {
+
+ int lastCommonPositionInSynth = getLastCommonPositionInSynthCode();
+ int firstOfCommonEndInOriginal = getFirstPositionOfCommonEndInOriginalCode(lastCommonPositionInSynth);
+ int lastCommonPositionInOriginal = getLastCommonPositionInOriginalCode();
+ int firstOfCommonEndInSynth = getFirstPositionOfCommonEndInSynthCode(lastCommonPositionInSynth);
+
+ if ((firstOfCommonEndInSynth >= 0 ? firstOfCommonEndInOriginal
+ : originalCode.length())
+ - lastCommonPositionInOriginal <= 0) {
+ String insertCode = synthCode.substring(
+ lastCommonPositionInSynth, firstOfCommonEndInSynth + 1);
+ InsertEdit iEdit = new InsertEdit(changeOffset
+ + lastCommonPositionInOriginal, insertCode);
+ edit.addChild(iEdit);
+ } else if ((firstOfCommonEndInSynth >= 0 ? firstOfCommonEndInSynth
+ : synthCode.length())
+ - lastCommonPositionInSynth <= 0) {
+ int correction = 0;
+ if (lastCommonPositionInSynth > firstOfCommonEndInSynth) {
+ correction = lastCommonPositionInSynth
+ - firstOfCommonEndInSynth;
+ }
+ DeleteEdit dEdit = new DeleteEdit(changeOffset
+ + lastCommonPositionInOriginal,
+ firstOfCommonEndInOriginal
+ - lastCommonPositionInOriginal + correction);
+ edit.addChild(dEdit);
+ } else {
+ String replacementCode = getReplacementCode(
+ lastCommonPositionInSynth, firstOfCommonEndInSynth);
+ ReplaceEdit rEdit = new ReplaceEdit(
+ changeOffset
+ + Math.max(lastCommonPositionInOriginal, 0),
+ (firstOfCommonEndInOriginal >= 0 ? firstOfCommonEndInOriginal
+ : originalCode.length())
+ - Math.max(lastCommonPositionInOriginal, 0),
+ replacementCode);
+ edit.addChild(rEdit);
+ }
+ }
+
+ private String getReplacementCode(int lastCommonPositionInSynth,
+ int firstOfCommonEndInSynth) {
+ int replacementStart = Math.max(lastCommonPositionInSynth, 0);
+ int replacementEnd = (firstOfCommonEndInSynth >= 0 ? firstOfCommonEndInSynth
+ : synthCode.length());
+ if (replacementStart < replacementEnd) {
+ return synthCode.substring(replacementStart, replacementEnd);
+ } else {
+ return ""; //$NON-NLS-1$
+ }
+ }
+ }
+
+ public Change getChange() {
+ return change;
+ }
+}
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
new file mode 100644
index 00000000000..2dd900aa110
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/ChangeGeneratorWriterVisitor.java
@@ -0,0 +1,378 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.internal.core.dom.rewrite.changegenerator;
+
+import java.util.List;
+
+import org.eclipse.cdt.core.dom.ast.IASTComment;
+import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
+import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
+import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
+import org.eclipse.cdt.core.dom.ast.IASTExpression;
+import org.eclipse.cdt.core.dom.ast.IASTInitializer;
+import org.eclipse.cdt.core.dom.ast.IASTName;
+import org.eclipse.cdt.core.dom.ast.IASTNode;
+import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
+import org.eclipse.cdt.core.dom.ast.IASTProblem;
+import org.eclipse.cdt.core.dom.ast.IASTStatement;
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
+import org.eclipse.cdt.core.dom.ast.IASTTypeId;
+import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator;
+import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateParameter;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationMap;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
+import org.eclipse.cdt.internal.core.dom.rewrite.astwriter.ASTWriterVisitor;
+import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap;
+
+public class ChangeGeneratorWriterVisitor extends ASTWriterVisitor {
+
+ private static final String DEFAULT_INDENTATION = ""; //$NON-NLS-1$
+ private final ASTModificationStore modificationStore;
+ private ASTModificationMap modificationsForScope;
+ private final String fileScope;
+
+ public ChangeGeneratorWriterVisitor(CPPASTVisitor delegateVisitor,
+ ASTModificationStore modificationStore, String fileScope, NodeCommentMap commentMap) {
+ super(commentMap);
+
+ this.modificationStore = modificationStore;
+ this.modificationsForScope = modificationStore.getRootModifications();
+ this.fileScope = fileScope;
+
+ shouldVisitExpressions = delegateVisitor.shouldVisitExpressions;
+ shouldVisitStatements = delegateVisitor.shouldVisitStatements;
+ shouldVisitNames = delegateVisitor.shouldVisitNames;
+ shouldVisitDeclarations = delegateVisitor.shouldVisitDeclarators;
+ shouldVisitDeclSpecifiers = delegateVisitor.shouldVisitDeclSpecifiers;
+ shouldVisitDeclarators = delegateVisitor.shouldVisitDeclarators;
+ shouldVisitInitializers = delegateVisitor.shouldVisitInitializers;
+ shouldVisitBaseSpecifiers = delegateVisitor.shouldVisitBaseSpecifiers;
+ shouldVisitNamespaces = delegateVisitor.shouldVisitNamespaces;
+ shouldVisitTemplateParameters = delegateVisitor.shouldVisitTemplateParameters;
+ shouldVisitParameterDeclarations = delegateVisitor.shouldVisitParameterDeclarations;
+ shouldVisitTranslationUnit = delegateVisitor.shouldVisitTranslationUnit;
+ shouldVisitProblems = delegateVisitor.shouldVisitProblems;
+ shouldVisitTypeIds = delegateVisitor.shouldVisitTypeIds;
+
+ }
+
+ public ChangeGeneratorWriterVisitor(ASTModificationStore modStore, NodeCommentMap nodeMap) {
+ this(modStore, DEFAULT_INDENTATION, null, nodeMap);
+ }
+
+ public ChangeGeneratorWriterVisitor(ASTModificationStore modStore,
+ String givenIndentation, String fileScope, NodeCommentMap commentMap) {
+ super(givenIndentation, commentMap);
+ declaratorWriter = new ModifiedASTDeclaratorWriter(scribe, this,
+ modStore, commentMap);
+ expWriter = new ModifiedASTExpressionWriter(scribe, this, macroHandler,
+ modStore, commentMap);
+ statementWriter = new ModifiedASTStatementWriter(scribe, this, modStore, commentMap);
+ declSpecWriter = new ModifiedASTDeclSpecWriter(scribe, this, modStore, commentMap);
+
+ this.modificationStore = modStore;
+ this.modificationsForScope = modificationStore.getRootModifications();
+ this.fileScope = fileScope;
+ this.shouldVisitTranslationUnit = true;
+ }
+
+ @Override
+ public int leave(ICPPASTBaseSpecifier specifier) {
+ super.leave(specifier);
+ return PROCESS_SKIP;
+ }
+
+ @Override
+ public int leave(ICPPASTNamespaceDefinition namespace) {
+ super.leave(namespace);
+ return PROCESS_SKIP;
+ }
+
+ @Override
+ public int leave(ICPPASTTemplateParameter parameter) {
+ super.leave(parameter);
+ return PROCESS_SKIP;
+ }
+
+ @Override
+ public int visit(ICPPASTBaseSpecifier specifier) {
+ if (doBeforeEveryNode(specifier) == PROCESS_CONTINUE) {
+ return super.visit(specifier);
+ }
+ return PROCESS_SKIP;
+ }
+
+ @Override
+ public int visit(ICPPASTNamespaceDefinition namespace) {
+ if (doBeforeEveryNode(namespace) == PROCESS_CONTINUE) {
+ return super.visit(namespace);
+ }
+ return PROCESS_SKIP;
+ }
+
+ @Override
+ public int visit(ICPPASTTemplateParameter parameter) {
+ if (doBeforeEveryNode(parameter) == PROCESS_CONTINUE) {
+ return super.visit(parameter);
+ }
+ return PROCESS_SKIP;
+ }
+
+ @Override
+ public int leave(IASTComment comment) {
+ super.leave(comment);
+ return PROCESS_SKIP;
+ }
+
+ @Override
+ public int leave(IASTDeclaration declaration) {
+ super.leave(declaration);
+ return PROCESS_SKIP;
+ }
+
+ @Override
+ public int leave(IASTDeclarator declarator) {
+ super.leave(declarator);
+ return PROCESS_SKIP;
+ }
+
+ @Override
+ public int leave(IASTDeclSpecifier declSpec) {
+ super.leave(declSpec);
+ return PROCESS_SKIP;
+ }
+
+ @Override
+ public int leave(IASTEnumerator enumerator) {
+ super.leave(enumerator);
+ return PROCESS_SKIP;
+ }
+
+ @Override
+ public int leave(IASTExpression expression) {
+ super.leave(expression);
+ return PROCESS_SKIP;
+ }
+
+ @Override
+ public int leave(IASTInitializer initializer) {
+ super.leave(initializer);
+ return PROCESS_SKIP;
+ }
+
+ @Override
+ public int leave(IASTName name) {
+ super.leave(name);
+ return PROCESS_SKIP;
+ }
+
+ @Override
+ public int leave(IASTParameterDeclaration parameterDeclaration) {
+ super.leave(parameterDeclaration);
+ return PROCESS_SKIP;
+ }
+
+ @Override
+ public int leave(IASTProblem problem) {
+ super.leave(problem);
+ return PROCESS_SKIP;
+ }
+
+ @Override
+ public int leave(IASTStatement statement) {
+ super.leave(statement);
+ return PROCESS_SKIP;
+ }
+
+ @Override
+ public int leave(IASTTranslationUnit tu) {
+ super.leave(tu);
+ return PROCESS_SKIP;
+ }
+
+ @Override
+ public int leave(IASTTypeId typeId) {
+ super.leave(typeId);
+ return PROCESS_SKIP;
+ }
+
+ @Override
+ public int visit(IASTDeclaration declaration) {
+ if (doBeforeEveryNode(declaration) == PROCESS_CONTINUE) {
+ return super.visit(declaration);
+ }
+ return PROCESS_SKIP;
+ }
+
+ @Override
+ public int visit(IASTDeclarator declarator) {
+ if (doBeforeEveryNode(declarator) == PROCESS_CONTINUE) {
+ return super.visit(declarator);
+ }
+ return PROCESS_SKIP;
+ }
+
+ @Override
+ public int visit(IASTDeclSpecifier declSpec) {
+ if (doBeforeEveryNode(declSpec) == PROCESS_CONTINUE) {
+ return super.visit(declSpec);
+ }
+ return PROCESS_SKIP;
+ }
+
+ @Override
+ public int visit(IASTEnumerator enumerator) {
+ if (doBeforeEveryNode(enumerator) == PROCESS_CONTINUE) {
+ return super.visit(enumerator);
+ }
+ return PROCESS_SKIP;
+ }
+
+ @Override
+ public int visit(IASTExpression expression) {
+ if (doBeforeEveryNode(expression) == PROCESS_CONTINUE) {
+ return super.visit(expression);
+ }
+ return PROCESS_SKIP;
+ }
+
+ @Override
+ public int visit(IASTInitializer initializer) {
+ if (doBeforeEveryNode(initializer) == PROCESS_CONTINUE) {
+ return super.visit(initializer);
+ }
+ return PROCESS_SKIP;
+ }
+
+ @Override
+ public int visit(IASTName name) {
+ if (doBeforeEveryNode(name) == PROCESS_CONTINUE) {
+ return super.visit(name);
+ }
+ return PROCESS_SKIP;
+ }
+
+ @Override
+ public int visit(IASTParameterDeclaration parameterDeclaration) {
+ if (doBeforeEveryNode(parameterDeclaration) == PROCESS_CONTINUE) {
+ return super.visit(parameterDeclaration);
+ }
+ return PROCESS_SKIP;
+ }
+
+ @Override
+ public int visit(IASTProblem problem) {
+ if (doBeforeEveryNode(problem) == PROCESS_CONTINUE) {
+ return super.visit(problem);
+ }
+ return PROCESS_SKIP;
+ }
+
+ @Override
+ public int visit(IASTStatement statement) {
+ if (doBeforeEveryNode(statement) == PROCESS_CONTINUE) {
+ return super.visit(statement);
+ }
+ return PROCESS_SKIP;
+ }
+
+ @Override
+ public int visit(IASTTranslationUnit tu) {
+ ASTModificationHelper helper = new ASTModificationHelper(
+ modificationStore);
+
+ IASTDeclaration[] declarations = helper.createModifiedChildArray(tu, tu
+ .getDeclarations());
+ for (IASTDeclaration currentDeclaration : declarations) {
+ currentDeclaration.accept(this);
+ }
+
+ return PROCESS_SKIP;
+ }
+
+ @Override
+ public int visit(IASTTypeId typeId) {
+ if (doBeforeEveryNode(typeId) == PROCESS_CONTINUE) {
+ return super.visit(typeId);
+ }
+ return PROCESS_SKIP;
+ }
+
+ protected int doBeforeEveryNode(IASTNode node) {
+
+ if (fileScope != null) {
+ String file = getCorrespondingFile(node);
+ if (!fileScope.equals(file)) {
+ return PROCESS_SKIP;
+ }
+ }
+
+ if (modificationsForScope != null
+ && modificationsForScope.getModifiedNodes().contains(node)) {
+ List<ASTModification> modificationList = modificationsForScope
+ .getModificationsForNode(node);
+ if (modificationList == null) {
+ return PROCESS_CONTINUE;
+ }
+
+ for (ASTModification currentMod : modificationList) {
+ switch (currentMod.getKind()) {
+ case APPEND_CHILD:
+ return PROCESS_CONTINUE;
+ case INSERT_BEFORE:
+ return PROCESS_CONTINUE;
+ case REPLACE:
+ if (currentMod.getNewNode() == null) {
+ continue;
+ }
+
+ ASTModificationMap modificationsForThisScope = modificationsForScope;
+ modificationsForScope = modificationStore
+ .getNestedModifications(currentMod);
+ currentMod.getNewNode().accept(this);
+ modificationsForScope = modificationsForThisScope;
+ break;
+ }
+ }
+
+ return PROCESS_SKIP;
+ }
+ return PROCESS_CONTINUE;
+ }
+
+ private String getCorrespondingFile(IASTNode node) {
+
+ if (node.getFileLocation() != null) {
+ return node.getFileLocation().getFileName();
+ }
+
+ if (node.getParent() != null) {
+ return getCorrespondingFile(node.getParent());
+ }
+
+ for (IASTNode modifiedNode : modificationStore.getRootModifications()
+ .getModifiedNodes()) {
+ for (ASTModification modification : modificationStore
+ .getRootModifications().getModificationsForNode(
+ modifiedNode)) {
+ if (modification.getNewNode() == node) {
+ return getCorrespondingFile(modification.getTargetNode());
+ }
+ }
+ }
+ return null;
+ }
+}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/Messages.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/Messages.java
new file mode 100644
index 00000000000..b85600d1d49
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/Messages.java
@@ -0,0 +1,31 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Wind River Systems, Inc. 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:
+ * Markus Schorn - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.internal.core.dom.rewrite.changegenerator;
+
+import org.eclipse.osgi.util.NLS;
+
+/**
+ * mstodo
+ *
+ * @since 5.0
+ */
+public class Messages extends NLS {
+ private static final String BUNDLE_NAME = "org.eclipse.cdt.internal.core.dom.rewrite.changegenerator.messages"; //$NON-NLS-1$
+ public static String ChangeGenerator_compositeChange;
+ public static String ChangeGenerator_group;
+ static {
+ // initialize resource bundle
+ NLS.initializeMessages(BUNDLE_NAME, Messages.class);
+ }
+
+ private Messages() {
+ }
+}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/ModifiedASTDeclSpecWriter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/ModifiedASTDeclSpecWriter.java
new file mode 100644
index 00000000000..de0dbc79d2c
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/ModifiedASTDeclSpecWriter.java
@@ -0,0 +1,37 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.internal.core.dom.rewrite.changegenerator;
+
+import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier;
+import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
+import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
+import org.eclipse.cdt.internal.core.dom.rewrite.astwriter.DeclSpecWriter;
+import org.eclipse.cdt.internal.core.dom.rewrite.astwriter.Scribe;
+import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap;
+
+public class ModifiedASTDeclSpecWriter extends DeclSpecWriter {
+
+ private final ASTModificationHelper modificationHelper;
+
+ public ModifiedASTDeclSpecWriter(Scribe scribe, CPPASTVisitor visitor, ASTModificationStore modificationStore, NodeCommentMap commentMap) {
+ super(scribe, visitor, commentMap);
+ this.modificationHelper = new ASTModificationHelper(modificationStore);
+ }
+
+ @Override
+ protected IASTDeclaration[] getMembers(
+ IASTCompositeTypeSpecifier compDeclSpec) {
+ return modificationHelper.createModifiedChildArray(compDeclSpec, compDeclSpec.getMembers());
+ }
+
+}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/ModifiedASTDeclaratorWriter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/ModifiedASTDeclaratorWriter.java
new file mode 100644
index 00000000000..729b8496096
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/ModifiedASTDeclaratorWriter.java
@@ -0,0 +1,102 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.internal.core.dom.rewrite.changegenerator;
+
+import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator;
+import org.eclipse.cdt.core.dom.ast.IASTArrayModifier;
+import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
+import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
+import org.eclipse.cdt.core.dom.ast.IASTInitializer;
+import org.eclipse.cdt.core.dom.ast.IASTName;
+import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
+import org.eclipse.cdt.core.dom.ast.IASTPointerOperator;
+import org.eclipse.cdt.core.dom.ast.IASTStandardFunctionDeclarator;
+import org.eclipse.cdt.core.dom.ast.IASTTypeId;
+import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator;
+import org.eclipse.cdt.core.dom.ast.gnu.c.ICASTKnRFunctionDeclarator;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
+import org.eclipse.cdt.internal.core.dom.rewrite.astwriter.DeclaratorWriter;
+import org.eclipse.cdt.internal.core.dom.rewrite.astwriter.Scribe;
+import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap;
+
+
+public class ModifiedASTDeclaratorWriter extends DeclaratorWriter {
+
+ private final ASTModificationHelper modificationHelper;
+
+ public ModifiedASTDeclaratorWriter(Scribe scribe, CPPASTVisitor visitor, ASTModificationStore modificationStore, NodeCommentMap commentMap) {
+ super(scribe, visitor, commentMap);
+ this.modificationHelper = new ASTModificationHelper(modificationStore);
+ }
+
+ @Override
+ protected void writeParameterDeclarations(
+ IASTStandardFunctionDeclarator funcDec,
+ IASTParameterDeclaration[] paraDecls) {
+ IASTParameterDeclaration[] modifiedParameters = modificationHelper.createModifiedChildArray(funcDec, paraDecls);
+ super.writeParameterDeclarations(funcDec, modifiedParameters);
+
+ }
+
+ @Override
+ protected void writePointerOperators(IASTDeclarator declarator,IASTPointerOperator[] unmodifiedPointerOperations) {
+ IASTPointerOperator[] modifiedPointer = modificationHelper.createModifiedChildArray(declarator, unmodifiedPointerOperations);
+ super.writePointerOperators(declarator, modifiedPointer);
+ }
+
+
+
+ @Override
+ protected void writeCtorChainInitializer(ICPPASTFunctionDeclarator funcDec,
+ ICPPASTConstructorChainInitializer[] ctorInitChain) {
+ ICPPASTConstructorChainInitializer[] modifiedChainInitializer = modificationHelper.createModifiedChildArray(funcDec, ctorInitChain);
+ super.writeCtorChainInitializer(funcDec, modifiedChainInitializer);
+ }
+
+ @Override
+ protected void writeArrayModifiers(IASTArrayDeclarator arrDecl,
+ IASTArrayModifier[] arrMods) {
+ IASTArrayModifier[] modifiedModifiers = modificationHelper.createModifiedChildArray(arrDecl, arrMods);
+ super.writeArrayModifiers(arrDecl, modifiedModifiers);
+ }
+
+ @Override
+ protected void writeExceptionSpecification(ICPPASTFunctionDeclarator funcDec, IASTTypeId[] exceptions ) {
+ IASTTypeId[] modifiedExceptions = modificationHelper.createModifiedChildArray(funcDec, exceptions);
+ super.writeExceptionSpecification(funcDec, modifiedExceptions);
+ }
+
+
+
+ @Override
+ protected void writeKnRParameterDeclarations(
+ ICASTKnRFunctionDeclarator knrFunct,
+ IASTDeclaration[] knrDeclarations) {
+ IASTDeclaration[] modifiedDeclarations = modificationHelper.createModifiedChildArray(knrFunct, knrDeclarations);
+
+ super.writeKnRParameterDeclarations(knrFunct, modifiedDeclarations);
+ }
+
+ @Override
+ protected void writeKnRParameterNames(
+ ICASTKnRFunctionDeclarator knrFunct, IASTName[] parameterNames) {
+ IASTName[] modifiedNames = modificationHelper.createModifiedChildArray(knrFunct, parameterNames);
+ super.writeKnRParameterNames(knrFunct, modifiedNames);
+ }
+
+ @Override
+ protected IASTInitializer getInitializer(IASTDeclarator decl) {
+ return modificationHelper.getInitializer(decl);
+ }
+}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/ModifiedASTExpressionWriter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/ModifiedASTExpressionWriter.java
new file mode 100644
index 00000000000..eb478953ae8
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/ModifiedASTExpressionWriter.java
@@ -0,0 +1,89 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.internal.core.dom.rewrite.changegenerator;
+
+import org.eclipse.cdt.core.dom.ast.IASTExpression;
+import org.eclipse.cdt.core.dom.ast.IASTExpressionList;
+import org.eclipse.cdt.core.dom.ast.IASTInitializer;
+import org.eclipse.cdt.core.dom.ast.IASTNode;
+import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNewExpression;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind;
+import org.eclipse.cdt.internal.core.dom.rewrite.astwriter.ExpressionWriter;
+import org.eclipse.cdt.internal.core.dom.rewrite.astwriter.MacroExpansionHandler;
+import org.eclipse.cdt.internal.core.dom.rewrite.astwriter.Scribe;
+import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap;
+
+public class ModifiedASTExpressionWriter extends ExpressionWriter {
+
+ private final ASTModificationHelper modificationHelpder;
+
+ public ModifiedASTExpressionWriter(Scribe scribe, CPPASTVisitor visitor,
+ MacroExpansionHandler macroHandler, ASTModificationStore modStore, NodeCommentMap commentMap) {
+ super(scribe, visitor, macroHandler, commentMap);
+ this.modificationHelpder = new ASTModificationHelper(modStore);
+ }
+
+ @Override
+ protected void writeExpressions(IASTExpressionList expList,
+ IASTExpression[] expressions) {
+ IASTExpression[] modifiedExpressions = modificationHelpder.createModifiedChildArray(expList, expressions);
+ super.writeExpressions(expList, modifiedExpressions);
+ }
+
+ @Override
+ protected IASTExpression getNewInitializer(ICPPASTNewExpression newExp) {
+
+
+ IASTExpression initializer = newExp.getNewInitializer();
+
+ if(initializer != null){
+ for(ASTModification childModification : modificationHelpder.modificationsForNode(initializer)){
+ switch(childModification.getKind()){
+ case REPLACE:
+ if(childModification.getNewNode() instanceof IASTInitializer){
+ return (IASTExpression)childModification.getNewNode();
+ }
+ break;
+ case INSERT_BEFORE:
+ throw new UnhandledASTModificationException(childModification);
+
+ case APPEND_CHILD:
+ throw new UnhandledASTModificationException(childModification);
+ }
+ }
+ }
+ else
+ {
+ for(ASTModification parentModification : modificationHelpder.modificationsForNode(newExp)){
+ if(parentModification.getKind() == ModificationKind.APPEND_CHILD){
+ IASTNode newNode = parentModification.getNewNode();
+ if(newNode instanceof IASTInitializer){
+ return (IASTExpression) newNode;
+ }
+ }
+ }
+ }
+ return initializer;
+ }
+
+ @Override
+ protected IASTExpression[] getNewTypeIdArrayExpressions(
+ ICPPASTNewExpression newExp, IASTExpression[] expressions) {
+ IASTExpression[] modifiedExpressions = modificationHelpder.createModifiedChildArray(newExp, expressions);
+ return modifiedExpressions;
+ }
+
+
+}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/ModifiedASTStatementWriter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/ModifiedASTStatementWriter.java
new file mode 100644
index 00000000000..e5d3b98d631
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/ModifiedASTStatementWriter.java
@@ -0,0 +1,43 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.internal.core.dom.rewrite.changegenerator;
+
+import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
+import org.eclipse.cdt.core.dom.ast.IASTStatement;
+import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
+import org.eclipse.cdt.internal.core.dom.rewrite.astwriter.Scribe;
+import org.eclipse.cdt.internal.core.dom.rewrite.astwriter.StatementWriter;
+import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap;
+
+public class ModifiedASTStatementWriter extends StatementWriter {
+
+ private final ASTModificationHelper modificationHelper;
+
+ public ModifiedASTStatementWriter(Scribe scribe, CPPASTVisitor visitor, ASTModificationStore modStore, NodeCommentMap commentMap) {
+ super(scribe, visitor, commentMap);
+ this.modificationHelper = new ASTModificationHelper(modStore);
+ }
+
+ @Override
+ protected void writeBodyStatement(IASTStatement statement,
+ boolean isDoStatement) {
+ IASTStatement replacementNode = modificationHelper.getNodeAfterReplacement(statement);
+ super.writeBodyStatement(replacementNode, isDoStatement);
+ }
+
+ @Override
+ protected void writeDeclarationWithoutSemicolon(IASTDeclaration declaration) {
+ IASTDeclaration replacementNode = modificationHelper.getNodeAfterReplacement(declaration);
+ super.writeDeclarationWithoutSemicolon(replacementNode);
+ }
+}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/UnhandledASTModificationException.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/UnhandledASTModificationException.java
new file mode 100644
index 00000000000..fee2ecd60b1
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/UnhandledASTModificationException.java
@@ -0,0 +1,36 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.internal.core.dom.rewrite.changegenerator;
+
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
+
+public class UnhandledASTModificationException extends RuntimeException {
+
+ private static final long serialVersionUID = 1L;
+ private final ASTModification illegalModification;
+
+ public UnhandledASTModificationException(ASTModification illegalModification) {
+ this.illegalModification = illegalModification;
+ }
+
+ @Override
+ public String getMessage() {
+ StringBuilder message = new StringBuilder();
+ message.append("Tried to "). //$NON-NLS-1$
+ append(illegalModification.getKind().name()).
+ append(" on "). //$NON-NLS-1$
+ append(illegalModification.getTargetNode()).
+ append(" with "). //$NON-NLS-1$
+ append(illegalModification.getNewNode());
+ return message.toString();
+ }
+}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/messages.properties b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/messages.properties
new file mode 100644
index 00000000000..f9b86acca1d
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/messages.properties
@@ -0,0 +1,2 @@
+ChangeGenerator_compositeChange=Changes
+ChangeGenerator_group=Generated Group
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/commenthandler/ASTCommenter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/commenthandler/ASTCommenter.java
new file mode 100644
index 00000000000..4b1efac508f
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/commenthandler/ASTCommenter.java
@@ -0,0 +1,84 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Institute for Software - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.cdt.internal.core.dom.rewrite.commenthandler;
+
+import java.util.Vector;
+
+import org.eclipse.cdt.core.dom.ast.IASTComment;
+import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
+import org.eclipse.cdt.core.dom.ast.IASTNode;
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Platform;
+
+/**
+ * @author Guido Zgraggen IFS
+ *
+ */
+public class ASTCommenter {
+
+ public static NodeCommentMap getCommentedNodeMap(IASTTranslationUnit transUnit){
+ if(transUnit== null) {
+ return new NodeCommentMap();
+ }
+ Vector<IASTComment> comments = getCommentsInWorkspace(transUnit);
+ if(comments == null || comments.size() == 0) {
+ return new NodeCommentMap();
+ }
+ return addCommentsToCommentMap(transUnit, comments);
+ }
+
+ private static Vector<IASTComment> getCommentsInWorkspace(IASTTranslationUnit tu) {
+ IASTComment[] comments = tu.getComments();
+ Vector<IASTComment> commentsInWorksapce = new Vector<IASTComment>();
+
+ if (comments == null || comments.length == 0) {
+ return null;
+ }
+
+ for (IASTComment comment : comments) {
+ if (isInWorkspace(comment)) {
+ commentsInWorksapce.add(comment);
+ }
+ }
+ return commentsInWorksapce;
+ }
+
+ private static boolean isInWorkspace(IASTNode node) {
+ IPath workspacePath = Platform.getLocation();
+ IPath nodePath = new Path(node.getContainingFilename());
+ return workspacePath.isPrefixOf(nodePath);
+ }
+
+
+ private static NodeCommentMap addCommentsToCommentMap(IASTTranslationUnit rootNode, Vector<IASTComment> comments){
+ NodeCommentMap commentMap = new NodeCommentMap();
+ CommentHandler commHandler = new CommentHandler(comments);
+
+ IASTDeclaration[] declarations = rootNode.getDeclarations();
+ for (int i = 0; i < declarations.length; i++) {
+
+ if (isInWorkspace(declarations[i])) {
+
+ ASTCommenterVisitor commenter = new ASTCommenterVisitor(commHandler, commentMap);
+ declarations[i].accept(commenter);
+
+ //add remaining comments to the last declaration => Comments won't get lost
+ if (i + 1 == declarations.length) {
+ commenter.addRemainingComments(declarations[i]);
+ }
+ }
+ }
+ return commentMap;
+ }
+}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/commenthandler/ASTCommenterVisitor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/commenthandler/ASTCommenterVisitor.java
new file mode 100644
index 00000000000..6856c23494b
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/commenthandler/ASTCommenterVisitor.java
@@ -0,0 +1,197 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.internal.core.dom.rewrite.commenthandler;
+
+import org.eclipse.cdt.core.dom.ast.IASTComment;
+import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
+import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
+import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
+import org.eclipse.cdt.core.dom.ast.IASTExpression;
+import org.eclipse.cdt.core.dom.ast.IASTInitializer;
+import org.eclipse.cdt.core.dom.ast.IASTName;
+import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
+import org.eclipse.cdt.core.dom.ast.IASTProblem;
+import org.eclipse.cdt.core.dom.ast.IASTStatement;
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
+import org.eclipse.cdt.core.dom.ast.IASTTypeId;
+import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator;
+import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateParameter;
+import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTCompositeTypeSpecifier;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTCompoundStatement;
+
+/**
+ * @author Guido Zgraggen IFS
+ *
+ */
+public class ASTCommenterVisitor extends CPPASTVisitor {
+
+ protected CommentHandler commHandler;
+ protected NodeCommentMap commentMap;
+
+ private NodeCommenter nodeCommenter;
+
+ {
+ shouldVisitExpressions = true;
+ shouldVisitStatements = true;
+ shouldVisitNames = true;
+ shouldVisitDeclarations = true;
+ shouldVisitDeclSpecifiers = true;
+ shouldVisitDeclarators = true;
+ shouldVisitInitializers = true;
+ shouldVisitBaseSpecifiers = true;
+ shouldVisitNamespaces = true;
+ shouldVisitTemplateParameters = true;
+ shouldVisitParameterDeclarations = true;
+ }
+
+ public ASTCommenterVisitor(CommentHandler commHandler, NodeCommentMap commentMap) {
+ this.commHandler = commHandler;
+ this.commentMap = commentMap;
+ init();
+ }
+
+ private void init() {
+ nodeCommenter = new NodeCommenter(this, commHandler, commentMap);
+ }
+
+
+ public void addRemainingComments(IASTDeclaration declaration) {
+ nodeCommenter.appendRemainingComments(declaration);
+ }
+
+
+
+ @Override
+ public int visit(IASTName name) {
+ return nodeCommenter.appendComments((ASTNode)name);
+ }
+
+ @Override
+ public int visit(IASTDeclSpecifier declSpec) {
+ return nodeCommenter.appendComments((ASTNode)declSpec);
+ }
+
+ @Override
+ public int visit(IASTExpression expression) {
+ return nodeCommenter.appendComments((ASTNode)expression);
+ }
+
+ @Override
+ public int visit(IASTStatement statement) {
+ return nodeCommenter.appendComments((ASTNode)statement);
+ }
+
+ @Override
+ public int visit(IASTDeclaration declaration) {
+ return nodeCommenter.appendComments((ASTNode)declaration);
+ }
+
+ @Override
+ public int visit(IASTDeclarator declarator) {
+ return nodeCommenter.appendComments((ASTNode)declarator);
+ }
+
+ @Override
+ public int visit(IASTInitializer initializer) {
+ return nodeCommenter.appendComments((ASTNode)initializer);
+ }
+
+ @Override
+ public int visit(IASTParameterDeclaration parameterDeclaration) {
+ return nodeCommenter.appendComments((ASTNode)parameterDeclaration);
+ }
+
+ @Override
+ public int visit(ICPPASTNamespaceDefinition namespace) {
+ return nodeCommenter.appendComments((ASTNode)namespace);
+ }
+
+ @Override
+ public int visit(ICPPASTTemplateParameter parameter) {
+ return nodeCommenter.appendComments((ASTNode)parameter);
+ }
+
+ @Override
+ public int leave(IASTTranslationUnit tu) {
+ nodeCommenter.appendComments((ASTNode)tu);
+ return PROCESS_CONTINUE;
+ }
+ @Override
+ public int leave(IASTName name) {
+ nodeCommenter.appendComments((ASTNode)name);
+ return PROCESS_CONTINUE;
+ }
+ @Override
+ public int leave(IASTDeclaration declaration) {
+ nodeCommenter.appendComments((ASTNode)declaration);
+ return PROCESS_CONTINUE;
+ }
+ @Override
+ public int leave(IASTInitializer initializer) {
+ nodeCommenter.appendComments((ASTNode)initializer);
+ return PROCESS_CONTINUE;
+ }
+ @Override
+ public int leave(IASTParameterDeclaration parameterDeclaration) {
+ nodeCommenter.appendComments((ASTNode)parameterDeclaration);
+ return PROCESS_CONTINUE;
+ }
+ @Override
+ public int leave(IASTDeclarator declarator) {
+ nodeCommenter.appendComments((ASTNode)declarator);
+ return PROCESS_CONTINUE;
+ }
+ @Override
+ public int leave(IASTDeclSpecifier declSpec) {
+ if(declSpec instanceof CPPASTCompositeTypeSpecifier) {
+ return nodeCommenter.appendFreestandingComments((ASTNode)declSpec);
+ }
+ nodeCommenter.appendComments((ASTNode)declSpec);
+ return PROCESS_CONTINUE;
+ }
+ @Override
+ public int leave(IASTExpression expression) {
+ nodeCommenter.appendComments((ASTNode)expression);
+ return PROCESS_CONTINUE;
+ }
+ @Override
+ public int leave(IASTStatement statement) {
+ if(statement instanceof CPPASTCompoundStatement) {
+ return nodeCommenter.appendFreestandingComments((ASTNode)statement);
+ }
+ nodeCommenter.appendComments((ASTNode)statement);
+ return PROCESS_CONTINUE;
+ }
+ @Override
+ public int leave(IASTTypeId typeId) {
+ nodeCommenter.appendComments((ASTNode)typeId);
+ return PROCESS_CONTINUE;
+ }
+ @Override
+ public int leave(IASTEnumerator enumerator) {
+ nodeCommenter.appendComments((ASTNode)enumerator);
+ return PROCESS_CONTINUE;
+ }
+ @Override
+ public int leave(IASTProblem problem){
+ nodeCommenter.appendComments((ASTNode)problem);
+ return PROCESS_CONTINUE;
+ }
+ @Override
+ public int leave( IASTComment comment){
+ nodeCommenter.appendComments((ASTNode)comment);
+ return PROCESS_CONTINUE;
+ }
+}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/commenthandler/CommentHandler.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/commenthandler/CommentHandler.java
new file mode 100644
index 00000000000..f053014bb30
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/commenthandler/CommentHandler.java
@@ -0,0 +1,42 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.internal.core.dom.rewrite.commenthandler;
+
+import java.util.Vector;
+
+import org.eclipse.cdt.core.dom.ast.IASTComment;
+
+/**
+ * @author Guido Zgraggen IFS
+ *
+ */
+public class CommentHandler {
+
+ private final Vector<IASTComment> comments;
+
+ public CommentHandler(Vector<IASTComment> comments) {
+ super();
+ this.comments = comments;
+ }
+
+ public void allreadyAdded(IASTComment com) {
+ comments.remove(com);
+ }
+
+ public boolean hasMore() {
+ return comments.size()>0;
+ }
+
+ public IASTComment getFirst() {
+ return comments.firstElement();
+ }
+}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/commenthandler/NodeCommentMap.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/commenthandler/NodeCommentMap.java
new file mode 100644
index 00000000000..08fc854912f
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/commenthandler/NodeCommentMap.java
@@ -0,0 +1,116 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Institute for Software - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.cdt.internal.core.dom.rewrite.commenthandler;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+
+import org.eclipse.cdt.core.dom.ast.IASTComment;
+import org.eclipse.cdt.core.dom.ast.IASTNode;
+
+/**
+ * @author Guido Zgraggen IFS
+ *
+ */
+public class NodeCommentMap {
+
+ protected final HashMap<IASTNode, ArrayList<IASTComment>> map = new HashMap<IASTNode, ArrayList<IASTComment>>();
+
+ public void addCommentToNode(IASTNode node, IASTComment comment){
+ ArrayList<IASTComment> comments = map.get(node);
+ if(comments == null){
+ comments = new ArrayList<IASTComment>();
+ }
+ comments.add(comment);
+ map.put(node, comments);
+ }
+
+ public ArrayList<IASTComment> getCommentsForNode(IASTNode node){
+ if(map.get(node) == null) {
+ return new ArrayList<IASTComment>();
+ }
+ return map.get(node);
+ }
+
+ //needed for testing
+ public HashMap<IASTNode, ArrayList<IASTComment>> getMap() {
+ return map;
+ }
+
+
+ //===
+ //Erst nur einmal zu test zwecken
+ // Wenn wircklich gebraucht refactorn
+ protected final HashMap<IASTNode, ArrayList<IASTComment>> leadingMap = new HashMap<IASTNode, ArrayList<IASTComment>>();
+ protected final HashMap<IASTNode, ArrayList<IASTComment>> trailingMap = new HashMap<IASTNode, ArrayList<IASTComment>>();
+ protected final HashMap<IASTNode, ArrayList<IASTComment>> freestandingMap = new HashMap<IASTNode, ArrayList<IASTComment>>();
+
+ public void addTrailingCommentToNode(IASTNode node, IASTComment comment){
+ ArrayList<IASTComment> comments = trailingMap.get(node);
+ if(comments == null){
+ comments = new ArrayList<IASTComment>();
+ }
+ comments.add(comment);
+ trailingMap.put(node, comments);
+ }
+
+ public ArrayList<IASTComment> getTrailingCommentsForNode(IASTNode node){
+ if(trailingMap.get(node) == null) {
+ return new ArrayList<IASTComment>();
+ }
+ return trailingMap.get(node);
+ }
+
+ public void addLeadingCommentToNode(IASTNode node, IASTComment comment){
+ ArrayList<IASTComment> comments = leadingMap.get(node);
+ if(comments == null){
+ comments = new ArrayList<IASTComment>();
+ }
+ comments.add(comment);
+ leadingMap.put(node, comments);
+ }
+
+ public ArrayList<IASTComment> getLeadingCommentsForNode(IASTNode node){
+ if(leadingMap.get(node) == null) {
+ return new ArrayList<IASTComment>();
+ }
+ return leadingMap.get(node);
+ }
+
+ public void addFreestandingCommentToNode(IASTNode node, IASTComment comment){
+ ArrayList<IASTComment> comments = freestandingMap.get(node);
+ if(comments == null){
+ comments = new ArrayList<IASTComment>();
+ }
+ comments.add(comment);
+ freestandingMap.put(node, comments);
+ }
+
+ public ArrayList<IASTComment> getFreestandingCommentsForNode(IASTNode node){
+ if(freestandingMap.get(node) == null) {
+ return new ArrayList<IASTComment>();
+ }
+ return freestandingMap.get(node);
+ }
+
+ public HashMap<IASTNode, ArrayList<IASTComment>> getLeadingMap() {
+ return leadingMap;
+ }
+ public HashMap<IASTNode, ArrayList<IASTComment>> getTrailingMap() {
+ return trailingMap;
+ }
+ public HashMap<IASTNode, ArrayList<IASTComment>> getFreestandingMap() {
+ return freestandingMap;
+ }
+
+
+}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/commenthandler/NodeCommenter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/commenthandler/NodeCommenter.java
new file mode 100644
index 00000000000..09677a232b2
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/commenthandler/NodeCommenter.java
@@ -0,0 +1,247 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.internal.core.dom.rewrite.commenthandler;
+
+import java.io.InputStream;
+import java.util.Vector;
+
+import org.eclipse.cdt.core.dom.ast.ASTVisitor;
+import org.eclipse.cdt.core.dom.ast.IASTComment;
+import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
+import org.eclipse.cdt.core.dom.ast.IASTNode;
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
+import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier;
+import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTDeclarationStatement;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTForStatement;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDefinition;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTIfStatement;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTLabelStatement;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTSwitchStatement;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTWhileStatement;
+import org.eclipse.cdt.internal.core.dom.rewrite.util.OffsetHelper;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+
+/**
+ * @author Guido Zgraggen IFS
+ *
+ */
+public class NodeCommenter {
+
+ protected CPPASTVisitor visitor;
+ protected CommentHandler commHandler;
+ protected NodeCommentMap commentMap;
+ protected Vector<IASTNode> children;
+
+ public NodeCommenter(CPPASTVisitor visitor, CommentHandler commHandler, NodeCommentMap commentMap) {
+ this.visitor = visitor;
+ this.commHandler = commHandler;
+ this.commentMap = commentMap;
+ this.children = new Vector<IASTNode>();
+ }
+
+ protected void writeNodeList(IASTNode[] nodes) {
+ for(int i = 0; i < nodes.length; ++i) {
+ nodes[i].accept(visitor);
+ }
+ }
+
+ protected void visitNodeIfNotNull(IASTNode node){
+ if(node != null){
+ node.accept(visitor);
+ }
+ }
+
+ protected boolean appendComment(ASTNode node, IASTComment comment) {
+ ASTNode com = (ASTNode) comment;
+
+ if(node.getFileLocation() == null) {
+ //MacroExpansions have no Filelocation
+ return false;
+ }
+
+ int nodeLineNumber = OffsetHelper.getEndingLineNumber(node);
+ int commentLineNumber= OffsetHelper.getStartingLineNumber(comment);
+
+ if(OffsetHelper.getNodeEndPoint(com) <= OffsetHelper.getNodeOffset(node)) {
+ addLeadingCommentToMap(node, comment);
+ return true;
+ }
+ else if(isTrailing(node, com, nodeLineNumber, commentLineNumber)) {
+ addTrailingCommentToMap(node, comment);
+ return true;
+ }
+ return false;
+ }
+
+ protected boolean appendFreestandingComment(ASTNode node, IASTComment comment) {
+ ASTNode com = (ASTNode) comment;
+
+ if(node.getFileLocation() == null) {
+ //MacroExpansions have no Filelocation
+ return false;
+ }
+ if(OffsetHelper.getNodeEndPoint(com) <= OffsetHelper.getNodeEndPoint(node)) {
+ addFreestandingCommentToMap(node, comment);
+ return true;
+ }
+ return false;
+ }
+
+ private void addLeadingCommentToMap(ASTNode node, IASTComment comment) {
+ commentMap.addLeadingCommentToNode(node, comment);
+ commHandler.allreadyAdded(comment);
+ }
+
+ private void addTrailingCommentToMap(ASTNode node, IASTComment comment) {
+ commentMap.addTrailingCommentToNode(node, comment);
+ commHandler.allreadyAdded(comment);
+ }
+
+ private void addFreestandingCommentToMap(ASTNode node, IASTComment comment) {
+ commentMap.addFreestandingCommentToNode(node, comment);
+ commHandler.allreadyAdded(comment);
+ }
+
+ private boolean isTrailing(ASTNode node, ASTNode com, int nodeLineNumber, int commentLineNumber) {
+ if(nodeLineNumber == commentLineNumber
+ && OffsetHelper.getNodeOffset(com) >= OffsetHelper.getNodeEndPoint(node)
+ && canNotBeAddedToParent(node,com)
+ && !mustBeAddToSubnodes(node)) {
+
+ if(OffsetHelper.getNodeOffset(com) < OffsetHelper.getNodeEndPoint(node) + 2) {
+ return true;
+ }
+ else {
+ IPath path = new Path(node.getContainingFilename());
+ IFile file = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(path);
+
+ //XXX HSR Guido: Possible Performance Issue (File access)
+ try {
+ InputStream is = file.getContents();
+
+ int length = OffsetHelper.getNodeOffset(com)-OffsetHelper.getNodeEndPoint(node);
+ byte[] b = new byte[length];
+
+ is.skip(OffsetHelper.getNodeEndPoint(node));
+ is.read(b, 0, length);
+
+ for(byte bb : b) {
+ if(!Character.isWhitespace(bb)) {
+ is.close();
+ return false;
+ }
+ }
+ is.close();
+ return true;
+ } catch (Exception e) {
+ return false;
+ }
+ }
+ }
+
+ return false;
+ }
+
+ private boolean canNotBeAddedToParent(ASTNode node, ASTNode com) {
+ ASTNode parent = (ASTNode) node.getParent();
+
+ if(hasNodeSameEndingAsSubnode(parent)) {
+ return true;
+ }else if(parent instanceof IASTTranslationUnit) {
+ return true;
+ }else if(parent instanceof ICPPASTBaseSpecifier) {
+ parent = (ASTNode) parent.getParent();
+ }else if(parent instanceof ICPPASTTemplateDeclaration) {
+ return true;
+ }else if(parent instanceof CPPASTIfStatement) {
+ return true;
+ }
+ return !(OffsetHelper.getNodeOffset(com) >= OffsetHelper.getNodeEndPoint(parent));
+ }
+
+ private boolean mustBeAddToSubnodes(ASTNode node) {
+ return hasNodeSameEndingAsSubnode(node);
+ }
+
+ private boolean hasNodeSameEndingAsSubnode(ASTNode node) {
+ if(node instanceof CPPASTFunctionDefinition) {
+ return true;
+ }else if(node instanceof CPPASTDeclarationStatement) {
+ return true;
+ }else if(node instanceof CPPASTForStatement) {
+ return true;
+ }else if(node instanceof CPPASTLabelStatement) {
+ return true;
+ }else if(node instanceof CPPASTIfStatement) {
+ return true;
+ }else if(node instanceof CPPASTSwitchStatement) {
+ return true;
+ }else if(node instanceof CPPASTWhileStatement) {
+ return true;
+ }
+ return false;
+ }
+
+ protected int appendComments(ASTNode node) {
+ while(commHandler.hasMore()) {
+ IASTComment comment = commHandler.getFirst();
+
+ if(isNotSameFile(node, comment)) {
+ return ASTVisitor.PROCESS_SKIP;
+ }
+
+ if(!appendComment(node, comment)) {
+ return ASTVisitor.PROCESS_CONTINUE;
+ }
+ }
+ return ASTVisitor.PROCESS_ABORT;
+ }
+
+ protected int appendFreestandingComments(ASTNode node) {
+ while(commHandler.hasMore()) {
+ IASTComment comment = commHandler.getFirst();
+
+ if(isNotSameFile(node, comment)) {
+ return ASTVisitor.PROCESS_SKIP;
+ }
+
+ if(appendComment(node, comment)) {
+ return ASTVisitor.PROCESS_CONTINUE;
+ }
+
+ if(!appendFreestandingComment(node, comment)) {
+ return ASTVisitor.PROCESS_CONTINUE;
+ }
+ }
+ return ASTVisitor.PROCESS_ABORT;
+ }
+
+ public void appendRemainingComments(IASTDeclaration declaration) {
+ while(commHandler.hasMore()) {
+ IASTComment comment = commHandler.getFirst();
+ addFreestandingCommentToMap((ASTNode) declaration, comment);
+ }
+ }
+
+ private boolean isNotSameFile(IASTNode node, IASTComment comment) {
+ if(node.getFileLocation()==null) {
+ return true;
+ }
+ return !node.getFileLocation().getFileName().equals(comment.getFileLocation().getFileName());
+ }
+}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/util/FileContentHelper.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/util/FileContentHelper.java
new file mode 100644
index 00000000000..a9fa9a9faa7
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/util/FileContentHelper.java
@@ -0,0 +1,100 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Institute for Software - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.cdt.internal.core.dom.rewrite.util;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.UnsupportedEncodingException;
+
+import org.eclipse.cdt.core.CCorePlugin;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.CoreException;
+
+/**
+ * @author Emanuel Graf IFS
+ *
+ */
+public class FileContentHelper {
+
+ private static final int bufferSize = 512;
+
+ public static String getContent(IFile file, int start) throws CoreException, IOException{
+
+ InputStreamReader reader = getReaderForFile(file);
+ skip(start, reader);
+
+ return readRest(reader);
+
+ }
+
+ public static String getContent(IFile file, int start, int length) {
+ try {
+ InputStreamReader r = getReaderForFile(file);
+ char[] bytes = new char[length];
+
+ skip(start, r);
+
+ read(length, r, bytes);
+
+ return new String(bytes);
+ } catch (IOException e) {
+ CCorePlugin.log(e);
+ } catch (CoreException e) {
+ CCorePlugin.log(e);
+ }
+ return ""; //$NON-NLS-1$
+ }
+
+ private static InputStreamReader getReaderForFile(IFile file)
+ throws CoreException, UnsupportedEncodingException {
+ InputStream contents = file.getContents();
+ InputStreamReader r = new InputStreamReader(contents, file.getCharset());
+ return r;
+ }
+
+ private static String readRest(InputStreamReader reader) throws IOException{
+ StringBuilder content = new StringBuilder();
+ char[] buffer = new char[bufferSize];
+ int bytesRead = 0;
+ while((bytesRead = reader.read(buffer)) >= 0){
+ content.append(buffer, 0, bytesRead);
+ }
+
+
+ return content.toString();
+ }
+
+ private static void read(int length, InputStreamReader r, char[] bytes)
+ throws IOException {
+ int bufferOffset = 0;
+ int charactersRead = 0;
+ while(charactersRead >= 0 && length > 0){
+ charactersRead = r.read(bytes, bufferOffset, length);
+ if(charactersRead > 0){
+ bufferOffset += charactersRead;
+ length -= charactersRead;
+ }
+ }
+ }
+
+ private static void skip(int start, InputStreamReader r) throws IOException {
+ long skipped = 0;
+ while(skipped >= 0 && start > 0 && r.ready()){
+ skipped = r.skip(start);
+ if(skipped > 0){
+ start -= skipped;
+ }
+ }
+ }
+
+}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/util/FileHelper.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/util/FileHelper.java
new file mode 100644
index 00000000000..6a64c399dbe
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/util/FileHelper.java
@@ -0,0 +1,78 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+
+
+package org.eclipse.cdt.internal.core.dom.rewrite.util;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
+import org.eclipse.cdt.core.dom.ast.IASTNode;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ProjectScope;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.preferences.IScopeContext;
+import org.eclipse.core.runtime.preferences.InstanceScope;
+import org.eclipse.jface.text.TextUtilities;
+
+public class FileHelper {
+
+ private static final String DEFAULT_LINE_DELIMITTER = "\n"; //$NON-NLS-1$
+
+ public static IFile getIFilefromIASTNode(IASTNode node) {
+ IPath implPath = new Path(node.getContainingFilename());
+ return ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(implPath);
+ }
+
+ public static boolean isFirstWithinSecondLocation(IASTFileLocation loc1, IASTFileLocation loc2){
+
+ boolean isEquals = true;
+
+ isEquals &= loc1.getFileName().equals(loc2.getFileName());
+ isEquals &= loc1.getNodeOffset() >= loc2.getNodeOffset();
+ isEquals &= loc1.getNodeOffset()+loc1.getNodeLength() <= loc2.getNodeOffset() + loc2.getNodeLength();
+
+ return isEquals;
+ }
+
+ public static String determineLineDelimiter(IFile file) {
+ StringBuilder fileContent = new StringBuilder();
+ try {
+ InputStream fis = file.getContents();
+ byte[] buffer = new byte[1024];
+ int read;
+ while ((read = fis.read(buffer)) >= 0)
+ fileContent.append(new String(buffer, 0, read));
+ } catch (CoreException e) {
+ } catch (IOException e) {
+ } catch (NullPointerException e){
+ }
+
+ IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject();
+ IScopeContext[] scopeContext;
+ if(project != null){
+ scopeContext = new IScopeContext[] { new ProjectScope(project)};
+ }
+ else{
+ scopeContext = new IScopeContext[] { new InstanceScope()};
+ }
+ String platformDefaultLineDelimiter = System.getProperty("line.separator", DEFAULT_LINE_DELIMITTER); //$NON-NLS-1$
+ String defaultLineDelimiter = Platform.getPreferencesService().getString(Platform.PI_RUNTIME, Platform.PREF_LINE_SEPARATOR, platformDefaultLineDelimiter, scopeContext);
+ return TextUtilities.determineLineDelimiter(fileContent.toString(), defaultLineDelimiter);
+ }
+}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/util/OffsetHelper.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/util/OffsetHelper.java
new file mode 100644
index 00000000000..ba7a270190a
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/util/OffsetHelper.java
@@ -0,0 +1,97 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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:
+ * Institute for Software - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.cdt.internal.core.dom.rewrite.util;
+
+import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
+import org.eclipse.cdt.core.dom.ast.IASTMacroExpansionLocation;
+import org.eclipse.cdt.core.dom.ast.IASTNode;
+import org.eclipse.cdt.core.dom.ast.IASTNodeLocation;
+import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
+
+/**
+ * @author Emanuel Graf IFS
+ *
+ */
+public class OffsetHelper {
+
+ public static int getOffsetIncludingComment(IASTNode node) {
+ int nodeStart = Integer.MAX_VALUE;
+ IASTNodeLocation[] nodeLocations = node.getNodeLocations();
+ if (nodeLocations.length != 1) {
+ int offset;
+ for (IASTNodeLocation location : nodeLocations) {
+ if (location instanceof IASTMacroExpansionLocation) {
+ IASTMacroExpansionLocation macroLoc = (IASTMacroExpansionLocation) location;
+ offset = macroLoc.asFileLocation().getNodeOffset();
+ }else {
+ offset = location.asFileLocation().getNodeOffset();
+ }
+ if(offset < nodeStart) nodeStart = offset;
+ }
+ } else {
+ nodeStart = node.getFileLocation().getNodeOffset();
+ }
+
+ return nodeStart;
+ }
+
+ public static int getEndOffsetIncludingComments(IASTNode node) {
+ int fileOffset = 0;
+ int length = 0;
+
+ IASTNodeLocation[] nodeLocations = node.getNodeLocations();
+ if (nodeLocations.length != 1) {
+ for (IASTNodeLocation location : nodeLocations) {
+ if (location instanceof IASTMacroExpansionLocation) {
+ IASTMacroExpansionLocation macroLoc = (IASTMacroExpansionLocation) location;
+ fileOffset = macroLoc.asFileLocation().getNodeOffset();
+ length = macroLoc.asFileLocation().getNodeLength();
+ }else {
+ fileOffset = location.asFileLocation().getNodeOffset();
+ length = location.asFileLocation().getNodeLength();
+ }
+ }
+ } else {
+ IASTFileLocation loc = node.getFileLocation();
+
+ fileOffset = loc.getNodeOffset();
+ length = loc.getNodeLength();
+ }
+ return fileOffset + length;
+
+ }
+
+ public static int getEndOffsetWithoutComments(IASTNode node) {
+ return node.getFileLocation().getNodeOffset() + node.getFileLocation().getNodeLength();
+ }
+
+ public static int getLengthIncludingComment(IASTNode node) {
+ return OffsetHelper.getEndOffsetIncludingComments(node) - OffsetHelper.getOffsetIncludingComment(node);
+ }
+
+ public static int getNodeOffset(ASTNode node) {
+ return node.getOffset();
+ }
+
+ public static int getNodeEndPoint(ASTNode node) {
+ return node.getOffset() + node.getLength();
+ }
+
+ public static int getStartingLineNumber(IASTNode node) {
+ return node.getFileLocation().getStartingLineNumber();
+ }
+
+ public static int getEndingLineNumber(IASTNode node) {
+ return node.getFileLocation().getEndingLineNumber();
+ }
+
+}

Back to the top