diff options
| author | Sergey Prigogin | 2011-12-14 03:44:22 +0000 |
|---|---|---|
| committer | Sergey Prigogin | 2011-12-14 03:46:10 +0000 |
| commit | c521604dd1dde08dfd55e8e08fae1de4ad6a2e21 (patch) | |
| tree | c222b9837b561e15d15f9ffc8386058a2d515f31 | |
| parent | 18ec28be0f857e0e6b6e7ee293b148f8dc64f21c (diff) | |
| download | org.eclipse.cdt-c521604dd1dde08dfd55e8e08fae1de4ad6a2e21.tar.gz org.eclipse.cdt-c521604dd1dde08dfd55e8e08fae1de4ad6a2e21.tar.xz org.eclipse.cdt-c521604dd1dde08dfd55e8e08fae1de4ad6a2e21.zip | |
Bug 363244 - Generate Getters and Setters expands macro with typedef and
breaks formatting. The bug was fixed by minimizing areas of code
affected by the refactoring changes. This minimization had a huge ripple
effect.
91 files changed, 1681 insertions, 1615 deletions
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 index 29f9781df2a..8eea3e22ddf 100644 --- 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 @@ -97,7 +97,7 @@ public class ASTWriterTest extends RewriteBaseTest { IScanner scanner = AST2BaseTest.createScanner(codeReader, language, ParserMode.COMPLETE_PARSE, scannerInfo); - ISourceCodeParser parser2 = null; + ISourceCodeParser parser = null; if (language == ParserLanguage.CPP) { ICPPParserExtensionConfiguration config = null; if (useGNUExtensions) { @@ -105,7 +105,7 @@ public class ASTWriterTest extends RewriteBaseTest { } else { config = new ANSICPPParserExtensionConfiguration(); } - parser2 = new GNUCPPSourceParser(scanner, ParserMode.COMPLETE_PARSE, NULL_LOG, config); + parser = new GNUCPPSourceParser(scanner, ParserMode.COMPLETE_PARSE, NULL_LOG, config); } else { ICParserExtensionConfiguration config = null; @@ -115,9 +115,9 @@ public class ASTWriterTest extends RewriteBaseTest { config = new ANSICParserExtensionConfiguration(); } - parser2 = new GNUCSourceParser(scanner, ParserMode.COMPLETE_PARSE, NULL_LOG, config); + parser = new GNUCSourceParser(scanner, ParserMode.COMPLETE_PARSE, NULL_LOG, config); } - return parser2; + return parser; } private boolean getGNUExtension(TestSourceFile file) { 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 index ee1b12a3f24..2abf569e661 100644 --- 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 @@ -15,7 +15,6 @@ 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; @@ -35,18 +34,17 @@ public class SourceRewriteTester extends TestSuite { 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} + 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)); + file = FileLocator.toFileURL(FileLocator.find(bundle, path, null)).getFile(); + return new BufferedReader(new FileReader(file)); } 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); @@ -54,9 +52,7 @@ public class SourceRewriteTester extends TestSuite { 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(); + for (RewriteBaseTest subject : testCases) { suite.addTest(subject); } return suite; @@ -155,7 +151,8 @@ public class SourceRewriteTester extends TestSuite { return ParserLanguage.C; } - private static RewriteBaseTest createTestClass(String testName, ASTWriterTestSourceFile file) throws Exception { + private static RewriteBaseTest createTestClass(String testName, ASTWriterTestSourceFile file) + throws Exception { ASTWriterTest test = new ASTWriterTest(testName, file); TextSelection sel = file.getSelection(); if (sel != null) { 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 index f4cce8ff6e7..01b7186116f 100644 --- 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 @@ -7,7 +7,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Institute for Software - initial API and implementation + * Institute for Software - initial API and implementation *******************************************************************************/ package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.append; @@ -16,13 +16,11 @@ import junit.framework.TestSuite; /** * @author Thomas Corbat - * */ -public class AppendTestSuite{ +public class AppendTestSuite { public static Test suite() throws Exception { - TestSuite suite = new TestSuite("Changegenerator Append Child Tests"); - + TestSuite suite = new TestSuite("ChangeGenerator Append Child Tests"); suite.addTest(ParameterTest.suite()); suite.addTest(ParameterToListTest.suite()); suite.addTest(PointerToParameterTest.suite()); @@ -32,7 +30,6 @@ public class AppendTestSuite{ 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 index c076cf39eea..5980bd53a73 100644 --- 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 @@ -49,13 +49,14 @@ public class ArrayModifierTest extends ChangeGeneratorTest { @Override public int visit(IASTDeclarator declarator) { if (declarator instanceof IASTArrayDeclarator) { - IASTArrayDeclarator arrayDeclarator = (IASTArrayDeclarator)declarator; + IASTArrayDeclarator arrayDeclarator = (IASTArrayDeclarator) declarator; arrayDeclarator.getArrayModifiers(); IASTArrayModifier newModifier = new CPPASTArrayModifier(); IASTExpression expr = new CPPASTLiteralExpression( IASTLiteralExpression.lk_integer_constant, "3".toCharArray()); //$NON-NLS-1$ newModifier.setConstantExpression(expr); - ASTModification modification = new ASTModification(ModificationKind.APPEND_CHILD, declarator, newModifier, null); + ASTModification modification = new ASTModification(ModificationKind.APPEND_CHILD, + declarator, 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/append/ArraySizeExpressionTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/append/ArraySizeExpressionTest.java index 7a382a59501..484f6037c8c 100644 --- 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 @@ -7,7 +7,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Institute for Software - initial API and implementation + * Institute for Software - initial API and implementation *******************************************************************************/ package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.append; @@ -39,8 +39,7 @@ public class ArraySizeExpressionTest extends ChangeGeneratorTest { } @Override - protected ASTVisitor createModificator( - final ASTModificationStore modStore) { + protected ASTVisitor createModificator(final ASTModificationStore modStore) { return new ASTVisitor() { { shouldVisitExpressions = true; @@ -53,8 +52,9 @@ public class ArraySizeExpressionTest extends ChangeGeneratorTest { IASTTypeId id= newExpression.getTypeId(); IASTArrayDeclarator dtor= (IASTArrayDeclarator) id.getAbstractDeclarator(); IASTArrayModifier[] mods= dtor.getArrayModifiers(); - IASTArrayModifier add= new CPPASTArrayModifier(new CPPASTLiteralExpression(0, "5")); - ASTModification modification = new ASTModification(ASTModification.ModificationKind.APPEND_CHILD, dtor, add, null); + IASTArrayModifier add= new CPPASTArrayModifier(new CPPASTLiteralExpression(0, "5".toCharArray())); + ASTModification modification = new ASTModification(ASTModification.ModificationKind.APPEND_CHILD, + dtor, add, 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/append/CtorChainInitializerTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/append/CtorChainInitializerTest.java index 52ba71e2ecc..5f785a29d27 100644 --- 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 @@ -33,14 +33,13 @@ public class CtorChainInitializerTest extends ChangeGeneratorTest { @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$ + source = "TestClass::TestClass(int a, int b) :\n\t\tbeta(b) {\n}\n"; //$NON-NLS-1$ + expectedSource = "TestClass::TestClass(int a, int b) :\n\t\tbeta(b), alpha(a) {\n}\n"; //$NON-NLS-1$ super.setUp(); } @Override - protected ASTVisitor createModificator( - final ASTModificationStore modStore) { + protected ASTVisitor createModificator(final ASTModificationStore modStore) { return new ASTVisitor() { { shouldVisitDeclarations = true; @@ -49,12 +48,13 @@ public class CtorChainInitializerTest extends ChangeGeneratorTest { @Override public int visit(IASTDeclaration decl) { if (decl instanceof CPPASTFunctionDefinition) { - CPPASTFunctionDefinition fdef = (CPPASTFunctionDefinition)decl; + CPPASTFunctionDefinition fdef = (CPPASTFunctionDefinition) decl; 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, null); newInitializer.setInitializerValue(initExpr); - ASTModification modification = new ASTModification(ModificationKind.APPEND_CHILD, fdef, newInitializer, null); + ASTModification modification = new ASTModification(ModificationKind.APPEND_CHILD, + fdef, 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/append/ExceptionTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/append/ExceptionTest.java index 64c10ec2da7..9a9a1d0519a 100644 --- 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 @@ -35,8 +35,8 @@ public class ExceptionTest extends ChangeGeneratorTest { @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$ + 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(); } @@ -57,7 +57,8 @@ public class ExceptionTest extends ChangeGeneratorTest { exDeclSpec.setType(IASTSimpleDeclSpecifier.t_int); exception.setDeclSpecifier(exDeclSpec); exception.setAbstractDeclarator(exceptionDeclarator); - ASTModification modification = new ASTModification(ModificationKind.APPEND_CHILD, declarator, exception, null); + ASTModification modification = new ASTModification(ModificationKind.APPEND_CHILD, + declarator, 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/append/ExpressionTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/append/ExpressionTest.java index ee3fcf6c906..fe2e6e295be 100644 --- 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 @@ -33,8 +33,8 @@ public class ExpressionTest extends ChangeGeneratorTest { @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$ + source = "void main() {\n\tint s = 0, c = 0, h = 0;\n\ts = 3, h = 5;\n}"; //$NON-NLS-1$ + expectedSource = "void main() {\n\tint s = 0, c = 0, h = 0;\n\ts = 3, h = 5, c = 9;\n}"; //$NON-NLS-1$ super.setUp(); } @Override @@ -49,18 +49,19 @@ public class ExpressionTest extends ChangeGeneratorTest { 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); + CPPASTIdExpression idExpression = new CPPASTIdExpression(new CPPASTName("c".toCharArray())); + CPPASTBinaryExpression binEx = new CPPASTBinaryExpression(IASTBinaryExpression.op_assign, + idExpression, new CPPASTLiteralExpression(0, "9".toCharArray())); //$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 index 82a494a31b7..1133eba9ebb 100644 --- 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 @@ -7,7 +7,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Institute for Software - initial API and implementation + * Institute for Software - initial API and implementation *******************************************************************************/ package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.append; @@ -34,8 +34,8 @@ public class ParameterTest extends ChangeGeneratorTest { @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$ + source = "void foo(int existing) {\n}\n"; //$NON-NLS-1$ + expectedSource = "void foo(int existing, int newParameter) {\n}\n"; //$NON-NLS-1$ super.setUp(); } @@ -49,7 +49,7 @@ public class ParameterTest extends ChangeGeneratorTest { @Override public int visit(IASTDeclarator declarator) { if (declarator instanceof CPPASTFunctionDeclarator) { - CPPASTFunctionDeclarator functionDeclarator = (CPPASTFunctionDeclarator)declarator; + CPPASTFunctionDeclarator functionDeclarator = (CPPASTFunctionDeclarator) declarator; CPPASTParameterDeclaration insertedParameter = new CPPASTParameterDeclaration(); CPPASTDeclarator parameterDeclarator = new CPPASTDeclarator(); @@ -59,7 +59,8 @@ public class ParameterTest extends ChangeGeneratorTest { CPPASTSimpleDeclSpecifier parameterDeclSpec = new CPPASTSimpleDeclSpecifier(); parameterDeclSpec.setType(IASTSimpleDeclSpecifier.t_int); insertedParameter.setDeclSpecifier(parameterDeclSpec); - ASTModification modification = new ASTModification(ModificationKind.APPEND_CHILD, functionDeclarator, insertedParameter, null); + ASTModification modification = new ASTModification(ModificationKind.APPEND_CHILD, + functionDeclarator, insertedParameter, 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/append/ParameterToListTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/append/ParameterToListTest.java index 82bfec4dd84..3ebf4630255 100644 --- 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 @@ -34,8 +34,8 @@ public class ParameterToListTest extends ChangeGeneratorTest { @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$ + source = "void foo() {\n}\n\n"; //$NON-NLS-1$ + expectedSource = "void foo(int newParameter) {\n}\n\n"; //$NON-NLS-1$ super.setUp(); } @@ -49,7 +49,7 @@ public class ParameterToListTest extends ChangeGeneratorTest { @Override public int visit(IASTDeclarator declarator) { if (declarator instanceof CPPASTFunctionDeclarator) { - CPPASTFunctionDeclarator functionDeclarator = (CPPASTFunctionDeclarator)declarator; + CPPASTFunctionDeclarator functionDeclarator = (CPPASTFunctionDeclarator) declarator; CPPASTParameterDeclaration insertedParameter = new CPPASTParameterDeclaration(); CPPASTDeclarator parameterDeclarator = new CPPASTDeclarator(); @@ -59,7 +59,8 @@ public class ParameterToListTest extends ChangeGeneratorTest { CPPASTSimpleDeclSpecifier parameterDeclSpec = new CPPASTSimpleDeclSpecifier(); parameterDeclSpec.setType(IASTSimpleDeclSpecifier.t_int); insertedParameter.setDeclSpecifier(parameterDeclSpec); - ASTModification modification = new ASTModification(ModificationKind.APPEND_CHILD, functionDeclarator, insertedParameter, null); + ASTModification modification = new ASTModification(ModificationKind.APPEND_CHILD, + functionDeclarator, insertedParameter, 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/append/PointerToParameterTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/append/PointerToParameterTest.java index 1daa37a8b59..b80a12b223e 100644 --- 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 @@ -31,8 +31,8 @@ public class PointerToParameterTest extends ChangeGeneratorTest { @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$ + source = "void foo(int parameter) {\n}\n\n"; //$NON-NLS-1$ + expectedSource = "void foo(int *parameter) {\n}\n\n"; //$NON-NLS-1$ super.setUp(); } @@ -46,12 +46,13 @@ public class PointerToParameterTest extends ChangeGeneratorTest { @Override public int visit(IASTDeclarator declarator) { if (declarator instanceof CPPASTFunctionDeclarator) { - CPPASTFunctionDeclarator functionDeclarator = (CPPASTFunctionDeclarator)declarator; + 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); + ASTModification modification = new ASTModification(ModificationKind.APPEND_CHILD, + curParam.getDeclarator(), addedPointer, null); modStore.storeModification(null, modification); } } 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 index f9c2e1837ca..7e5d9497a3e 100644 --- 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 @@ -31,8 +31,8 @@ public class PointerToPointerParameterTest extends ChangeGeneratorTest { @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$ + source = "void foo(int *parameter) {\n}\n\n"; //$NON-NLS-1$ + expectedSource = "void foo(int **parameter) {\n}\n\n"; //$NON-NLS-1$ super.setUp(); } @@ -46,12 +46,13 @@ public class PointerToPointerParameterTest extends ChangeGeneratorTest { @Override public int visit(IASTDeclarator declarator) { if (declarator instanceof CPPASTFunctionDeclarator) { - CPPASTFunctionDeclarator functionDeclarator = (CPPASTFunctionDeclarator)declarator; + 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); + ASTModification modification = new ASTModification(ModificationKind.APPEND_CHILD, + curParam.getDeclarator(), addedPointer, null); modStore.storeModification(null, modification); } } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/insertbefore/AddDeclarationBug.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/insertbefore/AddDeclarationBug.java index a4ee61615bd..70289c4204e 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/insertbefore/AddDeclarationBug.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/insertbefore/AddDeclarationBug.java @@ -69,7 +69,8 @@ public class AddDeclarationBug extends ChangeGeneratorTest { returnTyp.setType(IASTSimpleDeclSpecifier.t_int); newDecl.setDeclSpecifier(returnTyp); - IASTStandardFunctionDeclarator declarator = new CPPASTFunctionDeclarator(new CPPASTName("exp".toCharArray())); //$NON-NLS-1$ + IASTStandardFunctionDeclarator declarator = new CPPASTFunctionDeclarator( + new CPPASTName("exp".toCharArray())); //$NON-NLS-1$ IASTSimpleDeclSpecifier paramTyp = new CPPASTSimpleDeclSpecifier(); paramTyp.setType(IASTSimpleDeclSpecifier.t_int); IASTDeclarator decl = new CPPASTDeclarator(new CPPASTName("i".toCharArray())); //$NON-NLS-1$ @@ -77,7 +78,8 @@ public class AddDeclarationBug extends ChangeGeneratorTest { declarator.addParameterDeclaration(param); newDecl.addDeclarator(declarator); - ASTModification mod = new ASTModification(ModificationKind.APPEND_CHILD, classNode, newDecl, null); + ASTModification mod = new ASTModification(ModificationKind.APPEND_CHILD, classNode, + newDecl, null); modStore.storeModification(null, mod); } return PROCESS_CONTINUE; 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 index 68f994fbdeb..06631d32759 100644 --- 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 @@ -60,7 +60,8 @@ public class ArrayModifierTest extends ChangeGeneratorTest { IASTExpression expr = new CPPASTLiteralExpression(IASTLiteralExpression.lk_integer_constant, "5".toCharArray()); //$NON-NLS-1$ newModifier.setConstantExpression(expr); - ASTModification modification = new ASTModification(ModificationKind.INSERT_BEFORE, modifiers[0], newModifier, null); + ASTModification modification = new ASTModification(ModificationKind.INSERT_BEFORE, + 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/insertbefore/ArraySizeExpressionTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/insertbefore/ArraySizeExpressionTest.java index df71239e075..35b4e438051 100644 --- 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 @@ -59,7 +59,8 @@ public class ArraySizeExpressionTest extends ChangeGeneratorTest { IASTArrayModifier[] mods= dtor.getArrayModifiers(); IASTArrayModifier add= new CPPASTArrayModifier( new CPPASTLiteralExpression(IASTLiteralExpression.lk_integer_constant, "6".toCharArray())); - ASTModification modification = new ASTModification(ASTModification.ModificationKind.INSERT_BEFORE, mods[0], add, null); + ASTModification modification = new ASTModification(ASTModification.ModificationKind.INSERT_BEFORE, + mods[0], add, 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/insertbefore/CtorChainInitializerTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/insertbefore/CtorChainInitializerTest.java index 983348efcbb..d99d7cb36fb 100644 --- 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 @@ -60,7 +60,6 @@ public class CtorChainInitializerTest extends ChangeGeneratorTest { newInitializer.setInitializerValue(initExpr); ASTModification modification = new ASTModification(ModificationKind.INSERT_BEFORE, ctorInitializer, 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/insertbefore/ExceptionTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/insertbefore/ExceptionTest.java index 4612e5a13fb..2346209def5 100644 --- 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 @@ -54,7 +54,7 @@ public class ExceptionTest extends ChangeGeneratorTest { @Override public int visit(IASTDeclarator declarator) { if (declarator instanceof CPPASTFunctionDeclarator) { - CPPASTFunctionDeclarator functionDeclarator = (CPPASTFunctionDeclarator)declarator; + CPPASTFunctionDeclarator functionDeclarator = (CPPASTFunctionDeclarator) declarator; IASTTypeId existingException = functionDeclarator.getExceptionSpecification()[0]; IASTTypeId exception = new CPPASTTypeId(); @@ -64,9 +64,9 @@ public class ExceptionTest extends ChangeGeneratorTest { exDeclSpec.setType(IASTSimpleDeclSpecifier.t_int); exception.setDeclSpecifier(exDeclSpec); exception.setAbstractDeclarator(exceptionDeclarator); - ASTModification modification = new ASTModification(ModificationKind.INSERT_BEFORE, existingException, exception, null); + ASTModification modification = new ASTModification(ModificationKind.INSERT_BEFORE, + 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/insertbefore/ExpressionTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/insertbefore/ExpressionTest.java index af06f5d44fb..cd347cb44dc 100644 --- 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 @@ -37,8 +37,8 @@ public class ExpressionTest extends ChangeGeneratorTest { @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$ + source = "void main() {\n\tint s = 0, c = 0, h = 0;\n\ts = 3, h = 5;\n}"; //$NON-NLS-1$ + expectedSource = "void main() {\n\tint s = 0, c = 0, h = 0;\n\ts = 3, c = 9, h = 5;\n}"; //$NON-NLS-1$ super.setUp(); } @@ -54,8 +54,11 @@ public class ExpressionTest extends ChangeGeneratorTest { 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); + CPPASTIdExpression idExpression = new CPPASTIdExpression(new CPPASTName("c".toCharArray())); //$NON-NLS-1$ + CPPASTBinaryExpression binEx = new CPPASTBinaryExpression(IASTBinaryExpression.op_assign, + idExpression, new CPPASTLiteralExpression(0, "9".toCharArray())); //$NON-NLS-1$ + ASTModification modification = new ASTModification(ASTModification.ModificationKind.INSERT_BEFORE, + 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/insertbefore/FirstParameterTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/insertbefore/FirstParameterTest.java index 52e3fc5e10d..13db57b275b 100644 --- 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 @@ -39,8 +39,8 @@ public class FirstParameterTest extends ChangeGeneratorTest { @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$ + 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(); } @@ -54,10 +54,10 @@ public class FirstParameterTest extends ChangeGeneratorTest { @Override public int visit(IASTDeclarator declarator) { if (declarator instanceof CPPASTFunctionDeclarator) { - CPPASTFunctionDeclarator functionDeclarator = (CPPASTFunctionDeclarator)declarator; + CPPASTFunctionDeclarator functionDeclarator = (CPPASTFunctionDeclarator) declarator; IASTParameterDeclaration[] parameters = functionDeclarator.getParameters(); - for(IASTParameterDeclaration curParam : parameters){ - if(String.valueOf(curParam.getDeclarator().getName().toCharArray()).equals("a")){ //$NON-NLS-1$ + 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$ @@ -66,7 +66,8 @@ public class FirstParameterTest extends ChangeGeneratorTest { CPPASTSimpleDeclSpecifier parameterDeclSpec = new CPPASTSimpleDeclSpecifier(); parameterDeclSpec.setType(IASTSimpleDeclSpecifier.t_int); insertedParameter.setDeclSpecifier(parameterDeclSpec); - ASTModification modification = new ASTModification(ModificationKind.INSERT_BEFORE, curParam, insertedParameter, null); + ASTModification modification = new ASTModification(ModificationKind.INSERT_BEFORE, + curParam, insertedParameter, null); modStore.storeModification(null, modification); } } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/insertbefore/MultilineWhitespaceHandlingTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/insertbefore/MultilineWhitespaceHandlingTest.java index fd334b535b6..8384465ad83 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/insertbefore/MultilineWhitespaceHandlingTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/insertbefore/MultilineWhitespaceHandlingTest.java @@ -38,8 +38,8 @@ public class MultilineWhitespaceHandlingTest extends ChangeGeneratorTest { @Override protected void setUp() throws Exception { - source = "void foo() {\r\n\r\n\tfor(int i = 0; i < 10; i++) {\r\n\r\n\t}\r\n}\r\n"; //$NON-NLS-1$ - expectedSource = "void foo() {\r\n\r\n\tfor(int i = 0; i < 10; i++) {\r\n\t\tint i;\r\n\t\tint j;\r\n\r\n\t}\r\n}\r\n"; //$NON-NLS-1$ + source = "void foo() {\n\tfor (int i = 0; i < 10; i++) {\n\n\n\t}\n}\n"; //$NON-NLS-1$ + expectedSource = "void foo() {\n\tfor (int i = 0; i < 10; i++) {\n\t\tint i;\n\t\tint j;\n\t}\n}\n"; //$NON-NLS-1$ super.setUp(); } @@ -73,7 +73,8 @@ public class MultilineWhitespaceHandlingTest extends ChangeGeneratorTest { newSimpleDeclaration.addDeclarator(nf.newDeclarator(nf.newName(variableName.toCharArray()))); IASTDeclarationStatement newDeclaration = nf.newDeclarationStatement(newSimpleDeclaration); - ASTModification modification = new ASTModification(ASTModification.ModificationKind.APPEND_CHILD, compoundStatement, newDeclaration, null); + ASTModification modification = new ASTModification(ASTModification.ModificationKind.APPEND_CHILD, + compoundStatement, newDeclaration, null); modStore.storeModification(null, modification); } }; 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 index aebdd2799d6..d71ad4fe2ad 100644 --- 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 @@ -36,8 +36,8 @@ public class PointerParameterTest extends ChangeGeneratorTest { @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$ + source = "void foo(int *parameter) {\n}\n\n"; //$NON-NLS-1$ + expectedSource = "void foo(int **parameter) {\n}\n\n"; //$NON-NLS-1$ super.setUp(); } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/insertbefore/SelfInsertionTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/insertbefore/SelfInsertionTest.java index ebaf97b3a3c..d93bc36e7a5 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/insertbefore/SelfInsertionTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/insertbefore/SelfInsertionTest.java @@ -51,7 +51,8 @@ public class SelfInsertionTest extends ChangeGeneratorTest { IASTForStatement forStatement = (IASTForStatement) statement; IASTCompoundStatement compoundStatement = (IASTCompoundStatement) forStatement.getBody(); - ASTModification modification = new ASTModification(ASTModification.ModificationKind.APPEND_CHILD, compoundStatement, forStatement, null); + ASTModification modification = new ASTModification(ASTModification.ModificationKind.APPEND_CHILD, + compoundStatement, forStatement, null); modStore.storeModification(null, modification); } 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 index d133af89f15..efa059ed979 100644 --- 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 @@ -7,7 +7,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Institute for Software - initial API and implementation + * Institute for Software - initial API and implementation *******************************************************************************/ package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.remove; @@ -24,14 +24,14 @@ import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKin public class CtorChainInitializerTest extends ChangeGeneratorTest { - public CtorChainInitializerTest(){ + 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$ + 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(); } @@ -40,8 +40,7 @@ public class CtorChainInitializerTest extends ChangeGeneratorTest { } @Override - protected ASTVisitor createModificator( - final ASTModificationStore modStore) { + protected ASTVisitor createModificator(final ASTModificationStore modStore) { return new ASTVisitor() { { shouldVisitDeclarators = true; @@ -50,11 +49,12 @@ public class CtorChainInitializerTest extends ChangeGeneratorTest { @Override public int visit(IASTDeclarator declarator) { if (declarator instanceof CPPASTFunctionDeclarator) { - CPPASTFunctionDeclarator functionDeclarator = (CPPASTFunctionDeclarator)declarator; + 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); + 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/ExceptionTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/remove/ExceptionTest.java index d696478de52..c267f02e629 100644 --- 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 @@ -7,7 +7,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Institute for Software - initial API and implementation + * Institute for Software - initial API and implementation *******************************************************************************/ package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.remove; @@ -30,8 +30,8 @@ public class ExceptionTest extends ChangeGeneratorTest { @Override protected void setUp() throws Exception { - source = "void foo(int parameter) throw (int){\n}\n\n"; //$NON-NLS-1$ - expectedSource = "void foo(int parameter) throw (){\n}\n\n"; //$NON-NLS-1$ + source = "void foo(int parameter) throw (int) {\n}\n\n"; //$NON-NLS-1$ + expectedSource = "void foo(int parameter) throw () {\n}\n\n"; //$NON-NLS-1$ super.setUp(); } @@ -40,8 +40,7 @@ public class ExceptionTest extends ChangeGeneratorTest { } @Override - protected ASTVisitor createModificator( - final ASTModificationStore modStore) { + protected ASTVisitor createModificator(final ASTModificationStore modStore) { return new ASTVisitor() { { shouldVisitDeclarators = true; @@ -50,11 +49,12 @@ public class ExceptionTest extends ChangeGeneratorTest { @Override public int visit(IASTDeclarator declarator) { if (declarator instanceof CPPASTFunctionDeclarator) { - CPPASTFunctionDeclarator functionDeclarator = (CPPASTFunctionDeclarator)declarator; + 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); + 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 index 9db30320ffd..80ee20081ae 100644 --- 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 @@ -7,7 +7,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Institute for Software - initial API and implementation + * Institute for Software - initial API and implementation *******************************************************************************/ package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.remove; @@ -20,20 +20,16 @@ import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGenerator 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(){ + 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$ + source = "void main() {\n\tint s = 0, c = 0, h = 0;\n\ts = 3, c = 4, h = 5;\n}"; //$NON-NLS-1$ + expectedSource = "void main() {\n\tint s = 0, c = 0, h = 0;\n\ts = 3, h = 5;\n}"; //$NON-NLS-1$ super.setUp(); } @@ -42,8 +38,7 @@ public class ExpressionTest extends ChangeGeneratorTest { } @Override - protected ASTVisitor createModificator( - final ASTModificationStore modStore) { + protected ASTVisitor createModificator(final ASTModificationStore modStore) { return new ASTVisitor() { { shouldVisitExpressions = true; @@ -54,13 +49,12 @@ public class ExpressionTest extends ChangeGeneratorTest { if (expression instanceof IASTExpressionList) { IASTExpressionList expressionList = (IASTExpressionList) expression; IASTExpression[] expressions = expressionList.getExpressions(); - ASTModification modification = new ASTModification(ASTModification.ModificationKind.REPLACE, expressions[1], null, null); + 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 index ef0eb694f3d..9038843fd12 100644 --- 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 @@ -7,7 +7,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Institute for Software - initial API and implementation + * Institute for Software - initial API and implementation *******************************************************************************/ package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.remove; @@ -22,31 +22,25 @@ 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(){ + 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$ + 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 ASTVisitor createModificator( - final ASTModificationStore modStore) { + protected ASTVisitor createModificator(final ASTModificationStore modStore) { return new ASTVisitor() { { shouldVisitDeclarators = true; @@ -55,11 +49,12 @@ public class FirstParameterTest extends ChangeGeneratorTest { @Override public int visit(IASTDeclarator declarator) { if (declarator instanceof CPPASTFunctionDeclarator) { - CPPASTFunctionDeclarator functionDeclarator = (CPPASTFunctionDeclarator)declarator; + 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); + 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); } } @@ -69,6 +64,4 @@ public class FirstParameterTest extends ChangeGeneratorTest { }; } - - } 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 index 247af14a7b2..479ded5bc10 100644 --- 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 @@ -7,7 +7,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Institute for Software - initial API and implementation + * Institute for Software - initial API and implementation *******************************************************************************/ package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.remove; @@ -22,18 +22,16 @@ 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(){ + 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$ + 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(); } @@ -42,8 +40,7 @@ public class LastParameterTest extends ChangeGeneratorTest { } @Override - protected ASTVisitor createModificator( - final ASTModificationStore modStore) { + protected ASTVisitor createModificator(final ASTModificationStore modStore) { return new ASTVisitor() { { shouldVisitDeclarators = true; @@ -52,17 +49,17 @@ public class LastParameterTest extends ChangeGeneratorTest { @Override public int visit(IASTDeclarator declarator) { if (declarator instanceof CPPASTFunctionDeclarator) { - CPPASTFunctionDeclarator functionDeclarator = (CPPASTFunctionDeclarator)declarator; + 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); + 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 index bce8240daa9..04186f85057 100644 --- 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 @@ -7,7 +7,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Institute for Software - initial API and implementation + * Institute for Software - initial API and implementation *******************************************************************************/ package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.remove; @@ -22,10 +22,6 @@ 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(){ @@ -34,8 +30,8 @@ public class MiddleParameterTest extends ChangeGeneratorTest { @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$ + 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(); } @@ -44,10 +40,8 @@ public class MiddleParameterTest extends ChangeGeneratorTest { return new MiddleParameterTest(); } - @Override - protected ASTVisitor createModificator( - final ASTModificationStore modStore) { + protected ASTVisitor createModificator(final ASTModificationStore modStore) { return new ASTVisitor() { { shouldVisitDeclarators = true; @@ -56,11 +50,12 @@ public class MiddleParameterTest extends ChangeGeneratorTest { @Override public int visit(IASTDeclarator declarator) { if (declarator instanceof CPPASTFunctionDeclarator) { - CPPASTFunctionDeclarator functionDeclarator = (CPPASTFunctionDeclarator)declarator; + 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); + 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); } } 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 index 40345c68d49..c1b61f6d94b 100644 --- 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 @@ -7,7 +7,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Institute for Software - initial API and implementation + * Institute for Software - initial API and implementation *******************************************************************************/ package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.remove; @@ -25,25 +25,23 @@ import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKin public class PointerInParameterTest extends ChangeGeneratorTest { - public PointerInParameterTest(){ + 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$ + 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 ASTVisitor createModificator( - final ASTModificationStore modStore) { + protected ASTVisitor createModificator(final ASTModificationStore modStore) { return new ASTVisitor() { { shouldVisitDeclarators = true; @@ -52,18 +50,18 @@ public class PointerInParameterTest extends ChangeGeneratorTest { @Override public int visit(IASTDeclarator declarator) { if (declarator instanceof CPPASTFunctionDeclarator) { - CPPASTFunctionDeclarator functionDeclarator = (CPPASTFunctionDeclarator)declarator; + CPPASTFunctionDeclarator functionDeclarator = (CPPASTFunctionDeclarator) declarator; IASTParameterDeclaration[] parameters = functionDeclarator.getParameters(); - for(IASTParameterDeclaration curParam : parameters){ - if(String.valueOf(curParam.getDeclarator().getName().toCharArray()).equals("parameter")){ //$NON-NLS-1$ + 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); + 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 index be547e43068..2cdc0314d3a 100644 --- 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 @@ -7,7 +7,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Institute for Software - initial API and implementation + * Institute for Software - initial API and implementation *******************************************************************************/ package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.remove; @@ -16,13 +16,11 @@ import junit.framework.TestSuite; /** * @author Thomas Corbat - * */ -public class RemoveTestSuite{ +public class RemoveTestSuite { public static Test suite() throws Exception { - TestSuite suite = new TestSuite("Changegenerator Remove Tests"); - + TestSuite suite = new TestSuite("ChangeGenerator Remove Tests"); suite.addTest(DeclarationTest.suite()); suite.addTest(FirstParameterTest.suite()); suite.addTest(MiddleParameterTest.suite()); @@ -36,7 +34,6 @@ public class RemoveTestSuite{ 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 index 4d86c479b3e..0ac211f999e 100644 --- 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 @@ -7,7 +7,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Institute for Software - initial API and implementation + * Institute for Software - initial API and implementation *******************************************************************************/ package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.remove; @@ -24,25 +24,23 @@ import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKin public class SingleParameterTest extends ChangeGeneratorTest { - public SingleParameterTest(){ + 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$ + 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 ASTVisitor createModificator( - final ASTModificationStore modStore) { + protected ASTVisitor createModificator(final ASTModificationStore modStore) { return new ASTVisitor() { { shouldVisitDeclarators = true; @@ -51,11 +49,12 @@ public class SingleParameterTest extends ChangeGeneratorTest { @Override public int visit(IASTDeclarator declarator) { if (declarator instanceof CPPASTFunctionDeclarator) { - CPPASTFunctionDeclarator functionDeclarator = (CPPASTFunctionDeclarator)declarator; + 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); + 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); } } 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 index 2ba4ce83dc7..7d14200d15e 100644 --- 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 @@ -7,7 +7,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Institute for Software - initial API and implementation + * Institute for Software - initial API and implementation *******************************************************************************/ package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.replace; @@ -29,15 +29,14 @@ import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKin 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$ + 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(); } @@ -46,8 +45,7 @@ public class ExceptionTest extends ChangeGeneratorTest { } @Override - protected ASTVisitor createModificator( - final ASTModificationStore modStore) { + protected ASTVisitor createModificator(final ASTModificationStore modStore) { return new ASTVisitor() { { shouldVisitDeclarators = true; @@ -56,7 +54,7 @@ public class ExceptionTest extends ChangeGeneratorTest { @Override public int visit(IASTDeclarator declarator) { if (declarator instanceof CPPASTFunctionDeclarator) { - CPPASTFunctionDeclarator functionDeclarator = (CPPASTFunctionDeclarator)declarator; + CPPASTFunctionDeclarator functionDeclarator = (CPPASTFunctionDeclarator) declarator; IASTTypeId existingException = functionDeclarator.getExceptionSpecification()[0]; IASTTypeId exception = new CPPASTTypeId(); @@ -66,13 +64,12 @@ public class ExceptionTest extends ChangeGeneratorTest { exDeclSpec.setType(IASTSimpleDeclSpecifier.t_int); exception.setDeclSpecifier(exDeclSpec); exception.setAbstractDeclarator(exceptionDeclarator); - ASTModification modification = new ASTModification(ModificationKind.REPLACE, existingException, exception, null); + 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 index 5d86fa5eef5..63ab2dc63cf 100644 --- 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 @@ -7,7 +7,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Institute for Software - initial API and implementation + * Institute for Software - initial API and implementation *******************************************************************************/ package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.replace; @@ -25,20 +25,16 @@ 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(){ + 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$ + source = "void main() {\n\tint s = 0, c = 0, h = 0;\n\ts = 3, c = 4, h = 5;\n}"; //$NON-NLS-1$ + expectedSource = "void main() {\n\tint s = 0, c = 0, h = 0;\n\ts = 3, c = 9, h = 5;\n}"; //$NON-NLS-1$ super.setUp(); } @@ -46,10 +42,8 @@ public class ExpressionTest extends ChangeGeneratorTest { return new ExpressionTest(); } - @Override - protected ASTVisitor createModificator( - final ASTModificationStore modStore) { + protected ASTVisitor createModificator(final ASTModificationStore modStore) { return new ASTVisitor() { { shouldVisitExpressions = true; @@ -60,8 +54,11 @@ public class ExpressionTest extends ChangeGeneratorTest { 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); + CPPASTBinaryExpression binEx = new CPPASTBinaryExpression(IASTBinaryExpression.op_assign, + new CPPASTIdExpression(new CPPASTName("c".toCharArray())), //$NON-NLS-1$ + new CPPASTLiteralExpression(0, "9".toCharArray())); //$NON-NLS-1$ + 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/PointerInParameterTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/replace/PointerInParameterTest.java index da04057e0ae..86936d0effb 100644 --- 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 @@ -7,7 +7,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Institute for Software - initial API and implementation + * Institute for Software - initial API and implementation *******************************************************************************/ package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.replace; @@ -26,14 +26,14 @@ import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKin public class PointerInParameterTest extends ChangeGeneratorTest { - public PointerInParameterTest(){ + public PointerInParameterTest() { super("Replace Pointer for Parameter"); //$NON-NLS-1$ } @Override protected void setUp() throws Exception { - source = "void foo(int ¶meter){\n}\n\n"; //$NON-NLS-1$ - expectedSource = "void foo(int *parameter){\n}\n\n"; //$NON-NLS-1$ + source = "void foo(int ¶meter) {\n}\n\n"; //$NON-NLS-1$ + expectedSource = "void foo(int *parameter) {\n}\n\n"; //$NON-NLS-1$ super.setUp(); } @@ -42,8 +42,7 @@ public class PointerInParameterTest extends ChangeGeneratorTest { } @Override - protected ASTVisitor createModificator( - final ASTModificationStore modStore) { + protected ASTVisitor createModificator(final ASTModificationStore modStore) { return new ASTVisitor() { { shouldVisitDeclarators = true; @@ -52,10 +51,10 @@ public class PointerInParameterTest extends ChangeGeneratorTest { @Override public int visit(IASTDeclarator declarator) { if (declarator instanceof CPPASTFunctionDeclarator) { - CPPASTFunctionDeclarator functionDeclarator = (CPPASTFunctionDeclarator)declarator; + CPPASTFunctionDeclarator functionDeclarator = (CPPASTFunctionDeclarator) declarator; IASTParameterDeclaration[] parameters = functionDeclarator.getParameters(); - for(IASTParameterDeclaration curParam : parameters){ - if(String.valueOf(curParam.getDeclarator().getName().toCharArray()).equals("parameter")){ //$NON-NLS-1$ + 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); 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 index a2a46caf25e..e0c52e5d88c 100644 --- 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 @@ -7,7 +7,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Institute for Software - initial API and implementation + * Institute for Software - initial API and implementation *******************************************************************************/ package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.replace; @@ -16,12 +16,11 @@ import junit.framework.TestSuite; /** * @author Thomas Corbat - * */ -public class ReplaceTestSuite{ +public class ReplaceTestSuite { public static Test suite() throws Exception { - TestSuite suite = new TestSuite("ChangegeneratorReplaceTests"); + TestSuite suite = new TestSuite("ChangeGeneratorReplaceTests"); suite.addTest(NameTest.suite()); suite.addTest(MoveTest.suite()); 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 index 067a29f8f28..2075f407f3c 100644 --- 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 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik + * Copyright (c) 2008, 2011 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 @@ -11,9 +11,9 @@ ******************************************************************************/ package org.eclipse.cdt.core.parser.tests.rewrite.comenthandler; -import java.util.ArrayList; import java.util.Comparator; -import java.util.HashMap; +import java.util.List; +import java.util.Map; import java.util.TreeSet; import java.util.Vector; import java.util.regex.Matcher; @@ -140,12 +140,12 @@ public class CommentHandlingTest extends RewriteBaseTest { return actualResultBuilder; } - private String getCommentMapResult(HashMap<IASTNode, ArrayList<IASTComment>> map) { + private String getCommentMapResult(Map<IASTNode, List<IASTComment>> map) { 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); + List<IASTComment> comments = map.get(actNode); output.append(getSignature(actNode) + " = "); //$NON-NLS-1$ boolean first = true; for (IASTComment actComment : comments) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/ASTModificationMap.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/ASTModificationMap.java index ea35926d435..ee28e24cea8 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/ASTModificationMap.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/ASTModificationMap.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2008 Wind River Systems, Inc. and others. + * Copyright (c) 2007, 2011 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 @@ -7,6 +7,7 @@ * * Contributors: * Markus Schorn - initial API and implementation + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.rewrite; @@ -15,6 +16,7 @@ import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.List; +import java.util.Map; import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind; @@ -22,20 +24,18 @@ import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKin /** * Represents a list of modifications to an AST node. If there are nested modifications * to nodes introduced by insertions or replacements, these modifications are collected - * in separate modification maps. I.e. a modification map represents one level of - * modifications. + * in separate modification maps. I.e. a modification map represents one level of modifications. * @see ASTModificationStore * @since 5.0 */ public class ASTModificationMap { - private HashMap<IASTNode, List<ASTModification>> fModifications= new HashMap<IASTNode, List<ASTModification>>(); + private final Map<IASTNode, List<ASTModification>> fModifications= new HashMap<IASTNode, List<ASTModification>>(); /** * Adds a modification to this modification map. */ public void addModification(ASTModification mod) { - final IASTNode targetNode = mod.getKind() == ASTModification.ModificationKind.INSERT_BEFORE ? - mod.getTargetNode().getParent() : mod.getTargetNode(); + IASTNode targetNode = mod.getTargetNode(); List<ASTModification> mods= fModifications.get(targetNode); if (mods == null || mods.isEmpty()) { mods= new ArrayList<ASTModification>(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/ASTWriter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/ASTWriter.java index 5b7229e5de9..dc19453bfbc 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/ASTWriter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/ASTWriter.java @@ -14,9 +14,13 @@ package org.eclipse.cdt.internal.core.dom.rewrite.astwriter; import org.eclipse.cdt.core.dom.ast.IASTASMDeclaration; import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement; +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.IASTIfStatement; import org.eclipse.cdt.core.dom.ast.IASTNode; +import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement; +import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; import org.eclipse.cdt.core.dom.ast.IASTStatement; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration; @@ -34,7 +38,6 @@ import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap; */ public class ASTWriter { private ASTModificationStore modificationStore = new ASTModificationStore(); - private String givenIndentation = ""; //$NON-NLS-1$ /** * Creates a <code>ASTWriter</code>. @@ -44,16 +47,6 @@ public class ASTWriter { } /** - * Creates a <code>ASTWriter</code> that indents the code. - * - * @param givenIndentation The indentation added to each line - */ - public ASTWriter(String givenIndentation) { - super(); - this.givenIndentation = givenIndentation; - } - - /** * Generates the source code representing this node. * * @param rootNode Node to write. @@ -75,10 +68,9 @@ public class ASTWriter { * * @see ASTCommenter#getCommentedNodeMap(org.eclipse.cdt.core.dom.ast.IASTTranslationUnit) */ - public String write(IASTNode rootNode, NodeCommentMap commentMap) - throws ProblemRuntimeException { + public String write(IASTNode rootNode, NodeCommentMap commentMap) throws ProblemRuntimeException { ChangeGeneratorWriterVisitor writer = new ChangeGeneratorWriterVisitor( - modificationStore, givenIndentation, null, commentMap); + modificationStore, null, commentMap); if (rootNode != null) { rootNode.accept(writer); } @@ -152,10 +144,35 @@ public class ASTWriter { * @return <code>true</code> if the blank line between the nodes is needed. */ public static boolean requireBlankLineInBetween(IASTNode node1, IASTNode node2) { - if (requiresTrailingBlankLine(node1)) + if (node1 instanceof ICPPASTVisibilityLabel && node2 instanceof ICPPASTVisibilityLabel) { + return true; + } + if (suppressesTrailingBlankLine(node1)) { + return false; + } + if (node1 instanceof IASTPreprocessorIncludeStatement != + node2 instanceof IASTPreprocessorIncludeStatement) { + return true; + } + if (isFunctionDeclaration(node1) != isFunctionDeclaration(node2)) { + return true; + } + if (requiresTrailingBlankLine(node1)) { return true; + } + + return requiresLeadingBlankLine(node2); + } - return !suppressesTrailingBlankLine(node1) && requiresLeadingBlankLine(node2); + private static boolean isFunctionDeclaration(IASTNode node) { + if (!(node instanceof IASTSimpleDeclaration)) { + return false; + } + for (IASTDeclarator declarator : ((IASTSimpleDeclaration) node).getDeclarators()) { + if (declarator instanceof IASTFunctionDeclarator) + return true; + } + return false; } /** 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 index 16f9325785f..4ff5321d55a 100644 --- 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 @@ -13,7 +13,7 @@ *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.rewrite.astwriter; -import java.util.ArrayList; +import java.util.List; import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTArrayModifier; @@ -29,6 +29,7 @@ import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNodeLocation; import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration; +import org.eclipse.cdt.core.dom.ast.IASTPointerOperator; import org.eclipse.cdt.core.dom.ast.IASTStatement; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition; @@ -62,28 +63,25 @@ public class ASTWriterVisitor extends ASTVisitor { private boolean spaceNeededBeforeName; { - shouldVisitExpressions = true; - shouldVisitStatements = true; - shouldVisitNames = true; + shouldVisitArrayModifiers = true; + shouldVisitBaseSpecifiers = true; shouldVisitDeclarations = true; - shouldVisitDeclSpecifiers = true; shouldVisitDeclarators = true; - shouldVisitArrayModifiers= true; + shouldVisitDeclSpecifiers = true; + shouldVisitExpressions = true; shouldVisitInitializers = true; - shouldVisitBaseSpecifiers = true; + shouldVisitNames = true; shouldVisitNamespaces = true; - shouldVisitTemplateParameters = true; shouldVisitParameterDeclarations = true; + shouldVisitPointerOperators = true; + shouldVisitStatements = true; + shouldVisitTemplateParameters = true; shouldVisitTranslationUnit = true; + shouldVisitTypeIds = 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; this.suppressLeadingBlankLine = true; @@ -123,8 +121,8 @@ public class ASTWriterVisitor extends ASTVisitor { } } - private ArrayList<IASTComment> getLeadingComments(IASTNode node) { - ArrayList<IASTComment> leadingComments = commentMap.getLeadingCommentsForNode(node); + private List<IASTComment> getLeadingComments(IASTNode node) { + List<IASTComment> leadingComments = commentMap.getLeadingCommentsForNode(node); IASTNodeLocation[] locs = node.getNodeLocations(); if (locs != null && locs.length > 0 && locs[0] instanceof IASTCopyLocation) { IASTCopyLocation copyLoc = (IASTCopyLocation) locs[0]; @@ -240,6 +238,15 @@ public class ASTWriterVisitor extends ASTVisitor { return ASTVisitor.PROCESS_SKIP; } + @Override + public int visit(IASTPointerOperator pointerOperator) { + writeLeadingComments(pointerOperator); + if (!macroHandler.checkisMacroExpansionNode(pointerOperator)) { + declaratorWriter.writePointerOperator(pointerOperator); + } + return ASTVisitor.PROCESS_SKIP; + } + protected IASTName getParameterName(IASTDeclarator declarator) { return declarator.getName(); } @@ -303,6 +310,10 @@ public class ASTWriterVisitor extends ASTVisitor { this.spaceNeededBeforeName = value; } + public Scribe getScribe() { + return scribe; + } + public void newLine() { scribe.newLine(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/DeclSpecWriter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/DeclSpecWriter.java index ba7fb2e8623..66d25dd9378 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/DeclSpecWriter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/DeclSpecWriter.java @@ -267,7 +267,7 @@ public class DeclSpecWriter extends NodeWriter { } if (hasFreestandingComments(compDeclSpec)) { - writeFreeStandingComments(compDeclSpec); + writeFreestandingComments(compDeclSpec); } scribe.decrementIndentationLevel(); scribe.print('}'); 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 index 41ed66fc643..29e21800a75 100644 --- 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 @@ -98,17 +98,12 @@ public class DeclarationWriter extends NodeWriter { writeVisibilityLabel((ICPPASTVisibilityLabel) declaration); } - if (hasTrailingComments(declaration)) { - writeTrailingComments(declaration, false); - } - if (addNewLine) { - scribe.newLine(); - } + writeTrailingComments(declaration, addNewLine); if (hasFreestandingComments(declaration)) { if (declaration instanceof IASTFunctionDefinition) { scribe.newLine(); } - writeFreeStandingComments(declaration); + writeFreestandingComments(declaration); } } @@ -186,7 +181,7 @@ public class DeclarationWriter extends NodeWriter { scribe.newLine(2); writeDeclarationsInNamespace(namespaceDefinition, namespaceDefinition.getDeclarations()); if (hasFreestandingComments(namespaceDefinition)) { - writeFreeStandingComments(namespaceDefinition); + writeFreestandingComments(namespaceDefinition); } scribe.newLine(); scribe.print('}'); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/DeclaratorWriter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/DeclaratorWriter.java index 4a9a8af3852..7d3fdf05c10 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/DeclaratorWriter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/DeclaratorWriter.java @@ -62,9 +62,7 @@ public class DeclaratorWriter extends NodeWriter { } visitor.setSpaceNeededBeforeName(false); - if (hasTrailingComments(declarator)) { - writeTrailingComments(declarator, false); - } + writeTrailingComments(declarator, false); } protected void writeDefaultDeclarator(IASTDeclarator declarator) { @@ -81,7 +79,7 @@ public class DeclaratorWriter extends NodeWriter { protected void writePointerOperators(IASTDeclarator declarator, IASTPointerOperator[] pointOps) { for (IASTPointerOperator operator : pointOps) { - writePointerOp(operator); + writePointerOperator(operator); } } @@ -194,7 +192,7 @@ public class DeclaratorWriter extends NodeWriter { } } - private void writePointerOp(IASTPointerOperator operator) { + public void writePointerOperator(IASTPointerOperator operator) { if (operator instanceof IASTPointer) { IASTPointer pointOp = (IASTPointer) operator; writePointer(pointOp); 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 index 7adc8fdce86..8b1da40bc37 100644 --- 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 @@ -51,8 +51,8 @@ public class InitializerWriter extends NodeWriter{ } else if (initializer instanceof ICPPASTConstructorChainInitializer) { writeConstructorChainInitializer((ICPPASTConstructorChainInitializer) initializer); } - if (hasTrailingComments(initializer)) - writeTrailingComments(initializer, false); + + writeTrailingComments(initializer, false); } private void writeEqualsInitializer(IASTEqualsInitializer initializer) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/NodeWriter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/NodeWriter.java index 627e8158a5f..aa160a77bdf 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/NodeWriter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/NodeWriter.java @@ -11,7 +11,7 @@ *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.rewrite.astwriter; -import java.util.ArrayList; +import java.util.List; import org.eclipse.cdt.core.dom.ast.IASTComment; import org.eclipse.cdt.core.dom.ast.IASTCopyLocation; @@ -83,7 +83,7 @@ public class NodeWriter { } protected void writeTrailingComments(IASTNode node) { - // Default is to write a new line after trailing comments. + // Default is to write a new line after the trailing comments. writeTrailingComments(node, true); } @@ -106,8 +106,8 @@ public class NodeWriter { return !getTrailingComments(node).isEmpty(); } - private ArrayList<IASTComment> getTrailingComments(IASTNode node) { - ArrayList<IASTComment> trailingComments = commentMap.getTrailingCommentsForNode(node); + private List<IASTComment> getTrailingComments(IASTNode node) { + List<IASTComment> trailingComments = commentMap.getTrailingCommentsForNode(node); IASTNodeLocation[] locs = node.getNodeLocations(); if (locs != null && locs.length > 0 && locs[0] instanceof IASTCopyLocation) { IASTCopyLocation loc = (IASTCopyLocation) locs[0]; @@ -120,8 +120,8 @@ public class NodeWriter { return !getFreestandingComments(node).isEmpty(); } - private ArrayList<IASTComment> getFreestandingComments(IASTNode node) { - ArrayList<IASTComment> freestandingComments = commentMap.getFreestandingCommentsForNode(node); + private List<IASTComment> getFreestandingComments(IASTNode node) { + List<IASTComment> freestandingComments = commentMap.getFreestandingCommentsForNode(node); IASTNodeLocation[] locs = node.getNodeLocations(); if (locs != null && locs.length > 0 && locs[0] instanceof IASTCopyLocation) { IASTCopyLocation loc = (IASTCopyLocation) locs[0]; @@ -130,7 +130,7 @@ public class NodeWriter { return freestandingComments; } - protected void writeFreeStandingComments(IASTNode node) { + protected void writeFreestandingComments(IASTNode node) { for (IASTComment comment : getFreestandingComments(node)) { scribe.print(comment.getComment()); scribe.newLine(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/Scribe.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/Scribe.java index 8bc32d8396d..7f715f5e28f 100644 --- 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 @@ -8,6 +8,7 @@ * * Contributors: * Institute for Software - initial API and implementation + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.rewrite.astwriter; @@ -19,42 +20,43 @@ package org.eclipse.cdt.internal.core.dom.rewrite.astwriter; * @author Emanuel Graf IFS */ public class Scribe { - private int indentationLevel = 0; - // Any positive indentation size is good enough since the code is going to be formatted anyway. - private int indentationSize = 4; + // Indentation is not necessary since the code is going to be formatted anyway. + // Preserved because some tests depend on it. + private static final int INDENTATION_SIZE = 4; + private final String newLine = System.getProperty("line.separator"); //$NON-NLS-1$ private StringBuilder buffer = new StringBuilder(); - private boolean isAtLineBeginning = true; - private String newLine = System.getProperty("line.separator"); //$NON-NLS-1$ - private String givenIndentation; + private int indentationLevel = 0; + private boolean isAtBeginningOfLine = true; private boolean skipLineBreaks; private boolean skipSemicolons; + public String getLineSeparator() { + return newLine; + } + public void newLine() { if (!skipLineBreaks) { - isAtLineBeginning = true; - buffer.append(getNewline()); + isAtBeginningOfLine = true; + buffer.append(newLine); } } + public boolean isAtBeginningOfLine() { + return isAtBeginningOfLine; + } + private void indent() { - if (givenIndentation != null) { - buffer.append(givenIndentation); - } - printSpaces(indentationLevel * indentationSize); + printSpaces(indentationLevel * INDENTATION_SIZE); } private void indentIfNewLine() { - if (isAtLineBeginning) { - isAtLineBeginning = false; + if (isAtBeginningOfLine) { + isAtBeginningOfLine = false; indent(); } } - private String getNewline() { - return newLine; - } - public void print(String code) { indentIfNewLine(); buffer.append(code); @@ -171,14 +173,6 @@ public class Scribe { buffer.append(' '); } - public String getGivenIndentation() { - return givenIndentation; - } - - public void setGivenIndentation(String givenIndentation) { - this.givenIndentation = givenIndentation; - } - public void cleanCache() { buffer = new StringBuilder(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/StatementWriter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/StatementWriter.java index ac8c6f21f37..fd0cf9a59a7 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/StatementWriter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/StatementWriter.java @@ -154,12 +154,8 @@ public class StatementWriter extends NodeWriter { throw new ProblemRuntimeException((IASTProblemStatement)statement); } - if (hasTrailingComments(statement)) { - writeTrailingComments(statement, newLine); - } else if (newLine) { - scribe.newLine(); - } - + writeTrailingComments(statement, newLine); + return ASTVisitor.PROCESS_SKIP; } @@ -389,7 +385,7 @@ public class StatementWriter extends NodeWriter { } if (hasFreestandingComments(compoundStatement)) { - writeFreeStandingComments(compoundStatement); + writeFreestandingComments(compoundStatement); } if (decrementIndentationLevelOneMore) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/ASTModificationHelper.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/ASTModificationHelper.java index 3354844d4d1..30fd72f613a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/ASTModificationHelper.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/ASTModificationHelper.java @@ -15,8 +15,8 @@ import java.lang.reflect.Array; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; -import java.util.HashMap; import java.util.List; +import java.util.Map; import org.eclipse.cdt.core.dom.ast.IASTComment; import org.eclipse.cdt.core.dom.ast.IASTDeclarator; @@ -100,29 +100,29 @@ public class ASTModificationHelper { private void copyComments(IASTNode newNode, IASTNode oldNode, NodeCommentMap commentMap) { // Attach all the comments that is attached to oldNode to newNode - ArrayList<IASTComment> leadingComments = commentMap.getLeadingCommentsForNode(oldNode); + List<IASTComment> leadingComments = commentMap.getLeadingCommentsForNode(oldNode); for (IASTComment comment : leadingComments) { commentMap.addLeadingCommentToNode(newNode, comment); } - ArrayList<IASTComment> trailingComments = commentMap.getTrailingCommentsForNode(oldNode); + List<IASTComment> trailingComments = commentMap.getTrailingCommentsForNode(oldNode); for (IASTComment comment : trailingComments) { commentMap.addTrailingCommentToNode(newNode, comment); } - ArrayList<IASTComment> freestandingComments = commentMap.getFreestandingCommentsForNode(oldNode); + List<IASTComment> freestandingComments = commentMap.getFreestandingCommentsForNode(oldNode); for (IASTComment comment : freestandingComments) { commentMap.addFreestandingCommentToNode(newNode, comment); } // Detach comments from oldNode (to avoid memory leak) - HashMap<IASTNode, ArrayList<IASTComment>> leadingMap = commentMap.getLeadingMap(); + Map<IASTNode, List<IASTComment>> leadingMap = commentMap.getLeadingMap(); leadingMap.remove(oldNode); - HashMap<IASTNode, ArrayList<IASTComment>> trailingMap = commentMap.getTrailingMap(); + Map<IASTNode, List<IASTComment>> trailingMap = commentMap.getTrailingMap(); trailingMap.remove(oldNode); - HashMap<IASTNode, ArrayList<IASTComment>> freestandingMap = commentMap.getFreestandingMap(); + Map<IASTNode, List<IASTComment>> freestandingMap = commentMap.getFreestandingMap(); freestandingMap.remove(oldNode); } 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 index d8d2b173c00..a42d26721ba 100644 --- 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 @@ -15,9 +15,13 @@ package org.eclipse.cdt.internal.core.dom.rewrite.changegenerator; import java.io.IOException; import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.TreeMap; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.ToolFactory; @@ -30,15 +34,27 @@ 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.IASTExpressionList; import org.eclipse.cdt.core.dom.ast.IASTFileLocation; +import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition; 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.IASTNodeSelector; import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration; +import org.eclipse.cdt.core.dom.ast.IASTPointerOperator; +import org.eclipse.cdt.core.dom.ast.IASTPreprocessorStatement; +import org.eclipse.cdt.core.dom.ast.IASTStandardFunctionDeclarator; 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.cpp.ICPPASTCatchHandler; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDefinition; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionWithTryBlock; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition; import org.eclipse.cdt.core.formatter.CodeFormatter; +import org.eclipse.cdt.core.formatter.DefaultCodeFormatterConstants; import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification; import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind; @@ -61,11 +77,11 @@ import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.Document; import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.IRegion; +import org.eclipse.jface.text.Region; import org.eclipse.jface.text.TextUtilities; import org.eclipse.ltk.core.refactoring.Change; import org.eclipse.ltk.core.refactoring.CompositeChange; import org.eclipse.ltk.core.refactoring.TextFileChange; -import org.eclipse.text.edits.DeleteEdit; import org.eclipse.text.edits.InsertEdit; import org.eclipse.text.edits.MalformedTreeException; import org.eclipse.text.edits.MultiTextEdit; @@ -74,28 +90,31 @@ import org.eclipse.text.edits.TextEdit; import org.eclipse.text.edits.TextEditGroup; public class ChangeGenerator extends ASTVisitor { - 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 final Map<String, Integer> sourceOffsets = new LinkedHashMap<String, Integer>(); + private final Map<IASTNode, Map<ModificationKind, List<ASTModification>>> classifiedModifications = + new HashMap<IASTNode, Map<ModificationKind, List<ASTModification>>>(); + private final Map<IFile, MultiTextEdit> changes = new LinkedHashMap<IFile, MultiTextEdit>(); private CompositeChange change; private final ASTModificationStore modificationStore; private NodeCommentMap commentMap; { - shouldVisitExpressions = true; - shouldVisitStatements = true; + shouldVisitArrayModifiers= true; + shouldVisitBaseSpecifiers = true; shouldVisitNames = true; shouldVisitDeclarations = true; - shouldVisitDeclSpecifiers = true; shouldVisitDeclarators = true; - shouldVisitArrayModifiers= true; + shouldVisitDeclSpecifiers = true; + shouldVisitExpressions = true; shouldVisitInitializers = true; - shouldVisitBaseSpecifiers = true; shouldVisitNamespaces = true; - shouldVisitTemplateParameters = true; shouldVisitParameterDeclarations = true; + shouldVisitPointerOperators = true; + shouldVisitStatements = true; + shouldVisitTemplateParameters = true; shouldVisitTranslationUnit = true; + shouldVisitTypeIds = true; } public ChangeGenerator(ASTModificationStore modificationStore, NodeCommentMap commentMap) { @@ -110,7 +129,7 @@ public class ChangeGenerator extends ASTVisitor { public void generateChange(IASTNode rootNode, ASTVisitor pathProvider) throws ProblemRuntimeException { change = new CompositeChange(Messages.ChangeGenerator_compositeChange); - initParentModList(); + classifyModifications(); rootNode.accept(pathProvider); for (IFile currentFile : changes.keySet()) { MultiTextEdit edit = changes.get(currentFile); @@ -121,145 +140,426 @@ public class ChangeGenerator extends ASTVisitor { } } - private void initParentModList() { + private void classifyModifications() { ASTModificationMap rootModifications = modificationStore.getRootModifications(); - if (rootModifications != null) { - for (IASTNode modifiedNode : rootModifications.getModifiedNodes()) { - List<ASTModification> modificationsForNode = rootModifications.getModificationsForNode(modifiedNode); - IASTNode modifiedNodeParent = determineParentToBeRewritten(modifiedNode, modificationsForNode); - List<ASTModification> list = modificationParent.get(modifiedNodeParent != null ? - modifiedNodeParent : modifiedNode); - if (list != null) { - list.addAll(modificationsForNode); - } else { - List<ASTModification> modifiableList = new ArrayList<ASTModification>(modificationsForNode); - modificationParent.put(modifiedNodeParent != null ? - modifiedNodeParent : modifiedNode, modifiableList); + if (rootModifications == null) + return; + + for (IASTNode node : rootModifications.getModifiedNodes()) { + List<ASTModification> modifications = rootModifications.getModificationsForNode(node); + for (ASTModification modification : modifications) { + Map<ModificationKind, List<ASTModification>> map = classifiedModifications.get(node); + if (map == null) { + map = new TreeMap<ModificationKind, List<ASTModification>>(); + classifiedModifications.put(node, map); } + ModificationKind kind = modification.getKind(); + List<ASTModification> list = map.get(kind); + if (list == null) { + list = new ArrayList<ASTModification>(2); + map.put(kind, list); + } + list.add(modification); } } } - private IASTNode determineParentToBeRewritten(IASTNode modifiedNode, List<ASTModification> modificationsForNode) { - IASTNode modifiedNodeParent = modifiedNode; - for (ASTModification currentModification : modificationsForNode) { - if (currentModification.getKind() == ASTModification.ModificationKind.REPLACE) { - modifiedNodeParent = modifiedNode.getParent(); - break; - } + @Override + public int visit(IASTTranslationUnit tu) { + IASTFileLocation location = tu.getFileLocation(); + sourceOffsets.put(location.getFileName(), Integer.valueOf(location.getNodeOffset())); + return super.visit(tu); + } + + @Override + public int leave(IASTTranslationUnit tu) { + handleAppends(tu); + return super.leave(tu); + } + + @Override + public int visit(IASTDeclaration declaration) { + handleInserts(declaration); + if (requiresRewrite(declaration)) { + handleReplace(declaration); + return ASTVisitor.PROCESS_SKIP; + } + return super.visit(declaration); + } + + @Override + public int visit(IASTDeclarator declarator) { + handleInserts(declarator); + if (requiresRewrite(declarator)) { + handleReplace(declarator); + return ASTVisitor.PROCESS_SKIP; + } + return super.visit(declarator); + } + + @Override + public int visit(IASTArrayModifier arrayModifier) { + handleInserts(arrayModifier); + if (requiresRewrite(arrayModifier)) { + handleReplace(arrayModifier); + return ASTVisitor.PROCESS_SKIP; + } + return super.visit(arrayModifier); + } + + @Override + public int visit(ICPPASTNamespaceDefinition namespaceDefinition) { + handleInserts(namespaceDefinition); + if (requiresRewrite(namespaceDefinition)) { + handleReplace(namespaceDefinition); + return ASTVisitor.PROCESS_SKIP; + } + return super.visit(namespaceDefinition); + } + + @Override + public int leave(ICPPASTNamespaceDefinition namespaceDefinition) { + if (!requiresRewrite(namespaceDefinition)) { + handleAppends(namespaceDefinition); + } + return super.leave(namespaceDefinition); + } + + @Override + public int visit(IASTDeclSpecifier declSpec) { + handleInserts(declSpec); + if (requiresRewrite(declSpec)) { + handleReplace(declSpec); + return ASTVisitor.PROCESS_SKIP; + } + return super.visit(declSpec); + } + + @Override + public int leave(IASTDeclSpecifier declSpec) { + if (!requiresRewrite(declSpec)) { + handleAppends(declSpec); + } + return super.leave(declSpec); + } + + @Override + public int visit(IASTExpression expression) { + handleInserts(expression); + if (requiresRewrite(expression)) { + handleReplace(expression); + return ASTVisitor.PROCESS_SKIP; + } + return super.visit(expression); + } + + @Override + public int visit(IASTInitializer initializer) { + handleInserts(initializer); + if (requiresRewrite(initializer)) { + handleReplace(initializer); + return ASTVisitor.PROCESS_SKIP; + } + return super.visit(initializer); + } + + @Override + public int visit(IASTName name) { + handleInserts(name); + if (requiresRewrite(name)) { + handleReplace(name); + return ASTVisitor.PROCESS_SKIP; + } + return super.visit(name); + } + + @Override + public int visit(IASTParameterDeclaration parameterDeclaration) { + handleInserts(parameterDeclaration); + if (requiresRewrite(parameterDeclaration)) { + handleReplace(parameterDeclaration); + return ASTVisitor.PROCESS_SKIP; + } + return super.visit(parameterDeclaration); + } + + @Override + public int visit(IASTPointerOperator pointerOperator) { + handleInserts(pointerOperator); + if (requiresRewrite(pointerOperator)) { + handleReplace(pointerOperator); + return ASTVisitor.PROCESS_SKIP; + } + return super.visit(pointerOperator); + } + + @Override + public int visit(IASTTypeId typeId) { + handleInserts(typeId); + if (requiresRewrite(typeId)) { + handleReplace(typeId); + return ASTVisitor.PROCESS_SKIP; + } + return super.visit(typeId); + } + + @Override + public int visit(IASTStatement statement) { + handleInserts(statement); + if (requiresRewrite(statement)) { + handleReplace(statement); + return ASTVisitor.PROCESS_SKIP; + } + return super.visit(statement); + } + + @Override + public int leave(IASTStatement statement) { + if (!requiresRewrite(statement)) { + handleAppends(statement); } - modifiedNodeParent = modifiedNodeParent != null ? modifiedNodeParent : modifiedNode; - return modifiedNodeParent; + return super.leave(statement); } /** * Applies the C++ code formatter to the code affected by refactoring. * - * @param edit The text edit produced by refactoring. + * @param multiEdit The text edit produced by refactoring. * @param file The file being modified. * @return The text edit containing formatted refactoring changes, or the original text edit * in case of errors. */ - private MultiTextEdit formatChangedCode(MultiTextEdit edit, IFile file) { + private MultiTextEdit formatChangedCode(MultiTextEdit multiEdit, IFile file) { String code; try { code = FileContentHelper.getContent(file, 0); } catch (IOException e) { CCorePlugin.log(e); - return edit; + return multiEdit; } catch (CoreException e) { CCorePlugin.log(e); - return edit; + return multiEdit; } IDocument document = new Document(code); try { - TextEdit tempEdit = edit.copy(); - tempEdit.apply(document, TextEdit.UPDATE_REGIONS); - TextEdit[] edits = tempEdit.getChildren(); - IRegion[] regions = new IRegion[edits.length]; + // Apply refactoring changes to a temporary document. + TextEdit edit = multiEdit.copy(); + edit.apply(document, TextEdit.UPDATE_REGIONS); + + // Expand regions affected by the changes to cover complete lines. We calculate two + // sets of regions, reflecting the state of the document before and after + // the refactoring changes. + TextEdit[] edits = edit.getChildren(); + TextEdit[] originalEdits = multiEdit.getChildren(); + IRegion[] regionsAfter = new IRegion[edits.length]; + IRegion[] regionsBefore = new IRegion[edits.length]; + int numRegions = 0; + int prevEnd = -1; for (int i = 0; i < edits.length; i++) { - regions[i] = edits[i].getRegion(); + edit = edits[i]; + int offset = edit.getOffset(); + int end = offset + edit.getLength(); + int newOffset = document.getLineInformationOfOffset(offset).getOffset(); + int newEnd = endOffset(document.getLineInformationOfOffset(end)); + edit = originalEdits[i]; + int offsetBefore = edit.getOffset(); + int newOffsetBefore = newOffset + offsetBefore - offset; + int newEndBefore = newEnd + offsetBefore + edit.getLength() - end; + if (newOffset <= prevEnd) { + numRegions--; + newOffset = regionsAfter[numRegions].getOffset(); + newOffsetBefore = regionsBefore[numRegions].getOffset(); + } + prevEnd = newEnd; + regionsAfter[numRegions] = new Region(newOffset, newEnd - newOffset); + regionsBefore[numRegions] = new Region(newOffsetBefore, newEndBefore - newOffsetBefore); + numRegions++; + } + + if (numRegions < regionsAfter.length) { + regionsAfter = Arrays.copyOf(regionsAfter, numRegions); + regionsBefore = Arrays.copyOf(regionsBefore, numRegions); } + + // Calculate formatting changes for the regions after the refactoring changes. ICProject project = CCorePlugin.getDefault().getCoreModel().create(file.getProject()); Map<String, String> options = project.getOptions(true); + // Allow all comments to be indented. + options.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_NEVER_INDENT_LINE_COMMENTS_ON_FIRST_COLUMN, + DefaultCodeFormatterConstants.FALSE); CodeFormatter formatter = ToolFactory.createCodeFormatter(options); code = document.get(); TextEdit[] formatEdits = formatter.format(CCodeFormatter.K_TRANSLATION_UNIT, code, - regions, TextUtilities.getDefaultLineDelimiter(document)); + regionsAfter, TextUtilities.getDefaultLineDelimiter(document)); + + // For each of the regions we apply formatting changes and create a ReplaceEdit using + // the region before the refactoring changes and the text after the formatting changes. MultiTextEdit resultEdit = new MultiTextEdit(); - edits = edit.getChildren(); - for (int i = 0; i < edits.length; i++) { - IRegion region = regions[i]; + for (int i = 0; i < regionsAfter.length; i++) { + IRegion region = regionsAfter[i]; int offset = region.getOffset(); - TextEdit formatEdit = formatEdits[i]; - formatEdit.moveTree(-offset); + edit = formatEdits[i]; + edit.moveTree(-offset); document = new Document(code.substring(offset, offset + region.getLength())); - formatEdit.apply(document, TextEdit.NONE); - TextEdit textEdit = edits[i]; - resultEdit.addChild( - new ReplaceEdit(textEdit.getOffset(), textEdit.getLength(), document.get())); + edit.apply(document, TextEdit.NONE); + region = regionsBefore[i]; + edit = new ReplaceEdit(region.getOffset(), region.getLength(), document.get()); + resultEdit.addChild(edit); } return resultEdit; } catch (MalformedTreeException e) { CCorePlugin.log(e); - return edit; + return multiEdit; } catch (BadLocationException e) { CCorePlugin.log(e); - return edit; + return multiEdit; } } - @Override - public int visit(IASTTranslationUnit translationUnit) { - if (hasChangedChild(translationUnit)) { - synthTreatment(translationUnit); - } - IASTFileLocation location = translationUnit.getFileLocation(); - sourceOffsets.put(location.getFileName(), Integer.valueOf(location.getNodeOffset())); - return super.visit(translationUnit); + private int endOffset(IRegion region) { + return region.getOffset() + region.getLength(); } - @Override - public int leave(IASTTranslationUnit tu) { - return super.leave(tu); + private int endOffset(IASTFileLocation nodeLocation) { + return nodeLocation.getNodeOffset() + nodeLocation.getNodeLength(); } - @Override - public int visit(IASTDeclaration declaration) { - if (hasChangedChild(declaration)) { - synthTreatment(declaration); - return ASTVisitor.PROCESS_SKIP; + private int endOffset(IASTNode node) { + return endOffset(node.getFileLocation()); + } + + private int offset(IASTNode node) { + return node.getFileLocation().getNodeOffset(); + } + + private void handleInserts(IASTNode anchorNode) { + List<ASTModification> modifications = getModifications(anchorNode, ModificationKind.INSERT_BEFORE); + if (modifications.isEmpty()) + return; + ChangeGeneratorWriterVisitor writer = + new ChangeGeneratorWriterVisitor(modificationStore, commentMap); + IASTNode newNode = null; + for (ASTModification modification : modifications) { + boolean first = newNode == null; + newNode = modification.getNewNode(); + if (first) { + IASTNode prevNode = getPreviousSiblingOrPreprocessorNode(anchorNode); + if (prevNode != null) { + if (ASTWriter.requireBlankLineInBetween(prevNode, newNode)) { + writer.newLine(); + } + } else if (anchorNode.getParent() instanceof ICPPASTNamespaceDefinition) { + writer.newLine(); + } + } + newNode.accept(writer); + if (getContainingNodeList(anchorNode) != null) { + writer.getScribe().print(", "); //$NON-NLS-1$ + } } - return super.visit(declaration); + if (ASTWriter.requireBlankLineInBetween(newNode, anchorNode)) { + writer.newLine(); + } + int insertPos = getOffsetIncludingComments(anchorNode); + int length = 0; + if (writer.getScribe().isAtBeginningOfLine()) { + String tuCode = anchorNode.getTranslationUnit().getRawSignature(); + insertPos = skipPrecedingWhitespace(tuCode, insertPos); + length = insertPos; + insertPos = skipPrecedingBlankLines(tuCode, insertPos); + length -= insertPos; + } + String code = writer.toString(); + ReplaceEdit edit = new ReplaceEdit(insertPos, length, code); + IFile file = FileHelper.getFileFromNode(anchorNode); + MultiTextEdit parentEdit = getEdit(anchorNode, file); + parentEdit.addChild(edit); + sourceOffsets.put(file.getName(), Integer.valueOf(edit.getOffset())); } - private void synthTreatment(IASTNode synthNode) { + private void handleReplace(IASTNode node) { + List<ASTModification> modifications = getModifications(node, ModificationKind.REPLACE); + String source = node.getTranslationUnit().getRawSignature(); + TextEdit edit; ChangeGeneratorWriterVisitor writer = new ChangeGeneratorWriterVisitor(modificationStore, commentMap); - synthNode.accept(writer); - String synthSource = writer.toString(); - createChange(synthNode, synthSource); + if (modifications.size() == 1 && modifications.get(0).getNewNode() == null) { + int offset = getOffsetIncludingComments(node); + int endOffset = getEndOffsetIncludingComments(node); + offset = skipPrecedingBlankLines(source, offset); + endOffset = skipTrailingBlankLines(source, endOffset); + IASTNode[] siblingsList = getContainingNodeList(node); + if (siblingsList != null) { + if (siblingsList.length > 1) { + if (node == siblingsList[0]) { + endOffset = skipToTrailingDelimiter(source, ',', endOffset); + } else { + offset = skipToPrecedingDelimiter(source, ',', offset); + } + } else if (node.getPropertyInParent() == ICPPASTFunctionDefinition.MEMBER_INITIALIZER) { + offset = skipToPrecedingDelimiter(source, ':', offset); + } + } + IASTNode prevNode = getPreviousSiblingOrPreprocessorNode(node); + IASTNode nextNode = getNextSiblingOrPreprocessorNode(node); + if (prevNode != null && nextNode != null) { + if (ASTWriter.requireBlankLineInBetween(prevNode, nextNode)) { + writer.newLine(); + } + } else if (node.getParent() instanceof ICPPASTNamespaceDefinition) { + writer.newLine(); + } + String code = writer.toString(); + edit = new ReplaceEdit(offset, endOffset - offset, code); + } else { + node.accept(writer); + String code = writer.toString(); + IASTFileLocation location = node.getFileLocation(); + int offset = location.getNodeOffset(); + int endOffset = offset + location.getNodeLength(); + if (node instanceof IASTStatement || node instanceof IASTDeclaration) { + // Include trailing comments in the area to be replaced. + endOffset = Math.max(endOffset, getEndOffsetIncludingTrailingComments(node)); + } + String lineSeparator = writer.getScribe().getLineSeparator(); + if (code.endsWith(lineSeparator)) { + code = code.substring(0, code.length() - lineSeparator.length()); + } + edit = new ReplaceEdit(offset, endOffset - offset, code); + } + IFile file = FileHelper.getFileFromNode(node); + MultiTextEdit parentEdit = getEdit(node, file); + parentEdit.addChild(edit); - IASTFileLocation fileLocation = synthNode.getFileLocation(); + IASTFileLocation fileLocation = node.getFileLocation(); int newOffset = fileLocation.getNodeOffset() + fileLocation.getNodeLength(); sourceOffsets.put(fileLocation.getFileName(), Integer.valueOf(newOffset)); } private void handleAppends(IASTNode node) { + List<ASTModification> modifications = getModifications(node, ModificationKind.APPEND_CHILD); + if (modifications.isEmpty()) + return; ChangeGeneratorWriterVisitor writer = new ChangeGeneratorWriterVisitor(modificationStore, commentMap); - List<ASTModification> modifications = modificationParent.get(node); ReplaceEdit anchor = getAppendAnchor(node); Assert.isNotNull(anchor); IASTNode precedingNode = getLastNodeBeforeAppendPoint(node); - if (precedingNode != null && - ASTWriter.requireBlankLineInBetween(precedingNode, modifications.get(0).getNewNode())) { - writer.newLine(); - } for (ASTModification modification : modifications) { IASTNode newNode = modification.getNewNode(); + if (precedingNode != null) { + if (ASTWriter.requireBlankLineInBetween(precedingNode, newNode)) { + writer.newLine(); + } + } else if (node instanceof ICPPASTNamespaceDefinition) { + writer.newLine(); + } + precedingNode = null; newNode.accept(writer); } + if (node instanceof ICPPASTNamespaceDefinition) { + writer.newLine(); + } String code = writer.toString(); IFile file = FileHelper.getFileFromNode(node); MultiTextEdit parentEdit = getEdit(node, file); @@ -271,29 +571,217 @@ public class ChangeGenerator extends ASTVisitor { sourceOffsets.put(fileLocation.getFileName(), Integer.valueOf(newOffset)); } + private void handleAppends(IASTTranslationUnit tu) { + ASTWriter synthWriter = new ASTWriter(); + synthWriter.setModificationStore(modificationStore); + + for (ASTModification modification : getModifications(tu, ModificationKind.APPEND_CHILD)) { + IASTNode targetNode = modification.getTargetNode(); + IASTFileLocation targetLocation = targetNode.getFileLocation(); + String currentFile = targetLocation.getFileName(); + IPath implPath = new Path(currentFile); + IFile relevantFile= ResourceLookup.selectFileForLocation(implPath, null); + if (relevantFile == null || !relevantFile.exists()) { // If not in workspace or local file system + throw new UnhandledASTModificationException(modification); + } + MultiTextEdit edit; + if (changes.containsKey(relevantFile)) { + edit = changes.get(relevantFile); + } else { + edit = new MultiTextEdit(); + changes.put(relevantFile, edit); + } + String code = synthWriter.write(modification.getNewNode(), commentMap); + + if (targetNode instanceof IASTTranslationUnit && + ((IASTTranslationUnit) targetNode).getDeclarations().length > 0) { + IASTTranslationUnit targetTu = (IASTTranslationUnit) targetNode; + IASTDeclaration lastDecl = targetTu.getDeclarations()[targetTu.getDeclarations().length - 1]; + targetLocation = lastDecl.getFileLocation(); + } + String lineDelimiter = FileHelper.determineLineDelimiter( + FileHelper.getFileFromNode(targetNode)); + edit.addChild(new InsertEdit(endOffset(targetLocation), lineDelimiter + lineDelimiter + code)); + } + } + + /** + * Returns the list of nodes the given node is part of, for example function parameters if + * the node is a parameter. + * + * @param node the node possibly belonging to a list. + * @return the list of nodes containing the given node, or <code>null</code> if the node + * does not belong to a list + */ + private IASTNode[] getContainingNodeList(IASTNode node) { + if (node.getPropertyInParent() == IASTStandardFunctionDeclarator.FUNCTION_PARAMETER) { + return ((IASTStandardFunctionDeclarator) node.getParent()).getParameters(); + } else if (node.getPropertyInParent() == IASTExpressionList.NESTED_EXPRESSION) { + return ((IASTExpressionList) node.getParent()).getExpressions(); + } else if (node.getPropertyInParent() == ICPPASTFunctionDefinition.MEMBER_INITIALIZER) { + return ((ICPPASTFunctionDefinition) node.getParent()).getMemberInitializers(); + } else if (node.getPropertyInParent() == ICPPASTFunctionDeclarator.EXCEPTION_TYPEID) { + return ((ICPPASTFunctionDeclarator) node.getParent()).getExceptionSpecification(); + } + + return null; + } + private IASTNode getLastNodeBeforeAppendPoint(IASTNode node) { IASTNode[] children; - if (node instanceof IASTCompositeTypeSpecifier) { + if (node instanceof ICPPASTNamespaceDefinition) { + children = ((ICPPASTNamespaceDefinition) node).getDeclarations(true); + } else if (node instanceof IASTCompositeTypeSpecifier) { children = ((IASTCompositeTypeSpecifier) node).getDeclarations(true); } else { children = node.getChildren(); } - return children.length > 0 ? children[children.length - 1] : null; + for (int i = children.length; --i >= 0;) { + IASTNode child = getReplacementNode(children[i]); + if (child != null) + return child; + } + return null; } - private boolean isAppendable(Iterable<ASTModification> modifications) { - for (ASTModification modification : modifications) { - if (!isAppendable(modification)) + private IASTNode getReplacementNode(IASTNode node) { + List<ASTModification> modifications = getModifications(node, ModificationKind.REPLACE); + if (!modifications.isEmpty()) { + node = modifications.get(modifications.size() - 1).getNewNode(); + } + return node; + } + + private IASTNode getPreviousSiblingNode(IASTNode node) { + IASTNode parent = node.getParent(); + IASTNode[] siblings; + if (parent instanceof ICPPASTNamespaceDefinition) { + siblings = ((ICPPASTNamespaceDefinition) parent).getDeclarations(true); + } else if (parent instanceof IASTCompositeTypeSpecifier) { + siblings = ((IASTCompositeTypeSpecifier) parent).getDeclarations(true); + } else { + siblings = parent.getChildren(); + } + boolean beforeNode = false; + for (int i = siblings.length; --i >= 0;) { + IASTNode sibling = siblings[i]; + if (sibling == node) { + beforeNode = true; + } else if (beforeNode) { + sibling = getReplacementNode(sibling); + if (sibling != null) + return sibling; + } + } + return null; + } + + private IASTNode getPreviousSiblingOrPreprocessorNode(IASTNode node) { + int offset = offset(node); + IASTTranslationUnit ast = node.getTranslationUnit(); + IASTPreprocessorStatement[] preprocessorStatements = ast.getAllPreprocessorStatements(); + int low = 0; + int high = preprocessorStatements.length; + while (low < high) { + int mid = (low + high) / 2; + IASTNode statement = preprocessorStatements[mid]; + if (statement.isPartOfTranslationUnitFile() && endOffset(statement) > offset) { + high = mid; + } else { + low = mid + 1; + } + } + low--; + if (low >= 0) { + IASTNode statement = preprocessorStatements[low]; + if (statement.isPartOfTranslationUnitFile()) { + int endOffset = endOffset(statement); + if (!doesRegionContainNode(ast, endOffset, offset - endOffset)) { + return statement; + } + } + } + + return getPreviousSiblingNode(node); + } + + private IASTNode getNextSiblingNode(IASTNode node) { + IASTNode parent = node.getParent(); + IASTNode[] siblings; + if (parent instanceof ICPPASTNamespaceDefinition) { + siblings = ((ICPPASTNamespaceDefinition) parent).getDeclarations(true); + } else if (parent instanceof IASTCompositeTypeSpecifier) { + siblings = ((IASTCompositeTypeSpecifier) parent).getDeclarations(true); + } else { + siblings = parent.getChildren(); + } + boolean beforeNode = false; + for (int i = 0; i < siblings.length; i++) { + IASTNode sibling = siblings[i]; + if (sibling == node) { + beforeNode = true; + } else if (beforeNode) { + sibling = getReplacementNode(sibling); + if (sibling != null) + return sibling; + } + } + return null; + } + + private IASTNode getNextSiblingOrPreprocessorNode(IASTNode node) { + int endOffset = endOffset(node); + IASTTranslationUnit ast = node.getTranslationUnit(); + IASTPreprocessorStatement[] preprocessorStatements = ast.getAllPreprocessorStatements(); + int low = 0; + int high = preprocessorStatements.length; + while (low < high) { + int mid = (low + high) / 2; + IASTNode statement = preprocessorStatements[mid]; + if (statement.isPartOfTranslationUnitFile() && offset(statement) > endOffset) { + high = mid; + } else { + low = mid + 1; + } + } + if (high < preprocessorStatements.length) { + IASTNode statement = preprocessorStatements[high]; + if (statement.isPartOfTranslationUnitFile()) { + int offset = offset(statement); + if (!doesRegionContainNode(ast, endOffset, offset - endOffset)) { + return statement; + } + } + } + + return getNextSiblingNode(node); + } + + /** + * Checks if a given region contains at least a piece of a node after rewrite. + */ + private boolean doesRegionContainNode(IASTTranslationUnit ast, int offset, int length) { + IASTNodeSelector nodeSelector = ast.getNodeSelector(ast.getFilePath()); + while (length > 0) { + IASTNode node = nodeSelector.findFirstContainedNode(offset, length - 1); + if (node == null) return false; + if (!isNodeRemoved(node)) + return true; + int oldOffset = offset; + offset = endOffset(node); + length -= offset - oldOffset; } - return true; + return false; } - private boolean isAppendable(ASTModification modification) { - if (modification.getKind() != ModificationKind.APPEND_CHILD) - return false; - IASTNode node = modification.getNewNode(); - return node instanceof IASTDeclaration || node instanceof IASTStatement; + private boolean isNodeRemoved(IASTNode node) { + do { + if (getReplacementNode(node) == null) + return true; + } while ((node = node.getParent()) != null); + + return false; } /** @@ -310,93 +798,148 @@ public class ChangeGenerator extends ASTVisitor { node instanceof ICPPASTNamespaceDefinition)) { return null; } - IFile file = FileHelper.getFileFromNode(node); - String code = originalCodeOfNode(node, file); + String code = node.getRawSignature(); IASTFileLocation location = node.getFileLocation(); int pos = location.getNodeOffset() + location.getNodeLength(); int len = code.endsWith("}") ? 1 : 0; //$NON-NLS-1$ - int startOfLine = skipPrecedingBlankLines(code, code.length() - len); - if (startOfLine < 0) { + int insertPos = code.length() - len; + int startOfLine = skipPrecedingBlankLines(code, insertPos); + if (startOfLine == insertPos) { // Include the closing brace in the region that will be reformatted. - return new ReplaceEdit(pos - len, len, code.substring(code.length() - len)); + return new ReplaceEdit(pos - len, len, code.substring(insertPos)); } - return new ReplaceEdit(location.getNodeOffset() + startOfLine, 0, ""); //$NON-NLS-1$ + return new ReplaceEdit(location.getNodeOffset() + startOfLine, insertPos - startOfLine, ""); //$NON-NLS-1$ } /** - * Skips blank lines preceding the given position. - * @param text the text to scan - * @param pos the position after that blank lines. - * @return the beginning of the first blank line, or -1 if the beginning of the line - * corresponding to the given position contains non-whitespace characters. + * Skips whitespace between the beginning of the line and the given position. + * + * @param text The text to scan. + * @param startPos The start position. + * @return The beginning of the line containing the start position, if there are no + * non-whitespace characters between the beginning of the line and the start position. + * Otherwise returns the start position. */ - private int skipPrecedingBlankLines(String text, int pos) { - int lineStart = -1; - while (--pos >= 0) { + private int skipPrecedingWhitespace(String text, int startPos) { + for (int pos = startPos; --pos >= 0; ) { char c = text.charAt(pos); if (c == '\n') { - lineStart = pos + 1; + return pos + 1; } else if (!Character.isWhitespace(c)) { - break; + return startPos; } } - return lineStart; + return 0; } - private void synthTreatment(IASTTranslationUnit synthTU) { - ASTWriter synthWriter = new ASTWriter(); - synthWriter.setModificationStore(modificationStore); + /** + * Skips whitespace between the beginning of the line and the given position and blank lines + * above that. + * + * @param text The text to scan. + * @param startPos The start position. + * @return The beginning of the first blank line preceding the start position, + * or beginning of the current line, if there are no non-whitespace characters between + * the beginning of the line and the start position. + * Otherwise returns the start position. + */ + private int skipPrecedingBlankLines(String text, int startPos) { + for (int pos = startPos; --pos >= 0;) { + char c = text.charAt(pos); + if (c == '\n') { + startPos = pos + 1; + } else if (!Character.isWhitespace(c)) { + return startPos; + } + } + return 0; + } - for (ASTModification modification : modificationParent.get(synthTU)) { - IASTNode targetNode = modification.getTargetNode(); - IASTFileLocation targetLocation = targetNode.getFileLocation(); - String currentFile = targetLocation.getFileName(); - IPath implPath = new Path(currentFile); - IFile relevantFile= ResourceLookup.selectFileForLocation(implPath, null); - if (relevantFile == null || !relevantFile.exists()) { // If not in workspace or local file system - throw new UnhandledASTModificationException(modification); + /** + * Skips whitespace between the given position and the end of the line. + * + * @param text The text to scan. + * @param startPos The start position. + * @return The end of the line containing the start position, if there are no non-whitespace + * characters between the start position and the end of the line. + * Otherwise returns the start position. + */ + private int skipTrailingWhitespace(String text, int startPos) { + for (int pos = startPos; pos < text.length(); pos++) { + char c = text.charAt(pos); + if (c == '\n') { + return pos + 1; + } else if (!Character.isWhitespace(c)) { + return startPos; } - MultiTextEdit edit; - if (changes.containsKey(relevantFile)) { - edit = changes.get(relevantFile); - } else { - edit = new MultiTextEdit(); - changes.put(relevantFile, edit); + } + return text.length(); + } + + /** + * Skips whitespace between the given position and the end of the line and blank lines + * below that. + * + * @param text The text to scan. + * @param startPos The start position. + * @return The beginning of the first non-blank line following the start position, if there are + * no non-whitespace characters between the start position and the end of the line. + * Otherwise returns the start position. + */ + private int skipTrailingBlankLines(String text, int startPos) { + for (int pos = startPos; pos < text.length(); pos++) { + char c = text.charAt(pos); + if (c == '\n') { + startPos = pos + 1; + } else if (!Character.isWhitespace(c)) { + return startPos; } - String newNodeCode = synthWriter.write(modification.getNewNode(), commentMap); - - switch (modification.getKind()) { - case REPLACE: - edit.addChild(new ReplaceEdit(targetLocation.getNodeOffset(), - targetLocation.getNodeLength(), newNodeCode)); - break; - case INSERT_BEFORE: - if (ASTWriter.requireBlankLineInBetween(modification.getNewNode(), targetNode)) { - newNodeCode = newNodeCode + "\n"; //$NON-NLS-1$ - } - edit.addChild(new InsertEdit(getOffsetIncludingComments(targetNode), newNodeCode)); - break; - case APPEND_CHILD: - if (targetNode instanceof IASTTranslationUnit && - ((IASTTranslationUnit) targetNode).getDeclarations().length > 0) { - IASTTranslationUnit tu = (IASTTranslationUnit) targetNode; - IASTDeclaration lastDecl = tu.getDeclarations()[tu.getDeclarations().length - 1]; - targetLocation = lastDecl.getFileLocation(); - } - String lineDelimiter = FileHelper.determineLineDelimiter( - FileHelper.getFileFromNode(targetNode)); - edit.addChild(new InsertEdit(targetLocation.getNodeOffset() + targetLocation.getNodeLength(), - lineDelimiter + lineDelimiter + newNodeCode)); - break; + } + return text.length(); + } + + /** + * Skips whitespace to the left of the given position until the given delimiter character + * is found. + * + * @param text The text to scan. + * @param delimiter the delimiter to find + * @param startPos The start position. + * @return The position of the given delimiter, or the start position if a non-whitespace + * character is encountered before the given delimiter. + */ + private int skipToPrecedingDelimiter(String text, char delimiter, int startPos) { + for (int pos = startPos; --pos >= 0; ) { + char c = text.charAt(pos); + if (c == delimiter) { + return pos; + } else if (!Character.isWhitespace(c)) { + return startPos; } } + return startPos; } - private void createChange(IASTNode synthNode, String synthSource) { - IFile relevantFile = FileHelper.getFileFromNode(synthNode); - String originalCode = originalCodeOfNode(synthNode, relevantFile); - CodeComparer codeComparer = new CodeComparer(originalCode, synthSource); - codeComparer.createChange(getEdit(synthNode, relevantFile), synthNode); + /** + * Skips whitespace to the right of the given position until the given delimiter character + * is found. + * + * @param text The text to scan. + * @param delimiter the delimiter to find + * @param startPos The start position. + * @return The position after the given delimiter, or the start position if a non-whitespace + * character is encountered before the given delimiter. + */ + private int skipToTrailingDelimiter(String text, char delimiter, int startPos) { + for (int pos = startPos; pos < text.length(); pos++) { + char c = text.charAt(pos); + if (c == delimiter) { + return pos + 1; + } else if (!Character.isWhitespace(c)) { + return startPos; + } + } + return startPos; } private MultiTextEdit getEdit(IASTNode modifiedNode, IFile file) { @@ -406,366 +949,108 @@ public class ChangeGenerator extends ASTVisitor { changes.put(file, edit); } TextEditGroup editGroup = new TextEditGroup(Messages.ChangeGenerator_group); - for (ASTModification currentModification : modificationParent.get(modifiedNode)) { - if (currentModification.getAssociatedEditGroup() != null) { - editGroup = currentModification.getAssociatedEditGroup(); - edit.addChildren(editGroup.getTextEdits()); - break; + for (List<ASTModification> modifications : getModifications(modifiedNode).values()) { + for (ASTModification modification : modifications) { + if (modification.getAssociatedEditGroup() != null) { + editGroup = modification.getAssociatedEditGroup(); + edit.addChildren(editGroup.getTextEdits()); + return edit; + } } } return edit; } - private String originalCodeOfNode(IASTNode node, IFile sourceFile) { - int nodeOffset = getOffsetIncludingComments(node); - int nodeLength = getNodeLengthIncludingComments(node); - return FileContentHelper.getContent(sourceFile, nodeOffset, nodeLength); - } - - private int getNodeLengthIncludingComments(IASTNode node) { + private int getOffsetIncludingComments(IASTNode node) { int nodeOffset = node.getFileLocation().getNodeOffset(); - int nodeLength = node.getFileLocation().getNodeLength(); - ArrayList<IASTComment> comments = commentMap.getAllCommentsForNode(node); + List<IASTComment> comments = commentMap.getAllCommentsForNode(node); if (!comments.isEmpty()) { int startOffset = nodeOffset; - int endOffset = nodeOffset + nodeLength; for (IASTComment comment : comments) { IASTFileLocation commentLocation = comment.getFileLocation(); if (commentLocation.getNodeOffset() < startOffset) { startOffset = commentLocation.getNodeOffset(); } - if (commentLocation.getNodeOffset() + commentLocation.getNodeLength() >= endOffset) { - endOffset = commentLocation.getNodeOffset() + commentLocation.getNodeLength(); - } } - nodeLength = endOffset - startOffset; + nodeOffset = startOffset; } - return nodeLength; + return nodeOffset; } - private int getOffsetIncludingComments(IASTNode node) { - int nodeOffset = node.getFileLocation().getNodeOffset(); + private int getEndOffsetIncludingComments(IASTNode node) { + IASTFileLocation nodeLocation = node.getFileLocation(); + int endOffset = nodeLocation.getNodeOffset() + nodeLocation.getNodeLength(); - ArrayList<IASTComment> comments = commentMap.getAllCommentsForNode(node); + List<IASTComment> comments = commentMap.getAllCommentsForNode(node); if (!comments.isEmpty()) { - int startOffset = nodeOffset; for (IASTComment comment : comments) { - IASTFileLocation commentLocation = comment.getFileLocation(); - if (commentLocation.getNodeOffset() < startOffset) { - startOffset = commentLocation.getNodeOffset(); + int commentEndOffset = endOffset(comment.getFileLocation()); + if (commentEndOffset >= endOffset) { + endOffset = commentEndOffset; } } - nodeOffset = startOffset; } - return nodeOffset; + return endOffset; } - private boolean hasChangedChild(IASTNode node) { - return modificationParent.containsKey(node); - } + private int getEndOffsetIncludingTrailingComments(IASTNode node) { + IASTFileLocation nodeLocation = node.getFileLocation(); + int endOffset = nodeLocation.getNodeOffset() + nodeLocation.getNodeLength(); - private boolean hasAppendsOnly(IASTNode node) { - List<ASTModification> modifications = modificationParent.get(node); - if (modifications == null) - return false; - return isAppendable(modifications); - } - - @Override - public int visit(IASTDeclarator declarator) { - if (hasChangedChild(declarator)) { - synthTreatment(declarator); - return ASTVisitor.PROCESS_SKIP; - } - return super.visit(declarator); - } - - @Override - public int visit(IASTArrayModifier mod) { - if (hasChangedChild(mod)) { - synthTreatment(mod); - return ASTVisitor.PROCESS_SKIP; - } - return super.visit(mod); - } - - @Override - public int visit(ICPPASTNamespaceDefinition namespaceDefinition) { - if (hasChangedChild(namespaceDefinition) && !hasAppendsOnly(namespaceDefinition)) { - synthTreatment(namespaceDefinition); - return ASTVisitor.PROCESS_SKIP; - } - return super.visit(namespaceDefinition); - } - - @Override - public int leave(ICPPASTNamespaceDefinition namespaceDefinition) { - if (hasAppendsOnly(namespaceDefinition)) { - handleAppends(namespaceDefinition); - } - return super.leave(namespaceDefinition); - } - - @Override - public int visit(IASTDeclSpecifier declSpec) { - if (hasChangedChild(declSpec) && !hasAppendsOnly(declSpec)) { - synthTreatment(declSpec); - return ASTVisitor.PROCESS_SKIP; - } - return super.visit(declSpec); - } - - @Override - public int leave(IASTDeclSpecifier declSpec) { - if (hasAppendsOnly(declSpec)) { - handleAppends(declSpec); - } - return super.leave(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; + List<IASTComment> comments = commentMap.getTrailingCommentsForNode(node); + if (!comments.isEmpty()) { + for (IASTComment comment : comments) { + int commentEndOffset = endOffset(comment.getFileLocation()); + if (commentEndOffset >= endOffset) { + endOffset = commentEndOffset; + } + } } - return super.visit(name); - } - - @Override - public int visit(IASTParameterDeclaration parameterDeclaration) { - if (hasChangedChild(parameterDeclaration)) { - synthTreatment(parameterDeclaration); - return ASTVisitor.PROCESS_SKIP; + // TODO(sprigogin): Remove when comments are always assigned to the outermost nodes. + if (node instanceof ICPPASTFunctionWithTryBlock) { + ICPPASTCatchHandler[] catchHandlers = ((ICPPASTFunctionWithTryBlock) node).getCatchHandlers(); + if (catchHandlers.length > 0) { + endOffset = Math.max(endOffset, + getEndOffsetIncludingTrailingComments(catchHandlers[catchHandlers.length - 1])); + } + } else if (node instanceof IASTFunctionDefinition) { + endOffset = Math.max(endOffset, + getEndOffsetIncludingTrailingComments(((IASTFunctionDefinition) node).getBody())); } - return super.visit(parameterDeclaration); + return endOffset; } - @Override - public int visit(IASTStatement statement) { - if (hasChangedChild(statement) && !hasAppendsOnly(statement)) { - synthTreatment(statement); - return ASTVisitor.PROCESS_SKIP; - } - return super.visit(statement); + private Map<ModificationKind, List<ASTModification>> getModifications(IASTNode node) { + Map<ModificationKind, List<ASTModification>> modifications = classifiedModifications.get(node); + if (modifications == null) + return Collections.emptyMap(); + return modifications; } - @Override - public int leave(IASTStatement statement) { - if (hasAppendsOnly(statement)) { - handleAppends(statement); - } - return super.leave(statement); + private List<ASTModification> getModifications(IASTNode node, ModificationKind kind) { + Map<ModificationKind, List<ASTModification>> allModifications = getModifications(node); + List<ASTModification> modifications = allModifications.get(kind); + if (modifications == null) + return Collections.emptyList(); + return modifications; } - class CodeComparer { - private final StringBuilder originalCode; - private final StringBuilder synthCode; - private int lastCommonInSynthStart; - private int lastCommonInOriginalStart; - private int firstCommonInSynthEnd; - private int firstCommonInOriginalEnd; - - public CodeComparer(String originalCode, String synthCode) { - this.originalCode = new StringBuilder(originalCode); - this.synthCode = new StringBuilder(synthCode); - calculatePositions(); - } - - private void calculatePositions() { - lastCommonInSynthStart = calcLastCommonPositionInSynthCode(); - lastCommonInOriginalStart = calcLastCommonPositionInOriginalCode(); - firstCommonInSynthEnd = - calcFirstPositionOfCommonEndInSynthCode(lastCommonInSynthStart, lastCommonInOriginalStart); - firstCommonInOriginalEnd = - calcFirstPositionOfCommonEndInOriginalCode(lastCommonInOriginalStart, lastCommonInSynthStart); - trimTrailingNewlines(); - } - - private void trimTrailingNewlines() { - int prevOrigEnd = firstCommonInOriginalEnd - 1; - while (prevOrigEnd > lastCommonInOriginalStart && prevOrigEnd > -1 && - isUninterresting(originalCode, prevOrigEnd)) { - firstCommonInOriginalEnd = prevOrigEnd; - prevOrigEnd--; - } - - while (firstCommonInOriginalEnd > 0 && firstCommonInOriginalEnd + 1 < originalCode.length() && - (originalCode.charAt(firstCommonInOriginalEnd) == ' ' || originalCode.charAt(firstCommonInOriginalEnd) == '\t')) { - firstCommonInOriginalEnd++; - } - - int prevSynthEnd = firstCommonInSynthEnd - 1; - while (prevSynthEnd > lastCommonInSynthStart && prevSynthEnd > -1 && - isUninterresting(synthCode, prevSynthEnd)) { - firstCommonInSynthEnd = prevSynthEnd; - prevSynthEnd--; - } - while (firstCommonInSynthEnd > 0 && firstCommonInSynthEnd + 1 < synthCode.length() && - (synthCode.charAt(firstCommonInSynthEnd) == ' ' || synthCode.charAt(firstCommonInSynthEnd) == '\t')) { - firstCommonInSynthEnd++; - } - } - - public int getLastCommonPositionInSynthCode() { - return lastCommonInSynthStart; - } - - public int getLastCommonPositionInOriginalCode() { - return lastCommonInOriginalStart; - } - - public int getFirstPositionOfCommonEndInOriginalCode() { - return firstCommonInOriginalEnd; - } - - public int getFirstPositionOfCommonEndInSynthCode() { - return firstCommonInSynthEnd; - } - - public int calcLastCommonPositionInSynthCode() { - return findLastCommonPosition(synthCode, originalCode); - } - - public int calcLastCommonPositionInOriginalCode() { - return findLastCommonPosition(originalCode, synthCode); - } - - private int calcFirstPositionOfCommonEndInOriginalCode(int originalLimit, int synthLimit) { - StringBuilder reverseOriginalCode = new StringBuilder(originalCode).reverse(); - StringBuilder reverseSynthCode = new StringBuilder(synthCode).reverse(); - int lastCommonPosition = findLastCommonPosition(reverseOriginalCode, reverseSynthCode, - reverseOriginalCode.length() - originalLimit - 1, - reverseSynthCode.length() - synthLimit - 1); - - if (lastCommonPosition < 0 || lastCommonPosition >= originalCode.length()) { - return -1; - } - - return originalCode.length() - lastCommonPosition - 1; - } - - private int calcFirstPositionOfCommonEndInSynthCode(int synthLimit, int originalLimit) { - StringBuilder reverseOriginalCode = new StringBuilder(originalCode).reverse(); - StringBuilder reverseSynthCode = new StringBuilder(synthCode).reverse(); - - int lastCommonPosition = findLastCommonPosition(reverseSynthCode, reverseOriginalCode, - reverseSynthCode.length() - synthLimit - 1, - reverseOriginalCode.length() - originalLimit - 1); - - if (lastCommonPosition < 0 || lastCommonPosition >= synthCode.length()) { - return -1; - } - - return synthCode.length() - lastCommonPosition - 1; - } - - private int findLastCommonPosition(StringBuilder first, StringBuilder second) { - return findLastCommonPosition(first, second, first.length(), second.length()); - } - - private int findLastCommonPosition(StringBuilder first, StringBuilder second, int firstLimit, - int secondLimit) { - int firstIndex = -1; - int secondIndex = -1; - int lastCommonIndex = -1; - - do { - lastCommonIndex = firstIndex; - firstIndex = nextInterrestingPosition(first, firstIndex); - secondIndex = nextInterrestingPosition(second, secondIndex); - } while (firstIndex > -1 && firstIndex <= firstLimit && secondIndex > -1 && - secondIndex <= secondLimit && first.charAt(firstIndex) == second.charAt(secondIndex)); - return lastCommonIndex; - } - - 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': + private boolean requiresRewrite(IASTNode node) { + if (!getModifications(node, ModificationKind.REPLACE).isEmpty()) + return true; + for (ASTModification modification : getModifications(node, ModificationKind.APPEND_CHILD)) { + if (!isAppendable(modification)) return true; - - default: - return false; - } - } - - protected void createChange(MultiTextEdit edit, IASTNode changedNode) { - int changeOffset = getOffsetIncludingComments(changedNode); - createChange(edit, changeOffset); - } - - private void createChange(MultiTextEdit edit, int changeOffset) { - int i = (firstCommonInSynthEnd >= 0 ? - firstCommonInOriginalEnd : originalCode.length()) - lastCommonInOriginalStart; - if (i <= 0) { - String insertCode = synthCode.substring(lastCommonInSynthStart, - firstCommonInSynthEnd); - InsertEdit iEdit = new InsertEdit(changeOffset + lastCommonInOriginalStart, - insertCode); - edit.addChild(iEdit); - } else if ((firstCommonInSynthEnd >= 0 ? - firstCommonInSynthEnd : synthCode.length()) - lastCommonInSynthStart <= 0) { - int correction = 0; - if (lastCommonInSynthStart > firstCommonInSynthEnd) { - correction = lastCommonInSynthStart - firstCommonInSynthEnd; - } - DeleteEdit dEdit = new DeleteEdit(changeOffset + lastCommonInOriginalStart, - firstCommonInOriginalEnd - lastCommonInOriginalStart + correction); - edit.addChild(dEdit); - } else { - String replacementCode = getReplacementCode(lastCommonInSynthStart, - firstCommonInSynthEnd); - ReplaceEdit rEdit = new ReplaceEdit( - changeOffset + Math.max(lastCommonInOriginalStart, 0), - (firstCommonInOriginalEnd >= 0 ? - firstCommonInOriginalEnd : - originalCode.length()) - Math.max(lastCommonInOriginalStart, 0), - replacementCode); - edit.addChild(rEdit); - } } + return false; + } - 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); - } - return ""; //$NON-NLS-1$ - } + private boolean isAppendable(ASTModification modification) { + if (modification.getKind() != ModificationKind.APPEND_CHILD) + return false; + IASTNode node = modification.getNewNode(); + return node instanceof IASTDeclaration || node instanceof IASTStatement; } public Change getChange() { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/ChangeGeneratorWriterVisitor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/ChangeGeneratorWriterVisitor.java index 72537365b5d..7fd8a078166 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/ChangeGeneratorWriterVisitor.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/ChangeGeneratorWriterVisitor.java @@ -23,6 +23,7 @@ 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.IASTPointerOperator; import org.eclipse.cdt.core.dom.ast.IASTProblem; import org.eclipse.cdt.core.dom.ast.IASTStatement; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; @@ -43,7 +44,6 @@ import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap; * @author Emanuel Graf IFS */ public class ChangeGeneratorWriterVisitor extends ASTWriterVisitor { - private static final String DEFAULT_INDENTATION = ""; //$NON-NLS-1$ private final ASTModificationStore modificationStore; private final String fileScope; private ModificationScopeStack stack; @@ -56,30 +56,31 @@ public class ChangeGeneratorWriterVisitor extends ASTWriterVisitor { this.fileScope = fileScope; this.stack = new ModificationScopeStack(modificationStore); - shouldVisitExpressions = delegateVisitor.shouldVisitExpressions; - shouldVisitStatements = delegateVisitor.shouldVisitStatements; - shouldVisitNames = delegateVisitor.shouldVisitNames; + shouldVisitArrayModifiers= delegateVisitor.shouldVisitArrayModifiers; + shouldVisitBaseSpecifiers = delegateVisitor.shouldVisitBaseSpecifiers; shouldVisitDeclarations = delegateVisitor.shouldVisitDeclarators; - shouldVisitDeclSpecifiers = delegateVisitor.shouldVisitDeclSpecifiers; shouldVisitDeclarators = delegateVisitor.shouldVisitDeclarators; + shouldVisitDeclSpecifiers = delegateVisitor.shouldVisitDeclSpecifiers; + shouldVisitExpressions = delegateVisitor.shouldVisitExpressions; shouldVisitInitializers = delegateVisitor.shouldVisitInitializers; - shouldVisitBaseSpecifiers = delegateVisitor.shouldVisitBaseSpecifiers; + shouldVisitNames = delegateVisitor.shouldVisitNames; shouldVisitNamespaces = delegateVisitor.shouldVisitNamespaces; - shouldVisitTemplateParameters = delegateVisitor.shouldVisitTemplateParameters; shouldVisitParameterDeclarations = delegateVisitor.shouldVisitParameterDeclarations; - shouldVisitTranslationUnit = delegateVisitor.shouldVisitTranslationUnit; + shouldVisitPointerOperators= delegateVisitor.shouldVisitPointerOperators; shouldVisitProblems = delegateVisitor.shouldVisitProblems; + shouldVisitStatements = delegateVisitor.shouldVisitStatements; + shouldVisitTemplateParameters = delegateVisitor.shouldVisitTemplateParameters; + shouldVisitTranslationUnit = delegateVisitor.shouldVisitTranslationUnit; shouldVisitTypeIds = delegateVisitor.shouldVisitTypeIds; - shouldVisitArrayModifiers= delegateVisitor.shouldVisitArrayModifiers; } public ChangeGeneratorWriterVisitor(ASTModificationStore modStore, NodeCommentMap nodeMap) { - this(modStore, DEFAULT_INDENTATION, null, nodeMap); + this(modStore, null, nodeMap); } - public ChangeGeneratorWriterVisitor(ASTModificationStore modStore, String givenIndentation, - String fileScope, NodeCommentMap commentMap) { - super(givenIndentation, commentMap); + public ChangeGeneratorWriterVisitor(ASTModificationStore modStore, String fileScope, + NodeCommentMap commentMap) { + super(commentMap); this.modificationStore = modStore; this.fileScope = fileScope; this.shouldVisitTranslationUnit = true; @@ -210,6 +211,12 @@ public class ChangeGeneratorWriterVisitor extends ASTWriterVisitor { } @Override + public int leave(IASTPointerOperator pointerOperator) { + super.leave(pointerOperator); + return PROCESS_SKIP; + } + + @Override public int leave(IASTProblem problem) { super.leave(problem); return PROCESS_SKIP; @@ -306,6 +313,14 @@ public class ChangeGeneratorWriterVisitor extends ASTWriterVisitor { } @Override + public int visit(IASTPointerOperator pointerOperator) { + if (doBeforeEveryNode(pointerOperator) == PROCESS_CONTINUE) { + return super.visit(pointerOperator); + } + return PROCESS_SKIP; + } + + @Override public int visit(IASTProblem problem) { if (doBeforeEveryNode(problem) == PROCESS_CONTINUE) { return super.visit(problem); @@ -369,10 +384,8 @@ public class ChangeGeneratorWriterVisitor extends ASTWriterVisitor { stack.pushScope(node); currentMod.getNewNode().accept(this); stack.popScope(node); - return PROCESS_SKIP; - } else { - return PROCESS_SKIP; } + return PROCESS_SKIP; } } } 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 index 25620836f9d..d6defc940b4 100644 --- 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 @@ -13,6 +13,7 @@ package org.eclipse.cdt.internal.core.dom.rewrite.commenthandler; import java.util.ArrayList; import java.util.Collections; +import java.util.List; import java.util.TreeMap; import org.eclipse.cdt.core.dom.ast.ASTVisitor; @@ -171,26 +172,25 @@ public class ASTCommenter { * @return NodeCommentMap */ public static NodeCommentMap getCommentedNodeMap(IASTTranslationUnit transUnit){ - if (transUnit== null) { + if (transUnit == null) { return new NodeCommentMap(); } - ArrayList<IASTComment> comments = removeNotNeededComments(transUnit); - if (comments == null || comments.size() == 0) { + List<IASTComment> comments = removeNotNeededComments(transUnit); + if (comments == null || comments.isEmpty()) { return new NodeCommentMap(); } return addCommentsToCommentMap(transUnit, comments); } - private static ArrayList<IASTComment> removeNotNeededComments(IASTTranslationUnit transUnit) { - ArrayList<IASTComment> comments = getCommentsInWorkspace(transUnit); - if (comments == null || comments.size() == 0) { + private static List<IASTComment> removeNotNeededComments(IASTTranslationUnit transUnit) { + List<IASTComment> comments = getCommentsInWorkspace(transUnit); + if (comments == null || comments.isEmpty()) { return null; } - ArrayList<IASTComment> com = removeAllPreprocessorComments(transUnit, comments); - return com; + return removeAllPreprocessorComments(transUnit, comments); } - private static ArrayList<IASTComment> getCommentsInWorkspace(IASTTranslationUnit tu) { + private static List<IASTComment> getCommentsInWorkspace(IASTTranslationUnit tu) { IASTComment[] comments = tu.getComments(); ArrayList<IASTComment> commentsInWorkspace = new ArrayList<IASTComment>(); @@ -206,8 +206,8 @@ public class ASTCommenter { return commentsInWorkspace; } - private static ArrayList<IASTComment> removeAllPreprocessorComments(IASTTranslationUnit tu, - ArrayList<IASTComment> comments) { + private static List<IASTComment> removeAllPreprocessorComments(IASTTranslationUnit tu, + List<IASTComment> comments) { IASTPreprocessorStatement[] preprocessorStatements = tu.getAllPreprocessorStatements(); TreeMap<Integer, String> treeOfPreProcessorLines = new TreeMap<Integer,String>(); TreeMap<String, ArrayList<Integer>> ppOffsetForFiles = new TreeMap<String, ArrayList<Integer>>(); @@ -286,7 +286,7 @@ public class ASTCommenter { } private static NodeCommentMap addCommentsToCommentMap(IASTTranslationUnit rootNode, - ArrayList<IASTComment> comments){ + List<IASTComment> comments){ NodeCommentMap commentMap = new NodeCommentMap(); CommentHandler commHandler = new CommentHandler(comments); @@ -296,8 +296,8 @@ public class ASTCommenter { 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) { + // Add the remaining comments to the last declaration to prevent comment loss. + if (i == declarations.length - 1) { commenter.addRemainingComments(declarations[i]); } } 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 index 6d7b1e26776..9fbd6bbf19f 100644 --- 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 @@ -45,17 +45,18 @@ public class ASTCommenterVisitor extends ASTVisitor { private NodeCommenter nodeCommenter; { - shouldVisitExpressions = true; - shouldVisitStatements = true; - shouldVisitNames = true; + shouldVisitBaseSpecifiers = true; shouldVisitDeclarations = true; - shouldVisitDeclSpecifiers = true; shouldVisitDeclarators = true; + shouldVisitDeclSpecifiers = true; + shouldVisitExpressions = true; shouldVisitInitializers = true; - shouldVisitBaseSpecifiers = true; + shouldVisitNames = true; shouldVisitNamespaces = true; - shouldVisitTemplateParameters = true; shouldVisitParameterDeclarations = true; + shouldVisitStatements = true; + shouldVisitTemplateParameters = true; + shouldVisitTypeIds = true; } public ASTCommenterVisitor(CommentHandler commHandler, NodeCommentMap commentMap) { @@ -93,6 +94,11 @@ public class ASTCommenterVisitor extends ASTVisitor { } @Override + public int visit(IASTTypeId typeId) { + return nodeCommenter.appendComments((ASTNode) typeId); + } + + @Override public int visit(IASTDeclaration declaration) { return nodeCommenter.appendComments((ASTNode) declaration); } 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 index 9299f42963b..9ef98352418 100644 --- 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 @@ -7,11 +7,11 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Institute for Software - initial API and implementation + * Institute for Software - initial API and implementation *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.rewrite.commenthandler; -import java.util.ArrayList; +import java.util.List; import org.eclipse.cdt.core.dom.ast.IASTComment; @@ -23,10 +23,9 @@ import org.eclipse.cdt.core.dom.ast.IASTComment; * @author Guido Zgraggen IFS */ public class CommentHandler { - - private final ArrayList<IASTComment> comments; + private final List<IASTComment> comments; - public CommentHandler(ArrayList<IASTComment> comments) { + public CommentHandler(List<IASTComment> comments) { super(); this.comments = comments; } @@ -36,7 +35,7 @@ public class CommentHandler { } public boolean hasMore() { - return comments.size()>0; + return !comments.isEmpty(); } public IASTComment getFirst() { 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 index 4f65d336710..829c2ddd4e2 100644 --- 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 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik + * Copyright (c) 2008, 2011 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 @@ -7,12 +7,14 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Institute for Software - initial API and implementation + * Institute for Software - initial API and implementation ******************************************************************************/ package org.eclipse.cdt.internal.core.dom.rewrite.commenthandler; import java.util.ArrayList; import java.util.HashMap; +import java.util.List; +import java.util.Map; import org.eclipse.cdt.core.dom.ast.IASTComment; import org.eclipse.cdt.core.dom.ast.IASTNode; @@ -25,18 +27,18 @@ import org.eclipse.cdt.core.dom.ast.IASTNode; * @author Guido Zgraggen IFS */ public class NodeCommentMap { - 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>>(); + protected final Map<IASTNode, List<IASTComment>> leadingMap = new HashMap<IASTNode, List<IASTComment>>(); + protected final Map<IASTNode, List<IASTComment>> trailingMap = new HashMap<IASTNode, List<IASTComment>>(); + protected final Map<IASTNode, List<IASTComment>> freestandingMap = new HashMap<IASTNode, List<IASTComment>>(); /** * Add a comment to the map with the trailing comments. * @param node The node is the key. * @param comment The comment is the value */ - public void addTrailingCommentToNode(IASTNode node, IASTComment comment){ - ArrayList<IASTComment> comments = trailingMap.get(node); - if(comments == null){ + public void addTrailingCommentToNode(IASTNode node, IASTComment comment) { + List<IASTComment> comments = trailingMap.get(node); + if (comments == null) { comments = new ArrayList<IASTComment>(); } comments.add(comment); @@ -44,17 +46,15 @@ public class NodeCommentMap { } /** - * Returns an ArrayList for the given node. This ArrayList contains all the comments + * Returns a List for the given node. This List contains all the comments * which are assigned to this specific node. If no comments are available an empty - * ArrayList is returned. + * List is returned. * @param node The key to fetch the associated comments. - * @return ArrayList + * @return List */ - public ArrayList<IASTComment> getTrailingCommentsForNode(IASTNode node){ - if(trailingMap.get(node) == null) { - return new ArrayList<IASTComment>(); - } - return trailingMap.get(node); + public List<IASTComment> getTrailingCommentsForNode(IASTNode node) { + List<IASTComment> list = trailingMap.get(node); + return list != null ? list : new ArrayList<IASTComment>(); } /** @@ -62,9 +62,9 @@ public class NodeCommentMap { * @param node The node is the key. * @param comment The comment is the value */ - public void addLeadingCommentToNode(IASTNode node, IASTComment comment){ - ArrayList<IASTComment> comments = leadingMap.get(node); - if(comments == null){ + public void addLeadingCommentToNode(IASTNode node, IASTComment comment) { + List<IASTComment> comments = leadingMap.get(node); + if (comments == null) { comments = new ArrayList<IASTComment>(); } comments.add(comment); @@ -72,17 +72,15 @@ public class NodeCommentMap { } /** - * Returns an ArrayList for the given node. This ArrayList contains all the comments + * Returns a List for the given node. This List contains all the comments * which are assigned to this specific node. If no comments are available an empty - * ArrayList is returned. + * List is returned. * @param node The key to fetch the associated comments. - * @return ArrayList + * @return List */ - public ArrayList<IASTComment> getLeadingCommentsForNode(IASTNode node){ - if(leadingMap.get(node) == null) { - return new ArrayList<IASTComment>(); - } - return leadingMap.get(node); + public List<IASTComment> getLeadingCommentsForNode(IASTNode node) { + List<IASTComment> list = leadingMap.get(node); + return list != null ? list : new ArrayList<IASTComment>(); } /** @@ -90,9 +88,9 @@ public class NodeCommentMap { * @param node The node is the key. * @param comment The comment is the value */ - public void addFreestandingCommentToNode(IASTNode node, IASTComment comment){ - ArrayList<IASTComment> comments = freestandingMap.get(node); - if(comments == null){ + public void addFreestandingCommentToNode(IASTNode node, IASTComment comment) { + List<IASTComment> comments = freestandingMap.get(node); + if (comments == null) { comments = new ArrayList<IASTComment>(); } comments.add(comment); @@ -100,51 +98,50 @@ public class NodeCommentMap { } /** - * Returns an ArrayList for the given node. This ArrayList contains all the comments + * Returns a List for the given node. This List contains all the comments * which are assigned to this specific node. If no comments are available an empty - * ArrayList is returned. + * List is returned. * @param node The key to fetch the associated comments. - * @return ArrayList + * @return List */ - public ArrayList<IASTComment> getFreestandingCommentsForNode(IASTNode node){ - if(freestandingMap.get(node) == null) { - return new ArrayList<IASTComment>(); - } - return freestandingMap.get(node); + public List<IASTComment> getFreestandingCommentsForNode(IASTNode node) { + List<IASTComment> list = freestandingMap.get(node); + return list != null ? list : new ArrayList<IASTComment>(); } - - + /** - * Returns the HashMap with all leading maps. Used only for test purpose - * @return HashMap of all leading comments + * Returns the Map with all leading maps. Used only for test purpose + * @return Map of all leading comments */ - public HashMap<IASTNode, ArrayList<IASTComment>> getLeadingMap() { + public Map<IASTNode, List<IASTComment>> getLeadingMap() { return leadingMap; } + /** - * Returns the HashMap with all trailing maps. Used only for test purpose - * @return HashMap of all trailing comments + * Returns the Map with all trailing maps. Used only for test purpose + * @return Map of all trailing comments */ - public HashMap<IASTNode, ArrayList<IASTComment>> getTrailingMap() { + public Map<IASTNode, List<IASTComment>> getTrailingMap() { return trailingMap; } + /** - * Returns the HashMap with all freestanding maps. Used only for test purpose - * @return HashMap of all freestanding comments + * Returns the Map with all freestanding maps. Used only for test purpose + * @return Map of all freestanding comments */ - public HashMap<IASTNode, ArrayList<IASTComment>> getFreestandingMap() { + public Map<IASTNode, List<IASTComment>> getFreestandingMap() { return freestandingMap; } /** - * Returns an ArrayList for the given node. This ArrayList contains all the comments + * Returns an List for the given node. This List contains all the comments * which are assigned to this specific node. If no comments are available an empty - * ArrayList is returned. + * List is returned. * @param node The key to fetch the associated comments. - * @return ArrayList + * @return List */ - public ArrayList<IASTComment> getAllCommentsForNode(IASTNode node) { - ArrayList<IASTComment> comment = new ArrayList<IASTComment>(); + public List<IASTComment> getAllCommentsForNode(IASTNode node) { + List<IASTComment> comment = new ArrayList<IASTComment>(); comment.addAll(getFreestandingCommentsForNode(node)); comment.addAll(getLeadingCommentsForNode(node)); comment.addAll(getTrailingCommentsForNode(node)); 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 index 5ae49e8f7dc..75430528969 100644 --- 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 @@ -7,7 +7,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Institute for Software - initial API and implementation + * Institute for Software - initial API and implementation *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.rewrite.commenthandler; @@ -39,25 +39,27 @@ import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.Path; /** - * The NodeCommenter contains all the logic that is needed for the ASTCommentVisitor to assign the comments - * to the suitable node. Together with the ASTCommenterVisitor it fills all the comments with the correspondent - * node into the NodeCommentMap. + * The NodeCommenter contains all the logic that is needed for the ASTCommentVisitor to assign + * the comments to the suitable node. Together with the ASTCommenterVisitor it fills all + * the comments with the correspondent node into the NodeCommentMap. * - * Following, a little explanation of the assignment logic. It is only a loose illustration a detailed description - * would include a combined explanation of ASTCommenterVisitor and NodeCommenter.<br> + * Following, a little explanation of the assignment logic. It is only a loose illustration + * a detailed description would include a combined explanation of ASTCommenterVisitor and + * NodeCommenter.<br> * To understand the logic we define the three types of comments:<br> * leading comments - Comments before a statement, declaration, or definition.<br> * trailing comments - Comments right after the AST node on the same line.<br> * freestanding comments - Comments before a closing brace such as they occur in * namespace-, class- and method-definitions or at the end of a file.<br> * - * The first comment is fetched and the position of it is compared to the position of the actual node. If - * the position of the comment is smaller than the comment is added to the node as leading. If it is behind the node - * but on the same line it is added as trailing. If one of these possibilities match the next comment is fetched for - * the same check. If it doesn't match the same procedure is done for all the child nodes. After checking the sub nodes - * the actual node is checked again if the comment is trailing. Then there is also the possibility that this comment is - * freestanding. This is the case when the comment is not added to any child node but the position is smaller den - * the end position of the node. + * The first comment is fetched and the position of it is compared to the position of the actual + * node. If the position of the comment is smaller than the comment is added to the node as leading. + * If it is behind the node but on the same line it is added as trailing. If one of these + * possibilities match the next comment is fetched for the same check. If it doesn't match the same + * procedure is done for all the child nodes. After checking the sub nodes the actual node is + * checked again if the comment is trailing. Then there is also the possibility that this comment is + * freestanding. This is the case when the comment is not added to any child node but the position + * is smaller than the end position of the node. * * @author Guido Zgraggen IFS */ @@ -90,7 +92,7 @@ public class NodeCommenter { ASTNode com = (ASTNode) comment; if (node.getFileLocation() == null) { - //MacroExpansions have no FileLocation + // MacroExpansions have no FileLocation return false; } @@ -111,7 +113,7 @@ public class NodeCommenter { ASTNode com = (ASTNode) comment; if (node.getFileLocation() == null) { - //MacroExpansions have no Filelocation + // MacroExpansions have no FileLocation return false; } if (OffsetHelper.getNodeEndPoint(com) <= OffsetHelper.getNodeEndPoint(node)) { @@ -151,7 +153,7 @@ public class NodeCommenter { try { InputStream is = file.getContents(); - int length = OffsetHelper.getNodeOffset(com)-OffsetHelper.getNodeEndPoint(node); + int length = OffsetHelper.getNodeOffset(com) - OffsetHelper.getNodeEndPoint(node); byte[] b = new byte[length]; long count = is.skip(OffsetHelper.getEndOffsetWithoutComments(node)); diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/ToolFactory.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/ToolFactory.java index 40575273b00..04e26c65036 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/ToolFactory.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/ToolFactory.java @@ -9,7 +9,6 @@ * QNX Software Systems - Initial API and implementation * Anton Leherbauer (Wind River Systems) *******************************************************************************/ - package org.eclipse.cdt.core; import java.util.Map; @@ -49,19 +48,19 @@ public class ToolFactory { IExtensionPoint extension = Platform.getExtensionRegistry().getExtensionPoint(CCorePlugin.PLUGIN_ID, extID); if (extension != null) { IExtension[] extensions = extension.getExtensions(); - for(int i = 0; i < extensions.length; i++){ + for (int i = 0; i < extensions.length; i++){ IConfigurationElement [] configElements = extensions[i].getConfigurationElements(); - for(int j = 0; j < configElements.length; j++){ + for (int j = 0; j < configElements.length; j++){ String initializerID = configElements[j].getAttribute("id"); //$NON-NLS-1$ if (initializerID != null && initializerID.equals(formatterID)){ try { Object execExt = configElements[j].createExecutableExtension("class"); //$NON-NLS-1$ if (execExt instanceof CodeFormatter){ - CodeFormatter formatter = (CodeFormatter)execExt; + CodeFormatter formatter = (CodeFormatter) execExt; formatter.setOptions(options); return formatter; } - } catch(CoreException e) { + } catch (CoreException e) { CCorePlugin.log(e.getStatus()); break; } diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/formatter/DefaultCodeFormatterConstants.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/formatter/DefaultCodeFormatterConstants.java index eaa5781b257..711786b3bb1 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/formatter/DefaultCodeFormatterConstants.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/formatter/DefaultCodeFormatterConstants.java @@ -530,6 +530,7 @@ public class DefaultCodeFormatterConstants { * @since 5.3 */ public final static String FORMATTER_COMMENT_MIN_DISTANCE_BETWEEN_CODE_AND_LINE_COMMENT = CCorePlugin.PLUGIN_ID + ".formatter.comment.min_distance_between_code_and_line_comment"; //$NON-NLS-1$ + /** * <pre> * FORMATTER / Option to control whether the white space between code and line comments should be preserved or replaced with a single space @@ -541,11 +542,23 @@ public class DefaultCodeFormatterConstants { * @see #FALSE * @since 5.3 */ - public final static String FORMATTER_COMMENT_PRESERVE_WHITE_SPACE_BETWEEN_CODE_AND_LINE_COMMENT = CCorePlugin.PLUGIN_ID + ".formatter.comment.preserve_white_space_between_code_and_line_comments"; //$NON-NLS-1$ /** * <pre> + * FORMATTER / Option to control whether comments starting from the beginning of line should stay that way and never be indented. + * - option id: "org.eclipse.cdt.core.formatter.comment.never_indent_line_comments_on_first_column" + * - possible values: { TRUE, FALSE } + * - default: TRUE + * </pre> + * @see #TRUE + * @see #FALSE + * @since 5.4 + */ + public final static String FORMATTER_COMMENT_NEVER_INDENT_LINE_COMMENTS_ON_FIRST_COLUMN = CCorePlugin.PLUGIN_ID + ".formatter.comment.never_indent_line_comments_on_first_column"; //$NON-NLS-1$ + + /** + * <pre> * FORMATTER / Option to compact else/if * - option id: "org.eclipse.cdt.core.formatter.compact_else_if" * - possible values: { TRUE, FALSE } diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/DefaultCodeFormatterOptions.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/DefaultCodeFormatterOptions.java index 7d5c4b76a0b..dc1e040c11e 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/DefaultCodeFormatterOptions.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/DefaultCodeFormatterOptions.java @@ -100,7 +100,7 @@ public class DefaultCodeFormatterOptions { // public int comment_line_length; public int comment_min_distance_between_code_and_line_comment; public boolean comment_preserve_white_space_between_code_and_line_comment; - public boolean never_indent_line_comments_on_first_column = true; + public boolean never_indent_line_comments_on_first_column; public int continuation_indentation; public int continuation_indentation_for_initializer_list; @@ -314,6 +314,7 @@ public class DefaultCodeFormatterOptions { // options.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_LINE_LENGTH, Integer.toString(this.comment_line_length)); options.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_MIN_DISTANCE_BETWEEN_CODE_AND_LINE_COMMENT, Integer.toString(this.comment_min_distance_between_code_and_line_comment)); options.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_PRESERVE_WHITE_SPACE_BETWEEN_CODE_AND_LINE_COMMENT, this.comment_preserve_white_space_between_code_and_line_comment ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE); + options.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_NEVER_INDENT_LINE_COMMENTS_ON_FIRST_COLUMN, this.never_indent_line_comments_on_first_column ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE); options.put(DefaultCodeFormatterConstants.FORMATTER_CONTINUATION_INDENTATION, Integer.toString(this.continuation_indentation)); options.put(DefaultCodeFormatterConstants.FORMATTER_CONTINUATION_INDENTATION_FOR_INITIALIZER_LIST, Integer.toString(this.continuation_indentation_for_initializer_list)); options.put(DefaultCodeFormatterConstants.FORMATTER_INDENT_STATEMENTS_COMPARE_TO_BLOCK, this.indent_statements_compare_to_block ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE); @@ -847,6 +848,10 @@ public class DefaultCodeFormatterOptions { if (commentPreserveWhiteSpaceBetweenCodeAndLineCommentOption != null) { this.comment_preserve_white_space_between_code_and_line_comment = DefaultCodeFormatterConstants.TRUE.equals(commentPreserveWhiteSpaceBetweenCodeAndLineCommentOption); } + final Object neverIndentLineCommentsOnFirstColumn = settings.get(DefaultCodeFormatterConstants.FORMATTER_COMMENT_NEVER_INDENT_LINE_COMMENTS_ON_FIRST_COLUMN); + if (neverIndentLineCommentsOnFirstColumn != null) { + this.never_indent_line_comments_on_first_column = DefaultCodeFormatterConstants.TRUE.equals(neverIndentLineCommentsOnFirstColumn); + } final Object continuationIndentationOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_CONTINUATION_INDENTATION); if (continuationIndentationOption != null) { try { @@ -1525,7 +1530,8 @@ public class DefaultCodeFormatterOptions { this.brace_position_for_switch = DefaultCodeFormatterConstants.END_OF_LINE; this.brace_position_for_type_declaration = DefaultCodeFormatterConstants.END_OF_LINE; this.comment_min_distance_between_code_and_line_comment = 1; - this.comment_preserve_white_space_between_code_and_line_comment = false; + this.comment_preserve_white_space_between_code_and_line_comment = true; + this.never_indent_line_comments_on_first_column = true; // this.comment_clear_blank_lines = false; // this.comment_format = true; // this.comment_format_header = false; diff --git a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractConstant.rts b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractConstant.rts index 52391193643..a402270781e 100644 --- a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractConstant.rts +++ b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractConstant.rts @@ -13,8 +13,6 @@ public: }; #endif /*A_H_*/ - - //= #ifndef A_H_ #define A_H_ @@ -25,12 +23,11 @@ public: virtual ~A(); int foo(); void bar(); + static const int theAnswer = 42; }; #endif /*A_H_*/ - - //@A.cpp #include "A.h" @@ -48,7 +45,6 @@ void A::bar() { int a = 42; int b = 42; } - //= #include "A.h" @@ -66,7 +62,6 @@ void A::bar() { int a = theAnswer; int b = theAnswer; } - //!ExtractConstantInt 2 //#org.eclipse.cdt.ui.tests.refactoring.extractconstant.ExtractConstantRefactoringTest //@A.h @@ -82,8 +77,6 @@ public: }; #endif /*A_H_*/ - - //= #ifndef A_H_ #define A_H_ @@ -94,12 +87,11 @@ public: virtual ~A(); int foo(); void bar(); + static const int theAnswer = 42; }; #endif /*A_H_*/ - - //@A.cpp #include "A.h" @@ -118,7 +110,6 @@ void A::bar() { int a = 42; int b = 42; } - //= #include "A.h" @@ -137,7 +128,6 @@ void A::bar() { int a = theAnswer; int b = theAnswer; } - //!ExtractConstantFloat //#org.eclipse.cdt.ui.tests.refactoring.extractconstant.ExtractConstantRefactoringTest //@A.h @@ -153,8 +143,6 @@ public: }; #endif /*A_H_*/ - - //= #ifndef A_H_ #define A_H_ @@ -165,12 +153,11 @@ public: virtual ~A(); float foo(); void bar(); + static const float theAnswer = 42.0f; }; #endif /*A_H_*/ - - //@A.cpp #include "A.h" @@ -188,7 +175,6 @@ void A::bar() { float a = 42.0f; float b = 42.0f; } - //= #include "A.h" @@ -206,7 +192,6 @@ void A::bar() { float a = theAnswer; float b = theAnswer; } - //!ExtractConstantDouble //#org.eclipse.cdt.ui.tests.refactoring.extractconstant.ExtractConstantRefactoringTest //@A.h @@ -222,8 +207,6 @@ public: }; #endif /*A_H_*/ - - //= #ifndef A_H_ #define A_H_ @@ -234,12 +217,11 @@ public: virtual ~A(); double foo(); void bar(); + static const double theAnswer = 42.0; }; #endif /*A_H_*/ - - //@A.cpp #include "A.h" @@ -257,7 +239,6 @@ void A::bar() { double a = 42.0; double b = 42.0; } - //= #include "A.h" @@ -275,7 +256,6 @@ void A::bar() { double a = theAnswer; double b = theAnswer; } - //!ExtractConstantStaticInt //#org.eclipse.cdt.ui.tests.refactoring.extractconstant.ExtractConstantRefactoringTest //@A.h @@ -291,7 +271,6 @@ public: }; #endif /*A_H_*/ - //= #ifndef A_H_ #define A_H_ @@ -305,7 +284,6 @@ public: }; #endif /*A_H_*/ - //@A.cpp #include "A.h" @@ -322,7 +300,6 @@ int A::foo() { int bar() { return /*$*/42/*$$*/; } - //= #include "A.h" @@ -345,7 +322,6 @@ int A::foo() { int bar() { return theAnswer; } - //!replaceNumberProtected //#org.eclipse.cdt.ui.tests.refactoring.extractconstant.ExtractConstantRefactoringTest //@.config diff --git a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractConstantHistory.rts b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractConstantHistory.rts index 10835096456..6df4814549a 100644 --- a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractConstantHistory.rts +++ b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractConstantHistory.rts @@ -13,7 +13,6 @@ public: }; #endif /*A_H_*/ - //= #ifndef A_H_ #define A_H_ @@ -24,11 +23,11 @@ public: virtual ~A(); int foo(); void bar(); + static const int theAnswer = 42; }; #endif /*A_H_*/ - //@A.cpp #include "A.h" @@ -46,7 +45,6 @@ void A::bar() { int a = 42; int b = 42; } - //= #include "A.h" @@ -64,7 +62,6 @@ void A::bar() { int a = theAnswer; int b = theAnswer; } - //@refScript.xml <?xml version="1.0" encoding="UTF-8"?> <session version="1.0"> @@ -89,7 +86,6 @@ public: }; #endif /*A_H_*/ - //= #ifndef A_H_ #define A_H_ @@ -105,7 +101,6 @@ protected: }; #endif /*A_H_*/ - //@A.cpp #include "A.h" @@ -118,7 +113,6 @@ A::~A() { int A::foo() { return 42; } - //= #include "A.h" @@ -131,7 +125,6 @@ A::~A() { int A::foo() { return theAnswer; } - //@refScript.xml <?xml version="1.0" encoding="UTF-8"?> <session version="1.0"> @@ -155,7 +148,6 @@ public: }; #endif /*A_H_*/ - //= #ifndef A_H_ #define A_H_ @@ -171,7 +163,6 @@ private: }; #endif /*A_H_*/ - //@A.cpp #include "A.h" @@ -184,7 +175,6 @@ A::~A() { int A::foo() { return 42; } - //= #include "A.h" @@ -197,7 +187,6 @@ A::~A() { int A::foo() { return theAnswer; } - //@refScript.xml <?xml version="1.0" encoding="UTF-8"?> <session version="1.0"> diff --git a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractExpression.rts b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractExpression.rts index 2381a7d7510..ec68a962ec6 100644 --- a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractExpression.rts +++ b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractExpression.rts @@ -296,7 +296,7 @@ class Klass { void set(bool b) { } - void test() { + void test() { other o; this->set(/*$*/o.value()/*$$*/); } @@ -740,22 +740,17 @@ methodname=invalid class Test { void test(); }; - - //= class Test { void test(); bool invalid(); }; - - //@test.cpp #include "test.h" void Test::test() { bool b = /*$*/false/*$$*/; } - //= #include "test.h" @@ -766,34 +761,30 @@ bool Test::invalid() { void Test::test() { bool b = invalid(); } - -//!Extract expresion with typdef Bug 331985 +//!Extract expression with typedef Bug 331985 //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest - //@.config filename=test.cpp methodname=bar //@test.cpp typedef int& foo; + int test(foo s) { - int a = /*$*/s + 1/*$$*/; // type of id-expression 's' is int, not 'foo' or 'int&' - return a; + int a = /*$*/s + 1/*$$*/; // type of id-expression 's' is int, not 'foo' or 'int&' + return a; } - - //= typedef int& foo; + int bar(foo s) { return s + 1; } int test(foo s) { - int a = bar(s); // type of id-expression 's' is int, not 'foo' or 'int&' - return a; + int a = bar(s); // type of id-expression 's' is int, not 'foo' or 'int&' + return a; } - - //!Bug 260133 Extract function and extract local variable don't handle type promotion //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest @@ -802,14 +793,11 @@ filename=test.cpp methodname=bar //@test.cpp - void foo() { int x = 3; double y = /*$*/x + 2.5/*$$*/; } - //= - double bar(int x) { return x + 2.5; } @@ -818,7 +806,6 @@ void foo() { int x = 3; double y = bar(x); } - //! Extract macro //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest @@ -836,7 +823,6 @@ int main() { return i; } - //= #define five 5 #define ADD(a, b) a + b @@ -851,7 +837,6 @@ int main() { return i; } - //! Extract macro //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest @@ -869,7 +854,6 @@ int main() { return i; } - //= #define five 5 #define ADD(a, b) a + b @@ -884,4 +868,3 @@ int main() { return i; } - diff --git a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractFunctionTemplates.rts b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractFunctionTemplates.rts index 271a5091f27..b84828e254d 100644 --- a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractFunctionTemplates.rts +++ b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractFunctionTemplates.rts @@ -4,16 +4,15 @@ void test() { } -template <typename T> +template<typename T> int tempFunct() { T i; i = 0; /*$*/i++; i += 3;/*$$*/ - + return 0; } - //= void test() { } @@ -24,22 +23,20 @@ void exp(T i) { i += 3; } -template <typename T> +template<typename T> int tempFunct() { T i; i = 0; exp(i); - return 0; } - //!Extract template function with template parameter Bug #12 //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //@A.cpp void test() { } -template <typename T> +template<typename T> int tempFunct(T p) { /*$*/++p; p + 4;/*$$*/ @@ -56,7 +53,7 @@ void exp(T p) { p + 4; } -template <typename T> +template<typename T> int tempFunct(T p) { exp(p); return 0; @@ -68,7 +65,7 @@ int tempFunct(T p) { void test() { } -template <typename T> +template<typename T> int tempFunct() { /*$*/T p; p = 0; @@ -76,7 +73,6 @@ int tempFunct() { p + 2; return 0; } - //= void test() { } @@ -89,10 +85,9 @@ T exp() { return p; } -template <typename T> +template<typename T> int tempFunct() { T p = exp(); p + 2; return 0; } - diff --git a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractMethod.rts b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractMethod.rts index c30d66c2640..514248dbf4e 100644 --- a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractMethod.rts +++ b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractMethod.rts @@ -15,7 +15,6 @@ private: }; #endif /*A_H_*/ - //= #ifndef A_H_ #define A_H_ @@ -32,7 +31,6 @@ private: }; #endif /*A_H_*/ - //@A.cpp #include "A.h" @@ -52,7 +50,6 @@ int A::foo() { int A::help() { return 42; } - //= #include "A.h" @@ -77,7 +74,6 @@ int A::foo() { int A::help() { return 42; } - //!ExtractFunctionRefactoringTest with comment //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //@A.h @@ -95,7 +91,6 @@ private: }; #endif /*A_H_*/ - //= #ifndef A_H_ #define A_H_ @@ -112,7 +107,6 @@ private: }; #endif /*A_H_*/ - //@A.cpp #include "A.h" @@ -133,7 +127,6 @@ int A::foo() { int A::help() { return 42; } - //= #include "A.h" @@ -159,7 +152,6 @@ int A::foo() { int A::help() { return 42; } - //@.config filename=A.cpp methodname=exp @@ -213,7 +205,7 @@ void exp(int& i) { int main() { int i; - exp(i); // Comment + exp(i); return i; } @@ -1739,7 +1731,6 @@ returnparameterindex=0 filename=main.h methodname=loop //@main.h - void method() { /*$*/for (int var = 0; var < 100; ++var) { if (var < 50) @@ -1747,7 +1738,6 @@ void method() { }/*$$*/ } //= - void loop() { for (int var = 0; var < 100; ++var) { if (var < 50) @@ -1764,7 +1754,6 @@ void method() { filename=main.h fatalerror=true //@main.h - void method() { /*$*/if (true) return;/*$$*/ @@ -1776,14 +1765,12 @@ void method() { fatalerror=true filename=A.h //@A.h - void function() { for (int var = 0; var < 100; ++var) { /*$*/if (var < 50) continue;/*$$*/ } } - //! Bug #124 Extract Function with a Macro call in selected code "forgets" the macro //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //@.config @@ -2411,7 +2398,6 @@ class Test { }; #endif - //= /* * Copyright 2009 @@ -2438,11 +2424,11 @@ class Test { * Retain a value for something. */ int m_value; + int exp(); }; #endif - //@test.cpp #include "test.h" diff --git a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractMethodDuplicates.rts b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractMethodDuplicates.rts index 438d6b780b6..3967ebcda7a 100644 --- a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractMethodDuplicates.rts +++ b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractMethodDuplicates.rts @@ -170,7 +170,7 @@ int A::help() { return 42; } -//!ExtractFunctionRefactoringTest dublicate with field +//!ExtractFunctionRefactoringTest duplicate with field //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //@.config replaceduplicates=true @@ -267,7 +267,7 @@ int A::help() { return 42; } -//!ExtractFunctionRefactoringTest dublicate with field in marked scope +//!ExtractFunctionRefactoringTest duplicate with field in marked scope //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //@.config replaceduplicates=true @@ -289,7 +289,6 @@ private: }; #endif /*A_H_*/ - //= #ifndef A_H_ #define A_H_ @@ -308,7 +307,6 @@ private: }; #endif /*A_H_*/ - //@A.cpp #include "A.h" @@ -336,7 +334,6 @@ void A::foo() { int A::help() { return 42; } - //= #include "A.h" @@ -360,6 +357,7 @@ int A::exp(int j) { void A::foo() { int j = 0; + j = exp(j); field++; j++; @@ -368,7 +366,6 @@ void A::foo() { int A::help() { return 42; } - //!ExtractFunctionRefactoringTest duplicates with different Names and return type //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //@.config @@ -561,7 +558,7 @@ int A::help() { return 42; } -//!ExtractFunctionRefactoringTest with duplicates name used afterwards in duplicate but not in original selection this is no dublicate +//!ExtractFunctionRefactoringTest with duplicate name used afterwards in duplicate but not in original selection this is no duplicate //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //@.config replaceduplicates=true diff --git a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractMethodHistory.rts b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractMethodHistory.rts index 34e7e832400..d10e5350ec6 100644 --- a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractMethodHistory.rts +++ b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractMethodHistory.rts @@ -211,7 +211,7 @@ int main() { name="exp" project="RegressionTestProject" selection="34,6" visibility="private"/> </session> -//!Extract Function History extracted statement with trailling comment +//!Extract Function History extracted statement with trailing comment //#org.eclipse.cdt.ui.tests.refactoring.RefactoringHistoryTest //@main.cpp int main() { @@ -227,7 +227,7 @@ void exp(int& i) { int main() { int i; - exp(i); // Comment + exp(i); return i; } diff --git a/core/org.eclipse.cdt.ui.tests/resources/refactoring/GenerateGettersAndSetters.rts b/core/org.eclipse.cdt.ui.tests/resources/refactoring/GenerateGettersAndSetters.rts index 3afa9b7a863..683aa03e439 100644 --- a/core/org.eclipse.cdt.ui.tests/resources/refactoring/GenerateGettersAndSetters.rts +++ b/core/org.eclipse.cdt.ui.tests/resources/refactoring/GenerateGettersAndSetters.rts @@ -1,22 +1,11 @@ //!Generate Getters and Setters One Getter Selection //#org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest //@.config -filename=C.h +filename=A.h getters=name -//@C.cpp -#include "C.h" - -int Person::SocSecNo() { - return socSecNo; -} - -int main(int argc, char** argv) { -} - -//= -//@C.h -#ifndef C_H_ -#define C_H_ +//@A.h +#ifndef A_H_ +#define A_H_ class Person { private: @@ -53,10 +42,10 @@ public: int gooo = 1; -#endif /* C_H_ */ +#endif /* A_H_ */ //= -#ifndef C_H_ -#define C_H_ +#ifndef A_H_ +#define A_H_ class Person { private: @@ -97,14 +86,9 @@ public: int gooo = 1; -#endif /* C_H_ */ -//!Generate Getters and Setters One Getter Selection with Namespace -//#org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest -//@.config -filename=C.h -getters=name -//@C.cpp -#include "C.h" +#endif /* A_H_ */ +//@A.cpp +#include "A.h" int Person::SocSecNo() { return socSecNo; @@ -112,11 +96,15 @@ int Person::SocSecNo() { int main(int argc, char** argv) { } - //= -//@C.h -#ifndef C_H_ -#define C_H_ +//!Generate Getters and Setters One Getter Selection with Namespace +//#org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest +//@.config +filename=A.h +getters=name +//@A.h +#ifndef A_H_ +#define A_H_ namespace Personal { @@ -157,11 +145,10 @@ public: int gooo = 1; -#endif /* C_H_ */ - +#endif /* A_H_ */ //= -#ifndef C_H_ -#define C_H_ +#ifndef A_H_ +#define A_H_ namespace Personal { @@ -206,15 +193,9 @@ public: int gooo = 1; -#endif /* C_H_ */ - -//!Generate Getters and Setters One Setter Selection -//#org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest -//@.config -filename=C.h -setters=name -//@C.cpp -#include "C.h" +#endif /* A_H_ */ +//@A.cpp +#include "A.h" int Person::SocSecNo() { return socSecNo; @@ -222,11 +203,15 @@ int Person::SocSecNo() { int main(int argc, char** argv) { } - //= -//@C.h -#ifndef C_H_ -#define C_H_ +//!Generate Getters and Setters One Setter Selection +//#org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest +//@.config +filename=A.h +setters=name +//@A.h +#ifndef A_H_ +#define A_H_ class Person { private: @@ -264,10 +249,10 @@ public: int gooo = 1; -#endif /* C_H_ */ +#endif /* A_H_ */ //= -#ifndef C_H_ -#define C_H_ +#ifndef A_H_ +#define A_H_ class Person { private: @@ -309,15 +294,9 @@ public: int gooo = 1; -#endif /* C_H_ */ -//!Generate Getters and Setters Getter and Setter Selection -//#org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest -//@.config -filename=C.h -setters=name -getters=name -//@C.cpp -#include "C.h" +#endif /* A_H_ */ +//@A.cpp +#include "A.h" int Person::SocSecNo() { return socSecNo; @@ -325,11 +304,16 @@ int Person::SocSecNo() { int main(int argc, char** argv) { } - //= -//@C.h -#ifndef C_H_ -#define C_H_ +//!Generate Getters and Setters Getter and Setter Selection +//#org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest +//@.config +filename=A.h +setters=name +getters=name +//@A.h +#ifndef A_H_ +#define A_H_ class Person { private: @@ -364,13 +348,12 @@ public: } }; - int gooo = 1; -#endif /* C_H_ */ +#endif /* A_H_ */ //= -#ifndef C_H_ -#define C_H_ +#ifndef A_H_ +#define A_H_ class Person { private: @@ -413,18 +396,11 @@ public: } }; - int gooo = 1; -#endif /* C_H_ */ -//!Generate Getters and Setters Multiple Selection -//#org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest -//@.config -filename=C.h -getters=name,systemId -setters=name,systemId -//@C.cpp -#include "C.h" +#endif /* A_H_ */ +//@A.cpp +#include "A.h" int Person::SocSecNo() { return socSecNo; @@ -432,11 +408,16 @@ int Person::SocSecNo() { int main(int argc, char** argv) { } - //= -//@C.h -#ifndef C_H_ -#define C_H_ +//!Generate Getters and Setters Multiple Selection +//#org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest +//@.config +filename=A.h +getters=name,systemId +setters=name,systemId +//@A.h +#ifndef A_H_ +#define A_H_ class Person { private: @@ -465,11 +446,10 @@ public: int gooo = 1; -#endif /* C_H_ */ - +#endif /* A_H_ */ //= -#ifndef C_H_ -#define C_H_ +#ifndef A_H_ +#define A_H_ class Person { private: @@ -514,23 +494,23 @@ public: int gooo = 1; -#endif /* C_H_ */ +#endif /* A_H_ */ +//@A.cpp +#include "A.h" +int Person::SocSecNo() { + return socSecNo; +} + +int main(int argc, char** argv) { +} +//= //!Generate Getters and Setters Visibility order 1 //#org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest //@.config filename=GaS.h getters=i,ok setters=i,ok -//@GaS.cpp -#include "Getters.h" - -GaS::Getters() { -} - -GaS::~Getters() { -} - //@GaS.h #ifndef GAS_H_ #define GAS_H_ @@ -547,7 +527,6 @@ private: }; #endif - //= #ifndef GAS_H_ #define GAS_H_ @@ -580,27 +559,33 @@ private: }; #endif +//@GaS.cpp +#include "Getters.h" + +GaS::Getters() { +} +GaS::~Getters() { +} //!Generate Getters and Setters no Methods //#org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest //@.config -filename=C.h +filename=A.h getters=id setters=id -//@C.h -#ifndef C_H_ -#define C_H_ +//@A.h +#ifndef A_H_ +#define A_H_ class Person { private: int /*$*/id/*$$*/; }; -#endif /* C_H_ */ - +#endif /* A_H_ */ //= -#ifndef C_H_ -#define C_H_ +#ifndef A_H_ +#define A_H_ class Person { private: @@ -616,15 +601,14 @@ public: } }; -#endif /* C_H_ */ - +#endif /* A_H_ */ //!Generate Getters and Setters no Methods //#org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest //@.config -filename=C.h +filename=A.h getters=i setters=i -//@C.h +//@A.h /* * test.h */ @@ -670,9 +654,9 @@ public: //!Generate Getters and Setters no Fields //#org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest //@.config -filename=C.h +filename=A.h fatalerror=true -//@C.h +//@A.h /* * test.h */ @@ -687,7 +671,6 @@ class test { }; #endif /* TEST_H_ */ - //= /* * test.h @@ -703,17 +686,16 @@ class test { }; #endif /* TEST_H_ */ - //!Generate Getters and Setters, Pass by Reference, Separate Definition //#org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest //@.config -filename=C.h +filename=A.h getters=name setters=name definitionSeparate=true -//@C.h -#ifndef C_H_ -#define C_H_ +//@A.h +#ifndef A_H_ +#define A_H_ struct FullName { const char* first; @@ -753,10 +735,10 @@ public: int gooo = 1; -#endif /* C_H_ */ +#endif /* A_H_ */ //= -#ifndef C_H_ -#define C_H_ +#ifndef A_H_ +#define A_H_ struct FullName { const char* first; @@ -776,9 +758,9 @@ public: const int socSecNo; Person myFriend; + const FullName& getName() const; void setName(const FullName& name); - Person(int socSecNo); // constructor ~Person(); // destructor @@ -798,9 +780,9 @@ public: int gooo = 1; -#endif /* C_H_ */ -//@C.cpp -#include "C.h" +#endif /* A_H_ */ +//@A.cpp +#include "A.h" int Person::SocSecNo() { return socSecNo; @@ -808,9 +790,8 @@ int Person::SocSecNo() { int main(int argc, char** argv) { } - //= -#include "C.h" +#include "A.h" const FullName& Person::getName() const { return name; @@ -826,48 +807,15 @@ int Person::SocSecNo() { int main(int argc, char** argv) { } - //!Generate Getters and Setters One Getter Selection with Namespace Separate Definition //#org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest //@.config -filename=C.h +filename=A.h getters=name definitionSeparate=true -//@C.cpp -#include "C.h" - -namespace Personal { - -int Person::SocSecNo() { - return socSecNo; -} - -} // namespace Personal - -int main(int argc, char** argv) { -} - -//= -#include "C.h" - -namespace Personal { - -char* Person::getName() const { - return name; -} - -int Person::SocSecNo() { - return socSecNo; -} - -} // namespace Personal - -int main(int argc, char** argv) { -} - -//@C.h -#ifndef C_H_ -#define C_H_ +//@A.h +#ifndef A_H_ +#define A_H_ namespace Personal { @@ -908,11 +856,10 @@ public: int gooo = 1; -#endif /* C_H_ */ - +#endif /* A_H_ */ //= -#ifndef C_H_ -#define C_H_ +#ifndef A_H_ +#define A_H_ namespace Personal { @@ -954,43 +901,46 @@ public: int gooo = 1; -#endif /* C_H_ */ +#endif /* A_H_ */ +//@A.cpp +#include "A.h" -//!Generate Getters and Setters One Setter Selection Separate Definition -//#org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest -//@.config -filename=C.h -setters=name -definitionSeparate=true -//@C.cpp -#include "C.h" +namespace Personal { int Person::SocSecNo() { return socSecNo; } +} // namespace Personal + int main(int argc, char** argv) { } - - //= -#include "C.h" +#include "A.h" -void Person::setName(char* name) { - this->name = name; +namespace Personal { + +char* Person::getName() const { + return name; } int Person::SocSecNo() { return socSecNo; } +} // namespace Personal + int main(int argc, char** argv) { } - - -//@C.h -#ifndef C_H_ -#define C_H_ +//!Generate Getters and Setters One Setter Selection Separate Definition +//#org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest +//@.config +filename=A.h +setters=name +definitionSeparate=true +//@A.h +#ifndef A_H_ +#define A_H_ class Person { private: @@ -1025,13 +975,12 @@ public: } }; - int gooo = 1; -#endif /* C_H_ */ +#endif /* A_H_ */ //= -#ifndef C_H_ -#define C_H_ +#ifndef A_H_ +#define A_H_ class Person { private: @@ -1067,19 +1016,11 @@ public: } }; - int gooo = 1; -#endif /* C_H_ */ -//!Getter and Setter Selection Separate Definition -//#org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest -//@.config -filename=C.h -setters=name -getters=name -definitionSeparate=true -//@C.cpp -#include "C.h" +#endif /* A_H_ */ +//@A.cpp +#include "A.h" int Person::SocSecNo() { return socSecNo; @@ -1087,13 +1028,8 @@ int Person::SocSecNo() { int main(int argc, char** argv) { } - //= -#include "C.h" - -char* Person::getName() const { - return name; -} +#include "A.h" void Person::setName(char* name) { this->name = name; @@ -1105,10 +1041,16 @@ int Person::SocSecNo() { int main(int argc, char** argv) { } - -//@C.h -#ifndef C_H_ -#define C_H_ +//!Getter and Setter Selection Separate Definition +//#org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest +//@.config +filename=A.h +setters=name +getters=name +definitionSeparate=true +//@A.h +#ifndef A_H_ +#define A_H_ class Person { private: @@ -1143,14 +1085,12 @@ public: } }; - int gooo = 1; -#endif /* C_H_ */ - +#endif /* A_H_ */ //= -#ifndef C_H_ -#define C_H_ +#ifndef A_H_ +#define A_H_ class Person { private: @@ -1187,32 +1127,56 @@ public: } }; - int gooo = 1; -#endif /* C_H_ */ +#endif /* A_H_ */ +//@A.cpp +#include "A.h" + +int Person::SocSecNo() { + return socSecNo; +} + +int main(int argc, char** argv) { +} +//= +#include "A.h" + +char* Person::getName() const { + return name; +} + +void Person::setName(char* name) { + this->name = name; +} + +int Person::SocSecNo() { + return socSecNo; +} +int main(int argc, char** argv) { +} //!Generate Getters and Setters no Methods Separate Definition //#org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest //@.config -filename=C.h +filename=A.h getters=id setters=id definitionSeparate=true -//@C.h -#ifndef C_H_ -#define C_H_ +//@A.h +#ifndef A_H_ +#define A_H_ class Person { private: int /*$*/id/*$$*/; }; -#endif /* C_H_ */ +#endif /* A_H_ */ //= -#ifndef C_H_ -#define C_H_ +#ifndef A_H_ +#define A_H_ class Person { private: @@ -1232,16 +1196,16 @@ inline void Person::setId(int id) { } -#endif /* C_H_ */ +#endif /* A_H_ */ //!No Methods Separate Definition //#org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest //@.config -filename=C.h +filename=A.h getters=i setters=i definitionSeparate=true -//@C.h +//@A.h /* * test.h */ @@ -1257,7 +1221,6 @@ class test { }; #endif /* TEST_H_ */ - //= /* * test.h @@ -1287,7 +1250,6 @@ inline void test::setI(int i) { #endif /* TEST_H_ */ - //!Bug 323780 "Generate Getters and Setters..." crashes //#org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest //@.config @@ -1337,7 +1299,6 @@ void Test::foo() { } } - //= #include "Test.h" @@ -1355,7 +1316,6 @@ void Test::foo() { } } - //!Bug 337040 - Insert definition in empty implementation file (.cxx) //#org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest //@.config @@ -1445,3 +1405,49 @@ void Test::setTestField(int testField) { //@component_a/implementation/Test.cpp //= + +//!Bug 363244 - Generate Getters and Setters for class with macro +//#org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest +//@.config +filename=A.h +getters=test +//@A.h +#ifndef A_H_ +#define A_H_ + +#define Typedef \ + typedef int Int + +class Test +{ +public: + Typedef; + + void Foo(); + Test(); + + int /*$*/test/*$$*/; +}; +#endif /* A_H_ */ +//= +#ifndef A_H_ +#define A_H_ + +#define Typedef \ + typedef int Int + +class Test +{ +public: + Typedef; + + void Foo(); + Test(); + + int getTest() const { + return test; + } + + int test; +}; +#endif /* A_H_ */ diff --git a/core/org.eclipse.cdt.ui.tests/resources/refactoring/HideMethod.rts b/core/org.eclipse.cdt.ui.tests/resources/refactoring/HideMethod.rts index 4184e0be140..9329f5d7ded 100644 --- a/core/org.eclipse.cdt.ui.tests/resources/refactoring/HideMethod.rts +++ b/core/org.eclipse.cdt.ui.tests/resources/refactoring/HideMethod.rts @@ -19,7 +19,6 @@ private: }; #endif /*A_H_*/ - //= #ifndef A_H_ #define A_H_ @@ -33,11 +32,11 @@ public: private: int i; + void method2(); }; #endif /*A_H_*/ - //!HideMethodLineComment //#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest //@.config @@ -60,7 +59,6 @@ private: }; #endif /*A_H_*/ - //= #ifndef A_H_ #define A_H_ @@ -74,12 +72,12 @@ public: private: int i; + //Comment void method2(); }; #endif /*A_H_*/ - //!HideMethodBlockComment //#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest //@.config @@ -102,7 +100,6 @@ private: }; #endif /*A_H_*/ - //= #ifndef A_H_ #define A_H_ @@ -116,12 +113,12 @@ public: private: int i; + /*Comment*/ void method2(); }; #endif /*A_H_*/ - //!HideMethodLineCommentBehind //#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest //@.config @@ -143,7 +140,6 @@ private: }; #endif /*A_H_*/ - //= #ifndef A_H_ #define A_H_ @@ -157,11 +153,11 @@ public: private: int i; + void method2(); //Comment }; #endif /*A_H_*/ - //!HideMethodBlockCommentBehind //#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest //@.config @@ -183,7 +179,6 @@ private: }; #endif /*A_H_*/ - //= #ifndef A_H_ #define A_H_ @@ -197,11 +192,11 @@ public: private: int i; + void method2(); /*Comment*/ }; #endif /*A_H_*/ - //!HideMethodLineCommentWithSpace //#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest //@.config @@ -225,7 +220,6 @@ private: }; #endif /*A_H_*/ - //= #ifndef A_H_ #define A_H_ @@ -239,12 +233,12 @@ public: private: int i; + //Comment void method2(); }; #endif /*A_H_*/ - //!HideMethodBlockCommentWithSpace //#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest //@.config @@ -268,7 +262,6 @@ private: }; #endif /*A_H_*/ - //= #ifndef A_H_ #define A_H_ @@ -282,12 +275,12 @@ public: private: int i; + /*Comment*/ void method2(); }; #endif /*A_H_*/ - //!HideMethodLineCommentWithSpaceBehind //#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest //@.config @@ -309,7 +302,6 @@ private: }; #endif /*A_H_*/ - //= #ifndef A_H_ #define A_H_ @@ -323,11 +315,11 @@ public: private: int i; + void method2(); //Comment }; #endif /*A_H_*/ - //!HideMethodBlockCommentWithSpaceBehind //#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest //@.config @@ -349,7 +341,6 @@ private: int i; }; #endif /*A_H_*/ - //= #ifndef A_H_ #define A_H_ @@ -363,10 +354,10 @@ public: private: int i; + void method2(); /*Comment*/ }; #endif /*A_H_*/ - //!HideMethodBigBlockComment //#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest //@.config @@ -390,7 +381,6 @@ private: int i; }; #endif /*A_H_*/ - //= #ifndef A_H_ #define A_H_ @@ -404,13 +394,13 @@ public: private: int i; + /* * Comment */ void method2(); }; #endif /*A_H_*/ - //!HideMethodBigBlockCommentBehind //#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest //@.config @@ -434,7 +424,6 @@ private: }; #endif /*A_H_*/ - //= #ifndef A_H_ #define A_H_ @@ -448,13 +437,13 @@ public: private: int i; + void method2(); /* * Comment */ }; #endif /*A_H_*/ - //!HideMethodBigBlockCommentBeforeAndBehind //#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest //@.config @@ -481,7 +470,6 @@ private: }; #endif /*A_H_*/ - //= #ifndef A_H_ #define A_H_ @@ -495,6 +483,7 @@ public: private: int i; + /* * Davor */ @@ -504,7 +493,6 @@ private: }; #endif /*A_H_*/ - //!HideMethodMixedCommentBeforeAndAfter //#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest //@.config @@ -527,7 +515,6 @@ private: }; #endif /*A_H_*/ - //= #ifndef A_H_ #define A_H_ @@ -541,12 +528,12 @@ public: private: int i; + /*123*/ void method2(); //TEST }; #endif /*A_H_*/ - //!HideMethodBlockCommentBeforeAndBehind //#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest //@.config @@ -568,7 +555,6 @@ private: int i; }; #endif /*A_H_*/ - //= #ifndef A_H_ #define A_H_ @@ -582,11 +568,11 @@ public: private: int i; + /*123*/ void method2(); /*TEST*/ }; #endif /*A_H_*/ - //!HideMethodNoChange //#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest //@.config @@ -604,7 +590,6 @@ private: }; #endif /*A_H_*/ - //= #ifndef A_H_ #define A_H_ @@ -617,7 +602,6 @@ private: }; #endif /*A_H_*/ - //!HideMethod2MethodsDifferentLine //#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest //@.config @@ -635,7 +619,6 @@ public: }; #endif /*A_H_*/ - //= #ifndef A_H_ #define A_H_ @@ -651,7 +634,6 @@ private: }; #endif /*A_H_*/ - //!HideMethod2MethodsSameLine //#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest //@.config @@ -668,7 +650,6 @@ public: }; #endif /*A_H_*/ - //= #ifndef A_H_ #define A_H_ @@ -684,7 +665,6 @@ private: }; #endif /*A_H_*/ - //!HideMethod2MethodsDifferentLineWithComment //#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest //@.config @@ -703,7 +683,6 @@ public: }; #endif /*A_H_*/ - //= #ifndef A_H_ #define A_H_ @@ -720,7 +699,6 @@ private: }; #endif /*A_H_*/ - //!HideMethod2MethodsSameLineWithComment //#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest //@.config @@ -738,7 +716,6 @@ public: }; #endif /*A_H_*/ - //= #ifndef A_H_ #define A_H_ @@ -755,7 +732,6 @@ private: }; #endif /*A_H_*/ - //!HideMethodSimple ImplementationFile //#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest //@A.h @@ -775,7 +751,6 @@ private: }; #endif /*A_H_*/ - //= #ifndef A_H_ #define A_H_ @@ -789,18 +764,17 @@ public: private: int i; + void method2(); }; #endif /*A_H_*/ - //@A.cpp #include "A.h" void A::/*$*/method2/*$$*/() { } - //!HideMethodSimple ImplementationFile with Comments BUG #60 //#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest //@A.h @@ -821,7 +795,6 @@ private: }; #endif /*A_H_*/ - //= #ifndef A_H_ #define A_H_ @@ -835,12 +808,12 @@ public: private: int i; + //TEST 1 void method2(); //TEST 2 }; #endif /*A_H_*/ - //@A.cpp #include "A.h" @@ -848,7 +821,7 @@ void A::/*$*/method2/*$$*/() { } -//!HideMethod with References 1 +//!HideMethod with references 1 //#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest //@.config filename=HideMethod.h @@ -860,14 +833,14 @@ class HideMethod { public: HideMethod(); virtual ~HideMethod(); - void /*$*/methode2/*$$*/(); - void methode3() { - methode2(); + void /*$*/method2/*$$*/(); + + void method3() { + method2(); } }; #endif /* HIDEMETHOD_H_ */ - //= #ifndef HIDEMETHOD_H_ #define HIDEMETHOD_H_ @@ -876,17 +849,17 @@ class HideMethod { public: HideMethod(); virtual ~HideMethod(); - void methode3() { - methode2(); + + void method3() { + method2(); } private: - void methode2(); + void method2(); }; #endif /* HIDEMETHOD_H_ */ - -//!HideMethod with References 2 +//!HideMethod with references 2 //#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest //@.config filename=HideMethod.h @@ -898,12 +871,11 @@ class HideMethod { public: HideMethod(); virtual ~HideMethod(); - void /*$*/methode2/*$$*/(); - void methode3(); + void /*$*/method2/*$$*/(); + void method3(); }; #endif /* HIDEMETHOD_H_ */ - //= #ifndef HIDEMETHOD_H_ #define HIDEMETHOD_H_ @@ -912,14 +884,13 @@ class HideMethod { public: HideMethod(); virtual ~HideMethod(); - void methode3(); + void method3(); private: - void methode2(); + void method2(); }; #endif /* HIDEMETHOD_H_ */ - //@HideMethod.cpp #include "HideMethod.h" @@ -931,15 +902,13 @@ HideMethod::~HideMethod() { // TODO Auto-generated destructor stub } -void HideMethod::methode2() { +void HideMethod::method2() { //do nothing } -void HideMethod::methode3() -{ - methode2(); +void HideMethod::method3() { + method2(); } - //= #include "HideMethod.h" @@ -951,16 +920,14 @@ HideMethod::~HideMethod() { // TODO Auto-generated destructor stub } -void HideMethod::methode2() { +void HideMethod::method2() { //do nothing } -void HideMethod::methode3() -{ - methode2(); +void HideMethod::method3() { + method2(); } - -//!HideMethod with References 3 +//!HideMethod with references 3 //#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest //@.config filename=HideMethod.h @@ -973,20 +940,19 @@ class HideMethod { public: HideMethod(); virtual ~HideMethod(); - void /*$*/methode2/*$$*/(); - void methode3(); + void /*$*/method2/*$$*/(); + void method3(); }; class test{ public: void call() { HideMethod hm; - hm.methode2(); + hm.method2(); } }; #endif /* HIDEMETHOD_H_ */ - //= #ifndef HIDEMETHOD_H_ #define HIDEMETHOD_H_ @@ -995,23 +961,22 @@ class HideMethod { public: HideMethod(); virtual ~HideMethod(); - void methode3(); + void method3(); private: - void methode2(); + void method2(); }; class test{ public: void call() { HideMethod hm; - hm.methode2(); + hm.method2(); } }; #endif /* HIDEMETHOD_H_ */ - -//!HideMethod with References 4 +//!HideMethod with references 4 //#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest //@.config filename=HideMethod.h @@ -1024,12 +989,11 @@ class HideMethod { public: HideMethod(); virtual ~HideMethod(); - void /*$*/methode2/*$$*/(); - void methode3(); + void /*$*/method2/*$$*/(); + void method3(); }; #endif /* HIDEMETHOD_H_ */ - //= #ifndef HIDEMETHOD_H_ #define HIDEMETHOD_H_ @@ -1038,14 +1002,13 @@ class HideMethod { public: HideMethod(); virtual ~HideMethod(); - void methode3(); + void method3(); private: - void methode2(); + void method2(); }; #endif /* HIDEMETHOD_H_ */ - //@HideMethod.cpp #include "HideMethod.h" @@ -1058,19 +1021,18 @@ HideMethod::~HideMethod() { // TODO Auto-generated destructor stub } -void HideMethod::methode2() { +void HideMethod::method2() { //do nothing } -void HideMethod::methode3() { +void HideMethod::method3() { //do nothing } int main() { HideMethod hm; - hm.methode2(); + hm.method2(); } - //= //@HideMethod.cpp #include "HideMethod.h" @@ -1084,20 +1046,19 @@ HideMethod::~HideMethod() { // TODO Auto-generated destructor stub } -void HideMethod::methode2() { +void HideMethod::method2() { //do nothing } -void HideMethod::methode3() { +void HideMethod::method3() { //do nothing } int main() { HideMethod hm; - hm.methode2(); + hm.method2(); } - -//!HideMethod with CPP File selection +//!HideMethod with CPP file selection //#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest //@.config filename=HideMethod.h @@ -1109,12 +1070,11 @@ class HideMethod { public: HideMethod(); virtual ~HideMethod(); - void methode2(); - void methode3(); + void method2(); + void method3(); }; #endif /* HIDEMETHOD_H_ */ - //= #ifndef HIDEMETHOD_H_ #define HIDEMETHOD_H_ @@ -1123,14 +1083,13 @@ class HideMethod { public: HideMethod(); virtual ~HideMethod(); - void methode3(); + void method3(); private: - void methode2(); + void method2(); }; #endif /* HIDEMETHOD_H_ */ - //@HideMethod.cpp #include "HideMethod.h" @@ -1142,15 +1101,13 @@ HideMethod::~HideMethod() { // TODO Auto-generated destructor stub } -void HideMethod::/*$*/methode2/*$$*/() { +void HideMethod::/*$*/method2/*$$*/() { //do nothing } -void HideMethod::methode3() -{ - methode2(); +void HideMethod::method3() { + method2(); } - //= #include "HideMethod.h" @@ -1162,15 +1119,13 @@ HideMethod::~HideMethod() { // TODO Auto-generated destructor stub } -void HideMethod::methode2() { +void HideMethod::method2() { //do nothing } -void HideMethod::methode3() -{ - methode2(); +void HideMethod::method3() { + method2(); } - //!HideMethodChangeToDefaultVisibility Class1 //#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest //@.config @@ -1187,7 +1142,6 @@ public: }; #endif /*A_H_*/ - //= #ifndef A_H_ #define A_H_ @@ -1196,12 +1150,12 @@ public: class A { public: + private: void method2(); }; #endif /*A_H_*/ - //!HideMethodChangeToDefaultVisibility Class2 //#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest //@.config @@ -1246,7 +1200,6 @@ struct A { }; #endif /*A_H_*/ - //= #ifndef A_H_ #define A_H_ @@ -1259,7 +1212,6 @@ private: }; #endif /*A_H_*/ - //!HideMethod CheckIfPrivateBug 1 //#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest //@.config @@ -1354,7 +1306,9 @@ public: //= struct other { private: - bool value() { return true; } + bool value() { + return true; + } }; class Class { @@ -1397,7 +1351,6 @@ public: } private: - void test() { other o; this->set(o.value()); @@ -1435,15 +1388,14 @@ public: private: void just_private(); }; - //= class Class { public: + private: void just_private(); void to_move(); }; - //!HideMethod several private sections //#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest //@.config @@ -1458,14 +1410,13 @@ private: private: }; - //= class Class { public: + private: void just_private(); void to_move(); private: }; - diff --git a/core/org.eclipse.cdt.ui.tests/resources/refactoring/HideMethodHistory.rts b/core/org.eclipse.cdt.ui.tests/resources/refactoring/HideMethodHistory.rts index de72504e590..35d7d9cbcf9 100644 --- a/core/org.eclipse.cdt.ui.tests/resources/refactoring/HideMethodHistory.rts +++ b/core/org.eclipse.cdt.ui.tests/resources/refactoring/HideMethodHistory.rts @@ -17,7 +17,6 @@ private: }; #endif /*A_H_*/ - //= #ifndef A_H_ #define A_H_ @@ -31,11 +30,11 @@ public: private: int i; + void method2(); }; #endif /*A_H_*/ - //@refScript.xml <?xml version="1.0" encoding="UTF-8"?> <session version="1.0"> diff --git a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ImplementMethod.rts b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ImplementMethod.rts index c2d1a0d3a9e..df5711bf73b 100644 --- a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ImplementMethod.rts +++ b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ImplementMethod.rts @@ -182,7 +182,6 @@ public: }; } - //@A.cpp #include "A.h" diff --git a/core/org.eclipse.cdt.ui.tests/resources/refactoring/NewCreationTest.rts b/core/org.eclipse.cdt.ui.tests/resources/refactoring/NewCreationTest.rts index 61c750b2d60..4ac721ac2a1 100644 --- a/core/org.eclipse.cdt.ui.tests/resources/refactoring/NewCreationTest.rts +++ b/core/org.eclipse.cdt.ui.tests/resources/refactoring/NewCreationTest.rts @@ -1,4 +1,4 @@ -//!FreefunctionFromHeaderToImpl +//!FreeFunctionFromHeaderToImpl //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //@.config filename=A.h @@ -20,7 +20,7 @@ void freefunction(); void freefunction() { return; } -//!FreefunctionFromImplToHeader +//!FreeFunctionFromImplToHeader //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //@.config filename=A.cpp diff --git a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleCommentsClassToHeader.rts b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleCommentsClassToHeader.rts index 61351a117fc..30546140280 100644 --- a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleCommentsClassToHeader.rts +++ b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleCommentsClassToHeader.rts @@ -107,7 +107,6 @@ class A { // Top comment template<typename T> T member(); - }; // Top comment diff --git a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleCommentsHeaderToClass.rts b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleCommentsHeaderToClass.rts index 61c768a4c0b..70d269f1b47 100644 --- a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleCommentsHeaderToClass.rts +++ b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleCommentsHeaderToClass.rts @@ -21,8 +21,6 @@ class A { return T(); } }; - - //!HeaderToClassRetainTopComments //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //@.config @@ -44,18 +42,14 @@ inline T A<T>::member() { //= template<typename T> class A { - // Third comment - // Fourth comment // First comment // Second comment + // Third comment + // Fourth comment T member() { return T(); } }; - - - - //!HeaderToClassTryCatchComment //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //@.config @@ -93,8 +87,6 @@ class A { // Catch 2 } }; - - //!HeaderToClassMultiTemplateComment //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //@.config @@ -123,11 +115,7 @@ class A { // body comment return T(); } - }; - -// 2nd Top Comment - //!HeaderToClassBodyComment //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //@.config @@ -151,6 +139,3 @@ class A { return T(); } }; - - - diff --git a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleCommentsHeaderToImpl.rts b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleCommentsHeaderToImpl.rts index 7ac828d6e94..95ac67e6d36 100644 --- a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleCommentsHeaderToImpl.rts +++ b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleCommentsHeaderToImpl.rts @@ -15,8 +15,6 @@ inline void A::member() { class A { void member(); }; - - //@A.cpp #include "A.h" //= @@ -44,8 +42,6 @@ catch /*3*/ (int e) { /*4*/ } class A { void member(); }; - - //@A.cpp #include "A.h" //= @@ -80,9 +76,6 @@ inline void A::member() { class A { void member(); }; - - - //@A.cpp #include "A.h" //= @@ -105,10 +98,8 @@ void /*$*/member/*$$*/() { //= // Definition comment void member(); - //@A.cpp #include "A.h" - //= #include "A.h" diff --git a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleCommentsImplToHeader.rts b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleCommentsImplToHeader.rts index 62f1a398f6e..628d3debd6b 100644 --- a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleCommentsImplToHeader.rts +++ b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleCommentsImplToHeader.rts @@ -11,8 +11,6 @@ void A::/*$*/member/*$$*/() { } //= #include "A.h" - - //@A.h class A { void member(); @@ -37,9 +35,6 @@ void A::/*$*/member/*$$*/() { } //= #include "A.h" - -// Definition comment - //@A.h class A { void member(); @@ -64,9 +59,6 @@ void A::/*$*/member/*$$*/() try { } /*1*/ catch (int e) { /*2*/ } /*3*/ catch (int e) { /*4*/ } //= #include "A.h" - -// Definition comment - //@A.h class A { void member(); @@ -98,8 +90,6 @@ void /*$*/member/*$$*/() { } //= #include "A.h" - - //@A.h //= @@ -122,9 +112,6 @@ void /*$*/member/*$$*/() { } //= #include "A.h" - -// Top comment - //@A.h //= diff --git a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleCtorDtorRefactoring.rts b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleCtorDtorRefactoring.rts index 04ec07acf62..ffef1312d81 100644 --- a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleCtorDtorRefactoring.rts +++ b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleCtorDtorRefactoring.rts @@ -69,8 +69,6 @@ public: ~A() { } }; - - //@A.cpp #include "A.h" @@ -105,8 +103,6 @@ int main() { //= #include "A.h" - - int main() { return 0; } @@ -188,8 +184,6 @@ private: public: ~A(); }; - - //@A.cpp #include "A.h" @@ -225,8 +219,6 @@ int main() { //= #include "A.h" - - int main() { return 0; } diff --git a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleDefaultParameterRefactoring.rts b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleDefaultParameterRefactoring.rts index d1d2fa2b715..7a1eeb54057 100644 --- a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleDefaultParameterRefactoring.rts +++ b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleDefaultParameterRefactoring.rts @@ -41,8 +41,6 @@ inline void /*$*/A::member/*$$*/(int a, int b) { class A { void member(int a = 0, int b = 0); }; - - //@A.cpp #include "A.h" @@ -77,8 +75,6 @@ int main() { //= #include "A.h" - - int main() { return 0; } diff --git a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleDifferentSelections.rts b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleDifferentSelections.rts index 535e98acf15..a08d9a0453a 100644 --- a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleDifferentSelections.rts +++ b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleDifferentSelections.rts @@ -18,8 +18,6 @@ void N::A::/*$*/foo/*$$*/() { int main() { return 0; } - - //@A.h #include <iostream> #include <exception> @@ -90,5 +88,3 @@ void N::A::foo() { int main() { return 0; } - - diff --git a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleFreeFunction.rts b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleFreeFunction.rts index 57cf41340c6..7000fe3ac22 100644 --- a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleFreeFunction.rts +++ b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleFreeFunction.rts @@ -38,7 +38,6 @@ public: }; int freeFunction(int* a, int& b); - //@A.cpp #include "A.h" @@ -76,8 +75,6 @@ int /*$*/freeFunction/*$$*/(int* a, int& b) { int main() { return 0; } - - //@A.h #include <iostream> @@ -114,7 +111,6 @@ public: int freeFunction(int* a, int& b) { return 42; } - //!TestFreeFunctionToggleFromImplementationToHeaderWithOutDeclaration //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //@.config @@ -132,14 +128,13 @@ try { } catch (std::exception& e) { } + //= #include "A.h" int main() { return 0; } - - //@A.h #include <iostream> @@ -155,7 +150,6 @@ public: ~A() { } }; - //= #include <iostream> @@ -179,7 +173,6 @@ try { catch (std::exception& e) { } - //!TestFreeFunction //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //@.config @@ -190,7 +183,6 @@ int /*$*/freeFunction/*$$*/() { } //= int freeFunction(); - //@A.cpp #include "A.h" //= diff --git a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleNamespaceRefactoring.rts b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleNamespaceRefactoring.rts index 598bf314c06..e002c3cffde 100644 --- a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleNamespaceRefactoring.rts +++ b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleNamespaceRefactoring.rts @@ -132,6 +132,7 @@ namespace N { void A::foo() { return; } + } //!TestSimpleNamespaceInHeaderToImplementationWithNamespaceQualifiedName //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest @@ -163,8 +164,6 @@ class A { }; } - - //@A.cpp #include "A.h" @@ -203,8 +202,6 @@ int main() { //= #include "A.h" - - int main() { return 0; } @@ -246,8 +243,6 @@ void /*$*/A::foo/*$$*/() { } //= #include "A.h" - - //@A.h #include <iostream> diff --git a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleNestedRefactoring.rts b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleNestedRefactoring.rts index d73288018e8..3e53d81da6d 100644 --- a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleNestedRefactoring.rts +++ b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleNestedRefactoring.rts @@ -49,8 +49,6 @@ class A { void member(int a, int b); }; }; - - //@A.cpp #include "A.h" @@ -88,8 +86,6 @@ void A::B::/*$*/member/*$$*/(int a, int b) { int main() { return 0; } - - //@A.h #include <iostream> diff --git a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleOrdering.rts b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleOrdering.rts index 6c1ccc5b5f9..2622b732712 100644 --- a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleOrdering.rts +++ b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleOrdering.rts @@ -59,7 +59,6 @@ public: inline void A::/*$*/func2/*$$*/() { return; } - //= #include <iostream> @@ -71,9 +70,6 @@ public: void func4() { } }; - - - //@A.cpp #include "A.h" @@ -201,8 +197,6 @@ template<typename T> inline void A<T>::func1() { } - - template<typename T> inline void A<T>::func3() { } diff --git a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleSimpleFunctionRefactoring.rts b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleSimpleFunctionRefactoring.rts index b92b03b8a8a..aaec086264d 100644 --- a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleSimpleFunctionRefactoring.rts +++ b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleSimpleFunctionRefactoring.rts @@ -57,8 +57,6 @@ public: private: int a; }; - - //@A.cpp #include "A.h" @@ -93,8 +91,6 @@ int main() { //= #include "A.h" - - int main() { return 0; } @@ -137,8 +133,6 @@ int main() { //= #include "MyClass.h" - - int main() { return 0; } @@ -175,24 +169,18 @@ int main() { //= #include "MyClass.h" - - int main() { return 0; } //@MyClass.h - struct myClass { int fVal; myClass(int); }; - //= - struct myClass { int fVal; myClass(int implname) : fVal(implname) { } }; - diff --git a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleTemplateRefactoring.rts b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleTemplateRefactoring.rts index 19c4330b515..af12e2930d3 100644 --- a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleTemplateRefactoring.rts +++ b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleTemplateRefactoring.rts @@ -57,8 +57,6 @@ class A { } }; }; - - //!TestTemplateFunctionInHeaderToInClassWithTemplateSelected //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //@.config @@ -74,7 +72,6 @@ class A { class A { template<typename T> T foo(); - }; template<typename T> @@ -101,7 +98,6 @@ class A { public: template<typename U, typename V> void foo(const U& u, const V& v); - }; template<typename T, typename S> @@ -135,7 +131,4 @@ public: void foo(const U& u, const V& v) { return; } - }; - - diff --git a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleTryCatchRefactoring.rts b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleTryCatchRefactoring.rts index 30a83009e4b..d5777071018 100644 --- a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleTryCatchRefactoring.rts +++ b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleTryCatchRefactoring.rts @@ -57,8 +57,6 @@ catch (std::exception& e1) { class A { void member(int a, int b); }; - - //@A.cpp #include "A.h" @@ -103,8 +101,6 @@ int main() { #include <exception> #include "A.h" - - int main() { return 0; } @@ -194,8 +190,6 @@ catch (std::exception& e2) { class A { void member(int a, int b); }; - - //@A.cpp #include "A.h" @@ -246,8 +240,6 @@ int main() { #include <exception> #include "A.h" - - int main() { return 0; } diff --git a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleVirtualFunction.rts b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleVirtualFunction.rts index 8a51d64b8c7..a0af0150b1b 100644 --- a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleVirtualFunction.rts +++ b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleVirtualFunction.rts @@ -25,7 +25,6 @@ inline int A::foo() { //@.config filename=A.h //@A.h - class A { virtual int /*$*/foo/*$$*/(); }; @@ -34,12 +33,9 @@ inline int A::foo() { return 0; } //= - class A { virtual int foo(); }; - - //@A.cpp #include "A.h" @@ -62,12 +58,10 @@ int A::foo() { //@.config filename=A.h //@A.h - class A { virtual int /*$*/foo/*$$*/(); }; //= - class A { virtual int foo() { return 0; @@ -89,5 +83,3 @@ int A::foo() { int main() { return 0; } - - diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java index 4eb659df105..08d5345b1cc 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java @@ -556,12 +556,12 @@ public class CodeFormatterTest extends BaseUITestCase { //} //typedef signed int TInt; - //extern void Bar(); // should not have space between parens + //extern void Bar(); // should not have space between parens // - //void Foo() // should not have space between parens + //void Foo() // should not have space between parens // { - // TInt a( 3 ); // should become TInt a( 3 ); - // Bar(); // should not have space between parens + // TInt a( 3 ); // should become TInt a( 3 ); + // Bar(); // should not have space between parens // } public void testSpaceBetweenParen_Bug217918() throws Exception { fOptions.put(DefaultCodeFormatterConstants.FORMATTER_BRACE_POSITION_FOR_METHOD_DECLARATION, @@ -893,9 +893,9 @@ public class CodeFormatterTest extends BaseUITestCase { //namespace ns1 { //namespace ns2 { //void foo() { - // int x; // comment - // int y; // comment - // // continuation of the previous comment + // int x;// comment + // int y;// comment + // // continuation of the previous comment //// int z; <- comments starting from the beginning of line are not indented //} //}// namespace ns2 @@ -914,6 +914,7 @@ public class CodeFormatterTest extends BaseUITestCase { public void testLineCommentMinDistanceFromCode() throws Exception { fOptions.put(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, CCorePlugin.SPACE); fOptions.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_MIN_DISTANCE_BETWEEN_CODE_AND_LINE_COMMENT, "2"); + fOptions.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_PRESERVE_WHITE_SPACE_BETWEEN_CODE_AND_LINE_COMMENT, DefaultCodeFormatterConstants.FALSE); assertFormatterResult(); } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/SourceHeaderPartnerFinder.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/SourceHeaderPartnerFinder.java index c544dae4386..1bac52aad40 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/SourceHeaderPartnerFinder.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/SourceHeaderPartnerFinder.java @@ -77,6 +77,7 @@ public final class SourceHeaderPartnerFinder { private static class PartnerFileComputer implements ASTRunnable { PartnerFileVisitor fVisitor = null; + @Override public IStatus runOnAST(ILanguage lang, IASTTranslationUnit ast) { if (ast != null && ast.getIndex() != null) { fVisitor = new PartnerFileVisitor(); @@ -86,7 +87,7 @@ public final class SourceHeaderPartnerFinder { } public IPath getPartnerFileLocation() { - if(fVisitor != null) { + if (fVisitor != null) { return fVisitor.getPartnerFileLocation(); } @@ -120,6 +121,7 @@ public final class SourceHeaderPartnerFinder { shouldVisitDeclarators= true; shouldVisitTranslationUnit = true; } + public PartnerFileVisitor() { fMap= new HashMap<IPath, Counter>(); } @@ -127,7 +129,7 @@ public final class SourceHeaderPartnerFinder { @Override public int visit(IASTTranslationUnit tu) { fIndex= tu.getIndex(); - if(fIndex == null) { + if (fIndex == null) { return PROCESS_ABORT; } @@ -212,6 +214,7 @@ public final class SourceHeaderPartnerFinder { private static IFile findInContainer(IContainer container, final String basename) { final IFile[] result= { null }; IResourceProxyVisitor visitor= new IResourceProxyVisitor() { + @Override public boolean visit(IResourceProxy proxy) throws CoreException { if (result[0] != null) { return false; @@ -227,8 +230,8 @@ public final class SourceHeaderPartnerFinder { }}; try { container.accept(visitor, 0); - } catch (CoreException exc) { - // ignore + } catch (CoreException e) { + // Ignore } return result[0]; } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/AddDeclarationNodeToClassChange.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/AddDeclarationNodeToClassChange.java index 7160e69321b..0fa86ca0b49 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/AddDeclarationNodeToClassChange.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/AddDeclarationNodeToClassChange.java @@ -38,7 +38,7 @@ import org.eclipse.cdt.internal.ui.refactoring.utils.VisibilityEnum; * @author Mirko Stocker */ public class AddDeclarationNodeToClassChange { - private final ICPPASTCompositeTypeSpecifier nodeClass; + private final ICPPASTCompositeTypeSpecifier classNode; private final VisibilityEnum visibility; private List<IASTNode> fieldNodes = new ArrayList<IASTNode>(); private final ModificationCollector collector; @@ -49,26 +49,26 @@ public class AddDeclarationNodeToClassChange { new AddDeclarationNodeToClassChange(nodeClass, visibility, fieldNodes, collector, isField); } - public static void createChange(ICPPASTCompositeTypeSpecifier nodeClass, + public static void createChange(ICPPASTCompositeTypeSpecifier classNode, VisibilityEnum visibility, List<IASTNode> fieldNodes, boolean isField, ModificationCollector collector) { - new AddDeclarationNodeToClassChange(nodeClass, visibility, fieldNodes, collector, isField); + new AddDeclarationNodeToClassChange(classNode, visibility, fieldNodes, collector, isField); } - private AddDeclarationNodeToClassChange(ICPPASTCompositeTypeSpecifier nodeClass, + private AddDeclarationNodeToClassChange(ICPPASTCompositeTypeSpecifier classNode, VisibilityEnum visibility, List<IASTNode> fieldNodes, ModificationCollector collector, boolean isField) { this.fieldNodes = fieldNodes; - this.nodeClass = nodeClass; + this.classNode = classNode; this.visibility = visibility; this.collector = collector; createRewrites(isField); } - private AddDeclarationNodeToClassChange(ICPPASTCompositeTypeSpecifier nodeClass, + private AddDeclarationNodeToClassChange(ICPPASTCompositeTypeSpecifier classNode, VisibilityEnum visibility, IASTNode fieldNodes, ModificationCollector collector, boolean isField) { - this.nodeClass = nodeClass; + this.classNode = classNode; this.visibility = visibility; this.fieldNodes.add(fieldNodes); this.collector = collector; @@ -78,12 +78,10 @@ public class AddDeclarationNodeToClassChange { private void createRewrites(boolean isField) { int lastFunctionDeclaration = -1; int lastFieldDeclaration = -1; - IASTDeclaration[] members = nodeClass.getMembers(); + IASTDeclaration[] members = classNode.getMembers(); - VisibilityEnum currentVisibility = VisibilityEnum.v_private; - if (IASTCompositeTypeSpecifier.k_struct == nodeClass.getKey()) { - currentVisibility = VisibilityEnum.v_public; - } + VisibilityEnum currentVisibility = classNode.getKey() == IASTCompositeTypeSpecifier.k_struct ? + VisibilityEnum.v_public : VisibilityEnum.v_private; // Find the insert location by iterating over the elements of the class // and remembering the last element with the matching visibility @@ -92,18 +90,13 @@ public class AddDeclarationNodeToClassChange { if (declaration instanceof ICPPASTVisibilityLabel) { currentVisibility = VisibilityEnum.from((ICPPASTVisibilityLabel) declaration); - } - - if (declaration instanceof IASTSimpleDeclaration) { + } else if (declaration instanceof IASTSimpleDeclaration && currentVisibility.equals(visibility)) { IASTSimpleDeclaration simple = (IASTSimpleDeclaration) declaration; IASTDeclarator[] declarators = simple.getDeclarators(); - if (declarators.length > 0 && declarators[0] != null && - declarators[0] instanceof IASTFunctionDeclarator) { - if (currentVisibility.equals(visibility)) { + if (declarators.length > 0 && declarators[0] != null) { + if (declarators[0] instanceof IASTFunctionDeclarator) { lastFunctionDeclaration = i; - } - } else if (declarators.length > 0 && declarators[0] != null) { - if (currentVisibility.equals(visibility)) { + } else { lastFieldDeclaration = i; } } @@ -142,29 +135,29 @@ public class AddDeclarationNodeToClassChange { } } - private void insertBefore(IASTNode nearestNode) { - ASTRewrite rewrite = collector.rewriterForTranslationUnit(nearestNode.getTranslationUnit()); + private void insertBefore(IASTNode nextNode) { + ASTRewrite rewrite = collector.rewriterForTranslationUnit(nextNode.getTranslationUnit()); for (IASTNode node : fieldNodes) { - rewrite.insertBefore(nearestNode.getParent(), nearestNode, node, createEditDescription()); + rewrite.insertBefore(nextNode.getParent(), nextNode, node, createEditDescription()); } } private void insertAtTheEnd(VisibilityEnum currentVisibility) { - ASTRewrite rewrite = collector.rewriterForTranslationUnit(nodeClass.getTranslationUnit()); + ASTRewrite rewrite = collector.rewriterForTranslationUnit(classNode.getTranslationUnit()); if (!currentVisibility.equals(visibility)) { ICPPASTVisibilityLabel label = new CPPASTVisibilityLabel(visibility.getICPPASTVisiblityLabelVisibility()); - rewrite.insertBefore(nodeClass, null, label, createEditDescription()); + rewrite.insertBefore(classNode, null, label, createEditDescription()); } for (IASTNode node : fieldNodes) { - rewrite.insertBefore(nodeClass, null, node, createEditDescription()); + rewrite.insertBefore(classNode, null, node, createEditDescription()); } } private TextEditGroup createEditDescription() { return new TextEditGroup(NLS.bind(Messages.AddDeclarationNodeToClassChange_AddDeclaration, - nodeClass.getName())); + classNode.getName())); } } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/togglefunction/Messages.properties b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/togglefunction/Messages.properties index e7df79b214e..d422dd488e6 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/togglefunction/Messages.properties +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/togglefunction/Messages.properties @@ -7,14 +7,14 @@ # http://www.eclipse.org/legal/epl-v10.html # # Contributors: -# Martin Schwab & Thomas Kallenberg - initial API and implementation +# Martin Schwab & Thomas Kallenberg - initial API and implementation ############################################################################### DeclaratorFinder_NestedFunction=Nested function declarations not supported -DeclaratorFinder_NoDeclarator=cannot work without declarator -DeclaratorFinder_MultipleDeclarators=cannot work with multiple declarators -RefactoringJob_UndoName=toggle function definition +DeclaratorFinder_NoDeclarator=Cannot work without declarator +DeclaratorFinder_MultipleDeclarators=Cannot work with multiple declarators +RefactoringJob_UndoName=Toggle function definition ToggleFileCreator_andMove=\ and move -ToggleFileCreator_CanNotCreateNewFile=Cannot create new filechange +ToggleFileCreator_CanNotCreateNewFile=Cannot create new file change ToggleFileCreator_CreateNewFile=Create a new file named: ToggleFileCreator_NewImplFile=New Implementation file? ToggleFileCreator_NoTuForSibling=Cannot find translation unit for sibling file @@ -22,18 +22,18 @@ ToggleFileCreator_QMark=? ToggleFromClassToInHeaderStrategy_DefAndDecInsideClass=Definition and Declaration both inside class. Behavior is undefined. ToggleFromImplementationToHeaderOrClassStrategy_CanNotCreateNewFile=Cannot create new File ToggleFromImplementationToHeaderOrClassStrategy_CanNotToggle=Not a free function. Cannot decide where to toggle -ToggleFromInHeaderToClassStrategy_CanNotToggleTemplateFreeFunction=Cannot toggle templated free function +ToggleFromInHeaderToClassStrategy_CanNotToggleTemplateFreeFunction=Cannot toggle template free function EditGroupName=Toggle function body placement ToggleFromInHeaderToImplementationStrategy_CanNotCreateImplFile=Cannot create new Implementation File ToggleRefactoring_AnalyseSelection=analyzing user text selection ToggleRefactoring_CalculateModifications=calculating required code modifications ToggleRefactoring_CanNotSaveFiles=Cannot save files ToggleRefactoring_InvalidSelection=Invalid selection -ToggleRefactoring_NoIndex=cannot work without the indexer +ToggleRefactoring_NoIndex=Cannot work without the index ToggleRefactoring_WaitingForIndexer=waiting for indexer -ToggleRefactoringContext_MultipleDeclarations=multiple declarations would result in ambiguous results -ToggleRefactoringContext_MultipleDefinitions=one-definition-rule broken -ToggleRefactoringContext_NoDefinitionFound=cannot work without definition -ToggleRefactoringContext_NoTuFound=cannot work without translation unit -ToggleStrategyFactory_NoDefinitionFound=cannot work without function definition +ToggleRefactoringContext_MultipleDeclarations=Multiple declarations would result in ambiguous results +ToggleRefactoringContext_MultipleDefinitions=One-definition-rule broken +ToggleRefactoringContext_NoDefinitionFound=Cannot work without definition +ToggleRefactoringContext_NoTuFound=Cannot work without translation unit +ToggleStrategyFactory_NoDefinitionFound=Cannot work without function definition ToggleStrategyFactory_UnsupportedSituation=Unsupported situation for moving function body. diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/togglefunction/ToggleNodeHelper.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/togglefunction/ToggleNodeHelper.java index f13fd5a7a44..bcfeee84ff8 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/togglefunction/ToggleNodeHelper.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/togglefunction/ToggleNodeHelper.java @@ -7,7 +7,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Martin Schwab & Thomas Kallenberg - initial API and implementation + * Martin Schwab & Thomas Kallenberg - initial API and implementation ******************************************************************************/ package org.eclipse.cdt.internal.ui.refactoring.togglefunction; @@ -70,7 +70,6 @@ import org.eclipse.cdt.internal.ui.refactoring.ModificationCollector; import org.eclipse.cdt.internal.ui.refactoring.utils.NodeHelper; public class ToggleNodeHelper extends NodeHelper { - private static final String EMPTY_STRING = ""; //$NON-NLS-1$ private static void removeParameterInitializations(IASTFunctionDeclarator funcDecl) { @@ -85,7 +84,7 @@ public class ToggleNodeHelper extends NodeHelper { private static ArrayList<ICPPASTConstructorChainInitializer> getInitializerList(IASTFunctionDefinition definition) { ArrayList<ICPPASTConstructorChainInitializer> initalizers = - new ArrayList<ICPPASTConstructorChainInitializer>(); + new ArrayList<ICPPASTConstructorChainInitializer>(); for (IASTNode node : definition.getChildren()) { if (node instanceof ICPPASTConstructorChainInitializer) { @@ -145,8 +144,7 @@ public class ToggleNodeHelper extends NodeHelper { IASTTranslationUnit definitionUnit, IASTNode nameSpace) { ICPPASTDeclSpecifier newDeclSpec = - (ICPPASTDeclSpecifier) oldDefinition.getDeclSpecifier().copy( - CopyStyle.withLocations); + (ICPPASTDeclSpecifier) oldDefinition.getDeclSpecifier().copy(CopyStyle.withLocations); newDeclSpec.setVirtual(false); newDeclSpec.setInline(true); @@ -157,7 +155,7 @@ public class ToggleNodeHelper extends NodeHelper { removeParameterInitializations(newDeclarator); ICPPASTFunctionDefinition newFunction = - createFunctionSignatureWithEmptyBody(newDeclSpec, newDeclarator, oldDefinition); + createFunctionSignatureWithEmptyBody(newDeclSpec, newDeclarator, oldDefinition); return newFunction; } @@ -172,7 +170,7 @@ public class ToggleNodeHelper extends NodeHelper { ArrayList<ICPPASTTemplateDeclaration> templdecs, IASTFunctionDefinition newfunc) { ListIterator<ICPPASTTemplateDeclaration> iter1 = templdecs.listIterator(); ICPPASTTemplateDeclaration child = null; - while(iter1.hasNext()) { + while (iter1.hasNext()) { child = iter1.next(); child.setDeclaration(newfunc); ListIterator<ICPPASTTemplateDeclaration> iter2 = iter1; @@ -198,10 +196,8 @@ public class ToggleNodeHelper extends NodeHelper { return templdecs; } - static IASTFunctionDefinition createInClassDefinition( - IASTFunctionDeclarator dec, - IASTFunctionDefinition def, - IASTTranslationUnit insertionunit) { + static IASTFunctionDefinition createInClassDefinition(IASTFunctionDeclarator dec, + IASTFunctionDefinition def, IASTTranslationUnit insertionunit) { IASTFunctionDeclarator declarator = dec.copy(CopyStyle.withLocations); ICPPASTDeclSpecifier declSpec = (ICPPASTDeclSpecifier) def.getDeclSpecifier().copy( CopyStyle.withLocations); @@ -232,9 +228,10 @@ public class ToggleNodeHelper extends NodeHelper { static IASTNode getParentRemovePoint(IASTFunctionDefinition definition) { IASTNode toremove = definition; - while (toremove.getParent() != null && - toremove.getParent() instanceof ICPPASTTemplateDeclaration) + while (toremove.getParent() != null && + toremove.getParent() instanceof ICPPASTTemplateDeclaration) { toremove = toremove.getParent(); + } return toremove; } @@ -252,15 +249,13 @@ public class ToggleNodeHelper extends NodeHelper { private static CPPASTQualifiedName reAssembleQualifiedName(Stack<IASTNode> nodes) { CPPASTQualifiedName qName = new CPPASTQualifiedName(); - while(!nodes.isEmpty()) { + while (!nodes.isEmpty()) { IASTNode nnode = nodes.pop(); if (nnode instanceof IASTCompositeTypeSpecifier) { qName.addName(((IASTCompositeTypeSpecifier) nnode).getName()); - } - else if (nnode instanceof ICPPASTNamespaceDefinition) { + } else if (nnode instanceof ICPPASTNamespaceDefinition) { qName.addName(((ICPPASTNamespaceDefinition) nnode).getName()); - } - else if (nnode instanceof ICPPASTTemplateId) { + } else if (nnode instanceof ICPPASTTemplateId) { qName.addName((ICPPASTTemplateId) nnode); } } @@ -271,17 +266,15 @@ public class ToggleNodeHelper extends NodeHelper { IASTFunctionDeclarator declarator, IASTNode limiter, IASTNode node) { IASTName lastName = declarator.getName(); Stack<IASTNode> nodes = new Stack<IASTNode>(); - while(node.getParent() != null && node.getParent() != limiter) { + while (node.getParent() != null && node.getParent() != limiter) { node = node.getParent(); if (node instanceof IASTCompositeTypeSpecifier) { nodes.push(((IASTCompositeTypeSpecifier) node).copy(CopyStyle.withLocations)); lastName = ((IASTCompositeTypeSpecifier) node).getName(); - } - else if (node instanceof ICPPASTNamespaceDefinition) { + } else if (node instanceof ICPPASTNamespaceDefinition) { nodes.push(((ICPPASTNamespaceDefinition) node).copy(CopyStyle.withLocations)); lastName = ((ICPPASTNamespaceDefinition) node).getName(); - } - else if (shouldAddTemplateBrackets(node)) { + } else if (shouldAddTemplateBrackets(node)) { if (!nodes.isEmpty()) nodes.pop(); ICPPASTTemplateId templateID = ToggleNodeHelper.getTemplateParameter(node, lastName); @@ -315,40 +308,48 @@ public class ToggleNodeHelper extends NodeHelper { return templateID; } - static IASTTranslationUnit getSiblingFile(IFile file, IASTTranslationUnit asttu) throws CoreException { + /** + * @deprecated Use SourceHeaderPartnerHelper + */ + @Deprecated + static IASTTranslationUnit getSiblingFile(IFile file, IASTTranslationUnit ast) throws CoreException { ICProject cProject = CoreModel.getDefault().create(file).getCProject(); ICProject[] projects = CoreModel.getDefault().getCModel().getCProjects(); IIndex projectIndex = CCorePlugin.getIndexManager().getIndex(projects); try { projectIndex.acquireReadLock(); - IIndexFile thisFile = projectIndex.getFile(asttu.getLinkage().getLinkageID(), + IIndexFile[] thisFileVariants = projectIndex.getFiles(ast.getLinkage().getLinkageID(), IndexLocationFactory.getWorkspaceIFL(file)); String fileName = ToggleNodeHelper.getFilenameWithoutExtension( file.getFullPath().toString()); - if (asttu.isHeaderUnit()) { - for (IIndexInclude include : projectIndex.findIncludedBy(thisFile)) { - if (ToggleNodeHelper.getFilenameWithoutExtension(include.getIncludedBy().getLocation().getFullPath()).equals(fileName)) { - ITranslationUnit tu = CoreModelUtil.findTranslationUnitForLocation(include.getIncludedBy().getLocation().getURI(), cProject); - return tu.getAST(projectIndex, ITranslationUnit.AST_SKIP_ALL_HEADERS); + if (ast.isHeaderUnit()) { + for (IIndexFile thisFile : thisFileVariants) { + for (IIndexInclude include : projectIndex.findIncludedBy(thisFile)) { + if (ToggleNodeHelper.getFilenameWithoutExtension(include.getIncludedBy().getLocation().getFullPath()).equals(fileName)) { + ITranslationUnit tu = CoreModelUtil.findTranslationUnitForLocation(include.getIncludedBy().getLocation().getURI(), cProject); + return tu.getAST(projectIndex, ITranslationUnit.AST_SKIP_ALL_HEADERS); + } } } } else { - for (IIndexInclude include : projectIndex.findIncludes(thisFile)) { - if (ToggleNodeHelper.getFilenameWithoutExtension(include.getFullName()).equals(fileName)) { - if (include.getIncludesLocation() == null){ - throw new NotSupportedException("The include file does not exist"); //$NON-NLS-1$ + for (IIndexFile thisFile : thisFileVariants) { + for (IIndexInclude include : projectIndex.findIncludes(thisFile)) { + if (ToggleNodeHelper.getFilenameWithoutExtension(include.getFullName()).equals(fileName)) { + if (include.getIncludesLocation() == null){ + throw new NotSupportedException("The include file does not exist"); //$NON-NLS-1$ + } + String loc = include.getIncludesLocation().getFullPath(); + ICElement tufile = CoreModel.getDefault().create(new Path(loc)); + if (tufile instanceof TranslationUnit) { + return ((TranslationUnit) tufile).getAST(null, ITranslationUnit.AST_SKIP_ALL_HEADERS); + } } - String loc = include.getIncludesLocation().getFullPath(); - ICElement tufile = CoreModel.getDefault().create(new Path(loc)); - if (tufile instanceof TranslationUnit) { - return ((TranslationUnit) tufile).getAST(null, ITranslationUnit.AST_SKIP_ALL_HEADERS); - } } } } - }catch (InterruptedException e) { - e.printStackTrace(); + } catch (InterruptedException e) { + // Ignore } finally { projectIndex.releaseReadLock(); } @@ -403,16 +404,16 @@ public class ToggleNodeHelper extends NodeHelper { ModificationCollector modifications) { String leadingComments = getCommentsAsString(getLeadingCommentsFromNode(oldDefinition.getBody(), oldUnit, modifications)); - String trailingComments = getCommentsAsString(getTrailingComments(oldDefinition.getBody(), oldUnit, - modifications)); + String trailingComments = getCommentsAsString(getTrailingComments(oldDefinition.getBody(), + oldUnit, modifications)); return leadingComments + oldDefinition.getBody().getRawSignature() + trailingComments; } private static String getCatchHandlers(IASTFunctionDefinition oldDefinition, IASTTranslationUnit oldUnit, ModificationCollector modifications) { if (oldDefinition instanceof ICPPASTFunctionWithTryBlock) { - ICPPASTCatchHandler[] oldCatches = ((ICPPASTFunctionWithTryBlock) oldDefinition) - .getCatchHandlers(); + ICPPASTCatchHandler[] oldCatches = + ((ICPPASTFunctionWithTryBlock) oldDefinition).getCatchHandlers(); String allCatchHandlers = ""; //$NON-NLS-1$ for (int i = 0; i < oldCatches.length; i++) { String lead = getCommentsAsString(getLeadingCommentsFromNode(oldCatches[i], oldUnit, @@ -437,16 +438,13 @@ public class ToggleNodeHelper extends NodeHelper { return rw.getComments(existingNode, CommentPosition.trailing); } - - public static IASTNode getParentTemplateDeclaration( - IASTNode def) { + public static IASTNode getParentTemplateDeclaration(IASTNode def) { if (def == null) return null; IASTNode lastSeen = def; IASTNode node = def.getParent(); while (node != null) { - if (node instanceof ICPPASTTemplateDeclaration || - node instanceof IASTSimpleDeclaration) { + if (node instanceof ICPPASTTemplateDeclaration || node instanceof IASTSimpleDeclaration) { lastSeen = node; node = node.getParent(); continue; @@ -466,7 +464,7 @@ public class ToggleNodeHelper extends NodeHelper { @SuppressWarnings("unchecked") public static <T> T getAncestorOfType(IASTNode node, Class<?> T) { - while(node != null) { + while (node != null) { if (T.isInstance(node)) { return (T) node; } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/togglefunction/ToggleRefactoringContext.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/togglefunction/ToggleRefactoringContext.java index a263af8246c..8db57ec62f2 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/togglefunction/ToggleRefactoringContext.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/togglefunction/ToggleRefactoringContext.java @@ -7,7 +7,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Martin Schwab & Thomas Kallenberg - initial API and implementation + * Martin Schwab & Thomas Kallenberg - initial API and implementation ******************************************************************************/ package org.eclipse.cdt.internal.ui.refactoring.togglefunction; @@ -33,7 +33,6 @@ import org.eclipse.cdt.internal.ui.refactoring.IndexToASTNameHelper; import org.eclipse.cdt.internal.ui.refactoring.utils.TranslationUnitHelper; public class ToggleRefactoringContext { - private IASTFunctionDefinition targetDefinition; private IASTFunctionDeclarator targetDeclaration; private IASTTranslationUnit targetDefinitionUnit; @@ -79,7 +78,7 @@ public class ToggleRefactoringContext { throw new NotSupportedException( Messages.ToggleRefactoringContext_MultipleDeclarations); for (IIndexName iname : decnames) { - selectionUnit = getTUForNameinFile(iname); + selectionUnit = getTUForNameInFile(iname); IASTName astname = IndexToASTNameHelper.findMatchingASTName( selectionUnit, iname, index); if (astname != null) { @@ -100,9 +99,8 @@ public class ToggleRefactoringContext { throw new NotSupportedException(Messages.ToggleRefactoringContext_MultipleDefinitions); } for (IIndexName iname : defnames) { - IASTTranslationUnit unit = getTUForNameinFile(iname); - IASTName astname = IndexToASTNameHelper.findMatchingASTName( - unit, iname, index); + IASTTranslationUnit unit = getTUForNameInFile(iname); + IASTName astname = IndexToASTNameHelper.findMatchingASTName(unit, iname, index); if (astname != null) { targetDefinition = findFunctionDefinition(astname); targetDefinitionUnit = unit; @@ -150,15 +148,14 @@ public class ToggleRefactoringContext { private void findSelectionUnit() { try { - selectionUnit = TranslationUnitHelper.loadTranslationUnit( - selectionFile, true); + selectionUnit = TranslationUnitHelper.loadTranslationUnit(selectionFile, true); } catch (Exception e) { } if (selectionUnit == null) throw new NotSupportedException(Messages.ToggleRefactoringContext_NoTuFound); } - private IASTTranslationUnit getTUForNameinFile(IIndexName iname) + private IASTTranslationUnit getTUForNameInFile(IIndexName iname) throws CModelException, CoreException { if (isSameFileAsInTU(iname)) { return selectionUnit; diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/utils/FileHelper.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/utils/FileHelper.java index f80c9d54e4f..f32fbfdfd39 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/utils/FileHelper.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/utils/FileHelper.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik + * Copyright (c) 2008, 2011 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 @@ -7,7 +7,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Institute for Software - initial API and implementation + * Institute for Software - initial API and implementation *******************************************************************************/ package org.eclipse.cdt.internal.ui.refactoring.utils; @@ -22,11 +22,10 @@ import org.eclipse.cdt.core.dom.ast.IASTNode; * Helper class concerning files. * * @author Lukas Felber - * */ public class FileHelper { - public static IFile getIFilefromIASTNode(IASTNode node) { + public static IFile getFileFromNode(IASTNode node) { IPath implPath = new Path(node.getContainingFilename()); return ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(implPath); } |
