You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by ms...@apache.org on 2015/06/12 17:38:55 UTC

git commit: [flex-falcon] [refs/heads/develop] - Fixed Math "namespace" not being recognized as a final class. - Still major work and tests to support packages, not impl currently. - Initial ES3 test for classes - My formatter is back to the original I w

Repository: flex-falcon
Updated Branches:
  refs/heads/develop e39f4e042 -> 4e7322ff0


Fixed Math "namespace" not being recognized as a final class.
- Still major work and tests to support packages, not impl currently.
- Initial ES3 test for classes
- My formatter is back to the original I was using, no more messed up
formatted commits where nothing really changed.


Project: http://git-wip-us.apache.org/repos/asf/flex-falcon/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-falcon/commit/4e7322ff
Tree: http://git-wip-us.apache.org/repos/asf/flex-falcon/tree/4e7322ff
Diff: http://git-wip-us.apache.org/repos/asf/flex-falcon/diff/4e7322ff

Branch: refs/heads/develop
Commit: 4e7322ff029cf928d7fe910a616d1cd3e072867a
Parents: e39f4e0
Author: Michael Schmalle <ms...@apache.org>
Authored: Fri Jun 12 11:38:23 2015 -0400
Committer: Michael Schmalle <ms...@apache.org>
Committed: Fri Jun 12 11:38:23 2015 -0400

----------------------------------------------------------------------
 .../codegen/externals/ExternalsTestBase.java    |  5 ++
 .../codegen/externals/TestConstructor.java      | 56 +++++++++++----
 .../codegen/externals/TestExternES3.java        | 75 ++++++++++++++++++++
 .../externals_unit_tests/constructor_params.js  | 12 +++-
 .../codegen/externals/pass/AddMemberPass.java   |  5 +-
 .../externals/reference/ClassReference.java     | 10 +++
 .../reference/NullConstructorReference.java     | 45 ++++++++++++
 .../externals/reference/ReferenceModel.java     | 41 ++++++++++-
 .../codegen/externals/utils/FunctionUtils.java  | 44 ++++++------
 9 files changed, 253 insertions(+), 40 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/4e7322ff/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/externals/ExternalsTestBase.java
----------------------------------------------------------------------
diff --git a/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/externals/ExternalsTestBase.java b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/externals/ExternalsTestBase.java
index 1e1ff73..b4b8789 100644
--- a/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/externals/ExternalsTestBase.java
+++ b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/externals/ExternalsTestBase.java
@@ -70,6 +70,11 @@ public abstract class ExternalsTestBase
     protected Result compile(File file) throws IOException
     {
         config.addExternal(file);
+        return compile();
+    }
+
+    protected Result compile() throws IOException
+    {
         Result result = client.compile();
         Assert.assertTrue(result.success);
         return result;

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/4e7322ff/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/externals/TestConstructor.java
----------------------------------------------------------------------
diff --git a/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/externals/TestConstructor.java b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/externals/TestConstructor.java
index 973c31e..175c803 100644
--- a/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/externals/TestConstructor.java
+++ b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/externals/TestConstructor.java
@@ -34,6 +34,17 @@ public class TestConstructor extends ExternalsTestBase
 {
 
     @Test
+    public void test_const_object_literal() throws IOException
+    {
+        compile("constructor_params.js");
+
+        assertTrue(model.hasClass("FinalClass"));
+        assertTrue(model.getClassReference("FinalClass").isFinal());
+        assertTrue(model.getClassReference("FinalClass").hasMethod("bar"));
+        assertTrue(model.getClassReference("FinalClass").getMethod("bar").isStatic());
+    }
+
+    @Test
     public void test_constructor_args() throws IOException
     {
         compile("constructor_params.js");
@@ -51,20 +62,33 @@ public class TestConstructor extends ExternalsTestBase
         assertEquals(0, FooNoArgs.getConstructor().getParameterNames().size());
         assertEquals(2, FooOptArgs.getConstructor().getParameterNames().size());
         assertEquals(2, FooVarArgs.getConstructor().getParameterNames().size());
-        assertEquals(3, FooOptVarArgs.getConstructor().getParameterNames().size());
-
-        assertFalse(FooOptArgs.getConstructor().getComment().getParameterType("arg1").isOptionalArg());
-        assertTrue(FooOptArgs.getConstructor().getComment().getParameterType("opt_arg2").isOptionalArg());
-
-        assertFalse(FooVarArgs.getConstructor().getComment().getParameterType("arg1").isVarArgs());
-        assertTrue(FooVarArgs.getConstructor().getComment().getParameterType("var_args").isVarArgs());
-
-        assertTrue(FooOptVarArgs.getConstructor().getComment().getParameterType("opt_arg2").isOptionalArg());
-        assertTrue(FooOptVarArgs.getConstructor().getComment().getParameterType("var_args").isVarArgs());
-
-        assertEquals("number", evaluateParam(FooOptVarArgs.getConstructor(), "arg1").toAnnotationString());
-        assertEquals("*", evaluateParam(FooOptVarArgs.getConstructor(), "opt_arg2").toAnnotationString());
-        assertEquals("*", evaluateParam(FooOptVarArgs.getConstructor(), "var_args").toAnnotationString());
+        assertEquals(3,
+                FooOptVarArgs.getConstructor().getParameterNames().size());
+
+        assertFalse(FooOptArgs.getConstructor().getComment().getParameterType(
+                "arg1").isOptionalArg());
+        assertTrue(FooOptArgs.getConstructor().getComment().getParameterType(
+                "opt_arg2").isOptionalArg());
+
+        assertFalse(FooVarArgs.getConstructor().getComment().getParameterType(
+                "arg1").isVarArgs());
+        assertTrue(FooVarArgs.getConstructor().getComment().getParameterType(
+                "var_args").isVarArgs());
+
+        assertTrue(FooOptVarArgs.getConstructor().getComment().getParameterType(
+                "opt_arg2").isOptionalArg());
+        assertTrue(FooOptVarArgs.getConstructor().getComment().getParameterType(
+                "var_args").isVarArgs());
+
+        assertEquals(
+                "number",
+                evaluateParam(FooOptVarArgs.getConstructor(), "arg1").toAnnotationString());
+        assertEquals(
+                "*",
+                evaluateParam(FooOptVarArgs.getConstructor(), "opt_arg2").toAnnotationString());
+        assertEquals(
+                "*",
+                evaluateParam(FooOptVarArgs.getConstructor(), "var_args").toAnnotationString());
     }
 
     @Test
@@ -77,7 +101,9 @@ public class TestConstructor extends ExternalsTestBase
         ClassReference FooOptVarArgs = model.getClassReference("FooOptVarArgs");
         FooOptVarArgs.getConstructor().emit(sb);
         String string = sb.toString();
-        assertEquals("    /**\n     * A constructor with arg, opt arg and var args.\n     *\n     * @param arg1 [number] The arg 1.\n     * @param opt_arg2 [*] The arg  that is wrapped by another line in the comment.\n     * @param var_args [*] A var agr param.\n     * @see http://foo.bar.com \n     * @see [constructor_params]\n     * @returns {(FooVarArgs|null)} Another instance.\n     */\n    native public function FooOptVarArgs(arg1:Number, opt_arg2:* = null, ...rest);\n", string);
+        assertEquals(
+                "    /**\n     * A constructor with arg, opt arg and var args.\n     *\n     * @param arg1 [number] The arg 1.\n     * @param opt_arg2 [*] The arg  that is wrapped by another line in the comment.\n     * @param var_args [*] A var agr param.\n     * @see http://foo.bar.com \n     * @see [constructor_params]\n     * @returns {(FooVarArgs|null)} Another instance.\n     */\n    native public function FooOptVarArgs(arg1:Number, opt_arg2:* = null, ...rest);\n",
+                string);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/4e7322ff/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/externals/TestExternES3.java
----------------------------------------------------------------------
diff --git a/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/externals/TestExternES3.java b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/externals/TestExternES3.java
new file mode 100644
index 0000000..5dee9b5
--- /dev/null
+++ b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/externals/TestExternES3.java
@@ -0,0 +1,75 @@
+/*
+ *
+ *  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.assertTrue;
+
+import java.io.IOException;
+
+import org.apache.flex.compiler.clients.ExternCConfiguration;
+import org.junit.Test;
+
+import com.google.javascript.jscomp.Result;
+
+public class TestExternES3 extends ExternalsTestBase
+{
+    @Test
+    public void test_classes() throws IOException
+    {
+        Result result = compile();
+        assertTrue(result.success);
+
+        String[] classes = {
+                "Arguments",
+                "Object",
+                "Function",
+                "Array",
+                "Boolean",
+                "Number",
+                "Date",
+                "String",
+                "RegExp",
+                "Error",
+                "EvalError",
+                "RangeError",
+                "ReferenceError",
+                "SyntaxError",
+                "TypeError",
+                "URIError",
+                "Math" };
+
+        assertEquals(17, model.getClasses().size());
+        for (String className : classes)
+        {
+            assertTrue(model.hasClass(className));
+        }
+    }
+
+    @Override
+    protected void configure(ExternCConfiguration config) throws IOException
+    {
+        config.setASRoot(ExternalsTestUtils.AS_ROOT_DIR);
+
+        String coreRoot = ExternalsTestUtils.EXTERNAL_JS_DIR.getAbsolutePath();
+        config.addExternal(coreRoot + "/es3.js");
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/4e7322ff/compiler.jx.tests/test-files/externals_unit_tests/constructor_params.js
----------------------------------------------------------------------
diff --git a/compiler.jx.tests/test-files/externals_unit_tests/constructor_params.js b/compiler.jx.tests/test-files/externals_unit_tests/constructor_params.js
index 87a1254..1029bdb 100644
--- a/compiler.jx.tests/test-files/externals_unit_tests/constructor_params.js
+++ b/compiler.jx.tests/test-files/externals_unit_tests/constructor_params.js
@@ -68,4 +68,14 @@ AssignFooNoArgs = function () {};
  *
  * @constructor
  */
-var VarAssignFooNoArgs = function () {};
\ No newline at end of file
+var VarAssignFooNoArgs = function () {};
+
+/**
+ * @const
+ */
+var FinalClass = {};
+
+/**
+ * A static method.
+ */
+FinalClass.bar = function () {};
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/4e7322ff/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/pass/AddMemberPass.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/pass/AddMemberPass.java b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/pass/AddMemberPass.java
index 18b65be..303a80e 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/pass/AddMemberPass.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/pass/AddMemberPass.java
@@ -209,7 +209,7 @@ public class AddMemberPass extends AbstractCompilerPass
 
         if (getProp.getFirstChild().isGetProp())
         {
-            ClassReference classReference = model.getClassReference(className.getString());
+            ClassReference classReference = model.findClassReference(className.getString());
             if (classReference != null)
             {
                 classReference.addMethod(n, functionName.getString(), jsDoc,
@@ -217,6 +217,7 @@ public class AddMemberPass extends AbstractCompilerPass
             }
             else
             {
+
                 System.err.println(">>>> {AddMemberPass.addMethod()} Class ["
                         + className + "] not found in " + n.getSourceFileName());
             }
@@ -227,7 +228,7 @@ public class AddMemberPass extends AbstractCompilerPass
             functionName = getProp.getLastChild(); // Same
 
             //System.err.println(n.toStringTree());
-            ClassReference classReference = model.getClassReference(className.getString());
+            ClassReference classReference = model.findClassReference(className.getString());
             if (classReference != null)
             {
                 classReference.addMethod(n, functionName.getString(), jsDoc,

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/4e7322ff/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/reference/ClassReference.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/reference/ClassReference.java b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/reference/ClassReference.java
index b733af4..04deede 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/reference/ClassReference.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/reference/ClassReference.java
@@ -108,6 +108,16 @@ public class ClassReference extends BaseReference
                 NAME MediaConstraints 727 [source_file: [w3c_rtc]] [length: 16]
              */
         }
+        else if (comment.isConstant())
+        {
+            /*
+             VAR 882 [jsdoc_info: JSDocInfo]
+                NAME Math 
+                    OBJECTLIT
+             */
+            constructor = new NullConstructorReference(model, this, node,
+                    getBaseName(), comment);
+        }
         else if (node.isFunction())
         {
             /*

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/4e7322ff/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/reference/NullConstructorReference.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/reference/NullConstructorReference.java b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/reference/NullConstructorReference.java
new file mode 100644
index 0000000..80c1369
--- /dev/null
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/reference/NullConstructorReference.java
@@ -0,0 +1,45 @@
+/*
+ *
+ *  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.reference;
+
+import com.google.javascript.rhino.JSDocInfo;
+import com.google.javascript.rhino.Node;
+
+public class NullConstructorReference extends MethodReference
+{
+
+    public NullConstructorReference(ReferenceModel model,
+            ClassReference classReference, Node node, String name,
+            JSDocInfo comment)
+    {
+        super(model, classReference, node, name, comment, false);
+    }
+
+    @Override
+    protected void emitFunctionCommentBody(StringBuilder sb)
+    {
+        super.emitFunctionCommentBody(sb);
+
+        emitBlockDescription(sb);
+        emitSee(sb);
+        emitSeeSourceFileName(sb);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/4e7322ff/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/reference/ReferenceModel.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/reference/ReferenceModel.java b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/reference/ReferenceModel.java
index 31900fd..9319153 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/reference/ReferenceModel.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/reference/ReferenceModel.java
@@ -39,6 +39,9 @@ public class ReferenceModel
     private Compiler compiler;
 
     private List<String> namespaces = new ArrayList<String>();
+
+    private HashMap<String, ClassReference> possibleClasses = new HashMap<String, ClassReference>();
+
     private HashMap<String, ClassReference> typedefs = new HashMap<String, ClassReference>();
     private HashMap<String, ClassReference> classes = new HashMap<String, ClassReference>();
     private HashMap<String, FunctionReference> functions = new HashMap<String, FunctionReference>();
@@ -94,6 +97,25 @@ public class ReferenceModel
         return classes.get(qName);
     }
 
+    public ClassReference findClassReference(String qName)
+    {
+        ClassReference reference = classes.get(qName);
+        if (reference != null)
+            return reference;
+        reference = possibleClasses.get(qName);
+        if (reference != null)
+        {
+            System.err.println(">>>> {ReferenceModel} Found class ["
+                    + qName
+                    + "] in possible classes from namespace, promoting to class in "
+                    + reference.getNode().getSourceFileName());
+            possibleClasses.remove(qName);
+            classes.put(qName, reference);
+            return reference;
+        }
+        return null;
+    }
+
     public void addNamespace(Node node, String qName)
     {
         if (namespaces.contains(qName))
@@ -102,7 +124,17 @@ public class ReferenceModel
             return;
         }
 
-        System.out.println("Model.addNamespace(" + qName + ")");
+        if (node.getJSDocInfo().isConstant())
+        {
+            System.out.println("Model.addPossibleClass(" + qName + ")");
+            ClassReference reference = new ClassReference(this, node, qName);
+            reference.setFinal(true);
+            possibleClasses.put(qName, reference);
+        }
+        else
+        {
+            System.out.println("Model.addNamespace(" + qName + ")");
+        }
 
         namespaces.add(qName);
     }
@@ -179,6 +211,11 @@ public class ReferenceModel
         functions.put(qName, reference);
     }
 
+    public boolean hasClass(String className)
+    {
+        return classes.containsKey(className);
+    }
+
     public boolean hasConstant(String qName)
     {
         return constants.containsKey(qName);
@@ -224,7 +261,7 @@ public class ReferenceModel
 
     public void addStaticField(Node node, String className, String qualfiedName)
     {
-        ClassReference classReference = getClassReference(className);
+        ClassReference classReference = findClassReference(className);
         // XXX this is here because for now, the doc might be on the parent ASSIGN node
         // if it's a static property with a value
         JSDocInfo comment = NodeUtil.getBestJSDocInfo(node);

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/4e7322ff/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/utils/FunctionUtils.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/utils/FunctionUtils.java b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/utils/FunctionUtils.java
index ebbe279..e6a8a39 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/utils/FunctionUtils.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/utils/FunctionUtils.java
@@ -58,34 +58,38 @@ public class FunctionUtils
     {
         StringBuilder sb = new StringBuilder();
         sb.append("(");
-        int index = 0;
-        int len = comment.getParameterCount();
 
-        if (len == 0)
+        if (paramNode != null)
         {
-            len = paramNode.getChildCount();
-            // Missing JSDocInf @param tags
-            if (len > 0)
+            int index = 0;
+            int len = comment.getParameterCount();
+
+            if (len == 0)
             {
-                for (Node param : paramNode.children())
+                len = paramNode.getChildCount();
+                // Missing JSDocInf @param tags
+                if (len > 0)
                 {
-                    sb.append(param.getString() + ":Object");
-                    if (index < len - 1)
-                        sb.append(", ");
-                    index++;
+                    for (Node param : paramNode.children())
+                    {
+                        sb.append(param.getString() + ":Object");
+                        if (index < len - 1)
+                            sb.append(", ");
+                        index++;
+                    }
                 }
             }
-        }
-        else
-        {
-            for (String paramName : comment.getParameterNames())
+            else
             {
-                sb.append(toParameter(reference, comment, paramName,
-                        comment.getParameterType(paramName)));
+                for (String paramName : comment.getParameterNames())
+                {
+                    sb.append(toParameter(reference, comment, paramName,
+                            comment.getParameterType(paramName)));
 
-                if (index < len - 1)
-                    sb.append(", ");
-                index++;
+                    if (index < len - 1)
+                        sb.append(", ");
+                    index++;
+                }
             }
         }