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

Bug 363244 - Generate Getters and Setters expands macro with typedef and

breaks formatting. The bug was fixed by minimizing areas of code
affected by the refactoring changes. This minimization had a huge ripple
effect.
This commit is contained in:
Sergey Prigogin 2011-12-13 19:44:22 -08:00
parent 18ec28be0f
commit c521604dd1
91 changed files with 1753 additions and 1687 deletions

View file

@ -97,7 +97,7 @@ public class ASTWriterTest extends RewriteBaseTest {
IScanner scanner = AST2BaseTest.createScanner(codeReader, language, ParserMode.COMPLETE_PARSE, scannerInfo); IScanner scanner = AST2BaseTest.createScanner(codeReader, language, ParserMode.COMPLETE_PARSE, scannerInfo);
ISourceCodeParser parser2 = null; ISourceCodeParser parser = null;
if (language == ParserLanguage.CPP) { if (language == ParserLanguage.CPP) {
ICPPParserExtensionConfiguration config = null; ICPPParserExtensionConfiguration config = null;
if (useGNUExtensions) { if (useGNUExtensions) {
@ -105,7 +105,7 @@ public class ASTWriterTest extends RewriteBaseTest {
} else { } else {
config = new ANSICPPParserExtensionConfiguration(); config = new ANSICPPParserExtensionConfiguration();
} }
parser2 = new GNUCPPSourceParser(scanner, ParserMode.COMPLETE_PARSE, NULL_LOG, config); parser = new GNUCPPSourceParser(scanner, ParserMode.COMPLETE_PARSE, NULL_LOG, config);
} else { } else {
ICParserExtensionConfiguration config = null; ICParserExtensionConfiguration config = null;
@ -115,9 +115,9 @@ public class ASTWriterTest extends RewriteBaseTest {
config = new ANSICParserExtensionConfiguration(); config = new ANSICParserExtensionConfiguration();
} }
parser2 = new GNUCSourceParser(scanner, ParserMode.COMPLETE_PARSE, NULL_LOG, config); parser = new GNUCSourceParser(scanner, ParserMode.COMPLETE_PARSE, NULL_LOG, config);
} }
return parser2; return parser;
} }
private boolean getGNUExtension(TestSourceFile file) { private boolean getGNUExtension(TestSourceFile file) {

View file

@ -15,7 +15,6 @@ import java.io.BufferedReader;
import java.io.FileReader; import java.io.FileReader;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -35,18 +34,17 @@ public class SourceRewriteTester extends TestSuite {
private static final String codeTypeRegexp = "//%(C|CPP)( GNU)?$"; //$NON-NLS-1$ private static final String codeTypeRegexp = "//%(C|CPP)( GNU)?$"; //$NON-NLS-1$
private static final String resultRegexp = "//=.*$"; //$NON-NLS-1$ private static final String resultRegexp = "//=.*$"; //$NON-NLS-1$
enum MatcherState{skip, inTest, inSource, inExpectedResult} enum MatcherState { skip, inTest, inSource, inExpectedResult }
protected static BufferedReader createReader(String file) throws IOException { protected static BufferedReader createReader(String file) throws IOException {
Bundle bundle = CTestPlugin.getDefault().getBundle(); Bundle bundle = CTestPlugin.getDefault().getBundle();
Path path = new Path(file); Path path = new Path(file);
String file2 = FileLocator.toFileURL(FileLocator.find(bundle, path, null)).getFile(); file = FileLocator.toFileURL(FileLocator.find(bundle, path, null)).getFile();
return new BufferedReader(new FileReader(file2)); return new BufferedReader(new FileReader(file));
} }
public static Test suite(String name, String file)throws Exception { public static Test suite(String name, String file)throws Exception {
BufferedReader in = createReader(file); BufferedReader in = createReader(file);
ArrayList<RewriteBaseTest> testCases = createTests(in); ArrayList<RewriteBaseTest> testCases = createTests(in);
in.close(); in.close();
return createSuite(testCases, name); return createSuite(testCases, name);
@ -54,9 +52,7 @@ public class SourceRewriteTester extends TestSuite {
private static TestSuite createSuite(ArrayList<RewriteBaseTest> testCases, String name) { private static TestSuite createSuite(ArrayList<RewriteBaseTest> testCases, String name) {
TestSuite suite = new TestSuite(name); TestSuite suite = new TestSuite(name);
Iterator<RewriteBaseTest> it = testCases.iterator(); for (RewriteBaseTest subject : testCases) {
while (it.hasNext()) {
RewriteBaseTest subject = it.next();
suite.addTest(subject); suite.addTest(subject);
} }
return suite; return suite;
@ -155,7 +151,8 @@ public class SourceRewriteTester extends TestSuite {
return ParserLanguage.C; return ParserLanguage.C;
} }
private static RewriteBaseTest createTestClass(String testName, ASTWriterTestSourceFile file) throws Exception { private static RewriteBaseTest createTestClass(String testName, ASTWriterTestSourceFile file)
throws Exception {
ASTWriterTest test = new ASTWriterTest(testName, file); ASTWriterTest test = new ASTWriterTest(testName, file);
TextSelection sel = file.getSelection(); TextSelection sel = file.getSelection();
if (sel != null) { if (sel != null) {

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.append; package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.append;
@ -16,13 +16,11 @@ import junit.framework.TestSuite;
/** /**
* @author Thomas Corbat * @author Thomas Corbat
*
*/ */
public class AppendTestSuite{ public class AppendTestSuite {
public static Test suite() throws Exception { public static Test suite() throws Exception {
TestSuite suite = new TestSuite("Changegenerator Append Child Tests"); TestSuite suite = new TestSuite("ChangeGenerator Append Child Tests");
suite.addTest(ParameterTest.suite()); suite.addTest(ParameterTest.suite());
suite.addTest(ParameterToListTest.suite()); suite.addTest(ParameterToListTest.suite());
suite.addTest(PointerToParameterTest.suite()); suite.addTest(PointerToParameterTest.suite());
@ -32,7 +30,6 @@ public class AppendTestSuite{
suite.addTest(ArrayModifierTest.suite()); suite.addTest(ArrayModifierTest.suite());
suite.addTest(ExpressionTest.suite()); suite.addTest(ExpressionTest.suite());
suite.addTest(ArraySizeExpressionTest.suite()); suite.addTest(ArraySizeExpressionTest.suite());
return suite; return suite;
} }
} }

View file

@ -49,13 +49,14 @@ 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;
arrayDeclarator.getArrayModifiers(); arrayDeclarator.getArrayModifiers();
IASTArrayModifier newModifier = new CPPASTArrayModifier(); IASTArrayModifier newModifier = new CPPASTArrayModifier();
IASTExpression expr = new CPPASTLiteralExpression( IASTExpression expr = new CPPASTLiteralExpression(
IASTLiteralExpression.lk_integer_constant, "3".toCharArray()); //$NON-NLS-1$ IASTLiteralExpression.lk_integer_constant, "3".toCharArray()); //$NON-NLS-1$
newModifier.setConstantExpression(expr); newModifier.setConstantExpression(expr);
ASTModification modification = new ASTModification(ModificationKind.APPEND_CHILD, declarator, newModifier, null); ASTModification modification = new ASTModification(ModificationKind.APPEND_CHILD,
declarator, newModifier, null);
modStore.storeModification(null, modification); modStore.storeModification(null, modification);
} }
return PROCESS_CONTINUE; return PROCESS_CONTINUE;

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.append; package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.append;
@ -39,8 +39,7 @@ public class ArraySizeExpressionTest 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;
@ -53,8 +52,9 @@ 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, "5")); IASTArrayModifier add= new CPPASTArrayModifier(new CPPASTLiteralExpression(0, "5".toCharArray()));
ASTModification modification = new ASTModification(ASTModification.ModificationKind.APPEND_CHILD, dtor, add, null); ASTModification modification = new ASTModification(ASTModification.ModificationKind.APPEND_CHILD,
dtor, add, null);
modStore.storeModification(null, modification); modStore.storeModification(null, modification);
} }
return PROCESS_CONTINUE; return PROCESS_CONTINUE;

View file

@ -33,14 +33,13 @@ public class CtorChainInitializerTest extends ChangeGeneratorTest {
@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) :\n\t\tbeta(b) {\n}\n"; //$NON-NLS-1$
expectedSource = "TestClass::TestClass(int a, int b):beta(b), alpha(a){\n}\n\n"; //$NON-NLS-1$ expectedSource = "TestClass::TestClass(int a, int b) :\n\t\tbeta(b), alpha(a) {\n}\n"; //$NON-NLS-1$
super.setUp(); super.setUp();
} }
@Override @Override
protected ASTVisitor createModificator( protected ASTVisitor createModificator(final ASTModificationStore modStore) {
final ASTModificationStore modStore) {
return new ASTVisitor() { return new ASTVisitor() {
{ {
shouldVisitDeclarations = true; shouldVisitDeclarations = true;
@ -49,12 +48,13 @@ public class CtorChainInitializerTest extends ChangeGeneratorTest {
@Override @Override
public int visit(IASTDeclaration decl) { public int visit(IASTDeclaration decl) {
if (decl instanceof CPPASTFunctionDefinition) { if (decl instanceof CPPASTFunctionDefinition) {
CPPASTFunctionDefinition fdef = (CPPASTFunctionDefinition)decl; CPPASTFunctionDefinition fdef = (CPPASTFunctionDefinition) decl;
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$
ICPPASTConstructorChainInitializer newInitializer = new CPPASTConstructorChainInitializer(initName, null); ICPPASTConstructorChainInitializer newInitializer = new CPPASTConstructorChainInitializer(initName, null);
newInitializer.setInitializerValue(initExpr); newInitializer.setInitializerValue(initExpr);
ASTModification modification = new ASTModification(ModificationKind.APPEND_CHILD, fdef, newInitializer, null); ASTModification modification = new ASTModification(ModificationKind.APPEND_CHILD,
fdef, newInitializer, null);
modStore.storeModification(null, modification); modStore.storeModification(null, modification);
} }
return PROCESS_CONTINUE; return PROCESS_CONTINUE;

View file

@ -35,8 +35,8 @@ public class ExceptionTest extends ChangeGeneratorTest {
@Override @Override
protected void setUp() throws Exception { protected void setUp() throws Exception {
source = "void foo(int parameter){\n}\n\n"; //$NON-NLS-1$ source = "void foo(int parameter) {\n}\n\n"; //$NON-NLS-1$
expectedSource = "void foo(int parameter) throw (int){\n}\n\n"; //$NON-NLS-1$ expectedSource = "void foo(int parameter) throw (int) {\n}\n\n"; //$NON-NLS-1$
super.setUp(); super.setUp();
} }
@ -57,7 +57,8 @@ public class ExceptionTest extends ChangeGeneratorTest {
exDeclSpec.setType(IASTSimpleDeclSpecifier.t_int); exDeclSpec.setType(IASTSimpleDeclSpecifier.t_int);
exception.setDeclSpecifier(exDeclSpec); exception.setDeclSpecifier(exDeclSpec);
exception.setAbstractDeclarator(exceptionDeclarator); exception.setAbstractDeclarator(exceptionDeclarator);
ASTModification modification = new ASTModification(ModificationKind.APPEND_CHILD, declarator, exception, null); ASTModification modification = new ASTModification(ModificationKind.APPEND_CHILD,
declarator, exception, null);
modStore.storeModification(null, modification); modStore.storeModification(null, modification);
} }
return PROCESS_CONTINUE; return PROCESS_CONTINUE;

View file

@ -33,8 +33,8 @@ public class ExpressionTest extends ChangeGeneratorTest {
@Override @Override
protected void setUp() throws Exception { protected void setUp() throws Exception {
source = "void main(){int s = 0, c = 0, h = 0;\ns = 3, h = 5;}"; //$NON-NLS-1$ source = "void main() {\n\tint s = 0, c = 0, h = 0;\n\ts = 3, h = 5;\n}"; //$NON-NLS-1$
expectedSource = "void main(){int s = 0, c = 0, h = 0;\ns = 3, h = 5, c = 9;}"; //$NON-NLS-1$ expectedSource = "void main() {\n\tint s = 0, c = 0, h = 0;\n\ts = 3, h = 5, c = 9;\n}"; //$NON-NLS-1$
super.setUp(); super.setUp();
} }
@Override @Override
@ -49,18 +49,19 @@ public class ExpressionTest extends ChangeGeneratorTest {
if (expression instanceof IASTExpressionList) { if (expression instanceof IASTExpressionList) {
IASTExpressionList expressionList = (IASTExpressionList) expression; IASTExpressionList expressionList = (IASTExpressionList) expression;
expressionList.getExpressions(); expressionList.getExpressions();
CPPASTBinaryExpression binEx = new CPPASTBinaryExpression(IASTBinaryExpression.op_assign, new CPPASTIdExpression(new CPPASTName("c".toCharArray())), new CPPASTLiteralExpression(0, "9")); //$NON-NLS-1$ //$NON-NLS-2$ CPPASTIdExpression idExpression = new CPPASTIdExpression(new CPPASTName("c".toCharArray()));
ASTModification modification = new ASTModification(ASTModification.ModificationKind.APPEND_CHILD, expressionList, binEx, null); CPPASTBinaryExpression binEx = new CPPASTBinaryExpression(IASTBinaryExpression.op_assign,
idExpression, new CPPASTLiteralExpression(0, "9".toCharArray())); //$NON-NLS-1$ //$NON-NLS-2$
ASTModification modification = new ASTModification(ASTModification.ModificationKind.APPEND_CHILD,
expressionList, binEx, null);
modStore.storeModification(null, modification); modStore.storeModification(null, modification);
} }
return PROCESS_CONTINUE; return PROCESS_CONTINUE;
} }
}; };
} }
public static Test suite() { public static Test suite() {
return new ExpressionTest(); return new ExpressionTest();
} }
} }

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.append; package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.append;
@ -34,8 +34,8 @@ public class ParameterTest extends ChangeGeneratorTest {
@Override @Override
protected void setUp() throws Exception { protected void setUp() throws Exception {
source = "void foo(int existing){\n}\n\n"; //$NON-NLS-1$ source = "void foo(int existing) {\n}\n"; //$NON-NLS-1$
expectedSource = "void foo(int existing, int newParameter){\n}\n\n"; //$NON-NLS-1$ expectedSource = "void foo(int existing, int newParameter) {\n}\n"; //$NON-NLS-1$
super.setUp(); super.setUp();
} }
@ -49,7 +49,7 @@ public class ParameterTest 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;
CPPASTParameterDeclaration insertedParameter = new CPPASTParameterDeclaration(); CPPASTParameterDeclaration insertedParameter = new CPPASTParameterDeclaration();
CPPASTDeclarator parameterDeclarator = new CPPASTDeclarator(); CPPASTDeclarator parameterDeclarator = new CPPASTDeclarator();
@ -59,7 +59,8 @@ public class ParameterTest extends ChangeGeneratorTest {
CPPASTSimpleDeclSpecifier parameterDeclSpec = new CPPASTSimpleDeclSpecifier(); CPPASTSimpleDeclSpecifier parameterDeclSpec = new CPPASTSimpleDeclSpecifier();
parameterDeclSpec.setType(IASTSimpleDeclSpecifier.t_int); parameterDeclSpec.setType(IASTSimpleDeclSpecifier.t_int);
insertedParameter.setDeclSpecifier(parameterDeclSpec); insertedParameter.setDeclSpecifier(parameterDeclSpec);
ASTModification modification = new ASTModification(ModificationKind.APPEND_CHILD, functionDeclarator, insertedParameter, null); ASTModification modification = new ASTModification(ModificationKind.APPEND_CHILD,
functionDeclarator, insertedParameter, null);
modStore.storeModification(null, modification); modStore.storeModification(null, modification);
} }
return PROCESS_CONTINUE; return PROCESS_CONTINUE;

View file

@ -34,8 +34,8 @@ public class ParameterToListTest extends ChangeGeneratorTest {
@Override @Override
protected void setUp() throws Exception { protected void setUp() throws Exception {
source = "void foo(){\n}\n\n"; //$NON-NLS-1$ source = "void foo() {\n}\n\n"; //$NON-NLS-1$
expectedSource = "void foo(int newParameter){\n}\n\n"; //$NON-NLS-1$ expectedSource = "void foo(int newParameter) {\n}\n\n"; //$NON-NLS-1$
super.setUp(); super.setUp();
} }
@ -49,7 +49,7 @@ public class ParameterToListTest 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;
CPPASTParameterDeclaration insertedParameter = new CPPASTParameterDeclaration(); CPPASTParameterDeclaration insertedParameter = new CPPASTParameterDeclaration();
CPPASTDeclarator parameterDeclarator = new CPPASTDeclarator(); CPPASTDeclarator parameterDeclarator = new CPPASTDeclarator();
@ -59,7 +59,8 @@ public class ParameterToListTest extends ChangeGeneratorTest {
CPPASTSimpleDeclSpecifier parameterDeclSpec = new CPPASTSimpleDeclSpecifier(); CPPASTSimpleDeclSpecifier parameterDeclSpec = new CPPASTSimpleDeclSpecifier();
parameterDeclSpec.setType(IASTSimpleDeclSpecifier.t_int); parameterDeclSpec.setType(IASTSimpleDeclSpecifier.t_int);
insertedParameter.setDeclSpecifier(parameterDeclSpec); insertedParameter.setDeclSpecifier(parameterDeclSpec);
ASTModification modification = new ASTModification(ModificationKind.APPEND_CHILD, functionDeclarator, insertedParameter, null); ASTModification modification = new ASTModification(ModificationKind.APPEND_CHILD,
functionDeclarator, insertedParameter, null);
modStore.storeModification(null, modification); modStore.storeModification(null, modification);
} }
return PROCESS_CONTINUE; return PROCESS_CONTINUE;

View file

@ -31,8 +31,8 @@ public class PointerToParameterTest extends ChangeGeneratorTest {
@Override @Override
protected void setUp() throws Exception { protected void setUp() throws Exception {
source = "void foo(int parameter){\n}\n\n"; //$NON-NLS-1$ source = "void foo(int parameter) {\n}\n\n"; //$NON-NLS-1$
expectedSource = "void foo(int *parameter){\n}\n\n"; //$NON-NLS-1$ expectedSource = "void foo(int *parameter) {\n}\n\n"; //$NON-NLS-1$
super.setUp(); super.setUp();
} }
@ -46,12 +46,13 @@ public class PointerToParameterTest 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;
IASTParameterDeclaration[] parameters = functionDeclarator.getParameters(); IASTParameterDeclaration[] parameters = functionDeclarator.getParameters();
for (IASTParameterDeclaration curParam : parameters){ for (IASTParameterDeclaration curParam : parameters){
if (String.valueOf(curParam.getDeclarator().getName().toCharArray()).equals("parameter")){ //$NON-NLS-1$ if (String.valueOf(curParam.getDeclarator().getName().toCharArray()).equals("parameter")){ //$NON-NLS-1$
CPPASTPointer addedPointer = new CPPASTPointer(); CPPASTPointer addedPointer = new CPPASTPointer();
ASTModification modification = new ASTModification(ModificationKind.APPEND_CHILD, curParam.getDeclarator(), addedPointer, null); ASTModification modification = new ASTModification(ModificationKind.APPEND_CHILD,
curParam.getDeclarator(), addedPointer, null);
modStore.storeModification(null, modification); modStore.storeModification(null, modification);
} }
} }

View file

@ -31,8 +31,8 @@ public class PointerToPointerParameterTest extends ChangeGeneratorTest {
@Override @Override
protected void setUp() throws Exception { protected void setUp() throws Exception {
source = "void foo(int *parameter){\n}\n\n"; //$NON-NLS-1$ source = "void foo(int *parameter) {\n}\n\n"; //$NON-NLS-1$
expectedSource = "void foo(int **parameter){\n}\n\n"; //$NON-NLS-1$ expectedSource = "void foo(int **parameter) {\n}\n\n"; //$NON-NLS-1$
super.setUp(); super.setUp();
} }
@ -46,12 +46,13 @@ public class PointerToPointerParameterTest 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;
IASTParameterDeclaration[] parameters = functionDeclarator.getParameters(); IASTParameterDeclaration[] parameters = functionDeclarator.getParameters();
for (IASTParameterDeclaration curParam : parameters){ for (IASTParameterDeclaration curParam : parameters){
if (String.valueOf(curParam.getDeclarator().getName().toCharArray()).equals("parameter")){ //$NON-NLS-1$ if (String.valueOf(curParam.getDeclarator().getName().toCharArray()).equals("parameter")){ //$NON-NLS-1$
CPPASTPointer addedPointer = new CPPASTPointer(); CPPASTPointer addedPointer = new CPPASTPointer();
ASTModification modification = new ASTModification(ModificationKind.APPEND_CHILD, curParam.getDeclarator(), addedPointer, null); ASTModification modification = new ASTModification(ModificationKind.APPEND_CHILD,
curParam.getDeclarator(), addedPointer, null);
modStore.storeModification(null, modification); modStore.storeModification(null, modification);
} }
} }

View file

@ -69,7 +69,8 @@ public class AddDeclarationBug extends ChangeGeneratorTest {
returnTyp.setType(IASTSimpleDeclSpecifier.t_int); returnTyp.setType(IASTSimpleDeclSpecifier.t_int);
newDecl.setDeclSpecifier(returnTyp); newDecl.setDeclSpecifier(returnTyp);
IASTStandardFunctionDeclarator declarator = new CPPASTFunctionDeclarator(new CPPASTName("exp".toCharArray())); //$NON-NLS-1$ IASTStandardFunctionDeclarator declarator = new CPPASTFunctionDeclarator(
new CPPASTName("exp".toCharArray())); //$NON-NLS-1$
IASTSimpleDeclSpecifier paramTyp = new CPPASTSimpleDeclSpecifier(); IASTSimpleDeclSpecifier paramTyp = new CPPASTSimpleDeclSpecifier();
paramTyp.setType(IASTSimpleDeclSpecifier.t_int); paramTyp.setType(IASTSimpleDeclSpecifier.t_int);
IASTDeclarator decl = new CPPASTDeclarator(new CPPASTName("i".toCharArray())); //$NON-NLS-1$ IASTDeclarator decl = new CPPASTDeclarator(new CPPASTName("i".toCharArray())); //$NON-NLS-1$
@ -77,7 +78,8 @@ public class AddDeclarationBug extends ChangeGeneratorTest {
declarator.addParameterDeclaration(param); declarator.addParameterDeclaration(param);
newDecl.addDeclarator(declarator); newDecl.addDeclarator(declarator);
ASTModification mod = new ASTModification(ModificationKind.APPEND_CHILD, classNode, newDecl, null); ASTModification mod = new ASTModification(ModificationKind.APPEND_CHILD, classNode,
newDecl, null);
modStore.storeModification(null, mod); modStore.storeModification(null, mod);
} }
return PROCESS_CONTINUE; return PROCESS_CONTINUE;

View file

@ -60,7 +60,8 @@ public class ArrayModifierTest extends ChangeGeneratorTest {
IASTExpression expr = IASTExpression expr =
new CPPASTLiteralExpression(IASTLiteralExpression.lk_integer_constant, "5".toCharArray()); //$NON-NLS-1$ 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);
} }
return PROCESS_CONTINUE; return PROCESS_CONTINUE;

View file

@ -59,7 +59,8 @@ public class ArraySizeExpressionTest extends ChangeGeneratorTest {
IASTArrayModifier[] mods= dtor.getArrayModifiers(); IASTArrayModifier[] mods= dtor.getArrayModifiers();
IASTArrayModifier add= new CPPASTArrayModifier( IASTArrayModifier add= new CPPASTArrayModifier(
new CPPASTLiteralExpression(IASTLiteralExpression.lk_integer_constant, "6".toCharArray())); 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);
} }
return PROCESS_CONTINUE; return PROCESS_CONTINUE;

View file

@ -60,7 +60,6 @@ public class CtorChainInitializerTest extends ChangeGeneratorTest {
newInitializer.setInitializerValue(initExpr); newInitializer.setInitializerValue(initExpr);
ASTModification modification = new ASTModification(ModificationKind.INSERT_BEFORE, ctorInitializer, newInitializer, null); ASTModification modification = new ASTModification(ModificationKind.INSERT_BEFORE, ctorInitializer, newInitializer, null);
modStore.storeModification(null, modification); modStore.storeModification(null, modification);
} }
return PROCESS_CONTINUE; return PROCESS_CONTINUE;
} }

View file

@ -54,7 +54,7 @@ public class ExceptionTest 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;
IASTTypeId existingException = functionDeclarator.getExceptionSpecification()[0]; IASTTypeId existingException = functionDeclarator.getExceptionSpecification()[0];
IASTTypeId exception = new CPPASTTypeId(); IASTTypeId exception = new CPPASTTypeId();
@ -64,9 +64,9 @@ public class ExceptionTest extends ChangeGeneratorTest {
exDeclSpec.setType(IASTSimpleDeclSpecifier.t_int); exDeclSpec.setType(IASTSimpleDeclSpecifier.t_int);
exception.setDeclSpecifier(exDeclSpec); exception.setDeclSpecifier(exDeclSpec);
exception.setAbstractDeclarator(exceptionDeclarator); exception.setAbstractDeclarator(exceptionDeclarator);
ASTModification modification = new ASTModification(ModificationKind.INSERT_BEFORE, existingException, exception, null); ASTModification modification = new ASTModification(ModificationKind.INSERT_BEFORE,
existingException, exception, null);
modStore.storeModification(null, modification); modStore.storeModification(null, modification);
} }
return PROCESS_CONTINUE; return PROCESS_CONTINUE;
} }

View file

