You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by cd...@apache.org on 2016/04/13 20:56:18 UTC
[26/51] [partial] git commit: [flex-falcon]
[refs/heads/feature/maven-migration-test] - - Check-In of the migrated
project to make error analysis easier
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/externals/TestReferenceModel.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/externals/TestReferenceModel.java b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/externals/TestReferenceModel.java
new file mode 100644
index 0000000..d4374b3
--- /dev/null
+++ b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/externals/TestReferenceModel.java
@@ -0,0 +1,64 @@
+/*
+ *
+ * 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.codegen.externals;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+
+import org.apache.flex.compiler.clients.ExternCConfiguration;
+import org.junit.Ignore;
+import org.junit.Test;
+
+public class TestReferenceModel extends ExternalsTestBase
+{
+ @Ignore
+ @Test
+ public void test_full_compile() throws IOException
+ {
+
+ client.cleanOutput();
+
+ // TODO (mschmalle) this root needs to create 'classes' in the root and move
+ // constants and functions up into it aside classes
+ assertFalse(ExternalsTestUtils.AS_ROOT_DIR.exists());
+
+ // TODO (mschmalle) get warnings and errors from the closure compiler
+ client.compile();
+
+ client.emit();
+
+ assertTrue(config.getAsClassRoot().exists());
+ assertTrue(config.getAsInterfaceRoot().exists());
+ assertTrue(config.getAsFunctionRoot().exists());
+ assertTrue(config.getAsConstantRoot().exists());
+ assertTrue(config.getAsTypeDefRoot().exists());
+ }
+
+ @Override
+ protected void configure(ExternCConfiguration config) throws IOException
+ {
+ config.setASRoot(ExternalsTestUtils.AS_ROOT_DIR);
+
+ ExternalsTestUtils.addTestExcludesFull(config);
+ ExternalsTestUtils.addTestExternalsFull(config);
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/externals/TestTypeExternals.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/externals/TestTypeExternals.java b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/externals/TestTypeExternals.java
new file mode 100644
index 0000000..514f7a9
--- /dev/null
+++ b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/externals/TestTypeExternals.java
@@ -0,0 +1,141 @@
+/*
+ *
+ * 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.codegen.externals;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+
+import org.apache.flex.compiler.clients.ExternCConfiguration;
+import org.apache.flex.compiler.internal.codegen.externals.reference.ClassReference;
+import org.apache.flex.compiler.internal.codegen.externals.reference.MethodReference;
+import org.junit.Test;
+
+import com.google.javascript.rhino.JSDocInfo;
+import com.google.javascript.rhino.JSTypeExpression;
+import com.google.javascript.rhino.jstype.JSType;
+import com.google.javascript.rhino.jstype.NamedType;
+
+public class TestTypeExternals extends ExternalsTestBase
+{
+ @Test
+ public void test_constructor() throws IOException
+ {
+ compile("constructor_members.js");
+
+ ClassReference reference = model.getClassReference("Foo");
+ assertTrue(reference.hasInstanceField("bar"));
+ assertFalse(reference.hasInstanceField("foo"));
+ assertTrue(reference.hasInstanceMethod("method1"));
+ assertTrue(reference.hasInstanceMethod("method2"));
+ assertTrue(model.hasConstant("bar"));
+ }
+
+ @SuppressWarnings("unused")
+ @Test
+ public void test_types() throws IOException
+ {
+ compile("types_param.js");
+
+ ClassReference reference = model.getClassReference("Foo");
+
+ JSType jsType1 = getJSType("test1", "arg1");
+ JSType jsType2 = getJSType("test2", "arg1");
+ JSType jsType3 = getJSType("test3", "arg1");
+ JSType jsType4 = getJSType("test4", "arg1");
+ JSType jsType5 = getJSType("test5", "arg1");
+ JSType jsType6 = getJSType("test6", "arg1");
+
+ assertTrue(jsType1.isString());
+ assertTrue(jsType2.isUnionType());
+ assertTrue(jsType3.isRecordType());
+ assertTrue(jsType4.isUnionType());
+ assertTrue(jsType5.isInstanceType());
+ assertTrue(jsType6.isFunctionType());
+
+ assertEquals("String", toParamTypeString(jsType1));
+ assertEquals("foo.bar.Baz", toParamTypeString(jsType2));
+ assertEquals("Object /* {myNum: number, myObject: ?} */",
+ toParamTypeString(jsType3));
+ assertEquals("Number", toParamTypeString(jsType4));
+ assertEquals("Object", toParamTypeString(jsType5));
+ assertEquals("Function /* function (string, boolean): ? */",
+ toParamTypeString(jsType6));
+ }
+
+ public String toParamTypeString(JSType jsType)
+ {
+ String result = "";
+ if (jsType instanceof NamedType)
+ {
+ NamedType nt = (NamedType) jsType;
+ return nt.toAnnotationString();
+ }
+ else if (jsType.isString())
+ {
+ return "String";
+ }
+ else if (jsType.isBooleanObjectType())
+ {
+ return "Boolean";
+ }
+ else if (jsType.isNumber())
+ {
+ return "Number";
+ }
+ else if (jsType.isUnionType())
+ {
+ JSType collapseUnion = jsType.restrictByNotNullOrUndefined();
+ return toParamTypeString(collapseUnion);
+ }
+ else if (jsType.isRecordType())
+ {
+ return "Object /* " + jsType.toAnnotationString() + " */";
+ }
+ else if (jsType.isInstanceType())
+ {
+ return jsType.toAnnotationString();
+ }
+ else if (jsType.isFunctionType())
+ {
+ return "Function /* " + jsType.toAnnotationString() + " */";
+ }
+
+ return result;
+ }
+
+ private JSType getJSType(String methodName, String paramName)
+ {
+ MethodReference method = model.getClassReference("Foo").getInstanceMethod(methodName);
+ if (method == null)
+ method = model.getClassReference("Foo").getStaticMethod(methodName);
+ JSDocInfo comment = method.getComment();
+ JSTypeExpression parameterType = comment.getParameterType("arg1");
+ JSType jsType = model.evaluate(parameterType);
+ return jsType;
+ }
+
+ @Override
+ protected void configure(ExternCConfiguration config) throws IOException
+ {
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/externals/TestTypeInheritence.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/externals/TestTypeInheritence.java b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/externals/TestTypeInheritence.java
new file mode 100644
index 0000000..ee19443
--- /dev/null
+++ b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/externals/TestTypeInheritence.java
@@ -0,0 +1,87 @@
+/*
+ *
+ * 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.codegen.externals;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+import java.util.List;
+
+import org.apache.flex.compiler.clients.ExternCConfiguration;
+import org.apache.flex.compiler.internal.codegen.externals.reference.ClassReference;
+import org.junit.Test;
+
+public class TestTypeInheritence extends ExternalsTestBase
+{
+
+ @Test
+ public void test_superclasses() throws Exception
+ {
+ compile("type_inheritence.js");
+
+ ClassReference EventTarget = model.getInterfaceReference("EventTarget");
+
+ ClassReference Object = model.getClassReference("Object");
+ ClassReference Foo = model.getClassReference("Foo");
+ ClassReference Bar = model.getClassReference("Bar");
+ ClassReference Baz = model.getClassReference("Baz");
+
+ assertNotNull(Object);
+ assertNotNull(EventTarget);
+ assertNotNull(Foo);
+ assertNotNull(Bar);
+ assertNotNull(Baz);
+
+ assertSame(EventTarget, Foo.getImplementedInterfaces().get(0));
+ assertSame(Object, Foo.getSuperClass());
+ assertSame(Foo, Bar.getSuperClass());
+ assertSame(Bar, Baz.getSuperClass());
+
+ List<ClassReference> superClasses = Baz.getSuperClasses();
+ assertEquals(3, superClasses.size());
+ assertSame(Bar, superClasses.get(0));
+ assertSame(Foo, superClasses.get(1));
+ assertSame(Object, superClasses.get(2));
+
+ assertTrue(Foo.hasInstanceMethod("addEventListener"));
+
+ // TODO (mschmalle) need to revisit interface method overload
+ // XXX Since Foo implements EventTarget BUT changes it's signature, we have to
+ // use EventTargt.addEventListener()'s signature
+ String result = client.getEmitter().emit(
+ Foo.getInstanceMethod("addEventListener"));
+ assertEquals(
+ " /**\n "
+ + "* @param opt_useCapture [(boolean|undefined)] \n "
+ + "* @see [type_inheritence]\n */\n"
+ + " public function addEventListener(type:String, listener:Object, useCapture:Boolean):Object /* undefined */ "
+ + "{ return null; }\n", result);
+ }
+
+ @Override
+ protected void configure(ExternCConfiguration config) throws IOException
+ {
+ config.setASRoot(ExternalsTestUtils.AS_ROOT_DIR);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/amd/TestAMDClassA.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/amd/TestAMDClassA.java b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/amd/TestAMDClassA.java
new file mode 100644
index 0000000..666e67a
--- /dev/null
+++ b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/amd/TestAMDClassA.java
@@ -0,0 +1,181 @@
+/*
+ *
+ * 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.codegen.js.amd;
+
+import org.apache.flex.compiler.internal.test.AMDTestBase;
+import org.apache.flex.compiler.tree.as.IFunctionNode;
+import org.apache.flex.compiler.tree.as.IGetterNode;
+import org.apache.flex.compiler.tree.as.ISetterNode;
+import org.apache.flex.compiler.tree.as.IVariableNode;
+import org.junit.Ignore;
+import org.junit.Test;
+
+/**
+ * This class tests the production of AMD JavaScript for the test project, class
+ * A.
+ *
+ * @author Michael Schmalle
+ */
+@Ignore
+public class TestAMDClassA extends AMDTestBase
+{
+ // !!! the errors have to do with how I change 'this' on member expressions
+
+ //--------------------------------------------------------------------------
+ // Class A
+ //--------------------------------------------------------------------------
+
+ @Test
+ public void test_field_msg()
+ {
+ IVariableNode vnode = findField("_msg", classNode);
+ asBlockWalker.visitVariable(vnode);
+ assertOut("_msg$1: {\n\tvalue:0,\n\twritable:true\n}");
+ }
+
+ @Test
+ public void test_constructor()
+ {
+ IFunctionNode vnode = findFunction("A", classNode);
+ asBlockWalker.visitFunction(vnode);
+ assertOut("function A(msg) {\n\tthis.msg = msg;\n}");
+ }
+
+ @Test
+ public void test_get_msg()
+ {
+ IGetterNode node = findGetter("msg", classNode);
+ asBlockWalker.visitGetter(node);
+ assertOut("msg: {\n\tget: function msg$get() {\n\t\treturn String(this._msg$1);\n\t},"
+ + "\n\tset: function msg$set(value) {\n\t\tthis._msg$1 = parseInt(value, 10);\n\t}\n}");
+ }
+
+ @Test
+ public void test_set_msg()
+ {
+ ISetterNode node = findSetter("msg", classNode);
+ asBlockWalker.visitSetter(node);
+ assertOut("msg: {\n\tget: function msg$get() {\n\t\treturn String(this._msg$1);\n\t},"
+ + "\n\tset: function msg$set(value) {\n\t\tthis._msg$1 = parseInt(value, 10);\n\t}\n}");
+ }
+
+ @Test
+ public void test_secret()
+ {
+ IFunctionNode vnode = findFunction("secret", classNode);
+ asBlockWalker.visitFunction(vnode);
+ assertOut("secret$1: function secret(n) {\n\treturn this.msg + n;\n}");
+ }
+
+ @Test
+ public void test_foo()
+ {
+ IFunctionNode vnode = findFunction("foo", classNode);
+ asBlockWalker.visitFunction(vnode);
+ assertOut("foo: function foo(x) {\n\treturn this.secret$1(A.bar(x));\n}");
+ }
+
+ @Test
+ public void test_baz()
+ {
+ IFunctionNode vnode = findFunction("baz", classNode);
+ asBlockWalker.visitFunction(vnode);
+ assertOut("baz: function baz() {\n\tvar tmp = AS3.bind(this, "
+ + "\"secret$1\");\n\treturn tmp(\"-bound\");\n}");
+ }
+
+ @Test
+ public void test_bar()
+ {
+ IFunctionNode vnode = findFunction("bar", classNode);
+ asBlockWalker.visitFunction(vnode);
+ assertOut("bar: function bar(x) {\n\treturn x + 1;\n}");
+ }
+
+ @Test
+ public void test_file()
+ {
+ // not going to put this test production in until everything is concrete and agreed upon
+ asBlockWalker.visitFile(fileNode);
+ //assertOut("");
+ }
+
+ @Override
+ protected String getTypeUnderTest()
+ {
+ return "com.acme.A";
+ }
+}
+
+/*
+
+--------------------------------------------------------------------------------
+02-07-2013
+Current Production of visitFile()
+--------------------------------------------------------------------------------
+
+define(["exports", "runtime/AS3", "classes/I", "classes/String", "classes/parseInt", "classes/trace"], function($exports, AS3, I, String, parseInt, trace) {
+ "use strict";
+ AS3.compilationUnit($exports, function($primaryDeclaration){
+ function A(msg) {
+ this.msg = msg;
+ }
+ $primaryDeclaration(AS3.class_({
+ package_: "com.acme",
+ class_: "A",
+ implements_: [
+ I
+ ],
+ members: {
+ constructor: A,
+ _msg$1: {
+ value:0,
+ writable:true
+ },
+ msg: {
+ get: function msg$get() {
+ return String(this._msg$1);
+ },
+ set: function msg$set(value) {
+ this._msg$1 = parseInt(value, 10);
+ }
+ },
+ secret$1: function secret(n) {
+ return this.msg + n;
+ },
+ foo: function foo(x) {
+ return this.secret$1(A.bar(x));
+ },
+ baz: function baz() {
+ var tmp = AS3.bind(this, "secret$1");
+ return tmp("-bound");
+ }
+ },
+ staticMembers: {
+ bar: function bar(x) {
+ return x + 1;
+ }
+ }
+ }));
+ trace("Class A is initialized!");
+ });
+});
+
+*/
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/amd/TestAMDClassB.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/amd/TestAMDClassB.java b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/amd/TestAMDClassB.java
new file mode 100644
index 0000000..272aedb
--- /dev/null
+++ b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/amd/TestAMDClassB.java
@@ -0,0 +1,97 @@
+/*
+ *
+ * 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.codegen.js.amd;
+
+import org.apache.flex.compiler.internal.test.AMDTestBase;
+import org.apache.flex.compiler.tree.as.IFunctionNode;
+import org.apache.flex.compiler.tree.as.IVariableNode;
+import org.junit.Ignore;
+import org.junit.Test;
+
+/**
+ * This class tests the production of AMD JavaScript for the test project, class
+ * B.
+ *
+ * @author Michael Schmalle
+ */
+@Ignore
+public class TestAMDClassB extends AMDTestBase
+{
+ //--------------------------------------------------------------------------
+ // Class B
+ //--------------------------------------------------------------------------
+
+ // XXX (mschmalle) () get back to this when more work is done
+ @Test
+ public void test_nowPlusOne()
+ {
+// IFunctionNode vnode = findFunction("nowPlusOne", classNode);
+// asBlockWalker.visitFunction(vnode);
+// assertOut("nowPlusOne: function nowPlusOne() {\n\treturn new Date(B.now.getTime() + 60 * 60 * 1000);\n}");
+ }
+
+ @Test
+ public void test_constructor()
+ {
+ IFunctionNode vnode = findFunction("B", classNode);
+ asBlockWalker.visitFunction(vnode);
+ assertOut("function B(msg, count) {\n\tthis.barfoo = (A._ || A._$get()).bar(3);"
+ + "\n\tSuper.call(this, msg);\n\tthis.count = count;\n\ttrace(\"now: \" + B.now);\n}");
+ }
+
+ @Test
+ public void test_count()
+ {
+ IVariableNode node = findField("count", classNode);
+ asBlockWalker.visitVariable(node);
+ assertOut("count: {\n\tvalue:0,\n\twritable:true\n}");
+ }
+
+ @Test
+ public void test_override_foo()
+ {
+ IFunctionNode vnode = findFunction("foo", classNode);
+ asBlockWalker.visitFunction(vnode);
+ assertOut("foo: function foo(x) {\n\treturn this.foo$2(x + 2) + \"-sub\";\n}");
+ }
+
+ @Test
+ public void test_now()
+ {
+ IVariableNode node = findField("now", classNode);
+ asBlockWalker.visitVariable(node);
+ assertOut("B.now = new Date()");
+ }
+
+ @Test
+ public void test_file()
+ {
+ // not going to put this test production in until everything is concrete and agreed upon
+ asBlockWalker.visitFile(fileNode);
+ //assertOut("");
+ }
+
+ @Override
+ protected String getTypeUnderTest()
+ {
+ return "com.acme.B";
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/amd/TestAMDEmiter.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/amd/TestAMDEmiter.java b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/amd/TestAMDEmiter.java
new file mode 100644
index 0000000..71e35dc
--- /dev/null
+++ b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/amd/TestAMDEmiter.java
@@ -0,0 +1,144 @@
+/*
+ *
+ * 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.codegen.js.amd;
+
+import org.apache.flex.compiler.driver.IBackend;
+import org.apache.flex.compiler.internal.driver.js.amd.AMDBackend;
+import org.apache.flex.compiler.internal.test.ASTestBase;
+import org.junit.Test;
+
+/**
+ * This class tests the production of 'AMD' JavaScript output.
+ * <p>
+ * Note; this is a complete prototype more used in figuring out where
+ * abstraction and indirection is needed concerning the AS -> JS translations.
+ *
+ * @author Michael Schmalle
+ */
+public class TestAMDEmiter extends ASTestBase
+{
+ // TODO (mschmalle) these tests were all ignored... ?
+
+ @Test
+ public void testSimple()
+ {
+// String code = "package com.example.components {"
+// + "import org.apache.flex.html.staticControls.TextButton;"
+// + "public class MyTextButton extends TextButton {"
+// + "public function MyTextButton() {if (foo() != 42) { bar(); } }"
+// + "private var _privateVar:String = \"do \";"
+// + "public var publicProperty:Number = 100;"
+// + "public function myFunction(value: String): String{"
+// + "return \"Don't \" + _privateVar + value; }";
+// IFileNode node = compileAS(code);
+// asBlockWalker.visitFile(node);
+// assertOut("package com.example.components {\n\tpublic class MyTextButton extends TextButton {\n\t\tcom.example.components.MyTextButton = function() {\n\t\t\tif (foo() != 42) {\n\t\t\t\tbar();\n\t\t\t}\n\t\t}\n\t\tprivate var _privateVar:String = \"do \";\n\t\tpublic var publicProperty:Number = 100;\n\t\tcom.example.components.MyTextButton.prototype.myFunction = function(value) {\n\t\t\treturn \"Don't \" + _privateVar + value;\n\t\t}\n\t}\n}");
+ }
+
+ @Test
+ public void testSimpleMethod()
+ {
+// IFunctionNode node = getMethod("function method1():void{\n}");
+// asBlockWalker.visitFunction(node);
+// assertOut("A.prototype.method1 = function() {\n}");
+ }
+
+ @Test
+ public void testSimpleParameterReturnType()
+ {
+// IFunctionNode node = getMethod("function method1(bar:int):int{\n}");
+// asBlockWalker.visitFunction(node);
+// assertOut("A.prototype.method1 = function(bar) {\n}");
+ }
+
+ @Test
+ public void testSimpleMultipleParameter()
+ {
+// IFunctionNode node = getMethod("function method1(bar:int, baz:String, goo:A):void{\n}");
+// asBlockWalker.visitFunction(node);
+// assertOut("A.prototype.method1 = function(bar, baz, goo) {\n}");
+ }
+
+ @Test
+ public void testDefaultParameter()
+ {
+// /*
+// foo.bar.A.method1 = function(p1, p2, p3, p4) {
+// if (arguments.length < 4) {
+// if (arguments.length < 3) {
+// p3 = 3;
+// }
+// p4 = 4;
+// }
+// return p1 + p2 + p3 + p4;
+// }
+// */
+// IFunctionNode node = getMethod("function method1(p1:int, p2:int, p3:int = 3, p4:int = 4):int{return p1 + p2 + p3 + p4;}");
+// asBlockWalker.visitFunction(node);
+// assertOut("A.prototype.method1 = function(p1, p2, p3, p4) {\n\tif (arguments.length < 4) "
+// + "{\n\t\tif (arguments.length < 3) {\n\t\t\tp3 = 3;\n\t\t}\n\t\tp4 = 4;\n\t}"
+// + "\n\treturn p1 + p2 + p3 + p4;\n}");
+ }
+
+ @Test
+ public void testDefaultParameter_Body()
+ {
+// /*
+// foo.bar.A.method1 = function(bar, bax) {
+// if (arguments.length < 2) {
+// if (arguments.length < 1) {
+// bar = 42;
+// }
+// bax = 4;
+// }
+// }
+// */
+// IFunctionNode node = getMethod("function method1(bar:int = 42, bax:int = 4):void{if (a) foo();}");
+// asBlockWalker.visitFunction(node);
+// assertOut("A.prototype.method1 = function(bar, bax) {\n\tif (arguments.length < 2) {\n\t\t"
+// + "if (arguments.length < 1) {\n\t\t\tbar = 42;\n\t\t}\n\t\tbax = 4;\n\t}\n\t"
+// + "if (a)\n\t\tfoo();\n}");
+ }
+
+ @Test
+ public void testDefaultParameter_NoBody_Alternate()
+ {
+// /*
+// foo.bar.A.method1 = function(bar, bax) {
+// if (arguments.length < 2) {
+// if (arguments.length < 1) {
+// bar = 42;
+// }
+// bax = 4;
+// }
+// }
+// */
+// IFunctionNode node = getMethod("function method1(bar:int = 42, bax:int = 4):void{\n}");
+// asBlockWalker.visitFunction(node);
+// assertOut("A.prototype.method1 = function(bar, bax) {\n\tif (arguments.length < 2) {\n\t\t"
+// + "if (arguments.length < 1) {\n\t\t\tbar = 42;\n\t\t}\n\t\tbax = 4;\n\t}\n}");
+ }
+
+ @Override
+ protected IBackend createBackend()
+ {
+ return new AMDBackend();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/amd/TestAMDInterfaceI.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/amd/TestAMDInterfaceI.java b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/amd/TestAMDInterfaceI.java
new file mode 100644
index 0000000..1be8965
--- /dev/null
+++ b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/amd/TestAMDInterfaceI.java
@@ -0,0 +1,51 @@
+/*
+ *
+ * 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.codegen.js.amd;
+
+import org.apache.flex.compiler.internal.test.AMDTestBase;
+import org.junit.Test;
+
+/**
+ * This class tests the production of AMD JavaScript for the test project,
+ * interface I.
+ *
+ * @author Michael Schmalle
+ */
+public class TestAMDInterfaceI extends AMDTestBase
+{
+ //--------------------------------------------------------------------------
+ // Interface I
+ //--------------------------------------------------------------------------
+
+ @Test
+ public void test_file()
+ {
+ asBlockWalker.visitFile(fileNode);
+ assertOut("define([\"exports\", \"runtime/AS3\"], function($exports, AS3) {"
+ + "\n\t\"use strict\"; \n\tAS3.interface_($exports, {\n\t\tpackage_: "
+ + "\"com.acme\",\n\t\tinterface_: \"I\"\n\t});\n});");
+ }
+
+ @Override
+ protected String getTypeUnderTest()
+ {
+ return "com.acme.I";
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/amd/TestAMDInterfaceIOther.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/amd/TestAMDInterfaceIOther.java b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/amd/TestAMDInterfaceIOther.java
new file mode 100644
index 0000000..b1e78f0
--- /dev/null
+++ b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/amd/TestAMDInterfaceIOther.java
@@ -0,0 +1,51 @@
+/*
+ *
+ * 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.codegen.js.amd;
+
+import org.apache.flex.compiler.internal.test.AMDTestBase;
+import org.junit.Test;
+
+/**
+ * This class tests the production of AMD JavaScript for the test project,
+ * interface com.acme.sub.IOther.
+ *
+ * @author Michael Schmalle
+ */
+public class TestAMDInterfaceIOther extends AMDTestBase
+{
+ //--------------------------------------------------------------------------
+ // Interface IOther
+ //--------------------------------------------------------------------------
+
+ @Test
+ public void test_file()
+ {
+ asBlockWalker.visitFile(fileNode);
+ assertOut("define([\"exports\", \"runtime/AS3\"], function($exports, AS3) {"
+ + "\n\t\"use strict\"; \n\tAS3.interface_($exports, {\n\t\tpackage_: "
+ + "\"com.acme.sub\",\n\t\tinterface_: \"IOther\"\n\t});\n});");
+ }
+
+ @Override
+ protected String getTypeUnderTest()
+ {
+ return "com.acme.sub.IOther";
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/amd/TestAMDInterfaceISub.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/amd/TestAMDInterfaceISub.java b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/amd/TestAMDInterfaceISub.java
new file mode 100644
index 0000000..fea3b4a
--- /dev/null
+++ b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/amd/TestAMDInterfaceISub.java
@@ -0,0 +1,52 @@
+/*
+ *
+ * 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.codegen.js.amd;
+
+import org.apache.flex.compiler.internal.test.AMDTestBase;
+import org.junit.Test;
+
+/**
+ * This class tests the production of AMD JavaScript for the test project,
+ * interface com.acme.sub.ISub.
+ *
+ * @author Michael Schmalle
+ */
+public class TestAMDInterfaceISub extends AMDTestBase
+{
+ //--------------------------------------------------------------------------
+ // Interface ISub
+ //--------------------------------------------------------------------------
+
+ @Test
+ public void test_file()
+ {
+ asBlockWalker.visitFile(fileNode);
+ assertOut("define([\"exports\", \"runtime/AS3\", \"classes/com/acme/I\"], "
+ + "function($exports, AS3, I) {\n\t\"use strict\"; \n\tAS3.interface_($exports, {"
+ + "\n\t\tpackage_: \"com.acme.sub\",\n\t\tinterface_: \"ISub\"\n\t\textends_: "
+ + "[\n\t\t\tI\n\t\t]\n\t});\n});");
+ }
+
+ @Override
+ protected String getTypeUnderTest()
+ {
+ return "com.acme.sub.ISub";
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/amd/TestAMDPackage.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/amd/TestAMDPackage.java b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/amd/TestAMDPackage.java
new file mode 100644
index 0000000..ca8a4c0
--- /dev/null
+++ b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/amd/TestAMDPackage.java
@@ -0,0 +1,127 @@
+/*
+ *
+ * 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.codegen.js.amd;
+
+import java.io.IOException;
+
+import org.apache.flex.compiler.driver.IBackend;
+import org.apache.flex.compiler.internal.codegen.as.TestPackage;
+import org.apache.flex.compiler.internal.driver.js.amd.AMDBackend;
+import org.apache.flex.compiler.tree.as.IFileNode;
+import org.apache.flex.compiler.tree.as.IFunctionNode;
+import org.junit.Test;
+
+/**
+ * This class tests the production of AMD JavaScript for AS package.
+ *
+ * @author Michael Schmalle
+ */
+public class TestAMDPackage extends TestPackage
+{
+
+ @Override
+ @Test
+ public void testPackage_Simple()
+ {
+ IFileNode node = compileAS("package{}");
+ asBlockWalker.visitFile(node);
+ assertOut("");
+ }
+
+ @Override
+ @Test
+ public void testPackage_SimpleName()
+ {
+ IFileNode node = compileAS("package foo {}");
+ asBlockWalker.visitFile(node);
+ assertOut("");
+ }
+
+ @Override
+ @Test
+ public void testPackage_Name()
+ {
+ IFileNode node = compileAS("package foo.bar.baz {}");
+ asBlockWalker.visitFile(node);
+ assertOut("");
+ }
+
+ @Override
+ @Test
+ public void testPackageSimple_Class()
+ {
+ IFileNode node = compileAS("package {public class A{}}");
+ asBlockWalker.visitFile(node);
+ //assertOut("");
+ }
+
+ // XXX (mschmalle) ?
+ @Test
+ public void testPackageSimple_TestA() throws IOException
+ {
+ }
+
+ @Override
+ @Test
+ public void testPackageQualified_Class()
+ {
+ IFileNode node = compileAS("package foo.bar.baz {public class A{}}");
+ asBlockWalker.visitFile(node);
+ //assertOut("");
+ }
+
+ @Override
+ @Test
+ public void testPackageQualified_ClassBody()
+ {
+ IFileNode node = compileAS("package foo.bar.baz {public class A{public function A(){}}}");
+ asBlockWalker.visitFile(node);
+ //assertOut("");
+ }
+
+ @Override
+ @Test
+ public void testPackageQualified_ClassBodyMethodContents()
+ {
+ IFileNode node = compileAS("package foo.bar.baz {public class A{public function A(){if (a){for (var i:Object in obj){doit();}}}}}");
+ asBlockWalker.visitFile(node);
+ //assertOut("");
+ }
+
+ //@Test
+ public void testMethod()
+ {
+ IFunctionNode node = getMethod("function foo(){}");
+ asBlockWalker.visitFunction(node);
+ assertOut("A.prototype.foo = function() {\n}");
+ }
+
+ @Override
+ protected IBackend createBackend()
+ {
+ return new AMDBackend();
+ }
+
+ protected IFileNode getFile(String code)
+ {
+ IFileNode node = compileAS(code);
+ return node;
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSAccessorMembers.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSAccessorMembers.java b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSAccessorMembers.java
new file mode 100644
index 0000000..58769fe
--- /dev/null
+++ b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSAccessorMembers.java
@@ -0,0 +1,156 @@
+/*
+ *
+ * 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.codegen.js.flexjs;
+
+import org.apache.flex.compiler.driver.IBackend;
+import org.apache.flex.compiler.internal.codegen.js.goog.TestGoogAccessorMembers;
+import org.apache.flex.compiler.internal.driver.js.flexjs.FlexJSBackend;
+import org.apache.flex.compiler.tree.as.IClassNode;
+import org.junit.Test;
+
+/**
+ * @author Erik de Bruin
+ */
+public class TestFlexJSAccessorMembers extends TestGoogAccessorMembers
+{
+ @Override
+ @Test
+ public void testGetAccessor()
+ {
+ IClassNode node = (IClassNode) getNode("function get foo():int{}",
+ IClassNode.class, WRAP_LEVEL_CLASS);
+ asBlockWalker.visitClass(node);
+ assertOut("/**\n * @constructor\n */\nFalconTest_A = function() {\n};\n\n\nObject.defineProperties(FalconTest_A.prototype, /** @lends {FalconTest_A.prototype} */ {\n/** @export */\nfoo: {\nget: /** @this {FalconTest_A} */ function() {\n}}}\n);");
+ }
+
+ @Override
+ @Test
+ public void testGetAccessor_withBody()
+ {
+ IClassNode node = (IClassNode) getNode("function get foo():int{return -1;}",
+ IClassNode.class, WRAP_LEVEL_CLASS);
+ asBlockWalker.visitClass(node);
+ assertOut("/**\n * @constructor\n */\nFalconTest_A = function() {\n};\n\n\nObject.defineProperties(FalconTest_A.prototype, /** @lends {FalconTest_A.prototype} */ {\n/** @export */\nfoo: {\nget: /** @this {FalconTest_A} */ function() {\n return -1;\n}}}\n);");
+ }
+
+ @Override
+ @Test
+ public void testGetAccessor_withNamespace()
+ {
+ IClassNode node = (IClassNode) getNode("public function get foo():int{return -1;}",
+ IClassNode.class, WRAP_LEVEL_CLASS);
+ asBlockWalker.visitClass(node);
+ assertOut("/**\n * @constructor\n */\nFalconTest_A = function() {\n};\n\n\nObject.defineProperties(FalconTest_A.prototype, /** @lends {FalconTest_A.prototype} */ {\n/** @export */\nfoo: {\nget: /** @this {FalconTest_A} */ function() {\n return -1;\n}}}\n);");
+ }
+
+ @Override
+ @Test
+ public void testGetAccessor_withNamespaceOverride()
+ {
+ IClassNode node = (IClassNode) getNode("public class B extends A { public override function get foo():int{return super.foo;} }; public class A {public function get foo():int {return 0;}} ",
+ IClassNode.class, WRAP_LEVEL_PACKAGE);
+ asBlockWalker.visitClass(node);
+ assertOut("/**\n * @constructor\n * @extends {A}\n */\nB = function() {\n B.base(this, 'constructor');\n};\ngoog.inherits(B, A);\n\n\nObject.defineProperties(B.prototype, /** @lends {B.prototype} */ {\n/** @export */\nfoo: {\nget: /** @this {B} */ function() {\n return org.apache.flex.utils.Language.superGetter(B, this, 'foo');\n}}}\n);");
+ }
+
+ @Test
+ public void testGetAccessor_withGeneratedSetOverride()
+ {
+ IClassNode node = (IClassNode) getNode("public class B extends A { public override function get foo():int{return super.foo;} }; public class A { public function set foo(value:int):void{} public function get foo():int {return 0;}}",
+ IClassNode.class, WRAP_LEVEL_PACKAGE);
+ asBlockWalker.visitClass(node);
+ assertOut("/**\n * @constructor\n * @extends {A}\n */\nB = function() {\n B.base(this, 'constructor');\n};\ngoog.inherits(B, A);\n\n\nObject.defineProperties(B.prototype, /** @lends {B.prototype} */ {\n/** @export */\nfoo: {\nget: /** @this {B} */ function() {\n return org.apache.flex.utils.Language.superGetter(B, this, 'foo');\n},\nset: /** @this {B} */ function(value) {\norg.apache.flex.utils.Language.superSetter(B, this, 'foo', value);\n}}}\n);");
+ }
+
+ @Override
+ @Test
+ public void testGetAccessor_withStatic()
+ {
+ IClassNode node = (IClassNode) getNode("public static function get foo():int{return -1;}",
+ IClassNode.class, WRAP_LEVEL_CLASS);
+ asBlockWalker.visitClass(node);
+ assertOut("/**\n * @constructor\n */\nFalconTest_A = function() {\n};Object.defineProperties(FalconTest_A, /** @lends {FalconTest_A} */ {\n/** @export */\nfoo: {\nget: function() {\n return -1;\n}}}\n);");
+ }
+
+ @Override
+ @Test
+ public void testSetAccessor()
+ {
+ IClassNode node = (IClassNode) getNode("function set foo(value:int):void{}",
+ IClassNode.class, WRAP_LEVEL_CLASS);
+ asBlockWalker.visitClass(node);
+ assertOut("/**\n * @constructor\n */\nFalconTest_A = function() {\n};\n\n\nObject.defineProperties(FalconTest_A.prototype, /** @lends {FalconTest_A.prototype} */ {\n/** @export */\nfoo: {\nset: /** @this {FalconTest_A} */ function(value) {\n}}}\n);");
+ }
+
+ @Override
+ @Test
+ public void testSetAccessor_withBody()
+ {
+ IClassNode node = (IClassNode) getNode("function set foo(value:int):void{fetch('haai');}",
+ IClassNode.class, WRAP_LEVEL_CLASS);
+ asBlockWalker.visitClass(node);
+ assertOut("/**\n * @constructor\n */\nFalconTest_A = function() {\n};\n\n\nObject.defineProperties(FalconTest_A.prototype, /** @lends {FalconTest_A.prototype} */ {\n/** @export */\nfoo: {\nset: /** @this {FalconTest_A} */ function(value) {\n fetch('haai');\n}}}\n);");
+ }
+
+ @Override
+ @Test
+ public void testSetAccessor_withNamespace()
+ {
+ IClassNode node = (IClassNode) getNode("public function set foo(value:int):void{}",
+ IClassNode.class, WRAP_LEVEL_CLASS);
+ asBlockWalker.visitClass(node);
+ assertOut("/**\n * @constructor\n */\nFalconTest_A = function() {\n};\n\n\nObject.defineProperties(FalconTest_A.prototype, /** @lends {FalconTest_A.prototype} */ {\n/** @export */\nfoo: {\nset: /** @this {FalconTest_A} */ function(value) {\n}}}\n);");
+ }
+
+ @Override
+ @Test
+ public void testSetAccessor_withNamespaceOverride()
+ {
+ IClassNode node = (IClassNode) getNode("public class B extends A { public override function set foo(value:int):void {super.foo = value;} }; public class A { public function set foo(value:int):void{}}",
+ IClassNode.class, WRAP_LEVEL_PACKAGE);
+ asBlockWalker.visitClass(node);
+ assertOut("/**\n * @constructor\n * @extends {A}\n */\nB = function() {\n B.base(this, 'constructor');\n};\ngoog.inherits(B, A);\n\n\nObject.defineProperties(B.prototype, /** @lends {B.prototype} */ {\n/** @export */\nfoo: {\nset: /** @this {B} */ function(value) {\n org.apache.flex.utils.Language.superSetter(B, this, 'foo', value);\n}}}\n);");
+ }
+
+ @Override
+ @Test
+ public void testSetAccessor_withStatic()
+ {
+ IClassNode node = (IClassNode) getNode("public static function set foo(value:int):void{}",
+ IClassNode.class, WRAP_LEVEL_CLASS);
+ asBlockWalker.visitClass(node);
+ assertOut("/**\n * @constructor\n */\nFalconTest_A = function() {\n};Object.defineProperties(FalconTest_A, /** @lends {FalconTest_A} */ {\n/** @export */\nfoo: {\nset: function(value) {\n}}}\n);");
+ }
+
+ @Test
+ public void testSetAccessor_withGeneratedGetOverride()
+ {
+ IClassNode node = (IClassNode) getNode("public class B extends A { public override function set foo(value:int):void {super.foo = value;} }; public class A { public function set foo(value:int):void{} public function get foo():int { return 0;}}",
+ IClassNode.class, WRAP_LEVEL_PACKAGE);
+ asBlockWalker.visitClass(node);
+ assertOut("/**\n * @constructor\n * @extends {A}\n */\nB = function() {\n B.base(this, 'constructor');\n};\ngoog.inherits(B, A);\n\n\nObject.defineProperties(B.prototype, /** @lends {B.prototype} */ {\n/** @export */\nfoo: {\nget: /** @this {B} */ function() {\nreturn org.apache.flex.utils.Language.superGetter(B, this, 'foo');\n},\nset: /** @this {B} */ function(value) {\n org.apache.flex.utils.Language.superSetter(B, this, 'foo', value);\n}}}\n);");
+ }
+
+ @Override
+ protected IBackend createBackend()
+ {
+ return new FlexJSBackend();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSAccessors.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSAccessors.java b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSAccessors.java
new file mode 100644
index 0000000..7083e3a
--- /dev/null
+++ b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSAccessors.java
@@ -0,0 +1,84 @@
+/*
+ *
+ * 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.codegen.js.flexjs;
+
+import org.apache.flex.compiler.driver.IBackend;
+import org.apache.flex.compiler.internal.driver.js.flexjs.FlexJSBackend;
+import org.apache.flex.compiler.internal.test.ASTestBase;
+import org.apache.flex.compiler.tree.as.IClassNode;
+import org.junit.Test;
+
+/**
+ * @author Erik de Bruin
+ */
+public class TestFlexJSAccessors extends ASTestBase
+{
+
+ @Test
+ public void testGetAndSetAccessor()
+ {
+ IClassNode node = (IClassNode) getNode(
+ "public function doStuff():void {label = 'hello, bye'; var theLabel:String = label;}; private var _label:String; public function get label():String {return _label}; public function set label(value:String):void {_label = value}; ",
+ IClassNode.class, WRAP_LEVEL_CLASS);
+ asBlockWalker.visitClass(node);
+ String expected = "/**\n * @constructor\n */\nFalconTest_A = function() {\n};\n\n\n/**\n * @export\n */\nFalconTest_A.prototype.doStuff = function() {\n this.label = 'hello, bye';\n var /** @type {string} */ theLabel = this.label;\n};\n\n\n/**\n * @private\n * @type {string}\n */\nFalconTest_A.prototype._label;\n\n\nObject.defineProperties(FalconTest_A.prototype, /** @lends {FalconTest_A.prototype} */ {\n/** @export */\nlabel: {\nget: /** @this {FalconTest_A} */ function() {\n return this._label;\n},\nset: /** @this {FalconTest_A} */ function(value) {\n this._label = value;\n}}}\n);";
+ assertOut(expected);
+ }
+
+ @Test
+ public void testSetAccessorWithMemberAccessOnLeftSide()
+ {
+ IClassNode node = (IClassNode) getNode(
+ "public class B { public function B() {}; public function doStuff():void {this.label = label + 'bye'; var theLabel:String = label;}; private var _label:String; public function get label():String {return _label}; public function set label(value:String):void {_label = value};}",
+ IClassNode.class, WRAP_LEVEL_PACKAGE);
+ asBlockWalker.visitClass(node);
+ String expected = "/**\n * @constructor\n */\nB = function() {\n};\n\n\n/**\n * @export\n */\nB.prototype.doStuff = function() {\n this.label = this.label + 'bye';\n var /** @type {string} */ theLabel = this.label;\n};\n\n\n/**\n * @private\n * @type {string}\n */\nB.prototype._label;\n\n\nObject.defineProperties(B.prototype, /** @lends {B.prototype} */ {\n/** @export */\nlabel: {\nget: /** @this {B} */ function() {\n return this._label;\n},\nset: /** @this {B} */ function(value) {\n this._label = value;\n}}}\n);";
+ assertOut(expected);
+ }
+
+ @Test
+ public void testSetAccessorWithCompoundRightSide()
+ {
+ IClassNode node = (IClassNode) getNode(
+ "public function doStuff():void {label = label + 'bye'; var theLabel:String = label;}; private var _label:String; public function get label():String {return _label}; public function set label(value:String):void {_label = value}; ",
+ IClassNode.class, WRAP_LEVEL_CLASS);
+ asBlockWalker.visitClass(node);
+ String expected = "/**\n * @constructor\n */\nFalconTest_A = function() {\n};\n\n\n/**\n * @export\n */\nFalconTest_A.prototype.doStuff = function() {\n this.label = this.label + 'bye';\n var /** @type {string} */ theLabel = this.label;\n};\n\n\n/**\n * @private\n * @type {string}\n */\nFalconTest_A.prototype._label;\n\n\nObject.defineProperties(FalconTest_A.prototype, /** @lends {FalconTest_A.prototype} */ {\n/** @export */\nlabel: {\nget: /** @this {FalconTest_A} */ function() {\n return this._label;\n},\nset: /** @this {FalconTest_A} */ function(value) {\n this._label = value;\n}}}\n);";
+ assertOut(expected);
+ }
+
+ @Test
+ public void testSetAccessorWithMemberAccessOnRightSide()
+ {
+ IClassNode node = (IClassNode) getNode(
+ "public class B { public function B() {}; public function doStuff():void {label = this.label; var theLabel:String = label;}; private var _label:String; public function get label():String {return _label}; public function set label(value:String):void {_label = value};}",
+ IClassNode.class, WRAP_LEVEL_PACKAGE);
+ asBlockWalker.visitClass(node);
+ String expected = "/**\n * @constructor\n */\nB = function() {\n};\n\n\n/**\n * @export\n */\nB.prototype.doStuff = function() {\n this.label = this.label;\n var /** @type {string} */ theLabel = this.label;\n};\n\n\n/**\n * @private\n * @type {string}\n */\nB.prototype._label;\n\n\nObject.defineProperties(B.prototype, /** @lends {B.prototype} */ {\n/** @export */\nlabel: {\nget: /** @this {B} */ function() {\n return this._label;\n},\nset: /** @this {B} */ function(value) {\n this._label = value;\n}}}\n);";
+ assertOut(expected);
+ }
+
+ @Override
+ protected IBackend createBackend()
+ {
+ return new FlexJSBackend();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSClass.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSClass.java b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSClass.java
new file mode 100644
index 0000000..509c491
--- /dev/null
+++ b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSClass.java
@@ -0,0 +1,397 @@
+/*
+ *
+ * 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.codegen.js.flexjs;
+
+import org.apache.flex.compiler.driver.IBackend;
+import org.apache.flex.compiler.internal.codegen.js.goog.TestGoogClass;
+import org.apache.flex.compiler.internal.driver.js.flexjs.FlexJSBackend;
+import org.apache.flex.compiler.tree.as.IClassNode;
+import org.junit.Test;
+
+/**
+ * @author Erik de Bruin
+ */
+public class TestFlexJSClass extends TestGoogClass
+{
+
+ @Override
+ @Test
+ public void testConstructor_super()
+ {
+ IClassNode node = getClassNode("public class A {public function A() { super(); }}");
+ asBlockWalker.visitClass(node);
+ assertOut("/**\n * @constructor\n */\norg.apache.flex.A = function() {\n ;\n};");
+ }
+
+ @Override
+ @Test
+ public void testSimpleExtends()
+ {
+ IClassNode node = getClassNode("public class A extends EventTarget {public function A() {}}");
+ asBlockWalker.visitClass(node);
+ assertOut("/**\n * @constructor\n * @extends {goog.events.EventTarget}\n */\norg.apache.flex.A = function() {\n org.apache.flex.A.base(this, 'constructor');\n};\ngoog.inherits(org.apache.flex.A, goog.events.EventTarget);");
+ }
+
+ @Test
+ public void testSimpleExtendsWithArgs()
+ {
+ IClassNode node = getClassNode("public class A extends EventTarget {public function A(arg:String) { super(arg);}}");
+ asBlockWalker.visitClass(node);
+ assertOut("/**\n * @constructor\n * @extends {goog.events.EventTarget}\n * @param {string} arg\n */\norg.apache.flex.A = function(arg) {\n org.apache.flex.A.base(this, 'constructor', arg);\n};\ngoog.inherits(org.apache.flex.A, goog.events.EventTarget);");
+ }
+
+ @Test
+ public void testSimpleExtendsWithArgsImplicitSuper()
+ {
+ IClassNode node = getClassNode("public class A extends EventTarget {public function A(arg:String) {}}");
+ asBlockWalker.visitClass(node);
+ assertOut("/**\n * @constructor\n * @extends {goog.events.EventTarget}\n * @param {string} arg\n */\norg.apache.flex.A = function(arg) {\n org.apache.flex.A.base(this, 'constructor');\n};\ngoog.inherits(org.apache.flex.A, goog.events.EventTarget);");
+ }
+
+ @Override
+ @Test
+ public void testSimpleExtendsImplements()
+ {
+ IClassNode node = getClassNode("public class A extends EventTarget implements IEventDispatcher {public function A() {}}");
+ asBlockWalker.visitClass(node);
+ assertOut("/**\n * @constructor\n * @extends {goog.events.EventTarget}\n * @implements {flash.events.IEventDispatcher}\n */\norg.apache.flex.A = function() {\n org.apache.flex.A.base(this, 'constructor');\n};\ngoog.inherits(org.apache.flex.A, goog.events.EventTarget);");
+ }
+
+ @Override
+ @Test
+ public void testSimpleExtendsImplementsMultiple()
+ {
+ IClassNode node = getClassNode("public class A extends EventTarget implements IEventDispatcher, ListenableKey {public function A() {}}");
+ asBlockWalker.visitClass(node);
+ assertOut("/**\n * @constructor\n * @extends {goog.events.EventTarget}\n * @implements {flash.events.IEventDispatcher}\n * @implements {goog.events.ListenableKey}\n */\norg.apache.flex.A = function() {\n org.apache.flex.A.base(this, 'constructor');\n};\ngoog.inherits(org.apache.flex.A, goog.events.EventTarget);");
+ }
+
+ @Override
+ @Test
+ public void testSimpleFinalExtendsImplementsMultiple()
+ {
+ IClassNode node = getClassNode("public final class A extends EventTarget implements IEventDispatcher, ListenableKey {public function A() {}}");
+ asBlockWalker.visitClass(node);
+ assertOut("/**\n * @constructor\n * @extends {goog.events.EventTarget}\n * @implements {flash.events.IEventDispatcher}\n * @implements {goog.events.ListenableKey}\n */\norg.apache.flex.A = function() {\n org.apache.flex.A.base(this, 'constructor');\n};\ngoog.inherits(org.apache.flex.A, goog.events.EventTarget);");
+ }
+
+ @Override
+ @Test
+ public void testQualifiedExtendsImplementsMultiple()
+ {
+ IClassNode node = getClassNode("public class A extends goog.events.EventTarget implements flash.events.IEventDispatcher, goog.events.ListenableKey {public function A() {}}");
+ asBlockWalker.visitClass(node);
+ assertOut("/**\n * @constructor\n * @extends {goog.events.EventTarget}\n * @implements {flash.events.IEventDispatcher}\n * @implements {goog.events.ListenableKey}\n */\norg.apache.flex.A = function() {\n org.apache.flex.A.base(this, 'constructor');\n};\ngoog.inherits(org.apache.flex.A, goog.events.EventTarget);");
+ }
+
+ @Override
+ @Test
+ public void testExtendsConstructor_super()
+ {
+ IClassNode node = getClassNode("public class A extends goog.events.EventTarget { public function A() { super('foo', 42);}}");
+ asBlockWalker.visitClass(node);
+ assertOut("/**\n * @constructor\n * @extends {goog.events.EventTarget}\n */\norg.apache.flex.A = function() {\n org.apache.flex.A.base(this, 'constructor', 'foo', 42);\n};\ngoog.inherits(org.apache.flex.A, goog.events.EventTarget);");
+ }
+
+ @Test
+ public void testConstructor_withArgumentNameMatchingMemberName()
+ {
+ IClassNode node = getClassNode("public class B {public function B(arg1:String) {this.arg1 = arg1}; public var arg1:String;}");
+ asBlockWalker.visitClass(node);
+ String expected = "/**\n * @constructor\n * @param {string} arg1\n */\norg.apache.flex.B = function(arg1) {\n this.arg1 = arg1;\n};\n\n\n/**\n * @export\n * @type {string}\n */\norg.apache.flex.B.prototype.arg1;";
+ assertOut(expected);
+ }
+
+ @Test
+ public void testMethod_withImplicitSelfInReturnValue()
+ {
+ IClassNode node = getClassNode("public class B {public function B() {}; public var event:Event = new Event(); public function foo():String {return event.type;};}");
+ asBlockWalker.visitClass(node);
+ String expected = "/**\n * @constructor\n */\norg.apache.flex.B = function() {\n\nthis.event = new goog.events.Event();\n};\n\n\n/**\n * @export\n * @type {goog.events.Event}\n */\norg.apache.flex.B.prototype.event;\n\n\n/**\n * @export\n * @return {string}\n */\norg.apache.flex.B.prototype.foo = function() {\n return this.event.type;\n};";
+ assertOut(expected);
+ }
+
+ @Test
+ public void testMethod_noArgsNoReturn()
+ {
+ IClassNode node = getClassNode("public class B {public function B() {}; public function foo():void {};}");
+ asBlockWalker.visitClass(node);
+ String expected = "/**\n * @constructor\n */\norg.apache.flex.B = function() {\n};\n\n\n/**\n * @export\n */\norg.apache.flex.B.prototype.foo = function() {\n};";
+ assertOut(expected);
+ }
+
+ @Test
+ public void testMethod_override()
+ {
+ IClassNode node = getClassNode("public class B {public function B() {}; override public function foo():void {};}");
+ asBlockWalker.visitClass(node);
+ String expected = "/**\n * @constructor\n */\norg.apache.flex.B = function() {\n};\n\n\n/**\n * @export\n * @override\n */\norg.apache.flex.B.prototype.foo = function() {\n};";
+ assertOut(expected);
+ }
+
+ @Test
+ public void testMethod_overrideWithFunctionBody()
+ {
+ IClassNode node = getClassNode("public class B {public function B() {}; override public function foo(value:Object):void {baz = ''};}");
+ asBlockWalker.visitClass(node);
+ String expected = "/**\n * @constructor\n */\norg.apache.flex.B = function() {\n};\n\n\n/**\n * @export\n * @override\n */\norg.apache.flex.B.prototype.foo = function(value) {\n baz = '';\n};";
+ assertOut(expected);
+ }
+
+ @Test
+ public void testMethod_overrideSuperCall()
+ {
+ IClassNode node = getClassNode("public class B {public function B() {}; override public function foo():void {super.foo();};}");
+ asBlockWalker.visitClass(node);
+ String expected = "/**\n * @constructor\n */\norg.apache.flex.B = function() {\n};\n\n\n/**\n * @export\n * @override\n */\norg.apache.flex.B.prototype.foo = function() {\n org.apache.flex.B.base(this, 'foo');\n};";
+ assertOut(expected);
+ }
+
+ @Test
+ public void testMethod_setterCall()
+ {
+ IClassNode node = getClassNode("public class B {public function B() {}; public function set baz(value:Object):void {}; public function set foo(value:Object):void {baz = value;};}");
+ asBlockWalker.visitClass(node);
+ String expected = "/**\n * @constructor\n */\norg.apache.flex.B = function() {\n};\n\n\nObject.defineProperties(org.apache.flex.B.prototype, /** @lends {org.apache.flex.B.prototype} */ {\n/** @export */\nbaz: {\nset: /** @this {org.apache.flex.B} */ function(value) {\n}},\n/** @export */\nfoo: {\nset: /** @this {org.apache.flex.B} */ function(value) {\n this.baz = value;\n}}}\n);";
+ assertOut(expected);
+ }
+
+ @Test
+ public void testMethod_overrideSetterSuperCall()
+ {
+ IClassNode node = getClassNode("public class B extends A {public function B() {}; override public function set foo(value:Object):void {super.foo = value;};} class A {public function set foo(value:Object):void {}}");
+ asBlockWalker.visitClass(node);
+ String expected = "/**\n * @constructor\n * @extends {org.apache.flex.A}\n */\norg.apache.flex.B = function() {\n org.apache.flex.B.base(this, 'constructor');\n};\ngoog.inherits(org.apache.flex.B, org.apache.flex.A);\n\n\nObject.defineProperties(org.apache.flex.B.prototype, /** @lends {org.apache.flex.B.prototype} */ {\n/** @export */\nfoo: {\nset: /** @this {org.apache.flex.B} */ function(value) {\n org.apache.flex.utils.Language.superSetter(org.apache.flex.B, this, 'foo', value);\n}}}\n);";
+ assertOut(expected);
+ }
+
+ @Override
+ @Test
+ public void testExtendsConstructor_withArguments()
+ {
+ IClassNode node = getClassNode("public class A extends goog.events.EventTarget {public function A(arg1:String, arg2:int) {}}");
+ asBlockWalker.visitClass(node);
+ assertOut("/**\n * @constructor\n * @extends {goog.events.EventTarget}\n * @param {string} arg1\n * @param {number} arg2\n */\norg.apache.flex.A = function(arg1, arg2) {\n org.apache.flex.A.base(this, 'constructor');\n};\ngoog.inherits(org.apache.flex.A, goog.events.EventTarget);");
+ }
+
+ @Override
+ @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}");
+ asBlockWalker.visitClass(node);
+ assertOut("/**\n * @constructor\n */\norg.apache.flex.A = function() {\n};\n\n\n/**\n * @export\n * @type {Object}\n */\norg.apache.flex.A.prototype.a;\n\n\n/**\n * @protected\n * @type {string}\n */\norg.apache.flex.A.prototype.b;\n\n\n/**\n * @private\n * @type {number}\n */\norg.apache.flex.A.prototype.c;\n\n\n/**\n * @export\n * @type {number}\n */\norg.apache.flex.A.prototype.d;\n\n\n/**\n * @export\n * @type {number}\n */\norg.apache.flex.A.prototype.e;");
+ }
+
+ @Override
+ @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';");
+ asBlockWalker.visitClass(node);
+ assertOut("/**\n * @constructor\n */\norg.apache.flex.A = function() {\n};\n\n\n/**\n * @export\n * @const\n * @type {number}\n */\norg.apache.flex.A.A = 42;\n\n\n/**\n * @protected\n * @const\n * @type {number}\n */\norg.apache.flex.A.B = 42;\n\n\n/**\n * @private\n * @const\n * @type {number}\n */\norg.apache.flex.A.C = 42;\n\n\n/**\n * @export\n * @const\n * @type {string}\n */\norg.apache.flex.A.C = 'me' + 'you';");
+ }
+
+ @Override
+ @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{}" + "}");
+ asBlockWalker.visitClass(node);
+ assertOut("/**\n * @constructor\n */\norg.apache.flex.A = function() {\n};\n\n\nObject.defineProperties(org.apache.flex.A.prototype, /** @lends {org.apache.flex.A.prototype} */ {\n/** @export */\nfoo1: {\nget: /** @this {org.apache.flex.A} */ function() {\n return null;\n},\nset: /** @this {org.apache.flex.A} */ function(value) {\n}},\n/** @export */\nfoo2: {\nget: /** @this {org.apache.flex.A} */ function() {\n return null;\n},\nset: /** @this {org.apache.flex.A} */ function(value) {\n}},\n/** @export */\nfoo3: {\nget: /** @this {org.apache.flex.A} */ function() {\n return null;\n},\nset: /** @this {org.apache.flex.A} */ function(value) {\n}},\n/** @export */\nfoo5: {\nget: /** @this {org.apache.flex.A} */ function() {\n return null;\n},\nset: /** @this {org.apache.flex.A} */ function(value) {\n}},\n/** @export */\nfoo6: {\nget: /** @this {org.apache.flex.A} */ function() {\n return null;\n},\nset: /** @this {org.apache.flex.A} */ function(value) {\n}}}\n);");
+ }
+
+ @Override
+ @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{}" + "}");
+ asBlockWalker.visitClass(node);
+ assertOut("/**\n * @constructor\n */\norg.apache.flex.A = function() {\n};\n\n\n/**\n * @export\n * @return {Object}\n */\norg.apache.flex.A.prototype.foo1 = function() {\n return null;\n};\n\n\n/**\n * @export\n * @return {Object}\n */\norg.apache.flex.A.prototype.foo1a = function() {\n return null;\n};\n\n\n/**\n * @export\n * @override\n */\norg.apache.flex.A.prototype.foo1b = function() {\n return org.apache.flex.A.base(this, 'foo1b');\n};\n\n\n/**\n * @protected\n * @param {Object} value\n */\norg.apache.flex.A.prototype.foo2 = function(value) {\n};\n\n\n/**\n * @private\n * @param {Object} value\n */\norg.apache.flex.A.prototype.foo3 = function(value) {\n};\n\n\n/**\n * @param {Object} value\n */\norg.apache.flex.A.prototype.foo5 = function(value) {\n};\n\n\n/**\n * @param {Object} value\n */\norg.apache.flex.A.prototype.foo6 = function(value) {\n};\n\n\n/**\n * @export\n * @param {Object} value\n */\norg.apache.flex.A.foo7 = function(value) {\n};\n\n\n/**\n * @para
m {Object} value\n */\norg.apache.flex.A.foo7 = function(value) {\n};");
+ }
+
+ @Test
+ public void testMethodsWithLocalFunctions()
+ {
+ IClassNode node = getClassNode("public class B {"
+ + "public function foo1():Object{function bar1():Object {return null;}; return bar1()}"
+ + "public function foo2():Object{function bar2(param1:Object):Object {return null;}; return bar2('foo');}"
+ + "}");
+ asBlockWalker.visitClass(node);
+ assertOut("/**\n * @constructor\n */\norg.apache.flex.B = function() {\n};\n\n\n/**\n * @export\n * @return {Object}\n */\norg.apache.flex.B.prototype.foo1 = function() {\n var self = this;\n function bar1() {\n return null;\n };\n return bar1();\n};\n\n\n/**\n * @export\n * @return {Object}\n */\norg.apache.flex.B.prototype.foo2 = function() {\n var self = this;\n function bar2(param1) {\n return null;\n };\n return bar2('foo');\n};");
+ }
+
+ @Test
+ public void testMethodsWithLocalFunctions2()
+ {
+ IClassNode node = getClassNode("public class B {"
+ + "public var baz1:String;"
+ + "public function foo1():String{function bar1():String {return baz1;}; return bar1()}"
+ + "public function foo2():String{function bar2(param1:String):String {return param1 + baz1;}; return bar2('foo');}"
+ + "}");
+ asBlockWalker.visitClass(node);
+ assertOut("/**\n * @constructor\n */\norg.apache.flex.B = function() {\n};\n\n\n/**\n * @export\n * @type {string}\n */\norg.apache.flex.B.prototype.baz1;\n\n\n/**\n * @export\n * @return {string}\n */\norg.apache.flex.B.prototype.foo1 = function() {\n var self = this;\n function bar1() {\n return this.baz1;\n };\n return bar1();\n};\n\n\n/**\n * @export\n * @return {string}\n */\norg.apache.flex.B.prototype.foo2 = function() {\n var self = this;\n function bar2(param1) {\n return param1 + this.baz1;\n };\n return bar2('foo');\n};");
+ }
+
+ @Test
+ public void testClassWithoutConstructor()
+ {
+ /* AJH couldn't find a way to reproduce the code paths
+ * in a simple test case. May require multiple compilation
+ * units in the same package.
+ */
+
+ // (erikdebruin) what's wrong with this test case and/or the resulting code?
+
+ // (erikdebruin) if you're looking for a way to test multiple cu's
+ // (a project), look in 'TestGoogProject' for an example
+
+ IClassNode node = getClassNode("public class B {"
+ + "public function clone():B { return new B() }"
+ + "}");
+ asBlockWalker.visitClass(node);
+ assertOut("/**\n * @constructor\n */\norg.apache.flex.B = function() {\n};\n\n\n/**\n * @export\n * @return {org.apache.flex.B}\n */\norg.apache.flex.B.prototype.clone = function() {\n return new org.apache.flex.B();\n};");
+ }
+
+ @Override
+ @Test
+ public void testSimple()
+ {
+ IClassNode node = getClassNode("public class A{}");
+ asBlockWalker.visitClass(node);
+ assertOut("/**\n * @constructor\n */\norg.apache.flex.A = function() {\n};");
+ }
+
+ @Override
+ @Test
+ public void testSimpleInternal()
+ {
+ // (erikdebruin) the AS compiler will enforce 'internal' namespace,
+ // in JS we ignore it
+ IClassNode node = getClassNode("internal class A{}");
+ asBlockWalker.visitClass(node);
+ assertOut("/**\n * @constructor\n */\norg.apache.flex.A = function() {\n};");
+ }
+
+ @Override
+ @Test
+ public void testSimpleFinal()
+ {
+ // (erikdebruin) the AS compiler will enforce the 'final' keyword,
+ // in JS we ignore it
+ IClassNode node = getClassNode("public final class A{}");
+ asBlockWalker.visitClass(node);
+ assertOut("/**\n * @constructor\n */\norg.apache.flex.A = function() {\n};");
+ }
+
+ @Override
+ @Test
+ public void testSimpleDynamic()
+ {
+ // (erikdebruin) all JS objects are 'dynamic' by design
+ IClassNode node = getClassNode("public dynamic class A{}");
+ asBlockWalker.visitClass(node);
+ assertOut("/**\n * @constructor\n */\norg.apache.flex.A = function() {\n};");
+ }
+
+ @Override
+ @Test
+ public void testSimpleImplements()
+ {
+ IClassNode node = getClassNode("public class A implements IEventDispatcher {public function A() {}}");
+ asBlockWalker.visitClass(node);
+ assertOut("/**\n * @constructor\n * @implements {flash.events.IEventDispatcher}\n */\norg.apache.flex.A = function() {\n};");
+ }
+
+ @Override
+ @Test
+ public void testSimpleImplementsMultiple()
+ {
+ IClassNode node = getClassNode("public class A implements IEventDispatcher, ListenableKey {public function A() {}}");
+ asBlockWalker.visitClass(node);
+ assertOut("/**\n * @constructor\n * @implements {flash.events.IEventDispatcher}\n * @implements {goog.events.ListenableKey}\n */\norg.apache.flex.A = function() {\n};");
+ }
+
+
+ @Override
+ @Test
+ public void testConstructor()
+ {
+ IClassNode node = getClassNode("public class A {public function A() { }}");
+ asBlockWalker.visitClass(node);
+ assertOut("/**\n * @constructor\n */\norg.apache.flex.A = function() {\n};");
+ }
+
+
+ @Override
+ @Test
+ public void testConstructor_withArguments()
+ {
+ IClassNode node = getClassNode("public class A {public function A(arg1:String, arg2:int) {}}");
+ asBlockWalker.visitClass(node);
+ assertOut("/**\n * @constructor\n * @param {string} arg1\n * @param {number} arg2\n */\norg.apache.flex.A = function(arg1, arg2) {\n};");
+ }
+
+ @Test
+ public void testConstructor_withBodyAndComplexInitializer()
+ {
+ IClassNode node = getClassNode("public class A {public function A(arg1:String, arg2:int) {arg2 = arg2 + 2;} public var foo:Array = [];}");
+ asBlockWalker.visitClass(node);
+ assertOut("/**\n * @constructor\n * @param {string} arg1\n * @param {number} arg2\n */\norg.apache.flex.A = function(arg1, arg2) {\n \n this.foo = [];\n arg2 = arg2 + 2;\n};\n\n\n/**\n * @export\n * @type {Array}\n */\norg.apache.flex.A.prototype.foo;");
+ }
+
+ @Test
+ public void testConstructor_withImplicitSuperAndBodyAndComplexInitializer()
+ {
+ IClassNode node = getClassNode("public class A extends EventTarget {public function A(arg1:String, arg2:int) {arg2 = arg2 + 2;} public var foo:Array = [];}");
+ asBlockWalker.visitClass(node);
+ assertOut("/**\n * @constructor\n * @extends {goog.events.EventTarget}\n * @param {string} arg1\n * @param {number} arg2\n */\norg.apache.flex.A = function(arg1, arg2) {\n org.apache.flex.A.base(this, 'constructor');\n \n this.foo = [];\n arg2 = arg2 + 2;\n};\ngoog.inherits(org.apache.flex.A, goog.events.EventTarget);\n\n\n/**\n * @export\n * @type {Array}\n */\norg.apache.flex.A.prototype.foo;");
+ }
+
+ protected IBackend createBackend()
+ {
+ return new FlexJSBackend();
+ }
+
+}