flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ftho...@apache.org
Subject git commit: [flex-falcon] [refs/heads/add-CollectImportPass] - Use a compiler pass to collect imports
Date Sun, 05 Jul 2015 23:05:12 GMT
Repository: flex-falcon
Updated Branches:
  refs/heads/add-CollectImportPass [created] 18d55ff81


Use a compiler pass to collect imports

- Replaced the last fix by a compiler pass.
- Code cleanup

Note: I guess this approach follows more the pattern
as suggested by Mike and catch more 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/18d55ff8
Tree: http://git-wip-us.apache.org/repos/asf/flex-falcon/tree/18d55ff8
Diff: http://git-wip-us.apache.org/repos/asf/flex-falcon/diff/18d55ff8

Branch: refs/heads/add-CollectImportPass
Commit: 18d55ff8193ea96fbb6ebc2c9e287b5db955022b
Parents: d30b0c4
Author: Frédéric THOMAS <webdoublefx@gmail.com>
Authored: Sun Jul 5 23:56:25 2015 +0100
Committer: Frédéric THOMAS <webdoublefx@gmail.com>
Committed: Mon Jul 6 00:04:15 2015 +0100

----------------------------------------------------------------------
 .../externals/pass/CollectImportsPass.java      | 160 +++++++++++++++
 .../externals/pass/ReferenceCompiler.java       |  23 +--
 .../externals/pass/ResolvePackagesPass.java     |   9 +-
 .../externals/reference/BaseReference.java      |  36 ++--
 .../externals/reference/ClassReference.java     | 195 ++++++++-----------
 .../externals/reference/FieldReference.java     |  24 +--
 .../externals/reference/FunctionReference.java  |  94 +++++++--
 .../externals/reference/MethodReference.java    |  77 ++++++--
 .../externals/reference/ParameterReference.java |  34 ++++
 .../externals/reference/ReferenceModel.java     |  38 ++--
 .../codegen/externals/utils/FunctionUtils.java  |  71 ++++---
 11 files changed, 511 insertions(+), 250 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/18d55ff8/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..b07163d