@ -37,8 +37,8 @@ public class ExpressionTest extends ChangeGeneratorTest {
@Override @Override
protected void setUp() throws Exception { protected void setUp() throws Exception {
source = "void main(){int s = 0, c = 0, h = 0;\ns = 3, h = 5;}"; //$NON-NLS-1$ source = "void main() {\n\tint s = 0, c = 0, h = 0;\n\ts = 3, h = 5;\n}"; //$NON-NLS-1$
expectedSource = "void main(){int s = 0, c = 0, h = 0;\ns = 3, c = 9, h = 5;}"; //$NON-NLS-1$ expectedSource = "void main() {\n\tint s = 0, c = 0, h = 0;\n\ts = 3, c = 9, h = 5;\n}"; //$NON-NLS-1$
super.setUp(); super.setUp();
} }
@ -54,8 +54,11 @@ public class ExpressionTest extends ChangeGeneratorTest {
if (expression instanceof IASTExpressionList) { if (expression instanceof IASTExpressionList) {
IASTExpressionList expressionList = (IASTExpressionList) expression; IASTExpressionList expressionList = (IASTExpressionList) expression;
IASTExpression[] expressions = expressionList.getExpressions(); IASTExpression[] expressions = expressionList.getExpressions();
CPPASTBinaryExpression binEx = new CPPASTBinaryExpression(IASTBinaryExpression.op_assign, new CPPASTIdExpression(new CPPASTName("c".toCharArray())), new CPPASTLiteralExpression(0, "9")); //$NON-NLS-1$ //$NON-NLS-2$ CPPASTIdExpression idExpression = new CPPASTIdExpression(new CPPASTName("c".toCharArray())); //$NON-NLS-1$
ASTModification modification = new ASTModification(ASTModification.ModificationKind.INSERT_BEFORE, expressions[1], binEx, null); CPPASTBinaryExpression binEx = new CPPASTBinaryExpression(IASTBinaryExpression.op_assign,
idExpression, new CPPASTLiteralExpression(0, "9".toCharArray())); //$NON-NLS-1$
ASTModification modification = new ASTModification(ASTModification.ModificationKind.INSERT_BEFORE,
expressions[1], binEx, null);
modStore.storeModification(null, modification); modStore.storeModification(null, modification);
} }
return PROCESS_CONTINUE; return PROCESS_CONTINUE;

View file

@ -39,8 +39,8 @@ public class FirstParameterTest extends ChangeGeneratorTest {
@Override @Override
protected void setUp() throws Exception { protected void setUp() throws Exception {
source = "void foo(int a){\n}\n\n"; //$NON-NLS-1$ source = "void foo(int a) {\n}\n\n"; //$NON-NLS-1$
expectedSource = "void foo(int newParameter, int a){\n}\n\n"; //$NON-NLS-1$ expectedSource = "void foo(int newParameter, int a) {\n}\n\n"; //$NON-NLS-1$
super.setUp(); super.setUp();
} }
@ -54,10 +54,10 @@ public class FirstParameterTest 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;
IASTParameterDeclaration[] parameters = functionDeclarator.getParameters(); IASTParameterDeclaration[] parameters = functionDeclarator.getParameters();
for(IASTParameterDeclaration curParam : parameters){ for (IASTParameterDeclaration curParam : parameters){
if(String.valueOf(curParam.getDeclarator().getName().toCharArray()).equals("a")){ //$NON-NLS-1$ if (String.valueOf(curParam.getDeclarator().getName().toCharArray()).equals("a")){ //$NON-NLS-1$
CPPASTParameterDeclaration insertedParameter = new CPPASTParameterDeclaration(); CPPASTParameterDeclaration insertedParameter = new CPPASTParameterDeclaration();
CPPASTDeclarator parameterDeclarator = new CPPASTDeclarator(); CPPASTDeclarator parameterDeclarator = new CPPASTDeclarator();
CPPASTName parameterName = new CPPASTName("newParameter".toCharArray()); //$NON-NLS-1$ CPPASTName parameterName = new CPPASTName("newParameter".toCharArray()); //$NON-NLS-1$
@ -66,7 +66,8 @@ public class FirstParameterTest extends ChangeGeneratorTest {
CPPASTSimpleDeclSpecifier parameterDeclSpec = new CPPASTSimpleDeclSpecifier(); CPPASTSimpleDeclSpecifier parameterDeclSpec = new CPPASTSimpleDeclSpecifier();
parameterDeclSpec.setType(IASTSimpleDeclSpecifier.t_int); parameterDeclSpec.setType(IASTSimpleDeclSpecifier.t_int);
insertedParameter.setDeclSpecifier(parameterDeclSpec); insertedParameter.setDeclSpecifier(parameterDeclSpec);
ASTModification modification = new ASTModification(ModificationKind.INSERT_BEFORE, curParam, insertedParameter, null); ASTModification modification = new ASTModification(ModificationKind.INSERT_BEFORE,
curParam, insertedParameter, null);
modStore.storeModification(null, modification); modStore.storeModification(null, modification);
} }
} }

View file

@ -38,8 +38,8 @@ public class MultilineWhitespaceHandlingTest extends ChangeGeneratorTest {
@Override @Override
protected void setUp() throws Exception { 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$ source = "void foo() {\n\tfor (int i = 0; i < 10; i++) {\n\n\n\t}\n}\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$ expectedSource = "void foo() {\n\tfor (int i = 0; i < 10; i++) {\n\t\tint i;\n\t\tint j;\n\t}\n}\n"; //$NON-NLS-1$
super.setUp(); super.setUp();
} }
@ -73,7 +73,8 @@ public class MultilineWhitespaceHandlingTest extends ChangeGeneratorTest {
newSimpleDeclaration.addDeclarator(nf.newDeclarator(nf.newName(variableName.toCharArray()))); newSimpleDeclaration.addDeclarator(nf.newDeclarator(nf.newName(variableName.toCharArray())));
IASTDeclarationStatement newDeclaration = nf.newDeclarationStatement(newSimpleDeclaration); IASTDeclarationStatement newDeclaration = nf.newDeclarationStatement(newSimpleDeclaration);
ASTModification modification = new ASTModification(ASTModification.ModificationKind.APPEND_CHILD, compoundStatement, newDeclaration, null); ASTModification modification = new ASTModification(ASTModification.ModificationKind.APPEND_CHILD,
compoundStatement, newDeclaration, null);
modStore.storeModification(null, modification); modStore.storeModification(null, modification);
} }
}; };

View file

