You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by ft...@apache.org on 2015/07/09 16:50:36 UTC

[1/8] git commit: [flex-falcon] [refs/heads/add-collect-import-pass] - Build JS test files based on the Test Method Name

Repository: flex-falcon
Updated Branches:
  refs/heads/add-collect-import-pass [created] 134f1020b


Build JS test files based on the Test Method Name


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

Branch: refs/heads/add-collect-import-pass
Commit: 72fe8eaf12382752d468c4c1af1bae7d414f4377
Parents: 0a63b49
Author: Frédéric THOMAS <we...@gmail.com>
Authored: Tue Jul 7 18:30:45 2015 +0100
Committer: Frédéric THOMAS <we...@gmail.com>
Committed: Tue Jul 7 19:15:39 2015 +0100

----------------------------------------------------------------------
 .../codegen/externals/ExternalsTestBase.java    | 29 ++++++++++++++++----
 1 file changed, 23 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/72fe8eaf/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 b4b8789..cfb088f 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
@@ -19,6 +19,8 @@
 
 package org.apache.flex.compiler.internal.codegen.externals;
 
+import static org.junit.Assert.assertTrue;
+
 import java.io.File;
 import java.io.IOException;
 
@@ -36,8 +38,7 @@ import com.google.javascript.rhino.jstype.JSType;
 
 public abstract class ExternalsTestBase
 {
-    private static File unitTestBaseDir = new File(
-            FilenameNormalization.normalize("test-files/externals_unit_tests"));
+    private static File unitTestBaseDir = new File(FilenameNormalization.normalize("test-files/externals_unit_tests"));
 
     // Only used for testing, all configuration must happen in configure()
     protected ExternCConfiguration config;
@@ -53,8 +54,7 @@ public abstract class ExternalsTestBase
         model = client.getModel();
     }
 
-    protected abstract void configure(ExternCConfiguration config)
-            throws IOException;
+    protected abstract void configure(ExternCConfiguration config) throws IOException;
 
     @After
     public void tearDown()
@@ -82,9 +82,26 @@ public abstract class ExternalsTestBase
 
     protected JSType evaluateParam(MethodReference method, String paramName)
     {
-        JSType jsType = method.getComment().getParameterType(paramName).evaluate(
-                null, client.getCompiler().getJSCompiler().getTypeRegistry());
+        JSType jsType = method.getComment().getParameterType(paramName).evaluate(null,
+                client.getCompiler().getJSCompiler().getTypeRegistry());
         return jsType;
     }
 
+    /**
+     * Clean, compile a js file based on the test method name.
+     * 
+     * @param relativeTestDir unitTestBaseDir relative base test directory.
+     * @throws IOException
+     */
+    protected void assertCompileTestFileSuccess(String relativeTestDir) throws IOException
+    {
+        if (config.getAsRoot() != null)
+        {
+            client.cleanOutput();
+        }
+        final StackTraceElement[] ste = Thread.currentThread().getStackTrace();
+        final String methodName = ste[2].getMethodName();
+        Result result = compile(relativeTestDir + methodName + ".js");
+        assertTrue(result.success);
+    }
 }


[2/8] git commit: [flex-falcon] [refs/heads/add-collect-import-pass] - Introduce ParameterReference and hasImport()

Posted by ft...@apache.org.
Introduce ParameterReference and hasImport()


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

Branch: refs/heads/add-collect-import-pass
Commit: afc574a695251ebcfd6dd4a1483ae4e8d624c369
Parents: 72fe8ea
Author: Frédéric THOMAS <we...@gmail.com>
Authored: Tue Jul 7 19:03:27 2015 +0100
Committer: Frédéric THOMAS <we...@gmail.com>
Committed: Tue Jul 7 19:15:43 2015 +0100

----------------------------------------------------------------------
 .../externals/reference/FunctionReference.java  | 126 ++++++++++++-------
 .../externals/reference/ParameterReference.java |  34 +++++
 2 files changed, 114 insertions(+), 46 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/afc574a6/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/reference/FunctionReference.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/reference/FunctionReference.java b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/reference/FunctionReference.java
index e47cb83..1fbc944 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/reference/FunctionReference.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/reference/FunctionReference.java
@@ -19,38 +19,40 @@
 
 package org.apache.flex.compiler.internal.codegen.externals.reference;
 
-import com.google.javascript.rhino.JSDocInfo;
-import com.google.javascript.rhino.Node;
+import java.io.File;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
 import org.apache.flex.compiler.clients.ExternCConfiguration.ExcludedMember;
 import org.apache.flex.compiler.internal.codegen.externals.utils.FunctionUtils;
 
-import java.io.File;
+import com.google.common.collect.Lists;
+import com.google.javascript.rhino.JSDocInfo;
+import com.google.javascript.rhino.Node;
 
