You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by er...@apache.org on 2013/01/10 10:23:53 UTC
svn commit: r1431223 - in /flex/whiteboard/mschmalle/falconjx:
compiler.jx.tests/src/org/apache/flex/compiler/internal/as/codegen/
compiler.jx.tests/src/org/apache/flex/compiler/internal/js/codegen/goog/
compiler.jx/src/org/apache/flex/compiler/interna...
Author: erikdebruin
Date: Thu Jan 10 09:23:53 2013
New Revision: 1431223
URL: http://svn.apache.org/viewvc?rev=1431223&view=rev
Log:
- created tests for AS Global Functions and made some minor adjustments to the doc emitter to make them pass
Added:
flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/compiler/internal/as/codegen/TestGlobalFunctions.java (with props)
flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/compiler/internal/js/codegen/goog/TestGoogGlobalFunctions.java (with props)
Modified:
flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/js/codegen/goog/JSGoogDocEmitter.java
Added: flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/compiler/internal/as/codegen/TestGlobalFunctions.java
URL: http://svn.apache.org/viewvc/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/compiler/internal/as/codegen/TestGlobalFunctions.java?rev=1431223&view=auto
==============================================================================
--- flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/compiler/internal/as/codegen/TestGlobalFunctions.java (added)
+++ flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/compiler/internal/as/codegen/TestGlobalFunctions.java Thu Jan 10 09:23:53 2013
@@ -0,0 +1,215 @@
+/*
+ *
+ * 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.IFunctionCallNode;
+import org.apache.flex.compiler.tree.as.IVariableNode;
+import org.junit.Test;
+
+/**
+ * @author Erik de Bruin
+ */
+public class TestGlobalFunctions extends TestWalkerBase
+{
+ @Test
+ public void testArray()
+ {
+ IVariableNode node = getVariable("var a:Array = Array(1);");
+ visitor.visitVariable(node);
+ assertOut("var a:Array = Array(1)");
+ }
+
+ @Test
+ public void testBoolean()
+ {
+ IVariableNode node = getVariable("var a:Boolean = Boolean(1);");
+ visitor.visitVariable(node);
+ assertOut("var a:Boolean = Boolean(1)");
+ }
+
+ @Test
+ public void testDecodeURI()
+ {
+ IVariableNode node = getVariable("var a:String = decodeURI('http://whatever.com');");
+ visitor.visitVariable(node);
+ assertOut("var a:String = decodeURI('http://whatever.com')");
+ }
+
+ @Test
+ public void testDecodeURIComponent()
+ {
+ IVariableNode node = getVariable("var a:String = decodeURIComponent('http://whatever.com');");
+ visitor.visitVariable(node);
+ assertOut("var a:String = decodeURIComponent('http://whatever.com')");
+ }
+
+ @Test
+ public void testEncodeURI()
+ {
+ IVariableNode node = getVariable("var a:String = encodeURI('http://whatever.com');");
+ visitor.visitVariable(node);
+ assertOut("var a:String = encodeURI('http://whatever.com')");
+ }
+
+ @Test
+ public void testEncodeURIComponent()
+ {
+ IVariableNode node = getVariable("var a:String = encodeURIComponent('http://whatever.com');");
+ visitor.visitVariable(node);
+ assertOut("var a:String = encodeURIComponent('http://whatever.com')");
+ }
+
+ @Test
+ public void testEscape()
+ {
+ IVariableNode node = getVariable("var a:String = escape('http://whatever.com');");
+ visitor.visitVariable(node);
+ assertOut("var a:String = escape('http://whatever.com')");
+ }
+
+ @Test
+ public void testInt()
+ {
+ IVariableNode node = getVariable("var a:int = int(1.8);");
+ visitor.visitVariable(node);
+ assertOut("var a:int = int(1.8)");
+ }
+
+ @Test
+ public void testIsFinite()
+ {
+ IVariableNode node = getVariable("var a:Boolean = isFinite(1000000.9);");
+ visitor.visitVariable(node);
+ assertOut("var a:Boolean = isFinite(1000000.9)");
+ }
+
+ @Test
+ public void testIsNaN()
+ {
+ IVariableNode node = getVariable("var a:Boolean = isNaN(NaN);");
+ visitor.visitVariable(node);
+ assertOut("var a:Boolean = isNaN(NaN)");
+ }
+
+ @Test
+ public void testIsXMLName()
+ {
+ IVariableNode node = getVariable("var a:Boolean = isXMLName(\"?\");");
+ visitor.visitVariable(node);
+ assertOut("var a:Boolean = isXMLName(\"?\")");
+ }
+
+ @Test
+ public void testNumber()
+ {
+ IVariableNode node = getVariable("var a:Number = Number(\"1\");");
+ visitor.visitVariable(node);
+ assertOut("var a:Number = Number(\"1\")");
+ }
+
+ @Test
+ public void testObject()
+ {
+ IVariableNode node = getVariable("var a:Object = Object(\"1\");");
+ visitor.visitVariable(node);
+ assertOut("var a:Object = Object(\"1\")");
+ }
+
+ @Test
+ public void testParseFloat()
+ {
+ IVariableNode node = getVariable("var a:Number = parseFloat(\"1.8\");");
+ visitor.visitVariable(node);
+ assertOut("var a:Number = parseFloat(\"1.8\")");
+ }
+
+ @Test
+ public void testParseInt()
+ {
+ IVariableNode node = getVariable("var a:Number = parseInt(\"666\", 10);");
+ visitor.visitVariable(node);
+ assertOut("var a:Number = parseInt(\"666\", 10)");
+ }
+
+ @Test
+ public void testString()
+ {
+ IVariableNode node = getVariable("var a:String = String(100);");
+ visitor.visitVariable(node);
+ assertOut("var a:String = String(100)");
+ }
+
+ @Test
+ public void testTrace()
+ {
+ IFunctionCallNode node = (IFunctionCallNode) getNode(
+ "trace('Hello World');", IFunctionCallNode.class);
+ visitor.visitFunctionCall(node);
+ assertOut("trace('Hello World')");
+ }
+
+ @Test
+ public void testUint()
+ {
+ IVariableNode node = getVariable("var a:uint = uint(-100);");
+ visitor.visitVariable(node);
+ assertOut("var a:uint = uint(-100)");
+ }
+
+ @Test
+ public void testUnescape()
+ {
+ IVariableNode node = getVariable("var a:String = unescape('%25');");
+ visitor.visitVariable(node);
+ assertOut("var a:String = unescape('%25')");
+ }
+
+ @Test
+ public void testVector()
+ {
+ // TODO (erikdebruin/mschmalle) the space between the comma and 'World'
+ // is lost in translation?
+ IVariableNode node = getVariable("var a:Vector.<String> = Vector.<String>(['Hello', 'World']);");
+ visitor.visitVariable(node);
+ assertOut("var a:Vector.<String> = Vector.<String>(['Hello','World'])");
+ }
+
+ @Test
+ public void testXML()
+ {
+ IVariableNode node = getVariable("var a:XML = XML('@');");
+ visitor.visitVariable(node);
+ assertOut("var a:XML = XML('@')");
+ }
+
+ @Test
+ public void testXMLList()
+ {
+ IVariableNode node = getVariable("var a:XMLList = XMLList('<!-- comment -->');");
+ visitor.visitVariable(node);
+ assertOut("var a:XMLList = XMLList('<!-- comment -->')");
+ }
+
+ protected IVariableNode getVariable(String code)
+ {
+ IVariableNode node = (IVariableNode) getNode(code, IVariableNode.class);
+ return node;
+ }
+}
Propchange: flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/compiler/internal/as/codegen/TestGlobalFunctions.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/compiler/internal/js/codegen/goog/TestGoogGlobalFunctions.java
URL: http://svn.apache.org/viewvc/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/compiler/internal/js/codegen/goog/TestGoogGlobalFunctions.java?rev=1431223&view=auto
==============================================================================
--- flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/compiler/internal/js/codegen/goog/TestGoogGlobalFunctions.java (added)
+++ flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/compiler/internal/js/codegen/goog/TestGoogGlobalFunctions.java Thu Jan 10 09:23:53 2013
@@ -0,0 +1,242 @@
+/*
+ *
+ * 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.js.codegen.goog;
+
+import org.apache.flex.compiler.clients.IBackend;
+import org.apache.flex.compiler.internal.as.codegen.TestGlobalFunctions;
+import org.apache.flex.compiler.internal.js.driver.goog.GoogBackend;
+import org.apache.flex.compiler.tree.as.IFunctionCallNode;
+import org.apache.flex.compiler.tree.as.IVariableNode;
+import org.junit.Ignore;
+import org.junit.Test;
+
+/**
+ * @author Erik de Bruin
+ */
+public class TestGoogGlobalFunctions extends TestGlobalFunctions
+{
+ @Override
+ @Test
+ public void testArray()
+ {
+ IVariableNode node = getVariable("var a:Array = Array(1);");
+ visitor.visitVariable(node);
+ assertOut("var /** @type {Array} */ a = Array(1)");
+ }
+
+ @Override
+ @Test
+ public void testBoolean()
+ {
+ IVariableNode node = getVariable("var a:Boolean = Boolean(1);");
+ visitor.visitVariable(node);
+ assertOut("var /** @type {boolean} */ a = Boolean(1)");
+ }
+
+ @Override
+ @Test
+ public void testDecodeURI()
+ {
+ IVariableNode node = getVariable("var a:String = decodeURI('http://whatever.com');");
+ visitor.visitVariable(node);
+ assertOut("var /** @type {string} */ a = decodeURI('http://whatever.com')");
+ }
+
+ @Override
+ @Test
+ public void testDecodeURIComponent()
+ {
+ IVariableNode node = getVariable("var a:String = decodeURIComponent('http://whatever.com');");
+ visitor.visitVariable(node);
+ assertOut("var /** @type {string} */ a = decodeURIComponent('http://whatever.com')");
+ }
+
+ @Override
+ @Test
+ public void testEncodeURI()
+ {
+ IVariableNode node = getVariable("var a:String = encodeURI('http://whatever.com');");
+ visitor.visitVariable(node);
+ assertOut("var /** @type {string} */ a = encodeURI('http://whatever.com')");
+ }
+
+ @Override
+ @Test
+ public void testEncodeURIComponent()
+ {
+ IVariableNode node = getVariable("var a:String = encodeURIComponent('http://whatever.com');");
+ visitor.visitVariable(node);
+ assertOut("var /** @type {string} */ a = encodeURIComponent('http://whatever.com')");
+ }
+
+ @Override
+ @Test
+ public void testEscape()
+ {
+ IVariableNode node = getVariable("var a:String = escape('http://whatever.com');");
+ visitor.visitVariable(node);
+ assertOut("var /** @type {string} */ a = escape('http://whatever.com')");
+ }
+
+ @Override
+ @Test
+ public void testInt()
+ {
+ IVariableNode node = getVariable("var a:int = int(1.8);");
+ visitor.visitVariable(node);
+ assertOut("var /** @type {number} */ a = int(1.8)");
+ }
+
+ @Override
+ @Test
+ public void testIsFinite()
+ {
+ IVariableNode node = getVariable("var a:Boolean = isFinite(1000000.9);");
+ visitor.visitVariable(node);
+ assertOut("var /** @type {boolean} */ a = isFinite(1000000.9)");
+ }
+
+ @Override
+ @Test
+ public void testIsNaN()
+ {
+ IVariableNode node = getVariable("var a:Boolean = isNaN(NaN);");
+ visitor.visitVariable(node);
+ assertOut("var /** @type {boolean} */ a = isNaN(NaN)");
+ }
+
+ @Override
+ @Test
+ public void testIsXMLName()
+ {
+ IVariableNode node = getVariable("var a:Boolean = isXMLName(\"?\");");
+ visitor.visitVariable(node);
+ assertOut("var /** @type {boolean} */ a = isXMLName(\"?\")");
+ }
+
+ @Override
+ @Test
+ public void testNumber()
+ {
+ IVariableNode node = getVariable("var a:Number = Number(\"1\");");
+ visitor.visitVariable(node);
+ assertOut("var /** @type {number} */ a = Number(\"1\")");
+ }
+
+ @Override
+ @Test
+ public void testObject()
+ {
+ IVariableNode node = getVariable("var a:Object = Object(\"1\");");
+ visitor.visitVariable(node);
+ assertOut("var /** @type {Object} */ a = Object(\"1\")");
+ }
+
+ @Override
+ @Test
+ public void testParseFloat()
+ {
+ IVariableNode node = getVariable("var a:Number = parseFloat(\"1.8\");");
+ visitor.visitVariable(node);
+ assertOut("var /** @type {number} */ a = parseFloat(\"1.8\")");
+ }
+
+ @Override
+ @Test
+ public void testParseInt()
+ {
+ IVariableNode node = getVariable("var a:Number = parseInt(\"666\", 10);");
+ visitor.visitVariable(node);
+ assertOut("var /** @type {number} */ a = parseInt(\"666\", 10)");
+ }
+
+ @Override
+ @Test
+ public void testString()
+ {
+ IVariableNode node = getVariable("var a:String = String(100);");
+ visitor.visitVariable(node);
+ assertOut("var /** @type {string} */ a = String(100)");
+ }
+
+ @Override
+ @Test
+ public void testTrace()
+ {
+ IFunctionCallNode node = (IFunctionCallNode) getNode(
+ "trace('Hello World');", IFunctionCallNode.class);
+ visitor.visitFunctionCall(node);
+ assertOut("trace('Hello World')");
+ }
+
+ @Override
+ @Test
+ public void testUint()
+ {
+ IVariableNode node = getVariable("var a:uint = uint(-100);");
+ visitor.visitVariable(node);
+ assertOut("var /** @type {number} */ a = uint(-100)");
+ }
+
+ @Override
+ @Test
+ public void testUnescape()
+ {
+ IVariableNode node = getVariable("var a:String = unescape('%25');");
+ visitor.visitVariable(node);
+ assertOut("var /** @type {string} */ a = unescape('%25')");
+ }
+
+ @Ignore
+ @Override
+ @Test
+ public void testVector()
+ {
+ // TODO (erikdebruin) first create a Vector workaround, then revisit
+ // this test.
+ IVariableNode node = getVariable("var a:Vector.<String> = Vector.<String>(['Hello', 'World']);");
+ visitor.visitVariable(node);
+ assertOut("var /** @type {Object.<string>} */ a = Vector(['Hello','World'])");
+ }
+
+ @Override
+ @Test
+ public void testXML()
+ {
+ IVariableNode node = getVariable("var a:XML = XML('@');");
+ visitor.visitVariable(node);
+ assertOut("var /** @type {XML} */ a = XML('@')");
+ }
+
+ @Override
+ @Test
+ public void testXMLList()
+ {
+ IVariableNode node = getVariable("var a:XMLList = XMLList('<!-- comment -->');");
+ visitor.visitVariable(node);
+ assertOut("var /** @type {XMLList} */ a = XMLList('<!-- comment -->')");
+ }
+
+ @Override
+ protected IBackend createBackend()
+ {
+ return new GoogBackend();
+ }
+}
Propchange: flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/compiler/internal/js/codegen/goog/TestGoogGlobalFunctions.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/js/codegen/goog/JSGoogDocEmitter.java
URL: http://svn.apache.org/viewvc/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/js/codegen/goog/JSGoogDocEmitter.java?rev=1431223&r1=1431222&r2=1431223&view=diff
==============================================================================
--- flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/js/codegen/goog/JSGoogDocEmitter.java (original)
+++ flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/js/codegen/goog/JSGoogDocEmitter.java Thu Jan 10 09:23:53 2013
@@ -330,16 +330,13 @@ public class JSGoogDocEmitter extends JS
if (name.equals(""))
result = "*";
-
- if (name.equals("String"))
- result = "string";
-
- if (name.equals("int") || name.equals("uint") || name.equals("Number"))
+ else if (name.equals("Boolean") || name.equals("String") || name.equals("Number"))
+ result = result.toLowerCase();
+ else if (name.equals("int") || name.equals("uint"))
result = "number";
-
- // TODO (erikdebruin) this will not work with nested Vector declarations...
- if (name.matches("Vector.<.*>"))
- result = name.replace("Vector", "Array");
+ else if (name.matches("Vector.<.*>"))
+ // TODO (erikdebruin) will this work with nested Vector declarations?
+ result = name.replace("Vector", "Array");
return result;
}