--- /dev/null
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/pass/CollectImportsPass.java
@@ -0,0 +1,160 @@
+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
+{
+    private static boolean done;
+
+    public CollectImportsPass(final ReferenceModel model, AbstractCompiler compiler)
+    {
+        super(model, compiler);
+    }
+
+    @Override
+    public boolean shouldTraverse(final NodeTraversal nodeTraversal, final Node n, final Node parent)
+    {
+        if (!done)
+        {
+            for (ClassReference reference : model.getClasses())
+            {
+                addClassImports(reference);
+            }
+
+            for (FunctionReference reference : model.getFunctions())
+            {
+                addFunctionImports(reference);
+            }
+
+            done = true;
+        }
+        return false;
+    }
+
+    private void addClassImports(ClassReference reference)
+    {
+        final List<ClassReference> superClasses = reference.getSuperClasses();
+        final List<ClassReference> interfaces = reference.getInterfaces();
+        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 (FieldReference field : fields.values())
+        {
+            if (field.isExcluded() == null)
+            {
+                addClassImport(reference, getType(field));
+            }
+        }
+
+        for (MethodReference method : methods.values())
+        {
+            if (method.isExcluded() == null)
+            {
+                addClassImport(reference, getReturnType(method));
+
+                for (ParameterReference parameterReference : method.getParameters())
+                {
+                    addClassImport(reference, getType(parameterReference));
+                }
+            }
+        }
+    }
+
+    private void addFunctionImports(final FunctionReference function)
+    {
+        if (function.isExcluded() == null)
+        {
+            ClassReference returnType = getReturnType(function);
+            ClassReference filteredImport = filterImport(returnType);
+
+            if (filteredImport != null)
+            {
+                function.addImport(filteredImport);
+
+                for (ParameterReference parameterReference : function.getParameters())
+                {
+                    ClassReference type = getType(parameterReference);
+                    filteredImport = filterImport(type);
+
+                    if (filteredImport != null)
+                    {
+                        function.addImport(filteredImport);
+                    }
+                }
+            }
+        }
+    }
+
+    private ClassReference getType(final FieldReference field)
+    {
+        return model.getClassReference(field.toTypeString());
+    }
+
+    private ClassReference getReturnType(final MethodReference method)
+    {
+        return model.getClassReference(method.toReturnTypeAnnotationString());
+    }
+
+    private ClassReference getReturnType(final FunctionReference function)
+    {
+        return model.getClassReference(function.transformReturnString());
+    }
+
+    private ClassReference getType(final ParameterReference parameter)
+    {
+        return model.getClassReference(parameter.getQualifiedName());
+    }
+
+    private ClassReference filterImport(ClassReference classReference)
+    {
+        final boolean canImport = classReference != null && classReference.isQualifiedName()
+                && model.isExcludedClass(classReference) == null;
+        return canImport ? classReference : null;
+    }
+
+    private void addClassImport(final ClassReference thisReference, final ClassReference importReference)
+    {
+        final ClassReference filteredImport = filterImport(importReference);
+        if (filteredImport != null)
+        {
+            final String thisPackageName = thisReference.getPackageName();
+            final String importPackageName = filteredImport.getPackageName();
+
+            if (!importPackageName.equals(thisPackageName))
+            {
+                thisReference.addImport(filteredImport);
+            }
+        }
+    }
+
+    @Override
+    public void visit(final NodeTraversal t, final Node n, final Node parent)
+    {
+    }
+}

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/18d55ff8/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/18d55ff8/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());
             }
         }
 

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/18d55ff8/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/18d55ff8/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..3cd677a 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,21 @@ public class ClassReference extends BaseReference
                 objLit = node.getLastChild();
             }
 
-            for (Node stringKey : objLit.children())
-            {
-                if (stringKey.isStringKey())
+            if (objLit != null) {
+                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 +197,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 +254,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 +268,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 +362,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 +376,7 @@ 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);
         }
@@ -420,20 +416,12 @@ public class ClassReference extends BaseReference
         return fields.containsKey(fieldName);
     }
 
