Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/insertbefore/ArraySizeExpressionTest.java')
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/insertbefore/ArraySizeExpressionTest.java65
1 files changed, 65 insertions, 0 deletions
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/insertbefore/ArraySizeExpressionTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/insertbefore/ArraySizeExpressionTest.java
new file mode 100644
index 00000000000..caae9c52925
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/insertbefore/ArraySizeExpressionTest.java
@@ -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();
+
+ }
+}

Back to the top