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

View file

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

View file

@ -7,7 +7,7 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Institute for Software - initial API and implementation
* Institute for Software - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.append;
@ -16,13 +16,11 @@ import junit.framework.TestSuite;
/**
* @author Thomas Corbat
*
*/
public class AppendTestSuite{
public class AppendTestSuite {
public static Test suite() throws Exception {
TestSuite suite = new TestSuite("Changegenerator Append Child Tests");
TestSuite suite = new TestSuite("ChangeGenerator Append Child Tests");
suite.addTest(ParameterTest.suite());
suite.addTest(ParameterToListTest.suite());
suite.addTest(PointerToParameterTest.suite());
@ -32,7 +30,6 @@ public class AppendTestSuite{
suite.addTest(ArrayModifierTest.suite());
suite.addTest(ExpressionTest.suite());
suite.addTest(ArraySizeExpressionTest.suite());
return suite;
}
}

View file

@ -49,13 +49,14 @@ public class ArrayModifierTest extends ChangeGeneratorTest {
@Override
public int visit(IASTDeclarator declarator) {
if (declarator instanceof IASTArrayDeclarator) {
IASTArrayDeclarator arrayDeclarator = (IASTArrayDeclarator)declarator;
IASTArrayDeclarator arrayDeclarator = (IASTArrayDeclarator) declarator;
arrayDeclarator.getArrayModifiers();
IASTArrayModifier newModifier = new CPPASTArrayModifier();
IASTExpression expr = new CPPASTLiteralExpression(
IASTLiteralExpression.lk_integer_constant, "3".toCharArray()); //$NON-NLS-1$
newModifier.setConstantExpression(expr);
ASTModification modification = new ASTModification(ModificationKind.APPEND_CHILD, declarator, newModifier, null);
ASTModification modification = new ASTModification(ModificationKind.APPEND_CHILD,
declarator, newModifier, null);
modStore.storeModification(null, modification);
}
return PROCESS_CONTINUE;

View file

@ -7,7 +7,7 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Institute for Software - initial API and implementation
* Institute for Software - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.append;
@ -39,8 +39,7 @@ public class ArraySizeExpressionTest extends ChangeGeneratorTest {
}
@Override
protected ASTVisitor createModificator(
final ASTModificationStore modStore) {
protected ASTVisitor createModificator(final ASTModificationStore modStore) {
return new ASTVisitor() {
{
shouldVisitExpressions = true;
@ -53,8 +52,9 @@ public class ArraySizeExpressionTest extends ChangeGeneratorTest {
IASTTypeId id= newExpression.getTypeId();
IASTArrayDeclarator dtor= (IASTArrayDeclarator) id.getAbstractDeclarator();
IASTArrayModifier[] mods= dtor.getArrayModifiers();
IASTArrayModifier add= new CPPASTArrayModifier(new CPPASTLiteralExpression(0, "5"));
ASTModification modification = new ASTModification(ASTModification.ModificationKind.APPEND_CHILD, dtor, add, null);
IASTArrayModifier add= new CPPASTArrayModifier(new CPPASTLiteralExpression(0, "5".toCharArray()));
ASTModification modification = new ASTModification(ASTModification.ModificationKind.APPEND_CHILD,
dtor, add, null);
modStore.storeModification(null, modification);
}
return PROCESS_CONTINUE;

View file

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

View file

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

View file

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

View file

@ -7,7 +7,7 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Institute for Software - initial API and implementation
* Institute for Software - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.append;
@ -34,8 +34,8 @@ public class ParameterTest extends ChangeGeneratorTest {
@Override
protected void setUp() throws Exception {
source = "void foo(int existing){\n}\n\n"; //$NON-NLS-1$
expectedSource = "void foo(int existing, int newParameter){\n}\n\n"; //$NON-NLS-1$
source = "void foo(int existing) {\n}\n"; //$NON-NLS-1$
expectedSource = "void foo(int existing, int newParameter) {\n}\n"; //$NON-NLS-1$
super.setUp();
}
@ -49,7 +49,7 @@ public class ParameterTest extends ChangeGeneratorTest {
@Override
public int visit(IASTDeclarator declarator) {
if (declarator instanceof CPPASTFunctionDeclarator) {
CPPASTFunctionDeclarator functionDeclarator = (CPPASTFunctionDeclarator)declarator;
CPPASTFunctionDeclarator functionDeclarator = (CPPASTFunctionDeclarator) declarator;
CPPASTParameterDeclaration insertedParameter = new CPPASTParameterDeclaration();
CPPASTDeclarator parameterDeclarator = new CPPASTDeclarator();
@ -59,7 +59,8 @@ public class ParameterTest extends ChangeGeneratorTest {
CPPASTSimpleDeclSpecifier parameterDeclSpec = new CPPASTSimpleDeclSpecifier();
parameterDeclSpec.setType(IASTSimpleDeclSpecifier.t_int);
insertedParameter.setDeclSpecifier(parameterDeclSpec);
ASTModification modification = new ASTModification(ModificationKind.APPEND_CHILD, functionDeclarator, insertedParameter, null);
ASTModification modification = new ASTModification(ModificationKind.APPEND_CHILD,
functionDeclarator, insertedParameter, null);
modStore.storeModification(null, modification);
}
return PROCESS_CONTINUE;

View file

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

View file

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

View file

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

View file

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

View file

@ -60,7 +60,8 @@ public class ArrayModifierTest extends ChangeGeneratorTest {
IASTExpression expr =
new CPPASTLiteralExpression(IASTLiteralExpression.lk_integer_constant, "5".toCharArray()); //$NON-NLS-1$
newModifier.setConstantExpression(expr);
ASTModification modification = new ASTModification(ModificationKind.INSERT_BEFORE, modifiers[0], newModifier, null);
ASTModification modification = new ASTModification(ModificationKind.INSERT_BEFORE,
modifiers[0], newModifier, null);
modStore.storeModification(null, modification);
}
return PROCESS_CONTINUE;

View file

@ -59,7 +59,8 @@ public class ArraySizeExpressionTest extends ChangeGeneratorTest {
IASTArrayModifier[] mods= dtor.getArrayModifiers();
IASTArrayModifier add= new CPPASTArrayModifier(
new CPPASTLiteralExpression(IASTLiteralExpression.lk_integer_constant, "6".toCharArray()));
ASTModification modification = new ASTModification(ASTModification.ModificationKind.INSERT_BEFORE, mods[0], add, null);
ASTModification modification = new ASTModification(ASTModification.ModificationKind.INSERT_BEFORE,
mods[0], add, null);
modStore.storeModification(null, modification);
}
return PROCESS_CONTINUE;

View file

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

View file

@ -54,7 +54,7 @@ public class ExceptionTest extends ChangeGeneratorTest {
@Override
public int visit(IASTDeclarator declarator) {
if (declarator instanceof CPPASTFunctionDeclarator) {
CPPASTFunctionDeclarator functionDeclarator = (CPPASTFunctionDeclarator)declarator;
CPPASTFunctionDeclarator functionDeclarator = (CPPASTFunctionDeclarator) declarator;
IASTTypeId existingException = functionDeclarator.getExceptionSpecification()[0];
IASTTypeId exception = new CPPASTTypeId();
@ -64,9 +64,9 @@ public class ExceptionTest extends ChangeGeneratorTest {
exDeclSpec.setType(IASTSimpleDeclSpecifier.t_int);
exception.setDeclSpecifier(exDeclSpec);
exception.setAbstractDeclarator(exceptionDeclarator);
ASTModification modification = new ASTModification(ModificationKind.INSERT_BEFORE, existingException, exception, null);
ASTModification modification = new ASTModification(ModificationKind.INSERT_BEFORE,
existingException, exception, null);
modStore.storeModification(null, modification);
}
return PROCESS_CONTINUE;
}

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -7,7 +7,7 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Institute for Software - initial API and implementation
* Institute for Software - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.remove;
@ -24,14 +24,14 @@ import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKin
public class CtorChainInitializerTest extends ChangeGeneratorTest {
public CtorChainInitializerTest(){
public CtorChainInitializerTest() {
super("Remove Ctor Initializer"); //$NON-NLS-1$
}
@Override
protected void setUp() throws Exception {
source = "TestClass::TestClass(int a):alpha(a){\n}\n\n"; //$NON-NLS-1$
expectedSource = "TestClass::TestClass(int a){\n}\n\n"; //$NON-NLS-1$
source = "TestClass::TestClass(int a):alpha(a) {\n}\n\n"; //$NON-NLS-1$
expectedSource = "TestClass::TestClass(int a) {\n}\n\n"; //$NON-NLS-1$
super.setUp();
}
@ -40,8 +40,7 @@ public class CtorChainInitializerTest extends ChangeGeneratorTest {
}
@Override
protected ASTVisitor createModificator(
final ASTModificationStore modStore) {
protected ASTVisitor createModificator(final ASTModificationStore modStore) {
return new ASTVisitor() {
{
shouldVisitDeclarators = true;
@ -50,11 +49,12 @@ public class CtorChainInitializerTest extends ChangeGeneratorTest {
@Override
public int visit(IASTDeclarator declarator) {
if (declarator instanceof CPPASTFunctionDeclarator) {
CPPASTFunctionDeclarator functionDeclarator = (CPPASTFunctionDeclarator)declarator;
CPPASTFunctionDeclarator functionDeclarator = (CPPASTFunctionDeclarator) declarator;
ICPPASTConstructorChainInitializer[] ctorInitializers = functionDeclarator.getConstructorChain();
for(ICPPASTConstructorChainInitializer curInitializer : ctorInitializers){
ASTModification modification = new ASTModification(ModificationKind.REPLACE, curInitializer, null, null);
modStore.storeModification(null, modification);
for (ICPPASTConstructorChainInitializer curInitializer : ctorInitializers){
ASTModification modification = new ASTModification(ModificationKind.REPLACE,
curInitializer, null, null);
modStore.storeModification(null, modification);
}
}
return PROCESS_CONTINUE;

View file

@ -7,7 +7,7 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Institute for Software - initial API and implementation
* Institute for Software - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.remove;
@ -30,8 +30,8 @@ public class ExceptionTest extends ChangeGeneratorTest {
@Override
protected void setUp() throws Exception {
source = "void foo(int parameter) throw (int){\n}\n\n"; //$NON-NLS-1$
expectedSource = "void foo(int parameter) throw (){\n}\n\n"; //$NON-NLS-1$
source = "void foo(int parameter) throw (int) {\n}\n\n"; //$NON-NLS-1$
expectedSource = "void foo(int parameter) throw () {\n}\n\n"; //$NON-NLS-1$
super.setUp();
}
@ -40,8 +40,7 @@ public class ExceptionTest extends ChangeGeneratorTest {
}
@Override
protected ASTVisitor createModificator(
final ASTModificationStore modStore) {
protected ASTVisitor createModificator(final ASTModificationStore modStore) {
return new ASTVisitor() {
{
shouldVisitDeclarators = true;
@ -50,11 +49,12 @@ public class ExceptionTest extends ChangeGeneratorTest {
@Override
public int visit(IASTDeclarator declarator) {
if (declarator instanceof CPPASTFunctionDeclarator) {
CPPASTFunctionDeclarator functionDeclarator = (CPPASTFunctionDeclarator)declarator;
CPPASTFunctionDeclarator functionDeclarator = (CPPASTFunctionDeclarator) declarator;
IASTTypeId[] exceptions = functionDeclarator.getExceptionSpecification();
for(IASTTypeId curException : exceptions){
ASTModification modification = new ASTModification(ModificationKind.REPLACE, curException, null, null);
modStore.storeModification(null, modification);
for (IASTTypeId curException : exceptions) {
ASTModification modification = new ASTModification(ModificationKind.REPLACE,
curException, null, null);
modStore.storeModification(null, modification);
}
}
return PROCESS_CONTINUE;

View file

@ -7,7 +7,7 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Institute for Software - initial API and implementation
* Institute for Software - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.remove;
@ -20,20 +20,16 @@ import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGenerator
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
public class ExpressionTest extends ChangeGeneratorTest {
public ExpressionTest(){
public ExpressionTest() {
super("Remove Expression"); //$NON-NLS-1$
}
@Override
protected void setUp() throws Exception {
source = "void main(){int s = 0, c = 0, h = 0;\ns = 3, c = 4, h = 5;}"; //$NON-NLS-1$
expectedSource = "void main(){int s = 0, c = 0, h = 0;\ns = 3, h = 5;}"; //$NON-NLS-1$
source = "void main() {\n\tint s = 0, c = 0, h = 0;\n\ts = 3, c = 4, h = 5;\n}"; //$NON-NLS-1$
expectedSource = "void main() {\n\tint s = 0, c = 0, h = 0;\n\ts = 3, h = 5;\n}"; //$NON-NLS-1$
super.setUp();
}
@ -42,8 +38,7 @@ public class ExpressionTest extends ChangeGeneratorTest {
}
@Override
protected ASTVisitor createModificator(
final ASTModificationStore modStore) {
protected ASTVisitor createModificator(final ASTModificationStore modStore) {
return new ASTVisitor() {
{
shouldVisitExpressions = true;
@ -54,13 +49,12 @@ public class ExpressionTest extends ChangeGeneratorTest {
if (expression instanceof IASTExpressionList) {
IASTExpressionList expressionList = (IASTExpressionList) expression;
IASTExpression[] expressions = expressionList.getExpressions();
ASTModification modification = new ASTModification(ASTModification.ModificationKind.REPLACE, expressions[1], null, null);
ASTModification modification = new ASTModification(ASTModification.ModificationKind.REPLACE,
expressions[1], null, null);
modStore.storeModification(null, modification);
}
return PROCESS_CONTINUE;
}
};
}
}

View file

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

View file

@ -7,7 +7,7 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Institute for Software - initial API and implementation
* Institute for Software - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.remove;
@ -22,18 +22,16 @@ import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind;
public class LastParameterTest extends ChangeGeneratorTest {
public LastParameterTest(){
public LastParameterTest() {
super("Remove Last Parameter Node"); //$NON-NLS-1$
}
@Override
protected void setUp() throws Exception {
source = "void foo(int a, int b, int c){\n}\n\n"; //$NON-NLS-1$
expectedSource = "void foo(int a, int b){\n}\n\n"; //$NON-NLS-1$
source = "void foo(int a, int b, int c) {\n}\n\n"; //$NON-NLS-1$
expectedSource = "void foo(int a, int b) {\n}\n\n"; //$NON-NLS-1$
super.setUp();
}
@ -42,8 +40,7 @@ public class LastParameterTest extends ChangeGeneratorTest {
}
@Override
protected ASTVisitor createModificator(
final ASTModificationStore modStore) {
protected ASTVisitor createModificator(final ASTModificationStore modStore) {
return new ASTVisitor() {
{
shouldVisitDeclarators = true;
@ -52,17 +49,17 @@ public class LastParameterTest extends ChangeGeneratorTest {
@Override
public int visit(IASTDeclarator declarator) {
if (declarator instanceof CPPASTFunctionDeclarator) {
CPPASTFunctionDeclarator functionDeclarator = (CPPASTFunctionDeclarator)declarator;
CPPASTFunctionDeclarator functionDeclarator = (CPPASTFunctionDeclarator) declarator;
IASTParameterDeclaration[] parameters = functionDeclarator.getParameters();
for(IASTParameterDeclaration curParam : parameters){
if(String.valueOf(curParam.getDeclarator().getName().toCharArray()).equals("c")){ //$NON-NLS-1$
ASTModification modification = new ASTModification(ModificationKind.REPLACE, curParam, null, null);
for (IASTParameterDeclaration curParam : parameters){
if (String.valueOf(curParam.getDeclarator().getName().toCharArray()).equals("c")) { //$NON-NLS-1$
ASTModification modification = new ASTModification(ModificationKind.REPLACE,
curParam, null, null);
modStore.storeModification(null, modification);
}
}
}
return PROCESS_CONTINUE;
}
};

View file

@ -7,7 +7,7 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Institute for Software - initial API and implementation
* Institute for Software - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.remove;
@ -22,10 +22,6 @@ import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind;
public class MiddleParameterTest extends ChangeGeneratorTest {
public MiddleParameterTest(){
@ -34,8 +30,8 @@ public class MiddleParameterTest extends ChangeGeneratorTest {
@Override
protected void setUp() throws Exception {
source = "void foo(int a, int b, int c){\n}\n\n"; //$NON-NLS-1$
expectedSource = "void foo(int a, int c){\n}\n\n"; //$NON-NLS-1$
source = "void foo(int a, int b, int c) {\n}\n\n"; //$NON-NLS-1$
expectedSource = "void foo(int a, int c) {\n}\n\n"; //$NON-NLS-1$
super.setUp();
}
@ -44,10 +40,8 @@ public class MiddleParameterTest extends ChangeGeneratorTest {
return new MiddleParameterTest();
}
@Override
protected ASTVisitor createModificator(
final ASTModificationStore modStore) {
protected ASTVisitor createModificator(final ASTModificationStore modStore) {
return new ASTVisitor() {
{
shouldVisitDeclarators = true;
@ -56,11 +50,12 @@ public class MiddleParameterTest extends ChangeGeneratorTest {
@Override
public int visit(IASTDeclarator declarator) {
if (declarator instanceof CPPASTFunctionDeclarator) {
CPPASTFunctionDeclarator functionDeclarator = (CPPASTFunctionDeclarator)declarator;
CPPASTFunctionDeclarator functionDeclarator = (CPPASTFunctionDeclarator) declarator;
IASTParameterDeclaration[] parameters = functionDeclarator.getParameters();
for(IASTParameterDeclaration curParam : parameters){
if(String.valueOf(curParam.getDeclarator().getName().toCharArray()).equals("b")){ //$NON-NLS-1$
ASTModification modification = new ASTModification(ModificationKind.REPLACE, curParam, null, null);
for (IASTParameterDeclaration curParam : parameters){
if (String.valueOf(curParam.getDeclarator().getName().toCharArray()).equals("b")) { //$NON-NLS-1$
ASTModification modification = new ASTModification(ModificationKind.REPLACE,
curParam, null, null);
modStore.storeModification(null, modification);
}
}

View file

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

View file

@ -7,7 +7,7 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Institute for Software - initial API and implementation
* Institute for Software - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.remove;
@ -16,13 +16,11 @@ import junit.framework.TestSuite;
/**
* @author Thomas Corbat
*
*/
public class RemoveTestSuite{
public class RemoveTestSuite {
public static Test suite() throws Exception {
TestSuite suite = new TestSuite("Changegenerator Remove Tests");
TestSuite suite = new TestSuite("ChangeGenerator Remove Tests");
suite.addTest(DeclarationTest.suite());
suite.addTest(FirstParameterTest.suite());
suite.addTest(MiddleParameterTest.suite());
@ -36,7 +34,6 @@ public class RemoveTestSuite{
suite.addTest(ArraySizeExpressionTest.suite());
suite.addTest(NewInitializerExpressionTest.suite());
suite.addTest(StatementTest.suite());
return suite;
}
}

View file

@ -7,7 +7,7 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Institute for Software - initial API and implementation
* Institute for Software - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.remove;
@ -24,25 +24,23 @@ import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKin
public class SingleParameterTest extends ChangeGeneratorTest {
public SingleParameterTest(){
public SingleParameterTest() {
super("Remove The Only Parameter Node"); //$NON-NLS-1$
}
@Override
protected void setUp() throws Exception {
source = "void foo(int parameter){\n}\n\n"; //$NON-NLS-1$
expectedSource = "void foo(){\n}\n\n"; //$NON-NLS-1$
source = "void foo(int parameter) {\n}\n\n"; //$NON-NLS-1$
expectedSource = "void foo() {\n}\n\n"; //$NON-NLS-1$
super.setUp();
}
public static Test suite() {
return new SingleParameterTest();
}
@Override
protected ASTVisitor createModificator(
final ASTModificationStore modStore) {
protected ASTVisitor createModificator(final ASTModificationStore modStore) {
return new ASTVisitor() {
{
shouldVisitDeclarators = true;
@ -51,11 +49,12 @@ public class SingleParameterTest extends ChangeGeneratorTest {
@Override
public int visit(IASTDeclarator declarator) {
if (declarator instanceof CPPASTFunctionDeclarator) {
CPPASTFunctionDeclarator functionDeclarator = (CPPASTFunctionDeclarator)declarator;
CPPASTFunctionDeclarator functionDeclarator = (CPPASTFunctionDeclarator) declarator;
IASTParameterDeclaration[] parameters = functionDeclarator.getParameters();
for(IASTParameterDeclaration curParam : parameters){
if(String.valueOf(curParam.getDeclarator().getName().toCharArray()).equals("parameter")){ //$NON-NLS-1$
ASTModification modification = new ASTModification(ModificationKind.REPLACE, curParam, null, null);
for (IASTParameterDeclaration curParam : parameters){
if (String.valueOf(curParam.getDeclarator().getName().toCharArray()).equals("parameter")){ //$NON-NLS-1$
ASTModification modification = new ASTModification(ModificationKind.REPLACE,
curParam, null, null);
modStore.storeModification(null, modification);
}
}

View file

@ -7,7 +7,7 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Institute for Software - initial API and implementation
* Institute for Software - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.replace;
@ -29,15 +29,14 @@ import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKin
public class ExceptionTest extends ChangeGeneratorTest {
public ExceptionTest(){
super("Remove Exception Declaration"); //$NON-NLS-1$
}
@Override
protected void setUp() throws Exception {
source = "void foo(int parameter) throw (float){\n}\n\n"; //$NON-NLS-1$
expectedSource = "void foo(int parameter) throw (int){\n}\n\n"; //$NON-NLS-1$
source = "void foo(int parameter) throw (float) {\n}\n\n"; //$NON-NLS-1$
expectedSource = "void foo(int parameter) throw (int) {\n}\n\n"; //$NON-NLS-1$
super.setUp();
}
@ -46,8 +45,7 @@ public class ExceptionTest extends ChangeGeneratorTest {
}
@Override
protected ASTVisitor createModificator(
final ASTModificationStore modStore) {
protected ASTVisitor createModificator(final ASTModificationStore modStore) {
return new ASTVisitor() {
{
shouldVisitDeclarators = true;
@ -56,7 +54,7 @@ public class ExceptionTest extends ChangeGeneratorTest {
@Override
public int visit(IASTDeclarator declarator) {
if (declarator instanceof CPPASTFunctionDeclarator) {
CPPASTFunctionDeclarator functionDeclarator = (CPPASTFunctionDeclarator)declarator;
CPPASTFunctionDeclarator functionDeclarator = (CPPASTFunctionDeclarator) declarator;
IASTTypeId existingException = functionDeclarator.getExceptionSpecification()[0];
IASTTypeId exception = new CPPASTTypeId();
@ -66,13 +64,12 @@ public class ExceptionTest extends ChangeGeneratorTest {
exDeclSpec.setType(IASTSimpleDeclSpecifier.t_int);
exception.setDeclSpecifier(exDeclSpec);
exception.setAbstractDeclarator(exceptionDeclarator);
ASTModification modification = new ASTModification(ModificationKind.REPLACE, existingException, exception, null);
ASTModification modification = new ASTModification(ModificationKind.REPLACE,
existingException, exception, null);
modStore.storeModification(null, modification);
}
return PROCESS_CONTINUE;
}
};
}
}

View file

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

View file

@ -7,7 +7,7 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Institute for Software - initial API and implementation
* Institute for Software - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.replace;
@ -26,14 +26,14 @@ import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKin
public class PointerInParameterTest extends ChangeGeneratorTest {
public PointerInParameterTest(){
public PointerInParameterTest() {
super("Replace Pointer for Parameter"); //$NON-NLS-1$
}
@Override
protected void setUp() throws Exception {
source = "void foo(int &parameter){\n}\n\n"; //$NON-NLS-1$
expectedSource = "void foo(int *parameter){\n}\n\n"; //$NON-NLS-1$
source = "void foo(int &parameter) {\n}\n\n"; //$NON-NLS-1$
expectedSource = "void foo(int *parameter) {\n}\n\n"; //$NON-NLS-1$
super.setUp();
}
@ -42,8 +42,7 @@ public class PointerInParameterTest extends ChangeGeneratorTest {
}
@Override
protected ASTVisitor createModificator(
final ASTModificationStore modStore) {
protected ASTVisitor createModificator(final ASTModificationStore modStore) {
return new ASTVisitor() {
{
shouldVisitDeclarators = true;
@ -52,10 +51,10 @@ public class PointerInParameterTest extends ChangeGeneratorTest {
@Override
public int visit(IASTDeclarator declarator) {
if (declarator instanceof CPPASTFunctionDeclarator) {
CPPASTFunctionDeclarator functionDeclarator = (CPPASTFunctionDeclarator)declarator;
CPPASTFunctionDeclarator functionDeclarator = (CPPASTFunctionDeclarator) declarator;
IASTParameterDeclaration[] parameters = functionDeclarator.getParameters();
for(IASTParameterDeclaration curParam : parameters){
if(String.valueOf(curParam.getDeclarator().getName().toCharArray()).equals("parameter")){ //$NON-NLS-1$
for (IASTParameterDeclaration curParam : parameters){
if (String.valueOf(curParam.getDeclarator().getName().toCharArray()).equals("parameter")) { //$NON-NLS-1$
IASTPointerOperator pointer = curParam.getDeclarator().getPointerOperators()[0];
CPPASTPointer newPointer = new CPPASTPointer();
ASTModification modification = new ASTModification(ModificationKind.REPLACE, pointer, newPointer, null);

View file

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

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

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

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.IASTCompoundStatement;
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.IASTIfStatement;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement;
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTStatement;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration;
@ -34,7 +38,6 @@ import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap;
*/
public class ASTWriter {
private ASTModificationStore modificationStore = new ASTModificationStore();
private String givenIndentation = ""; //$NON-NLS-1$
/**
* Creates a <code>ASTWriter</code>.
@ -43,16 +46,6 @@ public class ASTWriter {
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.
*
@ -75,10 +68,9 @@ public class ASTWriter {
*
* @see ASTCommenter#getCommentedNodeMap(org.eclipse.cdt.core.dom.ast.IASTTranslationUnit)
*/
public String write(IASTNode rootNode, NodeCommentMap commentMap)
throws ProblemRuntimeException {
public String write(IASTNode rootNode, NodeCommentMap commentMap) throws ProblemRuntimeException {
ChangeGeneratorWriterVisitor writer = new ChangeGeneratorWriterVisitor(
modificationStore, givenIndentation, null, commentMap);
modificationStore, null, commentMap);
if (rootNode != null) {
rootNode.accept(writer);
}
@ -152,10 +144,35 @@ public class ASTWriter {
* @return <code>true</code> if the blank line between the nodes is needed.
*/
public static boolean requireBlankLineInBetween(IASTNode node1, IASTNode node2) {
if (requiresTrailingBlankLine(node1))
if (node1 instanceof ICPPASTVisibilityLabel && node2 instanceof ICPPASTVisibilityLabel) {
return true;
}
if (suppressesTrailingBlankLine(node1)) {
return false;
}
if (node1 instanceof IASTPreprocessorIncludeStatement !=
node2 instanceof IASTPreprocessorIncludeStatement) {
return true;
}
if (isFunctionDeclaration(node1) != isFunctionDeclaration(node2)) {
return true;
}
if (requiresTrailingBlankLine(node1)) {
return true;
}
return !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;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTArrayModifier;
@ -29,6 +29,7 @@ import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTNodeLocation;
import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTPointerOperator;
import org.eclipse.cdt.core.dom.ast.IASTStatement;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition;
@ -62,28 +63,25 @@ public class ASTWriterVisitor extends ASTVisitor {
private boolean spaceNeededBeforeName;
{
shouldVisitExpressions = true;
shouldVisitStatements = true;
shouldVisitNames = true;
shouldVisitDeclarations = true;
shouldVisitDeclSpecifiers = true;
shouldVisitDeclarators = true;
shouldVisitArrayModifiers= true;
shouldVisitInitializers = true;
shouldVisitArrayModifiers = true;
shouldVisitBaseSpecifiers = true;
shouldVisitDeclarations = true;
shouldVisitDeclarators = true;
shouldVisitDeclSpecifiers = true;
shouldVisitExpressions = true;
shouldVisitInitializers = true;
shouldVisitNames = true;
shouldVisitNamespaces = true;
shouldVisitTemplateParameters = true;
shouldVisitParameterDeclarations = true;
shouldVisitPointerOperators = true;
shouldVisitStatements = true;
shouldVisitTemplateParameters = true;
shouldVisitTranslationUnit = true;
shouldVisitTypeIds = true;
}
public ASTWriterVisitor(NodeCommentMap commentMap) {
this("", commentMap); //$NON-NLS-1$
}
public ASTWriterVisitor(String givenIndentation, NodeCommentMap commentMap) {
super();
scribe.setGivenIndentation(givenIndentation);
init(commentMap);
this.commentMap = commentMap;
this.suppressLeadingBlankLine = true;
@ -123,8 +121,8 @@ public class ASTWriterVisitor extends ASTVisitor {
}
}
private ArrayList<IASTComment> getLeadingComments(IASTNode node) {
ArrayList<IASTComment> leadingComments = commentMap.getLeadingCommentsForNode(node);
private List<IASTComment> getLeadingComments(IASTNode node) {
List<IASTComment> leadingComments = commentMap.getLeadingCommentsForNode(node);
IASTNodeLocation[] locs = node.getNodeLocations();
if (locs != null && locs.length > 0 && locs[0] instanceof IASTCopyLocation) {
IASTCopyLocation copyLoc = (IASTCopyLocation) locs[0];
@ -240,6 +238,15 @@ public class ASTWriterVisitor extends ASTVisitor {
return ASTVisitor.PROCESS_SKIP;
}
@Override
public int visit(IASTPointerOperator pointerOperator) {
writeLeadingComments(pointerOperator);
if (!macroHandler.checkisMacroExpansionNode(pointerOperator)) {
declaratorWriter.writePointerOperator(pointerOperator);
}
return ASTVisitor.PROCESS_SKIP;
}
protected IASTName getParameterName(IASTDeclarator declarator) {
return declarator.getName();
}
@ -303,6 +310,10 @@ public class ASTWriterVisitor extends ASTVisitor {
this.spaceNeededBeforeName = value;
}
public Scribe getScribe() {
return scribe;
}
public void newLine() {
scribe.newLine();
}

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

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

View file

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

View file

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

View file

@ -7,11 +7,11 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Institute for Software - initial API and implementation
* Institute for Software - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.rewrite.commenthandler;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.cdt.core.dom.ast.IASTComment;
@ -23,10 +23,9 @@ import org.eclipse.cdt.core.dom.ast.IASTComment;
* @author Guido Zgraggen IFS
*/
public class CommentHandler {
private final ArrayList<IASTComment> comments;
private final List<IASTComment> comments;
public CommentHandler(ArrayList<IASTComment> comments) {
public CommentHandler(List<IASTComment> comments) {
super();
this.comments = comments;
}
@ -36,7 +35,7 @@ public class CommentHandler {
}
public boolean hasMore() {
return comments.size()>0;
return !comments.isEmpty();
}
public IASTComment getFirst() {

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -4,16 +4,15 @@
void test() {
}
template <typename T>
template<typename T>
int tempFunct() {
T i;
i = 0;
/*$*/i++;
i += 3;/*$$*/
return 0;
}
//=
void test() {
}
@ -24,22 +23,20 @@ void exp(T i) {
i += 3;
}
template <typename T>
template<typename T>
int tempFunct() {
T i;
i = 0;
exp(i);
return 0;
}
//!Extract template function with template parameter Bug #12
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
//@A.cpp
void test() {
}
template <typename T>
template<typename T>
int tempFunct(T p) {
/*$*/++p;
p + 4;/*$$*/
@ -56,7 +53,7 @@ void exp(T p) {
p + 4;
}
template <typename T>
template<typename T>
int tempFunct(T p) {
exp(p);
return 0;
@ -68,7 +65,7 @@ int tempFunct(T p) {
void test() {
}
template <typename T>
template<typename T>
int tempFunct() {
/*$*/T p;
p = 0;
@ -76,7 +73,6 @@ int tempFunct() {
p + 2;
return 0;
}
//=
void test() {
}
@ -89,10 +85,9 @@ T exp() {
return p;
}
template <typename T>
template<typename T>
int tempFunct() {
T p = exp();
p + 2;
return 0;
}

View file

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

View file

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

View file

@ -211,7 +211,7 @@ int main() {
name="exp" project="RegressionTestProject" selection="34,6" visibility="private"/>
</session>
//!Extract Function History extracted statement with trailling comment
//!Extract Function History extracted statement with trailing comment
//#org.eclipse.cdt.ui.tests.refactoring.RefactoringHistoryTest
//@main.cpp
int main() {
@ -227,7 +227,7 @@ void exp(int& i) {
int main() {
int i;
exp(i); // Comment
exp(i);
return i;
}

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -11,8 +11,6 @@ void A::/*$*/member/*$$*/() {
}
//=
#include "A.h"
//@A.h
class A {
void member();
@ -37,9 +35,6 @@ void A::/*$*/member/*$$*/() {
}
//=
#include "A.h"
// Definition comment
//@A.h
class A {
void member();
@ -64,9 +59,6 @@ void A::/*$*/member/*$$*/() try {
} /*1*/ catch (int e) { /*2*/ } /*3*/ catch (int e) { /*4*/ }
//=
#include "A.h"
// Definition comment
//@A.h
class A {
void member();
@ -98,8 +90,6 @@ void /*$*/member/*$$*/() {
}
//=
#include "A.h"
//@A.h
//=
@ -122,9 +112,6 @@ void /*$*/member/*$$*/() {
}
//=
#include "A.h"
// Top comment
//@A.h
//=

View file

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

View file

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

View file

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

View file

@ -38,7 +38,6 @@ public:
};
int freeFunction(int* a, int& b);
//@A.cpp
#include "A.h"
@ -76,8 +75,6 @@ int /*$*/freeFunction/*$$*/(int* a, int& b) {
int main() {
return 0;
}
//@A.h
#include <iostream>
@ -114,7 +111,6 @@ public:
int freeFunction(int* a, int& b) {
return 42;
}
//!TestFreeFunctionToggleFromImplementationToHeaderWithOutDeclaration
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config
@ -132,14 +128,13 @@ try {
}
catch (std::exception& e) {
}
//=
#include "A.h"
int main() {
return 0;
}
//@A.h
#include <iostream>
@ -155,7 +150,6 @@ public:
~A() {
}
};
//=
#include <iostream>
@ -179,7 +173,6 @@ try {
catch (std::exception& e) {
}
//!TestFreeFunction
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
//@.config
@ -190,7 +183,6 @@ int /*$*/freeFunction/*$$*/() {
}
//=
int freeFunction();
//@A.cpp
#include "A.h"
//=

View file

@ -132,6 +132,7 @@ namespace N {
void A::foo() {
return;
}
}
//!TestSimpleNamespaceInHeaderToImplementationWithNamespaceQualifiedName
//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest
@ -163,8 +164,6 @@ class A {
};
}
//@A.cpp
#include "A.h"
@ -203,8 +202,6 @@ int main() {
//=
#include "A.h"
int main() {
return 0;
}
@ -246,8 +243,6 @@ void /*$*/A::foo/*$$*/() {
}
//=
#include "A.h"
//@A.h
#include <iostream>

View file

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

View file

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

View file

@ -57,8 +57,6 @@ public:
private:
int a;
};
//@A.cpp
#include "A.h"
@ -93,8 +91,6 @@ int main() {
//=
#include "A.h"
int main() {
return 0;
}
@ -137,8 +133,6 @@ int main() {
//=
#include "MyClass.h"
int main() {
return 0;
}
@ -175,24 +169,18 @@ int main() {
//=
#include "MyClass.h"
int main() {
return 0;
}
//@MyClass.h
struct myClass {
int fVal;
myClass(int);
};
//=
struct myClass {
int fVal;
myClass(int implname) :
fVal(implname) {
}
};

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

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