-    public boolean hasInstanceField(String fieldName)
-    {
-        if (!fields.containsKey(fieldName))
-            return false;
-
-        return !fields.get(fieldName).isStatic();
+    public boolean hasInstanceField(String fieldName) {
+        return fields.containsKey(fieldName) && !fields.get(fieldName).isStatic();
     }
 
-    public boolean hasStaticField(String fieldName)
-    {
-        if (!fields.containsKey(fieldName))
-            return false;
-
-        return fields.get(fieldName).isStatic();
+    public boolean hasStaticField(String fieldName) {
+        return fields.containsKey(fieldName) && fields.get(fieldName).isStatic();
     }
 
     public boolean hasMethod(String methodName)
@@ -441,24 +429,15 @@ public class ClassReference extends BaseReference
         return methods.containsKey(methodName);
     }
 
-    public boolean hasInstanceMethod(String fieldName)
-    {
-        if (!methods.containsKey(fieldName))
-            return false;
-
-        return !methods.get(fieldName).isStatic();
+    public boolean hasInstanceMethod(String fieldName) {
+        return methods.containsKey(fieldName) && !methods.get(fieldName).isStatic();
     }
 
-    public boolean hasStaticMethod(String fieldName)
-    {
-        if (!methods.containsKey(fieldName))
-            return false;
-
-        return methods.get(fieldName).isStatic();
+    public boolean hasStaticMethod(String fieldName) {
+        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 +450,63 @@ 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 +584,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 +604,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 +630,7 @@ public class ClassReference extends BaseReference
         }
 
         sb.append("class ");
-        sb.append(getBaseName() + " ");
+        sb.append(getBaseName()).append(" ");
 
         if (getComment().hasBaseType())
         {
@@ -694,7 +653,7 @@ 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();
@@ -771,8 +730,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 +741,8 @@ public class ClassReference extends BaseReference
         String sdirPath = "";
         if (cname.length > 0)
         {
-            for (int i = 0; i < cname.length; i++)
-            {
-                sdirPath += cname[i] + File.separator;
+            for (final String aCname : cname) {
+                sdirPath += aCname + File.separator;
             }
 
             return sdirPath;

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/18d55ff8/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/18d55ff8/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..57950f6 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,18 +19,25 @@
 
 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
 {
     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)
     {
@@ -41,7 +48,7 @@ public class FunctionReference extends BaseReference
 
     private FunctionReference getContext()
     {
-        return override == null ? this : override;
+        return this;
     }
 
     public boolean isStatic()
@@ -67,6 +74,43 @@ public class FunctionReference extends BaseReference
     {
         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
@@ -75,7 +119,7 @@ public class FunctionReference extends BaseReference
         String packageName = "";
 
         sb.append("package ");
-        sb.append(packageName + " ");
+        sb.append(packageName).append(" ");
         sb.append("{\n");
         sb.append("\n");
 
@@ -92,7 +136,7 @@ public class FunctionReference extends BaseReference
         String staticValue = (isStatic) ? "static " : "";
 
         String publicModifier = "public ";
-        String braces = "";
+        String braces;
 
         String returns = "";
         if (!transformReturnString().equals("void"))
@@ -107,7 +151,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);
@@ -118,25 +162,24 @@ public class FunctionReference extends BaseReference
 
     private void printImports(final StringBuilder sb)
     {
-        String returnType = transformReturnString();
-
-        final boolean canBeImported = FunctionUtils.canBeImported(getModel(), getNode(), returnType, getPackageName());
-
-        if (canBeImported)
+        if (imports.size() > 0)
         {
-            sb.append("import ").append(returnType).append(";\n\n");
+            for (String anImport : imports)
+            {
+                sb.append("import ").append(anImport).append(";\n");
+            }
+            sb.append("\n");
         }
-
     }
 
-    private String transformReturnString()
+    public String transformReturnString()
     {
-        return FunctionUtils.toReturnString(getContext(), getComment());
+        return FunctionUtils.toReturnString(getContext());
     }
 
-    private String toPrameterString()
+    private String toParameterString()
     {
-        return FunctionUtils.toPrameterString(getContext(), getComment(), paramNode);
+        return FunctionUtils.toParameterString(getContext(), getComment(), paramNode);
     }
 
     public boolean isOverride()
@@ -149,4 +192,17 @@ public class FunctionReference extends BaseReference
     {
         emitFunctionCommentBody(sb);
     }
+
+    public void addImport(ClassReference reference)
+    {
+        if (reference != null)
+        {
+            imports.add(reference.getQualifiedName());
+        }
+    }
+
+    public List<ParameterReference> getParameters()
+    {
+        return parameters;
+    }
 }

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/18d55ff8/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..38cd91f 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();
@@ -57,12 +67,16 @@ public class MethodReference extends MemberReference
 
     public String toReturnTypeAnnotationString()
     {
-        JSType jsType = getModel().evaluate(getComment().getReturnType());
-        return jsType.toAnnotationString();
+        JSType jsType = null;
+        if (getComment() != null && getComment().getReturnType() != null)
+        {
+            jsType = getModel().evaluate(getComment().getReturnType());
+        }
+        return jsType != null ? jsType.toAnnotationString() : "Object";
     }
 
-    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 +89,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 +167,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 +195,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 +211,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);
@@ -207,14 +256,12 @@ public class MethodReference extends MemberReference
 
     private 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/18d55ff8/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;
+    }
+}

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/18d55ff8/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/18d55ff8/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;
     }


Mime
View raw message