summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpelder2007-06-01 16:26:19 (EDT)
committerpelder2007-06-01 16:26:19 (EDT)
commitb90ede1920bca18583181e1d713ee9d832d18d7a (patch)
tree804d7c77cc63e82d68e311b3d082013ca31c08f2
parente2923ee699865e27c4c84415cc573cf532b8560c (diff)
downloadorg.eclipse.jet-b90ede1920bca18583181e1d713ee9d832d18d7a.zip
org.eclipse.jet-b90ede1920bca18583181e1d713ee9d832d18d7a.tar.gz
org.eclipse.jet-b90ede1920bca18583181e1d713ee9d832d18d7a.tar.bz2
[190568] JET AST Visitor does not always call preVisit and postVisit
-rw-r--r--plugins/org.eclipse.jet.core/src/org/eclipse/jet/core/parser/ast/JETCompilationUnit.java4
-rw-r--r--plugins/org.eclipse.jet.core/src/org/eclipse/jet/core/parser/ast/XMLBodyElement.java4
-rw-r--r--tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/compiler/TestCompilationHelper.java163
3 files changed, 167 insertions, 4 deletions
diff --git a/plugins/org.eclipse.jet.core/src/org/eclipse/jet/core/parser/ast/JETCompilationUnit.java b/plugins/org.eclipse.jet.core/src/org/eclipse/jet/core/parser/ast/JETCompilationUnit.java
index 3501c50..31b5b6a 100644
--- a/plugins/org.eclipse.jet.core/src/org/eclipse/jet/core/parser/ast/JETCompilationUnit.java
+++ b/plugins/org.eclipse.jet.core/src/org/eclipse/jet/core/parser/ast/JETCompilationUnit.java
@@ -10,7 +10,7 @@
*
* </copyright>
*
- * $Id: JETCompilationUnit.java,v 1.4 2007/04/12 18:02:42 pelder Exp $
+ * $Id: JETCompilationUnit.java,v 1.5 2007/06/01 20:26:19 pelder Exp $
* /
*******************************************************************************/
@@ -125,7 +125,7 @@ public final class JETCompilationUnit extends JETASTElement {
if (visitChildren) {
for (Iterator i = getBodyElements().iterator(); i.hasNext();) {
JETASTElement element = (JETASTElement) i.next();
- element.accept0(visitor);
+ element.accept(visitor);
}
}
visitor.endVisit(this);
diff --git a/plugins/org.eclipse.jet.core/src/org/eclipse/jet/core/parser/ast/XMLBodyElement.java b/plugins/org.eclipse.jet.core/src/org/eclipse/jet/core/parser/ast/XMLBodyElement.java
index 3489475..13d0f34 100644
--- a/plugins/org.eclipse.jet.core/src/org/eclipse/jet/core/parser/ast/XMLBodyElement.java
+++ b/plugins/org.eclipse.jet.core/src/org/eclipse/jet/core/parser/ast/XMLBodyElement.java
@@ -10,7 +10,7 @@
*
* </copyright>
*
- * $Id: XMLBodyElement.java,v 1.3 2007/04/12 18:02:42 pelder Exp $
+ * $Id: XMLBodyElement.java,v 1.4 2007/06/01 20:26:19 pelder Exp $
* /
*******************************************************************************/
@@ -95,7 +95,7 @@ public final class XMLBodyElement extends XMLElement {
if (visitChildren) {
for (Iterator i = getBodyElements().iterator(); i.hasNext();) {
JETASTElement element = (JETASTElement) i.next();
- element.accept0(visitor);
+ element.accept(visitor);
}
}
visitor.endVisit(this);
diff --git a/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/compiler/TestCompilationHelper.java b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/compiler/TestCompilationHelper.java
new file mode 100644
index 0000000..963a59b
--- /dev/null
+++ b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/compiler/TestCompilationHelper.java
@@ -0,0 +1,163 @@
+/**
+ *
+ */
+package org.eclipse.jet.tests.compiler;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.util.HashMap;
+import java.util.Map;
+
+import junit.extensions.TestSetup;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IWorkspaceRunnable;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.jet.JET2Platform;
+import org.eclipse.jet.core.parser.ast.JETASTVisitor;
+import org.eclipse.jet.core.parser.ast.JETCompilationUnit;
+import org.eclipse.jet.core.parser.ast.JavaDeclaration;
+import org.eclipse.jet.core.parser.ast.JavaElement;
+import org.eclipse.jet.core.parser.ast.JavaExpression;
+import org.eclipse.jet.core.parser.ast.JavaScriptlet;
+import org.eclipse.jet.internal.compiler.CompilationHelper;
+import org.eclipse.jet.tests.FileUtils;
+import org.eclipse.jface.text.Position;
+
+/**
+ * @author pelder
+ *
+ */
+public class TestCompilationHelper extends TestCase {
+
+ private static final String TEST_PLUGIN_BASE_URL = "platform:/plugin/org.eclipse.jet.tests/data/";
+ private static final String TEST_PROJECT_NAME = TestCompilationHelper.class.getName() + " Tests";
+ protected static IProject project;
+ private CompilationHelper helper;
+
+ public static Test suite() {
+ TestSetup setup = new TestSetup(new TestSuite(TestCompilationHelper.class)) {
+ protected void setUp() throws Exception {
+ setUpAllTests();
+ }
+
+ protected void tearDown() throws Exception {
+ tearDownAllTests();
+ }
+ };
+
+ return setup;
+ }
+
+ protected static void tearDownAllTests() {
+ // TODO Auto-generated method stub
+
+ }
+
+ protected static void setUpAllTests() {
+ String newProjectModel = "<newProjectModel>" +
+ "<project" +
+ " name=\"" + TEST_PROJECT_NAME + "\"" +
+ "/>" +
+ "</newProjectModel>";
+
+ IStatus status = JET2Platform.runTransformOnString("org.eclipse.jet.transforms.newproject", newProjectModel, new NullProgressMonitor());
+ assertTrue("setUpAllTests", status.isOK());
+ try {
+ ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable() {
+
+ public void run(IProgressMonitor monitor) throws CoreException {
+ // TODO Auto-generated method stub
+
+ }}, new NullProgressMonitor());
+ } catch (CoreException e) {
+ fail(e.getMessage());
+ }
+
+ project = ResourcesPlugin.getWorkspace().getRoot().getProject(TEST_PROJECT_NAME);
+ assertTrue("Test project exists", project.exists());
+
+ }
+
+ protected void setUp() throws Exception {
+ helper = new CompilationHelper(project);
+ }
+
+ public void testGetAST() {
+ JETCompilationUnit ast = helper.getAST("templates/main.jet");
+
+ assertNotNull(ast);
+ assertFalse(ast.hasErrors() && ast.hasWarnings());
+ }
+
+ public void testGetASTFromSource() throws MalformedURLException, IOException, CoreException {
+ String source = FileUtils.getFileContents(TEST_PLUGIN_BASE_URL + "simplifiedCompiler/templates/simple.v2.input.jet", true);
+ JETCompilationUnit ast = helper.getASTFromSource(source);
+
+ assertNotNull(ast);
+ assertFalse(ast.hasErrors() && ast.hasWarnings());
+ }
+
+ public void testJavaCode() throws MalformedURLException, IOException, CoreException {
+ String source = FileUtils.getFileContents(TEST_PLUGIN_BASE_URL + "simplifiedCompiler/templates/simple.v2.input.jet", true);
+ JETCompilationUnit ast = helper.getASTFromSource(source);
+
+ assertNotNull(ast);
+ ast.setOutputJavaClassName("_jet_simplev2input");
+ assertFalse(ast.hasErrors() && ast.hasWarnings());
+
+ String code = helper.getJavaCode(ast);
+ String expectedCode = FileUtils.getFileContents(TEST_PLUGIN_BASE_URL + "simplifiedCompiler/templates/simple.v2.input.jet.expected.java", true);
+ assertEquals(expectedCode, code);
+ }
+
+ public void testJavaCode_ast_map() throws MalformedURLException, IOException, CoreException {
+ String source = FileUtils.getFileContents(TEST_PLUGIN_BASE_URL + "alljet2.jet", true);
+ JETCompilationUnit ast = helper.getASTFromSource(source);
+
+ assertNotNull(ast);
+ assertFalse(ast.hasErrors() && ast.hasWarnings());
+
+ final Map elementPositions = new HashMap();
+ final String code = helper.getJavaCode(ast, elementPositions);
+ String expectedCode = FileUtils.getFileContents(TEST_PLUGIN_BASE_URL + "alljet2.jet.expected.java", true);
+ assertEquals(expectedCode, code);
+
+ ast.accept(new JETASTVisitor() {
+ public boolean visit(JavaDeclaration declaration) {
+ checkJavaElement(declaration);
+
+ return true;
+ }
+
+ public boolean visit(JavaExpression expression) {
+ checkJavaElement(expression);
+
+ return true;
+ }
+
+ public boolean visit(JavaScriptlet scriptlet) {
+ checkJavaElement(scriptlet);
+
+ return true;
+ }
+
+ /**
+ * @param element
+ */
+ private void checkJavaElement(JavaElement element) {
+ Position position = (Position) elementPositions.get(element);
+
+ assertEquals(element.getJavaContent(), code.substring(position.offset, position.offset + position.length));
+ }
+ });
+
+ }
+}