mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Source Change Generator for ASTTransformations by Emanuel Graf and others, bug 214605.
This commit is contained in:
parent
f242093f1e
commit
1f19d506f8
120 changed files with 17078 additions and 14 deletions
|
@ -23,7 +23,8 @@ Require-Bundle: org.eclipse.core.resources,
|
|||
org.eclipse.ui.ide,
|
||||
org.eclipse.ui,
|
||||
org.eclipse.jface.text,
|
||||
org.eclipse.core.filesystem
|
||||
org.eclipse.core.filesystem,
|
||||
org.eclipse.ltk.core.refactoring;bundle-version="3.4.0"
|
||||
Bundle-ActivationPolicy: lazy
|
||||
Bundle-Vendor: Eclipse.org
|
||||
Bundle-RequiredExecutionEnvironment: J2SE-1.5
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2007 Institute for Software, HSR Hochschule fuer Technik
|
||||
* 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
|
||||
|
|
|
@ -26,6 +26,7 @@ import org.eclipse.cdt.core.dom.ast.IASTPreprocessorFunctionStyleMacroDefinition
|
|||
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroExpansion;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorObjectStyleMacroDefinition;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorUndefStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
|
||||
|
@ -295,7 +296,7 @@ public class DOMLocationMacroTests extends AST2BaseTest {
|
|||
assertEquals( firstReferences.length, 2 );
|
||||
assertEquals( firstReferences[0].getPropertyInParent(), IASTPreprocessorMacroExpansion.EXPANSION_NAME );
|
||||
assertEquals( firstReferences[0].getParent().getParent(), tu );
|
||||
assertEquals( firstReferences[1].getPropertyInParent(), IASTPreprocessorUndefStatement.MACRO_NAME );
|
||||
assertEquals( firstReferences[1].getPropertyInParent(), IASTPreprocessorStatement.MACRO_NAME );
|
||||
assertTrue( firstReferences[1].getParent() instanceof IASTPreprocessorUndefStatement );
|
||||
assertEquals( firstDeclarations.length, 1 );
|
||||
assertSame( ABC1.getName(), firstDeclarations[0] );
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2007 Institute for Software, HSR Hochschule fuer Technik
|
||||
* 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
|
||||
|
|
|
@ -0,0 +1,116 @@
|
|||
/*******************************************************************************
|
||||
* 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.core.parser.tests.rewrite;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
import java.util.Vector;
|
||||
|
||||
import org.eclipse.cdt.core.tests.BaseTestFramework;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.runtime.ILogListener;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
import org.eclipse.jface.text.TextSelection;
|
||||
|
||||
/**
|
||||
* @author Guido Zgraggen IFS
|
||||
*
|
||||
*/
|
||||
public abstract class RewriteBaseTest extends BaseTestFramework implements ILogListener{
|
||||
protected static final NullProgressMonitor NULL_PROGRESS_MONITOR = new NullProgressMonitor();
|
||||
|
||||
protected TreeMap<String, TestSourceFile> fileMap = new TreeMap<String, TestSourceFile>();
|
||||
protected String fileWithSelection;
|
||||
protected TextSelection selection;
|
||||
|
||||
protected RewriteBaseTest(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
public RewriteBaseTest(String name, Vector<TestSourceFile> files) {
|
||||
super(name);
|
||||
for (TestSourceFile file : files) {
|
||||
fileMap.put(file.getName(), file);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected abstract void runTest() throws Throwable;
|
||||
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
for (TestSourceFile testFile : fileMap.values()) {
|
||||
if(testFile.getSource().length() > 0) {
|
||||
importFile(testFile.getName(), testFile.getSource());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void assertEquals(TestSourceFile file, IFile file2) throws Exception {
|
||||
StringBuffer code = getCodeFromIFile(file2);
|
||||
assertEquals(file.getExpectedSource(), TestHelper.unifyNewLines(code.toString()));
|
||||
}
|
||||
|
||||
protected void compareFiles(Map<String,TestSourceFile> testResourceFiles) throws Exception {
|
||||
for (String fileName : testResourceFiles.keySet()) {
|
||||
TestSourceFile file = testResourceFiles.get(fileName);
|
||||
IFile iFile = project.getFile(new Path(fileName));
|
||||
StringBuffer code = getCodeFromIFile(iFile);
|
||||
assertEquals(TestHelper.unifyNewLines(file.getExpectedSource()), TestHelper.unifyNewLines(code.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
protected StringBuffer getCodeFromIFile(IFile file) throws Exception {
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(file.getContents()));
|
||||
StringBuffer code = new StringBuffer();
|
||||
String line;
|
||||
while((line = br.readLine()) != null) {
|
||||
code.append(line);
|
||||
code.append('\n');
|
||||
}
|
||||
br.close();
|
||||
return code;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
System.gc();
|
||||
fileManager.closeAllFiles();
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
public void logging(IStatus status, String plugin) {
|
||||
Throwable ex = status.getException();
|
||||
StringBuffer stackTrace = new StringBuffer();
|
||||
if(ex != null) {
|
||||
stackTrace.append('\n');
|
||||
for(StackTraceElement ste : ex.getStackTrace()) {
|
||||
stackTrace.append(ste.toString());
|
||||
}
|
||||
}
|
||||
fail("Log-Message: " + status.getMessage() + stackTrace.toString()); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
public void setFileWithSelection(String fileWithSelection) {
|
||||
this.fileWithSelection = fileWithSelection;
|
||||
}
|
||||
|
||||
public void setSelection(TextSelection selection) {
|
||||
this.selection = selection;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,215 @@
|
|||
/*******************************************************************************
|
||||
* 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.core.parser.tests.rewrite;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.Vector;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
import org.eclipse.cdt.core.testplugin.CTestPlugin;
|
||||
import org.eclipse.core.runtime.FileLocator;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
import org.eclipse.jface.text.TextSelection;
|
||||
import org.osgi.framework.Bundle;
|
||||
|
||||
/**
|
||||
* @author Emanuel Graf
|
||||
*
|
||||
*/
|
||||
public class RewriteTester extends TestSuite{
|
||||
|
||||
enum MatcherState{skip, inTest, inSource, inExpectedResult}
|
||||
|
||||
private static final String classRegexp = "//#(.*)\\s*(\\w*)*$"; //$NON-NLS-1$
|
||||
private static final String testRegexp = "//!(.*)\\s*(\\w*)*$"; //$NON-NLS-1$
|
||||
private static final String fileRegexp = "//@(.*)\\s*(\\w*)*$"; //$NON-NLS-1$
|
||||
private static final String resultRegexp = "//=.*$"; //$NON-NLS-1$
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
private static ArrayList<RewriteBaseTest> createTests(BufferedReader inputReader) throws Exception {
|
||||
|
||||
String line;
|
||||
Vector<TestSourceFile> files = new Vector<TestSourceFile>();
|
||||
TestSourceFile actFile = null;
|
||||
MatcherState matcherState = MatcherState.skip;
|
||||
ArrayList<RewriteBaseTest> testCases = new ArrayList<RewriteBaseTest>();
|
||||
String testName = null;
|
||||
String className = null;
|
||||
boolean bevorFirstTest = true;
|
||||
|
||||
while ((line = inputReader.readLine()) != null){
|
||||
|
||||
if(lineMatchesBeginOfTest(line)) {
|
||||
if(!bevorFirstTest) {
|
||||
RewriteBaseTest test = createTestClass(className, testName, files);
|
||||
testCases.add(test);
|
||||
files = new Vector<TestSourceFile>();
|
||||
className = null;
|
||||
testName = null;
|
||||
}
|
||||
matcherState = MatcherState.inTest;
|
||||
testName = getNameOfTest(line);
|
||||
bevorFirstTest = false;
|
||||
continue;
|
||||
} else if (lineMatchesBeginOfResult(line)) {
|
||||
matcherState = MatcherState.inExpectedResult;
|
||||
continue;
|
||||
}else if (lineMatchesFileName(line)) {
|
||||
matcherState = MatcherState.inSource;
|
||||
actFile = new TestSourceFile(getFileName(line));
|
||||
files.add(actFile);
|
||||
continue;
|
||||
}else if(lineMatchesClassName(line)) {
|
||||
className = getNameOfClass(line);
|
||||
continue;
|
||||
}
|
||||
|
||||
switch(matcherState) {
|
||||
case inSource:
|
||||
if(actFile != null) {
|
||||
actFile.addLineToSource(line);
|
||||
}
|
||||
break;
|
||||
case inExpectedResult:
|
||||
if(actFile != null) {
|
||||
actFile.addLineToExpectedSource(line);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
RewriteBaseTest test = createTestClass(className, testName, files);
|
||||
testCases.add(test);
|
||||
return testCases;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private static RewriteBaseTest createTestClass(String className, String testName, Vector<TestSourceFile> files) throws Exception {
|
||||
|
||||
|
||||
try {
|
||||
Class<?> refClass = Class.forName(className);
|
||||
Class<?> paratypes[] = new Class[2];
|
||||
paratypes[0] = testName.getClass();
|
||||
paratypes[1] = files.getClass();
|
||||
Constructor<?> ct = refClass.getConstructor(paratypes);
|
||||
Object arglist[] = new Object[2];
|
||||
arglist[0] = testName;
|
||||
arglist[1] = files;
|
||||
RewriteBaseTest test = (RewriteBaseTest) ct.newInstance(arglist);
|
||||
for (TestSourceFile file : files) {
|
||||
TextSelection sel = file.getSelection();
|
||||
if(sel != null) {
|
||||
test.setFileWithSelection(file.getName());
|
||||
test.setSelection(sel);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return test;
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new Exception("Unknown TestClass. Make sure the test's sourcefile specifies a valid test class.");
|
||||
} catch (SecurityException e) {
|
||||
throw new Exception("Security Exception during Test creation", e);
|
||||
} catch (NoSuchMethodException e) {
|
||||
throw new Exception("Test class does not provied required constructor.");
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new Exception("IllegalArgumentException during Test creation", e);
|
||||
} catch (InstantiationException e) {
|
||||
throw new Exception("InstantiationException during Test creation", e);
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new Exception("IllegalAccessException during Test creation", e);
|
||||
} catch (InvocationTargetException e) {
|
||||
throw new Exception("InvocationTargetException during Test creation", e);
|
||||
}
|
||||
}
|
||||
|
||||
private static String getFileName(String line) {
|
||||
Matcher matcherBeginOfTest = createMatcherFromString(fileRegexp, line);
|
||||
if(matcherBeginOfTest.find())
|
||||
return matcherBeginOfTest.group(1);
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
private static String getNameOfClass(String line) {
|
||||
Matcher matcherBeginOfTest = createMatcherFromString(classRegexp, line);
|
||||
if(matcherBeginOfTest.find())
|
||||
return matcherBeginOfTest.group(1);
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
private static boolean lineMatchesBeginOfTest(String line) {
|
||||
return createMatcherFromString(testRegexp, line).find();
|
||||
}
|
||||
|
||||
private static boolean lineMatchesClassName(String line) {
|
||||
return createMatcherFromString(classRegexp, line).find();
|
||||
}
|
||||
|
||||
private static boolean lineMatchesFileName(String line) {
|
||||
return createMatcherFromString(fileRegexp, line).find();
|
||||
}
|
||||
|
||||
protected static Matcher createMatcherFromString(String pattern, String line) {
|
||||
return Pattern.compile(pattern).matcher(line);
|
||||
}
|
||||
|
||||
private static String getNameOfTest(String line) {
|
||||
Matcher matcherBeginOfTest = createMatcherFromString(testRegexp, line);
|
||||
if(matcherBeginOfTest.find())
|
||||
return matcherBeginOfTest.group(1);
|
||||
else
|
||||
return "Not Named";
|
||||
}
|
||||
|
||||
private static boolean lineMatchesBeginOfResult(String line) {
|
||||
return createMatcherFromString(resultRegexp, line).find();
|
||||
}
|
||||
|
||||
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();
|
||||
suite.addTest(subject);
|
||||
}
|
||||
return suite;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
/*******************************************************************************
|
||||
* 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.core.parser.tests.rewrite;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
import org.eclipse.cdt.core.parser.tests.rewrite.astwriter.AstWriterTestSuite;
|
||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTestSuite;
|
||||
import org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTestSuite;
|
||||
|
||||
public class RewriteTests extends TestSuite {
|
||||
|
||||
public static Test suite() throws Exception {
|
||||
TestSuite suite = new TestSuite(RewriteTests.class.getName());
|
||||
suite.addTest(AstWriterTestSuite.suite());
|
||||
suite.addTest(CommentHandlingTestSuite.suite());
|
||||
suite.addTest(ChangeGeneratorTestSuite.suite());
|
||||
return suite;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
/*******************************************************************************
|
||||
* 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.core.parser.tests.rewrite;
|
||||
|
||||
public class TestHelper {
|
||||
|
||||
public static String unifyNewLines(String code) {
|
||||
String replacement = System.getProperty("line.separator"); //$NON-NLS-1$
|
||||
return code.replaceAll("(\n)|(\r\n)", replacement); //$NON-NLS-1$
|
||||
}
|
||||
}
|
|
@ -0,0 +1,88 @@
|
|||
/*******************************************************************************
|
||||
* 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.core.parser.tests.rewrite;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.eclipse.jface.text.TextSelection;
|
||||
|
||||
/**
|
||||
* @author Emanuel Graf
|
||||
*
|
||||
*/
|
||||
public class TestSourceFile {
|
||||
|
||||
private static final String REPLACEMENT = ""; //$NON-NLS-1$
|
||||
private String name;
|
||||
private StringBuffer source = new StringBuffer();
|
||||
private StringBuffer expectedSource = new StringBuffer();
|
||||
private String separator = System.getProperty("line.separator"); //$NON-NLS-1$
|
||||
private int selectionStart = -1;
|
||||
private int selectionEnd = -1;
|
||||
|
||||
protected static final String selectionStartRegex = "//\\$"; //$NON-NLS-1$
|
||||
protected static final String selectionEndRegex = "\\$//"; //$NON-NLS-1$
|
||||
protected static final String selectionStartLineRegex = "(.*)(" + selectionStartRegex + ")(.*)"; //$NON-NLS-1$ //$NON-NLS-2$
|
||||
protected static final String selectionEndLineRegex = "(.*)("+ selectionEndRegex + ")(.*)"; //$NON-NLS-1$ //$NON-NLS-2$
|
||||
|
||||
public TestSourceFile(String name) {
|
||||
super();
|
||||
this.name = name;
|
||||
}
|
||||
public String getExpectedSource() {
|
||||
String exp = expectedSource.toString();
|
||||
if(exp.length() == 0) {
|
||||
return getSource();
|
||||
}else {
|
||||
return exp;
|
||||
}
|
||||
}
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public String getSource() {
|
||||
return source.toString();
|
||||
}
|
||||
|
||||
public void addLineToSource(String code) {
|
||||
Matcher start = createMatcherFromString(selectionStartLineRegex, code);
|
||||
if(start.matches()) {
|
||||
selectionStart = start.start(2) + source.length();
|
||||
code = code.replaceAll(selectionStartRegex, REPLACEMENT);
|
||||
}
|
||||
Matcher end = createMatcherFromString(selectionEndLineRegex, code);
|
||||
if(end.matches()) {
|
||||
selectionEnd = end.start(2) + source.length();
|
||||
code = code.replaceAll(selectionEndRegex, REPLACEMENT);
|
||||
}
|
||||
source.append(code);
|
||||
source.append(separator);
|
||||
}
|
||||
|
||||
public void addLineToExpectedSource(String code) {
|
||||
expectedSource.append(code);
|
||||
expectedSource.append(separator);
|
||||
}
|
||||
|
||||
public TextSelection getSelection() {
|
||||
if(selectionStart < 0 || selectionEnd <0 ) {
|
||||
return null;
|
||||
}else {
|
||||
return new TextSelection(selectionStart, selectionEnd -selectionStart);
|
||||
}
|
||||
}
|
||||
|
||||
protected static Matcher createMatcherFromString(String pattern, String line) {
|
||||
return Pattern.compile(pattern).matcher(line);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,140 @@
|
|||
/*******************************************************************************
|
||||
* 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.core.parser.tests.rewrite.astwriter;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.dom.parser.ISourceCodeParser;
|
||||
import org.eclipse.cdt.core.dom.parser.c.ANSICParserExtensionConfiguration;
|
||||
import org.eclipse.cdt.core.dom.parser.c.GCCParserExtensionConfiguration;
|
||||
import org.eclipse.cdt.core.dom.parser.c.ICParserExtensionConfiguration;
|
||||
import org.eclipse.cdt.core.dom.parser.cpp.ANSICPPParserExtensionConfiguration;
|
||||
import org.eclipse.cdt.core.dom.parser.cpp.GPPParserExtensionConfiguration;
|
||||
import org.eclipse.cdt.core.dom.parser.cpp.ICPPParserExtensionConfiguration;
|
||||
import org.eclipse.cdt.core.parser.CodeReader;
|
||||
import org.eclipse.cdt.core.parser.IParserLogService;
|
||||
import org.eclipse.cdt.core.parser.IScanner;
|
||||
import org.eclipse.cdt.core.parser.NullLogService;
|
||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||
import org.eclipse.cdt.core.parser.ParserMode;
|
||||
import org.eclipse.cdt.core.parser.ScannerInfo;
|
||||
import org.eclipse.cdt.core.parser.tests.ast2.AST2BaseTest;
|
||||
import org.eclipse.cdt.core.parser.tests.rewrite.RewriteBaseTest;
|
||||
import org.eclipse.cdt.core.parser.tests.rewrite.TestHelper;
|
||||
import org.eclipse.cdt.core.parser.tests.rewrite.TestSourceFile;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.c.GNUCSourceParser;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.GNUCPPSourceParser;
|
||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationMap;
|
||||
import org.eclipse.cdt.internal.core.dom.rewrite.astwriter.ASTWriter;
|
||||
import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.ASTCommenter;
|
||||
import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
|
||||
/**
|
||||
* @author Guido Zgraggen
|
||||
*/
|
||||
public class ASTWriterTest extends RewriteBaseTest {
|
||||
private static final IParserLogService NULL_LOG = new NullLogService();
|
||||
|
||||
private IFile file;
|
||||
|
||||
public ASTWriterTest(String name, ASTWriterTestSourceFile file) {
|
||||
super(name);
|
||||
fileMap.put(file.getName(), file);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
for (TestSourceFile testFile : fileMap.values()) {
|
||||
if(testFile.getSource().length() > 0) {
|
||||
file = importFile(testFile.getName(), testFile.getSource());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void runTest() throws Throwable {
|
||||
file = project.getFile("ASTWritterTest.h"); //$NON-NLS-1$
|
||||
compareFiles(fileMap);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void compareFiles(Map<String,TestSourceFile> testResourceFiles) throws Exception {
|
||||
for (String fileName : testResourceFiles.keySet()) {
|
||||
TestSourceFile testFile = testResourceFiles.get(fileName);
|
||||
String code = generateSource(testFile);
|
||||
assertEquals(TestHelper.unifyNewLines(testFile.getExpectedSource()), TestHelper.unifyNewLines(code + System.getProperty("line.separator"))); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
|
||||
public String generateSource(TestSourceFile testFile) throws Exception {
|
||||
IASTTranslationUnit unit = getParser(testFile).parse();
|
||||
NodeCommentMap commentMap = ASTCommenter.getCommentedNodeMap(unit);
|
||||
ASTModificationMap map = new ASTModificationMap();
|
||||
map.getModificationsForNode(unit.getDeclarations()[0]);
|
||||
ASTWriter writer = new ASTWriter();
|
||||
return writer.write(unit, null, commentMap);
|
||||
}
|
||||
|
||||
protected ISourceCodeParser getParser(TestSourceFile testFile) throws Exception {
|
||||
CodeReader codeReader = new CodeReader(file.getLocation().toOSString(), file.getContents());
|
||||
|
||||
ScannerInfo scannerInfo = new ScannerInfo();
|
||||
ParserLanguage language = getLanguage(testFile);
|
||||
boolean useGNUExtensions = getGNUExtension(testFile);
|
||||
|
||||
IScanner scanner = AST2BaseTest.createScanner(codeReader, language, ParserMode.COMPLETE_PARSE, scannerInfo, true);
|
||||
|
||||
ISourceCodeParser parser2 = null;
|
||||
if( language == ParserLanguage.CPP ) {
|
||||
ICPPParserExtensionConfiguration config = null;
|
||||
if (useGNUExtensions){
|
||||
config = new GPPParserExtensionConfiguration();
|
||||
} else{
|
||||
config = new ANSICPPParserExtensionConfiguration();
|
||||
}
|
||||
parser2 = new GNUCPPSourceParser(scanner, ParserMode.COMPLETE_PARSE, NULL_LOG, config );
|
||||
} else {
|
||||
ICParserExtensionConfiguration config = null;
|
||||
|
||||
if (useGNUExtensions){
|
||||
config = new GCCParserExtensionConfiguration();
|
||||
} else{
|
||||
config = new ANSICParserExtensionConfiguration();
|
||||
}
|
||||
|
||||
parser2 = new GNUCSourceParser(scanner, ParserMode.COMPLETE_PARSE, NULL_LOG, config );
|
||||
}
|
||||
return parser2;
|
||||
}
|
||||
|
||||
private boolean getGNUExtension(TestSourceFile file) {
|
||||
if(file instanceof ASTWriterTestSourceFile) {
|
||||
return ((ASTWriterTestSourceFile)file).isUseGNUExtensions();
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private ParserLanguage getLanguage(TestSourceFile file) {
|
||||
if(file instanceof ASTWriterTestSourceFile) {
|
||||
return ((ASTWriterTestSourceFile)file).getParserLanguage();
|
||||
}
|
||||
else {
|
||||
return ParserLanguage.CPP;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
/*******************************************************************************
|
||||
* 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.core.parser.tests.rewrite.astwriter;
|
||||
|
||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||
import org.eclipse.cdt.core.parser.tests.rewrite.TestSourceFile;
|
||||
|
||||
/**
|
||||
* @author Guido Zgraggen IFS
|
||||
*
|
||||
*/
|
||||
public class ASTWriterTestSourceFile extends TestSourceFile {
|
||||
private ParserLanguage parserLanguage = ParserLanguage.CPP;
|
||||
private boolean useGNUExtensions = false;
|
||||
|
||||
public ASTWriterTestSourceFile(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
public void setParserLanguage(ParserLanguage lang) {
|
||||
this.parserLanguage = lang;
|
||||
}
|
||||
|
||||
public ParserLanguage getParserLanguage() {
|
||||
return parserLanguage;
|
||||
}
|
||||
|
||||
public boolean isUseGNUExtensions() {
|
||||
return useGNUExtensions;
|
||||
}
|
||||
|
||||
public void setUseGNUExtensions(boolean useGNUExtensions) {
|
||||
this.useGNUExtensions = useGNUExtensions;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2006, 2007 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.core.parser.tests.rewrite.astwriter;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
/**
|
||||
* @author Emanuel Graf
|
||||
*
|
||||
*/
|
||||
public class AstWriterTestSuite{
|
||||
|
||||
@SuppressWarnings("nls")
|
||||
public static Test suite() throws Exception {
|
||||
TestSuite suite = new TestSuite("AstWriterTests");
|
||||
suite.addTest(SourceRewriteTester.suite("ExpressionTests", "resources/rewrite/ASTWriterExpressionTestSource.awts"));
|
||||
|
||||
suite.addTest(SourceRewriteTester.suite("DelcSpecifierTests", "resources/rewrite/ASTWriterDeclSpecTestSource.awts"));
|
||||
suite.addTest(SourceRewriteTester.suite("Commented DelcSpecifierTests",
|
||||
"resources/rewrite/ASTWriterCommentedDeclSpecTestSource.awts"));
|
||||
|
||||
suite.addTest(SourceRewriteTester.suite("DeclaratorTests", "resources/rewrite/ASTWriterDeclaratorTestSource.awts"));
|
||||
suite.addTest(SourceRewriteTester.suite("Commented DeclaratorTests",
|
||||
"resources/rewrite/ASTWriterCommentedDeclaratorTestSource.awts"));
|
||||
|
||||
suite.addTest(SourceRewriteTester.suite("StatementsTests", "resources/rewrite/ASTWriterStatementTestSource.awts"));
|
||||
suite.addTest(SourceRewriteTester
|
||||
.suite("Commented StatementsTests", "resources/rewrite/ASTWriterCommentedStatementTestSource.awts"));
|
||||
|
||||
suite.addTest(SourceRewriteTester.suite("NameTests", "resources/rewrite/ASTWriterNameTestSource.awts"));
|
||||
suite.addTest(SourceRewriteTester.suite("Commented NameTests", "resources/rewrite/ASTWriterCommentedNameTestSource.awts"));
|
||||
|
||||
suite.addTest(SourceRewriteTester.suite("InitializerTests", "resources/rewrite/ASTWriterInitializerTestSource.awts"));
|
||||
|
||||
suite.addTest(SourceRewriteTester.suite("DeclarationTests", "resources/rewrite/ASTWriterDeclarationTestSource.awts"));
|
||||
suite.addTest(SourceRewriteTester.suite("Commented DeclarationTests",
|
||||
"resources/rewrite/ASTWriterCommentedDeclarationTestSource.awts"));
|
||||
|
||||
suite.addTest(SourceRewriteTester.suite("TemplatesTests", "resources/rewrite/ASTWriterTemplateTestSource.awts"));
|
||||
|
||||
suite.addTest(SourceRewriteTester.suite("CommentTests", "resources/rewrite/ASTWriterCommentedTestSource.awts"));
|
||||
suite.addTest(SourceRewriteTester.suite("NewCommentTests", "resources/rewrite/ASTWriterCommentedTestSource2.awts"));
|
||||
return suite;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,167 @@
|
|||
/*******************************************************************************
|
||||
* 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.core.parser.tests.rewrite.astwriter;
|
||||
|
||||
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;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||
import org.eclipse.cdt.core.parser.tests.rewrite.RewriteBaseTest;
|
||||
import org.eclipse.cdt.core.testplugin.CTestPlugin;
|
||||
import org.eclipse.core.runtime.FileLocator;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
import org.eclipse.jface.text.TextSelection;
|
||||
import org.osgi.framework.Bundle;
|
||||
|
||||
public class SourceRewriteTester extends TestSuite {
|
||||
|
||||
private static final String testRegexp = "//!(.*)\\s*(\\w*)*$"; //$NON-NLS-1$
|
||||
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}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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();
|
||||
suite.addTest(subject);
|
||||
}
|
||||
return suite;
|
||||
}
|
||||
|
||||
protected static boolean lineMatchesBeginOfTest(String line) {
|
||||
return createMatcherFromString(testRegexp, line).find();
|
||||
}
|
||||
|
||||
protected static boolean lineMatchesCodeType(String line) {
|
||||
return createMatcherFromString(codeTypeRegexp, line).find();
|
||||
}
|
||||
|
||||
protected static Matcher createMatcherFromString(String pattern, String line) {
|
||||
return Pattern.compile(pattern).matcher(line);
|
||||
}
|
||||
|
||||
protected static String getNameOfTest(String line) {
|
||||
Matcher matcherBeginOfTest = createMatcherFromString(testRegexp, line);
|
||||
if(matcherBeginOfTest.find())
|
||||
return matcherBeginOfTest.group(1);
|
||||
else
|
||||
return "Not Named";
|
||||
}
|
||||
|
||||
protected static boolean lineMatchesBeginOfResult(String line) {
|
||||
return createMatcherFromString(resultRegexp, line).find();
|
||||
}
|
||||
|
||||
private static ArrayList<RewriteBaseTest> createTests(BufferedReader inputReader) throws Exception {
|
||||
String line;
|
||||
ASTWriterTestSourceFile file = null;
|
||||
MatcherState matcherState = MatcherState.skip;
|
||||
ArrayList<RewriteBaseTest> testCases = new ArrayList<RewriteBaseTest>();
|
||||
|
||||
while ((line = inputReader.readLine()) != null){
|
||||
if(lineMatchesBeginOfTest(line)) {
|
||||
matcherState = MatcherState.inTest;
|
||||
file = new ASTWriterTestSourceFile("ASTWritterTest.h"); //$NON-NLS-1$
|
||||
testCases.add(createTestClass(getNameOfTest(line), file));
|
||||
continue;
|
||||
} else if (lineMatchesBeginOfResult(line)) {
|
||||
matcherState = MatcherState.inExpectedResult;
|
||||
continue;
|
||||
}else if (lineMatchesCodeType(line)) {
|
||||
matcherState = MatcherState.inSource;
|
||||
if(file != null) {
|
||||
file.setParserLanguage(getParserLanguage(line));
|
||||
file.setUseGNUExtensions(useGNUExtensions(line));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
switch(matcherState) {
|
||||
case inSource:
|
||||
if(file != null) {
|
||||
file.addLineToSource(line);
|
||||
}
|
||||
break;
|
||||
case inExpectedResult:
|
||||
if(file != null) {
|
||||
file.addLineToExpectedSource(line);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
return testCases;
|
||||
}
|
||||
|
||||
protected static boolean useGNUExtensions(String line) {
|
||||
Matcher matcherBeginOfTest = createMatcherFromString(codeTypeRegexp, line);
|
||||
if(matcherBeginOfTest.find()) {
|
||||
String codeType = matcherBeginOfTest.group(2);
|
||||
if(codeType == null) {
|
||||
return false;
|
||||
}else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected static ParserLanguage getParserLanguage(String line) {
|
||||
Matcher matcherBeginOfTest = createMatcherFromString(codeTypeRegexp, line);
|
||||
if(matcherBeginOfTest.find()) {
|
||||
String codeType = matcherBeginOfTest.group(1);
|
||||
if(codeType.equalsIgnoreCase("CPP")) { //$NON-NLS-1$
|
||||
return ParserLanguage.CPP;
|
||||
}else {
|
||||
return ParserLanguage.C;
|
||||
}
|
||||
}
|
||||
return ParserLanguage.C;
|
||||
}
|
||||
|
||||
private static RewriteBaseTest createTestClass(String testName, ASTWriterTestSourceFile file) throws Exception {
|
||||
ASTWriterTest test = new ASTWriterTest(testName,file);
|
||||
TextSelection sel = file.getSelection();
|
||||
if(sel != null) {
|
||||
test.setFileWithSelection(file.getName());
|
||||
test.setSelection(sel);
|
||||
}
|
||||
return test;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,91 @@
|
|||
/*******************************************************************************
|
||||
* 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.core.parser.tests.rewrite.changegenerator;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.dom.CDOM;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
|
||||
import org.eclipse.cdt.core.index.IIndexManager;
|
||||
import org.eclipse.cdt.core.parser.tests.rewrite.TestHelper;
|
||||
import org.eclipse.cdt.core.tests.BaseTestFramework;
|
||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
|
||||
import org.eclipse.cdt.internal.core.dom.rewrite.changegenerator.CTextFileChange;
|
||||
import org.eclipse.cdt.internal.core.dom.rewrite.changegenerator.ChangeGenerator;
|
||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
import org.eclipse.jface.text.Document;
|
||||
import org.eclipse.ltk.core.refactoring.Change;
|
||||
import org.eclipse.ltk.core.refactoring.CompositeChange;
|
||||
|
||||
public abstract class ChangeGeneratorTest extends BaseTestFramework {
|
||||
|
||||
protected String source;
|
||||
protected String expectedSource;
|
||||
|
||||
public ChangeGeneratorTest() {
|
||||
super();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
CCorePlugin.getIndexManager().joinIndexer(IIndexManager.FOREVER, new NullProgressMonitor());
|
||||
super.setUp();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runTest() {
|
||||
final ASTModificationStore modStore = new ASTModificationStore();
|
||||
final ChangeGenerator changegenartor = new ChangeGenerator(modStore);
|
||||
try {
|
||||
importFile("source.h", source); //$NON-NLS-1$
|
||||
|
||||
IASTTranslationUnit unit = CDOM.getInstance().getTranslationUnit(
|
||||
project.getFile(new Path("source.h")), //$NON-NLS-1$
|
||||
CDOM.getInstance().getCodeReaderFactory(
|
||||
CDOM.PARSE_SAVED_RESOURCES),
|
||||
true);
|
||||
CPPASTVisitor visitor = createModificator(modStore);
|
||||
|
||||
unit.accept(visitor);
|
||||
|
||||
|
||||
// assertEquals(expectedSource, changegenartor.write(unit));
|
||||
changegenartor.generateChange(unit);
|
||||
Document doc = new Document(source);
|
||||
for(Change curChange : ((CompositeChange)changegenartor.getChange()).getChildren()){
|
||||
if (curChange instanceof CTextFileChange) {
|
||||
CTextFileChange textChange = (CTextFileChange) curChange;
|
||||
textChange.getEdit().apply(doc);
|
||||
}
|
||||
}
|
||||
assertEquals(TestHelper.unifyNewLines(expectedSource), TestHelper.unifyNewLines(doc.get()));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
assertTrue(false);
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract CPPASTVisitor createModificator(ASTModificationStore modStore);
|
||||
|
||||
public ChangeGeneratorTest(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
System.gc();
|
||||
fileManager.closeAllFiles();
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
/*******************************************************************************
|
||||
* 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.core.parser.tests.rewrite.changegenerator;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.append.AppendTestSuite;
|
||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.insertbefore.InsertBeforeTestSuite;
|
||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.remove.RemoveTestSuite;
|
||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.replace.ReplaceTestSuite;
|
||||
|
||||
/**
|
||||
* @author Thomas Corbat
|
||||
*
|
||||
*/
|
||||
public class ChangeGeneratorTestSuite{
|
||||
|
||||
@SuppressWarnings("nls")
|
||||
public static Test suite() throws Exception {
|
||||
TestSuite suite = new TestSuite("ChangeGeneratorTests");
|
||||
|
||||
suite.addTest(ReplaceTestSuite.suite());
|
||||
suite.addTest(RemoveTestSuite.suite());
|
||||
suite.addTest(InsertBeforeTestSuite.suite());
|
||||
suite.addTest(AppendTestSuite.suite());
|
||||
|
||||
return suite;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
/*******************************************************************************
|
||||
* 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.core.parser.tests.rewrite.changegenerator.append;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
/**
|
||||
* @author Thomas Corbat
|
||||
*
|
||||
*/
|
||||
public class AppendTestSuite{
|
||||
|
||||
@SuppressWarnings("nls")
|
||||
public static Test suite() throws Exception {
|
||||
TestSuite suite = new TestSuite("Changegenerator Append Child Tests");
|
||||
|
||||
suite.addTest(ParameterTest.suite());
|
||||
suite.addTest(ParameterToListTest.suite());
|
||||
suite.addTest(PointerToParameterTest.suite());
|
||||
suite.addTest(PointerToPointerParameterTest.suite());
|
||||
suite.addTest(ExceptionTest.suite());
|
||||
suite.addTest(CtorChainInitializerTest.suite());
|
||||
suite.addTest(ArrayModifierTest.suite());
|
||||
suite.addTest(ExpressionTest.suite());
|
||||
suite.addTest(ArraySizeExpressionTest.suite());
|
||||
|
||||
return suite;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
/*******************************************************************************
|
||||
* 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.core.parser.tests.rewrite.changegenerator.append;
|
||||
|
||||
import junit.framework.Test;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTArrayModifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
|
||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTArrayModifier;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTLiteralExpression;
|
||||
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 ArrayModifierTest extends ChangeGeneratorTest {
|
||||
|
||||
public ArrayModifierTest(){
|
||||
super("Replace Array Modifier"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
|
||||
|
||||
source = "int *pi[5];"; //$NON-NLS-1$
|
||||
expectedSource = "int *pi[5][3];"; //$NON-NLS-1$
|
||||
super.setUp();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CPPASTVisitor createModificator(
|
||||
final ASTModificationStore modStore) {
|
||||
return new CPPASTVisitor() {
|
||||
{
|
||||
shouldVisitDeclarators = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTDeclarator declarator) {
|
||||
if (declarator instanceof IASTArrayDeclarator) {
|
||||
IASTArrayDeclarator arrayDeclarator = (IASTArrayDeclarator)declarator;
|
||||
arrayDeclarator.getArrayModifiers();
|
||||
IASTArrayModifier newModifier = new CPPASTArrayModifier();
|
||||
IASTExpression expr = new CPPASTLiteralExpression(0, "3"); //$NON-NLS-1$
|
||||
newModifier.setConstantExpression(expr);
|
||||
ASTModification modification = new ASTModification(ModificationKind.APPEND_CHILD, declarator, newModifier, null);
|
||||
modStore.storeModification(null, modification);
|
||||
}
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
return new ArrayModifierTest();
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,64 @@
|
|||
/*******************************************************************************
|
||||
* 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.core.parser.tests.rewrite.changegenerator.append;
|
||||
|
||||
import junit.framework.Test;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNewExpression;
|
||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTLiteralExpression;
|
||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
|
||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
|
||||
|
||||
public class ArraySizeExpressionTest extends ChangeGeneratorTest {
|
||||
|
||||
public ArraySizeExpressionTest(){
|
||||
super("Append Array Size Expression"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
source = "int *values = new int[6];"; //$NON-NLS-1$
|
||||
expectedSource = "int *values = new int[6][5];"; //$NON-NLS-1$
|
||||
super.setUp();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected CPPASTVisitor createModificator(
|
||||
final ASTModificationStore modStore) {
|
||||
return new CPPASTVisitor() {
|
||||
{
|
||||
shouldVisitExpressions = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTExpression expression) {
|
||||
if (expression instanceof ICPPASTNewExpression) {
|
||||
ICPPASTNewExpression newExpression = (ICPPASTNewExpression) expression;
|
||||
newExpression.getNewTypeIdArrayExpressions();
|
||||
ASTModification modification = new ASTModification(ASTModification.ModificationKind.APPEND_CHILD, newExpression, new CPPASTLiteralExpression(0, "5"), null); //$NON-NLS-1$
|
||||
modStore.storeModification(null, modification);
|
||||
}
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
return new ArraySizeExpressionTest();
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,72 @@
|
|||
/*******************************************************************************
|
||||
* 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.core.parser.tests.rewrite.changegenerator.append;
|
||||
|
||||
import junit.framework.Test;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer;
|
||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTConstructorChainInitializer;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDeclarator;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTIdExpression;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName;
|
||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
|
||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
|
||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind;
|
||||
|
||||
public class CtorChainInitializerTest extends ChangeGeneratorTest {
|
||||
|
||||
|
||||
public CtorChainInitializerTest(){
|
||||
super("Append Ctor Initializer"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
@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$
|
||||
super.setUp();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CPPASTVisitor createModificator(
|
||||
final ASTModificationStore modStore) {
|
||||
return new CPPASTVisitor() {
|
||||
{
|
||||
shouldVisitDeclarators = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTDeclarator declarator) {
|
||||
if (declarator instanceof CPPASTFunctionDeclarator) {
|
||||
CPPASTFunctionDeclarator functionDeclarator = (CPPASTFunctionDeclarator)declarator;
|
||||
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, initExpr);
|
||||
ASTModification modification = new ASTModification(ModificationKind.APPEND_CHILD, functionDeclarator, newInitializer, null);
|
||||
modStore.storeModification(null, modification);
|
||||
|
||||
}
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
return new CtorChainInitializerTest();
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,74 @@
|
|||
/*******************************************************************************
|
||||
* 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.core.parser.tests.rewrite.changegenerator.append;
|
||||
|
||||
import junit.framework.Test;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTypeId;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
|
||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTDeclarator;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDeclarator;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTSimpleDeclSpecifier;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTTypeId;
|
||||
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 ExceptionTest extends ChangeGeneratorTest {
|
||||
|
||||
public ExceptionTest(){
|
||||
super("Append Exception Declaration"); //$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) throw (int){\n}\n\n"; //$NON-NLS-1$
|
||||
super.setUp();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CPPASTVisitor createModificator(
|
||||
final ASTModificationStore modStore) {
|
||||
return new CPPASTVisitor() {
|
||||
{
|
||||
shouldVisitDeclarators = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTDeclarator declarator) {
|
||||
if (declarator instanceof CPPASTFunctionDeclarator) {
|
||||
IASTTypeId exception = new CPPASTTypeId();
|
||||
CPPASTDeclarator exceptionDeclarator = new CPPASTDeclarator();
|
||||
exceptionDeclarator.setName(new CPPASTName());
|
||||
CPPASTSimpleDeclSpecifier exDeclSpec = new CPPASTSimpleDeclSpecifier();
|
||||
exDeclSpec.setType(IASTSimpleDeclSpecifier.t_int);
|
||||
exception.setDeclSpecifier(exDeclSpec);
|
||||
exception.setAbstractDeclarator(exceptionDeclarator);
|
||||
ASTModification modification = new ASTModification(ModificationKind.APPEND_CHILD, declarator, exception, null);
|
||||
modStore.storeModification(null, modification);
|
||||
|
||||
}
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
return new ExceptionTest();
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
/*******************************************************************************
|
||||
* 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.core.parser.tests.rewrite.changegenerator.append;
|
||||
|
||||
import junit.framework.Test;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTExpressionList;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
|
||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTBinaryExpression;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTIdExpression;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTLiteralExpression;
|
||||
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(){
|
||||
super("Append Expression"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
@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$
|
||||
super.setUp();
|
||||
}
|
||||
@Override
|
||||
protected CPPASTVisitor createModificator(
|
||||
final ASTModificationStore modStore) {
|
||||
return new CPPASTVisitor() {
|
||||
{
|
||||
shouldVisitExpressions = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTExpression expression) {
|
||||
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);
|
||||
modStore.storeModification(null, modification);
|
||||
}
|
||||
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
public static Test suite() {
|
||||
return new ExpressionTest();
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,79 @@
|
|||
/*******************************************************************************
|
||||
* 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.core.parser.tests.rewrite.changegenerator.append;
|
||||
|
||||
import junit.framework.Test;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
|
||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTDeclarator;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDeclarator;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTParameterDeclaration;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTSimpleDeclSpecifier;
|
||||
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 ParameterTest extends ChangeGeneratorTest {
|
||||
|
||||
public ParameterTest(){
|
||||
super("Append Parameter to List"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
@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$
|
||||
super.setUp();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CPPASTVisitor createModificator(
|
||||
final ASTModificationStore modStore) {
|
||||
return new CPPASTVisitor() {
|
||||
{
|
||||
shouldVisitDeclarators = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTDeclarator declarator) {
|
||||
if (declarator instanceof CPPASTFunctionDeclarator) {
|
||||
CPPASTFunctionDeclarator functionDeclarator = (CPPASTFunctionDeclarator)declarator;
|
||||
|
||||
CPPASTParameterDeclaration insertedParameter = new CPPASTParameterDeclaration();
|
||||
CPPASTDeclarator parameterDeclarator = new CPPASTDeclarator();
|
||||
CPPASTName parameterName = new CPPASTName("newParameter".toCharArray()); //$NON-NLS-1$
|
||||
parameterDeclarator.setName(parameterName);
|
||||
insertedParameter.setDeclarator(parameterDeclarator);
|
||||
CPPASTSimpleDeclSpecifier parameterDeclSpec = new CPPASTSimpleDeclSpecifier();
|
||||
parameterDeclSpec.setType(IASTSimpleDeclSpecifier.t_int);
|
||||
insertedParameter.setDeclSpecifier(parameterDeclSpec);
|
||||
ASTModification modification = new ASTModification(ModificationKind.APPEND_CHILD, functionDeclarator, insertedParameter, null);
|
||||
modStore.storeModification(null, modification);
|
||||
}
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
return new ParameterTest();
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,79 @@
|
|||
/*******************************************************************************
|
||||
* 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.core.parser.tests.rewrite.changegenerator.append;
|
||||
|
||||
import junit.framework.Test;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
|
||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTDeclarator;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDeclarator;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTParameterDeclaration;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTSimpleDeclSpecifier;
|
||||
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 ParameterToListTest extends ChangeGeneratorTest {
|
||||
|
||||
public ParameterToListTest(){
|
||||
super("Append Parameter to Empty List"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
@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$
|
||||
super.setUp();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CPPASTVisitor createModificator(
|
||||
final ASTModificationStore modStore) {
|
||||
return new CPPASTVisitor() {
|
||||
{
|
||||
shouldVisitDeclarators = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTDeclarator declarator) {
|
||||
if (declarator instanceof CPPASTFunctionDeclarator) {
|
||||
CPPASTFunctionDeclarator functionDeclarator = (CPPASTFunctionDeclarator)declarator;
|
||||
|
||||
CPPASTParameterDeclaration insertedParameter = new CPPASTParameterDeclaration();
|
||||
CPPASTDeclarator parameterDeclarator = new CPPASTDeclarator();
|
||||
CPPASTName parameterName = new CPPASTName("newParameter".toCharArray()); //$NON-NLS-1$
|
||||
parameterDeclarator.setName(parameterName);
|
||||
insertedParameter.setDeclarator(parameterDeclarator);
|
||||
CPPASTSimpleDeclSpecifier parameterDeclSpec = new CPPASTSimpleDeclSpecifier();
|
||||
parameterDeclSpec.setType(IASTSimpleDeclSpecifier.t_int);
|
||||
insertedParameter.setDeclSpecifier(parameterDeclSpec);
|
||||
ASTModification modification = new ASTModification(ModificationKind.APPEND_CHILD, functionDeclarator, insertedParameter, null);
|
||||
modStore.storeModification(null, modification);
|
||||
}
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
return new ParameterToListTest();
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,72 @@
|
|||
/*******************************************************************************
|
||||
* 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.core.parser.tests.rewrite.changegenerator.append;
|
||||
|
||||
import junit.framework.Test;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
|
||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDeclarator;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTPointer;
|
||||
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 PointerToParameterTest extends ChangeGeneratorTest {
|
||||
|
||||
|
||||
public PointerToParameterTest(){
|
||||
super("Append Pointer to 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$
|
||||
super.setUp();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected CPPASTVisitor createModificator(
|
||||
final ASTModificationStore modStore) {
|
||||
return new CPPASTVisitor() {
|
||||
{
|
||||
shouldVisitDeclarators = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTDeclarator declarator) {
|
||||
if (declarator instanceof CPPASTFunctionDeclarator) {
|
||||
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);
|
||||
modStore.storeModification(null, modification);
|
||||
}
|
||||
}
|
||||
}
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
return new PointerToParameterTest();
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
/*******************************************************************************
|
||||
* 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.core.parser.tests.rewrite.changegenerator.append;
|
||||
|
||||
import junit.framework.Test;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
|
||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDeclarator;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTPointer;
|
||||
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 PointerToPointerParameterTest extends ChangeGeneratorTest {
|
||||
|
||||
public PointerToPointerParameterTest(){
|
||||
super("Append Pointer to Pointer 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$
|
||||
super.setUp();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CPPASTVisitor createModificator(
|
||||
final ASTModificationStore modStore) {
|
||||
return new CPPASTVisitor() {
|
||||
{
|
||||
shouldVisitDeclarators = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTDeclarator declarator) {
|
||||
if (declarator instanceof CPPASTFunctionDeclarator) {
|
||||
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);
|
||||
modStore.storeModification(null, modification);
|
||||
}
|
||||
}
|
||||
}
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
return new PointerToPointerParameterTest();
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
/*******************************************************************************
|
||||
* 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.core.parser.tests.rewrite.changegenerator.insertbefore;
|
||||
|
||||
import junit.framework.Test;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTArrayModifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
|
||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTArrayModifier;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTLiteralExpression;
|
||||
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 ArrayModifierTest extends ChangeGeneratorTest {
|
||||
|
||||
public ArrayModifierTest(){
|
||||
super("Replace Array Modifier"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
source = "int *pi[3];"; //$NON-NLS-1$
|
||||
expectedSource = "int *pi[5][3];"; //$NON-NLS-1$
|
||||
super.setUp();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CPPASTVisitor createModificator(
|
||||
final ASTModificationStore modStore) {
|
||||
return new CPPASTVisitor() {
|
||||
{
|
||||
shouldVisitDeclarators = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTDeclarator declarator) {
|
||||
if (declarator instanceof IASTArrayDeclarator) {
|
||||
IASTArrayDeclarator arrayDeclarator = (IASTArrayDeclarator)declarator;
|
||||
|
||||
IASTArrayModifier[] modifiers = arrayDeclarator.getArrayModifiers();
|
||||
IASTArrayModifier newModifier = new CPPASTArrayModifier();
|
||||
IASTExpression expr = new CPPASTLiteralExpression(0, "5"); //$NON-NLS-1$
|
||||
newModifier.setConstantExpression(expr);
|
||||
ASTModification modification = new ASTModification(ModificationKind.INSERT_BEFORE, modifiers[0], newModifier, null);
|
||||
modStore.storeModification(null, modification);
|
||||
}
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
return new ArrayModifierTest();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
/*******************************************************************************
|
||||
* 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.core.parser.tests.rewrite.changegenerator.insertbefore;
|
||||
|
||||
import junit.framework.Test;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNewExpression;
|
||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTLiteralExpression;
|
||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
|
||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
|
||||
|
||||
|
||||
|
||||
public class ArraySizeExpressionTest extends ChangeGeneratorTest {
|
||||
|
||||
public ArraySizeExpressionTest(){
|
||||
super("Insert Array Size Expression"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
source = "int *values = new int[5];"; //$NON-NLS-1$
|
||||
expectedSource = "int *values = new int[6][5];"; //$NON-NLS-1$
|
||||
super.setUp();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected CPPASTVisitor createModificator(
|
||||
final ASTModificationStore modStore) {
|
||||
return new CPPASTVisitor() {
|
||||
{
|
||||
shouldVisitExpressions = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTExpression expression) {
|
||||
if (expression instanceof ICPPASTNewExpression) {
|
||||
ICPPASTNewExpression newExpression = (ICPPASTNewExpression) expression;
|
||||
IASTExpression[] arraySizeExpressions = newExpression.getNewTypeIdArrayExpressions();
|
||||
ASTModification modification = new ASTModification(ASTModification.ModificationKind.INSERT_BEFORE, arraySizeExpressions[0], new CPPASTLiteralExpression(0, "6"), null); //$NON-NLS-1$
|
||||
modStore.storeModification(null, modification);
|
||||
}
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
return new ArraySizeExpressionTest();
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
/*******************************************************************************
|
||||
* 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.core.parser.tests.rewrite.changegenerator.insertbefore;
|
||||
|
||||
import junit.framework.Test;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer;
|
||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTConstructorChainInitializer;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDeclarator;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTIdExpression;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName;
|
||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
|
||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
|
||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind;
|
||||
|
||||
public class CtorChainInitializerTest extends ChangeGeneratorTest {
|
||||
|
||||
public CtorChainInitializerTest(){
|
||||
super("Insert Before Ctor Initializer"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
@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):alpha(a), beta(b){\n}\n\n"; //$NON-NLS-1$
|
||||
super.setUp();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CPPASTVisitor createModificator(
|
||||
final ASTModificationStore modStore) {
|
||||
return new CPPASTVisitor() {
|
||||
{
|
||||
shouldVisitDeclarators = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTDeclarator declarator) {
|
||||
if (declarator instanceof CPPASTFunctionDeclarator) {
|
||||
CPPASTFunctionDeclarator functionDeclarator = (CPPASTFunctionDeclarator)declarator;
|
||||
ICPPASTConstructorChainInitializer ctorInitializer = functionDeclarator.getConstructorChain()[0];
|
||||
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, initExpr);
|
||||
ASTModification modification = new ASTModification(ModificationKind.INSERT_BEFORE, ctorInitializer, newInitializer, null);
|
||||
modStore.storeModification(null, modification);
|
||||
|
||||
}
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
return new CtorChainInitializerTest();
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,77 @@
|
|||
/*******************************************************************************
|
||||
* 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.core.parser.tests.rewrite.changegenerator.insertbefore;
|
||||
|
||||
import junit.framework.Test;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTypeId;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
|
||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTDeclarator;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDeclarator;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTSimpleDeclSpecifier;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTTypeId;
|
||||
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 ExceptionTest extends ChangeGeneratorTest {
|
||||
|
||||
public ExceptionTest(){
|
||||
super("Insert Before 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, float){\n}\n\n"; //$NON-NLS-1$
|
||||
super.setUp();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CPPASTVisitor createModificator(
|
||||
final ASTModificationStore modStore) {
|
||||
return new CPPASTVisitor() {
|
||||
{
|
||||
shouldVisitDeclarators = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTDeclarator declarator) {
|
||||
if (declarator instanceof CPPASTFunctionDeclarator) {
|
||||
CPPASTFunctionDeclarator functionDeclarator = (CPPASTFunctionDeclarator)declarator;
|
||||
IASTTypeId existingException = functionDeclarator.getExceptionSpecification()[0];
|
||||
|
||||
IASTTypeId exception = new CPPASTTypeId();
|
||||
CPPASTDeclarator exceptionDeclarator = new CPPASTDeclarator();
|
||||
exceptionDeclarator.setName(new CPPASTName());
|
||||
CPPASTSimpleDeclSpecifier exDeclSpec = new CPPASTSimpleDeclSpecifier();
|
||||
exDeclSpec.setType(IASTSimpleDeclSpecifier.t_int);
|
||||
exception.setDeclSpecifier(exDeclSpec);
|
||||
exception.setAbstractDeclarator(exceptionDeclarator);
|
||||
ASTModification modification = new ASTModification(ModificationKind.INSERT_BEFORE, existingException, exception, null);
|
||||
modStore.storeModification(null, modification);
|
||||
|
||||
}
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
return new ExceptionTest();
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
/*******************************************************************************
|
||||
* 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.core.parser.tests.rewrite.changegenerator.insertbefore;
|
||||
|
||||
import junit.framework.Test;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTExpressionList;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
|
||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTBinaryExpression;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTIdExpression;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTLiteralExpression;
|
||||
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(){
|
||||
super("Insert Expression"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
@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$
|
||||
super.setUp();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CPPASTVisitor createModificator(
|
||||
final ASTModificationStore modStore) {
|
||||
return new CPPASTVisitor() {
|
||||
{
|
||||
shouldVisitExpressions = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTExpression expression) {
|
||||
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);
|
||||
modStore.storeModification(null, modification);
|
||||
}
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
return new ExpressionTest();
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,85 @@
|
|||
/*******************************************************************************
|
||||
* 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.core.parser.tests.rewrite.changegenerator.insertbefore;
|
||||
|
||||
import junit.framework.Test;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
|
||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTDeclarator;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDeclarator;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTParameterDeclaration;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTSimpleDeclSpecifier;
|
||||
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(){
|
||||
super("Insert Before First Parameter"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
@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$
|
||||
super.setUp();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected CPPASTVisitor createModificator(
|
||||
final ASTModificationStore modStore) {
|
||||
return new CPPASTVisitor() {
|
||||
{
|
||||
shouldVisitDeclarators = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTDeclarator declarator) {
|
||||
if (declarator instanceof CPPASTFunctionDeclarator) {
|
||||
CPPASTFunctionDeclarator functionDeclarator = (CPPASTFunctionDeclarator)declarator;
|
||||
IASTParameterDeclaration[] parameters = functionDeclarator.getParameters();
|
||||
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$
|
||||
parameterDeclarator.setName(parameterName);
|
||||
insertedParameter.setDeclarator(parameterDeclarator);
|
||||
CPPASTSimpleDeclSpecifier parameterDeclSpec = new CPPASTSimpleDeclSpecifier();
|
||||
parameterDeclSpec.setType(IASTSimpleDeclSpecifier.t_int);
|
||||
insertedParameter.setDeclSpecifier(parameterDeclSpec);
|
||||
ASTModification modification = new ASTModification(ModificationKind.INSERT_BEFORE, curParam, insertedParameter, null);
|
||||
modStore.storeModification(null, modification);
|
||||
}
|
||||
}
|
||||
}
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
return new FirstParameterTest();
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
/*******************************************************************************
|
||||
* 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.core.parser.tests.rewrite.changegenerator.insertbefore;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
/**
|
||||
* @author Thomas Corbat
|
||||
*
|
||||
*/
|
||||
public class InsertBeforeTestSuite{
|
||||
|
||||
@SuppressWarnings("nls")
|
||||
public static Test suite() throws Exception {
|
||||
TestSuite suite = new TestSuite("Changegenerator InsertBefore Tests");
|
||||
|
||||
suite.addTest(FirstParameterTest.suite());
|
||||
suite.addTest(PointerParameterTest.suite());
|
||||
suite.addTest(ExceptionTest.suite());
|
||||
suite.addTest(CtorChainInitializerTest.suite());
|
||||
suite.addTest(ArrayModifierTest.suite());
|
||||
suite.addTest(ExpressionTest.suite());
|
||||
suite.addTest(ArraySizeExpressionTest.suite());
|
||||
|
||||
return suite;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
/*******************************************************************************
|
||||
* 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.core.parser.tests.rewrite.changegenerator.insertbefore;
|
||||
|
||||
import junit.framework.Test;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTPointerOperator;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
|
||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDeclarator;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTPointer;
|
||||
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 PointerParameterTest extends ChangeGeneratorTest {
|
||||
|
||||
public PointerParameterTest(){
|
||||
super("Insert Pointer for Parameter"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
source = "void foo(int *parameter){\n}\n\n"; //$NON-NLS-1$
|
||||
expectedSource = "void foo(int **parameter){\n}\n\n"; //$NON-NLS-1$
|
||||
super.setUp();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CPPASTVisitor createModificator(
|
||||
final ASTModificationStore modStore) {
|
||||
return new CPPASTVisitor() {
|
||||
{
|
||||
shouldVisitDeclarators = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTDeclarator declarator) {
|
||||
if (declarator instanceof CPPASTFunctionDeclarator) {
|
||||
CPPASTFunctionDeclarator functionDeclarator = (CPPASTFunctionDeclarator)declarator;
|
||||
IASTParameterDeclaration[] parameters = functionDeclarator.getParameters();
|
||||
for(IASTParameterDeclaration curParam : parameters){
|
||||
if(String.valueOf(curParam.getDeclarator().getName().toCharArray()).equals("parameter")){ //$NON-NLS-1$
|
||||
IASTPointerOperator pointer = curParam.getDeclarator().getPointerOperators()[0];
|
||||
CPPASTPointer insertedPointer = new CPPASTPointer();
|
||||
ASTModification modification = new ASTModification(ModificationKind.INSERT_BEFORE, pointer, insertedPointer, null);
|
||||
modStore.storeModification(null, modification);
|
||||
}
|
||||
}
|
||||
}
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
return new PointerParameterTest();
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
/*******************************************************************************
|
||||
* 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.core.parser.tests.rewrite.changegenerator.remove;
|
||||
|
||||
import junit.framework.Test;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTArrayModifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
|
||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
|
||||
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 ArrayModifierTest extends ChangeGeneratorTest {
|
||||
|
||||
public ArrayModifierTest(){
|
||||
super("Remove Array Modifier"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
source = "int *pi[3];"; //$NON-NLS-1$
|
||||
expectedSource = "int *pi;"; //$NON-NLS-1$
|
||||
super.setUp();
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
return new ArrayModifierTest();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CPPASTVisitor createModificator(
|
||||
final ASTModificationStore modStore) {
|
||||
return new CPPASTVisitor() {
|
||||
{
|
||||
shouldVisitDeclarators = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTDeclarator declarator) {
|
||||
if (declarator instanceof IASTArrayDeclarator) {
|
||||
IASTArrayDeclarator arrayDeclarator = (IASTArrayDeclarator)declarator;
|
||||
|
||||
IASTArrayModifier[] modifiers = arrayDeclarator.getArrayModifiers();
|
||||
ASTModification modification = new ASTModification(ModificationKind.REPLACE, modifiers[0], null, null);
|
||||
modStore.storeModification(null, modification);
|
||||
}
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
/*******************************************************************************
|
||||
* 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.core.parser.tests.rewrite.changegenerator.remove;
|
||||
|
||||
import junit.framework.Test;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNewExpression;
|
||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
|
||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
|
||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
|
||||
|
||||
|
||||
|
||||
public class ArraySizeExpressionTest extends ChangeGeneratorTest {
|
||||
|
||||
public ArraySizeExpressionTest(){
|
||||
super("Remove Array Size Expression"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
source = "int *values = new int[5][6];"; //$NON-NLS-1$
|
||||
expectedSource = "int *values = new int[5];"; //$NON-NLS-1$
|
||||
super.setUp();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CPPASTVisitor createModificator(
|
||||
final ASTModificationStore modStore) {
|
||||
return new CPPASTVisitor() {
|
||||
{
|
||||
shouldVisitExpressions = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTExpression expression) {
|
||||
if (expression instanceof ICPPASTNewExpression) {
|
||||
ICPPASTNewExpression newExpression = (ICPPASTNewExpression) expression;
|
||||
IASTExpression[] arraySizeExpressions = newExpression.getNewTypeIdArrayExpressions();
|
||||
ASTModification modification = new ASTModification(ASTModification.ModificationKind.REPLACE, arraySizeExpressions[1], null, null);
|
||||
modStore.storeModification(null, modification);
|
||||
}
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
return new ArraySizeExpressionTest();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,64 @@
|
|||
/*******************************************************************************
|
||||
* 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.core.parser.tests.rewrite.changegenerator.remove;
|
||||
|
||||
import junit.framework.Test;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer;
|
||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDeclarator;
|
||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
|
||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
|
||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind;
|
||||
|
||||
public class CtorChainInitializerTest extends ChangeGeneratorTest {
|
||||
|
||||
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$
|
||||
super.setUp();
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
return new CtorChainInitializerTest();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CPPASTVisitor createModificator(
|
||||
final ASTModificationStore modStore) {
|
||||
return new CPPASTVisitor() {
|
||||
{
|
||||
shouldVisitDeclarators = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTDeclarator declarator) {
|
||||
if (declarator instanceof CPPASTFunctionDeclarator) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
/*******************************************************************************
|
||||
* 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.core.parser.tests.rewrite.changegenerator.remove;
|
||||
|
||||
import junit.framework.Test;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
|
||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTSimpleDeclaration;
|
||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
|
||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public class DeclarationTest extends ChangeGeneratorTest {
|
||||
|
||||
public DeclarationTest(){
|
||||
super("Remove Declaration Node"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
source = "#ifndef A_H_\n#define A_H_\n\nclass A {\n\nprivate:\n int b;\n int c;\n};\n\n#endif /*A_H_*/\n\n"; //$NON-NLS-1$
|
||||
expectedSource = "#ifndef A_H_\n#define A_H_\n\nclass A {\n\nprivate:\n int b;\n};\n\n#endif /*A_H_*/\n\n"; //$NON-NLS-1$
|
||||
super.setUp();
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
|
||||
return new DeclarationTest();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CPPASTVisitor createModificator(
|
||||
final ASTModificationStore modStore) {
|
||||
return new CPPASTVisitor() {
|
||||
{
|
||||
shouldVisitDeclarations = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTDeclaration declaration) {
|
||||
if (declaration instanceof CPPASTSimpleDeclaration) {
|
||||
CPPASTSimpleDeclaration simpleDeclaration = (CPPASTSimpleDeclaration) declaration;
|
||||
if(simpleDeclaration.getDeclarators().length > 0){
|
||||
String name = String.valueOf(simpleDeclaration.getDeclarators()[0].getName().toCharArray());
|
||||
if(name.equals("c")){ //$NON-NLS-1$
|
||||
ASTModification modification = new ASTModification(ASTModification.ModificationKind.REPLACE, declaration, null, null);
|
||||
modStore.storeModification(null, modification);
|
||||
}
|
||||
}
|
||||
}
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
|
@ -0,0 +1,64 @@
|
|||
/*******************************************************************************
|
||||
* 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.core.parser.tests.rewrite.changegenerator.remove;
|
||||
|
||||
import junit.framework.Test;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTypeId;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
|
||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDeclarator;
|
||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
|
||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
|
||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind;
|
||||
|
||||
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 (int){\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 ExceptionTest();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CPPASTVisitor createModificator(
|
||||
final ASTModificationStore modStore) {
|
||||
return new CPPASTVisitor() {
|
||||
{
|
||||
shouldVisitDeclarators = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTDeclarator declarator) {
|
||||
if (declarator instanceof CPPASTFunctionDeclarator) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
/*******************************************************************************
|
||||
* 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.core.parser.tests.rewrite.changegenerator.remove;
|
||||
|
||||
import junit.framework.Test;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTExpressionList;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
|
||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
|
||||
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(){
|
||||
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$
|
||||
super.setUp();
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
return new ExpressionTest();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CPPASTVisitor createModificator(
|
||||
final ASTModificationStore modStore) {
|
||||
return new CPPASTVisitor() {
|
||||
{
|
||||
shouldVisitExpressions = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTExpression expression) {
|
||||
if (expression instanceof IASTExpressionList) {
|
||||
IASTExpressionList expressionList = (IASTExpressionList) expression;
|
||||
IASTExpression[] expressions = expressionList.getExpressions();
|
||||
ASTModification modification = new ASTModification(ASTModification.ModificationKind.REPLACE, expressions[1], null, null);
|
||||
modStore.storeModification(null, modification);
|
||||
}
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,74 @@
|
|||
/*******************************************************************************
|
||||
* 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.core.parser.tests.rewrite.changegenerator.remove;
|
||||
|
||||
import junit.framework.Test;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
|
||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDeclarator;
|
||||
import org.eclipse.cdt.internal.core.dom.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(){
|
||||
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$
|
||||
super.setUp();
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
return new FirstParameterTest();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CPPASTVisitor createModificator(
|
||||
final ASTModificationStore modStore) {
|
||||
return new CPPASTVisitor() {
|
||||
{
|
||||
shouldVisitDeclarators = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTDeclarator declarator) {
|
||||
if (declarator instanceof CPPASTFunctionDeclarator) {
|
||||
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);
|
||||
modStore.storeModification(null, modification);
|
||||
}
|
||||
}
|
||||
}
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
/*******************************************************************************
|
||||
* 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.core.parser.tests.rewrite.changegenerator.remove;
|
||||
|
||||
import junit.framework.Test;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
|
||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDeclarator;
|
||||
import org.eclipse.cdt.internal.core.dom.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(){
|
||||
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$
|
||||
super.setUp();
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
return new LastParameterTest();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CPPASTVisitor createModificator(
|
||||
final ASTModificationStore modStore) {
|
||||
return new CPPASTVisitor() {
|
||||
{
|
||||
shouldVisitDeclarators = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTDeclarator declarator) {
|
||||
if (declarator instanceof CPPASTFunctionDeclarator) {
|
||||
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);
|
||||
modStore.storeModification(null, modification);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
|
@ -0,0 +1,72 @@
|
|||
/*******************************************************************************
|
||||
* 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.core.parser.tests.rewrite.changegenerator.remove;
|
||||
|
||||
import junit.framework.Test;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
|
||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDeclarator;
|
||||
import org.eclipse.cdt.internal.core.dom.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(){
|
||||
super("Remove Middle 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 c){\n}\n\n"; //$NON-NLS-1$
|
||||
super.setUp();
|
||||
}
|
||||
|
||||
|
||||
public static Test suite() {
|
||||
return new MiddleParameterTest();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected CPPASTVisitor createModificator(
|
||||
final ASTModificationStore modStore) {
|
||||
return new CPPASTVisitor() {
|
||||
{
|
||||
shouldVisitDeclarators = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTDeclarator declarator) {
|
||||
if (declarator instanceof CPPASTFunctionDeclarator) {
|
||||
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);
|
||||
modStore.storeModification(null, modification);
|
||||
}
|
||||
}
|
||||
}
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
/*******************************************************************************
|
||||
* 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.core.parser.tests.rewrite.changegenerator.remove;
|
||||
|
||||
import junit.framework.Test;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNewExpression;
|
||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
|
||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
|
||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public class NewInitializerExpressionTest extends ChangeGeneratorTest {
|
||||
|
||||
public NewInitializerExpressionTest(){
|
||||
super("Remove New Initializer Expression"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUp() throws Exception{
|
||||
source = "int *value = new int(5);"; //$NON-NLS-1$
|
||||
expectedSource = "int *value = new int();"; //$NON-NLS-1$
|
||||
super.setUp();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CPPASTVisitor createModificator(
|
||||
final ASTModificationStore modStore) {
|
||||
return new CPPASTVisitor() {
|
||||
{
|
||||
shouldVisitExpressions = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTExpression expression) {
|
||||
if (expression instanceof ICPPASTNewExpression) {
|
||||
ICPPASTNewExpression newExpression = (ICPPASTNewExpression) expression;
|
||||
ASTModification modification = new ASTModification(ASTModification.ModificationKind.REPLACE, newExpression.getNewInitializer(), null, null);
|
||||
modStore.storeModification(null, modification);
|
||||
}
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
return new NewInitializerExpressionTest();
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,74 @@
|
|||
/*******************************************************************************
|
||||
* 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.core.parser.tests.rewrite.changegenerator.remove;
|
||||
|
||||
import junit.framework.Test;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTPointerOperator;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
|
||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDeclarator;
|
||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
|
||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
|
||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind;
|
||||
|
||||
public class PointerInParameterTest extends ChangeGeneratorTest {
|
||||
|
||||
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$
|
||||
super.setUp();
|
||||
}
|
||||
|
||||
|
||||
public static Test suite() {
|
||||
return new PointerInParameterTest();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CPPASTVisitor createModificator(
|
||||
final ASTModificationStore modStore) {
|
||||
return new CPPASTVisitor() {
|
||||
{
|
||||
shouldVisitDeclarators = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTDeclarator declarator) {
|
||||
if (declarator instanceof CPPASTFunctionDeclarator) {
|
||||
CPPASTFunctionDeclarator functionDeclarator = (CPPASTFunctionDeclarator)declarator;
|
||||
IASTParameterDeclaration[] parameters = functionDeclarator.getParameters();
|
||||
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);
|
||||
modStore.storeModification(null, modification);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
/*******************************************************************************
|
||||
* 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.core.parser.tests.rewrite.changegenerator.remove;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
/**
|
||||
* @author Thomas Corbat
|
||||
*
|
||||
*/
|
||||
public class RemoveTestSuite{
|
||||
|
||||
@SuppressWarnings("nls")
|
||||
public static Test suite() throws Exception {
|
||||
TestSuite suite = new TestSuite("Changegenerator Remove Tests");
|
||||
|
||||
suite.addTest(DeclarationTest.suite());
|
||||
suite.addTest(FirstParameterTest.suite());
|
||||
suite.addTest(MiddleParameterTest.suite());
|
||||
suite.addTest(LastParameterTest.suite());
|
||||
suite.addTest(SingleParameterTest.suite());
|
||||
suite.addTest(PointerInParameterTest.suite());
|
||||
suite.addTest(ExceptionTest.suite());
|
||||
suite.addTest(CtorChainInitializerTest.suite());
|
||||
suite.addTest(ArrayModifierTest.suite());
|
||||
suite.addTest(ExpressionTest.suite());
|
||||
suite.addTest(ArraySizeExpressionTest.suite());
|
||||
suite.addTest(NewInitializerExpressionTest.suite());
|
||||
suite.addTest(StatementTest.suite());
|
||||
|
||||
return suite;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
/*******************************************************************************
|
||||
* 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.core.parser.tests.rewrite.changegenerator.remove;
|
||||
|
||||
import junit.framework.Test;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
|
||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDeclarator;
|
||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
|
||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
|
||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind;
|
||||
|
||||
public class SingleParameterTest extends ChangeGeneratorTest {
|
||||
|
||||
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$
|
||||
super.setUp();
|
||||
}
|
||||
|
||||
|
||||
public static Test suite() {
|
||||
return new SingleParameterTest();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CPPASTVisitor createModificator(
|
||||
final ASTModificationStore modStore) {
|
||||
return new CPPASTVisitor() {
|
||||
{
|
||||
shouldVisitDeclarators = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTDeclarator declarator) {
|
||||
if (declarator instanceof CPPASTFunctionDeclarator) {
|
||||
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);
|
||||
modStore.storeModification(null, modification);
|
||||
}
|
||||
}
|
||||
}
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
/*******************************************************************************
|
||||
* 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.core.parser.tests.rewrite.changegenerator.remove;
|
||||
|
||||
import junit.framework.Test;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTIfStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
|
||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
|
||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
|
||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public class StatementTest extends ChangeGeneratorTest {
|
||||
|
||||
public StatementTest(){
|
||||
super("Remove Then-Statement"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
source = "int f()\r\n{\r\n\tint i = 0;\r\n\tif(i < 1){\r\n\t\t++i;\r\n\t}\r\n}\r\n"; //$NON-NLS-1$
|
||||
expectedSource = "int f()\r\n{\r\n\tint i = 0;\r\n}\r\n"; //$NON-NLS-1$
|
||||
super.setUp();
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
return new StatementTest();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected CPPASTVisitor createModificator(
|
||||
final ASTModificationStore modStore) {
|
||||
return new CPPASTVisitor() {
|
||||
{
|
||||
shouldVisitStatements = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTStatement statement) {
|
||||
if (statement instanceof IASTIfStatement) {
|
||||
IASTIfStatement ifStatement = (IASTIfStatement) statement;
|
||||
|
||||
ASTModification modification = new ASTModification(ASTModification.ModificationKind.REPLACE, ifStatement, null, null);
|
||||
modStore.storeModification(null, modification);
|
||||
}
|
||||
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
/*******************************************************************************
|
||||
* 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.core.parser.tests.rewrite.changegenerator.replace;
|
||||
|
||||
import junit.framework.Test;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTArrayModifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
|
||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTArrayModifier;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTLiteralExpression;
|
||||
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 ArrayModifierTest extends ChangeGeneratorTest {
|
||||
|
||||
public ArrayModifierTest(){
|
||||
super("Replace Array Modifier"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
source = "int *pi[3];"; //$NON-NLS-1$
|
||||
expectedSource = "int *pi[15];"; //$NON-NLS-1$
|
||||
super.setUp();
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
return new ArrayModifierTest();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected CPPASTVisitor createModificator(
|
||||
final ASTModificationStore modStore) {
|
||||
return new CPPASTVisitor() {
|
||||
{
|
||||
shouldVisitDeclarators = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTDeclarator declarator) {
|
||||
if (declarator instanceof IASTArrayDeclarator) {
|
||||
IASTArrayDeclarator arrayDeclarator = (IASTArrayDeclarator)declarator;
|
||||
IASTArrayModifier[] modifiers = arrayDeclarator.getArrayModifiers();
|
||||
IASTArrayModifier newModifier = new CPPASTArrayModifier();
|
||||
IASTExpression expr = new CPPASTLiteralExpression(0, "15"); //$NON-NLS-1$
|
||||
newModifier.setConstantExpression(expr);
|
||||
ASTModification modification = new ASTModification(ModificationKind.REPLACE, modifiers[0], newModifier, null);
|
||||
modStore.storeModification(null, modification);
|
||||
}
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
/*******************************************************************************
|
||||
* 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.core.parser.tests.rewrite.changegenerator.replace;
|
||||
|
||||
import junit.framework.Test;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNewExpression;
|
||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTLiteralExpression;
|
||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
|
||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public class ArraySizeExpressionTest extends ChangeGeneratorTest {
|
||||
|
||||
public ArraySizeExpressionTest(){
|
||||
super("Relpace Array Size Expression"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
source = "int *values = new int[5][6];"; //$NON-NLS-1$
|
||||
expectedSource = "int *values = new int[5][7];"; //$NON-NLS-1$
|
||||
super.setUp();
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
return new ArraySizeExpressionTest();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CPPASTVisitor createModificator(
|
||||
final ASTModificationStore modStore) {
|
||||
return new CPPASTVisitor() {
|
||||
{
|
||||
shouldVisitExpressions = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTExpression expression) {
|
||||
if (expression instanceof ICPPASTNewExpression) {
|
||||
ICPPASTNewExpression newExpression = (ICPPASTNewExpression) expression;
|
||||
IASTExpression[] arraySizeExpressions = newExpression.getNewTypeIdArrayExpressions();
|
||||
ASTModification modification = new ASTModification(ASTModification.ModificationKind.REPLACE, arraySizeExpressions[1], new CPPASTLiteralExpression(0, "7"), null); //$NON-NLS-1$
|
||||
modStore.storeModification(null, modification);
|
||||
}
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
/*******************************************************************************
|
||||
* 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.core.parser.tests.rewrite.changegenerator.replace;
|
||||
|
||||
import junit.framework.Test;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer;
|
||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTConstructorChainInitializer;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDeclarator;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTIdExpression;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName;
|
||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
|
||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
|
||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind;
|
||||
|
||||
public class CtorChainInitializerTest extends ChangeGeneratorTest {
|
||||
|
||||
public CtorChainInitializerTest(){
|
||||
super("Replace Ctor Initializer"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
source = "TestClass::TestClass(int a):beta(b){\n}\n\n"; //$NON-NLS-1$
|
||||
expectedSource = "TestClass::TestClass(int a): alpha(a){\n}\n\n"; //$NON-NLS-1$
|
||||
super.setUp();
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
return new CtorChainInitializerTest();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CPPASTVisitor createModificator(
|
||||
final ASTModificationStore modStore) {
|
||||
return new CPPASTVisitor() {
|
||||
{
|
||||
shouldVisitDeclarators = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTDeclarator declarator) {
|
||||
if (declarator instanceof CPPASTFunctionDeclarator) {
|
||||
CPPASTFunctionDeclarator functionDeclarator = (CPPASTFunctionDeclarator)declarator;
|
||||
ICPPASTConstructorChainInitializer[] ctorInitializers = functionDeclarator.getConstructorChain();
|
||||
for(ICPPASTConstructorChainInitializer curInitializer : ctorInitializers){
|
||||
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, initExpr);
|
||||
ASTModification modification = new ASTModification(ModificationKind.REPLACE, curInitializer, newInitializer, null);
|
||||
modStore.storeModification(null, modification);
|
||||
}
|
||||
}
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
|
@ -0,0 +1,78 @@
|
|||
/*******************************************************************************
|
||||
* 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.core.parser.tests.rewrite.changegenerator.replace;
|
||||
|
||||
import junit.framework.Test;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTypeId;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
|
||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTDeclarator;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDeclarator;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTSimpleDeclSpecifier;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTTypeId;
|
||||
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 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$
|
||||
super.setUp();
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
return new ExceptionTest();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CPPASTVisitor createModificator(
|
||||
final ASTModificationStore modStore) {
|
||||
return new CPPASTVisitor() {
|
||||
{
|
||||
shouldVisitDeclarators = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTDeclarator declarator) {
|
||||
if (declarator instanceof CPPASTFunctionDeclarator) {
|
||||
CPPASTFunctionDeclarator functionDeclarator = (CPPASTFunctionDeclarator)declarator;
|
||||
IASTTypeId existingException = functionDeclarator.getExceptionSpecification()[0];
|
||||
|
||||
IASTTypeId exception = new CPPASTTypeId();
|
||||
CPPASTDeclarator exceptionDeclarator = new CPPASTDeclarator();
|
||||
exceptionDeclarator.setName(new CPPASTName());
|
||||
CPPASTSimpleDeclSpecifier exDeclSpec = new CPPASTSimpleDeclSpecifier();
|
||||
exDeclSpec.setType(IASTSimpleDeclSpecifier.t_int);
|
||||
exception.setDeclSpecifier(exDeclSpec);
|
||||
exception.setAbstractDeclarator(exceptionDeclarator);
|
||||
ASTModification modification = new ASTModification(ModificationKind.REPLACE, existingException, exception, null);
|
||||
modStore.storeModification(null, modification);
|
||||
}
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
/*******************************************************************************
|
||||
* 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.core.parser.tests.rewrite.changegenerator.replace;
|
||||
|
||||
import junit.framework.Test;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTExpressionList;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
|
||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTBinaryExpression;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTIdExpression;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTLiteralExpression;
|
||||
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(){
|
||||
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$
|
||||
super.setUp();
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
return new ExpressionTest();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected CPPASTVisitor createModificator(
|
||||
final ASTModificationStore modStore) {
|
||||
return new CPPASTVisitor() {
|
||||
{
|
||||
shouldVisitExpressions = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTExpression expression) {
|
||||
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);
|
||||
modStore.storeModification(null, modification);
|
||||
}
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
/*******************************************************************************
|
||||
* 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.core.parser.tests.rewrite.changegenerator.replace;
|
||||
|
||||
import junit.framework.Test;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
|
||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
|
||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
|
||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public class IdenticalTest extends ChangeGeneratorTest {
|
||||
|
||||
public IdenticalTest(){
|
||||
super("Replace Node Same Node"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
source = "#ifndef A_H_\n#define A_H_\n\nclass A {\n\nprivate:\n int c;\n};\n\n#endif /*A_H_*/\n\n"; //$NON-NLS-1$
|
||||
expectedSource = "#ifndef A_H_\n#define A_H_\n\nclass A {\n\nprivate:\n int c;\n};\n\n#endif /*A_H_*/\n\n"; //$NON-NLS-1$
|
||||
super.setUp();
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
return new IdenticalTest();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CPPASTVisitor createModificator(
|
||||
final ASTModificationStore modStore) {
|
||||
return new CPPASTVisitor() {
|
||||
{
|
||||
shouldVisitDeclarators = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTDeclarator declarator) {
|
||||
ASTModification modification = new ASTModification(ASTModification.ModificationKind.REPLACE, declarator.getName(), declarator.getName(), null);
|
||||
modStore.storeModification(null, modification);
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
/*******************************************************************************
|
||||
* 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.core.parser.tests.rewrite.changegenerator.replace;
|
||||
|
||||
import junit.framework.Test;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTInitializer;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
|
||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTDeclarator;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTInitializerExpression;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTLiteralExpression;
|
||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
|
||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
|
||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind;
|
||||
|
||||
public class InitializerTest extends ChangeGeneratorTest {
|
||||
|
||||
public InitializerTest(){
|
||||
super("Replace Initializer"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
source = "int hs = 5;"; //$NON-NLS-1$
|
||||
expectedSource = "int hs = 999;"; //$NON-NLS-1$
|
||||
super.setUp();
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
return new InitializerTest();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected CPPASTVisitor createModificator(
|
||||
final ASTModificationStore modStore) {
|
||||
return new CPPASTVisitor() {
|
||||
{
|
||||
shouldVisitDeclarators = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTDeclarator declarator) {
|
||||
if (declarator instanceof CPPASTDeclarator) {
|
||||
CPPASTDeclarator fieldDeclarator = (CPPASTDeclarator)declarator;
|
||||
IASTInitializer initializer = fieldDeclarator.getInitializer();
|
||||
|
||||
CPPASTLiteralExpression litEx = new CPPASTLiteralExpression(0, "999"); //$NON-NLS-1$
|
||||
CPPASTInitializerExpression initExpr = new CPPASTInitializerExpression(litEx);
|
||||
|
||||
ASTModification modification = new ASTModification(ModificationKind.REPLACE, initializer, initExpr, null);
|
||||
modStore.storeModification(null, modification);
|
||||
}
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
|
@ -0,0 +1,77 @@
|
|||
/*******************************************************************************
|
||||
* 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.core.parser.tests.rewrite.changegenerator.replace;
|
||||
|
||||
import junit.framework.Test;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
|
||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTCompositeTypeSpecifier;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTSimpleDeclaration;
|
||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
|
||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public class MoveRenameTest extends ChangeGeneratorTest {
|
||||
|
||||
public MoveRenameTest(){
|
||||
super("Swap Rename Declarations"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
|
||||
source = "#ifndef A_H_\r\n#define A_H_\r\n\r\nclass A {\r\n\r\nprivate:\r\n int b;\r\n int a;\r\n};\r\n\r\n#endif /*A_H_*/\r\n\r\n"; //$NON-NLS-1$
|
||||
expectedSource = "#ifndef A_H_\r\n#define A_H_\r\n\r\nclass A {\r\n\r\nprivate:\r\n int d;\r\n int b;\r\n};\r\n\r\n#endif /*A_H_*/\r\n\r\n"; //$NON-NLS-1$
|
||||
super.setUp();
|
||||
}
|
||||
|
||||
|
||||
public static Test suite() {
|
||||
return new MoveRenameTest();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CPPASTVisitor createModificator(
|
||||
final ASTModificationStore modStore) {
|
||||
return new CPPASTVisitor() {
|
||||
{
|
||||
shouldVisitDeclSpecifiers = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTDeclSpecifier declSpec) {
|
||||
if (declSpec instanceof ICPPASTCompositeTypeSpecifier) {
|
||||
CPPASTCompositeTypeSpecifier classSpecifier = (CPPASTCompositeTypeSpecifier) declSpec;
|
||||
IASTDeclaration[] members = classSpecifier.getMembers();
|
||||
ASTModification swap1 = new ASTModification(ASTModification.ModificationKind.REPLACE, members[1], members[2], null);
|
||||
ASTModification swap2 = new ASTModification(ASTModification.ModificationKind.REPLACE, members[2], members[1], null);
|
||||
IASTName name =((CPPASTSimpleDeclaration)members[2]).getDeclarators()[0].getName();
|
||||
modStore.storeModification(null, swap1);
|
||||
modStore.storeModification(null, swap2);
|
||||
modStore.storeModification(swap1, new ASTModification(ASTModification.ModificationKind.REPLACE, name, new CPPASTName("d".toCharArray()), null)); //$NON-NLS-1$
|
||||
}
|
||||
return super.visit(declSpec);
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
/*******************************************************************************
|
||||
* 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.core.parser.tests.rewrite.changegenerator.replace;
|
||||
|
||||
import junit.framework.Test;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
|
||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTCompositeTypeSpecifier;
|
||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
|
||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public class MoveTest extends ChangeGeneratorTest {
|
||||
|
||||
public MoveTest(){
|
||||
super("Swap Declarations"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
source = "#ifndef A_H_\r\n#define A_H_\r\n\r\nclass A {\r\n\r\nprivate:\r\n int b;\r\n int a;\r\n};\r\n\r\n#endif /*A_H_*/\r\n\r\n"; //$NON-NLS-1$
|
||||
expectedSource = "#ifndef A_H_\r\n#define A_H_\r\n\r\nclass A {\r\n\r\nprivate:\r\n int a;\r\n int b;\r\n};\r\n\r\n#endif /*A_H_*/\r\n\r\n"; //$NON-NLS-1$
|
||||
super.setUp();
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
return new MoveTest();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CPPASTVisitor createModificator(
|
||||
final ASTModificationStore modStore) {
|
||||
return new CPPASTVisitor() {
|
||||
{
|
||||
shouldVisitDeclSpecifiers = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTDeclSpecifier declSpec) {
|
||||
if (declSpec instanceof ICPPASTCompositeTypeSpecifier) {
|
||||
CPPASTCompositeTypeSpecifier classSpecifier = (CPPASTCompositeTypeSpecifier) declSpec;
|
||||
IASTDeclaration[] members = classSpecifier.getMembers();
|
||||
ASTModification swap1 = new ASTModification(ASTModification.ModificationKind.REPLACE, members[1], members[2], null);
|
||||
ASTModification swap2 = new ASTModification(ASTModification.ModificationKind.REPLACE, members[2], members[1], null);
|
||||
modStore.storeModification(null, swap1);
|
||||
modStore.storeModification(null, swap2);
|
||||
}
|
||||
return super.visit(declSpec);
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
/*******************************************************************************
|
||||
* 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.core.parser.tests.rewrite.changegenerator.replace;
|
||||
|
||||
import junit.framework.Test;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
|
||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
|
||||
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 NameTest extends ChangeGeneratorTest {
|
||||
|
||||
|
||||
public NameTest(){
|
||||
super("Replace Name Node"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
source = "#ifndef A_H_\r\n#define A_H_\r\n\r\nclass A {\r\n\r\nprivate:\r\n int c;\r\n};\r\n\r\n#endif /*A_H_*/\r\n\r\n"; //$NON-NLS-1$
|
||||
expectedSource = "#ifndef A_H_\r\n#define A_H_\r\n\r\nclass A {\r\n\r\nprivate:\r\n int b;\r\n};\r\n\r\n#endif /*A_H_*/\r\n\r\n"; //$NON-NLS-1$
|
||||
super.setUp();
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
return new NameTest();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CPPASTVisitor createModificator(
|
||||
final ASTModificationStore modStore) {
|
||||
return new CPPASTVisitor() {
|
||||
{
|
||||
shouldVisitDeclarators = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTDeclarator declarator) {
|
||||
char[] newName = new char[]{'b'};
|
||||
IASTName name = new CPPASTName(newName);
|
||||
ASTModification modification = new ASTModification(ASTModification.ModificationKind.REPLACE, declarator.getName(), name, null);
|
||||
modStore.storeModification(null, modification);
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
/*******************************************************************************
|
||||
* 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.core.parser.tests.rewrite.changegenerator.replace;
|
||||
|
||||
import junit.framework.Test;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNewExpression;
|
||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTLiteralExpression;
|
||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
|
||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public class NewInitializerExpressionTest extends ChangeGeneratorTest {
|
||||
|
||||
public NewInitializerExpressionTest(){
|
||||
super("Replace New Initializer Expression"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
source = "int *value = new int(5);"; //$NON-NLS-1$
|
||||
expectedSource = "int *value = new int(6);"; //$NON-NLS-1$
|
||||
super.setUp();
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
return new NewInitializerExpressionTest();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CPPASTVisitor createModificator(
|
||||
final ASTModificationStore modStore) {
|
||||
return new CPPASTVisitor() {
|
||||
{
|
||||
shouldVisitExpressions = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTExpression expression) {
|
||||
if (expression instanceof ICPPASTNewExpression) {
|
||||
ICPPASTNewExpression newExpression = (ICPPASTNewExpression) expression;
|
||||
ASTModification modification = new ASTModification(ASTModification.ModificationKind.REPLACE, newExpression.getNewInitializer(), new CPPASTLiteralExpression(0, "6"), null); //$NON-NLS-1$
|
||||
modStore.storeModification(null, modification);
|
||||
}
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
/*******************************************************************************
|
||||
* 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.core.parser.tests.rewrite.changegenerator.replace;
|
||||
|
||||
import junit.framework.Test;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTPointerOperator;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
|
||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDeclarator;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTPointer;
|
||||
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 PointerInParameterTest extends ChangeGeneratorTest {
|
||||
|
||||
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$
|
||||
super.setUp();
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
return new PointerInParameterTest();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CPPASTVisitor createModificator(
|
||||
final ASTModificationStore modStore) {
|
||||
return new CPPASTVisitor() {
|
||||
{
|
||||
shouldVisitDeclarators = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTDeclarator declarator) {
|
||||
if (declarator instanceof CPPASTFunctionDeclarator) {
|
||||
CPPASTFunctionDeclarator functionDeclarator = (CPPASTFunctionDeclarator)declarator;
|
||||
IASTParameterDeclaration[] parameters = functionDeclarator.getParameters();
|
||||
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);
|
||||
modStore.storeModification(null, modification);
|
||||
}
|
||||
}
|
||||
}
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
/*******************************************************************************
|
||||
* 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.core.parser.tests.rewrite.changegenerator.replace;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
/**
|
||||
* @author Thomas Corbat
|
||||
*
|
||||
*/
|
||||
public class ReplaceTestSuite{
|
||||
|
||||
@SuppressWarnings("nls")
|
||||
public static Test suite() throws Exception {
|
||||
TestSuite suite = new TestSuite("ChangegeneratorReplaceTests");
|
||||
|
||||
suite.addTest(NameTest.suite());
|
||||
suite.addTest(MoveTest.suite());
|
||||
suite.addTest(MoveRenameTest.suite());
|
||||
suite.addTest(SameNameTest.suite());
|
||||
suite.addTest(IdenticalTest.suite());
|
||||
suite.addTest(PointerInParameterTest.suite());
|
||||
suite.addTest(ExceptionTest.suite());
|
||||
suite.addTest(ArrayModifierTest.suite());
|
||||
suite.addTest(InitializerTest.suite());
|
||||
suite.addTest(ExpressionTest.suite());
|
||||
suite.addTest(ArraySizeExpressionTest.suite());
|
||||
suite.addTest(NewInitializerExpressionTest.suite());
|
||||
suite.addTest(StatementTest.suite());
|
||||
return suite;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
/*******************************************************************************
|
||||
* 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.core.parser.tests.rewrite.changegenerator.replace;
|
||||
|
||||
import junit.framework.Test;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
|
||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
|
||||
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 SameNameTest extends ChangeGeneratorTest {
|
||||
|
||||
public SameNameTest(){
|
||||
super("Replace Name Node Same Name"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
|
||||
source = "#ifndef A_H_\r\n#define A_H_\r\n\r\nclass A {\r\n\r\nprivate:\r\n int c;\r\n};\r\n\r\n#endif /*A_H_*/\r\n\r\n"; //$NON-NLS-1$
|
||||
expectedSource = "#ifndef A_H_\r\n#define A_H_\r\n\r\nclass A {\r\n\r\nprivate:\r\n int c;\r\n};\r\n\r\n#endif /*A_H_*/\r\n\r\n"; //$NON-NLS-1$
|
||||
super.setUp();
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
return new SameNameTest();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CPPASTVisitor createModificator(
|
||||
final ASTModificationStore modStore) {
|
||||
return new CPPASTVisitor() {
|
||||
{
|
||||
shouldVisitDeclarators = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTDeclarator declarator) {
|
||||
char[] newName = new char[]{'c'};
|
||||
IASTName name = new CPPASTName(newName);
|
||||
ASTModification modification = new ASTModification(ASTModification.ModificationKind.REPLACE, declarator.getName(), name, null);
|
||||
modStore.storeModification(null, modification);
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
/*******************************************************************************
|
||||
* 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.core.parser.tests.rewrite.changegenerator.replace;
|
||||
|
||||
import junit.framework.Test;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTIfStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
|
||||
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTCompoundStatement;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTExpressionStatement;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTIdExpression;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTUnaryExpression;
|
||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
|
||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public class StatementTest extends ChangeGeneratorTest {
|
||||
|
||||
public StatementTest(){
|
||||
super("Replace Then-Statement"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
source = "int f()\r\n{\r\n\tint i = 0;\r\n\tif(i < 1){\r\n\t\t++i;\r\n\t}\r\n}\r\n"; //$NON-NLS-1$
|
||||
expectedSource = "int f()\r\n{\r\n\tint i = 0;\r\n\tif(i < 1){\r\n\t i++;\r\n\t}\r\n}\r\n"; //$NON-NLS-1$
|
||||
super.setUp();
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
return new StatementTest();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected CPPASTVisitor createModificator(
|
||||
final ASTModificationStore modStore) {
|
||||
return new CPPASTVisitor() {
|
||||
{
|
||||
shouldVisitStatements = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTStatement statement) {
|
||||
if (statement instanceof IASTIfStatement) {
|
||||
IASTIfStatement ifStatement = (IASTIfStatement) statement;
|
||||
CPPASTCompoundStatement compound = new CPPASTCompoundStatement();
|
||||
|
||||
CPPASTExpressionStatement expr = new CPPASTExpressionStatement(new CPPASTUnaryExpression(IASTUnaryExpression.op_postFixIncr, new CPPASTIdExpression(new CPPASTName("i".toCharArray())))); //$NON-NLS-1$
|
||||
compound.addStatement(expr);
|
||||
ASTModification modification = new ASTModification(ASTModification.ModificationKind.REPLACE, ifStatement.getThenClause(), compound, null);
|
||||
modStore.storeModification(null, modification);
|
||||
}
|
||||
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
|
@ -0,0 +1,118 @@
|
|||
/*******************************************************************************
|
||||
* 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.core.parser.tests.rewrite.comenthandler;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.TreeSet;
|
||||
import java.util.Vector;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTComment;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
import org.eclipse.cdt.core.parser.tests.rewrite.RewriteBaseTest;
|
||||
import org.eclipse.cdt.core.parser.tests.rewrite.TestSourceFile;
|
||||
import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.ASTCommenter;
|
||||
import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
||||
/**
|
||||
* @author Guido Zgraggen IFS
|
||||
*
|
||||
*/
|
||||
public class CommentHandlingTest extends RewriteBaseTest {
|
||||
|
||||
private static final String ANY_CHAR_REGEXP = "(.*)"; //$NON-NLS-1$
|
||||
private static String separator = System.getProperty("line.separator"); //$NON-NLS-1$
|
||||
|
||||
private static String LEADING_COMMENT_SEPARATOR = "=>leading"; //$NON-NLS-1$
|
||||
private static String TRAILING_COMMENT_SEPARATOR = "=>trailing"; //$NON-NLS-1$
|
||||
private static String FREESTANDING_COMMENT_SEPARATOR = "=>freestanding"; //$NON-NLS-1$
|
||||
|
||||
public CommentHandlingTest(String name, Vector<TestSourceFile> files) {
|
||||
super(name, files);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void runTest() throws Throwable {
|
||||
|
||||
if (fileMap.size() > 1) {
|
||||
throw new Exception("To many files for CommentHandlingTest"); //$NON-NLS-1$
|
||||
} else if (fileMap.size() == 0) {
|
||||
throw new Exception("No file for testing"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
TestSourceFile file = fileMap.values().iterator().next();
|
||||
|
||||
NodeCommentMap nodeMap = ASTCommenter.getCommentedNodeMap(getUnit());
|
||||
Matcher matcher = Pattern.compile(CommentHandlingTest.getSeparatingRegexp(), Pattern.MULTILINE | Pattern.DOTALL).matcher(file.getExpectedSource());
|
||||
|
||||
if (!matcher.find()) {
|
||||
fail("Missing expected section. Expected result code must be of the following format:\n\"=>leading\n...\n=>trailing\n...\n=>freestanding\""); //$NON-NLS-1$
|
||||
}
|
||||
String leadingResult = matcher.group(1);
|
||||
String trailingResult = matcher.group(2);
|
||||
String freestandingResult = matcher.group(3);
|
||||
|
||||
testMap(nodeMap.getLeadingMap(), leadingResult, "Leading test failed."); //$NON-NLS-1$
|
||||
testMap(nodeMap.getTrailingMap(), trailingResult, "Trailing test failed."); //$NON-NLS-1$
|
||||
testMap(nodeMap.getFreestandingMap(), freestandingResult, "Freestanding test failed."); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
private void testMap(HashMap<IASTNode, ArrayList<IASTComment>> map, String expectedResult, String err) {
|
||||
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);
|
||||
|
||||
output.append(actNode.getRawSignature() + " = "); //$NON-NLS-1$
|
||||
boolean first = true;
|
||||
for (IASTComment actComment : comments) {
|
||||
if (!first) {
|
||||
output.append(" , "); //$NON-NLS-1$
|
||||
}
|
||||
output.append(actComment.getRawSignature());
|
||||
first = false;
|
||||
}
|
||||
output.append(separator);
|
||||
}
|
||||
assertEquals(err, expectedResult.trim(), output.toString().trim());
|
||||
}
|
||||
|
||||
private static String getSeparatingRegexp() {
|
||||
return LEADING_COMMENT_SEPARATOR + ANY_CHAR_REGEXP + TRAILING_COMMENT_SEPARATOR + ANY_CHAR_REGEXP + FREESTANDING_COMMENT_SEPARATOR + ANY_CHAR_REGEXP;
|
||||
}
|
||||
|
||||
// === Nested classes for testing purpose
|
||||
private final class NodeOffsetComparator implements Comparator<IASTNode> {
|
||||
public int compare(IASTNode o1, IASTNode o2) {
|
||||
int offDif = o1.getFileLocation().getNodeOffset() - o2.getFileLocation().getNodeOffset();
|
||||
if (offDif == 0) {
|
||||
return o1.getFileLocation().getNodeLength() - o2.getFileLocation().getNodeLength();
|
||||
}
|
||||
return offDif;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private IASTTranslationUnit getUnit() throws CoreException {
|
||||
ITranslationUnit tu = (ITranslationUnit) CCorePlugin.getDefault().getCoreModel().create(project.getFile(fileMap.keySet().iterator().next()));
|
||||
return tu.getAST();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
/*******************************************************************************
|
||||
* 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.core.parser.tests.rewrite.comenthandler;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
import org.eclipse.cdt.core.parser.tests.rewrite.RewriteTester;
|
||||
|
||||
/**
|
||||
* @author Guido Zgraggen IFS
|
||||
*
|
||||
*/
|
||||
public class CommentHandlingTestSuite extends TestSuite {
|
||||
|
||||
public static Test suite() throws Exception {
|
||||
TestSuite suite = new TestSuite(CommentHandlingTestSuite.class.getName());
|
||||
|
||||
suite.addTest(RewriteTester.suite("CommentTests", "resources/rewrite/CommentHandlingTestSource.rts")); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
|
||||
suite.addTestSuite(NodeCommentMapTest.class);
|
||||
|
||||
return suite;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,102 @@
|
|||
/*******************************************************************************
|
||||
* 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.core.parser.tests.rewrite.comenthandler;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTComment;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName;
|
||||
import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap;
|
||||
|
||||
/**
|
||||
* @author Guido Zgraggen IFS
|
||||
*
|
||||
*/
|
||||
public class NodeCommentMapTest extends TestCase {
|
||||
|
||||
private NodeCommentMap map;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
map = new NodeCommentMap();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
map = null;
|
||||
}
|
||||
|
||||
public void testNoComment(){
|
||||
ASTNode node = new CPPASTName();
|
||||
|
||||
assertEquals(0, map.getCommentsForNode(node).size());
|
||||
}
|
||||
|
||||
public void testOneComment(){
|
||||
ASTNode node = new CPPASTName();
|
||||
IASTComment comm = new Comment();
|
||||
|
||||
map.addCommentToNode(node, comm);
|
||||
|
||||
assertEquals(1, map.getCommentsForNode(node).size());
|
||||
assertEquals(comm, map.getCommentsForNode(node).get(0));
|
||||
}
|
||||
|
||||
public void testTwoComment(){
|
||||
ASTNode node = new CPPASTName();
|
||||
IASTComment com1 = new Comment();
|
||||
IASTComment com2 = new Comment();
|
||||
|
||||
map.addCommentToNode(node, com1);
|
||||
map.addCommentToNode(node, com2);
|
||||
|
||||
assertEquals(2, map.getCommentsForNode(node).size());
|
||||
assertEquals(com1, map.getCommentsForNode(node).get(0));
|
||||
assertEquals(com2, map.getCommentsForNode(node).get(1));
|
||||
}
|
||||
|
||||
|
||||
public void testCommentOnDifferentNodes(){
|
||||
ASTNode node1 = new CPPASTName();
|
||||
ASTNode node2 = new CPPASTName();
|
||||
IASTComment com1 = new Comment();
|
||||
IASTComment com2 = new Comment();
|
||||
IASTComment com3 = new Comment();
|
||||
|
||||
|
||||
map.addCommentToNode(node1, com1);
|
||||
map.addCommentToNode(node2, com2);
|
||||
map.addCommentToNode(node1, com3);
|
||||
|
||||
assertEquals(2, map.getCommentsForNode(node1).size());
|
||||
assertEquals(1, map.getCommentsForNode(node2).size());
|
||||
assertEquals(com1, map.getCommentsForNode(node1).get(0));
|
||||
assertEquals(com2, map.getCommentsForNode(node2).get(0));
|
||||
assertEquals(com3, map.getCommentsForNode(node1).get(1));
|
||||
}
|
||||
|
||||
|
||||
//=== InternalComment class for testing
|
||||
private class Comment extends ASTNode implements IASTComment{
|
||||
private char[] comment;
|
||||
|
||||
public char[] getComment() {
|
||||
return comment;
|
||||
}
|
||||
public void setComment(char[] comment) {
|
||||
this.comment = comment;
|
||||
}
|
||||
//not used
|
||||
public boolean isBlockComment() {return false;}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,222 @@
|
|||
//!Commented DeclSpecifierTest
|
||||
//%CPP
|
||||
//Test1
|
||||
inline int foo()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
//Test2
|
||||
const int a = 1;
|
||||
//Test3
|
||||
volatile int b = 3;
|
||||
//Test4
|
||||
typedef int *intp;
|
||||
//Test5
|
||||
extern int b;
|
||||
//Test6
|
||||
static int c;
|
||||
//Test7
|
||||
int foo()
|
||||
{
|
||||
auto int i = 1;
|
||||
return i;
|
||||
}
|
||||
|
||||
//Test8
|
||||
int bar()
|
||||
{
|
||||
register int i = c;
|
||||
return i;
|
||||
}
|
||||
|
||||
|
||||
//!Commented CompositeTypeSpecifier
|
||||
//%CPP
|
||||
//Test1
|
||||
struct B //Test1
|
||||
{
|
||||
int c; //Test3
|
||||
char b; //Test4
|
||||
//Test5
|
||||
};
|
||||
//Test6
|
||||
union D //Test7
|
||||
{
|
||||
int i; //Test8
|
||||
int y; //Test9
|
||||
//Test10
|
||||
};
|
||||
//Test11
|
||||
class E //Test12
|
||||
{
|
||||
//Test13
|
||||
public:
|
||||
int c; //Test14
|
||||
//Test15
|
||||
};
|
||||
|
||||
//!Commented ElaboratedTypeSpecifier 1
|
||||
//%CPP
|
||||
//Test1
|
||||
class A *A; //Test2
|
||||
//Test3
|
||||
enum Status{ good, bad}; //Test4
|
||||
//Test5
|
||||
enum Status stat; //Test6
|
||||
//Test7
|
||||
union D //Test8
|
||||
{
|
||||
int i; //Test9
|
||||
int y; //Test10
|
||||
//Test11
|
||||
};
|
||||
//Test12
|
||||
union D d; //Test13
|
||||
|
||||
//!Commented ElaboratedTypeSpecifier 2
|
||||
//%CPP
|
||||
enum Status{ good, bad};
|
||||
enum /*Test*/
|
||||
Status stat;
|
||||
|
||||
//!Commented EnumeratioSpecifier
|
||||
//%CPP
|
||||
enum /*Test*/
|
||||
Status{ good, bad};
|
||||
|
||||
//!NamedTypeSpecifier
|
||||
//%CPP
|
||||
typedef int INT;
|
||||
typedef INT (FOO)(INT);
|
||||
|
||||
//!SimpleDeclSpecifier
|
||||
//%CPP
|
||||
signed short int i;
|
||||
unsigned long int y;
|
||||
float f;
|
||||
void x();
|
||||
char c;
|
||||
double d;
|
||||
|
||||
//!Commented CPPCompositeTypeSpecifier 1
|
||||
//%CPP
|
||||
//TEST 1
|
||||
class TestClass //TEST 2
|
||||
{
|
||||
//TEST 3
|
||||
}; //TEST 4
|
||||
|
||||
//!Commented CPPCompositeTypeSpecifier 2
|
||||
//%CPP
|
||||
/*TEST 1*/
|
||||
class TestClass /*TEST 2*/
|
||||
{
|
||||
/*TEST 3*/
|
||||
}; /*TEST 4*/
|
||||
|
||||
//!Commented CPPCompositeTypeSpecifier 3
|
||||
//%CPP
|
||||
//TEST 1
|
||||
class TestClass2 //TEST 2
|
||||
: public TestClass //TEST 3
|
||||
{
|
||||
//TEST 4
|
||||
}; //TEST 5
|
||||
|
||||
//!Commented CPPCompositeTypeSpecifier 4
|
||||
//%CPP
|
||||
/*TEST 1*/
|
||||
class TestClass2 /*TEST 2*/
|
||||
: public TestClass
|
||||
{
|
||||
/*TEST 3*/
|
||||
}; /*TEST 4*/
|
||||
|
||||
//!Commented CPPCompositeTypeSpecifier 5
|
||||
//%CPP
|
||||
class TestClass2 /*TEST 1*/
|
||||
: public TestClass
|
||||
{
|
||||
};
|
||||
|
||||
//!Commented CPPCompositeTypeSpecifier 6
|
||||
//%CPP
|
||||
|
||||
class TestClass2
|
||||
: public TestClass /*TEST 1*/
|
||||
{
|
||||
};
|
||||
|
||||
//=
|
||||
class TestClass2 : public TestClass /*TEST 1*/
|
||||
{
|
||||
};
|
||||
|
||||
//!Commented CPPCompositeTypeSpecifier 7
|
||||
//%CPP
|
||||
class TestClass2 : public TestClass
|
||||
{ //TEST 1
|
||||
};
|
||||
|
||||
//=
|
||||
class TestClass2 : public TestClass
|
||||
{
|
||||
//TEST 1
|
||||
};
|
||||
|
||||
//!Commented CPPCompositeTypeSpecifier 8
|
||||
//%CPP
|
||||
class TestClass2
|
||||
: public TestClass
|
||||
{ /*TEST 1*/
|
||||
};
|
||||
|
||||
//=
|
||||
class TestClass2 : public TestClass
|
||||
{
|
||||
/*TEST 1*/
|
||||
};
|
||||
|
||||
//!Commented CPPNamedTypeSpecifier 1
|
||||
//%CPP
|
||||
template<class T> class A
|
||||
{
|
||||
//TEST 1
|
||||
typedef char C; //TEST 2
|
||||
};
|
||||
|
||||
//!Commented CPPNamedTypeSpecifier 2
|
||||
//%CPP
|
||||
template<class T> class A
|
||||
{
|
||||
/*TEST 1*/
|
||||
typedef char C; /*TEST 2*/
|
||||
};
|
||||
|
||||
//!Commented SimpleDeclSpecifier 1
|
||||
//%CPP
|
||||
//TEST 1
|
||||
bool b; //TEST 2
|
||||
|
||||
//!Commented SimpleDeclSpecifier 2
|
||||
//%CPP
|
||||
/*TEST 1*/
|
||||
wchar_t wc; /*TEST 2*/
|
||||
|
||||
//!Commented DeclSpecifier in Definition
|
||||
//%CPP
|
||||
//comment a
|
||||
void tree(int a){ //comment b
|
||||
a = 1; //comment c
|
||||
} //comment d
|
||||
|
||||
//=
|
||||
//comment a
|
||||
void tree(int a)
|
||||
{
|
||||
//comment b
|
||||
a = 1; //comment c
|
||||
} //comment d
|
||||
|
||||
|
|
@ -0,0 +1,168 @@
|
|||
//!Commented ASMDeclarationTest 1
|
||||
//%CPP
|
||||
//TEST 1
|
||||
asm("movl %1, %%eax;"); //TEST 2
|
||||
|
||||
//!Commented ASMDeclarationTest 2
|
||||
//%CPP
|
||||
/*TEST 1*/
|
||||
asm("movl %1, %%eax;"); /*TEST 2*/
|
||||
|
||||
//!Commented FunctionDefinitionTest 1
|
||||
//%CPP
|
||||
//TEST 1
|
||||
int foo()
|
||||
{
|
||||
//inner comment
|
||||
return 1;
|
||||
} //TEST 2
|
||||
|
||||
|
||||
//!Commented FunctionDefinitionTest 2
|
||||
//%CPP
|
||||
/*TEST 1*/
|
||||
int foo()
|
||||
{
|
||||
//inner comment
|
||||
return 1;
|
||||
} /*TEST 1*/
|
||||
|
||||
|
||||
//!Commented SimpleDeclarationTest 1
|
||||
//%CPP
|
||||
//TEST 1
|
||||
int i = 2, y = 3; //TEST 2
|
||||
//TEST 3
|
||||
int b = 0; //TEST 4
|
||||
|
||||
//!Commented NamespaceAlias 1
|
||||
//%CPP
|
||||
//TEST 1
|
||||
namespace kurz = ziemlichlangernamespace; //TEST 2
|
||||
|
||||
//!Commented NamespaceAlias 2
|
||||
//%CPP
|
||||
/*TEST 1*/
|
||||
namespace kurz = ziemlichlangernamespace; /*TEST 2*/
|
||||
|
||||
//!Commented TemplateDeclaration 1
|
||||
//%CPP
|
||||
//TEST 1
|
||||
template<class T> class vector //TEST 2
|
||||
{
|
||||
//TEST 3
|
||||
}; //TEST 4
|
||||
|
||||
//!Commented TemplateDeclaration 2
|
||||
//%CPP
|
||||
/*TEST 1*/
|
||||
template<class T> class vector /*TEST 2*/
|
||||
{
|
||||
/*TEST 3*/
|
||||
}; /*TEST 4*/
|
||||
|
||||
//!Commented NestedTemplateDeclaration 1
|
||||
//%CPP
|
||||
//TEST 1
|
||||
template<template <class T> class K> class vector //TEST 2
|
||||
{
|
||||
//TEST 3
|
||||
}; //TEST 4
|
||||
|
||||
//!Commented NestedTemplateDeclaration 2
|
||||
//%CPP
|
||||
/*TEST 1*/
|
||||
template<template <class T> class K> class vector /*TEST 2*/
|
||||
{
|
||||
/*TEST 3*/
|
||||
}; /*TEST 4*/
|
||||
|
||||
//!Commented TemplateSpecialization 1
|
||||
//%CPP
|
||||
//TEST 1
|
||||
template<> class MyQueue<double> //TEST 2
|
||||
{
|
||||
//TEST 3
|
||||
std::vector<double> data;
|
||||
public:
|
||||
void Add(const double& );
|
||||
void Remove();
|
||||
void Print();
|
||||
//TEST 4
|
||||
}; //TEST 5
|
||||
|
||||
//!Commented TemplateSpecialization 2
|
||||
//%CPP
|
||||
/*TEST 1*/
|
||||
template<> class MyQueue<double> /*TEST 2*/
|
||||
{
|
||||
/*TEST 3*/
|
||||
std::vector<double> data;
|
||||
public:
|
||||
void Add(const double& );
|
||||
void Remove();
|
||||
void Print();
|
||||
/*TEST 4*/
|
||||
}; /*TEST 5*/
|
||||
|
||||
//!Commented UsingDeclaration 1
|
||||
//%CPP
|
||||
struct A
|
||||
{
|
||||
void f();
|
||||
enum E{ e};
|
||||
union
|
||||
{
|
||||
int u;
|
||||
};
|
||||
};
|
||||
struct B : A
|
||||
{
|
||||
//TEST 1
|
||||
using A::f; //TEST 2
|
||||
/*TEST 3*/
|
||||
using typename A::e; /*TEST 4*/
|
||||
using A::u;
|
||||
/*TEST 5*/
|
||||
};
|
||||
|
||||
//!Commented UsingDirective 1
|
||||
//%CPP
|
||||
//TEST
|
||||
using namespace B; //TEST
|
||||
|
||||
|
||||
//!Commented VisibilityLabel 1
|
||||
//%CPP
|
||||
class A
|
||||
{
|
||||
//TEST 1
|
||||
public: //TEST 2
|
||||
int hallo();
|
||||
/*TEST 3*/
|
||||
protected: /*TEST 4*/
|
||||
int b, c;
|
||||
private:
|
||||
int p;
|
||||
};
|
||||
|
||||
//!Comment BeforeSimpleDeclaration 1
|
||||
//%CPP
|
||||
//TEST 1
|
||||
int i = 2; //TEST 2
|
||||
|
||||
//!Comment BeforeSimpleDeclaration 2
|
||||
//%CPP
|
||||
/*TEST 1*/
|
||||
int i = 2; /*TEST 2*/
|
||||
|
||||
//!Commented typename qualfier 1
|
||||
//%CPP
|
||||
//TEST 1
|
||||
typename T::A *a6; //TEST 2
|
||||
|
||||
//!Commented typename qualfier 2
|
||||
//%CPP
|
||||
/*TEST 1*/
|
||||
typename T::A *a6; /*TEST 2*/
|
||||
|
|
@ -0,0 +1,275 @@
|
|||
//!Commented DeclaratorTest 1
|
||||
//%CPP
|
||||
//TEST 1
|
||||
void foo()
|
||||
{
|
||||
//TEST 2
|
||||
struct B
|
||||
{
|
||||
int f();
|
||||
};
|
||||
int (B::* pb)() = &B::f;
|
||||
}
|
||||
|
||||
|
||||
//!Commented DeclaratorTest 2
|
||||
//%CPP
|
||||
/*TEST 1*/
|
||||
void foo()
|
||||
{
|
||||
/*TEST 2*/
|
||||
struct B
|
||||
{
|
||||
int f();
|
||||
};
|
||||
int (B::* pb)() = &B::f;
|
||||
}
|
||||
|
||||
|
||||
//!Commented CPPFunctionDeclaratorTest 1
|
||||
//%CPP
|
||||
char & operator [](unsigned int);
|
||||
//TEST 1
|
||||
TestClass::TestClass(int a) //TEST 2
|
||||
{
|
||||
//TEST 3
|
||||
} //TEST 4
|
||||
|
||||
|
||||
//!Commented CPPFunctionDeclaratorTest 2
|
||||
//%CPP
|
||||
char & operator [](unsigned int);
|
||||
/*TEST 1*/
|
||||
TestClass::TestClass(int a) /*TEST 2*/
|
||||
{
|
||||
/*TEST 3*/
|
||||
} /*TEST 4*/
|
||||
|
||||
|
||||
//!Commented CPPFunctionDeclaratorTest 3
|
||||
//%CPP
|
||||
char & operator [](unsigned int);
|
||||
//TEST 1
|
||||
TestClass::TestClass(int a)
|
||||
:alpha(a) //TEST 2
|
||||
{
|
||||
//TEST 3
|
||||
} //TEST 4
|
||||
|
||||
|
||||
//!Commented CPPFunctionDeclaratorTest 4
|
||||
//%CPP
|
||||
char & operator [](unsigned int);
|
||||
/*TEST 1*/
|
||||
TestClass::TestClass(int a)
|
||||
:alpha(a) /*TEST 3*/
|
||||
{
|
||||
/*TEST 4*/
|
||||
} /*TEST 5*/
|
||||
|
||||
|
||||
//!Commented ICPPASTFunctionTryBlockDeclarator1
|
||||
//%CPP
|
||||
void foo()
|
||||
{
|
||||
int i = 1;
|
||||
try {
|
||||
i++;
|
||||
}
|
||||
catch(...){
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//!Commented ICPPASTFunctionTryBlockDeclarator2
|
||||
//%CPP
|
||||
void foo()
|
||||
{
|
||||
int i = 1;
|
||||
//Test
|
||||
try {
|
||||
i++;
|
||||
}
|
||||
catch(...){
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//!Commented ICPPASTFunctionTryBlockDeclarator3
|
||||
//%CPP
|
||||
void foo()
|
||||
{
|
||||
int i = 1;
|
||||
try {
|
||||
//Test
|
||||
i++;
|
||||
}
|
||||
catch(...){
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//!Commented ICPPASTFunctionTryBlockDeclarator3b
|
||||
//%CPP
|
||||
void foo()
|
||||
{
|
||||
int i = 1;
|
||||
try //Test
|
||||
{
|
||||
i++;
|
||||
}
|
||||
catch(...){
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//!Commented ICPPASTFunctionTryBlockDeclarator4
|
||||
//%CPP
|
||||
void foo()
|
||||
{
|
||||
int i = 1;
|
||||
try {
|
||||
//Test
|
||||
i++;
|
||||
}
|
||||
catch(...){
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//!Commented ICPPASTFunctionTryBlockDeclarator5
|
||||
//%CPP
|
||||
void foo()
|
||||
{
|
||||
int i = 1;
|
||||
try {
|
||||
i++; //Test
|
||||
}
|
||||
catch(...){
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//!Commented ICPPASTFunctionTryBlockDeclarator6
|
||||
//%CPP
|
||||
void foo()
|
||||
{
|
||||
int i = 1;
|
||||
try {
|
||||
i++;
|
||||
//Test
|
||||
}
|
||||
catch(...){
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//!Commented ICPPASTFunctionTryBlockDeclarator7
|
||||
//%CPP
|
||||
void foo()
|
||||
{
|
||||
int i = 1;
|
||||
try {
|
||||
i++;
|
||||
} //Test
|
||||
catch(...){
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//!Commented ICPPASTFunctionTryBlockDeclarator8
|
||||
//%CPP
|
||||
void foo()
|
||||
{
|
||||
int i = 1;
|
||||
try {
|
||||
i++;
|
||||
}
|
||||
catch(...){
|
||||
//Test
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//!Commented ICPPASTFunctionTryBlockDeclarator9
|
||||
//%CPP
|
||||
void foo()
|
||||
{
|
||||
int i = 1;
|
||||
try {
|
||||
i++;
|
||||
}
|
||||
catch(...){
|
||||
//Test
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//!Commented ICPPASTFunctionTryBlockDeclarator11
|
||||
//%CPP
|
||||
void foo()
|
||||
{
|
||||
int i = 1;
|
||||
try {
|
||||
i++;
|
||||
}
|
||||
catch(...){
|
||||
}
|
||||
//Test
|
||||
}
|
||||
|
||||
|
||||
//!Commented ICPPASTFunctionTryBlockDeclarator12
|
||||
//%CPP
|
||||
void foo()
|
||||
{
|
||||
int i = 1;
|
||||
try {
|
||||
i++;
|
||||
}
|
||||
catch(Overflow oo){
|
||||
}
|
||||
catch(Matherr mm){
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//!Commented ICPPASTFunctionTryBlockDeclarator13
|
||||
//%CPP
|
||||
void foo()
|
||||
{
|
||||
int i = 1;
|
||||
try {
|
||||
i++;
|
||||
}
|
||||
catch(Overflow oo){
|
||||
}
|
||||
catch(Matherr mm){
|
||||
//Test
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//!Commented ICPPASTFunctionTryBlockDeclarator 14
|
||||
//%CPP
|
||||
void foo()
|
||||
{
|
||||
int f(int);
|
||||
class C
|
||||
{
|
||||
int i;
|
||||
double d;
|
||||
public:
|
||||
C(int, double);
|
||||
};
|
||||
C::C(int ii, double id)
|
||||
try
|
||||
:i(f(ii)), d(id)
|
||||
{
|
||||
}
|
||||
catch(...){
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,86 @@
|
|||
//!Commented NameTest1
|
||||
//%CPP
|
||||
//Test
|
||||
Hallo;
|
||||
|
||||
//!Commented NameTest2
|
||||
//%CPP
|
||||
Hallo; //Test
|
||||
|
||||
//!Commented NameTest2
|
||||
//%CPP
|
||||
Hallo /*Test*/;
|
||||
|
||||
//!Commented QualifiedName1
|
||||
//%CPP
|
||||
//TEST
|
||||
TestClass::Hallo;
|
||||
|
||||
//!Commented QualifiedName1
|
||||
//%CPP
|
||||
TestClass::Hallo; //TEST
|
||||
|
||||
//!Commented QualifiedName1
|
||||
//%CPP
|
||||
TestClass::Hallo /*Test*/;
|
||||
|
||||
//!Commented OperatorName1
|
||||
//%CPP
|
||||
class Foo
|
||||
{
|
||||
public:
|
||||
//Test
|
||||
char & operator [](unsigned int);
|
||||
};
|
||||
|
||||
//!Commented OperatorName2
|
||||
//%CPP
|
||||
class Foo
|
||||
{
|
||||
public:
|
||||
char & operator [](unsigned int); //Test
|
||||
};
|
||||
|
||||
//!Commented ConversionName1
|
||||
//%CPP
|
||||
class Foo
|
||||
{
|
||||
public:
|
||||
//Test
|
||||
operator int();
|
||||
};
|
||||
|
||||
//!Commented ConversionName2
|
||||
//%CPP
|
||||
class Foo
|
||||
{
|
||||
public:
|
||||
operator int(); //Test
|
||||
};
|
||||
|
||||
//!Commented ConversionName3
|
||||
//%CPP
|
||||
class Foo
|
||||
{
|
||||
public:
|
||||
operator int() /*Test*/;
|
||||
};
|
||||
|
||||
//!Commented TemplateID1
|
||||
//%CPP
|
||||
//Test
|
||||
A::B<T> b;
|
||||
|
||||
//!Commented TemplateID2
|
||||
//%CPP
|
||||
A::B<T> b; //Test
|
||||
|
||||
//!Commented NestedTemplates1
|
||||
//%CPP
|
||||
//Test
|
||||
vector<vector<int> > vvi;
|
||||
|
||||
//!Commented NestedTemplates2
|
||||
//%CPP
|
||||
vector<vector<int> > vvi; //Test
|
||||
|
|
@ -0,0 +1,660 @@
|
|||
//!Commented BreakStatementTest 1
|
||||
//%CPP
|
||||
void foo()
|
||||
{
|
||||
while(true){
|
||||
//TEST 1
|
||||
break; //TEST 2
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//!Commented BreakStatementTest 2
|
||||
//%CPP
|
||||
void foo()
|
||||
{
|
||||
while(true){
|
||||
/*TEST 1*/
|
||||
break; /*TEST 2*/
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//!Commented CompoundStatementTest 1
|
||||
//%CPP
|
||||
void foo()
|
||||
{
|
||||
int i = 2;
|
||||
//TEST 1
|
||||
{
|
||||
//TEST 2
|
||||
int a = i;
|
||||
{
|
||||
//TEST 3
|
||||
a++;
|
||||
//TEST 4
|
||||
} //TEST 5
|
||||
//TEST 6
|
||||
} //TEST 7
|
||||
}
|
||||
|
||||
|
||||
//!Commented CompoundStatementTest 2
|
||||
//%CPP
|
||||
void foo()
|
||||
{
|
||||
int i = 2;
|
||||
/*TEST 1*/
|
||||
{
|
||||
/*TEST 2*/
|
||||
int a = i;
|
||||
{
|
||||
/*TEST 3*/
|
||||
a++;
|
||||
/*TEST 4*/
|
||||
} /*TEST 5*/
|
||||
/*TEST 6*/
|
||||
} /*TEST 7*/
|
||||
}
|
||||
|
||||
|
||||
//!Commented ContinueStatementTest 1
|
||||
//%CPP
|
||||
void foo()
|
||||
{
|
||||
while(true){
|
||||
//TEST 1
|
||||
continue; //TEST 2
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//!Commented ContinueStatementTest 2
|
||||
//%CPP
|
||||
void foo()
|
||||
{
|
||||
while(true){
|
||||
/*TEST 1*/
|
||||
continue; /*TEST 2*/
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//!Commented DeclarationStatementTest 1
|
||||
//%CPP
|
||||
void foo()
|
||||
{
|
||||
//TEST 1
|
||||
int i = 2; //TEST 2
|
||||
//TEST 3
|
||||
int a; //TEST 4
|
||||
//TEST 5
|
||||
}
|
||||
|
||||
|
||||
//!Commented DeclarationStatementTest 2
|
||||
//%CPP
|
||||
void foo()
|
||||
{
|
||||
/*TEST 1*/
|
||||
int i = 2; /*TEST 2*/
|
||||
/*TEST 3*/
|
||||
int a; /*TEST 4*/
|
||||
/*TEST 5*/
|
||||
}
|
||||
|
||||
|
||||
//!Commented DoStatementTest 1
|
||||
//%CPP
|
||||
void foo()
|
||||
{
|
||||
//TEST 1
|
||||
do{ //TEST 2
|
||||
continue; //TEST 3
|
||||
//TEST 4
|
||||
} while(true); //TEST 5
|
||||
}
|
||||
|
||||
|
||||
//=
|
||||
void foo()
|
||||
{
|
||||
//TEST 1
|
||||
do{
|
||||
//TEST 2
|
||||
continue; //TEST 3
|
||||
//TEST 4
|
||||
} while(true); //TEST 5
|
||||
}
|
||||
|
||||
|
||||
//!Commented DoStatementTest 2
|
||||
//%CPP
|
||||
void foo()
|
||||
{
|
||||
/*TEST 1*/
|
||||
do{ /*TEST 2*/
|
||||
continue; /*TEST 3*/
|
||||
/*TEST 4*/
|
||||
} while(true); /*TEST 5*/
|
||||
}
|
||||
|
||||
|
||||
//=
|
||||
void foo()
|
||||
{
|
||||
/*TEST 1*/
|
||||
do{
|
||||
/*TEST 2*/
|
||||
continue; /*TEST 3*/
|
||||
/*TEST 4*/
|
||||
} while(true); /*TEST 5*/
|
||||
}
|
||||
|
||||
|
||||
//!Commented DoStatementTest 3
|
||||
//%CPP
|
||||
void foo()
|
||||
{
|
||||
do{
|
||||
continue;
|
||||
} while(true); /*TEST 1*/
|
||||
}
|
||||
|
||||
|
||||
//!Commented ExpressionsStatement1
|
||||
//%CPP
|
||||
void foo()
|
||||
{
|
||||
bar1();
|
||||
//TEST
|
||||
bar2();
|
||||
}
|
||||
|
||||
|
||||
//!Commented ExpressionsStatement2
|
||||
//%CPP
|
||||
void foo()
|
||||
{
|
||||
//TEST
|
||||
bar1();
|
||||
bar2();
|
||||
}
|
||||
|
||||
|
||||
//!Commented ExpressionsStatement3
|
||||
//%CPP
|
||||
void foo()
|
||||
{
|
||||
bar1();
|
||||
bar2();
|
||||
//TEST
|
||||
}
|
||||
|
||||
|
||||
//!Commented ForStatementTest 1
|
||||
//%CPP
|
||||
void foo()
|
||||
{
|
||||
//TEST 1
|
||||
for(int i = 0;i < 1;++i){ //TEST 2
|
||||
break; //TEST 3
|
||||
} //TEST 4
|
||||
}
|
||||
|
||||
|
||||
//=
|
||||
void foo()
|
||||
{
|
||||
//TEST 1
|
||||
for(int i = 0;i < 1;++i){
|
||||
//TEST 2
|
||||
break; //TEST 3
|
||||
} //TEST 4
|
||||
}
|
||||
|
||||
|
||||
//!Commented ForStatementTest 2
|
||||
//%CPP
|
||||
void foo()
|
||||
{
|
||||
/*TEST 1*/
|
||||
for(int i = 0;i < 1;++i){ /*TEST 2*/
|
||||
break; /*TEST 3*/
|
||||
} /*TEST 4*/
|
||||
}
|
||||
|
||||
|
||||
//=
|
||||
void foo()
|
||||
{
|
||||
/*TEST 1*/
|
||||
for(int i = 0;i < 1;++i){
|
||||
/*TEST 2*/
|
||||
break; /*TEST 3*/
|
||||
} /*TEST 4*/
|
||||
}
|
||||
|
||||
|
||||
//!Commented ForStatementTest 3
|
||||
//%CPP
|
||||
void foo()
|
||||
{
|
||||
for(int i = 0;i < 1;++i){
|
||||
break;
|
||||
} /*TEST 4*/
|
||||
}
|
||||
|
||||
|
||||
//!Commented GotoStatement1
|
||||
//%CPP
|
||||
void foo()
|
||||
{
|
||||
start:
|
||||
bar();
|
||||
//TEST
|
||||
goto start;
|
||||
}
|
||||
|
||||
|
||||
//!Commented GotoStatement2
|
||||
//%CPP
|
||||
void foo()
|
||||
{
|
||||
start:
|
||||
bar();
|
||||
goto start; //TEST
|
||||
}
|
||||
|
||||
|
||||
//!Commented GotoStatement3
|
||||
//%CPP
|
||||
void foo()
|
||||
{
|
||||
start:
|
||||
bar();
|
||||
goto /*TEST*/ start;
|
||||
}
|
||||
|
||||
|
||||
//=
|
||||
void foo()
|
||||
{
|
||||
start:
|
||||
bar();
|
||||
goto /*TEST*/
|
||||
start;
|
||||
}
|
||||
|
||||
|
||||
//!Commented GotoStatement4
|
||||
//%CPP
|
||||
void foo()
|
||||
{
|
||||
start:
|
||||
bar();
|
||||
goto //TEST
|
||||
start;
|
||||
}
|
||||
|
||||
|
||||
//!Commented GotoStatement5
|
||||
//%CPP
|
||||
void foo()
|
||||
{
|
||||
start:
|
||||
bar();
|
||||
goto /*TEST*/
|
||||
start;
|
||||
}
|
||||
|
||||
|
||||
//!Commented LabelStatement1
|
||||
//%CPP
|
||||
void foo()
|
||||
{
|
||||
//Test
|
||||
start:
|
||||
bar();
|
||||
goto start;
|
||||
}
|
||||
|
||||
|
||||
//!Commented LabelStatement2
|
||||
//%CPP
|
||||
void foo()
|
||||
{
|
||||
start: //Test
|
||||
bar();
|
||||
goto start;
|
||||
}
|
||||
|
||||
|
||||
//=
|
||||
void foo()
|
||||
{
|
||||
start:
|
||||
//Test
|
||||
bar();
|
||||
goto start;
|
||||
}
|
||||
|
||||
|
||||
//!Commented LabelStatement3
|
||||
//%CPP
|
||||
void foo()
|
||||
{
|
||||
start: /*Test*/
|
||||
bar();
|
||||
goto start;
|
||||
}
|
||||
|
||||
|
||||
//=
|
||||
void foo()
|
||||
{
|
||||
start:
|
||||
/*Test*/
|
||||
bar();
|
||||
goto start;
|
||||
}
|
||||
|
||||
|
||||
//!Commented LabelStatement4
|
||||
//%CPP
|
||||
void foo()
|
||||
{
|
||||
start:
|
||||
//Test
|
||||
bar();
|
||||
goto start;
|
||||
}
|
||||
|
||||
|
||||
//!Commented LabelStatement5
|
||||
//%CPP
|
||||
void foo()
|
||||
{
|
||||
start:
|
||||
bar(); //Test
|
||||
goto start;
|
||||
}
|
||||
|
||||
|
||||
//!Commented IfStatementTest 1
|
||||
//%CPP
|
||||
int f()
|
||||
{
|
||||
if(int c = f()){
|
||||
c++;
|
||||
} //TEST 1
|
||||
return i;
|
||||
}
|
||||
|
||||
|
||||
//!Commented IfStatementTest 2
|
||||
//%CPP
|
||||
int f()
|
||||
{
|
||||
int i = 0;
|
||||
//TEST 1
|
||||
if(i < 1){
|
||||
//TEST 3
|
||||
++i;
|
||||
//TEST 4
|
||||
}else{
|
||||
//TEST 5
|
||||
--i;
|
||||
//TEST 6
|
||||
} //TEST 7
|
||||
if(int c = f()){
|
||||
c++;
|
||||
} //TEST 8
|
||||
return i;
|
||||
}
|
||||
|
||||
|
||||
//!Commented IfStatementTest 3
|
||||
//%CPP
|
||||
int f()
|
||||
{
|
||||
int i = 0;
|
||||
/*TEST 1*/
|
||||
if(i < 1){
|
||||
/*TEST 1*/
|
||||
++i;
|
||||
/*TEST 1*/
|
||||
}else{
|
||||
/*TEST 1*/
|
||||
--i;
|
||||
/*TEST 1*/
|
||||
} /*TEST 1*/
|
||||
if(int c = f()){
|
||||
c++;
|
||||
} /*TEST 1*/
|
||||
return i;
|
||||
}
|
||||
|
||||
|
||||
//!Commented IfStatementTest 4
|
||||
//%CPP
|
||||
int g()
|
||||
{
|
||||
if(10 > 5) //TEST 1
|
||||
return 1; //TEST 2
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
//=
|
||||
int g()
|
||||
{
|
||||
if(10 > 5)
|
||||
//TEST 1
|
||||
return 1; //TEST 2
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
//!Commented IfStatementTest 5
|
||||
//%CPP
|
||||
int g()
|
||||
{
|
||||
if(10 > 5) /*TEST 1*/
|
||||
return 1; /*TEST 2*/
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
//=
|
||||
int g()
|
||||
{
|
||||
if(10 > 5)
|
||||
/*TEST 1*/
|
||||
return 1; /*TEST 2*/
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
//!NullStatementTest
|
||||
//%CPP
|
||||
void f()
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
//!Commented ReturnStatement1
|
||||
//%CPP
|
||||
void foo()
|
||||
{
|
||||
return; //Test
|
||||
}
|
||||
|
||||
|
||||
//!Commented ReturnStatement2
|
||||
//%CPP
|
||||
void foo()
|
||||
{
|
||||
return 5; //Test
|
||||
}
|
||||
|
||||
|
||||
//!Commented ReturnStatement3
|
||||
//%CPP
|
||||
void foo()
|
||||
{
|
||||
//Test
|
||||
return 1 + 1;
|
||||
}
|
||||
|
||||
|
||||
//!Commented SwitchStatementTest 1
|
||||
//%CPP
|
||||
void foo()
|
||||
{
|
||||
//TEST 1
|
||||
switch (1){
|
||||
//TEST 2
|
||||
case 1: //TEST 3
|
||||
return 1; //TEST 4
|
||||
case 2:
|
||||
return 2;
|
||||
default: //TEST 5
|
||||
return 3;
|
||||
//TEST 6
|
||||
} //TEST 7
|
||||
}
|
||||
|
||||
|
||||
//!Commented SwitchStatementTest 2
|
||||
//%CPP
|
||||
void foo()
|
||||
{
|
||||
/*TEST 1*/
|
||||
switch (1){ /*TEST 2*/
|
||||
/*TEST 3*/
|
||||
case 1: /*TEST 4*/
|
||||
return 1; /*TEST 5*/
|
||||
case 2:
|
||||
return 2;
|
||||
default: /*TEST 6*/
|
||||
return 3;
|
||||
/*TEST 7*/
|
||||
} /*TEST 8*/
|
||||
}
|
||||
|
||||
|
||||
//=
|
||||
void foo()
|
||||
{
|
||||
/*TEST 1*/
|
||||
switch (1){
|
||||
/*TEST 2*/
|
||||
/*TEST 3*/
|
||||
case 1: /*TEST 4*/
|
||||
return 1; /*TEST 5*/
|
||||
case 2:
|
||||
return 2;
|
||||
default: /*TEST 6*/
|
||||
return 3;
|
||||
/*TEST 7*/
|
||||
} /*TEST 8*/
|
||||
}
|
||||
|
||||
|
||||
//!Commented SwitchStatementTest 3
|
||||
//%CPP
|
||||
void foo()
|
||||
{
|
||||
switch (1){
|
||||
case 1:
|
||||
return 1;
|
||||
case 2:
|
||||
return 2;
|
||||
default:
|
||||
return 3;
|
||||
} /*TEST 8*/
|
||||
}
|
||||
|
||||
|
||||
//!Commented WhileStatementTest 1
|
||||
//%CPP
|
||||
void foo()
|
||||
{
|
||||
//TEST 1
|
||||
while(true){ //TEST 2
|
||||
//TEST 3
|
||||
break; //TEST 4
|
||||
//TEST 5
|
||||
} //TEST 6
|
||||
}
|
||||
|
||||
|
||||
//=
|
||||
void foo()
|
||||
{
|
||||
//TEST 1
|
||||
while(true){
|
||||
//TEST 2
|
||||
//TEST 3
|
||||
break; //TEST 4
|
||||
//TEST 5
|
||||
} //TEST 6
|
||||
}
|
||||
|
||||
|
||||
//!Commented WhileStatementTest 2
|
||||
//%CPP
|
||||
void foo()
|
||||
{
|
||||
/*TEST 1*/
|
||||
while(true){ /*TEST 2*/
|
||||
/*TEST 3*/
|
||||
break; /*TEST 4*/
|
||||
/*TEST 5*/
|
||||
} /*TEST 6*/
|
||||
}
|
||||
|
||||
|
||||
//=
|
||||
void foo()
|
||||
{
|
||||
/*TEST 1*/
|
||||
while(true){
|
||||
/*TEST 2*/
|
||||
/*TEST 3*/
|
||||
break; /*TEST 4*/
|
||||
/*TEST 5*/
|
||||
} /*TEST 6*/
|
||||
}
|
||||
|
||||
|
||||
//!Commented WhileStatementTest 3
|
||||
//%CPP
|
||||
void foo()
|
||||
{
|
||||
while(true){
|
||||
break;
|
||||
} /*TEST 6*/
|
||||
}
|
||||
|
||||
|
||||
//!TryBlockStatement
|
||||
//%CPP
|
||||
int foo()
|
||||
{
|
||||
try {
|
||||
int i = 1;
|
||||
try {
|
||||
++i;
|
||||
return i;
|
||||
}
|
||||
catch(...){
|
||||
}
|
||||
}
|
||||
catch(...){
|
||||
}
|
||||
}
|
||||
|
||||
|
File diff suppressed because it is too large
Load diff
|
@ -0,0 +1,57 @@
|
|||
//!Commented TemplateFunction1
|
||||
//%CPP
|
||||
template<typename T> int tempFunct(T p)
|
||||
{
|
||||
++p;
|
||||
//Kommentar
|
||||
p + 4;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
//!Commented TemplateFunction2
|
||||
//%CPP
|
||||
//Kommentar
|
||||
template<typename T> int tempFunct(T p)
|
||||
{
|
||||
++p;
|
||||
p + 4;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
//!Commented ExpressionList1
|
||||
//%CPP
|
||||
void foo()
|
||||
{
|
||||
int i, j, k;
|
||||
//Test
|
||||
i = 1, j = 2, k = 3;
|
||||
}
|
||||
|
||||
|
||||
//!Commented ExpressionList2
|
||||
//%CPP
|
||||
void foo()
|
||||
{
|
||||
int i, j, k;
|
||||
i = 1, j = 2, k = 3; //Test
|
||||
}
|
||||
|
||||
|
||||
//!Commented ExpressionList3
|
||||
//%CPP
|
||||
void foo(){
|
||||
int i, j, k;
|
||||
i = 1, j = 2, k = 3; //Test
|
||||
}
|
||||
|
||||
|
||||
//=
|
||||
void foo()
|
||||
{
|
||||
int i, j, k;
|
||||
i = 1, j = 2, k = 3; //Test
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,164 @@
|
|||
//!DeclSpecifierTest
|
||||
//%CPP
|
||||
inline int foo()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
const int a = 1;
|
||||
volatile int b = 3;
|
||||
typedef int *intp;
|
||||
extern int b;
|
||||
static int c;
|
||||
int foo()
|
||||
{
|
||||
auto int i = 1;
|
||||
return i;
|
||||
}
|
||||
|
||||
int bar()
|
||||
{
|
||||
register int i = c;
|
||||
return i;
|
||||
}
|
||||
|
||||
|
||||
//!CompositeTypeSpecifier
|
||||
//%CPP
|
||||
struct B
|
||||
{
|
||||
int c;
|
||||
char b;
|
||||
};
|
||||
union D
|
||||
{
|
||||
int i;
|
||||
int y;
|
||||
};
|
||||
class E
|
||||
{
|
||||
public:
|
||||
int c;
|
||||
};
|
||||
|
||||
//!ElaboratedTypeSpecifier
|
||||
//%CPP
|
||||
class A *A;
|
||||
enum Status{ good, bad};
|
||||
enum Status stat;
|
||||
union D
|
||||
{
|
||||
int i;
|
||||
int y;
|
||||
};
|
||||
union D d;
|
||||
struct S *S;
|
||||
|
||||
//!EnumeratioSpecifier
|
||||
//%CPP
|
||||
enum Status{ good = 0, bad};
|
||||
|
||||
//!NamedTypeSpecifier
|
||||
//%CPP
|
||||
typedef int INT;
|
||||
typedef INT (FOO)(INT);
|
||||
|
||||
//!SimpleDeclSpecifier
|
||||
//%CPP
|
||||
signed short int i;
|
||||
unsigned long int y;
|
||||
float f;
|
||||
void x();
|
||||
char c;
|
||||
double d;
|
||||
|
||||
//!CDeclSpecifer
|
||||
//%C
|
||||
restrict int i = 1;
|
||||
|
||||
//!CCompositeTypeSpecifier
|
||||
//%C
|
||||
restrict struct B
|
||||
{
|
||||
int c;
|
||||
char b;
|
||||
};
|
||||
restrict union D
|
||||
{
|
||||
int i;
|
||||
int y;
|
||||
};
|
||||
|
||||
//!CElaboratedTypeSpecifier
|
||||
//%C
|
||||
enum Status{ good, bad};
|
||||
restrict enum Status stat;
|
||||
union D
|
||||
{
|
||||
int i;
|
||||
int y;
|
||||
};
|
||||
restrict union D d;
|
||||
|
||||
//!CEnumeratioSpecifier
|
||||
//%C
|
||||
restrict enum Status{ good, bad};
|
||||
|
||||
//!CSimpleDeclSpecifier
|
||||
//%C
|
||||
long long int lli;
|
||||
_Complex float cf;
|
||||
_Bool b;
|
||||
|
||||
//!CPPCompositeTypeSpecifier
|
||||
//%CPP
|
||||
class TestClass
|
||||
{
|
||||
explicit TestClass(int);
|
||||
friend int AddToFriend(int x);
|
||||
};
|
||||
class A
|
||||
{
|
||||
};
|
||||
class TestClass2 : public TestClass, A
|
||||
{
|
||||
};
|
||||
|
||||
//!protected Base Specifiers
|
||||
//%CPP
|
||||
class TestClass
|
||||
{
|
||||
explicit TestClass(int);
|
||||
friend int AddToFriend(int x);
|
||||
};
|
||||
class TestClass2 : protected TestClass
|
||||
{
|
||||
};
|
||||
|
||||
//!private Base Specifiers
|
||||
//%CPP
|
||||
class TestClass
|
||||
{
|
||||
explicit TestClass(int);
|
||||
friend int AddToFriend(int x);
|
||||
};
|
||||
class TestClass2 : private TestClass
|
||||
{
|
||||
};
|
||||
|
||||
//!CPPNamedTypeSpecifier
|
||||
//%CPP
|
||||
template<class T> class A
|
||||
{
|
||||
typedef char C;
|
||||
};
|
||||
|
||||
//!SimpleDeclSpecifier
|
||||
//%CPP
|
||||
bool b;
|
||||
wchar_t wc;
|
||||
|
||||
//!ICPPSimpleDeclSpecifier mutable Bug 40
|
||||
//%CPP
|
||||
mutable int n;
|
||||
|
|
@ -0,0 +1,109 @@
|
|||
//!ASMDeclarationTest
|
||||
//%CPP
|
||||
asm("movl %1, %%eax;");
|
||||
|
||||
//!FunctionDefinitionTest
|
||||
//%CPP
|
||||
int foo()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
//!SimpleDeclarationTest
|
||||
//%CPP
|
||||
int i = 2, y = 3;
|
||||
int b = 0;
|
||||
|
||||
//!ExplicitTemplateInstantion
|
||||
//%CPP
|
||||
template class vector<int>;
|
||||
|
||||
//!GPPExplicitTemplateInstantion
|
||||
//%CPP GNU
|
||||
static template class vector<int>;
|
||||
inline template class vector<int>;
|
||||
inline template class vector<int>;
|
||||
|
||||
//!LinkageSpecification
|
||||
//%CPP
|
||||
extern "C" typedef void FUNC();
|
||||
|
||||
|
||||
//!NamespaceAlias
|
||||
//%CPP
|
||||
namespace kurz = ziemlichlangernamespace;
|
||||
|
||||
//!NamespaceDefinition
|
||||
//%CPP
|
||||
namespace ziemlichlangernamespace
|
||||
{
|
||||
}
|
||||
|
||||
//!TemplateDeclaration
|
||||
//%CPP
|
||||
template<class T> class vector
|
||||
{
|
||||
};
|
||||
|
||||
//!NestedTemplateDeclaration
|
||||
//%CPP
|
||||
template<template <class T> class K> class vector
|
||||
{
|
||||
};
|
||||
|
||||
//!TemplateSpecialization
|
||||
//%CPP
|
||||
template<> class MyQueue<double>
|
||||
{
|
||||
std::vector<double> data;
|
||||
public:
|
||||
void Add(const double& );
|
||||
void Remove();
|
||||
void Print();
|
||||
};
|
||||
|
||||
//!UsingDeclaration
|
||||
//%CPP
|
||||
struct A
|
||||
{
|
||||
void f();
|
||||
enum E{ e};
|
||||
union
|
||||
{
|
||||
int u;
|
||||
};
|
||||
};
|
||||
struct B : A
|
||||
{
|
||||
using A::f;
|
||||
using typename A::e;
|
||||
using A::u;
|
||||
};
|
||||
|
||||
//!UsingDirective
|
||||
//%CPP
|
||||
using namespace B;
|
||||
|
||||
|
||||
//!VisibilityLabel
|
||||
//%CPP
|
||||
class A
|
||||
{
|
||||
public:
|
||||
int hallo();
|
||||
protected:
|
||||
int b, c;
|
||||
private:
|
||||
int p;
|
||||
};
|
||||
|
||||
//!CommentBeforeSimpleDeclaration
|
||||
//%CPP
|
||||
//Comment
|
||||
int i = 2;
|
||||
|
||||
//!typename qualfier
|
||||
//%CPP
|
||||
typename T::A *a6;
|
||||
|
|
@ -0,0 +1,93 @@
|
|||
//!DeclaratorTest
|
||||
//%CPP
|
||||
int sd;
|
||||
int *ip;
|
||||
int hs = 1;
|
||||
char & c;
|
||||
void foo()
|
||||
{
|
||||
struct B
|
||||
{
|
||||
int f();
|
||||
};
|
||||
int (B::* pb)() = &B::f;
|
||||
}
|
||||
|
||||
|
||||
//!ArrayDeclaratorTest
|
||||
//%CPP
|
||||
int *pi[3];
|
||||
int (*p3i)[3];
|
||||
|
||||
//!FieldDeclaratorTest
|
||||
//%CPP
|
||||
struct Bit
|
||||
{
|
||||
int bit : 3;
|
||||
};
|
||||
|
||||
//!CStandardFunctionDeclaratorTest
|
||||
//%C
|
||||
int foo();
|
||||
int bar(int a, int b);
|
||||
int fun(const char *a, ...);
|
||||
int fun3(int i, const char *a, ...);
|
||||
|
||||
//!CPPStandardFunctionDeclaratorTest
|
||||
//%CPP
|
||||
int foo();
|
||||
int bar(int a, int b);
|
||||
int fun(const char *a, ...);
|
||||
int fun2(const char *a ...);
|
||||
int fun3(int i, const char *a, ...);
|
||||
//= ,... is synonymous with ...
|
||||
int foo();
|
||||
int bar(int a, int b);
|
||||
int fun(const char *a, ...);
|
||||
int fun2(const char *a, ...);
|
||||
int fun3(int i, const char *a, ...);
|
||||
|
||||
//!CPPFunctionDeclaratorTest
|
||||
//%CPP
|
||||
char & operator [](unsigned int);
|
||||
TestClass::TestClass(int a)
|
||||
:alpha(a)
|
||||
{
|
||||
}
|
||||
|
||||
void undefPar(const char *c) throw (int);
|
||||
virtual void pure() =0;
|
||||
int getV() const;
|
||||
int vol() volatile;
|
||||
|
||||
//!ICPPASTFunctionTryBlockDeclarator
|
||||
//%CPP
|
||||
void foo()
|
||||
{
|
||||
int f(int);
|
||||
class C
|
||||
{
|
||||
int i;
|
||||
double d;
|
||||
public:
|
||||
C(int, double);
|
||||
};
|
||||
C::C(int ii, double id)
|
||||
try
|
||||
:i(f(ii)), d(id)
|
||||
{
|
||||
}
|
||||
catch(...){
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
//!CKnRFunctionDeclarator
|
||||
//%C GNU
|
||||
int foo(a, b)
|
||||
int b, a;
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,185 @@
|
|||
//!CCastExpression
|
||||
//%C
|
||||
int i = (int)'A';
|
||||
|
||||
//!CPPCastExpression
|
||||
//%CPP
|
||||
TestClass *i = dynamic_cast<TestClass*>(tc);
|
||||
TestClass *i = static_cast<TestClass*>(tc);
|
||||
TestClass *i = reinterpret_cast<TestClass*>(tc);
|
||||
TestClass *i = const_cast<TestClass*>(tc);
|
||||
|
||||
//!ArraySubscrition
|
||||
//%C GNU
|
||||
int i = arr[0];
|
||||
int i = arr[y];
|
||||
|
||||
//!CPPBinaryExpression
|
||||
//%CPP
|
||||
int i = 1 * x;
|
||||
int i = 1 / x;
|
||||
int i = 1 % x;
|
||||
int i = 1 + x;
|
||||
int i = 1 - x;
|
||||
int i = 1 << x;
|
||||
int i = 1 >> x;
|
||||
bool b = 1 < x;
|
||||
bool b = 1 > x;
|
||||
bool b = 1 <= x;
|
||||
bool b = 1 >= x;
|
||||
int i = 1 & x;
|
||||
int i = 1 ^ x;
|
||||
int i = 1 | x;
|
||||
bool b = 1 && x;
|
||||
bool b = 1 || x;
|
||||
int i = x;
|
||||
void foo()
|
||||
{
|
||||
i *= x;
|
||||
}
|
||||
|
||||
void foo()
|
||||
{
|
||||
i /= x;
|
||||
}
|
||||
|
||||
void foo()
|
||||
{
|
||||
1 %= x;
|
||||
}
|
||||
|
||||
void foo()
|
||||
{
|
||||
1 += x;
|
||||
}
|
||||
|
||||
void foo()
|
||||
{
|
||||
1 -= x;
|
||||
}
|
||||
|
||||
void foo()
|
||||
{
|
||||
1 <<= x;
|
||||
}
|
||||
|
||||
void foo()
|
||||
{
|
||||
1 >>= x;
|
||||
}
|
||||
|
||||
void foo()
|
||||
{
|
||||
1 &= x;
|
||||
}
|
||||
|
||||
void foo()
|
||||
{
|
||||
1 |= x;
|
||||
}
|
||||
|
||||
bool b = 1 == x;
|
||||
bool b = 1 != x;
|
||||
int i = a.x;
|
||||
int i = a->x;
|
||||
|
||||
//!BinaryExpression with MacroExpansions
|
||||
//%CPP
|
||||
#define ZWO 2
|
||||
int i = ZWO + 2;
|
||||
int i = 2 + ZWO;
|
||||
//= Preprocessor-Direkrive wird nur bei VP-Translationunits geschrieben
|
||||
int i = ZWO + 2;
|
||||
int i = 2 + ZWO;
|
||||
|
||||
//!GPPBinaryExpression
|
||||
//%CPP GNU
|
||||
int i = 1 <? x;
|
||||
int i = 1 >? x;
|
||||
|
||||
//!ConditionalExpression
|
||||
//%CPP
|
||||
int a = 1 < 2 ? 2 : 3;
|
||||
|
||||
//!ExpressionList
|
||||
//%CPP
|
||||
int a = 1, b = 2, c = 3;
|
||||
|
||||
//!FieldReference
|
||||
//%CPP
|
||||
int i = tc->a;
|
||||
int y = tc.getI();
|
||||
|
||||
//!CPPFieldReference
|
||||
//%CPP
|
||||
int i = tc->template get_new<int>();
|
||||
int y = tc.template get_new<int>();
|
||||
|
||||
//!FunctionCall
|
||||
//%CPP
|
||||
int a = tc.getI();
|
||||
|
||||
//!IdExpression
|
||||
//%CPP
|
||||
int i = a;
|
||||
|
||||
//!LiteralExpression
|
||||
//%CPP
|
||||
int i = 1;
|
||||
int i = 'a';
|
||||
string s = "abc";
|
||||
|
||||
//!CPPLiteralExpression
|
||||
//%CPP
|
||||
TestClass *tc = this;
|
||||
bool b = true;
|
||||
bool b = false;
|
||||
|
||||
//!UnaryExpression
|
||||
//%CPP
|
||||
int i = ++a;
|
||||
int i = --a;
|
||||
int i = +a;
|
||||
int i = -a;
|
||||
int *b = &a;
|
||||
int i = *b;
|
||||
int i = ~b;
|
||||
bool b = !false;
|
||||
int i = sizeof a;
|
||||
int i = a--;
|
||||
int i = a++;
|
||||
int i = (b);
|
||||
|
||||
//!CPPUnaryExpression
|
||||
//%CPP
|
||||
void f()
|
||||
{
|
||||
throw "Fehler";
|
||||
}
|
||||
|
||||
type_info c = typeid (a);
|
||||
|
||||
//!TypeIdExpression
|
||||
//%CPP
|
||||
int d = sizeof (int);
|
||||
|
||||
//!CPPTypeIdExpression
|
||||
//%CPP
|
||||
type_info c = typeid (int);
|
||||
|
||||
//!CPPDeleteExpression
|
||||
//%CPP
|
||||
void f()
|
||||
{
|
||||
delete tc;
|
||||
}
|
||||
|
||||
|
||||
//!CPPNewExpression
|
||||
//%CPP
|
||||
TestClass *tc = new TestClass();
|
||||
|
||||
//!CPPSimpleTypeConstructorExpression
|
||||
//%CPP
|
||||
int i = int(1);
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
//!InitializerExpressionTest
|
||||
//%CPP
|
||||
int i = 0;
|
||||
|
||||
//!InitializerListTest
|
||||
//%CPP
|
||||
struct A
|
||||
{
|
||||
int x;
|
||||
struct B
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
} b;
|
||||
} abs = {1, {2, 3}};
|
||||
|
||||
//!DesignatedInitializer
|
||||
//%C
|
||||
typedef struct
|
||||
{
|
||||
int x;
|
||||
int y;
|
||||
} Coord;
|
||||
Coord xy = {.y = 10, .x = 11};
|
||||
|
||||
//!CPPConstructorInitializer
|
||||
//%CPP
|
||||
int i(3);
|
||||
|
||||
//!CArrayDesignator
|
||||
//%C
|
||||
struct ABC
|
||||
{
|
||||
int def[10];
|
||||
};
|
||||
struct ABC instance = {.def[0] = 9};
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
//!NameTest
|
||||
//%CPP
|
||||
Hallo;
|
||||
|
||||
//!QualifiedName
|
||||
//%CPP
|
||||
TestClass::Hallo;
|
||||
|
||||
//!OperatorName
|
||||
//%CPP
|
||||
class Foo
|
||||
{
|
||||
public:
|
||||
char & operator [](unsigned int);
|
||||
};
|
||||
|
||||
//!ConversionName
|
||||
//%CPP
|
||||
class Foo
|
||||
{
|
||||
public:
|
||||
operator int();
|
||||
};
|
||||
|
||||
//!TemplateID
|
||||
//%CPP
|
||||
A::B<T> b;
|
||||
|
||||
//!NestedTemplates
|
||||
//%CPP
|
||||
vector<vector<int> > vvi;
|
||||
|
|
@ -0,0 +1,94 @@
|
|||
//!DefineObjectStyleMacroWithoutExpansion
|
||||
//%CPP
|
||||
#define LIFE_THE_UNIVERSE_AND_EVERYTHING
|
||||
|
||||
//!DefineObjectStyleMacroWithExpansion
|
||||
//%CPP
|
||||
#define FOO int i = 1;
|
||||
|
||||
//!DefineFunctionStyleMacro
|
||||
//%CPP
|
||||
#define BAR(a, b) a + b
|
||||
|
||||
//!IfElfElseEndif
|
||||
//%CPP
|
||||
#if 1
|
||||
int a;
|
||||
#elif 0
|
||||
int b;
|
||||
#else
|
||||
int c;
|
||||
#endif
|
||||
|
||||
|
||||
//!Ifdef
|
||||
//%CPP
|
||||
#ifdef LIFE_THE_UNIVERS_AND_EVERYTHING
|
||||
#endif
|
||||
|
||||
|
||||
//!Ifndef
|
||||
//%CPP
|
||||
#ifndef LIFE_THE_UNIVERS_AND_EVERYTHING
|
||||
#define LIFE_THE_UNIVERS_AND_EVERYTHING
|
||||
#endif
|
||||
|
||||
|
||||
//!Undef
|
||||
//%CPP
|
||||
#define FOO
|
||||
#undef FOO
|
||||
|
||||
//!Pragma
|
||||
//%CPP
|
||||
#pragma GCC poison printf sprintf fprintf
|
||||
|
||||
//!Error
|
||||
//%CPP
|
||||
#error fehler
|
||||
|
||||
//!ObjectMacroExpansion
|
||||
//%CPP
|
||||
#define FOO 3
|
||||
int main()
|
||||
{
|
||||
int i = FOO;
|
||||
return i;
|
||||
}
|
||||
|
||||
|
||||
//!DefineFunctionStyleMacro
|
||||
//%CPP
|
||||
#define BAR(a, b) a + b
|
||||
int i = BAR(1, 2);
|
||||
|
||||
//!MacroExpansio2ExpansionsBug
|
||||
//%CPP
|
||||
#define HALLO(a, b) a + b
|
||||
int main()
|
||||
{
|
||||
int i = HALLO(45, 2) + HALLO(1, 2);
|
||||
return HALLO(i, i);
|
||||
}
|
||||
|
||||
|
||||
//!MacroExpansio3ExpansionsBug
|
||||
//%CPP
|
||||
#define HALLO(a, b) a + b
|
||||
int main()
|
||||
{
|
||||
int i = HALLO(45, 2) + HALLO(1, 2) + HALLO(1, 2);
|
||||
return HALLO(i, i);
|
||||
}
|
||||
|
||||
|
||||
//!MacroExpansio4ExpansionsBug
|
||||
//%CPP
|
||||
#define HALLO(a, b) a + b
|
||||
int main()
|
||||
{
|
||||
int i = HALLO(45, 2) + HALLO(1, 2) + HALLO(1, 2) + HALLO(1, 2);
|
||||
return HALLO(i, i);
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,283 @@
|
|||
//!BreakStatementTest
|
||||
//%CPP
|
||||
void foo()
|
||||
{
|
||||
while(true){
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//!CaseDefaultStatementTest
|
||||
//%CPP
|
||||
foo()
|
||||
{
|
||||
switch (1){
|
||||
case 1:
|
||||
return 1;
|
||||
case 2:
|
||||
return 2;
|
||||
default:
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//!CompoundStatementTest
|
||||
//%CPP
|
||||
void foo()
|
||||
{
|
||||
int i = 2;
|
||||
{
|
||||
int a = i;
|
||||
{
|
||||
a++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//!ContinueStatementTest
|
||||
//%CPP
|
||||
void foo()
|
||||
{
|
||||
while(true){
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//!DeclarationStatementTest
|
||||
//%CPP
|
||||
void foo()
|
||||
{
|
||||
int i = 2;
|
||||
int a;
|
||||
}
|
||||
|
||||
|
||||
//!DoStatementTest
|
||||
//%CPP
|
||||
void foo()
|
||||
{
|
||||
do{
|
||||
continue;
|
||||
} while(true);
|
||||
}
|
||||
|
||||
|
||||
//!ExpressionStatementTest
|
||||
//%CPP
|
||||
void foo()
|
||||
{
|
||||
int i;
|
||||
++i;
|
||||
}
|
||||
|
||||
|
||||
//!ForStatementTest
|
||||
//%CPP
|
||||
void foo()
|
||||
{
|
||||
for(int i = 0;i < 1;++i){
|
||||
break;
|
||||
}
|
||||
for(;;){
|
||||
break;
|
||||
}
|
||||
for(;int c = f();){
|
||||
c++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//!C ForStatement
|
||||
//%C
|
||||
void foo()
|
||||
{
|
||||
int i;
|
||||
for(i = 0;i < 1;++i){
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//!Goto&LabelStatementTest
|
||||
//%CPP
|
||||
int f()
|
||||
{
|
||||
badStyle:
|
||||
goto badStyle;
|
||||
}
|
||||
|
||||
|
||||
//!IfStatementTest
|
||||
//%CPP
|
||||
int f()
|
||||
{
|
||||
int i = 0;
|
||||
if(i < 1){
|
||||
++i;
|
||||
}else{
|
||||
--i;
|
||||
}
|
||||
if(int c = f()){
|
||||
c++;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
|
||||
//!IfStatementTest
|
||||
//%CPP
|
||||
int g()
|
||||
{
|
||||
if(10 > 5)
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
//!C IfStatementTest
|
||||
//%C
|
||||
int g()
|
||||
{
|
||||
if(10 > 5)
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
//!NullStatementTest
|
||||
//%CPP
|
||||
void f()
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
//!ReturnStatementTest
|
||||
//%CPP
|
||||
int f()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
//!SwitchStatementTest
|
||||
//%CPP
|
||||
void foo()
|
||||
{
|
||||
switch (1){
|
||||
case 1:
|
||||
return 1;
|
||||
case 2:
|
||||
return 2;
|
||||
default:
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
|
||||
int foo()
|
||||
{
|
||||
switch (int i = f()){
|
||||
case 1:
|
||||
++i;
|
||||
return 1;
|
||||
case 2:
|
||||
return 2;
|
||||
default:
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//!SwitchStatementTest
|
||||
//%C
|
||||
void foo()
|
||||
{
|
||||
switch (1){
|
||||
case 1:
|
||||
return 1;
|
||||
case 2:
|
||||
return 2;
|
||||
default:
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//!WhileStatementTest
|
||||
//%CPP
|
||||
void foo()
|
||||
{
|
||||
while(true){
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void fa()
|
||||
{
|
||||
while(int i = f()){
|
||||
++i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void fb()
|
||||
{
|
||||
while(true);
|
||||
|
||||
}
|
||||
|
||||
//!C WhileStatementTest
|
||||
//%C
|
||||
void foo()
|
||||
{
|
||||
while(true){
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//!TryBlockStatement
|
||||
//%CPP
|
||||
int foo()
|
||||
{
|
||||
try {
|
||||
int i = 1;
|
||||
try {
|
||||
++i;
|
||||
return i;
|
||||
}
|
||||
catch(...){
|
||||
}
|
||||
}
|
||||
catch(...){
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//!MixedStatement
|
||||
//%CPP
|
||||
#define ZWO 2
|
||||
int foo()
|
||||
{
|
||||
int i = 1;
|
||||
if( i == ZWO)
|
||||
{
|
||||
}
|
||||
}
|
||||
//=
|
||||
int foo()
|
||||
{
|
||||
int i = 1;
|
||||
if( i == ZWO)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//!ArrayDeclarationStatementTest
|
||||
//%CPP
|
||||
string *newElements = new string[m_capacity];
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
//![temp.names] examples abschnitt 4/1
|
||||
//%CPP
|
||||
T *p1 = p->template alloc<100>();
|
||||
|
||||
//![temp.names] examples abschnitt 4/2, didn't work cause of Bug# 164482
|
||||
//%CPP
|
||||
template<class T> void f(T *p)
|
||||
{
|
||||
T::template adjust<100>();
|
||||
}
|
||||
|
||||
|
File diff suppressed because it is too large
Load diff
|
@ -31,6 +31,7 @@ import org.eclipse.cdt.core.model.tests.BinaryTests;
|
|||
import org.eclipse.cdt.core.model.tests.ElementDeltaTests;
|
||||
import org.eclipse.cdt.core.model.tests.WorkingCopyTests;
|
||||
import org.eclipse.cdt.core.parser.tests.ParserTestSuite;
|
||||
import org.eclipse.cdt.core.parser.tests.rewrite.RewriteTests;
|
||||
import org.eclipse.cdt.core.tests.templateengine.AllTemplateEngineTests;
|
||||
import org.eclipse.cdt.internal.index.tests.IndexTests;
|
||||
import org.eclipse.cdt.internal.pdom.tests.PDOMTests;
|
||||
|
@ -57,7 +58,7 @@ public class AutomatedIntegrationSuite extends TestSuite {
|
|||
super(name);
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
public static Test suite() throws Exception {
|
||||
final AutomatedIntegrationSuite suite = new AutomatedIntegrationSuite();
|
||||
|
||||
// Add all success tests
|
||||
|
@ -71,6 +72,7 @@ public class AutomatedIntegrationSuite extends TestSuite {
|
|||
suite.addTest(PositionTrackerTests.suite());
|
||||
suite.addTest(StringBuilderTest.suite());
|
||||
suite.addTest(AllLanguageTests.suite());
|
||||
suite.addTest(RewriteTests.suite());
|
||||
|
||||
// Add in PDOM tests
|
||||
suite.addTest(PDOMTests.suite());
|
||||
|
|
|
@ -41,16 +41,19 @@ Export-Package: org.eclipse.cdt.core,
|
|||
org.eclipse.cdt.core.templateengine.process.processes,
|
||||
org.eclipse.cdt.internal.core;x-friends:="org.eclipse.cdt.ui",
|
||||
org.eclipse.cdt.internal.core.browser.util;x-friends:="org.eclipse.cdt.ui",
|
||||
org.eclipse.cdt.internal.core.cdtvariables,
|
||||
org.eclipse.cdt.internal.core.cdtvariables;x-internal:=true,
|
||||
org.eclipse.cdt.internal.core.dom;x-friends:="org.eclipse.cdt.ui,org.eclipse.cdt.refactoring",
|
||||
org.eclipse.cdt.internal.core.dom.parser;x-friends:="org.eclipse.cdt.refactoring",
|
||||
org.eclipse.cdt.internal.core.dom.parser.c;x-friends:="org.eclipse.cdt.refactoring",
|
||||
org.eclipse.cdt.internal.core.dom.parser.cpp;x-friends:="org.eclipse.cdt.ui,org.eclipse.cdt.refactoring",
|
||||
org.eclipse.cdt.internal.core.dom.rewrite;x-friends:="org.eclipse.cdt.core.tests",
|
||||
org.eclipse.cdt.internal.core.envvar,
|
||||
org.eclipse.cdt.internal.core.dom.rewrite.astwriter;x-internal:=true,
|
||||
org.eclipse.cdt.internal.core.dom.rewrite.changegenerator;x-internal:=true,
|
||||
org.eclipse.cdt.internal.core.dom.rewrite.commenthandler;x-internal:=true,
|
||||
org.eclipse.cdt.internal.core.envvar;x-friends:="org.eclipse.cdt.ui",
|
||||
org.eclipse.cdt.internal.core.index;x-friends:="org.eclipse.cdt.ui",
|
||||
org.eclipse.cdt.internal.core.index.provider,
|
||||
org.eclipse.cdt.internal.core.language,
|
||||
org.eclipse.cdt.internal.core.index.provider;x-internal:=true,
|
||||
org.eclipse.cdt.internal.core.language;x-friends:="org.eclipse.cdt.ui",
|
||||
org.eclipse.cdt.internal.core.model;x-friends:="org.eclipse.cdt.ui,org.eclipse.cdt.refactoring",
|
||||
org.eclipse.cdt.internal.core.model.ext;x-friends:="org.eclipse.cdt.ui",
|
||||
org.eclipse.cdt.internal.core.parser;x-internal:=true,
|
||||
|
@ -63,13 +66,13 @@ Export-Package: org.eclipse.cdt.core,
|
|||
org.eclipse.cdt.internal.core.pdom.dom;x-friends:="org.eclipse.cdt.ui",
|
||||
org.eclipse.cdt.internal.core.pdom.dom.c;x-internal:=true,
|
||||
org.eclipse.cdt.internal.core.pdom.dom.cpp;x-internal:=true,
|
||||
org.eclipse.cdt.internal.core.pdom.export,
|
||||
org.eclipse.cdt.internal.core.pdom.export;x-internal:=true,
|
||||
org.eclipse.cdt.internal.core.pdom.indexer;x-friends:="org.eclipse.cdt.ui",
|
||||
org.eclipse.cdt.internal.core.util;x-internal:=true,
|
||||
org.eclipse.cdt.internal.errorparsers;x-internal:=true,
|
||||
org.eclipse.cdt.internal.formatter;x-internal:=true,
|
||||
org.eclipse.cdt.internal.formatter.align;x-internal:=true,
|
||||
org.eclipse.cdt.internal.formatter.scanner,
|
||||
org.eclipse.cdt.internal.formatter.scanner;x-internal:=true,
|
||||
org.eclipse.cdt.utils,
|
||||
org.eclipse.cdt.utils.cdtvariables,
|
||||
org.eclipse.cdt.utils.coff,
|
||||
|
|
|
@ -163,6 +163,7 @@ public abstract class ASTVisitor {
|
|||
return PROCESS_CONTINUE;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public int visit( IASTComment comment){
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2007 Wind River Systems, Inc. and others.
|
||||
* Copyright (c) 2008 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
|
||||
|
@ -11,12 +11,14 @@
|
|||
package org.eclipse.cdt.internal.core.dom.rewrite;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.internal.core.dom.rewrite.changegenerator.ChangeGenerator;
|
||||
import org.eclipse.ltk.core.refactoring.Change;
|
||||
|
||||
public class ASTRewriteAnalyzer {
|
||||
|
||||
public static Change rewriteAST(IASTTranslationUnit root, ASTModificationStore modificationStore) {
|
||||
throw new UnsupportedOperationException("The rewriter is not yet implemented"); //$NON-NLS-1$
|
||||
ChangeGenerator rewriter = new ChangeGenerator(modificationStore);
|
||||
rewriter.generateChange(root);
|
||||
return rewriter.getChange();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
/*******************************************************************************
|
||||
* 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.astwriter;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
|
||||
import org.eclipse.cdt.internal.core.dom.rewrite.changegenerator.ChangeGeneratorWriterVisitor;
|
||||
import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap;
|
||||
|
||||
/**
|
||||
* @author Emanuel Graf
|
||||
*
|
||||
*/
|
||||
public class ASTWriter {
|
||||
|
||||
private ChangeGeneratorWriterVisitor transformationVisitor;
|
||||
private ASTModificationStore modificationStore = new ASTModificationStore();
|
||||
private String givenIndentation = ""; //$NON-NLS-1$
|
||||
|
||||
|
||||
public ASTWriter() {
|
||||
super();
|
||||
}
|
||||
|
||||
public ASTWriter(String givenIndentation) {
|
||||
super();
|
||||
this.givenIndentation = givenIndentation;
|
||||
}
|
||||
|
||||
public String write(IASTNode rootNode) throws ProblemRuntimeException {
|
||||
return write(rootNode, null, new NodeCommentMap());
|
||||
}
|
||||
|
||||
public String write(IASTNode rootNode, String fileScope, NodeCommentMap commentMap) throws ProblemRuntimeException {
|
||||
transformationVisitor = new ChangeGeneratorWriterVisitor(modificationStore, givenIndentation, fileScope, commentMap);
|
||||
rootNode.accept(transformationVisitor);
|
||||
String str = transformationVisitor.toString();
|
||||
transformationVisitor.cleanCache();
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void setModificationStore(ASTModificationStore modificationStore) {
|
||||
this.modificationStore = modificationStore;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,243 @@
|
|||
/*******************************************************************************
|
||||
* 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.astwriter;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTComment;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
|
||||
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.IASTInitializer;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
|
||||
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.gnu.IGNUASTCompoundStatementExpression;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
|
||||
import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap;
|
||||
|
||||
public class ASTWriterVisitor extends CPPASTVisitor {
|
||||
|
||||
protected Scribe scribe = new Scribe();
|
||||
protected NodeCommentMap commentMap;
|
||||
protected ExpressionWriter expWriter;
|
||||
protected DeclSpecWriter declSpecWriter;
|
||||
protected StatementWriter statementWriter;
|
||||
protected DeclaratorWriter declaratorWriter;
|
||||
protected DeclarationWriter declarationWriter;
|
||||
protected InitializerWriter initializerWriter;
|
||||
protected NameWriter nameWriter;
|
||||
protected TemplateParameterWriter tempParameterWriter;
|
||||
protected MacroExpansionHandler macroHandler;
|
||||
{
|
||||
shouldVisitExpressions = true;
|
||||
|
||||
shouldVisitStatements = true;
|
||||
|
||||
shouldVisitNames = true;
|
||||
|
||||
shouldVisitDeclarations = true;
|
||||
|
||||
shouldVisitDeclSpecifiers = true;
|
||||
|
||||
shouldVisitDeclarators = true;
|
||||
|
||||
shouldVisitInitializers = true;
|
||||
|
||||
shouldVisitBaseSpecifiers = true;
|
||||
|
||||
shouldVisitNamespaces = true;
|
||||
|
||||
shouldVisitTemplateParameters = true;
|
||||
|
||||
shouldVisitParameterDeclarations = true;
|
||||
|
||||
shouldVisitTranslationUnit = 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;
|
||||
|
||||
}
|
||||
|
||||
private void init(NodeCommentMap commentMap) {
|
||||
macroHandler = new MacroExpansionHandler(scribe);
|
||||
statementWriter = new StatementWriter(scribe,this, commentMap);
|
||||
declaratorWriter = new DeclaratorWriter(scribe,this, commentMap);
|
||||
declarationWriter = new DeclarationWriter(scribe,this, commentMap);
|
||||
declSpecWriter = new DeclSpecWriter(scribe,this, commentMap);
|
||||
expWriter = new ExpressionWriter(scribe,this, macroHandler, commentMap);
|
||||
initializerWriter = new InitializerWriter (scribe,this, commentMap);
|
||||
// ppStmtWriter = new PreprocessorStatementWriter(scribe, this, commentMap);
|
||||
nameWriter = new NameWriter(scribe,this, commentMap);
|
||||
tempParameterWriter = new TemplateParameterWriter(scribe, this, commentMap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
return scribe.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int leave(IASTTranslationUnit tu) {
|
||||
for(IASTComment comment : commentMap.getFreestandingCommentsForNode(tu)) {
|
||||
scribe.print(comment.getComment());
|
||||
scribe.newLine();
|
||||
}
|
||||
return super.leave(tu);
|
||||
}
|
||||
|
||||
private void writeLeadingComments(ASTNode node) {
|
||||
for(IASTComment comment : commentMap.getLeadingCommentsForNode(node)) {
|
||||
scribe.print(comment.getComment());
|
||||
scribe.newLine();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int visit(IASTName name) {
|
||||
writeLeadingComments((ASTNode) name);
|
||||
if(!macroHandler.checkisMacroExpansionNode(name)) {
|
||||
nameWriter.writeName(name);
|
||||
}
|
||||
return ASTVisitor.PROCESS_SKIP;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public int visit(IASTDeclSpecifier declSpec) {
|
||||
writeLeadingComments((ASTNode) declSpec);
|
||||
declSpecWriter.writeDelcSpec(declSpec);
|
||||
return ASTVisitor.PROCESS_SKIP;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public int visit(IASTExpression expression) {
|
||||
writeLeadingComments((ASTNode) expression);
|
||||
if(!macroHandler.checkisMacroExpansionNode(expression)) {
|
||||
if (expression instanceof IGNUASTCompoundStatementExpression) {
|
||||
IGNUASTCompoundStatementExpression gnuCompStmtExp = (IGNUASTCompoundStatementExpression) expression;
|
||||
gnuCompStmtExp.getCompoundStatement().accept(this);
|
||||
}else {
|
||||
expWriter.writeExpression(expression);
|
||||
}
|
||||
}
|
||||
return ASTVisitor.PROCESS_SKIP;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public int visit(IASTStatement statement) {
|
||||
writeLeadingComments((ASTNode) statement);
|
||||
if(macroHandler.isStatementWithMixedLocation(statement) && !(statement instanceof IASTCompoundStatement)){
|
||||
return statementWriter.writeMixedStatement(statement);
|
||||
}
|
||||
if(macroHandler.checkisMacroExpansionNode(statement)) {
|
||||
return ASTVisitor.PROCESS_SKIP;
|
||||
}
|
||||
return statementWriter.writeStatement(statement, true);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int visit(IASTDeclaration declaration) {
|
||||
writeLeadingComments((ASTNode) declaration);
|
||||
if(!macroHandler.checkisMacroExpansionNode(declaration)) {
|
||||
declarationWriter.writeDeclaration(declaration);
|
||||
}
|
||||
return ASTVisitor.PROCESS_SKIP;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public int visit(IASTDeclarator declarator) {
|
||||
writeLeadingComments((ASTNode) declarator);
|
||||
if(!macroHandler.checkisMacroExpansionNode(declarator)) {
|
||||
declaratorWriter.writeDeclarator(declarator);
|
||||
}
|
||||
return ASTVisitor.PROCESS_SKIP;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public int visit(IASTInitializer initializer) {
|
||||
writeLeadingComments((ASTNode) initializer);
|
||||
if(!macroHandler.checkisMacroExpansionNode(initializer)) {
|
||||
initializerWriter.writeInitializer(initializer);
|
||||
}
|
||||
return ASTVisitor.PROCESS_SKIP;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public int visit(IASTParameterDeclaration parameterDeclaration) {
|
||||
writeLeadingComments((ASTNode) parameterDeclaration);
|
||||
if(!macroHandler.checkisMacroExpansionNode(parameterDeclaration)) {
|
||||
parameterDeclaration.getDeclSpecifier().accept(this);
|
||||
IASTDeclarator declarator = parameterDeclaration.getDeclarator();
|
||||
if(declarator.getName().toString().length() != 0){
|
||||
scribe.printSpaces(1);
|
||||
}
|
||||
declarator.accept(this);
|
||||
}
|
||||
return ASTVisitor.PROCESS_SKIP;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(ICPPASTNamespaceDefinition namespace) {
|
||||
writeLeadingComments((ASTNode) namespace);
|
||||
if(!macroHandler.checkisMacroExpansionNode(namespace)) {
|
||||
declarationWriter.writeDeclaration(namespace);
|
||||
}
|
||||
return ASTVisitor.PROCESS_SKIP;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(ICPPASTTemplateParameter parameter) {
|
||||
writeLeadingComments((ASTNode) parameter);
|
||||
if(!macroHandler.checkisMacroExpansionNode(parameter)) {
|
||||
tempParameterWriter.writeTemplateParameter(parameter);
|
||||
}
|
||||
return ASTVisitor.PROCESS_SKIP;
|
||||
}
|
||||
|
||||
|
||||
public void cleanCache() {
|
||||
scribe.cleanCache();
|
||||
macroHandler.reset();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
/*******************************************************************************
|
||||
* 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.astwriter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
|
||||
|
||||
/**
|
||||
* @author Emanuel Graf
|
||||
*
|
||||
*/
|
||||
public class ContainerNode extends ASTNode {
|
||||
|
||||
private final IASTTranslationUnit tu = null;
|
||||
|
||||
private final ArrayList<IASTNode> nodes = new ArrayList<IASTNode>();
|
||||
|
||||
public ContainerNode(IASTNode... nodes) {
|
||||
for (IASTNode each : nodes) {
|
||||
addNode(each);
|
||||
}
|
||||
}
|
||||
|
||||
public void addNode(IASTNode node) {
|
||||
nodes.add(node);
|
||||
if(node.getParent() == null) {
|
||||
node.setParent(tu);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean accept(ASTVisitor visitor) {
|
||||
boolean ret = true;
|
||||
for (IASTNode node : nodes) {
|
||||
ret = node.accept(visitor);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public IASTTranslationUnit getTu() {
|
||||
return tu;
|
||||
}
|
||||
|
||||
public List<IASTNode> getNodes(){
|
||||
return Collections.unmodifiableList(nodes);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,411 @@
|
|||
/*******************************************************************************
|
||||
* 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.astwriter;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTElaboratedTypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNamedTypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator;
|
||||
import org.eclipse.cdt.core.dom.ast.c.ICASTCompositeTypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.c.ICASTDeclSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.c.ICASTElaboratedTypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.c.ICASTEnumerationSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.c.ICASTSimpleDeclSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.c.ICASTTypedefNameSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTElaboratedTypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamedTypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleDeclSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier;
|
||||
import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap;
|
||||
|
||||
/**
|
||||
* @author Emanuel Graf
|
||||
*
|
||||
*/
|
||||
public class DeclSpecWriter extends NodeWriter {
|
||||
private static final String MUTABLE = "mutable "; //$NON-NLS-1$
|
||||
private static final String _COMPLEX = "_Complex "; //$NON-NLS-1$
|
||||
private static final String LONG_LONG = "long long "; //$NON-NLS-1$
|
||||
private static final String REGISTER = "register "; //$NON-NLS-1$
|
||||
private static final String AUTO = "auto "; //$NON-NLS-1$
|
||||
private static final String TYPEDEF = "typedef "; //$NON-NLS-1$
|
||||
private static final String UNION = "union"; //$NON-NLS-1$
|
||||
private static final String STRUCT = "struct"; //$NON-NLS-1$
|
||||
private static final String CLASS = "class"; //$NON-NLS-1$
|
||||
private static final String FRIEND = "friend "; //$NON-NLS-1$
|
||||
private static final String EXPLICIT = "explicit "; //$NON-NLS-1$
|
||||
private static final String VIRTUAL = "virtual "; //$NON-NLS-1$
|
||||
private static final String UNION_SPACE = "union "; //$NON-NLS-1$
|
||||
private static final String STRUCT_SPACE = "struct "; //$NON-NLS-1$
|
||||
private static final String ENUM = "enum "; //$NON-NLS-1$
|
||||
private static final String _BOOL = "_Bool"; //$NON-NLS-1$
|
||||
|
||||
public DeclSpecWriter(Scribe scribe, CPPASTVisitor visitor, NodeCommentMap commentMap) {
|
||||
super(scribe, visitor, commentMap);
|
||||
|
||||
}
|
||||
|
||||
protected void writeDelcSpec(IASTDeclSpecifier declSpec) {
|
||||
// Write general DelcSpec Keywords
|
||||
writeDeclSpec(declSpec);
|
||||
if (declSpec instanceof ICPPASTDeclSpecifier) {
|
||||
writeCPPDeclSpec((ICPPASTDeclSpecifier) declSpec);
|
||||
}else if (declSpec instanceof ICASTDeclSpecifier) {
|
||||
writeCDeclSpec((ICASTDeclSpecifier) declSpec);
|
||||
}
|
||||
}
|
||||
|
||||
private String getCPPSimpleDecSpecifier(ICPPASTSimpleDeclSpecifier simpDeclSpec) {
|
||||
int type = simpDeclSpec.getType();
|
||||
if(type <= IASTSimpleDeclSpecifier.t_last) {
|
||||
return getASTSimpleDecSpecifier(type);
|
||||
}else {
|
||||
switch (type) {
|
||||
case ICPPASTSimpleDeclSpecifier.t_bool:
|
||||
return CPP_BOOL;
|
||||
case ICPPASTSimpleDeclSpecifier.t_wchar_t:
|
||||
return WCHAR_T;
|
||||
default:
|
||||
System.err.println("Unknow Specifiertype: " + type); //$NON-NLS-1$
|
||||
throw new IllegalArgumentException("Unknow Specifiertype: " + type); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String getCSimpleDecSpecifier(ICASTSimpleDeclSpecifier simpDeclSpec) {
|
||||
int type = simpDeclSpec.getType();
|
||||
if(type <= IASTSimpleDeclSpecifier.t_last) {
|
||||
return getASTSimpleDecSpecifier(type);
|
||||
}else {
|
||||
switch (type) {
|
||||
case ICASTSimpleDeclSpecifier.t_Bool:
|
||||
return _BOOL;
|
||||
default:
|
||||
System.err.println("Unknow Specifiertype: " + type); //$NON-NLS-1$
|
||||
throw new IllegalArgumentException("Unknow Specifiertype: " + type); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private String getASTSimpleDecSpecifier(int type) {
|
||||
|
||||
if(type <= IASTSimpleDeclSpecifier.t_last) {
|
||||
switch (type) {
|
||||
case IASTSimpleDeclSpecifier.t_unspecified:
|
||||
return ""; //$NON-NLS-1$
|
||||
case IASTSimpleDeclSpecifier.t_void:
|
||||
return VOID;
|
||||
case IASTSimpleDeclSpecifier.t_char:
|
||||
return CHAR;
|
||||
case IASTSimpleDeclSpecifier.t_int:
|
||||
return INT;
|
||||
|
||||
case IASTSimpleDeclSpecifier.t_float:
|
||||
return FLOAT;
|
||||
|
||||
case IASTSimpleDeclSpecifier.t_double:
|
||||
return DOUBLE;
|
||||
default:
|
||||
System.err.println("Unknow Specifiertype: " + type); //$NON-NLS-1$
|
||||
throw new IllegalArgumentException("Unknow Specifiertype: " + type); //$NON-NLS-1$
|
||||
|
||||
}
|
||||
}
|
||||
System.err.println("Unknow Specifiertype: " + type); //$NON-NLS-1$
|
||||
throw new IllegalArgumentException("Unknow Specifiertype: " + type); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
private void writeCDeclSpec(ICASTDeclSpecifier cDeclSpec) {
|
||||
if(cDeclSpec.isRestrict()) {
|
||||
scribe.print(RESTRICT);
|
||||
}
|
||||
|
||||
if (cDeclSpec instanceof ICASTCompositeTypeSpecifier) {
|
||||
writeCompositeTypeSpecifier((ICASTCompositeTypeSpecifier) cDeclSpec);
|
||||
}else if (cDeclSpec instanceof ICASTEnumerationSpecifier) {
|
||||
writeEnumSpec((ICASTEnumerationSpecifier) cDeclSpec);
|
||||
}else if (cDeclSpec instanceof ICASTElaboratedTypeSpecifier) {
|
||||
writeElaboratedTypeSec((ICASTElaboratedTypeSpecifier) cDeclSpec);
|
||||
}else if (cDeclSpec instanceof ICASTSimpleDeclSpecifier) {
|
||||
writeCSimpleDeclSpec((ICASTSimpleDeclSpecifier) cDeclSpec);
|
||||
}else if (cDeclSpec instanceof ICASTTypedefNameSpecifier) {
|
||||
writeNamedTypeSpecifier((ICASTTypedefNameSpecifier) cDeclSpec);
|
||||
}
|
||||
}
|
||||
|
||||
private void writeNamedTypeSpecifier(ICPPASTNamedTypeSpecifier namedSpc) {
|
||||
if( namedSpc.isTypename() ){
|
||||
scribe.print(TYPENAME);
|
||||
}
|
||||
namedSpc.getName().accept(visitor);
|
||||
}
|
||||
|
||||
private void writeNamedTypeSpecifier(IASTNamedTypeSpecifier namedSpc) {
|
||||
namedSpc.getName().accept(visitor);
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void writeElaboratedTypeSec(IASTElaboratedTypeSpecifier elabType) {
|
||||
scribe.print(getElabTypeString(elabType.getKind()));
|
||||
elabType.getName().accept(visitor);
|
||||
}
|
||||
|
||||
|
||||
|
||||
private String getElabTypeString(int kind) {
|
||||
switch(kind) {
|
||||
case IASTElaboratedTypeSpecifier.k_enum:
|
||||
return ENUM;
|
||||
case IASTElaboratedTypeSpecifier.k_struct:
|
||||
return STRUCT_SPACE;
|
||||
case IASTElaboratedTypeSpecifier.k_union:
|
||||
return UNION_SPACE;
|
||||
case ICPPASTElaboratedTypeSpecifier.k_class:
|
||||
return CLASS_SPACE;
|
||||
|
||||
default:
|
||||
System.err.println("Unknown ElaboratedType: " + kind); //$NON-NLS-1$
|
||||
throw new IllegalArgumentException("Unknown ElaboratedType: " + kind); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void writeCPPDeclSpec(ICPPASTDeclSpecifier cppDelcSpec) {
|
||||
if (cppDelcSpec.isVirtual()) {
|
||||
scribe.print(VIRTUAL);
|
||||
}
|
||||
if(cppDelcSpec.isExplicit()) {
|
||||
scribe.print(EXPLICIT);
|
||||
}
|
||||
if(cppDelcSpec.isFriend()) {
|
||||
scribe.print(FRIEND);
|
||||
}
|
||||
if(cppDelcSpec.getStorageClass() == ICPPASTDeclSpecifier.sc_mutable) {
|
||||
scribe.print(MUTABLE);
|
||||
}
|
||||
|
||||
if (cppDelcSpec instanceof ICPPASTCompositeTypeSpecifier) {
|
||||
writeCompositeTypeSpecifier((ICPPASTCompositeTypeSpecifier) cppDelcSpec);
|
||||
}else if (cppDelcSpec instanceof IASTEnumerationSpecifier) {
|
||||
writeEnumSpec((IASTEnumerationSpecifier) cppDelcSpec);
|
||||
}else if (cppDelcSpec instanceof ICPPASTElaboratedTypeSpecifier) {
|
||||
writeElaboratedTypeSec((ICPPASTElaboratedTypeSpecifier) cppDelcSpec);
|
||||
}else if (cppDelcSpec instanceof ICPPASTSimpleDeclSpecifier) {
|
||||
writeCPPSimpleDeclSpec((ICPPASTSimpleDeclSpecifier) cppDelcSpec);
|
||||
}else if (cppDelcSpec instanceof ICPPASTNamedTypeSpecifier) {
|
||||
writeNamedTypeSpecifier((ICPPASTNamedTypeSpecifier) cppDelcSpec);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void writeEnumSpec(IASTEnumerationSpecifier enumSpec) {
|
||||
scribe.print(ENUM);
|
||||
enumSpec.getName().accept(visitor);
|
||||
scribe.print('{');
|
||||
scribe.printSpace();
|
||||
IASTEnumerator[] enums = enumSpec.getEnumerators();
|
||||
for(int i = 0; i< enums.length;++i) {
|
||||
writeEnumerator(enums[i]);
|
||||
if(i+1< enums.length) {
|
||||
scribe.print(NodeWriter.COMMA_SPACE);
|
||||
}
|
||||
}
|
||||
scribe.print('}');
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void writeEnumerator(IASTEnumerator enumerator) {
|
||||
enumerator.getName().accept(visitor);
|
||||
|
||||
IASTExpression value = enumerator.getValue();
|
||||
if(value != null) {
|
||||
scribe.print(EQUALS);
|
||||
value.accept(visitor);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void writeCompositeTypeSpecifier(IASTCompositeTypeSpecifier compDeclSpec) {
|
||||
boolean hasTrailingComments = hasTrailingComments(compDeclSpec.getName());
|
||||
scribe.printStringSpace(getCPPCompositeTypeString(compDeclSpec.getKey()));
|
||||
compDeclSpec.getName().accept(visitor);
|
||||
if (compDeclSpec instanceof ICPPASTCompositeTypeSpecifier) {
|
||||
ICPPASTCompositeTypeSpecifier cppComp = (ICPPASTCompositeTypeSpecifier) compDeclSpec;
|
||||
ICPPASTBaseSpecifier[] baseSpecifiers = cppComp.getBaseSpecifiers();
|
||||
if (baseSpecifiers.length > 0) {
|
||||
scribe.print(SPACE_COLON_SPACE);
|
||||
for(int i = 0; i < baseSpecifiers.length;++i) {
|
||||
writeBaseSpecifiers(baseSpecifiers[i]);
|
||||
if(i+1 < baseSpecifiers.length) {
|
||||
scribe.print(COMMA_SPACE);
|
||||
}
|
||||
}
|
||||
hasTrailingComments = hasTrailingComments(baseSpecifiers[baseSpecifiers.length-1].getName());
|
||||
}
|
||||
}
|
||||
if(!hasTrailingComments){
|
||||
scribe.newLine();
|
||||
}
|
||||
scribe.print('{');
|
||||
scribe.newLine();
|
||||
scribe.incrementIndentationLevel();
|
||||
IASTDeclaration[] decls = getMembers(compDeclSpec);
|
||||
|
||||
if(decls.length > 0) {
|
||||
for (IASTDeclaration declaration : decls) {
|
||||
declaration.accept(visitor);
|
||||
}
|
||||
}
|
||||
|
||||
if(hasFreestandingComments(compDeclSpec)) {
|
||||
writeFreeStandingComments(compDeclSpec);
|
||||
}
|
||||
scribe.decrementIndentationLevel();
|
||||
scribe.print('}');
|
||||
|
||||
if(hasTrailingComments(compDeclSpec)) {
|
||||
writeTrailingComments(compDeclSpec);
|
||||
}
|
||||
}
|
||||
|
||||
protected IASTDeclaration[] getMembers(IASTCompositeTypeSpecifier compDeclSpec) {
|
||||
return compDeclSpec.getMembers();
|
||||
}
|
||||
|
||||
private void writeBaseSpecifiers(ICPPASTBaseSpecifier specifier) {
|
||||
switch(specifier.getVisibility()) {
|
||||
case ICPPASTBaseSpecifier.v_public:
|
||||
scribe.printStringSpace(PUBLIC);
|
||||
break;
|
||||
case ICPPASTBaseSpecifier.v_protected:
|
||||
scribe.printStringSpace(PROTECTED);
|
||||
break;
|
||||
case ICPPASTBaseSpecifier.v_private:
|
||||
scribe.printStringSpace(PRIVATE);
|
||||
break;
|
||||
}
|
||||
specifier.getName().accept(visitor);
|
||||
}
|
||||
|
||||
|
||||
|
||||
private String getCPPCompositeTypeString(int key) {
|
||||
if(key <= IASTCompositeTypeSpecifier.k_last) {
|
||||
return getCompositeTypeString(key);
|
||||
}
|
||||
switch (key) {
|
||||
case ICPPASTCompositeTypeSpecifier.k_class:
|
||||
return CLASS;
|
||||
default:
|
||||
System.err.println("Unknow Specifiertype: " + key); //$NON-NLS-1$
|
||||
throw new IllegalArgumentException("Unknow Specifiertype: " + key); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private String getCompositeTypeString(int key) {
|
||||
switch (key) {
|
||||
case IASTCompositeTypeSpecifier.k_struct:
|
||||
return STRUCT;
|
||||
case IASTCompositeTypeSpecifier.k_union:
|
||||
return UNION;
|
||||
default:
|
||||
System.err.println("Unknow Specifiertype: " + key); //$NON-NLS-1$
|
||||
throw new IllegalArgumentException("Unknow Specifiertype: " + key); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void writeDeclSpec(IASTDeclSpecifier declSpec) {
|
||||
if(declSpec.isInline()) {
|
||||
scribe.print(INLINE);
|
||||
}
|
||||
switch(declSpec.getStorageClass()) {
|
||||
case IASTDeclSpecifier.sc_typedef:
|
||||
scribe.print(TYPEDEF);
|
||||
break;
|
||||
case IASTDeclSpecifier.sc_extern:
|
||||
scribe.print(EXTERN);
|
||||
break;
|
||||
case IASTDeclSpecifier.sc_static:
|
||||
scribe.print(STATIC);
|
||||
break;
|
||||
case IASTDeclSpecifier.sc_auto:
|
||||
scribe.print(AUTO);
|
||||
break;
|
||||
case IASTDeclSpecifier.sc_register:
|
||||
scribe.print(REGISTER);
|
||||
break;
|
||||
}
|
||||
if (declSpec.isConst()) {
|
||||
scribe.printStringSpace(CONST);
|
||||
}
|
||||
if (declSpec.isVolatile()) {
|
||||
scribe.printStringSpace(VOLATILE);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void writeCPPSimpleDeclSpec(ICPPASTSimpleDeclSpecifier simpDeclSpec) {
|
||||
printQualifiers(simpDeclSpec);
|
||||
scribe.print(getCPPSimpleDecSpecifier(simpDeclSpec));
|
||||
}
|
||||
|
||||
private void printQualifiers(IASTSimpleDeclSpecifier simpDeclSpec) {
|
||||
if(simpDeclSpec.isSigned()) {
|
||||
scribe.printStringSpace(SIGNED);
|
||||
}else if(simpDeclSpec.isUnsigned()){
|
||||
scribe.printStringSpace(UNSIGNED);
|
||||
}
|
||||
|
||||
if(simpDeclSpec.isShort()) {
|
||||
scribe.printStringSpace(SHORT);
|
||||
}else if(simpDeclSpec.isLong()) {
|
||||
scribe.printStringSpace(LONG);
|
||||
}
|
||||
if (simpDeclSpec instanceof ICASTSimpleDeclSpecifier) {
|
||||
ICASTSimpleDeclSpecifier cSimpDeclSpec = (ICASTSimpleDeclSpecifier) simpDeclSpec;
|
||||
if (cSimpDeclSpec.isLongLong()) {
|
||||
scribe.print(LONG_LONG);
|
||||
}
|
||||
if (cSimpDeclSpec.isComplex()) {
|
||||
scribe.print(_COMPLEX);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void writeCSimpleDeclSpec(ICASTSimpleDeclSpecifier simpDeclSpec) {
|
||||
printQualifiers(simpDeclSpec);
|
||||
scribe.print(getCSimpleDecSpecifier(simpDeclSpec));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,309 @@
|
|||
/*******************************************************************************
|
||||
* 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.astwriter;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTASMDeclaration;
|
||||
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.IASTFunctionDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTProblemDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCatchHandler;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTExplicitTemplateInstantiation;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionTryBlockDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLinkageSpecification;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceAlias;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateParameter;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateSpecialization;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDirective;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTVisiblityLabel;
|
||||
import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTExplicitTemplateInstantiation;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguousDeclaration;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.IASTDeclarationAmbiguity;
|
||||
import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap;
|
||||
|
||||
/**
|
||||
* @author Emanuel Graf
|
||||
*
|
||||
*/
|
||||
public class DeclarationWriter extends NodeWriter{
|
||||
|
||||
private static final String ASM_END = ")"; //$NON-NLS-1$
|
||||
private static final String ASM_START = "asm("; //$NON-NLS-1$
|
||||
private static final String TEMPLATE_DECLARATION = "template<"; //$NON-NLS-1$
|
||||
private static final String EXPORT = "export "; //$NON-NLS-1$
|
||||
private static final String TEMPLATE_SPECIALIZATION = "template <> "; //$NON-NLS-1$
|
||||
private static final String NAMESPACE = "namespace "; //$NON-NLS-1$
|
||||
private static final String USING = "using "; //$NON-NLS-1$
|
||||
private boolean printSemicolon;
|
||||
|
||||
public DeclarationWriter(Scribe scribe, CPPASTVisitor visitor, NodeCommentMap commentMap) {
|
||||
super(scribe, visitor, commentMap);
|
||||
}
|
||||
|
||||
protected void writeDeclaration(IASTDeclaration declaration) throws ProblemRuntimeException{
|
||||
writeDeclaration(declaration, true);
|
||||
}
|
||||
|
||||
protected void writeDeclaration(IASTDeclaration declaration, boolean writeSemicolon) {
|
||||
boolean addNewLine = true;
|
||||
printSemicolon = writeSemicolon;
|
||||
if (declaration instanceof IASTAmbiguousDeclaration) {
|
||||
//Not implemented
|
||||
} else if (declaration instanceof IASTASMDeclaration) {
|
||||
writeASMDeclatation((IASTASMDeclaration) declaration);
|
||||
} else if (declaration instanceof IASTDeclarationAmbiguity) {
|
||||
//There is no class which implements IASTDeclarationAmbiguity
|
||||
} else if (declaration instanceof IASTFunctionDefinition) {
|
||||
writeFunctionDefinition((IASTFunctionDefinition) declaration);
|
||||
} else if (declaration instanceof IASTProblemDeclaration) {
|
||||
throw new ProblemRuntimeException((IASTProblemDeclaration) declaration);
|
||||
} else if (declaration instanceof IASTSimpleDeclaration) {
|
||||
writeSimpleDeclaration((IASTSimpleDeclaration) declaration);
|
||||
} else if (declaration instanceof ICPPASTExplicitTemplateInstantiation) {
|
||||
writeExplicitTemplateInstantiation((ICPPASTExplicitTemplateInstantiation) declaration);
|
||||
addNewLine = false;
|
||||
} else if (declaration instanceof ICPPASTLinkageSpecification) {
|
||||
writeLinkageSpecification((ICPPASTLinkageSpecification) declaration);
|
||||
} else if (declaration instanceof ICPPASTNamespaceAlias) {
|
||||
writeNamespaceAlias((ICPPASTNamespaceAlias) declaration);
|
||||
} else if (declaration instanceof ICPPASTTemplateDeclaration) {
|
||||
writeTemplateDeclaration((ICPPASTTemplateDeclaration) declaration);
|
||||
addNewLine = false;
|
||||
} else if (declaration instanceof ICPPASTTemplateSpecialization) {
|
||||
writeTemplateSpecialization((ICPPASTTemplateSpecialization) declaration);
|
||||
addNewLine = false;
|
||||
} else if (declaration instanceof ICPPASTUsingDeclaration) {
|
||||
writeUsingDeclaration((ICPPASTUsingDeclaration) declaration);
|
||||
} else if (declaration instanceof ICPPASTUsingDirective) {
|
||||
writeUsingDirective((ICPPASTUsingDirective) declaration);
|
||||
} else if (declaration instanceof ICPPASTVisiblityLabel) {
|
||||
writeVisibilityLabel((ICPPASTVisiblityLabel) declaration);
|
||||
}
|
||||
|
||||
if(hasTrailingComments(declaration)) {
|
||||
writeTrailingComments(declaration, addNewLine);
|
||||
}else if(addNewLine){
|
||||
scribe.newLine();
|
||||
}
|
||||
if(hasFreestandingComments(declaration)){
|
||||
writeFreeStandingComments(declaration);
|
||||
}
|
||||
|
||||
if (declaration instanceof ICPPASTUsingDirective) {
|
||||
scribe.newLine();
|
||||
}
|
||||
}
|
||||
|
||||
private void writeVisibilityLabel(ICPPASTVisiblityLabel visiblityLabel) {
|
||||
scribe.decrementIndentationLevel();
|
||||
switch (visiblityLabel.getVisibility()) {
|
||||
case ICPPASTVisiblityLabel.v_private:
|
||||
scribe.print(PRIVATE);
|
||||
scribe.print(':');
|
||||
break;
|
||||
case ICPPASTVisiblityLabel.v_protected:
|
||||
scribe.print(PROTECTED);
|
||||
scribe.print(':');
|
||||
break;
|
||||
case ICPPASTVisiblityLabel.v_public:
|
||||
scribe.print(PUBLIC);
|
||||
scribe.print(':');
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
scribe.incrementIndentationLevel();
|
||||
}
|
||||
|
||||
private void writeUsingDirective(ICPPASTUsingDirective usingDirective) {
|
||||
scribe.print(USING + NAMESPACE);
|
||||
usingDirective.getQualifiedName().accept(visitor);
|
||||
scribe.printSemicolon();
|
||||
}
|
||||
|
||||
private void writeUsingDeclaration(ICPPASTUsingDeclaration usingDeclaration) {
|
||||
scribe.print(USING);
|
||||
if(usingDeclaration.isTypename()){
|
||||
scribe.print(TYPENAME);
|
||||
}
|
||||
usingDeclaration.getName().accept(visitor);
|
||||
scribe.printSemicolon();
|
||||
}
|
||||
|
||||
private void writeTemplateSpecialization(ICPPASTTemplateSpecialization templateSpecialization) {
|
||||
scribe.print(TEMPLATE_SPECIALIZATION);
|
||||
templateSpecialization.getDeclaration().accept(visitor);
|
||||
}
|
||||
|
||||
private void writeTemplateDeclaration(ICPPASTTemplateDeclaration templateDeclaration) {
|
||||
if(templateDeclaration.isExported()){
|
||||
scribe.print(EXPORT);
|
||||
}
|
||||
scribe.print(TEMPLATE_DECLARATION);
|
||||
ICPPASTTemplateParameter[] paraDecls = templateDeclaration.getTemplateParameters();
|
||||
for(int i = 0; i < paraDecls.length; ++i) {
|
||||
paraDecls[i].accept(visitor);
|
||||
if(i + 1 < paraDecls.length) {
|
||||
scribe.print(',');
|
||||
scribe.printSpaces(1);
|
||||
}
|
||||
}
|
||||
scribe.print('>');
|
||||
scribe.printSpace();
|
||||
templateDeclaration.getDeclaration().accept(visitor);
|
||||
}
|
||||
|
||||
protected void writeDeclaration(ICPPASTNamespaceDefinition declaration){
|
||||
printSemicolon = true;
|
||||
writeNamespaceDefinition(declaration);
|
||||
}
|
||||
|
||||
private void writeNamespaceDefinition(ICPPASTNamespaceDefinition namespaceDefinition) {
|
||||
scribe.print(NAMESPACE);
|
||||
namespaceDefinition.getName().accept(visitor);
|
||||
if(!hasTrailingComments(namespaceDefinition.getName())) {
|
||||
scribe.newLine();
|
||||
}
|
||||
scribe.printLBrace();
|
||||
scribe.newLine();
|
||||
for (IASTDeclaration declarations : namespaceDefinition.getDeclarations()) {
|
||||
declarations.accept(visitor);
|
||||
}
|
||||
if(hasFreestandingComments(namespaceDefinition)) {
|
||||
writeFreeStandingComments(namespaceDefinition);
|
||||
}
|
||||
scribe.printRBrace();
|
||||
|
||||
if(hasTrailingComments(namespaceDefinition)) {
|
||||
writeTrailingComments(namespaceDefinition);
|
||||
}else{
|
||||
scribe.newLine();
|
||||
}
|
||||
}
|
||||
|
||||
private void writeNamespaceAlias(ICPPASTNamespaceAlias namespaceAliasDefinition) {
|
||||
scribe.print(NAMESPACE);
|
||||
namespaceAliasDefinition.getAlias().accept(visitor);
|
||||
scribe.print(EQUALS);
|
||||
namespaceAliasDefinition.getMappingName().accept(visitor);
|
||||
printSemicolon();
|
||||
}
|
||||
|
||||
private void writeLinkageSpecification(ICPPASTLinkageSpecification linkageSpecification) {
|
||||
scribe.print( EXTERN);
|
||||
scribe.print(linkageSpecification.getLiteral());
|
||||
scribe.printSpaces(1);
|
||||
|
||||
IASTDeclaration[] declarations = linkageSpecification.getDeclarations();
|
||||
if(declarations.length > 1){
|
||||
scribe.printLBrace();
|
||||
scribe.decrementIndentationLevel();
|
||||
scribe.newLine();
|
||||
for (IASTDeclaration declaration : declarations) {
|
||||
declaration.accept(visitor);
|
||||
}
|
||||
scribe.printRBrace();
|
||||
scribe.incrementIndentationLevel();
|
||||
} else if(declarations.length > 0) {
|
||||
visitNodeIfNotNull(declarations[0]);
|
||||
}
|
||||
}
|
||||
|
||||
private void writeExplicitTemplateInstantiation(ICPPASTExplicitTemplateInstantiation explicitTemplateInstantiation) {
|
||||
if (explicitTemplateInstantiation instanceof IGPPASTExplicitTemplateInstantiation) {
|
||||
IGPPASTExplicitTemplateInstantiation gppExplicitTemplateInstantiation = (IGPPASTExplicitTemplateInstantiation) explicitTemplateInstantiation;
|
||||
switch(gppExplicitTemplateInstantiation.getModifier()){
|
||||
case IGPPASTExplicitTemplateInstantiation.ti_extern:
|
||||
scribe.print(EXTERN);
|
||||
break;
|
||||
case IGPPASTExplicitTemplateInstantiation.ti_inline:
|
||||
scribe.print(INLINE);
|
||||
break;
|
||||
case IGPPASTExplicitTemplateInstantiation.ti_static:
|
||||
scribe.print(STATIC);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
scribe.print(TEMPLATE);
|
||||
explicitTemplateInstantiation.getDeclaration().accept(visitor);
|
||||
}
|
||||
|
||||
private void writeASMDeclatation(IASTASMDeclaration asmDeclaration) {
|
||||
scribe.print(ASM_START);
|
||||
scribe.print(asmDeclaration.getAssembly());
|
||||
scribe.print(ASM_END);
|
||||
printSemicolon();
|
||||
}
|
||||
|
||||
private void printSemicolon() {
|
||||
if(printSemicolon) {
|
||||
scribe.printSemicolon();
|
||||
}
|
||||
}
|
||||
|
||||
private void writeFunctionDefinition(IASTFunctionDefinition funcDef) {
|
||||
IASTDeclSpecifier declSpecifier = funcDef.getDeclSpecifier();
|
||||
declSpecifier.accept(visitor);
|
||||
if (declSpecifier instanceof IASTSimpleDeclSpecifier) {
|
||||
IASTSimpleDeclSpecifier simDeclSpec = (IASTSimpleDeclSpecifier) declSpecifier;
|
||||
if(simDeclSpec.getType() != IASTSimpleDeclSpecifier.t_unspecified) {
|
||||
scribe.printSpace();
|
||||
}
|
||||
}else {
|
||||
scribe.printSpace();
|
||||
}
|
||||
IASTFunctionDeclarator declarator = funcDef.getDeclarator();
|
||||
declarator.accept(visitor);
|
||||
scribe.newLine();
|
||||
funcDef.getBody().accept(visitor);
|
||||
if (declarator instanceof ICPPASTFunctionTryBlockDeclarator) {
|
||||
ICPPASTFunctionTryBlockDeclarator tryDeclSpec = (ICPPASTFunctionTryBlockDeclarator) declarator;
|
||||
ICPPASTCatchHandler[] catches = tryDeclSpec.getCatchHandlers();
|
||||
for (ICPPASTCatchHandler handler : catches) {
|
||||
handler.accept(visitor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void writeSimpleDeclaration(IASTSimpleDeclaration simpDec) {
|
||||
IASTDeclSpecifier declSpecifier = simpDec.getDeclSpecifier();
|
||||
IASTDeclarator[] decls = simpDec.getDeclarators();
|
||||
|
||||
declSpecifier.accept(visitor);
|
||||
boolean noSpace = false;
|
||||
if (declSpecifier instanceof IASTSimpleDeclSpecifier) {
|
||||
IASTSimpleDeclSpecifier simpleDeclSpecifier = (IASTSimpleDeclSpecifier) declSpecifier;
|
||||
if(simpleDeclSpecifier.getType() == IASTSimpleDeclSpecifier.t_unspecified) {
|
||||
noSpace = true;
|
||||
}
|
||||
}
|
||||
|
||||
if(decls.length > 0) {
|
||||
if(!noSpace) {
|
||||
scribe.printSpace();
|
||||
}
|
||||
writeNodeList(decls);
|
||||
}
|
||||
|
||||
printSemicolon();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,298 @@
|
|||
/*******************************************************************************
|
||||
* 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.astwriter;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTArrayModifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFieldDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTInitializer;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTPointer;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTPointerOperator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTStandardFunctionDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTypeId;
|
||||
import org.eclipse.cdt.core.dom.ast.c.ICASTPointer;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorInitializer;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionTryBlockDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTPointerToMember;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTReferenceOperator;
|
||||
import org.eclipse.cdt.core.dom.ast.gnu.c.ICASTKnRFunctionDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTPointer;
|
||||
import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap;
|
||||
|
||||
/**
|
||||
* @author Emanuel Graf
|
||||
*
|
||||
*/
|
||||
public class DeclaratorWriter extends NodeWriter {
|
||||
|
||||
private static final String AMPERSAND_SPACE = "& "; //$NON-NLS-1$
|
||||
private static final String STAR_SPACE = "* "; //$NON-NLS-1$
|
||||
private static final String TRY = "try"; //$NON-NLS-1$
|
||||
private static final String PURE_VIRTUAL = " =0"; //$NON-NLS-1$
|
||||
|
||||
public DeclaratorWriter(Scribe scribe, CPPASTVisitor visitor, NodeCommentMap commentMap) {
|
||||
super(scribe, visitor, commentMap);
|
||||
}
|
||||
|
||||
protected void writeDeclarator(IASTDeclarator declarator) {
|
||||
if (declarator instanceof IASTStandardFunctionDeclarator) {
|
||||
writeFunctionDeclarator((IASTStandardFunctionDeclarator) declarator);
|
||||
}else if (declarator instanceof IASTArrayDeclarator) {
|
||||
writeArrayDeclarator((IASTArrayDeclarator) declarator);
|
||||
}else if (declarator instanceof IASTFieldDeclarator) {
|
||||
writeFieldDeclarator((IASTFieldDeclarator) declarator);
|
||||
}else if (declarator instanceof ICASTKnRFunctionDeclarator) {
|
||||
writeCKnRFunctionDeclarator((ICASTKnRFunctionDeclarator) declarator);
|
||||
}else{
|
||||
writeDefaultDeclarator(declarator);
|
||||
}
|
||||
|
||||
if(hasTrailingComments(declarator)) {
|
||||
writeTrailingComments(declarator, false);
|
||||
}
|
||||
}
|
||||
|
||||
protected void writeDefaultDeclarator(IASTDeclarator declarator) {
|
||||
IASTPointerOperator[] pointOps = declarator.getPointerOperators();
|
||||
writePointerOperators(declarator, pointOps);
|
||||
IASTName name = declarator.getName();
|
||||
name.accept(visitor);
|
||||
IASTInitializer init = getInitializer(declarator);
|
||||
if(init!= null) {
|
||||
if (! (init instanceof ICPPASTConstructorInitializer)) {
|
||||
scribe.print(EQUALS);
|
||||
}
|
||||
init.accept(visitor);
|
||||
}
|
||||
}
|
||||
|
||||
protected void writePointerOperators(IASTDeclarator declarator, IASTPointerOperator[] pointOps) {
|
||||
for (IASTPointerOperator operator : pointOps) {
|
||||
writePointerOp(operator);
|
||||
}
|
||||
}
|
||||
|
||||
private void writeFunctionDeclarator(IASTStandardFunctionDeclarator funcDec) {
|
||||
IASTPointerOperator[] pointOps = funcDec.getPointerOperators();
|
||||
writePointerOperators(funcDec, pointOps);
|
||||
funcDec.getName().accept(visitor);
|
||||
writeNestedDeclarator(funcDec);
|
||||
writeParameters(funcDec);
|
||||
writeInitializer(funcDec);
|
||||
if (funcDec instanceof ICPPASTFunctionDeclarator) {
|
||||
writeCppFunctionDeclarator((ICPPASTFunctionDeclarator) funcDec);
|
||||
}
|
||||
}
|
||||
|
||||
private void writeInitializer(IASTStandardFunctionDeclarator funcDec) {
|
||||
IASTInitializer init = getInitializer(funcDec);
|
||||
if(init != null) {
|
||||
scribe.print(EQUALS);
|
||||
init.accept(visitor);
|
||||
}
|
||||
}
|
||||
|
||||
private void writeParameters(IASTStandardFunctionDeclarator funcDec) {
|
||||
IASTParameterDeclaration[] paraDecls = funcDec.getParameters();
|
||||
scribe.print('(');
|
||||
writeParameterDeclarations(funcDec, paraDecls);
|
||||
scribe.print(')');
|
||||
}
|
||||
|
||||
private void writeNestedDeclarator(IASTDeclarator funcDec) {
|
||||
IASTDeclarator nestedDeclarator = funcDec.getNestedDeclarator();
|
||||
if(nestedDeclarator != null) {
|
||||
scribe.print('(');
|
||||
nestedDeclarator.accept(visitor);
|
||||
scribe.print(')');
|
||||
}
|
||||
}
|
||||
|
||||
private void writeCppFunctionDeclarator(ICPPASTFunctionDeclarator funcDec) {
|
||||
if (funcDec.isConst()) {
|
||||
scribe.printSpace();
|
||||
scribe.print(CONST);
|
||||
}
|
||||
if (funcDec.isVolatile()) {
|
||||
scribe.printSpace();
|
||||
scribe.print(VOLATILE);
|
||||
}
|
||||
if(funcDec.isPureVirtual()) {
|
||||
scribe.print(PURE_VIRTUAL);
|
||||
}
|
||||
writeExceptionSpecification(funcDec, funcDec.getExceptionSpecification());
|
||||
if (funcDec instanceof ICPPASTFunctionTryBlockDeclarator) {
|
||||
scribe.newLine();
|
||||
scribe.print(TRY);
|
||||
}
|
||||
writeCtorChainInitializer(funcDec, funcDec.getConstructorChain());
|
||||
}
|
||||
|
||||
protected void writeCtorChainInitializer(
|
||||
ICPPASTFunctionDeclarator funcDec, ICPPASTConstructorChainInitializer[] ctorInitChain) {
|
||||
if(ctorInitChain.length != 0) {
|
||||
scribe.newLine();
|
||||
scribe.print(':');
|
||||
}
|
||||
for(int i = 0; i < ctorInitChain.length; ++i) {
|
||||
ICPPASTConstructorChainInitializer initializer = ctorInitChain[i];
|
||||
initializer.getMemberInitializerId().accept(visitor);
|
||||
scribe.print('(');
|
||||
initializer.getInitializerValue().accept(visitor);
|
||||
scribe.print(')');
|
||||
if(i+1 < ctorInitChain.length) {
|
||||
scribe.print(COMMA_SPACE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void writeExceptionSpecification(ICPPASTFunctionDeclarator funcDec, IASTTypeId[] exceptions) {
|
||||
if(exceptions.length != 0) {
|
||||
scribe.printSpace();
|
||||
scribe.print(THROW);
|
||||
scribe.print('(');
|
||||
writeNodeList(exceptions);
|
||||
scribe.print(')');
|
||||
}
|
||||
}
|
||||
|
||||
protected void writeParameterDeclarations(IASTStandardFunctionDeclarator funcDec, IASTParameterDeclaration[] paraDecls) {
|
||||
writeNodeList(paraDecls);
|
||||
if(funcDec.takesVarArgs()){
|
||||
if(paraDecls.length > 0){
|
||||
scribe.print(COMMA_SPACE);
|
||||
}
|
||||
scribe.print(VAR_ARGS);
|
||||
}
|
||||
}
|
||||
|
||||
private void writePointer(IASTPointer operator) {
|
||||
if (operator instanceof ICPPASTPointerToMember) {
|
||||
ICPPASTPointerToMember pointerToMemberOp = (ICPPASTPointerToMember) operator;
|
||||
if(pointerToMemberOp.getName() != null){
|
||||
pointerToMemberOp.getName().accept(visitor);
|
||||
scribe.print(STAR_SPACE);
|
||||
}
|
||||
} else {
|
||||
scribe.print('*');
|
||||
}
|
||||
|
||||
|
||||
if (operator.isConst()) {
|
||||
scribe.printStringSpace(CONST);
|
||||
|
||||
}
|
||||
if (operator.isVolatile()) {
|
||||
scribe.printStringSpace(VOLATILE);
|
||||
}
|
||||
if (operator instanceof ICASTPointer) {
|
||||
ICASTPointer cPoint = (ICASTPointer) operator;
|
||||
if(cPoint.isRestrict()) {
|
||||
scribe.print(RESTRICT);
|
||||
}
|
||||
}
|
||||
if (operator instanceof IGPPASTPointer) {
|
||||
IGPPASTPointer gppPoint = (IGPPASTPointer) operator;
|
||||
if(gppPoint.isRestrict()) {
|
||||
scribe.print(RESTRICT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void writePointerOp(IASTPointerOperator operator) {
|
||||
if (operator instanceof IASTPointer) {
|
||||
IASTPointer pointOp = (IASTPointer) operator;
|
||||
writePointer(pointOp);
|
||||
}else if (operator instanceof ICPPASTReferenceOperator) {
|
||||
scribe.print(AMPERSAND_SPACE);
|
||||
}
|
||||
}
|
||||
|
||||
private void writeArrayDeclarator(IASTArrayDeclarator arrDecl) {
|
||||
IASTPointerOperator[] pointOps = arrDecl.getPointerOperators();
|
||||
writePointerOperators(arrDecl, pointOps);
|
||||
IASTName name = arrDecl.getName();
|
||||
name.accept(visitor);
|
||||
|
||||
writeNestedDeclarator(arrDecl);
|
||||
|
||||
IASTArrayModifier[] arrMods = arrDecl.getArrayModifiers();
|
||||
writeArrayModifiers(arrDecl, arrMods);
|
||||
IASTInitializer initializer = getInitializer(arrDecl);
|
||||
if(initializer != null) {
|
||||
scribe.print(EQUALS);
|
||||
initializer.accept(visitor);
|
||||
}
|
||||
}
|
||||
|
||||
protected IASTInitializer getInitializer(IASTDeclarator decl) {
|
||||
return decl.getInitializer();
|
||||
}
|
||||
|
||||
protected void writeArrayModifiers(IASTArrayDeclarator arrDecl, IASTArrayModifier[] arrMods) {
|
||||
for (IASTArrayModifier modifier : arrMods) {
|
||||
scribe.print('[');
|
||||
modifier.accept(visitor);
|
||||
scribe.print(']');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void writeFieldDeclarator(IASTFieldDeclarator fieldDecl) {
|
||||
IASTPointerOperator[] pointOps = fieldDecl.getPointerOperators();
|
||||
writePointerOperators(fieldDecl, pointOps);
|
||||
fieldDecl.getName().accept(visitor);
|
||||
scribe.printSpace();
|
||||
scribe.print(':');
|
||||
scribe.printSpace();
|
||||
fieldDecl.getBitFieldSize().accept(visitor);
|
||||
IASTInitializer initializer = getInitializer(fieldDecl);
|
||||
if(initializer != null) {
|
||||
scribe.print(EQUALS);
|
||||
initializer.accept(visitor);
|
||||
}
|
||||
}
|
||||
|
||||
private void writeCKnRFunctionDeclarator(ICASTKnRFunctionDeclarator knrFunct) {
|
||||
knrFunct.getName().accept(visitor);
|
||||
scribe.print('(');
|
||||
writeKnRParameterNames(knrFunct, knrFunct.getParameterNames());
|
||||
scribe.print(')');
|
||||
scribe.newLine();
|
||||
writeKnRParameterDeclarations(knrFunct, knrFunct.getParameterDeclarations());
|
||||
|
||||
|
||||
}
|
||||
|
||||
protected void writeKnRParameterDeclarations(
|
||||
ICASTKnRFunctionDeclarator knrFunct, IASTDeclaration[] knrDeclarations) {
|
||||
for (int i = 0; i < knrDeclarations.length; ++i) {
|
||||
scribe.noNewLines();
|
||||
knrDeclarations[i].accept(visitor);
|
||||
scribe.newLines();
|
||||
if(i + 1 < knrDeclarations.length) {
|
||||
scribe.newLine();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void writeKnRParameterNames(ICASTKnRFunctionDeclarator knrFunct, IASTName[] parameterNames) {
|
||||
writeNodeList(parameterNames);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,634 @@
|
|||
/*******************************************************************************
|
||||
* 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.astwriter;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTArraySubscriptExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTCastExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTConditionalExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTExpressionList;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFieldReference;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTProblemExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTypeId;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTBinaryExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCastExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeleteExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFieldReference;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNewExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleTypeConstructorExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTypeIdExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTypenameExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUnaryExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTTypeIdExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTUnaryExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTBinaryExpression;
|
||||
import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap;
|
||||
|
||||
/**
|
||||
* @author Emanuel Graf
|
||||
*
|
||||
*/
|
||||
public class ExpressionWriter extends NodeWriter{
|
||||
|
||||
private static final String VECTORED_DELETE_OP = "[] "; //$NON-NLS-1$
|
||||
private static final String DELETE = "delete "; //$NON-NLS-1$
|
||||
private static final String STATIC_CAST_OP = "static_cast<"; //$NON-NLS-1$
|
||||
private static final String REINTERPRET_CAST_OP = "reinterpret_cast<"; //$NON-NLS-1$
|
||||
private static final String DYNAMIC_CAST_OP = "dynamic_cast<"; //$NON-NLS-1$
|
||||
private static final String CONST_CAST_OP = "const_cast<"; //$NON-NLS-1$
|
||||
private static final String CLOSING_CAST_BRACKET_OP = ">"; //$NON-NLS-1$
|
||||
private static final String ARROW = "->"; //$NON-NLS-1$
|
||||
private static final String SPACE_QUESTIONMARK_SPACE = " ? "; //$NON-NLS-1$
|
||||
private static final String NEW = "new "; //$NON-NLS-1$
|
||||
private static final String CLOSING_BRACKET_OP = ")"; //$NON-NLS-1$
|
||||
private static final String TYPEOF_OP = "typeof ("; //$NON-NLS-1$
|
||||
private static final String ALIGNOF_OP = "alignof ("; //$NON-NLS-1$
|
||||
private static final String TYPEID_OP = "typeid ("; //$NON-NLS-1$
|
||||
private static final String OPEN_BRACKET_OP = "("; //$NON-NLS-1$
|
||||
private static final String SIZEOF_OP = "sizeof "; //$NON-NLS-1$
|
||||
private static final String NOT_OP = "!"; //$NON-NLS-1$
|
||||
private static final String TILDE_OP = "~"; //$NON-NLS-1$
|
||||
private static final String AMPERSAND_OP = "&"; //$NON-NLS-1$
|
||||
private static final String STAR_OP = "*"; //$NON-NLS-1$
|
||||
private static final String UNARY_MINUS_OP = "-"; //$NON-NLS-1$
|
||||
private static final String UNARY_PLUS_OP = "+"; //$NON-NLS-1$
|
||||
private static final String INCREMENT_OP = "++"; //$NON-NLS-1$
|
||||
private static final String DECREMENT_OP = "--"; //$NON-NLS-1$
|
||||
private static final String MIN_OP = " <? "; //$NON-NLS-1$
|
||||
private static final String MAX_OP = " >? "; //$NON-NLS-1$
|
||||
private static final String PMARROW_OP = "->*"; //$NON-NLS-1$
|
||||
private static final String PMDOT_OP = ".*"; //$NON-NLS-1$
|
||||
private static final String NOT_EQUALS_OP = " != "; //$NON-NLS-1$
|
||||
private static final String EQUALS_OP = " == "; //$NON-NLS-1$
|
||||
private static final String BINARY_OR_ASSIGN = " |= "; //$NON-NLS-1$
|
||||
private static final String BINARY_XOR_ASSIGN_OP = " ^= "; //$NON-NLS-1$
|
||||
private static final String BINARY_AND_ASSIGN_OP = " &= "; //$NON-NLS-1$
|
||||
private static final String SHIFT_RIGHT_ASSIGN_OP = " >>= "; //$NON-NLS-1$
|
||||
private static final String SHIFT_LEFT_ASSIGN_OP = " <<= "; //$NON-NLS-1$
|
||||
private static final String MINUS_ASSIGN_OP = " -= "; //$NON-NLS-1$
|
||||
private static final String PLUS_ASSIGN_OP = " += "; //$NON-NLS-1$
|
||||
private static final String MODULO_ASSIGN_OP = " %= "; //$NON-NLS-1$
|
||||
private static final String DIVIDE_ASSIGN_OP = " /= "; //$NON-NLS-1$
|
||||
private static final String MULTIPLY_ASSIGN_OP = " *= "; //$NON-NLS-1$
|
||||
private static final String LOGICAL_OR_OP = " || "; //$NON-NLS-1$
|
||||
private static final String LOGICAL_AND_OP = " && "; //$NON-NLS-1$
|
||||
private static final String BINARY_OR_OP = " | "; //$NON-NLS-1$
|
||||
private static final String BINARY_XOR_OP = " ^ "; //$NON-NLS-1$
|
||||
private static final String BINARY_AND_OP = " & "; //$NON-NLS-1$
|
||||
private static final String GREAER_EQUAL_OP = " >= "; //$NON-NLS-1$
|
||||
private static final String LESS_EQUAL_OP = " <= "; //$NON-NLS-1$
|
||||
private static final String GREATER_THAN_OP = " > "; //$NON-NLS-1$
|
||||
private static final String LESS_THAN_OP = " < "; //$NON-NLS-1$
|
||||
private static final String SHIFT_RIGHT_OP = " >> "; //$NON-NLS-1$
|
||||
private static final String SHIFT_LEFT_OP = " << "; //$NON-NLS-1$
|
||||
private static final String MINUS_OP = " - "; //$NON-NLS-1$
|
||||
private static final String PLUS_OP = " + "; //$NON-NLS-1$
|
||||
private static final String MODULO_OP = " % "; //$NON-NLS-1$
|
||||
private static final String DIVIDE_OP = " / "; //$NON-NLS-1$
|
||||
private static final String MULTIPLY_OP = " * "; //$NON-NLS-1$
|
||||
private final MacroExpansionHandler macroHandler;
|
||||
|
||||
public ExpressionWriter(Scribe scribe, CPPASTVisitor visitor, MacroExpansionHandler macroHandler, NodeCommentMap commentMap) {
|
||||
super(scribe, visitor, commentMap);
|
||||
this.macroHandler = macroHandler;
|
||||
}
|
||||
|
||||
protected void writeExpression(IASTExpression expression) {
|
||||
if (expression instanceof IASTBinaryExpression) {
|
||||
writeBinaryExpression((IASTBinaryExpression) expression);
|
||||
} else if (expression instanceof IASTIdExpression) {
|
||||
((IASTIdExpression) expression).getName().accept(visitor);
|
||||
} else if (expression instanceof IASTLiteralExpression) {
|
||||
writeLiteralExpression((IASTLiteralExpression) expression);
|
||||
} else if (expression instanceof IASTUnaryExpression) {//UnaryExpressions including Cast Expressions
|
||||
writeUnaryExpression((IASTUnaryExpression) expression);
|
||||
} else if (expression instanceof ICPPASTNewExpression) {
|
||||
writeCPPNewExpression((ICPPASTNewExpression) expression);
|
||||
}else if (expression instanceof IASTConditionalExpression) {
|
||||
writeConditionalExpression((IASTConditionalExpression) expression);
|
||||
}else if (expression instanceof IASTArraySubscriptExpression) {
|
||||
writeArraySubscriptExpression((IASTArraySubscriptExpression) expression);
|
||||
}else if (expression instanceof IASTFieldReference) {
|
||||
writeFieldReference((IASTFieldReference) expression);
|
||||
}else if (expression instanceof IASTFunctionCallExpression) {
|
||||
writeFunctionCallExpression((IASTFunctionCallExpression) expression);
|
||||
}else if (expression instanceof IASTExpressionList) {
|
||||
writeExpressionList((IASTExpressionList) expression);
|
||||
}else if (expression instanceof IASTProblemExpression) {
|
||||
throw new ProblemRuntimeException(((IASTProblemExpression) expression));
|
||||
}else if (expression instanceof IASTTypeIdExpression) {
|
||||
writeTypeIdExpression((IASTTypeIdExpression) expression);
|
||||
}else if (expression instanceof ICPPASTDeleteExpression) {
|
||||
writeDeleteExpression((ICPPASTDeleteExpression) expression);
|
||||
}else if (expression instanceof ICPPASTSimpleTypeConstructorExpression) {
|
||||
writeSimpleTypeConstructorExpression((ICPPASTSimpleTypeConstructorExpression) expression);
|
||||
}else if (expression instanceof ICPPASTTypenameExpression) {
|
||||
//No example found for this Node
|
||||
throw new UnsupportedOperationException("You found a example for a TypenameExpression: " + expression.getRawSignature()); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private String getBinaryExpressionOperator(int operator){
|
||||
|
||||
switch(operator){
|
||||
case IASTBinaryExpression.op_multiply:
|
||||
return MULTIPLY_OP;
|
||||
case IASTBinaryExpression.op_divide:
|
||||
return DIVIDE_OP;
|
||||
case IASTBinaryExpression.op_modulo:
|
||||
return MODULO_OP;
|
||||
case IASTBinaryExpression.op_plus:
|
||||
return PLUS_OP;
|
||||
case IASTBinaryExpression.op_minus:
|
||||
return MINUS_OP;
|
||||
case IASTBinaryExpression.op_shiftLeft:
|
||||
return SHIFT_LEFT_OP;
|
||||
case IASTBinaryExpression.op_shiftRight:
|
||||
return SHIFT_RIGHT_OP;
|
||||
case IASTBinaryExpression.op_lessThan:
|
||||
return LESS_THAN_OP;
|
||||
case IASTBinaryExpression.op_greaterThan:
|
||||
return GREATER_THAN_OP;
|
||||
case IASTBinaryExpression.op_lessEqual:
|
||||
return LESS_EQUAL_OP;
|
||||
case IASTBinaryExpression.op_greaterEqual:
|
||||
return GREAER_EQUAL_OP;
|
||||
case IASTBinaryExpression.op_binaryAnd:
|
||||
return BINARY_AND_OP;
|
||||
case IASTBinaryExpression.op_binaryXor:
|
||||
return BINARY_XOR_OP;
|
||||
case IASTBinaryExpression.op_binaryOr:
|
||||
return BINARY_OR_OP;
|
||||
case IASTBinaryExpression.op_logicalAnd:
|
||||
return LOGICAL_AND_OP;
|
||||
case IASTBinaryExpression.op_logicalOr:
|
||||
return LOGICAL_OR_OP;
|
||||
case IASTBinaryExpression.op_assign:
|
||||
return EQUALS;
|
||||
case IASTBinaryExpression.op_multiplyAssign:
|
||||
return MULTIPLY_ASSIGN_OP;
|
||||
case IASTBinaryExpression.op_divideAssign:
|
||||
return DIVIDE_ASSIGN_OP;
|
||||
case IASTBinaryExpression.op_moduloAssign:
|
||||
return MODULO_ASSIGN_OP;
|
||||
case IASTBinaryExpression.op_plusAssign:
|
||||
return PLUS_ASSIGN_OP;
|
||||
case IASTBinaryExpression.op_minusAssign:
|
||||
return MINUS_ASSIGN_OP;
|
||||
case IASTBinaryExpression.op_shiftLeftAssign:
|
||||
return SHIFT_LEFT_ASSIGN_OP;
|
||||
case IASTBinaryExpression.op_shiftRightAssign:
|
||||
return SHIFT_RIGHT_ASSIGN_OP;
|
||||
case IASTBinaryExpression.op_binaryAndAssign:
|
||||
return BINARY_AND_ASSIGN_OP;
|
||||
case IASTBinaryExpression.op_binaryXorAssign:
|
||||
return BINARY_XOR_ASSIGN_OP;
|
||||
case IASTBinaryExpression.op_binaryOrAssign:
|
||||
return BINARY_OR_ASSIGN;
|
||||
case IASTBinaryExpression.op_equals:
|
||||
return EQUALS_OP;
|
||||
case IASTBinaryExpression.op_notequals:
|
||||
return NOT_EQUALS_OP;
|
||||
case ICPPASTBinaryExpression.op_pmdot:
|
||||
return PMDOT_OP;
|
||||
case ICPPASTBinaryExpression.op_pmarrow:
|
||||
return PMARROW_OP;
|
||||
case IGPPASTBinaryExpression.op_max:
|
||||
return MAX_OP;
|
||||
case IGPPASTBinaryExpression.op_min:
|
||||
return MIN_OP;
|
||||
default:
|
||||
System.err.println("Unknown unaryExpressionType: " + operator); //$NON-NLS-1$
|
||||
throw new IllegalArgumentException("Unknown unaryExpressionType: " + operator); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private boolean isPrefixExpression(IASTUnaryExpression unExp) {
|
||||
int unaryExpressionType = unExp.getOperator();
|
||||
if (unaryExpressionType <= IASTUnaryExpression.op_last) {
|
||||
|
||||
switch (unaryExpressionType) {
|
||||
case IASTUnaryExpression.op_prefixDecr:
|
||||
case IASTUnaryExpression.op_prefixIncr:
|
||||
case IASTUnaryExpression.op_plus:
|
||||
case IASTUnaryExpression.op_minus:
|
||||
case IASTUnaryExpression.op_star:
|
||||
case IASTUnaryExpression.op_amper:
|
||||
case IASTUnaryExpression.op_tilde:
|
||||
case IASTUnaryExpression.op_not:
|
||||
case IASTUnaryExpression.op_sizeof:
|
||||
case IASTUnaryExpression.op_bracketedPrimary:
|
||||
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}else {
|
||||
if (unExp instanceof ICPPASTUnaryExpression) {
|
||||
switch (unaryExpressionType) {
|
||||
case ICPPASTUnaryExpression.op_throw:
|
||||
case ICPPASTUnaryExpression.op_typeid:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}else if (unExp instanceof IGNUASTUnaryExpression) {
|
||||
switch (unaryExpressionType) {
|
||||
case IGNUASTUnaryExpression.op_alignOf:
|
||||
case IGNUASTUnaryExpression.op_typeof:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isPostfixExpression(IASTUnaryExpression unExp) {
|
||||
int unaryExpressionType = unExp.getOperator();
|
||||
if (unaryExpressionType <= IASTUnaryExpression.op_last) {
|
||||
switch (unaryExpressionType) {
|
||||
case IASTUnaryExpression.op_postFixDecr:
|
||||
case IASTUnaryExpression.op_postFixIncr:
|
||||
case IASTUnaryExpression.op_bracketedPrimary:
|
||||
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}else {
|
||||
if (unExp instanceof ICPPASTUnaryExpression) {
|
||||
return unaryExpressionType == ICPPASTUnaryExpression.op_typeid;
|
||||
}else if (unExp instanceof IGNUASTUnaryExpression) {
|
||||
switch (unaryExpressionType) {
|
||||
case IGNUASTUnaryExpression.op_alignOf:
|
||||
case IGNUASTUnaryExpression.op_typeof:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private String getPrefixOperator(IASTUnaryExpression unExp) {
|
||||
int unaryExpressionType = unExp.getOperator();
|
||||
if (unaryExpressionType <= IASTUnaryExpression.op_last) {
|
||||
switch (unaryExpressionType) {
|
||||
case IASTUnaryExpression.op_prefixDecr:
|
||||
return DECREMENT_OP;
|
||||
case IASTUnaryExpression.op_prefixIncr:
|
||||
return INCREMENT_OP;
|
||||
case IASTUnaryExpression.op_plus:
|
||||
return UNARY_PLUS_OP;
|
||||
case IASTUnaryExpression.op_minus:
|
||||
return UNARY_MINUS_OP;
|
||||
case IASTUnaryExpression.op_star:
|
||||
return STAR_OP;
|
||||
case IASTUnaryExpression.op_amper:
|
||||
return AMPERSAND_OP;
|
||||
case IASTUnaryExpression.op_tilde:
|
||||
return TILDE_OP;
|
||||
case IASTUnaryExpression.op_not:
|
||||
return NOT_OP;
|
||||
case IASTUnaryExpression.op_sizeof:
|
||||
return SIZEOF_OP;
|
||||
case IASTUnaryExpression.op_bracketedPrimary:
|
||||
return OPEN_BRACKET_OP;
|
||||
default:
|
||||
System.err.println("Unkwown unaryExpressionType: " + unaryExpressionType); //$NON-NLS-1$
|
||||
throw new IllegalArgumentException("Unkwown unaryExpressionType: " + unaryExpressionType); //$NON-NLS-1$
|
||||
}
|
||||
}else {
|
||||
if (unExp instanceof ICPPASTUnaryExpression) {
|
||||
switch (unaryExpressionType) {
|
||||
case ICPPASTUnaryExpression.op_throw:
|
||||
return THROW;
|
||||
case ICPPASTUnaryExpression.op_typeid:
|
||||
return TYPEID_OP;
|
||||
default:
|
||||
System.err.println("Unkwown unaryExpressionType: " + unaryExpressionType); //$NON-NLS-1$
|
||||
throw new IllegalArgumentException("Unkwown unaryExpressionType: " + unaryExpressionType); //$NON-NLS-1$
|
||||
}
|
||||
}else if (unExp instanceof IGNUASTUnaryExpression) {
|
||||
switch (unaryExpressionType) {
|
||||
case IGNUASTUnaryExpression.op_alignOf:
|
||||
return ALIGNOF_OP;
|
||||
case IGNUASTUnaryExpression.op_typeof:
|
||||
return TYPEOF_OP;
|
||||
default:
|
||||
System.err.println("Unkwown unaryExpressionType: " + unaryExpressionType); //$NON-NLS-1$
|
||||
throw new IllegalArgumentException("Unkwown unaryExpressionType: " + unaryExpressionType); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
}
|
||||
System.err.println("Unkwown unaryExpressionType: " + unaryExpressionType); //$NON-NLS-1$
|
||||
throw new IllegalArgumentException("Unkwown unaryExpressionType: " + unaryExpressionType); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
private String getPostfixOperator(IASTUnaryExpression unExp) {
|
||||
int unaryExpressionType = unExp.getOperator();
|
||||
if (unaryExpressionType <= IASTUnaryExpression.op_last) {
|
||||
switch (unaryExpressionType) {
|
||||
case IASTUnaryExpression.op_postFixDecr:
|
||||
return DECREMENT_OP;
|
||||
case IASTUnaryExpression.op_postFixIncr:
|
||||
return INCREMENT_OP;
|
||||
case IASTUnaryExpression.op_bracketedPrimary:
|
||||
return CLOSING_BRACKET_OP;
|
||||
default:
|
||||
System.err.println("Unkwown unaryExpressionType " + unaryExpressionType); //$NON-NLS-1$
|
||||
throw new IllegalArgumentException("Unkwown unaryExpressionType " + unaryExpressionType); //$NON-NLS-1$
|
||||
}
|
||||
}else {
|
||||
if (unExp instanceof ICPPASTUnaryExpression) {
|
||||
switch (unaryExpressionType) {
|
||||
case ICPPASTUnaryExpression.op_typeid:
|
||||
return CLOSING_BRACKET_OP;
|
||||
default:
|
||||
System.err.println("Unkwown unaryExpressionType " + unaryExpressionType); //$NON-NLS-1$
|
||||
throw new IllegalArgumentException("Unkwown unaryExpressionType " + unaryExpressionType); //$NON-NLS-1$
|
||||
}
|
||||
}else if (unExp instanceof IGNUASTUnaryExpression) {
|
||||
switch (unaryExpressionType) {
|
||||
case IGNUASTUnaryExpression.op_alignOf:
|
||||
case IGNUASTUnaryExpression.op_typeof:
|
||||
return CLOSING_BRACKET_OP;
|
||||
default:
|
||||
System.err.println("Unkwown unaryExpressionType " + unaryExpressionType); //$NON-NLS-1$
|
||||
throw new IllegalArgumentException("Unkwown unaryExpressionType " + unaryExpressionType); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
}
|
||||
System.err.println("Unkwown unaryExpressionType " + unaryExpressionType); //$NON-NLS-1$
|
||||
throw new IllegalArgumentException("Unkwown unaryExpressionType " + unaryExpressionType); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
private void writeBinaryExpression(IASTBinaryExpression binExp) {
|
||||
IASTExpression operand1 = binExp.getOperand1();
|
||||
if (!macroHandler.checkisMacroExpansionNode(operand1)) {
|
||||
operand1.accept(visitor);
|
||||
}
|
||||
IASTExpression operand2 = binExp.getOperand2();
|
||||
if(macroHandler.checkisMacroExpansionNode(operand2, false)&& macroHandler.macroExpansionAlreadyPrinted(operand2)) {
|
||||
return;
|
||||
}
|
||||
scribe.print(getBinaryExpressionOperator(binExp.getOperator()));
|
||||
operand2.accept(visitor);
|
||||
}
|
||||
|
||||
private void writeCPPNewExpression(ICPPASTNewExpression newExp) {
|
||||
if(newExp.isGlobal()) {
|
||||
scribe.print(COLON_COLON);
|
||||
}
|
||||
scribe.print(NEW);
|
||||
IASTExpression placement = newExp.getNewPlacement();
|
||||
visitNodeIfNotNull(placement);
|
||||
|
||||
IASTTypeId typeId = newExp.getTypeId();
|
||||
visitNodeIfNotNull(typeId);
|
||||
|
||||
IASTExpression[] arraySizeExpressions = getNewTypeIdArrayExpressions(newExp, newExp.getNewTypeIdArrayExpressions());
|
||||
for (IASTExpression expression : arraySizeExpressions) {
|
||||
scribe.print('[');
|
||||
expression.accept(visitor);
|
||||
scribe.print(']');
|
||||
}
|
||||
if (arraySizeExpressions.length == 0 ) {
|
||||
scribe.print('(');
|
||||
IASTExpression initExp = getNewInitializer(newExp);
|
||||
visitNodeIfNotNull(initExp);
|
||||
scribe.print(')');
|
||||
}
|
||||
}
|
||||
|
||||
protected IASTExpression[] getNewTypeIdArrayExpressions(
|
||||
ICPPASTNewExpression newExp, IASTExpression[] expressions) {
|
||||
return newExp.getNewTypeIdArrayExpressions();
|
||||
}
|
||||
|
||||
protected IASTExpression getNewInitializer(ICPPASTNewExpression newExp) {
|
||||
return newExp.getNewInitializer();
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void writeLiteralExpression(IASTLiteralExpression litExp) {
|
||||
scribe.print(litExp.toString());
|
||||
}
|
||||
|
||||
private void writeUnaryExpression(IASTUnaryExpression unExp) {
|
||||
if (unExp instanceof IASTCastExpression) {//Castoperatoren sind auch Un�reoperatoren
|
||||
writeCastExpression((IASTCastExpression) unExp);
|
||||
}else{
|
||||
if(isPrefixExpression(unExp )) {
|
||||
scribe.print(getPrefixOperator(unExp));
|
||||
}
|
||||
unExp.getOperand().accept(visitor);
|
||||
if(isPostfixExpression(unExp)) {
|
||||
scribe.print(getPostfixOperator(unExp));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void writeConditionalExpression(IASTConditionalExpression condExp) {
|
||||
condExp.getLogicalConditionExpression().accept(visitor);
|
||||
scribe.print(SPACE_QUESTIONMARK_SPACE);
|
||||
condExp.getPositiveResultExpression().accept(visitor);
|
||||
scribe.print(SPACE_COLON_SPACE);
|
||||
condExp.getNegativeResultExpression().accept(visitor);
|
||||
|
||||
}
|
||||
|
||||
private void writeArraySubscriptExpression(IASTArraySubscriptExpression arrSubExp) {
|
||||
arrSubExp.getArrayExpression().accept(visitor);
|
||||
scribe.print('[');
|
||||
arrSubExp.getSubscriptExpression().accept(visitor);
|
||||
scribe.print(']');
|
||||
|
||||
}
|
||||
|
||||
private void writeFieldReference(IASTFieldReference fieldRef) {
|
||||
fieldRef.getFieldOwner().accept(visitor);
|
||||
if(fieldRef.isPointerDereference()) {
|
||||
scribe.print(ARROW);
|
||||
}else {
|
||||
scribe.print('.');
|
||||
}
|
||||
if (fieldRef instanceof ICPPASTFieldReference) {
|
||||
ICPPASTFieldReference cppFieldRef = (ICPPASTFieldReference) fieldRef;
|
||||
if(cppFieldRef.isTemplate()) {
|
||||
scribe.print(TEMPLATE);
|
||||
}
|
||||
}
|
||||
fieldRef.getFieldName().accept(visitor);
|
||||
|
||||
}
|
||||
|
||||
private void writeFunctionCallExpression(IASTFunctionCallExpression funcCallExp) {
|
||||
funcCallExp.getFunctionNameExpression().accept(visitor);
|
||||
scribe.print('(');
|
||||
IASTExpression parameterExpression = funcCallExp.getParameterExpression();
|
||||
visitNodeIfNotNull(parameterExpression);
|
||||
scribe.print(')');
|
||||
|
||||
}
|
||||
|
||||
private void writeCastExpression(IASTCastExpression castExp) {
|
||||
scribe.print(getCastPrefix(castExp.getOperator()));
|
||||
castExp.getTypeId().accept(visitor);
|
||||
scribe.print(getCastPostfix(castExp.getOperator()));
|
||||
if (castExp instanceof ICPPASTCastExpression) {
|
||||
scribe.print('(');
|
||||
}
|
||||
castExp.getOperand().accept(visitor);
|
||||
if (castExp instanceof ICPPASTCastExpression) {
|
||||
scribe.print(')');
|
||||
}
|
||||
}
|
||||
|
||||
private String getCastPostfix(int castType) {
|
||||
switch (castType) {
|
||||
case IASTCastExpression.op_cast:
|
||||
return CLOSING_BRACKET_OP;
|
||||
case ICPPASTCastExpression.op_const_cast:
|
||||
case ICPPASTCastExpression.op_dynamic_cast:
|
||||
case ICPPASTCastExpression.op_reinterpret_cast:
|
||||
case ICPPASTCastExpression.op_static_cast:
|
||||
return CLOSING_CAST_BRACKET_OP;
|
||||
default:
|
||||
throw new IllegalArgumentException("Unknown Cast Type"); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
|
||||
private String getCastPrefix(int castType) {
|
||||
switch (castType) {
|
||||
case IASTCastExpression.op_cast:
|
||||
return OPEN_BRACKET_OP;
|
||||
case ICPPASTCastExpression.op_const_cast:
|
||||
return CONST_CAST_OP;
|
||||
case ICPPASTCastExpression.op_dynamic_cast:
|
||||
return DYNAMIC_CAST_OP;
|
||||
case ICPPASTCastExpression.op_reinterpret_cast:
|
||||
return REINTERPRET_CAST_OP;
|
||||
case ICPPASTCastExpression.op_static_cast:
|
||||
return STATIC_CAST_OP;
|
||||
default:
|
||||
throw new IllegalArgumentException("Unknown Cast Type"); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
|
||||
private void writeExpressionList(IASTExpressionList expList) {
|
||||
|
||||
IASTExpression[] expressions = expList.getExpressions();
|
||||
writeExpressions(expList, expressions);
|
||||
}
|
||||
|
||||
protected void writeExpressions(IASTExpressionList expList, IASTExpression[] expressions) {
|
||||
writeNodeList(expressions);
|
||||
}
|
||||
|
||||
private void writeTypeIdExpression(IASTTypeIdExpression typeIdExp) {
|
||||
scribe.print(getTypeIdExp(typeIdExp));
|
||||
typeIdExp.getTypeId().accept(visitor);
|
||||
scribe.print(')');
|
||||
}
|
||||
|
||||
private String getTypeIdExp(IASTTypeIdExpression typeIdExp) {
|
||||
int type = typeIdExp.getOperator();
|
||||
if (type <= IASTTypeIdExpression.op_last) {
|
||||
if(type == IASTTypeIdExpression.op_sizeof) {
|
||||
return SIZEOF_OP + "("; //$NON-NLS-1$
|
||||
}
|
||||
}else {
|
||||
if (typeIdExp instanceof ICPPASTTypeIdExpression) {
|
||||
if(type == ICPPASTTypeIdExpression.op_typeid) {
|
||||
return TYPEID_OP;
|
||||
}
|
||||
}else if (typeIdExp instanceof IGNUASTTypeIdExpression) {
|
||||
switch (type) {//TODO HSR Emanuel: check if there can't be GNUTypeIdExpressions here, see #162470
|
||||
case IGNUASTTypeIdExpression.op_alignof:
|
||||
return ALIGNOF_OP + "("; //$NON-NLS-1$
|
||||
case IGNUASTTypeIdExpression.op_typeof:
|
||||
return TYPEOF_OP;
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException("Unknown TypeId Type"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
private void writeDeleteExpression(ICPPASTDeleteExpression delExp) {
|
||||
if(delExp.isGlobal()) {
|
||||
scribe.print(COLON_COLON);
|
||||
}
|
||||
scribe.print(DELETE);
|
||||
if(delExp.isVectored()) {
|
||||
scribe.print(VECTORED_DELETE_OP);
|
||||
}
|
||||
delExp.getOperand().accept(visitor);
|
||||
}
|
||||
|
||||
private void writeSimpleTypeConstructorExpression(ICPPASTSimpleTypeConstructorExpression simpTypeCtorExp) {
|
||||
scribe.print(getSimpleTypeString(simpTypeCtorExp.getSimpleType()));
|
||||
scribe.print('(');
|
||||
IASTExpression initalizer = simpTypeCtorExp.getInitialValue();
|
||||
visitNodeIfNotNull(initalizer);
|
||||
scribe.print(')');
|
||||
}
|
||||
|
||||
private String getSimpleTypeString(int typeId) {
|
||||
switch (typeId) {
|
||||
|
||||
case ICPPASTSimpleTypeConstructorExpression.t_void:
|
||||
return VOID;
|
||||
case ICPPASTSimpleTypeConstructorExpression.t_char:
|
||||
return CHAR;
|
||||
case ICPPASTSimpleTypeConstructorExpression.t_int:
|
||||
return INT;
|
||||
case ICPPASTSimpleTypeConstructorExpression.t_float:
|
||||
return FLOAT;
|
||||
case ICPPASTSimpleTypeConstructorExpression.t_double:
|
||||
return DOUBLE;
|
||||
case ICPPASTSimpleTypeConstructorExpression.t_bool:
|
||||
return CPP_BOOL;
|
||||
case ICPPASTSimpleTypeConstructorExpression.t_wchar_t:
|
||||
return WCHAR_T;
|
||||
case ICPPASTSimpleTypeConstructorExpression.t_short:
|
||||
return SHORT;
|
||||
case ICPPASTSimpleTypeConstructorExpression.t_long:
|
||||
return LONG;
|
||||
case ICPPASTSimpleTypeConstructorExpression.t_signed:
|
||||
return SIGNED;
|
||||
case ICPPASTSimpleTypeConstructorExpression.t_unsigned :
|
||||
return UNSIGNED;
|
||||
|
||||
default:
|
||||
System.err.println("Unknown simpleTypeId: " + typeId); //$NON-NLS-1$
|
||||
throw new IllegalArgumentException("Unknown simpleTypeId: " + typeId); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,87 @@
|
|||
/*******************************************************************************
|
||||
* 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.astwriter;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTInitializer;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTInitializerExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTInitializerList;
|
||||
import org.eclipse.cdt.core.dom.ast.c.ICASTArrayDesignator;
|
||||
import org.eclipse.cdt.core.dom.ast.c.ICASTDesignatedInitializer;
|
||||
import org.eclipse.cdt.core.dom.ast.c.ICASTDesignator;
|
||||
import org.eclipse.cdt.core.dom.ast.c.ICASTFieldDesignator;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorInitializer;
|
||||
import org.eclipse.cdt.core.dom.ast.gnu.c.IGCCASTArrayRangeDesignator;
|
||||
import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap;
|
||||
|
||||
/**
|
||||
* @author Emanuel Graf
|
||||
*
|
||||
*/
|
||||
public class InitializerWriter extends NodeWriter{
|
||||
|
||||
public InitializerWriter(Scribe scribe, CPPASTVisitor visitor, NodeCommentMap commentMap) {
|
||||
super(scribe, visitor, commentMap);
|
||||
}
|
||||
|
||||
protected void writeInitializer(IASTInitializer initializer) {
|
||||
if (initializer instanceof IASTInitializerExpression) {
|
||||
((IASTInitializerExpression) initializer).getExpression().accept(visitor);
|
||||
}else if (initializer instanceof IASTInitializerList) {
|
||||
writeInitializerList((IASTInitializerList) initializer);
|
||||
}else if (initializer instanceof ICPPASTConstructorInitializer) {
|
||||
writeConstructorInitializer((ICPPASTConstructorInitializer) initializer);
|
||||
}else if (initializer instanceof ICASTDesignatedInitializer) {
|
||||
writeDesignatedInitializer((ICASTDesignatedInitializer) initializer);
|
||||
}
|
||||
}
|
||||
|
||||
private void writeInitializerList(IASTInitializerList initList) {
|
||||
scribe.printLBrace();
|
||||
IASTInitializer[] inits = initList.getInitializers();
|
||||
writeNodeList(inits);
|
||||
scribe.printRBrace();
|
||||
}
|
||||
|
||||
private void writeConstructorInitializer(ICPPASTConstructorInitializer ctorInit) {
|
||||
scribe.print('(');
|
||||
ctorInit.getExpression().accept(visitor);
|
||||
scribe.print(')');
|
||||
}
|
||||
|
||||
private void writeDesignatedInitializer(ICASTDesignatedInitializer desigInit) {
|
||||
ICASTDesignator[] designators = desigInit.getDesignators();
|
||||
for (ICASTDesignator designator : designators) {
|
||||
writeDesignator(designator);
|
||||
}
|
||||
scribe.print(EQUALS);
|
||||
desigInit.getOperandInitializer().accept(visitor);
|
||||
}
|
||||
|
||||
private void writeDesignator(ICASTDesignator designator) {
|
||||
if (designator instanceof ICASTFieldDesignator) {
|
||||
ICASTFieldDesignator fieldDes = (ICASTFieldDesignator) designator;
|
||||
scribe.print('.');
|
||||
fieldDes.getName().accept(visitor);
|
||||
}else if (designator instanceof ICASTArrayDesignator) {
|
||||
ICASTArrayDesignator arrDes = (ICASTArrayDesignator) designator;
|
||||
scribe.print('[');
|
||||
arrDes.getSubscriptExpression().accept(visitor);
|
||||
scribe.print(']');
|
||||
}else if (designator instanceof IGCCASTArrayRangeDesignator) {
|
||||
//IGCCASTArrayRangeDesignator new_name = (IGCCASTArrayRangeDesignator) designator;
|
||||
//TODO IGCCASTArrayRangeDesignator Bespiel zu parsen bringen
|
||||
throw new UnsupportedOperationException("Writing of GCC ArrayRangeDesignator is not yet implemented"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,81 @@
|
|||
/*******************************************************************************
|
||||
* 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.astwriter;
|
||||
|
||||
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.core.dom.ast.IASTStatement;
|
||||
|
||||
public class MacroExpansionHandler {
|
||||
|
||||
private int lastMacroExpOffset;
|
||||
private final Scribe scribe;
|
||||
|
||||
public MacroExpansionHandler(Scribe scribe) {
|
||||
this.scribe = scribe;
|
||||
}
|
||||
|
||||
protected boolean checkisMacroExpansionNode(IASTNode node) {
|
||||
return checkisMacroExpansionNode(node, true);
|
||||
}
|
||||
|
||||
protected boolean isStatementWithMixedLocation(IASTStatement node) {
|
||||
if(node.getNodeLocations().length > 1) {
|
||||
for (IASTNodeLocation loc : node.getNodeLocations()) {
|
||||
if (loc instanceof IASTMacroExpansionLocation) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected boolean macroExpansionAlreadyPrinted(IASTNode node) {
|
||||
IASTNodeLocation[] locs = node.getNodeLocations();
|
||||
if(locs.length ==1) {
|
||||
if (locs[0] instanceof IASTMacroExpansionLocation) {
|
||||
IASTMacroExpansionLocation macroNode = (IASTMacroExpansionLocation) locs[0];
|
||||
if (macroNode.asFileLocation().getNodeOffset() == lastMacroExpOffset) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected boolean checkisMacroExpansionNode(IASTNode node, boolean write) {
|
||||
IASTNodeLocation[] locs = node.getNodeLocations();
|
||||
if(locs.length ==1) {
|
||||
if (locs[0] instanceof IASTMacroExpansionLocation) {
|
||||
IASTMacroExpansionLocation macroNode = (IASTMacroExpansionLocation) locs[0];
|
||||
|
||||
if (macroNode.asFileLocation().getNodeOffset() == lastMacroExpOffset) {
|
||||
return true;
|
||||
} else {
|
||||
if (write) {
|
||||
lastMacroExpOffset = macroNode.asFileLocation().getNodeOffset();
|
||||
scribe.print(node.getRawSignature());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void reset(){
|
||||
lastMacroExpOffset = -1;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,132 @@
|
|||
/*******************************************************************************
|
||||
* 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.astwriter;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConversionName;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateTypeParameter;
|
||||
import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap;
|
||||
|
||||
/**
|
||||
* @author Emanuel Graf
|
||||
*
|
||||
*/
|
||||
public class NameWriter extends NodeWriter {
|
||||
|
||||
private static final String OPERATOR = "operator "; //$NON-NLS-1$
|
||||
|
||||
|
||||
/**
|
||||
* @param scribe
|
||||
* @param visitor
|
||||
*/
|
||||
public NameWriter(Scribe scribe, CPPASTVisitor visitor, NodeCommentMap commentMap) {
|
||||
super(scribe, visitor, commentMap);
|
||||
}
|
||||
|
||||
protected void writeName(IASTName name) {
|
||||
if (name instanceof ICPPASTTemplateId) {
|
||||
writeTempalteId((ICPPASTTemplateId) name);
|
||||
} else if (name instanceof ICPPASTConversionName) {
|
||||
scribe.print(OPERATOR);
|
||||
((ICPPASTConversionName)name).getTypeId().accept(visitor);
|
||||
} else if (name instanceof ICPPASTQualifiedName){
|
||||
writeQualifiedName((ICPPASTQualifiedName) name);
|
||||
} else {
|
||||
scribe.print(name.toString());
|
||||
}
|
||||
|
||||
if(hasTrailingComments(name)) {
|
||||
writeTrailingComments(name);
|
||||
}
|
||||
}
|
||||
|
||||
private void writeTempalteId(ICPPASTTemplateId tempId) {
|
||||
if(needsTemplateQualifier(tempId)) {
|
||||
scribe.print(TEMPLATE);
|
||||
}
|
||||
scribe.print(tempId.getTemplateName().toString());
|
||||
scribe.print('<');
|
||||
IASTNode[] nodes = tempId.getTemplateArguments();
|
||||
for (int i = 0; i < nodes.length; ++i) {
|
||||
nodes[i].accept(visitor);
|
||||
if(i + 1 < nodes.length) {
|
||||
scribe.print(',');
|
||||
}
|
||||
}
|
||||
scribe.print('>');
|
||||
if(isNestedTemplateId(tempId)) {
|
||||
scribe.printSpace();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean needsTemplateQualifier(ICPPASTTemplateId templId){
|
||||
if (templId.getParent() instanceof ICPPASTQualifiedName) {
|
||||
ICPPASTQualifiedName qName = (ICPPASTQualifiedName) templId.getParent();
|
||||
return isDependentName(qName, templId);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isDependentName(ICPPASTQualifiedName qname, ICPPASTTemplateId tempId) {
|
||||
IASTName[] names = qname.getNames();
|
||||
int i = 0;
|
||||
for(;i < names.length; ++i){
|
||||
if(names[i] == tempId){
|
||||
return isDependentName(qname, tempId, i);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isDependentName(ICPPASTQualifiedName qname,
|
||||
ICPPASTTemplateId tempId, int i) {
|
||||
if(i <= 0){
|
||||
return false;
|
||||
}else{
|
||||
if (qname.getNames()[i-1] instanceof ICPPASTTemplateId) {
|
||||
return true;
|
||||
}else{
|
||||
IBinding binding = qname.getNames()[i-1].resolveBinding();
|
||||
if (binding instanceof CPPTemplateTypeParameter) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return isDependentName(qname, tempId, i-1);
|
||||
}
|
||||
|
||||
private boolean isNestedTemplateId(IASTNode node) {
|
||||
while((node = node.getParent()) != null) {
|
||||
if (node instanceof ICPPASTTemplateId) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
private void writeQualifiedName(ICPPASTQualifiedName qname) {
|
||||
IASTName[] nodes = qname.getNames();
|
||||
for (int i = 0; i < nodes.length; ++i) {
|
||||
nodes[i].accept(visitor);
|
||||
if(i + 1 < nodes.length) {
|
||||
scribe.print(COLON_COLON);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,112 @@
|
|||
/*******************************************************************************
|
||||
* 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.astwriter;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTComment;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
|
||||
import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap;
|
||||
|
||||
public class NodeWriter {
|
||||
|
||||
protected Scribe scribe;
|
||||
protected CPPASTVisitor visitor;
|
||||
protected NodeCommentMap commentMap;
|
||||
protected static final String COMMA_SPACE = ", "; //$NON-NLS-1$
|
||||
protected static final String EQUALS = " = "; //$NON-NLS-1$
|
||||
protected static final String RESTRICT = "restrict "; //$NON-NLS-1$
|
||||
protected static final String TYPENAME = "typename "; //$NON-NLS-1$
|
||||
protected static final String PUBLIC = "public"; //$NON-NLS-1$
|
||||
protected static final String PRIVATE = "private"; //$NON-NLS-1$
|
||||
protected static final String PROTECTED = "protected"; //$NON-NLS-1$
|
||||
protected static final String CONST = "const"; //$NON-NLS-1$
|
||||
protected static final String VOLATILE = "volatile"; //$NON-NLS-1$
|
||||
protected static final String INLINE = "inline "; //$NON-NLS-1$
|
||||
protected static final String EXTERN = "extern "; //$NON-NLS-1$
|
||||
protected static final String STATIC = "static "; //$NON-NLS-1$
|
||||
protected static final String THROW = "throw "; //$NON-NLS-1$
|
||||
protected static final String SPACE_COLON_SPACE = " : "; //$NON-NLS-1$
|
||||
protected static final String TEMPLATE = "template "; //$NON-NLS-1$
|
||||
protected static final String DOUBLE = "double"; //$NON-NLS-1$
|
||||
protected static final String FLOAT = "float"; //$NON-NLS-1$
|
||||
protected static final String INT = "int"; //$NON-NLS-1$
|
||||
protected static final String CHAR = "char"; //$NON-NLS-1$
|
||||
protected static final String VOID = "void"; //$NON-NLS-1$
|
||||
protected static final String WCHAR_T = "wchar_t"; //$NON-NLS-1$
|
||||
protected static final String CPP_BOOL = "bool"; //$NON-NLS-1$
|
||||
protected static final String LONG = "long"; //$NON-NLS-1$
|
||||
protected static final String SHORT = "short"; //$NON-NLS-1$
|
||||
protected static final String UNSIGNED = "unsigned"; //$NON-NLS-1$
|
||||
protected static final String SIGNED = "signed"; //$NON-NLS-1$
|
||||
protected static final String CLASS_SPACE = "class "; //$NON-NLS-1$
|
||||
protected static final String VAR_ARGS = "..."; //$NON-NLS-1$
|
||||
protected static final String COLON_COLON = "::"; //$NON-NLS-1$
|
||||
|
||||
public NodeWriter(Scribe scribe, CPPASTVisitor visitor, NodeCommentMap commentMap) {
|
||||
super();
|
||||
this.scribe = scribe;
|
||||
this.visitor = visitor;
|
||||
this.commentMap = commentMap;
|
||||
}
|
||||
|
||||
protected void writeNodeList(IASTNode[] nodes) {
|
||||
for(int i = 0; i < nodes.length; ++i) {
|
||||
nodes[i].accept(visitor);
|
||||
if(i + 1 < nodes.length) {
|
||||
scribe.print(COMMA_SPACE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void visitNodeIfNotNull(IASTNode node){
|
||||
if(node != null){
|
||||
node.accept(visitor);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected void writeTrailingComments(IASTNode node) {
|
||||
//default write newLine
|
||||
writeTrailingComments(node, true);
|
||||
}
|
||||
|
||||
protected boolean hasTrailingComments(IASTNode node){
|
||||
if(commentMap.getTrailingCommentsForNode(node).size()>0) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected void writeTrailingComments(IASTNode node, boolean newLine) {
|
||||
for(IASTComment comment : commentMap.getTrailingCommentsForNode(node)) {
|
||||
scribe.printSpace();
|
||||
scribe.print(comment.getComment());
|
||||
if(newLine) {
|
||||
scribe.newLine();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean hasFreestandingComments(IASTNode node){
|
||||
if(commentMap.getFreestandingCommentsForNode(node).size()>0) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected void writeFreeStandingComments(IASTNode node) {
|
||||
for(IASTComment comment : commentMap.getFreestandingCommentsForNode(node)) {
|
||||
scribe.print(comment.getComment());
|
||||
scribe.newLine();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
/*******************************************************************************
|
||||
* 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.astwriter;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTProblemHolder;
|
||||
|
||||
public class ProblemRuntimeException extends RuntimeException {
|
||||
|
||||
private static final long serialVersionUID = -3661425564246498786L;
|
||||
private IASTProblemHolder problem;
|
||||
|
||||
public ProblemRuntimeException(IASTProblemHolder statement) {
|
||||
problem = statement;
|
||||
}
|
||||
|
||||
public IASTProblemHolder getProblem(){
|
||||
return problem;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,180 @@
|
|||
/*******************************************************************************
|
||||
* 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.astwriter;
|
||||
|
||||
public class Scribe {
|
||||
|
||||
|
||||
private int indentationLevel = 0;
|
||||
private int indentationSize = 4; //HSR tcorbat: could be a tab character too - this is not a very elegant solution
|
||||
private StringBuffer buffer = new StringBuffer();
|
||||
private boolean isAtLineBeginning = true;
|
||||
private String newLine = System.getProperty("line.separator"); //$NON-NLS-1$
|
||||
private String givenIndentation = null;
|
||||
|
||||
private boolean noNewLine = false;
|
||||
private boolean noSemicolon = false;
|
||||
|
||||
public void newLine(){
|
||||
if(!noNewLine) {
|
||||
isAtLineBeginning = true;
|
||||
buffer.append(getNewline());
|
||||
}
|
||||
}
|
||||
|
||||
private void indent(){
|
||||
if( givenIndentation != null ){
|
||||
buffer.append( givenIndentation );
|
||||
}
|
||||
printSpaces(indentationLevel * indentationSize);
|
||||
}
|
||||
|
||||
private void indentIfNewLine(){
|
||||
if(isAtLineBeginning){
|
||||
isAtLineBeginning = false;
|
||||
indent();
|
||||
}
|
||||
}
|
||||
|
||||
private String getNewline(){
|
||||
return newLine;
|
||||
}
|
||||
|
||||
public void print(String code){
|
||||
indentIfNewLine();
|
||||
buffer.append(code);
|
||||
}
|
||||
|
||||
public void println(String code) {
|
||||
print(code);
|
||||
newLine();
|
||||
}
|
||||
|
||||
public void print(String code, String code2) {
|
||||
print(code);
|
||||
buffer.append(code2);
|
||||
}
|
||||
|
||||
public void println(String code, String code2) {
|
||||
print(code, code2);
|
||||
newLine();
|
||||
}
|
||||
|
||||
public void println(String code , char[] code2) {
|
||||
print(code);
|
||||
buffer.append(code2);
|
||||
newLine();
|
||||
}
|
||||
|
||||
public void printSpaces(int number){
|
||||
indentIfNewLine();
|
||||
for(int i = 0; i < number; ++i){
|
||||
printSpace();
|
||||
}
|
||||
}
|
||||
|
||||
public void noSemicolon() {
|
||||
noSemicolon = true;
|
||||
}
|
||||
|
||||
public void printSemicolon(){
|
||||
if(!noSemicolon) {
|
||||
indentIfNewLine();
|
||||
buffer.append(';');
|
||||
}
|
||||
else {
|
||||
noSemicolon = false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
public void print (char code) {
|
||||
indentIfNewLine();
|
||||
buffer.append(code);
|
||||
}
|
||||
|
||||
public void print(char[] code) {
|
||||
indentIfNewLine();
|
||||
buffer.append(code);
|
||||
}
|
||||
|
||||
public void println(char[] code) {
|
||||
print(code);
|
||||
newLine();
|
||||
}
|
||||
|
||||
public void printStringSpace(String code){
|
||||
print(code);
|
||||
printSpace();
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints a { to the Buffer an increases the Indentationlevel.
|
||||
*/
|
||||
public void printLBrace() {
|
||||
print('{');
|
||||
++indentationLevel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints a } to the Buffer an decrease the Indentationlevel.
|
||||
*/
|
||||
public void printRBrace() {
|
||||
--indentationLevel;
|
||||
print('}');
|
||||
}
|
||||
|
||||
public void incrementIndentationLevel(){
|
||||
++indentationLevel;
|
||||
}
|
||||
|
||||
public void decrementIndentationLevel(){
|
||||
if(indentationLevel>0) {
|
||||
--indentationLevel;
|
||||
}
|
||||
}
|
||||
|
||||
protected void noNewLines(){
|
||||
noNewLine = true;
|
||||
}
|
||||
|
||||
protected void newLines(){
|
||||
noNewLine = false;
|
||||
}
|
||||
|
||||
public void newLine(int i) {
|
||||
while(i > 0) {
|
||||
newLine();
|
||||
--i;
|
||||
}
|
||||
}
|
||||
|
||||
public void printSpace() {
|
||||
buffer.append(' ');
|
||||
}
|
||||
|
||||
public String getGivenIndentation() {
|
||||
return givenIndentation;
|
||||
}
|
||||
|
||||
public void setGivenIndentation(String givenIndentation) {
|
||||
this.givenIndentation = givenIndentation;
|
||||
}
|
||||
|
||||
public void cleanCache() {
|
||||
buffer = new StringBuffer();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,430 @@
|
|||
/*******************************************************************************
|
||||
* 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.astwriter;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTBreakStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTCaseStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTContinueStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarationStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDefaultStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDoStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTExpressionStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTForStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTGotoStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTIfStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTLabelStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNullStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTProblemStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTReturnStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTSwitchStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTWhileStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCatchHandler;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTForStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTIfStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSwitchStatement;
|
||||
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;
|
||||
|
||||
public class StatementWriter extends NodeWriter{
|
||||
|
||||
private static final String DEFAULT = "default:"; //$NON-NLS-1$
|
||||
private static final String CASE = "case "; //$NON-NLS-1$
|
||||
private static final String WHILE = "while("; //$NON-NLS-1$
|
||||
private static final String TRY = "try "; //$NON-NLS-1$
|
||||
private static final String CATCH = "catch("; //$NON-NLS-1$
|
||||
private static final String RETURN = "return"; //$NON-NLS-1$
|
||||
private static final String GOTO = "goto "; //$NON-NLS-1$
|
||||
private static final String CONTINUE = "continue"; //$NON-NLS-1$
|
||||
private static final String BREAK = "break"; //$NON-NLS-1$
|
||||
private static final String ELSE = "else"; //$NON-NLS-1$
|
||||
private static final String IF = "if("; //$NON-NLS-1$
|
||||
private static final String FOR = "for("; //$NON-NLS-1$
|
||||
private static final String DO_WHILE = " while("; //$NON-NLS-1$
|
||||
private static final String DO = "do"; //$NON-NLS-1$
|
||||
private static final String SWITCH_BRACKET = "switch ("; //$NON-NLS-1$
|
||||
private boolean compoundNoNewLine = false;
|
||||
private boolean switchIsNew;
|
||||
private boolean decrementIndentationLevelOneMore = false;
|
||||
private final DeclarationWriter declWriter;
|
||||
|
||||
public StatementWriter(Scribe scribe, CPPASTVisitor visitor, NodeCommentMap commentMap) {
|
||||
super(scribe, visitor, commentMap);
|
||||
declWriter = new DeclarationWriter(scribe, visitor, commentMap);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param statement
|
||||
* @param newLine if true print a newline if statment usually have one.
|
||||
* @return {@link ASTVisitor#PROCESS_SKIP}
|
||||
*/
|
||||
protected int writeStatement(IASTStatement statement, boolean newLine) {
|
||||
if (statement instanceof IASTAmbiguousStatement) {
|
||||
//TODO HSR Leo test
|
||||
statement.accept(visitor);
|
||||
newLine = false;
|
||||
} else if (statement instanceof IASTExpressionStatement) {
|
||||
writeExpressionStatement((IASTExpressionStatement) statement);
|
||||
//usually newLine
|
||||
} else if (statement instanceof IASTDeclarationStatement) {
|
||||
writeDeclarationStatement((IASTDeclarationStatement) statement);
|
||||
newLine = false;
|
||||
} else if (statement instanceof IASTNullStatement) {
|
||||
writeNullStatement((IASTNullStatement)statement);
|
||||
// usually newLine
|
||||
} else if (statement instanceof IASTReturnStatement) {
|
||||
writeReturnStatement((IASTReturnStatement)statement);
|
||||
// usually newLine
|
||||
} else if (statement instanceof IASTGotoStatement) {
|
||||
writeGotoStatement((IASTGotoStatement) statement);
|
||||
// usually newLine
|
||||
} else if (statement instanceof IASTLabelStatement) {
|
||||
writeLabelStatement((IASTLabelStatement) statement);
|
||||
newLine = false;
|
||||
} else if (statement instanceof IASTCaseStatement) {
|
||||
writeCaseStatement((IASTCaseStatement) statement);
|
||||
// usually newLine
|
||||
}else if (statement instanceof IASTDefaultStatement) {
|
||||
writeDefaultStatement((IASTDefaultStatement)statement);
|
||||
} else if (statement instanceof IASTContinueStatement){
|
||||
writeContinueStatement((IASTContinueStatement)statement);
|
||||
// usually newLine
|
||||
} else if (statement instanceof IASTCompoundStatement) {
|
||||
writeCompoundStatement((IASTCompoundStatement) statement);
|
||||
if(compoundNoNewLine){
|
||||
newLine = false;
|
||||
compoundNoNewLine = false;
|
||||
}
|
||||
} else if (statement instanceof IASTBreakStatement) {
|
||||
writeBreakStatement((IASTBreakStatement) statement);
|
||||
// usually newLine
|
||||
} else if (statement instanceof IASTSwitchStatement) {
|
||||
writeSwitchStatement((IASTSwitchStatement) statement);
|
||||
newLine = false;
|
||||
} else if (statement instanceof IASTIfStatement) {
|
||||
writeIfStatement((IASTIfStatement) statement);
|
||||
newLine = false;
|
||||
} else if (statement instanceof IASTWhileStatement) {
|
||||
writeWhileStatement( (IASTWhileStatement) statement );
|
||||
newLine = false;
|
||||
} else if (statement instanceof IASTForStatement) {
|
||||
writeForStatement((IASTForStatement) statement);
|
||||
newLine = false;
|
||||
} else if (statement instanceof IASTDoStatement) {
|
||||
writeDoStatement((IASTDoStatement) statement);
|
||||
newLine = true;
|
||||
} else if (statement instanceof ICPPASTTryBlockStatement) {
|
||||
writeTryBlockStatement((ICPPASTTryBlockStatement) statement);
|
||||
newLine = false;
|
||||
} else if (statement instanceof ICPPASTCatchHandler) {
|
||||
writeCatchHandler((ICPPASTCatchHandler) statement);
|
||||
newLine = false;
|
||||
} else if (statement instanceof IASTProblemStatement) {
|
||||
throw new ProblemRuntimeException((IASTProblemStatement)statement);
|
||||
}
|
||||
|
||||
if(hasTrailingComments(statement)) {
|
||||
writeTrailingComments(statement, newLine);
|
||||
}
|
||||
else{
|
||||
if(newLine){
|
||||
scribe.newLine();
|
||||
}
|
||||
}
|
||||
|
||||
return ASTVisitor.PROCESS_SKIP;
|
||||
}
|
||||
|
||||
private void writeDoStatement(IASTDoStatement doStatement) {
|
||||
nextCompoundNoNewLine();
|
||||
|
||||
scribe.print(DO);
|
||||
writeBodyStatement(doStatement.getBody(), true);
|
||||
scribe.print(DO_WHILE);
|
||||
doStatement.getCondition().accept(visitor);
|
||||
scribe.print(')');
|
||||
scribe.printSemicolon();
|
||||
}
|
||||
|
||||
private void writeForStatement(IASTForStatement forStatment) {
|
||||
scribe.noNewLines();
|
||||
scribe.print(FOR);
|
||||
writeStatement(forStatment.getInitializerStatement(),false);
|
||||
if (forStatment instanceof ICPPASTForStatement) {
|
||||
ICPPASTForStatement cppForStatment = (ICPPASTForStatement) forStatment;
|
||||
IASTDeclaration cppConditionDeclaration = cppForStatment.getConditionDeclaration();
|
||||
if(cppConditionDeclaration == null) {
|
||||
visitNodeIfNotNull(cppForStatment.getConditionExpression());
|
||||
scribe.printSemicolon();
|
||||
} else {
|
||||
cppConditionDeclaration.accept(visitor);
|
||||
}
|
||||
|
||||
} else {
|
||||
if(forStatment.getConditionExpression() != null) {
|
||||
forStatment.getConditionExpression().accept(visitor);
|
||||
scribe.printSemicolon();
|
||||
}
|
||||
}
|
||||
|
||||
visitNodeIfNotNull(forStatment.getIterationExpression());
|
||||
scribe.print(')');
|
||||
scribe.newLines();
|
||||
nextCompoundNoNewLine();
|
||||
writeBodyStatement(forStatment.getBody(), false);
|
||||
}
|
||||
|
||||
private void writeIfStatement(IASTIfStatement ifStatement) {
|
||||
scribe.print(IF);
|
||||
scribe.noNewLines();
|
||||
if (ifStatement instanceof ICPPASTIfStatement) {
|
||||
ICPPASTIfStatement cppIfStatment = (ICPPASTIfStatement) ifStatement;
|
||||
|
||||
if(cppIfStatment.getConditionDeclaration() == null) {
|
||||
cppIfStatment.getConditionExpression().accept(visitor);
|
||||
} else {
|
||||
writeDeclarationWithoutSemicolon(cppIfStatment.getConditionDeclaration());
|
||||
}
|
||||
} else {
|
||||
ifStatement.getConditionExpression().accept(visitor);
|
||||
}
|
||||
|
||||
scribe.print(')');
|
||||
scribe.newLines();
|
||||
nextCompoundNoNewLine();
|
||||
IASTStatement elseClause = ifStatement.getElseClause();
|
||||
writeBodyStatement(ifStatement.getThenClause(), elseClause != null ? true : false);
|
||||
|
||||
if(elseClause != null){
|
||||
scribe.print(ELSE);
|
||||
nextCompoundNoNewLine();
|
||||
writeBodyStatement(elseClause, false);
|
||||
}
|
||||
}
|
||||
|
||||
protected void writeDeclarationWithoutSemicolon(
|
||||
IASTDeclaration declaration) {
|
||||
declWriter.writeDeclaration(declaration, false);
|
||||
}
|
||||
|
||||
private void writeBreakStatement(IASTBreakStatement statement) {
|
||||
scribe.print(BREAK);
|
||||
scribe.printSemicolon();
|
||||
}
|
||||
|
||||
private void writeContinueStatement(IASTContinueStatement statement) {
|
||||
scribe.print(CONTINUE);
|
||||
scribe.printSemicolon();
|
||||
}
|
||||
|
||||
private void writeLabelStatement(IASTLabelStatement labelStatement) {
|
||||
labelStatement.getName().accept(visitor);
|
||||
scribe.print(':');
|
||||
scribe.newLine();
|
||||
labelStatement.getNestedStatement().accept(visitor);
|
||||
}
|
||||
|
||||
private void writeGotoStatement(IASTGotoStatement gotoStatement) {
|
||||
scribe.print(GOTO);
|
||||
gotoStatement.getName().accept(visitor);
|
||||
scribe.printSemicolon();
|
||||
}
|
||||
|
||||
private void writeReturnStatement(IASTReturnStatement returnStatement) {
|
||||
scribe.noNewLines();
|
||||
scribe.print(RETURN);
|
||||
IASTExpression returnValue = returnStatement.getReturnValue();
|
||||
if(returnValue != null){
|
||||
scribe.printSpaces(1);
|
||||
returnValue.accept(visitor);
|
||||
}
|
||||
scribe.newLines();
|
||||
scribe.printSemicolon();
|
||||
}
|
||||
|
||||
private void writeNullStatement(IASTNullStatement nullStmt) {
|
||||
scribe.printSemicolon();
|
||||
}
|
||||
|
||||
private void writeDeclarationStatement(IASTDeclarationStatement decStmt) {
|
||||
decStmt.getDeclaration().accept(visitor);
|
||||
}
|
||||
|
||||
private void writeExpressionStatement(IASTExpressionStatement expStmt) {
|
||||
expStmt.getExpression().accept(visitor);
|
||||
scribe.printSemicolon();
|
||||
}
|
||||
|
||||
private void writeCatchHandler(ICPPASTCatchHandler catchStatement) {
|
||||
scribe.print(CATCH);
|
||||
if (catchStatement.isCatchAll()) {
|
||||
scribe.print(VAR_ARGS);
|
||||
} else {
|
||||
scribe.noSemicolon();
|
||||
scribe.noNewLines();
|
||||
catchStatement.getDeclaration().accept(visitor);
|
||||
scribe.newLines();
|
||||
}
|
||||
scribe.print(')');
|
||||
writeBodyStatement(catchStatement.getCatchBody(), true);
|
||||
}
|
||||
|
||||
private void writeTryBlockStatement(ICPPASTTryBlockStatement tryStatement) {
|
||||
scribe.print(TRY);
|
||||
tryStatement.getTryBody().accept(visitor);
|
||||
for (ICPPASTCatchHandler catchStatement : tryStatement.getCatchHandlers()) {
|
||||
writeStatement(catchStatement, false);
|
||||
}
|
||||
}
|
||||
|
||||
private void writeWhileStatement(IASTWhileStatement whileStatment) {
|
||||
scribe.print(WHILE);
|
||||
scribe.noNewLines();
|
||||
if (whileStatment instanceof ICPPASTWhileStatement) {
|
||||
ICPPASTWhileStatement cppWhileStatment = (ICPPASTWhileStatement) whileStatment;
|
||||
if(cppWhileStatment.getConditionDeclaration() == null) {
|
||||
cppWhileStatment.getCondition().accept(visitor);
|
||||
} else {
|
||||
writeDeclarationWithoutSemicolon(cppWhileStatment.getConditionDeclaration());
|
||||
}
|
||||
} else {
|
||||
whileStatment.getCondition().accept(visitor);
|
||||
}
|
||||
scribe.print(')');
|
||||
scribe.newLines();
|
||||
nextCompoundNoNewLine();
|
||||
writeBodyStatement(whileStatment.getBody(), false);
|
||||
}
|
||||
|
||||
private void writeCaseStatement(IASTCaseStatement caseStatement) {
|
||||
nextCompoundIndentationLevelOneMore();
|
||||
|
||||
if(!switchIsNew){
|
||||
scribe.decrementIndentationLevel();
|
||||
}
|
||||
scribe.print(CASE);
|
||||
caseStatement.getExpression().accept(visitor);
|
||||
scribe.print(':');
|
||||
scribe.incrementIndentationLevel();
|
||||
switchIsNew = false;
|
||||
}
|
||||
|
||||
private void writeSwitchStatement(IASTSwitchStatement switchStatement) {
|
||||
switchIsNew = true;
|
||||
|
||||
scribe.print(SWITCH_BRACKET);
|
||||
scribe.noNewLines();
|
||||
if (switchStatement instanceof ICPPASTSwitchStatement) {
|
||||
ICPPASTSwitchStatement cppSwitchStatement = (ICPPASTSwitchStatement) switchStatement;
|
||||
if(cppSwitchStatement.getControllerDeclaration() == null) {
|
||||
cppSwitchStatement.getControllerExpression().accept(visitor);
|
||||
} else {
|
||||
declWriter.writeDeclaration(cppSwitchStatement.getControllerDeclaration(), false);
|
||||
}
|
||||
} else {
|
||||
switchStatement.getControllerExpression().accept(visitor);
|
||||
}
|
||||
scribe.print(')');
|
||||
scribe.newLines();
|
||||
nextCompoundNoNewLine();
|
||||
writeBodyStatement(switchStatement.getBody(), false);
|
||||
|
||||
switchIsNew = false;
|
||||
}
|
||||
|
||||
private void writeDefaultStatement(IASTDefaultStatement defaultStatement) {
|
||||
nextCompoundIndentationLevelOneMore();
|
||||
|
||||
if(!switchIsNew){
|
||||
scribe.decrementIndentationLevel();
|
||||
}
|
||||
scribe.print(DEFAULT);
|
||||
scribe.incrementIndentationLevel();
|
||||
switchIsNew = false;
|
||||
}
|
||||
|
||||
private void writeCompoundStatement(IASTCompoundStatement compoundStatement) {
|
||||
scribe.printLBrace();
|
||||
scribe.newLine();
|
||||
for (IASTStatement statements : compoundStatement.getStatements()) {
|
||||
statements.accept(visitor);
|
||||
}
|
||||
|
||||
if(hasFreestandingComments(compoundStatement)) {
|
||||
writeFreeStandingComments(compoundStatement);
|
||||
}
|
||||
|
||||
if(decrementIndentationLevelOneMore){
|
||||
scribe.decrementIndentationLevel();
|
||||
decrementIndentationLevelOneMore = false;
|
||||
}
|
||||
scribe.printRBrace();
|
||||
}
|
||||
|
||||
protected void writeBodyStatement(IASTStatement statement, boolean isDoStatement) {
|
||||
if (statement instanceof IASTCompoundStatement){
|
||||
//TODO hsr existiert noch eine methode
|
||||
statement.accept(visitor);
|
||||
if(!isDoStatement){
|
||||
scribe.newLine();
|
||||
}
|
||||
compoundNoNewLine = false;
|
||||
} else if (statement instanceof IASTNullStatement){
|
||||
statement.accept(visitor);
|
||||
scribe.newLine();
|
||||
} else {
|
||||
scribe.incrementIndentationLevel();
|
||||
scribe.newLine();
|
||||
statement.accept(visitor);
|
||||
scribe.decrementIndentationLevel();
|
||||
scribe.newLine();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Write no new Line after the next Compound-Statement
|
||||
*
|
||||
*/
|
||||
protected void nextCompoundNoNewLine(){
|
||||
compoundNoNewLine = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indent one time more at the end (before the closing Brackets)
|
||||
* of a Compound-Statement
|
||||
*
|
||||
*/
|
||||
protected void nextCompoundIndentationLevelOneMore(){
|
||||
decrementIndentationLevelOneMore = true;
|
||||
}
|
||||
|
||||
protected int writeMixedStatement(IASTStatement statement) {
|
||||
IFile file = FileHelper.getIFilefromIASTNode(statement);
|
||||
int offset = statement.getFileLocation().getNodeOffset();
|
||||
int length = statement.getFileLocation().getNodeLength();
|
||||
String code =FileContentHelper.getContent(file, offset, length);
|
||||
|
||||
scribe.println(code);
|
||||
return ASTVisitor.PROCESS_SKIP;
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue