FLEX-35053 MXML implements attribute

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

Branch: refs/heads/feature/maven-migration
Commit: 6541ded7d9e8c0f092b3766d6709c7c3518134f1
Parents: e736a12
Author: Alex Harui <aha...@apache.org>
Authored: Mon Mar 21 23:46:22 2016 -0700
Committer: Alex Harui <aha...@apache.org>
Committed: Mon Mar 21 23:46:22 2016 -0700

----------------------------------------------------------------------
 .../mxml/flexjs/TestFlexJSMXMLApplication.java  | 193 +++++++++++++++++++
 .../compiler/internal/test/FlexJSTestBase.java  |   1 +
 .../codegen/mxml/flexjs/MXMLFlexJSEmitter.java  |  38 +++-
 3 files changed, 231 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/6541ded7/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/mxml/flexjs/TestFlexJSMXMLApplication.java
----------------------------------------------------------------------
diff --git 
a/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/mxml/flexjs/TestFlexJSMXMLApplication.java
 
b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/mxml/flexjs/TestFlexJSMXMLApplication.java
index a4dce65..474f496 100644
--- 
a/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/mxml/flexjs/TestFlexJSMXMLApplication.java
+++ 
b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/mxml/flexjs/TestFlexJSMXMLApplication.java
@@ -18,10 +18,13 @@
  */
 package org.apache.flex.compiler.internal.codegen.mxml.flexjs;
 
+import org.apache.flex.compiler.internal.codegen.js.flexjs.JSFlexJSEmitter;
 import org.apache.flex.compiler.internal.driver.js.goog.JSGoogConfiguration;
 import org.apache.flex.compiler.internal.projects.FlexJSProject;
 import org.apache.flex.compiler.internal.test.FlexJSTestBase;
+import org.apache.flex.compiler.tree.mxml.IMXMLDocumentNode;
 import org.apache.flex.compiler.tree.mxml.IMXMLFileNode;
+import org.apache.flex.compiler.tree.mxml.IMXMLScriptNode;
 import org.junit.Test;
 
 public class TestFlexJSMXMLApplication extends FlexJSTestBase
@@ -77,5 +80,195 @@ public class TestFlexJSMXMLApplication extends 
FlexJSTestBase
 
         assertOutWithMetadata(getCodeFromFile(fileName + "_result", true, 
"flexjs/files"));
     }
+    
+    @Test
+    public void testInterfaceAttribute()
+    {
+        String code = "<basic:Application 
xmlns:fx=\"http://ns.adobe.com/mxml/2009\"; 
xmlns:basic=\"library://ns.apache.org/flexjs/basic\" 
implements=\"org.apache.flex.core.IChrome\">"
+                       + "<fx:Script><![CDATA["
+                + "    import org.apache.flex.core.IChrome;"
+                + "]]></fx:Script></basic:Application>";
+
+        IMXMLDocumentNode dnode = (IMXMLDocumentNode) getNode(code,
+                       IMXMLDocumentNode.class, 
FlexJSTestBase.WRAP_LEVEL_NONE);
+
+        
((JSFlexJSEmitter)(mxmlBlockWalker.getASEmitter())).getModel().setCurrentClass(dnode.getDefinition());
+        mxmlBlockWalker.visitDocument(dnode);
+        String appName = dnode.getQualifiedName();
+        String outTemplate = "/**\n" +
+                       " * AppName\n" +
+                       " *\n" +
+                       " * @fileoverview\n" +
+                       " *\n" +
+                       " * @suppress {checkTypes|accessControls}\n" +
+                       " */\n" +
+                       "\n" +
+                       "goog.provide('AppName');\n" +
+                       "\n" +
+                       "goog.require('org.apache.flex.core.Application');\n" +
+                       "goog.require('org.apache.flex.core.IChrome');\n" +
+                       "\n" +
+                       "\n" +
+                       "\n" +
+                       "/**\n" +
+                       " * @constructor\n" +
+                       " * @extends {org.apache.flex.core.Application}\n" +
+                       " */\n" +
+                       "AppName = function() {\n" +
+                       "  AppName.base(this, 'constructor');\n" +
+                       "  \n" +
+                       "  /**\n" +
+                       "   * @private\n" +
+                       "   * @type {Array}\n" +
+                       "   */\n" +
+                       "  this.mxmldd;\n" +
+                       "  \n" +
+                       "  /**\n" +
+                       "   * @private\n" +
+                       "   * @type {Array}\n" +
+                       "   */\n" +
+                       "  this.mxmldp;\n" +
+                       "};\n" +
+                       "goog.inherits(AppName, 
org.apache.flex.core.Application);\n" +
+                       "\n" +
+                       "\n" +
+                       "/**\n" +
+                       " * Metadata\n" +
+                       " *\n" +
+                       " * @type {Object.<string, Array.<Object>>}\n" +
+                       " */\n" +
+                       "AppName.prototype.FLEXJS_CLASS_INFO = { names: [{ 
name: 'AppName', qName: 'AppName' }], interfaces: 
[org.apache.flex.core.IChrome] };\n" +
+                       "\n" +
+                       "\n" +
+                       "/**\n" +
+                       " * Prevent renaming of class. Needed for 
reflection.\n" +
+                       " */\n" +
+                       "goog.exportSymbol('AppName', AppName);\n" +
+                       "\n" +
+                       "\n" +
+                       "\n" +
+                       "/**\n" +
+                       " * Reflection\n" +
+                       " *\n" +
+                       " * @return {Object.<string, Function>}\n" +
+                       " */\n" +
+                       "AppName.prototype.FLEXJS_REFLECTION_INFO = function () 
{\n" +
+                       "  return {\n" +
+                       "    variables: function () {\n" +
+                       "      return {\n" +
+                       "      };\n" + 
+                       "    },\n" +
+                       "    accessors: function () {\n" +
+                       "      return {\n" +
+                       "      };\n" +
+                       "    },\n" +
+                       "    methods: function () {\n" +
+                       "      return {\n" +
+                       "      };\n" +
+                       "    }\n" +
+                       "  };\n" +
+                       "};\n" +
+                       "\n" +
+                       "\n" +
+                       "\n";
+               
+        assertOutWithMetadata(outTemplate.replaceAll("AppName", appName));
+    }
+
+    @Test
+    public void testTwoInterfaceAttribute()
+    {
+        String code = "<basic:Application 
xmlns:fx=\"http://ns.adobe.com/mxml/2009\"; 
xmlns:basic=\"library://ns.apache.org/flexjs/basic\" 
implements=\"org.apache.flex.core.IChrome, org.apache.flex.core.IPopUp\">"
+                       + "<fx:Script><![CDATA["
+                + "    import org.apache.flex.core.IPopUp;"
+                + "    import org.apache.flex.core.IChrome;"
+                + "]]></fx:Script></basic:Application>";
+
+        IMXMLDocumentNode dnode = (IMXMLDocumentNode) getNode(code,
+                       IMXMLDocumentNode.class, 
FlexJSTestBase.WRAP_LEVEL_NONE);
+
+        
((JSFlexJSEmitter)(mxmlBlockWalker.getASEmitter())).getModel().setCurrentClass(dnode.getDefinition());
+        mxmlBlockWalker.visitDocument(dnode);
+        String appName = dnode.getQualifiedName();
+        String outTemplate = "/**\n" +
+                       " * AppName\n" +
+                       " *\n" +
+                       " * @fileoverview\n" +
+                       " *\n" +
+                       " * @suppress {checkTypes|accessControls}\n" +
+                       " */\n" +
+                       "\n" +
+                       "goog.provide('AppName');\n" +
+                       "\n" +
+                       "goog.require('org.apache.flex.core.Application');\n" +
+                       "goog.require('org.apache.flex.core.IChrome');\n" +
+                       "goog.require('org.apache.flex.core.IPopUp');\n" +
+                       "\n" +
+                       "\n" +
+                       "\n" +
+                       "/**\n" +
+                       " * @constructor\n" +
+                       " * @extends {org.apache.flex.core.Application}\n" +
+                       " */\n" +
+                       "AppName = function() {\n" +
+                       "  AppName.base(this, 'constructor');\n" +
+                       "  \n" +
+                       "  /**\n" +
+                       "   * @private\n" +
+                       "   * @type {Array}\n" +
+                       "   */\n" +
+                       "  this.mxmldd;\n" +
+                       "  \n" +
+                       "  /**\n" +
+                       "   * @private\n" +
+                       "   * @type {Array}\n" +
+                       "   */\n" +
+                       "  this.mxmldp;\n" +
+                       "};\n" +
+                       "goog.inherits(AppName, 
org.apache.flex.core.Application);\n" +
+                       "\n" +
+                       "\n" +
+                       "/**\n" +
+                       " * Metadata\n" +
+                       " *\n" +
+                       " * @type {Object.<string, Array.<Object>>}\n" +
+                       " */\n" +
+                       "AppName.prototype.FLEXJS_CLASS_INFO = { names: [{ 
name: 'AppName', qName: 'AppName' }], interfaces: 
[org.apache.flex.core.IChrome, org.apache.flex.core.IPopUp] };\n" +
+                       "\n" +
+                       "\n" +
+                       "/**\n" +
+                       " * Prevent renaming of class. Needed for 
reflection.\n" +
+                       " */\n" +
+                       "goog.exportSymbol('AppName', AppName);\n" +
+                       "\n" +
+                       "\n" +
+                       "\n" +
+                       "/**\n" +
+                       " * Reflection\n" +
+                       " *\n" +
+                       " * @return {Object.<string, Function>}\n" +
+                       " */\n" +
+                       "AppName.prototype.FLEXJS_REFLECTION_INFO = function () 
{\n" +
+                       "  return {\n" +
+                       "    variables: function () {\n" +
+                       "      return {\n" +
+                       "      };\n" + 
+                       "    },\n" +
+                       "    accessors: function () {\n" +
+                       "      return {\n" +
+                       "      };\n" +
+                       "    },\n" +
+                       "    methods: function () {\n" +
+                       "      return {\n" +
+                       "      };\n" +
+                       "    }\n" +
+                       "  };\n" +
+                       "};\n" +
+                       "\n" +
+                       "\n" +
+                       "\n";
+               
+        assertOutWithMetadata(outTemplate.replaceAll("AppName", appName));
+    }
 
 }

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/6541ded7/compiler.jx.tests/src/org/apache/flex/compiler/internal/test/FlexJSTestBase.java
----------------------------------------------------------------------
diff --git 
a/compiler.jx.tests/src/org/apache/flex/compiler/internal/test/FlexJSTestBase.java
 
b/compiler.jx.tests/src/org/apache/flex/compiler/internal/test/FlexJSTestBase.java
index 0caa8a9..e1c5056 100644
--- 
a/compiler.jx.tests/src/org/apache/flex/compiler/internal/test/FlexJSTestBase.java
+++ 
b/compiler.jx.tests/src/org/apache/flex/compiler/internal/test/FlexJSTestBase.java
@@ -98,6 +98,7 @@ public class FlexJSTestBase extends TestBase
     // Node "factory"
     
//--------------------------------------------------------------------------
 
+    public static final int WRAP_LEVEL_NONE = 0;
     public static final int WRAP_LEVEL_DOCUMENT = 1;
 
     protected IMXMLNode getNode(String code, Class<? extends IMXMLNode> type,

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/6541ded7/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSEmitter.java
----------------------------------------------------------------------
diff --git 
a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSEmitter.java
 
b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSEmitter.java
index dd89f6b..a3dfac8 100644
--- 
a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSEmitter.java
+++ 
b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSEmitter.java
@@ -65,6 +65,7 @@ import org.apache.flex.compiler.tree.ASTNodeID;
 import org.apache.flex.compiler.tree.as.IASNode;
 import org.apache.flex.compiler.tree.as.IExpressionNode;
 import org.apache.flex.compiler.tree.as.IFunctionNode;
+import org.apache.flex.compiler.tree.as.IIdentifierNode;
 import org.apache.flex.compiler.tree.as.IImportNode;
 import org.apache.flex.compiler.tree.as.IVariableNode;
 import org.apache.flex.compiler.tree.metadata.IMetaTagNode;
@@ -78,6 +79,7 @@ import 
org.apache.flex.compiler.tree.mxml.IMXMLDeclarationsNode;
 import org.apache.flex.compiler.tree.mxml.IMXMLDocumentNode;
 import org.apache.flex.compiler.tree.mxml.IMXMLEventSpecifierNode;
 import org.apache.flex.compiler.tree.mxml.IMXMLFactoryNode;
+import org.apache.flex.compiler.tree.mxml.IMXMLImplementsNode;
 import org.apache.flex.compiler.tree.mxml.IMXMLInstanceNode;
 import org.apache.flex.compiler.tree.mxml.IMXMLLiteralNode;
 import org.apache.flex.compiler.tree.mxml.IMXMLMetadataNode;
@@ -130,6 +132,7 @@ public class MXMLFlexJSEmitter extends MXMLEmitter 
implements
     
     private StringBuilder subDocuments = new StringBuilder();
     private ArrayList<String> subDocumentNames = new ArrayList<String>();
+    private String interfaceList;
     
     /**
      * This keeps track of the entries in our temporary array of 
@@ -497,7 +500,14 @@ public class MXMLFlexJSEmitter extends MXMLEmitter 
implements
         write(cdef.getBaseName());
         write("', qName: '");
         write(formatQualifiedName(cname));
-        write("' }] };");
+        write("' }]");
+        if (interfaceList != null)
+        {
+               write(", interfaces: [");
+               write(interfaceList);
+               write("]");
+        }
+        write(" };");
         
            writeNewline();
            writeNewline();
@@ -2008,6 +2018,15 @@ public class MXMLFlexJSEmitter extends MXMLEmitter 
implements
                 .getCompilationUnitForDefinition(cdef);
         ArrayList<String> deps = project.getRequires(cu);
 
+        if (interfaceList != null)
+        {
+               String[] interfaces = interfaceList.split(", ");
+               for (String iface : interfaces)
+               {
+                       deps.add(iface);
+                       usedNames.add(iface);
+               }
+        }
         if (deps != null)
         {
                Collections.sort(deps);
@@ -2213,4 +2232,21 @@ public class MXMLFlexJSEmitter extends MXMLEmitter 
implements
                }
        }
     }
+    
+    @Override
+    public void emitImplements(IMXMLImplementsNode node)
+    {
+       StringBuilder list = new StringBuilder();
+       boolean needsComma = false;
+        IIdentifierNode[] interfaces = node.getInterfaceNodes();
+        for (IIdentifierNode iface : interfaces)
+        {
+               if (needsComma)
+                       list.append(", ");
+               list.append(iface.getName());
+               needsComma = true;
+        }
+        interfaceList = list.toString();
+    }
+    
 }

Reply via email to