@ -36,8 +36,8 @@ public class PointerParameterTest extends ChangeGeneratorTest {
@Override @Override
protected void setUp() throws Exception { protected void setUp() throws Exception {
source = "void foo(int *parameter){\n}\n\n"; //$NON-NLS-1$ source = "void foo(int *parameter) {\n}\n\n"; //$NON-NLS-1$
expectedSource = "void foo(int **parameter){\n}\n\n"; //$NON-NLS-1$ expectedSource = "void foo(int **parameter) {\n}\n\n"; //$NON-NLS-1$
super.setUp(); super.setUp();
} }

View file

@ -51,7 +51,8 @@ public class SelfInsertionTest extends ChangeGeneratorTest {
IASTForStatement forStatement = (IASTForStatement) statement; IASTForStatement forStatement = (IASTForStatement) statement;
IASTCompoundStatement compoundStatement = (IASTCompoundStatement) forStatement.getBody(); IASTCompoundStatement compoundStatement = (IASTCompoundStatement) forStatement.getBody();
ASTModification modification = new ASTModification(ASTModification.ModificationKind.APPEND_CHILD, compoundStatement, forStatement, null); ASTModification modification = new ASTModification(ASTModification.ModificationKind.APPEND_CHILD,
compoundStatement, forStatement, null);
modStore.storeModification(null, modification); modStore.storeModification(null, modification);
} }

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.remove; package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.remove;
@ -24,14 +24,14 @@ import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKin
public class CtorChainInitializerTest extends ChangeGeneratorTest { public class CtorChainInitializerTest extends ChangeGeneratorTest {
public CtorChainInitializerTest(){ public CtorChainInitializerTest() {
super("Remove Ctor Initializer"); //$NON-NLS-1$ super("Remove Ctor Initializer"); //$NON-NLS-1$
} }
@Override @Override
protected void setUp() throws Exception { protected void setUp() throws Exception {
source = "TestClass::TestClass(int a):alpha(a){\n}\n\n"; //$NON-NLS-1$ source = "TestClass::TestClass(int a):alpha(a) {\n}\n\n"; //$NON-NLS-1$
expectedSource = "TestClass::TestClass(int a){\n}\n\n"; //$NON-NLS-1$ expectedSource = "TestClass::TestClass(int a) {\n}\n\n"; //$NON-NLS-1$
super.setUp(); super.setUp();
} }
@ -40,8 +40,7 @@ public class CtorChainInitializerTest 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;
@ -50,11 +49,12 @@ 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[] ctorInitializers = functionDeclarator.getConstructorChain(); ICPPASTConstructorChainInitializer[] ctorInitializers = functionDeclarator.getConstructorChain();
for(ICPPASTConstructorChainInitializer curInitializer : ctorInitializers){ for (ICPPASTConstructorChainInitializer curInitializer : ctorInitializers){
ASTModification modification = new ASTModification(ModificationKind.REPLACE, curInitializer, null, null); ASTModification modification = new ASTModification(ModificationKind.REPLACE,
modStore.storeModification(null, modification); curInitializer, null, null);
modStore.storeModification(null, modification);
} }
} }
return PROCESS_CONTINUE; return PROCESS_CONTINUE;

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.remove; package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.remove;
@ -30,8 +30,8 @@ public class ExceptionTest extends ChangeGeneratorTest {
@Override @Override
protected void setUp() throws Exception { protected void setUp() throws Exception {
source = "void foo(int parameter) throw (int){\n}\n\n"; //$NON-NLS-1$ source = "void foo(int parameter) throw (int) {\n}\n\n"; //$NON-NLS-1$
expectedSource = "void foo(int parameter) throw (){\n}\n\n"; //$NON-NLS-1$ expectedSource = "void foo(int parameter) throw () {\n}\n\n"; //$NON-NLS-1$
super.setUp(); super.setUp();
} }
@ -40,8 +40,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;
@ -50,11 +49,12 @@ public class ExceptionTest 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;
IASTTypeId[] exceptions = functionDeclarator.getExceptionSpecification(); IASTTypeId[] exceptions = functionDeclarator.getExceptionSpecification();
for(IASTTypeId curException : exceptions){ for (IASTTypeId curException : exceptions) {
ASTModification modification = new ASTModification(ModificationKind.REPLACE, curException, null, null); ASTModification modification = new ASTModification(ModificationKind.REPLACE,
modStore.storeModification(null, modification); curException, null, null);
modStore.storeModification(null, modification);
} }
} }
return PROCESS_CONTINUE; return PROCESS_CONTINUE;

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.remove; package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.remove;
@ -20,20 +20,16 @@ import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGenerator
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification; import org.eclipse.cdt.internal.core.dom.rewrite.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(){ public ExpressionTest() {
super("Remove Expression"); //$NON-NLS-1$ super("Remove Expression"); //$NON-NLS-1$
} }
@Override @Override
protected void setUp() throws Exception { protected void setUp() throws Exception {
source = "void main(){int s = 0, c = 0, h = 0;\ns = 3, c = 4, h = 5;}"; //$NON-NLS-1$ source = "void main() {\n\tint s = 0, c = 0, h = 0;\n\ts = 3, c = 4, h = 5;\n}"; //$NON-NLS-1$
expectedSource = "void main(){int s = 0, c = 0, h = 0;\ns = 3, h = 5;}"; //$NON-NLS-1$ expectedSource = "void main() {\n\tint s = 0, c = 0, h = 0;\n\ts = 3, h = 5;\n}"; //$NON-NLS-1$
super.setUp(); super.setUp();
} }
@ -42,8 +38,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;
@ -54,13 +49,12 @@ public class ExpressionTest extends ChangeGeneratorTest {
if (expression instanceof IASTExpressionList) { if (expression instanceof IASTExpressionList) {
IASTExpressionList expressionList = (IASTExpressionList) expression; IASTExpressionList expressionList = (IASTExpressionList) expression;
IASTExpression[] expressions = expressionList.getExpressions(); IASTExpression[] expressions = expressionList.getExpressions();
ASTModification modification = new ASTModification(ASTModification.ModificationKind.REPLACE, expressions[1], null, null); ASTModification modification = new ASTModification(ASTModification.ModificationKind.REPLACE,
expressions[1], null, null);
modStore.storeModification(null, modification); modStore.storeModification(null, modification);
} }
return PROCESS_CONTINUE; return PROCESS_CONTINUE;
} }
}; };
} }
} }

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.remove; package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.remove;
@ -22,31 +22,25 @@ import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore; import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind; import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind;
public class FirstParameterTest extends ChangeGeneratorTest { public class FirstParameterTest extends ChangeGeneratorTest {
public FirstParameterTest(){ public FirstParameterTest() {
super("Remove First Parameter Node"); //$NON-NLS-1$ super("Remove First Parameter Node"); //$NON-NLS-1$
} }
@Override @Override
protected void setUp() throws Exception { protected void setUp() throws Exception {
source = "void foo(int a, int b, int c){\n}\n\n"; //$NON-NLS-1$ source = "void foo(int a, int b, int c) {\n}\n\n"; //$NON-NLS-1$
expectedSource = "void foo(int b, int c){\n}\n\n"; //$NON-NLS-1$ expectedSource = "void foo(int b, int c) {\n}\n\n"; //$NON-NLS-1$
super.setUp(); super.setUp();
} }
public static Test suite() { public static Test suite() {
return new FirstParameterTest(); return new FirstParameterTest();
} }
@Override @Override
protected ASTVisitor createModificator( protected ASTVisitor createModificator(final ASTModificationStore modStore) {
final ASTModificationStore modStore) {
return new ASTVisitor() { return new ASTVisitor() {
{ {
shouldVisitDeclarators = true; shouldVisitDeclarators = true;
@ -55,11 +49,12 @@ public class FirstParameterTest 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;
IASTParameterDeclaration[] parameters = functionDeclarator.getParameters(); IASTParameterDeclaration[] parameters = functionDeclarator.getParameters();
for(IASTParameterDeclaration curParam : parameters){ for (IASTParameterDeclaration curParam : parameters){
if(String.valueOf(curParam.getDeclarator().getName().toCharArray()).equals("a")){ //$NON-NLS-1$ if (String.valueOf(curParam.getDeclarator().getName().toCharArray()).equals("a")) { //$NON-NLS-1$
ASTModification modification = new ASTModification(ModificationKind.REPLACE, curParam, null, null); ASTModification modification = new ASTModification(ModificationKind.REPLACE,
curParam, null, null);
modStore.storeModification(null, modification); modStore.storeModification(null, modification);
} }
} }
@ -69,6 +64,4 @@ public class FirstParameterTest extends ChangeGeneratorTest {
}; };
} }
} }

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.remove; package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.remove;
@ -22,18 +22,16 @@ import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore; import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind; import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind;
public class LastParameterTest extends ChangeGeneratorTest { public class LastParameterTest extends ChangeGeneratorTest {
public LastParameterTest(){ public LastParameterTest() {
super("Remove Last Parameter Node"); //$NON-NLS-1$ super("Remove Last Parameter Node"); //$NON-NLS-1$
} }
@Override @Override
protected void setUp() throws Exception { protected void setUp() throws Exception {
source = "void foo(int a, int b, int c){\n}\n\n"; //$NON-NLS-1$ source = "void foo(int a, int b, int c) {\n}\n\n"; //$NON-NLS-1$
expectedSource = "void foo(int a, int b){\n}\n\n"; //$NON-NLS-1$ expectedSource = "void foo(int a, int b) {\n}\n\n"; //$NON-NLS-1$
super.setUp(); super.setUp();
} }
@ -42,8 +40,7 @@ public class LastParameterTest 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;
@ -52,17 +49,17 @@ public class LastParameterTest 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;
IASTParameterDeclaration[] parameters = functionDeclarator.getParameters(); IASTParameterDeclaration[] parameters = functionDeclarator.getParameters();
for(IASTParameterDeclaration curParam : parameters){ for (IASTParameterDeclaration curParam : parameters){
if(String.valueOf(curParam.getDeclarator().getName().toCharArray()).equals("c")){ //$NON-NLS-1$ if (String.valueOf(curParam.getDeclarator().getName().toCharArray()).equals("c")) { //$NON-NLS-1$
ASTModification modification = new ASTModification(ModificationKind.REPLACE, curParam, null, null); ASTModification modification = new ASTModification(ModificationKind.REPLACE,
curParam, null, null);
modStore.storeModification(null, modification); modStore.storeModification(null, modification);
} }
} }
} }
return PROCESS_CONTINUE; return PROCESS_CONTINUE;
} }
}; };

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.remove; package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.remove;
@ -22,10 +22,6 @@ import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore; import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind; import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind;
public class MiddleParameterTest extends ChangeGeneratorTest { public class MiddleParameterTest extends ChangeGeneratorTest {
public MiddleParameterTest(){ public MiddleParameterTest(){
@ -34,8 +30,8 @@ public class MiddleParameterTest extends ChangeGeneratorTest {
@Override @Override
protected void setUp() throws Exception { protected void setUp() throws Exception {
source = "void foo(int a, int b, int c){\n}\n\n"; //$NON-NLS-1$ source = "void foo(int a, int b, int c) {\n}\n\n"; //$NON-NLS-1$
expectedSource = "void foo(int a, int c){\n}\n\n"; //$NON-NLS-1$ expectedSource = "void foo(int a, int c) {\n}\n\n"; //$NON-NLS-1$
super.setUp(); super.setUp();
} }
@ -44,10 +40,8 @@ public class MiddleParameterTest extends ChangeGeneratorTest {
return new MiddleParameterTest(); return new MiddleParameterTest();
} }
@Override @Override
protected ASTVisitor createModificator( protected ASTVisitor createModificator(final ASTModificationStore modStore) {
final ASTModificationStore modStore) {
return new ASTVisitor() { return new ASTVisitor() {
{ {
shouldVisitDeclarators = true; shouldVisitDeclarators = true;
@ -56,11 +50,12 @@ public class MiddleParameterTest 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;
IASTParameterDeclaration[] parameters = functionDeclarator.getParameters(); IASTParameterDeclaration[] parameters = functionDeclarator.getParameters();
for(IASTParameterDeclaration curParam : parameters){ for (IASTParameterDeclaration curParam : parameters){
if(String.valueOf(curParam.getDeclarator().getName().toCharArray()).equals("b")){ //$NON-NLS-1$ if (String.valueOf(curParam.getDeclarator().getName().toCharArray()).equals("b")) { //$NON-NLS-1$
ASTModification modification = new ASTModification(ModificationKind.REPLACE, curParam, null, null); ASTModification modification = new ASTModification(ModificationKind.REPLACE,
curParam, null, null);
modStore.storeModification(null, modification); modStore.storeModification(null, modification);
} }
} }

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.remove; package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.remove;
@ -25,25 +25,23 @@ import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKin
public class PointerInParameterTest extends ChangeGeneratorTest { public class PointerInParameterTest extends ChangeGeneratorTest {
public PointerInParameterTest(){ public PointerInParameterTest() {
super("Remove Pointer in Parameter"); //$NON-NLS-1$ super("Remove Pointer in Parameter"); //$NON-NLS-1$
} }
@Override @Override
protected void setUp() throws Exception { protected void setUp() throws Exception {
source = "void foo(int *parameter){\n}\n\n"; //$NON-NLS-1$ source = "void foo(int *parameter) {\n}\n\n"; //$NON-NLS-1$
expectedSource = "void foo(int parameter){\n}\n\n"; //$NON-NLS-1$ expectedSource = "void foo(int parameter) {\n}\n\n"; //$NON-NLS-1$
super.setUp(); super.setUp();
} }
public static Test suite() { public static Test suite() {
return new PointerInParameterTest(); return new PointerInParameterTest();
} }
@Override @Override
protected ASTVisitor createModificator( protected ASTVisitor createModificator(final ASTModificationStore modStore) {
final ASTModificationStore modStore) {
return new ASTVisitor() { return new ASTVisitor() {
{ {
shouldVisitDeclarators = true; shouldVisitDeclarators = true;
@ -52,18 +50,18 @@ public class PointerInParameterTest 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;
IASTParameterDeclaration[] parameters = functionDeclarator.getParameters(); IASTParameterDeclaration[] parameters = functionDeclarator.getParameters();
for(IASTParameterDeclaration curParam : parameters){ for (IASTParameterDeclaration curParam : parameters){
if(String.valueOf(curParam.getDeclarator().getName().toCharArray()).equals("parameter")){ //$NON-NLS-1$ if (String.valueOf(curParam.getDeclarator().getName().toCharArray()).equals("parameter")){ //$NON-NLS-1$
IASTPointerOperator pointer = curParam.getDeclarator().getPointerOperators()[0]; IASTPointerOperator pointer = curParam.getDeclarator().getPointerOperators()[0];
ASTModification modification = new ASTModification(ModificationKind.REPLACE, pointer, null, null); ASTModification modification = new ASTModification(ModificationKind.REPLACE,
pointer, null, null);
modStore.storeModification(null, modification); modStore.storeModification(null, modification);
} }
} }
} }
return PROCESS_CONTINUE; return PROCESS_CONTINUE;
} }

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.remove; package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.remove;
@ -16,13 +16,11 @@ import junit.framework.TestSuite;
/** /**
* @author Thomas Corbat * @author Thomas Corbat
*
*/ */
public class RemoveTestSuite{ public class RemoveTestSuite {
public static Test suite() throws Exception { public static Test suite() throws Exception {
TestSuite suite = new TestSuite("Changegenerator Remove Tests"); TestSuite suite = new TestSuite("ChangeGenerator Remove Tests");
suite.addTest(DeclarationTest.suite()); suite.addTest(DeclarationTest.suite());
suite.addTest(FirstParameterTest.suite()); suite.addTest(FirstParameterTest.suite());
suite.addTest(MiddleParameterTest.suite()); suite.addTest(MiddleParameterTest.suite());
@ -36,7 +34,6 @@ public class RemoveTestSuite{
suite.addTest(ArraySizeExpressionTest.suite()); suite.addTest(ArraySizeExpressionTest.suite());
suite.addTest(NewInitializerExpressionTest.suite()); suite.addTest(NewInitializerExpressionTest.suite());
suite.addTest(StatementTest.suite()); suite.addTest(StatementTest.suite());
return suite; return suite;
} }
} }

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.remove; package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.remove;
@ -24,25 +24,23 @@ import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKin
public class SingleParameterTest extends ChangeGeneratorTest { public class SingleParameterTest extends ChangeGeneratorTest {
public SingleParameterTest(){ public SingleParameterTest() {
super("Remove The Only Parameter Node"); //$NON-NLS-1$ super("Remove The Only Parameter Node"); //$NON-NLS-1$
} }
@Override @Override
protected void setUp() throws Exception { protected void setUp() throws Exception {
source = "void foo(int parameter){\n}\n\n"; //$NON-NLS-1$ source = "void foo(int parameter) {\n}\n\n"; //$NON-NLS-1$
expectedSource = "void foo(){\n}\n\n"; //$NON-NLS-1$ expectedSource = "void foo() {\n}\n\n"; //$NON-NLS-1$
super.setUp(); super.setUp();
} }
public static Test suite() { public static Test suite() {
return new SingleParameterTest(); return new SingleParameterTest();
} }
@Override @Override
protected ASTVisitor createModificator( protected ASTVisitor createModificator(final ASTModificationStore modStore) {
final ASTModificationStore modStore) {
return new ASTVisitor() { return new ASTVisitor() {
{ {
shouldVisitDeclarators = true; shouldVisitDeclarators = true;
@ -51,11 +49,12 @@ public class SingleParameterTest 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;
IASTParameterDeclaration[] parameters = functionDeclarator.getParameters(); IASTParameterDeclaration[] parameters = functionDeclarator.getParameters();
for(IASTParameterDeclaration curParam : parameters){ for (IASTParameterDeclaration curParam : parameters){
if(String.valueOf(curParam.getDeclarator().getName().toCharArray()).equals("parameter")){ //$NON-NLS-1$ if (String.valueOf(curParam.getDeclarator().getName().toCharArray()).equals("parameter")){ //$NON-NLS-1$
ASTModification modification = new ASTModification(ModificationKind.REPLACE, curParam, null, null); ASTModification modification = new ASTModification(ModificationKind.REPLACE,
curParam, null, null);
modStore.storeModification(null, modification); modStore.storeModification(null, modification);
} }
} }

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.replace; package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.replace;
@ -29,15 +29,14 @@ import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKin
public class ExceptionTest extends ChangeGeneratorTest { public class ExceptionTest extends ChangeGeneratorTest {
public ExceptionTest(){ public ExceptionTest(){
super("Remove Exception Declaration"); //$NON-NLS-1$ super("Remove Exception Declaration"); //$NON-NLS-1$
} }
@Override @Override
protected void setUp() throws Exception { protected void setUp() throws Exception {
source = "void foo(int parameter) throw (float){\n}\n\n"; //$NON-NLS-1$ source = "void foo(int parameter) throw (float) {\n}\n\n"; //$NON-NLS-1$
expectedSource = "void foo(int parameter) throw (int){\n}\n\n"; //$NON-NLS-1$ expectedSource = "void foo(int parameter) throw (int) {\n}\n\n"; //$NON-NLS-1$
super.setUp(); super.setUp();
} }
@ -46,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;
@ -56,7 +54,7 @@ public class ExceptionTest 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;
IASTTypeId existingException = functionDeclarator.getExceptionSpecification()[0]; IASTTypeId existingException = functionDeclarator.getExceptionSpecification()[0];
IASTTypeId exception = new CPPASTTypeId(); IASTTypeId exception = new CPPASTTypeId();
@ -66,13 +64,12 @@ public class ExceptionTest extends ChangeGeneratorTest {
exDeclSpec.setType(IASTSimpleDeclSpecifier.t_int); exDeclSpec.setType(IASTSimpleDeclSpecifier.t_int);
exception.setDeclSpecifier(exDeclSpec); exception.setDeclSpecifier(exDeclSpec);
exception.setAbstractDeclarator(exceptionDeclarator); exception.setAbstractDeclarator(exceptionDeclarator);
ASTModification modification = new ASTModification(ModificationKind.REPLACE, existingException, exception, null); ASTModification modification = new ASTModification(ModificationKind.REPLACE,
existingException, exception, null);
modStore.storeModification(null, modification); modStore.storeModification(null, modification);
} }
return PROCESS_CONTINUE; return PROCESS_CONTINUE;
} }
}; };
} }
} }

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.replace; package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.replace;
@ -25,20 +25,16 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName;
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification; import org.eclipse.cdt.internal.core.dom.rewrite.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(){ public ExpressionTest() {
super("Replace Expression"); //$NON-NLS-1$ super("Replace Expression"); //$NON-NLS-1$
} }
@Override @Override
protected void setUp() throws Exception { protected void setUp() throws Exception {
source = "void main(){int s = 0, c = 0, h = 0;\ns = 3, c = 4, h = 5;}"; //$NON-NLS-1$ source = "void main() {\n\tint s = 0, c = 0, h = 0;\n\ts = 3, c = 4, h = 5;\n}"; //$NON-NLS-1$
expectedSource = "void main(){int s = 0, c = 0, h = 0;\ns = 3, c = 9, h = 5;}"; //$NON-NLS-1$ expectedSource = "void main() {\n\tint s = 0, c = 0, h = 0;\n\ts = 3, c = 9, h = 5;\n}"; //$NON-NLS-1$
super.setUp(); super.setUp();
} }
@ -46,10 +42,8 @@ public class ExpressionTest extends ChangeGeneratorTest {
return new ExpressionTest(); return new ExpressionTest();
} }
@Override @Override
protected ASTVisitor createModificator( protected ASTVisitor createModificator(final ASTModificationStore modStore) {
final ASTModificationStore modStore) {
return new ASTVisitor() { return new ASTVisitor() {
{ {
shouldVisitExpressions = true; shouldVisitExpressions = true;
@ -60,8 +54,11 @@ public class ExpressionTest extends ChangeGeneratorTest {
if (expression instanceof IASTExpressionList) { if (expression instanceof IASTExpressionList) {
IASTExpressionList expressionList = (IASTExpressionList) expression; IASTExpressionList expressionList = (IASTExpressionList) expression;
IASTExpression[] expressions = expressionList.getExpressions(); IASTExpression[] expressions = expressionList.getExpressions();
CPPASTBinaryExpression binEx = new CPPASTBinaryExpression(IASTBinaryExpression.op_assign, new CPPASTIdExpression(new CPPASTName("c".toCharArray())), new CPPASTLiteralExpression(0, "9")); //$NON-NLS-1$ //$NON-NLS-2$ CPPASTBinaryExpression binEx = new CPPASTBinaryExpression(IASTBinaryExpression.op_assign,
ASTModification modification = new ASTModification(ASTModification.ModificationKind.REPLACE, expressions[1], binEx, null); new CPPASTIdExpression(new CPPASTName("c".toCharArray())), //$NON-NLS-1$
new CPPASTLiteralExpression(0, "9".toCharArray())); //$NON-NLS-1$
ASTModification modification = new ASTModification(ASTModification.ModificationKind.REPLACE,
expressions[1], binEx, null);
modStore.storeModification(null, modification); modStore.storeModification(null, modification);
} }
return PROCESS_CONTINUE; return PROCESS_CONTINUE;

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.replace; package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.replace;
@ -26,14 +26,14 @@ import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKin
public class PointerInParameterTest extends ChangeGeneratorTest { public class PointerInParameterTest extends ChangeGeneratorTest {
public PointerInParameterTest(){ public PointerInParameterTest() {
super("Replace Pointer for Parameter"); //$NON-NLS-1$ super("Replace Pointer for Parameter"); //$NON-NLS-1$
} }
@Override @Override
protected void setUp() throws Exception { protected void setUp() throws Exception {
source = "void foo(int &parameter){\n}\n\n"; //$NON-NLS-1$ source = "void foo(int &parameter) {\n}\n\n"; //$NON-NLS-1$
expectedSource = "void foo(int *parameter){\n}\n\n"; //$NON-NLS-1$ expectedSource = "void foo(int *parameter) {\n}\n\n"; //$NON-NLS-1$
super.setUp(); super.setUp();
} }
@ -42,8 +42,7 @@ public class PointerInParameterTest 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;
@ -52,10 +51,10 @@ public class PointerInParameterTest 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;
IASTParameterDeclaration[] parameters = functionDeclarator.getParameters(); IASTParameterDeclaration[] parameters = functionDeclarator.getParameters();
for(IASTParameterDeclaration curParam : parameters){ for (IASTParameterDeclaration curParam : parameters){
if(String.valueOf(curParam.getDeclarator().getName().toCharArray()).equals("parameter")){ //$NON-NLS-1$ if (String.valueOf(curParam.getDeclarator().getName().toCharArray()).equals("parameter")) { //$NON-NLS-1$
IASTPointerOperator pointer = curParam.getDeclarator().getPointerOperators()[0]; IASTPointerOperator pointer = curParam.getDeclarator().getPointerOperators()[0];
CPPASTPointer newPointer = new CPPASTPointer(); CPPASTPointer newPointer = new CPPASTPointer();
ASTModification modification = new ASTModification(ModificationKind.REPLACE, pointer, newPointer, null); ASTModification modification = new ASTModification(ModificationKind.REPLACE, pointer, newPointer, null);

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.replace; package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.replace;
@ -16,12 +16,11 @@ import junit.framework.TestSuite;
/** /**
* @author Thomas Corbat * @author Thomas Corbat
*
*/ */
public class ReplaceTestSuite{ public class ReplaceTestSuite {
public static Test suite() throws Exception { public static Test suite() throws Exception {
TestSuite suite = new TestSuite("ChangegeneratorReplaceTests"); TestSuite suite = new TestSuite("ChangeGeneratorReplaceTests");
suite.addTest(NameTest.suite()); suite.addTest(NameTest.suite());
suite.addTest(MoveTest.suite()); suite.addTest(MoveTest.suite());

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik * Copyright (c) 2008, 2011 Institute for Software, HSR Hochschule fuer Technik
* Rapperswil, University of applied sciences and others * Rapperswil, University of applied sciences and others
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
@ -11,9 +11,9 @@
******************************************************************************/ ******************************************************************************/
package org.eclipse.cdt.core.parser.tests.rewrite.comenthandler; package org.eclipse.cdt.core.parser.tests.rewrite.comenthandler;
import java.util.ArrayList;
import java.util.Comparator; import java.util.Comparator;
import java.util.HashMap; import java.util.List;
import java.util.Map;
import java.util.TreeSet; import java.util.TreeSet;
import java.util.Vector; import java.util.Vector;
import java.util.regex.Matcher; import java.util.regex.Matcher;
@ -140,12 +140,12 @@ public class CommentHandlingTest extends RewriteBaseTest {
return actualResultBuilder; return actualResultBuilder;
} }
private String getCommentMapResult(HashMap<IASTNode, ArrayList<IASTComment>> map) { private String getCommentMapResult(Map<IASTNode, List<IASTComment>> map) {
TreeSet<IASTNode> keyTree = new TreeSet<IASTNode>(new NodeOffsetComparator()); TreeSet<IASTNode> keyTree = new TreeSet<IASTNode>(new NodeOffsetComparator());
keyTree.addAll(map.keySet()); keyTree.addAll(map.keySet());
StringBuilder output = new StringBuilder(); StringBuilder output = new StringBuilder();
for (IASTNode actNode : keyTree) { for (IASTNode actNode : keyTree) {
ArrayList<IASTComment> comments = map.get(actNode); List<IASTComment> comments = map.get(actNode);
output.append(getSignature(actNode) + " = "); //$NON-NLS-1$ output.append(getSignature(actNode) + " = "); //$NON-NLS-1$
boolean first = true; boolean first = true;
for (IASTComment actComment : comments) { for (IASTComment actComment : comments) {

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2007, 2008 Wind River Systems, Inc. and others. * Copyright (c) 2007, 2011 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,6 +7,7 @@
* *
* Contributors: * Contributors:
* Markus Schorn - initial API and implementation * Markus Schorn - initial API and implementation
* Sergey Prigogin (Google)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.rewrite; package org.eclipse.cdt.internal.core.dom.rewrite;
@ -15,6 +16,7 @@ import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind; import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind;
@ -22,20 +24,18 @@ import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKin
/** /**
* Represents a list of modifications to an AST node. If there are nested modifications * Represents a list of modifications to an AST node. If there are nested modifications
* to nodes introduced by insertions or replacements, these modifications are collected * to nodes introduced by insertions or replacements, these modifications are collected
* in separate modification maps. I.e. a modification map represents one level of * in separate modification maps. I.e. a modification map represents one level of modifications.
* modifications.
* @see ASTModificationStore * @see ASTModificationStore
* @since 5.0 * @since 5.0
*/ */
public class ASTModificationMap { public class ASTModificationMap {
private HashMap<IASTNode, List<ASTModification>> fModifications= new HashMap<IASTNode, List<ASTModification>>(); private final Map<IASTNode, List<ASTModification>> fModifications= new HashMap<IASTNode, List<ASTModification>>();
/** /**
* Adds a modification to this modification map. * Adds a modification to this modification map.
*/ */
public void addModification(ASTModification mod) { public void addModification(ASTModification mod) {
final IASTNode targetNode = mod.getKind() == ASTModification.ModificationKind.INSERT_BEFORE ? IASTNode targetNode = mod.getTargetNode();
mod.getTargetNode().getParent() : mod.getTargetNode();
List<ASTModification> mods= fModifications.get(targetNode); List<ASTModification> mods= fModifications.get(targetNode);
if (mods == null || mods.isEmpty()) { if (mods == null || mods.isEmpty()) {
mods= new ArrayList<ASTModification>(); mods= new ArrayList<ASTModification>();

View file

@ -14,9 +14,13 @@ package org.eclipse.cdt.internal.core.dom.rewrite.astwriter;
import org.eclipse.cdt.core.dom.ast.IASTASMDeclaration; import org.eclipse.cdt.core.dom.ast.IASTASMDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement; import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition; import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.IASTIfStatement; 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.IASTPreprocessorIncludeStatement;
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.cpp.ICPPASTNamespaceDefinition; 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.ICPPASTTemplateDeclaration;
@ -34,7 +38,6 @@ import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap;
*/ */
public class ASTWriter { public class ASTWriter {
private ASTModificationStore modificationStore = new ASTModificationStore(); private ASTModificationStore modificationStore = new ASTModificationStore();
private String givenIndentation = ""; //$NON-NLS-1$
/** /**
* Creates a <code>ASTWriter</code>. * Creates a <code>ASTWriter</code>.
@ -43,16 +46,6 @@ public class ASTWriter {
super(); super();
} }
/**
* Creates a <code>ASTWriter</code> that indents the code.
*
* @param givenIndentation The indentation added to each line
*/
public ASTWriter(String givenIndentation) {
super();
this.givenIndentation = givenIndentation;
}
/** /**
* Generates the source code representing this node. * Generates the source code representing this node.
* *
@ -75,10 +68,9 @@ 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, NodeCommentMap commentMap) public String write(IASTNode rootNode, NodeCommentMap commentMap) throws ProblemRuntimeException {
throws ProblemRuntimeException {
ChangeGeneratorWriterVisitor writer = new ChangeGeneratorWriterVisitor( ChangeGeneratorWriterVisitor writer = new ChangeGeneratorWriterVisitor(
modificationStore, givenIndentation, null, commentMap); modificationStore, null, commentMap);
if (rootNode != null) { if (rootNode != null) {
rootNode.accept(writer); rootNode.accept(writer);
} }
@ -152,10 +144,35 @@ public class ASTWriter {
* @return <code>true</code> if the blank line between the nodes is needed. * @return <code>true</code> if the blank line between the nodes is needed.
*/ */
public static boolean requireBlankLineInBetween(IASTNode node1, IASTNode node2) { public static boolean requireBlankLineInBetween(IASTNode node1, IASTNode node2) {
if (requiresTrailingBlankLine(node1)) if (node1 instanceof ICPPASTVisibilityLabel && node2 instanceof ICPPASTVisibilityLabel) {
return true; return true;
}
if (suppressesTrailingBlankLine(node1)) {
return false;
}
if (node1 instanceof IASTPreprocessorIncludeStatement !=
node2 instanceof IASTPreprocessorIncludeStatement) {
return true;
}
if (isFunctionDeclaration(node1) != isFunctionDeclaration(node2)) {
return true;
}
if (requiresTrailingBlankLine(node1)) {
return true;
}
return !suppressesTrailingBlankLine(node1) && requiresLeadingBlankLine(node2); return requiresLeadingBlankLine(node2);
}
private static boolean isFunctionDeclaration(IASTNode node) {
if (!(node instanceof IASTSimpleDeclaration)) {
return false;
}
for (IASTDeclarator declarator : ((IASTSimpleDeclaration) node).getDeclarators()) {
if (declarator instanceof IASTFunctionDeclarator)
return true;
}
return false;
} }
/** /**

View file

@ -13,7 +13,7 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.rewrite.astwriter; package org.eclipse.cdt.internal.core.dom.rewrite.astwriter;
import java.util.ArrayList; import java.util.List;
import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTArrayModifier; import org.eclipse.cdt.core.dom.ast.IASTArrayModifier;
@ -29,6 +29,7 @@ import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTNodeLocation; import org.eclipse.cdt.core.dom.ast.IASTNodeLocation;
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.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;
@ -62,28 +63,25 @@ public class ASTWriterVisitor extends ASTVisitor {
private boolean spaceNeededBeforeName; private boolean spaceNeededBeforeName;
{ {
shouldVisitExpressions = true; shouldVisitArrayModifiers = true;
shouldVisitStatements = true;
shouldVisitNames = true;
shouldVisitDeclarations = true;
shouldVisitDeclSpecifiers = true;
shouldVisitDeclarators = true;
shouldVisitArrayModifiers= true;
shouldVisitInitializers = true;
shouldVisitBaseSpecifiers = true; shouldVisitBaseSpecifiers = true;
shouldVisitDeclarations = true;
shouldVisitDeclarators = true;
shouldVisitDeclSpecifiers = true;
shouldVisitExpressions = true;
shouldVisitInitializers = true;
shouldVisitNames = true;
shouldVisitNamespaces = true; shouldVisitNamespaces = true;
shouldVisitTemplateParameters = true;
shouldVisitParameterDeclarations = true; shouldVisitParameterDeclarations = true;
shouldVisitPointerOperators = true;
shouldVisitStatements = true;
shouldVisitTemplateParameters = true;
shouldVisitTranslationUnit = true; shouldVisitTranslationUnit = true;
shouldVisitTypeIds = true;
} }
public ASTWriterVisitor(NodeCommentMap commentMap) { public ASTWriterVisitor(NodeCommentMap commentMap) {
this("", commentMap); //$NON-NLS-1$
}
public ASTWriterVisitor(String givenIndentation, NodeCommentMap commentMap) {
super(); super();
scribe.setGivenIndentation(givenIndentation);
init(commentMap); init(commentMap);
this.commentMap = commentMap; this.commentMap = commentMap;
this.suppressLeadingBlankLine = true; this.suppressLeadingBlankLine = true;
@ -123,8 +121,8 @@ public class ASTWriterVisitor extends ASTVisitor {
} }
} }
private ArrayList<IASTComment> getLeadingComments(IASTNode node) { private List<IASTComment> getLeadingComments(IASTNode node) {
ArrayList<IASTComment> leadingComments = commentMap.getLeadingCommentsForNode(node); List<IASTComment> leadingComments = commentMap.getLeadingCommentsForNode(node);
IASTNodeLocation[] locs = node.getNodeLocations(); IASTNodeLocation[] locs = node.getNodeLocations();
if (locs != null && locs.length > 0 && locs[0] instanceof IASTCopyLocation) { if (locs != null && locs.length > 0 && locs[0] instanceof IASTCopyLocation) {
IASTCopyLocation copyLoc = (IASTCopyLocation) locs[0]; IASTCopyLocation copyLoc = (IASTCopyLocation) locs[0];
@ -240,6 +238,15 @@ public class ASTWriterVisitor extends ASTVisitor {
return ASTVisitor.PROCESS_SKIP; return ASTVisitor.PROCESS_SKIP;
} }
@Override
public int visit(IASTPointerOperator pointerOperator) {
writeLeadingComments(pointerOperator);
if (!macroHandler.checkisMacroExpansionNode(pointerOperator)) {
declaratorWriter.writePointerOperator(pointerOperator);
}
return ASTVisitor.PROCESS_SKIP;
}
protected IASTName getParameterName(IASTDeclarator declarator) { protected IASTName getParameterName(IASTDeclarator declarator) {
return declarator.getName(); return declarator.getName();
} }
@ -303,6 +310,10 @@ public class ASTWriterVisitor extends ASTVisitor {
this.spaceNeededBeforeName = value; this.spaceNeededBeforeName = value;
} }
public Scribe getScribe() {
return scribe;
}
public void newLine() { public void newLine() {
scribe.newLine(); scribe.newLine();
} }

View file

@ -267,7 +267,7 @@ public class DeclSpecWriter extends NodeWriter {
} }
if (hasFreestandingComments(compDeclSpec)) { if (hasFreestandingComments(compDeclSpec)) {
writeFreeStandingComments(compDeclSpec); writeFreestandingComments(compDeclSpec);
} }
scribe.decrementIndentationLevel(); scribe.decrementIndentationLevel();
scribe.print('}'); scribe.print('}');

View file

@ -98,17 +98,12 @@ public class DeclarationWriter extends NodeWriter {
writeVisibilityLabel((ICPPASTVisibilityLabel) declaration); writeVisibilityLabel((ICPPASTVisibilityLabel) declaration);
} }
if (hasTrailingComments(declaration)) { writeTrailingComments(declaration, addNewLine);
writeTrailingComments(declaration, false);
}
if (addNewLine) {
scribe.newLine();
}
if (hasFreestandingComments(declaration)) { if (hasFreestandingComments(declaration)) {
if (declaration instanceof IASTFunctionDefinition) { if (declaration instanceof IASTFunctionDefinition) {
scribe.newLine(); scribe.newLine();
} }
writeFreeStandingComments(declaration); writeFreestandingComments(declaration);
} }
} }
@ -186,7 +181,7 @@ public class DeclarationWriter extends NodeWriter {
scribe.newLine(2); scribe.newLine(2);
writeDeclarationsInNamespace(namespaceDefinition, namespaceDefinition.getDeclarations()); writeDeclarationsInNamespace(namespaceDefinition, namespaceDefinition.getDeclarations());
if (hasFreestandingComments(namespaceDefinition)) { if (hasFreestandingComments(namespaceDefinition)) {
writeFreeStandingComments(namespaceDefinition); writeFreestandingComments(namespaceDefinition);
} }
scribe.newLine(); scribe.newLine();
scribe.print('}'); scribe.print('}');

View file

@ -62,9 +62,7 @@ public class DeclaratorWriter extends NodeWriter {
} }
visitor.setSpaceNeededBeforeName(false); visitor.setSpaceNeededBeforeName(false);
if (hasTrailingComments(declarator)) { writeTrailingComments(declarator, false);
writeTrailingComments(declarator, false);
}
} }
protected void writeDefaultDeclarator(IASTDeclarator declarator) { protected void writeDefaultDeclarator(IASTDeclarator declarator) {
@ -81,7 +79,7 @@ public class DeclaratorWriter extends NodeWriter {
protected void writePointerOperators(IASTDeclarator declarator, IASTPointerOperator[] pointOps) { protected void writePointerOperators(IASTDeclarator declarator, IASTPointerOperator[] pointOps) {
for (IASTPointerOperator operator : pointOps) { for (IASTPointerOperator operator : pointOps) {
writePointerOp(operator); writePointerOperator(operator);
} }
} }
@ -194,7 +192,7 @@ public class DeclaratorWriter extends NodeWriter {
} }
} }
private void writePointerOp(IASTPointerOperator operator) { public void writePointerOperator(IASTPointerOperator operator) {
if (operator instanceof IASTPointer) { if (operator instanceof IASTPointer) {
IASTPointer pointOp = (IASTPointer) operator; IASTPointer pointOp = (IASTPointer) operator;
writePointer(pointOp); writePointer(pointOp);

View file

@ -51,8 +51,8 @@ public class InitializerWriter extends NodeWriter{
} else if (initializer instanceof ICPPASTConstructorChainInitializer) { } else if (initializer instanceof ICPPASTConstructorChainInitializer) {
writeConstructorChainInitializer((ICPPASTConstructorChainInitializer) initializer); writeConstructorChainInitializer((ICPPASTConstructorChainInitializer) initializer);
} }
if (hasTrailingComments(initializer))
writeTrailingComments(initializer, false); writeTrailingComments(initializer, false);
} }
private void writeEqualsInitializer(IASTEqualsInitializer initializer) { private void writeEqualsInitializer(IASTEqualsInitializer initializer) {

View file

@ -11,7 +11,7 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.rewrite.astwriter; package org.eclipse.cdt.internal.core.dom.rewrite.astwriter;
import java.util.ArrayList; import java.util.List;
import org.eclipse.cdt.core.dom.ast.IASTComment; import org.eclipse.cdt.core.dom.ast.IASTComment;
import org.eclipse.cdt.core.dom.ast.IASTCopyLocation; import org.eclipse.cdt.core.dom.ast.IASTCopyLocation;
@ -83,7 +83,7 @@ public class NodeWriter {
} }
protected void writeTrailingComments(IASTNode node) { protected void writeTrailingComments(IASTNode node) {
// Default is to write a new line after trailing comments. // Default is to write a new line after the trailing comments.
writeTrailingComments(node, true); writeTrailingComments(node, true);
} }
@ -106,8 +106,8 @@ public class NodeWriter {
return !getTrailingComments(node).isEmpty(); return !getTrailingComments(node).isEmpty();
} }
private ArrayList<IASTComment> getTrailingComments(IASTNode node) { private List<IASTComment> getTrailingComments(IASTNode node) {
ArrayList<IASTComment> trailingComments = commentMap.getTrailingCommentsForNode(node); List<IASTComment> trailingComments = commentMap.getTrailingCommentsForNode(node);
IASTNodeLocation[] locs = node.getNodeLocations(); IASTNodeLocation[] locs = node.getNodeLocations();
if (locs != null && locs.length > 0 && locs[0] instanceof IASTCopyLocation) { if (locs != null && locs.length > 0 && locs[0] instanceof IASTCopyLocation) {
IASTCopyLocation loc = (IASTCopyLocation) locs[0]; IASTCopyLocation loc = (IASTCopyLocation) locs[0];
@ -120,8 +120,8 @@ public class NodeWriter {
return !getFreestandingComments(node).isEmpty(); return !getFreestandingComments(node).isEmpty();
} }
private ArrayList<IASTComment> getFreestandingComments(IASTNode node) { private List<IASTComment> getFreestandingComments(IASTNode node) {
ArrayList<IASTComment> freestandingComments = commentMap.getFreestandingCommentsForNode(node); List<IASTComment> freestandingComments = commentMap.getFreestandingCommentsForNode(node);
IASTNodeLocation[] locs = node.getNodeLocations(); IASTNodeLocation[] locs = node.getNodeLocations();
if (locs != null && locs.length > 0 && locs[0] instanceof IASTCopyLocation) { if (locs != null && locs.length > 0 && locs[0] instanceof IASTCopyLocation) {
IASTCopyLocation loc = (IASTCopyLocation) locs[0]; IASTCopyLocation loc = (IASTCopyLocation) locs[0];
@ -130,7 +130,7 @@ public class NodeWriter {
return freestandingComments; return freestandingComments;
} }
protected void writeFreeStandingComments(IASTNode node) { protected void writeFreestandingComments(IASTNode node) {
for (IASTComment comment : getFreestandingComments(node)) { for (IASTComment comment : getFreestandingComments(node)) {
scribe.print(comment.getComment()); scribe.print(comment.getComment());
scribe.newLine(); scribe.newLine();

View file

@ -8,6 +8,7 @@
* *
* 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;
@ -19,42 +20,43 @@ package org.eclipse.cdt.internal.core.dom.rewrite.astwriter;
* @author Emanuel Graf IFS * @author Emanuel Graf IFS
*/ */
public class Scribe { public class Scribe {
private int indentationLevel = 0; // Indentation is not necessary since the code is going to be formatted anyway.
// Any positive indentation size is good enough since the code is going to be formatted anyway. // Preserved because some tests depend on it.
private int indentationSize = 4; private static final int INDENTATION_SIZE = 4;
private final String newLine = System.getProperty("line.separator"); //$NON-NLS-1$
private StringBuilder buffer = new StringBuilder(); private StringBuilder buffer = new StringBuilder();
private boolean isAtLineBeginning = true; private int indentationLevel = 0;
private String newLine = System.getProperty("line.separator"); //$NON-NLS-1$ private boolean isAtBeginningOfLine = true;
private String givenIndentation;
private boolean skipLineBreaks; private boolean skipLineBreaks;
private boolean skipSemicolons; private boolean skipSemicolons;
public String getLineSeparator() {
return newLine;
}
public void newLine() { public void newLine() {
if (!skipLineBreaks) { if (!skipLineBreaks) {
isAtLineBeginning = true; isAtBeginningOfLine = true;
buffer.append(getNewline()); buffer.append(newLine);
} }
} }
public boolean isAtBeginningOfLine() {
return isAtBeginningOfLine;
}
private void indent() { private void indent() {
if (givenIndentation != null) { printSpaces(indentationLevel * INDENTATION_SIZE);
buffer.append(givenIndentation);
}
printSpaces(indentationLevel * indentationSize);
} }
private void indentIfNewLine() { private void indentIfNewLine() {
if (isAtLineBeginning) { if (isAtBeginningOfLine) {
isAtLineBeginning = false; isAtBeginningOfLine = false;
indent(); indent();
} }
} }
private String getNewline() {
return newLine;
}
public void print(String code) { public void print(String code) {
indentIfNewLine(); indentIfNewLine();
buffer.append(code); buffer.append(code);
@ -171,14 +173,6 @@ public class Scribe {
buffer.append(' '); buffer.append(' ');
} }
public String getGivenIndentation() {
return givenIndentation;
}
public void setGivenIndentation(String givenIndentation) {
this.givenIndentation = givenIndentation;
}
public void cleanCache() { public void cleanCache() {
buffer = new StringBuilder(); buffer = new StringBuilder();
} }

View file

@ -154,11 +154,7 @@ public class StatementWriter extends NodeWriter {
throw new ProblemRuntimeException((IASTProblemStatement)statement); throw new ProblemRuntimeException((IASTProblemStatement)statement);
} }
if (hasTrailingComments(statement)) { writeTrailingComments(statement, newLine);
writeTrailingComments(statement, newLine);
} else if (newLine) {
scribe.newLine();
}
return ASTVisitor.PROCESS_SKIP; return ASTVisitor.PROCESS_SKIP;
} }
@ -389,7 +385,7 @@ public class StatementWriter extends NodeWriter {
} }
if (hasFreestandingComments(compoundStatement)) { if (hasFreestandingComments(compoundStatement)) {
writeFreeStandingComments(compoundStatement); writeFreestandingComments(compoundStatement);
} }
if (decrementIndentationLevelOneMore) { if (decrementIndentationLevelOneMore) {

View file

@ -15,8 +15,8 @@ import java.lang.reflect.Array;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import org.eclipse.cdt.core.dom.ast.IASTComment; import org.eclipse.cdt.core.dom.ast.IASTComment;
import org.eclipse.cdt.core.dom.ast.IASTDeclarator; import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
@ -100,29 +100,29 @@ public class ASTModificationHelper {
private void copyComments(IASTNode newNode, IASTNode oldNode, NodeCommentMap commentMap) { private void copyComments(IASTNode newNode, IASTNode oldNode, NodeCommentMap commentMap) {
// Attach all the comments that is attached to oldNode to newNode // Attach all the comments that is attached to oldNode to newNode
ArrayList<IASTComment> leadingComments = commentMap.getLeadingCommentsForNode(oldNode); List<IASTComment> leadingComments = commentMap.getLeadingCommentsForNode(oldNode);
for (IASTComment comment : leadingComments) { for (IASTComment comment : leadingComments) {
commentMap.addLeadingCommentToNode(newNode, comment); commentMap.addLeadingCommentToNode(newNode, comment);
} }
ArrayList<IASTComment> trailingComments = commentMap.getTrailingCommentsForNode(oldNode); List<IASTComment> trailingComments = commentMap.getTrailingCommentsForNode(oldNode);
for (IASTComment comment : trailingComments) { for (IASTComment comment : trailingComments) {
commentMap.addTrailingCommentToNode(newNode, comment); commentMap.addTrailingCommentToNode(newNode, comment);
} }
ArrayList<IASTComment> freestandingComments = commentMap.getFreestandingCommentsForNode(oldNode); List<IASTComment> freestandingComments = commentMap.getFreestandingCommentsForNode(oldNode);
for (IASTComment comment : freestandingComments) { for (IASTComment comment : freestandingComments) {
commentMap.addFreestandingCommentToNode(newNode, comment); commentMap.addFreestandingCommentToNode(newNode, comment);
} }
// Detach comments from oldNode (to avoid memory leak) // Detach comments from oldNode (to avoid memory leak)
HashMap<IASTNode, ArrayList<IASTComment>> leadingMap = commentMap.getLeadingMap(); Map<IASTNode, List<IASTComment>> leadingMap = commentMap.getLeadingMap();
leadingMap.remove(oldNode); leadingMap.remove(oldNode);
HashMap<IASTNode, ArrayList<IASTComment>> trailingMap = commentMap.getTrailingMap(); Map<IASTNode, List<IASTComment>> trailingMap = commentMap.getTrailingMap();
trailingMap.remove(oldNode); trailingMap.remove(oldNode);
HashMap<IASTNode, ArrayList<IASTComment>> freestandingMap = commentMap.getFreestandingMap(); Map<IASTNode, List<IASTComment>> freestandingMap = commentMap.getFreestandingMap();
freestandingMap.remove(oldNode); freestandingMap.remove(oldNode);
} }

View file

@ -23,6 +23,7 @@ import org.eclipse.cdt.core.dom.ast.IASTInitializer;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNode;
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.IASTProblem; import org.eclipse.cdt.core.dom.ast.IASTProblem;
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;
@ -43,7 +44,6 @@ import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap;
* @author Emanuel Graf IFS * @author Emanuel Graf IFS
*/ */
public class ChangeGeneratorWriterVisitor extends ASTWriterVisitor { public class ChangeGeneratorWriterVisitor extends ASTWriterVisitor {
private static final String DEFAULT_INDENTATION = ""; //$NON-NLS-1$
private final ASTModificationStore modificationStore; private final ASTModificationStore modificationStore;
private final String fileScope; private final String fileScope;
private ModificationScopeStack stack; private ModificationScopeStack stack;
@ -56,30 +56,31 @@ public class ChangeGeneratorWriterVisitor extends ASTWriterVisitor {
this.fileScope = fileScope; this.fileScope = fileScope;
this.stack = new ModificationScopeStack(modificationStore); this.stack = new ModificationScopeStack(modificationStore);
shouldVisitExpressions = delegateVisitor.shouldVisitExpressions;
shouldVisitStatements = delegateVisitor.shouldVisitStatements;
shouldVisitNames = delegateVisitor.shouldVisitNames;
shouldVisitDeclarations = delegateVisitor.shouldVisitDeclarators;
shouldVisitDeclSpecifiers = delegateVisitor.shouldVisitDeclSpecifiers;
shouldVisitDeclarators = delegateVisitor.shouldVisitDeclarators;
shouldVisitInitializers = delegateVisitor.shouldVisitInitializers;
shouldVisitBaseSpecifiers = delegateVisitor.shouldVisitBaseSpecifiers;
shouldVisitNamespaces = delegateVisitor.shouldVisitNamespaces;
shouldVisitTemplateParameters = delegateVisitor.shouldVisitTemplateParameters;
shouldVisitParameterDeclarations = delegateVisitor.shouldVisitParameterDeclarations;
shouldVisitTranslationUnit = delegateVisitor.shouldVisitTranslationUnit;
shouldVisitProblems = delegateVisitor.shouldVisitProblems;
shouldVisitTypeIds = delegateVisitor.shouldVisitTypeIds;
shouldVisitArrayModifiers= delegateVisitor.shouldVisitArrayModifiers; shouldVisitArrayModifiers= delegateVisitor.shouldVisitArrayModifiers;
shouldVisitBaseSpecifiers = delegateVisitor.shouldVisitBaseSpecifiers;
shouldVisitDeclarations = delegateVisitor.shouldVisitDeclarators;
shouldVisitDeclarators = delegateVisitor.shouldVisitDeclarators;
shouldVisitDeclSpecifiers = delegateVisitor.shouldVisitDeclSpecifiers;
shouldVisitExpressions = delegateVisitor.shouldVisitExpressions;
shouldVisitInitializers = delegateVisitor.shouldVisitInitializers;
shouldVisitNames = delegateVisitor.shouldVisitNames;
shouldVisitNamespaces = delegateVisitor.shouldVisitNamespaces;
shouldVisitParameterDeclarations = delegateVisitor.shouldVisitParameterDeclarations;
shouldVisitPointerOperators= delegateVisitor.shouldVisitPointerOperators;
shouldVisitProblems = delegateVisitor.shouldVisitProblems;
shouldVisitStatements = delegateVisitor.shouldVisitStatements;
shouldVisitTemplateParameters = delegateVisitor.shouldVisitTemplateParameters;
shouldVisitTranslationUnit = delegateVisitor.shouldVisitTranslationUnit;
shouldVisitTypeIds = delegateVisitor.shouldVisitTypeIds;
} }
public ChangeGeneratorWriterVisitor(ASTModificationStore modStore, NodeCommentMap nodeMap) { public ChangeGeneratorWriterVisitor(ASTModificationStore modStore, NodeCommentMap nodeMap) {
this(modStore, DEFAULT_INDENTATION, null, nodeMap); this(modStore, null, nodeMap);
} }
public ChangeGeneratorWriterVisitor(ASTModificationStore modStore, String givenIndentation, public ChangeGeneratorWriterVisitor(ASTModificationStore modStore, String fileScope,
String fileScope, NodeCommentMap commentMap) { NodeCommentMap commentMap) {
super(givenIndentation, commentMap); super(commentMap);
this.modificationStore = modStore; this.modificationStore = modStore;
this.fileScope = fileScope; this.fileScope = fileScope;
this.shouldVisitTranslationUnit = true; this.shouldVisitTranslationUnit = true;
@ -209,6 +210,12 @@ public class ChangeGeneratorWriterVisitor extends ASTWriterVisitor {
return PROCESS_SKIP; return PROCESS_SKIP;
} }
@Override
public int leave(IASTPointerOperator pointerOperator) {
super.leave(pointerOperator);
return PROCESS_SKIP;
}
@Override @Override
public int leave(IASTProblem problem) { public int leave(IASTProblem problem) {
super.leave(problem); super.leave(problem);
@ -305,6 +312,14 @@ public class ChangeGeneratorWriterVisitor extends ASTWriterVisitor {
return PROCESS_SKIP; return PROCESS_SKIP;
} }
@Override
public int visit(IASTPointerOperator pointerOperator) {
if (doBeforeEveryNode(pointerOperator) == PROCESS_CONTINUE) {
return super.visit(pointerOperator);
}
return PROCESS_SKIP;
}
@Override @Override
public int visit(IASTProblem problem) { public int visit(IASTProblem problem) {
if (doBeforeEveryNode(problem) == PROCESS_CONTINUE) { if (doBeforeEveryNode(problem) == PROCESS_CONTINUE) {
@ -369,10 +384,8 @@ public class ChangeGeneratorWriterVisitor extends ASTWriterVisitor {
stack.pushScope(node); stack.pushScope(node);
currentMod.getNewNode().accept(this); currentMod.getNewNode().accept(this);
stack.popScope(node); stack.popScope(node);
return PROCESS_SKIP;
} else {
return PROCESS_SKIP;
} }
return PROCESS_SKIP;
} }
} }
} }

View file

@ -13,6 +13,7 @@ package org.eclipse.cdt.internal.core.dom.rewrite.commenthandler;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List;
import java.util.TreeMap; import java.util.TreeMap;
import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.ASTVisitor;
@ -171,26 +172,25 @@ public class ASTCommenter {
* @return NodeCommentMap * @return NodeCommentMap
*/ */
public static NodeCommentMap getCommentedNodeMap(IASTTranslationUnit transUnit){ public static NodeCommentMap getCommentedNodeMap(IASTTranslationUnit transUnit){
if (transUnit== null) { if (transUnit == null) {
return new NodeCommentMap(); return new NodeCommentMap();
} }
ArrayList<IASTComment> comments = removeNotNeededComments(transUnit); List<IASTComment> comments = removeNotNeededComments(transUnit);
if (comments == null || comments.size() == 0) { if (comments == null || comments.isEmpty()) {
return new NodeCommentMap(); return new NodeCommentMap();
} }
return addCommentsToCommentMap(transUnit, comments); return addCommentsToCommentMap(transUnit, comments);
} }
private static ArrayList<IASTComment> removeNotNeededComments(IASTTranslationUnit transUnit) { private static List<IASTComment> removeNotNeededComments(IASTTranslationUnit transUnit) {
ArrayList<IASTComment> comments = getCommentsInWorkspace(transUnit); List<IASTComment> comments = getCommentsInWorkspace(transUnit);
if (comments == null || comments.size() == 0) { if (comments == null || comments.isEmpty()) {
return null; return null;
} }
ArrayList<IASTComment> com = removeAllPreprocessorComments(transUnit, comments); return removeAllPreprocessorComments(transUnit, comments);
return com;
} }
private static ArrayList<IASTComment> getCommentsInWorkspace(IASTTranslationUnit tu) { private static List<IASTComment> getCommentsInWorkspace(IASTTranslationUnit tu) {
IASTComment[] comments = tu.getComments(); IASTComment[] comments = tu.getComments();
ArrayList<IASTComment> commentsInWorkspace = new ArrayList<IASTComment>(); ArrayList<IASTComment> commentsInWorkspace = new ArrayList<IASTComment>();
@ -206,8 +206,8 @@ public class ASTCommenter {
return commentsInWorkspace; return commentsInWorkspace;
} }
private static ArrayList<IASTComment> removeAllPreprocessorComments(IASTTranslationUnit tu, private static List<IASTComment> removeAllPreprocessorComments(IASTTranslationUnit tu,
ArrayList<IASTComment> comments) { List<IASTComment> comments) {
IASTPreprocessorStatement[] preprocessorStatements = tu.getAllPreprocessorStatements(); IASTPreprocessorStatement[] preprocessorStatements = tu.getAllPreprocessorStatements();
TreeMap<Integer, String> treeOfPreProcessorLines = new TreeMap<Integer,String>(); TreeMap<Integer, String> treeOfPreProcessorLines = new TreeMap<Integer,String>();
TreeMap<String, ArrayList<Integer>> ppOffsetForFiles = new TreeMap<String, ArrayList<Integer>>(); TreeMap<String, ArrayList<Integer>> ppOffsetForFiles = new TreeMap<String, ArrayList<Integer>>();
@ -286,7 +286,7 @@ public class ASTCommenter {
} }
private static NodeCommentMap addCommentsToCommentMap(IASTTranslationUnit rootNode, private static NodeCommentMap addCommentsToCommentMap(IASTTranslationUnit rootNode,
ArrayList<IASTComment> comments){ List<IASTComment> comments){
NodeCommentMap commentMap = new NodeCommentMap(); NodeCommentMap commentMap = new NodeCommentMap();
CommentHandler commHandler = new CommentHandler(comments); CommentHandler commHandler = new CommentHandler(comments);
@ -296,8 +296,8 @@ public class ASTCommenter {
ASTCommenterVisitor commenter = new ASTCommenterVisitor(commHandler, commentMap); ASTCommenterVisitor commenter = new ASTCommenterVisitor(commHandler, commentMap);
declarations[i].accept(commenter); declarations[i].accept(commenter);
//add remaining comments to the last declaration => Comments won't get lost // Add the remaining comments to the last declaration to prevent comment loss.
if (i + 1 == declarations.length) { if (i == declarations.length - 1) {
commenter.addRemainingComments(declarations[i]); commenter.addRemainingComments(declarations[i]);
} }
} }

View file

@ -45,17 +45,18 @@ public class ASTCommenterVisitor extends ASTVisitor {
private NodeCommenter nodeCommenter; private NodeCommenter nodeCommenter;
{ {
shouldVisitExpressions = true;
shouldVisitStatements = true;
shouldVisitNames = true;
shouldVisitDeclarations = true;
shouldVisitDeclSpecifiers = true;
shouldVisitDeclarators = true;
shouldVisitInitializers = true;
shouldVisitBaseSpecifiers = true; shouldVisitBaseSpecifiers = true;
shouldVisitDeclarations = true;
shouldVisitDeclarators = true;
shouldVisitDeclSpecifiers = true;
shouldVisitExpressions = true;
shouldVisitInitializers = true;
shouldVisitNames = true;
shouldVisitNamespaces = true; shouldVisitNamespaces = true;
shouldVisitTemplateParameters = true;
shouldVisitParameterDeclarations = true; shouldVisitParameterDeclarations = true;
shouldVisitStatements = true;
shouldVisitTemplateParameters = true;
shouldVisitTypeIds = true;
} }
public ASTCommenterVisitor(CommentHandler commHandler, NodeCommentMap commentMap) { public ASTCommenterVisitor(CommentHandler commHandler, NodeCommentMap commentMap) {
@ -92,6 +93,11 @@ public class ASTCommenterVisitor extends ASTVisitor {
return nodeCommenter.appendComments((ASTNode) statement); return nodeCommenter.appendComments((ASTNode) statement);
} }
@Override
public int visit(IASTTypeId typeId) {
return nodeCommenter.appendComments((ASTNode) typeId);
}
@Override @Override
public int visit(IASTDeclaration declaration) { public int visit(IASTDeclaration declaration) {
return nodeCommenter.appendComments((ASTNode) declaration); return nodeCommenter.appendComments((ASTNode) declaration);

View file

@ -7,11 +7,11 @@
* 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.commenthandler; package org.eclipse.cdt.internal.core.dom.rewrite.commenthandler;
import java.util.ArrayList; import java.util.List;
import org.eclipse.cdt.core.dom.ast.IASTComment; import org.eclipse.cdt.core.dom.ast.IASTComment;
@ -23,10 +23,9 @@ import org.eclipse.cdt.core.dom.ast.IASTComment;
* @author Guido Zgraggen IFS * @author Guido Zgraggen IFS
*/ */
public class CommentHandler { public class CommentHandler {
private final List<IASTComment> comments;
private final ArrayList<IASTComment> comments; public CommentHandler(List<IASTComment> comments) {
public CommentHandler(ArrayList<IASTComment> comments) {
super(); super();
this.comments = comments; this.comments = comments;
} }
@ -36,7 +35,7 @@ public class CommentHandler {
} }
public boolean hasMore() { public boolean hasMore() {
return comments.size()>0; return !comments.isEmpty();
} }
public IASTComment getFirst() { public IASTComment getFirst() {

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik * Copyright (c) 2008, 2011 Institute for Software, HSR Hochschule fuer Technik
* Rapperswil, University of applied sciences and others * Rapperswil, University of applied sciences and others
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
@ -7,12 +7,14 @@
* http://www.eclipse.org/legal/epl-v10.html * 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.commenthandler; package org.eclipse.cdt.internal.core.dom.rewrite.commenthandler;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.eclipse.cdt.core.dom.ast.IASTComment; import org.eclipse.cdt.core.dom.ast.IASTComment;
import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNode;
@ -25,18 +27,18 @@ import org.eclipse.cdt.core.dom.ast.IASTNode;
* @author Guido Zgraggen IFS * @author Guido Zgraggen IFS
*/ */
public class NodeCommentMap { public class NodeCommentMap {
protected final HashMap<IASTNode, ArrayList<IASTComment>> leadingMap = new HashMap<IASTNode, ArrayList<IASTComment>>(); protected final Map<IASTNode, List<IASTComment>> leadingMap = new HashMap<IASTNode, List<IASTComment>>();
protected final HashMap<IASTNode, ArrayList<IASTComment>> trailingMap = new HashMap<IASTNode, ArrayList<IASTComment>>(); protected final Map<IASTNode, List<IASTComment>> trailingMap = new HashMap<IASTNode, List<IASTComment>>();
protected final HashMap<IASTNode, ArrayList<IASTComment>> freestandingMap = new HashMap<IASTNode, ArrayList<IASTComment>>(); protected final Map<IASTNode, List<IASTComment>> freestandingMap = new HashMap<IASTNode, List<IASTComment>>();
/** /**
* Add a comment to the map with the trailing comments. * Add a comment to the map with the trailing comments.
* @param node The node is the key. * @param node The node is the key.
* @param comment The comment is the value * @param comment The comment is the value
*/ */
public void addTrailingCommentToNode(IASTNode node, IASTComment comment){ public void addTrailingCommentToNode(IASTNode node, IASTComment comment) {
ArrayList<IASTComment> comments = trailingMap.get(node); List<IASTComment> comments = trailingMap.get(node);
if(comments == null){ if (comments == null) {
comments = new ArrayList<IASTComment>(); comments = new ArrayList<IASTComment>();
} }
comments.add(comment); comments.add(comment);
@ -44,17 +46,15 @@ public class NodeCommentMap {
} }
/** /**
* Returns an ArrayList for the given node. This ArrayList contains all the comments * Returns a List for the given node. This List contains all the comments
* which are assigned to this specific node. If no comments are available an empty * which are assigned to this specific node. If no comments are available an empty
* ArrayList is returned. * List is returned.
* @param node The key to fetch the associated comments. * @param node The key to fetch the associated comments.
* @return ArrayList * @return List
*/ */
public ArrayList<IASTComment> getTrailingCommentsForNode(IASTNode node){ public List<IASTComment> getTrailingCommentsForNode(IASTNode node) {
if(trailingMap.get(node) == null) { List<IASTComment> list = trailingMap.get(node);
return new ArrayList<IASTComment>(); return list != null ? list : new ArrayList<IASTComment>();
}
return trailingMap.get(node);
} }
/** /**
@ -62,9 +62,9 @@ public class NodeCommentMap {
* @param node The node is the key. * @param node The node is the key.
* @param comment The comment is the value * @param comment The comment is the value
*/ */
public void addLeadingCommentToNode(IASTNode node, IASTComment comment){ public void addLeadingCommentToNode(IASTNode node, IASTComment comment) {
ArrayList<IASTComment> comments = leadingMap.get(node); List<IASTComment> comments = leadingMap.get(node);
if(comments == null){ if (comments == null) {
comments = new ArrayList<IASTComment>(); comments = new ArrayList<IASTComment>();
} }
comments.add(comment); comments.add(comment);
@ -72,17 +72,15 @@ public class NodeCommentMap {
} }
/** /**
* Returns an ArrayList for the given node. This ArrayList contains all the comments * Returns a List for the given node. This List contains all the comments
* which are assigned to this specific node. If no comments are available an empty * which are assigned to this specific node. If no comments are available an empty
* ArrayList is returned. * List is returned.
* @param node The key to fetch the associated comments. * @param node The key to fetch the associated comments.
* @return ArrayList * @return List
*/ */
public ArrayList<IASTComment> getLeadingCommentsForNode(IASTNode node){ public List<IASTComment> getLeadingCommentsForNode(IASTNode node) {
if(leadingMap.get(node) == null) { List<IASTComment> list = leadingMap.get(node);
return new ArrayList<IASTComment>(); return list != null ? list : new ArrayList<IASTComment>();
}
return leadingMap.get(node);
} }
/** /**
@ -90,9 +88,9 @@ public class NodeCommentMap {
* @param node The node is the key. * @param node The node is the key.
* @param comment The comment is the value * @param comment The comment is the value
*/ */
public void addFreestandingCommentToNode(IASTNode node, IASTComment comment){ public void addFreestandingCommentToNode(IASTNode node, IASTComment comment) {
ArrayList<IASTComment> comments = freestandingMap.get(node); List<IASTComment> comments = freestandingMap.get(node);
if(comments == null){ if (comments == null) {
comments = new ArrayList<IASTComment>(); comments = new ArrayList<IASTComment>();
} }
comments.add(comment); comments.add(comment);
@ -100,51 +98,50 @@ public class NodeCommentMap {
} }
/** /**
* Returns an ArrayList for the given node. This ArrayList contains all the comments * Returns a List for the given node. This List contains all the comments
* which are assigned to this specific node. If no comments are available an empty * which are assigned to this specific node. If no comments are available an empty
* ArrayList is returned. * List is returned.
* @param node The key to fetch the associated comments. * @param node The key to fetch the associated comments.
* @return ArrayList * @return List
*/ */
public ArrayList<IASTComment> getFreestandingCommentsForNode(IASTNode node){ public List<IASTComment> getFreestandingCommentsForNode(IASTNode node) {
if(freestandingMap.get(node) == null) { List<IASTComment> list = freestandingMap.get(node);
return new ArrayList<IASTComment>(); return list != null ? list : new ArrayList<IASTComment>();
}
return freestandingMap.get(node);
} }
/** /**
* Returns the HashMap with all leading maps. Used only for test purpose * Returns the Map with all leading maps. Used only for test purpose
* @return HashMap of all leading comments * @return Map of all leading comments
*/ */
public HashMap<IASTNode, ArrayList<IASTComment>> getLeadingMap() { public Map<IASTNode, List<IASTComment>> getLeadingMap() {
return leadingMap; return leadingMap;
} }
/** /**
* Returns the HashMap with all trailing maps. Used only for test purpose * Returns the Map with all trailing maps. Used only for test purpose
* @return HashMap of all trailing comments * @return Map of all trailing comments
*/ */
public HashMap<IASTNode, ArrayList<IASTComment>> getTrailingMap() { public Map<IASTNode, List<IASTComment>> getTrailingMap() {
return trailingMap; return trailingMap;
} }
/** /**
* Returns the HashMap with all freestanding maps. Used only for test purpose * Returns the Map with all freestanding maps. Used only for test purpose
* @return HashMap of all freestanding comments * @return Map of all freestanding comments
*/ */
public HashMap<IASTNode, ArrayList<IASTComment>> getFreestandingMap() { public Map<IASTNode, List<IASTComment>> getFreestandingMap() {
return freestandingMap; return freestandingMap;
} }
/** /**
* Returns an ArrayList for the given node. This ArrayList contains all the comments * Returns an List for the given node. This List contains all the comments
* which are assigned to this specific node. If no comments are available an empty * which are assigned to this specific node. If no comments are available an empty
* ArrayList is returned. * List is returned.
* @param node The key to fetch the associated comments. * @param node The key to fetch the associated comments.
* @return ArrayList * @return List
*/ */
public ArrayList<IASTComment> getAllCommentsForNode(IASTNode node) { public List<IASTComment> getAllCommentsForNode(IASTNode node) {
ArrayList<IASTComment> comment = new ArrayList<IASTComment>(); List<IASTComment> comment = new ArrayList<IASTComment>();
comment.addAll(getFreestandingCommentsForNode(node)); comment.addAll(getFreestandingCommentsForNode(node));
comment.addAll(getLeadingCommentsForNode(node)); comment.addAll(getLeadingCommentsForNode(node));
comment.addAll(getTrailingCommentsForNode(node)); comment.addAll(getTrailingCommentsForNode(node));

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.commenthandler; package org.eclipse.cdt.internal.core.dom.rewrite.commenthandler;
@ -39,25 +39,27 @@ import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Path;
/** /**
* The NodeCommenter contains all the logic that is needed for the ASTCommentVisitor to assign the comments * The NodeCommenter contains all the logic that is needed for the ASTCommentVisitor to assign
* to the suitable node. Together with the ASTCommenterVisitor it fills all the comments with the correspondent * the comments to the suitable node. Together with the ASTCommenterVisitor it fills all
* node into the NodeCommentMap. * the comments with the correspondent node into the NodeCommentMap.
* *
* Following, a little explanation of the assignment logic. It is only a loose illustration a detailed description * Following, a little explanation of the assignment logic. It is only a loose illustration
* would include a combined explanation of ASTCommenterVisitor and NodeCommenter.<br> * a detailed description would include a combined explanation of ASTCommenterVisitor and
* NodeCommenter.<br>
* To understand the logic we define the three types of comments:<br> * To understand the logic we define the three types of comments:<br>
* leading comments - Comments before a statement, declaration, or definition.<br> * leading comments - Comments before a statement, declaration, or definition.<br>
* trailing comments - Comments right after the AST node on the same line.<br> * trailing comments - Comments right after the AST node on the same line.<br>
* freestanding comments - Comments before a closing brace such as they occur in * freestanding comments - Comments before a closing brace such as they occur in
* namespace-, class- and method-definitions or at the end of a file.<br> * namespace-, class- and method-definitions or at the end of a file.<br>
* *
* The first comment is fetched and the position of it is compared to the position of the actual node. If * The first comment is fetched and the position of it is compared to the position of the actual
* the position of the comment is smaller than the comment is added to the node as leading. If it is behind the node * node. If the position of the comment is smaller than the comment is added to the node as leading.
* but on the same line it is added as trailing. If one of these possibilities match the next comment is fetched for * If it is behind the node but on the same line it is added as trailing. If one of these
* the same check. If it doesn't match the same procedure is done for all the child nodes. After checking the sub nodes * possibilities match the next comment is fetched for the same check. If it doesn't match the same
* the actual node is checked again if the comment is trailing. Then there is also the possibility that this comment is * procedure is done for all the child nodes. After checking the sub nodes the actual node is
* freestanding. This is the case when the comment is not added to any child node but the position is smaller den * checked again if the comment is trailing. Then there is also the possibility that this comment is
* the end position of the node. * freestanding. This is the case when the comment is not added to any child node but the position
* is smaller than the end position of the node.
* *
* @author Guido Zgraggen IFS * @author Guido Zgraggen IFS
*/ */
@ -90,7 +92,7 @@ public class NodeCommenter {
ASTNode com = (ASTNode) comment; ASTNode com = (ASTNode) comment;
if (node.getFileLocation() == null) { if (node.getFileLocation() == null) {
//MacroExpansions have no FileLocation // MacroExpansions have no FileLocation
return false; return false;
} }
@ -111,7 +113,7 @@ public class NodeCommenter {
ASTNode com = (ASTNode) comment; ASTNode com = (ASTNode) comment;
if (node.getFileLocation() == null) { if (node.getFileLocation() == null) {
//MacroExpansions have no Filelocation // MacroExpansions have no FileLocation
return false; return false;
} }
if (OffsetHelper.getNodeEndPoint(com) <= OffsetHelper.getNodeEndPoint(node)) { if (OffsetHelper.getNodeEndPoint(com) <= OffsetHelper.getNodeEndPoint(node)) {
@ -151,7 +153,7 @@ public class NodeCommenter {
try { try {
InputStream is = file.getContents(); InputStream is = file.getContents();
int length = OffsetHelper.getNodeOffset(com)-OffsetHelper.getNodeEndPoint(node); int length = OffsetHelper.getNodeOffset(com) - OffsetHelper.getNodeEndPoint(node);
byte[] b = new byte[length]; byte[] b = new byte[length];
long count = is.skip(OffsetHelper.getEndOffsetWithoutComments(node)); long count = is.skip(OffsetHelper.getEndOffsetWithoutComments(node));

View file

@ -9,7 +9,6 @@
* QNX Software Systems - Initial API and implementation * QNX Software Systems - Initial API and implementation
* Anton Leherbauer (Wind River Systems) * Anton Leherbauer (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.core; package org.eclipse.cdt.core;
import java.util.Map; import java.util.Map;
@ -49,19 +48,19 @@ public class ToolFactory {
IExtensionPoint extension = Platform.getExtensionRegistry().getExtensionPoint(CCorePlugin.PLUGIN_ID, extID); IExtensionPoint extension = Platform.getExtensionRegistry().getExtensionPoint(CCorePlugin.PLUGIN_ID, extID);
if (extension != null) { if (extension != null) {
IExtension[] extensions = extension.getExtensions(); IExtension[] extensions = extension.getExtensions();
for(int i = 0; i < extensions.length; i++){ for (int i = 0; i < extensions.length; i++){
IConfigurationElement [] configElements = extensions[i].getConfigurationElements(); IConfigurationElement [] configElements = extensions[i].getConfigurationElements();
for(int j = 0; j < configElements.length; j++){ for (int j = 0; j < configElements.length; j++){
String initializerID = configElements[j].getAttribute("id"); //$NON-NLS-1$ String initializerID = configElements[j].getAttribute("id"); //$NON-NLS-1$
if (initializerID != null && initializerID.equals(formatterID)){ if (initializerID != null && initializerID.equals(formatterID)){
try { try {
Object execExt = configElements[j].createExecutableExtension("class"); //$NON-NLS-1$ Object execExt = configElements[j].createExecutableExtension("class"); //$NON-NLS-1$
if (execExt instanceof CodeFormatter){ if (execExt instanceof CodeFormatter){
CodeFormatter formatter = (CodeFormatter)execExt; CodeFormatter formatter = (CodeFormatter) execExt;
formatter.setOptions(options); formatter.setOptions(options);
return formatter; return formatter;
} }
} catch(CoreException e) { } catch (CoreException e) {
CCorePlugin.log(e.getStatus()); CCorePlugin.log(e.getStatus());
break; break;
} }

View file

@ -530,6 +530,7 @@ public class DefaultCodeFormatterConstants {
* @since 5.3 * @since 5.3
*/ */
public final static String FORMATTER_COMMENT_MIN_DISTANCE_BETWEEN_CODE_AND_LINE_COMMENT = CCorePlugin.PLUGIN_ID + ".formatter.comment.min_distance_between_code_and_line_comment"; //$NON-NLS-1$ public final static String FORMATTER_COMMENT_MIN_DISTANCE_BETWEEN_CODE_AND_LINE_COMMENT = CCorePlugin.PLUGIN_ID + ".formatter.comment.min_distance_between_code_and_line_comment"; //$NON-NLS-1$
/** /**
* <pre> * <pre>
* FORMATTER / Option to control whether the white space between code and line comments should be preserved or replaced with a single space * FORMATTER / Option to control whether the white space between code and line comments should be preserved or replaced with a single space
@ -541,9 +542,21 @@ public class DefaultCodeFormatterConstants {
* @see #FALSE * @see #FALSE
* @since 5.3 * @since 5.3
*/ */
public final static String FORMATTER_COMMENT_PRESERVE_WHITE_SPACE_BETWEEN_CODE_AND_LINE_COMMENT = CCorePlugin.PLUGIN_ID + ".formatter.comment.preserve_white_space_between_code_and_line_comments"; //$NON-NLS-1$ public final static String FORMATTER_COMMENT_PRESERVE_WHITE_SPACE_BETWEEN_CODE_AND_LINE_COMMENT = CCorePlugin.PLUGIN_ID + ".formatter.comment.preserve_white_space_between_code_and_line_comments"; //$NON-NLS-1$
/**
* <pre>
* FORMATTER / Option to control whether comments starting from the beginning of line should stay that way and never be indented.
* - option id: "org.eclipse.cdt.core.formatter.comment.never_indent_line_comments_on_first_column"
* - possible values: { TRUE, FALSE }
* - default: TRUE
* </pre>
* @see #TRUE
* @see #FALSE
* @since 5.4
*/
public final static String FORMATTER_COMMENT_NEVER_INDENT_LINE_COMMENTS_ON_FIRST_COLUMN = CCorePlugin.PLUGIN_ID + ".formatter.comment.never_indent_line_comments_on_first_column"; //$NON-NLS-1$
/** /**
* <pre> * <pre>
* FORMATTER / Option to compact else/if * FORMATTER / Option to compact else/if

View file

@ -100,7 +100,7 @@ public class DefaultCodeFormatterOptions {
// public int comment_line_length; // public int comment_line_length;
public int comment_min_distance_between_code_and_line_comment; public int comment_min_distance_between_code_and_line_comment;
public boolean comment_preserve_white_space_between_code_and_line_comment; public boolean comment_preserve_white_space_between_code_and_line_comment;
public boolean never_indent_line_comments_on_first_column = true; public boolean never_indent_line_comments_on_first_column;
public int continuation_indentation; public int continuation_indentation;
public int continuation_indentation_for_initializer_list; public int continuation_indentation_for_initializer_list;
@ -314,6 +314,7 @@ public class DefaultCodeFormatterOptions {
// options.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_LINE_LENGTH, Integer.toString(this.comment_line_length)); // options.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_LINE_LENGTH, Integer.toString(this.comment_line_length));
options.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_MIN_DISTANCE_BETWEEN_CODE_AND_LINE_COMMENT, Integer.toString(this.comment_min_distance_between_code_and_line_comment)); options.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_MIN_DISTANCE_BETWEEN_CODE_AND_LINE_COMMENT, Integer.toString(this.comment_min_distance_between_code_and_line_comment));
options.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_PRESERVE_WHITE_SPACE_BETWEEN_CODE_AND_LINE_COMMENT, this.comment_preserve_white_space_between_code_and_line_comment ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE); options.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_PRESERVE_WHITE_SPACE_BETWEEN_CODE_AND_LINE_COMMENT, this.comment_preserve_white_space_between_code_and_line_comment ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE);
options.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_NEVER_INDENT_LINE_COMMENTS_ON_FIRST_COLUMN, this.never_indent_line_comments_on_first_column ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE);
options.put(DefaultCodeFormatterConstants.FORMATTER_CONTINUATION_INDENTATION, Integer.toString(this.continuation_indentation)); options.put(DefaultCodeFormatterConstants.FORMATTER_CONTINUATION_INDENTATION, Integer.toString(this.continuation_indentation));
options.put(DefaultCodeFormatterConstants.FORMATTER_CONTINUATION_INDENTATION_FOR_INITIALIZER_LIST, Integer.toString(this.continuation_indentation_for_initializer_list)); options.put(DefaultCodeFormatterConstants.FORMATTER_CONTINUATION_INDENTATION_FOR_INITIALIZER_LIST, Integer.toString(this.continuation_indentation_for_initializer_list));
options.put(DefaultCodeFormatterConstants.FORMATTER_INDENT_STATEMENTS_COMPARE_TO_BLOCK, this.indent_statements_compare_to_block ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE); options.put(DefaultCodeFormatterConstants.FORMATTER_INDENT_STATEMENTS_COMPARE_TO_BLOCK, this.indent_statements_compare_to_block ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE);
@ -847,6 +848,10 @@ public class DefaultCodeFormatterOptions {
if (commentPreserveWhiteSpaceBetweenCodeAndLineCommentOption != null) { if (commentPreserveWhiteSpaceBetweenCodeAndLineCommentOption != null) {
this.comment_preserve_white_space_between_code_and_line_comment = DefaultCodeFormatterConstants.TRUE.equals(commentPreserveWhiteSpaceBetweenCodeAndLineCommentOption); this.comment_preserve_white_space_between_code_and_line_comment = DefaultCodeFormatterConstants.TRUE.equals(commentPreserveWhiteSpaceBetweenCodeAndLineCommentOption);
} }
final Object neverIndentLineCommentsOnFirstColumn = settings.get(DefaultCodeFormatterConstants.FORMATTER_COMMENT_NEVER_INDENT_LINE_COMMENTS_ON_FIRST_COLUMN);
if (neverIndentLineCommentsOnFirstColumn != null) {
this.never_indent_line_comments_on_first_column = DefaultCodeFormatterConstants.TRUE.equals(neverIndentLineCommentsOnFirstColumn);
}
final Object continuationIndentationOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_CONTINUATION_INDENTATION); final Object continuationIndentationOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_CONTINUATION_INDENTATION);
if (continuationIndentationOption != null) { if (continuationIndentationOption != null) {
try { try {
@ -1525,7 +1530,8 @@ public class DefaultCodeFormatterOptions {
this.brace_position_for_switch = DefaultCodeFormatterConstants.END_OF_LINE; this.brace_position_for_switch = DefaultCodeFormatterConstants.END_OF_LINE;
this.brace_position_for_type_declaration = DefaultCodeFormatterConstants.END_OF_LINE; this.brace_position_for_type_declaration = DefaultCodeFormatterConstants.END_OF_LINE;
this.comment_min_distance_between_code_and_line_comment = 1; this.comment_min_distance_between_code_and_line_comment = 1;
this.comment_preserve_white_space_between_code_and_line_comment = false; this.comment_preserve_white_space_between_code_and_line_comment = true;
this.never_indent_line_comments_on_first_column = true;
// this.comment_clear_blank_lines = false; // this.comment_clear_blank_lines = false;
// this.comment_format = true; // this.comment_format = true;
// this.comment_format_header = false; // this.comment_format_header = false;

View file

@ -13,8 +13,6 @@ public:
}; };
#endif /*A_H_*/ #endif /*A_H_*/
//= //=
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
@ -25,12 +23,11 @@ public:
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_*/
//@A.cpp //@A.cpp
#include "A.h" #include "A.h"
@ -48,7 +45,6 @@ void A::bar() {
int a = 42; int a = 42;
int b = 42; int b = 42;
} }
//= //=
#include "A.h" #include "A.h"
@ -66,7 +62,6 @@ void A::bar() {
int a = theAnswer; int a = theAnswer;
int b = theAnswer; int b = theAnswer;
} }
//!ExtractConstantInt 2 //!ExtractConstantInt 2
//#org.eclipse.cdt.ui.tests.refactoring.extractconstant.ExtractConstantRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.extractconstant.ExtractConstantRefactoringTest
//@A.h //@A.h
@ -82,8 +77,6 @@ public:
}; };
#endif /*A_H_*/ #endif /*A_H_*/
//= //=
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
@ -94,12 +87,11 @@ public:
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_*/
//@A.cpp //@A.cpp
#include "A.h" #include "A.h"
@ -118,7 +110,6 @@ void A::bar() {
int a = 42; int a = 42;
int b = 42; int b = 42;
} }
//= //=
#include "A.h" #include "A.h"
@ -137,7 +128,6 @@ void A::bar() {
int a = theAnswer; int a = theAnswer;
int b = theAnswer; int b = theAnswer;
} }
//!ExtractConstantFloat //!ExtractConstantFloat
//#org.eclipse.cdt.ui.tests.refactoring.extractconstant.ExtractConstantRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.extractconstant.ExtractConstantRefactoringTest
//@A.h //@A.h
@ -153,8 +143,6 @@ public:
}; };
#endif /*A_H_*/ #endif /*A_H_*/
//= //=
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
@ -165,12 +153,11 @@ public:
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_*/
//@A.cpp //@A.cpp
#include "A.h" #include "A.h"
@ -188,7 +175,6 @@ void A::bar() {
float a = 42.0f; float a = 42.0f;
float b = 42.0f; float b = 42.0f;
} }
//= //=
#include "A.h" #include "A.h"
@ -206,7 +192,6 @@ void A::bar() {
float a = theAnswer; float a = theAnswer;
float b = theAnswer; float b = theAnswer;
} }
//!ExtractConstantDouble //!ExtractConstantDouble
//#org.eclipse.cdt.ui.tests.refactoring.extractconstant.ExtractConstantRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.extractconstant.ExtractConstantRefactoringTest
//@A.h //@A.h
@ -222,8 +207,6 @@ public:
}; };
#endif /*A_H_*/ #endif /*A_H_*/
//= //=
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
@ -234,12 +217,11 @@ public:
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_*/
//@A.cpp //@A.cpp
#include "A.h" #include "A.h"
@ -257,7 +239,6 @@ void A::bar() {
double a = 42.0; double a = 42.0;
double b = 42.0; double b = 42.0;
} }
//= //=
#include "A.h" #include "A.h"
@ -275,7 +256,6 @@ void A::bar() {
double a = theAnswer; double a = theAnswer;
double b = theAnswer; double b = theAnswer;
} }
//!ExtractConstantStaticInt //!ExtractConstantStaticInt
//#org.eclipse.cdt.ui.tests.refactoring.extractconstant.ExtractConstantRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.extractconstant.ExtractConstantRefactoringTest
//@A.h //@A.h
@ -291,7 +271,6 @@ public:
}; };
#endif /*A_H_*/ #endif /*A_H_*/
//= //=
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
@ -305,7 +284,6 @@ public:
}; };
#endif /*A_H_*/ #endif /*A_H_*/
//@A.cpp //@A.cpp
#include "A.h" #include "A.h"
@ -322,7 +300,6 @@ int A::foo() {
int bar() { int bar() {
return /*$*/42/*$$*/; return /*$*/42/*$$*/;
} }
//= //=
#include "A.h" #include "A.h"
@ -345,7 +322,6 @@ int A::foo() {
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

View file

@ -13,7 +13,6 @@ public:
}; };
#endif /*A_H_*/ #endif /*A_H_*/
//= //=
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
@ -24,11 +23,11 @@ public:
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_*/
//@A.cpp //@A.cpp
#include "A.h" #include "A.h"
@ -46,7 +45,6 @@ void A::bar() {
int a = 42; int a = 42;
int b = 42; int b = 42;
} }
//= //=
#include "A.h" #include "A.h"
@ -64,7 +62,6 @@ void A::bar() {
int a = theAnswer; int a = theAnswer;
int b = theAnswer; int b = theAnswer;
} }
//@refScript.xml //@refScript.xml
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<session version="1.0"> <session version="1.0">
@ -89,7 +86,6 @@ public:
}; };
#endif /*A_H_*/ #endif /*A_H_*/
//= //=
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
@ -105,7 +101,6 @@ protected:
}; };
#endif /*A_H_*/ #endif /*A_H_*/
//@A.cpp //@A.cpp
#include "A.h" #include "A.h"
@ -118,7 +113,6 @@ A::~A() {
int A::foo() { int A::foo() {
return 42; return 42;
} }
//= //=
#include "A.h" #include "A.h"
@ -131,7 +125,6 @@ A::~A() {
int A::foo() { int A::foo() {
return theAnswer; return theAnswer;
} }
//@refScript.xml //@refScript.xml
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<session version="1.0"> <session version="1.0">
@ -155,7 +148,6 @@ public:
}; };
#endif /*A_H_*/ #endif /*A_H_*/
//= //=
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
@ -171,7 +163,6 @@ private:
}; };
#endif /*A_H_*/ #endif /*A_H_*/
//@A.cpp //@A.cpp
#include "A.h" #include "A.h"
@ -184,7 +175,6 @@ A::~A() {
int A::foo() { int A::foo() {
return 42; return 42;
} }
//= //=
#include "A.h" #include "A.h"
@ -197,7 +187,6 @@ A::~A() {
int A::foo() { int A::foo() {
return theAnswer; return theAnswer;
} }
//@refScript.xml //@refScript.xml
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<session version="1.0"> <session version="1.0">

View file

@ -296,7 +296,7 @@ class Klass {
void set(bool b) { void set(bool b) {
} }
void test() { void test() {
other o; other o;
this->set(/*$*/o.value()/*$$*/); this->set(/*$*/o.value()/*$$*/);
} }
@ -740,22 +740,17 @@ methodname=invalid
class Test { class Test {
void test(); void test();
}; };
//= //=
class Test { class Test {
void test(); void test();
bool invalid(); bool invalid();
}; };
//@test.cpp //@test.cpp
#include "test.h" #include "test.h"
void Test::test() { void Test::test() {
bool b = /*$*/false/*$$*/; bool b = /*$*/false/*$$*/;
} }
//= //=
#include "test.h" #include "test.h"
@ -766,34 +761,30 @@ bool Test::invalid() {
void Test::test() { void Test::test() {
bool b = invalid(); bool b = invalid();
} }
//!Extract expression with typedef Bug 331985
//!Extract expresion with typdef Bug 331985
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
//@.config //@.config
filename=test.cpp filename=test.cpp
methodname=bar methodname=bar
//@test.cpp //@test.cpp
typedef int& foo; typedef int& foo;
int test(foo s) { int test(foo s) {
int a = /*$*/s + 1/*$$*/; // type of id-expression 's' is int, not 'foo' or 'int&' int a = /*$*/s + 1/*$$*/; // type of id-expression 's' is int, not 'foo' or 'int&'
return a; return a;
} }
//= //=
typedef int& foo; typedef int& foo;
int bar(foo s) { int bar(foo s) {
return s + 1; return s + 1;
} }
int test(foo s) { int test(foo s) {
int a = bar(s); // type of id-expression 's' is int, not 'foo' or 'int&' int a = bar(s); // type of id-expression 's' is int, not 'foo' or 'int&'
return a; return a;
} }
//!Bug 260133 Extract function and extract local variable don't handle type promotion //!Bug 260133 Extract function and extract local variable don't handle type promotion
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
@ -802,14 +793,11 @@ filename=test.cpp
methodname=bar methodname=bar
//@test.cpp //@test.cpp
void foo() { void foo() {
int x = 3; int x = 3;
double y = /*$*/x + 2.5/*$$*/; double y = /*$*/x + 2.5/*$$*/;
} }
//= //=
double bar(int x) { double bar(int x) {
return x + 2.5; return x + 2.5;
} }
@ -818,7 +806,6 @@ void foo() {
int x = 3; int x = 3;
double y = bar(x); double y = bar(x);
} }
//! Extract macro //! Extract macro
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
@ -836,7 +823,6 @@ int main() {
return i; return i;
} }
//= //=
#define five 5 #define five 5
#define ADD(a, b) a + b #define ADD(a, b) a + b
@ -851,7 +837,6 @@ int main() {
return i; return i;
} }
//! Extract macro //! Extract macro
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
@ -869,7 +854,6 @@ int main() {
return i; return i;
} }
//= //=
#define five 5 #define five 5
#define ADD(a, b) a + b #define ADD(a, b) a + b
@ -884,4 +868,3 @@ int main() {
return i; return i;
} }

View file

@ -4,7 +4,7 @@
void test() { void test() {
} }
template <typename T> template<typename T>
int tempFunct() { int tempFunct() {
T i; T i;
i = 0; i = 0;
@ -13,7 +13,6 @@ int tempFunct() {
return 0; return 0;
} }
//= //=
void test() { void test() {
} }
@ -24,22 +23,20 @@ void exp(T i) {
i += 3; 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;
} }
//!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> template<typename T>
int tempFunct(T p) { int tempFunct(T p) {
/*$*/++p; /*$*/++p;
p + 4;/*$$*/ p + 4;/*$$*/
@ -56,7 +53,7 @@ void exp(T p) {
p + 4; p + 4;
} }
template <typename T> template<typename T>
int tempFunct(T p) { int tempFunct(T p) {
exp(p); exp(p);
return 0; return 0;
@ -68,7 +65,7 @@ int tempFunct(T p) {
void test() { void test() {
} }
template <typename T> template<typename T>
int tempFunct() { int tempFunct() {
/*$*/T p; /*$*/T p;
p = 0; p = 0;
@ -76,7 +73,6 @@ int tempFunct() {
p + 2; p + 2;
return 0; return 0;
} }
//= //=
void test() { void test() {
} }
@ -89,10 +85,9 @@ T exp() {
return p; 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

@ -15,7 +15,6 @@ private:
}; };
#endif /*A_H_*/ #endif /*A_H_*/
//= //=
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
@ -32,7 +31,6 @@ private:
}; };
#endif /*A_H_*/ #endif /*A_H_*/
//@A.cpp //@A.cpp
#include "A.h" #include "A.h"
@ -52,7 +50,6 @@ int A::foo() {
int A::help() { int A::help() {
return 42; return 42;
} }
//= //=
#include "A.h" #include "A.h"
@ -77,7 +74,6 @@ int A::foo() {
int A::help() { int A::help() {
return 42; return 42;
} }
//!ExtractFunctionRefactoringTest with comment //!ExtractFunctionRefactoringTest with comment
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
//@A.h //@A.h
@ -95,7 +91,6 @@ private:
}; };
#endif /*A_H_*/ #endif /*A_H_*/
//= //=
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
@ -112,7 +107,6 @@ private:
}; };
#endif /*A_H_*/ #endif /*A_H_*/
//@A.cpp //@A.cpp
#include "A.h" #include "A.h"
@ -133,7 +127,6 @@ int A::foo() {
int A::help() { int A::help() {
return 42; return 42;
} }
//= //=
#include "A.h" #include "A.h"
@ -159,7 +152,6 @@ int A::foo() {
int A::help() { int A::help() {
return 42; return 42;
} }
//@.config //@.config
filename=A.cpp filename=A.cpp
methodname=exp methodname=exp
@ -213,7 +205,7 @@ void exp(int& i) {
int main() { int main() {
int i; int i;
exp(i); // Comment exp(i);
return i; return i;
} }
@ -1739,7 +1731,6 @@ returnparameterindex=0
filename=main.h filename=main.h
methodname=loop methodname=loop
//@main.h //@main.h
void method() { void method() {
/*$*/for (int var = 0; var < 100; ++var) { /*$*/for (int var = 0; var < 100; ++var) {
if (var < 50) if (var < 50)
@ -1747,7 +1738,6 @@ void method() {
}/*$$*/ }/*$$*/
} }
//= //=
void loop() { void loop() {
for (int var = 0; var < 100; ++var) { for (int var = 0; var < 100; ++var) {
if (var < 50) if (var < 50)
@ -1764,7 +1754,6 @@ void method() {
filename=main.h filename=main.h
fatalerror=true fatalerror=true
//@main.h //@main.h
void method() { void method() {
/*$*/if (true) /*$*/if (true)
return;/*$$*/ return;/*$$*/
@ -1776,14 +1765,12 @@ void method() {
fatalerror=true fatalerror=true
filename=A.h filename=A.h
//@A.h //@A.h
void function() { void function() {
for (int var = 0; var < 100; ++var) { for (int var = 0; var < 100; ++var) {
/*$*/if (var < 50) /*$*/if (var < 50)
continue;/*$$*/ continue;/*$$*/
} }
} }
//! Bug #124 Extract Function with a Macro call in selected code "forgets" the macro //! Bug #124 Extract Function with a Macro call in selected code "forgets" the macro
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
//@.config //@.config
@ -2411,7 +2398,6 @@ class Test {
}; };
#endif #endif
//= //=
/* /*
* Copyright 2009 * Copyright 2009
@ -2438,11 +2424,11 @@ class Test {
* Retain a value for something. * Retain a value for something.
*/ */
int m_value; int m_value;
int exp(); int exp();
}; };
#endif #endif
//@test.cpp //@test.cpp
#include "test.h" #include "test.h"

View file

@ -170,7 +170,7 @@ int A::help() {
return 42; return 42;
} }
//!ExtractFunctionRefactoringTest dublicate with field //!ExtractFunctionRefactoringTest duplicate with field
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
//@.config //@.config
replaceduplicates=true replaceduplicates=true
@ -267,7 +267,7 @@ int A::help() {
return 42; return 42;
} }
//!ExtractFunctionRefactoringTest dublicate with field in marked scope //!ExtractFunctionRefactoringTest duplicate with field in marked scope
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
//@.config //@.config
replaceduplicates=true replaceduplicates=true
@ -289,7 +289,6 @@ private:
}; };
#endif /*A_H_*/ #endif /*A_H_*/
//= //=
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
@ -308,7 +307,6 @@ private:
}; };
#endif /*A_H_*/ #endif /*A_H_*/
//@A.cpp //@A.cpp
#include "A.h" #include "A.h"
@ -336,7 +334,6 @@ void A::foo() {
int A::help() { int A::help() {
return 42; return 42;
} }
//= //=
#include "A.h" #include "A.h"
@ -360,6 +357,7 @@ int A::exp(int j) {
void A::foo() { void A::foo() {
int j = 0; int j = 0;
j = exp(j); j = exp(j);
field++; field++;
j++; j++;
@ -368,7 +366,6 @@ void A::foo() {
int A::help() { int A::help() {
return 42; return 42;
} }
//!ExtractFunctionRefactoringTest duplicates with different Names and return type //!ExtractFunctionRefactoringTest duplicates with different Names and return type
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
//@.config //@.config
@ -561,7 +558,7 @@ int A::help() {
return 42; return 42;
} }
//!ExtractFunctionRefactoringTest with duplicates name used afterwards in duplicate but not in original selection this is no dublicate //!ExtractFunctionRefactoringTest with duplicate name used afterwards in duplicate but not in original selection this is no duplicate
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
//@.config //@.config
replaceduplicates=true replaceduplicates=true

View file

@ -211,7 +211,7 @@ int main() {
name="exp" project="RegressionTestProject" selection="34,6" 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 trailing comment
//#org.eclipse.cdt.ui.tests.refactoring.RefactoringHistoryTest //#org.eclipse.cdt.ui.tests.refactoring.RefactoringHistoryTest
//@main.cpp //@main.cpp
int main() { int main() {
@ -227,7 +227,7 @@ void exp(int& i) {
int main() { int main() {
int i; int i;
exp(i); // Comment exp(i);
return i; return i;
} }

View file

@ -1,22 +1,11 @@
//!Generate Getters and Setters One Getter Selection //!Generate Getters and Setters One Getter Selection
//#org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest //#org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest
//@.config //@.config
filename=C.h filename=A.h
getters=name getters=name
//@C.cpp //@A.h
#include "C.h" #ifndef A_H_
#define A_H_
int Person::SocSecNo() {
return socSecNo;
}
int main(int argc, char** argv) {
}
//=
//@C.h
#ifndef C_H_
#define C_H_
class Person { class Person {
private: private:
@ -53,10 +42,10 @@ public:
int gooo = 1; int gooo = 1;
#endif /* C_H_ */ #endif /* A_H_ */
//= //=
#ifndef C_H_ #ifndef A_H_
#define C_H_ #define A_H_
class Person { class Person {
private: private:
@ -97,26 +86,25 @@ public:
int gooo = 1; int gooo = 1;
#endif /* C_H_ */ #endif /* A_H_ */
//@A.cpp
#include "A.h"
int Person::SocSecNo() {
return socSecNo;
}
int main(int argc, char** argv) {
}
//=
//!Generate Getters and Setters One Getter Selection with Namespace //!Generate Getters and Setters One Getter Selection with Namespace
//#org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest //#org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest
//@.config //@.config
filename=C.h filename=A.h
getters=name getters=name
//@C.cpp //@A.h
#include "C.h" #ifndef A_H_
#define A_H_
int Person::SocSecNo() {
return socSecNo;
}
int main(int argc, char** argv) {
}
//=
//@C.h
#ifndef C_H_
#define C_H_
namespace Personal { namespace Personal {
@ -157,11 +145,10 @@ public:
int gooo = 1; int gooo = 1;
#endif /* C_H_ */ #endif /* A_H_ */
//= //=
#ifndef C_H_ #ifndef A_H_
#define C_H_ #define A_H_
namespace Personal { namespace Personal {
@ -206,27 +193,25 @@ public:
int gooo = 1; int gooo = 1;
#endif /* C_H_ */ #endif /* A_H_ */
//@A.cpp
#include "A.h"
int Person::SocSecNo() {
return socSecNo;
}
int main(int argc, char** argv) {
}
//=
//!Generate Getters and Setters One Setter Selection //!Generate Getters and Setters One Setter Selection
//#org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest //#org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest
//@.config //@.config
filename=C.h filename=A.h
setters=name setters=name
//@C.cpp //@A.h
#include "C.h" #ifndef A_H_
#define A_H_
int Person::SocSecNo() {
return socSecNo;
}
int main(int argc, char** argv) {
}
//=
//@C.h
#ifndef C_H_
#define C_H_
class Person { class Person {
private: private:
@ -264,10 +249,10 @@ public:
int gooo = 1; int gooo = 1;
#endif /* C_H_ */ #endif /* A_H_ */
//= //=
#ifndef C_H_ #ifndef A_H_
#define C_H_ #define A_H_
class Person { class Person {
private: private:
@ -309,15 +294,9 @@ public:
int gooo = 1; int gooo = 1;
#endif /* C_H_ */ #endif /* A_H_ */
//!Generate Getters and Setters Getter and Setter Selection //@A.cpp
//#org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest #include "A.h"
//@.config
filename=C.h
setters=name
getters=name
//@C.cpp
#include "C.h"
int Person::SocSecNo() { int Person::SocSecNo() {
return socSecNo; return socSecNo;
@ -325,11 +304,16 @@ int Person::SocSecNo() {
int main(int argc, char** argv) { int main(int argc, char** argv) {
} }
//= //=
//@C.h //!Generate Getters and Setters Getter and Setter Selection
#ifndef C_H_ //#org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest
#define C_H_ //@.config
filename=A.h
setters=name
getters=name
//@A.h
#ifndef A_H_
#define A_H_
class Person { class Person {
private: private:
@ -364,13 +348,12 @@ public:
} }
}; };
int gooo = 1; int gooo = 1;
#endif /* C_H_ */ #endif /* A_H_ */
//= //=
#ifndef C_H_ #ifndef A_H_
#define C_H_ #define A_H_
class Person { class Person {
private: private:
@ -413,18 +396,11 @@ public:
} }
}; };
int gooo = 1; int gooo = 1;
#endif /* C_H_ */ #endif /* A_H_ */
//!Generate Getters and Setters Multiple Selection //@A.cpp
//#org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest #include "A.h"
//@.config
filename=C.h
getters=name,systemId
setters=name,systemId
//@C.cpp
#include "C.h"
int Person::SocSecNo() { int Person::SocSecNo() {
return socSecNo; return socSecNo;
@ -432,11 +408,16 @@ int Person::SocSecNo() {
int main(int argc, char** argv) { int main(int argc, char** argv) {
} }
//= //=
//@C.h //!Generate Getters and Setters Multiple Selection
#ifndef C_H_ //#org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest
#define C_H_ //@.config
filename=A.h
getters=name,systemId
setters=name,systemId
//@A.h
#ifndef A_H_
#define A_H_
class Person { class Person {
private: private:
@ -465,11 +446,10 @@ public:
int gooo = 1; int gooo = 1;
#endif /* C_H_ */ #endif /* A_H_ */
//= //=
#ifndef C_H_ #ifndef A_H_
#define C_H_ #define A_H_
class Person { class Person {
private: private:
@ -514,23 +494,23 @@ public:
int gooo = 1; int gooo = 1;
#endif /* C_H_ */ #endif /* A_H_ */
//@A.cpp
#include "A.h"
int Person::SocSecNo() {
return socSecNo;
}
int main(int argc, char** argv) {
}
//=
//!Generate Getters and Setters Visibility order 1 //!Generate Getters and Setters Visibility order 1
//#org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest //#org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest
//@.config //@.config
filename=GaS.h filename=GaS.h
getters=i,ok getters=i,ok
setters=i,ok setters=i,ok
//@GaS.cpp
#include "Getters.h"
GaS::Getters() {
}
GaS::~Getters() {
}
//@GaS.h //@GaS.h
#ifndef GAS_H_ #ifndef GAS_H_
#define GAS_H_ #define GAS_H_
@ -547,7 +527,6 @@ private:
}; };
#endif #endif
//= //=
#ifndef GAS_H_ #ifndef GAS_H_
#define GAS_H_ #define GAS_H_
@ -580,27 +559,33 @@ private:
}; };
#endif #endif
//@GaS.cpp
#include "Getters.h"
GaS::Getters() {
}
GaS::~Getters() {
}
//!Generate Getters and Setters no Methods //!Generate Getters and Setters no Methods
//#org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest //#org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest
//@.config //@.config
filename=C.h filename=A.h
getters=id getters=id
setters=id setters=id
//@C.h //@A.h
#ifndef C_H_ #ifndef A_H_
#define C_H_ #define A_H_
class Person { class Person {
private: private:
int /*$*/id/*$$*/; int /*$*/id/*$$*/;
}; };
#endif /* C_H_ */ #endif /* A_H_ */
//= //=
#ifndef C_H_ #ifndef A_H_
#define C_H_ #define A_H_
class Person { class Person {
private: private:
@ -616,15 +601,14 @@ public:
} }
}; };
#endif /* C_H_ */ #endif /* A_H_ */
//!Generate Getters and Setters no Methods //!Generate Getters and Setters no Methods
//#org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest //#org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest
//@.config //@.config
filename=C.h filename=A.h
getters=i getters=i
setters=i setters=i
//@C.h //@A.h
/* /*
* test.h * test.h
*/ */
@ -670,9 +654,9 @@ public:
//!Generate Getters and Setters no Fields //!Generate Getters and Setters no Fields
//#org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest //#org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest
//@.config //@.config
filename=C.h filename=A.h
fatalerror=true fatalerror=true
//@C.h //@A.h
/* /*
* test.h * test.h
*/ */
@ -687,7 +671,6 @@ class test {
}; };
#endif /* TEST_H_ */ #endif /* TEST_H_ */
//= //=
/* /*
* test.h * test.h
@ -703,17 +686,16 @@ class test {
}; };
#endif /* TEST_H_ */ #endif /* TEST_H_ */
//!Generate Getters and Setters, Pass by Reference, Separate Definition //!Generate Getters and Setters, Pass by Reference, Separate Definition
//#org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest //#org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest
//@.config //@.config
filename=C.h filename=A.h
getters=name getters=name
setters=name setters=name
definitionSeparate=true definitionSeparate=true
//@C.h //@A.h
#ifndef C_H_ #ifndef A_H_
#define C_H_ #define A_H_
struct FullName { struct FullName {
const char* first; const char* first;
@ -753,10 +735,10 @@ public:
int gooo = 1; int gooo = 1;
#endif /* C_H_ */ #endif /* A_H_ */
//= //=
#ifndef C_H_ #ifndef A_H_
#define C_H_ #define A_H_
struct FullName { struct FullName {
const char* first; const char* first;
@ -776,9 +758,9 @@ public:
const int socSecNo; const int socSecNo;
Person myFriend; Person myFriend;
const FullName& getName() const; const FullName& getName() const;
void setName(const FullName& name); void setName(const FullName& name);
Person(int socSecNo); // constructor Person(int socSecNo); // constructor
~Person(); // destructor ~Person(); // destructor
@ -798,9 +780,9 @@ public:
int gooo = 1; int gooo = 1;
#endif /* C_H_ */ #endif /* A_H_ */
//@C.cpp //@A.cpp
#include "C.h" #include "A.h"
int Person::SocSecNo() { int Person::SocSecNo() {
return socSecNo; return socSecNo;
@ -808,9 +790,8 @@ int Person::SocSecNo() {
int main(int argc, char** argv) { int main(int argc, char** argv) {
} }
//= //=
#include "C.h" #include "A.h"
const FullName& Person::getName() const { const FullName& Person::getName() const {
return name; return name;
@ -826,48 +807,15 @@ int Person::SocSecNo() {
int main(int argc, char** argv) { int main(int argc, char** argv) {
} }
//!Generate Getters and Setters One Getter Selection with Namespace Separate Definition //!Generate Getters and Setters One Getter Selection with Namespace Separate Definition
//#org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest //#org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest
//@.config //@.config
filename=C.h filename=A.h
getters=name getters=name
definitionSeparate=true definitionSeparate=true
//@C.cpp //@A.h
#include "C.h" #ifndef A_H_
#define A_H_
namespace Personal {
int Person::SocSecNo() {
return socSecNo;
}
} // namespace Personal
int main(int argc, char** argv) {
}
//=
#include "C.h"
namespace Personal {
char* Person::getName() const {
return name;
}
int Person::SocSecNo() {
return socSecNo;
}
} // namespace Personal
int main(int argc, char** argv) {
}
//@C.h
#ifndef C_H_
#define C_H_
namespace Personal { namespace Personal {
@ -908,11 +856,10 @@ public:
int gooo = 1; int gooo = 1;
#endif /* C_H_ */ #endif /* A_H_ */
//= //=
#ifndef C_H_ #ifndef A_H_
#define C_H_ #define A_H_
namespace Personal { namespace Personal {
@ -954,43 +901,46 @@ public:
int gooo = 1; int gooo = 1;
#endif /* C_H_ */ #endif /* A_H_ */
//@A.cpp
#include "A.h"
namespace Personal {
int Person::SocSecNo() {
return socSecNo;
}
} // namespace Personal
int main(int argc, char** argv) {
}
//=
#include "A.h"
namespace Personal {
char* Person::getName() const {
return name;
}
int Person::SocSecNo() {
return socSecNo;
}
} // namespace Personal
int main(int argc, char** argv) {
}
//!Generate Getters and Setters One Setter Selection Separate Definition //!Generate Getters and Setters One Setter Selection Separate Definition
//#org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest //#org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest
//@.config //@.config
filename=C.h filename=A.h
setters=name setters=name
definitionSeparate=true definitionSeparate=true
//@C.cpp //@A.h
#include "C.h" #ifndef A_H_
#define A_H_
int Person::SocSecNo() {
return socSecNo;
}
int main(int argc, char** argv) {
}
//=
#include "C.h"
void Person::setName(char* name) {
this->name = name;
}
int Person::SocSecNo() {
return socSecNo;
}
int main(int argc, char** argv) {
}
//@C.h
#ifndef C_H_
#define C_H_
class Person { class Person {
private: private:
@ -1025,13 +975,12 @@ public:
} }
}; };
int gooo = 1; int gooo = 1;
#endif /* C_H_ */ #endif /* A_H_ */
//= //=
#ifndef C_H_ #ifndef A_H_
#define C_H_ #define A_H_
class Person { class Person {
private: private:
@ -1067,19 +1016,11 @@ public:
} }
}; };
int gooo = 1; int gooo = 1;
#endif /* C_H_ */ #endif /* A_H_ */
//!Getter and Setter Selection Separate Definition //@A.cpp
//#org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest #include "A.h"
//@.config
filename=C.h
setters=name
getters=name
definitionSeparate=true
//@C.cpp
#include "C.h"
int Person::SocSecNo() { int Person::SocSecNo() {
return socSecNo; return socSecNo;
@ -1087,13 +1028,8 @@ int Person::SocSecNo() {
int main(int argc, char** argv) { int main(int argc, char** argv) {
} }
//= //=
#include "C.h" #include "A.h"
char* Person::getName() const {
return name;
}
void Person::setName(char* name) { void Person::setName(char* name) {
this->name = name; this->name = name;
@ -1105,10 +1041,16 @@ int Person::SocSecNo() {
int main(int argc, char** argv) { int main(int argc, char** argv) {
} }
//!Getter and Setter Selection Separate Definition
//@C.h //#org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest
#ifndef C_H_ //@.config
#define C_H_ filename=A.h
setters=name
getters=name
definitionSeparate=true
//@A.h
#ifndef A_H_
#define A_H_
class Person { class Person {
private: private:
@ -1143,14 +1085,12 @@ public:
} }
}; };
int gooo = 1; int gooo = 1;
#endif /* C_H_ */ #endif /* A_H_ */
//= //=
#ifndef C_H_ #ifndef A_H_
#define C_H_ #define A_H_
class Person { class Person {
private: private:
@ -1187,32 +1127,56 @@ public:
} }
}; };
int gooo = 1; int gooo = 1;
#endif /* C_H_ */ #endif /* A_H_ */
//@A.cpp
#include "A.h"
int Person::SocSecNo() {
return socSecNo;
}
int main(int argc, char** argv) {
}
//=
#include "A.h"
char* Person::getName() const {
return name;
}
void Person::setName(char* name) {
this->name = name;
}
int Person::SocSecNo() {
return socSecNo;
}
int main(int argc, char** argv) {
}
//!Generate Getters and Setters no Methods Separate Definition //!Generate Getters and Setters no Methods Separate Definition
//#org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest //#org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest
//@.config //@.config
filename=C.h filename=A.h
getters=id getters=id
setters=id setters=id
definitionSeparate=true definitionSeparate=true
//@C.h //@A.h
#ifndef C_H_ #ifndef A_H_
#define C_H_ #define A_H_
class Person { class Person {
private: private:
int /*$*/id/*$$*/; int /*$*/id/*$$*/;
}; };
#endif /* C_H_ */ #endif /* A_H_ */
//= //=
#ifndef C_H_ #ifndef A_H_
#define C_H_ #define A_H_
class Person { class Person {
private: private:
@ -1232,16 +1196,16 @@ inline void Person::setId(int id) {
} }
#endif /* C_H_ */ #endif /* A_H_ */
//!No Methods Separate Definition //!No Methods Separate Definition
//#org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest //#org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest
//@.config //@.config
filename=C.h filename=A.h
getters=i getters=i
setters=i setters=i
definitionSeparate=true definitionSeparate=true
//@C.h //@A.h
/* /*
* test.h * test.h
*/ */
@ -1257,7 +1221,6 @@ class test {
}; };
#endif /* TEST_H_ */ #endif /* TEST_H_ */
//= //=
/* /*
* test.h * test.h
@ -1287,7 +1250,6 @@ inline void test::setI(int i) {
#endif /* TEST_H_ */ #endif /* TEST_H_ */
//!Bug 323780 "Generate Getters and Setters..." crashes //!Bug 323780 "Generate Getters and Setters..." crashes
//#org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest //#org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest
//@.config //@.config
@ -1337,7 +1299,6 @@ void Test::foo() {
} }
} }
//= //=
#include "Test.h" #include "Test.h"
@ -1355,7 +1316,6 @@ void Test::foo() {
} }
} }
//!Bug 337040 - Insert definition in empty implementation file (.cxx) //!Bug 337040 - Insert definition in empty implementation file (.cxx)
//#org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest //#org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest
//@.config //@.config
@ -1445,3 +1405,49 @@ void Test::setTestField(int testField) {
//@component_a/implementation/Test.cpp //@component_a/implementation/Test.cpp
//= //=
//!Bug 363244 - Generate Getters and Setters for class with macro
//#org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest
//@.config
filename=A.h
getters=test
//@A.h
#ifndef A_H_
#define A_H_
#define Typedef \
typedef int Int
class Test
{
public:
Typedef;
void Foo();
Test();
int /*$*/test/*$$*/;
};
#endif /* A_H_ */
//=
#ifndef A_H_
#define A_H_
#define Typedef \
typedef int Int
class Test
{
public:
Typedef;
void Foo();
Test();
int getTest() const {
return test;
}
int test;
};
#endif /* A_H_ */

View file

@ -19,7 +19,6 @@ private:
}; };
#endif /*A_H_*/ #endif /*A_H_*/
//= //=
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
@ -33,11 +32,11 @@ public:
private: private:
int i; int i;
void method2(); void method2();
}; };
#endif /*A_H_*/ #endif /*A_H_*/
//!HideMethodLineComment //!HideMethodLineComment
//#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest
//@.config //@.config
@ -60,7 +59,6 @@ private:
}; };
#endif /*A_H_*/ #endif /*A_H_*/
//= //=
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
@ -74,12 +72,12 @@ public:
private: private:
int i; int i;
//Comment //Comment
void method2(); void method2();
}; };
#endif /*A_H_*/ #endif /*A_H_*/
//!HideMethodBlockComment //!HideMethodBlockComment
//#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest
//@.config //@.config
@ -102,7 +100,6 @@ private:
}; };
#endif /*A_H_*/ #endif /*A_H_*/
//= //=
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
@ -116,12 +113,12 @@ public:
private: private:
int i; int i;
/*Comment*/ /*Comment*/
void method2(); void method2();
}; };
#endif /*A_H_*/ #endif /*A_H_*/
//!HideMethodLineCommentBehind //!HideMethodLineCommentBehind
//#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest
//@.config //@.config
@ -143,7 +140,6 @@ private:
}; };
#endif /*A_H_*/ #endif /*A_H_*/
//= //=
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
@ -157,11 +153,11 @@ public:
private: private:
int i; int i;
void method2(); //Comment void method2(); //Comment
}; };
#endif /*A_H_*/ #endif /*A_H_*/
//!HideMethodBlockCommentBehind //!HideMethodBlockCommentBehind
//#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest
//@.config //@.config
@ -183,7 +179,6 @@ private:
}; };
#endif /*A_H_*/ #endif /*A_H_*/
//= //=
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
@ -197,11 +192,11 @@ public:
private: private:
int i; int i;
void method2(); /*Comment*/ void method2(); /*Comment*/
}; };
#endif /*A_H_*/ #endif /*A_H_*/
//!HideMethodLineCommentWithSpace //!HideMethodLineCommentWithSpace
//#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest
//@.config //@.config
@ -225,7 +220,6 @@ private:
}; };
#endif /*A_H_*/ #endif /*A_H_*/
//= //=
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
@ -239,12 +233,12 @@ public:
private: private:
int i; int i;
//Comment //Comment
void method2(); void method2();
}; };
#endif /*A_H_*/ #endif /*A_H_*/
//!HideMethodBlockCommentWithSpace //!HideMethodBlockCommentWithSpace
//#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest
//@.config //@.config
@ -268,7 +262,6 @@ private:
}; };
#endif /*A_H_*/ #endif /*A_H_*/
//= //=
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
@ -282,12 +275,12 @@ public:
private: private:
int i; int i;
/*Comment*/ /*Comment*/
void method2(); void method2();
}; };
#endif /*A_H_*/ #endif /*A_H_*/
//!HideMethodLineCommentWithSpaceBehind //!HideMethodLineCommentWithSpaceBehind
//#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest
//@.config //@.config
@ -309,7 +302,6 @@ private:
}; };
#endif /*A_H_*/ #endif /*A_H_*/
//= //=
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
@ -323,11 +315,11 @@ public:
private: private:
int i; int i;
void method2(); //Comment void method2(); //Comment
}; };
#endif /*A_H_*/ #endif /*A_H_*/
//!HideMethodBlockCommentWithSpaceBehind //!HideMethodBlockCommentWithSpaceBehind
//#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest
//@.config //@.config
@ -349,7 +341,6 @@ private:
int i; int i;
}; };
#endif /*A_H_*/ #endif /*A_H_*/
//= //=
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
@ -363,10 +354,10 @@ public:
private: private:
int i; int i;
void method2(); /*Comment*/ void method2(); /*Comment*/
}; };
#endif /*A_H_*/ #endif /*A_H_*/
//!HideMethodBigBlockComment //!HideMethodBigBlockComment
//#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest
//@.config //@.config
@ -390,7 +381,6 @@ private:
int i; int i;
}; };
#endif /*A_H_*/ #endif /*A_H_*/
//= //=
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
@ -404,13 +394,13 @@ public:
private: private:
int i; int i;
/* /*
* Comment * Comment
*/ */
void method2(); void method2();
}; };
#endif /*A_H_*/ #endif /*A_H_*/
//!HideMethodBigBlockCommentBehind //!HideMethodBigBlockCommentBehind
//#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest
//@.config //@.config
@ -434,7 +424,6 @@ private:
}; };
#endif /*A_H_*/ #endif /*A_H_*/
//= //=
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
@ -448,13 +437,13 @@ public:
private: private:
int i; int i;
void method2(); /* void method2(); /*
* Comment * Comment
*/ */
}; };
#endif /*A_H_*/ #endif /*A_H_*/
//!HideMethodBigBlockCommentBeforeAndBehind //!HideMethodBigBlockCommentBeforeAndBehind
//#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest
//@.config //@.config
@ -481,7 +470,6 @@ private:
}; };
#endif /*A_H_*/ #endif /*A_H_*/
//= //=
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
@ -495,6 +483,7 @@ public:
private: private:
int i; int i;
/* /*
* Davor * Davor
*/ */
@ -504,7 +493,6 @@ private:
}; };
#endif /*A_H_*/ #endif /*A_H_*/
//!HideMethodMixedCommentBeforeAndAfter //!HideMethodMixedCommentBeforeAndAfter
//#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest
//@.config //@.config
@ -527,7 +515,6 @@ private:
}; };
#endif /*A_H_*/ #endif /*A_H_*/
//= //=
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
@ -541,12 +528,12 @@ public:
private: private:
int i; int i;
/*123*/ /*123*/
void method2(); //TEST void method2(); //TEST
}; };
#endif /*A_H_*/ #endif /*A_H_*/
//!HideMethodBlockCommentBeforeAndBehind //!HideMethodBlockCommentBeforeAndBehind
//#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest
//@.config //@.config
@ -568,7 +555,6 @@ private:
int i; int i;
}; };
#endif /*A_H_*/ #endif /*A_H_*/
//= //=
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
@ -582,11 +568,11 @@ public:
private: private:
int i; int i;
/*123*/ /*123*/
void method2(); /*TEST*/ void method2(); /*TEST*/
}; };
#endif /*A_H_*/ #endif /*A_H_*/
//!HideMethodNoChange //!HideMethodNoChange
//#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest
//@.config //@.config
@ -604,7 +590,6 @@ private:
}; };
#endif /*A_H_*/ #endif /*A_H_*/
//= //=
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
@ -617,7 +602,6 @@ private:
}; };
#endif /*A_H_*/ #endif /*A_H_*/
//!HideMethod2MethodsDifferentLine //!HideMethod2MethodsDifferentLine
//#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest
//@.config //@.config
@ -635,7 +619,6 @@ public:
}; };
#endif /*A_H_*/ #endif /*A_H_*/
//= //=
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
@ -651,7 +634,6 @@ private:
}; };
#endif /*A_H_*/ #endif /*A_H_*/
//!HideMethod2MethodsSameLine //!HideMethod2MethodsSameLine
//#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest
//@.config //@.config
@ -668,7 +650,6 @@ public:
}; };
#endif /*A_H_*/ #endif /*A_H_*/
//= //=
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
@ -684,7 +665,6 @@ private:
}; };
#endif /*A_H_*/ #endif /*A_H_*/
//!HideMethod2MethodsDifferentLineWithComment //!HideMethod2MethodsDifferentLineWithComment
//#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest
//@.config //@.config
@ -703,7 +683,6 @@ public:
}; };
#endif /*A_H_*/ #endif /*A_H_*/
//= //=
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
@ -720,7 +699,6 @@ private:
}; };
#endif /*A_H_*/ #endif /*A_H_*/
//!HideMethod2MethodsSameLineWithComment //!HideMethod2MethodsSameLineWithComment
//#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest
//@.config //@.config
@ -738,7 +716,6 @@ public:
}; };
#endif /*A_H_*/ #endif /*A_H_*/
//= //=
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
@ -755,7 +732,6 @@ private:
}; };
#endif /*A_H_*/ #endif /*A_H_*/
//!HideMethodSimple ImplementationFile //!HideMethodSimple ImplementationFile
//#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest
//@A.h //@A.h
@ -775,7 +751,6 @@ private:
}; };
#endif /*A_H_*/ #endif /*A_H_*/
//= //=
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
@ -789,18 +764,17 @@ public:
private: private:
int i; int i;
void method2(); void method2();
}; };
#endif /*A_H_*/ #endif /*A_H_*/
//@A.cpp //@A.cpp
#include "A.h" #include "A.h"
void A::/*$*/method2/*$$*/() void A::/*$*/method2/*$$*/()
{ {
} }
//!HideMethodSimple ImplementationFile with Comments BUG #60 //!HideMethodSimple ImplementationFile with Comments BUG #60
//#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest
//@A.h //@A.h
@ -821,7 +795,6 @@ private:
}; };
#endif /*A_H_*/ #endif /*A_H_*/
//= //=
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
@ -835,12 +808,12 @@ public:
private: private:
int i; int i;
//TEST 1 //TEST 1
void method2(); //TEST 2 void method2(); //TEST 2
}; };
#endif /*A_H_*/ #endif /*A_H_*/
//@A.cpp //@A.cpp
#include "A.h" #include "A.h"
@ -848,7 +821,7 @@ void A::/*$*/method2/*$$*/()
{ {
} }
//!HideMethod with References 1 //!HideMethod with references 1
//#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest
//@.config //@.config
filename=HideMethod.h filename=HideMethod.h
@ -860,14 +833,14 @@ class HideMethod {
public: public:
HideMethod(); HideMethod();
virtual ~HideMethod(); virtual ~HideMethod();
void /*$*/methode2/*$$*/(); void /*$*/method2/*$$*/();
void methode3() {
methode2(); void method3() {
method2();
} }
}; };
#endif /* HIDEMETHOD_H_ */ #endif /* HIDEMETHOD_H_ */
//= //=
#ifndef HIDEMETHOD_H_ #ifndef HIDEMETHOD_H_
#define HIDEMETHOD_H_ #define HIDEMETHOD_H_
@ -876,17 +849,17 @@ class HideMethod {
public: public:
HideMethod(); HideMethod();
virtual ~HideMethod(); virtual ~HideMethod();
void methode3() {
methode2(); void method3() {
method2();
} }
private: private:
void methode2(); void method2();
}; };
#endif /* HIDEMETHOD_H_ */ #endif /* HIDEMETHOD_H_ */
//!HideMethod with references 2
//!HideMethod with References 2
//#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest
//@.config //@.config
filename=HideMethod.h filename=HideMethod.h
@ -898,12 +871,11 @@ class HideMethod {
public: public:
HideMethod(); HideMethod();
virtual ~HideMethod(); virtual ~HideMethod();
void /*$*/methode2/*$$*/(); void /*$*/method2/*$$*/();
void methode3(); void method3();
}; };
#endif /* HIDEMETHOD_H_ */ #endif /* HIDEMETHOD_H_ */
//= //=
#ifndef HIDEMETHOD_H_ #ifndef HIDEMETHOD_H_
#define HIDEMETHOD_H_ #define HIDEMETHOD_H_
@ -912,14 +884,13 @@ class HideMethod {
public: public:
HideMethod(); HideMethod();
virtual ~HideMethod(); virtual ~HideMethod();
void methode3(); void method3();
private: private:
void methode2(); void method2();
}; };
#endif /* HIDEMETHOD_H_ */ #endif /* HIDEMETHOD_H_ */
//@HideMethod.cpp //@HideMethod.cpp
#include "HideMethod.h" #include "HideMethod.h"
@ -931,15 +902,13 @@ HideMethod::~HideMethod() {
// TODO Auto-generated destructor stub // TODO Auto-generated destructor stub
} }
void HideMethod::methode2() { void HideMethod::method2() {
//do nothing //do nothing
} }
void HideMethod::methode3() void HideMethod::method3() {
{ method2();
methode2();
} }
//= //=
#include "HideMethod.h" #include "HideMethod.h"
@ -951,16 +920,14 @@ HideMethod::~HideMethod() {
// TODO Auto-generated destructor stub // TODO Auto-generated destructor stub
} }
void HideMethod::methode2() { void HideMethod::method2() {
//do nothing //do nothing
} }
void HideMethod::methode3() void HideMethod::method3() {
{ method2();
methode2();
} }
//!HideMethod with references 3
//!HideMethod with References 3
//#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest
//@.config //@.config
filename=HideMethod.h filename=HideMethod.h
@ -973,20 +940,19 @@ class HideMethod {
public: public:
HideMethod(); HideMethod();
virtual ~HideMethod(); virtual ~HideMethod();
void /*$*/methode2/*$$*/(); void /*$*/method2/*$$*/();
void methode3(); void method3();
}; };
class test{ class test{
public: public:
void call() { void call() {
HideMethod hm; HideMethod hm;
hm.methode2(); hm.method2();
} }
}; };
#endif /* HIDEMETHOD_H_ */ #endif /* HIDEMETHOD_H_ */
//= //=
#ifndef HIDEMETHOD_H_ #ifndef HIDEMETHOD_H_
#define HIDEMETHOD_H_ #define HIDEMETHOD_H_
@ -995,23 +961,22 @@ class HideMethod {
public: public:
HideMethod(); HideMethod();
virtual ~HideMethod(); virtual ~HideMethod();
void methode3(); void method3();
private: private:
void methode2(); void method2();
}; };
class test{ class test{
public: public:
void call() { void call() {
HideMethod hm; HideMethod hm;
hm.methode2(); hm.method2();
} }
}; };
#endif /* HIDEMETHOD_H_ */ #endif /* HIDEMETHOD_H_ */
//!HideMethod with references 4
//!HideMethod with References 4
//#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest
//@.config //@.config
filename=HideMethod.h filename=HideMethod.h
@ -1024,12 +989,11 @@ class HideMethod {
public: public:
HideMethod(); HideMethod();
virtual ~HideMethod(); virtual ~HideMethod();
void /*$*/methode2/*$$*/(); void /*$*/method2/*$$*/();
void methode3(); void method3();
}; };
#endif /* HIDEMETHOD_H_ */ #endif /* HIDEMETHOD_H_ */
//= //=
#ifndef HIDEMETHOD_H_ #ifndef HIDEMETHOD_H_
#define HIDEMETHOD_H_ #define HIDEMETHOD_H_
@ -1038,14 +1002,13 @@ class HideMethod {
public: public:
HideMethod(); HideMethod();
virtual ~HideMethod(); virtual ~HideMethod();
void methode3(); void method3();
private: private:
void methode2(); void method2();
}; };
#endif /* HIDEMETHOD_H_ */ #endif /* HIDEMETHOD_H_ */
//@HideMethod.cpp //@HideMethod.cpp
#include "HideMethod.h" #include "HideMethod.h"
@ -1058,19 +1021,18 @@ HideMethod::~HideMethod() {
// TODO Auto-generated destructor stub // TODO Auto-generated destructor stub
} }
void HideMethod::methode2() { void HideMethod::method2() {
//do nothing //do nothing
} }
void HideMethod::methode3() { void HideMethod::method3() {
//do nothing //do nothing
} }
int main() { int main() {
HideMethod hm; HideMethod hm;
hm.methode2(); hm.method2();
} }
//= //=
//@HideMethod.cpp //@HideMethod.cpp
#include "HideMethod.h" #include "HideMethod.h"
@ -1084,20 +1046,19 @@ HideMethod::~HideMethod() {
// TODO Auto-generated destructor stub // TODO Auto-generated destructor stub
} }
void HideMethod::methode2() { void HideMethod::method2() {
//do nothing //do nothing
} }
void HideMethod::methode3() { void HideMethod::method3() {
//do nothing //do nothing
} }
int main() { int main() {
HideMethod hm; HideMethod hm;
hm.methode2(); hm.method2();
} }
//!HideMethod with CPP file selection
//!HideMethod with CPP File selection
//#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest
//@.config //@.config
filename=HideMethod.h filename=HideMethod.h
@ -1109,12 +1070,11 @@ class HideMethod {
public: public:
HideMethod(); HideMethod();
virtual ~HideMethod(); virtual ~HideMethod();
void methode2(); void method2();
void methode3(); void method3();
}; };
#endif /* HIDEMETHOD_H_ */ #endif /* HIDEMETHOD_H_ */
//= //=
#ifndef HIDEMETHOD_H_ #ifndef HIDEMETHOD_H_
#define HIDEMETHOD_H_ #define HIDEMETHOD_H_
@ -1123,14 +1083,13 @@ class HideMethod {
public: public:
HideMethod(); HideMethod();
virtual ~HideMethod(); virtual ~HideMethod();
void methode3(); void method3();
private: private:
void methode2(); void method2();
}; };
#endif /* HIDEMETHOD_H_ */ #endif /* HIDEMETHOD_H_ */
//@HideMethod.cpp //@HideMethod.cpp
#include "HideMethod.h" #include "HideMethod.h"
@ -1142,15 +1101,13 @@ HideMethod::~HideMethod() {
// TODO Auto-generated destructor stub // TODO Auto-generated destructor stub
} }
void HideMethod::/*$*/methode2/*$$*/() { void HideMethod::/*$*/method2/*$$*/() {
//do nothing //do nothing
} }
void HideMethod::methode3() void HideMethod::method3() {
{ method2();
methode2();
} }
//= //=
#include "HideMethod.h" #include "HideMethod.h"
@ -1162,15 +1119,13 @@ HideMethod::~HideMethod() {
// TODO Auto-generated destructor stub // TODO Auto-generated destructor stub
} }
void HideMethod::methode2() { void HideMethod::method2() {
//do nothing //do nothing
} }
void HideMethod::methode3() void HideMethod::method3() {
{ method2();
methode2();
} }
//!HideMethodChangeToDefaultVisibility Class1 //!HideMethodChangeToDefaultVisibility Class1
//#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest
//@.config //@.config
@ -1187,7 +1142,6 @@ public:
}; };
#endif /*A_H_*/ #endif /*A_H_*/
//= //=
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
@ -1196,12 +1150,12 @@ public:
class A { class A {
public: public:
private: private:
void method2(); void method2();
}; };
#endif /*A_H_*/ #endif /*A_H_*/
//!HideMethodChangeToDefaultVisibility Class2 //!HideMethodChangeToDefaultVisibility Class2
//#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest
//@.config //@.config
@ -1246,7 +1200,6 @@ struct A {
}; };
#endif /*A_H_*/ #endif /*A_H_*/
//= //=
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
@ -1259,7 +1212,6 @@ private:
}; };
#endif /*A_H_*/ #endif /*A_H_*/
//!HideMethod CheckIfPrivateBug 1 //!HideMethod CheckIfPrivateBug 1
//#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest
//@.config //@.config
@ -1354,7 +1306,9 @@ public:
//= //=
struct other { struct other {
private: private:
bool value() { return true; } bool value() {
return true;
}
}; };
class Class { class Class {
@ -1397,7 +1351,6 @@ public:
} }
private: private:
void test() { void test() {
other o; other o;
this->set(o.value()); this->set(o.value());
@ -1435,15 +1388,14 @@ public:
private: private:
void just_private(); void just_private();
}; };
//= //=
class Class { class Class {
public: public:
private: private:
void just_private(); void just_private();
void to_move(); void to_move();
}; };
//!HideMethod several private sections //!HideMethod several private sections
//#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.hidemethod.HideMethodRefactoringTest
//@.config //@.config
@ -1458,14 +1410,13 @@ private:
private: private:
}; };
//= //=
class Class { class Class {
public: public:
private: private:
void just_private(); void just_private();
void to_move(); void to_move();
private: private:
}; };