-public class FunctionReference extends BaseReference
-{
+public class FunctionReference extends BaseReference {
     private boolean isStatic;
-    private FunctionReference override;
     private Node paramNode;
+    private Set<String> imports = new HashSet<String>();
+    private List<ParameterReference> parameters;
 
-    public File getFile(File asSourceRoot)
-    {
+    public File getFile(File asSourceRoot) {
         String packageName = "";
 
         return new File(asSourceRoot, packageName + File.separator + getQualifiedName() + ".as");
     }
 
-    private FunctionReference getContext()
-    {
-        return override == null ? this : override;
+    private FunctionReference getContext() {
+        return this;
     }
 
-    public boolean isStatic()
-    {
+    public boolean isStatic() {
         return isStatic;
     }
 
-    public void setStatic(boolean isStatic)
-    {
+    public void setStatic(boolean isStatic) {
         this.isStatic = isStatic;
     }
 
@@ -63,19 +65,47 @@ public class FunctionReference extends BaseReference
         BLOCK
     */
 
-    public FunctionReference(ReferenceModel model, Node node, String qualifiedName, JSDocInfo comment)
-    {
+    public FunctionReference(ReferenceModel model, Node node, String qualifiedName, JSDocInfo comment) {
         super(model, node, qualifiedName, comment);
         this.paramNode = node.getChildAtIndex(1);
+
+        addParameterReferences();
+    }
+
+    private void addParameterReferences() {
+
+        parameters = new ArrayList<ParameterReference>();
+
+        if (paramNode != null) {
+
+            final boolean isDocumented = comment.getParameterCount() > 0;
+            List<String> parameterNames = null;
+
+            if (isDocumented) {
+                parameterNames = Lists.newArrayList(comment.getParameterNames());
+            }
+
+            for (Node param : paramNode.children()) {
+                ParameterReference parameterReference;
+
+                if (isDocumented && parameterNames.contains(param.getString())) {
+                    final String qualifiedName = FunctionUtils.toParameterType(this, param.getString());
+                    parameterReference = new ParameterReference(getModel(), param, qualifiedName);
+                } else {
+                    parameterReference = new ParameterReference(getModel(), param);
+                }
+
+                parameters.add(parameterReference);
+            }
+        }
     }
 
     @Override
-    public void emit(StringBuilder sb)
-    {
+    public void emit(StringBuilder sb) {
         String packageName = "";
 
         sb.append("package ");
-        sb.append(packageName + " ");
+        sb.append(packageName).append(" ");
         sb.append("{\n");
         sb.append("\n");
 
@@ -84,19 +114,17 @@ public class FunctionReference extends BaseReference
         emitComment(sb);
 
         ExcludedMember excluded = isExcluded();
-        if (excluded != null)
-        {
+        if (excluded != null) {
             excluded.print(sb);
         }
 
         String staticValue = (isStatic) ? "static " : "";
 
         String publicModifier = "public ";
-        String braces = "";
+        String braces;
 
         String returns = "";
-        if (!transformReturnString().equals("void"))
-        {
+        if (!transformReturnString().equals("void")) {
             returns = " return null;";
         }
 
@@ -107,7 +135,7 @@ public class FunctionReference extends BaseReference
         sb.append(staticValue);
         sb.append("function ");
         sb.append(getQualifiedName());
-        sb.append(toPrameterString());
+        sb.append(toParameterString());
         sb.append(":");
         sb.append(transformReturnString());
         sb.append(braces);
@@ -116,37 +144,43 @@ public class FunctionReference extends BaseReference
         sb.append("}\n"); // package
     }
 
-    private void printImports(final StringBuilder sb)
-    {
-        String returnType = transformReturnString();
-
-        final boolean canBeImported = FunctionUtils.canBeImported(getModel(), getNode(), returnType, getPackageName());
-
-        if (canBeImported)
-        {
-            sb.append("import ").append(returnType).append(";\n\n");
+    private void printImports(final StringBuilder sb) {
+        if (imports.size() > 0) {
+            for (String anImport : imports) {
+                sb.append("import ").append(anImport).append(";\n");
+            }
+            sb.append("\n");
         }
-
     }
 
-    private String transformReturnString()
-    {
-        return FunctionUtils.toReturnString(getContext(), getComment());
+    public String transformReturnString() {
+        return FunctionUtils.toReturnString(getContext());
     }
 
-    private String toPrameterString()
-    {
-        return FunctionUtils.toPrameterString(getContext(), getComment(), paramNode);
+    private String toParameterString() {
+        return FunctionUtils.toParameterString(getContext(), getComment(), paramNode);
     }
 
-    public boolean isOverride()
-    {
+    public boolean isOverride() {
         return getComment().isOverride();
     }
 
     @Override
-    protected void emitCommentBody(StringBuilder sb)
-    {
+    protected void emitCommentBody(StringBuilder sb) {
         emitFunctionCommentBody(sb);
     }
+
+    public void addImport(ClassReference reference) {
+        if (reference != null) {
+            imports.add(reference.getQualifiedName());
+        }
+    }
+
+    public List<ParameterReference> getParameters() {
+        return parameters;
+    }
+
+    public boolean hasImport(String qualifiedName) {
+        return imports.contains(qualifiedName);
+    }
 }

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/afc574a6/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/reference/ParameterReference.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/reference/ParameterReference.java b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/reference/ParameterReference.java
new file mode 100644
index 0000000..171835f
--- /dev/null
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/reference/ParameterReference.java
@@ -0,0 +1,34 @@
+package org.apache.flex.compiler.internal.codegen.externals.reference;
+
+import com.google.javascript.rhino.Node;
+
+/**
+ * @author: Frederic Thomas Date: 05/07/2015 Time: 19:34
+ */
+public class ParameterReference extends BaseReference
+{
+
+    private String name;
+
+    public ParameterReference(final ReferenceModel model, final Node node, final String qualifiedName)
+    {
+        super(model, node, qualifiedName, null);
+        name = node.getString();
+    }
+
+    public ParameterReference(final ReferenceModel model, final Node parameterNode)
+    {
+        this(model, parameterNode, "Object");
+    }
+
+    @Override
+    public void emit(final StringBuilder sb)
+    {
+        // Emitted by the Method / Function reference.
+    }
+
+    public String getName()
+    {
+        return name;
+    }
+}


[3/8] git commit: [flex-falcon] [refs/heads/add-collect-import-pass] - Add tests for the collect of the imports

Posted by ft...@apache.org.
Add tests for the collect of the imports


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

Branch: refs/heads/add-collect-import-pass
Commit: 298cc732e3abc6078459ff433b6b00101a92377f
Parents: afc574a
Author: Frédéric THOMAS <we...@gmail.com>
Authored: Tue Jul 7 19:05:00 2015 +0100
Committer: Frédéric THOMAS <we...@gmail.com>
Committed: Tue Jul 7 19:15:46 2015 +0100

----------------------------------------------------------------------
 .../codegen/externals/TestCollectImports.java   | 221 +++++++++++++++++++
 .../imports/import_constructor_signatures.js    |  43 ++++
 .../imports/import_functions.js                 |  47 ++++
 .../imports/import_interfaces.js                |  49 ++++
 .../imports/import_method_signatures.js         |  71 ++++++
 .../imports/import_superclasses.js              |  46 ++++
 6 files changed, 477 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/298cc732/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/externals/TestCollectImports.java
----------------------------------------------------------------------
diff --git a/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/externals/TestCollectImports.java b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/externals/TestCollectImports.java
new file mode 100644
index 0000000..ad025c3
--- /dev/null
+++ b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/externals/TestCollectImports.java
@@ -0,0 +1,221 @@
+/*
+ *
+ *  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.*;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Collection;
+
+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.FunctionReference;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+@RunWith(Parameterized.class)
+public class TestCollectImports extends ExternalsTestBase
+{
+    private static final String IMPORTS_TEST_DIR = "imports/";
+
+    private Boolean excludeClass;
+
+    @Parameterized.Parameters
+    public static Collection<Object[]> excludeClassYesNo()
+    {
+        return Arrays.asList(new Object[][] { { true }, { false } });
+    }
+
+    public TestCollectImports(final Boolean excludeClass)
+    {
+        this.excludeClass = excludeClass;
+    }
+
+    @Test
+    public void import_constructor_signatures() throws Exception
+    {
+        if (excludeClass)
+        {
+            config.addClassExclude("foo.Baz");
+        }
+
+        assertCompileTestFileSuccess(IMPORTS_TEST_DIR);
+
+        //client.emit();
+
+        ClassReference importConstructorSignature = model.getClassReference("ImportConstructorSignature");
+        assertNotNull(importConstructorSignature);
+
+        assertFalse(importConstructorSignature.hasImport("Number"));
+        assertFalse(importConstructorSignature.hasImport("foo.Qux"));
+
+        assertTrue(importConstructorSignature.hasImport("foo.Bar"));
+
+        if (excludeClass)
+        {
+            assertFalse(importConstructorSignature.hasImport("foo.Baz"));
+        }
+        else
+        {
+            assertTrue(importConstructorSignature.hasImport("foo.Baz"));
+        }
+    }
+
+    @Test
+    public void import_method_signatures() throws Exception
+    {
+        if (excludeClass)
+        {
+            config.addClassExclude("foo.Qux");
+        }
+
+        assertCompileTestFileSuccess(IMPORTS_TEST_DIR);
+
+        //client.emit();
+
+        ClassReference importMethodSignature = model.getClassReference("ImportMethodSignature");
+        assertNotNull(importMethodSignature);
+
+        assertFalse(importMethodSignature.hasImport("Number"));
+        assertFalse(importMethodSignature.hasImport("foo.Quux"));
+        assertFalse(importMethodSignature.hasImport("foo.Quuux"));
+
+        assertTrue(importMethodSignature.hasImport("foo.Bar"));
+        assertTrue(importMethodSignature.hasImport("foo.Baz"));
+
+        if (excludeClass)
+        {
+            assertFalse(importMethodSignature.hasImport("foo.Qux"));
+        }
+        else
+        {
+            assertTrue(importMethodSignature.hasImport("foo.Qux"));
+        }
+    }
+
+    @Test
+    public void import_interfaces() throws Exception
+    {
+        if (excludeClass)
+        {
+            config.addClassExclude("API.foo.Baz");
+        }
+
+        assertCompileTestFileSuccess(IMPORTS_TEST_DIR);
+
+        //client.emit();
+
+        ClassReference importInterfaces = model.getClassReference("ImportInterfaces");
+        assertNotNull(importInterfaces);
+
+        assertFalse(importInterfaces.hasImport("qux"));
+        assertTrue(importInterfaces.hasImport("API.Foo"));
+
+        ClassReference apiFoo = model.getClassReference("API.Foo");
+        assertNotNull(apiFoo);
+
+        assertFalse(apiFoo.hasImport("qux"));
+        assertFalse(apiFoo.hasImport("API.Bar"));
+
+        if (excludeClass)
+        {
+            assertFalse(apiFoo.hasImport("API.foo.Baz"));
+        }
+        else
+        {
+            assertTrue(apiFoo.hasImport("API.foo.Baz"));
+        }
+    }
+
+    @Test
+    public void import_superclasses() throws Exception
+    {
+        if (excludeClass)
+        {
+            config.addClassExclude("BASE.Foo");
+        }
+
+        assertCompileTestFileSuccess(IMPORTS_TEST_DIR);
+
+        //client.emit();
+
+        ClassReference importSuperClass1 = model.getClassReference("ImportSuperClass1");
+        assertNotNull(importSuperClass1);
+
+        assertFalse(importSuperClass1.hasImport("qux"));
+
+        ClassReference importSuperClass2 = model.getClassReference("ImportSuperClass2");
+        assertNotNull(importSuperClass2);
+
+        if (excludeClass)
+        {
+            assertFalse(importSuperClass2.hasImport("BASE.Foo"));
+        }
+        else
+        {
+            assertTrue(importSuperClass2.hasImport("BASE.Foo"));
+        }
+
+        ClassReference foo = model.getClassReference("BASE.Foo");
+        assertNotNull(foo);
+
+        assertFalse(foo.hasImport("BASE.Bar"));
+    }
+
+    @Test
+    public void import_functions() throws Exception
+    {
+        if (excludeClass)
+        {
+            config.addClassExclude("foo.Qux");
+        }
+
+        assertCompileTestFileSuccess(IMPORTS_TEST_DIR);
+
+        client.emit();
+
+        FunctionReference importFunction = (FunctionReference) model.getFunctions().toArray()[0];
+        assertNotNull(importFunction);
+        assertTrue(importFunction.getQualifiedName().equals("ImportFunction"));
+
+        assertFalse(importFunction.hasImport("Quux"));
+
+        assertTrue(importFunction.hasImport("foo.Bar"));
+        assertTrue(importFunction.hasImport("foo.Baz"));
+
+        if (excludeClass)
+        {
+            assertFalse(importFunction.hasImport("foo.Qux"));
+        }
+        else
+        {
+            assertTrue(importFunction.hasImport("foo.Qux"));
+        }
+    }
+
+    @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/298cc732/compiler.jx.tests/test-files/externals_unit_tests/imports/import_constructor_signatures.js
----------------------------------------------------------------------
diff --git a/compiler.jx.tests/test-files/externals_unit_tests/imports/import_constructor_signatures.js b/compiler.jx.tests/test-files/externals_unit_tests/imports/import_constructor_signatures.js
new file mode 100644
index 0000000..9f80e7e
--- /dev/null
+++ b/compiler.jx.tests/test-files/externals_unit_tests/imports/import_constructor_signatures.js
@@ -0,0 +1,43 @@
+/*
+ *
+ *  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.
+ *
+ */
+
+
+/**
+ * @constructor
+ * @param {foo.Qux|foo.Bar} qux
+ * @param {foo.Bar} bar
+ * @param {number} value
+ * @param {foo.Baz?} baz
+ */
+ImportConstructorSignature = function(qux, bar, value, baz) {};
+
+/**
+ * @constructor
+ */
+foo.Bar = function() {};
+
+/**
+ * @constructor
+ */
+foo.Baz = function() {};
+
+/**
+ * @constructor
+ */
+foo.Qux = function() {};

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/298cc732/compiler.jx.tests/test-files/externals_unit_tests/imports/import_functions.js
----------------------------------------------------------------------
diff --git a/compiler.jx.tests/test-files/externals_unit_tests/imports/import_functions.js b/compiler.jx.tests/test-files/externals_unit_tests/imports/import_functions.js
new file mode 100644
index 0000000..b6c170b
--- /dev/null
+++ b/compiler.jx.tests/test-files/externals_unit_tests/imports/import_functions.js
@@ -0,0 +1,47 @@
+/*
+ *
+ *  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.
+ *
+ */
+
+
+/**
+ * @param {foo.Bar} bar
+ * @param {foo.Baz} baz
+ * @param {Quux} quux
+ * @return {!foo.Qux}
+ */
+function ImportFunction(bar, baz, quux) {}
+
+/**
+ * @constructor
+ */
+Quux = function() {};
+
+/**
+ * @constructor
+ */
+foo.Bar = function() {};
+
+/**
+ * @constructor
+ */
+foo.Baz = function() {};
+
+/**
+ * @constructor
+ */
+foo.Qux = function() {};

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/298cc732/compiler.jx.tests/test-files/externals_unit_tests/imports/import_interfaces.js
----------------------------------------------------------------------
diff --git a/compiler.jx.tests/test-files/externals_unit_tests/imports/import_interfaces.js b/compiler.jx.tests/test-files/externals_unit_tests/imports/import_interfaces.js
new file mode 100644
index 0000000..97a711f
--- /dev/null
+++ b/compiler.jx.tests/test-files/externals_unit_tests/imports/import_interfaces.js
@@ -0,0 +1,49 @@
+/*
+ *
+ *  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.
+ *
+ */
+
+/**
+ * @constructor
+ * @implements {Qux}
+ * @implements {API.Foo}
+ */
+ImportInterfaces = function() {};
+
+
+/**
+ * @interface
+ */
+Qux = function() {};
+
+/**
+ * @interface
+ * @extends {Qux}
+ * @extends {API.Bar}
+ * @extends {API.foo.Baz}
+ */
+API.Foo = function() {};
+
+/**
+ * @interface
+ */
+API.Bar = function() {};
+
+/**
+ * @interface
+ */
+API.foo.Baz = function() {};

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/298cc732/compiler.jx.tests/test-files/externals_unit_tests/imports/import_method_signatures.js
----------------------------------------------------------------------
diff --git a/compiler.jx.tests/test-files/externals_unit_tests/imports/import_method_signatures.js b/compiler.jx.tests/test-files/externals_unit_tests/imports/import_method_signatures.js
new file mode 100644
index 0000000..6524dc5
--- /dev/null
+++ b/compiler.jx.tests/test-files/externals_unit_tests/imports/import_method_signatures.js
@@ -0,0 +1,71 @@
+/*
+ *
+ *  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.
+ *
+ */
+
+/**
+ * @constructor
+ */
+ImportMethodSignature = function() {};
+
+/**
+ * @param {foo.Quux|foo.Bar} bar
+ * @param {number} value
+ * @param {foo.Baz?} baz
+ */
+ImportMethodSignature.myMethod = function(bar, value, baz) {};
+
+/**
+ * @param {foo.Bar} bar
+ * @param {number} value
+ * @param {foo.Baz?} baz
+ * @return {foo.Qux}
+ */
+ImportMethodSignature.prototype.myMethodWithReturnType = function(bar, value, baz) {};
+
+/**
+ * @param {foo.Bar} bar
+ * @param {number} value
+ * @param {foo.Baz?} baz
+ * @return {foo.Quuux|foo.Bar}
+ */
+ImportMethodSignature.myMethodWithUnionReturnType = function(bar, value, baz) {};
+
+/**
+ * @constructor
+ */
+foo.Bar = function() {};
+
+/**
+ * @constructor
+ */
+foo.Baz = function() {};
+
+/**
+ * @constructor
+ */
+foo.Qux = function() {};
+
+/**
+ * @constructor
+ */
+foo.Quux = function() {};
+
+/**
+ * @constructor
+ */
+foo.Quuux = function() {};

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/298cc732/compiler.jx.tests/test-files/externals_unit_tests/imports/import_superclasses.js
----------------------------------------------------------------------
diff --git a/compiler.jx.tests/test-files/externals_unit_tests/imports/import_superclasses.js b/compiler.jx.tests/test-files/externals_unit_tests/imports/import_superclasses.js
new file mode 100644
index 0000000..1a549d7
--- /dev/null
+++ b/compiler.jx.tests/test-files/externals_unit_tests/imports/import_superclasses.js
@@ -0,0 +1,46 @@
+/*
+ *
+ *  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.
+ *
+ */
+
+/**
+ * @constructor
+ * @extends {Qux}
+ */
+ImportSuperClass1 = function() {};
+
+/**
+ * @constructor
+ * @extends {BASE.Foo}
+ */
+ImportSuperClass2 = function() {};
+
+/**
+ * @constructor
+ */
+Qux = function() {};
+
+/**
+ * @constructor
+ * @extends {BASE.Bar}
+ */
+BASE.Foo = function() {};
+
+/**
+ * @constructor
+ */
+BASE.Bar = function() {};


[5/8] git commit: [flex-falcon] [refs/heads/add-collect-import-pass] - Adding the collect of imports pass

Posted by ft...@apache.org.
Adding the collect of imports pass

Replacing the last fix
Fix bugs
Cleanup and format


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

Branch: refs/heads/add-collect-import-pass
Commit: c55587ceb2cb8439b884c1c3c09367056ca52975
Parents: 69f0a8b
Author: Frédéric THOMAS <we...@gmail.com>
Authored: Tue Jul 7 19:12:53 2015 +0100
Committer: Frédéric THOMAS <we...@gmail.com>
Committed: Tue Jul 7 19:15:53 2015 +0100

----------------------------------------------------------------------
 .../externals/pass/CollectImportsPass.java      | 164 ++++++++++++++++
 .../externals/pass/ReferenceCompiler.java       |  23 +--
 .../externals/reference/BaseReference.java      |  36 ++--
 .../externals/reference/ClassReference.java     | 196 ++++++++-----------
 .../externals/reference/FieldReference.java     |  24 +--
 .../externals/reference/MethodReference.java    |  71 +++++--
 .../externals/reference/ReferenceModel.java     |  38 ++--
 .../codegen/externals/utils/FunctionUtils.java  |  71 ++++---
 .../codegen/externals/utils/JSTypeUtils.java    |  20 +-
 9 files changed, 414 insertions(+), 229 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c55587ce/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/pass/CollectImportsPass.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/pass/CollectImportsPass.java b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/pass/CollectImportsPass.java
new file mode 100644
index 0000000..28815f9
--- /dev/null
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/pass/CollectImportsPass.java
@@ -0,0 +1,164 @@
+package org.apache.flex.compiler.internal.codegen.externals.pass;
+
+import java.util.List;
+import java.util.Map;
+
+import org.apache.flex.compiler.internal.codegen.externals.reference.*;
+
+import com.google.javascript.jscomp.AbstractCompiler;
+import com.google.javascript.jscomp.NodeTraversal;
+import com.google.javascript.rhino.Node;
+
+/**
+ * @author: Frederic Thomas Date: 05/07/2015 Time: 18:16
+ */
+public class CollectImportsPass extends AbstractCompilerPass
+{
+    public CollectImportsPass(final ReferenceModel model, AbstractCompiler compiler)
+    {
+        super(model, compiler);
+    }
+
+    @Override
+    public boolean shouldTraverse(final NodeTraversal nodeTraversal, final Node n, final Node parent)
+    {
+        for (ClassReference reference : model.getClasses())
+        {
+            collectClassImports(reference);
+        }
+
+        for (FunctionReference reference : model.getFunctions())
+        {
+            collectFunctionImports(reference);
+        }
+
+        return false;
+    }
+
+    private void collectClassImports(ClassReference reference)
+    {
+        final MethodReference constructor = reference.getConstructor();
+        final List<ClassReference> superClasses = reference.getSuperClasses();
+        final List<ClassReference> interfaces = reference.getInterfaces();
+        final List<ClassReference> extendedInterfaces = reference.getExtendedInterfaces();
+        final Map<String, FieldReference> fields = reference.getFields();
+        final Map<String, MethodReference> methods = reference.getMethods();
+
+        for (ClassReference superClass : superClasses)
+        {
+            if (model.isExcludedClass(superClass) == null)
+            {
+                addClassImport(reference, superClass);
+            }
+        }
+
+        for (ClassReference _interface : interfaces)
+        {
+            if (model.isExcludedClass(_interface) == null)
+            {
+                addClassImport(reference, _interface);
+            }
+        }
+
+        for (ClassReference _interface : extendedInterfaces)
+        {
+            if (model.isExcludedClass(_interface) == null)
+            {
+                addClassImport(reference, _interface);
+            }
+        }
+
+        for (FieldReference field : fields.values())
+        {
+            if (field.isExcluded() == null)
+            {
+                addClassImport(reference, getType(field));
+            }
+        }
+
+        for (ParameterReference parameterReference : constructor.getParameters())
+        {
+            addClassImport(reference, getType(parameterReference));
+        }
+
+        for (MethodReference method : methods.values())
+        {
+            if (method.isExcluded() == null)
+            {
+                addClassImport(reference, getReturnType(method));
+
+                for (ParameterReference parameterReference : method.getParameters())
+                {
+                    addClassImport(reference, getType(parameterReference));
+                }
+            }
+        }
+    }
+
+    private void addClassImport(final ClassReference thisReference, final ClassReference referenceToImport)
+    {
+        if (canImport(referenceToImport))
+        {
+            final String thisPackageName = thisReference.getPackageName();
+            final String importPackageName = referenceToImport.getPackageName();
+
+            if (!importPackageName.equals(thisPackageName))
+            {
+                thisReference.addImport(referenceToImport);
+            }
+        }
+    }
+
+    private void collectFunctionImports(final FunctionReference function)
+    {
+        if (function.isExcluded() == null)
+        {
+            ClassReference returnType = getReturnType(function);
+
+            if (canImport(returnType))
+            {
+                function.addImport(returnType);
+            }
+
+            for (ParameterReference parameterReference : function.getParameters())
+            {
+                ClassReference type = getType(parameterReference);
+
+                if (canImport(type))
+                {
+                    function.addImport(type);
+                }
+            }
+        }
+    }
+
+    private ClassReference getType(final FieldReference field)
+    {
+        return model.getClassReference(field.toTypeString());
+    }
+
+    private ClassReference getReturnType(final MethodReference method)
+    {
+        return model.getClassReference(method.transformReturnString());
+    }
+
+    private ClassReference getReturnType(final FunctionReference function)
+    {
+        return model.getClassReference(function.transformReturnString());
+    }
+
+    private ClassReference getType(final ParameterReference parameter)
+    {
+        return model.getClassReference(parameter.getQualifiedName());
+    }
+
+    private boolean canImport(ClassReference reference)
+    {
+        return reference != null && reference.isQualifiedName() && model.isExcludedClass(reference) == null;
+    }
+
+    @Override
+    public void visit(final NodeTraversal t, final Node n, final Node parent)
+    {
+    }
+}

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c55587ce/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/pass/ReferenceCompiler.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/pass/ReferenceCompiler.java b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/pass/ReferenceCompiler.java
index ab47767..e5ac6c8 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/pass/ReferenceCompiler.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/pass/ReferenceCompiler.java
@@ -29,16 +29,12 @@ import org.apache.commons.io.FilenameUtils;
 import org.apache.flex.compiler.internal.codegen.externals.reference.ReferenceModel;
 
 import com.google.common.collect.ImmutableList;
+import com.google.javascript.jscomp.*;
 import com.google.javascript.jscomp.Compiler;
-import com.google.javascript.jscomp.CustomPassExecutionTime;
-import com.google.javascript.jscomp.JXCompilerOptions;
-import com.google.javascript.jscomp.Result;
-import com.google.javascript.jscomp.SourceFile;
 
 public class ReferenceCompiler
 {
-    private static final List<SourceFile> EMPTY_EXTERNS = ImmutableList.of(SourceFile.fromCode(
-            "externs", ""));
+    private static final List<SourceFile> EMPTY_EXTERNS = ImmutableList.of(SourceFile.fromCode("externs", ""));
 
     private ReferenceModel model;
 
@@ -72,15 +68,14 @@ public class ReferenceCompiler
         options.setParseJsDocDocumentation(true);
         options.setExternExports(false);
 
-        options.addCustomPass(CustomPassExecutionTime.BEFORE_OPTIMIZATIONS,
-                new NamespaceResolutionPass(model, jscompiler));
-        options.addCustomPass(CustomPassExecutionTime.BEFORE_OPTIMIZATIONS,
-                new ResolvePackagesPass(model, jscompiler));
+        options.addCustomPass(CustomPassExecutionTime.BEFORE_OPTIMIZATIONS, new NamespaceResolutionPass(model,
+                jscompiler));
+        options.addCustomPass(CustomPassExecutionTime.BEFORE_OPTIMIZATIONS, new ResolvePackagesPass(model, jscompiler));
 
-        options.addCustomPass(CustomPassExecutionTime.BEFORE_OPTIMIZATIONS,
-                new CollectTypesPass(model, jscompiler));
-        options.addCustomPass(CustomPassExecutionTime.BEFORE_OPTIMIZATIONS,
-                new AddMemberPass(model, jscompiler));
+        options.addCustomPass(CustomPassExecutionTime.BEFORE_OPTIMIZATIONS, new CollectTypesPass(model, jscompiler));
+        options.addCustomPass(CustomPassExecutionTime.BEFORE_OPTIMIZATIONS, new AddMemberPass(model, jscompiler));
+
+        options.addCustomPass(CustomPassExecutionTime.BEFORE_OPTIMIZATIONS, new CollectImportsPass(model, jscompiler));
 
         //compiler.setErrorManager(testErrorManager);
         jscompiler.initOptions(options);

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c55587ce/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/reference/BaseReference.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/reference/BaseReference.java b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/reference/BaseReference.java
index ea29a2f..cb3ef49 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/reference/BaseReference.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/reference/BaseReference.java
@@ -33,7 +33,7 @@ import com.google.javascript.rhino.Node;
 
 public abstract class BaseReference
 {
-    private String qualfiedName;
+    private String qualifiedName;
 
     protected JSDocInfo comment;
 
@@ -57,25 +57,25 @@ public abstract class BaseReference
 
     public String getBaseName()
     {
-        return qualfiedName.substring(qualfiedName.lastIndexOf('.') + 1);
+        return qualifiedName.substring(qualifiedName.lastIndexOf('.') + 1);
     }
 
     public String getPackageName()
     {
-        int end = qualfiedName.lastIndexOf('.');
+        int end = qualifiedName.lastIndexOf('.');
         if (end == -1)
             return "";
-        return qualfiedName.substring(0, end);
+        return qualifiedName.substring(0, end);
     }
 
     public String getQualifiedName()
     {
-        return qualfiedName;
+        return qualifiedName;
     }
 
     public final boolean isQualifiedName()
     {
-        return qualfiedName.indexOf('.') != -1;
+        return qualifiedName.indexOf('.') != -1;
     }
 
     public Node getNode()
@@ -103,12 +103,11 @@ public abstract class BaseReference
         return model;
     }
 
-    public BaseReference(ReferenceModel model, Node node, String qualfiedName,
-            JSDocInfo comment)
+    public BaseReference(ReferenceModel model, Node node, String qualifiedName, JSDocInfo comment)
     {
         this.model = model;
         this.node = node;
-        this.qualfiedName = qualfiedName;
+        this.qualifiedName = qualifiedName;
         this.comment = comment;
     }
 
@@ -143,7 +142,7 @@ public abstract class BaseReference
             sb.append(indent);
             sb.append(" * ");
             sb.append(blockDescription.replaceAll("\\n", "\n" + indent + " * "));
-            sb.append("\n " + indent + "*\n");
+            sb.append("\n ").append(indent).append("*\n");
         }
     }
 
@@ -161,11 +160,8 @@ public abstract class BaseReference
             if (!name.getItem().equals("see"))
                 continue;
 
-            if (name != null)
-            {
-                desc.append(name.getItem());
-                desc.append(" ");
-            }
+            desc.append(name.getItem());
+            desc.append(" ");
 
             if (typePosition != null)
             {
@@ -180,14 +176,14 @@ public abstract class BaseReference
             }
 
             sb.append(indent);
-            sb.append(" * @" + desc.toString() + "\n");
+            sb.append(" * @").append(desc.toString()).append("\n");
         }
     }
 
     protected void emitSeeSourceFileName(StringBuilder sb)
     {
         sb.append(indent);
-        sb.append(" * @see " + getNode().getSourceFileName() + "\n");
+        sb.append(" * @see ").append(getNode().getSourceFileName()).append("\n");
     }
 
     protected void emitFunctionCommentBody(StringBuilder sb)
@@ -204,10 +200,8 @@ public abstract class BaseReference
         Set<String> parameterNames = getComment().getParameterNames();
         for (String paramName : parameterNames)
         {
-            JSTypeExpression parameterType = getComment().getParameterType(
-                    paramName);
-            String description = getComment().getDescriptionForParameter(
-                    paramName);
+            JSTypeExpression parameterType = getComment().getParameterType(paramName);
+            String description = getComment().getDescriptionForParameter(paramName);
 
             sb.append(indent);
             sb.append(" * @param ");

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c55587ce/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 d2b1cc8..ae533d2 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
@@ -19,18 +19,18 @@
 
 package org.apache.flex.compiler.internal.codegen.externals.reference;
 
+import java.io.File;
+import java.util.*;
+import java.util.Map.Entry;
+
+import org.apache.flex.compiler.internal.codegen.externals.utils.DebugLogUtils;
+import org.apache.flex.compiler.internal.codegen.externals.utils.JSTypeUtils;
+
 import com.google.javascript.rhino.JSDocInfo;
 import com.google.javascript.rhino.JSDocInfoBuilder;
 import com.google.javascript.rhino.JSTypeExpression;
 import com.google.javascript.rhino.Node;
 import com.google.javascript.rhino.jstype.JSType;
-import org.apache.flex.compiler.internal.codegen.externals.utils.DebugLogUtils;
-import org.apache.flex.compiler.internal.codegen.externals.utils.FunctionUtils;
-import org.apache.flex.compiler.internal.codegen.externals.utils.JSTypeUtils;
-
-import java.io.File;
-import java.util.*;
-import java.util.Map.Entry;
 
 public class ClassReference extends BaseReference
 {
@@ -114,13 +114,12 @@ public class ClassReference extends BaseReference
     /**
      * 
      * @param model
-     * @param node (FUNCTION [NAME, PARAM_LIST, BLOCK]), or (ASSIGN [FUNCTION
-     *        [NAME, PARAM_LIST, BLOCK]])
-     * @param qualfiedName
+     * @param node (FUNCTION [NAME, PARAM_LIST, BLOCK]), or (ASSIGN [FUNCTION [NAME, PARAM_LIST, BLOCK]])
+     * @param qualifiedName
      */
-    public ClassReference(ReferenceModel model, Node node, String qualfiedName)
+    public ClassReference(ReferenceModel model, Node node, String qualifiedName)
     {
-        super(model, node, qualfiedName, node.getJSDocInfo());
+        super(model, node, qualifiedName, node.getJSDocInfo());
 
         indent = "";
 
@@ -165,20 +164,22 @@ public class ClassReference extends BaseReference
                 objLit = node.getLastChild();
             }
 
-            for (Node stringKey : objLit.children())
+            if (objLit != null)
             {
-                if (stringKey.isStringKey())
+                for (Node stringKey : objLit.children())
                 {
-                    Node valueNode = stringKey.getFirstChild();
-
-                    JSDocInfoBuilder b = new JSDocInfoBuilder(true);
-                    JSDocInfo fieldComment = b.build();
-                    String fieldName = stringKey.getString();
-                    FieldReference field = addField(stringKey, fieldName,
-                            fieldComment, true);
-                    field.setConst(true);
-                    field.setOverrideStringType(overrideStringType);
-                    field.setConstantValueNode(valueNode);
+                    if (stringKey.isStringKey())
+                    {
+                        Node valueNode = stringKey.getFirstChild();
+
+                        JSDocInfoBuilder b = new JSDocInfoBuilder(true);
+                        JSDocInfo fieldComment = b.build();
+                        String fieldName = stringKey.getString();
+                        FieldReference field = addField(stringKey, fieldName, fieldComment, true);
+                        field.setConst(true);
+                        field.setOverrideStringType(overrideStringType);
+                        field.setConstantValueNode(valueNode);
+                    }
                 }
             }
         }
@@ -197,8 +198,7 @@ public class ClassReference extends BaseReference
                 NAME Math 
                     OBJECTLIT
              */
-            constructor = new NullConstructorReference(model, this, node,
-                    getBaseName(), comment);
+            constructor = new NullConstructorReference(model, this, node, getBaseName(), comment);
         }
         else if (node.isFunction())
         {
@@ -255,8 +255,7 @@ public class ClassReference extends BaseReference
 
         if (functionNode != null)
         {
-            constructor = new MethodReference(model, this, functionNode,
-                    getBaseName(), comment, false);
+            constructor = new MethodReference(model, this, functionNode, getBaseName(), comment, false);
         }
 
     }
@@ -270,7 +269,7 @@ public class ClassReference extends BaseReference
 
         sb.append("package ");
         if (!packageName.equals(""))
-            sb.append(packageName + " ");
+            sb.append(packageName).append(" ");
         sb.append("{\n");
         sb.append("\n");
 
@@ -364,8 +363,7 @@ public class ClassReference extends BaseReference
         for (JSTypeExpression jsTypeExpression : getComment().getImplementedInterfaces())
         {
             String interfaceName = getModel().evaluate(jsTypeExpression).getDisplayName();
-            ClassReference classReference = getModel().getClassReference(
-                    interfaceName);
+            ClassReference classReference = getModel().getClassReference(interfaceName);
             if (classReference != null)
                 result.add(classReference);
         }
@@ -379,8 +377,20 @@ public class ClassReference extends BaseReference
         for (JSTypeExpression jsTypeExpression : getComment().getImplementedInterfaces())
         {
             String interfaceName = getModel().evaluate(jsTypeExpression).toAnnotationString();
-            ClassReference reference = getModel().getClassReference(
-                    interfaceName);
+            ClassReference reference = getModel().getClassReference(interfaceName);
+            if (reference != null)
+                result.add(reference);
+        }
+        return result;
+    }
+
+    public List<ClassReference> getExtendedInterfaces()
+    {
+        ArrayList<ClassReference> result = new ArrayList<ClassReference>();
+        for (JSTypeExpression jsTypeExpression : getComment().getExtendedInterfaces())
+        {
+            String interfaceName = getModel().evaluate(jsTypeExpression).toAnnotationString();
+            ClassReference reference = getModel().getClassReference(interfaceName);
             if (reference != null)
                 result.add(reference);
         }
@@ -422,18 +432,12 @@ public class ClassReference extends BaseReference
 
     public boolean hasInstanceField(String fieldName)
     {
-        if (!fields.containsKey(fieldName))
-            return false;
-
-        return !fields.get(fieldName).isStatic();
+        return fields.containsKey(fieldName) && !fields.get(fieldName).isStatic();
     }
 
     public boolean hasStaticField(String fieldName)
     {
-        if (!fields.containsKey(fieldName))
-            return false;
-
-        return fields.get(fieldName).isStatic();
+        return fields.containsKey(fieldName) && fields.get(fieldName).isStatic();
     }
 
     public boolean hasMethod(String methodName)
@@ -443,22 +447,15 @@ public class ClassReference extends BaseReference
 
     public boolean hasInstanceMethod(String fieldName)
     {
-        if (!methods.containsKey(fieldName))
-            return false;
-
-        return !methods.get(fieldName).isStatic();
+        return methods.containsKey(fieldName) && !methods.get(fieldName).isStatic();
     }
 
     public boolean hasStaticMethod(String fieldName)
     {
-        if (!methods.containsKey(fieldName))
-            return false;
-
-        return methods.get(fieldName).isStatic();
+        return methods.containsKey(fieldName) && methods.get(fieldName).isStatic();
     }
 
-    public FieldReference addField(Node node, String fieldName,
-            JSDocInfo comment, boolean isStatic)
+    public FieldReference addField(Node node, String fieldName, JSDocInfo comment, boolean isStatic)
     {
         if (hasField(fieldName))
         {
@@ -471,88 +468,62 @@ public class ClassReference extends BaseReference
 
         if (comment == null)
         {
-            DebugLogUtils.err("Field comment null for; "
-                    + node.getQualifiedName());
+            DebugLogUtils.err("Field comment null for; " + node.getQualifiedName());
             //DebugLogUtils.err(node);
             JSDocInfoBuilder b = new JSDocInfoBuilder(true);
             b.recordBlockDescription("Generated doc for missing field JSDoc.");
             comment = b.build();
         }
 
-        FieldReference field = new FieldReference(getModel(), this, node,
-                fieldName, comment, isStatic);
+        FieldReference field = new FieldReference(getModel(), this, node, fieldName, comment, isStatic);
 
         fields.put(fieldName, field);
         return field;
     }
 
-    public MethodReference addMethod(Node node, String functionName,
-            JSDocInfo comment, boolean isStatic)
+    public MethodReference addMethod(Node node, String functionName, JSDocInfo comment, boolean isStatic)
     {
         if (isNamespace)
             isStatic = false;
 
         if (comment == null)
         {
-            DebugLogUtils.err("Method comment null for; "
-                    + node.getQualifiedName());
+            DebugLogUtils.err("Method comment null for; " + node.getQualifiedName());
             //DebugLogUtils.err(node);
             JSDocInfoBuilder b = new JSDocInfoBuilder(true);
             b.recordBlockDescription("Generated doc for missing method JSDoc.");
             comment = b.build();
         }
 
-        MethodReference method = new MethodReference(getModel(), this, node,
-                functionName, comment, isStatic);
-
-        final String returnType = getReturnTypeToImport(method);
-        if (returnType != null)
-        {
-            addImport(returnType);
-        }
+        MethodReference method = new MethodReference(getModel(), this, node, functionName, comment, isStatic);
 
         methods.put(functionName, method);
         return method;
     }
 
-    private String getReturnTypeToImport(final MethodReference method) {
-        String returnType = null;
-
-        final JSDocInfo comment = method.getComment();
-        if (method.isExcluded() == null && comment != null && comment.hasReturnType())
-        {
-            try {
-                final Node firstChild = comment.getReturnType().getRoot().getFirstChild();
-                returnType = firstChild.getString();
-            } catch (Exception e) {
-                returnType = null;
-            }
-        }
-
-        final boolean canBeImported = FunctionUtils.canBeImported(getModel(), getNode(), returnType, getPackageName());
-
-        return canBeImported ? returnType : null;
-    }
-
     public boolean isMethodOverrideFromInterface(MethodReference reference)
     {
-        if (!hasImplementations())
-            return false;
+        boolean isMethodOverrideFromInterface = false;
 
-        List<JSTypeExpression> implementedInterfaces = getComment().getImplementedInterfaces();
-        for (JSTypeExpression jsTypeExpression : implementedInterfaces)
+        if (!hasImplementations())
         {
-            String interfaceName = getModel().evaluate(jsTypeExpression).getDisplayName();
-            ClassReference classReference = getModel().getClassReference(
-                    interfaceName);
-            return classReference.hasSuperMethod(reference.getQualifiedName());
+            List<JSTypeExpression> implementedInterfaces = getComment().getImplementedInterfaces();
+            for (JSTypeExpression jsTypeExpression : implementedInterfaces)
+            {
+                String interfaceName = getModel().evaluate(jsTypeExpression).getDisplayName();
+                ClassReference classReference = getModel().getClassReference(interfaceName);
+                if (classReference.hasSuperMethod(reference.getQualifiedName()))
+                {
+                    isMethodOverrideFromInterface = true;
+                    break;
+                }
+            }
         }
 
-        return false;
+        return isMethodOverrideFromInterface;
     }
 
-    public MethodReference getMethodOverrideFromInterface(
-            MethodReference reference)
+    public MethodReference getMethodOverrideFromInterface(MethodReference reference)
     {
         // get all super classes, reverse and search top down
         List<ClassReference> superClasses = getSuperClasses();
@@ -630,9 +601,12 @@ public class ClassReference extends BaseReference
         return fields.containsKey(fieldName);
     }
 
-    public void addImport(String qualifiedName)
+    public void addImport(ClassReference reference)
     {
-        imports.add(qualifiedName);
+        if (reference != null)
+        {
+            imports.add(reference.getQualifiedName());
+        }
     }
 
     public boolean hasImport(String qualifiedName)
@@ -647,12 +621,14 @@ public class ClassReference extends BaseReference
 
     private void emitImports(StringBuilder sb)
     {
-        sb.append("\n");
-        for (String imp : imports)
+        if (imports.size() > 0)
         {
-            sb.append("import " + imp + ";\n");
+            for (String anImport : imports)
+            {
+                sb.append("import ").append(anImport).append(";\n");
+            }
+            sb.append("\n");
         }
-        sb.append("\n");
     }
 
     private void emitClass(StringBuilder sb)
@@ -671,7 +647,7 @@ public class ClassReference extends BaseReference
         }
 
         sb.append("class ");
-        sb.append(getBaseName() + " ");
+        sb.append(getBaseName()).append(" ");
 
         if (getComment().hasBaseType())
         {
@@ -694,11 +670,10 @@ public class ClassReference extends BaseReference
     {
         sb.append("public interface ");
 
-        sb.append(getBaseName() + " ");
+        sb.append(getBaseName()).append(" ");
 
         List<JSTypeExpression> extendedInterfaces = getComment().getExtendedInterfaces();
         int len = extendedInterfaces.size();
-        int i = 0;
         if (len > 0)
         {
             sb.append("extends ");
@@ -706,7 +681,7 @@ public class ClassReference extends BaseReference
             {
                 String value = getModel().evaluate(jsTypeExpression).toAnnotationString();
                 sb.append(value);
-                if (i < len - 1)
+                if (--len > 0)
                     sb.append(", ");
             }
             sb.append(" ");
@@ -771,8 +746,7 @@ public class ClassReference extends BaseReference
     public File getFile(File asSourceRoot)
     {
         String packagePath = toPackagePath();
-        return new File(asSourceRoot, packagePath + File.separator
-                + getBaseName() + ".as");
+        return new File(asSourceRoot, packagePath + File.separator + getBaseName() + ".as");
     }
 
     private String toPackagePath()
@@ -783,9 +757,9 @@ public class ClassReference extends BaseReference
         String sdirPath = "";
         if (cname.length > 0)
         {
-            for (int i = 0; i < cname.length; i++)
+            for (final String aCname : cname)
             {
-                sdirPath += cname[i] + File.separator;
+                sdirPath += aCname + File.separator;
             }
 
             return sdirPath;

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c55587ce/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/reference/FieldReference.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/reference/FieldReference.java b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/reference/FieldReference.java
index 9cb6f09..ae39de9 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/reference/FieldReference.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/reference/FieldReference.java
@@ -67,12 +67,16 @@ public class FieldReference extends MemberReference
 
     public String toTypeAnnotationString()
     {
-        JSType jsType = getModel().evaluate(getComment().getType());
-        return jsType.toAnnotationString();
+        JSType jsType = null;
+        if (getComment() != null && getComment().getReturnType() != null)
+        {
+            jsType = getModel().evaluate(getComment().getType());
+        }
+        return jsType != null ? jsType.toAnnotationString() : "Object";
     }
 
-    public FieldReference(ReferenceModel model, ClassReference classReference,
-            Node node, String name, JSDocInfo comment, boolean isStatic)
+    public FieldReference(ReferenceModel model, ClassReference classReference, Node node, String name,
+            JSDocInfo comment, boolean isStatic)
     {
         super(model, classReference, node, name, comment);
         this.isStatic = isStatic;
@@ -101,10 +105,8 @@ public class FieldReference extends MemberReference
             return; // XXX (mschmalle) accessors are not treated right, need to exclude get/set
         }
 
-        if (!getClassReference().isInterface()
-                && !getComment().isOverride()
-                && !getClassReference().isPropertyInterfaceImplementation(
-                        getBaseName()))
+        if (!getClassReference().isInterface() && !getComment().isOverride()
+                && !getClassReference().isPropertyInterfaceImplementation(getBaseName()))
         {
             emitVar(sb);
         }
@@ -124,7 +126,7 @@ public class FieldReference extends MemberReference
         String setBody = isInterface ? "" : "{}";
 
         String type = toTypeString();
-        if (type.indexOf("|") != -1 || type.indexOf("?") != -1)
+        if (type.contains("|") || type.contains("?"))
             type = "*";
 
         // getter
@@ -157,7 +159,7 @@ public class FieldReference extends MemberReference
         String constVarValue = (isConst) ? "const " : "var ";
 
         String type = toTypeString();
-        if (type.indexOf("|") != -1 || type.indexOf("?") != -1)
+        if (type.contains("|") || type.contains("?"))
             type = "*";
 
         sb.append(indent);
@@ -189,7 +191,7 @@ public class FieldReference extends MemberReference
         return "undefined /* TODO type not set */";
     }
 
-    private String toTypeString()
+    public String toTypeString()
     {
         if (overrideStringType != null)
             return overrideStringType;

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c55587ce/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/reference/MethodReference.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/reference/MethodReference.java b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/reference/MethodReference.java
index d031945..b37677b 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/reference/MethodReference.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/reference/MethodReference.java
@@ -19,11 +19,14 @@
 
 package org.apache.flex.compiler.internal.codegen.externals.reference;
 
+import java.util.ArrayList;
+import java.util.List;
 import java.util.Set;
 
 import org.apache.flex.compiler.clients.ExternCConfiguration.ExcludedMember;
 import org.apache.flex.compiler.internal.codegen.externals.utils.FunctionUtils;
 
+import com.google.common.collect.Lists;
 import com.google.javascript.rhino.JSDocInfo;
 import com.google.javascript.rhino.Node;
 import com.google.javascript.rhino.jstype.JSType;
@@ -35,6 +38,8 @@ public class MethodReference extends MemberReference
     private MethodReference override;
     private Node paramNode;
 
+    private List<ParameterReference> parameters;
+
     private MethodReference getContext()
     {
         return override == null ? this : override;
@@ -50,6 +55,11 @@ public class MethodReference extends MemberReference
         this.isStatic = isStatic;
     }
 
+    public List<ParameterReference> getParameters()
+    {
+        return parameters;
+    }
+
     public Set<String> getParameterNames()
     {
         return getComment().getParameterNames();
@@ -61,8 +71,8 @@ public class MethodReference extends MemberReference
         return jsType.toAnnotationString();
     }
 
-    public MethodReference(ReferenceModel model, ClassReference classReference,
-            Node node, String name, JSDocInfo comment, boolean isStatic)
+    public MethodReference(ReferenceModel model, ClassReference classReference, Node node, String name,
+            JSDocInfo comment, boolean isStatic)
     {
         super(model, classReference, node, name, comment);
         this.isStatic = isStatic;
@@ -75,14 +85,50 @@ public class MethodReference extends MemberReference
         {
             this.paramNode = node.getLastChild().getChildAtIndex(1);
         }
+
+        addParameterReferences();
+    }
+
+    private void addParameterReferences()
+    {
+
+        parameters = new ArrayList<ParameterReference>();
+
+        if (paramNode != null)
+        {
+
+            final boolean isDocumented = comment.getParameterCount() > 0;
+            List<String> parameterNames = null;
+
+            if (isDocumented)
+            {
+                parameterNames = Lists.newArrayList(comment.getParameterNames());
+            }
+
+            for (Node param : paramNode.children())
+            {
+                ParameterReference parameterReference;
+
+                if (isDocumented && parameterNames.contains(param.getString()))
+                {
+                    final String qualifiedName = FunctionUtils.toParameterType(this, param.getString());
+                    parameterReference = new ParameterReference(getModel(), param, qualifiedName);
+                }
+                else
+                {
+                    parameterReference = new ParameterReference(getModel(), param);
+                }
+
+                parameters.add(parameterReference);
+            }
+        }
     }
 
     @Override
     public void emit(StringBuilder sb)
     {
         // XXX HACK TEMP!
-        if (getComment().isConstructor()
-                && !getBaseName().equals(getClassReference().getBaseName()))
+        if (getComment().isConstructor() && !getBaseName().equals(getClassReference().getBaseName()))
             return;
 
         if (isConstructor())
@@ -117,8 +163,7 @@ public class MethodReference extends MemberReference
 
         if (!getClassReference().isInterface())
         {
-            MethodReference overrideFromInterface = getClassReference().getMethodOverrideFromInterface(
-                    this);
+            MethodReference overrideFromInterface = getClassReference().getMethodOverrideFromInterface(this);
             if (/*isOverride() && */overrideFromInterface != null)
             {
                 override = overrideFromInterface;
@@ -146,7 +191,7 @@ public class MethodReference extends MemberReference
         sb.append(staticValue);
         sb.append("function ");
         sb.append(getQualifiedName());
-        sb.append(toPrameterString());
+        sb.append(toParameterString());
         sb.append(":");
         sb.append(transformReturnString());
         sb.append(braces);
@@ -162,7 +207,7 @@ public class MethodReference extends MemberReference
         sb.append(getBaseName());
         if (!getBaseName().equals("Object"))
         {
-            sb.append(toPrameterString());
+            sb.append(toParameterString());
             sb.append(" {\n");
             sb.append(indent);
             emitSuperCall(sb);
@@ -205,16 +250,14 @@ public class MethodReference extends MemberReference
         return getComment().isConstructor();
     }
 
-    private String transformReturnString()
+    public String transformReturnString()
     {
-        return FunctionUtils.toReturnString(getContext(),
-                getContext().getComment());
+        return FunctionUtils.toReturnString(getContext());
     }
 
-    private String toPrameterString()
+    private String toParameterString()
     {
-        return FunctionUtils.toPrameterString(getContext(),
-                getContext().getComment(), paramNode);
+        return FunctionUtils.toParameterString(getContext(), getContext().getComment(), paramNode);
     }
 
     public boolean isOverride()

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c55587ce/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 adfa8c9..872bcd1 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
@@ -208,8 +208,7 @@ public class ReferenceModel
 
         log("Model.addFunction(" + qualifiedName + ")");
 
-        FunctionReference reference = new FunctionReference(this, node,
-                qualifiedName, node.getJSDocInfo());
+        FunctionReference reference = new FunctionReference(this, node, qualifiedName, node.getJSDocInfo());
         functions.put(qualifiedName, reference);
     }
 
@@ -233,8 +232,7 @@ public class ReferenceModel
 
         log("Model.addConstant(" + qualifiedName + ")");
 
-        ConstantReference reference = new ConstantReference(this, node,
-                qualifiedName, node.getJSDocInfo());
+        ConstantReference reference = new ConstantReference(this, node, qualifiedName, node.getJSDocInfo());
         constants.put(qualifiedName, reference);
     }
 
@@ -248,8 +246,7 @@ public class ReferenceModel
 
         log("Model.addConstantType(" + qualifiedName + ")");
 
-        ConstantReference reference = new ConstantReference(this, node,
-                qualifiedName, node.getJSDocInfo(), type);
+        ConstantReference reference = new ConstantReference(this, node, qualifiedName, node.getJSDocInfo(), type);
         constants.put(qualifiedName, reference);
     }
 
@@ -257,8 +254,7 @@ public class ReferenceModel
     {
         ClassReference classReference = getClassReference(className);
         if (classReference != null)
-            classReference.addField(node, memberName, node.getJSDocInfo(),
-                    false);
+            classReference.addField(node, memberName, node.getJSDocInfo(), false);
     }
 
     public void addStaticField(Node node, String className, String memberName)
@@ -273,8 +269,7 @@ public class ReferenceModel
         }
         else
         {
-            err(">>>> {ReferenceModel} Class [" + className + "] not found in "
-                    + node.getSourceFileName());
+            err(">>>> {ReferenceModel} Class [" + className + "] not found in " + node.getSourceFileName());
         }
     }
 
@@ -298,14 +293,25 @@ public class ReferenceModel
         }
         else
         {
-            err(">>>> {ReferenceModel} Class [" + className + "] not found in "
-                    + node.getSourceFileName());
+            err(">>>> {ReferenceModel} Class [" + className + "] not found in " + node.getSourceFileName());
         }
     }
 
     public final JSType evaluate(JSTypeExpression expression)
     {
-        JSType jsType = expression.evaluate(null, jscompiler.getTypeRegistry());
+        JSType jsType = null;
+
+        if (expression != null)
+        {
+            try
+            {
+                jsType = expression.evaluate(null, jscompiler.getTypeRegistry());
+            }
+            catch (Exception e)
+            {
+                e.printStackTrace();
+            }
+        }
         return jsType;
     }
 
@@ -316,11 +322,9 @@ public class ReferenceModel
         return getConfiguration().isExcludedClass(classReference);
     }
 
-    public ExcludedMember isExcludedMember(ClassReference classReference,
-            MemberReference memberReference)
+    public ExcludedMember isExcludedMember(ClassReference classReference, MemberReference memberReference)
     {
-        return getConfiguration().isExcludedMember(classReference,
-                memberReference);
+        return getConfiguration().isExcludedMember(classReference, memberReference);
     }
 
     //--------------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c55587ce/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 561fddb..6bf3ac5 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
@@ -19,23 +19,45 @@
 
 package org.apache.flex.compiler.internal.codegen.externals.utils;
 
-import com.google.common.base.Strings;
 import org.apache.flex.compiler.internal.codegen.externals.reference.BaseReference;
+import org.apache.flex.compiler.internal.codegen.externals.reference.ClassReference;
+import org.apache.flex.compiler.internal.codegen.externals.reference.ReferenceModel;
 
+import com.google.common.base.Strings;
 import com.google.javascript.rhino.JSDocInfo;
 import com.google.javascript.rhino.JSTypeExpression;
 import com.google.javascript.rhino.Node;
-import org.apache.flex.compiler.internal.codegen.externals.reference.ClassReference;
-import org.apache.flex.compiler.internal.codegen.externals.reference.ReferenceModel;
 
 public class FunctionUtils
 {
-    public static String toReturnString(BaseReference reference,
-            JSDocInfo comment)
+    /**
+     * Compute the type of a function or method parameter.
+     * 
+     * @param reference The FunctionReference or MethodReference the parameter belongs to
+     * @param name The name of the parameter
+     * @return the type of a function or method parameter
+     */
+    public static String toParameterType(final BaseReference reference, final String name)
+    {
+
+        String parameterType;
+        if (FunctionUtils.hasTemplate(reference))
+        {
+            parameterType = "Object";
+        }
+        else
+        {
+            parameterType = JSTypeUtils.toParamTypeString(reference, name);
+        }
+
+        return parameterType;
+    }
+
+    public static String toReturnString(BaseReference reference)
     {
         final StringBuilder sb = new StringBuilder();
 
-        String returnType = null;
+        String returnType;
 
         if (hasTemplate(reference))
         {
@@ -51,8 +73,7 @@ public class FunctionUtils
         return sb.toString();
     }
 
-    public static String toPrameterString(BaseReference reference,
-            JSDocInfo comment, Node paramNode)
+    public static String toParameterString(BaseReference reference, JSDocInfo comment, Node paramNode)
     {
         final StringBuilder sb = new StringBuilder();
 
@@ -71,7 +92,7 @@ public class FunctionUtils
                 {
                     for (Node param : paramNode.children())
                     {
-                        sb.append(param.getString() + ":Object");
+                        sb.append(param.getString()).append(":Object");
                         if (index < len - 1)
                             sb.append(", ");
                         index++;
@@ -82,8 +103,7 @@ public class FunctionUtils
             {
                 for (String paramName : comment.getParameterNames())
                 {
-                    sb.append(toParameter(reference, comment, paramName,
-                            comment.getParameterType(paramName)));
+                    sb.append(toParameter(reference, comment, paramName, comment.getParameterType(paramName)));
 
                     if (index < len - 1)
                         sb.append(", ");
@@ -104,10 +124,11 @@ public class FunctionUtils
      * @param model The containing reference model
      * @param node The containing node
      * @param typeName The type we want check
-     * @param currentPackage The current package
+     * @param packageName The current package
      * @return true if we can import the given type into the given package
      */
-    public static boolean canBeImported(final ReferenceModel model, final Node node, final String typeName, final String currentPackage)
+    public static boolean canBeImported(final ReferenceModel model, final Node node, final String typeName,
+            final String packageName)
     {
         boolean canImport = false;
 
@@ -116,33 +137,27 @@ public class FunctionUtils
             final ClassReference reference = new ClassReference(null, node, typeName);
 
             final int lastDotPosition = typeName.lastIndexOf(".");
-            // Can import when the type to import does not belong the current package.
-            canImport = lastDotPosition > -1 && !typeName.substring(0, lastDotPosition).equals(currentPackage);
+
+            // Can import when the type to import does not belong to the current package.
+            canImport = lastDotPosition > -1 && !typeName.substring(0, lastDotPosition).equals(packageName);
+
             // And is not excluded.
             canImport &= model.isExcludedClass(reference) == null;
-
-            // TODO:
-            /*
-             Manage the case where a custom class belongs
-             to the top level package and needs to be imported
-             in a sub-package as I don't know how to deal with
-             builtin classes.
-             */
         }
 
         return canImport;
     }
 
-    private static String toParameter(BaseReference reference,
-            JSDocInfo comment, String paramName, JSTypeExpression parameterType)
+    private static String toParameter(BaseReference reference, JSDocInfo comment, String paramName,
+            JSTypeExpression parameterType)
     {
         final StringBuilder sb = new StringBuilder();
 
-        String paramType = null;
+        String paramType;
 
         if (parameterType.isVarArgs())
         {
-            sb.append("..." + paramName);
+            sb.append("...").append(paramName);
         }
         else
         {
@@ -182,7 +197,7 @@ public class FunctionUtils
         return "null";
     }
 
-    private static boolean hasTemplate(BaseReference reference)
+    public static boolean hasTemplate(BaseReference reference)
     {
         return reference.getComment().getTemplateTypeNames().size() > 0;
     }

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c55587ce/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/utils/JSTypeUtils.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/utils/JSTypeUtils.java b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/utils/JSTypeUtils.java
index 3b4ae40..c14ddb8 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/utils/JSTypeUtils.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/utils/JSTypeUtils.java
@@ -34,16 +34,13 @@ public class JSTypeUtils
 {
     public static String toClassTypeString(ClassReference reference)
     {
-        String type = getJsType(reference.getModel(),
-                reference.getComment().getBaseType()).toString();
+        String type = getJsType(reference.getModel(), reference.getComment().getBaseType()).toString();
         return type;
     }
 
-    public static String toParamTypeString(BaseReference reference,
-            String paramName)
+    public static String toParamTypeString(BaseReference reference, String paramName)
     {
-        JSTypeExpression expression = reference.getComment().getParameterType(
-                paramName);
+        JSTypeExpression expression = reference.getComment().getParameterType(paramName);
         if (expression == null)
             return "Object";
 
@@ -80,8 +77,7 @@ public class JSTypeUtils
     public static String toEnumTypeString(BaseReference reference)
     {
         JSTypeExpression enumParameterType = reference.getComment().getEnumParameterType();
-        String overrideStringType = transformType(reference.getModel().evaluate(
-                enumParameterType).toAnnotationString());
+        String overrideStringType = transformType(reference.getModel().evaluate(enumParameterType).toAnnotationString());
 
         return overrideStringType;
     }
@@ -100,7 +96,7 @@ public class JSTypeUtils
 
     //--------------------------------------------------------------------------
 
-    private static String transformType(String type)
+    public static String transformType(String type)
     {
         // XXX This is an error but, needs to be reduced in @param union
         if (type.indexOf("|") != -1)
@@ -121,8 +117,7 @@ public class JSTypeUtils
         return type;
     }
 
-    private static String toTypeExpressionString(BaseReference reference,
-            JSTypeExpression expression)
+    private static String toTypeExpressionString(BaseReference reference, JSTypeExpression expression)
     {
         JSType jsType = getJsType(reference.getModel(), expression);
         String type = toTypeString(jsType);
@@ -156,8 +151,7 @@ public class JSTypeUtils
         return type;
     }
 
-    private static JSType getJsType(ReferenceModel model,
-            JSTypeExpression typeExpression)
+    private static JSType getJsType(ReferenceModel model, JSTypeExpression typeExpression)
     {
         JSType jsType = model.evaluate(typeExpression);
 


[4/8] git commit: [flex-falcon] [refs/heads/add-collect-import-pass] - Remove collect of imports from ResolvePackagesPass

Posted by ft...@apache.org.
Remove collect of imports from ResolvePackagesPass


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

Branch: refs/heads/add-collect-import-pass
Commit: 69f0a8b4633ce6a9f5e86d87636f8e3b03000b64
Parents: 298cc73
Author: Frédéric THOMAS <we...@gmail.com>
Authored: Tue Jul 7 19:06:34 2015 +0100
Committer: Frédéric THOMAS <we...@gmail.com>
Committed: Tue Jul 7 19:15:49 2015 +0100

----------------------------------------------------------------------
 .../codegen/externals/pass/ResolvePackagesPass.java         | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/69f0a8b4/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/pass/ResolvePackagesPass.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/pass/ResolvePackagesPass.java b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/pass/ResolvePackagesPass.java
index d4664d7..b446d8c 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/pass/ResolvePackagesPass.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/pass/ResolvePackagesPass.java
@@ -68,22 +68,19 @@ public class ResolvePackagesPass extends AbstractCompilerPass
             String testName = qualifiedName + "." + baseName;
             if (testName.equals(child.getQualifiedName()))
             {
-                FieldReference field = null;
+                FieldReference field;
                 if (!reference.isQualifiedName())
                 {
                     log("   Add field: public static var " + baseName);
-                    field = reference.addField(child.getNode(), baseName,
-                            child.getNode().getJSDocInfo(), true);
+                    field = reference.addField(child.getNode(), baseName, child.getNode().getJSDocInfo(), true);
                 }
                 else
                 {
                     log("   Add field: public var " + baseName);
-                    field = reference.addField(child.getNode(), baseName,
-                            child.getNode().getJSDocInfo(), false);
+                    field = reference.addField(child.getNode(), baseName, child.getNode().getJSDocInfo(), false);
                 }
 
                 field.setOverrideStringType(child.getQualifiedName());
-                reference.addImport(child.getQualifiedName());
             }
         }
 


[6/8] git commit: [flex-falcon] [refs/heads/add-collect-import-pass] - Cleanup the tests

Posted by ft...@apache.org.
Cleanup the tests


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

Branch: refs/heads/add-collect-import-pass
Commit: 882e83ff3687f3fbbc51483f964bf9a37df39171
Parents: c55587c
Author: Frédéric THOMAS <we...@gmail.com>
Authored: Tue Jul 7 19:22:57 2015 +0100
Committer: Frédéric THOMAS <we...@gmail.com>
Committed: Tue Jul 7 19:22:57 2015 +0100

----------------------------------------------------------------------
 .../compiler/internal/codegen/externals/TestCollectImports.java  | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/882e83ff/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/externals/TestCollectImports.java
----------------------------------------------------------------------
diff --git a/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/externals/TestCollectImports.java b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/externals/TestCollectImports.java
index ad025c3..a7ab2b8 100644
--- a/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/externals/TestCollectImports.java
+++ b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/externals/TestCollectImports.java
@@ -191,7 +191,7 @@ public class TestCollectImports extends ExternalsTestBase
 
         assertCompileTestFileSuccess(IMPORTS_TEST_DIR);
 
-        client.emit();
+        //client.emit();
 
         FunctionReference importFunction = (FunctionReference) model.getFunctions().toArray()[0];
         assertNotNull(importFunction);
@@ -215,7 +215,7 @@ public class TestCollectImports extends ExternalsTestBase
     @Override
     protected void configure(ExternCConfiguration config) throws IOException
     {
-        config.setASRoot(ExternalsTestUtils.AS_ROOT_DIR);
+        //config.setASRoot(ExternalsTestUtils.AS_ROOT_DIR);
     }
 
 }


[8/8] git commit: [flex-falcon] [refs/heads/add-collect-import-pass] - Use process instead of shouldTraverse

Posted by ft...@apache.org.
Use process instead of shouldTraverse


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

Branch: refs/heads/add-collect-import-pass
Commit: 134f1020b3752fdc2097b15b48d7b76c1bb3e3f9
Parents: 986dd24
Author: Frédéric THOMAS <we...@gmail.com>
Authored: Thu Jul 9 15:42:48 2015 +0100
Committer: Frédéric THOMAS <we...@gmail.com>
Committed: Thu Jul 9 15:42:48 2015 +0100

----------------------------------------------------------------------
 .../internal/codegen/externals/pass/CollectImportsPass.java | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/134f1020/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/pass/CollectImportsPass.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/pass/CollectImportsPass.java b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/pass/CollectImportsPass.java
index 363eb2d..69af334 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/pass/CollectImportsPass.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/pass/CollectImportsPass.java
@@ -20,7 +20,7 @@ public class CollectImportsPass extends AbstractCompilerPass
     }
 
     @Override
-    public boolean shouldTraverse(final NodeTraversal nodeTraversal, final Node n, final Node parent)
+    public void process(Node externs, Node root)
     {
         for (ClassReference reference : model.getClasses())
         {
@@ -31,8 +31,6 @@ public class CollectImportsPass extends AbstractCompilerPass
         {
             collectFunctionImports(reference);
         }
-
-        return false;
     }
 
     private void collectClassImports(ClassReference reference)
@@ -161,6 +159,11 @@ public class CollectImportsPass extends AbstractCompilerPass
     }
 
     @Override
+    public boolean shouldTraverse(final NodeTraversal nodeTraversal, final Node n, final Node parent) {
+        return false;
+    }
+
+    @Override
     public void visit(final NodeTraversal t, final Node n, final Node parent)
     {
     }


[7/8] git commit: [flex-falcon] [refs/heads/add-collect-import-pass] - Check if we have a constructor

Posted by ft...@apache.org.
Check if we have a constructor


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

Branch: refs/heads/add-collect-import-pass
Commit: 986dd240980999f467bb41afe59552324e964905
Parents: 882e83f
Author: Frédéric THOMAS <we...@gmail.com>
Authored: Tue Jul 7 20:15:29 2015 +0100
Committer: Frédéric THOMAS <we...@gmail.com>
Committed: Tue Jul 7 20:15:29 2015 +0100

----------------------------------------------------------------------
 .../internal/codegen/externals/pass/CollectImportsPass.java   | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/986dd240/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/pass/CollectImportsPass.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/pass/CollectImportsPass.java b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/pass/CollectImportsPass.java
index 28815f9..363eb2d 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/pass/CollectImportsPass.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/pass/CollectImportsPass.java
@@ -76,9 +76,12 @@ public class CollectImportsPass extends AbstractCompilerPass
             }
         }
 
-        for (ParameterReference parameterReference : constructor.getParameters())
+        if (constructor != null)
         {
-            addClassImport(reference, getType(parameterReference));
+            for (ParameterReference parameterReference : constructor.getParameters())
+            {
+                addClassImport(reference, getType(parameterReference));
+            }
         }
 
         for (MethodReference method : methods.values())