You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by ms...@apache.org on 2012/12/28 13:59:01 UTC
svn commit: r1426489 [1/4] - in
/incubator/flex/whiteboard/mschmalle/falconjx:
compiler.jx.tests/src/org/apache/flex/compiler/
compiler.jx.tests/src/org/apache/flex/compiler/internal/
compiler.jx.tests/src/org/apache/flex/compiler/internal/as/ compiler...
Author: mschmalle
Date: Fri Dec 28 12:59:00 2012
New Revision: 1426489
URL: http://svn.apache.org/viewvc?rev=1426489&view=rev
Log:
Flex:FalconJx
- Major refactor of package structure
- emitters for js and documents and each target production are now abstract
- all tests pass
Added:
incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/compiler/
incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/compiler/internal/
incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/compiler/internal/as/
incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/compiler/internal/as/codegen/
incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/compiler/internal/as/codegen/TestAccessorMembers.java (with props)
incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/compiler/internal/as/codegen/TestBase.java (with props)
incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/compiler/internal/as/codegen/TestClass.java (with props)
incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/compiler/internal/as/codegen/TestExpressions.java (with props)
incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/compiler/internal/as/codegen/TestFieldMembers.java (with props)
incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/compiler/internal/as/codegen/TestInterface.java (with props)
incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/compiler/internal/as/codegen/TestMethodMembers.java (with props)
incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/compiler/internal/as/codegen/TestPackage.java (with props)
incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/compiler/internal/as/codegen/TestStatements.java (with props)
incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/compiler/internal/as/codegen/TestWalkerBase.java (with props)
incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/compiler/internal/js/
incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/compiler/internal/js/codegen/
incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/compiler/internal/js/codegen/TestGoogEmiter.java (with props)
incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/compiler/internal/js/codegen/goog/
incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/compiler/internal/js/codegen/goog/TestGoogPackage.java (with props)
incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/compiler/utils/
incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/compiler/utils/EnvProperties.java (with props)
incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/as/codegen/
incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/as/codegen/IASEmitter.java (with props)
incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/as/codegen/IASWriter.java (with props)
incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/as/codegen/IDocEmitter.java (with props)
incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/as/codegen/ASAfterNodeStrategy.java (with props)
incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/as/codegen/ASBeforeNodeStrategy.java (with props)
incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/as/codegen/ASBlockWalker.java (with props)
incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/as/driver/
incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/as/driver/ASBackend.java (with props)
incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/as/visitor/
incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/as/visitor/ASNodeHandler.java (with props)
incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/as/visitor/ASNodeSwitch.java (with props)
incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/as/visitor/BeforeAfterStrategy.java (with props)
incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/js/codegen/
incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/js/codegen/JSDocEmitter.java (with props)
incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/js/codegen/JSEmitter.java (with props)
incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/js/codegen/JSFilterWriter.java (with props)
incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/js/codegen/JSSharedData.java (with props)
incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/js/codegen/JSWriter.java (with props)
incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/js/codegen/goog/
incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/js/codegen/goog/JSGoogDocEmitter.java (with props)
incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/js/codegen/goog/JSGoogEmitter.java (with props)
incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/js/driver/
incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/js/driver/JSApplication.java (with props)
incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/js/driver/JSBackend.java (with props)
incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/js/driver/JSCompilationUnit.java (with props)
incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/js/driver/JSSourceFileHandler.java (with props)
incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/js/driver/goog/
incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/js/driver/goog/GoogBackend.java (with props)
incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/js/codegen/
incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/js/codegen/IJSDocEmitter.java (with props)
incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/js/codegen/IJSEmitter.java (with props)
incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/js/codegen/IJSWriter.java (with props)
incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/js/codegen/goog/
incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/js/codegen/goog/IJSGoogDocEmitter.java (with props)
incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/js/codegen/goog/IJSGoogEmitter.java (with props)
Removed:
incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/js/
incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/as/IASEmitter.java
incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/as/IASWriter.java
incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/driver/
incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/js/codgen/
incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/visitor/
incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/js/IJSDocEmitter.java
incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/js/IJSEmitter.java
incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/js/IJSWriter.java
Modified:
incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/clients/IBackend.java
incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/clients/MXMLJSC.java
incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/as/codegen/ASEmitter.java
incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/as/codegen/ASWriter.java
incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/targets/JSTarget.java
incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/visitor/IASBlockVisitor.java
Added: incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/compiler/internal/as/codegen/TestAccessorMembers.java
URL: http://svn.apache.org/viewvc/incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/compiler/internal/as/codegen/TestAccessorMembers.java?rev=1426489&view=auto
==============================================================================
--- incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/compiler/internal/as/codegen/TestAccessorMembers.java (added)
+++ incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/compiler/internal/as/codegen/TestAccessorMembers.java Fri Dec 28 12:59:00 2012
@@ -0,0 +1,110 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.flex.compiler.internal.as.codegen;
+
+import org.apache.flex.compiler.tree.as.IAccessorNode;
+import org.apache.flex.compiler.tree.as.IFileNode;
+import org.junit.Test;
+
+/**
+ * This class tests the production of valid ActionScript3 code for Class
+ * Accessor members.
+ *
+ * @author Michael Schmalle
+ */
+public class TestAccessorMembers extends TestWalkerBase
+{
+ //--------------------------------------------------------------------------
+ // Accessor
+ //--------------------------------------------------------------------------
+
+ @Test
+ public void testGetAccessor()
+ {
+ IAccessorNode node = getAccessor("function get foo():int{return -1;}");
+ visitor.visitFunction(node);
+ assertOut("function get foo():int {\n\treturn -1;\n}");
+ }
+
+ @Test
+ public void testGetAccessor_withNamespace()
+ {
+ IAccessorNode node = getAccessor("public function get foo():int{return -1;}");
+ visitor.visitFunction(node);
+ assertOut("public function get foo():int {\n\treturn -1;\n}");
+ }
+
+ @Test
+ public void testGetAccessor_withNamespaceOverride()
+ {
+ IAccessorNode node = getAccessor("public override function get foo():int{return -1;}");
+ visitor.visitFunction(node);
+ assertOut("public override function get foo():int {\n\treturn -1;\n}");
+ }
+
+ @Test
+ public void testGetAccessor_withStatic()
+ {
+ IAccessorNode node = getAccessor("public static function get foo():int{return -1;}");
+ visitor.visitFunction(node);
+ assertOut("public static function get foo():int {\n\treturn -1;\n}");
+ }
+
+ @Test
+ public void testSetAccessor()
+ {
+ IAccessorNode node = getAccessor("function set foo(value:int):void{}");
+ visitor.visitFunction(node);
+ assertOut("function set foo(value:int):void {\n}");
+ }
+
+ @Test
+ public void testSetAccessor_withNamespace()
+ {
+ IAccessorNode node = getAccessor("public function set foo(value:int):void{}");
+ visitor.visitFunction(node);
+ assertOut("public function set foo(value:int):void {\n}");
+ }
+
+ @Test
+ public void testSetAccessor_withNamespaceOverride()
+ {
+ IAccessorNode node = getAccessor("public override function set foo(value:int):void{}");
+ visitor.visitFunction(node);
+ assertOut("public override function set foo(value:int):void {\n}");
+ }
+
+ @Test
+ public void testSetAccessor_withStatic()
+ {
+ IAccessorNode node = getAccessor("public static function set foo(value:int):void{}");
+ visitor.visitFunction(node);
+ assertOut("public static function set foo(value:int):void {\n}");
+ }
+
+ protected IAccessorNode getAccessor(String code)
+ {
+ String source = "package {public class A {" + code + "}}";
+ IFileNode node = getFileNode(source);
+ IAccessorNode child = (IAccessorNode) findFirstDescendantOfType(node,
+ IAccessorNode.class);
+ return child;
+ }
+}
Propchange: incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/compiler/internal/as/codegen/TestAccessorMembers.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/compiler/internal/as/codegen/TestBase.java
URL: http://svn.apache.org/viewvc/incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/compiler/internal/as/codegen/TestBase.java?rev=1426489&view=auto
==============================================================================
--- incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/compiler/internal/as/codegen/TestBase.java (added)
+++ incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/compiler/internal/as/codegen/TestBase.java Fri Dec 28 12:59:00 2012
@@ -0,0 +1,224 @@
+package org.apache.flex.compiler.internal.as.codegen;
+
+import static org.junit.Assert.assertNotNull;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.apache.flex.compiler.clients.MXMLJSC;
+import org.apache.flex.compiler.internal.projects.FlexProject;
+import org.apache.flex.compiler.internal.projects.FlexProjectConfigurator;
+import org.apache.flex.compiler.internal.tree.as.FunctionNode;
+import org.apache.flex.compiler.internal.units.SourceCompilationUnitFactory;
+import org.apache.flex.compiler.internal.workspaces.Workspace;
+import org.apache.flex.compiler.mxml.IMXMLNamespaceMapping;
+import org.apache.flex.compiler.mxml.MXMLNamespaceMapping;
+import org.apache.flex.compiler.problems.ICompilerProblem;
+import org.apache.flex.compiler.tree.as.IASNode;
+import org.apache.flex.compiler.tree.as.IBinaryOperatorNode;
+import org.apache.flex.compiler.tree.as.IDynamicAccessNode;
+import org.apache.flex.compiler.tree.as.IExpressionNode;
+import org.apache.flex.compiler.tree.as.IFileNode;
+import org.apache.flex.compiler.tree.as.IUnaryOperatorNode;
+import org.apache.flex.compiler.units.ICompilationUnit;
+import org.apache.flex.compiler.utils.EnvProperties;
+import org.apache.flex.utils.FilenameNormalization;
+import org.junit.Before;
+
+public class TestBase
+{
+ protected void compileJS(String path)
+ {
+ // Construct a command line which simply loads the project's config file.
+ String playerglobalHome = System.getenv("PLAYERGLOBAL_HOME");
+ assertNotNull("Environment variable PLAYERGLOBAL_HOME is not set",
+ playerglobalHome);
+
+ String flexHome = System.getenv("FLEX_HOME");
+ assertNotNull("Environment variable FLEX_HOME is not set", flexHome);
+
+ String configFile = flexHome + "/frameworks/flex-config.xml";
+ String[] args = new String[] { "-load-config=" + configFile,
+ "+env.PLAYERGLOBAL_HOME=" + playerglobalHome,
+ "+playerglobal.version=11.1",
+ "-define=CONFIG::performanceInstrumentation,false", "" + path };
+
+ MXMLJSC.main(args);
+ }
+
+ protected List<ICompilerProblem> errors;
+
+ private static EnvProperties env = EnvProperties.initiate();
+
+ protected static Workspace workspace = new Workspace();
+
+ protected FlexProject project;
+
+ @Before
+ public void setUp()
+ {
+ assertNotNull("Environment variable FLEX_HOME is not set", env.SDK);
+ assertNotNull("Environment variable PLAYERGLOBAL_HOME is not set",
+ env.FPSDK);
+
+ errors = new ArrayList<ICompilerProblem>();
+
+ project = new FlexProject(workspace);
+ FlexProjectConfigurator.configure(project);
+ }
+
+ protected IASNode findFirstDescendantOfType(IASNode node,
+ Class<? extends IASNode> nodeType)
+ {
+ int n = node.getChildCount();
+ for (int i = 0; i < n; i++)
+ {
+ IASNode child = node.getChild(i);
+ if (child instanceof FunctionNode)
+ {
+ ((FunctionNode) child).parseFunctionBody(errors);
+ }
+ if (nodeType.isInstance(child))
+ return child;
+
+ IASNode found = findFirstDescendantOfType(child, nodeType);
+ if (found != null)
+ return found;
+ }
+
+ return null;
+ }
+
+ protected IFileNode getFileNode(String code)
+ {
+ String tempDir = FilenameNormalization.normalize("temp"); // ensure this exists
+
+ File tempASFile = null;
+ try
+ {
+ tempASFile = File.createTempFile(getClass().getSimpleName(), ".as",
+ new File(tempDir));
+ tempASFile.deleteOnExit();
+
+ BufferedWriter out = new BufferedWriter(new FileWriter(tempASFile));
+ out.write(code);
+ out.close();
+ }
+ catch (IOException e1)
+ {
+ e1.printStackTrace();
+ }
+
+ List<File> sourcePath = new ArrayList<File>();
+ sourcePath.add(new File(tempDir));
+ project.setSourcePath(sourcePath);
+
+ // Compile the code against playerglobal.swc.
+ List<File> libraries = new ArrayList<File>();
+ libraries.add(new File(FilenameNormalization.normalize(env.FPSDK
+ + "\\11.1\\playerglobal.swc")));
+ libraries.add(new File(FilenameNormalization.normalize(env.SDK
+ + "\\frameworks\\libs\\framework.swc")));
+ libraries.add(new File(FilenameNormalization.normalize(env.SDK
+ + "\\frameworks\\libs\\rpc.swc")));
+ libraries.add(new File(FilenameNormalization.normalize(env.SDK
+ + "\\frameworks\\libs\\spark.swc")));
+ project.setLibraries(libraries);
+
+ // Use the MXML 2009 manifest.
+ List<IMXMLNamespaceMapping> namespaceMappings = new ArrayList<IMXMLNamespaceMapping>();
+ IMXMLNamespaceMapping mxml2009 = new MXMLNamespaceMapping(
+ "http://ns.adobe.com/mxml/2009", env.SDK
+ + "\\frameworks\\mxml-2009-manifest.xml");
+ namespaceMappings.add(mxml2009);
+ project.setNamespaceMappings(namespaceMappings);
+
+ ICompilationUnit cu = null;
+ String normalizedMainFileName = FilenameNormalization
+ .normalize(tempASFile.getAbsolutePath());
+
+ SourceCompilationUnitFactory compilationUnitFactory = project
+ .getSourceCompilationUnitFactory();
+ File normalizedMainFile = new File(normalizedMainFileName);
+ if (compilationUnitFactory.canCreateCompilationUnit(normalizedMainFile))
+ {
+ Collection<ICompilationUnit> mainFileCompilationUnits = workspace
+ .getCompilationUnits(normalizedMainFileName, project);
+ for (ICompilationUnit cu2 : mainFileCompilationUnits)
+ {
+ if (cu2 != null)
+ cu = cu2;
+ }
+ }
+
+ // Build the AST.
+ IFileNode fileNode = null;
+ try
+ {
+ fileNode = (IFileNode) cu.getSyntaxTreeRequest().get().getAST();
+ }
+ catch (InterruptedException e)
+ {
+ e.printStackTrace();
+ }
+
+ return fileNode;
+ }
+
+ protected IASNode getNode(String code, Class<? extends IASNode> type)
+ {
+ String source = "package {public class A {function a():void {" + code
+ + "}}";
+ IFileNode node = getFileNode(source);
+ if (type.isInstance(node))
+ return node;
+ IASNode child = findFirstDescendantOfType(node, type);
+ return child;
+ }
+
+ protected IExpressionNode getExpressionNode(String code,
+ Class<? extends IASNode> type)
+ {
+ String source = "package {public class A {function a():void {" + code
+ + "}}";
+ IFileNode node = getFileNode(source);
+ IExpressionNode child = (IExpressionNode) findFirstDescendantOfType(
+ node, type);
+ return child;
+ }
+
+ protected IUnaryOperatorNode getUnaryNode(String code)
+ {
+ String source = "package {public class A {function a():void {" + code
+ + "}}";
+ IFileNode node = getFileNode(source);
+ IUnaryOperatorNode child = (IUnaryOperatorNode) findFirstDescendantOfType(
+ node, IUnaryOperatorNode.class);
+ return child;
+ }
+
+ protected IBinaryOperatorNode getBinaryNode(String code)
+ {
+ String source = "package {public class A {function a():void {" + code
+ + "}}";
+ IFileNode node = getFileNode(source);
+ IBinaryOperatorNode child = (IBinaryOperatorNode) findFirstDescendantOfType(
+ node, IBinaryOperatorNode.class);
+ return child;
+ }
+
+ protected IDynamicAccessNode getDynamicAccessNode(String code)
+ {
+ String source = "package {public class A {function a():void {" + code
+ + "}}";
+ IFileNode node = getFileNode(source);
+ IDynamicAccessNode child = (IDynamicAccessNode) findFirstDescendantOfType(
+ node, IDynamicAccessNode.class);
+ return child;
+ }
+}
Propchange: incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/compiler/internal/as/codegen/TestBase.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/compiler/internal/as/codegen/TestClass.java
URL: http://svn.apache.org/viewvc/incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/compiler/internal/as/codegen/TestClass.java?rev=1426489&view=auto
==============================================================================
--- incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/compiler/internal/as/codegen/TestClass.java (added)
+++ incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/compiler/internal/as/codegen/TestClass.java Fri Dec 28 12:59:00 2012
@@ -0,0 +1,209 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.flex.compiler.internal.as.codegen;
+
+import org.apache.flex.compiler.tree.as.IClassNode;
+import org.apache.flex.compiler.tree.as.IFileNode;
+import org.junit.Test;
+
+/**
+ * This class tests the production of valid ActionScript3 code for Class
+ * production.
+ *
+ * @author Michael Schmalle
+ */
+public class TestClass extends TestWalkerBase
+{
+ //--------------------------------------------------------------------------
+ // Class
+ //--------------------------------------------------------------------------
+
+ @Test
+ public void testSimple()
+ {
+ IClassNode node = getClassNode("public class A{}");
+ visitor.visitClass(node);
+ assertOut("public class A {\n}");
+ }
+
+ @Test
+ public void testSimpleInternal()
+ {
+ IClassNode node = getClassNode("internal class A{}");
+ visitor.visitClass(node);
+ assertOut("internal class A {\n}");
+ }
+
+ @Test
+ public void testSimpleFinal()
+ {
+ IClassNode node = getClassNode("public final class A{}");
+ visitor.visitClass(node);
+ assertOut("public final class A {\n}");
+ }
+
+ @Test
+ public void testSimpleExtends()
+ {
+ IClassNode node = getClassNode("public class A extends B {}");
+ visitor.visitClass(node);
+ assertOut("public class A extends B {\n}");
+ }
+
+ @Test
+ public void testSimpleImplements()
+ {
+ IClassNode node = getClassNode("public class A implements IA {}");
+ visitor.visitClass(node);
+ assertOut("public class A implements IA {\n}");
+ }
+
+ @Test
+ public void testSimpleImplementsMultiple()
+ {
+ IClassNode node = getClassNode("public class A implements IA, IB, IC {}");
+ visitor.visitClass(node);
+ assertOut("public class A implements IA, IB, IC {\n}");
+ }
+
+ @Test
+ public void testSimpleExtendsImplements()
+ {
+ IClassNode node = getClassNode("public class A extends B implements IA {}");
+ visitor.visitClass(node);
+ assertOut("public class A extends B implements IA {\n}");
+ }
+
+ @Test
+ public void testSimpleExtendsImplementsMultiple()
+ {
+ IClassNode node = getClassNode("public class A extends B implements IA, IB, IC {}");
+ visitor.visitClass(node);
+ assertOut("public class A extends B implements IA, IB, IC {\n}");
+ }
+
+ @Test
+ public void testSimpleFinalExtendsImplementsMultiple()
+ {
+ IClassNode node = getClassNode("public final class A extends B implements IA, IB, IC {}");
+ visitor.visitClass(node);
+ assertOut("public final class A extends B implements IA, IB, IC {\n}");
+ }
+
+ @Test
+ public void testQualifiedExtendsImplementsMultiple()
+ {
+ IClassNode node = getClassNode("public class A extends goo.B implements foo.bar.IA, goo.foo.IB, baz.boo.IC {}");
+ visitor.visitClass(node);
+ assertOut("public class A extends goo.B implements foo.bar.IA, goo.foo.IB, baz.boo.IC {\n}");
+ }
+
+ @Test
+ public void testConstructor()
+ {
+ IClassNode node = getClassNode("public class A {public function A(){super('foo', 42);}}");
+ visitor.visitClass(node);
+ assertOut("public class A {\n\tpublic function A() {\n\t\tsuper('foo', 42);\n\t}\n}");
+ }
+
+ @Test
+ public void testFields()
+ {
+ IClassNode node = getClassNode("public class A {public var a:Object;protected var b:String; "
+ + "private var c:int; internal var d:uint; var e:Number}");
+ visitor.visitClass(node);
+ assertOut("public class A {\n\tpublic var a:Object;\n\tprotected var b:String;"
+ + "\n\tprivate var c:int;\n\tvar d:uint;\n\tvar e:Number;\n}");
+ }
+
+ @Test
+ public void testConstants()
+ {
+ IClassNode node = getClassNode("public class A {"
+ + "public static const A:int = 42;"
+ + "protected static const B:Number = 42;"
+ + "private static const C:Number = 42;"
+ + "foo_bar static const C:String = 'me' + 'you';");
+ visitor.visitClass(node);
+ assertOut("public class A {\n\tpublic static const A:int = 42;\n\t"
+ + "protected static const B:Number = 42;\n\tprivate static const "
+ + "C:Number = 42;\n\tfoo_bar static const C:String = 'me' + 'you';\n}");
+ }
+
+ @Test
+ public void testAccessors()
+ {
+ IClassNode node = getClassNode("public class A {"
+ + "public function get foo1():Object{return null;}"
+ + "public function set foo1(value:Object):void{}"
+ + "protected function get foo2():Object{return null;}"
+ + "protected function set foo2(value:Object):void{}"
+ + "private function get foo3():Object{return null;}"
+ + "private function set foo3(value:Object):void{}"
+ + "internal function get foo5():Object{return null;}"
+ + "internal function set foo5(value:Object):void{}"
+ + "foo_bar function get foo6():Object{return null;}"
+ + "foo_bar function set foo6(value:Object):void{}" + "}");
+ visitor.visitClass(node);
+ assertOut("public class A {\n\tpublic function get foo1():Object {"
+ + "\n\t\treturn null;\n\t}\n\tpublic function set foo1(value:Object)"
+ + ":void {\n\t}\n\tprotected function get foo2():Object {\n\t\treturn "
+ + "null;\n\t}\n\tprotected function set foo2(value:Object):void "
+ + "{\n\t}\n\tprivate function get foo3():Object {\n\t\treturn null;"
+ + "\n\t}\n\tprivate function set foo3(value:Object):void {\n\t}\n\t"
+ + "function get foo5():Object {\n\t\treturn null;\n\t}\n\tfunction set "
+ + "foo5(value:Object):void {\n\t}\n\tfoo_bar function get foo6():Object "
+ + "{\n\t\treturn null;\n\t}\n\tfoo_bar function set "
+ + "foo6(value:Object):void {\n\t}\n}");
+ }
+
+ @Test
+ public void testMethods()
+ {
+ IClassNode node = getClassNode("public class A {"
+ + "public function foo1():Object{return null;}"
+ + "public final function foo1a():Object{return null;}"
+ + "override public function foo1b():Object{return super.foo1b();}"
+ + "protected function foo2(value:Object):void{}"
+ + "private function foo3(value:Object):void{}"
+ + "internal function foo5(value:Object):void{}"
+ + "foo_bar function foo6(value:Object):void{}"
+ + "public static function foo7(value:Object):void{}"
+ + "foo_bar static function foo7(value:Object):void{}" + "}");
+ visitor.visitClass(node);
+ assertOut("public class A {\n\tpublic function foo1():Object {\n\t\treturn "
+ + "null;\n\t}\n\tpublic final function foo1a():Object {\n\t\treturn "
+ + "null;\n\t}\n\tpublic override function foo1b():Object {\n\t\treturn "
+ + "super.foo1b();\n\t}\n\tprotected function foo2(value:Object):void "
+ + "{\n\t}\n\tprivate function foo3(value:Object):void {\n\t}\n\tfunction "
+ + "foo5(value:Object):void {\n\t}\n\tfoo_bar function foo6(value:Object"
+ + "):void {\n\t}\n\tpublic static function foo7(value:Object):void {\n\t}"
+ + "\n\tfoo_bar static function foo7(value:Object):void {\n\t}\n}");
+ }
+
+ protected IClassNode getClassNode(String code)
+ {
+ String source = "package {" + code + "}";
+ IFileNode node = getFileNode(source);
+ IClassNode child = (IClassNode) findFirstDescendantOfType(node,
+ IClassNode.class);
+ return child;
+ }
+}
Propchange: incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/compiler/internal/as/codegen/TestClass.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/compiler/internal/as/codegen/TestExpressions.java
URL: http://svn.apache.org/viewvc/incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/compiler/internal/as/codegen/TestExpressions.java?rev=1426489&view=auto
==============================================================================
--- incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/compiler/internal/as/codegen/TestExpressions.java (added)
+++ incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/compiler/internal/as/codegen/TestExpressions.java Fri Dec 28 12:59:00 2012
@@ -0,0 +1,713 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.flex.compiler.internal.as.codegen;
+
+import org.apache.flex.compiler.internal.tree.as.ArrayLiteralNode;
+import org.apache.flex.compiler.internal.tree.as.NamespaceAccessExpressionNode;
+import org.apache.flex.compiler.internal.tree.as.ObjectLiteralNode;
+import org.apache.flex.compiler.tree.as.IBinaryOperatorNode;
+import org.apache.flex.compiler.tree.as.IDynamicAccessNode;
+import org.apache.flex.compiler.tree.as.IFunctionCallNode;
+import org.apache.flex.compiler.tree.as.IIfNode;
+import org.apache.flex.compiler.tree.as.IIterationFlowNode;
+import org.apache.flex.compiler.tree.as.IMemberAccessExpressionNode;
+import org.apache.flex.compiler.tree.as.IReturnNode;
+import org.apache.flex.compiler.tree.as.ITernaryOperatorNode;
+import org.apache.flex.compiler.tree.as.IUnaryOperatorNode;
+import org.apache.flex.compiler.tree.as.IVariableNode;
+import org.junit.Ignore;
+import org.junit.Test;
+
+/**
+ * @author Michael Schmalle
+ */
+public class TestExpressions extends TestWalkerBase
+{
+
+ // ILanguageIdentifierNode -> IIdentifierNode
+
+ @Test
+ public void testVisitLanguageIdentifierNode_This()
+ {
+ IMemberAccessExpressionNode node = (IMemberAccessExpressionNode) getNode(
+ "if (a) this.a;", IMemberAccessExpressionNode.class);
+ visitor.visitMemberAccessExpression(node);
+ assertOut("this.a");
+ }
+
+ @Test
+ public void testVisitLanguageIdentifierNode_SuperMember()
+ {
+ IMemberAccessExpressionNode node = (IMemberAccessExpressionNode) getNode(
+ "if (a) super.foo;", IMemberAccessExpressionNode.class);
+ visitor.visitMemberAccessExpression(node);
+ assertOut("super.foo");
+ }
+
+ @Test
+ public void testVisitLanguageIdentifierNode_SuperMethod_1()
+ {
+ // NOTE: This is here as an example that a method call to super
+ // is always held within a IFunctionCallNode, here it's a plain member access
+ IMemberAccessExpressionNode node = (IMemberAccessExpressionNode) getNode(
+ "if (a) super.foo();", IMemberAccessExpressionNode.class);
+ visitor.visitMemberAccessExpression(node);
+ assertOut("super.foo");
+ }
+
+ @Test
+ public void testVisitLanguageIdentifierNode_SuperMethod_2()
+ {
+ IFunctionCallNode node = (IFunctionCallNode) getNode(
+ "if (a) super.foo(a, b, c);", IFunctionCallNode.class);
+ visitor.visitFunctionCall(node);
+ assertOut("super.foo(a, b, c)");
+ }
+
+ @Test
+ public void testVisitLanguageIdentifierNode_This1()
+ {
+ IMemberAccessExpressionNode node = (IMemberAccessExpressionNode) getNode(
+ "if (a) this.a;", IMemberAccessExpressionNode.class);
+
+ visitor.visitMemberAccessExpression(node);
+ assertOut("this.a");
+ }
+
+ @Test
+ public void testVisitLanguageIdentifierNode_This2()
+ {
+ IMemberAccessExpressionNode node = (IMemberAccessExpressionNode) getNode(
+ "if (a) this.a;", IMemberAccessExpressionNode.class);
+
+ visitor.visitMemberAccessExpression(node);
+ assertOut("this.a");
+ }
+
+ //----------------------------------
+ // Primary expression keywords
+ //----------------------------------
+
+ //----------------------------------
+ // Arithmetic
+ //----------------------------------
+
+ @Test
+ public void testVisitBinaryOperatorNode_Plus()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a + b");
+ visitor.visitBinaryOperator(node);
+ assertOut("a + b");
+ }
+
+ @Test
+ public void testVisitBinaryOperatorNode_Minus()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a - b");
+ visitor.visitBinaryOperator(node);
+ assertOut("a - b");
+ }
+
+ @Test
+ public void testVisitBinaryOperatorNode_Divide()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a / b");
+ visitor.visitBinaryOperator(node);
+ assertOut("a / b");
+ }
+
+ @Test
+ public void testVisitBinaryOperatorNode_Modulo()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a % b");
+ visitor.visitBinaryOperator(node);
+ assertOut("a % b");
+ }
+
+ @Test
+ public void testVisitBinaryOperatorNode_Multiply()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a * b");
+ visitor.visitBinaryOperator(node);
+ assertOut("a * b");
+ }
+
+ @Test
+ public void testVisitUnaryOperatorNode_PostIncrement()
+ {
+ IUnaryOperatorNode node = getUnaryNode("a++");
+ visitor.visitUnaryOperator(node);
+ assertOut("a++");
+ }
+
+ @Test
+ public void testVisitUnaryOperatorNode_PreIncrement()
+ {
+ IUnaryOperatorNode node = getUnaryNode("++a");
+ visitor.visitUnaryOperator(node);
+ assertOut("++a");
+ }
+
+ @Test
+ public void testVisitUnaryOperatorNode_PostDecrement()
+ {
+ IUnaryOperatorNode node = getUnaryNode("a--");
+ visitor.visitUnaryOperator(node);
+ assertOut("a--");
+ }
+
+ @Test
+ public void testVisitUnaryOperatorNode_PreDecrement()
+ {
+ IUnaryOperatorNode node = getUnaryNode("--a");
+ visitor.visitUnaryOperator(node);
+ assertOut("--a");
+ }
+
+ //----------------------------------
+ // Arithmetic compound assignment
+ //----------------------------------
+
+ @Test
+ public void testVisitBinaryOperatorNode_PlusAssignment()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a += b");
+ visitor.visitBinaryOperator(node);
+ assertOut("a += b");
+ }
+
+ @Test
+ public void testVisitBinaryOperatorNode_MinusAssignment()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a -= b");
+ visitor.visitBinaryOperator(node);
+ assertOut("a -= b");
+ }
+
+ @Test
+ public void testVisitBinaryOperatorNode_DivideAssignment()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a /= b");
+ visitor.visitBinaryOperator(node);
+ assertOut("a /= b");
+ }
+
+ @Test
+ public void testVisitBinaryOperatorNode_ModuloAssignment()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a %= b");
+ visitor.visitBinaryOperator(node);
+ assertOut("a %= b");
+ }
+
+ @Test
+ public void testVisitBinaryOperatorNode_MultiplyAssignment()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a *= b");
+ visitor.visitBinaryOperator(node);
+ assertOut("a *= b");
+ }
+
+ //----------------------------------
+ // Assignment
+ //----------------------------------
+
+ @Test
+ public void testVisitBinaryOperatorNode_Assignment()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a = b");
+ visitor.visitBinaryOperator(node);
+ assertOut("a = b");
+ }
+
+ //----------------------------------
+ // Bitwise
+ //----------------------------------
+
+ @Test
+ public void testVisitBinaryOperatorNode_BitwiseAnd()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a & b");
+ visitor.visitBinaryOperator(node);
+ assertOut("a & b");
+ }
+
+ @Test
+ public void testVisitBinaryOperatorNode_BitwiseLeftShift()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a << b");
+ visitor.visitBinaryOperator(node);
+ assertOut("a << b");
+ }
+
+ @Test
+ public void testVisitUnaryOperatorNode_BitwiseNot()
+ {
+ IUnaryOperatorNode node = getUnaryNode("~a");
+ visitor.visitUnaryOperator(node);
+ assertOut("~a");
+ }
+
+ @Test
+ public void testVisitBinaryOperatorNode_BitwiseOr()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a | b");
+ visitor.visitBinaryOperator(node);
+ assertOut("a | b");
+ }
+
+ @Test
+ public void testVisitBinaryOperatorNode_BitwiseRightShift()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a >> b");
+ visitor.visitBinaryOperator(node);
+ assertOut("a >> b");
+ }
+
+ @Test
+ public void testVisitBinaryOperatorNode_BitwiseUnsignedRightShift()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a >>> b");
+ visitor.visitBinaryOperator(node);
+ assertOut("a >>> b");
+ }
+
+ @Test
+ public void testVisitBinaryOperatorNode_BitwiseXOR()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a ^ b");
+ visitor.visitBinaryOperator(node);
+ assertOut("a ^ b");
+ }
+
+ //----------------------------------
+ // Bitwise compound assignment
+ //----------------------------------
+
+ @Test
+ public void testVisitBinaryOperatorNode_BitwiseAndAssignment()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a &= b");
+ visitor.visitBinaryOperator(node);
+ assertOut("a &= b");
+ }
+
+ @Test
+ public void testVisitBinaryOperatorNode_BitwiseLeftShiftAssignment()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a <<= b");
+ visitor.visitBinaryOperator(node);
+ assertOut("a <<= b");
+ }
+
+ @Test
+ public void testVisitBinaryOperatorNode_BitwiseOrAssignment()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a |= b");
+ visitor.visitBinaryOperator(node);
+ assertOut("a |= b");
+ }
+
+ @Test
+ public void testVisitBinaryOperatorNode_BitwiseRightShiftAssignment()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a >>= b");
+ visitor.visitBinaryOperator(node);
+ assertOut("a >>= b");
+ }
+
+ @Test
+ public void
+ testVisitBinaryOperatorNode_BitwiseUnsignedRightShiftAssignment()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a >>>= b");
+ visitor.visitBinaryOperator(node);
+ assertOut("a >>>= b");
+ }
+
+ @Test
+ public void testVisitBinaryOperatorNode_BitwiseXORAssignment()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a ^= b");
+ visitor.visitBinaryOperator(node);
+ assertOut("a ^= b");
+ }
+
+ //----------------------------------
+ // Comparison
+ //----------------------------------
+
+ @Test
+ public void testVisitBinaryOperatorNode_Equal()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a == b");
+ visitor.visitBinaryOperator(node);
+ assertOut("a == b");
+ }
+
+ @Test
+ public void testVisitBinaryOperatorNode_GreaterThan()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a > b");
+ visitor.visitBinaryOperator(node);
+ assertOut("a > b");
+ }
+
+ @Test
+ public void testVisitBinaryOperatorNode_GreaterThanEqual()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a >= b");
+ visitor.visitBinaryOperator(node);
+ assertOut("a >= b");
+ }
+
+ @Test
+ public void testVisitBinaryOperatorNode_NotEqual()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a != b");
+ visitor.visitBinaryOperator(node);
+ assertOut("a != b");
+ }
+
+ @Test
+ public void testVisitBinaryOperatorNode_LessThan()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a < b");
+ visitor.visitBinaryOperator(node);
+ assertOut("a < b");
+ }
+
+ @Test
+ public void testVisitBinaryOperatorNode_LessThanEqual()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a <= b");
+ visitor.visitBinaryOperator(node);
+ assertOut("a <= b");
+ }
+
+ @Test
+ public void testVisitBinaryOperatorNode_StrictEqual()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a === b");
+ visitor.visitBinaryOperator(node);
+ assertOut("a === b");
+ }
+
+ @Test
+ public void testVisitBinaryOperatorNode_StrictNotEqual()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a !== b");
+ visitor.visitBinaryOperator(node);
+ assertOut("a !== b");
+ }
+
+ //----------------------------------
+ // Logical
+ //----------------------------------
+
+ @Test
+ public void testVisitBinaryOperatorNode_LogicalAnd()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a && b");
+ visitor.visitBinaryOperator(node);
+ assertOut("a && b");
+ }
+
+ @Test
+ public void testVisitBinaryOperatorNode_LogicalAndAssignment()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a &&= b");
+ visitor.visitBinaryOperator(node);
+ assertOut("a &&= b");
+ }
+
+ @Test
+ public void testVisitUnaryOperatorNode_LogicalNot()
+ {
+ IUnaryOperatorNode node = getUnaryNode("!a");
+ visitor.visitUnaryOperator(node);
+ assertOut("!a");
+ }
+
+ @Test
+ public void testVisitBinaryOperatorNode_LogicalOr()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a || b");
+ visitor.visitBinaryOperator(node);
+ assertOut("a || b");
+ }
+
+ @Test
+ public void testVisitBinaryOperatorNode_LogicalOrAssignment()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a ||= b");
+ visitor.visitBinaryOperator(node);
+ assertOut("a ||= b");
+ }
+
+ //----------------------------------
+ // Other
+ //----------------------------------
+
+ @Test
+ public void testAnonymousFunction()
+ {
+ IVariableNode node = (IVariableNode) getNode("var a = function(){};",
+ IVariableNode.class);
+ visitor.visitVariable(node);
+ assertOut("var a:* = function() {\n}");
+ }
+
+ @Test
+ public void testAnonymousFunctionWithParamsReturn()
+ {
+ IVariableNode node = (IVariableNode) getNode(
+ "var a:Object = function(foo:int, bar:String = 'goo'):int{return -1;};",
+ IVariableNode.class);
+ visitor.visitVariable(node);
+ assertOut("var a:Object = function(foo:int, bar:String = 'goo'):int {\n\treturn -1;\n}");
+ }
+
+ @Test
+ public void testAnonymousFunctionAsArgument()
+ {
+ // TODO (mschmalle) using IIfNode in expressions test, any other way to do this without statement?
+ IIfNode node = (IIfNode) getNode(
+ "if (a) {addListener('foo', function(event:Object):void{doit();});}",
+ IIfNode.class);
+ visitor.visitIf(node);
+ assertOut("if (a) {\n\taddListener('foo', function(event:Object):void {\n\t\tdoit();\n\t});\n}");
+ }
+
+ @Test
+ public void testVisitDynamicAccessNode_1()
+ {
+ IDynamicAccessNode node = getDynamicAccessNode("a[b]");
+ visitor.visitDynamicAccess(node);
+ assertOut("a[b]");
+ }
+
+ @Test
+ public void testVisitDynamicAccessNode_2()
+ {
+ IDynamicAccessNode node = getDynamicAccessNode("a[b[c][d]]");
+ visitor.visitDynamicAccess(node);
+ assertOut("a[b[c][d]]");
+ }
+
+ @Test
+ public void testVisitAs()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a as b");
+ visitor.visitBinaryOperator(node);
+ assertOut("a as b");
+ }
+
+ @Test
+ public void testVisitBinaryOperatorNode_Comma()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a, b");
+ visitor.visitBinaryOperator(node);
+ assertOut("a, b");
+ }
+
+ @Test
+ public void testVisitTernaryOperatorNode()
+ {
+ ITernaryOperatorNode node = (ITernaryOperatorNode) getExpressionNode(
+ "a ? b : c", ITernaryOperatorNode.class);
+ visitor.visitTernaryOperator(node);
+ assertOut("a ? b : c");
+ }
+
+ @Test
+ public void testVisitUnaryOperator_Delete()
+ {
+ IUnaryOperatorNode node = getUnaryNode("delete a");
+ visitor.visitUnaryOperator(node);
+ assertOut("delete a");
+ }
+
+ @Test
+ public void testVisitMemberAccess_1()
+ {
+ IMemberAccessExpressionNode node = (IMemberAccessExpressionNode) getExpressionNode(
+ "a.b", IMemberAccessExpressionNode.class);
+ visitor.visitMemberAccessExpression(node);
+ assertOut("a.b");
+ }
+
+ @Test
+ public void testVisitMemberAccess_2()
+ {
+ IMemberAccessExpressionNode node = (IMemberAccessExpressionNode) getExpressionNode(
+ "a.b.c.d", IMemberAccessExpressionNode.class);
+ visitor.visitMemberAccessExpression(node);
+ assertOut("a.b.c.d");
+ }
+
+ @Test
+ public void testVisitBinaryOperator_In()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a in b");
+ visitor.visitBinaryOperator(node);
+ assertOut("a in b");
+ }
+
+ @Test
+ public void testVisitBinaryOperator_Instancof()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a instanceof b");
+ visitor.visitBinaryOperator(node);
+ assertOut("a instanceof b");
+ }
+
+ @Test
+ public void testVisitBinaryOperator_Is()
+ {
+ IBinaryOperatorNode node = getBinaryNode("a is b");
+ visitor.visitBinaryOperator(node);
+ assertOut("a is b");
+ }
+
+ @Test
+ public void testVisitBinaryOperator_NamespaceAccess_1()
+ {
+ // TODO this needs INamespaceAccessExpressionNode interface
+ NamespaceAccessExpressionNode node = (NamespaceAccessExpressionNode) getExpressionNode(
+ "a::b", NamespaceAccessExpressionNode.class);
+ visitor.visitNamespaceAccessExpression(node);
+ assertOut("a::b");
+ }
+
+ @Test
+ public void testVisitBinaryOperator_NamespaceAccess_2()
+ {
+ // TODO this needs INamespaceAccessExpressionNode interface
+ NamespaceAccessExpressionNode node = (NamespaceAccessExpressionNode) getExpressionNode(
+ "a::b::c", NamespaceAccessExpressionNode.class);
+ visitor.visitNamespaceAccessExpression(node);
+ assertOut("a::b::c");
+ }
+
+ @Test
+ public void testVisitBinaryOperator_New()
+ {
+ IFunctionCallNode node = (IFunctionCallNode) getExpressionNode(
+ "new Object()", IFunctionCallNode.class);
+ visitor.visitFunctionCall(node);
+ assertOut("new Object()");
+ }
+
+ @Test
+ public void testVisitObjectLiteral_1()
+ {
+ ObjectLiteralNode node = (ObjectLiteralNode) getExpressionNode(
+ "a = {a:1}", ObjectLiteralNode.class);
+ visitor.visitLiteral(node);
+ assertOut("{a:1}");
+ }
+
+ @Test
+ public void testVisitObjectLiteral_2()
+ {
+ ObjectLiteralNode node = (ObjectLiteralNode) getExpressionNode(
+ "a = {a:1,b:{c:2,d:{e:4}}}", ObjectLiteralNode.class);
+ visitor.visitLiteral(node);
+ assertOut("{a:1,b:{c:2,d:{e:4}}}");
+ }
+
+ @Test
+ public void testVisitArrayLiteral_1()
+ {
+ ArrayLiteralNode node = (ArrayLiteralNode) getExpressionNode(
+ "a = [0,1,2]", ArrayLiteralNode.class);
+ visitor.visitLiteral(node);
+ assertOut("[0,1,2]");
+ }
+
+ @Test
+ public void testVisitArrayLiteral_2()
+ {
+ ArrayLiteralNode node = (ArrayLiteralNode) getExpressionNode(
+ "a = [0,[0,1,[0,1]],2,[1,2]]", ArrayLiteralNode.class);
+ visitor.visitLiteral(node);
+ assertOut("[0,[0,1,[0,1]],2,[1,2]]");
+ }
+
+ @Test
+ public void testVisitUnaryOperatorNode_Typeof()
+ {
+ IUnaryOperatorNode node = getUnaryNode("typeof(a)");
+ visitor.visitUnaryOperator(node);
+ assertOut("typeof(a)");
+ }
+
+ @Test
+ public void testVisitUnaryOperatorNode_Void()
+ {
+ IUnaryOperatorNode node = getUnaryNode("void a");
+ visitor.visitUnaryOperator(node);
+ assertOut("void a");
+ }
+
+ @Test
+ public void testVisitUnaryOperatorNode_Concate_1()
+ {
+ IBinaryOperatorNode node = getBinaryNode("\"a\" + \"b\"");
+ visitor.visitBinaryOperator(node);
+ assertOut("\"a\" + \"b\"");
+ }
+
+ @Ignore
+ @Test
+ public void testVisitUnaryOperatorNode_Concate_2()
+ {
+ IBinaryOperatorNode node = getBinaryNode("\"a\\\"\" + \"\\\"b\"");
+ visitor.visitBinaryOperator(node);
+ assertOut("\"a\\\"\" + \"\\\"b\"");
+ }
+
+ @Test
+ public void testVisitIterationFlowNode_Break()
+ {
+ IIterationFlowNode node = (IIterationFlowNode) getNode("break",
+ IIterationFlowNode.class);
+ visitor.visitIterationFlow(node);
+ assertOut("break");
+ }
+
+ @Test
+ public void testVisitIterationFlowNode_Continue()
+ {
+ IIterationFlowNode node = (IIterationFlowNode) getNode("continue",
+ IIterationFlowNode.class);
+ visitor.visitIterationFlow(node);
+ assertOut("continue");
+ }
+
+ @Test
+ public void testVisitReturn()
+ {
+ IReturnNode node = (IReturnNode) getNode("return", IReturnNode.class);
+ visitor.visitReturn(node);
+ assertOut("return");
+ }
+}
Propchange: incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/compiler/internal/as/codegen/TestExpressions.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/compiler/internal/as/codegen/TestFieldMembers.java
URL: http://svn.apache.org/viewvc/incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/compiler/internal/as/codegen/TestFieldMembers.java?rev=1426489&view=auto
==============================================================================
--- incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/compiler/internal/as/codegen/TestFieldMembers.java (added)
+++ incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/compiler/internal/as/codegen/TestFieldMembers.java Fri Dec 28 12:59:00 2012
@@ -0,0 +1,175 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.flex.compiler.internal.as.codegen;
+
+import org.apache.flex.compiler.tree.as.IFileNode;
+import org.apache.flex.compiler.tree.as.IVariableNode;
+import org.junit.Test;
+
+/**
+ * This class tests the production of valid ActionScript3 code for Class Field
+ * members.
+ *
+ * @author Michael Schmalle
+ */
+public class TestFieldMembers extends TestWalkerBase
+{
+ /*
+ * Field, Constant, [Namespace]
+ *
+ * var foo;
+ * var foo:int;
+ * var foo:int = 42;
+ * private var foo:int;
+ * private var foo:int = 42;
+ * protected var foo:int;
+ * public var foo:int;
+ */
+
+ //--------------------------------------------------------------------------
+ // Field
+ //--------------------------------------------------------------------------
+
+ @Test
+ public void testField()
+ {
+ IVariableNode node = getField("var foo;");
+ visitor.visitVariable(node);
+ assertOut("var foo:*");
+ }
+
+ @Test
+ public void testField_withType()
+ {
+ IVariableNode node = getField("var foo:int;");
+ visitor.visitVariable(node);
+ assertOut("var foo:int");
+ }
+
+ @Test
+ public void testField_withTypeValue()
+ {
+ IVariableNode node = getField("var foo:int = 420;");
+ visitor.visitVariable(node);
+ assertOut("var foo:int = 420");
+ }
+
+ @Test
+ public void testField_withNamespaceTypeValue()
+ {
+ IVariableNode node = getField("private var foo:int = 420;");
+ visitor.visitVariable(node);
+ assertOut("private var foo:int = 420");
+ }
+
+ @Test
+ public void testField_withCustomNamespaceTypeValue()
+ {
+ IVariableNode node = getField("mx_internal var foo:int = 420;");
+ visitor.visitVariable(node);
+ assertOut("mx_internal var foo:int = 420");
+ }
+
+ @Test
+ public void testField_withNamespaceTypeCollection()
+ {
+ IVariableNode node = getField("protected var foo:Vector.<Foo>;");
+ visitor.visitVariable(node);
+ assertOut("protected var foo:Vector.<Foo>");
+ }
+
+ @Test
+ public void testField_withNamespaceTypeCollectionComplex()
+ {
+ IVariableNode node = getField("protected var foo:Vector.<Vector.<Vector.<Foo>>>;");
+ visitor.visitVariable(node);
+ assertOut("protected var foo:Vector.<Vector.<Vector.<Foo>>>");
+ }
+
+ @Test
+ public void testField_withNamespaceTypeValueComplex()
+ {
+ IVariableNode node = getField("protected var foo:Foo = new Foo('bar', 42);");
+ visitor.visitVariable(node);
+ assertOut("protected var foo:Foo = new Foo('bar', 42)");
+ }
+
+ @Test
+ public void testField_withList()
+ {
+ IVariableNode node = getField("protected var a:int = 4, b:int = 11, c:int = 42;");
+ visitor.visitVariable(node);
+ assertOut("protected var a:int = 4, b:int = 11, c:int = 42");
+ }
+
+ //--------------------------------------------------------------------------
+ // Constant
+ //--------------------------------------------------------------------------
+
+ @Test
+ public void testConstant()
+ {
+ IVariableNode node = getField("static const foo;");
+ visitor.visitVariable(node);
+ // TODO (mschmalle) is * type even possible for a constant?
+ assertOut("static const foo:*");
+ }
+
+ @Test
+ public void testConstant_withType()
+ {
+ IVariableNode node = getField("static const foo:int;");
+ visitor.visitVariable(node);
+ assertOut("static const foo:int");
+ }
+
+ @Test
+ public void testConstant_withTypeValue()
+ {
+ IVariableNode node = getField("static const foo:int = 420;");
+ visitor.visitVariable(node);
+ assertOut("static const foo:int = 420");
+ }
+
+ @Test
+ public void testConstant_withNamespaceTypeValue()
+ {
+ IVariableNode node = getField("private static const foo:int = 420;");
+ visitor.visitVariable(node);
+ assertOut("private static const foo:int = 420");
+ }
+
+ @Test
+ public void testConstant_withCustomNamespaceTypeValue()
+ {
+ IVariableNode node = getField("mx_internal static const foo:int = 420;");
+ visitor.visitVariable(node);
+ assertOut("mx_internal static const foo:int = 420");
+ }
+
+ protected IVariableNode getField(String code)
+ {
+ String source = "package {public class A {" + code + "}}";
+ IFileNode node = getFileNode(source);
+ IVariableNode child = (IVariableNode) findFirstDescendantOfType(node,
+ IVariableNode.class);
+ return child;
+ }
+}
Propchange: incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/compiler/internal/as/codegen/TestFieldMembers.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/compiler/internal/as/codegen/TestInterface.java
URL: http://svn.apache.org/viewvc/incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/compiler/internal/as/codegen/TestInterface.java?rev=1426489&view=auto
==============================================================================
--- incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/compiler/internal/as/codegen/TestInterface.java (added)
+++ incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/compiler/internal/as/codegen/TestInterface.java Fri Dec 28 12:59:00 2012
@@ -0,0 +1,114 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.flex.compiler.internal.as.codegen;
+
+import org.apache.flex.compiler.tree.as.IFileNode;
+import org.apache.flex.compiler.tree.as.IInterfaceNode;
+import org.junit.Test;
+
+/**
+ * This class tests the production of valid ActionScript3 code for Interface
+ * production.
+ *
+ * @author Michael Schmalle
+ */
+public class TestInterface extends TestWalkerBase
+{
+ //--------------------------------------------------------------------------
+ // Interface
+ //--------------------------------------------------------------------------
+
+ @Test
+ public void testSimple()
+ {
+ IInterfaceNode node = getInterfaceNode("public interface IA{}");
+ visitor.visitInterface(node);
+ assertOut("public interface IA {\n}");
+ }
+
+ @Test
+ public void testSimpleExtends()
+ {
+ IInterfaceNode node = getInterfaceNode("public interface IA extends IB{}");
+ visitor.visitInterface(node);
+ assertOut("public interface IA extends IB {\n}");
+ }
+
+ @Test
+ public void testSimpleExtendsMultiple()
+ {
+ IInterfaceNode node = getInterfaceNode("public interface IA extends IB, IC, ID {}");
+ visitor.visitInterface(node);
+ assertOut("public interface IA extends IB, IC, ID {\n}");
+ }
+
+ @Test
+ public void testQualifiedExtendsMultiple()
+ {
+ IInterfaceNode node = getInterfaceNode("public interface IA extends foo.bar.IB, baz.goo.IC, foo.ID {}");
+ visitor.visitInterface(node);
+ assertOut("public interface IA extends foo.bar.IB, baz.goo.IC, foo.ID {\n}");
+ }
+
+ @Test
+ public void testAccessors()
+ {
+ IInterfaceNode node = getInterfaceNode("public interface IA {"
+ + "function get foo1():Object;"
+ + "function set foo1(value:Object):void;}");
+ visitor.visitInterface(node);
+ assertOut("public interface IA {\n\tfunction get foo1():Object;\n\t"
+ + "function set foo1(value:Object):void;\n}");
+ }
+
+ @Test
+ public void testMethods()
+ {
+ IInterfaceNode node = getInterfaceNode("public interface IA {"
+ + "function foo1():Object;"
+ + "function foo1(value:Object):void;}");
+ visitor.visitInterface(node);
+ assertOut("public interface IA {\n\tfunction foo1():Object;\n\t"
+ + "function foo1(value:Object):void;\n}");
+ }
+
+ @Test
+ public void testAccessorsMethods()
+ {
+ IInterfaceNode node = getInterfaceNode("public interface IA {"
+ + "function get foo1():Object;"
+ + "function set foo1(value:Object):void;"
+ + "function baz1():Object;"
+ + "function baz2(value:Object):void;}");
+ visitor.visitInterface(node);
+ assertOut("public interface IA {\n\tfunction get foo1():Object;"
+ + "\n\tfunction set foo1(value:Object):void;\n\tfunction baz1()"
+ + ":Object;\n\tfunction baz2(value:Object):void;\n}");
+ }
+
+ protected IInterfaceNode getInterfaceNode(String code)
+ {
+ String source = "package {" + code + "}";
+ IFileNode node = getFileNode(source);
+ IInterfaceNode child = (IInterfaceNode) findFirstDescendantOfType(node,
+ IInterfaceNode.class);
+ return child;
+ }
+}
Propchange: incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/compiler/internal/as/codegen/TestInterface.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/compiler/internal/as/codegen/TestMethodMembers.java
URL: http://svn.apache.org/viewvc/incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/compiler/internal/as/codegen/TestMethodMembers.java?rev=1426489&view=auto
==============================================================================
--- incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/compiler/internal/as/codegen/TestMethodMembers.java (added)
+++ incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/compiler/internal/as/codegen/TestMethodMembers.java Fri Dec 28 12:59:00 2012
@@ -0,0 +1,158 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.flex.compiler.internal.as.codegen;
+
+import org.apache.flex.compiler.tree.as.IFileNode;
+import org.apache.flex.compiler.tree.as.IFunctionNode;
+import org.junit.Ignore;
+import org.junit.Test;
+
+/**
+ * This class tests the production of valid ActionScript3 code for Class Method
+ * members.
+ *
+ * @author Michael Schmalle
+ */
+public class TestMethodMembers extends TestWalkerBase
+{
+ /*
+ * Method
+ *
+ * function foo(){}
+ * function foo():int{}
+ * function foo(bar):int{}
+ * function foo(bar:String):int{}
+ * function foo(bar:String = "baz"):int{}
+ * function foo(bar:String, baz:int = null):int{}
+ * function foo(bar:String, ...rest):int{}
+ * public function foo(bar:String, baz:int = null):int{}
+ * public static function foo(bar:String, baz:int = null):int{}
+ */
+
+ //--------------------------------------------------------------------------
+ // Method
+ //--------------------------------------------------------------------------
+
+ @Test
+ public void testMethod()
+ {
+ IFunctionNode node = getMethod("function foo(){}");
+ visitor.visitFunction(node);
+ assertOut("function foo() {\n}");
+ }
+
+ @Test
+ public void testMethod_withReturnType()
+ {
+ IFunctionNode node = getMethod("function foo():int{\treturn -1;}");
+ visitor.visitFunction(node);
+ assertOut("function foo():int {\n\treturn -1;\n}");
+ }
+
+ @Test
+ public void testMethod_withParameterReturnType()
+ {
+ IFunctionNode node = getMethod("function foo(bar):int{\treturn -1;}");
+ visitor.visitFunction(node);
+ assertOut("function foo(bar:*):int {\n\treturn -1;\n}");
+ }
+
+ @Test
+ public void testMethod_withParameterTypeReturnType()
+ {
+ IFunctionNode node = getMethod("function foo(bar:String):int{\treturn -1;}");
+ visitor.visitFunction(node);
+ assertOut("function foo(bar:String):int {\n\treturn -1;\n}");
+ }
+
+ @Test
+ public void testMethod_withDefaultParameterTypeReturnType()
+ {
+ IFunctionNode node = getMethod("function foo(bar:String = \"baz\"):int{\treturn -1;}");
+ visitor.visitFunction(node);
+ assertOut("function foo(bar:String = \"baz\"):int {\n\treturn -1;\n}");
+ }
+
+ @Test
+ public void testMethod_withMultipleDefaultParameterTypeReturnType()
+ {
+ IFunctionNode node = getMethod("function foo(bar:String, baz:int = null):int{\treturn -1;}");
+ visitor.visitFunction(node);
+ assertOut("function foo(bar:String, baz:int = null):int {\n\treturn -1;\n}");
+ }
+
+ @Ignore
+ @Test
+ public void testMethod_withRestParameterTypeReturnType()
+ {
+ IFunctionNode node = getMethod("function foo(bar:String, ...rest):int{\treturn -1;}");
+ visitor.visitFunction(node);
+ assertOut("function foo(bar:String, ...rest):int {\n\treturn -1;\n}");
+ }
+
+ @Test
+ public void testMethod_withNamespace()
+ {
+ IFunctionNode node = getMethod("public function foo(bar:String, baz:int = null):int{\treturn -1;}");
+ visitor.visitFunction(node);
+ assertOut("public function foo(bar:String, baz:int = null):int {\n\treturn -1;\n}");
+ }
+
+ @Test
+ public void testMethod_withNamespaceCustom()
+ {
+ IFunctionNode node = getMethod("mx_internal function foo(bar:String, baz:int = null):int{\treturn -1;}");
+ visitor.visitFunction(node);
+ assertOut("mx_internal function foo(bar:String, baz:int = null):int {\n\treturn -1;\n}");
+ }
+
+ @Test
+ public void testMethod_withNamespaceModifiers()
+ {
+ IFunctionNode node = getMethod("public static function foo(bar:String, baz:int = null):int{\treturn -1;}");
+ visitor.visitFunction(node);
+ assertOut("public static function foo(bar:String, baz:int = null):int {\n\treturn -1;\n}");
+ }
+
+ @Test
+ public void testMethod_withNamespaceModifierOverride()
+ {
+ IFunctionNode node = getMethod("public override function foo(bar:String, baz:int = null):int{\treturn -1;}");
+ visitor.visitFunction(node);
+ assertOut("public override function foo(bar:String, baz:int = null):int {\n\treturn -1;\n}");
+ }
+
+ @Test
+ public void testMethod_withNamespaceModifierOverrideBackwards()
+ {
+ IFunctionNode node = getMethod("override public function foo(bar:String, baz:int = null):int{return -1;}");
+ visitor.visitFunction(node);
+ assertOut("public override function foo(bar:String, baz:int = null):int {\n\treturn -1;\n}");
+ }
+
+ protected IFunctionNode getMethod(String code)
+ {
+ String source = "package {public class A {" + code + "}}";
+ IFileNode node = getFileNode(source);
+ IFunctionNode child = (IFunctionNode) findFirstDescendantOfType(node,
+ IFunctionNode.class);
+ return child;
+ }
+}
Propchange: incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/compiler/internal/as/codegen/TestMethodMembers.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/compiler/internal/as/codegen/TestPackage.java
URL: http://svn.apache.org/viewvc/incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/compiler/internal/as/codegen/TestPackage.java?rev=1426489&view=auto
==============================================================================
--- incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/compiler/internal/as/codegen/TestPackage.java (added)
+++ incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/compiler/internal/as/codegen/TestPackage.java Fri Dec 28 12:59:00 2012
@@ -0,0 +1,85 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.flex.compiler.internal.as.codegen;
+
+import org.apache.flex.compiler.tree.as.IFileNode;
+import org.junit.Test;
+
+/**
+ * This class tests the production of valid ActionScript3 code for Package
+ * production.
+ *
+ * @author Michael Schmalle
+ */
+public class TestPackage extends TestWalkerBase
+{
+ //--------------------------------------------------------------------------
+ // Package
+ //--------------------------------------------------------------------------
+
+ @Test
+ public void testPackage_Simple()
+ {
+ IFileNode node = getFileNode("package{}");
+ visitor.visitFile(node);
+ assertOut("package {\n}");
+ }
+
+ @Test
+ public void testPackage_Name()
+ {
+ IFileNode node = getFileNode("package foo.bar.baz {}");
+ visitor.visitFile(node);
+ assertOut("package foo.bar.baz {\n}");
+ }
+
+ @Test
+ public void testPackageSimple_Class()
+ {
+ IFileNode node = getFileNode("package {public class A{}}");
+ visitor.visitFile(node);
+ assertOut("package {\n\tpublic class A {\n\t}\n}");
+ }
+
+ @Test
+ public void testPackageQualified_Class()
+ {
+ IFileNode node = getFileNode("package foo.bar.baz {public class A{}}");
+ visitor.visitFile(node);
+ assertOut("package foo.bar.baz {\n\tpublic class A {\n\t}\n}");
+ }
+
+ @Test
+ public void testPackageQualified_ClassBody()
+ {
+ IFileNode node = getFileNode("package foo.bar.baz {public class A{public function A(){}}}");
+ visitor.visitFile(node);
+ assertOut("package foo.bar.baz {\n\tpublic class A {\n\t\tpublic function A() {\n\t\t}\n\t}\n}");
+ }
+
+ @Test
+ public void testPackageQualified_ClassBodyMethodContents()
+ {
+ IFileNode node = getFileNode("package foo.bar.baz {public class A{public function A(){if (a){for each(var i:Object in obj){doit();}}}}}");
+ visitor.visitFile(node);
+ assertOut("package foo.bar.baz {\n\tpublic class A {\n\t\tpublic function A() {\n\t\t\t"
+ + "if (a) {\n\t\t\t\tfor each (var i:Object in obj) {\n\t\t\t\t\tdoit();\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}");
+ }
+}
Propchange: incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/compiler/internal/as/codegen/TestPackage.java
------------------------------------------------------------------------------
svn:eol-style = native