View file

@ -17,7 +17,6 @@ private:
}; };
#endif /*A_H_*/ #endif /*A_H_*/
//= //=
#ifndef A_H_ #ifndef A_H_
#define A_H_ #define A_H_
@ -31,11 +30,11 @@ public:
private: private:
int i; int i;
void method2(); void method2();
}; };
#endif /*A_H_*/ #endif /*A_H_*/
//@refScript.xml //@refScript.xml
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<session version="1.0"> <session version="1.0">

View file

@ -182,7 +182,6 @@ public:
}; };
} }
//@A.cpp //@A.cpp
#include "A.h" #include "A.h"

View file

@ -1,4 +1,4 @@
//!FreefunctionFromHeaderToImpl //!FreeFunctionFromHeaderToImpl
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config //@.config
filename=A.h filename=A.h
@ -20,7 +20,7 @@ void freefunction();
void freefunction() { void freefunction() {
return; return;
} }
//!FreefunctionFromImplToHeader //!FreeFunctionFromImplToHeader
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config //@.config
filename=A.cpp filename=A.cpp

View file

@ -107,7 +107,6 @@ class A {
// Top comment // Top comment
template<typename T> template<typename T>
T member(); T member();
}; };
// Top comment // Top comment

View file

@ -21,8 +21,6 @@ class A {
return T(); return T();
} }
}; };
//!HeaderToClassRetainTopComments //!HeaderToClassRetainTopComments
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config //@.config
@ -44,18 +42,14 @@ inline T A<T>::member() {
//= //=
template<typename T> template<typename T>
class A { class A {
// Third comment
// Fourth comment
// First comment // First comment
// Second comment // Second comment
// Third comment
// Fourth comment
T member() { T member() {
return T(); return T();
} }
}; };
//!HeaderToClassTryCatchComment //!HeaderToClassTryCatchComment
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config //@.config
@ -93,8 +87,6 @@ class A {
// Catch 2 // Catch 2
} }
}; };
//!HeaderToClassMultiTemplateComment //!HeaderToClassMultiTemplateComment
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config //@.config
@ -123,11 +115,7 @@ class A {
// body comment // body comment
return T(); return T();
} }
}; };
// 2nd Top Comment
//!HeaderToClassBodyComment //!HeaderToClassBodyComment
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config //@.config
@ -151,6 +139,3 @@ class A {
return T(); return T();
} }
}; };

