mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-01 06:05:24 +02:00
Merge remote-tracking branch 'cdt/master' into sd90
This commit is contained in:
commit
bbec91c5bc
194 changed files with 2589 additions and 2873 deletions
|
@ -273,7 +273,8 @@ public class DefaultRunSIProvider implements IExternalScannerInfoProvider {
|
|||
// of the language as long as the encoding is set to UTF-8.
|
||||
// English language is chosen because parser relies on English messages
|
||||
// in the output of the 'gcc -v' command.
|
||||
props.put("LC_ALL", "en_US.UTF-8"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
props.put("LANGUAGE", "en"); // override for GNU gettext //$NON-NLS-1$ //$NON-NLS-2$
|
||||
props.put("LC_ALL", "en_US.UTF-8"); // for other parts of the system libraries //$NON-NLS-1$ //$NON-NLS-2$
|
||||
return props;
|
||||
}
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -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 {
|
|||
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Institute for Software - initial API and implementation
|
||||
* Institute for Software - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.replace;
|
||||
|
||||
|
@ -26,14 +26,14 @@ import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKin
|
|||
|
||||
public class PointerInParameterTest extends ChangeGeneratorTest {
|
||||
|
||||
public PointerInParameterTest(){
|
||||
public PointerInParameterTest() {
|
||||
super("Replace Pointer for Parameter"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
source = "void foo(int ¶meter){\n}\n\n"; //$NON-NLS-1$
|
||||
expectedSource = "void foo(int *parameter){\n}\n\n"; //$NON-NLS-1$
|
||||
source = "void foo(int ¶meter) {\n}\n\n"; //$NON-NLS-1$
|
||||
expectedSource = "void foo(int *parameter) {\n}\n\n"; //$NON-NLS-1$
|
||||
super.setUp();
|
||||
}
|
||||
|
||||
|
@ -42,8 +42,7 @@ public class PointerInParameterTest extends ChangeGeneratorTest {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected ASTVisitor createModificator(
|
||||
final ASTModificationStore modStore) {
|
||||
protected ASTVisitor createModificator(final ASTModificationStore modStore) {
|
||||
return new ASTVisitor() {
|
||||
{
|
||||
shouldVisitDeclarators = true;
|
||||
|
@ -52,10 +51,10 @@ public class PointerInParameterTest extends ChangeGeneratorTest {
|
|||
@Override
|
||||
public int visit(IASTDeclarator declarator) {
|
||||
if (declarator instanceof CPPASTFunctionDeclarator) {
|
||||
CPPASTFunctionDeclarator functionDeclarator = (CPPASTFunctionDeclarator)declarator;
|
||||
CPPASTFunctionDeclarator functionDeclarator = (CPPASTFunctionDeclarator) declarator;
|
||||
IASTParameterDeclaration[] parameters = functionDeclarator.getParameters();
|
||||
for(IASTParameterDeclaration curParam : parameters){
|
||||
if(String.valueOf(curParam.getDeclarator().getName().toCharArray()).equals("parameter")){ //$NON-NLS-1$
|
||||
for (IASTParameterDeclaration curParam : parameters){
|
||||
if (String.valueOf(curParam.getDeclarator().getName().toCharArray()).equals("parameter")) { //$NON-NLS-1$
|
||||
IASTPointerOperator pointer = curParam.getDeclarator().getPointerOperators()[0];
|
||||
CPPASTPointer newPointer = new CPPASTPointer();
|
||||
ASTModification modification = new ASTModification(ModificationKind.REPLACE, pointer, newPointer, null);
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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;
|
||||
|
@ -74,7 +74,6 @@ import org.eclipse.core.runtime.CoreException;
|
|||
* @author Guido Zgraggen IFS, Lukas Felber IFS
|
||||
*/
|
||||
public class CommentHandlingTest extends RewriteBaseTest {
|
||||
|
||||
private static final String ANY_CHAR_REGEXP = "(.*)"; //$NON-NLS-1$
|
||||
private static final String SEPARATOR = System.getProperty("line.separator"); //$NON-NLS-1$
|
||||
|
||||
|
@ -92,7 +91,7 @@ public class CommentHandlingTest extends RewriteBaseTest {
|
|||
|
||||
@Override
|
||||
protected void runTest() throws Throwable {
|
||||
if (fileMap.size() == 0) {
|
||||
if (fileMap.isEmpty()) {
|
||||
fail("No file for testing"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
|
@ -140,12 +139,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) {
|
||||
|
|
|
@ -12,7 +12,6 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.model;
|
||||
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import org.eclipse.cdt.core.CCProjectNature;
|
||||
|
@ -1425,7 +1424,7 @@ public class CoreModel {
|
|||
}
|
||||
|
||||
/**
|
||||
* forces the cached data of the specified projects to be re-calculated.
|
||||
* Forces the cached data of the specified projects to be re-calculated.
|
||||
* if the <code>projects</code> argument is <code>null</code> al projects
|
||||
* within the workspace are updated
|
||||
*
|
||||
|
@ -1438,14 +1437,14 @@ public class CoreModel {
|
|||
}
|
||||
|
||||
/**
|
||||
* answers whether the given project is a new-style project, i.e. CConfigurationDataProvider-driven
|
||||
* Answers whether the given project is a new-style project, i.e. CConfigurationDataProvider-driven
|
||||
*/
|
||||
public boolean isNewStyleProject(IProject project){
|
||||
return descriptionManager.isNewStyleProject(project);
|
||||
}
|
||||
|
||||
/**
|
||||
* answers whether the given project is a new-style project, i.e. CConfigurationDataProvider-driven
|
||||
* Answers whether the given project is a new-style project, i.e. CConfigurationDataProvider-driven
|
||||
*/
|
||||
public boolean isNewStyleProject(ICProjectDescription des){
|
||||
return descriptionManager.isNewStyleProject(des);
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* John Camelon (IBM Rational Software) - Initial API and implementation
|
||||
* John Camelon (IBM Rational Software) - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.dom.ast;
|
||||
|
||||
|
@ -44,10 +44,12 @@ public interface IASTExpressionList extends IASTExpression {
|
|||
/**
|
||||
* @since 5.1
|
||||
*/
|
||||
@Override
|
||||
public IASTExpressionList copy();
|
||||
|
||||
/**
|
||||
* @since 5.3
|
||||
*/
|
||||
@Override
|
||||
public IASTExpressionList copy(CopyStyle style);
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Doug Schaefer (IBM) - Initial API and implementation
|
||||
* Doug Schaefer (IBM) - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.dom.ast;
|
||||
|
||||
|
@ -20,7 +20,7 @@ public interface IASTParameterDeclaration extends IASTNode {
|
|||
/**
|
||||
* Constant/sentinel.
|
||||
*/
|
||||
public static final IASTParameterDeclaration[] EMPTY_PARAMETERDECLARATION_ARRAY = new IASTParameterDeclaration[0];
|
||||
public static final IASTParameterDeclaration[] EMPTY_PARAMETERDECLARATION_ARRAY = {};
|
||||
|
||||
/**
|
||||
* <code>DECL_SPECIFIER</code> represents the relationship between an
|
||||
|
@ -71,10 +71,12 @@ public interface IASTParameterDeclaration extends IASTNode {
|
|||
/**
|
||||
* @since 5.1
|
||||
*/
|
||||
@Override
|
||||
public IASTParameterDeclaration copy();
|
||||
|
||||
/**
|
||||
* @since 5.3
|
||||
*/
|
||||
@Override
|
||||
public IASTParameterDeclaration copy(CopyStyle style);
|
||||
}
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Doug Schaefer (IBM) - Initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
* Doug Schaefer (IBM) - Initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.dom.ast;
|
||||
|
||||
|
@ -18,7 +18,6 @@ package org.eclipse.cdt.core.dom.ast;
|
|||
* @noimplement This interface is not intended to be implemented by clients.
|
||||
*/
|
||||
public interface IASTStandardFunctionDeclarator extends IASTFunctionDeclarator {
|
||||
|
||||
/**
|
||||
* <code>FUNCTION_PARAMETER</code> represents the relationship between an
|
||||
* <code>IASTStandardFunctionDeclarator</code> and it's nested
|
||||
|
@ -67,10 +66,12 @@ public interface IASTStandardFunctionDeclarator extends IASTFunctionDeclarator {
|
|||
/**
|
||||
* @since 5.1
|
||||
*/
|
||||
@Override
|
||||
public IASTStandardFunctionDeclarator copy();
|
||||
|
||||
/**
|
||||
* @since 5.3
|
||||
*/
|
||||
@Override
|
||||
public IASTStandardFunctionDeclarator copy(CopyStyle style);
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM - Initial API and implementation
|
||||
* IBM - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.dom.ast.cpp;
|
||||
|
||||
|
@ -24,8 +24,7 @@ import org.eclipse.cdt.core.dom.ast.IScope;
|
|||
* @noimplement This interface is not intended to be implemented by clients.
|
||||
*/
|
||||
public interface ICPPASTCatchHandler extends IASTStatement {
|
||||
|
||||
public static final ICPPASTCatchHandler[] EMPTY_CATCHHANDLER_ARRAY = new ICPPASTCatchHandler[0];
|
||||
public static final ICPPASTCatchHandler[] EMPTY_CATCHHANDLER_ARRAY = {};
|
||||
|
||||
/**
|
||||
* <code>DECLARATION</code> represents the nested declaration within the catch handler.
|
||||
|
@ -78,10 +77,12 @@ public interface ICPPASTCatchHandler extends IASTStatement {
|
|||
/**
|
||||
* @since 5.1
|
||||
*/
|
||||
@Override
|
||||
public ICPPASTCatchHandler copy();
|
||||
|
||||
/**
|
||||
* @since 5.3
|
||||
*/
|
||||
@Override
|
||||
public ICPPASTCatchHandler copy(CopyStyle style);
|
||||
}
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM - Initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
* IBM - Initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.dom.ast.cpp;
|
||||
|
||||
|
@ -22,7 +22,6 @@ import org.eclipse.cdt.core.dom.ast.IASTTypeId;
|
|||
* @noextend This interface is not intended to be extended by clients.
|
||||
*/
|
||||
public interface ICPPASTFunctionDeclarator extends IASTStandardFunctionDeclarator, ICPPASTDeclarator {
|
||||
|
||||
/**
|
||||
* Used as return value for {@link #getExceptionSpecification()}.
|
||||
* @since 5.1
|
||||
|
@ -80,6 +79,7 @@ public interface ICPPASTFunctionDeclarator extends IASTStandardFunctionDeclarato
|
|||
/**
|
||||
* @since 5.2
|
||||
*/
|
||||
@Override
|
||||
public ICPPASTParameterDeclaration[] getParameters();
|
||||
|
||||
/**
|
||||
|
@ -117,6 +117,7 @@ public interface ICPPASTFunctionDeclarator extends IASTStandardFunctionDeclarato
|
|||
* Get function scope this node represents. Returns <code>null</code>, if this declarator does not
|
||||
* declare a function-prototype or function-definition.
|
||||
*/
|
||||
@Override
|
||||
public ICPPFunctionScope getFunctionScope();
|
||||
|
||||
|
||||
|
@ -136,10 +137,12 @@ public interface ICPPASTFunctionDeclarator extends IASTStandardFunctionDeclarato
|
|||
/**
|
||||
* @since 5.1
|
||||
*/
|
||||
@Override
|
||||
public ICPPASTFunctionDeclarator copy();
|
||||
|
||||
/**
|
||||
* @since 5.3
|
||||
*/
|
||||
@Override
|
||||
public ICPPASTFunctionDeclarator copy(CopyStyle style);
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
* Markus Schorn - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.dom.ast.cpp;
|
||||
|
||||
|
@ -42,11 +42,13 @@ public interface ICPPASTFunctionDefinition extends IASTFunctionDefinition {
|
|||
/**
|
||||
* @since 5.1
|
||||
*/
|
||||
@Override
|
||||
public ICPPASTFunctionDefinition copy();
|
||||
|
||||
/**
|
||||
* @since 5.3
|
||||
*/
|
||||
@Override
|
||||
public ICPPASTFunctionDefinition copy(CopyStyle style);
|
||||
|
||||
/**
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
* Markus Schorn - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.dom.ast.cpp;
|
||||
|
||||
|
@ -23,7 +23,6 @@ import org.eclipse.cdt.core.dom.ast.ASTNodeProperty;
|
|||
* @noimplement This interface is not intended to be implemented by clients.
|
||||
*/
|
||||
public interface ICPPASTFunctionWithTryBlock extends ICPPASTFunctionDefinition {
|
||||
|
||||
/**
|
||||
* A <code>CATCH_HANDLER</code> is the role of an ICPPASTCatchHandler in
|
||||
* this interface.
|
||||
|
@ -44,6 +43,6 @@ public interface ICPPASTFunctionWithTryBlock extends ICPPASTFunctionDefinition {
|
|||
/**
|
||||
* @since 5.1
|
||||
*/
|
||||
@Override
|
||||
public ICPPASTFunctionWithTryBlock copy();
|
||||
|
||||
}
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* John Camelon (IBM) - Initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
* John Camelon (IBM) - Initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.dom.ast.cpp;
|
||||
|
||||
|
@ -25,7 +25,6 @@ import org.eclipse.cdt.core.dom.ast.IScope;
|
|||
* @noimplement This interface is not intended to be implemented by clients.
|
||||
*/
|
||||
public interface ICPPASTNamespaceDefinition extends IASTDeclaration, IASTNameOwner, IASTDeclarationListOwner {
|
||||
|
||||
/**
|
||||
* <code>OWNED_DECLARATION</code> is the role served by all the nested
|
||||
* declarations.
|
||||
|
@ -68,22 +67,22 @@ public interface ICPPASTNamespaceDefinition extends IASTDeclaration, IASTNameOwn
|
|||
public boolean isInline();
|
||||
|
||||
/**
|
||||
* A translation unit contains an ordered sequence of declarations.
|
||||
* A namespace contains an ordered sequence of declarations.
|
||||
*
|
||||
* @return <code>IASTDeclaration []</code>
|
||||
* @return an array of declarations contained in the namespace
|
||||
*/
|
||||
public IASTDeclaration[] getDeclarations();
|
||||
|
||||
/**
|
||||
* Add a declaration to the namespace.
|
||||
* Adds a declaration to the namespace.
|
||||
*
|
||||
* @param declaration
|
||||
* <code>IASTDeclaration</code>
|
||||
* @param declaration <code>IASTDeclaration</code>
|
||||
*/
|
||||
@Override
|
||||
public void addDeclaration(IASTDeclaration declaration);
|
||||
|
||||
/**
|
||||
* Get the scope object represented by this construct.
|
||||
* Returns the scope object represented by this construct.
|
||||
*
|
||||
* @return <code>IScope</code>
|
||||
*/
|
||||
|
@ -92,10 +91,12 @@ public interface ICPPASTNamespaceDefinition extends IASTDeclaration, IASTNameOwn
|
|||
/**
|
||||
* @since 5.1
|
||||
*/
|
||||
@Override
|
||||
public ICPPASTNamespaceDefinition copy();
|
||||
|
||||
/**
|
||||
* @since 5.3
|
||||
*/
|
||||
@Override
|
||||
public ICPPASTNamespaceDefinition copy(CopyStyle style);
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Institute for Software (IFS)- initial API and implementation
|
||||
* Institute for Software (IFS)- initial API and implementation
|
||||
******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.dom.parser;
|
||||
|
||||
|
@ -17,32 +17,31 @@ import org.eclipse.cdt.core.dom.ast.IASTNode;
|
|||
|
||||
/**
|
||||
* @author Emanuel Graf IFS
|
||||
*
|
||||
*/
|
||||
public class ASTCopyLocation implements IASTCopyLocation {
|
||||
|
||||
private IASTNode originalNode;
|
||||
|
||||
|
||||
|
||||
public ASTCopyLocation(IASTNode originalNode) {
|
||||
this.originalNode = originalNode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getNodeOffset() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getNodeLength() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IASTFileLocation asFileLocation() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IASTNode getOriginalNode() {
|
||||
return originalNode;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -40,6 +40,7 @@ public abstract class ASTEnumerator extends ASTNode implements IASTEnumerator, I
|
|||
copy.setOffsetAndLength(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setName(IASTName name) {
|
||||
assertNotFrozen();
|
||||
this.name = name;
|
||||
|
@ -49,11 +50,13 @@ public abstract class ASTEnumerator extends ASTNode implements IASTEnumerator, I
|
|||
}
|
||||
}
|
||||
|
||||
public IASTName getName() {
|
||||
@Override
|
||||
public IASTName getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setValue(IASTExpression expression) {
|
||||
@Override
|
||||
public void setValue(IASTExpression expression) {
|
||||
assertNotFrozen();
|
||||
this.value = expression;
|
||||
if (expression != null) {
|
||||
|
@ -62,7 +65,8 @@ public abstract class ASTEnumerator extends ASTNode implements IASTEnumerator, I
|
|||
}
|
||||
}
|
||||
|
||||
public IASTExpression getValue() {
|
||||
@Override
|
||||
public IASTExpression getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
|
@ -87,6 +91,7 @@ public abstract class ASTEnumerator extends ASTNode implements IASTEnumerator, I
|
|||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRoleForName(IASTName n) {
|
||||
if (n == name)
|
||||
return r_definition;
|
||||
|
@ -94,7 +99,8 @@ public abstract class ASTEnumerator extends ASTNode implements IASTEnumerator, I
|
|||
return r_reference;
|
||||
}
|
||||
|
||||
public void replace(IASTNode child, IASTNode other) {
|
||||
@Override
|
||||
public void replace(IASTNode child, IASTNode other) {
|
||||
if (child == value) {
|
||||
other.setPropertyInParent(child.getPropertyInParent());
|
||||
other.setParent(child.getParent());
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* John Camelon (IBM) - Initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
* John Camelon (IBM) - Initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.dom.parser;
|
||||
|
||||
|
@ -32,11 +32,13 @@ public abstract class ASTEqualsInitializer extends ASTNode implements IASTEquals
|
|||
setInitializerClause(arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IASTInitializerClause getInitializerClause() {
|
||||
return fArgument;
|
||||
}
|
||||
|
||||
public void setInitializerClause(IASTInitializerClause clause) {
|
||||
@Override
|
||||
public void setInitializerClause(IASTInitializerClause clause) {
|
||||
assertNotFrozen();
|
||||
fArgument = clause;
|
||||
if (clause != null) {
|
||||
|
@ -64,6 +66,7 @@ public abstract class ASTEqualsInitializer extends ASTNode implements IASTEquals
|
|||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void replace(IASTNode child, IASTNode other) {
|
||||
if (child == fArgument) {
|
||||
other.setPropertyInParent(child.getPropertyInParent());
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* John Camelon - Initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
* John Camelon - Initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.dom.parser;
|
||||
|
||||
|
@ -42,23 +42,29 @@ public abstract class ASTNode implements IASTNode {
|
|||
|
||||
private int length;
|
||||
private int offset;
|
||||
private IASTNodeLocation[] locations;
|
||||
private IASTFileLocation fileLocation;
|
||||
|
||||
private boolean frozen = false;
|
||||
private boolean active = true;
|
||||
|
||||
public IASTNode getParent() {
|
||||
@Override
|
||||
public IASTNode getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IASTNode[] getChildren() {
|
||||
ChildCollector collector= new ChildCollector(this);
|
||||
return collector.getChildren();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFrozen() {
|
||||
return frozen;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isActive() {
|
||||
return active;
|
||||
}
|
||||
|
@ -78,16 +84,19 @@ public abstract class ASTNode implements IASTNode {
|
|||
throw new IllegalStateException("attempt to modify frozen AST node"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
public void setParent(IASTNode node) {
|
||||
@Override
|
||||
public void setParent(IASTNode node) {
|
||||
assertNotFrozen();
|
||||
this.parent = node;
|
||||
}
|
||||
|
||||
public ASTNodeProperty getPropertyInParent() {
|
||||
@Override
|
||||
public ASTNodeProperty getPropertyInParent() {
|
||||
return property;
|
||||
}
|
||||
|
||||
public void setPropertyInParent(ASTNodeProperty property) {
|
||||
@Override
|
||||
public void setPropertyInParent(ASTNodeProperty property) {
|
||||
assertNotFrozen();
|
||||
this.property = property;
|
||||
}
|
||||
|
@ -120,10 +129,8 @@ public abstract class ASTNode implements IASTNode {
|
|||
setOffsetAndLength(node.getOffset(), node.getLength());
|
||||
}
|
||||
|
||||
private IASTNodeLocation[] locations = null;
|
||||
private IASTFileLocation fileLocation = null;
|
||||
|
||||
public IASTNodeLocation[] getNodeLocations() {
|
||||
@Override
|
||||
public IASTNodeLocation[] getNodeLocations() {
|
||||
if (locations != null)
|
||||
return locations;
|
||||
if (length == 0) {
|
||||
|
@ -163,11 +170,13 @@ public abstract class ASTNode implements IASTNode {
|
|||
return CharArrayUtils.EMPTY;
|
||||
}
|
||||
|
||||
public String getRawSignature() {
|
||||
@Override
|
||||
public String getRawSignature() {
|
||||
return new String(getRawSignatureChars());
|
||||
}
|
||||
|
||||
public String getContainingFilename() {
|
||||
@Override
|
||||
public String getContainingFilename() {
|
||||
if (offset <= 0 && (length == 0 || offset < 0)) {
|
||||
final IASTNode parent = getParent();
|
||||
if (parent == null) {
|
||||
|
@ -181,7 +190,8 @@ public abstract class ASTNode implements IASTNode {
|
|||
return getTranslationUnit().getContainingFilename(offset);
|
||||
}
|
||||
|
||||
public IASTFileLocation getFileLocation() {
|
||||
@Override
|
||||
public IASTFileLocation getFileLocation() {
|
||||
if (fileLocation != null)
|
||||
return fileLocation;
|
||||
// TODO(sprigogin): The purpose of offset == 0 && length == 0 condition is not clear to me.
|
||||
|
@ -201,7 +211,8 @@ public abstract class ASTNode implements IASTNode {
|
|||
return fileLocation;
|
||||
}
|
||||
|
||||
public boolean isPartOfTranslationUnitFile() {
|
||||
@Override
|
||||
public boolean isPartOfTranslationUnitFile() {
|
||||
IASTTranslationUnit ast = getTranslationUnit();
|
||||
if (ast != null) {
|
||||
ILocationResolver lr= (ILocationResolver) ast.getAdapter(ILocationResolver.class);
|
||||
|
@ -223,15 +234,18 @@ public abstract class ASTNode implements IASTNode {
|
|||
return false;
|
||||
}
|
||||
|
||||
public IASTTranslationUnit getTranslationUnit() {
|
||||
@Override
|
||||
public IASTTranslationUnit getTranslationUnit() {
|
||||
return parent != null ? parent.getTranslationUnit() : null;
|
||||
}
|
||||
|
||||
public boolean accept(ASTVisitor visitor) {
|
||||
@Override
|
||||
public boolean accept(ASTVisitor visitor) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean contains(IASTNode node) {
|
||||
@Override
|
||||
public boolean contains(IASTNode node) {
|
||||
if (node instanceof ASTNode) {
|
||||
ASTNode astNode= (ASTNode) node;
|
||||
return offset <= astNode.offset &&
|
||||
|
@ -240,15 +254,18 @@ public abstract class ASTNode implements IASTNode {
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IToken getSyntax() throws ExpansionOverlapsBoundaryException {
|
||||
return getSyntax(offset, offset+length, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IToken getLeadingSyntax() throws ExpansionOverlapsBoundaryException {
|
||||
int left= getBoundary(-1);
|
||||
return getSyntax(left, offset, -1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IToken getTrailingSyntax() throws ExpansionOverlapsBoundaryException {
|
||||
int right= getBoundary(1);
|
||||
return getSyntax(offset+length, right, 1);
|
||||
|
@ -346,5 +363,4 @@ public abstract class ASTNode implements IASTNode {
|
|||
protected void setCopyLocation(IASTNode originalNode) {
|
||||
locations = new IASTNodeLocation[] {new ASTCopyLocation(originalNode)};
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
* Markus Schorn - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.dom.parser;
|
||||
|
||||
|
@ -24,7 +24,6 @@ import org.eclipse.cdt.internal.core.parser.scanner.ILocationResolver;
|
|||
* @since 5.0
|
||||
*/
|
||||
public class ASTNodeSelector implements IASTNodeSelector {
|
||||
|
||||
private ASTTranslationUnit fTu;
|
||||
private ILocationResolver fLocationResolver;
|
||||
private String fFilePath;
|
||||
|
@ -74,7 +73,7 @@ public class ASTNodeSelector implements IASTNodeSelector {
|
|||
sequenceLength= 0;
|
||||
if (offsetInFile > 0) {
|
||||
altSequenceNumber= fLocationResolver.getSequenceNumberForFileOffset(fFilePath, offsetInFile-1);
|
||||
if (altSequenceNumber+1 == sequenceNumber) {
|
||||
if (altSequenceNumber + 1 == sequenceNumber) {
|
||||
altSequenceNumber= -1;
|
||||
} else {
|
||||
// we are on a context boundary and we need to check the variant to the left and
|
||||
|
@ -118,55 +117,67 @@ public class ASTNodeSelector implements IASTNodeSelector {
|
|||
return nodeSpec.getBestNode();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public IASTNode findFirstContainedNode(int offset, int length) {
|
||||
return findNode(offset, length, Relation.FIRST_CONTAINED, IASTNode.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IASTNode findNode(int offset, int length) {
|
||||
return findNode(offset, length, Relation.EXACT_MATCH, IASTNode.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IASTNode findEnclosingNode(int offset, int length) {
|
||||
return findNode(offset, length, Relation.ENCLOSING, IASTNode.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IASTNode findStrictlyEnclosingNode(int offset, int length) {
|
||||
return findNode(offset, length, Relation.STRICTLY_ENCLOSING, IASTNode.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IASTNode findFirstContainedNodeInExpansion(int offset, int length) {
|
||||
return findNode(offset, length, Relation.FIRST_CONTAINED, IASTNode.class, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IASTNode findNodeInExpansion(int offset, int length) {
|
||||
return findNode(offset, length, Relation.EXACT_MATCH, IASTNode.class, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IASTNode findEnclosingNodeInExpansion(int offset, int length) {
|
||||
return findNode(offset, length, Relation.ENCLOSING, IASTNode.class, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IASTName findFirstContainedName(int offset, int length) {
|
||||
return findNode(offset, length, Relation.FIRST_CONTAINED, IASTName.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IASTName findName(int offset, int length) {
|
||||
return findNode(offset, length, Relation.EXACT_MATCH, IASTName.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IASTName findEnclosingName(int offset, int length) {
|
||||
return findNode(offset, length, Relation.ENCLOSING, IASTName.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IASTImplicitName findImplicitName(int offset, int length) {
|
||||
return findNode(offset, length, Relation.EXACT_MATCH, IASTImplicitName.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IASTImplicitName findEnclosingImplicitName(int offset, int length) {
|
||||
return findNode(offset, length, Relation.ENCLOSING, IASTImplicitName.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IASTPreprocessorMacroExpansion findEnclosingMacroExpansion(int offset, int length) {
|
||||
return findNode(offset, length, Relation.ENCLOSING, IASTPreprocessorMacroExpansion.class);
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
* Markus Schorn - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.dom.parser;
|
||||
|
||||
|
@ -41,12 +41,12 @@ public class ASTNodeSpecification<T extends IASTNode> {
|
|||
fRelation= relation;
|
||||
fClass= clazz;
|
||||
fFileOffset= fileOffset;
|
||||
fFileEndOffset= fileOffset+fileLength;
|
||||
fFileEndOffset= fileOffset + fileLength;
|
||||
}
|
||||
|
||||
public void setRangeInSequence(int offsetInSeq, int lengthInSeq) {
|
||||
fSeqNumber= offsetInSeq;
|
||||
fSeqEndNumber= offsetInSeq+lengthInSeq;
|
||||
fSeqEndNumber= offsetInSeq + lengthInSeq;
|
||||
}
|
||||
|
||||
public void setRangeInSequence(int offsetInSeq, int lengthInSeq, boolean zeroRangeToLeft) {
|
||||
|
|
|
@ -6,9 +6,9 @@
|
|||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM - Initial API and implementation
|
||||
* Anton Leherbauer (Wind River Systems)
|
||||
* Markus Schorn (Wind River Systems)
|
||||
* IBM - Initial API and implementation
|
||||
* Anton Leherbauer (Wind River Systems)
|
||||
* Markus Schorn (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.dom.parser;
|
||||
|
||||
|
@ -23,95 +23,10 @@ import org.eclipse.cdt.internal.core.parser.ParserMessages;
|
|||
|
||||
import com.ibm.icu.text.MessageFormat;
|
||||
|
||||
|
||||
/**
|
||||
* Models problems, all problems should derive from this class.
|
||||
*/
|
||||
public class ASTProblem extends ASTNode implements IASTProblem {
|
||||
|
||||
private final int id;
|
||||
private final char[] arg;
|
||||
private boolean isError= false;
|
||||
|
||||
public ASTProblem(IASTNode parent, ASTNodeProperty property, int id, char[] arg, boolean isError, int startNumber, int endNumber) {
|
||||
setParent(parent);
|
||||
setPropertyInParent(property);
|
||||
setOffset(startNumber);
|
||||
setLength(endNumber-startNumber);
|
||||
|
||||
this.isError= isError;
|
||||
this.id = id;
|
||||
this.arg = arg;
|
||||
}
|
||||
|
||||
public ASTProblem(int id, char[] arg, boolean isError) {
|
||||
this.id = id;
|
||||
this.arg = arg;
|
||||
this.isError= isError;
|
||||
}
|
||||
|
||||
public ASTProblem copy() {
|
||||
return copy(CopyStyle.withoutLocations);
|
||||
}
|
||||
|
||||
public ASTProblem copy(CopyStyle style) {
|
||||
ASTProblem problem = new ASTProblem(id, arg == null ? null : arg.clone(), isError);
|
||||
problem.setOffsetAndLength(this);
|
||||
if (style == CopyStyle.withLocations) {
|
||||
problem.setCopyLocation(this);
|
||||
}
|
||||
return problem;
|
||||
}
|
||||
|
||||
public int getID() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public boolean isError() {
|
||||
return isError;
|
||||
}
|
||||
|
||||
public boolean isWarning() {
|
||||
return !isError;
|
||||
}
|
||||
|
||||
public String getMessageWithLocation() {
|
||||
String msg= getMessage();
|
||||
|
||||
char[] file= getOriginatingFileName();
|
||||
int line= getSourceLineNumber();
|
||||
Object[] args = new Object[] { msg, new String(file), new Integer(line) };
|
||||
return ParserMessages.getFormattedString("BaseProblemFactory.problemPattern", args); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
public static String getMessage(int id, String arg) {
|
||||
String msg = errorMessages.get(new Integer(id));
|
||||
if (msg == null)
|
||||
msg = ""; //$NON-NLS-1$
|
||||
|
||||
if (arg != null) {
|
||||
return MessageFormat.format(msg, new Object[] {arg});
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return getMessage(id, arg == null ? null : new String(arg));
|
||||
}
|
||||
|
||||
public boolean checkCategory(int bitmask) {
|
||||
return ((id & bitmask) != 0);
|
||||
}
|
||||
|
||||
public String[] getArguments() {
|
||||
return arg == null ? new String[0] : new String[] {new String(arg)};
|
||||
}
|
||||
|
||||
public char[] getArgument() {
|
||||
return arg;
|
||||
}
|
||||
|
||||
|
||||
protected static final Map<Integer, String> errorMessages;
|
||||
static {
|
||||
errorMessages = new HashMap<Integer, String>();
|
||||
|
@ -179,16 +94,104 @@ public class ASTProblem extends ASTNode implements IASTProblem {
|
|||
ParserMessages.getString("ParserProblemFactory.error.syntax.missingSemicolon")); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.cdt.core.parser.IProblem#getOriginatingFileName()
|
||||
*/
|
||||
private final int id;
|
||||
private final char[] arg;
|
||||
private boolean isError;
|
||||
|
||||
public ASTProblem(IASTNode parent, ASTNodeProperty property, int id, char[] arg, boolean isError,
|
||||
int startNumber, int endNumber) {
|
||||
setParent(parent);
|
||||
setPropertyInParent(property);
|
||||
setOffset(startNumber);
|
||||
setLength(endNumber-startNumber);
|
||||
|
||||
this.isError= isError;
|
||||
this.id = id;
|
||||
this.arg = arg;
|
||||
}
|
||||
|
||||
public ASTProblem(int id, char[] arg, boolean isError) {
|
||||
this.id = id;
|
||||
this.arg = arg;
|
||||
this.isError= isError;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ASTProblem copy() {
|
||||
return copy(CopyStyle.withoutLocations);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ASTProblem copy(CopyStyle style) {
|
||||
ASTProblem problem = new ASTProblem(id, arg == null ? null : arg.clone(), isError);
|
||||
problem.setOffsetAndLength(this);
|
||||
if (style == CopyStyle.withLocations) {
|
||||
problem.setCopyLocation(this);
|
||||
}
|
||||
return problem;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getID() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isError() {
|
||||
return isError;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWarning() {
|
||||
return !isError;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessageWithLocation() {
|
||||
String msg= getMessage();
|
||||
|
||||
char[] file= getOriginatingFileName();
|
||||
int line= getSourceLineNumber();
|
||||
Object[] args = new Object[] { msg, new String(file), new Integer(line) };
|
||||
return ParserMessages.getFormattedString("BaseProblemFactory.problemPattern", args); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
public static String getMessage(int id, String arg) {
|
||||
String msg = errorMessages.get(new Integer(id));
|
||||
if (msg == null)
|
||||
msg = ""; //$NON-NLS-1$
|
||||
|
||||
if (arg != null) {
|
||||
return MessageFormat.format(msg, new Object[] {arg});
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
return getMessage(id, arg == null ? null : new String(arg));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkCategory(int bitmask) {
|
||||
return (id & bitmask) != 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getArguments() {
|
||||
return arg == null ? new String[0] : new String[] { new String(arg) };
|
||||
}
|
||||
|
||||
public char[] getArgument() {
|
||||
return arg;
|
||||
}
|
||||
|
||||
@Override
|
||||
public char[] getOriginatingFileName() {
|
||||
return getContainingFilename().toCharArray();
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.cdt.core.parser.IProblem#getSourceEnd()
|
||||
*/
|
||||
@Override
|
||||
public int getSourceEnd() {
|
||||
final IASTFileLocation location= getFileLocation();
|
||||
if (location != null) {
|
||||
|
@ -197,9 +200,7 @@ public class ASTProblem extends ASTNode implements IASTProblem {
|
|||
return INT_VALUE_NOT_PROVIDED;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.cdt.core.parser.IProblem#getSourceLineNumber()
|
||||
*/
|
||||
@Override
|
||||
public int getSourceLineNumber() {
|
||||
final IASTFileLocation location= getFileLocation();
|
||||
if (location != null) {
|
||||
|
@ -208,9 +209,7 @@ public class ASTProblem extends ASTNode implements IASTProblem {
|
|||
return INT_VALUE_NOT_PROVIDED;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.cdt.core.parser.IProblem#getSourceStart()
|
||||
*/
|
||||
@Override
|
||||
public int getSourceStart() {
|
||||
final IASTFileLocation location= getFileLocation();
|
||||
if (location != null) {
|
||||
|
|
|
@ -6,9 +6,9 @@
|
|||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* John Camelon (IBM Rational Software) - Initial API and implementation
|
||||
* Yuan Zhang / Beth Tibbitts (IBM Research)
|
||||
* Markus Schorn (Wind River Systems)
|
||||
* John Camelon (IBM Rational Software) - Initial API and implementation
|
||||
* Yuan Zhang / Beth Tibbitts (IBM Research)
|
||||
* Markus Schorn (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.dom.parser;
|
||||
|
||||
|
@ -41,11 +41,13 @@ public abstract class ASTTypeIdInitializerExpression extends ASTNode implements
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IASTTypeId getTypeId() {
|
||||
return typeId;
|
||||
}
|
||||
|
||||
public void setTypeId(IASTTypeId typeId) {
|
||||
@Override
|
||||
public void setTypeId(IASTTypeId typeId) {
|
||||
assertNotFrozen();
|
||||
this.typeId = typeId;
|
||||
if (typeId != null) {
|
||||
|
@ -54,11 +56,13 @@ public abstract class ASTTypeIdInitializerExpression extends ASTNode implements
|
|||
}
|
||||
}
|
||||
|
||||
public IASTInitializer getInitializer() {
|
||||
@Override
|
||||
public IASTInitializer getInitializer() {
|
||||
return initializer;
|
||||
}
|
||||
|
||||
public void setInitializer(IASTInitializer initializer) {
|
||||
@Override
|
||||
public void setInitializer(IASTInitializer initializer) {
|
||||
assertNotFrozen();
|
||||
this.initializer = initializer;
|
||||
if (initializer != null) {
|
||||
|
@ -68,32 +72,34 @@ public abstract class ASTTypeIdInitializerExpression extends ASTNode implements
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean accept( ASTVisitor action ){
|
||||
if( action.shouldVisitExpressions ){
|
||||
switch( action.visit( this ) ){
|
||||
case ASTVisitor.PROCESS_ABORT : return false;
|
||||
case ASTVisitor.PROCESS_SKIP : return true;
|
||||
default : break;
|
||||
public boolean accept(ASTVisitor action) {
|
||||
if (action.shouldVisitExpressions) {
|
||||
switch(action.visit(this)) {
|
||||
case ASTVisitor.PROCESS_ABORT: return false;
|
||||
case ASTVisitor.PROCESS_SKIP: return true;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
if( typeId != null ) if( !typeId.accept( action ) ) return false;
|
||||
if( initializer != null ) if( !initializer.accept( action ) ) return false;
|
||||
if (typeId != null && !typeId.accept(action)) return false;
|
||||
if (initializer != null && !initializer.accept(action)) return false;
|
||||
|
||||
if( action.shouldVisitExpressions ){
|
||||
switch( action.leave( this ) ){
|
||||
case ASTVisitor.PROCESS_ABORT : return false;
|
||||
case ASTVisitor.PROCESS_SKIP : return true;
|
||||
default : break;
|
||||
if (action.shouldVisitExpressions) {
|
||||
switch(action.leave(this)) {
|
||||
case ASTVisitor.PROCESS_ABORT: return false;
|
||||
case ASTVisitor.PROCESS_SKIP: return true;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean isLValue() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final ValueCategory getValueCategory() {
|
||||
return ValueCategory.PRVALUE;
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
* Markus Schorn - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.dom.parser;
|
||||
|
||||
|
@ -20,7 +20,6 @@ import org.eclipse.cdt.core.dom.ast.IASTNode;
|
|||
* Collector to find all children for an ast-node.
|
||||
*/
|
||||
class ChildCollector extends ASTGenericVisitor {
|
||||
|
||||
private final IASTNode fNode;
|
||||
private List<IASTNode> fNodes;
|
||||
|
||||
|
|
|
@ -1,65 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2005, 2009 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.dom.parser;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.eclipse.cdt.core.index.IIndexFileLocation;
|
||||
import org.eclipse.cdt.core.parser.CodeReader;
|
||||
import org.eclipse.cdt.core.parser.ICodeReaderCache;
|
||||
import org.eclipse.cdt.internal.core.parser.InternalParserUtil;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
||||
/**
|
||||
* This is an empty implementation of the ICodeReaderCache interface. It is used to implement a
|
||||
* cache for the interface that isn't actually a cache, but rather always creates new CodeReaders
|
||||
* every time a CodeReader is retrieved.
|
||||
*
|
||||
* This cache is not optimized to be run from within Eclipse (i.e. it ignores IResources).
|
||||
* @deprecated
|
||||
*/
|
||||
@Deprecated
|
||||
public class EmptyCodeReaderCache implements ICodeReaderCache {
|
||||
|
||||
/**
|
||||
* Creates a new CodeReader for the given file location.
|
||||
*/
|
||||
public CodeReader get(String location) {
|
||||
try {
|
||||
return new CodeReader(location);
|
||||
} catch (IOException e) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public CodeReader get(String key, IIndexFileLocation ifl) throws CoreException, IOException {
|
||||
return InternalParserUtil.createCodeReader(ifl, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns null.
|
||||
*/
|
||||
public CodeReader remove(String key) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns 0.
|
||||
*/
|
||||
public int getCurrentSpace() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void flush() {
|
||||
// nothing to do
|
||||
|
||||
}
|
||||
}
|
|
@ -6,10 +6,10 @@
|
|||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM - Initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
* Anton Leherbauer (Wind River Systems)
|
||||
* Sergey Prigogin (Google)
|
||||
* IBM - Initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
* Anton Leherbauer (Wind River Systems)
|
||||
* Sergey Prigogin (Google)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.dom.parser;
|
||||
|
||||
|
@ -63,7 +63,7 @@ public class GCCBuiltinSymbolProvider implements IBuiltinBindingsProvider {
|
|||
private static final Map<String, char[]> CHAR_ARRAYS = new HashMap<String, char[]>();
|
||||
|
||||
private IBinding[] fBindings;
|
||||
private IScope fScope= null;
|
||||
private IScope fScope;
|
||||
private final boolean fCpp;
|
||||
private final boolean fGnu;
|
||||
|
||||
|
@ -75,6 +75,7 @@ public class GCCBuiltinSymbolProvider implements IBuiltinBindingsProvider {
|
|||
fGnu= supportGnuSymbols;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBinding[] getBuiltinBindings(IScope scope) {
|
||||
fScope= scope;
|
||||
initialize();
|
||||
|
|
|
@ -6,29 +6,31 @@
|
|||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
* Markus Schorn - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.dom.parser;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier;
|
||||
|
||||
/**
|
||||
* Internal interface for c- or c++ enumeration specifiers.
|
||||
* Internal interface for C or C++ enumeration specifiers.
|
||||
*/
|
||||
public interface IASTInternalEnumerationSpecifier extends IASTEnumerationSpecifier {
|
||||
/**
|
||||
* Notifies that the value computation for the enumeration is started. Returns whether this is the
|
||||
* first attempt to do so.
|
||||
* Notifies that the value computation for the enumeration is started. Returns whether this is
|
||||
* the first attempt to do so.
|
||||
*/
|
||||
boolean startValueComputation();
|
||||
|
||||
/**
|
||||
* @since 5.1
|
||||
*/
|
||||
@Override
|
||||
public IASTInternalEnumerationSpecifier copy();
|
||||
|
||||
/**
|
||||
* @since 5.3
|
||||
*/
|
||||
@Override
|
||||
public IASTInternalEnumerationSpecifier copy(CopyStyle style);
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
* Markus Schorn - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.dom.parser;
|
||||
|
||||
|
@ -18,15 +18,18 @@ import org.eclipse.cdt.core.dom.ast.INodeFactory;
|
|||
*/
|
||||
public abstract class NodeFactory implements INodeFactory {
|
||||
|
||||
@Override
|
||||
public final void setOffsets(IASTNode node, int offset, int endOffset) {
|
||||
((ASTNode) node).setOffsetAndLength(offset, endOffset-offset);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void setEndOffset(IASTNode node, int endOffset) {
|
||||
ASTNode a= (ASTNode) node;
|
||||
a.setLength(endOffset - a.getOffset());
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void setEndOffset(IASTNode node, IASTNode endNode) {
|
||||
ASTNode a= (ASTNode) node;
|
||||
ASTNode e= (ASTNode) endNode;
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
* Markus Schorn - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.dom.parser;
|
||||
|
||||
|
@ -36,26 +36,32 @@ public class ProblemFunctionType extends ProblemType implements ICPPFunctionType
|
|||
return new ProblemFunctionType(buffer.getShort());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IType getReturnType() {
|
||||
return new ProblemType(getID());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IType[] getParameterTypes() {
|
||||
return new IType[] {new ProblemType(getID())};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConst() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVolatile() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean takesVarArgs() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPointerType getThisType() {
|
||||
return new CPPPointerType(new ProblemType(getID()));
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
* Markus Schorn - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.dom.parser;
|
||||
|
||||
|
@ -15,7 +15,6 @@ import org.eclipse.cdt.core.dom.ast.IType;
|
|||
import org.eclipse.cdt.internal.core.parser.ParserMessages;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
||||
|
||||
/**
|
||||
* Implementation of problem types.
|
||||
*/
|
||||
|
@ -28,14 +27,17 @@ public class ProblemType implements IProblemType, ISerializableType {
|
|||
fID= id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getID() {
|
||||
return fID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
return ParserMessages.getProblemPattern(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSameType(IType type) {
|
||||
return type == this;
|
||||
}
|
||||
|
@ -49,6 +51,7 @@ public class ProblemType implements IProblemType, ISerializableType {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void marshal(ITypeMarshalBuffer buffer) throws CoreException {
|
||||
buffer.putByte(ITypeMarshalBuffer.PROBLEM_TYPE);
|
||||
buffer.putShort((short) getID());
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM - Initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
* IBM - Initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||
|
||||
|
@ -24,7 +24,6 @@ import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
|
|||
* @author jcamelon
|
||||
*/
|
||||
public class CPPASTCatchHandler extends ASTNode implements ICPPASTCatchHandler, IASTAmbiguityParent {
|
||||
|
||||
private boolean isCatchAll;
|
||||
private IASTStatement body;
|
||||
private IASTDeclaration declaration;
|
||||
|
@ -38,10 +37,12 @@ public class CPPASTCatchHandler extends ASTNode implements ICPPASTCatchHandler,
|
|||
setDeclaration(declaration);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CPPASTCatchHandler copy() {
|
||||
return copy(CopyStyle.withoutLocations);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CPPASTCatchHandler copy(CopyStyle style) {
|
||||
CPPASTCatchHandler copy = new CPPASTCatchHandler();
|
||||
copy.setDeclaration(declaration == null ? null : declaration.copy(style));
|
||||
|
@ -54,16 +55,19 @@ public class CPPASTCatchHandler extends ASTNode implements ICPPASTCatchHandler,
|
|||
return copy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setIsCatchAll(boolean isEllipsis) {
|
||||
assertNotFrozen();
|
||||
isCatchAll = isEllipsis;
|
||||
}
|
||||
|
||||
public boolean isCatchAll() {
|
||||
@Override
|
||||
public boolean isCatchAll() {
|
||||
return isCatchAll;
|
||||
}
|
||||
|
||||
public void setCatchBody(IASTStatement compoundStatement) {
|
||||
@Override
|
||||
public void setCatchBody(IASTStatement compoundStatement) {
|
||||
assertNotFrozen();
|
||||
body = compoundStatement;
|
||||
if (compoundStatement != null) {
|
||||
|
@ -72,11 +76,13 @@ public class CPPASTCatchHandler extends ASTNode implements ICPPASTCatchHandler,
|
|||
}
|
||||
}
|
||||
|
||||
public IASTStatement getCatchBody() {
|
||||
@Override
|
||||
public IASTStatement getCatchBody() {
|
||||
return body;
|
||||
}
|
||||
|
||||
public void setDeclaration(IASTDeclaration decl) {
|
||||
@Override
|
||||
public void setDeclaration(IASTDeclaration decl) {
|
||||
assertNotFrozen();
|
||||
declaration = decl;
|
||||
if (decl != null) {
|
||||
|
@ -85,48 +91,48 @@ public class CPPASTCatchHandler extends ASTNode implements ICPPASTCatchHandler,
|
|||
}
|
||||
}
|
||||
|
||||
public IASTDeclaration getDeclaration() {
|
||||
@Override
|
||||
public IASTDeclaration getDeclaration() {
|
||||
return declaration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean accept( ASTVisitor action ){
|
||||
if( action.shouldVisitStatements ){
|
||||
switch( action.visit( this ) ){
|
||||
case ASTVisitor.PROCESS_ABORT : return false;
|
||||
case ASTVisitor.PROCESS_SKIP : return true;
|
||||
default : break;
|
||||
public boolean accept(ASTVisitor action) {
|
||||
if (action.shouldVisitStatements) {
|
||||
switch (action.visit(this)) {
|
||||
case ASTVisitor.PROCESS_ABORT: return false;
|
||||
case ASTVisitor.PROCESS_SKIP: return true;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
if( declaration != null ) if( !declaration.accept( action ) ) return false;
|
||||
if( body != null ) if( !body.accept( action ) ) return false;
|
||||
if (declaration != null && !declaration.accept(action)) return false;
|
||||
if (body != null && !body.accept(action)) return false;
|
||||
|
||||
if( action.shouldVisitStatements ){
|
||||
switch( action.leave( this ) ){
|
||||
case ASTVisitor.PROCESS_ABORT : return false;
|
||||
case ASTVisitor.PROCESS_SKIP : return true;
|
||||
default : break;
|
||||
if (action.shouldVisitStatements) {
|
||||
switch (action.leave(this)) {
|
||||
case ASTVisitor.PROCESS_ABORT: return false;
|
||||
case ASTVisitor.PROCESS_SKIP: return true;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void replace(IASTNode child, IASTNode other) {
|
||||
if( body == child )
|
||||
{
|
||||
other.setPropertyInParent( child.getPropertyInParent() );
|
||||
other.setParent( child.getParent() );
|
||||
@Override
|
||||
public void replace(IASTNode child, IASTNode other) {
|
||||
if (body == child) {
|
||||
other.setPropertyInParent(child.getPropertyInParent());
|
||||
other.setParent(child.getParent());
|
||||
body = (IASTStatement) other;
|
||||
}
|
||||
if( declaration == child )
|
||||
{
|
||||
other.setParent( child.getParent() );
|
||||
other.setPropertyInParent( child.getPropertyInParent() );
|
||||
if (declaration == child) {
|
||||
other.setParent(child.getParent());
|
||||
other.setPropertyInParent(child.getPropertyInParent());
|
||||
declaration = (IASTDeclaration) other;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public IScope getScope() {
|
||||
if (scope == null) {
|
||||
scope = new CPPBlockScope(this);
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM - Initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
* IBM - Initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||
|
||||
|
@ -77,6 +77,7 @@ public class CPPASTFunctionDeclarator extends CPPASTDeclarator implements ICPPAS
|
|||
return copy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICPPASTParameterDeclaration[] getParameters() {
|
||||
if (parameters == null)
|
||||
return ICPPASTParameterDeclaration.EMPTY_CPPPARAMETERDECLARATION_ARRAY;
|
||||
|
@ -84,7 +85,8 @@ public class CPPASTFunctionDeclarator extends CPPASTDeclarator implements ICPPAS
|
|||
return parameters= ArrayUtil.trim(parameters);
|
||||
}
|
||||
|
||||
public void addParameterDeclaration(IASTParameterDeclaration parameter) {
|
||||
@Override
|
||||
public void addParameterDeclaration(IASTParameterDeclaration parameter) {
|
||||
assertNotFrozen();
|
||||
if (parameter != null) {
|
||||
parameter.setParent(this);
|
||||
|
@ -93,52 +95,63 @@ public class CPPASTFunctionDeclarator extends CPPASTDeclarator implements ICPPAS
|
|||
}
|
||||
}
|
||||
|
||||
public boolean takesVarArgs() {
|
||||
@Override
|
||||
public boolean takesVarArgs() {
|
||||
return varArgs;
|
||||
}
|
||||
|
||||
public void setVarArgs(boolean value) {
|
||||
@Override
|
||||
public void setVarArgs(boolean value) {
|
||||
assertNotFrozen();
|
||||
varArgs = value;
|
||||
}
|
||||
|
||||
public boolean isConst() {
|
||||
@Override
|
||||
public boolean isConst() {
|
||||
return isConst;
|
||||
}
|
||||
|
||||
public void setConst(boolean value) {
|
||||
@Override
|
||||
public void setConst(boolean value) {
|
||||
assertNotFrozen();
|
||||
this.isConst = value;
|
||||
}
|
||||
|
||||
public boolean isVolatile() {
|
||||
@Override
|
||||
public boolean isVolatile() {
|
||||
return isVolatile;
|
||||
}
|
||||
|
||||
public void setVolatile(boolean value) {
|
||||
@Override
|
||||
public void setVolatile(boolean value) {
|
||||
assertNotFrozen();
|
||||
this.isVolatile = value;
|
||||
}
|
||||
|
||||
public boolean isMutable() {
|
||||
@Override
|
||||
public boolean isMutable() {
|
||||
return isMutable;
|
||||
}
|
||||
|
||||
public void setMutable(boolean value) {
|
||||
@Override
|
||||
public void setMutable(boolean value) {
|
||||
assertNotFrozen();
|
||||
this.isMutable = value;
|
||||
}
|
||||
|
||||
public IASTTypeId[] getExceptionSpecification() {
|
||||
@Override
|
||||
public IASTTypeId[] getExceptionSpecification() {
|
||||
return typeIds= ArrayUtil.trim(typeIds);
|
||||
}
|
||||
|
||||
public void setEmptyExceptionSpecification() {
|
||||
@Override
|
||||
public void setEmptyExceptionSpecification() {
|
||||
assertNotFrozen();
|
||||
typeIds= IASTTypeId.EMPTY_TYPEID_ARRAY;
|
||||
}
|
||||
|
||||
public void addExceptionSpecificationTypeId(IASTTypeId typeId) {
|
||||
@Override
|
||||
public void addExceptionSpecificationTypeId(IASTTypeId typeId) {
|
||||
assertNotFrozen();
|
||||
if (typeId != null) {
|
||||
assert typeIds != null;
|
||||
|
@ -147,12 +160,13 @@ public class CPPASTFunctionDeclarator extends CPPASTDeclarator implements ICPPAS
|
|||
typeId.setPropertyInParent(EXCEPTION_TYPEID);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public IASTTypeId getTrailingReturnType() {
|
||||
@Override
|
||||
public IASTTypeId getTrailingReturnType() {
|
||||
return trailingReturnType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTrailingReturnType(IASTTypeId typeId) {
|
||||
assertNotFrozen();
|
||||
trailingReturnType= typeId;
|
||||
|
@ -162,20 +176,23 @@ public class CPPASTFunctionDeclarator extends CPPASTDeclarator implements ICPPAS
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPureVirtual() {
|
||||
return pureVirtual;
|
||||
}
|
||||
|
||||
public void setPureVirtual(boolean isPureVirtual) {
|
||||
@Override
|
||||
public void setPureVirtual(boolean isPureVirtual) {
|
||||
assertNotFrozen();
|
||||
this.pureVirtual = isPureVirtual;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
@Deprecated
|
||||
public org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer[] getConstructorChain() {
|
||||
if (ASTQueries.findTypeRelevantDeclarator(this) == this) {
|
||||
IASTNode parent= getParent();
|
||||
while(!(parent instanceof IASTDeclaration)) {
|
||||
while (!(parent instanceof IASTDeclaration)) {
|
||||
if (parent == null)
|
||||
break;
|
||||
parent= parent.getParent();
|
||||
|
@ -187,18 +204,20 @@ public class CPPASTFunctionDeclarator extends CPPASTDeclarator implements ICPPAS
|
|||
return org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer.EMPTY_CONSTRUCTORCHAININITIALIZER_ARRAY;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
@Deprecated
|
||||
public void addConstructorToChain(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer initializer) {
|
||||
assertNotFrozen();
|
||||
}
|
||||
|
||||
public ICPPFunctionScope getFunctionScope() {
|
||||
@Override
|
||||
public ICPPFunctionScope getFunctionScope() {
|
||||
if (scope != null)
|
||||
return scope;
|
||||
|
||||
// introduce a scope for function declarations and definitions, only.
|
||||
IASTNode node= getParent();
|
||||
while(!(node instanceof IASTDeclaration)) {
|
||||
while (!(node instanceof IASTDeclaration)) {
|
||||
if (node==null)
|
||||
return null;
|
||||
node= node.getParent();
|
||||
|
@ -232,6 +251,7 @@ public class CPPASTFunctionDeclarator extends CPPASTDeclarator implements ICPPAS
|
|||
return super.postAccept(action);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void replace(IASTNode child, IASTNode other) {
|
||||
if (parameters != null) {
|
||||
for (int i = 0; i < parameters.length; ++i) {
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
* Markus Schorn - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||
|
||||
|
@ -24,7 +24,9 @@ import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
|||
* @see ICPPASTFunctionWithTryBlock
|
||||
*/
|
||||
public class CPPASTFunctionWithTryBlock extends CPPASTFunctionDefinition implements ICPPASTFunctionWithTryBlock {
|
||||
|
||||
private ICPPASTCatchHandler[] catchHandlers;
|
||||
private int catchHandlersPos= -1;
|
||||
|
||||
public CPPASTFunctionWithTryBlock() {
|
||||
}
|
||||
|
||||
|
@ -49,10 +51,12 @@ public class CPPASTFunctionWithTryBlock extends CPPASTFunctionDefinition impleme
|
|||
copy.setDeclarator(declarator == null ? null : declarator.copy(style));
|
||||
copy.setBody(bodyStatement == null ? null : bodyStatement.copy(style));
|
||||
|
||||
for (ICPPASTConstructorChainInitializer initializer : getMemberInitializers())
|
||||
for (ICPPASTConstructorChainInitializer initializer : getMemberInitializers()) {
|
||||
copy.addMemberInitializer(initializer == null ? null : initializer.copy(style));
|
||||
for (ICPPASTCatchHandler handler : getCatchHandlers())
|
||||
}
|
||||
for (ICPPASTCatchHandler handler : getCatchHandlers()) {
|
||||
copy.addCatchHandler(handler == null ? null : handler.copy(style));
|
||||
}
|
||||
|
||||
copy.setOffsetAndLength(this);
|
||||
if (style == CopyStyle.withLocations) {
|
||||
|
@ -61,29 +65,27 @@ public class CPPASTFunctionWithTryBlock extends CPPASTFunctionDefinition impleme
|
|||
return copy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCatchHandler(ICPPASTCatchHandler statement) {
|
||||
assertNotFrozen();
|
||||
if (statement != null) {
|
||||
catchHandlers = (ICPPASTCatchHandler[]) ArrayUtil.append( ICPPASTCatchHandler.class, catchHandlers, ++catchHandlersPos, statement );
|
||||
catchHandlers = (ICPPASTCatchHandler[]) ArrayUtil.append(ICPPASTCatchHandler.class, catchHandlers, ++catchHandlersPos, statement);
|
||||
statement.setParent(this);
|
||||
statement.setPropertyInParent(CATCH_HANDLER);
|
||||
}
|
||||
}
|
||||
|
||||
public ICPPASTCatchHandler [] getCatchHandlers() {
|
||||
if( catchHandlers == null ) return ICPPASTCatchHandler.EMPTY_CATCHHANDLER_ARRAY;
|
||||
catchHandlers = (ICPPASTCatchHandler[]) ArrayUtil.removeNullsAfter( ICPPASTCatchHandler.class, catchHandlers, catchHandlersPos );
|
||||
@Override
|
||||
public ICPPASTCatchHandler[] getCatchHandlers() {
|
||||
if (catchHandlers == null) return ICPPASTCatchHandler.EMPTY_CATCHHANDLER_ARRAY;
|
||||
catchHandlers = (ICPPASTCatchHandler[]) ArrayUtil.removeNullsAfter(ICPPASTCatchHandler.class, catchHandlers, catchHandlersPos);
|
||||
return catchHandlers;
|
||||
}
|
||||
|
||||
|
||||
private ICPPASTCatchHandler [] catchHandlers = null;
|
||||
private int catchHandlersPos=-1;
|
||||
|
||||
@Override
|
||||
protected boolean acceptCatchHandlers( ASTVisitor action ){
|
||||
final ICPPASTCatchHandler [] handlers = getCatchHandlers();
|
||||
for (int i=0; i<handlers.length; i++) {
|
||||
protected boolean acceptCatchHandlers(ASTVisitor action) {
|
||||
final ICPPASTCatchHandler[] handlers = getCatchHandlers();
|
||||
for (int i= 0; i < handlers.length; i++) {
|
||||
if (!handlers[i].accept(action))
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM - Initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
* IBM - Initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||
|
||||
|
@ -32,10 +32,12 @@ public class CPPASTSimpleDeclaration extends ASTNode implements IASTSimpleDeclar
|
|||
setDeclSpecifier(declSpecifier);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CPPASTSimpleDeclaration copy() {
|
||||
return copy(CopyStyle.withoutLocations);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CPPASTSimpleDeclaration copy(CopyStyle style) {
|
||||
CPPASTSimpleDeclaration copy = new CPPASTSimpleDeclaration();
|
||||
copy.setDeclSpecifier(declSpecifier == null ? null : declSpecifier.copy(style));
|
||||
|
@ -48,17 +50,21 @@ public class CPPASTSimpleDeclaration extends ASTNode implements IASTSimpleDeclar
|
|||
return copy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IASTDeclSpecifier getDeclSpecifier() {
|
||||
return declSpecifier;
|
||||
}
|
||||
|
||||
public IASTDeclarator[] getDeclarators() {
|
||||
if (declarators == null) return IASTDeclarator.EMPTY_DECLARATOR_ARRAY;
|
||||
@Override
|
||||
public IASTDeclarator[] getDeclarators() {
|
||||
if (declarators == null)
|
||||
return IASTDeclarator.EMPTY_DECLARATOR_ARRAY;
|
||||
declarators = (IASTDeclarator[]) ArrayUtil.removeNullsAfter(IASTDeclarator.class, declarators, declaratorsPos);
|
||||
return declarators;
|
||||
}
|
||||
|
||||
public void addDeclarator(IASTDeclarator d) {
|
||||
@Override
|
||||
public void addDeclarator(IASTDeclarator d) {
|
||||
assertNotFrozen();
|
||||
if (d != null) {
|
||||
declarators = (IASTDeclarator[]) ArrayUtil.append(IASTDeclarator.class, declarators, ++declaratorsPos, d);
|
||||
|
@ -67,14 +73,15 @@ public class CPPASTSimpleDeclaration extends ASTNode implements IASTSimpleDeclar
|
|||
}
|
||||
}
|
||||
|
||||
private IASTDeclarator[] declarators = null;
|
||||
private IASTDeclarator[] declarators;
|
||||
private int declaratorsPos = -1;
|
||||
private IASTDeclSpecifier declSpecifier;
|
||||
|
||||
/**
|
||||
* @param declSpecifier The declSpecifier to set.
|
||||
*/
|
||||
public void setDeclSpecifier(IASTDeclSpecifier declSpecifier) {
|
||||
@Override
|
||||
public void setDeclSpecifier(IASTDeclSpecifier declSpecifier) {
|
||||
assertNotFrozen();
|
||||
this.declSpecifier = declSpecifier;
|
||||
if (declSpecifier != null) {
|
||||
|
@ -93,10 +100,12 @@ public class CPPASTSimpleDeclaration extends ASTNode implements IASTSimpleDeclar
|
|||
}
|
||||
}
|
||||
|
||||
if (declSpecifier != null) if (!declSpecifier.accept(action)) return false;
|
||||
if (declSpecifier != null && !declSpecifier.accept(action)) return false;
|
||||
IASTDeclarator[] dtors = getDeclarators();
|
||||
for (int i = 0; i < dtors.length; i++)
|
||||
if (!dtors[i].accept(action)) return false;
|
||||
for (int i = 0; i < dtors.length; i++) {
|
||||
if (!dtors[i].accept(action))
|
||||
return false;
|
||||
}
|
||||
|
||||
if (action.shouldVisitDeclarations) {
|
||||
switch (action.leave(this)) {
|
||||
|
@ -108,7 +117,8 @@ public class CPPASTSimpleDeclaration extends ASTNode implements IASTSimpleDeclar
|
|||
return true;
|
||||
}
|
||||
|
||||
public void replace(IASTNode child, IASTNode other) {
|
||||
@Override
|
||||
public void replace(IASTNode child, IASTNode other) {
|
||||
IASTDeclarator[] declarators = getDeclarators();
|
||||
for (int i = 0; i < declarators.length; i++) {
|
||||
if (declarators[i] == child) {
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* John Camelon (IBM) - Initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
* John Camelon (IBM) - Initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||
|
||||
|
@ -24,7 +24,6 @@ public class CPPASTTypeId extends ASTNode implements ICPPASTTypeId {
|
|||
private IASTDeclSpecifier declSpec;
|
||||
private IASTDeclarator absDecl;
|
||||
private boolean isPackExpansion;
|
||||
|
||||
|
||||
public CPPASTTypeId() {
|
||||
}
|
||||
|
@ -34,10 +33,12 @@ public class CPPASTTypeId extends ASTNode implements ICPPASTTypeId {
|
|||
setAbstractDeclarator(absDecl);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CPPASTTypeId copy() {
|
||||
return copy(CopyStyle.withoutLocations);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CPPASTTypeId copy(CopyStyle style) {
|
||||
CPPASTTypeId copy = new CPPASTTypeId();
|
||||
copy.setDeclSpecifier(declSpec == null ? null : declSpec.copy(style));
|
||||
|
@ -50,11 +51,13 @@ public class CPPASTTypeId extends ASTNode implements ICPPASTTypeId {
|
|||
return copy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IASTDeclSpecifier getDeclSpecifier() {
|
||||
return declSpec;
|
||||
}
|
||||
|
||||
public void setDeclSpecifier(IASTDeclSpecifier declSpec) {
|
||||
@Override
|
||||
public void setDeclSpecifier(IASTDeclSpecifier declSpec) {
|
||||
assertNotFrozen();
|
||||
this.declSpec = declSpec;
|
||||
if (declSpec != null) {
|
||||
|
@ -63,12 +66,13 @@ public class CPPASTTypeId extends ASTNode implements ICPPASTTypeId {
|
|||
}
|
||||
}
|
||||
|
||||
public IASTDeclarator getAbstractDeclarator() {
|
||||
@Override
|
||||
public IASTDeclarator getAbstractDeclarator() {
|
||||
return absDecl;
|
||||
}
|
||||
|
||||
|
||||
public void setAbstractDeclarator(IASTDeclarator abstractDeclarator) {
|
||||
@Override
|
||||
public void setAbstractDeclarator(IASTDeclarator abstractDeclarator) {
|
||||
assertNotFrozen();
|
||||
this.absDecl = abstractDeclarator;
|
||||
if (abstractDeclarator != null) {
|
||||
|
@ -77,10 +81,12 @@ public class CPPASTTypeId extends ASTNode implements ICPPASTTypeId {
|
|||
}
|
||||
}
|
||||
|
||||
public boolean isPackExpansion() {
|
||||
@Override
|
||||
public boolean isPackExpansion() {
|
||||
return isPackExpansion;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setIsPackExpansion(boolean val) {
|
||||
isPackExpansion= val;
|
||||
}
|
||||
|
|
|
@ -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>();
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -267,7 +267,7 @@ public class DeclSpecWriter extends NodeWriter {
|
|||
}
|
||||
|
||||
if (hasFreestandingComments(compDeclSpec)) {
|
||||
writeFreeStandingComments(compDeclSpec);
|
||||
writeFreestandingComments(compDeclSpec);
|
||||
}
|
||||
scribe.decrementIndentationLevel();
|
||||
scribe.print('}');
|
||||
|
|
|
@ -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('}');
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -41,9 +41,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTryBlockStatement;
|
|||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTWhileStatement;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguousStatement;
|
||||
import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap;
|
||||
import org.eclipse.cdt.internal.core.dom.rewrite.util.FileContentHelper;
|
||||
import org.eclipse.cdt.internal.core.dom.rewrite.util.FileHelper;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
|
||||
/**
|
||||
* Generates source code of statement nodes. The actual string operations are delegated
|
||||
|
@ -154,12 +151,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 +382,7 @@ public class StatementWriter extends NodeWriter {
|
|||
}
|
||||
|
||||
if (hasFreestandingComments(compoundStatement)) {
|
||||
writeFreeStandingComments(compoundStatement);
|
||||
writeFreestandingComments(compoundStatement);
|
||||
}
|
||||
|
||||
if (decrementIndentationLevelOneMore) {
|
||||
|
@ -438,11 +431,7 @@ public class StatementWriter extends NodeWriter {
|
|||
}
|
||||
|
||||
protected int writeMixedStatement(IASTStatement statement) {
|
||||
IFile file = FileHelper.getFileFromNode(statement);
|
||||
int offset = statement.getFileLocation().getNodeOffset();
|
||||
int length = statement.getFileLocation().getNodeLength();
|
||||
String code = FileContentHelper.getContent(file, offset, length);
|
||||
|
||||
String code = statement.getRawSignature();
|
||||
scribe.println(code);
|
||||
return ASTVisitor.PROCESS_SKIP;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -6,7 +6,7 @@
|
|||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
* Markus Schorn - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.dom.rewrite.changegenerator;
|
||||
|
||||
|
@ -16,15 +16,15 @@ import org.eclipse.osgi.util.NLS;
|
|||
* External strings for the change generator.
|
||||
* @since 5.0
|
||||
*/
|
||||
public class Messages extends NLS {
|
||||
private static final String BUNDLE_NAME = "org.eclipse.cdt.internal.core.dom.rewrite.changegenerator.messages"; //$NON-NLS-1$
|
||||
public class ChangeGeneratorMessages extends NLS {
|
||||
public static String ChangeGenerator_compositeChange;
|
||||
public static String ChangeGenerator_group;
|
||||
|
||||
static {
|
||||
// initialize resource bundle
|
||||
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
|
||||
// Initialize resource bundle
|
||||
NLS.initializeMessages(ChangeGeneratorMessages.class.getName(), ChangeGeneratorMessages.class);
|
||||
}
|
||||
|
||||
private Messages() {
|
||||
private ChangeGeneratorMessages() {
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
@ -22,6 +23,7 @@ import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTInitializer;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
|
@ -36,7 +38,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition;
|
|||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateParameter;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
|
||||
import org.eclipse.cdt.internal.core.dom.rewrite.util.OffsetHelper;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
|
@ -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>>();
|
||||
|
@ -215,7 +215,7 @@ public class ASTCommenter {
|
|||
for (IASTPreprocessorStatement statement : preprocessorStatements) {
|
||||
if (isInWorkspace(statement)) {
|
||||
String fileName = statement.getFileLocation().getFileName();
|
||||
treeOfPreProcessorLines.put(OffsetHelper.getStartingLineNumber(statement), fileName);
|
||||
treeOfPreProcessorLines.put(statement.getFileLocation().getStartingLineNumber(), fileName);
|
||||
ArrayList<Integer> offsetList = ppOffsetForFiles.get(fileName);
|
||||
if (offsetList == null) {
|
||||
offsetList = new ArrayList<Integer>();
|
||||
|
@ -227,8 +227,9 @@ public class ASTCommenter {
|
|||
|
||||
ArrayList<IASTComment> commentsInCode = new ArrayList<IASTComment>();
|
||||
for (IASTComment comment : comments) {
|
||||
int comStartLineNumber = OffsetHelper.getStartingLineNumber(comment);
|
||||
String fileName = comment.getFileLocation().getFileName();
|
||||
IASTFileLocation commentFileLocation = comment.getFileLocation();
|
||||
int comStartLineNumber = commentFileLocation.getStartingLineNumber();
|
||||
String fileName = commentFileLocation.getFileName();
|
||||
if (treeOfPreProcessorLines.containsKey(comStartLineNumber)
|
||||
&& treeOfPreProcessorLines.get(comStartLineNumber).equals(fileName)) {
|
||||
continue;
|
||||
|
@ -248,7 +249,7 @@ public class ASTCommenter {
|
|||
return false;
|
||||
}
|
||||
|
||||
if (comment.getTranslationUnit()==null || comment.getTranslationUnit().getDeclarations().length < 1) {
|
||||
if (comment.getTranslationUnit() == null || comment.getTranslationUnit().getDeclarations().length < 1) {
|
||||
return true;
|
||||
}
|
||||
IASTDeclaration decl = comment.getTranslationUnit().getDeclarations()[0];
|
||||
|
@ -286,7 +287,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 +297,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]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -7,20 +7,21 @@
|
|||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Institute for Software - initial API and implementation
|
||||
* Institute for Software - initial API and implementation
|
||||
* Sergey Prigogin (Google)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.dom.rewrite.commenthandler;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.Vector;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTComment;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTDeclarationStatement;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTExplicitTemplateInstantiation;
|
||||
|
@ -32,32 +33,29 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTLinkageSpecification;
|
|||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTSwitchStatement;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTTemplateDeclaration;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTWhileStatement;
|
||||
import org.eclipse.cdt.internal.core.dom.rewrite.util.OffsetHelper;
|
||||
import org.eclipse.cdt.internal.core.resources.ResourceLookup;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
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,14 +88,14 @@ public class NodeCommenter {
|
|||
ASTNode com = (ASTNode) comment;
|
||||
|
||||
if (node.getFileLocation() == null) {
|
||||
//MacroExpansions have no FileLocation
|
||||
// MacroExpansions have no FileLocation
|
||||
return false;
|
||||
}
|
||||
|
||||
int nodeLineNumber = OffsetHelper.getEndingLineNumber(node);
|
||||
int commentLineNumber= OffsetHelper.getStartingLineNumber(comment);
|
||||
int nodeLineNumber = getEndingLineNumber(node);
|
||||
int commentLineNumber= getStartingLineNumber(comment);
|
||||
|
||||
if (OffsetHelper.getNodeEndPoint(com) <= OffsetHelper.getNodeOffset(node)) {
|
||||
if (getNodeEndPoint(com) <= getNodeOffset(node)) {
|
||||
addLeadingCommentToMap(node, comment);
|
||||
return true;
|
||||
} else if (isTrailing(node, com, nodeLineNumber, commentLineNumber)) {
|
||||
|
@ -111,10 +109,10 @@ 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)) {
|
||||
if (getNodeEndPoint(com) <= getNodeEndPoint(node)) {
|
||||
addFreestandingCommentToMap(node, comment);
|
||||
return true;
|
||||
}
|
||||
|
@ -137,47 +135,23 @@ public class NodeCommenter {
|
|||
}
|
||||
|
||||
private boolean isTrailing(ASTNode node, ASTNode com, int nodeLineNumber, int commentLineNumber) {
|
||||
if (nodeLineNumber == commentLineNumber
|
||||
&& OffsetHelper.getNodeOffset(com) >= OffsetHelper.getNodeEndPoint(node)
|
||||
&& canNotBeAddedToParent(node,com)
|
||||
&& !mustBeAddToSubnodes(node)) {
|
||||
if (OffsetHelper.getNodeOffset(com) < OffsetHelper.getNodeEndPoint(node) + 2) {
|
||||
return true;
|
||||
}
|
||||
IPath path = new Path(node.getContainingFilename());
|
||||
IFile file = ResourceLookup.selectFileForLocation(path, null); // NPE thrown below, like original behavior
|
||||
|
||||
//XXX HSR Guido: Possible Performance Issue (File access)
|
||||
try {
|
||||
InputStream is = file.getContents();
|
||||
|
||||
int length = OffsetHelper.getNodeOffset(com)-OffsetHelper.getNodeEndPoint(node);
|
||||
byte[] b = new byte[length];
|
||||
|
||||
long count = is.skip(OffsetHelper.getEndOffsetWithoutComments(node));
|
||||
if (count < OffsetHelper.getEndOffsetWithoutComments(node)) {
|
||||
return false;
|
||||
}
|
||||
if (is.read(b, 0, length) == -1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (byte bb : b) {
|
||||
if (!Character.isWhitespace(bb)) {
|
||||
is.close();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
is.close();
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
if (nodeLineNumber != commentLineNumber ||
|
||||
getNodeOffset(com) < getNodeEndPoint(node) ||
|
||||
!canNotBeAddedToParent(node, com) ||
|
||||
mustBeAddedToSubnodes(node)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
if (getNodeOffset(com) < getNodeEndPoint(node) + 2) {
|
||||
return true;
|
||||
}
|
||||
String code = node.getTranslationUnit().getRawSignature();
|
||||
int commentOffset = getNodeOffset(com) - getNodeEndPoint(node) + getNodeEndOffset(node);
|
||||
for (int offset = getNodeEndOffset(node); offset < commentOffset; offset++) {
|
||||
if (!Character.isWhitespace(code.charAt(offset)))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean canNotBeAddedToParent(ASTNode node, ASTNode com) {
|
||||
ASTNode parent = (ASTNode) node.getParent();
|
||||
|
||||
|
@ -192,10 +166,10 @@ public class NodeCommenter {
|
|||
} else if (parent instanceof ICPPASTBaseSpecifier) {
|
||||
parent = (ASTNode) parent.getParent();
|
||||
}
|
||||
return !(OffsetHelper.getNodeOffset(com) >= OffsetHelper.getNodeEndPoint(parent));
|
||||
return getNodeOffset(com) < getNodeEndPoint(parent);
|
||||
}
|
||||
|
||||
private boolean mustBeAddToSubnodes(ASTNode node) {
|
||||
private boolean mustBeAddedToSubnodes(ASTNode node) {
|
||||
return hasNodeSameEndingAsSubnode(node);
|
||||
}
|
||||
|
||||
|
@ -274,4 +248,25 @@ public class NodeCommenter {
|
|||
}
|
||||
return !node.getFileLocation().getFileName().equals(comment.getFileLocation().getFileName());
|
||||
}
|
||||
|
||||
private static int getNodeEndOffset(IASTNode node) {
|
||||
IASTFileLocation fileLocation = node.getFileLocation();
|
||||
return fileLocation.getNodeOffset() + fileLocation.getNodeLength();
|
||||
}
|
||||
|
||||
private static int getNodeOffset(ASTNode node) {
|
||||
return node.getOffset();
|
||||
}
|
||||
|
||||
private static int getNodeEndPoint(ASTNode node) {
|
||||
return node.getOffset() + node.getLength();
|
||||
}
|
||||
|
||||
private static int getStartingLineNumber(IASTNode node) {
|
||||
return node.getFileLocation().getStartingLineNumber();
|
||||
}
|
||||
|
||||
private static int getEndingLineNumber(IASTNode node) {
|
||||
return node.getFileLocation().getEndingLineNumber();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,94 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* 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
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Institute for Software - initial API and implementation
|
||||
******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.dom.rewrite.util;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
||||
/**
|
||||
* @author Emanuel Graf IFS
|
||||
*/
|
||||
public class FileContentHelper {
|
||||
private static final int BUFFER_SIZE = 2048;
|
||||
|
||||
public static String getContent(IFile file, int start) throws CoreException, IOException {
|
||||
InputStreamReader reader = getReaderForFile(file);
|
||||
skip(start, reader);
|
||||
|
||||
final String rest = readRest(reader);
|
||||
reader.close();
|
||||
return rest;
|
||||
}
|
||||
|
||||
public static String getContent(IFile file, int start, int length) {
|
||||
try {
|
||||
InputStreamReader r = getReaderForFile(file);
|
||||
char[] chars = new char[length];
|
||||
|
||||
skip(start, r);
|
||||
|
||||
read(length, r, chars);
|
||||
r.close();
|
||||
return new String(chars);
|
||||
} catch (IOException e) {
|
||||
CCorePlugin.log(e);
|
||||
} catch (CoreException e) {
|
||||
CCorePlugin.log(e);
|
||||
}
|
||||
return ""; //$NON-NLS-1$
|
||||
}
|
||||
|
||||
private static InputStreamReader getReaderForFile(IFile file)
|
||||
throws CoreException, UnsupportedEncodingException {
|
||||
InputStream contents = file.getContents();
|
||||
return new InputStreamReader(contents, file.getCharset());
|
||||
}
|
||||
|
||||
private static String readRest(InputStreamReader reader) throws IOException {
|
||||
StringBuilder content = new StringBuilder();
|
||||
char[] buffer = new char[BUFFER_SIZE];
|
||||
int bytesRead = 0;
|
||||
while ((bytesRead = reader.read(buffer)) >= 0) {
|
||||
content.append(buffer, 0, bytesRead);
|
||||
}
|
||||
|
||||
return content.toString();
|
||||
}
|
||||
|
||||
private static void read(int length, InputStreamReader r, char[] bytes) throws IOException {
|
||||
int bufferOffset = 0;
|
||||
int charactersRead = 0;
|
||||
while (charactersRead >= 0 && length > 0) {
|
||||
charactersRead = r.read(bytes, bufferOffset, length);
|
||||
if (charactersRead > 0) {
|
||||
bufferOffset += charactersRead;
|
||||
length -= charactersRead;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void skip(int start, InputStreamReader r) throws IOException {
|
||||
long skipped = 0;
|
||||
while (skipped >= 0 && start > 0 && r.ready()) {
|
||||
skipped = r.skip(start);
|
||||
if (skipped > 0) {
|
||||
start -= skipped;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -11,21 +11,12 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.dom.rewrite.util;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.internal.core.resources.ResourceLookup;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.ProjectScope;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
import org.eclipse.core.runtime.Platform;
|
||||
import org.eclipse.core.runtime.preferences.IScopeContext;
|
||||
import org.eclipse.core.runtime.preferences.InstanceScope;
|
||||
import org.eclipse.jface.text.TextUtilities;
|
||||
|
||||
public class FileHelper {
|
||||
|
@ -36,36 +27,13 @@ public class FileHelper {
|
|||
return ResourceLookup.selectFileForLocation(implPath, null);
|
||||
}
|
||||
|
||||
public static boolean isFirstWithinSecondLocation(IASTFileLocation loc1, IASTFileLocation loc2) {
|
||||
boolean isEquals = true;
|
||||
|
||||
isEquals &= loc1.getFileName().equals(loc2.getFileName());
|
||||
isEquals &= loc1.getNodeOffset() >= loc2.getNodeOffset();
|
||||
isEquals &= loc1.getNodeOffset() + loc1.getNodeLength() <= loc2.getNodeOffset()
|
||||
+ loc2.getNodeLength();
|
||||
|
||||
return isEquals;
|
||||
}
|
||||
|
||||
public static String determineLineDelimiter(IFile file) {
|
||||
String fileContent = ""; //$NON-NLS-1$
|
||||
|
||||
try {
|
||||
fileContent = FileContentHelper.getContent(file, 0);
|
||||
} catch (CoreException e) {
|
||||
} catch (IOException e) {
|
||||
}
|
||||
|
||||
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject();
|
||||
IScopeContext[] scopeContext;
|
||||
if (project != null) {
|
||||
scopeContext = new IScopeContext[] { new ProjectScope(project) };
|
||||
} else {
|
||||
scopeContext = new IScopeContext[] { InstanceScope.INSTANCE };
|
||||
}
|
||||
public static String determineLineDelimiter(String text) {
|
||||
String platformDefaultLineDelimiter = System.getProperty("line.separator", DEFAULT_LINE_DELIMITTER); //$NON-NLS-1$
|
||||
String defaultLineDelimiter = Platform.getPreferencesService().getString(Platform.PI_RUNTIME,
|
||||
Platform.PREF_LINE_SEPARATOR, platformDefaultLineDelimiter, scopeContext);
|
||||
return TextUtilities.determineLineDelimiter(fileContent.toString(), defaultLineDelimiter);
|
||||
Platform.PREF_LINE_SEPARATOR, platformDefaultLineDelimiter, null);
|
||||
if (text.isEmpty()) {
|
||||
return defaultLineDelimiter;
|
||||
}
|
||||
return TextUtilities.determineLineDelimiter(text, defaultLineDelimiter);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,95 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
|
||||
* Rapperswil, University of applied sciences and others
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Institute for Software - initial API and implementation
|
||||
******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.dom.rewrite.util;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTMacroExpansionLocation;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNodeLocation;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
|
||||
|
||||
/**
|
||||
* @author Emanuel Graf IFS
|
||||
*/
|
||||
public class OffsetHelper {
|
||||
|
||||
public static int getOffsetIncludingComment(IASTNode node) {
|
||||
int nodeStart = Integer.MAX_VALUE;
|
||||
IASTNodeLocation[] nodeLocations = node.getNodeLocations();
|
||||
if (nodeLocations.length != 1) {
|
||||
int offset;
|
||||
for (IASTNodeLocation location : nodeLocations) {
|
||||
if (location instanceof IASTMacroExpansionLocation) {
|
||||
IASTMacroExpansionLocation macroLoc = (IASTMacroExpansionLocation) location;
|
||||
offset = macroLoc.asFileLocation().getNodeOffset();
|
||||
} else {
|
||||
offset = location.asFileLocation().getNodeOffset();
|
||||
}
|
||||
if (offset < nodeStart)
|
||||
nodeStart = offset;
|
||||
}
|
||||
} else {
|
||||
nodeStart = node.getFileLocation().getNodeOffset();
|
||||
}
|
||||
|
||||
return nodeStart;
|
||||
}
|
||||
|
||||
public static int getEndOffsetIncludingComments(IASTNode node) {
|
||||
int fileOffset = 0;
|
||||
int length = 0;
|
||||
|
||||
IASTNodeLocation[] nodeLocations = node.getNodeLocations();
|
||||
if (nodeLocations.length != 1) {
|
||||
for (IASTNodeLocation location : nodeLocations) {
|
||||
if (location instanceof IASTMacroExpansionLocation) {
|
||||
IASTMacroExpansionLocation macroLoc = (IASTMacroExpansionLocation) location;
|
||||
fileOffset = macroLoc.asFileLocation().getNodeOffset();
|
||||
length = macroLoc.asFileLocation().getNodeLength();
|
||||
} else {
|
||||
fileOffset = location.asFileLocation().getNodeOffset();
|
||||
length = location.asFileLocation().getNodeLength();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
IASTFileLocation loc = node.getFileLocation();
|
||||
fileOffset = loc.getNodeOffset();
|
||||
length = loc.getNodeLength();
|
||||
}
|
||||
return fileOffset + length;
|
||||
|
||||
}
|
||||
|
||||
public static int getEndOffsetWithoutComments(IASTNode node) {
|
||||
return node.getFileLocation().getNodeOffset() + node.getFileLocation().getNodeLength();
|
||||
}
|
||||
|
||||
public static int getLengthIncludingComment(IASTNode node) {
|
||||
return getEndOffsetIncludingComments(node) - getOffsetIncludingComment(node);
|
||||
}
|
||||
|
||||
public static int getNodeOffset(ASTNode node) {
|
||||
return node.getOffset();
|
||||
}
|
||||
|
||||
public static int getNodeEndPoint(ASTNode node) {
|
||||
return node.getOffset() + node.getLength();
|
||||
}
|
||||
|
||||
public static int getStartingLineNumber(IASTNode node) {
|
||||
return node.getFileLocation().getStartingLineNumber();
|
||||
}
|
||||
|
||||
public static int getEndingLineNumber(IASTNode node) {
|
||||
return node.getFileLocation().getEndingLineNumber();
|
||||
}
|
||||
}
|
|
@ -68,6 +68,7 @@ public class LocationMap implements ILocationResolver {
|
|||
fLexerOptions= lexOptions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LexerOptions getLexerOptions() {
|
||||
return fLexerOptions;
|
||||
}
|
||||
|
@ -382,6 +383,7 @@ public class LocationMap implements ILocationResolver {
|
|||
addMacroReference(undef.getMacroName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRootNode(IASTTranslationUnit root) {
|
||||
fTranslationUnit= root;
|
||||
if (fTranslationUnit instanceof ISkippedIndexedFilesListener) {
|
||||
|
@ -389,6 +391,7 @@ public class LocationMap implements ILocationResolver {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTranslationUnitPath() {
|
||||
return fTranslationUnitPath;
|
||||
}
|
||||
|
@ -418,11 +421,13 @@ public class LocationMap implements ILocationResolver {
|
|||
return fCurrentContext.getSequenceNumberForOffset(offset, offset < fLastChildInsertionOffset);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getContainingFilePath(int sequenceNumber) {
|
||||
LocationCtx ctx= fRootContext.findSurroundingContext(sequenceNumber, 1);
|
||||
return new String(ctx.getFilePath());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPartOfSourceFile(int sequenceNumber) {
|
||||
LocationCtx ctx= fRootContext.findSurroundingContext(sequenceNumber, 1);
|
||||
if (ctx == fRootContext && fTranslationUnit != null)
|
||||
|
@ -431,14 +436,17 @@ public class LocationMap implements ILocationResolver {
|
|||
return ctx.isSourceFile();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ASTFileLocation getMappedFileLocation(int sequenceNumber, int length) {
|
||||
return fRootContext.findMappedFileLocation(sequenceNumber, length);
|
||||
}
|
||||
|
||||
public int convertToSequenceEndNumber(int sequenceNumber) {
|
||||
@Override
|
||||
public int convertToSequenceEndNumber(int sequenceNumber) {
|
||||
return fRootContext.convertToSequenceEndNumber(sequenceNumber);
|
||||
}
|
||||
|
||||
@Override
|
||||
public char[] getUnpreprocessedSignature(IASTFileLocation loc) {
|
||||
ASTFileLocation floc= convertFileLocation(loc);
|
||||
if (floc == null) {
|
||||
|
@ -447,6 +455,7 @@ public class LocationMap implements ILocationResolver {
|
|||
return floc.getSource();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IASTPreprocessorMacroExpansion[] getMacroExpansions(IASTFileLocation loc) {
|
||||
ASTFileLocation floc= convertFileLocation(loc);
|
||||
if (floc == null) {
|
||||
|
@ -485,17 +494,19 @@ public class LocationMap implements ILocationResolver {
|
|||
return getMappedFileLocation(sequenceNumber, length);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IASTNodeLocation[] getLocations(int sequenceNumber, int length) {
|
||||
ArrayList<IASTNodeLocation> result= new ArrayList<IASTNodeLocation>();
|
||||
fRootContext.collectLocations(sequenceNumber, length, result);
|
||||
return result.toArray(new IASTNodeLocation[result.size()]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isPartOfTranslationUnitFile(int sequenceNumber) {
|
||||
return fRootContext.isThisFile(sequenceNumber);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IASTImageLocation getImageLocation(int sequenceNumber, int length) {
|
||||
ArrayList<IASTNodeLocation> result= new ArrayList<IASTNodeLocation>();
|
||||
fRootContext.collectLocations(sequenceNumber, length, result);
|
||||
|
@ -515,6 +526,7 @@ public class LocationMap implements ILocationResolver {
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void findPreprocessorNode(ASTNodeSpecification<?> nodeSpec) {
|
||||
final int sequenceStart= nodeSpec.getSequenceStart();
|
||||
final int sequenceEnd= nodeSpec.getSequenceEnd();
|
||||
|
@ -600,6 +612,7 @@ public class LocationMap implements ILocationResolver {
|
|||
return lower;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSequenceNumberForFileOffset(String filePath, int fileOffset) {
|
||||
LocationCtx ctx= fRootContext;
|
||||
if (filePath != null) {
|
||||
|
@ -624,6 +637,7 @@ public class LocationMap implements ILocationResolver {
|
|||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IASTFileLocation flattenLocations(IASTNodeLocation[] locations) {
|
||||
if (locations.length == 0) {
|
||||
return null;
|
||||
|
@ -643,7 +657,7 @@ public class LocationMap implements ILocationResolver {
|
|||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public IASTPreprocessorMacroDefinition[] getMacroDefinitions() {
|
||||
ArrayList<Object> result= new ArrayList<Object>();
|
||||
for (Iterator<ASTPreprocessorNode> iterator = fDirectives.iterator(); iterator.hasNext();) {
|
||||
|
@ -655,7 +669,8 @@ public class LocationMap implements ILocationResolver {
|
|||
return result.toArray(new IASTPreprocessorMacroDefinition[result.size()]);
|
||||
}
|
||||
|
||||
public IASTPreprocessorIncludeStatement[] getIncludeDirectives() {
|
||||
@Override
|
||||
public IASTPreprocessorIncludeStatement[] getIncludeDirectives() {
|
||||
ArrayList<Object> result= new ArrayList<Object>();
|
||||
for (Iterator<ASTPreprocessorNode> iterator = fDirectives.iterator(); iterator.hasNext();) {
|
||||
Object directive= iterator.next();
|
||||
|
@ -666,26 +681,32 @@ public class LocationMap implements ILocationResolver {
|
|||
return result.toArray(new IASTPreprocessorIncludeStatement[result.size()]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IASTComment[] getComments() {
|
||||
return fComments.toArray(new IASTComment[fComments.size()]);
|
||||
}
|
||||
|
||||
public IASTPreprocessorStatement[] getAllPreprocessorStatements() {
|
||||
@Override
|
||||
public IASTPreprocessorStatement[] getAllPreprocessorStatements() {
|
||||
return fDirectives.toArray(new IASTPreprocessorStatement[fDirectives.size()]);
|
||||
}
|
||||
|
||||
public IASTPreprocessorMacroDefinition[] getBuiltinMacroDefinitions() {
|
||||
@Override
|
||||
public IASTPreprocessorMacroDefinition[] getBuiltinMacroDefinitions() {
|
||||
return fBuiltinMacros.toArray(new IASTPreprocessorMacroDefinition[fBuiltinMacros.size()]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IASTProblem[] getScannerProblems() {
|
||||
return fProblems.toArray(new IASTProblem[fProblems.size()]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getScannerProblemsCount() {
|
||||
return fProblems.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IASTName[] getDeclarations(IMacroBinding binding) {
|
||||
IASTPreprocessorMacroDefinition def = getMacroDefinition(binding);
|
||||
return def == null ? IASTName.EMPTY_NAME_ARRAY: new IASTName[] { def.getName() };
|
||||
|
@ -712,6 +733,7 @@ public class LocationMap implements ILocationResolver {
|
|||
return fMacroDefinitionMap.get(binding);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IASTName[] getReferences(IMacroBinding binding) {
|
||||
List<IASTName> result= new ArrayList<IASTName>();
|
||||
for (IASTName name : fMacroReferences) {
|
||||
|
@ -737,6 +759,7 @@ public class LocationMap implements ILocationResolver {
|
|||
return result.toArray(new ASTPreprocessorName[result.size()]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IDependencyTree getDependencyTree() {
|
||||
return new DependencyTree(fRootContext);
|
||||
}
|
||||
|
|
|
@ -525,26 +525,41 @@
|
|||
</content-type>
|
||||
</extension>
|
||||
|
||||
<!-- the reserved filenames by the C++ standard -->
|
||||
<!-- The reserved filenames by the C++ standard (cinttypes is G++ specific) -->
|
||||
<extension point="org.eclipse.core.contenttype.contentTypes">
|
||||
<file-association
|
||||
content-type="org.eclipse.cdt.core.cxxHeader"
|
||||
file-names="algorithm,bitset,cassert,cctype,cerrno,cfloat,ciso646,climits,clocale,cmath,complex,csetjmp,csignal"/>
|
||||
file-names="algorithm,array,atomic,bitset,cassert,ccomplex,cctype,cerrno,cfenv,cfloat,chrono,cinttypes"/>
|
||||
</extension>
|
||||
<extension point="org.eclipse.core.contenttype.contentTypes">
|
||||
<file-association
|
||||
content-type="org.eclipse.cdt.core.cxxHeader"
|
||||
file-names="cstdarg,cstddef,cstdio,cstdlib,cstring,ctime,cwchar,cwctype,deque,exception,fstream,functional"/>
|
||||
file-names="ciso646,climits,clocale,cmath,codecvt,complex,csetjmp,csignal,cstdarg,cstdbool,cstddef"/>
|
||||
</extension>
|
||||
<extension point="org.eclipse.core.contenttype.contentTypes">
|
||||
<file-association
|
||||
content-type="org.eclipse.cdt.core.cxxHeader"
|
||||
file-names="hash_map,hash_set,iomanip,ios,iosfwd,iostream,istream,iterator,limits,list,locale,map,memory"/>
|
||||
file-names="cstdint,cstdio,cstdlib,cstring,ctime,cwchar,cwctype,deque,exception,forward_list,fstream"/>
|
||||
</extension>
|
||||
<extension point="org.eclipse.core.contenttype.contentTypes">
|
||||
<file-association
|
||||
content-type="org.eclipse.cdt.core.cxxHeader"
|
||||
file-names="new,numeric,ostream,queue,set,sstream,stack,stdexcept,streambuf,string,strstream,typeinfo,utility,valarray,vector"/>
|
||||
file-names="functional,future,hash_map,hash_set,initializer_list,iomanip,ios,iosfwd,iostream,istream"/>
|
||||
</extension>
|
||||
<extension point="org.eclipse.core.contenttype.contentTypes">
|
||||
<file-association
|
||||
content-type="org.eclipse.cdt.core.cxxHeader"
|
||||
file-names="iterator,limits,list,locale,map,memory,mutex,new,numeric,ostream,queue,random,ratio,regex"/>
|
||||
</extension>
|
||||
<extension point="org.eclipse.core.contenttype.contentTypes">
|
||||
<file-association
|
||||
content-type="org.eclipse.cdt.core.cxxHeader"
|
||||
file-names="set,sstream,stack,stdexcept,streambuf,string,strstream,system_error,thread,tuple"/>
|
||||
</extension>
|
||||
<extension point="org.eclipse.core.contenttype.contentTypes">
|
||||
<file-association
|
||||
content-type="org.eclipse.cdt.core.cxxHeader"
|
||||
file-names="typeindex,typeinfo,type_traits,unordered_map,unordered_set,utility,valarray,vector"/>
|
||||
</extension>
|
||||
|
||||
<!-- =================================================================================== -->
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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">
|
||||
|
|
|
@ -296,7 +296,7 @@ class Klass {
|
|||
void set(bool b) {
|
||||
}
|
||||
|
||||
void test() {
|
||||
void test() {
|
||||
other o;
|
||||
this->set(/*$*/o.value()/*$$*/);
|
||||
}
|
||||
|
@ -615,185 +615,30 @@ void Test::test() {
|
|||
bool b = invalid();
|
||||
}
|
||||
|
||||
//!Extract int constant
|
||||
//!Extract expression with typedef Bug 331985
|
||||
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
|
||||
|
||||
//@.config
|
||||
filename=test.cpp
|
||||
methodname=size
|
||||
|
||||
//@test.h
|
||||
class Test {
|
||||
void test();
|
||||
};
|
||||
|
||||
|
||||
//=
|
||||
class Test {
|
||||
void test();
|
||||
int size();
|
||||
};
|
||||
|
||||
|
||||
//@test.cpp
|
||||
#include "test.h"
|
||||
|
||||
void Test::test() {
|
||||
int i = /*$*/42/*$$*/;
|
||||
}
|
||||
|
||||
//=
|
||||
#include "test.h"
|
||||
|
||||
int Test::size() {
|
||||
return 42;
|
||||
}
|
||||
|
||||
void Test::test() {
|
||||
int i = size();
|
||||
}
|
||||
|
||||
//!Extract char constant
|
||||
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
|
||||
|
||||
//@.config
|
||||
filename=test.cpp
|
||||
methodname=newline
|
||||
|
||||
//@test.h
|
||||
class Test {
|
||||
void test();
|
||||
};
|
||||
|
||||
|
||||
//=
|
||||
class Test {
|
||||
void test();
|
||||
char newline();
|
||||
};
|
||||
|
||||
|
||||
//@test.cpp
|
||||
#include "test.h"
|
||||
|
||||
void Test::test() {
|
||||
char nl = /*$*/'\n'/*$$*/;
|
||||
}
|
||||
|
||||
//=
|
||||
#include "test.h"
|
||||
|
||||
char Test::newline() {
|
||||
return '\n';
|
||||
}
|
||||
|
||||
void Test::test() {
|
||||
char nl = newline();
|
||||
}
|
||||
|
||||
//!Extract boolean true constant
|
||||
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
|
||||
|
||||
//@.config
|
||||
filename=test.cpp
|
||||
methodname=valid
|
||||
|
||||
//@test.h
|
||||
class Test {
|
||||
void test();
|
||||
};
|
||||
|
||||
|
||||
//=
|
||||
class Test {
|
||||
void test();
|
||||
bool valid();
|
||||
};
|
||||
|
||||
|
||||
//@test.cpp
|
||||
#include "test.h"
|
||||
|
||||
void Test::test() {
|
||||
bool b = /*$*/true/*$$*/;
|
||||
}
|
||||
|
||||
//=
|
||||
#include "test.h"
|
||||
|
||||
bool Test::valid() {
|
||||
return true;
|
||||
}
|
||||
|
||||
void Test::test() {
|
||||
bool b = valid();
|
||||
}
|
||||
|
||||
//!Extract boolean false constant
|
||||
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
|
||||
|
||||
//@.config
|
||||
filename=test.cpp
|
||||
methodname=invalid
|
||||
|
||||
//@test.h
|
||||
class Test {
|
||||
void test();
|
||||
};
|
||||
|
||||
|
||||
//=
|
||||
class Test {
|
||||
void test();
|
||||
bool invalid();
|
||||
};
|
||||
|
||||
|
||||
//@test.cpp
|
||||
#include "test.h"
|
||||
|
||||
void Test::test() {
|
||||
bool b = /*$*/false/*$$*/;
|
||||
}
|
||||
|
||||
//=
|
||||
#include "test.h"
|
||||
|
||||
bool Test::invalid() {
|
||||
return false;
|
||||
}
|
||||
|
||||
void Test::test() {
|
||||
bool b = invalid();
|
||||
}
|
||||
|
||||
//!Extract expresion with typdef 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 +647,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 +660,6 @@ void foo() {
|
|||
int x = 3;
|
||||
double y = bar(x);
|
||||
}
|
||||
|
||||
//! Extract macro
|
||||
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
|
||||
|
||||
|
@ -836,7 +677,6 @@ int main() {
|
|||
|
||||
return i;
|
||||
}
|
||||
|
||||
//=
|
||||
#define five 5
|
||||
#define ADD(a, b) a + b
|
||||
|
@ -851,37 +691,3 @@ int main() {
|
|||
|
||||
return i;
|
||||
}
|
||||
|
||||
//! Extract macro
|
||||
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
|
||||
|
||||
//@.config
|
||||
filename=test.cpp
|
||||
methodname=bar
|
||||
|
||||
//@test.cpp
|
||||
#define five 5
|
||||
#define ADD(a, b) a + b
|
||||
|
||||
int main() {
|
||||
int i = five; //comment3
|
||||
i = /*$*/ADD(i, five)/*$$*/;
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
//=
|
||||
#define five 5
|
||||
#define ADD(a, b) a + b
|
||||
|
||||
int bar(int& i) {
|
||||
return ADD(i, five);
|
||||
}
|
||||
|
||||
int main() {
|
||||
int i = five; //comment3
|
||||
i = bar(i);
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
@ -2220,7 +2207,6 @@ test::string toXML() {
|
|||
int main() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
//=
|
||||
#include "testString.h"
|
||||
|
||||
|
@ -2237,111 +2223,6 @@ test::string toXML() {
|
|||
int main() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
//!Bug 248622: Extract function fails to extract several expressions; Selection at the end
|
||||
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
|
||||
//@.config
|
||||
filename=Test.cpp
|
||||
methodname=endTag
|
||||
//@testString.h
|
||||
|
||||
namespace test {
|
||||
|
||||
class string {
|
||||
public:
|
||||
friend string operator+(const string& lhs, const string& rhs) {
|
||||
return rhs;
|
||||
}
|
||||
|
||||
string operator+(const string& rhs) { return rhs; }
|
||||
string(char* cp) {}
|
||||
string() {};
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
//@Test.cpp
|
||||
#include "testString.h"
|
||||
|
||||
test::string toXML() {
|
||||
test::string name;
|
||||
name = "hello";
|
||||
return "<" + name + ">" + /*$*/"</" + name + ">"/*$$*/;
|
||||
}
|
||||
|
||||
int main() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
//=
|
||||
#include "testString.h"
|
||||
|
||||
const char endTag(test::string name) {
|
||||
return "</" + name + ">";
|
||||
}
|
||||
|
||||
test::string toXML() {
|
||||
test::string name;
|
||||
name = "hello";
|
||||
return "<" + name + ">" + endTag(name);
|
||||
}
|
||||
|
||||
int main() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
//!Bug 248622: Extract function fails to extract several expressions; Selection in the middle
|
||||
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
|
||||
//@.config
|
||||
filename=Test.cpp
|
||||
methodname=exp
|
||||
//@testString.h
|
||||
|
||||
namespace test {
|
||||
|
||||
class string {
|
||||
public:
|
||||
friend string operator+(const string& lhs, const string& rhs) {
|
||||
return rhs;
|
||||
}
|
||||
|
||||
string operator+(const string& rhs) { return rhs; }
|
||||
string(char* cp) {}
|
||||
string() {};
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
//@Test.cpp
|
||||
#include "testString.h"
|
||||
|
||||
test::string toXML() {
|
||||
test::string name;
|
||||
name = "hello";
|
||||
return "<" + name + /*$*/">" + "</"/*$$*/ + name + ">";
|
||||
}
|
||||
|
||||
int main() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
//=
|
||||
#include "testString.h"
|
||||
|
||||
const char exp() {
|
||||
return ">" + "</";
|
||||
}
|
||||
|
||||
test::string toXML() {
|
||||
test::string name;
|
||||
name = "hello";
|
||||
return "<" + name + exp() + name + ">";
|
||||
}
|
||||
|
||||
int main() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
//!Bug#262000 refactoring "extract function" misinterprets artificial blocks
|
||||
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
|
||||
//@.config
|
||||
|
@ -2354,7 +2235,6 @@ int main(int argc, char** argv) {
|
|||
a++;
|
||||
}/*$$*/
|
||||
}
|
||||
|
||||
//=
|
||||
void exp() {
|
||||
int a = 0;
|
||||
|
@ -2366,7 +2246,6 @@ void exp() {
|
|||
int main(int argc, char** argv) {
|
||||
exp();
|
||||
}
|
||||
|
||||
//!Bug#264712 Refactor extract function deletes comments in header
|
||||
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
|
||||
//@.config
|
||||
|
@ -2411,7 +2290,6 @@ class Test {
|
|||
};
|
||||
|
||||
#endif
|
||||
|
||||
//=
|
||||
/*
|
||||
* Copyright 2009
|
||||
|
@ -2438,11 +2316,11 @@ class Test {
|
|||
* Retain a value for something.
|
||||
*/
|
||||
int m_value;
|
||||
|
||||
int exp();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
//@test.cpp
|
||||
#include "test.h"
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue