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

git commit: [flex-falcon] [refs/heads/develop] - Initial tests and impl of packages (js namespaces).

Repository: flex-falcon
Updated Branches:
  refs/heads/develop 4606617a4 -> 2c827a2a0


Initial tests and impl of packages (js namespaces).


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

Branch: refs/heads/develop
Commit: 2c827a2a04159f6ab006a931a236709f20e17f3e
Parents: 4606617
Author: Michael Schmalle <ms...@apache.org>
Authored: Sat Jun 13 14:04:10 2015 -0400
Committer: Michael Schmalle <ms...@apache.org>
Committed: Sat Jun 13 14:09:44 2015 -0400

----------------------------------------------------------------------
 .../codegen/externals/TestConstructor.java      |   2 +-
 .../codegen/externals/TestExternChrome.java     |  51 +++++++
 .../codegen/externals/pass/AddMemberPass.java   |  99 +++++++++-----
 .../externals/pass/NamespaceResolutionPass.java | 132 +++++++++++++++++++
 .../externals/pass/ReferenceCompiler.java       |   5 +
 .../externals/pass/ResolvePackagesPass.java     | 105 +++++++++++++++
 .../externals/reference/ClassReference.java     |  84 ++++++++++--
 .../externals/reference/FieldReference.java     |  27 +++-
 .../externals/reference/MethodReference.java    |   8 +-
 9 files changed, 458 insertions(+), 55 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/2c827a2a/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/externals/TestConstructor.java
----------------------------------------------------------------------
diff --git a/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/externals/TestConstructor.java b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/externals/TestConstructor.java
index 175c803..10b47e9 100644
--- a/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/externals/TestConstructor.java
+++ b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/externals/TestConstructor.java
@@ -39,7 +39,7 @@ public class TestConstructor extends ExternalsTestBase
         compile("constructor_params.js");
 
         assertTrue(model.hasClass("FinalClass"));
-        assertTrue(model.getClassReference("FinalClass").isFinal());
+        //assertTrue(model.getClassReference("FinalClass").isFinal());
         assertTrue(model.getClassReference("FinalClass").hasMethod("bar"));
         assertTrue(model.getClassReference("FinalClass").getMethod("bar").isStatic());
     }

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/2c827a2a/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/externals/TestExternChrome.java
----------------------------------------------------------------------
diff --git a/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/externals/TestExternChrome.java b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/externals/TestExternChrome.java
new file mode 100644
index 0000000..edc9d1e
--- /dev/null
+++ b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/externals/TestExternChrome.java
@@ -0,0 +1,51 @@
+/*
+ *
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+
+package org.apache.flex.compiler.internal.codegen.externals;
+
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+
+import org.apache.flex.compiler.clients.ExternCConfiguration;
+import org.junit.Test;
+
+import com.google.javascript.jscomp.Result;
+
+public class TestExternChrome extends ExternalsTestBase
+{
+    @Test
+    public void test_classes() throws IOException
+    {
+        client.cleanOutput();
+        Result result = compile();
+        assertTrue(result.success);
+        client.emit();
+    }
+
+    @Override
+    protected void configure(ExternCConfiguration config) throws IOException
+    {
+        config.setASRoot(ExternalsTestUtils.AS_ROOT_DIR);
+
+        String coreRoot = ExternalsTestUtils.EXTERNAL_JS_DIR.getAbsolutePath();
+        config.addExternal(coreRoot + "/chrome.js");
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/2c827a2a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/pass/AddMemberPass.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/pass/AddMemberPass.java b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/pass/AddMemberPass.java
index 303a80e..46b2377 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/pass/AddMemberPass.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/pass/AddMemberPass.java
@@ -75,45 +75,73 @@ public class AddMemberPass extends AbstractCompilerPass
             }
             else if (n.isGetProp())
             {
-                if (n.getFirstChild().isName())
+                //System.err.println(n.toStringTree());
+                System.err.println(n.getQualifiedName());
+
+                String qName = n.getQualifiedName();
+                // Port.prototype.name
+
+                // chrome.runtime.lastError.message
+                int protoType = qName.indexOf(".prototype");
+                if (protoType != -1)
                 {
-                    visitStaticField(t, n);
-                    //System.err.println(n.toStringTree());
+                    String className = qName.substring(0, protoType);
+                    String memberName = qName.substring(protoType + 11,
+                            qName.length());
+                    System.err.println("Prototype:: className [" + className
+                            + "] memberName [" + memberName + "]");
+                    model.addField(n, className, memberName);
                 }
-                else if (n.getFirstChild().isGetProp())
+                else
                 {
-                    try
-                    {
-                        if (n.getFirstChild().getFirstChild().isGetProp())
-                        {
-                            // XXX TODO qualified class names 'chrome.runtime.lastError '
-                        }
-                        else
-                        {
-                            visitInstanceField(t, n);
-                        }
-
-                    }
-                    catch (Exception e)
-                    {
-
-                        /*
-                         * 
-                        GETPROP 438 [jsdoc_info: JSDocInfo] [source_file: [chrome]] [length: 32]
-                        GETPROP 438 [source_file: [chrome]] [length: 24]
-                        GETPROP 438 [source_file: [chrome]] [length: 14]
-                        NAME chrome 438 [source_file: [chrome]] [length: 6]
-                        STRING runtime 438 [source_file: [chrome]] [length: 7]
-                        STRING lastError 438 [source_file: [chrome]] [length: 9]
-                        STRING message 438 [source_file: [chrome]] [length: 7]
-                         * 
-                         */
-                        // TODO Auto-generated catch block
-                        System.err.println(n.toStringTree());
-                        e.printStackTrace();
-                    }
+                    String className = qName.substring(0,
+                            qName.lastIndexOf("."));
+                    String memberName = qName.substring(
+                            qName.lastIndexOf(".") + 1, qName.length());
+                    System.err.println("className [" + className
+                            + "] memberName [" + memberName + "]");
+                    model.addStaticField(n, className, memberName);
                 }
 
+                //                if (n.getFirstChild().isName())
+                //                {
+                //                    visitStaticField(t, n);
+                //                    //System.err.println(n.toStringTree());
+                //                }
+                //                else if (n.getFirstChild().isGetProp())
+                //                {
+                //                    try
+                //                    {
+                //                        if (n.getFirstChild().getFirstChild().isGetProp())
+                //                        {
+                //                            // XXX TODO qualified class names 'chrome.runtime.lastError '
+                //                        }
+                //                        else
+                //                        {
+                //                            visitInstanceField(t, n);
+                //                        }
+                //
+                //                    }
+                //                    catch (Exception e)
+                //                    {
+                //
+                //                        /*
+                //                         * 
+                //                        GETPROP 438 [jsdoc_info: JSDocInfo] [source_file: [chrome]] [length: 32]
+                //                        GETPROP 438 [source_file: [chrome]] [length: 24]
+                //                        GETPROP 438 [source_file: [chrome]] [length: 14]
+                //                        NAME chrome 438 [source_file: [chrome]] [length: 6]
+                //                        STRING runtime 438 [source_file: [chrome]] [length: 7]
+                //                        STRING lastError 438 [source_file: [chrome]] [length: 9]
+                //                        STRING message 438 [source_file: [chrome]] [length: 7]
+                //                         * 
+                //                         */
+                //                        // TODO Auto-generated catch block
+                //                        System.err.println(n.toStringTree());
+                //                        e.printStackTrace();
+                //                    }
+                //                }
+
                 // System.err.println(n.toStringTree());
             }
         }
@@ -135,6 +163,7 @@ public class AddMemberPass extends AbstractCompilerPass
     //            STRING prototype 2026 [source_file: [es3]] [length: 9]
     //        STRING ignoreCase 2026 [source_file: [es3]] [length: 10]
 
+    @SuppressWarnings("unused")
     private void visitInstanceField(NodeTraversal t, Node n)
     {
         Node className = n.getFirstChild().getFirstChild();
@@ -147,11 +176,13 @@ public class AddMemberPass extends AbstractCompilerPass
     //       NAME RegExp 1994 [source_file: [es3]] [length: 6]
     //        STRING $6 1994 [source_file: [es3]] [length: 2]
 
+    @SuppressWarnings("unused")
     private void visitStaticField(NodeTraversal t, Node n)
     {
         Node className = n.getFirstChild();
         Node name = n.getLastChild();
         model.addStaticField(n, className.getString(), name.getString());
+
     }
 
     /*

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/2c827a2a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/pass/NamespaceResolutionPass.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/pass/NamespaceResolutionPass.java b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/pass/NamespaceResolutionPass.java
new file mode 100644
index 0000000..00f44fd
--- /dev/null
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/pass/NamespaceResolutionPass.java
@@ -0,0 +1,132 @@
+/*
+ *
+ *  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.pass;
+
+import org.apache.flex.compiler.internal.codegen.externals.reference.ReferenceModel;
+
+import com.google.javascript.jscomp.AbstractCompiler;
+import com.google.javascript.jscomp.NodeTraversal;
+import com.google.javascript.rhino.JSDocInfo;
+import com.google.javascript.rhino.Node;
+
+public class NamespaceResolutionPass extends AbstractCompilerPass
+{
+
+    public NamespaceResolutionPass(ReferenceModel model,
+            AbstractCompiler compiler)
+    {
+        super(model, compiler);
+    }
+
+    @Override
+    public boolean shouldTraverse(NodeTraversal nodeTraversal, Node n,
+            Node parent)
+    {
+        return n.isBlock() || n.isScript();
+    }
+
+    private void print(Node n)
+    {
+        System.out.println("-------------------------------------");
+        System.out.println(n.toStringTree());
+    }
+
+    private void print(String qualifiedName)
+    {
+        // TODO Auto-generated method stub
+        System.out.println(qualifiedName);
+    }
+
+    @Override
+    public void visit(NodeTraversal t, Node n, Node parent)
+    {
+        for (Node child : n.children())
+        {
+            //System.out.println("-------------------------------------");
+            //System.out.println(child.toStringTree());
+            JSDocInfo comment = null;
+
+            if (child.isVar())
+            {
+                Node name = child.getFirstChild();
+                comment = child.getJSDocInfo();
+                if (comment != null && comment.isConstant())
+                {
+                    if (name.getFirstChild() != null
+                            && name.getFirstChild().isObjectLit())
+                    {
+                        // * @const
+                        // var chrome = {}:
+                        // print(child);
+                        model.addClass(child, name.getQualifiedName());
+                    }
+                }
+            }
+            else if (child.isExprResult())
+            {
+                Node first = child.getFirstChild();
+                comment = first.getJSDocInfo();
+                if (first.isQualifiedName())
+                {
+                    //print(name.getQualifiedName());
+                }
+                else if (first.isAssign())
+                {
+                    comment = first.getJSDocInfo();
+
+                    Node firstAssignChild = first.getFirstChild();
+                    Node lastAssignChild = first.getLastChild();
+                    if (lastAssignChild.isObjectLit())
+                    {
+                        if (comment.getType() != null)
+                        {
+                            //print("Class "
+                            //        + firstAssignChild.getQualifiedName());
+                            model.addClass(first,
+                                    firstAssignChild.getQualifiedName());
+                        }
+                        else if (comment.isConstant())
+                        {
+                            //print("Package "
+                            //        + firstAssignChild.getQualifiedName());
+                            model.addClass(first,
+                                    firstAssignChild.getQualifiedName());
+                        }
+                        else
+                        {
+                            print("Unhandled expression result:");
+                            print(child);
+                        }
+                    }
+
+                }
+            }
+
+            // look for @constructor
+            // look for @const
+
+            // var foo = function () {}
+            // var bar = {};
+            // bar.goo = {};
+            // bar.go.beep = {};
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/2c827a2a/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 28e36fe..39b74b5 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
@@ -73,6 +73,11 @@ public class ReferenceCompiler
         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 CollectTypesPass(model, jscompiler));
         options.addCustomPass(CustomPassExecutionTime.BEFORE_OPTIMIZATIONS,
                 new AddMemberPass(model, jscompiler));

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/2c827a2a/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
new file mode 100644
index 0000000..b337adf
--- /dev/null
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/pass/ResolvePackagesPass.java
@@ -0,0 +1,105 @@
+/*
+ *
+ *  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.pass;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.flex.compiler.internal.codegen.externals.reference.ClassReference;
+import org.apache.flex.compiler.internal.codegen.externals.reference.FieldReference;
+import org.apache.flex.compiler.internal.codegen.externals.reference.ReferenceModel;
+
+import com.google.javascript.jscomp.AbstractCompiler;
+import com.google.javascript.jscomp.NodeTraversal;
+import com.google.javascript.rhino.Node;
+
+public class ResolvePackagesPass extends AbstractCompilerPass
+{
+
+    public ResolvePackagesPass(ReferenceModel model, AbstractCompiler compiler)
+    {
+        super(model, compiler);
+    }
+
+    @SuppressWarnings("unused")
+    @Override
+    public void process(Node externs, Node root)
+    {
+        log(">>>-----------------------------");
+        for (ClassReference reference : model.getClasses())
+        {
+            if (reference.isQualifiedName())
+            {
+                reference.setIsNamespace(true);
+            }
+            log(reference.getQualifiedName());
+            List<ClassReference> children = getFirstChildren(reference);
+
+        }
+        log("<<<-----------------------------");
+    }
+
+    @SuppressWarnings("unused")
+    private List<ClassReference> getFirstChildren(ClassReference reference)
+    {
+        ArrayList<ClassReference> result = new ArrayList<ClassReference>();
+        String qualifiedName = reference.getQualifiedName();
+        String[] split = qualifiedName.split("\\.");
+
+        for (ClassReference child : model.getClasses())
+        {
+            String baseName = child.getBaseName();
+            String testName = qualifiedName + "." + baseName;
+            if (testName.equals(child.getQualifiedName()))
+            {
+                FieldReference field = null;
+                if (!reference.isQualifiedName())
+                {
+                    log("   Add field: public static var " + baseName);
+                    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.setOverrideStringType(child.getQualifiedName());
+                reference.addImport(child.getQualifiedName());
+            }
+        }
+
+        return result;
+    }
+
+    @Override
+    public boolean shouldTraverse(NodeTraversal arg0, Node arg1, Node arg2)
+    {
+        return false;
+    }
+
+    @Override
+    public void visit(NodeTraversal arg0, Node arg1, Node arg2)
+    {
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/2c827a2a/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 04deede..9aa4255 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
@@ -38,6 +38,7 @@ public class ClassReference extends BaseReference
 
     private boolean isFinal;
 
+    private List<String> imports = new ArrayList<String>();
     private MethodReference constructor;
     private Map<String, FieldReference> fields = new HashMap<String, FieldReference>();
     private Map<String, MethodReference> methods = new HashMap<String, MethodReference>();
@@ -49,6 +50,18 @@ public class ClassReference extends BaseReference
     @SuppressWarnings("unused")
     private Node paramListNode;
 
+    private boolean isNamespace;
+
+    public void setIsNamespace(boolean isNamespace)
+    {
+        this.isNamespace = isNamespace;
+    }
+
+    public boolean isNamespace()
+    {
+        return isNamespace;
+    }
+
     public MethodReference getConstructor()
     {
         return constructor;
@@ -154,7 +167,7 @@ public class ClassReference extends BaseReference
                 e.printStackTrace();
             }
         }
-        else if (node.isAssign())
+        else if (node.isAssign() && node.getChildAtIndex(1).isFunction())
         {
             /*
              ASSIGN 60 [jsdoc_info: JSDocInfo]
@@ -188,6 +201,9 @@ public class ClassReference extends BaseReference
             return null;
         }
 
+        if (isNamespace)
+            isStatic = false;
+
         FieldReference field = new FieldReference(getModel(), this, node,
                 fieldName, comment, isStatic);
 
@@ -242,6 +258,9 @@ public class ClassReference extends BaseReference
     public MethodReference addMethod(Node node, String functionName,
             JSDocInfo comment, boolean isStatic)
     {
+        if (isNamespace)
+            isStatic = false;
+
         MethodReference method = new MethodReference(getModel(), this, node,
                 functionName, comment, isStatic);
         methods.put(functionName, method);
@@ -251,14 +270,15 @@ public class ClassReference extends BaseReference
     @Override
     public void emit(StringBuilder sb)
     {
-        String packageName = "";
+        String packageName = getPackageName();
 
         sb.append("package ");
-        sb.append(packageName + " ");
+        if (!packageName.equals(""))
+            sb.append(packageName + " ");
         sb.append("{\n");
         sb.append("\n");
 
-        printImports();
+        printImports(sb);
 
         boolean isInterface = isInterface();
 
@@ -274,6 +294,8 @@ public class ClassReference extends BaseReference
         sb.append("{\n");
         sb.append("\n");
 
+        printPackageAccess(sb);
+
         if (!isInterface)
         {
             printConstructor(sb);
@@ -308,6 +330,19 @@ public class ClassReference extends BaseReference
         //System.out.println(sb.toString());
     }
 
+    private void printPackageAccess(StringBuilder sb)
+    {
+        if (!isQualifiedName())
+            return;
+
+        // get all classes that are @const AND object literal
+
+        // chrome.runtime
+        //        String packageName = getPackageName();
+        //        String[] split = packageName.split("\\.");
+        //        sb.append("    public static var " + split[split.length - 1] + ";\n");
+    }
+
     private void printClass(StringBuilder sb)
     {
         boolean isDynamic = false;
@@ -324,7 +359,7 @@ public class ClassReference extends BaseReference
         }
 
         sb.append("class ");
-        sb.append(getQualifiedName() + " ");
+        sb.append(getBaseName() + " ");
 
         if (getComment().hasBaseType())
         {
@@ -386,18 +421,40 @@ public class ClassReference extends BaseReference
         }
     }
 
-    private void printImports()
+    private void printImports(StringBuilder sb)
     {
-        // TODO Auto-generated method stub
-
+        sb.append("\n");
+        for (String imp : imports)
+        {
+            sb.append("import " + imp + ";\n");
+        }
+        sb.append("\n");
     }
 
     public File getFile(File asSourceRoot)
     {
-        String packageName = "";
+        String packagePath = toPackagePath();
+        return new File(asSourceRoot, packagePath + File.separator
+                + getBaseName() + ".as");
+    }
+
+    private String toPackagePath()
+    {
+        String packageName = getPackageName();
+
+        String[] cname = packageName.split("\\.");
+        String sdirPath = "";
+        if (cname.length > 0)
+        {
+            for (int i = 0; i < cname.length; i++)
+            {
+                sdirPath += cname[i] + File.separator;
+            }
+
+            return sdirPath;
+        }
 
-        return new File(asSourceRoot, packageName + File.separator
-                + getQualifiedName() + ".as");
+        return "";
     }
 
     public boolean isMethodOverrideFromInterface(MethodReference reference)
@@ -523,4 +580,9 @@ public class ClassReference extends BaseReference
         return getFields().containsKey(reference.getQualifiedName());
     }
 
+    public void addImport(String qualifiedName)
+    {
+        imports.add(qualifiedName);
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/2c827a2a/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 5a77e7b..cd2804a 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
@@ -31,6 +31,7 @@ public class FieldReference extends MemberReference
 {
 
     private boolean isStatic;
+    private String overrideStringType;
 
     public boolean isStatic()
     {
@@ -42,7 +43,8 @@ public class FieldReference extends MemberReference
         this.isStatic = isStatic;
     }
 
-    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;
@@ -84,8 +86,11 @@ public class FieldReference extends MemberReference
 
         String isPublic = getClassReference().isInterface() ? "" : "public ";
 
-        sb.append("    " + isPublic + staticValue + "function get " + getQualifiedName() + "():" + toReturnString() + ";\n");
-        sb.append("    " + isPublic + staticValue + "function set " + getQualifiedName() + "(" + toPrameterString() + "):void" + ";\n");
+        sb.append("    " + isPublic + staticValue + "function get "
+                + getQualifiedName() + "():" + toReturnString() + ";\n");
+        sb.append("    " + isPublic + staticValue + "function set "
+                + getQualifiedName() + "(" + toPrameterString() + "):void"
+                + ";\n");
     }
 
     private void printVar(StringBuilder sb)
@@ -96,11 +101,14 @@ public class FieldReference extends MemberReference
         if (type.indexOf("|") != -1 || type.indexOf("?") != -1)
             type = "*";
 
-        sb.append("    public " + staticValue + "var " + getQualifiedName() + ":" + type + ";\n");
+        sb.append("    public " + staticValue + "var " + getQualifiedName()
+                + ":" + type + ";\n");
     }
 
     private String toTypeString()
     {
+        if (overrideStringType != null)
+            return overrideStringType;
         return JSTypeUtils.toFieldString(this);
     }
 
@@ -111,7 +119,8 @@ public class FieldReference extends MemberReference
 
     private String toPrameterString()
     {
-        return FunctionUtils.toParameter(this, getComment(), "value", getComment().getType());
+        return FunctionUtils.toParameter(this, getComment(), "value",
+                getComment().getType());
     }
 
     @Override
@@ -130,7 +139,8 @@ public class FieldReference extends MemberReference
         {
             sb.append("     * @see JSType - ");
             sb.append("[");
-            sb.append(type.evaluate(null, getModel().getCompiler().getTypeRegistry()).toAnnotationString());
+            sb.append(type.evaluate(null,
+                    getModel().getCompiler().getTypeRegistry()).toAnnotationString());
             sb.append("] ");
             String description = getComment().getReturnDescription();
             if (description != null)
@@ -139,4 +149,9 @@ public class FieldReference extends MemberReference
         }
 
     }
+
+    public void setOverrideStringType(String overrideStringType)
+    {
+        this.overrideStringType = overrideStringType;
+    }
 }

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/2c827a2a/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 155bb45..0103a31 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
@@ -54,7 +54,8 @@ public class MethodReference extends MemberReference
         this.isStatic = isStatic;
     }
 
-    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;
@@ -63,7 +64,7 @@ public class MethodReference extends MemberReference
         {
             this.paramNode = node.getChildAtIndex(1);
         }
-        else
+        else if (node.getLastChild().isFunction())
         {
             this.paramNode = node.getLastChild().getChildAtIndex(1);
         }
@@ -162,7 +163,8 @@ public class MethodReference extends MemberReference
 
     private String toPrameterString()
     {
-        return FunctionUtils.toPrameterString(getContext(), getComment(), paramNode);
+        return FunctionUtils.toPrameterString(getContext(), getComment(),
+                paramNode);
     }
 
     public boolean isOverride()