View file

@ -15,8 +15,6 @@ inline void A::member() {
class A { class A {
void member(); void member();
}; };
//@A.cpp //@A.cpp
#include "A.h" #include "A.h"
//= //=
@ -44,8 +42,6 @@ catch /*3*/ (int e) { /*4*/ }
class A { class A {
void member(); void member();
}; };
//@A.cpp //@A.cpp
#include "A.h" #include "A.h"
//= //=
@ -80,9 +76,6 @@ inline void A::member() {
class A { class A {
void member(); void member();
}; };
//@A.cpp //@A.cpp
#include "A.h" #include "A.h"
//= //=
@ -105,10 +98,8 @@ void /*$*/member/*$$*/() {
//= //=
// Definition comment // Definition comment
void member(); void member();
//@A.cpp //@A.cpp
#include "A.h" #include "A.h"
//= //=
#include "A.h" #include "A.h"

View file

@ -11,8 +11,6 @@ void A::/*$*/member/*$$*/() {
} }
//= //=
#include "A.h" #include "A.h"
//@A.h //@A.h
class A { class A {
void member(); void member();
@ -37,9 +35,6 @@ void A::/*$*/member/*$$*/() {
} }
//= //=
#include "A.h" #include "A.h"
// Definition comment
//@A.h //@A.h
class A { class A {
void member(); void member();
@ -64,9 +59,6 @@ void A::/*$*/member/*$$*/() try {
} /*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"
// Definition comment
//@A.h //@A.h
class A { class A {
void member(); void member();
@ -98,8 +90,6 @@ void /*$*/member/*$$*/() {
} }
//= //=
#include "A.h" #include "A.h"
//@A.h //@A.h
//= //=
@ -122,9 +112,6 @@ void /*$*/member/*$$*/() {
} }
//= //=
#include "A.h" #include "A.h"
// Top comment
//@A.h //@A.h
//= //=

View file

@ -69,8 +69,6 @@ public:
~A() { ~A() {
} }
}; };
//@A.cpp //@A.cpp
#include "A.h" #include "A.h"
@ -105,8 +103,6 @@ int main() {
//= //=
#include "A.h" #include "A.h"
int main() { int main() {
return 0; return 0;
} }
@ -188,8 +184,6 @@ private:
public: public:
~A(); ~A();
}; };
//@A.cpp //@A.cpp
#include "A.h" #include "A.h"
@ -225,8 +219,6 @@ int main() {
//= //=
#include "A.h" #include "A.h"
int main() { int main() {
return 0; return 0;
} }

View file

@ -41,8 +41,6 @@ inline void /*$*/A::member/*$$*/(int a, int b) {
class A { class A {
void member(int a = 0, int b = 0); void member(int a = 0, int b = 0);
}; };
//@A.cpp //@A.cpp
#include "A.h" #include "A.h"
@ -77,8 +75,6 @@ int main() {
//= //=
#include "A.h" #include "A.h"
int main() { int main() {
return 0; return 0;
} }

View file

@ -18,8 +18,6 @@ void N::A::/*$*/foo/*$$*/() {
int main() { int main() {
return 0; return 0;
} }
//@A.h //@A.h
#include <iostream> #include <iostream>
#include <exception> #include <exception>
@ -90,5 +88,3 @@ void N::A::foo() {
int main() { int main() {
return 0; return 0;
} }

View file

@ -38,7 +38,6 @@ public:
}; };
int freeFunction(int* a, int& b); int freeFunction(int* a, int& b);
//@A.cpp //@A.cpp
#include "A.h" #include "A.h"
@ -76,8 +75,6 @@ int /*$*/freeFunction/*$$*/(int* a, int& b) {
int main() { int main() {
return 0; return 0;
} }
//@A.h //@A.h
#include <iostream> #include <iostream>
@ -114,7 +111,6 @@ public:
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
@ -132,14 +128,13 @@ try {
} }
catch (std::exception& e) { catch (std::exception& e) {
} }
//= //=
#include "A.h" #include "A.h"
int main() { int main() {
return 0; return 0;
} }
//@A.h //@A.h
#include <iostream> #include <iostream>
@ -155,7 +150,6 @@ public:
~A() { ~A() {
} }
}; };
//= //=
#include <iostream> #include <iostream>
@ -179,7 +173,6 @@ try {
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
@ -190,7 +183,6 @@ int /*$*/freeFunction/*$$*/() {
} }
//= //=
int freeFunction(); int freeFunction();
//@A.cpp //@A.cpp
#include "A.h" #include "A.h"
//= //=

View file

@ -132,6 +132,7 @@ 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
@ -163,8 +164,6 @@ class A {
}; };
} }
//@A.cpp //@A.cpp
#include "A.h" #include "A.h"
@ -203,8 +202,6 @@ int main() {
//= //=
#include "A.h" #include "A.h"
int main() { int main() {
return 0; return 0;
} }
@ -246,8 +243,6 @@ void /*$*/A::foo/*$$*/() {
} }
//= //=
#include "A.h" #include "A.h"
//@A.h //@A.h
#include <iostream> #include <iostream>

