1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Automatic formatting of code affected by refactoring.

This commit is contained in:
Sergey Prigogin 2011-11-07 11:00:43 -08:00
parent 65673a50e1
commit afb3fae823
90 changed files with 5152 additions and 5765 deletions

View file

@ -70,11 +70,12 @@ public class ASTWriterTest extends RewriteBaseTest {
} }
@Override @Override
protected void compareFiles(Map<String,TestSourceFile> testResourceFiles) throws Exception { protected void compareFiles(Map<String, TestSourceFile> testResourceFiles) throws Exception {
for (String fileName : testResourceFiles.keySet()) { for (String fileName : testResourceFiles.keySet()) {
TestSourceFile testFile = testResourceFiles.get(fileName); TestSourceFile testFile = testResourceFiles.get(fileName);
String code = generateSource(testFile); String code = generateSource(testFile);
assertEquals(TestHelper.unifyNewLines(testFile.getExpectedSource()), TestHelper.unifyNewLines(code + System.getProperty("line.separator"))); //$NON-NLS-1$ assertEquals(TestHelper.unifyNewLines(testFile.getExpectedSource()),
TestHelper.unifyNewLines(code + System.getProperty("line.separator"))); //$NON-NLS-1$
} }
} }

View file

@ -56,7 +56,7 @@ public class SourceRewriteTester extends TestSuite {
TestSuite suite = new TestSuite(name); TestSuite suite = new TestSuite(name);
Iterator<RewriteBaseTest> it = testCases.iterator(); Iterator<RewriteBaseTest> it = testCases.iterator();
while (it.hasNext()) { while (it.hasNext()) {
RewriteBaseTest subject =it.next(); RewriteBaseTest subject = it.next();
suite.addTest(subject); suite.addTest(subject);
} }
return suite; return suite;
@ -88,11 +88,11 @@ public class SourceRewriteTester extends TestSuite {
} }
private static ArrayList<RewriteBaseTest> createTests(BufferedReader inputReader) throws Exception { private static ArrayList<RewriteBaseTest> createTests(BufferedReader inputReader) throws Exception {
String line;
ASTWriterTestSourceFile file = null; ASTWriterTestSourceFile file = null;
MatcherState matcherState = MatcherState.skip; MatcherState matcherState = MatcherState.skip;
ArrayList<RewriteBaseTest> testCases = new ArrayList<RewriteBaseTest>(); ArrayList<RewriteBaseTest> testCases = new ArrayList<RewriteBaseTest>();
String line;
while ((line = inputReader.readLine()) != null) { while ((line = inputReader.readLine()) != null) {
if (lineMatchesBeginOfTest(line)) { if (lineMatchesBeginOfTest(line)) {
matcherState = MatcherState.inTest; matcherState = MatcherState.inTest;
@ -156,7 +156,7 @@ public class SourceRewriteTester extends TestSuite {
} }
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); ASTWriterTest test = new ASTWriterTest(testName, file);
TextSelection sel = file.getSelection(); TextSelection sel = file.getSelection();
if (sel != null) { if (sel != null) {
test.setFileWithSelection(file.getName()); test.setFileWithSelection(file.getName());

View file

@ -49,7 +49,7 @@ public abstract class ChangeGeneratorTest extends BaseTestFramework {
} }
@Override @Override
public void runTest() throws Exception{ public void runTest() throws Exception {
final ASTModificationStore modStore = new ASTModificationStore(); final ASTModificationStore modStore = new ASTModificationStore();
IFile testFile = importFile("source.h", source); //$NON-NLS-1$ IFile testFile = importFile("source.h", source); //$NON-NLS-1$

View file

@ -7,18 +7,18 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* Institute for Software (IFS)- initial API and implementation * Institute for Software (IFS)- initial API and implementation
******************************************************************************/ ******************************************************************************/
package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.insertbefore; package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.insertbefore;
import junit.framework.Test; import junit.framework.Test;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTDeclarator; import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier; import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTStandardFunctionDeclarator; import org.eclipse.cdt.core.dom.ast.IASTStandardFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTParameterDeclaration; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTParameterDeclaration;
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest; import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
@ -29,26 +29,26 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTParameterDeclaration;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTSimpleDeclSpecifier; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTSimpleDeclSpecifier;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTSimpleDeclaration; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTSimpleDeclaration;
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification; import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind; import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind;
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
/** /**
* @author Emanuel Graf IFS * @author Emanuel Graf IFS
*
*/ */
public class AddDeclarationBug extends ChangeGeneratorTest { public class AddDeclarationBug extends ChangeGeneratorTest {
AddDeclarationBug() {
super("AddDeclarationBug");
}
public static Test suite() {
return new AddDeclarationBug();
public AddDeclarationBug() {
super("Add Declaration Bug Test");
} }
@Override @Override
protected void setUp() throws Exception { protected void setUp() throws Exception {
source = "class A\n{\npublic:\n A();\n virtual ~A();\n int foo();\n \nprivate:\n int help();\n};"; //$NON-NLS-1$ source = "class A\n{\npublic:\n A();\n virtual ~A();\n int foo();\n \nprivate:\n int help();\n};"; //$NON-NLS-1$
expectedSource = "class A\n{\npublic:\n A();\n virtual ~A();\n int foo();\n \nprivate:\n int help();\n int exp(int i);\n};"; //$NON-NLS-1$ expectedSource = "class A\n{\npublic:\n A();\n virtual ~A();\n int foo();\n \nprivate:\n int help();\n\tint exp(int i);\n};"; //$NON-NLS-1$
super.setUp(); super.setUp();
} }
@ -84,8 +84,4 @@ public class AddDeclarationBug extends ChangeGeneratorTest {
} }
}; };
} }
public static Test suite() {
return new AddDeclarationBug();
}
} }

View file

@ -7,40 +7,44 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* Institute for Software - initial API and implementation * Institute for Software - initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.insertbefore; package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.insertbefore;
import junit.framework.Test; import junit.framework.Test;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator; import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTArrayModifier; import org.eclipse.cdt.core.dom.ast.IASTArrayModifier;
import org.eclipse.cdt.core.dom.ast.IASTDeclarator; import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression;
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest; import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTArrayModifier; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTArrayModifier;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTLiteralExpression; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTLiteralExpression;
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification; import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind; import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind;
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
public class ArrayModifierTest extends ChangeGeneratorTest { public class ArrayModifierTest extends ChangeGeneratorTest {
public ArrayModifierTest(){ ArrayModifierTest() {
super("Replace Array Modifier"); //$NON-NLS-1$ super("ArrayModifierTest");
}
public static Test suite() {
return new ArrayModifierTest();
} }
@Override @Override
protected void setUp() throws Exception { protected void setUp() throws Exception {
source = "int *pi[3];"; //$NON-NLS-1$ source = "int* pi[3];"; //$NON-NLS-1$
expectedSource = "int *pi[5][3];"; //$NON-NLS-1$ expectedSource = "int* pi[5][3];"; //$NON-NLS-1$
super.setUp(); super.setUp();
} }
@Override @Override
protected ASTVisitor createModificator( protected ASTVisitor createModificator(final ASTModificationStore modStore) {
final ASTModificationStore modStore) {
return new ASTVisitor() { return new ASTVisitor() {
{ {
shouldVisitDeclarators = true; shouldVisitDeclarators = true;
@ -49,11 +53,12 @@ public class ArrayModifierTest extends ChangeGeneratorTest {
@Override @Override
public int visit(IASTDeclarator declarator) { public int visit(IASTDeclarator declarator) {
if (declarator instanceof IASTArrayDeclarator) { if (declarator instanceof IASTArrayDeclarator) {
IASTArrayDeclarator arrayDeclarator = (IASTArrayDeclarator)declarator; IASTArrayDeclarator arrayDeclarator = (IASTArrayDeclarator) declarator;
IASTArrayModifier[] modifiers = arrayDeclarator.getArrayModifiers(); IASTArrayModifier[] modifiers = arrayDeclarator.getArrayModifiers();
IASTArrayModifier newModifier = new CPPASTArrayModifier(); IASTArrayModifier newModifier = new CPPASTArrayModifier();
IASTExpression expr = new CPPASTLiteralExpression(0, "5"); //$NON-NLS-1$ IASTExpression expr =
new CPPASTLiteralExpression(IASTLiteralExpression.lk_integer_constant, "5".toCharArray()); //$NON-NLS-1$
newModifier.setConstantExpression(expr); 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); modStore.storeModification(null, modification);
@ -62,8 +67,4 @@ public class ArrayModifierTest extends ChangeGeneratorTest {
} }
}; };
} }
public static Test suite() {
return new ArrayModifierTest();
}
} }

View file

@ -7,17 +7,18 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* Institute for Software - initial API and implementation * Institute for Software - initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.insertbefore; package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.insertbefore;
import junit.framework.Test; import junit.framework.Test;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator; import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTArrayModifier; import org.eclipse.cdt.core.dom.ast.IASTArrayModifier;
import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression;
import org.eclipse.cdt.core.dom.ast.IASTTypeId; import org.eclipse.cdt.core.dom.ast.IASTTypeId;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNewExpression; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNewExpression;
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest; import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTArrayModifier; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTArrayModifier;
@ -25,25 +26,25 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTLiteralExpression;
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification; import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore; import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
public class ArraySizeExpressionTest extends ChangeGeneratorTest { public class ArraySizeExpressionTest extends ChangeGeneratorTest {
public ArraySizeExpressionTest(){ ArraySizeExpressionTest() {
super("Insert Array Size Expression"); //$NON-NLS-1$ super("ArraySizeExpressionTest");
}
public static Test suite() {
return new ArraySizeExpressionTest();
} }
@Override @Override
protected void setUp() throws Exception { protected void setUp() throws Exception {
source = "int *values = new int[5];"; //$NON-NLS-1$ source = "int* values = new int[5];"; //$NON-NLS-1$
expectedSource = "int *values = new int[6][5];"; //$NON-NLS-1$ expectedSource = "int* values = new int[6][5];"; //$NON-NLS-1$
super.setUp(); super.setUp();
} }
@Override @Override
protected ASTVisitor createModificator( protected ASTVisitor createModificator(final ASTModificationStore modStore) {
final ASTModificationStore modStore) {
return new ASTVisitor() { return new ASTVisitor() {
{ {
shouldVisitExpressions = true; shouldVisitExpressions = true;
@ -56,7 +57,8 @@ public class ArraySizeExpressionTest extends ChangeGeneratorTest {
IASTTypeId id= newExpression.getTypeId(); IASTTypeId id= newExpression.getTypeId();
IASTArrayDeclarator dtor= (IASTArrayDeclarator) id.getAbstractDeclarator(); IASTArrayDeclarator dtor= (IASTArrayDeclarator) id.getAbstractDeclarator();
IASTArrayModifier[] mods= dtor.getArrayModifiers(); IASTArrayModifier[] mods= dtor.getArrayModifiers();
IASTArrayModifier add= new CPPASTArrayModifier(new CPPASTLiteralExpression(0, "6")); 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); modStore.storeModification(null, modification);
} }
@ -64,9 +66,4 @@ public class ArraySizeExpressionTest extends ChangeGeneratorTest {
} }
}; };
} }
public static Test suite() {
return new ArraySizeExpressionTest();
}
} }

View file

@ -7,14 +7,14 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* Institute for Software - initial API and implementation * Institute for Software - initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.insertbefore; package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.insertbefore;
import junit.framework.Test; import junit.framework.Test;
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer;
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest; import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTConstructorChainInitializer; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTConstructorChainInitializer;
@ -22,25 +22,28 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDeclarator;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTIdExpression; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTIdExpression;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName; 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.ASTModification;
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind; import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind;
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
public class CtorChainInitializerTest extends ChangeGeneratorTest { public class CtorChainInitializerTest extends ChangeGeneratorTest {
public CtorChainInitializerTest(){ CtorChainInitializerTest() {
super("Insert Before Ctor Initializer"); //$NON-NLS-1$ super("CtorChainInitializerTest");
}
public static Test suite() {
return new CtorChainInitializerTest();
} }
@Override @Override
protected void setUp() throws Exception { protected void setUp() throws Exception {
source = "TestClass::TestClass(int a, int b):beta(b){\n}\n\n"; //$NON-NLS-1$ source = "TestClass::TestClass(int a, int b):beta(b) {\n}\n\n"; //$NON-NLS-1$
expectedSource = "TestClass::TestClass(int a, int b):alpha(a), beta(b){\n}\n\n"; //$NON-NLS-1$ expectedSource = "TestClass::TestClass(int a, int b) :\n\t\talpha(a), beta(b) {\n}\n\n"; //$NON-NLS-1$
super.setUp(); super.setUp();
} }
@Override @Override
protected ASTVisitor createModificator( protected ASTVisitor createModificator(final ASTModificationStore modStore) {
final ASTModificationStore modStore) {
return new ASTVisitor() { return new ASTVisitor() {
{ {
shouldVisitDeclarators = true; shouldVisitDeclarators = true;
@ -49,7 +52,7 @@ public class CtorChainInitializerTest extends ChangeGeneratorTest {
@Override @Override
public int visit(IASTDeclarator declarator) { public int visit(IASTDeclarator declarator) {
if (declarator instanceof CPPASTFunctionDeclarator) { if (declarator instanceof CPPASTFunctionDeclarator) {
CPPASTFunctionDeclarator functionDeclarator = (CPPASTFunctionDeclarator)declarator; CPPASTFunctionDeclarator functionDeclarator = (CPPASTFunctionDeclarator) declarator;
ICPPASTConstructorChainInitializer ctorInitializer = functionDeclarator.getConstructorChain()[0]; ICPPASTConstructorChainInitializer ctorInitializer = functionDeclarator.getConstructorChain()[0];
CPPASTIdExpression initExpr = new CPPASTIdExpression(new CPPASTName("a".toCharArray())); //$NON-NLS-1$ CPPASTIdExpression initExpr = new CPPASTIdExpression(new CPPASTName("a".toCharArray())); //$NON-NLS-1$
CPPASTName initName = new CPPASTName("alpha".toCharArray()); //$NON-NLS-1$ CPPASTName initName = new CPPASTName("alpha".toCharArray()); //$NON-NLS-1$
@ -63,9 +66,4 @@ public class CtorChainInitializerTest extends ChangeGeneratorTest {
} }
}; };
} }
public static Test suite() {
return new CtorChainInitializerTest();
}
} }

View file

@ -7,16 +7,16 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* Institute for Software - initial API and implementation * Institute for Software - initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.insertbefore; package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.insertbefore;
import junit.framework.Test; import junit.framework.Test;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTDeclarator; import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier; import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTTypeId; import org.eclipse.cdt.core.dom.ast.IASTTypeId;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest; import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTDeclarator; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTDeclarator;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDeclarator; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDeclarator;
@ -24,13 +24,17 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTSimpleDeclSpecifier; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTSimpleDeclSpecifier;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTTypeId; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTTypeId;
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification; import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind; import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind;
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
public class ExceptionTest extends ChangeGeneratorTest { public class ExceptionTest extends ChangeGeneratorTest {
public ExceptionTest(){ ExceptionTest() {
super("Insert Before Exception Declaration"); //$NON-NLS-1$ super("ExceptionTest");
}
public static Test suite() {
return new ExceptionTest();
} }
@Override @Override
@ -41,8 +45,7 @@ public class ExceptionTest extends ChangeGeneratorTest {
} }
@Override @Override
protected ASTVisitor createModificator( protected ASTVisitor createModificator(final ASTModificationStore modStore) {
final ASTModificationStore modStore) {
return new ASTVisitor() { return new ASTVisitor() {
{ {
shouldVisitDeclarators = true; shouldVisitDeclarators = true;
@ -69,9 +72,4 @@ public class ExceptionTest extends ChangeGeneratorTest {
} }
}; };
} }
public static Test suite() {
return new ExceptionTest();
}
} }

View file

@ -7,16 +7,16 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* Institute for Software - initial API and implementation * Institute for Software - initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.insertbefore; package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.insertbefore;
import junit.framework.Test; import junit.framework.Test;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression; import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression;
import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTExpressionList; import org.eclipse.cdt.core.dom.ast.IASTExpressionList;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest; import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTBinaryExpression; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTBinaryExpression;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTIdExpression; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTIdExpression;
@ -25,14 +25,14 @@ 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.ASTModification;
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore; import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
public class ExpressionTest extends ChangeGeneratorTest { public class ExpressionTest extends ChangeGeneratorTest {
public ExpressionTest(){ ExpressionTest() {
super("Insert Expression"); //$NON-NLS-1$ super("ExpressionTest");
}
public static Test suite() {
return new ExpressionTest();
} }
@Override @Override
@ -43,8 +43,7 @@ public class ExpressionTest extends ChangeGeneratorTest {
} }
@Override @Override
protected ASTVisitor createModificator( protected ASTVisitor createModificator(final ASTModificationStore modStore) {
final ASTModificationStore modStore) {
return new ASTVisitor() { return new ASTVisitor() {
{ {
shouldVisitExpressions = true; shouldVisitExpressions = true;
@ -63,9 +62,4 @@ public class ExpressionTest extends ChangeGeneratorTest {
} }
}; };
} }
public static Test suite() {
return new ExpressionTest();
}
} }

View file

@ -7,16 +7,16 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* Institute for Software - initial API and implementation * Institute for Software - initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.insertbefore; package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.insertbefore;
import junit.framework.Test; import junit.framework.Test;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTDeclarator; import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration; import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier; import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest; import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTDeclarator; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTDeclarator;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDeclarator; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDeclarator;
@ -24,17 +24,17 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTParameterDeclaration; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTParameterDeclaration;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTSimpleDeclSpecifier; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTSimpleDeclSpecifier;
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification; import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind; import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind;
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
public class FirstParameterTest extends ChangeGeneratorTest { public class FirstParameterTest extends ChangeGeneratorTest {
public FirstParameterTest(){ FirstParameterTest() {
super("Insert Before First Parameter"); //$NON-NLS-1$ super("FirstParameterTest");
}
public static Test suite() {
return new FirstParameterTest();
} }
@Override @Override
@ -44,10 +44,8 @@ public class FirstParameterTest extends ChangeGeneratorTest {
super.setUp(); super.setUp();
} }
@Override @Override
protected ASTVisitor createModificator( protected ASTVisitor createModificator(final ASTModificationStore modStore) {
final ASTModificationStore modStore) {
return new ASTVisitor() { return new ASTVisitor() {
{ {
shouldVisitDeclarators = true; shouldVisitDeclarators = true;
@ -77,9 +75,4 @@ public class FirstParameterTest extends ChangeGeneratorTest {
} }
}; };
} }
public static Test suite() {
return new FirstParameterTest();
}
} }

View file

@ -7,7 +7,7 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* Institute for Software - initial API and implementation * Institute for Software - initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.insertbefore; package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.insertbefore;
@ -16,12 +16,11 @@ import junit.framework.TestSuite;
/** /**
* @author Thomas Corbat * @author Thomas Corbat
*
*/ */
public class InsertBeforeTestSuite{ public class InsertBeforeTestSuite {
public static Test suite() throws Exception { public static Test suite() throws Exception {
TestSuite suite = new TestSuite("Changegenerator InsertBefore Tests"); TestSuite suite = new TestSuite("ChangeGenerator InsertBefore Tests");
suite.addTest(FirstParameterTest.suite()); suite.addTest(FirstParameterTest.suite());
suite.addTest(PointerParameterTest.suite()); suite.addTest(PointerParameterTest.suite());

View file

@ -7,50 +7,44 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* Institute for Software - initial API and implementation * Institute for Software - initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.insertbefore; package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.insertbefore;
import junit.framework.Test; import junit.framework.Test;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement; import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
import org.eclipse.cdt.core.dom.ast.IASTDeclarationStatement; import org.eclipse.cdt.core.dom.ast.IASTDeclarationStatement;
import org.eclipse.cdt.core.dom.ast.IASTForStatement; import org.eclipse.cdt.core.dom.ast.IASTForStatement;
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier; import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTStatement; import org.eclipse.cdt.core.dom.ast.IASTStatement;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleDeclSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleDeclSpecifier;
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest; import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPNodeFactory; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPNodeFactory;
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification; 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.ASTModificationStore;
public class MultilineWhitespaceHandlingTest extends ChangeGeneratorTest { public class MultilineWhitespaceHandlingTest extends ChangeGeneratorTest {
public MultilineWhitespaceHandlingTest(){ MultilineWhitespaceHandlingTest() {
super("Multiline Whitespace Handling"); //$NON-NLS-1$ super("MultilineWhitespaceHandlingTest");
}
@Override
protected void setUp() throws Exception {
source = "void foo(){\r\n\r\n for(int i = 0; i < 10; i++){\r\n\r\n }\r\n}\r\n"; //$NON-NLS-1$
expectedSource = "void foo(){\r\n\r\n for(int i = 0; i < 10; i++){\r\n int i;\r\n int j;\r\n\r\n }\r\n}\r\n"; //$NON-NLS-1$
super.setUp();
} }
public static Test suite() { public static Test suite() {
return new MultilineWhitespaceHandlingTest(); return new MultilineWhitespaceHandlingTest();
} }
@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$
super.setUp();
}
@Override @Override
protected ASTVisitor createModificator( protected ASTVisitor createModificator(final ASTModificationStore modStore) {
final ASTModificationStore modStore) {
return new ASTVisitor() { return new ASTVisitor() {
{ {
shouldVisitStatements = true; shouldVisitStatements = true;

View file

@ -7,27 +7,31 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* Institute for Software - initial API and implementation * Institute for Software - initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.insertbefore; package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.insertbefore;
import junit.framework.Test; import junit.framework.Test;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTDeclarator; import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration; import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTPointerOperator; import org.eclipse.cdt.core.dom.ast.IASTPointerOperator;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest; import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDeclarator; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDeclarator;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTPointer; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTPointer;
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification; import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind; import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind;
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
public class PointerParameterTest extends ChangeGeneratorTest { public class PointerParameterTest extends ChangeGeneratorTest {
public PointerParameterTest(){ PointerParameterTest() {
super("Insert Pointer for Parameter"); //$NON-NLS-1$ super("PointerParameterTest");
}
public static Test suite() {
return new PointerParameterTest();
} }
@Override @Override
@ -38,8 +42,7 @@ public class PointerParameterTest extends ChangeGeneratorTest {
} }
@Override @Override
protected ASTVisitor createModificator( protected ASTVisitor createModificator(final ASTModificationStore modStore) {
final ASTModificationStore modStore) {
return new ASTVisitor() { return new ASTVisitor() {
{ {
shouldVisitDeclarators = true; shouldVisitDeclarators = true;
@ -63,9 +66,4 @@ public class PointerParameterTest extends ChangeGeneratorTest {
} }
}; };
} }
public static Test suite() {
return new PointerParameterTest();
}
} }

View file

@ -7,7 +7,7 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* Institute for Software - initial API and implementation * Institute for Software - initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.insertbefore; package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.insertbefore;
@ -21,31 +21,25 @@ 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.ASTModification;
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore; import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
public class SelfInsertionTest extends ChangeGeneratorTest { public class SelfInsertionTest extends ChangeGeneratorTest {
public SelfInsertionTest(){ SelfInsertionTest() {
super("Self Insertion Test"); //$NON-NLS-1$ super("SelfInsertionTest");
}
@Override
protected void setUp() throws Exception {
source = "void foo(){\r\n\r\n for(int i = 0; i < 10; i++){\r\n }\r\n}\r\n"; //$NON-NLS-1$
expectedSource = "void foo(){\r\n\r\n for(int i = 0; i < 10; i++){\r\n for(int i = 0;i < 10;i++){\r\n }\r\n }\r\n}\r\n"; //$NON-NLS-1$
super.setUp();
} }
public static Test suite() { public static Test suite() {
return new SelfInsertionTest(); return new SelfInsertionTest();
} }
@Override
protected void setUp() throws Exception {
source = "void foo() {\r\n\r\n\tfor (int i = 0; i < 10; i++) {\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\tfor (int i = 0; i < 10; i++) {\r\n\t\t}\r\n\t}\r\n}\r\n"; //$NON-NLS-1$
super.setUp();
}
@Override @Override
protected ASTVisitor createModificator( protected ASTVisitor createModificator(final ASTModificationStore modStore) {
final ASTModificationStore modStore) {
return new ASTVisitor() { return new ASTVisitor() {
{ {
shouldVisitStatements = true; shouldVisitStatements = true;

View file

@ -7,16 +7,16 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* Institute for Software - initial API and implementation * Institute for Software - initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.replace; package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.replace;
import junit.framework.Test; import junit.framework.Test;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest; import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTCompositeTypeSpecifier; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTCompositeTypeSpecifier;
@ -25,32 +25,25 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTSimpleDeclaration;
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification; import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore; import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
public class MoveRenameTest extends ChangeGeneratorTest { public class MoveRenameTest extends ChangeGeneratorTest {
public MoveRenameTest(){ MoveRenameTest() {
super("Swap Rename Declarations"); //$NON-NLS-1$ super("MoveRenameTest");
} }
@Override
protected void setUp() throws Exception {
source = "#ifndef A_H_\r\n#define A_H_\r\n\r\nclass A {\r\n\r\nprivate:\r\n int b;\r\n int a;\r\n};\r\n\r\n#endif /*A_H_*/\r\n\r\n"; //$NON-NLS-1$
expectedSource = "#ifndef A_H_\r\n#define A_H_\r\n\r\nclass A {\r\n\r\nprivate:\r\n int d;\r\n int b;\r\n};\r\n\r\n#endif /*A_H_*/\r\n\r\n"; //$NON-NLS-1$
super.setUp();
}
public static Test suite() { public static Test suite() {
return new MoveRenameTest(); return new MoveRenameTest();
} }
@Override @Override
protected ASTVisitor createModificator( protected void setUp() throws Exception {
final ASTModificationStore modStore) { source = "#ifndef A_H_\r\n#define A_H_\r\n\r\nclass A {\r\n\r\nprivate:\r\n\tint b;\r\n\tint a;\r\n};\r\n\r\n#endif /*A_H_*/\r\n\r\n"; //$NON-NLS-1$
expectedSource = "#ifndef A_H_\r\n#define A_H_\r\n\r\nclass A {\r\n\r\nprivate:\r\n\tint d;\r\n\tint b;\r\n};\r\n\r\n#endif /*A_H_*/\r\n\r\n"; //$NON-NLS-1$
super.setUp();
}
@Override
protected ASTVisitor createModificator(final ASTModificationStore modStore) {
return new ASTVisitor() { return new ASTVisitor() {
{ {
shouldVisitDeclSpecifiers = true; shouldVisitDeclSpecifiers = true;
@ -70,8 +63,6 @@ public class MoveRenameTest extends ChangeGeneratorTest {
} }
return super.visit(declSpec); return super.visit(declSpec);
} }
}; };
} }
} }

View file

@ -7,46 +7,40 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* Institute for Software - initial API and implementation * Institute for Software - initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.replace; package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.replace;
import junit.framework.Test; import junit.framework.Test;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest; import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTCompositeTypeSpecifier; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTCompositeTypeSpecifier;
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification; 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.ASTModificationStore;
public class MoveTest extends ChangeGeneratorTest { public class MoveTest extends ChangeGeneratorTest {
public MoveTest(){ MoveTest() {
super("Swap Declarations"); //$NON-NLS-1$ super("MoveTest");
}
@Override
protected void setUp() throws Exception {
source = "#ifndef A_H_\r\n#define A_H_\r\n\r\nclass A {\r\n\r\nprivate:\r\n int b;\r\n int a;\r\n};\r\n\r\n#endif /*A_H_*/\r\n\r\n"; //$NON-NLS-1$
expectedSource = "#ifndef A_H_\r\n#define A_H_\r\n\r\nclass A {\r\n\r\nprivate:\r\n int a;\r\n int b;\r\n};\r\n\r\n#endif /*A_H_*/\r\n\r\n"; //$NON-NLS-1$
super.setUp();
} }
public static Test suite() { public static Test suite() {
return new MoveTest(); return new MoveTest();
} }
@Override @Override
protected ASTVisitor createModificator( protected void setUp() throws Exception {
final ASTModificationStore modStore) { source = "#ifndef A_H_\r\n#define A_H_\r\n\r\nclass A {\r\n\r\nprivate:\r\n\tint b;\r\n\tint a;\r\n};\r\n\r\n#endif /*A_H_*/\r\n\r\n"; //$NON-NLS-1$
expectedSource = "#ifndef A_H_\r\n#define A_H_\r\n\r\nclass A {\r\n\r\nprivate:\r\n\tint a;\r\n\tint b;\r\n};\r\n\r\n#endif /*A_H_*/\r\n\r\n"; //$NON-NLS-1$
super.setUp();
}
@Override
protected ASTVisitor createModificator(final ASTModificationStore modStore) {
return new ASTVisitor() { return new ASTVisitor() {
{ {
shouldVisitDeclSpecifiers = true; shouldVisitDeclSpecifiers = true;
@ -64,8 +58,6 @@ public class MoveTest extends ChangeGeneratorTest {
} }
return super.visit(declSpec); return super.visit(declSpec);
} }
}; };
} }
} }

View file

@ -7,12 +7,13 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* Institute for Software - initial API and implementation * Institute for Software - initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.replace; package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.replace;
import junit.framework.Test; import junit.framework.Test;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression; import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression;
import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement; import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
import org.eclipse.cdt.core.dom.ast.IASTExpressionStatement; import org.eclipse.cdt.core.dom.ast.IASTExpressionStatement;
@ -20,7 +21,6 @@ import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression; import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression;
import org.eclipse.cdt.core.dom.ast.IASTStatement; import org.eclipse.cdt.core.dom.ast.IASTStatement;
import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression; import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest; import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTBinaryExpression; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTBinaryExpression;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTExpressionStatement; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTExpressionStatement;
@ -33,43 +33,37 @@ import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
public class ReplaceInsertStatementTest extends ChangeGeneratorTest { public class ReplaceInsertStatementTest extends ChangeGeneratorTest {
public ReplaceInsertStatementTest() { ReplaceInsertStatementTest() {
super("Replace Insert Statement Test"); super("ReplaceInsertStatementTest");
}
@Override
protected void setUp() throws Exception {
source = "void main(){\r\n int i = 0;\r\n ++i;\r\n}"; //$NON-NLS-1$
expectedSource = "void main(){\r\n int i = 0;\r\n i = 42;\r\n i++;\r\n}"; //$NON-NLS-1$
super.setUp();
} }
public static Test suite() { public static Test suite() {
return new ReplaceInsertStatementTest(); return new ReplaceInsertStatementTest();
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest#createModificator(org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore)
*/
@Override @Override
protected ASTVisitor createModificator( protected void setUp() throws Exception {
final ASTModificationStore modStore) { source = "void main() {\r\n\tint i = 0;\r\n\t++i;\r\n}"; //$NON-NLS-1$
expectedSource = "void main() {\r\n\tint i = 0;\r\n\ti = 42;\r\n\ti++;\r\n}"; //$NON-NLS-1$
super.setUp();
}
@Override
protected ASTVisitor createModificator(final ASTModificationStore modStore) {
return new ASTVisitor() { return new ASTVisitor() {
{ {
shouldVisitStatements = true; shouldVisitStatements = true;
} }
@Override @Override
public int visit(IASTStatement statement) { public int visit(IASTStatement statement) {
if (statement instanceof IASTCompoundStatement) { if (statement instanceof IASTCompoundStatement) {
IASTCompoundStatement compStmt = (IASTCompoundStatement) statement; IASTCompoundStatement compStmt = (IASTCompoundStatement) statement;
IASTStatement stmt = compStmt.getStatements()[1]; IASTStatement stmt = compStmt.getStatements()[1];
IASTIdExpression id = new CPPASTIdExpression( IASTIdExpression id = new CPPASTIdExpression(new CPPASTName("i".toCharArray()));
new CPPASTName("i".toCharArray()));
IASTLiteralExpression value = new CPPASTLiteralExpression( IASTLiteralExpression value = new CPPASTLiteralExpression(
IASTLiteralExpression.lk_integer_constant, "42"); IASTLiteralExpression.lk_integer_constant, "42".toCharArray());
IASTExpressionStatement insertStmt = new CPPASTExpressionStatement( IASTExpressionStatement insertStmt = new CPPASTExpressionStatement(
new CPPASTBinaryExpression( new CPPASTBinaryExpression(
IASTBinaryExpression.op_assign, id, value)); IASTBinaryExpression.op_assign, id, value));
@ -82,15 +76,12 @@ public class ReplaceInsertStatementTest extends ChangeGeneratorTest {
incExp); incExp);
ASTModification replaceMod = new ASTModification( ASTModification replaceMod = new ASTModification(
ASTModification.ModificationKind.REPLACE, stmt, ASTModification.ModificationKind.REPLACE, stmt, replaceStatement, null);
replaceStatement, null);
modStore.storeModification(null, replaceMod); modStore.storeModification(null, replaceMod);
ASTModification insertMod = new ASTModification( ASTModification insertMod = new ASTModification(
ASTModification.ModificationKind.INSERT_BEFORE, ASTModification.ModificationKind.INSERT_BEFORE, stmt, insertStmt, null);
stmt, insertStmt, null);
modStore.storeModification(null, insertMod); modStore.storeModification(null, insertMod);
} }
return PROCESS_CONTINUE; return PROCESS_CONTINUE;

View file

@ -7,16 +7,16 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* Institute for Software - initial API and implementation * Institute for Software - initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.replace; package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.replace;
import junit.framework.Test; import junit.framework.Test;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTIfStatement; import org.eclipse.cdt.core.dom.ast.IASTIfStatement;
import org.eclipse.cdt.core.dom.ast.IASTStatement; import org.eclipse.cdt.core.dom.ast.IASTStatement;
import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression; import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest; import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTCompoundStatement; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTCompoundStatement;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTExpressionStatement; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTExpressionStatement;
@ -26,31 +26,25 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTUnaryExpression;
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification; import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore; import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
public class StatementTest extends ChangeGeneratorTest { public class StatementTest extends ChangeGeneratorTest {
public StatementTest(){ StatementTest() {
super("Replace Then-Statement"); //$NON-NLS-1$ super("StatementTest");
}
@Override
protected void setUp() throws Exception {
source = "int f()\r\n{\r\n\tint i = 0;\r\n\tif(i < 1){\r\n\t\t++i;\r\n\t}\r\n}\r\n"; //$NON-NLS-1$
expectedSource = "int f()\r\n{\r\n\tint i = 0;\r\n\tif(i < 1){\r\n\t i++;\r\n\t}\r\n}\r\n"; //$NON-NLS-1$
super.setUp();
} }
public static Test suite() { public static Test suite() {
return new StatementTest(); return new StatementTest();
} }
@Override
protected void setUp() throws Exception {
source = "int f()\r\n{\r\n\tint i = 0;\r\n\tif (i < 1) {\r\n\t\t++i;\r\n\t}\r\n}\r\n"; //$NON-NLS-1$
expectedSource = "int f()\r\n{\r\n\tint i = 0;\r\n\tif (i < 1) {\r\n\t\ti++;\r\n\t}\r\n}\r\n"; //$NON-NLS-1$
super.setUp();
}
@Override @Override
protected ASTVisitor createModificator( protected ASTVisitor createModificator(final ASTModificationStore modStore) {
final ASTModificationStore modStore) {
return new ASTVisitor() { return new ASTVisitor() {
{ {
shouldVisitStatements = true; shouldVisitStatements = true;

View file

@ -11,11 +11,12 @@ const int a = 1;
//Test3 //Test3
volatile int b = 3; volatile int b = 3;
//Test4 //Test4
typedef int *intp; typedef int* intp;
//Test5 //Test5
extern int b; extern int b;
//Test6 //Test6
static int c; static int c;
//Test7 //Test7
int foo() int foo()
{ {
@ -59,7 +60,7 @@ public:
//!Commented ElaboratedTypeSpecifier 1 //!Commented ElaboratedTypeSpecifier 1
//%CPP //%CPP
//Test1 //Test1
class A *A; //Test2 class A* A; //Test2
//Test3 //Test3
enum Status{ good, bad}; //Test4 enum Status{ good, bad}; //Test4
//Test5 //Test5

View file

@ -76,42 +76,51 @@ extern "C" typedef void FUNC(); /*TEST 2*/
//!Commented NamespaceAlias 1 //!Commented NamespaceAlias 1
//%CPP //%CPP
//TEST 1 //TEST 1
namespace kurz = ziemlichlangernamespace; //TEST 2 namespace kurz = somenamespace; //TEST 2
//!Commented NamespaceAlias 2 //!Commented NamespaceAlias 2
//%CPP //%CPP
/*TEST 1*/ /*TEST 1*/
namespace kurz = ziemlichlangernamespace; /*TEST 2*/ namespace kurz = somenamespace; /*TEST 2*/
//!Commented NamespaceDefinition 1 //!Commented NamespaceDefinition 1
//%CPP //%CPP
//TEST 1 //TEST 1
namespace ziemlichlangernamespace namespace namespace1
{ {
//TEST 2
//TEST 2
} //TEST 3 } //TEST 3
//!Commented NamespaceDefinition 2 //!Commented NamespaceDefinition 2
//%CPP //%CPP
/*TEST 1*/ /*TEST 1*/
namespace ziemlichlangernamespace namespace namespace2
{ {
/*TEST 2*/
/*TEST 2*/
} /*TEST 3*/ } /*TEST 3*/
//!Commented NamespaceDefinition 3 //!Commented NamespaceDefinition 3
//%CPP //%CPP
namespace ziemlichlangernamespace namespace namespace3
{ {
//TEST
//TEST
} }
//!Commented NamespaceDefinition 4 //!Commented NamespaceDefinition 4
//%CPP //%CPP
namespace ziemlichlangernamespace namespace namespace4
{ {
//TEST
//TEST
} }
void doIt() void doIt()
{ {
int i = 0; int i = 0;
@ -158,8 +167,9 @@ template<> class MyQueue<double> //TEST 2
{ {
//TEST 3 //TEST 3
std::vector<double> data; std::vector<double> data;
public: public:
void Add(const double& ); void Add(const double&);
void Remove(); void Remove();
void Print(); void Print();
//TEST 4 //TEST 4
@ -173,8 +183,9 @@ template<> class MyQueue<double> /*TEST 2*/
{ {
/*TEST 3*/ /*TEST 3*/
std::vector<double> data; std::vector<double> data;
public: public:
void Add(const double& ); void Add(const double&);
void Remove(); void Remove();
void Print(); void Print();
/*TEST 4*/ /*TEST 4*/
@ -214,9 +225,11 @@ class A
//TEST 1 //TEST 1
public: //TEST 2 public: //TEST 2
int hallo(); int hallo();
/*TEST 3*/ /*TEST 3*/
protected: /*TEST 4*/ protected: /*TEST 4*/
int b, c; int b, c;
private: private:
int p; int p;
}; };
@ -231,13 +244,13 @@ int i = 2; //TEST 2
/*TEST 1*/ /*TEST 1*/
int i = 2; /*TEST 2*/ int i = 2; /*TEST 2*/
//!Commented typename qualfier 1 //!Commented typename qualifier 1
//%CPP //%CPP
//TEST 1 //TEST 1
typename T::A *a6; //TEST 2 typename T::A* a6; //TEST 2
//!Commented typename qualfier 2 //!Commented typename qualifier 2
//%CPP //%CPP
/*TEST 1*/ /*TEST 1*/
typename T::A *a6; /*TEST 2*/ typename T::A* a6; /*TEST 2*/

View file

@ -8,7 +8,7 @@ void foo()
{ {
int f(); int f();
}; };
int (B::* pb)() = &B::f; int (B::*pb)() = &B::f;
} }
@ -22,13 +22,14 @@ void foo()
{ {
int f(); int f();
}; };
int (B::* pb)() = &B::f; int (B::*pb)() = &B::f;
} }
//!Commented CPPFunctionDeclaratorTest 1 //!Commented CPPFunctionDeclaratorTest 1
//%CPP //%CPP
char & operator [](unsigned int); char& operator [](unsigned int);
//TEST 1 //TEST 1
TestClass::TestClass(int a) //TEST 2 TestClass::TestClass(int a) //TEST 2
{ {
@ -38,7 +39,8 @@ TestClass::TestClass(int a) //TEST 2
//!Commented CPPFunctionDeclaratorTest 2 //!Commented CPPFunctionDeclaratorTest 2
//%CPP //%CPP
char & operator [](unsigned int); char& operator [](unsigned int);
/*TEST 1*/ /*TEST 1*/
TestClass::TestClass(int a) /*TEST 2*/ TestClass::TestClass(int a) /*TEST 2*/
{ {
@ -48,7 +50,8 @@ TestClass::TestClass(int a) /*TEST 2*/
//!Commented CPPFunctionDeclaratorTest 3 //!Commented CPPFunctionDeclaratorTest 3
//%CPP //%CPP
char & operator [](unsigned int); char& operator [](unsigned int);
//TEST 1 //TEST 1
TestClass::TestClass(int a) TestClass::TestClass(int a)
:alpha(a) //TEST 2 :alpha(a) //TEST 2
@ -59,7 +62,8 @@ TestClass::TestClass(int a)
//!Commented CPPFunctionDeclaratorTest 4 //!Commented CPPFunctionDeclaratorTest 4
//%CPP //%CPP
char & operator [](unsigned int); char& operator [](unsigned int);
/*TEST 1*/ /*TEST 1*/
TestClass::TestClass(int a) TestClass::TestClass(int a)
:alpha(a) /*TEST 3*/ :alpha(a) /*TEST 3*/
@ -76,7 +80,7 @@ void foo()
try { try {
i++; i++;
} }
catch(...){ catch (...){
} }
} }
@ -90,7 +94,7 @@ void foo()
try { try {
i++; i++;
} }
catch(...){ catch (...){
} }
} }
@ -104,7 +108,7 @@ void foo()
//Test //Test
i++; i++;
} }
catch(...){ catch (...){
} }
} }
@ -118,7 +122,7 @@ void foo()
{ {
i++; i++;
} }
catch(...){ catch (...){
} }
} }
@ -132,7 +136,7 @@ void foo()
//Test //Test
i++; i++;
} }
catch(...){ catch (...){
} }
} }
@ -145,7 +149,7 @@ void foo()
try { try {
i++; //Test i++; //Test
} }
catch(...){ catch (...){
} }
} }
@ -159,7 +163,7 @@ void foo()
i++; i++;
//Test //Test
} }
catch(...){ catch (...){
} }
} }
@ -172,7 +176,7 @@ void foo()
try { try {
i++; i++;
} //Test } //Test
catch(...){ catch (...){
} }
} }
@ -185,7 +189,7 @@ void foo()
try { try {
i++; i++;
} }
catch(...){ catch (...){
//Test //Test
} }
} }
@ -199,7 +203,7 @@ void foo()
try { try {
i++; i++;
} }
catch(...){ catch (...){
//Test //Test
} }
} }
@ -213,7 +217,7 @@ void foo()
try { try {
i++; i++;
} }
catch(...){ catch (...){
} }
//Test //Test
} }
@ -227,9 +231,9 @@ void foo()
try { try {
i++; i++;
} }
catch(Overflow oo){ catch (Overflow oo){
} }
catch(Matherr mm){ catch (Matherr mm){
} }
} }
@ -242,9 +246,9 @@ void foo()
try { try {
i++; i++;
} }
catch(Overflow oo){ catch (Overflow oo){
} }
catch(Matherr mm){ catch (Matherr mm){
//Test //Test
} }
} }

View file

@ -30,7 +30,7 @@ class Foo
{ {
public: public:
//Test //Test
char & operator [](unsigned int); char& operator [](unsigned int);
}; };
//!Commented OperatorName2 //!Commented OperatorName2
@ -38,7 +38,7 @@ public:
class Foo class Foo
{ {
public: public:
char & operator [](unsigned int); //Test char& operator [](unsigned int); //Test
}; };
//!Commented ConversionName1 //!Commented ConversionName1

View file

@ -2,7 +2,7 @@
//%CPP //%CPP
void foo() void foo()
{ {
while(true){ while (true){
//TEST 1 //TEST 1
break; //TEST 2 break; //TEST 2
} }
@ -13,7 +13,7 @@ void foo()
//%CPP //%CPP
void foo() void foo()
{ {
while(true){ while (true){
/*TEST 1*/ /*TEST 1*/
break; /*TEST 2*/ break; /*TEST 2*/
} }
@ -62,7 +62,7 @@ void foo()
//%CPP //%CPP
void foo() void foo()
{ {
while(true){ while (true){
//TEST 1 //TEST 1
continue; //TEST 2 continue; //TEST 2
} }
@ -73,7 +73,7 @@ void foo()
//%CPP //%CPP
void foo() void foo()
{ {
while(true){ while (true){
/*TEST 1*/ /*TEST 1*/
continue; /*TEST 2*/ continue; /*TEST 2*/
} }
@ -112,7 +112,7 @@ void foo()
do{ //TEST 2 do{ //TEST 2
continue; //TEST 3 continue; //TEST 3
//TEST 4 //TEST 4
} while(true); //TEST 5 } while (true); //TEST 5
} }
@ -124,7 +124,7 @@ void foo()
//TEST 2 //TEST 2
continue; //TEST 3 continue; //TEST 3
//TEST 4 //TEST 4
} while(true); //TEST 5 } while (true); //TEST 5
} }
@ -136,7 +136,7 @@ void foo()
do{ /*TEST 2*/ do{ /*TEST 2*/
continue; /*TEST 3*/ continue; /*TEST 3*/
/*TEST 4*/ /*TEST 4*/
} while(true); /*TEST 5*/ } while (true); /*TEST 5*/
} }
@ -148,7 +148,7 @@ void foo()
/*TEST 2*/ /*TEST 2*/
continue; /*TEST 3*/ continue; /*TEST 3*/
/*TEST 4*/ /*TEST 4*/
} while(true); /*TEST 5*/ } while (true); /*TEST 5*/
} }
@ -158,7 +158,7 @@ void foo()
{ {
do{ do{
continue; continue;
} while(true); /*TEST 1*/ } while (true); /*TEST 1*/
} }
@ -197,7 +197,7 @@ void foo()
void foo() void foo()
{ {
//TEST 1 //TEST 1
for(int i = 0;i < 1;++i){ //TEST 2 for (int i = 0;i < 1;++i){ //TEST 2
break; //TEST 3 break; //TEST 3
} //TEST 4 } //TEST 4
} }
@ -207,7 +207,7 @@ void foo()
void foo() void foo()
{ {
//TEST 1 //TEST 1
for(int i = 0;i < 1;++i){ for (int i = 0;i < 1;++i){
//TEST 2 //TEST 2
break; //TEST 3 break; //TEST 3
} //TEST 4 } //TEST 4
@ -219,7 +219,7 @@ void foo()
void foo() void foo()
{ {
/*TEST 1*/ /*TEST 1*/
for(int i = 0;i < 1;++i){ /*TEST 2*/ for (int i = 0;i < 1;++i){ /*TEST 2*/
break; /*TEST 3*/ break; /*TEST 3*/
} /*TEST 4*/ } /*TEST 4*/
} }
@ -229,7 +229,7 @@ void foo()
void foo() void foo()
{ {
/*TEST 1*/ /*TEST 1*/
for(int i = 0;i < 1;++i){ for (int i = 0;i < 1;++i){
/*TEST 2*/ /*TEST 2*/
break; /*TEST 3*/ break; /*TEST 3*/
} /*TEST 4*/ } /*TEST 4*/
@ -240,7 +240,7 @@ void foo()
//%CPP //%CPP
void foo() void foo()
{ {
for(int i = 0;i < 1;++i){ for (int i = 0;i < 1;++i){
break; break;
} /*TEST 4*/ } /*TEST 4*/
} }
@ -385,7 +385,7 @@ void foo()
//%CPP //%CPP
int f() int f()
{ {
if(int c = f()){ if (int c = f()){
c++; c++;
} //TEST 1 } //TEST 1
return i; return i;
@ -398,7 +398,7 @@ int f()
{ {
int i = 0; int i = 0;
//TEST 1 //TEST 1
if(i < 1){ if (i < 1){
//TEST 3 //TEST 3
++i; ++i;
//TEST 4 //TEST 4
@ -407,7 +407,7 @@ int f()
--i; --i;
//TEST 6 //TEST 6
} //TEST 7 } //TEST 7
if(int c = f()){ if (int c = f()){
c++; c++;
} //TEST 8 } //TEST 8
return i; return i;
@ -420,7 +420,7 @@ int f()
{ {
int i = 0; int i = 0;
/*TEST 1*/ /*TEST 1*/
if(i < 1){ if (i < 1){
/*TEST 1*/ /*TEST 1*/
++i; ++i;
/*TEST 1*/ /*TEST 1*/
@ -429,7 +429,7 @@ int f()
--i; --i;
/*TEST 1*/ /*TEST 1*/
} /*TEST 1*/ } /*TEST 1*/
if(int c = f()){ if (int c = f()){
c++; c++;
} /*TEST 1*/ } /*TEST 1*/
return i; return i;
@ -440,7 +440,7 @@ int f()
//%CPP //%CPP
int g() int g()
{ {
if(10 > 5) //TEST 1 if (10 > 5) //TEST 1
return 1; //TEST 2 return 1; //TEST 2
return 0; return 0;
@ -449,7 +449,7 @@ int g()
//= //=
int g() int g()
{ {
if(10 > 5) if (10 > 5)
//TEST 1 //TEST 1
return 1; //TEST 2 return 1; //TEST 2
@ -460,7 +460,7 @@ int g()
//%CPP //%CPP
int g() int g()
{ {
if(10 > 5) /*TEST 1*/ if (10 > 5) /*TEST 1*/
return 1; /*TEST 2*/ return 1; /*TEST 2*/
return 0; return 0;
@ -469,7 +469,7 @@ int g()
//= //=
int g() int g()
{ {
if(10 > 5) if (10 > 5)
/*TEST 1*/ /*TEST 1*/
return 1; /*TEST 2*/ return 1; /*TEST 2*/
@ -583,7 +583,7 @@ void foo()
void foo() void foo()
{ {
//TEST 1 //TEST 1
while(true){ //TEST 2 while (true){ //TEST 2
//TEST 3 //TEST 3
break; //TEST 4 break; //TEST 4
//TEST 5 //TEST 5
@ -595,7 +595,7 @@ void foo()
void foo() void foo()
{ {
//TEST 1 //TEST 1
while(true){ while (true){
//TEST 2 //TEST 2
//TEST 3 //TEST 3
break; //TEST 4 break; //TEST 4
@ -609,7 +609,7 @@ void foo()
void foo() void foo()
{ {
/*TEST 1*/ /*TEST 1*/
while(true){ /*TEST 2*/ while (true){ /*TEST 2*/
/*TEST 3*/ /*TEST 3*/
break; /*TEST 4*/ break; /*TEST 4*/
/*TEST 5*/ /*TEST 5*/
@ -621,7 +621,7 @@ void foo()
void foo() void foo()
{ {
/*TEST 1*/ /*TEST 1*/
while(true){ while (true){
/*TEST 2*/ /*TEST 2*/
/*TEST 3*/ /*TEST 3*/
break; /*TEST 4*/ break; /*TEST 4*/
@ -634,7 +634,7 @@ void foo()
//%CPP //%CPP
void foo() void foo()
{ {
while(true){ while (true){
break; break;
} /*TEST 6*/ } /*TEST 6*/
} }
@ -650,10 +650,10 @@ int foo()
++i; ++i;
return i; return i;
} }
catch(...){ catch (...){
} }
} }
catch(...){ catch (...){
} }
} }

View file

@ -1,6 +1,7 @@
//!Commented TemplateFunction1 //!Commented TemplateFunction1
//%CPP //%CPP
template<typename T> int tempFunct(T p) template<typename T>
int tempFunct(T p)
{ {
++p; ++p;
//Kommentar //Kommentar
@ -12,7 +13,8 @@ template<typename T> int tempFunct(T p)
//!Commented TemplateFunction2 //!Commented TemplateFunction2
//%CPP //%CPP
//Kommentar //Kommentar
template<typename T> int tempFunct(T p) template<typename T>
int tempFunct(T p)
{ {
++p; ++p;
p + 4; p + 4;
@ -22,7 +24,8 @@ template<typename T> int tempFunct(T p)
//!Commented TemplateFunction3 //!Commented TemplateFunction3
//%CPP //%CPP
template<typename T> int tempFunct(T p) template<typename T>
int tempFunct(T p)
{ {
++p; ++p;
p + 4; p + 4;

View file

@ -7,9 +7,10 @@ inline int foo()
const int a = 1; const int a = 1;
volatile int b = 3; volatile int b = 3;
typedef int *intp; typedef int* intp;
extern int b; extern int b;
static int c; static int c;
int foo() int foo()
{ {
int i = 1; int i = 1;
@ -43,7 +44,7 @@ public:
//!ElaboratedTypeSpecifier //!ElaboratedTypeSpecifier
//%CPP //%CPP
class A *A; class A* A;
enum Status{ good, bad}; enum Status{ good, bad};
enum Status stat; enum Status stat;
union D union D
@ -52,7 +53,7 @@ union D
int y; int y;
}; };
union D d; union D d;
struct S *S; struct S* S;
//!EnumeratioSpecifier //!EnumeratioSpecifier
//%CPP //%CPP

View file

@ -32,12 +32,14 @@ extern "C" typedef void FUNC();
//!NamespaceAlias //!NamespaceAlias
//%CPP //%CPP
namespace kurz = ziemlichlangernamespace; namespace kurz = somenamespace;
//!NamespaceDefinition //!NamespaceDefinition
//%CPP //%CPP
namespace ziemlichlangernamespace namespace somenamespace
{ {
} }
//!TemplateDeclaration //!TemplateDeclaration
@ -58,8 +60,9 @@ template<typename T> class MyQueue;
template<> class MyQueue<double> template<> class MyQueue<double>
{ {
std::vector<double> data; std::vector<double> data;
public: public:
void Add(const double& ); void Add(const double&);
void Remove(); void Remove();
void Print(); void Print();
}; };
@ -92,9 +95,11 @@ using namespace B;
class A class A
{ {
public: public:
int hallo(); int hello();
protected: protected:
int b, c; int b, c;
private: private:
int p; int p;
}; };
@ -104,7 +109,7 @@ private:
//Comment //Comment
int i = 2; int i = 2;
//!typename qualfier //!Typename qualifier
//%CPP //%CPP
typename T::A *a6; typename T::A* a6;

View file

@ -1,22 +1,23 @@
//!DeclaratorTest //!DeclaratorTest
//%CPP //%CPP
int sd; int sd;
int *ip; int* ip;
int hs = 1; int hs = 1;
char & c; char& c;
void foo() void foo()
{ {
struct B struct B
{ {
int f(); int f();
}; };
int (B::* pb)() = &B::f; int (B::*pb)() = &B::f;
} }
//!ArrayDeclaratorTest //!ArrayDeclaratorTest
//%CPP //%CPP
int *pi[3]; int* pi[3];
int (*p3i)[3]; int (*p3i)[3];
//!FieldDeclaratorTest //!FieldDeclaratorTest
@ -30,38 +31,39 @@ struct Bit
//%C //%C
int foo(); int foo();
int bar(int a, int b); int bar(int a, int b);
int fun(const char *a, ...); int fun(const char* a, ...);
int fun3(int i, const char *a, ...); int fun3(int i, const char* a, ...);
//!CPPStandardFunctionDeclaratorTest //!CPPStandardFunctionDeclaratorTest
//%CPP //%CPP
int foo(); int foo();
int bar(int a, int b); int bar(int a, int b);
int fun(const char *a, ...); int fun(const char* a, ...);
int fun2(const char *a ...); int fun2(const char* a ...);
int fun3(int i, const char *a, ...); int fun3(int i, const char* a, ...);
//= ,... is synonymous with ... //= ,... is synonymous with ...
int foo(); int foo();
int bar(int a, int b); int bar(int a, int b);
int fun(const char *a, ...); int fun(const char* a, ...);
int fun2(const char *a, ...); int fun2(const char* a, ...);
int fun3(int i, const char *a, ...); int fun3(int i, const char* a, ...);
//!CPPFunctionDeclaratorTest //!CPPFunctionDeclaratorTest
//%CPP //%CPP
char & operator [](unsigned int); char& operator [](unsigned int);
class TestClass class TestClass
{ {
int alpha; int alpha;
TestClass(int a); TestClass(int a);
virtual void pure() =0; virtual void pure() = 0;
}; };
TestClass::TestClass(int a) TestClass::TestClass(int a)
:alpha(a) :alpha(a)
{ {
} }
void undefPar(const char *c) throw (int); void undefPar(const char* c) throw (int);
int getV() const; int getV() const;
int vol() volatile; int vol() volatile;
@ -72,15 +74,17 @@ class C
{ {
int i; int i;
double d; double d;
public: public:
C(int, double); C(int, double);
}; };
C::C(int ii, double id) C::C(int ii, double id)
try try
:i(f(ii)), d(id) :i(f(ii)), d(id)
{ {
} }
catch(...){ catch (...){
} }
@ -94,7 +98,7 @@ int b, a;
//!ICPPASTDeclarator with nested declarator being a variable //!ICPPASTDeclarator with nested declarator being a variable
//%C //%C
int *(*var[3]); int* (*var[3]);
//!ICPPASTDeclarator with nested declarator and redundant parentheses //!ICPPASTDeclarator with nested declarator and redundant parentheses
//%C //%C
@ -108,8 +112,8 @@ class Foo
}; };
//!ICPPASTReferenceOperator rvalue reference //!ICPPASTReferenceOperator rvalue reference
//%CPP //%CPP
int && foo(int && a) int&& foo(int&& a)
{ {
char && b; char&& b;
} }

View file

@ -4,10 +4,10 @@ int i = (int)'A';
//!CPPCastExpression //!CPPCastExpression
//%CPP //%CPP
TestClass *i = dynamic_cast<TestClass*>(tc); TestClass* i = dynamic_cast<TestClass*>(tc);
TestClass *i = static_cast<TestClass*>(tc); TestClass* i = static_cast<TestClass*>(tc);
TestClass *i = reinterpret_cast<TestClass*>(tc); TestClass* i = reinterpret_cast<TestClass*>(tc);
TestClass *i = const_cast<TestClass*>(tc); TestClass* i = const_cast<TestClass*>(tc);
//!ArraySubscrition //!ArraySubscrition
//%C GNU //%C GNU
@ -33,6 +33,7 @@ int i = 1 | x;
bool b = 1 && x; bool b = 1 && x;
bool b = 1 || x; bool b = 1 || x;
int i = x; int i = x;
void foo() void foo()
{ {
i *= x; i *= x;
@ -131,7 +132,7 @@ string s = "abc";
//!CPPLiteralExpression //!CPPLiteralExpression
//%CPP //%CPP
TestClass *tc = this; TestClass* tc = this;
bool b = true; bool b = true;
bool b = false; bool b = false;
@ -141,7 +142,7 @@ int i = ++a;
int i = --a; int i = --a;
int i = +a; int i = +a;
int i = -a; int i = -a;
int *b = &a; int* b = &a;
int i = *b; int i = *b;
int i = ~b; int i = ~b;
bool b = !false; bool b = !false;
@ -167,7 +168,7 @@ void rethrow()
int i = 1; int i = 1;
throw i; throw i;
} }
catch(int j){ catch (int j){
throw ; throw ;
} }
} }
@ -191,7 +192,7 @@ void f()
//!CPPNewExpression //!CPPNewExpression
//%CPP //%CPP
TestClass *tc = new TestClass(); TestClass* tc = new TestClass();
//!CPPSimpleTypeConstructorExpression //!CPPSimpleTypeConstructorExpression
//%CPP //%CPP

View file

@ -11,7 +11,7 @@ int TestClass::Hallo;
class Foo class Foo
{ {
public: public:
char & operator [](unsigned int); char& operator [](unsigned int);
}; };
//!ConversionName //!ConversionName

View file

@ -2,7 +2,7 @@
//%CPP //%CPP
void foo() void foo()
{ {
while(true){ while (true){
break; break;
} }
} }
@ -41,7 +41,7 @@ void foo()
//%CPP //%CPP
void foo() void foo()
{ {
while(true){ while (true){
continue; continue;
} }
} }
@ -62,7 +62,7 @@ void foo()
{ {
do{ do{
continue; continue;
} while(true); } while (true);
} }
@ -79,13 +79,13 @@ void foo()
//%CPP //%CPP
void foo() void foo()
{ {
for(int i = 0;i < 1;++i){ for (int i = 0;i < 1;++i){
break; break;
} }
for(;;){ for (;;){
break; break;
} }
for(;int c = f();){ for (;int c = f();){
c++; c++;
} }
} }
@ -96,7 +96,7 @@ void foo()
void foo() void foo()
{ {
int i; int i;
for(i = 0;i < 1;++i){ for (i = 0;i < 1;++i){
} }
} }
@ -115,12 +115,12 @@ int f()
int f() int f()
{ {
int i = 0; int i = 0;
if(i < 1){ if (i < 1){
++i; ++i;
}else{ }else{
--i; --i;
} }
if(int c = f()){ if (int c = f()){
c++; c++;
} }
return i; return i;
@ -131,7 +131,7 @@ int f()
//%CPP //%CPP
int g() int g()
{ {
if(10 > 5) if (10 > 5)
return 1; return 1;
return 0; return 0;
@ -141,7 +141,7 @@ int g()
//%C //%C
int g() int g()
{ {
if(10 > 5) if (10 > 5)
return 1; return 1;
return 0; return 0;
@ -240,14 +240,14 @@ int foo(int a)
//%CPP //%CPP
void foo() void foo()
{ {
while(true){ while (true){
break; break;
} }
} }
void fa() void fa()
{ {
while(int i = f()){ while (int i = f()){
++i; ++i;
break; break;
} }
@ -255,7 +255,7 @@ void fa()
void fb() void fb()
{ {
while(true); while (true);
} }
@ -263,7 +263,7 @@ void fb()
//%C //%C
void foo() void foo()
{ {
while(true){ while (true){
break; break;
} }
} }
@ -279,10 +279,10 @@ int foo()
++i; ++i;
return i; return i;
} }
catch(...){ catch (...){
} }
} }
catch(...){ catch (...){
} }
} }
@ -293,7 +293,7 @@ int foo()
int foo() int foo()
{ {
int i = 1; int i = 1;
if( i == ZWO) if (i == ZWO)
{ {
} }
} }
@ -301,7 +301,7 @@ int foo()
int foo() int foo()
{ {
int i = 1; int i = 1;
if( i == ZWO) if (i == ZWO)
{ {
} }
} }
@ -309,5 +309,5 @@ int foo()
//!ArrayDeclarationStatementTest //!ArrayDeclarationStatementTest
//%CPP //%CPP
string *newElements = new string[m_capacity]; string* newElements = new string[m_capacity];

View file

@ -1,10 +1,11 @@
//![temp.names] examples abschnitt 4/1 //![temp.names] examples abschnitt 4/1
//%CPP //%CPP
T *p1 = p->template alloc<100>(); T* p1 = p->template alloc<100>();
//![temp.names] examples abschnitt 4/2, didn't work cause of Bug# 164482 //![temp.names] examples abschnitt 4/2, didn't work cause of Bug# 164482
//%CPP //%CPP
template<class T> void f(T *p) template<class T>
void f(T* p)
{ {
T::template adjust<100>(); T::template adjust<100>();
} }

View file

@ -148,6 +148,7 @@ class Klasse0
public: public:
Klasse0(); //Comment Klasse0(); //Comment
std::string toString(); std::string toString();
private: private:
int i; int i;
}; };
@ -170,6 +171,7 @@ class Klasse0
public: public:
Klasse1(); Klasse1();
std::string toString(); std::string toString();
private: private:
int i; int i;
}; };
@ -182,6 +184,7 @@ class Klasse0
public: public:
Klasse1(); Klasse1();
std::string toString(); std::string toString();
private: private:
int i; int i;
}; = //Comment1 }; = //Comment1
@ -2779,26 +2782,26 @@ int foo = bar; = //Zweiteilig
//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest //#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
//@Klasse1.h //@Klasse1.h
//TEST 1 //TEST 1
namespace ziemlichlangernamespace namespace somenamespace
{ {
//TEST 2 //TEST 2
} //TEST 3 } //TEST 3
//= //=
=>leading =>leading
namespace ziemlichlangernamespace namespace somenamespace
{ {
//TEST 2 //TEST 2
} = //TEST 1 } = //TEST 1
=>trailing =>trailing
namespace ziemlichlangernamespace namespace somenamespace
{ {
//TEST 2 //TEST 2
} = //TEST 3 } = //TEST 3
=>freestanding =>freestanding
namespace ziemlichlangernamespace namespace somenamespace
{ {
//TEST 2 //TEST 2
} = //TEST 2 } = //TEST 2
@ -2807,7 +2810,7 @@ namespace ziemlichlangernamespace
//!CommentRecognition215 - von ASTWriter NamesapceDefinition //!CommentRecognition215 - von ASTWriter NamesapceDefinition
//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest //#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
//@Klasse1.h //@Klasse1.h
namespace ziemlichlangernamespace namespace somenamespace
{ {
//TEST //TEST
} }
@ -2822,7 +2825,7 @@ void doIt(){
=>trailing =>trailing
=>freestanding =>freestanding
namespace ziemlichlangernamespace namespace somenamespace
{ {
//TEST //TEST
} = //TEST } = //TEST
@ -2830,7 +2833,7 @@ namespace ziemlichlangernamespace
//!CommentRecognition216 - von ASTWriter NamesapceDefinition //!CommentRecognition216 - von ASTWriter NamesapceDefinition
//#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest //#org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest
//@Klasse1.h //@Klasse1.h
namespace ziemlichlangernamespace namespace somenamespace
{ {
int i = 0; int i = 0;
//TEST //TEST
@ -2846,7 +2849,7 @@ void doIt(){
=>trailing =>trailing
=>freestanding =>freestanding
namespace ziemlichlangernamespace namespace somenamespace
{ {
int i = 0; int i = 0;
//TEST //TEST

View file

@ -8,10 +8,19 @@
* *
* Contributors: * Contributors:
* Institute for Software - initial API and implementation * Institute for Software - initial API and implementation
* Sergey Prigogin (Google)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.rewrite.astwriter; 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.IASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.IASTIfStatement;
import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNode;
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;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTVisibilityLabel;
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore; import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
import org.eclipse.cdt.internal.core.dom.rewrite.changegenerator.ChangeGeneratorWriterVisitor; import org.eclipse.cdt.internal.core.dom.rewrite.changegenerator.ChangeGeneratorWriterVisitor;
import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.ASTCommenter; import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.ASTCommenter;
@ -19,9 +28,7 @@ import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap;
/** /**
* ASTWriter main class. Generates source code from <code>IASTNode</code>. * ASTWriter main class. Generates source code from <code>IASTNode</code>.
* Uses a <code>hangeGeneratorWriterVisitor</code> to generate the code for the given nodes. * Uses a {@link ChangeGeneratorWriterVisitor} to generate the code for the given nodes.
*
* @see ChangeGeneratorWriterVisitor
* *
* @author Emanuel Graf * @author Emanuel Graf
*/ */
@ -54,18 +61,13 @@ public class ASTWriter {
* @throws ProblemRuntimeException if the node or one of it's children is a <code>IASTProblemNode</code>. * @throws ProblemRuntimeException if the node or one of it's children is a <code>IASTProblemNode</code>.
*/ */
public String write(IASTNode rootNode) throws ProblemRuntimeException { public String write(IASTNode rootNode) throws ProblemRuntimeException {
return write(rootNode, null, new NodeCommentMap()); return write(rootNode, new NodeCommentMap());
}
public String write(IASTNode rootNode, NodeCommentMap commentMap) {
return write(rootNode, null, commentMap);
} }
/** /**
* Generates the source code representing this node including comments. * Generates the source code representing this node including comments.
* *
* @param rootNode Node to write. * @param rootNode Node to write.
* @param fileScope
* @param commentMap Node Comment Map <code>ASTCommenter</code> * @param commentMap Node Comment Map <code>ASTCommenter</code>
* @return A <code>String</code> representing the source code for the node. * @return A <code>String</code> representing the source code for the node.
* @throws ProblemRuntimeException if the node or one of it's children is * @throws ProblemRuntimeException if the node or one of it's children is
@ -73,17 +75,95 @@ public class ASTWriter {
* *
* @see ASTCommenter#getCommentedNodeMap(org.eclipse.cdt.core.dom.ast.IASTTranslationUnit) * @see ASTCommenter#getCommentedNodeMap(org.eclipse.cdt.core.dom.ast.IASTTranslationUnit)
*/ */
public String write(IASTNode rootNode, String fileScope, NodeCommentMap commentMap) public String write(IASTNode rootNode, NodeCommentMap commentMap)
throws ProblemRuntimeException { throws ProblemRuntimeException {
ChangeGeneratorWriterVisitor transformationVisitor = new ChangeGeneratorWriterVisitor( ChangeGeneratorWriterVisitor writer = new ChangeGeneratorWriterVisitor(
modificationStore, givenIndentation, fileScope, commentMap); modificationStore, givenIndentation, null, commentMap);
if (rootNode != null) { if (rootNode != null) {
rootNode.accept(transformationVisitor); rootNode.accept(writer);
} }
return transformationVisitor.toString(); return writer.toString();
} }
public void setModificationStore(ASTModificationStore modificationStore) { public void setModificationStore(ASTModificationStore modificationStore) {
this.modificationStore = modificationStore; this.modificationStore = modificationStore;
} }
/**
* Returns <code>true</code> if the node should be separated by a blank line from the node
* before it.
*
* @param node The node.
* @return <code>true</code> if the node should be separated by a blank line from the node
* before it.
*/
public static boolean requiresLeadingBlankLine(IASTNode node) {
if (node instanceof ICPPASTTemplateDeclaration) {
node = ((ICPPASTTemplateDeclaration) node).getDeclaration();
}
return node instanceof IASTASMDeclaration ||
node instanceof IASTFunctionDefinition ||
node instanceof ICPPASTVisibilityLabel;
}
/**
* Returns <code>true</code> if the node should be separated by a blank line from the node
* after it.
*
* @param node The node.
* @return <code>true</code> if the node should be separated by a blank line from the node
* after it.
*/
public static boolean requiresTrailingBlankLine(IASTNode node) {
if (node instanceof ICPPASTNamespaceDefinition)
return true;
if (node instanceof IASTFunctionDefinition)
return true;
if (node instanceof IASTIfStatement) {
IASTIfStatement statement = ((IASTIfStatement) node);
IASTStatement lastClause = statement.getElseClause();
if (lastClause == null)
lastClause = statement.getThenClause();
if (!(lastClause instanceof IASTCompoundStatement) &&
!doNodesHaveSameOffset(lastClause, statement)) {
return true;
}
}
return false;
}
/**
* Returns <code>true</code> if there should be no blank line after this node even if a blank
* line is normally required before the subsequent node.
*
* @param node The node.
* @return <code>true</code> if there should be no blank line after this node.
*/
public static boolean suppressesTrailingBlankLine(IASTNode node) {
return node instanceof ICPPASTVisibilityLabel;
}
/**
* Returns <code>true</code> if the two given nodes should be separated by a blank line.
*
* @param node1 The first node.
* @param node2 The second node.
* @return <code>true</code> if the blank line between the nodes is needed.
*/
public static boolean requireBlankLineInBetween(IASTNode node1, IASTNode node2) {
if (requiresTrailingBlankLine(node1))
return true;
return !suppressesTrailingBlankLine(node1) && requiresLeadingBlankLine(node2);
}
/**
* Returns true if the two given nodes have the same offset. For nodes that are normally
* separated by other tokens this is an indication that they were produced by the same macro
* expansion.
*/
private static boolean doNodesHaveSameOffset(IASTNode node1, IASTNode node2) {
return node1.getFileLocation().getNodeOffset() == node2.getFileLocation().getNodeOffset();
}
} }

View file

@ -9,6 +9,7 @@
* Contributors: * Contributors:
* Institute for Software - initial API and implementation * Institute for Software - initial API and implementation
* Markus Schorn (Wind River Systems) * Markus Schorn (Wind River Systems)
* Sergey Prigogin (Google)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.rewrite.astwriter; package org.eclipse.cdt.internal.core.dom.rewrite.astwriter;
@ -38,15 +39,14 @@ import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap;
/** /**
* Visits all nodes, prints leading comments and handles macro expansions. The * Visits all nodes, prints leading comments and handles macro expansions. The
* source code generation is delegated to severals <code>NodeWriters</code>. * source code generation is delegated to severals {@code NodeWriter}s.
* *
* @see NodeWriter
* @see MacroExpansionHandler * @see MacroExpansionHandler
* *
* @author Emanuel Graf IFS * @author Emanuel Graf IFS
*/ */
public class ASTWriterVisitor extends ASTVisitor { public class ASTWriterVisitor extends ASTVisitor {
protected Scribe scribe = new Scribe(); protected final Scribe scribe = new Scribe();
protected NodeCommentMap commentMap; protected NodeCommentMap commentMap;
protected ExpressionWriter expWriter; protected ExpressionWriter expWriter;
protected DeclSpecWriter declSpecWriter; protected DeclSpecWriter declSpecWriter;
@ -57,6 +57,9 @@ public class ASTWriterVisitor extends ASTVisitor {
protected NameWriter nameWriter; protected NameWriter nameWriter;
protected TemplateParameterWriter tempParameterWriter; protected TemplateParameterWriter tempParameterWriter;
protected MacroExpansionHandler macroHandler; protected MacroExpansionHandler macroHandler;
private boolean insertLeadingBlankLine;
private boolean suppressLeadingBlankLine;
private boolean spaceNeededBeforeName;
{ {
shouldVisitExpressions = true; shouldVisitExpressions = true;
@ -83,6 +86,7 @@ public class ASTWriterVisitor extends ASTVisitor {
scribe.setGivenIndentation(givenIndentation); scribe.setGivenIndentation(givenIndentation);
init(commentMap); init(commentMap);
this.commentMap = commentMap; this.commentMap = commentMap;
this.suppressLeadingBlankLine = true;
} }
private void init(NodeCommentMap commentMap) { private void init(NodeCommentMap commentMap) {
@ -135,6 +139,10 @@ public class ASTWriterVisitor extends ASTVisitor {
@Override @Override
public int visit(IASTName name) { public int visit(IASTName name) {
if (spaceNeededBeforeName && name.getSimpleID().length != 0) {
scribe.printSpace();
spaceNeededBeforeName = false;
}
writeLeadingComments(name); writeLeadingComments(name);
if (!macroHandler.checkisMacroExpansionNode(name)) { if (!macroHandler.checkisMacroExpansionNode(name)) {
nameWriter.writeName(name); nameWriter.writeName(name);
@ -166,24 +174,31 @@ public class ASTWriterVisitor extends ASTVisitor {
@Override @Override
public int visit(IASTStatement statement) { public int visit(IASTStatement statement) {
insertBlankLineIfNeeded(statement);
writeLeadingComments(statement); writeLeadingComments(statement);
if (macroHandler.isStatementWithMixedLocation(statement) && try {
!(statement instanceof IASTCompoundStatement)) { if (macroHandler.isStatementWithMixedLocation(statement) &&
return statementWriter.writeMixedStatement(statement); !(statement instanceof IASTCompoundStatement)) {
return statementWriter.writeMixedStatement(statement);
}
if (macroHandler.checkisMacroExpansionNode(statement)) {
return ASTVisitor.PROCESS_SKIP;
}
return statementWriter.writeStatement(statement, true);
} finally {
setLeadingBlankLineFlags(statement);
} }
if (macroHandler.checkisMacroExpansionNode(statement)) {
return ASTVisitor.PROCESS_SKIP;
}
return statementWriter.writeStatement(statement, true);
} }
@Override @Override
public int visit(IASTDeclaration declaration) { public int visit(IASTDeclaration declaration) {
insertBlankLineIfNeeded(declaration);
writeLeadingComments(declaration); writeLeadingComments(declaration);
if (!macroHandler.checkisMacroExpansionNode(declaration)) { if (!macroHandler.checkisMacroExpansionNode(declaration)) {
declarationWriter.writeDeclaration(declaration); declarationWriter.writeDeclaration(declaration);
setLeadingBlankLineFlags(declaration);
} }
return ASTVisitor.PROCESS_SKIP; return ASTVisitor.PROCESS_SKIP;
} }
@Override @Override
@ -219,9 +234,7 @@ public class ASTWriterVisitor extends ASTVisitor {
parameterDeclaration.getDeclSpecifier().accept(this); parameterDeclaration.getDeclSpecifier().accept(this);
IASTDeclarator declarator = getParameterDeclarator(parameterDeclaration); IASTDeclarator declarator = getParameterDeclarator(parameterDeclaration);
if (getParameterName(declarator).toString().length() != 0) { spaceNeededBeforeName = true;
scribe.printSpaces(1);
}
declarator.accept(this); declarator.accept(this);
} }
return ASTVisitor.PROCESS_SKIP; return ASTVisitor.PROCESS_SKIP;
@ -237,9 +250,11 @@ public class ASTWriterVisitor extends ASTVisitor {
@Override @Override
public int visit(ICPPASTNamespaceDefinition namespace) { public int visit(ICPPASTNamespaceDefinition namespace) {
insertBlankLineIfNeeded(namespace);
writeLeadingComments(namespace); writeLeadingComments(namespace);
if (!macroHandler.checkisMacroExpansionNode(namespace)) { if (!macroHandler.checkisMacroExpansionNode(namespace)) {
declarationWriter.writeDeclaration(namespace); declarationWriter.writeDeclaration(namespace);
setLeadingBlankLineFlags(namespace);
} }
return ASTVisitor.PROCESS_SKIP; return ASTVisitor.PROCESS_SKIP;
} }
@ -257,4 +272,38 @@ public class ASTWriterVisitor extends ASTVisitor {
scribe.cleanCache(); scribe.cleanCache();
macroHandler.reset(); macroHandler.reset();
} }
private void insertBlankLineIfNeeded(IASTNode node) {
if (!suppressLeadingBlankLine &&
(insertLeadingBlankLine || ASTWriter.requiresLeadingBlankLine(node))) {
scribe.newLine();
}
insertLeadingBlankLine = false;
suppressLeadingBlankLine = false;
}
private void setLeadingBlankLineFlags(IASTNode node) {
insertLeadingBlankLine = ASTWriter.requiresTrailingBlankLine(node);
suppressLeadingBlankLine = ASTWriter.suppressesTrailingBlankLine(node);
}
public boolean isSuppressLeadingBlankLine() {
return suppressLeadingBlankLine;
}
public void setSuppressLeadingBlankLine(boolean value) {
this.suppressLeadingBlankLine = value;
}
public boolean isSpaceNeededBeforeName() {
return spaceNeededBeforeName;
}
public void setSpaceNeededBeforeName(boolean value) {
this.spaceNeededBeforeName = value;
}
public void newLine() {
scribe.newLine();
}
} }

View file

@ -11,7 +11,6 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.rewrite.astwriter; package org.eclipse.cdt.internal.core.dom.rewrite.astwriter;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier; import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
@ -62,12 +61,12 @@ public class DeclSpecWriter extends NodeWriter {
private static final String ENUM = "enum "; //$NON-NLS-1$ private static final String ENUM = "enum "; //$NON-NLS-1$
private static final String _BOOL = "_Bool"; //$NON-NLS-1$ private static final String _BOOL = "_Bool"; //$NON-NLS-1$
public DeclSpecWriter(Scribe scribe, ASTVisitor visitor, NodeCommentMap commentMap) { public DeclSpecWriter(Scribe scribe, ASTWriterVisitor visitor, NodeCommentMap commentMap) {
super(scribe, visitor, commentMap); super(scribe, visitor, commentMap);
} }
protected void writeDelcSpec(IASTDeclSpecifier declSpec) { protected void writeDelcSpec(IASTDeclSpecifier declSpec) {
// Write general DelcSpec Keywords // Write general DelcSpec Keywords
writeDeclSpec(declSpec); writeDeclSpec(declSpec);
if (declSpec instanceof ICPPASTDeclSpecifier) { if (declSpec instanceof ICPPASTDeclSpecifier) {
writeCPPDeclSpec((ICPPASTDeclSpecifier) declSpec); writeCPPDeclSpec((ICPPASTDeclSpecifier) declSpec);
@ -129,7 +128,6 @@ public class DeclSpecWriter extends NodeWriter {
break; break;
} }
System.err.println("Unknown specifier type: " + type); //$NON-NLS-1$
throw new IllegalArgumentException("Unknown specifier type: " + type); //$NON-NLS-1$ throw new IllegalArgumentException("Unknown specifier type: " + type); //$NON-NLS-1$
} }
@ -152,7 +150,7 @@ public class DeclSpecWriter extends NodeWriter {
} }
private void writeNamedTypeSpecifier(ICPPASTNamedTypeSpecifier namedSpc) { private void writeNamedTypeSpecifier(ICPPASTNamedTypeSpecifier namedSpc) {
if ( namedSpc.isTypename() ){ if (namedSpc.isTypename()) {
scribe.print(TYPENAME); scribe.print(TYPENAME);
} }
namedSpc.getName().accept(visitor); namedSpc.getName().accept(visitor);
@ -179,8 +177,7 @@ public class DeclSpecWriter extends NodeWriter {
return CLASS_SPACE; return CLASS_SPACE;
default: default:
System.err.println("Unknown ElaboratedType: " + kind); //$NON-NLS-1$ throw new IllegalArgumentException("Unknown elaborated type: " + kind); //$NON-NLS-1$
throw new IllegalArgumentException("Unknown ElaboratedType: " + kind); //$NON-NLS-1$
} }
} }
@ -254,12 +251,13 @@ public class DeclSpecWriter extends NodeWriter {
hasTrailingComments = hasTrailingComments(baseSpecifiers[baseSpecifiers.length-1].getName()); hasTrailingComments = hasTrailingComments(baseSpecifiers[baseSpecifiers.length-1].getName());
} }
} }
if (!hasTrailingComments){ if (!hasTrailingComments) {
scribe.newLine(); scribe.newLine();
} }
scribe.print('{'); scribe.print('{');
scribe.newLine(); scribe.newLine();
scribe.incrementIndentationLevel(); scribe.incrementIndentationLevel();
visitor.setSuppressLeadingBlankLine(true);
IASTDeclaration[] decls = getMembers(compDeclSpec); IASTDeclaration[] decls = getMembers(compDeclSpec);
if (decls.length > 0) { if (decls.length > 0) {
@ -306,8 +304,7 @@ public class DeclSpecWriter extends NodeWriter {
case ICPPASTCompositeTypeSpecifier.k_class: case ICPPASTCompositeTypeSpecifier.k_class:
return CLASS; return CLASS;
default: default:
System.err.println("Unknow Specifiertype: " + key); //$NON-NLS-1$ throw new IllegalArgumentException("Unknown type specifier: " + key); //$NON-NLS-1$
throw new IllegalArgumentException("Unknow Specifiertype: " + key); //$NON-NLS-1$
} }
} }
@ -318,8 +315,7 @@ public class DeclSpecWriter extends NodeWriter {
case IASTCompositeTypeSpecifier.k_union: case IASTCompositeTypeSpecifier.k_union:
return UNION; return UNION;
default: default:
System.err.println("Unknow Specifiertype: " + key); //$NON-NLS-1$ throw new IllegalArgumentException("Unknown type specifier: " + key); //$NON-NLS-1$
throw new IllegalArgumentException("Unknow Specifiertype: " + key); //$NON-NLS-1$
} }
} }
@ -368,7 +364,7 @@ public class DeclSpecWriter extends NodeWriter {
private void printQualifiers(IASTSimpleDeclSpecifier simpDeclSpec) { private void printQualifiers(IASTSimpleDeclSpecifier simpDeclSpec) {
if (simpDeclSpec.isSigned()) { if (simpDeclSpec.isSigned()) {
scribe.printStringSpace(SIGNED); scribe.printStringSpace(SIGNED);
} else if (simpDeclSpec.isUnsigned()){ } else if (simpDeclSpec.isUnsigned()) {
scribe.printStringSpace(UNSIGNED); scribe.printStringSpace(UNSIGNED);
} }

View file

@ -9,10 +9,10 @@
* Contributors: * Contributors:
* Institute for Software - initial API and implementation * Institute for Software - initial API and implementation
* Markus Schorn (Wind River Systems) * Markus Schorn (Wind River Systems)
* Sergey Prigogin (Google)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.rewrite.astwriter; package org.eclipse.cdt.internal.core.dom.rewrite.astwriter;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTASMDeclaration; import org.eclipse.cdt.core.dom.ast.IASTASMDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
@ -47,7 +47,7 @@ import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap;
* @see IASTDeclaration * @see IASTDeclaration
* @author Emanuel Graf IFS * @author Emanuel Graf IFS
*/ */
public class DeclarationWriter extends NodeWriter{ public class DeclarationWriter extends NodeWriter {
private static final String ASM_END = ")"; //$NON-NLS-1$ private static final String ASM_END = ")"; //$NON-NLS-1$
private static final String ASM_START = "asm("; //$NON-NLS-1$ private static final String ASM_START = "asm("; //$NON-NLS-1$
private static final String TEMPLATE_DECLARATION = "template<"; //$NON-NLS-1$ private static final String TEMPLATE_DECLARATION = "template<"; //$NON-NLS-1$
@ -57,7 +57,7 @@ public class DeclarationWriter extends NodeWriter{
private static final String USING = "using "; //$NON-NLS-1$ private static final String USING = "using "; //$NON-NLS-1$
private boolean printSemicolon; private boolean printSemicolon;
public DeclarationWriter(Scribe scribe, ASTVisitor visitor, NodeCommentMap commentMap) { public DeclarationWriter(Scribe scribe, ASTWriterVisitor visitor, NodeCommentMap commentMap) {
super(scribe, visitor, commentMap); super(scribe, visitor, commentMap);
} }
@ -72,6 +72,7 @@ public class DeclarationWriter extends NodeWriter{
writeASMDeclatation((IASTASMDeclaration) declaration); writeASMDeclatation((IASTASMDeclaration) declaration);
} else if (declaration instanceof IASTFunctionDefinition) { } else if (declaration instanceof IASTFunctionDefinition) {
writeFunctionDefinition((IASTFunctionDefinition) declaration); writeFunctionDefinition((IASTFunctionDefinition) declaration);
addNewLine = false;
} else if (declaration instanceof IASTProblemDeclaration) { } else if (declaration instanceof IASTProblemDeclaration) {
throw new ProblemRuntimeException((IASTProblemDeclaration) declaration); throw new ProblemRuntimeException((IASTProblemDeclaration) declaration);
} else if (declaration instanceof IASTSimpleDeclaration) { } else if (declaration instanceof IASTSimpleDeclaration) {
@ -98,17 +99,17 @@ public class DeclarationWriter extends NodeWriter{
} }
if (hasTrailingComments(declaration)) { if (hasTrailingComments(declaration)) {
writeTrailingComments(declaration, addNewLine); writeTrailingComments(declaration, false);
} else if (addNewLine) { }
if (addNewLine) {
scribe.newLine(); scribe.newLine();
} }
if (hasFreestandingComments(declaration)) { if (hasFreestandingComments(declaration)) {
if (declaration instanceof IASTFunctionDefinition) {
scribe.newLine();
}
writeFreeStandingComments(declaration); writeFreeStandingComments(declaration);
} }
if (declaration instanceof ICPPASTUsingDirective) {
scribe.newLine();
}
} }
private void writeVisibilityLabel(ICPPASTVisibilityLabel visiblityLabel) { private void writeVisibilityLabel(ICPPASTVisibilityLabel visiblityLabel) {
@ -181,17 +182,18 @@ public class DeclarationWriter extends NodeWriter{
if (!hasTrailingComments(namespaceDefinition.getName())) { if (!hasTrailingComments(namespaceDefinition.getName())) {
scribe.newLine(); scribe.newLine();
} }
scribe.printLBrace(); scribe.print('{');
scribe.newLine(); scribe.newLine(2);
writeDeclarationsInNamespace(namespaceDefinition, namespaceDefinition.getDeclarations()); writeDeclarationsInNamespace(namespaceDefinition, namespaceDefinition.getDeclarations());
if (hasFreestandingComments(namespaceDefinition)) { if (hasFreestandingComments(namespaceDefinition)) {
writeFreeStandingComments(namespaceDefinition); writeFreeStandingComments(namespaceDefinition);
} }
scribe.printRBrace(); scribe.newLine();
scribe.print('}');
if (hasTrailingComments(namespaceDefinition)) { if (hasTrailingComments(namespaceDefinition)) {
writeTrailingComments(namespaceDefinition); writeTrailingComments(namespaceDefinition);
}else{ } else {
scribe.newLine(); scribe.newLine();
} }
} }
@ -211,7 +213,7 @@ public class DeclarationWriter extends NodeWriter{
} }
private void writeLinkageSpecification(ICPPASTLinkageSpecification linkageSpecification) { private void writeLinkageSpecification(ICPPASTLinkageSpecification linkageSpecification) {
scribe.print( EXTERN); scribe.print(EXTERN);
scribe.print(linkageSpecification.getLiteral()); scribe.print(linkageSpecification.getLiteral());
scribe.printSpaces(1); scribe.printSpaces(1);
@ -266,10 +268,10 @@ public class DeclarationWriter extends NodeWriter{
if (declSpecifier instanceof IASTSimpleDeclSpecifier) { if (declSpecifier instanceof IASTSimpleDeclSpecifier) {
IASTSimpleDeclSpecifier simDeclSpec = (IASTSimpleDeclSpecifier) declSpecifier; IASTSimpleDeclSpecifier simDeclSpec = (IASTSimpleDeclSpecifier) declSpecifier;
if (simDeclSpec.getType() != IASTSimpleDeclSpecifier.t_unspecified) { if (simDeclSpec.getType() != IASTSimpleDeclSpecifier.t_unspecified) {
scribe.printSpace(); visitor.setSpaceNeededBeforeName(true);
} }
}else { } else {
scribe.printSpace(); visitor.setSpaceNeededBeforeName(true);
} }
IASTDeclarator declarator = ASTQueries.findOutermostDeclarator(funcDef.getDeclarator()); IASTDeclarator declarator = ASTQueries.findOutermostDeclarator(funcDef.getDeclarator());
declarator.accept(visitor); declarator.accept(visitor);
@ -325,10 +327,16 @@ public class DeclarationWriter extends NodeWriter{
} }
if (decls.length > 0) { if (decls.length > 0) {
if (!noSpace) { if (decls.length == 1) {
scribe.printSpace(); if (!noSpace)
visitor.setSpaceNeededBeforeName(true);
decls[0].accept(visitor);
} else {
if (!noSpace) {
scribe.printSpace();
}
writeNodeList(decls);
} }
writeNodeList(decls);
} }
printSemicolon(); printSemicolon();

View file

@ -12,7 +12,6 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.rewrite.astwriter; package org.eclipse.cdt.internal.core.dom.rewrite.astwriter;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator; import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTArrayModifier; import org.eclipse.cdt.core.dom.ast.IASTArrayModifier;
import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
@ -40,14 +39,12 @@ import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap;
* @author Emanuel Graf IFS * @author Emanuel Graf IFS
*/ */
public class DeclaratorWriter extends NodeWriter { public class DeclaratorWriter extends NodeWriter {
private static final String AMPERSAND_SPACE = "& "; //$NON-NLS-1$ private static final String AMPERSAND_AMPERSAND = "&&"; //$NON-NLS-1$
private static final String AMPERSAND_AMPERSAND_SPACE = "&& "; //$NON-NLS-1$
private static final String STAR_SPACE = "* "; //$NON-NLS-1$
private static final String PURE_VIRTUAL = " = 0"; //$NON-NLS-1$ private static final String PURE_VIRTUAL = " = 0"; //$NON-NLS-1$
private static final String MUTABLE = "mutable"; //$NON-NLS-1$ private static final String MUTABLE = "mutable"; //$NON-NLS-1$
private static final String ARROW_OPERATOR = "->"; //$NON-NLS-1$ private static final String ARROW_OPERATOR = "->"; //$NON-NLS-1$
public DeclaratorWriter(Scribe scribe, ASTVisitor visitor, NodeCommentMap commentMap) { public DeclaratorWriter(Scribe scribe, ASTWriterVisitor visitor, NodeCommentMap commentMap) {
super(scribe, visitor, commentMap); super(scribe, visitor, commentMap);
} }
@ -64,6 +61,7 @@ public class DeclaratorWriter extends NodeWriter {
writeDefaultDeclarator(declarator); writeDefaultDeclarator(declarator);
} }
visitor.setSpaceNeededBeforeName(false);
if (hasTrailingComments(declarator)) { if (hasTrailingComments(declarator)) {
writeTrailingComments(declarator, false); writeTrailingComments(declarator, false);
} }
@ -119,6 +117,10 @@ public class DeclaratorWriter extends NodeWriter {
private void writeNestedDeclarator(IASTDeclarator funcDec) { private void writeNestedDeclarator(IASTDeclarator funcDec) {
IASTDeclarator nestedDeclarator = funcDec.getNestedDeclarator(); IASTDeclarator nestedDeclarator = funcDec.getNestedDeclarator();
if (nestedDeclarator != null) { if (nestedDeclarator != null) {
if (visitor.isSpaceNeededBeforeName()) {
scribe.printSpace();
visitor.setSpaceNeededBeforeName(false);
}
scribe.print('('); scribe.print('(');
nestedDeclarator.accept(visitor); nestedDeclarator.accept(visitor);
scribe.print(')'); scribe.print(')');
@ -160,10 +162,10 @@ public class DeclaratorWriter extends NodeWriter {
} }
} }
protected void writeParameterDeclarations(IASTStandardFunctionDeclarator funcDec, IASTParameterDeclaration[] paraDecls) { protected void writeParameterDeclarations(IASTStandardFunctionDeclarator funcDec, IASTParameterDeclaration[] paramDecls) {
writeNodeList(paraDecls); writeNodeList(paramDecls);
if (funcDec.takesVarArgs()) { if (funcDec.takesVarArgs()) {
if (paraDecls.length > 0) { if (paramDecls.length > 0) {
scribe.print(COMMA_SPACE); scribe.print(COMMA_SPACE);
} }
scribe.print(VAR_ARGS); scribe.print(VAR_ARGS);
@ -175,7 +177,7 @@ public class DeclaratorWriter extends NodeWriter {
ICPPASTPointerToMember pointerToMemberOp = (ICPPASTPointerToMember) operator; ICPPASTPointerToMember pointerToMemberOp = (ICPPASTPointerToMember) operator;
if (pointerToMemberOp.getName() != null) { if (pointerToMemberOp.getName() != null) {
pointerToMemberOp.getName().accept(visitor); pointerToMemberOp.getName().accept(visitor);
scribe.print(STAR_SPACE); scribe.print('*');
} }
} else { } else {
scribe.print('*'); scribe.print('*');
@ -198,9 +200,9 @@ public class DeclaratorWriter extends NodeWriter {
writePointer(pointOp); writePointer(pointOp);
} else if (operator instanceof ICPPASTReferenceOperator) { } else if (operator instanceof ICPPASTReferenceOperator) {
if (((ICPPASTReferenceOperator) operator).isRValueReference()) { if (((ICPPASTReferenceOperator) operator).isRValueReference()) {
scribe.print(AMPERSAND_AMPERSAND_SPACE); scribe.print(AMPERSAND_AMPERSAND);
} else { } else {
scribe.print(AMPERSAND_SPACE); scribe.print('&');
} }
} }
} }

View file

@ -12,7 +12,6 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.rewrite.astwriter; package org.eclipse.cdt.internal.core.dom.rewrite.astwriter;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTArraySubscriptExpression; import org.eclipse.cdt.core.dom.ast.IASTArraySubscriptExpression;
import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression; import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression;
import org.eclipse.cdt.core.dom.ast.IASTCastExpression; import org.eclipse.cdt.core.dom.ast.IASTCastExpression;
@ -115,7 +114,7 @@ public class ExpressionWriter extends NodeWriter{
private static final String THIS = "this"; //$NON-NLS-1$ private static final String THIS = "this"; //$NON-NLS-1$
private final MacroExpansionHandler macroHandler; private final MacroExpansionHandler macroHandler;
public ExpressionWriter(Scribe scribe, ASTVisitor visitor, MacroExpansionHandler macroHandler, NodeCommentMap commentMap) { public ExpressionWriter(Scribe scribe, ASTWriterVisitor visitor, MacroExpansionHandler macroHandler, NodeCommentMap commentMap) {
super(scribe, visitor, commentMap); super(scribe, visitor, commentMap);
this.macroHandler = macroHandler; this.macroHandler = macroHandler;
} }

View file

@ -12,7 +12,6 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.rewrite.astwriter; package org.eclipse.cdt.internal.core.dom.rewrite.astwriter;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTEqualsInitializer; import org.eclipse.cdt.core.dom.ast.IASTEqualsInitializer;
import org.eclipse.cdt.core.dom.ast.IASTInitializer; import org.eclipse.cdt.core.dom.ast.IASTInitializer;
import org.eclipse.cdt.core.dom.ast.IASTInitializerClause; import org.eclipse.cdt.core.dom.ast.IASTInitializerClause;
@ -36,7 +35,7 @@ import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap;
*/ */
public class InitializerWriter extends NodeWriter{ public class InitializerWriter extends NodeWriter{
public InitializerWriter(Scribe scribe, ASTVisitor visitor, NodeCommentMap commentMap) { public InitializerWriter(Scribe scribe, ASTWriterVisitor visitor, NodeCommentMap commentMap) {
super(scribe, visitor, commentMap); super(scribe, visitor, commentMap);
} }

View file

@ -7,11 +7,10 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* Institute for Software - initial API and implementation * Institute for Software - initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.rewrite.astwriter; package org.eclipse.cdt.internal.core.dom.rewrite.astwriter;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IBinding;
@ -36,7 +35,7 @@ public class NameWriter extends NodeWriter {
* @param scribe * @param scribe
* @param visitor * @param visitor
*/ */
public NameWriter(Scribe scribe, ASTVisitor visitor, NodeCommentMap commentMap) { public NameWriter(Scribe scribe, ASTWriterVisitor visitor, NodeCommentMap commentMap) {
super(scribe, visitor, commentMap); super(scribe, visitor, commentMap);
} }
@ -45,7 +44,7 @@ public class NameWriter extends NodeWriter {
writeTempalteId((ICPPASTTemplateId) name); writeTempalteId((ICPPASTTemplateId) name);
} else if (name instanceof ICPPASTConversionName) { } else if (name instanceof ICPPASTConversionName) {
scribe.print(OPERATOR); scribe.print(OPERATOR);
((ICPPASTConversionName)name).getTypeId().accept(visitor); ((ICPPASTConversionName) name).getTypeId().accept(visitor);
} else if (name instanceof ICPPASTQualifiedName){ } else if (name instanceof ICPPASTQualifiedName){
writeQualifiedName((ICPPASTQualifiedName) name); writeQualifiedName((ICPPASTQualifiedName) name);
} else { } else {

View file

@ -13,7 +13,6 @@ package org.eclipse.cdt.internal.core.dom.rewrite.astwriter;
import java.util.ArrayList; import java.util.ArrayList;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTComment; import org.eclipse.cdt.core.dom.ast.IASTComment;
import org.eclipse.cdt.core.dom.ast.IASTCopyLocation; import org.eclipse.cdt.core.dom.ast.IASTCopyLocation;
import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNode;
@ -28,7 +27,7 @@ import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap;
*/ */
public class NodeWriter { public class NodeWriter {
protected Scribe scribe; protected Scribe scribe;
protected ASTVisitor visitor; protected ASTWriterVisitor visitor;
protected NodeCommentMap commentMap; protected NodeCommentMap commentMap;
protected static final String COMMA_SPACE = ", "; //$NON-NLS-1$ protected static final String COMMA_SPACE = ", "; //$NON-NLS-1$
protected static final String EQUALS = " = "; //$NON-NLS-1$ protected static final String EQUALS = " = "; //$NON-NLS-1$
@ -61,7 +60,7 @@ public class NodeWriter {
protected static final String COLON_COLON = "::"; //$NON-NLS-1$ protected static final String COLON_COLON = "::"; //$NON-NLS-1$
protected static final String COLON_SPACE = ": "; //$NON-NLS-1$ protected static final String COLON_SPACE = ": "; //$NON-NLS-1$
public NodeWriter(Scribe scribe, ASTVisitor visitor, NodeCommentMap commentMap) { public NodeWriter(Scribe scribe, ASTWriterVisitor visitor, NodeCommentMap commentMap) {
super(); super();
this.scribe = scribe; this.scribe = scribe;
this.visitor = visitor; this.visitor = visitor;
@ -89,12 +88,17 @@ public class NodeWriter {
} }
protected void writeTrailingComments(IASTNode node, boolean newLine) { protected void writeTrailingComments(IASTNode node, boolean newLine) {
boolean first = true;
for (IASTComment comment : getTrailingComments(node)) { for (IASTComment comment : getTrailingComments(node)) {
scribe.printSpace(); if (!first) {
scribe.print(comment.getComment());
if (newLine) {
scribe.newLine(); scribe.newLine();
} }
scribe.printSpace();
scribe.print(comment.getComment());
first = false;
}
if (newLine) {
scribe.newLine();
} }
} }

View file

@ -7,7 +7,7 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* Institute for Software - initial API and implementation * Institute for Software - initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.rewrite.astwriter; package org.eclipse.cdt.internal.core.dom.rewrite.astwriter;
@ -20,17 +20,18 @@ package org.eclipse.cdt.internal.core.dom.rewrite.astwriter;
*/ */
public class Scribe { public class Scribe {
private int indentationLevel = 0; private int indentationLevel = 0;
private int indentationSize = 4; //HSR tcorbat: could be a tab character too - this is not a very elegant solution // Any positive indentation size is good enough since the code is going to be formatted anyway.
private int indentationSize = 4;
private StringBuilder buffer = new StringBuilder(); private StringBuilder buffer = new StringBuilder();
private boolean isAtLineBeginning = true; private boolean isAtLineBeginning = true;
private String newLine = System.getProperty("line.separator"); //$NON-NLS-1$ private String newLine = System.getProperty("line.separator"); //$NON-NLS-1$
private String givenIndentation = null; private String givenIndentation;
private boolean noNewLine = false; private boolean skipLineBreaks;
private boolean noSemicolon = false; private boolean skipSemicolons;
public void newLine() { public void newLine() {
if (!noNewLine) { if (!skipLineBreaks) {
isAtLineBeginning = true; isAtLineBeginning = true;
buffer.append(getNewline()); buffer.append(getNewline());
} }
@ -88,15 +89,15 @@ public class Scribe {
} }
public void noSemicolon() { public void noSemicolon() {
noSemicolon = true; skipSemicolons = true;
} }
public void printSemicolon() { public void printSemicolon() {
if (!noSemicolon) { if (!skipSemicolons) {
indentIfNewLine(); indentIfNewLine();
buffer.append(';'); buffer.append(';');
} else { } else {
noSemicolon = false; skipSemicolons = false;
} }
} }
@ -105,7 +106,7 @@ public class Scribe {
return buffer.toString(); return buffer.toString();
} }
public void print (char code) { public void print(char code) {
indentIfNewLine(); indentIfNewLine();
buffer.append(code); buffer.append(code);
} }
@ -126,7 +127,7 @@ public class Scribe {
} }
/** /**
* Prints a { to the Buffer an increases the indentation level. * Prints a { to the buffer an increases the indentation level.
*/ */
public void printLBrace() { public void printLBrace() {
print('{'); print('{');
@ -134,7 +135,7 @@ public class Scribe {
} }
/** /**
* Prints a } to the Buffer an decrease the indentation level. * Prints a } to the buffer an decrease the indentation level.
*/ */
public void printRBrace() { public void printRBrace() {
--indentationLevel; --indentationLevel;
@ -152,11 +153,11 @@ public class Scribe {
} }
protected void noNewLines() { protected void noNewLines() {
noNewLine = true; skipLineBreaks = true;
} }
protected void newLines() { protected void newLines() {
noNewLine = false; skipLineBreaks = false;
} }
public void newLine(int i) { public void newLine(int i) {

View file

@ -56,17 +56,17 @@ import org.eclipse.core.resources.IFile;
public class StatementWriter extends NodeWriter { public class StatementWriter extends NodeWriter {
private static final String DEFAULT = "default:"; //$NON-NLS-1$ private static final String DEFAULT = "default:"; //$NON-NLS-1$
private static final String CASE = "case "; //$NON-NLS-1$ private static final String CASE = "case "; //$NON-NLS-1$
private static final String WHILE = "while("; //$NON-NLS-1$ private static final String WHILE = "while ("; //$NON-NLS-1$
private static final String TRY = "try "; //$NON-NLS-1$ private static final String TRY = "try "; //$NON-NLS-1$
private static final String CATCH = "catch("; //$NON-NLS-1$ private static final String CATCH = "catch ("; //$NON-NLS-1$
private static final String RETURN = "return"; //$NON-NLS-1$ private static final String RETURN = "return"; //$NON-NLS-1$
private static final String GOTO = "goto "; //$NON-NLS-1$ private static final String GOTO = "goto "; //$NON-NLS-1$
private static final String CONTINUE = "continue"; //$NON-NLS-1$ private static final String CONTINUE = "continue"; //$NON-NLS-1$
private static final String BREAK = "break"; //$NON-NLS-1$ private static final String BREAK = "break"; //$NON-NLS-1$
private static final String ELSE = "else"; //$NON-NLS-1$ private static final String ELSE = "else"; //$NON-NLS-1$
private static final String IF = "if("; //$NON-NLS-1$ private static final String IF = "if ("; //$NON-NLS-1$
private static final String FOR = "for("; //$NON-NLS-1$ private static final String FOR = "for ("; //$NON-NLS-1$
private static final String DO_WHILE = " while("; //$NON-NLS-1$ private static final String DO_WHILE = " while ("; //$NON-NLS-1$
private static final String DO = "do"; //$NON-NLS-1$ private static final String DO = "do"; //$NON-NLS-1$
private static final String SWITCH_BRACKET = "switch ("; //$NON-NLS-1$ private static final String SWITCH_BRACKET = "switch ("; //$NON-NLS-1$
private boolean compoundNoNewLine = false; private boolean compoundNoNewLine = false;
@ -74,14 +74,15 @@ public class StatementWriter extends NodeWriter {
private boolean decrementIndentationLevelOneMore = false; private boolean decrementIndentationLevelOneMore = false;
private final DeclarationWriter declWriter; private final DeclarationWriter declWriter;
public StatementWriter(Scribe scribe, ASTVisitor visitor, NodeCommentMap commentMap) { public StatementWriter(Scribe scribe, ASTWriterVisitor visitor, NodeCommentMap commentMap) {
super(scribe, visitor, commentMap); super(scribe, visitor, commentMap);
declWriter = new DeclarationWriter(scribe, visitor, commentMap); declWriter = new DeclarationWriter(scribe, visitor, commentMap);
} }
/** /**
* Prints a statement.
* *
* @param statement * @param statement the statement
* @param newLine if true print a newline if statement usually have one. * @param newLine if true print a newline if statement usually have one.
* @return {@link ASTVisitor#PROCESS_SKIP} * @return {@link ASTVisitor#PROCESS_SKIP}
*/ */
@ -132,7 +133,7 @@ public class StatementWriter extends NodeWriter {
writeIfStatement((IASTIfStatement) statement); writeIfStatement((IASTIfStatement) statement);
newLine = false; newLine = false;
} else if (statement instanceof IASTWhileStatement) { } else if (statement instanceof IASTWhileStatement) {
writeWhileStatement( (IASTWhileStatement) statement ); writeWhileStatement((IASTWhileStatement) statement);
newLine = false; newLine = false;
} else if (statement instanceof IASTForStatement) { } else if (statement instanceof IASTForStatement) {
writeForStatement((IASTForStatement) statement); writeForStatement((IASTForStatement) statement);
@ -173,12 +174,12 @@ public class StatementWriter extends NodeWriter {
scribe.printSemicolon(); scribe.printSemicolon();
} }
private void writeForStatement(IASTForStatement forStatment) { private void writeForStatement(IASTForStatement forStatement) {
scribe.noNewLines(); scribe.noNewLines();
scribe.print(FOR); scribe.print(FOR);
writeStatement(forStatment.getInitializerStatement(),false); writeStatement(forStatement.getInitializerStatement(),false);
if (forStatment instanceof ICPPASTForStatement) { if (forStatement instanceof ICPPASTForStatement) {
ICPPASTForStatement cppForStatment = (ICPPASTForStatement) forStatment; ICPPASTForStatement cppForStatment = (ICPPASTForStatement) forStatement;
IASTDeclaration cppConditionDeclaration = cppForStatment.getConditionDeclaration(); IASTDeclaration cppConditionDeclaration = cppForStatment.getConditionDeclaration();
if (cppConditionDeclaration == null) { if (cppConditionDeclaration == null) {
visitNodeIfNotNull(cppForStatment.getConditionExpression()); visitNodeIfNotNull(cppForStatment.getConditionExpression());
@ -187,17 +188,17 @@ public class StatementWriter extends NodeWriter {
cppConditionDeclaration.accept(visitor); cppConditionDeclaration.accept(visitor);
} }
} else { } else {
if (forStatment.getConditionExpression() != null) { if (forStatement.getConditionExpression() != null) {
forStatment.getConditionExpression().accept(visitor); forStatement.getConditionExpression().accept(visitor);
scribe.printSemicolon(); scribe.printSemicolon();
} }
} }
visitNodeIfNotNull(forStatment.getIterationExpression()); visitNodeIfNotNull(forStatement.getIterationExpression());
scribe.print(')'); scribe.print(')');
scribe.newLines(); scribe.newLines();
nextCompoundNoNewLine(); nextCompoundNoNewLine();
writeBodyStatement(forStatment.getBody(), false); writeBodyStatement(forStatement.getBody(), false);
} }
private void writeForStatement(ICPPASTRangeBasedForStatement forStatment) { private void writeForStatement(ICPPASTRangeBasedForStatement forStatment) {
@ -418,7 +419,6 @@ public class StatementWriter extends NodeWriter {
scribe.newLine(); scribe.newLine();
statement.accept(visitor); statement.accept(visitor);
scribe.decrementIndentationLevel(); scribe.decrementIndentationLevel();
scribe.newLine();
} }
} }

View file

@ -11,7 +11,6 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.rewrite.astwriter; package org.eclipse.cdt.internal.core.dom.rewrite.astwriter;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration; import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTParameterDeclaration; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTParameterDeclaration;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleTypeTemplateParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleTypeTemplateParameter;
@ -35,7 +34,7 @@ public class TemplateParameterWriter extends NodeWriter {
* @param scribe * @param scribe
* @param visitor * @param visitor
*/ */
public TemplateParameterWriter(Scribe scribe, ASTVisitor visitor, NodeCommentMap commentMap) { public TemplateParameterWriter(Scribe scribe, ASTWriterVisitor visitor, NodeCommentMap commentMap) {
super(scribe, visitor, commentMap); super(scribe, visitor, commentMap);
} }

View file

@ -44,8 +44,7 @@ public class ASTModificationHelper {
T appendedTNode = cast(newNode, clazz); T appendedTNode = cast(newNode, clazz);
if (appendedTNode != null) { if (appendedTNode != null) {
modifiedChildren.add(appendedTNode); modifiedChildren.add(appendedTNode);
} } else if (newNode instanceof ContainerNode) {
else if (newNode instanceof ContainerNode) {
ContainerNode nodeContainer = (ContainerNode) newNode; ContainerNode nodeContainer = (ContainerNode) newNode;
for (IASTNode currentNode : nodeContainer.getNodes()) { for (IASTNode currentNode : nodeContainer.getNodes()) {
T tnode= cast(currentNode, clazz); T tnode= cast(currentNode, clazz);

View file

@ -9,16 +9,23 @@
* Contributors: * Contributors:
* Institute for Software - initial API and implementation * Institute for Software - initial API and implementation
* Markus Schorn (Wind River Systems) * Markus Schorn (Wind River Systems)
* Sergey Prigogin (Google)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.rewrite.changegenerator; package org.eclipse.cdt.internal.core.dom.rewrite.changegenerator;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.ToolFactory;
import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTArrayModifier; import org.eclipse.cdt.core.dom.ast.IASTArrayModifier;
import org.eclipse.cdt.core.dom.ast.IASTComment; import org.eclipse.cdt.core.dom.ast.IASTComment;
import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTDeclarator; import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
@ -31,7 +38,10 @@ import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTStatement; import org.eclipse.cdt.core.dom.ast.IASTStatement;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition;
import org.eclipse.cdt.core.formatter.CodeFormatter;
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;
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind;
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationMap; import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationMap;
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore; import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
import org.eclipse.cdt.internal.core.dom.rewrite.ASTRewriteAnalyzer; import org.eclipse.cdt.internal.core.dom.rewrite.ASTRewriteAnalyzer;
@ -41,16 +51,26 @@ import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap;
import org.eclipse.cdt.internal.core.dom.rewrite.util.FileContentHelper; import org.eclipse.cdt.internal.core.dom.rewrite.util.FileContentHelper;
import org.eclipse.cdt.internal.core.dom.rewrite.util.FileHelper; import org.eclipse.cdt.internal.core.dom.rewrite.util.FileHelper;
import org.eclipse.cdt.internal.core.resources.ResourceLookup; import org.eclipse.cdt.internal.core.resources.ResourceLookup;
import org.eclipse.cdt.internal.formatter.CCodeFormatter;
import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Path;
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.TextUtilities;
import org.eclipse.ltk.core.refactoring.Change; import org.eclipse.ltk.core.refactoring.Change;
import org.eclipse.ltk.core.refactoring.CompositeChange; import org.eclipse.ltk.core.refactoring.CompositeChange;
import org.eclipse.ltk.core.refactoring.TextFileChange; import org.eclipse.ltk.core.refactoring.TextFileChange;
import org.eclipse.text.edits.DeleteEdit; import org.eclipse.text.edits.DeleteEdit;
import org.eclipse.text.edits.InsertEdit; import org.eclipse.text.edits.InsertEdit;
import org.eclipse.text.edits.MalformedTreeException;
import org.eclipse.text.edits.MultiTextEdit; import org.eclipse.text.edits.MultiTextEdit;
import org.eclipse.text.edits.ReplaceEdit; import org.eclipse.text.edits.ReplaceEdit;
import org.eclipse.text.edits.TextEdit;
import org.eclipse.text.edits.TextEditGroup; import org.eclipse.text.edits.TextEditGroup;
public class ChangeGenerator extends ASTVisitor { public class ChangeGenerator extends ASTVisitor {
@ -93,8 +113,10 @@ public class ChangeGenerator extends ASTVisitor {
initParentModList(); initParentModList();
rootNode.accept(pathProvider); rootNode.accept(pathProvider);
for (IFile currentFile : changes.keySet()) { for (IFile currentFile : changes.keySet()) {
MultiTextEdit edit = changes.get(currentFile);
edit = formatChangedCode(edit, currentFile);
TextFileChange subchange= ASTRewriteAnalyzer.createCTextFileChange(currentFile); TextFileChange subchange= ASTRewriteAnalyzer.createCTextFileChange(currentFile);
subchange.setEdit(changes.get(currentFile)); subchange.setEdit(edit);
change.add(subchange); change.add(subchange);
} }
} }
@ -130,6 +152,63 @@ public class ChangeGenerator extends ASTVisitor {
return modifiedNodeParent; return modifiedNodeParent;
} }
/**
* Applies the C++ code formatter to the code affected by refactoring.
*
* @param edit 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) {
String code;
try {
code = FileContentHelper.getContent(file, 0);
} catch (IOException e) {
CCorePlugin.log(e);
return edit;
} catch (CoreException e) {
CCorePlugin.log(e);
return edit;
}
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];
for (int i = 0; i < edits.length; i++) {
regions[i] = edits[i].getRegion();
}
ICProject project = CCorePlugin.getDefault().getCoreModel().create(file.getProject());
Map<String, String> options = project.getOptions(true);
CodeFormatter formatter = ToolFactory.createCodeFormatter(options);
code = document.get();
TextEdit[] formatEdits = formatter.format(CCodeFormatter.K_TRANSLATION_UNIT, code,
regions, TextUtilities.getDefaultLineDelimiter(document));
MultiTextEdit resultEdit = new MultiTextEdit();
edits = edit.getChildren();
for (int i = 0; i < edits.length; i++) {
IRegion region = regions[i];
int offset = region.getOffset();
TextEdit formatEdit = formatEdits[i];
formatEdit.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()));
}
return resultEdit;
} catch (MalformedTreeException e) {
CCorePlugin.log(e);
return edit;
} catch (BadLocationException e) {
CCorePlugin.log(e);
return edit;
}
}
@Override @Override
public int visit(IASTTranslationUnit translationUnit) { public int visit(IASTTranslationUnit translationUnit) {
if (hasChangedChild(translationUnit)) { if (hasChangedChild(translationUnit)) {
@ -145,11 +224,6 @@ public class ChangeGenerator extends ASTVisitor {
return super.leave(tu); return super.leave(tu);
} }
private int getOffsetForNodeFile(IASTNode rootNode) {
Integer offset = sourceOffsets.get(rootNode.getFileLocation().getFileName());
return offset == null ? 0 : offset.intValue();
}
@Override @Override
public int visit(IASTDeclaration declaration) { public int visit(IASTDeclaration declaration) {
if (hasChangedChild(declaration)) { if (hasChangedChild(declaration)) {
@ -160,16 +234,10 @@ public class ChangeGenerator extends ASTVisitor {
} }
private void synthTreatment(IASTNode synthNode) { private void synthTreatment(IASTNode synthNode) {
synthTreatment(synthNode, null); ChangeGeneratorWriterVisitor writer =
} new ChangeGeneratorWriterVisitor(modificationStore, commentMap);
synthNode.accept(writer);
private void synthTreatment(IASTNode synthNode, String fileScope) { String synthSource = writer.toString();
String indent = getIndent(synthNode);
ASTWriter synthWriter = new ASTWriter(indent);
synthWriter.setModificationStore(modificationStore);
String synthSource = synthWriter.write(synthNode, fileScope, commentMap);
createChange(synthNode, synthSource); createChange(synthNode, synthSource);
IASTFileLocation fileLocation = synthNode.getFileLocation(); IASTFileLocation fileLocation = synthNode.getFileLocation();
@ -177,16 +245,115 @@ public class ChangeGenerator extends ASTVisitor {
sourceOffsets.put(fileLocation.getFileName(), Integer.valueOf(newOffset)); sourceOffsets.put(fileLocation.getFileName(), Integer.valueOf(newOffset));
} }
private void handleAppends(IASTNode node) {
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();
newNode.accept(writer);
}
String code = writer.toString();
IFile file = FileHelper.getFileFromNode(node);
MultiTextEdit parentEdit = getEdit(node, file);
ReplaceEdit edit = new ReplaceEdit(anchor.getOffset(), anchor.getLength(),
code + anchor.getText());
parentEdit.addChild(edit);
IASTFileLocation fileLocation = node.getFileLocation();
int newOffset = fileLocation.getNodeOffset() + fileLocation.getNodeLength();
sourceOffsets.put(fileLocation.getFileName(), Integer.valueOf(newOffset));
}
private IASTNode getLastNodeBeforeAppendPoint(IASTNode node) {
IASTNode[] children;
if (node instanceof IASTCompositeTypeSpecifier) {
children = ((IASTCompositeTypeSpecifier) node).getDeclarations(true);
} else {
children = node.getChildren();
}
return children.length > 0 ? children[children.length - 1] : null;
}
private boolean isAppendable(Iterable<ASTModification> modifications) {
for (ASTModification modification : modifications) {
if (!isAppendable(modification))
return false;
}
return true;
}
private boolean isAppendable(ASTModification modification) {
if (modification.getKind() != ModificationKind.APPEND_CHILD)
return false;
IASTNode node = modification.getNewNode();
return node instanceof IASTDeclaration || node instanceof IASTStatement;
}
/**
* Returns a replace edit whose offset is the position where child appended nodes should be
* inserted at. The text contains the content of the code region that will be disturbed by
* the insertion.
* @param node The node to append children to.
* @return a ReplaceEdit object, or <code>null</code> if the node does not support appending
* children to it.
*/
private ReplaceEdit getAppendAnchor(IASTNode node) {
if (!(node instanceof IASTCompositeTypeSpecifier ||
node instanceof IASTCompoundStatement ||
node instanceof ICPPASTNamespaceDefinition)) {
return null;
}
IFile file = FileHelper.getFileFromNode(node);
String code = originalCodeOfNode(node, file);
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) {
// 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(location.getNodeOffset() + startOfLine, 0, ""); //$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.
*/
private int skipPrecedingBlankLines(String text, int pos) {
int lineStart = -1;
while (--pos >= 0) {
char c = text.charAt(pos);
if (c == '\n') {
lineStart = pos + 1;
} else if (!Character.isWhitespace(c)) {
break;
}
}
return lineStart;
}
private void synthTreatment(IASTTranslationUnit synthTU) { private void synthTreatment(IASTTranslationUnit synthTU) {
ASTWriter synthWriter = new ASTWriter(); ASTWriter synthWriter = new ASTWriter();
synthWriter.setModificationStore(modificationStore); synthWriter.setModificationStore(modificationStore);
for (ASTModification modification : modificationParent.get(synthTU)) { for (ASTModification modification : modificationParent.get(synthTU)) {
IASTFileLocation targetLocation = modification.getTargetNode().getFileLocation(); IASTNode targetNode = modification.getTargetNode();
IASTFileLocation targetLocation = targetNode.getFileLocation();
String currentFile = targetLocation.getFileName(); String currentFile = targetLocation.getFileName();
IPath implPath = new Path(currentFile); IPath implPath = new Path(currentFile);
IFile relevantFile= ResourceLookup.selectFileForLocation(implPath, null); IFile relevantFile= ResourceLookup.selectFileForLocation(implPath, null);
if (relevantFile == null || !relevantFile.exists()) { // if not in workspace or local file system if (relevantFile == null || !relevantFile.exists()) { // If not in workspace or local file system
throw new UnhandledASTModificationException(modification); throw new UnhandledASTModificationException(modification);
} }
MultiTextEdit edit; MultiTextEdit edit;
@ -196,7 +363,7 @@ public class ChangeGenerator extends ASTVisitor {
edit = new MultiTextEdit(); edit = new MultiTextEdit();
changes.put(relevantFile, edit); changes.put(relevantFile, edit);
} }
String newNodeCode = synthWriter.write(modification.getNewNode(), null, commentMap); String newNodeCode = synthWriter.write(modification.getNewNode(), commentMap);
switch (modification.getKind()) { switch (modification.getKind()) {
case REPLACE: case REPLACE:
@ -204,18 +371,20 @@ public class ChangeGenerator extends ASTVisitor {
targetLocation.getNodeLength(), newNodeCode)); targetLocation.getNodeLength(), newNodeCode));
break; break;
case INSERT_BEFORE: case INSERT_BEFORE:
edit.addChild(new InsertEdit(getOffsetIncludingComments(modification.getTargetNode()), if (ASTWriter.requireBlankLineInBetween(modification.getNewNode(), targetNode)) {
newNodeCode)); newNodeCode = newNodeCode + "\n"; //$NON-NLS-1$
}
edit.addChild(new InsertEdit(getOffsetIncludingComments(targetNode), newNodeCode));
break; break;
case APPEND_CHILD: case APPEND_CHILD:
if (modification.getTargetNode() instanceof IASTTranslationUnit && if (targetNode instanceof IASTTranslationUnit &&
((IASTTranslationUnit)modification.getTargetNode()).getDeclarations().length > 0) { ((IASTTranslationUnit) targetNode).getDeclarations().length > 0) {
IASTTranslationUnit tu = (IASTTranslationUnit)modification.getTargetNode(); IASTTranslationUnit tu = (IASTTranslationUnit) targetNode;
IASTDeclaration lastDecl = tu.getDeclarations()[tu.getDeclarations().length - 1]; IASTDeclaration lastDecl = tu.getDeclarations()[tu.getDeclarations().length - 1];
targetLocation = lastDecl.getFileLocation(); targetLocation = lastDecl.getFileLocation();
} }
String lineDelimiter = FileHelper.determineLineDelimiter( String lineDelimiter = FileHelper.determineLineDelimiter(
FileHelper.getFileFromNode(modification.getTargetNode())); FileHelper.getFileFromNode(targetNode));
edit.addChild(new InsertEdit(targetLocation.getNodeOffset() + targetLocation.getNodeLength(), edit.addChild(new InsertEdit(targetLocation.getNodeOffset() + targetLocation.getNodeLength(),
lineDelimiter + lineDelimiter + newNodeCode)); lineDelimiter + lineDelimiter + newNodeCode));
break; break;
@ -225,30 +394,32 @@ public class ChangeGenerator extends ASTVisitor {
private void createChange(IASTNode synthNode, String synthSource) { private void createChange(IASTNode synthNode, String synthSource) {
IFile relevantFile = FileHelper.getFileFromNode(synthNode); IFile relevantFile = FileHelper.getFileFromNode(synthNode);
String originalCode = originalCodeOfNode(synthNode, relevantFile);
String originalCode = originalCodeOfNode(synthNode);
CodeComparer codeComparer = new CodeComparer(originalCode, synthSource); CodeComparer codeComparer = new CodeComparer(originalCode, synthSource);
codeComparer.createChange(getEdit(synthNode, relevantFile), synthNode);
MultiTextEdit edit;
if (changes.containsKey(relevantFile)) {
edit = changes.get(relevantFile);
} else {
edit = new MultiTextEdit();
changes.put(relevantFile, edit);
}
codeComparer.createChange(edit, synthNode);
} }
public String originalCodeOfNode(IASTNode node) { private MultiTextEdit getEdit(IASTNode modifiedNode, IFile file) {
if (node.getFileLocation() != null) { MultiTextEdit edit = changes.get(file);
IFile sourceFile = FileHelper.getFileFromNode(node); if (edit == null) {
int nodeOffset = getOffsetIncludingComments(node); edit = new MultiTextEdit();
int nodeLength = getNodeLengthIncludingComments(node); changes.put(file, edit);
return FileContentHelper.getContent(sourceFile, nodeOffset, nodeLength);
} }
return null; 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;
}
}
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 getNodeLengthIncludingComments(IASTNode node) {
@ -290,23 +461,15 @@ public class ChangeGenerator extends ASTVisitor {
return nodeOffset; return nodeOffset;
} }
private String getIndent(IASTNode nextNode) { private boolean hasChangedChild(IASTNode node) {
IASTFileLocation fileLocation = nextNode.getFileLocation(); return modificationParent.containsKey(node);
int length = fileLocation.getNodeOffset() - getOffsetForNodeFile(nextNode);
String originalSource = FileContentHelper.getContent(FileHelper.getFileFromNode(nextNode),
getOffsetForNodeFile(nextNode), length);
StringBuilder indent = new StringBuilder(originalSource);
indent.reverse();
String lastline = indent.substring(0, Math.max(indent.indexOf("\n"), 0)); //$NON-NLS-1$
if (lastline.trim().length() == 0) {
return lastline;
}
return ""; //$NON-NLS-1$
} }
private boolean hasChangedChild(IASTNode parent) { private boolean hasAppendsOnly(IASTNode node) {
return modificationParent.containsKey(parent); List<ASTModification> modifications = modificationParent.get(node);
if (modifications == null)
return false;
return isAppendable(modifications);
} }
@Override @Override
@ -329,22 +492,38 @@ public class ChangeGenerator extends ASTVisitor {
@Override @Override
public int visit(ICPPASTNamespaceDefinition namespaceDefinition) { public int visit(ICPPASTNamespaceDefinition namespaceDefinition) {
if (hasChangedChild(namespaceDefinition)) { if (hasChangedChild(namespaceDefinition) && !hasAppendsOnly(namespaceDefinition)) {
synthTreatment(namespaceDefinition); synthTreatment(namespaceDefinition);
return ASTVisitor.PROCESS_SKIP; return ASTVisitor.PROCESS_SKIP;
} }
return super.visit(namespaceDefinition); return super.visit(namespaceDefinition);
} }
@Override
public int leave(ICPPASTNamespaceDefinition namespaceDefinition) {
if (hasAppendsOnly(namespaceDefinition)) {
handleAppends(namespaceDefinition);
}
return super.leave(namespaceDefinition);
}
@Override @Override
public int visit(IASTDeclSpecifier declSpec) { public int visit(IASTDeclSpecifier declSpec) {
if (hasChangedChild(declSpec)) { if (hasChangedChild(declSpec) && !hasAppendsOnly(declSpec)) {
synthTreatment(declSpec); synthTreatment(declSpec);
return ASTVisitor.PROCESS_SKIP; return ASTVisitor.PROCESS_SKIP;
} }
return super.visit(declSpec); return super.visit(declSpec);
} }
@Override
public int leave(IASTDeclSpecifier declSpec) {
if (hasAppendsOnly(declSpec)) {
handleAppends(declSpec);
}
return super.leave(declSpec);
}
@Override @Override
public int visit(IASTExpression expression) { public int visit(IASTExpression expression) {
if (hasChangedChild(expression)) { if (hasChangedChild(expression)) {
@ -383,13 +562,21 @@ public class ChangeGenerator extends ASTVisitor {
@Override @Override
public int visit(IASTStatement statement) { public int visit(IASTStatement statement) {
if (hasChangedChild(statement)) { if (hasChangedChild(statement) && !hasAppendsOnly(statement)) {
synthTreatment(statement); synthTreatment(statement);
return ASTVisitor.PROCESS_SKIP; return ASTVisitor.PROCESS_SKIP;
} }
return super.visit(statement); return super.visit(statement);
} }
@Override
public int leave(IASTStatement statement) {
if (hasAppendsOnly(statement)) {
handleAppends(statement);
}
return super.leave(statement);
}
class CodeComparer { class CodeComparer {
private final StringBuilder originalCode; private final StringBuilder originalCode;
private final StringBuilder synthCode; private final StringBuilder synthCode;
@ -536,14 +723,6 @@ public class ChangeGenerator extends ASTVisitor {
protected void createChange(MultiTextEdit edit, IASTNode changedNode) { protected void createChange(MultiTextEdit edit, IASTNode changedNode) {
int changeOffset = getOffsetIncludingComments(changedNode); int changeOffset = getOffsetIncludingComments(changedNode);
TextEditGroup editGroup = new TextEditGroup(Messages.ChangeGenerator_group);
for (ASTModification currentModification : modificationParent.get(changedNode)) {
if (currentModification.getAssociatedEditGroup() != null) {
editGroup = currentModification.getAssociatedEditGroup();
edit.addChildren(editGroup.getTextEdits());
break;
}
}
createChange(edit, changeOffset); createChange(edit, changeOffset);
} }

View file

@ -11,9 +11,9 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.rewrite.changegenerator; package org.eclipse.cdt.internal.core.dom.rewrite.changegenerator;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier; import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
import org.eclipse.cdt.internal.core.dom.rewrite.astwriter.ASTWriterVisitor;
import org.eclipse.cdt.internal.core.dom.rewrite.astwriter.DeclSpecWriter; import org.eclipse.cdt.internal.core.dom.rewrite.astwriter.DeclSpecWriter;
import org.eclipse.cdt.internal.core.dom.rewrite.astwriter.Scribe; import org.eclipse.cdt.internal.core.dom.rewrite.astwriter.Scribe;
import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap; import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap;
@ -21,8 +21,8 @@ import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap;
public class ModifiedASTDeclSpecWriter extends DeclSpecWriter { public class ModifiedASTDeclSpecWriter extends DeclSpecWriter {
private final ASTModificationHelper modificationHelper; private final ASTModificationHelper modificationHelper;
public ModifiedASTDeclSpecWriter(Scribe scribe, ASTVisitor visitor, ModificationScopeStack stack, public ModifiedASTDeclSpecWriter(Scribe scribe, ASTWriterVisitor visitor,
NodeCommentMap commentMap) { ModificationScopeStack stack, NodeCommentMap commentMap) {
super(scribe, visitor, commentMap); super(scribe, visitor, commentMap);
this.modificationHelper = new ASTModificationHelper(stack); this.modificationHelper = new ASTModificationHelper(stack);
} }

View file

@ -12,11 +12,11 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.rewrite.changegenerator; package org.eclipse.cdt.internal.core.dom.rewrite.changegenerator;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDefinition; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition;
import org.eclipse.cdt.internal.core.dom.rewrite.astwriter.ASTWriterVisitor;
import org.eclipse.cdt.internal.core.dom.rewrite.astwriter.DeclarationWriter; import org.eclipse.cdt.internal.core.dom.rewrite.astwriter.DeclarationWriter;
import org.eclipse.cdt.internal.core.dom.rewrite.astwriter.Scribe; import org.eclipse.cdt.internal.core.dom.rewrite.astwriter.Scribe;
import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap; import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap;
@ -24,21 +24,26 @@ import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap;
public class ModifiedASTDeclarationWriter extends DeclarationWriter { public class ModifiedASTDeclarationWriter extends DeclarationWriter {
private final ASTModificationHelper modificationHelper; private final ASTModificationHelper modificationHelper;
public ModifiedASTDeclarationWriter(Scribe scribe, ASTVisitor visitor, ModificationScopeStack stack, NodeCommentMap commentMap) { public ModifiedASTDeclarationWriter(Scribe scribe, ASTWriterVisitor visitor,
ModificationScopeStack stack, NodeCommentMap commentMap) {
super(scribe, visitor, commentMap); super(scribe, visitor, commentMap);
this.modificationHelper = new ASTModificationHelper(stack); this.modificationHelper = new ASTModificationHelper(stack);
} }
@Override @Override
protected void writeDeclarationsInNamespace(ICPPASTNamespaceDefinition namespaceDefinition, IASTDeclaration[] declarations) { protected void writeDeclarationsInNamespace(ICPPASTNamespaceDefinition namespaceDefinition,
IASTDeclaration[] modifiedDeclarations = modificationHelper.createModifiedChildArray(namespaceDefinition, declarations, IASTDeclaration.class, commentMap); IASTDeclaration[] declarations) {
IASTDeclaration[] modifiedDeclarations = modificationHelper.createModifiedChildArray(
namespaceDefinition, declarations, IASTDeclaration.class, commentMap);
super.writeDeclarationsInNamespace(namespaceDefinition, modifiedDeclarations); super.writeDeclarationsInNamespace(namespaceDefinition, modifiedDeclarations);
} }
@Override @Override
protected void writeCtorChainInitializer(ICPPASTFunctionDefinition funcDec, protected void writeCtorChainInitializer(ICPPASTFunctionDefinition funcDec,
ICPPASTConstructorChainInitializer[] ctorInitChain) { ICPPASTConstructorChainInitializer[] ctorInitChain) {
ICPPASTConstructorChainInitializer[] modifiedChainInitializer = modificationHelper.createModifiedChildArray(funcDec, ctorInitChain, ICPPASTConstructorChainInitializer.class, commentMap); ICPPASTConstructorChainInitializer[] modifiedInitializer =
super.writeCtorChainInitializer(funcDec, modifiedChainInitializer); modificationHelper.createModifiedChildArray(funcDec, ctorInitChain,
ICPPASTConstructorChainInitializer.class, commentMap);
super.writeCtorChainInitializer(funcDec, modifiedInitializer);
} }
} }

View file

@ -12,7 +12,6 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.rewrite.changegenerator; package org.eclipse.cdt.internal.core.dom.rewrite.changegenerator;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator; import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTArrayModifier; import org.eclipse.cdt.core.dom.ast.IASTArrayModifier;
import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
@ -25,6 +24,7 @@ import org.eclipse.cdt.core.dom.ast.IASTStandardFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTTypeId; import org.eclipse.cdt.core.dom.ast.IASTTypeId;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.gnu.c.ICASTKnRFunctionDeclarator; import org.eclipse.cdt.core.dom.ast.gnu.c.ICASTKnRFunctionDeclarator;
import org.eclipse.cdt.internal.core.dom.rewrite.astwriter.ASTWriterVisitor;
import org.eclipse.cdt.internal.core.dom.rewrite.astwriter.DeclaratorWriter; import org.eclipse.cdt.internal.core.dom.rewrite.astwriter.DeclaratorWriter;
import org.eclipse.cdt.internal.core.dom.rewrite.astwriter.Scribe; import org.eclipse.cdt.internal.core.dom.rewrite.astwriter.Scribe;
import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap; import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap;
@ -32,7 +32,7 @@ import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap;
public class ModifiedASTDeclaratorWriter extends DeclaratorWriter { public class ModifiedASTDeclaratorWriter extends DeclaratorWriter {
private final ASTModificationHelper modificationHelper; private final ASTModificationHelper modificationHelper;
public ModifiedASTDeclaratorWriter(Scribe scribe, ASTVisitor visitor, ModificationScopeStack stack, NodeCommentMap commentMap) { public ModifiedASTDeclaratorWriter(Scribe scribe, ASTWriterVisitor visitor, ModificationScopeStack stack, NodeCommentMap commentMap) {
super(scribe, visitor, commentMap); super(scribe, visitor, commentMap);
this.modificationHelper = new ASTModificationHelper(stack); this.modificationHelper = new ASTModificationHelper(stack);
} }
@ -40,29 +40,31 @@ public class ModifiedASTDeclaratorWriter extends DeclaratorWriter {
@Override @Override
protected void writeParameterDeclarations(IASTStandardFunctionDeclarator funcDec, protected void writeParameterDeclarations(IASTStandardFunctionDeclarator funcDec,
IASTParameterDeclaration[] paraDecls) { IASTParameterDeclaration[] paraDecls) {
IASTParameterDeclaration[] modifiedParameters = modificationHelper IASTParameterDeclaration[] modifiedParameters = modificationHelper.createModifiedChildArray(
.createModifiedChildArray(funcDec, paraDecls, IASTParameterDeclaration.class, funcDec, paraDecls, IASTParameterDeclaration.class, commentMap);
commentMap);
super.writeParameterDeclarations(funcDec, modifiedParameters); super.writeParameterDeclarations(funcDec, modifiedParameters);
} }
@Override @Override
protected void writePointerOperators(IASTDeclarator declarator,IASTPointerOperator[] unmodifiedPointerOperations) { protected void writePointerOperators(IASTDeclarator declarator,
IASTPointerOperator[] unmodifiedPointerOperations) {
IASTPointerOperator[] modifiedPointer = modificationHelper.createModifiedChildArray( IASTPointerOperator[] modifiedPointer = modificationHelper.createModifiedChildArray(
declarator, unmodifiedPointerOperations, IASTPointerOperator.class, commentMap); declarator, unmodifiedPointerOperations, IASTPointerOperator.class, commentMap);
super.writePointerOperators(declarator, modifiedPointer); super.writePointerOperators(declarator, modifiedPointer);
} }
@Override @Override
protected void writeArrayModifiers(IASTArrayDeclarator arrDecl, protected void writeArrayModifiers(IASTArrayDeclarator arrDecl, IASTArrayModifier[] arrMods) {
IASTArrayModifier[] arrMods) { IASTArrayModifier[] modifiedModifiers = modificationHelper.createModifiedChildArray(arrDecl,
IASTArrayModifier[] modifiedModifiers = modificationHelper.createModifiedChildArray(arrDecl, arrMods, IASTArrayModifier.class, commentMap); arrMods, IASTArrayModifier.class, commentMap);
super.writeArrayModifiers(arrDecl, modifiedModifiers); super.writeArrayModifiers(arrDecl, modifiedModifiers);
} }
@Override @Override
protected void writeExceptionSpecification(ICPPASTFunctionDeclarator funcDec, IASTTypeId[] exceptions ) { protected void writeExceptionSpecification(ICPPASTFunctionDeclarator funcDec,
IASTTypeId[] modifiedExceptions = modificationHelper.createModifiedChildArray(funcDec, exceptions, IASTTypeId.class, commentMap); IASTTypeId[] exceptions) {
IASTTypeId[] modifiedExceptions = modificationHelper.createModifiedChildArray(funcDec,
exceptions, IASTTypeId.class, commentMap);
// it makes a difference whether the exception array is identical to // it makes a difference whether the exception array is identical to
// ICPPASTFunctionDeclarator.NO_EXCEPTION_SPECIFICATION // ICPPASTFunctionDeclarator.NO_EXCEPTION_SPECIFICATION
if (modifiedExceptions.length == 0 && if (modifiedExceptions.length == 0 &&
@ -74,18 +76,18 @@ public class ModifiedASTDeclaratorWriter extends DeclaratorWriter {
} }
@Override @Override
protected void writeKnRParameterDeclarations( protected void writeKnRParameterDeclarations(ICASTKnRFunctionDeclarator knrFunct,
ICASTKnRFunctionDeclarator knrFunct,
IASTDeclaration[] knrDeclarations) { IASTDeclaration[] knrDeclarations) {
IASTDeclaration[] modifiedDeclarations = modificationHelper.createModifiedChildArray(knrFunct, knrDeclarations, IASTDeclaration.class, commentMap); IASTDeclaration[] modifiedDeclarations = modificationHelper.createModifiedChildArray(
knrFunct, knrDeclarations, IASTDeclaration.class, commentMap);
super.writeKnRParameterDeclarations(knrFunct, modifiedDeclarations); super.writeKnRParameterDeclarations(knrFunct, modifiedDeclarations);
} }
@Override @Override
protected void writeKnRParameterNames( protected void writeKnRParameterNames(ICASTKnRFunctionDeclarator knrFunct,
ICASTKnRFunctionDeclarator knrFunct, IASTName[] parameterNames) { IASTName[] parameterNames) {
IASTName[] modifiedNames = modificationHelper.createModifiedChildArray(knrFunct, parameterNames, IASTName.class, commentMap); IASTName[] modifiedNames = modificationHelper.createModifiedChildArray(knrFunct,
parameterNames, IASTName.class, commentMap);
super.writeKnRParameterNames(knrFunct, modifiedNames); super.writeKnRParameterNames(knrFunct, modifiedNames);
} }

View file

@ -12,7 +12,6 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.rewrite.changegenerator; package org.eclipse.cdt.internal.core.dom.rewrite.changegenerator;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTExpressionList; import org.eclipse.cdt.core.dom.ast.IASTExpressionList;
import org.eclipse.cdt.core.dom.ast.IASTInitializer; import org.eclipse.cdt.core.dom.ast.IASTInitializer;
@ -20,6 +19,7 @@ import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNewExpression; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNewExpression;
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification; import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind; import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind;
import org.eclipse.cdt.internal.core.dom.rewrite.astwriter.ASTWriterVisitor;
import org.eclipse.cdt.internal.core.dom.rewrite.astwriter.ExpressionWriter; import org.eclipse.cdt.internal.core.dom.rewrite.astwriter.ExpressionWriter;
import org.eclipse.cdt.internal.core.dom.rewrite.astwriter.MacroExpansionHandler; import org.eclipse.cdt.internal.core.dom.rewrite.astwriter.MacroExpansionHandler;
import org.eclipse.cdt.internal.core.dom.rewrite.astwriter.Scribe; import org.eclipse.cdt.internal.core.dom.rewrite.astwriter.Scribe;
@ -28,7 +28,7 @@ import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap;
public class ModifiedASTExpressionWriter extends ExpressionWriter { public class ModifiedASTExpressionWriter extends ExpressionWriter {
private final ASTModificationHelper modificationHelper; private final ASTModificationHelper modificationHelper;
public ModifiedASTExpressionWriter(Scribe scribe, ASTVisitor visitor, MacroExpansionHandler macroHandler, public ModifiedASTExpressionWriter(Scribe scribe, ASTWriterVisitor visitor, MacroExpansionHandler macroHandler,
ModificationScopeStack stack, NodeCommentMap commentMap) { ModificationScopeStack stack, NodeCommentMap commentMap) {
super(scribe, visitor, macroHandler, commentMap); super(scribe, visitor, macroHandler, commentMap);
this.modificationHelper = new ASTModificationHelper(stack); this.modificationHelper = new ASTModificationHelper(stack);

View file

@ -11,10 +11,10 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.rewrite.changegenerator; package org.eclipse.cdt.internal.core.dom.rewrite.changegenerator;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement; import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTStatement; import org.eclipse.cdt.core.dom.ast.IASTStatement;
import org.eclipse.cdt.internal.core.dom.rewrite.astwriter.ASTWriterVisitor;
import org.eclipse.cdt.internal.core.dom.rewrite.astwriter.Scribe; import org.eclipse.cdt.internal.core.dom.rewrite.astwriter.Scribe;
import org.eclipse.cdt.internal.core.dom.rewrite.astwriter.StatementWriter; import org.eclipse.cdt.internal.core.dom.rewrite.astwriter.StatementWriter;
import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap; import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap;
@ -22,7 +22,7 @@ import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap;
public class ModifiedASTStatementWriter extends StatementWriter { public class ModifiedASTStatementWriter extends StatementWriter {
private final ASTModificationHelper modificationHelper; private final ASTModificationHelper modificationHelper;
public ModifiedASTStatementWriter(Scribe scribe, ASTVisitor visitor, ModificationScopeStack stack, NodeCommentMap commentMap) { public ModifiedASTStatementWriter(Scribe scribe, ASTWriterVisitor visitor, ModificationScopeStack stack, NodeCommentMap commentMap) {
super(scribe, visitor, commentMap); super(scribe, visitor, commentMap);
this.modificationHelper = new ASTModificationHelper(stack); this.modificationHelper = new ASTModificationHelper(stack);
} }

View file

@ -13,8 +13,6 @@ void foo();
//@A.cpp //@A.cpp
#include "A.h" #include "A.h"
void foo() void foo() {
{
} }

View file

@ -4,8 +4,7 @@
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
class A class A {
{
public: public:
A(); A();
virtual ~A(); virtual ~A();
@ -20,14 +19,13 @@ public:
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
class A class A {
{
public: public:
A(); A();
virtual ~A(); virtual ~A();
int foo(); int foo();
void bar(); void bar();
static const int theAnswer = 42; static const int theAnswer = 42;
}; };
#endif /*A_H_*/ #endif /*A_H_*/
@ -36,21 +34,17 @@ public:
//@A.cpp //@A.cpp
#include "A.h" #include "A.h"
A::A() A::A() {
{
} }
A::~A() A::~A() {
{
} }
int A::foo() int A::foo() {
{ return /*$*/42/*$$*/; //Hello
return /*$*/42/*$$*/; //Hallo
} }
void A::bar() void A::bar() {
{
int a = 42; int a = 42;
int b = 42; int b = 42;
} }
@ -58,21 +52,17 @@ void A::bar()
//= //=
#include "A.h" #include "A.h"
A::A() A::A() {
{
} }
A::~A() A::~A() {
{
} }
int A::foo() int A::foo() {
{ return theAnswer; //Hello
return theAnswer; //Hallo
} }
void A::bar() void A::bar() {
{
int a = theAnswer; int a = theAnswer;
int b = theAnswer; int b = theAnswer;
} }
@ -83,8 +73,7 @@ void A::bar()
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
class A class A {
{
public: public:
A(); A();
virtual ~A(); virtual ~A();
@ -99,14 +88,13 @@ public:
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
class A class A {
{
public: public:
A(); A();
virtual ~A(); virtual ~A();
int foo(); int foo();
void bar(); void bar();
static const int theAnswer = 42; static const int theAnswer = 42;
}; };
#endif /*A_H_*/ #endif /*A_H_*/
@ -115,22 +103,18 @@ public:
//@A.cpp //@A.cpp
#include "A.h" #include "A.h"
A::A() A::A() {
{
} }
A::~A() A::~A() {
{
} }
int A::foo() int A::foo() {
{
//Hallo //Hallo
return /*$*/42/*$$*/; return /*$*/42/*$$*/;
} }
void A::bar() void A::bar() {
{
int a = 42; int a = 42;
int b = 42; int b = 42;
} }
@ -138,22 +122,18 @@ void A::bar()
//= //=
#include "A.h" #include "A.h"
A::A() A::A() {
{
} }
A::~A() A::~A() {
{
} }
int A::foo() int A::foo() {
{
//Hallo //Hallo
return theAnswer; return theAnswer;
} }
void A::bar() void A::bar() {
{
int a = theAnswer; int a = theAnswer;
int b = theAnswer; int b = theAnswer;
} }
@ -164,8 +144,7 @@ void A::bar()
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
class A class A {
{
public: public:
A(); A();
virtual ~A(); virtual ~A();
@ -180,14 +159,13 @@ public:
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
class A class A {
{
public: public:
A(); A();
virtual ~A(); virtual ~A();
float foo(); float foo();
void bar(); void bar();
static const float theAnswer = 42.0f; static const float theAnswer = 42.0f;
}; };
#endif /*A_H_*/ #endif /*A_H_*/
@ -196,21 +174,17 @@ public:
//@A.cpp //@A.cpp
#include "A.h" #include "A.h"
A::A() A::A() {
{
} }
A::~A() A::~A() {
{
} }
float A::foo() float A::foo() {
{
return /*$*/42.0f/*$$*/; return /*$*/42.0f/*$$*/;
} }
void A::bar() void A::bar() {
{
float a = 42.0f; float a = 42.0f;
float b = 42.0f; float b = 42.0f;
} }
@ -218,21 +192,17 @@ void A::bar()
//= //=
#include "A.h" #include "A.h"
A::A() A::A() {
{
} }
A::~A() A::~A() {
{
} }
float A::foo() float A::foo() {
{
return theAnswer; return theAnswer;
} }
void A::bar() void A::bar() {
{
float a = theAnswer; float a = theAnswer;
float b = theAnswer; float b = theAnswer;
} }
@ -243,8 +213,7 @@ void A::bar()
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
class A class A {
{
public: public:
A(); A();
virtual ~A(); virtual ~A();
@ -259,14 +228,13 @@ public:
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
class A class A {
{
public: public:
A(); A();
virtual ~A(); virtual ~A();
double foo(); double foo();
void bar(); void bar();
static const double theAnswer = 42.0; static const double theAnswer = 42.0;
}; };
#endif /*A_H_*/ #endif /*A_H_*/
@ -275,21 +243,17 @@ public:
//@A.cpp //@A.cpp
#include "A.h" #include "A.h"
A::A() A::A() {
{
} }
A::~A() A::~A() {
{
} }
double A::foo() double A::foo() {
{
return /*$*/42.0/*$$*/; return /*$*/42.0/*$$*/;
} }
void A::bar() void A::bar() {
{
double a = 42.0; double a = 42.0;
double b = 42.0; double b = 42.0;
} }
@ -297,21 +261,17 @@ void A::bar()
//= //=
#include "A.h" #include "A.h"
A::A() A::A() {
{
} }
A::~A() A::~A() {
{
} }
double A::foo() double A::foo() {
{
return theAnswer; return theAnswer;
} }
void A::bar() void A::bar() {
{
double a = theAnswer; double a = theAnswer;
double b = theAnswer; double b = theAnswer;
} }
@ -322,8 +282,7 @@ void A::bar()
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
class A class A {
{
public: public:
A(); A();
virtual ~A(); virtual ~A();
@ -337,8 +296,7 @@ public:
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
class A class A {
{
public: public:
A(); A();
virtual ~A(); virtual ~A();
@ -351,51 +309,43 @@ public:
//@A.cpp //@A.cpp
#include "A.h" #include "A.h"
A::A() A::A() {
{
} }
A::~A() A::~A() {
{
} }
int A::foo() int A::foo() {
{
return 42; return 42;
} }
int bar() int bar() {
{
return /*$*/42/*$$*/; return /*$*/42/*$$*/;
} }
//= //=
#include "A.h" #include "A.h"
namespace namespace {
{
const int theAnswer = 42; const int theAnswer = 42;
}
A::A()
{
} }
A::~A() A::A() {
{
} }
int A::foo() A::~A() {
{ }
int A::foo() {
return theAnswer; return theAnswer;
} }
int bar() int bar() {
{
return theAnswer; return theAnswer;
} }
//!replaceNumberProtected //!replaceNumberProtected
//#org.eclipse.cdt.ui.tests.refactoring.extractconstant.ExtractConstantRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.extractconstant.ExtractConstantRefactoringTest
//@.config //@.config
@ -404,8 +354,7 @@ visibility=protected
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
class A class A {
{
public: public:
A(); A();
virtual ~A(); virtual ~A();
@ -418,14 +367,14 @@ public:
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
class A class A {
{
public: public:
A(); A();
virtual ~A(); virtual ~A();
int foo(); int foo();
protected: protected:
static const int theAnswer = 42; static const int theAnswer = 42;
}; };
#endif /*A_H_*/ #endif /*A_H_*/
@ -433,32 +382,26 @@ protected:
//@A.cpp //@A.cpp
#include "A.h" #include "A.h"
A::A() A::A() {
{
} }
A::~A() A::~A() {
{
} }
int A::foo() int A::foo() {
{
return /*$*/42/*$$*/; return /*$*/42/*$$*/;
} }
//= //=
#include "A.h" #include "A.h"
A::A() A::A() {
{
} }
A::~A() A::~A() {
{
} }
int A::foo() int A::foo() {
{
return theAnswer; return theAnswer;
} }
@ -470,8 +413,7 @@ visibility=private
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
class A class A {
{
public: public:
A(); A();
virtual ~A(); virtual ~A();
@ -484,14 +426,14 @@ public:
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
class A class A {
{
public: public:
A(); A();
virtual ~A(); virtual ~A();
int foo(); int foo();
private: private:
static const int theAnswer = 42; static const int theAnswer = 42;
}; };
#endif /*A_H_*/ #endif /*A_H_*/
@ -499,32 +441,26 @@ private:
//@A.cpp //@A.cpp
#include "A.h" #include "A.h"
A::A() A::A() {
{
} }
A::~A() A::~A() {
{
} }
int A::foo() int A::foo() {
{
return /*$*/42/*$$*/; return /*$*/42/*$$*/;
} }
//= //=
#include "A.h" #include "A.h"
A::A() A::A() {
{
} }
A::~A() A::~A() {
{
} }
int A::foo() int A::foo() {
{
return theAnswer; return theAnswer;
} }
@ -535,18 +471,18 @@ filename=A.h
//@A.h //@A.h
class X { class X {
void method() { void method() {
int a= /*$*/42/*$$*/; int a = /*$*/42/*$$*/;
} }
}; };
//= //=
class X { class X {
void method() { void method() {
int a= theAnswer; int a = theAnswer;
} }
public: public:
static const int theAnswer = 42; static const int theAnswer = 42;
}; };
//!ExtractConstantString //!ExtractConstantString
@ -556,30 +492,26 @@ visibility=private
filename=A.h filename=A.h
//@A.h //@A.h
class X { class X {
void method() void method() {
{ char* a = /*$*/"sometext"/*$$*/;
char *a = /*$*/"sometext"/*$$*/; }
}
void method2() void method2() {
{ const char* b = "sometext";
const char *b = "sometext"; }
}
}; };
//= //=
class X { class X {
void method() void method() {
{ char* a = theAnswer;
char *a = theAnswer; }
}
void method2() void method2() {
{ const char* b = theAnswer;
const char *b = theAnswer; }
}
static const char *theAnswer = "sometext"; static const char* theAnswer = "sometext";
}; };
//!ExtractConstantWideString //!ExtractConstantWideString
@ -589,31 +521,27 @@ visibility=private
filename=A.h filename=A.h
//@A.h //@A.h
class X { class X {
void method() void method() {
{ wchar_t* a = /*$*/L"sometext"/*$$*/;
wchar_t *a = /*$*/L"sometext"/*$$*/; }
}
void method2() void method2() {
{ const wchar_t* b = L"sometext";
const wchar_t *b = L"sometext"; const char* c = "sometext";
const char *c = "sometext"; }
}
}; };
//= //=
class X { class X {
void method() void method() {
{ wchar_t* a = theAnswer;
wchar_t *a = theAnswer; }
}
void method2() void method2() {
{ const wchar_t* b = theAnswer;
const wchar_t *b = theAnswer; const char* c = "sometext";
const char *c = "sometext"; }
}
static const wchar_t *theAnswer = L"sometext"; static const wchar_t* theAnswer = L"sometext";
}; };

View file

@ -4,8 +4,7 @@
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
class A class A {
{
public: public:
A(); A();
virtual ~A(); virtual ~A();
@ -19,14 +18,13 @@ public:
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
class A class A {
{
public: public:
A(); A();
virtual ~A(); virtual ~A();
int foo(); int foo();
void bar(); void bar();
static const int theAnswer = 42; static const int theAnswer = 42;
}; };
#endif /*A_H_*/ #endif /*A_H_*/
@ -34,21 +32,17 @@ public:
//@A.cpp //@A.cpp
#include "A.h" #include "A.h"
A::A() A::A() {
{
} }
A::~A() A::~A() {
{
} }
int A::foo() int A::foo() {
{ return 42; // Hello
return 42; //Hallo
} }
void A::bar() void A::bar() {
{
int a = 42; int a = 42;
int b = 42; int b = 42;
} }
@ -56,21 +50,17 @@ void A::bar()
//= //=
#include "A.h" #include "A.h"
A::A() A::A() {
{
} }
A::~A() A::~A() {
{
} }
int A::foo() int A::foo() {
{ return theAnswer; // Hello
return theAnswer; //Hallo
} }
void A::bar() void A::bar() {
{
int a = theAnswer; int a = theAnswer;
int b = theAnswer; int b = theAnswer;
} }
@ -91,8 +81,7 @@ project="RegressionTestProject" selection="64,2" visibility="public"/>
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
class A class A {
{
public: public:
A(); A();
virtual ~A(); virtual ~A();
@ -105,14 +94,14 @@ public:
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
class A class A {
{
public: public:
A(); A();
virtual ~A(); virtual ~A();
int foo(); int foo();
protected: protected:
static const int theAnswer = 42; static const int theAnswer = 42;
}; };
#endif /*A_H_*/ #endif /*A_H_*/
@ -120,32 +109,26 @@ protected:
//@A.cpp //@A.cpp
#include "A.h" #include "A.h"
A::A() A::A() {
{
} }
A::~A() A::~A() {
{
} }
int A::foo() int A::foo() {
{
return 42; return 42;
} }
//= //=
#include "A.h" #include "A.h"
A::A() A::A() {
{
} }
A::~A() A::~A() {
{
} }
int A::foo() int A::foo() {
{
return theAnswer; return theAnswer;
} }
@ -164,8 +147,7 @@ project="RegressionTestProject" selection="64,2" visibility="protected"/>
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
class A class A {
{
public: public:
A(); A();
virtual ~A(); virtual ~A();
@ -178,14 +160,14 @@ public:
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
class A class A {
{
public: public:
A(); A();
virtual ~A(); virtual ~A();
int foo(); int foo();
private: private:
static const int theAnswer = 42; static const int theAnswer = 42;
}; };
#endif /*A_H_*/ #endif /*A_H_*/
@ -193,32 +175,26 @@ private:
//@A.cpp //@A.cpp
#include "A.h" #include "A.h"
A::A() A::A() {
{
} }
A::~A() A::~A() {
{
} }
int A::foo() int A::foo() {
{
return 42; return 42;
} }
//= //=
#include "A.h" #include "A.h"
A::A() A::A() {
{
} }
A::~A() A::~A() {
{
} }
int A::foo() int A::foo() {
{
return theAnswer; return theAnswer;
} }

View file

@ -1,34 +1,34 @@
//!Extract template function //!Extract template function
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
//@A.cpp //@A.cpp
void test(){ void test() {
} }
template <typename T>
int tempFunct(){
template <typename T>
int tempFunct() {
T i; T i;
i = 0; i = 0;
/*$*/i++; /*$*/i++;
i+=3;/*$$*/ i += 3;/*$$*/
return 0; return 0;
} }
//= //=
void test(){ void test() {
} }
template<typename T> void exp(T i)
{ template<typename T>
i++; void exp(T i) {
i += 3; i++;
i += 3;
} }
template <typename T> template <typename T>
int tempFunct(){ int tempFunct() {
T i; T i;
i = 0; i = 0;
exp(i); exp(i);
return 0; return 0;
} }
@ -36,39 +36,40 @@ int tempFunct(){
//!Extract template function with template parameter Bug #12 //!Extract template function with template parameter Bug #12
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
//@A.cpp //@A.cpp
void test(){ void test() {
} }
template <typename T>
int tempFunct(T p){
template <typename T>
int tempFunct(T p) {
/*$*/++p; /*$*/++p;
p + 4;/*$$*/ p + 4;/*$$*/
return 0; return 0;
} }
//= //=
void test(){ void test() {
} }
template<typename T> void exp(T p)
{ template<typename T>
++p; void exp(T p) {
p + 4; ++p;
p + 4;
} }
template <typename T> template <typename T>
int tempFunct(T p){ int tempFunct(T p) {
exp(p); exp(p);
return 0; return 0;
} }
//!Extract template function with template type declaration Bug #11 //!Extract template function with template type declaration Bug #11
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
//@A.cpp //@A.cpp
void test(){ void test() {
} }
template <typename T>
int tempFunct(){
template <typename T>
int tempFunct() {
/*$*/T p; /*$*/T p;
p = 0; p = 0;
p + 4;/*$$*/ p + 4;/*$$*/
@ -77,19 +78,19 @@ int tempFunct(){
} }
//= //=
void test(){ void test() {
} }
template<typename T> T exp()
{ template<typename T>
T p; T exp() {
p = 0; T p;
p + 4; p = 0;
return p; p + 4;
return p;
} }
template <typename T> template <typename T>
int tempFunct(){ int tempFunct() {
T p = exp(); T p = exp();
p + 2; p + 2;
return 0; return 0;

View file

@ -4,12 +4,11 @@
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
class A class A {
{
public: public:
A(); A();
virtual ~A(); virtual ~A();
int foo(); int foo();
}; };
#endif /*A_H_*/ #endif /*A_H_*/
@ -18,12 +17,11 @@ public:
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
class A class A {
{
public: public:
A(); A();
virtual ~A(); virtual ~A();
int foo(); int foo();
}; };
#endif /*A_H_*/ #endif /*A_H_*/
@ -31,34 +29,28 @@ public:
//@A.cpp //@A.cpp
#include "A.h" #include "A.h"
A::A() A::A() {
{
} }
A::~A() A::~A() {
{
} }
int A::foo() int A::foo() {
{ return /*$*/42/*$$*/;
return /*$*/42/*$$*/;
} }
//= //=
#include "A.h" #include "A.h"
A::A() A::A() {
{
} }
A::~A() A::~A() {
{
} }
int A::foo() int A::foo() {
{ int i = 42;
int i = 42; return i;
return i;
} }
//!ExtractLocalVariableRefactoringTest char //!ExtractLocalVariableRefactoringTest char
@ -67,12 +59,11 @@ int A::foo()
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
class A class A {
{
public: public:
A(); A();
virtual ~A(); virtual ~A();
int foo(); int foo();
}; };
#endif /*A_H_*/ #endif /*A_H_*/
@ -81,12 +72,11 @@ public:
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
class A class A {
{
public: public:
A(); A();
virtual ~A(); virtual ~A();
int foo(); int foo();
}; };
#endif /*A_H_*/ #endif /*A_H_*/
@ -94,34 +84,28 @@ public:
//@A.cpp //@A.cpp
#include "A.h" #include "A.h"
A::A() A::A() {
{
} }
A::~A() A::~A() {
{
} }
int A::foo() int A::foo() {
{ return /*$*/'c'/*$$*/;
return /*$*/'c'/*$$*/;
} }
//= //=
#include "A.h" #include "A.h"
A::A() A::A() {
{
} }
A::~A() A::~A() {
{
} }
int A::foo() int A::foo() {
{ char temp = 'c';
char temp = 'c'; return temp;
return temp;
} }
//!ExtractLocalVariableRefactoringTest float //!ExtractLocalVariableRefactoringTest float
@ -130,12 +114,11 @@ int A::foo()
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
class A class A {
{
public: public:
A(); A();
virtual ~A(); virtual ~A();
float foo(); float foo();
}; };
#endif /*A_H_*/ #endif /*A_H_*/
@ -144,12 +127,11 @@ public:
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
class A class A {
{
public: public:
A(); A();
virtual ~A(); virtual ~A();
float foo(); float foo();
}; };
#endif /*A_H_*/ #endif /*A_H_*/
@ -157,34 +139,28 @@ public:
//@A.cpp //@A.cpp
#include "A.h" #include "A.h"
A::A() A::A() {
{
} }
A::~A() A::~A() {
{
} }
float A::foo() float A::foo() {
{ return /*$*/42.0f/*$$*/;
return /*$*/42.0f/*$$*/;
} }
//= //=
#include "A.h" #include "A.h"
A::A() A::A() {
{
} }
A::~A() A::~A() {
{
} }
float A::foo() float A::foo() {
{ float f = 42.0f;
float f = 42.0f; return f;
return f;
} }
//!ExtractLocalVariableRefactoringTest double //!ExtractLocalVariableRefactoringTest double
@ -193,12 +169,11 @@ float A::foo()
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
class A class A {
{
public: public:
A(); A();
virtual ~A(); virtual ~A();
float foo(); float foo();
}; };
#endif /*A_H_*/ #endif /*A_H_*/
@ -207,12 +182,11 @@ public:
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
class A class A {
{
public: public:
A(); A();
virtual ~A(); virtual ~A();
float foo(); float foo();
}; };
#endif /*A_H_*/ #endif /*A_H_*/
@ -220,34 +194,28 @@ public:
//@A.cpp //@A.cpp
#include "A.h" #include "A.h"
A::A() A::A() {
{
} }
A::~A() A::~A() {
{
} }
float A::foo() float A::foo() {
{ return /*$*/42.0/*$$*/;
return /*$*/42.0/*$$*/;
} }
//= //=
#include "A.h" #include "A.h"
A::A() A::A() {
{
} }
A::~A() A::~A() {
{
} }
float A::foo() float A::foo() {
{ double f = 42.0;
double f = 42.0; return f;
return f;
} }
//!ExtractLocalVariableRefactoringTest parentheses //!ExtractLocalVariableRefactoringTest parentheses
@ -256,12 +224,11 @@ float A::foo()
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
class A class A {
{
public: public:
A(); A();
virtual ~A(); virtual ~A();
int foo(); int foo();
}; };
#endif /*A_H_*/ #endif /*A_H_*/
@ -270,12 +237,11 @@ public:
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
class A class A {
{
public: public:
A(); A();
virtual ~A(); virtual ~A();
int foo(); int foo();
}; };
#endif /*A_H_*/ #endif /*A_H_*/
@ -283,34 +249,28 @@ public:
//@A.cpp //@A.cpp
#include "A.h" #include "A.h"
A::A() A::A() {
{
} }
A::~A() A::~A() {
{
} }
int A::foo() int A::foo() {
{ return /*$*/(42)/*$$*/;
return /*$*/(42)/*$$*/;
} }
//= //=
#include "A.h" #include "A.h"
A::A() A::A() {
{
} }
A::~A() A::~A() {
{
} }
int A::foo() int A::foo() {
{ int i = 42;
int i = 42; return i;
return i;
} }
//!ExtractLocalVariableRefactoringTest proposed name in scope //!ExtractLocalVariableRefactoringTest proposed name in scope
@ -319,12 +279,11 @@ int A::foo()
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
class A class A {
{
public: public:
A(); A();
virtual ~A(); virtual ~A();
int foo(); int foo();
}; };
#endif /*A_H_*/ #endif /*A_H_*/
@ -333,12 +292,11 @@ public:
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
class A class A {
{
public: public:
A(); A();
virtual ~A(); virtual ~A();
int foo(); int foo();
}; };
#endif /*A_H_*/ #endif /*A_H_*/
@ -346,96 +304,94 @@ public:
//@A.cpp //@A.cpp
#include "A.h" #include "A.h"
A::A() A::A() {
{
} }
A::~A() A::~A() {
{
} }
int A::foo() int A::foo() {
{ int x = 3;
int x = 3; return /*$*/(x + 2)/*$$*/ * 15;
return /*$*/(x + 2)/*$$*/ * 15;
} }
//= //=
#include "A.h" #include "A.h"
A::A() A::A() {
{
} }
A::~A() A::~A() {
{
} }
int A::foo() int A::foo() {
{ int x = 3;
int x = 3; int i = x + 2;
int i = x + 2; return i * 15;
return i * 15;
} }
//!Bug #277065 extract local variable fails to extract from for loop //!Bug #277065 extract local variable fails to extract from for loop
//#org.eclipse.cdt.ui.tests.refactoring.extractlocalvariable.ExtractLocalVariableRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.extractlocalvariable.ExtractLocalVariableRefactoringTest
//@A.cpp //@A.cpp
void foo(){ void foo() {
for(int n = /*$*/5 + 2/*$$*/; n < 10; ++n); for (int n = /*$*/5 + 2/*$$*/; n < 10; ++n)
;
} }
//= //=
void foo(){ void foo() {
int i = 5 + 2; int i = 5 + 2;
for(int n = i; n < 10; ++n); for (int n = i; n < 10; ++n)
;
} }
//!ExtractLocalVariableRefactoringTest expression //!ExtractLocalVariableRefactoringTest expression
//#org.eclipse.cdt.ui.tests.refactoring.extractlocalvariable.ExtractLocalVariableRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.extractlocalvariable.ExtractLocalVariableRefactoringTest
//@A.cpp //@A.cpp
void foo(){ void foo() {
int a = 0; int a = 0;
float b = 0.1f; float b = 0.1f;
double c = /*$*/(a + b)/*$$*/ * 0.2; double c = /*$*/(a + b)/*$$*/ * 0.2;
} }
//= //=
void foo(){ void foo() {
int a = 0; int a = 0;
float b = 0.1f; float b = 0.1f;
float a0 = a + b; float a0 = a + b;
double c = a0 * 0.2; double c = a0 * 0.2;
} }
//!ExtractLocalVariableRefactoringTest pointer //!ExtractLocalVariableRefactoringTest pointer
//#org.eclipse.cdt.ui.tests.refactoring.extractlocalvariable.ExtractLocalVariableRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.extractlocalvariable.ExtractLocalVariableRefactoringTest
//@A.cpp //@A.cpp
void foo(){ void foo() {
int a[2]; int a[2];
int b = */*$*/(a + 1)/*$$*/; int b = */*$*/(a + 1)/*$$*/;
} }
//= //=
void foo(){ void foo() {
int a[2]; int a[2];
int *i = a + 1; int* i = a + 1;
int b = *i; int b = *i;
} }
//!ExtractLocalVariableRefactoringTest qualifiers //!ExtractLocalVariableRefactoringTest qualifiers
//#org.eclipse.cdt.ui.tests.refactoring.extractlocalvariable.ExtractLocalVariableRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.extractlocalvariable.ExtractLocalVariableRefactoringTest
//@A.cpp //@A.cpp
const volatile int *k; const volatile int* k;
void foo(){
/*$*/k;/*$$*/ void foo() {
/*$*/k;/*$$*/
} }
//= //=
const volatile int *k; const volatile int* k;
void foo(){
const volatile int *k0 = k; void foo() {
k0; const volatile int* k0 = k;
k0;
} }
//!ExtractLocalVariableRefactoringTest overloaded operators //!ExtractLocalVariableRefactoringTest overloaded operators
@ -443,24 +399,24 @@ void foo(){
//@A.cpp //@A.cpp
class K { class K {
public: public:
bool operator+(int b) {return true;} bool operator+(int b) { return true; }
float operator+(unsigned u) {return 1.0f;} float operator+(unsigned u) { return 1.0f; }
}; };
void foo(){ void foo() {
K k; K k;
/*$*/k+3u/*$$*/; /*$*/k+3u/*$$*/;
} }
//= //=
class K { class K {
public: public:
bool operator+(int b) {return true;} bool operator+(int b) { return true; }
float operator+(unsigned u) {return 1.0f;} float operator+(unsigned u) { return 1.0f; }
}; };
void foo(){ void foo() {
K k; K k;
float i = k + 3u; float i = k + 3u;
i; i;
} }
//!Bug 318784 DeclarationGenerator fails for some cases //!Bug 318784 DeclarationGenerator fails for some cases
@ -468,16 +424,16 @@ void foo(){
//@A.cpp //@A.cpp
void func() { void func() {
int *(*a)[2]; int* (*a)[2];
/*$*/a/*$$*/; /*$*/a/*$$*/;
} }
//= //=
void func() { void func() {
int *(*a)[2]; int* (*a)[2];
int *(*a0)[2] = a; int* (*a0)[2] = a;
a0; a0;
} }
//!Bug 331963 Extract local variable doesn't put template type parameters //!Bug 331963 Extract local variable doesn't put template type parameters
@ -491,10 +447,8 @@ class Foo {
Foo<int> getFoo(); Foo<int> getFoo();
int main() { int main() {
/*$*/getFoo()/*$$*/;
/*$*/getFoo()/*$$*/; return 0;
return 0;
} }
//= //=
@ -506,163 +460,163 @@ class Foo {
Foo<int> getFoo(); Foo<int> getFoo();
int main() { int main() {
Foo<int> foo = getFoo(); Foo<int> foo = getFoo();
foo; foo;
return 0;
return 0;
} }
//!Bug 331963 Extract local variable doesn't put template type parameters Namespace //!Bug 331963 Extract local variable doesn't put template type parameters Namespace
//#org.eclipse.cdt.ui.tests.refactoring.extractlocalvariable.ExtractLocalVariableRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.extractlocalvariable.ExtractLocalVariableRefactoringTest
//@A.cpp //@A.cpp
namespace bar{ namespace bar {
template<class T> template<class T>
class Foo { class Foo {
}; };
} }
bar::Foo<int> getFoo(); bar::Foo<int> getFoo();
int main() { int main() {
/*$*/getFoo()/*$$*/;
/*$*/getFoo()/*$$*/; return 0;
return 0;
} }
//= //=
namespace bar{ namespace bar {
template<class T> template<class T>
class Foo { class Foo {
}; };
} }
bar::Foo<int> getFoo(); bar::Foo<int> getFoo();
int main() { int main() {
bar::Foo<int> foo = getFoo(); bar::Foo<int> foo = getFoo();
foo; foo;
return 0;
return 0;
} }
//!Bug 330693 Improve suggested variable name in Extract Local Variable //!Bug 330693 Improve suggested variable name in Extract Local Variable
//#org.eclipse.cdt.ui.tests.refactoring.extractlocalvariable.ExtractLocalVariableRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.extractlocalvariable.ExtractLocalVariableRefactoringTest
//@A.cpp //@A.cpp
struct Foo{ struct Foo {
int getVarWithLongName(); int getVarWithLongName();
}; };
void bar(){ void bar() {
Foo f; Foo f;
/*$*/f.getVarWithLongName()/*$$*/; /*$*/f.getVarWithLongName()/*$$*/;
} }
//= //=
struct Foo{ struct Foo {
int getVarWithLongName(); int getVarWithLongName();
}; };
void bar(){ void bar() {
Foo f; Foo f;
int varWithLongName = f.getVarWithLongName(); int varWithLongName = f.getVarWithLongName();
varWithLongName; varWithLongName;
} }
//!Bug 330693 Improve suggested variable name in Extract Local Variable: name == prefix //!Bug 330693 Improve suggested variable name in Extract Local Variable: name == prefix
//#org.eclipse.cdt.ui.tests.refactoring.extractlocalvariable.ExtractLocalVariableRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.extractlocalvariable.ExtractLocalVariableRefactoringTest
//@A.cpp //@A.cpp
struct Foo{ struct Foo {
int get(); int get();
}; };
void bar(){ void bar() {
Foo f; Foo f;
/*$*/f.get()/*$$*/; /*$*/f.get()/*$$*/;
} }
//= //=
struct Foo{ struct Foo {
int get(); int get();
}; };
void bar(){ void bar() {
Foo f; Foo f;
int get = f.get(); int get = f.get();
get; get;
} }
//!Bug 335202 Suggested name is wrong for nested function calls - outer function call //!Bug 335202 Suggested name is wrong for nested function calls - outer function call
//#org.eclipse.cdt.ui.tests.refactoring.extractlocalvariable.ExtractLocalVariableRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.extractlocalvariable.ExtractLocalVariableRefactoringTest
//@A.cpp //@A.cpp
int getA(){ int getA() {
return 0; return 0;
}; };
int getB(int a){ int getB(int a) {
return a; return a;
} }
void bar(){ void bar() {
/*$*/getB(getA())/*$$*/; /*$*/getB(getA())/*$$*/;
} }
//= //=
int getA(){ int getA() {
return 0; return 0;
}; };
int getB(int a){ int getB(int a) {
return a; return a;
} }
void bar(){ void bar() {
int b = getB(getA()); int b = getB(getA());
b; b;
} }
//!Bug 335202 Suggested name is wrong for nested function calls - inner function call //!Bug 335202 Suggested name is wrong for nested function calls - inner function call
//#org.eclipse.cdt.ui.tests.refactoring.extractlocalvariable.ExtractLocalVariableRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.extractlocalvariable.ExtractLocalVariableRefactoringTest
//@A.cpp //@A.cpp
int getA(){ int getA() {
return 0; return 0;
}; };
int getB(int a){ int getB(int a) {
return a; return a;
} }
int getC(int a){ int getC(int a) {
return a; return a;
} }
void bar(){ void bar() {
getB(/*$*/getC(getA())/*$$*/); getB(/*$*/getC(getA())/*$$*/);
} }
//= //=
int getA(){ int getA() {
return 0; return 0;
}; };
int getB(int a){ int getB(int a) {
return a; return a;
} }
int getC(int a){ int getC(int a) {
return a; return a;
} }
void bar(){ void bar() {
int c = getC(getA()); int c = getC(getA());
getB(c); getB(c);
} }

View file

@ -1,14 +1,16 @@
//!extract local variable from for loop //!extract local variable from for loop
//#org.eclipse.cdt.ui.tests.refactoring.RefactoringHistoryTest //#org.eclipse.cdt.ui.tests.refactoring.RefactoringHistoryTest
//@main.cpp //@main.cpp
void foo(){ void foo() {
for(int n = 5 + 2; n < 10; ++n); for (int n = 5 + 2; n < 10; ++n)
;
} }
//= //=
void foo(){ void foo() {
int i = 5 + 2; int i = 5 + 2;
for(int n = i; n < 10; ++n); for (int n = i; n < 10; ++n)
;
} }
//@refScript.xml //@refScript.xml
@ -17,5 +19,5 @@ void foo(){
<refactoring comment="Extract 5 + 2" description="Extract Local Variable Refactoring" <refactoring comment="Extract 5 + 2" description="Extract Local Variable Refactoring"
fileName="file:$$projectPath$$/main.cpp" flags="4" fileName="file:$$projectPath$$/main.cpp" flags="4"
id="org.eclipse.cdt.internal.ui.refactoring.extractlocalvariable.ExtractLocalVariableRefactoring" id="org.eclipse.cdt.internal.ui.refactoring.extractlocalvariable.ExtractLocalVariableRefactoring"
name="i" project="RegressionTestProject" selection="25,5"/> name="i" project="RegressionTestProject" selection="27,5"/>
</session> </session>

View file

@ -4,8 +4,7 @@
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
class A class A {
{
public: public:
A(); A();
virtual ~A(); virtual ~A();
@ -21,8 +20,7 @@ private:
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
class A class A {
{
public: public:
A(); A();
virtual ~A(); virtual ~A();
@ -30,7 +28,7 @@ public:
private: private:
int help(); int help();
int exp(); int exp();
}; };
#endif /*A_H_*/ #endif /*A_H_*/
@ -38,52 +36,45 @@ private:
//@A.cpp //@A.cpp
#include "A.h" #include "A.h"
A::A() A::A() {
{
} }
A::~A() A::~A() {
{
} }
int A::foo()
{ int A::foo() {
int i = 2; int i = 2;
++i; ++i;
help(); help();
return i; return i;
} }
int A::help() int A::help() {
{
return 42; return 42;
} }
//= //=
#include "A.h" #include "A.h"
A::A() A::A() {
{
} }
A::~A() A::~A() {
{
}
int A::exp()
{
int i = 2;
++i;
help();
return i;
} }
int A::foo() int A::exp() {
{ int i = 2;
++i;
help();
return i;
}
int A::foo() {
int i = exp(); int i = exp();
return i; return i;
} }
int A::help() int A::help() {
{
return 42; return 42;
} }
@ -93,7 +84,7 @@ int A::help()
<refactoring comment="Create method exp" description="Extract Method Refactoring" <refactoring comment="Create method exp" description="Extract Method Refactoring"
fileName="file:$$projectPath$$/A.cpp" fileName="file:$$projectPath$$/A.cpp"
flags="4" id="org.eclipse.cdt.internal.ui.refactoring.extractfunction.ExtractFunctionRefactoring" flags="4" id="org.eclipse.cdt.internal.ui.refactoring.extractfunction.ExtractFunctionRefactoring"
name="exp" project="RegressionTestProject" selection="56,25" visibility="private"/> name="exp" project="RegressionTestProject" selection="57,25" visibility="private"/>
</session> </session>
@ -103,8 +94,7 @@ int A::help()
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
class A class A {
{
public: public:
A(); A();
virtual ~A(); virtual ~A();
@ -120,8 +110,7 @@ private:
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
class A class A {
{
public: public:
A(); A();
virtual ~A(); virtual ~A();
@ -129,7 +118,7 @@ public:
private: private:
int help(); int help();
void exp(int & i); void exp(int& i);
}; };
#endif /*A_H_*/ #endif /*A_H_*/
@ -137,15 +126,13 @@ private:
//@A.cpp //@A.cpp
#include "A.h" #include "A.h"
A::A() A::A() {
{
} }
A::~A() A::~A() {
{
} }
int A::foo()
{ int A::foo() {
int i = 2; int i = 2;
//comment //comment
++i; ++i;
@ -153,38 +140,33 @@ int A::foo()
return i; return i;
} }
int A::help() int A::help() {
{
return 42; return 42;
} }
//= //=
#include "A.h" #include "A.h"
A::A() A::A() {
{
} }
A::~A() A::~A() {
{
}
void A::exp(int & i)
{
//comment
++i;
help();
} }
int A::foo() void A::exp(int& i) {
{ //comment
++i;
help();
}
int A::foo() {
int i = 2; int i = 2;
//comment //comment
exp(i); exp(i);
return i; return i;
} }
int A::help() int A::help() {
{
return 42; return 42;
} }
@ -194,32 +176,29 @@ int A::help()
<refactoring comment="Create method exp" description="Extract Method Refactoring" <refactoring comment="Create method exp" description="Extract Method Refactoring"
fileName="file:$$projectPath$$/A.cpp" fileName="file:$$projectPath$$/A.cpp"
flags="4" id="org.eclipse.cdt.internal.ui.refactoring.extractfunction.ExtractFunctionRefactoring" flags="4" id="org.eclipse.cdt.internal.ui.refactoring.extractfunction.ExtractFunctionRefactoring"
name="exp" project="RegressionTestProject" selection="79,13" visibility="private"/> name="exp" project="RegressionTestProject" selection="69,24" visibility="private"/>
</session> </session>
//!Extract Function History first extracted statement with leading comment //!Extract Function History first extracted statement with leading comment
//#org.eclipse.cdt.ui.tests.refactoring.RefactoringHistoryTest //#org.eclipse.cdt.ui.tests.refactoring.RefactoringHistoryTest
//@main.cpp //@main.cpp
int main(){ int main() {
int i; int i;
// Comment // Comment
i= 7; i = 7;
return i; return i;
} }
//= //=
void exp(int & i) void exp(int& i) {
{ // Comment
// Comment i = 7;
i = 7;
} }
int main(){ int main() {
int i; int i;
// Comment // Comment
exp(i); exp(i);
return i; return i;
} }
@ -229,29 +208,26 @@ int main(){
<refactoring comment="Create method exp" description="Extract Method Refactoring" <refactoring comment="Create method exp" description="Extract Method Refactoring"
fileName="file:$$projectPath$$/main.cpp" fileName="file:$$projectPath$$/main.cpp"
flags="4" id="org.eclipse.cdt.internal.ui.refactoring.extractfunction.ExtractFunctionRefactoring" flags="4" id="org.eclipse.cdt.internal.ui.refactoring.extractfunction.ExtractFunctionRefactoring"
name="exp" project="RegressionTestProject" selection="35,5" visibility="private"/> name="exp" project="RegressionTestProject" selection="34,6" visibility="private"/>
</session> </session>
//!Extract Function History extracted statement with trailling comment //!Extract Function History extracted statement with trailling comment
//#org.eclipse.cdt.ui.tests.refactoring.RefactoringHistoryTest //#org.eclipse.cdt.ui.tests.refactoring.RefactoringHistoryTest
//@main.cpp //@main.cpp
int main(){ int main() {
int i; int i;
i= 7; // Comment i = 7; // Comment
return i; return i;
} }
//= //=
void exp(int & i) void exp(int& i) {
{ i = 7; // Comment
i = 7; // Comment
} }
int main(){ int main() {
int i; int i;
exp(i); // Comment exp(i); // Comment
return i; return i;
} }
@ -261,7 +237,7 @@ int main(){
<refactoring comment="Create method exp" description="Extract Method Refactoring" <refactoring comment="Create method exp" description="Extract Method Refactoring"
fileName="file:$$projectPath$$/main.cpp" fileName="file:$$projectPath$$/main.cpp"
flags="4" id="org.eclipse.cdt.internal.ui.refactoring.extractfunction.ExtractFunctionRefactoring" flags="4" id="org.eclipse.cdt.internal.ui.refactoring.extractfunction.ExtractFunctionRefactoring"
name="exp" project="RegressionTestProject" selection="23,5" visibility="private"/> name="exp" project="RegressionTestProject" selection="22,6" visibility="private"/>
</session> </session>
//!ExtractFunctionRefactoringTest duplicates with different Names History Test //!ExtractFunctionRefactoringTest duplicates with different Names History Test
@ -270,8 +246,7 @@ int main(){
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
class A class A {
{
public: public:
A(); A();
virtual ~A(); virtual ~A();
@ -287,8 +262,7 @@ private:
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
class A class A {
{
public: public:
A(); A();
virtual ~A(); virtual ~A();
@ -296,7 +270,7 @@ public:
private: private:
int help(); int help();
void exp(int & i); void exp(int& i);
}; };
#endif /*A_H_*/ #endif /*A_H_*/
@ -304,54 +278,49 @@ private:
//@A.cpp //@A.cpp
#include "A.h" #include "A.h"
A::A() A::A() {
{
} }
A::~A() A::~A() {
{
int oo = 99; int oo = 99;
++oo; ++oo;
help(); help();
}int A::foo() }
{
int A::foo() {
int i = 2; int i = 2;
++i; ++i;
help(); help();
return i; return i;
} }
int A::help() int A::help() {
{
return 42; return 42;
} }
//= //=
#include "A.h" #include "A.h"
A::A() A::A() {
{
} }
A::~A() A::~A() {
{
int oo = 99; int oo = 99;
exp(oo); exp(oo);
}void A::exp(int & i)
{
++i;
help();
} }
int A::foo() void A::exp(int& i) {
{ ++i;
help();
}
int A::foo() {
int i = 2; int i = 2;
exp(i); exp(i);
return i; return i;
} }
int A::help() int A::help() {
{
return 42; return 42;
} }
@ -360,5 +329,5 @@ int A::help()
<session version="1.0"> <session version="1.0">
<refactoring comment="Create method exp" description="Extract Method Refactoring" <refactoring comment="Create method exp" description="Extract Method Refactoring"
fileName="file:$$projectPath$$/A.cpp" flags="4" id="org.eclipse.cdt.internal.ui.refactoring.extractfunction.ExtractFunctionRefactoring" fileName="file:$$projectPath$$/A.cpp" flags="4" id="org.eclipse.cdt.internal.ui.refactoring.extractfunction.ExtractFunctionRefactoring"
name="exp" project="RegressionTestProject" replaceDuplicates="true" selection="97,13" visibility="private"/> name="exp" project="RegressionTestProject" replaceDuplicates="true" selection="99,13" visibility="private"/>
</session> </session>

View file

@ -4,8 +4,7 @@
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
class A class A {
{
public: public:
A(); A();
virtual ~A(); virtual ~A();
@ -21,8 +20,7 @@ private:
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
class A class A {
{
public: public:
A(); A();
virtual ~A(); virtual ~A();
@ -30,7 +28,7 @@ public:
private: private:
int help(); int help();
void exp(int & ii); void exp(int& ii);
}; };
#endif /*A_H_*/ #endif /*A_H_*/
@ -40,15 +38,13 @@ private:
#define ADD(a,ab) a + ab + 2 + a #define ADD(a,ab) a + ab + 2 + a
A::A() A::A() {
{
} }
A::~A() A::~A() {
{
} }
int A::foo()
{ int A::foo() {
int ii = 2; int ii = 2;
/*$*/++ii; /*$*/++ii;
ii = ADD(ii, 42); ii = ADD(ii, 42);
@ -56,8 +52,7 @@ int A::foo()
return ii; return ii;
} }
int A::help() int A::help() {
{
return 42; return 42;
} }
@ -66,29 +61,25 @@ int A::help()
#define ADD(a,ab) a + ab + 2 + a #define ADD(a,ab) a + ab + 2 + a
A::A() A::A() {
{
} }
A::~A() A::~A() {
{
}
void A::exp(int & ii)
{
++ii;
ii = ADD(ii, 42);
help();
} }
int A::foo() void A::exp(int& ii) {
{ ++ii;
ii = ADD(ii, 42);
help();
}
int A::foo() {
int ii = 2; int ii = 2;
exp(ii); exp(ii);
return ii; return ii;
} }
int A::help() int A::help() {
{
return 42; return 42;
} }
@ -101,14 +92,14 @@ returnparameterindex=1
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
class A class A {
{
public: public:
A(); A();
virtual ~A(); virtual ~A();
int foo(); int foo();
private: private:
int help(); int help();
}; };
#endif /*A_H_*/ #endif /*A_H_*/
@ -117,15 +108,15 @@ private:
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
class A class A {
{
public: public:
A(); A();
virtual ~A(); virtual ~A();
int foo(); int foo();
private: private:
int help(); int help();
int exp(int & i, int b); int exp(int& i, int b);
}; };
#endif /*A_H_*/ #endif /*A_H_*/
@ -135,26 +126,23 @@ private:
#define ADD(b) b = b + 2 #define ADD(b) b = b + 2
A::A() A::A() {
{
} }
A::~A() A::~A() {
{
} }
int A::foo()
{ int A::foo() {
int i = 2; int i = 2;
int b = 42; int b = 42;
/*$*/++i; /*$*/++i;
help(); help();
ADD(b);/*$$*/ ADD(b);/*$$*/
b += 2; b += 2;
return i; return i;
} }
int A::help() int A::help() {
{
return 42; return 42;
} }
@ -163,32 +151,28 @@ int A::help()
#define ADD(b) b = b + 2 #define ADD(b) b = b + 2
A::A() A::A() {
{
} }
A::~A() A::~A() {
{
}
int A::exp(int & i, int b)
{
++i;
help();
ADD(b);
return b;
} }
int A::foo() int A::exp(int& i, int b) {
{ ++i;
help();
ADD(b);
return b;
}
int A::foo() {
int i = 2; int i = 2;
int b = 42; int b = 42;
b = exp(i, b); b = exp(i, b);
b += 2; b += 2;
return i; return i;
} }
int A::help() int A::help() {
{
return 42; return 42;
} }
@ -202,14 +186,14 @@ replaceduplicates=true
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
class A class A {
{
public: public:
A(); A();
virtual ~A(); virtual ~A();
int foo(); int foo();
private: private:
int help(); int help();
}; };
#endif /*A_H_*/ #endif /*A_H_*/
@ -218,15 +202,15 @@ private:
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
class A class A {
{
public: public:
A(); A();
virtual ~A(); virtual ~A();
int foo(); int foo();
private: private:
int help(); int help();
int exp(int bb); int exp(int bb);
}; };
#endif /*A_H_*/ #endif /*A_H_*/
@ -236,26 +220,23 @@ private:
#define ADD(b) b = b + 2 #define ADD(b) b = b + 2
A::A() A::A() {
{
} }
A::~A() A::~A() {
{
} }
int A::foo()
{ int A::foo() {
int i = 2; int i = 2;
int bb = 42; int bb = 42;
++i; ++i;
/*$*/ADD(bb); /*$*/ADD(bb);
ADD(bb);/*$$*/ ADD(bb);/*$$*/
bb += 2; bb += 2;
return i; return i;
} }
int A::help() int A::help() {
{
return 42; return 42;
} }
@ -264,32 +245,28 @@ int A::help()
#define ADD(b) b = b + 2 #define ADD(b) b = b + 2
A::A() A::A() {
{
} }
A::~A() A::~A() {
{
}
int A::exp(int bb)
{
ADD(bb);
ADD(bb);
return bb;
} }
int A::foo() int A::exp(int bb) {
{ ADD(bb);
ADD(bb);
return bb;
}
int A::foo() {
int i = 2; int i = 2;
int bb = 42; int bb = 42;
++i; ++i;
bb = exp(bb); bb = exp(bb);
bb += 2; bb += 2;
return i; return i;
} }
int A::help() int A::help() {
{
return 42; return 42;
} }

View file

@ -6,11 +6,12 @@
#include <iostream> #include <iostream>
class A{ class A {
public: public:
A(); A();
void method2(); void method2();
std::string toString(); std::string toString();
private: private:
int i; int i;
}; };
@ -23,13 +24,14 @@ private:
#include <iostream> #include <iostream>
class A{ class A {
public: public:
A(); A();
std::string toString(); std::string toString();
private: private:
int i; int i;
void method2(); void method2();
}; };
#endif /*A_H_*/ #endif /*A_H_*/
@ -40,5 +42,5 @@ private:
<refactoring comment="Hide Method method2" description="Hide Method Refactoring" <refactoring comment="Hide Method method2" description="Hide Method Refactoring"
fileName="file:$$projectPath$$/A.h" flags="2" fileName="file:$$projectPath$$/A.h" flags="2"
id="org.eclipse.cdt.internal.ui.refactoring.hidemethod.HideMethodRefactoring" id="org.eclipse.cdt.internal.ui.refactoring.hidemethod.HideMethodRefactoring"
project="RegressionTestProject" selection="83,7"/> project="RegressionTestProject" selection="78,7"/>
</session> </session>

View file

@ -15,12 +15,10 @@ public:
bool a(int = 100) const; bool a(int = 100) const;
}; };
inline bool X::a(int int1) const inline bool X::a(int int1) const {
{
} }
//!Param const and reference and pointer two params //!Param const and reference and pointer two params
//#org.eclipse.cdt.ui.tests.refactoring.implementmethod.ImplementMethodRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.implementmethod.ImplementMethodRefactoringTest
//@.config //@.config
@ -38,37 +36,34 @@ public:
bool xy(int, int i) const; bool xy(int, int i) const;
}; };
inline bool X::xy(int int1, int i) const inline bool X::xy(int int1, int i) const {
{
} }
//!Test if TemplateMethod stays in header //!Test if TemplateMethod stays in header
//#org.eclipse.cdt.ui.tests.refactoring.implementmethod.ImplementMethodRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.implementmethod.ImplementMethodRefactoringTest
//@.config //@.config
filename=A.h filename=A.h
infos=1 infos=1
//@A.h //@A.h
template<class T> class A template<class T>
{ class A {
public: public:
/*$*/void test();/*$$*/ /*$*/void test();/*$$*/
}; };
//= //=
template<class T> class A template<class T>
{ class A {
public: public:
void test(); void test();
}; };
template<class T> inline void A<T>::test() template<class T>
{ inline void A<T>::test() {
} }
//@A.cpp //@A.cpp
#include "A.h" #include "A.h"
@ -81,45 +76,42 @@ template<class T> inline void A<T>::test()
filename=A.h filename=A.h
infos=1 infos=1
//@A.h //@A.h
template<class T> class A template<class T>
{ class A {
public: public:
A(); A();
/*$*/void test();/*$$*/ /*$*/void test();/*$$*/
}; };
template<class T> A<T>::A() template<class T>
{ A<T>::A() {
} }
//= //=
template<class T> class A template<class T>
{ class A {
public: public:
A(); A();
void test(); void test();
}; };
template<class T> A<T>::A() template<class T>
{ A<T>::A() {
} }
template<class T> inline void A<T>::test() template<class T>
{ inline void A<T>::test() {
} }
//!member class //!member class
//#org.eclipse.cdt.ui.tests.refactoring.implementmethod.ImplementMethodRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.implementmethod.ImplementMethodRefactoringTest
//@.config //@.config
filename=A.h filename=A.h
//@A.h //@A.h
class Demo class Demo {
{ class SubClass {
class SubClass
{
/*$*/void test();/*$$*/ /*$*/void test();/*$$*/
}; };
}; };
@ -131,102 +123,88 @@ class Demo
//= //=
#include "A.h" #include "A.h"
void Demo::SubClass::test() {
void Demo::SubClass::test()
{
} }
//!Method declared in otherwise empty class without cpp file
//!method declared in otherwise empty class without cpp file
//#org.eclipse.cdt.ui.tests.refactoring.implementmethod.ImplementMethodRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.implementmethod.ImplementMethodRefactoringTest
//@.config //@.config
filename=A.h filename=A.h
infos=1 infos=1
//@A.h //@A.h
class A class A {
{
public: public:
/*$*/void test();/*$$*/ /*$*/void test();/*$$*/
}; };
//= //=
class A class A {
{
public: public:
void test(); void test();
}; };
inline void A::test() inline void A::test() {
{
} }
//!Method declared in otherwise empty class
//!method declared in otherwise empty class
//#org.eclipse.cdt.ui.tests.refactoring.implementmethod.ImplementMethodRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.implementmethod.ImplementMethodRefactoringTest
//@.config //@.config
filename=A.h filename=A.h
//@A.h //@A.h
class A class A {
{
public: public:
/*$*/void test();/*$$*/ /*$*/void test();/*$$*/
}; };
//= //=
class A class A {
{
public: public:
void test(); void test();
}; };
//@A.cpp //@A.cpp
//= //=
void A::test() {
void A::test()
{
} }
//!Implement in existing namespace
//!implement in existing namespace
//#org.eclipse.cdt.ui.tests.refactoring.implementmethod.ImplementMethodRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.implementmethod.ImplementMethodRefactoringTest
//@.config //@.config
filename=A.h filename=A.h
//@A.h //@A.h
namespace NameSpace namespace Namespace {
{
class ClassInNamespace class ClassInNamespace {
{ public:
public: int test();
int test(); /*$*/void test2();/*$$*/
/*$*/void test2();/*$$*/ };
};
} }
//@A.cpp //@A.cpp
#include "A.h" #include "A.h"
namespace NameSpace namespace Namespace {
{
int ClassInNamespace::test() int ClassInNamespace::test() {
{ return 5;
return 5; }
}
} }
//= //=
#include "A.h" #include "A.h"
namespace NameSpace namespace Namespace {
{
int ClassInNamespace::test() int ClassInNamespace::test() {
{ return 5;
return 5; }
}
void ClassInNamespace::test2() {
}
void ClassInNamespace::test2()
{}
} }
//!virtual method in the middle of con/destructor, without parameters and void return value //!virtual method in the middle of con/destructor, without parameters and void return value
//#org.eclipse.cdt.ui.tests.refactoring.implementmethod.ImplementMethodRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.implementmethod.ImplementMethodRefactoringTest
@ -236,8 +214,7 @@ filename=A.h
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
class A class A {
{
public: public:
A(); A();
/*$*/virtual void foo();/*$$*/ /*$*/virtual void foo();/*$$*/
@ -248,30 +225,25 @@ public:
//@A.cpp //@A.cpp
#include "A.h" #include "A.h"
A::A() A::A() {
{
} }
A::~A() A::~A() {
{
} }
//= //=
#include "A.h" #include "A.h"
A::A() A::A() {
{
} }
void A::foo() void A::foo() {
{
} }
A::~A() A::~A() {
{
} }
//!implement a function at start of source file //!Implement a function at start of source file
//#org.eclipse.cdt.ui.tests.refactoring.implementmethod.ImplementMethodRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.implementmethod.ImplementMethodRefactoringTest
//@.config //@.config
filename=A.h filename=A.h
@ -279,18 +251,15 @@ filename=A.h
/*$*/void function();/*$$*/ /*$*/void function();/*$$*/
void function_with_impl(); void function_with_impl();
//@A.cpp //@A.cpp
void function_with_impl() void function_with_impl() {
{
} }
//= //=
void function() void function() {
{
} }
void function_with_impl() void function_with_impl() {
{
} }
//!method at end, without parameters and void return value //!Method at end, without parameters and void return value
//#org.eclipse.cdt.ui.tests.refactoring.implementmethod.ImplementMethodRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.implementmethod.ImplementMethodRefactoringTest
//@.config //@.config
filename=A.h filename=A.h
@ -298,8 +267,7 @@ filename=A.h
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
class A class A {
{
public: public:
A(); A();
/*$*/void foo();/*$$*/ /*$*/void foo();/*$$*/
@ -309,24 +277,20 @@ public:
//@A.cpp //@A.cpp
#include "A.h" #include "A.h"
A::A() A::A() {
{
} }
//= //=
#include "A.h" #include "A.h"
A::A() A::A() {
{
} }
void A::foo() void A::foo() {
{
} }
//!Method at beginning, without parameters, void return value and const
//!method at beginning, without parameters, void return value and const
//#org.eclipse.cdt.ui.tests.refactoring.implementmethod.ImplementMethodRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.implementmethod.ImplementMethodRefactoringTest
//@.config //@.config
filename=A.h filename=A.h
@ -334,8 +298,7 @@ filename=A.h
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
class A class A {
{
public: public:
/*$*/void foo() const;/*$$*/ /*$*/void foo() const;/*$$*/
A(); A();
@ -345,22 +308,19 @@ public:
//@A.cpp //@A.cpp
#include "A.h" #include "A.h"
A::A() A::A() {
{
} }
//= //=
#include "A.h" #include "A.h"
void A::foo() const void A::foo() const {
{
} }
A::A() A::A() {
{
} }
//!method with int return value //!Method with int return value
//#org.eclipse.cdt.ui.tests.refactoring.implementmethod.ImplementMethodRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.implementmethod.ImplementMethodRefactoringTest
//@.config //@.config
filename=A.h filename=A.h
@ -368,8 +328,7 @@ filename=A.h
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
class A class A {
{
public: public:
A(); A();
/*$*/int foo();/*$$*/ /*$*/int foo();/*$$*/
@ -379,24 +338,20 @@ public:
//@A.cpp //@A.cpp
#include "A.h" #include "A.h"
A::A() A::A() {
{
} }
//= //=
#include "A.h" #include "A.h"
A::A() A::A() {
{
} }
int A::foo() int A::foo() {
{
} }
//!Method with two int parameters
//!method with two int parameters
//#org.eclipse.cdt.ui.tests.refactoring.implementmethod.ImplementMethodRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.implementmethod.ImplementMethodRefactoringTest
//@.config //@.config
filename=A.h filename=A.h
@ -404,8 +359,7 @@ filename=A.h
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
class A class A {
{
public: public:
A(); A();
/*$*/int foo(int param1, int param2);/*$$*/ /*$*/int foo(int param1, int param2);/*$$*/
@ -415,59 +369,49 @@ public:
//@A.cpp //@A.cpp
#include "A.h" #include "A.h"
A::A() A::A() {
{
} }
//= //=
#include "A.h" #include "A.h"
A::A() A::A() {
{
} }
int A::foo(int param1, int param2) int A::foo(int param1, int param2) {
{
} }
//!Method defined in header
//!method defined in header
//#org.eclipse.cdt.ui.tests.refactoring.implementmethod.ImplementMethodRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.implementmethod.ImplementMethodRefactoringTest
//@.config //@.config
filename=A.h filename=A.h
infos=1 infos=1
//@A.h //@A.h
class A class A {
{
public: public:
A(); A();
/*$*/void test();/*$$*/ /*$*/void test();/*$$*/
}; };
A::A() A::A() {
{
} }
//= //=
class A class A {
{
public: public:
A(); A();
void test(); void test();
}; };
A::A() A::A() {
{
} }
inline void A::test() inline void A::test() {
{
} }
//!Implement a function at end of source file
//!implement a function at end of source file
//#org.eclipse.cdt.ui.tests.refactoring.implementmethod.ImplementMethodRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.implementmethod.ImplementMethodRefactoringTest
//@.config //@.config
filename=A.h filename=A.h
@ -475,113 +419,111 @@ filename=A.h
void function_with_impl(); void function_with_impl();
/*$*/void function();/*$$*/ /*$*/void function();/*$$*/
//@A.cpp //@A.cpp
void function_with_impl() void function_with_impl() {
{
} }
//= //=
void function_with_impl() void function_with_impl() {
{
} }
void function() void function() {
{
} }
//!Implement with namespace
//!implement with namespace
//#org.eclipse.cdt.ui.tests.refactoring.implementmethod.ImplementMethodRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.implementmethod.ImplementMethodRefactoringTest
//@.config //@.config
filename=A.h filename=A.h
//@A.h //@A.h
namespace NameSpace namespace Namespace {
{
class ClassInNamespace class ClassInNamespace {
{ public:
public: int other_test();
int other_test(); /*$*/void test();/*$$*/
/*$*/void test();/*$$*/ };
};
} }
//@A.cpp //@A.cpp
#include "A.h" #include "A.h"
void NameSpace::ClassInNamespace::other_test() void Namespace::ClassInNamespace::other_test() {
{
} }
//= //=
#include "A.h" #include "A.h"
void NameSpace::ClassInNamespace::other_test() void Namespace::ClassInNamespace::other_test() {
{
} }
void NameSpace::ClassInNamespace::test() void Namespace::ClassInNamespace::test() {
{
} }
//!Implement function within namespace
//!implement function within namespace
//#org.eclipse.cdt.ui.tests.refactoring.implementmethod.ImplementMethodRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.implementmethod.ImplementMethodRefactoringTest
//@.config //@.config
filename=A.h filename=A.h
//@A.h //@A.h
namespace OuterSpace { namespace OuterSpace {
namespace NameSpace namespace Namespace {
{
int test(); int test();
/*$*/int test2();/*$$*/ /*$*/int test2();/*$$*/
}
}
} }
//@A.cpp //@A.cpp
#include "A.h" #include "A.h"
namespace OuterSpace { namespace OuterSpace {
int NameSpace::test()
{ int Namespace::test() {
} }
} }
//= //=
#include "A.h" #include "A.h"
namespace OuterSpace { namespace OuterSpace {
int NameSpace::test()
{
}
int NameSpace::test2() int Namespace::test() {
{}
} }
//!implement function within namespaces
int Namespace::test2() {
}
}
//!Implement function within namespaces
//#org.eclipse.cdt.ui.tests.refactoring.implementmethod.ImplementMethodRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.implementmethod.ImplementMethodRefactoringTest
//@.config //@.config
filename=A.h filename=A.h
//@A.h //@A.h
namespace OuterSpace { namespace OuterSpace {
namespace NameSpace namespace Namespace {
{
int test(); int test();
/*$*/int test2();/*$$*/ /*$*/int test2();/*$$*/
}
}
} }
//@A.cpp //@A.cpp
#include "A.h" #include "A.h"
namespace OuterSpace { namespace OuterSpace {
namespace NameSpace { namespace Namespace {
int test()
{ int test() {
} }
}
}
} }
//= //=
#include "A.h" #include "A.h"
namespace OuterSpace { namespace OuterSpace {
namespace NameSpace { namespace Namespace {
int test()
{
}
int test2() int test() {
{} }
}
int test2() {
}
}
} }
//!class template member functions with multiple templates //!class template member functions with multiple templates
//#org.eclipse.cdt.ui.tests.refactoring.implementmethod.ImplementMethodRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.implementmethod.ImplementMethodRefactoringTest
@ -589,43 +531,41 @@ namespace OuterSpace {
filename=A.h filename=A.h
infos=1 infos=1
//@A.h //@A.h
template<class T, class U> class A template<class T, class U>
{ class A {
public: public:
A(); A();
/*$*/void test();/*$$*/ /*$*/void test();/*$$*/
}; };
template<class T, class U> A<T,U>::A() template<class T, class U>
{ A<T,U>::A() {
} }
//= //=
template<class T, class U> class A template<class T, class U>
{ class A {
public: public:
A(); A();
void test(); void test();
}; };
template<class T, class U> A<T,U>::A() template<class T, class U>
{ A<T,U>::A() {
} }
template<class T, class U> inline void A<T,U>::test() template<class T, class U>
{ inline void A<T, U>::test() {
} }
//!with default parameters //!with default parameters
//#org.eclipse.cdt.ui.tests.refactoring.implementmethod.ImplementMethodRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.implementmethod.ImplementMethodRefactoringTest
//@.config //@.config
filename=A.h filename=A.h
//@A.h //@A.h
class Class class Class {
{
public: public:
/*$*/void test(int param1, int param2 = 5, int param3 = 10);/*$$*/ /*$*/void test(int param1, int param2 = 5, int param3 = 10);/*$$*/
}; };
@ -637,20 +577,15 @@ public:
//= //=
#include "A.h" #include "A.h"
void Class::test(int param1, int param2, int param3) {
void Class::test(int param1, int param2, int param3)
{
} }
//!static method //!static method
//#org.eclipse.cdt.ui.tests.refactoring.implementmethod.ImplementMethodRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.implementmethod.ImplementMethodRefactoringTest
//@.config //@.config
filename=A.h filename=A.h
//@A.h //@A.h
class Class class Class {
{
public: public:
/*$*/static void test();/*$$*/ /*$*/static void test();/*$$*/
}; };
@ -662,12 +597,8 @@ public:
//= //=
#include "A.h" #include "A.h"
void Class::test() {
void Class::test()
{
} }
//! Bug 238253 Pointer refence of the return value lost //! Bug 238253 Pointer refence of the return value lost
//#org.eclipse.cdt.ui.tests.refactoring.implementmethod.ImplementMethodRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.implementmethod.ImplementMethodRefactoringTest
//@.config //@.config
@ -686,21 +617,16 @@ public:
//= //=
#include "A.h" #include "A.h"
int* TestClass::get(char* val) {
int *TestClass::get(char *val)
{
} }
//! Bug 238554 void parameters //! Bug 238554 void parameters
//#org.eclipse.cdt.ui.tests.refactoring.implementmethod.ImplementMethodRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.implementmethod.ImplementMethodRefactoringTest
//@.config //@.config
filename=A.h filename=A.h
//@A.h //@A.h
class Test class Test {
{ public:
public:
/*$*/void doNothing(void);/*$$*/ /*$*/void doNothing(void);/*$$*/
}; };
@ -711,12 +637,8 @@ class Test
//= //=
#include "A.h" #include "A.h"
void Test::doNothing(void) {
void Test::doNothing(void)
{
} }
//! Bug 282989 Refactor->Implement method option doesn't qualify the name in the method definition with a fully qualified container class name //! Bug 282989 Refactor->Implement method option doesn't qualify the name in the method definition with a fully qualified container class name
//#org.eclipse.cdt.ui.tests.refactoring.implementmethod.ImplementMethodRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.implementmethod.ImplementMethodRefactoringTest
//@.config //@.config
@ -726,10 +648,12 @@ infos=1
#ifndef TESTCLASS_H_ #ifndef TESTCLASS_H_
#define TESTCLASS_H_ #define TESTCLASS_H_
namespace nspace{ namespace nspace {
class TestClass { class TestClass {
void /*$*/testMethod()/*$$*/; void /*$*/testMethod()/*$$*/;
}; };
} }
#endif /* TESTCLASS_H_ */ #endif /* TESTCLASS_H_ */
@ -738,18 +662,18 @@ void /*$*/testMethod()/*$$*/;
#ifndef TESTCLASS_H_ #ifndef TESTCLASS_H_
#define TESTCLASS_H_ #define TESTCLASS_H_
namespace nspace{ namespace nspace {
class TestClass { class TestClass {
void testMethod(); void testMethod();
}; };
} }
inline void nspace::TestClass::testMethod() inline void nspace::TestClass::testMethod() {
{
} }
#endif /* TESTCLASS_H_ */ #endif /* TESTCLASS_H_ */
//!Bug 290110 Source-> Implement Method //!Bug 290110 Source-> Implement Method
@ -768,6 +692,7 @@ public:
A(); A();
~A(); ~A();
void testmethod(int x); void testmethod(int x);
protected: protected:
class B { class B {
public: public:
@ -810,12 +735,10 @@ A::~A() {
} }
} }
void n1::n2::A::B::testmethod2() void n1::n2::A::B::testmethod2() {
{
} }
//!Bug 337040 - Insert definition in empty implementation file (.cxx) //!Bug 337040 - Insert definition in empty implementation file (.cxx)
//#org.eclipse.cdt.ui.tests.refactoring.implementmethod.ImplementMethodRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.implementmethod.ImplementMethodRefactoringTest
//@.config //@.config
@ -832,12 +755,8 @@ public:
//= //=
void TestClass::foo() {
void TestClass::foo()
{
} }
//!Bug 355006 - NPE implementing template function //!Bug 355006 - NPE implementing template function
//#org.eclipse.cdt.ui.tests.refactoring.implementmethod.ImplementMethodRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.implementmethod.ImplementMethodRefactoringTest
//@.config //@.config
@ -845,15 +764,14 @@ filename=A.h
infos=1 infos=1
//@A.h //@A.h
/*$*/template<typename T> void func(T&);/*$$*/ /*$*/template<typename T>
void func(T&);/*$$*/
//= //=
template<typename T> void func(T&); template<typename T>
void func(T&);
template<typename T> inline void func(T& ) template<typename T>
{ inline void func(T&) {
} }

View file

@ -6,7 +6,7 @@ newfilecreation=true
newfiles=A.cpp newfiles=A.cpp
//@A.h //@A.h
void /*$*/freefunction/*$$*/() { void /*$*/freefunction/*$$*/() {
return; return;
} }
//= //=
void freefunction(); void freefunction();
@ -17,9 +17,8 @@ void freefunction();
#include "A.h" #include "A.h"
void freefunction() void freefunction() {
{ return;
return;
} }
//!FreefunctionFromImplToHeader //!FreefunctionFromImplToHeader
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
@ -28,9 +27,8 @@ filename=A.cpp
newfilecreation=true newfilecreation=true
newfiles=A.h newfiles=A.h
//@A.cpp //@A.cpp
void /*$*/freefunction/*$$*/() void /*$*/freefunction/*$$*/() {
{ return;
return;
} }
//= //=
#include "A.h" #include "A.h"
@ -40,8 +38,7 @@ void /*$*/freefunction/*$$*/()
//= //=
void freefunction() void freefunction() {
{ return;
return;
} }

View file

@ -7,16 +7,14 @@ filename=A.h
using namespace std; using namespace std;
class A { class A {
int /*$*/member/*$$*/(); int /*$*/member/*$$*/();
}; };
//= //=
#include<iostream> #include<iostream>
using namespace std; using namespace std;
class A { class A {
int member() int member() {
{ return int();
return int(); }
}
}; };

View file

@ -4,208 +4,190 @@
filename=A.h filename=A.h
//@A.h //@A.h
class A { class A {
void /*$*/member/*$$*/() void /*$*/member/*$$*/() {
{ // return comment
// return comment return;
return; }
}
}; };
//= //=
class A { class A {
void member(); void member();
}; };
inline void A::member() inline void A::member() {
{ // return comment
// return comment return;
return;
} }
//!ClassToHeaderTopCommentOrder //!ClassToHeaderTopCommentOrder
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config //@.config
filename=A.h filename=A.h
//@A.h //@A.h
class A { class A {
// First Top Comment // First Top Comment
// Second Top Comment // Second Top Comment
void /*$*/member/*$$*/() void /*$*/member/*$$*/() {
{ return;
return; }
}
}; };
//= //=
class A { class A {
// First Top Comment // First Top Comment
// Second Top Comment // Second Top Comment
void member(); void member();
}; };
inline void A::member() inline void A::member() {
{ return;
return;
} }
//!ClassToHeaderCatchComment //!ClassToHeaderCatchComment
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config //@.config
filename=A.h filename=A.h
//@A.h //@A.h
class A { class A {
void /*$*/member/*$$*/() try void /*$*/member/*$$*/() try
{ {
return; return;
} catch (int i) { }
// catch comment catch (int i) {
} // catch comment
}
}; };
//= //=
class A { class A {
void member(); void member();
}; };
inline void A::member() inline void A::member()
try try {
{ return;
return;
} }
catch(int i){ catch (int i) {
// catch comment // catch comment
} }
//!ClassToHeaderTopComment //!ClassToHeaderTopComment
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config //@.config
filename=A.h filename=A.h
//@A.h //@A.h
class A { class A {
// Top comment // Top comment
void /*$*/member/*$$*/() void /*$*/member/*$$*/() {
{ return;
return; }
}
}; };
//= //=
class A { class A {
// Top comment // Top comment
void member(); void member();
}; };
inline void A::member() inline void A::member() {
{ return;
return;
} }
//!ClassToHeaderTemplateTopComment //!ClassToHeaderTemplateTopComment
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config //@.config
filename=A.h filename=A.h
//@A.h //@A.h
class A { class A {
// Top comment // Top comment
template<typename T> template<typename T>
T /*$*/member/*$$*/() T /*$*/member/*$$*/() {
{ return T();
return T(); }
}
}; };
//= //=
class A { class A {
// Top comment // Top comment
template<typename T> template<typename T>
T member(); T member();
}; };
// Top comment // Top comment
template<typename T> inline T A::member() template<typename T>
{ inline T A::member() {
return T(); return T();
} }
//!ClassToHeaderTrailingComment //!ClassToHeaderTrailingComment
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config //@.config
filename=A.h filename=A.h
//@A.h //@A.h
class A { class A {
void /*$*/member/*$$*/() void /*$*/member/*$$*/() {
{ return;
return; } // Trailing comment
} // Trailing comment
}; };
//= //=
class A { class A {
void member(); void member();
}; };
inline void A::member() inline void A::member() {
{ return;
return;
} // Trailing comment } // Trailing comment
//!ClassToHeaderTrailingCommentWithTryBlock //!ClassToHeaderTrailingCommentWithTryBlock
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config //@.config
filename=A.h filename=A.h
//@A.h //@A.h
class A { class A {
void /*$*/member/*$$*/() try void /*$*/member/*$$*/()
{ try {
return; return;
} catch (int e) { }
} // Trailing comment catch (int e) {
} // Trailing comment
}; };
//= //=
class A { class A {
void member(); void member();
}; };
inline void A::member() inline void A::member()
try try {
{ return;
return;
} }
catch(int e){ catch (int e) {
} }
// Trailing comment // Trailing comment
//!ClassToHeaderTrailingMultipleCommentsInTryBlock //!ClassToHeaderTrailingMultipleCommentsInTryBlock
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config //@.config
filename=A.h filename=A.h
//@A.h //@A.h
class A { class A {
int /*$*/member/*$$*/() try int /*$*/member/*$$*/()
{ try {
// aans // aans
} /* one */ catch (int i) { } /* one */ catch (int i) {
// zwaa // zwaa
} /* two */ catch (int j) { } /* two */ catch (int j) {
// draa // draa
} /* three */ } /* three */
}; };
//= //=
class A { class A {
int member(); int member();
}; };
inline int A::member() inline int A::member()
try try {
{ // aans
// aans
} /* one */ } /* one */
catch(int i){ catch (int i) {
// zwaa // zwaa
} }
/* two */catch(int j){ /* two */catch (int j) {
// draa // draa
} }
/* three */ /* three */

View file

@ -5,21 +5,21 @@ filename=A.h
//@A.h //@A.h
template<typename T> template<typename T>
class A { class A {
T /*$*/member/*$$*/(); T /*$*/member/*$$*/();
}; };
template<typename T> inline T A<T>::member() { template<typename T>
// body comment inline T A<T>::member() {
return T(); // body comment
return T();
} }
//= //=
template<typename T> template<typename T>
class A { class A {
T member() T member() {
{ // body comment
// body comment return T();
return T(); }
}
}; };
@ -32,27 +32,25 @@ template<typename T>
class A { class A {
// First comment // First comment
// Second comment // Second comment
T /*$*/member/*$$*/(); T /*$*/member/*$$*/();
}; };
// Third comment // Third comment
// Fourth comment // Fourth comment
template<typename T> template<typename T>
inline T A<T>::member() inline T A<T>::member() {
{ return T();
return T();
} }
//= //=
template<typename T> template<typename T>
class A { class A {
// Third comment // Third comment
// Fourth comment // Fourth comment
// First comment // First comment
// Second comment // Second comment
T member() T member() {
{ return T();
return T(); }
}
}; };
@ -65,32 +63,35 @@ filename=A.h
//@A.h //@A.h
template<typename T> template<typename T>
class A { class A {
T /*$*/member/*$$*/(); T /*$*/member/*$$*/();
}; };
template<typename T> inline T A<T>::member() try { template<typename T>
// body comment inline T A<T>::member()
return T(); try {
} catch(int e) { // body comment
// Catch 1 return T();
} catch(int e) { }
// Catch 2 catch (int e) {
// Catch 1
}
catch (int e) {
// Catch 2
} }
//= //=
template<typename T> template<typename T>
class A { class A {
T member() T member()
try try {
{ // body comment
// body comment return T();
return T(); }
} catch (int e) {
catch(int e){ // Catch 1
// Catch 1 }
} catch (int e) {
catch(int e){ // Catch 2
// Catch 2 }
}
}; };
@ -101,29 +102,27 @@ filename=A.h
//@A.h //@A.h
template<typename S, typename T> template<typename S, typename T>
class A { class A {
// Top Comment // Top Comment
template<typename U, typename V> template<typename U, typename V>
T /*$*/member/*$$*/(); T /*$*/member/*$$*/();
}; };
// 2nd Top Comment // 2nd Top Comment
template<typename S, typename T> template<typename S, typename T>
template<typename U, typename V> template<typename U, typename V>
inline T A<S, T>::member() { inline T A<S, T>::member() {
// body comment // body comment
return T(); return T();
} }
//= //=
template<typename S, typename T> template<typename S, typename T>
class A { class A {
// Top Comment // Top Comment
template<typename U, typename V> template<typename U, typename V>
T member() T member() {
{ // body comment
// body comment return T();
return T(); }
}
}; };
@ -136,21 +135,21 @@ filename=A.h
//@A.h //@A.h
template<typename T> template<typename T>
class A { class A {
T /*$*/member/*$$*/(); T /*$*/member/*$$*/();
}; };
// Top comment // Top comment
template<typename T> inline T A<T>::member() { template<typename T>
return T(); inline T A<T>::member() {
return T();
} }
//= //=
template<typename T> template<typename T>
class A { class A {
// Top comment // Top comment
T member() T member() {
{ return T();
return T(); }
}
}; };

View file

@ -4,16 +4,16 @@
filename=A.h filename=A.h
//@A.h //@A.h
class A { class A {
void /*$*/member/*$$*/(); void /*$*/member/*$$*/();
}; };
inline void A::member() { inline void A::member() {
// body comment // body comment
return; return;
} }
//= //=
class A { class A {
void member(); void member();
}; };
@ -22,30 +22,27 @@ class A {
//= //=
#include "A.h" #include "A.h"
void A::member() {
void A::member() // body comment
{ return;
// body comment
return;
} }
//!HeaderToImplTryCatchComment //!HeaderToImplTryCatchComment
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config //@.config
filename=A.h filename=A.h
//@A.h //@A.h
class A { class A {
void /*$*/member/*$$*/(); void /*$*/member/*$$*/();
}; };
inline void A::member() try { inline void A::member() try {
// body comment // body comment
return; return;
} catch /*1*/ (int e) { /*2*/ } } catch /*1*/ (int e) { /*2*/ }
catch /*3*/ (int e) { /*4*/ } catch /*3*/ (int e) { /*4*/ }
//= //=
class A { class A {
void member(); void member();
}; };
@ -54,37 +51,34 @@ class A {
//= //=
#include "A.h" #include "A.h"
void A::member() void A::member()
try try {
{ // body comment
// body comment return;
return;
} }
catch(/*1*/int e){ catch (/*1*/int e) {
/*2*/ /*2*/
} }
catch(/*3*/int e){ catch (/*3*/int e) {
/*4*/ /*4*/
} }
//!HeaderToImplTopComment //!HeaderToImplTopComment
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config //@.config
filename=A.h filename=A.h
//@A.h //@A.h
class A { class A {
void /*$*/member/*$$*/(); void /*$*/member/*$$*/();
}; };
// Top comment // Top comment
inline void A::member() { inline void A::member() {
// body comment // body comment
return; return;
} }
//= //=
class A { class A {
void member(); void member();
}; };
@ -94,14 +88,11 @@ class A {
//= //=
#include "A.h" #include "A.h"
// Top comment // Top comment
void A::member() void A::member() {
{ // body comment
// body comment return;
return;
} }
//!HeaderToImplFreeFuncTopComment //!HeaderToImplFreeFuncTopComment
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config //@.config
@ -109,7 +100,7 @@ filename=A.h
//@A.h //@A.h
// Definition comment // Definition comment
void /*$*/member/*$$*/() { void /*$*/member/*$$*/() {
return; return;
} }
//= //=
// Definition comment // Definition comment
@ -121,11 +112,7 @@ void member();
//= //=
#include "A.h" #include "A.h"
// Definition comment // Definition comment
void member() void member() {
{ return;
return;
} }

View file

@ -5,10 +5,9 @@ filename=A.cpp
//@A.cpp //@A.cpp
#include "A.h" #include "A.h"
void A::/*$*/member/*$$*/() void A::/*$*/member/*$$*/() {
{ // body comment
// body comment return;
return;
} }
//= //=
#include "A.h" #include "A.h"
@ -16,15 +15,14 @@ void A::/*$*/member/*$$*/()
//@A.h //@A.h
class A { class A {
void member(); void member();
}; };
//= //=
class A { class A {
void member() void member() {
{ // body comment
// body comment return;
return; }
}
}; };
//!ImplToHeaderTopComment //!ImplToHeaderTopComment
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
@ -34,9 +32,8 @@ filename=A.cpp
#include "A.h" #include "A.h"
// Definition comment // Definition comment
void A::/*$*/member/*$$*/() void A::/*$*/member/*$$*/() {
{ return;
return;
} }
//= //=
#include "A.h" #include "A.h"
@ -45,15 +42,14 @@ void A::/*$*/member/*$$*/()
//@A.h //@A.h
class A { class A {
void member(); void member();
}; };
//= //=
class A { class A {
// Definition comment // Definition comment
void member() void member() {
{ return;
return; }
}
}; };
//!ImplToHeaderTryCatchComment //!ImplToHeaderTryCatchComment
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
@ -63,9 +59,8 @@ filename=A.cpp
#include "A.h" #include "A.h"
// Definition comment // Definition comment
void A::/*$*/member/*$$*/() try void A::/*$*/member/*$$*/() try {
{ return;
return;
} /*1*/ catch (int e) { /*2*/ } /*3*/ catch (int e) { /*4*/ } } /*1*/ catch (int e) { /*2*/ } /*3*/ catch (int e) { /*4*/ }
//= //=
#include "A.h" #include "A.h"
@ -74,22 +69,21 @@ void A::/*$*/member/*$$*/() try
//@A.h //@A.h
class A { class A {
void member(); void member();
}; };
//= //=
class A { class A {
// Definition comment // Definition comment
void member() void member()
try try {
{ return;
return; } /*1*/
} /*1*/ catch (int e) {
catch(int e){ /*2*/
/*2*/ }
} /*3*/catch (int e) {
/*3*/catch(int e){ /*4*/
/*4*/ }
}
}; };
//!ImplToHeaderBodyCommentWithoutDeclaration //!ImplToHeaderBodyCommentWithoutDeclaration
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
@ -98,10 +92,9 @@ filename=A.cpp
//@A.cpp //@A.cpp
#include "A.h" #include "A.h"
void /*$*/member/*$$*/() void /*$*/member/*$$*/() {
{ // body comment
// body comment return;
return;
} }
//= //=
#include "A.h" #include "A.h"
@ -111,14 +104,10 @@ void /*$*/member/*$$*/()
//= //=
void member() {
// body comment
void member() return;
{
// body comment
return;
} }
//!ImplToHeaderTopCommentWithoutDeclaration //!ImplToHeaderTopCommentWithoutDeclaration
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config //@.config
@ -127,10 +116,9 @@ filename=A.cpp
#include "A.h" #include "A.h"
// Top comment // Top comment
void /*$*/member/*$$*/() void /*$*/member/*$$*/() {
{ // body comment
// body comment return;
return;
} }
//= //=
#include "A.h" #include "A.h"
@ -141,12 +129,8 @@ void /*$*/member/*$$*/()
//= //=
// Top comment // Top comment
void member() void member() {
{ // body comment
// body comment return;
return;
} }

View file

@ -7,36 +7,34 @@ filename=A.h
class A { class A {
private: private:
int a; int a;
int b; int b;
public: public:
/*$*/A/*$$*/(int x, int y) /*$*/A/*$$*/(int x, int y) :
:a(x), b(y) a(x), b(y) {
{} }
~A() ~A() {
{ }
}
}; };
//= //=
#include <iostream> #include <iostream>
class A { class A {
private: private:
int a; int a;
int b; int b;
public: public:
A(int x, int y); A(int x, int y);
~A() ~A() {
{ }
}
}; };
inline A::A(int x, int y) inline A::A(int x, int y) :
:a(x), b(y) a(x), b(y) {
{
} }
//!TestConstructorToggleInHeaderToImplementation //!TestConstructorToggleInHeaderToImplementation
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config //@.config
@ -46,31 +44,30 @@ filename=A.h
class A { class A {
private: private:
int a; int a;
int b; int b;
public: public:
A(int x, int y); A(int x, int y);
~A() ~A() {
{ }
}
}; };
inline A::/*$*/A/*$$*/(int x, int y) inline A::/*$*/A/*$$*/(int x, int y) :
:a(x), b(y) a(x), b(y) {
{
} }
//= //=
#include <iostream> #include <iostream>
class A { class A {
private: private:
int a; int a;
int b; int b;
public: public:
A(int x, int y); A(int x, int y);
~A() ~A() {
{ }
}
}; };
@ -78,21 +75,19 @@ public:
#include "A.h" #include "A.h"
int main() { int main() {
return 0; return 0;
} }
//= //=
#include "A.h" #include "A.h"
int main() { int main() {
return 0; return 0;
} }
A::A(int x, int y) A::A(int x, int y) :
:a(x), b(y) a(x), b(y) {
{
} }
//!TestConstructorToggleInImplementationToClass //!TestConstructorToggleInImplementationToClass
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config //@.config
@ -100,13 +95,12 @@ filename=A.cpp
//@A.cpp //@A.cpp
#include "A.h" #include "A.h"
A::/*$*/A/*$$*/(int x, int y) A::/*$*/A/*$$*/(int x, int y) :
:a(x), b(y) a(x), b(y) {
{
} }
int main() { int main() {
return 0; return 0;
} }
//= //=
#include "A.h" #include "A.h"
@ -114,28 +108,25 @@ int main() {
int main() { int main() {
return 0; return 0;
} }
//@A.h //@A.h
#include <iostream> #include <iostream>
class A { class A {
A(int x, int y); A(int x, int y);
~A() ~A() {
{ }
}
}; };
//= //=
#include <iostream> #include <iostream>
class A { class A {
A(int x, int y) A(int x, int y) :
:a(x), b(y) a(x), b(y) {
{ }
} ~A() {
~A() }
{
}
}; };
//!TestDestructorToggleInClassToInHeader //!TestDestructorToggleInClassToInHeader
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
@ -146,28 +137,28 @@ filename=A.h
class A { class A {
private: private:
int a; int a;
int b; int b;
public: public:
/*$*/~A/*$$*/() /*$*/~A/*$$*/() {
{} }
}; };
//= //=
#include <iostream> #include <iostream>
class A { class A {
private: private:
int a; int a;
int b; int b;
public: public:
~A(); ~A();
}; };
inline A::~A() inline A::~A() {
{
} }
//!TestDestructorToggleInHeaderToImplementation //!TestDestructorToggleInHeaderToImplementation
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config //@.config
@ -177,24 +168,25 @@ filename=A.h
class A { class A {
private: private:
int a; int a;
int b; int b;
public: public:
~A(); ~A();
}; };
inline /*$*/A::~A/*$$*/() inline /*$*/A::~A/*$$*/() {
{
} }
//= //=
#include <iostream> #include <iostream>
class A { class A {
private: private:
int a; int a;
int b; int b;
public: public:
~A(); ~A();
}; };
@ -202,20 +194,18 @@ public:
#include "A.h" #include "A.h"
int main() { int main() {
return 0; return 0;
} }
//= //=
#include "A.h" #include "A.h"
int main() { int main() {
return 0; return 0;
} }
A::~A() A::~A() {
{
} }
//!TestDestructorToggleInImplementationToClass //!TestDestructorToggleInImplementationToClass
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config //@.config
@ -223,15 +213,14 @@ filename=A.cpp
//@A.cpp //@A.cpp
#include "A.h" #include "A.h"
/*$*/A::~A/*$$*/() /*$*/A::~A/*$$*/() {
{ int x;
int x; int y;
int y; return;
return;
} }
int main() { int main() {
return 0; return 0;
} }
//= //=
#include "A.h" #include "A.h"
@ -239,28 +228,27 @@ int main() {
int main() { int main() {
return 0; return 0;
} }
//@A.h //@A.h
#include <iostream> #include <iostream>
class A { class A {
A(int x, int y) A(int x, int y) :
:a(x), b(y) a(x), b(y) {
{} }
~A(); ~A();
}; };
//= //=
#include <iostream> #include <iostream>
class A { class A {
A(int x, int y) A(int x, int y) :
:a(x), b(y) a(x), b(y) {
{} }
~A() ~A() {
{ int x;
int x; int y;
int y; return;
return; }
}
}; };

View file

@ -6,24 +6,21 @@ filename=A.h
#include <iostream> #include <iostream>
class A { class A {
void /*$*/member/*$$*/(int a=0, int b=0) void /*$*/member/*$$*/(int a = 0, int b = 0) {
{ return;
return; }
}
}; };
//= //=
#include <iostream> #include <iostream>
class A { class A {
void member(int a=0, int b=0); void member(int a = 0, int b = 0);
}; };
inline void A::member(int a, int b) inline void A::member(int a, int b) {
{ return;
return;
} }
//!TestDefaultParameterInitializerInHeaderToImplementation //!TestDefaultParameterInitializerInHeaderToImplementation
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config //@.config
@ -32,18 +29,17 @@ filename=A.h
#include <iostream> #include <iostream>
class A { class A {
void member(int a=0, int b=0); void member(int a = 0, int b = 0);
}; };
inline void /*$*/A::member/*$$*/(int a, int b) inline void /*$*/A::member/*$$*/(int a, int b) {
{ return;
return;
} }
//= //=
#include <iostream> #include <iostream>
class A { class A {
void member(int a=0, int b=0); void member(int a = 0, int b = 0);
}; };
@ -51,21 +47,19 @@ class A {
#include "A.h" #include "A.h"
int main() { int main() {
return 0; return 0;
} }
//= //=
#include "A.h" #include "A.h"
int main() { int main() {
return 0; return 0;
} }
void A::member(int a, int b) void A::member(int a, int b) {
{ return;
return;
} }
//!TestDefaultParameterInitializerInImplementationToClass //!TestDefaultParameterInitializerInImplementationToClass
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config //@.config
@ -73,36 +67,32 @@ filename=A.cpp
//@A.cpp //@A.cpp
#include "A.h" #include "A.h"
void A::/*$*/member/*$$*/(int a, int b) void A::/*$*/member/*$$*/(int a, int b) {
{ return;
return;
} }
int main() int main() {
{ return 0;
return 0;
} }
//= //=
#include "A.h" #include "A.h"
int main() int main() {
{ return 0;
return 0;
} }
//@A.h //@A.h
#include <iostream> #include <iostream>
class A { class A {
void member(int a = 0, int b = 0); void member(int a = 0, int b = 0);
}; };
//= //=
#include <iostream> #include <iostream>
class A { class A {
void member(int a = 0, int b = 0) void member(int a = 0, int b = 0) {
{ return;
return; }
}
}; };

View file

@ -6,18 +6,17 @@ filename=A.cpp
#include "A.h" #include "A.h"
int main() { int main() {
return 0; return 0;
} }
void N::A::/*$*/foo/*$$*/() void N::A::/*$*/foo/*$$*/() {
{ return;
return;
} }
//= //=
#include "A.h" #include "A.h"
int main() { int main() {
return 0; return 0;
} }
@ -26,21 +25,24 @@ int main() {
#include <exception> #include <exception>
namespace N { namespace N {
class A {
void foo(); class A {
}; void foo();
};
} }
//= //=
#include <iostream> #include <iostream>
#include <exception> #include <exception>
namespace N { namespace N {
class A {
void foo() class A {
{ void foo() {
return; return;
} }
}; };
} }
//!TestImplementationToClassWithDeclarationSelected //!TestImplementationToClassWithDeclarationSelected
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
@ -51,9 +53,11 @@ filename=A.h
#include <exception> #include <exception>
namespace N { namespace N {
class A {
void /*$*/foo/*$$*/(); class A {
}; void /*$*/foo/*$$*/();
};
} }
//= //=
@ -61,28 +65,30 @@ namespace N {
#include <exception> #include <exception>
namespace N { namespace N {
class A {
void foo() class A {
{ void foo() {
return; return;
} }
}; };
} }
//@A.cpp //@A.cpp
#include "A.h" #include "A.h"
int main() { int main() {
return 0; return 0;
} }
void N::A::foo()
{ void N::A::foo() {
return; return;
} }
//= //=
#include "A.h" #include "A.h"
int main() { int main() {
return 0; return 0;
} }

View file

@ -7,11 +7,11 @@ fatalerror=true
class A { class A {
public: public:
void foo() void foo() {
{ }
}
private: private:
int /*$*/x/*$$*/; int /*$*/x/*$$*/;
}; };
//!TestNotSupportedNoDefinition //!TestNotSupportedNoDefinition
@ -23,14 +23,13 @@ fatalerror=true
class A { class A {
public: public:
void /*$*/foo/*$$*/(); void /*$*/foo/*$$*/();
}; };
//@A.cpp //@A.cpp
#include "A.h" #include "A.h"
int main() int main() {
{ return 0;
return 0;
} }
//!TestNotSupportedNoTranslationunit //!TestNotSupportedNoTranslationunit
@ -42,7 +41,7 @@ fatalerror=true
class A { class A {
public: public:
void /*$*/foo/*$$*/(); void /*$*/foo/*$$*/();
}; };
//!TestMultipleDeclarations //!TestMultipleDeclarations
@ -54,15 +53,14 @@ fatalerror=true
#include <iostream> #include <iostream>
class A { class A {
void /*$*/foo/*$$*/(); void /*$*/foo/*$$*/();
void foo(); void foo();
}; };
//@A.cpp //@A.cpp
#include "A.h" #include "A.h"
int main() int main() {
{ return 0;
return 0;
} }
//!TestMultipledefinitions //!TestMultipledefinitions
@ -73,28 +71,23 @@ fatalerror=true
#include <iostream> #include <iostream>
class A { class A {
void foo(); void foo();
void /*$*/foo/*$$*/() void /*$*/foo/*$$*/() {
{ return;
return; }
}
}; };
void blah() void blah() {
{
} }
inline void A::foo() inline void A::foo() {
{ return;
return;
} }
//@A.cpp //@A.cpp
#include "A.h" #include "A.h"
int main() int main() {
{ return 0;
return 0;
} }
//!TestNotSupportedNestedFunctions //!TestNotSupportedNestedFunctions
@ -105,9 +98,8 @@ fatalerror=true
#include <iostream> #include <iostream>
class A { class A {
void foo() void foo() {
{ void /*$*/bar/*$$*/() {
void /*$*/bar/*$$*/() { }
} }
}
}; };

View file

@ -7,57 +7,55 @@ filename=A.h
class A { class A {
private: private:
int a; int a;
int b; int b;
public: public:
A(int x, int y) A(int x, int y) :
:a(x), b(y) a(x), b(y) {
{} }
~A() ~A() {
{ }
}
}; };
int /*$*/freeFunction/*$$*/(int *a, int & b) { int /*$*/freeFunction/*$$*/(int* a, int& b) {
return 42; return 42;
} }
//= //=
#include <iostream> #include <iostream>
class A { class A {
private: private:
int a; int a;
int b; int b;
public: public:
A(int x, int y) A(int x, int y) :
:a(x), b(y) a(x), b(y) {
{} }
~A() ~A() {
{ }
}
}; };
int freeFunction(int *a, int & b); int freeFunction(int* a, int& b);
//@A.cpp //@A.cpp
#include "A.h" #include "A.h"
int main() { int main() {
return 0; return 0;
} }
//= //=
#include "A.h" #include "A.h"
int main() { int main() {
return 0; return 0;
} }
int freeFunction(int *a, int & b) int freeFunction(int* a, int& b) {
{ return 42;
return 42;
} }
//!TestFreeFunctionToggleFromImplementationToHeaderWithDeclaration //!TestFreeFunctionToggleFromImplementationToHeaderWithDeclaration
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config //@.config
@ -66,18 +64,17 @@ filename=A.cpp
#include "A.h" #include "A.h"
int main() { int main() {
return 0; return 0;
} }
int /*$*/freeFunction/*$$*/(int *a, int & b) int /*$*/freeFunction/*$$*/(int* a, int& b) {
{ return 42;
return 42;
} }
//= //=
#include "A.h" #include "A.h"
int main() { int main() {
return 0; return 0;
} }
@ -86,40 +83,38 @@ int main() {
class A { class A {
private: private:
int a; int a;
int b; int b;
public: public:
A(int x, int y) A(int x, int y) :
:a(x), b(y) a(x), b(y) {
{} }
~A() ~A() {
{ }
}
}; };
int freeFunction(int *a, int & b); int freeFunction(int* a, int& b);
//= //=
#include <iostream> #include <iostream>
class A { class A {
private: private:
int a; int a;
int b; int b;
public: public:
A(int x, int y) A(int x, int y) :
:a(x), b(y) a(x), b(y) {
{} }
~A() ~A() {
{ }
}
}; };
int freeFunction(int *a, int & b) int freeFunction(int* a, int& b) {
{ return 42;
return 42;
} }
//!TestFreeFunctionToggleFromImplementationToHeaderWithOutDeclaration //!TestFreeFunctionToggleFromImplementationToHeaderWithOutDeclaration
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config //@.config
@ -128,20 +123,20 @@ filename=A.cpp
#include "A.h" #include "A.h"
int main() { int main() {
return 0; return 0;
} }
int /*$*/freeFunction/*$$*/(int *a, int & b) int /*$*/freeFunction/*$$*/(int* a, int& b)
try { try {
return 42; return 42;
} catch (std::exception & e) }
{ catch (std::exception& e) {
} }
//= //=
#include "A.h" #include "A.h"
int main() { int main() {
return 0; return 0;
} }
@ -150,15 +145,15 @@ int main() {
class A { class A {
private: private:
int a; int a;
int b; int b;
public: public:
A(int x, int y) A(int x, int y) :
:a(x), b(y) a(x), b(y) {
{} }
~A() ~A() {
{ }
}
}; };
//= //=
@ -166,35 +161,32 @@ public:
class A { class A {
private: private:
int a; int a;
int b; int b;
public: public:
A(int x, int y) A(int x, int y) :
:a(x), b(y) a(x), b(y) {
{} }
~A() ~A() {
{ }
}
}; };
int freeFunction(int *a, int & b) int freeFunction(int* a, int& b)
try try {
{ return 42;
return 42;
} }
catch(std::exception & e){ catch (std::exception& e) {
} }
//!TestFreeFunction //!TestFreeFunction
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config //@.config
filename=A.h filename=A.h
//@A.h //@A.h
int /*$*/freeFunction/*$$*/() int /*$*/freeFunction/*$$*/() {
{ return 42;
return 42;
} }
//= //=
int freeFunction(); int freeFunction();
@ -204,12 +196,9 @@ int freeFunction();
//= //=
#include "A.h" #include "A.h"
int freeFunction() {
int freeFunction() return 42;
{
return 42;
} }
//!TestQualifiedNameToggle //!TestQualifiedNameToggle
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config //@.config
@ -218,18 +207,15 @@ fatalerror=true
//@A.cpp //@A.cpp
#include "A.h" #include "A.h"
int /*$*/A::freefunction/*$$*/() int /*$*/A::freefunction/*$$*/() {
{ return 42;
return 42;
} }
//= //=
#include "A.h" #include "A.h"
int A::freefunction() int A::freefunction() {
{ return 42;
return 42;
} }
//!TestNamespacedFreeFunction //!TestNamespacedFreeFunction
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config //@.config
@ -241,10 +227,11 @@ filename=A.h
#include <iostream> #include <iostream>
namespace N { namespace N {
void /*$*/freefunction/*$$*/()
{ void /*$*/freefunction/*$$*/() {
return; return;
} }
} }
#endif /* A_H_ */ #endif /* A_H_ */
@ -255,7 +242,9 @@ namespace N {
#include <iostream> #include <iostream>
namespace N { namespace N {
void freefunction();
void freefunction();
} }
#endif /* A_H_ */ #endif /* A_H_ */
@ -263,21 +252,20 @@ namespace N {
#include "A.h" #include "A.h"
int main() { int main() {
return 0; return 0;
} }
//= //=
#include "A.h" #include "A.h"
int main() { int main() {
return 0; return 0;
} }
namespace N namespace N {
{
void freefunction() void freefunction() {
{ return;
return; }
}
} }

View file

@ -7,24 +7,28 @@ filename=A.h
#include <exception> #include <exception>
namespace N { namespace N {
class A {
void /*$*/foo/*$$*/() { class A {
return; void /*$*/foo/*$$*/() {
} return;
}; }
};
} }
//= //=
#include <iostream> #include <iostream>
#include <exception> #include <exception>
namespace N { namespace N {
class A {
void foo(); class A {
}; void foo();
inline void A::foo() };
{
return; inline void A::foo() {
} return;
}
} }
//!TestSimpleNamespaceInHeaderToImplementationWithinNSDefinition //!TestSimpleNamespaceInHeaderToImplementationWithinNSDefinition
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
@ -35,42 +39,45 @@ filename=A.h
#include <exception> #include <exception>
namespace N { namespace N {
class A {
void foo(); class A {
}; void foo();
inline void A::/*$*/foo/*$$*/() };
{
return; inline void A::/*$*/foo/*$$*/() {
} return;
}
} }
//= //=
#include <iostream> #include <iostream>
#include <exception> #include <exception>
namespace N { namespace N {
class A {
void foo(); class A {
}; void foo();
};
} }
//@A.cpp //@A.cpp
#include "A.h" #include "A.h"
int main() { int main() {
return 0; return 0;
} }
//= //=
#include "A.h" #include "A.h"
int main() { int main() {
return 0; return 0;
} }
namespace N namespace N {
{
void A::foo() void A::foo() {
{ return;
return; }
}
} }
@ -83,13 +90,14 @@ filename=A.h
#include <exception> #include <exception>
namespace N { namespace N {
class A {
void foo(); class A {
}; void foo();
inline void A::/*$*/foo/*$$*/() };
{
return; inline void A::/*$*/foo/*$$*/() {
} return;
}
} }
//= //=
@ -97,34 +105,33 @@ namespace N {
#include <exception> #include <exception>
namespace N { namespace N {
class A {
void foo(); class A {
}; void foo();
};
} }
//@A.cpp //@A.cpp
#include "A.h" #include "A.h"
int main() { int main() {
return 0; return 0;
} }
namespace N namespace N {
{
} }
//= //=
#include "A.h" #include "A.h"
int main() { int main() {
return 0; return 0;
} }
namespace N namespace N {
{
void A::foo() void A::foo() {
{ return;
return; }
}
} }
//!TestSimpleNamespaceInHeaderToImplementationWithNamespaceQualifiedName //!TestSimpleNamespaceInHeaderToImplementationWithNamespaceQualifiedName
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
@ -135,23 +142,26 @@ filename=A.h
#include <exception> #include <exception>
namespace N { namespace N {
class A {
void foo(); class A {
}; void foo();
};
} }
inline void /*$*/N::A::foo/*$$*/() inline void /*$*/N::A::foo/*$$*/() {
{ return;
return;
} }
//= //=
#include <iostream> #include <iostream>
#include <exception> #include <exception>
namespace N { namespace N {
class A {
void foo(); class A {
}; void foo();
};
} }
@ -159,21 +169,20 @@ namespace N {
#include "A.h" #include "A.h"
int main() { int main() {
return 0; return 0;
} }
//= //=
#include "A.h" #include "A.h"
int main() { int main() {
return 0; return 0;
} }
namespace N namespace N {
{
void A::foo() void A::foo() {
{ return;
return; }
}
} }
@ -184,42 +193,42 @@ filename=A.cpp
//@A.cpp //@A.cpp
#include "A.h" #include "A.h"
void /*$*/N::A::foo/*$$*/() void /*$*/N::A::foo/*$$*/() {
{ return;
return;
} }
int main() int main() {
{ return 0;
return 0;
} }
//= //=
#include "A.h" #include "A.h"
int main() int main() {
{ return 0;
return 0;
} }
//@A.h //@A.h
#include <iostream> #include <iostream>
namespace N { namespace N {
class A {
void foo(); class A {
}; void foo();
};
} }
//= //=
#include <iostream> #include <iostream>
namespace N { namespace N {
class A {
void foo() class A {
{ void foo() {
return; return;
} }
}; };
} }
//!TestRemoveEmptyNamespaceFromImplentation //!TestRemoveEmptyNamespaceFromImplentation
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
@ -229,10 +238,11 @@ filename=A.cpp
#include "A.h" #include "A.h"
namespace N { namespace N {
void /*$*/A::foo/*$$*/()
{ void /*$*/A::foo/*$$*/() {
return; return;
} }
} }
//= //=
#include "A.h" #include "A.h"
@ -242,18 +252,21 @@ namespace N {
#include <iostream> #include <iostream>
namespace N { namespace N {
class A {
void foo(); class A {
}; void foo();
};
} }
//= //=
#include <iostream> #include <iostream>
namespace N { namespace N {
class A {
void foo() class A {
{ void foo() {
return; return;
} }
}; };
} }

View file

@ -6,27 +6,25 @@ filename=A.h
#include <iostream> #include <iostream>
class A { class A {
class B { class B {
void /*$*/member/*$$*/(int a, int b) { void /*$*/member/*$$*/(int a, int b) {
return; return;
} }
}; };
}; };
//= //=
#include <iostream> #include <iostream>
class A { class A {
class B { class B {
void member(int a, int b); void member(int a, int b);
}; };
}; };
inline void A::B::member(int a, int b) inline void A::B::member(int a, int b) {
{ return;
return;
} }
//!TestNestedClassInHeaderToImplementation //!TestNestedClassInHeaderToImplementation
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config //@.config
@ -35,46 +33,41 @@ filename=A.h
#include <iostream> #include <iostream>
class A { class A {
class B { class B {
void member(int a, int b); void member(int a, int b);
}; };
}; };
inline void A::B::/*$*/member/*$$*/(int a, int b) inline void A::B::/*$*/member/*$$*/(int a, int b) {
{ return;
return;
} }
//= //=
#include <iostream> #include <iostream>
class A { class A {
class B { class B {
void member(int a, int b); void member(int a, int b);
}; };
}; };
//@A.cpp //@A.cpp
#include "A.h" #include "A.h"
int main() int main() {
{ return 0;
return 0;
} }
//= //=
#include "A.h" #include "A.h"
int main() int main() {
{ return 0;
return 0;
} }
void A::B::member(int a, int b) void A::B::member(int a, int b) {
{ return;
return;
} }
//!TestNestedClassInImplementationToClass //!TestNestedClassInImplementationToClass
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config //@.config
@ -82,21 +75,18 @@ filename=A.cpp
//@A.cpp //@A.cpp
#include "A.h" #include "A.h"
int main() int main() {
{ return 0;
return 0;
} }
void A::B::/*$*/member/*$$*/(int a, int b) void A::B::/*$*/member/*$$*/(int a, int b) {
{ return;
return;
} }
//= //=
#include "A.h" #include "A.h"
int main() int main() {
{ return 0;
return 0;
} }
@ -104,18 +94,17 @@ int main()
#include <iostream> #include <iostream>
class A { class A {
class B { class B {
void member(int a, int b); void member(int a, int b);
}; };
}; };
//= //=
#include <iostream> #include <iostream>
class A { class A {
class B { class B {
void member(int a, int b) void member(int a, int b) {
{ return;
return; }
} };
};
}; };

View file

@ -7,46 +7,38 @@ filename=A.h
class A { class A {
public: public:
void func1(); void func1();
void /*$*/func2/*$$*/() void /*$*/func2/*$$*/() {
{ }
} void func3();
void func3(); void func4() {
void func4() }
{
}
}; };
inline void A::func1() inline void A::func1() {
{
} }
inline void A::func3() inline void A::func3() {
{
} }
//= //=
#include <iostream> #include <iostream>
class A { class A {
public: public:
void func1(); void func1();
void func2(); void func2();
void func3(); void func3();
void func4() void func4() {
{ }
}
}; };
inline void A::func1() inline void A::func1() {
{
} }
inline void A::func2() inline void A::func2() {
{
} }
inline void A::func3() inline void A::func3() {
{
} }
//!TestCorrectOrderingInHeaderToImplementation //!TestCorrectOrderingInHeaderToImplementation
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
@ -57,17 +49,15 @@ filename=A.h
class A { class A {
public: public:
void func1(); void func1();
void func2(); void func2();
void func3(); void func3();
void func4() void func4() {
{ }
}
}; };
inline void A::/*$*/func2/*$$*/() inline void A::/*$*/func2/*$$*/() {
{ return;
return;
} }
//= //=
@ -75,12 +65,11 @@ inline void A::/*$*/func2/*$$*/()
class A { class A {
public: public:
void func1(); void func1();
void func2(); void func2();
void func3(); void func3();
void func4() void func4() {
{ }
}
}; };
@ -88,41 +77,34 @@ public:
//@A.cpp //@A.cpp
#include "A.h" #include "A.h"
int main() int main() {
{ return 0;
return 0;
} }
void A::func1() void A::func1() {
{ return;
return;
} }
void A::func3() void A::func3() {
{ return;
return;
} }
//= //=
#include "A.h" #include "A.h"
int main() int main() {
{ return 0;
return 0;
} }
void A::func1() void A::func1() {
{ return;
return;
} }
void A::func2() void A::func2() {
{ return;
return;
} }
void A::func3() void A::func3() {
{ return;
return;
} }
//!TestCorrectTemplateOrderingInClassToInHeader //!TestCorrectTemplateOrderingInClassToInHeader
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
@ -134,21 +116,20 @@ filename=A.h
template <typename T> template <typename T>
class A { class A {
public: public:
void func1(); void func1();
void /*$*/func2/*$$*/() void /*$*/func2/*$$*/() {
{ }
} void func3();
void func3(); void func4() {
void func4() }
{
}
}; };
template<typename T> inline void A<T>::func1() template<typename T>
{ inline void A<T>::func1() {
} }
template<typename T> inline void A<T>::func3()
{ template<typename T>
inline void A<T>::func3() {
} }
//= //=
#include <iostream> #include <iostream>
@ -156,23 +137,23 @@ template<typename T> inline void A<T>::func3()
template <typename T> template <typename T>
class A { class A {
public: public:
void func1(); void func1();
void func2(); void func2();
void func3(); void func3();
void func4() void func4() {
{ }
}
}; };
template<typename T> inline void A<T>::func1() template<typename T>
{ inline void A<T>::func1() {
}
template<typename T> inline void A<T>::func2()
{
} }
template<typename T> inline void A<T>::func3() template<typename T>
{ inline void A<T>::func2() {
}
template<typename T>
inline void A<T>::func3() {
} }
//!TestCorrectTemplateOrderingInHeaderToInClass //!TestCorrectTemplateOrderingInHeaderToInClass
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
@ -184,22 +165,23 @@ filename=A.h
template <typename T> template <typename T>
class A { class A {
public: public:
void func1(); void func1();
void func2(); void func2();
void func3(); void func3();
void func4() void func4() {
{ }
}
}; };
template<typename T> inline void A<T>::func1() template<typename T>
{ inline void A<T>::func1() {
} }
template<typename T> inline void A<T>::/*$*/func2/*$$*/()
{ template<typename T>
inline void A<T>::/*$*/func2/*$$*/() {
} }
template<typename T> inline void A<T>::func3()
{ template<typename T>
inline void A<T>::func3() {
} }
//= //=
#include <iostream> #include <iostream>
@ -207,20 +189,20 @@ template<typename T> inline void A<T>::func3()
template <typename T> template <typename T>
class A { class A {
public: public:
void func1(); void func1();
void func2() void func2() {
{ }
} void func3();
void func3(); void func4() {
void func4() }
{
}
}; };
template<typename T> inline void A<T>::func1() template<typename T>
{ inline void A<T>::func1() {
} }
template<typename T> inline void A<T>::func3()
{
template<typename T>
inline void A<T>::func3() {
} }

View file

@ -4,153 +4,132 @@
filename=A.h filename=A.h
//@A.h //@A.h
class A { class A {
void me/*$*//*$$*/mber() void me/*$*//*$$*/mber() {
{ return;
return; }
}
}; };
//= //=
class A { class A {
void member(); void member();
}; };
inline void A::member() inline void A::member() {
{ return;
return;
} }
//!TestSubstringSelection //!TestSubstringSelection
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config //@.config
filename=A.h filename=A.h
//@A.h //@A.h
class A { class A {
void m/*$*/e/*$$*/mber() void m/*$*/e/*$$*/mber() {
{ return;
return; }
}
}; };
//= //=
class A { class A {
void member(); void member();
}; };
inline void A::member() inline void A::member() {
{ return;
return;
} }
//!TestBodySelection //!TestBodySelection
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config //@.config
filename=A.h filename=A.h
//@A.h //@A.h
class A { class A {
void member() void member() {
{ r/*$*//*$$*/eturn;
r/*$*//*$$*/eturn; }
}
}; };
//= //=
class A { class A {
void member(); void member();
}; };
inline void A::member() inline void A::member() {
{ return;
return;
} }
//!TestBodySelectionWithConfusingName //!TestBodySelectionWithConfusingName
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config //@.config
filename=A.h filename=A.h
//@A.h //@A.h
class A { class A {
void member() void member() {
{ int /*$*/abcd/*$$*/ = 42;
int /*$*/abcd/*$$*/ = 42; return;
return; }
}
}; };
//= //=
class A { class A {
void member(); void member();
}; };
inline void A::member() inline void A::member() {
{ int abcd = 42;
int abcd = 42; return;
return;
} }
//!TestLeftBorderSelection //!TestLeftBorderSelection
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config //@.config
filename=A.h filename=A.h
//@A.h //@A.h
class A { class A {
/*$*//*$$*/void member() /*$*//*$$*/void member() {
{ return;
return; }
}
}; };
//= //=
class A { class A {
void member(); void member();
}; };
inline void A::member() inline void A::member() {
{ return;
return;
} }
//!TestRightBorderSelection //!TestRightBorderSelection
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config //@.config
filename=A.h filename=A.h
//@A.h //@A.h
class A { class A {
void member() void member() {
{ return;
return; }/*$*//*$$*/
}/*$*//*$$*/
}; };
//= //=
class A { class A {
void member(); void member();
}; };
inline void A::member() inline void A::member() {
{ return;
return;
} }
//!TestOverlappingSelection //!TestOverlappingSelection
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config //@.config
filename=A.h filename=A.h
//@A.h //@A.h
class A { class A {
vo/*$*/id member() vo/*$*/id member() {
{ ret/*$$*/urn;
ret/*$$*/urn; }
}
}; };
//= //=
class A { class A {
void member(); void member();
}; };
inline void A::member() inline void A::member() {
{ return;
return;
} }

View file

@ -7,29 +7,28 @@ filename=A.h
class A { class A {
public: public:
int /*$*/function/*$$*/() int /*$*/function/*$$*/() {
{ return 0;
return 0; }
}
private: private:
int a; int a;
}; };
//= //=
#include <iostream> #include <iostream>
class A { class A {
public: public:
int function(); int function();
private: private:
int a; int a;
}; };
inline int A::function() inline int A::function() {
{ return 0;
return 0;
} }
//!TestSimpleFunctionInHeaderToImplementation //!TestSimpleFunctionInHeaderToImplementation
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config //@.config
@ -39,23 +38,24 @@ filename=A.h
class A { class A {
public: public:
int function(); int function();
private: private:
int a; int a;
}; };
inline int A::/*$*/function/*$$*/() inline int A::/*$*/function/*$$*/() {
{ return 0;
return 0;
} }
//= //=
#include <iostream> #include <iostream>
class A { class A {
public: public:
int function(); int function();
private: private:
int a; int a;
}; };
@ -63,21 +63,19 @@ private:
#include "A.h" #include "A.h"
int main() { int main() {
return 0; return 0;
} }
//= //=
#include "A.h" #include "A.h"
int main() { int main() {
return 0; return 0;
} }
int A::function() int A::function() {
{ return 0;
return 0;
} }
//!TestSimpleFunctionInImplementationToInClass //!TestSimpleFunctionInImplementationToInClass
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config //@.config
@ -85,44 +83,42 @@ filename=A.cpp
//@A.cpp //@A.cpp
#include "A.h" #include "A.h"
int A::/*$*/function/*$$*/() int A::/*$*/function/*$$*/() {
{ return 0;
return 0;
} }
int main() int main() {
{ return 0;
return 0;
} }
//= //=
#include "A.h" #include "A.h"
int main() int main() {
{ return 0;
return 0;
} }
//@A.h //@A.h
#include <iostream> #include <iostream>
class A { class A {
public: public:
int function(); int function();
private: private:
int a; int a;
}; };
//= //=
#include <iostream> #include <iostream>
class A { class A {
public: public:
int function() int function() {
{ return 0;
return 0; }
}
private: private:
int a; int a;
}; };
//!TestDifferentParameterNames //!TestDifferentParameterNames
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
@ -131,36 +127,35 @@ filename=MyClass.cpp
//@MyClass.cpp //@MyClass.cpp
#include "MyClass.h" #include "MyClass.h"
myClass::/*$*/myClass/*$$*/(int implname) : fVal(implname) {} myClass::/*$*/myClass/*$$*/(int implname) :
fVal(implname) {
}
int main() int main() {
{ return 0;
return 0;
} }
//= //=
#include "MyClass.h" #include "MyClass.h"
int main() int main() {
{ return 0;
return 0;
} }
//@MyClass.h //@MyClass.h
struct myClass { struct myClass {
int fVal; int fVal;
myClass(int headername); myClass(int headername);
}; };
//= //=
struct myClass { struct myClass {
int fVal; int fVal;
myClass(int implname) myClass(int implname) :
:fVal(implname) fVal(implname) {
{ }
}
}; };
//!TestMissingParameterNames //!TestMissingParameterNames
@ -170,35 +165,34 @@ filename=MyClass.cpp
//@MyClass.cpp //@MyClass.cpp
#include "MyClass.h" #include "MyClass.h"
myClass::/*$*/myClass/*$$*/(int implname) : fVal(implname) {} myClass::/*$*/myClass/*$$*/(int implname) :
fVal(implname) {
}
int main() int main() {
{ return 0;
return 0;
} }
//= //=
#include "MyClass.h" #include "MyClass.h"
int main() int main() {
{ return 0;
return 0;
} }
//@MyClass.h //@MyClass.h
struct myClass { struct myClass {
int fVal; int fVal;
myClass(int); myClass(int);
}; };
//= //=
struct myClass { struct myClass {
int fVal; int fVal;
myClass(int implname) myClass(int implname) :
:fVal(implname) fVal(implname) {
{ }
}
}; };

View file

@ -7,29 +7,27 @@ filename=A.h
template <typename T, typename U> template <typename T, typename U>
class A { class A {
class B { class B {
T /*$*/member/*$$*/() T /*$*/member/*$$*/() {
{ return T();
return T(); }
} };
};
}; };
//= //=
#include <iostream> #include <iostream>
template <typename T, typename U> template <typename T, typename U>
class A { class A {
class B { class B {
T member(); T member();
}; };
}; };
template<typename T, typename U> inline T A<T,U>::B::member() template<typename T, typename U>
{ inline T A<T, U>::B::member() {
return T(); return T();
} }
//!TestTemplateFunctionInHeaderToInClass //!TestTemplateFunctionInHeaderToInClass
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config //@.config
@ -39,28 +37,25 @@ filename=A.h
template <typename T> template <typename T>
class A { class A {
class B { class B {
T member(); T member();
}; };
}; };
template<typename T> inline T A<T>::B::/*$*/member/*$$*/() template<typename T>
{ inline T A<T>::B::/*$*/member/*$$*/() {
return T(); return T();
} }
//= //=
#include <iostream> #include <iostream>
template <typename T> template <typename T>
class A { class A {
class B { class B {
T member() T member() {
{ return T();
return T(); }
} };
};
}; };
@ -70,85 +65,76 @@ class A {
filename=A.h filename=A.h
//@A.h //@A.h
class A { class A {
tem/*$*/plate/*$$*/<typename T> tem/*$*/plate/*$$*/<typename T>
T foo() { T foo() {
return T(); return T();
} }
}; };
//= //=
class A { class A {
template<typename T> template<typename T>
T foo(); T foo();
}; };
template<typename T> inline T A::foo() template<typename T>
{ inline T A::foo() {
return T(); return T();
} }
//!TestComplexTemplateFunctionFromInClassToInheader //!TestComplexTemplateFunctionFromInClassToInheader
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config //@.config
filename=A.h filename=A.h
//@A.h //@A.h
template<typename T, typename S> template<typename T, typename S>
class A class A {
{
public: public:
template<typename U, typename V> template<typename U, typename V>
void /*$*/foo/*$$*/(const U & u, const V &v) void /*$*/foo/*$$*/(const U& u, const V& v) {
{ return;
return; }
}
}; };
//= //=
template<typename T, typename S> template<typename T, typename S>
class A class A {
{
public: public:
template<typename U, typename V> template<typename U, typename V>
void foo(const U & u, const V &v); void foo(const U& u, const V& v);
}; };
template<typename T, typename S> template<typename U, typename V> inline void A<T,S>::foo(const U & u, const V & v) template<typename T, typename S>
{ template<typename U, typename V>
return; inline void A<T, S>::foo(const U& u, const V& v) {
return;
} }
//!TestComplexTemplateFunctionFromInHeaderToInClass //!TestComplexTemplateFunctionFromInHeaderToInClass
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config //@.config
filename=A.h filename=A.h
//@A.h //@A.h
template<typename T, typename S> template<typename T, typename S>
class A class A {
{
public: public:
template<typename U, typename V> template<typename U, typename V>
void /*$*/foo/*$$*/(const U & u, const V &v); void /*$*/foo/*$$*/(const U& u, const V& v);
}; };
template<typename T, typename S> template<typename U, typename V> inline void A<T,S>::foo(const U & u, const V & v) template<typename T, typename S>
{ template<typename U, typename V>
return; inline void A<T,S>::foo(const U& u, const V& v) {
return;
} }
//= //=
template<typename T, typename S> template<typename T, typename S>
class A class A {
{
public: public:
template<typename U, typename V> template<typename U, typename V>
void foo(const U & u, const V &v) void foo(const U& u, const V& v) {
{ return;
return; }
}
}; };

View file

@ -7,33 +7,30 @@ filename=A.h
#include <exception> #include <exception>
class A { class A {
void /*$*/member/*$$*/(int a, int b) void /*$*/member/*$$*/(int a, int b)
try try {
{ return;
return; }
} catch (std::exception & e1) catch (std::exception& e1){
{ return;
return; }
}
}; };
//= //=
#include <iostream> #include <iostream>
#include <exception> #include <exception>
class A { class A {
void member(int a, int b); void member(int a, int b);
}; };
inline void A::member(int a, int b) inline void A::member(int a, int b)
try try {
{ return;
return;
} }
catch(std::exception & e1){ catch (std::exception& e1) {
return; return;
} }
//!TestTryCatchFromInHeaderToImplementation //!TestTryCatchFromInHeaderToImplementation
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config //@.config
@ -43,23 +40,22 @@ filename=A.h
#include <exception> #include <exception>
class A { class A {
void member(int a, int b); void member(int a, int b);
}; };
inline void /*$*/A::member/*$$*/(int a, int b) inline void /*$*/A::member/*$$*/(int a, int b)
try try {
{ return;
return;
} }
catch(std::exception & e1){ catch (std::exception& e1) {
return; return;
} }
//= //=
#include <iostream> #include <iostream>
#include <exception> #include <exception>
class A { class A {
void member(int a, int b); void member(int a, int b);
}; };
@ -67,25 +63,23 @@ class A {
#include "A.h" #include "A.h"
int main() { int main() {
return 0; return 0;
} }
//= //=
#include "A.h" #include "A.h"
int main() { int main() {
return 0; return 0;
} }
void A::member(int a, int b) void A::member(int a, int b)
try try {
{ return;
return;
} }
catch(std::exception & e1){ catch (std::exception& e1) {
return; return;
} }
//!TestTryCatchFromInImplementationToClass //!TestTryCatchFromInImplementationToClass
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config //@.config
@ -95,18 +89,15 @@ filename=A.cpp
#include "A.h" #include "A.h"
void A::/*$*/member/*$$*/() void A::/*$*/member/*$$*/()
try try {
{ return;
return;
} }
catch(std::exception & e1) catch (std::exception& e1) {
{ return;
return;
} }
int main() int main() {
{ return 0;
return 0;
} }
//= //=
#include <exception> #include <exception>
@ -114,28 +105,26 @@ int main()
int main() int main() {
{ return 0;
return 0;
} }
//@A.h //@A.h
#include <iostream> #include <iostream>
class A { class A {
void member(); void member();
}; };
//= //=
#include <iostream> #include <iostream>
class A { class A {
void member() void member()
try try {
{ return;
return; }
} catch (std::exception& e1) {
catch(std::exception & e1){ return;
return; }
}
}; };
//!TestMultipleTryCatchFromInClassToInHeader //!TestMultipleTryCatchFromInClassToInHeader
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
@ -146,39 +135,36 @@ filename=A.h
#include <exception> #include <exception>
class A { class A {
void /*$*/member/*$$*/(int a, int b) void /*$*/member/*$$*/(int a, int b)
try try {
{ return;
return; }
} catch (std::exception & e1) catch (std::exception& e1) {
{ return;
return; }
} catch (std::exception & e2) catch (std::exception& e2) {
{ return;
return; }
}
}; };
//= //=
#include <iostream> #include <iostream>
#include <exception> #include <exception>
class A { class A {
void member(int a, int b); void member(int a, int b);
}; };
inline void A::member(int a, int b) inline void A::member(int a, int b)
try try {
{ return;
return;
} }
catch(std::exception & e1){ catch (std::exception& e1) {
return; return;
} }
catch(std::exception & e2){ catch (std::exception& e2) {
return; return;
} }
//!TestMultipleTryCatchFromInHeaderToImplementation //!TestMultipleTryCatchFromInHeaderToImplementation
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config //@.config
@ -188,26 +174,25 @@ filename=A.h
#include <exception> #include <exception>
class A { class A {
void member(int a, int b); void member(int a, int b);
}; };
inline void /*$*/A::member/*$$*/(int a, int b) inline void /*$*/A::member/*$$*/(int a, int b)
try try {
{ return;
return;
} }
catch(std::exception & e1){ catch (std::exception& e1) {
return; return;
} }
catch(std::exception & e2){ catch (std::exception& e2) {
return; return;
} }
//= //=
#include <iostream> #include <iostream>
#include <exception> #include <exception>
class A { class A {
void member(int a, int b); void member(int a, int b);
}; };
@ -215,28 +200,26 @@ class A {
#include "A.h" #include "A.h"
int main() { int main() {
return 0; return 0;
} }
//= //=
#include "A.h" #include "A.h"
int main() { int main() {
return 0; return 0;
} }
void A::member(int a, int b) void A::member(int a, int b)
try try {
{ return;
return;
} }
catch(std::exception & e1){ catch (std::exception& e1) {
return; return;
} }
catch(std::exception & e2){ catch (std::exception& e2) {
return; return;
} }
//!TestMultipleTryCatchFromInImplementationToClass //!TestMultipleTryCatchFromInImplementationToClass
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config //@.config
@ -246,22 +229,18 @@ filename=A.cpp
#include "A.h" #include "A.h"
void A::/*$*/member/*$$*/() void A::/*$*/member/*$$*/()
try try {
{ return;
return;
} }
catch(std::exception & e1) catch (std::exception& e1) {
{ return;
return;
} }
catch(std::exception & e2) catch (std::exception& e2) {
{ return;
return;
} }
int main() int main() {
{ return 0;
return 0;
} }
//= //=
#include <exception> #include <exception>
@ -269,29 +248,27 @@ int main()
int main() int main() {
{ return 0;
return 0;
} }
//@A.h //@A.h
#include <iostream> #include <iostream>
class A { class A {
void member(); void member();
}; };
//= //=
#include <iostream> #include <iostream>
class A { class A {
void member() void member()
try try {
{ return;
return; }
} catch (std::exception& e1) {
catch(std::exception & e1){ return;
return; }
} catch (std::exception& e2) {
catch(std::exception & e2){ return;
return; }
}
}; };

View file

@ -5,23 +5,20 @@ filename=A.h
//@A.h //@A.h
class A { class A {
virtual int /*$*/foo/*$$*/() virtual int /*$*/foo/*$$*/() {
{ return 0;
return 0; }
}
}; };
//= //=
class A { class A {
virtual int foo(); virtual int foo();
}; };
inline int A::foo() inline int A::foo() {
{ return 0;
return 0;
} }
//!TestVirtualSpecifierFromInHeaderToImplementation //!TestVirtualSpecifierFromInHeaderToImplementation
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//%CPP //%CPP
@ -30,41 +27,36 @@ filename=A.h
//@A.h //@A.h
class A { class A {
virtual int /*$*/foo/*$$*/(); virtual int /*$*/foo/*$$*/();
}; };
inline int A::foo() inline int A::foo() {
{ return 0;
return 0;
} }
//= //=
class A { class A {
virtual int foo(); virtual int foo();
}; };
//@A.cpp //@A.cpp
#include "A.h" #include "A.h"
int main() int main() {
{ return 0;
return 0;
} }
//= //=
#include "A.h" #include "A.h"
int main() int main() {
{ return 0;
return 0;
} }
int A::foo() int A::foo() {
{ return 0;
return 0;
} }
//!TestVirtualSpecifierFromImplementationToHeader //!TestVirtualSpecifierFromImplementationToHeader
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config //@.config
@ -72,34 +64,30 @@ filename=A.h
//@A.h //@A.h
class A { class A {
virtual int /*$*/foo/*$$*/(); virtual int /*$*/foo/*$$*/();
}; };
//= //=
class A { class A {
virtual int foo() virtual int foo() {
{ return 0;
return 0; }
}
}; };
//@A.cpp //@A.cpp
#include "A.h" #include "A.h"
int main() int main() {
{ return 0;
return 0;
} }
int A::foo() int A::foo() {
{ return 0;
return 0;
} }
//= //=
#include "A.h" #include "A.h"
int main() int main() {
{ return 0;
return 0;
} }

View file

@ -7,8 +7,7 @@ offset=27
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
class A class A {
{
public: public:
A(); A();
void foo(); void foo();
@ -25,8 +24,7 @@ offset=0
//@A.h //@A.h
typedef int nummere; typedef int nummere;
class A class A {
{
public: public:
A(); A();
}; };

View file

@ -29,7 +29,7 @@ public class ExtractFunctionTestSuite extends TestSuite {
suite.addTest(RefactoringTester.suite("ExtractMethodPreprocessorRefactoringTests", "resources/refactoring/ExtractMethodPreprocessor.rts")); suite.addTest(RefactoringTester.suite("ExtractMethodPreprocessorRefactoringTests", "resources/refactoring/ExtractMethodPreprocessor.rts"));
suite.addTest(RefactoringTester.suite("Extract Function Templates Tests", "resources/refactoring/ExtractFunctionTemplates.rts")); suite.addTest(RefactoringTester.suite("Extract Function Templates Tests", "resources/refactoring/ExtractFunctionTemplates.rts"));
suite.addTest(RefactoringTester.suite("Extract Method History Test", "resources/refactoring/ExtractMethodHistory.rts")); suite.addTest(RefactoringTester.suite("Extract Method History Test", "resources/refactoring/ExtractMethodHistory.rts"));
suite.addTest(RefactoringTester.suite("Extract Function Dublicates Test", "resources/refactoring/ExtractMethodDuplicates.rts")); suite.addTest(RefactoringTester.suite("Extract Function Duplicates Test", "resources/refactoring/ExtractMethodDuplicates.rts"));
return suite; return suite;
} }
} }

View file

@ -885,7 +885,7 @@ public class ExtractFunctionRefactoring extends CRefactoring {
arguments.put(CRefactoringDescription.SELECTION, region.getOffset() + "," + region.getLength()); //$NON-NLS-1$ arguments.put(CRefactoringDescription.SELECTION, region.getOffset() + "," + region.getLength()); //$NON-NLS-1$
arguments.put(ExtractFunctionRefactoringDescription.NAME, info.getMethodName()); arguments.put(ExtractFunctionRefactoringDescription.NAME, info.getMethodName());
arguments.put(ExtractFunctionRefactoringDescription.VISIBILITY, info.getVisibility().toString()); arguments.put(ExtractFunctionRefactoringDescription.VISIBILITY, info.getVisibility().toString());
arguments.put(ExtractFunctionRefactoringDescription.REPLACE_DUBLICATES, Boolean.toString(info.isReplaceDuplicates())); arguments.put(ExtractFunctionRefactoringDescription.REPLACE_DUPLICATES, Boolean.toString(info.isReplaceDuplicates()));
return arguments; return arguments;
} }
} }

View file

@ -32,7 +32,7 @@ import org.eclipse.cdt.internal.ui.refactoring.utils.VisibilityEnum;
public class ExtractFunctionRefactoringDescription extends CRefactoringDescription { public class ExtractFunctionRefactoringDescription extends CRefactoringDescription {
protected static final String NAME = "name"; //$NON-NLS-1$ protected static final String NAME = "name"; //$NON-NLS-1$
protected static final String VISIBILITY = "visibility"; //$NON-NLS-1$ protected static final String VISIBILITY = "visibility"; //$NON-NLS-1$
protected static final String REPLACE_DUBLICATES = "replaceDuplicates"; //$NON-NLS-1$ protected static final String REPLACE_DUPLICATES = "replaceDuplicates"; //$NON-NLS-1$
public ExtractFunctionRefactoringDescription(String project, String description, public ExtractFunctionRefactoringDescription(String project, String description,
String comment, Map<String, String> arguments) { String comment, Map<String, String> arguments) {
@ -47,7 +47,7 @@ public class ExtractFunctionRefactoringDescription extends CRefactoringDescripti
info.setMethodName(arguments.get(NAME)); info.setMethodName(arguments.get(NAME));
info.setVisibility(VisibilityEnum.getEnumForStringRepresentation(arguments.get(VISIBILITY))); info.setVisibility(VisibilityEnum.getEnumForStringRepresentation(arguments.get(VISIBILITY)));
info.setReplaceDuplicates(Boolean.parseBoolean(arguments.get(REPLACE_DUBLICATES))); info.setReplaceDuplicates(Boolean.parseBoolean(arguments.get(REPLACE_DUPLICATES)));
proj = getCProject(); proj = getCProject();
file = getFile(); file = getFile();