View file

@ -49,8 +49,6 @@ class A {
void member(int a, int b); void member(int a, int b);
}; };
}; };
//@A.cpp //@A.cpp
#include "A.h" #include "A.h"
@ -88,8 +86,6 @@ void A::B::/*$*/member/*$$*/(int a, int b) {
int main() { int main() {
return 0; return 0;
} }
//@A.h //@A.h
#include <iostream> #include <iostream>

View file

@ -59,7 +59,6 @@ public:
inline void A::/*$*/func2/*$$*/() { inline void A::/*$*/func2/*$$*/() {
return; return;
} }
//= //=
#include <iostream> #include <iostream>
@ -71,9 +70,6 @@ public:
void func4() { void func4() {
} }
}; };
//@A.cpp //@A.cpp
#include "A.h" #include "A.h"
@ -201,8 +197,6 @@ template<typename T>
inline void A<T>::func1() { inline void A<T>::func1() {
} }
template<typename T> template<typename T>
inline void A<T>::func3() { inline void A<T>::func3() {
} }

View file

@ -57,8 +57,6 @@ public:
private: private:
int a; int a;
}; };
//@A.cpp //@A.cpp
#include "A.h" #include "A.h"
@ -93,8 +91,6 @@ int main() {
//= //=
#include "A.h" #include "A.h"
int main() { int main() {
return 0; return 0;
} }
@ -137,8 +133,6 @@ int main() {
//= //=
#include "MyClass.h" #include "MyClass.h"
int main() { int main() {
return 0; return 0;
} }
@ -175,24 +169,18 @@ int main() {
//= //=
#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

@ -57,8 +57,6 @@ class A {
} }
}; };
}; };
//!TestTemplateFunctionInHeaderToInClassWithTemplateSelected //!TestTemplateFunctionInHeaderToInClassWithTemplateSelected
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest //#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config //@.config
@ -74,7 +72,6 @@ class A {
class A { class A {
template<typename T> template<typename T>
T foo(); T foo();
}; };
template<typename T> template<typename T>
@ -101,7 +98,6 @@ 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 T, typename S>
@ -135,7 +131,4 @@ public:
void foo(const U& u, const V& v) { void foo(const U& u, const V& v) {
return; return;
} }
}; };

View file

@ -57,8 +57,6 @@ catch (std::exception& e1) {
class A { class A {
void member(int a, int b); void member(int a, int b);
}; };
//@A.cpp //@A.cpp
#include "A.h" #include "A.h"
@ -103,8 +101,6 @@ int main() {
#include <exception> #include <exception>
#include "A.h" #include "A.h"
int main() { int main() {
return 0; return 0;
} }
@ -194,8 +190,6 @@ catch (std::exception& e2) {
class A { class A {
void member(int a, int b); void member(int a, int b);
}; };
//@A.cpp //@A.cpp
#include "A.h" #include "A.h"
@ -246,8 +240,6 @@ int main() {
#include <exception> #include <exception>
#include "A.h" #include "A.h"
int main() { int main() {
return 0; return 0;
} }

View file

@ -25,7 +25,6 @@ inline int A::foo() {
//@.config //@.config
filename=A.h filename=A.h
//@A.h //@A.h
class A { class A {
virtual int /*$*/foo/*$$*/(); virtual int /*$*/foo/*$$*/();
}; };
@ -34,12 +33,9 @@ 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"
@ -62,12 +58,10 @@ int A::foo() {
//@.config //@.config
filename=A.h 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;
@ -89,5 +83,3 @@ int A::foo() {
int main() { int main() {
return 0; return 0;
} }

View file

@ -556,12 +556,12 @@ public class CodeFormatterTest extends BaseUITestCase {
//} //}
//typedef signed int TInt; //typedef signed int TInt;
//extern void Bar(); // should not have space between parens //extern void Bar(); // should not have space between parens
// //
//void Foo() // should not have space between parens //void Foo() // should not have space between parens
// { // {
// TInt a( 3 ); // should become TInt a( 3 ); // TInt a( 3 ); // should become TInt a( 3 );
// Bar(); // should not have space between parens // Bar(); // should not have space between parens
// } // }
public void testSpaceBetweenParen_Bug217918() throws Exception { public void testSpaceBetweenParen_Bug217918() throws Exception {
fOptions.put(DefaultCodeFormatterConstants.FORMATTER_BRACE_POSITION_FOR_METHOD_DECLARATION, fOptions.put(DefaultCodeFormatterConstants.FORMATTER_BRACE_POSITION_FOR_METHOD_DECLARATION,
@ -893,9 +893,9 @@ public class CodeFormatterTest extends BaseUITestCase {
//namespace ns1 { //namespace ns1 {
//namespace ns2 { //namespace ns2 {
//void foo() { //void foo() {
// int x; // comment // int x;// comment
// int y; // comment // int y;// comment
// // continuation of the previous comment // // continuation of the previous comment
//// int z; <- comments starting from the beginning of line are not indented //// int z; <- comments starting from the beginning of line are not indented
//} //}
//}// namespace ns2 //}// namespace ns2
@ -914,6 +914,7 @@ public class CodeFormatterTest extends BaseUITestCase {
public void testLineCommentMinDistanceFromCode() throws Exception { public void testLineCommentMinDistanceFromCode() throws Exception {
fOptions.put(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, CCorePlugin.SPACE); fOptions.put(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, CCorePlugin.SPACE);
fOptions.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_MIN_DISTANCE_BETWEEN_CODE_AND_LINE_COMMENT, "2"); fOptions.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_MIN_DISTANCE_BETWEEN_CODE_AND_LINE_COMMENT, "2");
fOptions.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_PRESERVE_WHITE_SPACE_BETWEEN_CODE_AND_LINE_COMMENT, DefaultCodeFormatterConstants.FALSE);
assertFormatterResult(); assertFormatterResult();
} }

View file

@ -77,6 +77,7 @@ public final class SourceHeaderPartnerFinder {
private static class PartnerFileComputer implements ASTRunnable { private static class PartnerFileComputer implements ASTRunnable {
PartnerFileVisitor fVisitor = null; PartnerFileVisitor fVisitor = null;
@Override
public IStatus runOnAST(ILanguage lang, IASTTranslationUnit ast) { public IStatus runOnAST(ILanguage lang, IASTTranslationUnit ast) {
if (ast != null && ast.getIndex() != null) { if (ast != null && ast.getIndex() != null) {
fVisitor = new PartnerFileVisitor(); fVisitor = new PartnerFileVisitor();
@ -86,7 +87,7 @@ public final class SourceHeaderPartnerFinder {
} }
public IPath getPartnerFileLocation() { public IPath getPartnerFileLocation() {
if(fVisitor != null) { if (fVisitor != null) {
return fVisitor.getPartnerFileLocation(); return fVisitor.getPartnerFileLocation();
} }
@ -120,6 +121,7 @@ public final class SourceHeaderPartnerFinder {
shouldVisitDeclarators= true; shouldVisitDeclarators= true;
shouldVisitTranslationUnit = true; shouldVisitTranslationUnit = true;
} }
public PartnerFileVisitor() { public PartnerFileVisitor() {
fMap= new HashMap<IPath, Counter>(); fMap= new HashMap<IPath, Counter>();
} }
@ -127,7 +129,7 @@ public final class SourceHeaderPartnerFinder {
@Override @Override
public int visit(IASTTranslationUnit tu) { public int visit(IASTTranslationUnit tu) {
fIndex= tu.getIndex(); fIndex= tu.getIndex();
if(fIndex == null) { if (fIndex == null) {
return PROCESS_ABORT; return PROCESS_ABORT;
} }
@ -212,6 +214,7 @@ public final class SourceHeaderPartnerFinder {
private static IFile findInContainer(IContainer container, final String basename) { private static IFile findInContainer(IContainer container, final String basename) {
final IFile[] result= { null }; final IFile[] result= { null };
IResourceProxyVisitor visitor= new IResourceProxyVisitor() { IResourceProxyVisitor visitor= new IResourceProxyVisitor() {
@Override
public boolean visit(IResourceProxy proxy) throws CoreException { public boolean visit(IResourceProxy proxy) throws CoreException {
if (result[0] != null) { if (result[0] != null) {
return false; return false;
@ -227,8 +230,8 @@ public final class SourceHeaderPartnerFinder {
}}; }};
try { try {
container.accept(visitor, 0); container.accept(visitor, 0);
} catch (CoreException exc) { } catch (CoreException e) {
// ignore // Ignore
} }
return result[0]; return result[0];
} }

View file

@ -38,7 +38,7 @@ import org.eclipse.cdt.internal.ui.refactoring.utils.VisibilityEnum;
* @author Mirko Stocker * @author Mirko Stocker
*/ */
public class AddDeclarationNodeToClassChange { public class AddDeclarationNodeToClassChange {
private final ICPPASTCompositeTypeSpecifier nodeClass; private final ICPPASTCompositeTypeSpecifier classNode;
private final VisibilityEnum visibility; private final VisibilityEnum visibility;
private List<IASTNode> fieldNodes = new ArrayList<IASTNode>(); private List<IASTNode> fieldNodes = new ArrayList<IASTNode>();
private final ModificationCollector collector; private final ModificationCollector collector;
@ -49,26 +49,26 @@ public class AddDeclarationNodeToClassChange {
new AddDeclarationNodeToClassChange(nodeClass, visibility, fieldNodes, collector, isField); new AddDeclarationNodeToClassChange(nodeClass, visibility, fieldNodes, collector, isField);
} }
public static void createChange(ICPPASTCompositeTypeSpecifier nodeClass, public static void createChange(ICPPASTCompositeTypeSpecifier classNode,
VisibilityEnum visibility, List<IASTNode> fieldNodes, boolean isField, VisibilityEnum visibility, List<IASTNode> fieldNodes, boolean isField,
ModificationCollector collector) { ModificationCollector collector) {
new AddDeclarationNodeToClassChange(nodeClass, visibility, fieldNodes, collector, isField); new AddDeclarationNodeToClassChange(classNode, visibility, fieldNodes, collector, isField);
} }
private AddDeclarationNodeToClassChange(ICPPASTCompositeTypeSpecifier nodeClass, private AddDeclarationNodeToClassChange(ICPPASTCompositeTypeSpecifier classNode,
VisibilityEnum visibility, List<IASTNode> fieldNodes, VisibilityEnum visibility, List<IASTNode> fieldNodes,
ModificationCollector collector, boolean isField) { ModificationCollector collector, boolean isField) {
this.fieldNodes = fieldNodes; this.fieldNodes = fieldNodes;
this.nodeClass = nodeClass; this.classNode = classNode;
this.visibility = visibility; this.visibility = visibility;
this.collector = collector; this.collector = collector;
createRewrites(isField); createRewrites(isField);
} }
private AddDeclarationNodeToClassChange(ICPPASTCompositeTypeSpecifier nodeClass, private AddDeclarationNodeToClassChange(ICPPASTCompositeTypeSpecifier classNode,
VisibilityEnum visibility, IASTNode fieldNodes, ModificationCollector collector, VisibilityEnum visibility, IASTNode fieldNodes, ModificationCollector collector,
boolean isField) { boolean isField) {
this.nodeClass = nodeClass; this.classNode = classNode;
this.visibility = visibility; this.visibility = visibility;
this.fieldNodes.add(fieldNodes); this.fieldNodes.add(fieldNodes);
this.collector = collector; this.collector = collector;
@ -78,12 +78,10 @@ public class AddDeclarationNodeToClassChange {
private void createRewrites(boolean isField) { private void createRewrites(boolean isField) {
int lastFunctionDeclaration = -1; int lastFunctionDeclaration = -1;
int lastFieldDeclaration = -1; int lastFieldDeclaration = -1;
IASTDeclaration[] members = nodeClass.getMembers(); IASTDeclaration[] members = classNode.getMembers();
VisibilityEnum currentVisibility = VisibilityEnum.v_private; VisibilityEnum currentVisibility = classNode.getKey() == IASTCompositeTypeSpecifier.k_struct ?
if (IASTCompositeTypeSpecifier.k_struct == nodeClass.getKey()) { VisibilityEnum.v_public : VisibilityEnum.v_private;
currentVisibility = VisibilityEnum.v_public;
}
// Find the insert location by iterating over the elements of the class // Find the insert location by iterating over the elements of the class
// and remembering the last element with the matching visibility // and remembering the last element with the matching visibility
@ -92,18 +90,13 @@ public class AddDeclarationNodeToClassChange {
if (declaration instanceof ICPPASTVisibilityLabel) { if (declaration instanceof ICPPASTVisibilityLabel) {
currentVisibility = VisibilityEnum.from((ICPPASTVisibilityLabel) declaration); currentVisibility = VisibilityEnum.from((ICPPASTVisibilityLabel) declaration);
} } else if (declaration instanceof IASTSimpleDeclaration && currentVisibility.equals(visibility)) {
if (declaration instanceof IASTSimpleDeclaration) {
IASTSimpleDeclaration simple = (IASTSimpleDeclaration) declaration; IASTSimpleDeclaration simple = (IASTSimpleDeclaration) declaration;
IASTDeclarator[] declarators = simple.getDeclarators(); IASTDeclarator[] declarators = simple.getDeclarators();
if (declarators.length > 0 && declarators[0] != null && if (declarators.length > 0 && declarators[0] != null) {
declarators[0] instanceof IASTFunctionDeclarator) { if (declarators[0] instanceof IASTFunctionDeclarator) {
if (currentVisibility.equals(visibility)) {
lastFunctionDeclaration = i; lastFunctionDeclaration = i;
} } else {
} else if (declarators.length > 0 && declarators[0] != null) {
if (currentVisibility.equals(visibility)) {
lastFieldDeclaration = i; lastFieldDeclaration = i;
} }
} }
@ -142,29 +135,29 @@ public class AddDeclarationNodeToClassChange {
} }
} }
private void insertBefore(IASTNode nearestNode) { private void insertBefore(IASTNode nextNode) {
ASTRewrite rewrite = collector.rewriterForTranslationUnit(nearestNode.getTranslationUnit()); ASTRewrite rewrite = collector.rewriterForTranslationUnit(nextNode.getTranslationUnit());
for (IASTNode node : fieldNodes) { for (IASTNode node : fieldNodes) {
rewrite.insertBefore(nearestNode.getParent(), nearestNode, node, createEditDescription()); rewrite.insertBefore(nextNode.getParent(), nextNode, node, createEditDescription());
} }
} }
private void insertAtTheEnd(VisibilityEnum currentVisibility) { private void insertAtTheEnd(VisibilityEnum currentVisibility) {
ASTRewrite rewrite = collector.rewriterForTranslationUnit(nodeClass.getTranslationUnit()); ASTRewrite rewrite = collector.rewriterForTranslationUnit(classNode.getTranslationUnit());
if (!currentVisibility.equals(visibility)) { if (!currentVisibility.equals(visibility)) {
ICPPASTVisibilityLabel label = ICPPASTVisibilityLabel label =
new CPPASTVisibilityLabel(visibility.getICPPASTVisiblityLabelVisibility()); new CPPASTVisibilityLabel(visibility.getICPPASTVisiblityLabelVisibility());
rewrite.insertBefore(nodeClass, null, label, createEditDescription()); rewrite.insertBefore(classNode, null, label, createEditDescription());
} }
for (IASTNode node : fieldNodes) { for (IASTNode node : fieldNodes) {
rewrite.insertBefore(nodeClass, null, node, createEditDescription()); rewrite.insertBefore(classNode, null, node, createEditDescription());
} }
} }
private TextEditGroup createEditDescription() { private TextEditGroup createEditDescription() {
return new TextEditGroup(NLS.bind(Messages.AddDeclarationNodeToClassChange_AddDeclaration, return new TextEditGroup(NLS.bind(Messages.AddDeclarationNodeToClassChange_AddDeclaration,
nodeClass.getName())); classNode.getName()));
} }
} }

View file

@ -7,14 +7,14 @@
# http://www.eclipse.org/legal/epl-v10.html # http://www.eclipse.org/legal/epl-v10.html
# #
# Contributors: # Contributors:
# Martin Schwab & Thomas Kallenberg - initial API and implementation # Martin Schwab & Thomas Kallenberg - initial API and implementation
############################################################################### ###############################################################################
DeclaratorFinder_NestedFunction=Nested function declarations not supported DeclaratorFinder_NestedFunction=Nested function declarations not supported
DeclaratorFinder_NoDeclarator=cannot work without declarator DeclaratorFinder_NoDeclarator=Cannot work without declarator
DeclaratorFinder_MultipleDeclarators=cannot work with multiple declarators DeclaratorFinder_MultipleDeclarators=Cannot work with multiple declarators
RefactoringJob_UndoName=toggle function definition RefactoringJob_UndoName=Toggle function definition
ToggleFileCreator_andMove=\ and move ToggleFileCreator_andMove=\ and move
ToggleFileCreator_CanNotCreateNewFile=Cannot create new filechange ToggleFileCreator_CanNotCreateNewFile=Cannot create new file change
ToggleFileCreator_CreateNewFile=Create a new file named: ToggleFileCreator_CreateNewFile=Create a new file named:
ToggleFileCreator_NewImplFile=New Implementation file? ToggleFileCreator_NewImplFile=New Implementation file?
ToggleFileCreator_NoTuForSibling=Cannot find translation unit for sibling file ToggleFileCreator_NoTuForSibling=Cannot find translation unit for sibling file
@ -22,18 +22,18 @@ ToggleFileCreator_QMark=?
ToggleFromClassToInHeaderStrategy_DefAndDecInsideClass=Definition and Declaration both inside class. Behavior is undefined. ToggleFromClassToInHeaderStrategy_DefAndDecInsideClass=Definition and Declaration both inside class. Behavior is undefined.
ToggleFromImplementationToHeaderOrClassStrategy_CanNotCreateNewFile=Cannot create new File ToggleFromImplementationToHeaderOrClassStrategy_CanNotCreateNewFile=Cannot create new File
ToggleFromImplementationToHeaderOrClassStrategy_CanNotToggle=Not a free function. Cannot decide where to toggle ToggleFromImplementationToHeaderOrClassStrategy_CanNotToggle=Not a free function. Cannot decide where to toggle
ToggleFromInHeaderToClassStrategy_CanNotToggleTemplateFreeFunction=Cannot toggle templated free function ToggleFromInHeaderToClassStrategy_CanNotToggleTemplateFreeFunction=Cannot toggle template free function
EditGroupName=Toggle function body placement EditGroupName=Toggle function body placement
ToggleFromInHeaderToImplementationStrategy_CanNotCreateImplFile=Cannot create new Implementation File ToggleFromInHeaderToImplementationStrategy_CanNotCreateImplFile=Cannot create new Implementation File
ToggleRefactoring_AnalyseSelection=analyzing user text selection ToggleRefactoring_AnalyseSelection=analyzing user text selection
ToggleRefactoring_CalculateModifications=calculating required code modifications ToggleRefactoring_CalculateModifications=calculating required code modifications
ToggleRefactoring_CanNotSaveFiles=Cannot save files ToggleRefactoring_CanNotSaveFiles=Cannot save files
ToggleRefactoring_InvalidSelection=Invalid selection ToggleRefactoring_InvalidSelection=Invalid selection
ToggleRefactoring_NoIndex=cannot work without the indexer ToggleRefactoring_NoIndex=Cannot work without the index
ToggleRefactoring_WaitingForIndexer=waiting for indexer ToggleRefactoring_WaitingForIndexer=waiting for indexer
ToggleRefactoringContext_MultipleDeclarations=multiple declarations would result in ambiguous results ToggleRefactoringContext_MultipleDeclarations=Multiple declarations would result in ambiguous results
ToggleRefactoringContext_MultipleDefinitions=one-definition-rule broken ToggleRefactoringContext_MultipleDefinitions=One-definition-rule broken
ToggleRefactoringContext_NoDefinitionFound=cannot work without definition ToggleRefactoringContext_NoDefinitionFound=Cannot work without definition
ToggleRefactoringContext_NoTuFound=cannot work without translation unit ToggleRefactoringContext_NoTuFound=Cannot work without translation unit
ToggleStrategyFactory_NoDefinitionFound=cannot work without function definition ToggleStrategyFactory_NoDefinitionFound=Cannot work without function definition
ToggleStrategyFactory_UnsupportedSituation=Unsupported situation for moving function body. ToggleStrategyFactory_UnsupportedSituation=Unsupported situation for moving function body.

View file

@ -7,7 +7,7 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* Martin Schwab & Thomas Kallenberg - initial API and implementation * Martin Schwab & Thomas Kallenberg - initial API and implementation
******************************************************************************/ ******************************************************************************/
package org.eclipse.cdt.internal.ui.refactoring.togglefunction; package org.eclipse.cdt.internal.ui.refactoring.togglefunction;
@ -70,7 +70,6 @@ import org.eclipse.cdt.internal.ui.refactoring.ModificationCollector;
import org.eclipse.cdt.internal.ui.refactoring.utils.NodeHelper; import org.eclipse.cdt.internal.ui.refactoring.utils.NodeHelper;
public class ToggleNodeHelper extends NodeHelper { public class ToggleNodeHelper extends NodeHelper {
private static final String EMPTY_STRING = ""; //$NON-NLS-1$ private static final String EMPTY_STRING = ""; //$NON-NLS-1$
private static void removeParameterInitializations(IASTFunctionDeclarator funcDecl) { private static void removeParameterInitializations(IASTFunctionDeclarator funcDecl) {
@ -85,7 +84,7 @@ public class ToggleNodeHelper extends NodeHelper {
private static ArrayList<ICPPASTConstructorChainInitializer> private static ArrayList<ICPPASTConstructorChainInitializer>
getInitializerList(IASTFunctionDefinition definition) { getInitializerList(IASTFunctionDefinition definition) {
ArrayList<ICPPASTConstructorChainInitializer> initalizers = ArrayList<ICPPASTConstructorChainInitializer> initalizers =
new ArrayList<ICPPASTConstructorChainInitializer>(); new ArrayList<ICPPASTConstructorChainInitializer>();
for (IASTNode node : definition.getChildren()) { for (IASTNode node : definition.getChildren()) {
if (node instanceof ICPPASTConstructorChainInitializer) { if (node instanceof ICPPASTConstructorChainInitializer) {
@ -145,8 +144,7 @@ public class ToggleNodeHelper extends NodeHelper {
IASTTranslationUnit definitionUnit, IASTNode nameSpace) { IASTTranslationUnit definitionUnit, IASTNode nameSpace) {
ICPPASTDeclSpecifier newDeclSpec = ICPPASTDeclSpecifier newDeclSpec =
(ICPPASTDeclSpecifier) oldDefinition.getDeclSpecifier().copy( (ICPPASTDeclSpecifier) oldDefinition.getDeclSpecifier().copy(CopyStyle.withLocations);
CopyStyle.withLocations);
newDeclSpec.setVirtual(false); newDeclSpec.setVirtual(false);
newDeclSpec.setInline(true); newDeclSpec.setInline(true);
@ -157,7 +155,7 @@ public class ToggleNodeHelper extends NodeHelper {
removeParameterInitializations(newDeclarator); removeParameterInitializations(newDeclarator);
ICPPASTFunctionDefinition newFunction = ICPPASTFunctionDefinition newFunction =
createFunctionSignatureWithEmptyBody(newDeclSpec, newDeclarator, oldDefinition); createFunctionSignatureWithEmptyBody(newDeclSpec, newDeclarator, oldDefinition);
return newFunction; return newFunction;
} }
@ -172,7 +170,7 @@ public class ToggleNodeHelper extends NodeHelper {
ArrayList<ICPPASTTemplateDeclaration> templdecs, IASTFunctionDefinition newfunc) { ArrayList<ICPPASTTemplateDeclaration> templdecs, IASTFunctionDefinition newfunc) {
ListIterator<ICPPASTTemplateDeclaration> iter1 = templdecs.listIterator(); ListIterator<ICPPASTTemplateDeclaration> iter1 = templdecs.listIterator();
ICPPASTTemplateDeclaration child = null; ICPPASTTemplateDeclaration child = null;
while(iter1.hasNext()) { while (iter1.hasNext()) {
child = iter1.next(); child = iter1.next();
child.setDeclaration(newfunc); child.setDeclaration(newfunc);
ListIterator<ICPPASTTemplateDeclaration> iter2 = iter1; ListIterator<ICPPASTTemplateDeclaration> iter2 = iter1;
@ -198,10 +196,8 @@ public class ToggleNodeHelper extends NodeHelper {
return templdecs; return templdecs;
} }
static IASTFunctionDefinition createInClassDefinition( static IASTFunctionDefinition createInClassDefinition(IASTFunctionDeclarator dec,
IASTFunctionDeclarator dec, IASTFunctionDefinition def, IASTTranslationUnit insertionunit) {
IASTFunctionDefinition def,
IASTTranslationUnit insertionunit) {
IASTFunctionDeclarator declarator = dec.copy(CopyStyle.withLocations); IASTFunctionDeclarator declarator = dec.copy(CopyStyle.withLocations);
ICPPASTDeclSpecifier declSpec = (ICPPASTDeclSpecifier) def.getDeclSpecifier().copy( ICPPASTDeclSpecifier declSpec = (ICPPASTDeclSpecifier) def.getDeclSpecifier().copy(
CopyStyle.withLocations); CopyStyle.withLocations);
@ -233,8 +229,9 @@ public class ToggleNodeHelper extends NodeHelper {
static IASTNode getParentRemovePoint(IASTFunctionDefinition definition) { static IASTNode getParentRemovePoint(IASTFunctionDefinition definition) {
IASTNode toremove = definition; IASTNode toremove = definition;
while (toremove.getParent() != null && while (toremove.getParent() != null &&
toremove.getParent() instanceof ICPPASTTemplateDeclaration) toremove.getParent() instanceof ICPPASTTemplateDeclaration) {
toremove = toremove.getParent(); toremove = toremove.getParent();
}
return toremove; return toremove;
} }
@ -252,15 +249,13 @@ public class ToggleNodeHelper extends NodeHelper {
private static CPPASTQualifiedName reAssembleQualifiedName(Stack<IASTNode> nodes) { private static CPPASTQualifiedName reAssembleQualifiedName(Stack<IASTNode> nodes) {
CPPASTQualifiedName qName = new CPPASTQualifiedName(); CPPASTQualifiedName qName = new CPPASTQualifiedName();
while(!nodes.isEmpty()) { while (!nodes.isEmpty()) {
IASTNode nnode = nodes.pop(); IASTNode nnode = nodes.pop();
if (nnode instanceof IASTCompositeTypeSpecifier) { if (nnode instanceof IASTCompositeTypeSpecifier) {
qName.addName(((IASTCompositeTypeSpecifier) nnode).getName()); qName.addName(((IASTCompositeTypeSpecifier) nnode).getName());
} } else if (nnode instanceof ICPPASTNamespaceDefinition) {
else if (nnode instanceof ICPPASTNamespaceDefinition) {
qName.addName(((ICPPASTNamespaceDefinition) nnode).getName()); qName.addName(((ICPPASTNamespaceDefinition) nnode).getName());
} } else if (nnode instanceof ICPPASTTemplateId) {
else if (nnode instanceof ICPPASTTemplateId) {
qName.addName((ICPPASTTemplateId) nnode); qName.addName((ICPPASTTemplateId) nnode);
} }
} }
@ -271,17 +266,15 @@ public class ToggleNodeHelper extends NodeHelper {
IASTFunctionDeclarator declarator, IASTNode limiter, IASTNode node) { IASTFunctionDeclarator declarator, IASTNode limiter, IASTNode node) {
IASTName lastName = declarator.getName(); IASTName lastName = declarator.getName();
Stack<IASTNode> nodes = new Stack<IASTNode>(); Stack<IASTNode> nodes = new Stack<IASTNode>();
while(node.getParent() != null && node.getParent() != limiter) { while (node.getParent() != null && node.getParent() != limiter) {
node = node.getParent(); node = node.getParent();
if (node instanceof IASTCompositeTypeSpecifier) { if (node instanceof IASTCompositeTypeSpecifier) {
nodes.push(((IASTCompositeTypeSpecifier) node).copy(CopyStyle.withLocations)); nodes.push(((IASTCompositeTypeSpecifier) node).copy(CopyStyle.withLocations));
lastName = ((IASTCompositeTypeSpecifier) node).getName(); lastName = ((IASTCompositeTypeSpecifier) node).getName();
} } else if (node instanceof ICPPASTNamespaceDefinition) {
else if (node instanceof ICPPASTNamespaceDefinition) {
nodes.push(((ICPPASTNamespaceDefinition) node).copy(CopyStyle.withLocations)); nodes.push(((ICPPASTNamespaceDefinition) node).copy(CopyStyle.withLocations));
lastName = ((ICPPASTNamespaceDefinition) node).getName(); lastName = ((ICPPASTNamespaceDefinition) node).getName();
} } else if (shouldAddTemplateBrackets(node)) {
else if (shouldAddTemplateBrackets(node)) {
if (!nodes.isEmpty()) if (!nodes.isEmpty())
nodes.pop(); nodes.pop();
ICPPASTTemplateId templateID = ToggleNodeHelper.getTemplateParameter(node, lastName); ICPPASTTemplateId templateID = ToggleNodeHelper.getTemplateParameter(node, lastName);
@ -315,40 +308,48 @@ public class ToggleNodeHelper extends NodeHelper {
return templateID; return templateID;
} }
static IASTTranslationUnit getSiblingFile(IFile file, IASTTranslationUnit asttu) throws CoreException { /**
* @deprecated Use SourceHeaderPartnerHelper
*/
@Deprecated
static IASTTranslationUnit getSiblingFile(IFile file, IASTTranslationUnit ast) throws CoreException {
ICProject cProject = CoreModel.getDefault().create(file).getCProject(); ICProject cProject = CoreModel.getDefault().create(file).getCProject();
ICProject[] projects = CoreModel.getDefault().getCModel().getCProjects(); ICProject[] projects = CoreModel.getDefault().getCModel().getCProjects();
IIndex projectIndex = CCorePlugin.getIndexManager().getIndex(projects); IIndex projectIndex = CCorePlugin.getIndexManager().getIndex(projects);
try { try {
projectIndex.acquireReadLock(); projectIndex.acquireReadLock();
IIndexFile thisFile = projectIndex.getFile(asttu.getLinkage().getLinkageID(), IIndexFile[] thisFileVariants = projectIndex.getFiles(ast.getLinkage().getLinkageID(),
IndexLocationFactory.getWorkspaceIFL(file)); IndexLocationFactory.getWorkspaceIFL(file));
String fileName = ToggleNodeHelper.getFilenameWithoutExtension( String fileName = ToggleNodeHelper.getFilenameWithoutExtension(
file.getFullPath().toString()); file.getFullPath().toString());
if (asttu.isHeaderUnit()) { if (ast.isHeaderUnit()) {
for (IIndexInclude include : projectIndex.findIncludedBy(thisFile)) { for (IIndexFile thisFile : thisFileVariants) {
if (ToggleNodeHelper.getFilenameWithoutExtension(include.getIncludedBy().getLocation().getFullPath()).equals(fileName)) { for (IIndexInclude include : projectIndex.findIncludedBy(thisFile)) {
ITranslationUnit tu = CoreModelUtil.findTranslationUnitForLocation(include.getIncludedBy().getLocation().getURI(), cProject); if (ToggleNodeHelper.getFilenameWithoutExtension(include.getIncludedBy().getLocation().getFullPath()).equals(fileName)) {
return tu.getAST(projectIndex, ITranslationUnit.AST_SKIP_ALL_HEADERS); ITranslationUnit tu = CoreModelUtil.findTranslationUnitForLocation(include.getIncludedBy().getLocation().getURI(), cProject);
return tu.getAST(projectIndex, ITranslationUnit.AST_SKIP_ALL_HEADERS);
}
} }
} }
} else { } else {
for (IIndexInclude include : projectIndex.findIncludes(thisFile)) { for (IIndexFile thisFile : thisFileVariants) {
if (ToggleNodeHelper.getFilenameWithoutExtension(include.getFullName()).equals(fileName)) { for (IIndexInclude include : projectIndex.findIncludes(thisFile)) {
if (include.getIncludesLocation() == null){ if (ToggleNodeHelper.getFilenameWithoutExtension(include.getFullName()).equals(fileName)) {
throw new NotSupportedException("The include file does not exist"); //$NON-NLS-1$ if (include.getIncludesLocation() == null){
throw new NotSupportedException("The include file does not exist"); //$NON-NLS-1$
}
String loc = include.getIncludesLocation().getFullPath();
ICElement tufile = CoreModel.getDefault().create(new Path(loc));
if (tufile instanceof TranslationUnit) {
return ((TranslationUnit) tufile).getAST(null, ITranslationUnit.AST_SKIP_ALL_HEADERS);
}
} }
String loc = include.getIncludesLocation().getFullPath();
ICElement tufile = CoreModel.getDefault().create(new Path(loc));
if (tufile instanceof TranslationUnit) {
return ((TranslationUnit) tufile).getAST(null, ITranslationUnit.AST_SKIP_ALL_HEADERS);
}
} }
} }
} }
}catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace(); // Ignore
} finally { } finally {
projectIndex.releaseReadLock(); projectIndex.releaseReadLock();
} }
@ -403,16 +404,16 @@ public class ToggleNodeHelper extends NodeHelper {
ModificationCollector modifications) { ModificationCollector modifications) {
String leadingComments = getCommentsAsString(getLeadingCommentsFromNode(oldDefinition.getBody(), String leadingComments = getCommentsAsString(getLeadingCommentsFromNode(oldDefinition.getBody(),
oldUnit, modifications)); oldUnit, modifications));
String trailingComments = getCommentsAsString(getTrailingComments(oldDefinition.getBody(), oldUnit, String trailingComments = getCommentsAsString(getTrailingComments(oldDefinition.getBody(),
modifications)); oldUnit, modifications));
return leadingComments + oldDefinition.getBody().getRawSignature() + trailingComments; return leadingComments + oldDefinition.getBody().getRawSignature() + trailingComments;
} }
private static String getCatchHandlers(IASTFunctionDefinition oldDefinition, IASTTranslationUnit oldUnit, private static String getCatchHandlers(IASTFunctionDefinition oldDefinition, IASTTranslationUnit oldUnit,
ModificationCollector modifications) { ModificationCollector modifications) {
if (oldDefinition instanceof ICPPASTFunctionWithTryBlock) { if (oldDefinition instanceof ICPPASTFunctionWithTryBlock) {
ICPPASTCatchHandler[] oldCatches = ((ICPPASTFunctionWithTryBlock) oldDefinition) ICPPASTCatchHandler[] oldCatches =
.getCatchHandlers(); ((ICPPASTFunctionWithTryBlock) oldDefinition).getCatchHandlers();
String allCatchHandlers = ""; //$NON-NLS-1$ String allCatchHandlers = ""; //$NON-NLS-1$
for (int i = 0; i < oldCatches.length; i++) { for (int i = 0; i < oldCatches.length; i++) {
String lead = getCommentsAsString(getLeadingCommentsFromNode(oldCatches[i], oldUnit, String lead = getCommentsAsString(getLeadingCommentsFromNode(oldCatches[i], oldUnit,
@ -437,16 +438,13 @@ public class ToggleNodeHelper extends NodeHelper {
return rw.getComments(existingNode, CommentPosition.trailing); return rw.getComments(existingNode, CommentPosition.trailing);
} }
public static IASTNode getParentTemplateDeclaration(IASTNode def) {
public static IASTNode getParentTemplateDeclaration(
IASTNode def) {
if (def == null) if (def == null)
return null; return null;
IASTNode lastSeen = def; IASTNode lastSeen = def;
IASTNode node = def.getParent(); IASTNode node = def.getParent();
while (node != null) { while (node != null) {
if (node instanceof ICPPASTTemplateDeclaration || if (node instanceof ICPPASTTemplateDeclaration || node instanceof IASTSimpleDeclaration) {
node instanceof IASTSimpleDeclaration) {
lastSeen = node; lastSeen = node;
node = node.getParent(); node = node.getParent();
continue; continue;
@ -466,7 +464,7 @@ public class ToggleNodeHelper extends NodeHelper {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static <T> T getAncestorOfType(IASTNode node, Class<?> T) { public static <T> T getAncestorOfType(IASTNode node, Class<?> T) {
while(node != null) { while (node != null) {
if (T.isInstance(node)) { if (T.isInstance(node)) {
return (T) node; return (T) node;
} }

View file

@ -7,7 +7,7 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* Martin Schwab & Thomas Kallenberg - initial API and implementation * Martin Schwab & Thomas Kallenberg - initial API and implementation
******************************************************************************/ ******************************************************************************/
package org.eclipse.cdt.internal.ui.refactoring.togglefunction; package org.eclipse.cdt.internal.ui.refactoring.togglefunction;
@ -33,7 +33,6 @@ import org.eclipse.cdt.internal.ui.refactoring.IndexToASTNameHelper;
import org.eclipse.cdt.internal.ui.refactoring.utils.TranslationUnitHelper; import org.eclipse.cdt.internal.ui.refactoring.utils.TranslationUnitHelper;
public class ToggleRefactoringContext { public class ToggleRefactoringContext {
private IASTFunctionDefinition targetDefinition; private IASTFunctionDefinition targetDefinition;
private IASTFunctionDeclarator targetDeclaration; private IASTFunctionDeclarator targetDeclaration;
private IASTTranslationUnit targetDefinitionUnit; private IASTTranslationUnit targetDefinitionUnit;
@ -79,7 +78,7 @@ public class ToggleRefactoringContext {
throw new NotSupportedException( throw new NotSupportedException(
Messages.ToggleRefactoringContext_MultipleDeclarations); Messages.ToggleRefactoringContext_MultipleDeclarations);
for (IIndexName iname : decnames) { for (IIndexName iname : decnames) {
selectionUnit = getTUForNameinFile(iname); selectionUnit = getTUForNameInFile(iname);
IASTName astname = IndexToASTNameHelper.findMatchingASTName( IASTName astname = IndexToASTNameHelper.findMatchingASTName(
selectionUnit, iname, index); selectionUnit, iname, index);
if (astname != null) { if (astname != null) {
@ -100,9 +99,8 @@ public class ToggleRefactoringContext {
throw new NotSupportedException(Messages.ToggleRefactoringContext_MultipleDefinitions); throw new NotSupportedException(Messages.ToggleRefactoringContext_MultipleDefinitions);
} }
for (IIndexName iname : defnames) { for (IIndexName iname : defnames) {
IASTTranslationUnit unit = getTUForNameinFile(iname); IASTTranslationUnit unit = getTUForNameInFile(iname);
IASTName astname = IndexToASTNameHelper.findMatchingASTName( IASTName astname = IndexToASTNameHelper.findMatchingASTName(unit, iname, index);
unit, iname, index);
if (astname != null) { if (astname != null) {
targetDefinition = findFunctionDefinition(astname); targetDefinition = findFunctionDefinition(astname);
targetDefinitionUnit = unit; targetDefinitionUnit = unit;
@ -150,15 +148,14 @@ public class ToggleRefactoringContext {
private void findSelectionUnit() { private void findSelectionUnit() {
try { try {
selectionUnit = TranslationUnitHelper.loadTranslationUnit( selectionUnit = TranslationUnitHelper.loadTranslationUnit(selectionFile, true);
selectionFile, true);
} catch (Exception e) { } catch (Exception e) {
} }
if (selectionUnit == null) if (selectionUnit == null)
throw new NotSupportedException(Messages.ToggleRefactoringContext_NoTuFound); throw new NotSupportedException(Messages.ToggleRefactoringContext_NoTuFound);
} }
private IASTTranslationUnit getTUForNameinFile(IIndexName iname) private IASTTranslationUnit getTUForNameInFile(IIndexName iname)
throws CModelException, CoreException { throws CModelException, CoreException {
if (isSameFileAsInTU(iname)) { if (isSameFileAsInTU(iname)) {
return selectionUnit; return selectionUnit;

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik * Copyright (c) 2008, 2011 Institute for Software, HSR Hochschule fuer Technik
* Rapperswil, University of applied sciences and others * Rapperswil, University of applied sciences and others
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
@ -7,7 +7,7 @@
* http://www.eclipse.org/legal/epl-v10.html * 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.ui.refactoring.utils; package org.eclipse.cdt.internal.ui.refactoring.utils;
@ -22,11 +22,10 @@ import org.eclipse.cdt.core.dom.ast.IASTNode;
* Helper class concerning files. * Helper class concerning files.
* *
* @author Lukas Felber * @author Lukas Felber
*
*/ */
public class FileHelper { public class FileHelper {
public static IFile getIFilefromIASTNode(IASTNode node) { public static IFile getFileFromNode(IASTNode node) {
IPath implPath = new Path(node.getContainingFilename()); IPath implPath = new Path(node.getContainingFilename());
return ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(implPath); return ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(implPath);
} }