flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From erikdebr...@apache.org
Subject svn commit: r1435071 - in /flex/falcon/trunk: compiler.jx.tests/src/org/apache/flex/compiler/internal/as/codegen/ compiler.jx.tests/src/org/apache/flex/compiler/internal/js/codegen/goog/ compiler.jx.tests/test-files/ compiler.jx/src/org/apache/flex/com...
Date Fri, 18 Jan 2013 10:30:18 GMT
Author: erikdebruin
Date: Fri Jan 18 10:30:17 2013
New Revision: 1435071

URL: http://svn.apache.org/viewvc?rev=1435071&view=rev
Log:
- implemented correct JSDoc annotation for 'implements': now emits fully qualified class name
- added two tests to 'TestGoogAccessorMembers' to test with and without function body
- fixed minor issue with reading external files for testing in 'TestBase'
- implemented accessor handling in 'emitClass'
    - added a 'hack' to allow me to emit an extra field declaration for each property so I
can tell the Closure Compiler about the type of the property...

Modified:
    flex/falcon/trunk/compiler.jx.tests/src/org/apache/flex/compiler/internal/as/codegen/TestBase.java
    flex/falcon/trunk/compiler.jx.tests/src/org/apache/flex/compiler/internal/js/codegen/goog/TestGoogAccessorMembers.java
    flex/falcon/trunk/compiler.jx.tests/src/org/apache/flex/compiler/internal/js/codegen/goog/TestGoogClass.java
    flex/falcon/trunk/compiler.jx.tests/src/org/apache/flex/compiler/internal/js/codegen/goog/TestGoogFile.java
    flex/falcon/trunk/compiler.jx.tests/test-files/output.js
    flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/js/codegen/goog/JSGoogDocEmitter.java
    flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/js/codegen/goog/JSGoogEmitter.java
    flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/js/codegen/goog/IJSGoogDocEmitter.java

Modified: flex/falcon/trunk/compiler.jx.tests/src/org/apache/flex/compiler/internal/as/codegen/TestBase.java
URL: http://svn.apache.org/viewvc/flex/falcon/trunk/compiler.jx.tests/src/org/apache/flex/compiler/internal/as/codegen/TestBase.java?rev=1435071&r1=1435070&r2=1435071&view=diff
==============================================================================
--- flex/falcon/trunk/compiler.jx.tests/src/org/apache/flex/compiler/internal/as/codegen/TestBase.java
(original)
+++ flex/falcon/trunk/compiler.jx.tests/src/org/apache/flex/compiler/internal/as/codegen/TestBase.java
Fri Jan 18 10:30:17 2013
@@ -127,7 +127,7 @@ public class TestBase
             }
             else
             {
-            	code = getCodeFromFile("input", false);
+            	code = getCodeFromFile(input, false);
             }
             
             BufferedWriter out = new BufferedWriter(new FileWriter(tempASFile));

Modified: flex/falcon/trunk/compiler.jx.tests/src/org/apache/flex/compiler/internal/js/codegen/goog/TestGoogAccessorMembers.java
URL: http://svn.apache.org/viewvc/flex/falcon/trunk/compiler.jx.tests/src/org/apache/flex/compiler/internal/js/codegen/goog/TestGoogAccessorMembers.java?rev=1435071&r1=1435070&r2=1435071&view=diff
==============================================================================
--- flex/falcon/trunk/compiler.jx.tests/src/org/apache/flex/compiler/internal/js/codegen/goog/TestGoogAccessorMembers.java
(original)
+++ flex/falcon/trunk/compiler.jx.tests/src/org/apache/flex/compiler/internal/js/codegen/goog/TestGoogAccessorMembers.java
Fri Jan 18 10:30:17 2013
@@ -44,16 +44,15 @@ public class TestGoogAccessorMembers ext
     @Test
     public void testGetAccessor()
     {
-        /*
-        Object.defineProperty(
-            A.prototype, 
-            'foo', 
-            {get:function() {
-                return -1;
-            }, configurable:true}
-        )
-         */
-    	// TODO (erikdebruin) add 'goog' type declaration
+        IGetterNode node = (IGetterNode) getAccessor("function get foo():int{}");
+        visitor.visitGetter(node);
+        assertOut("Object.defineProperty(\n\tA.prototype, \n\t'foo', "
+                + "\n\t{get:function() {\n\t}, configurable:true}\n)");
+    }
+
+    @Test
+    public void testGetAccessor_withBody()
+    {
         IGetterNode node = (IGetterNode) getAccessor("function get foo():int{return -1;}");
         visitor.visitGetter(node);
         assertOut("Object.defineProperty(\n\tA.prototype, \n\t'foo', "
@@ -96,20 +95,21 @@ public class TestGoogAccessorMembers ext
     @Test
     public void testSetAccessor()
     {
-        /*
-        Object.defineProperty(
-            A.prototype, 
-            'foo', 
-            {set:function(value) {
-            }, configurable:true}
-        )
-         */
         ISetterNode node = (ISetterNode) getAccessor("function set foo(value:int):void{}");
         visitor.visitSetter(node);
         assertOut("Object.defineProperty(\n\tA.prototype, \n\t'foo', \n\t{set:function(value)"
                 + " {\n\t}, configurable:true}\n)");
     }
 
+    @Test
+    public void testSetAccessor_withBody()
+    {
+        ISetterNode node = (ISetterNode) getAccessor("function set foo(value:int):void{trace('haai');}");
+        visitor.visitSetter(node);
+        assertOut("Object.defineProperty(\n\tA.prototype, \n\t'foo', "
+                + "\n\t{set:function(value) {\n\t\ttrace('haai');\n\t}, configurable:true}\n)");
+    }
+
     @Override
     @Test
     public void testSetAccessor_withNamespace()

Modified: flex/falcon/trunk/compiler.jx.tests/src/org/apache/flex/compiler/internal/js/codegen/goog/TestGoogClass.java
URL: http://svn.apache.org/viewvc/flex/falcon/trunk/compiler.jx.tests/src/org/apache/flex/compiler/internal/js/codegen/goog/TestGoogClass.java?rev=1435071&r1=1435070&r2=1435071&view=diff
==============================================================================
--- flex/falcon/trunk/compiler.jx.tests/src/org/apache/flex/compiler/internal/js/codegen/goog/TestGoogClass.java
(original)
+++ flex/falcon/trunk/compiler.jx.tests/src/org/apache/flex/compiler/internal/js/codegen/goog/TestGoogClass.java
Fri Jan 18 10:30:17 2013
@@ -95,7 +95,7 @@ public class TestGoogClass extends TestC
     {
         IClassNode node = getClassNode("public class A implements IEventDispatcher {public
function A() {}}");
         visitor.visitClass(node);
-        assertOut("/**\n * @constructor\n * @implements {IEventDispatcher}\n */\norg.apache.flex.A
= function() {\n};");
+        assertOut("/**\n * @constructor\n * @implements {flash.events.IEventDispatcher}\n
*/\norg.apache.flex.A = function() {\n};");
     }
 
 	@Override
@@ -104,7 +104,7 @@ public class TestGoogClass extends TestC
     {
         IClassNode node = getClassNode("public class A implements IEventDispatcher, ILogger
{public function A() {}}");
         visitor.visitClass(node);
-        assertOut("/**\n * @constructor\n * @implements {IEventDispatcher}\n * @implements
{ILogger}\n */\norg.apache.flex.A = function() {\n};");
+        assertOut("/**\n * @constructor\n * @implements {flash.events.IEventDispatcher}\n
* @implements {mx.logging.ILogger}\n */\norg.apache.flex.A = function() {\n};");
     }
 
 	@Override
@@ -113,7 +113,7 @@ public class TestGoogClass extends TestC
     {
         IClassNode node = getClassNode("public class A extends Button implements IEventDispatcher
{public function A() {}}");
         visitor.visitClass(node);
-        assertOut("/**\n * @constructor\n * @extends {spark.components.Button}\n * @implements
{IEventDispatcher}\n */\norg.apache.flex.A = function() {\n\tgoog.base(this);\n}\ngoog.inherits(org.apache.flex.A,
spark.components.Button);");
+        assertOut("/**\n * @constructor\n * @extends {spark.components.Button}\n * @implements
{flash.events.IEventDispatcher}\n */\norg.apache.flex.A = function() {\n\tgoog.base(this);\n}\ngoog.inherits(org.apache.flex.A,
spark.components.Button);");
     }
 
 	@Override
@@ -122,7 +122,7 @@ public class TestGoogClass extends TestC
     {
         IClassNode node = getClassNode("public class A extends Button implements IEventDispatcher,
ILogger {public function A() {}}");
         visitor.visitClass(node);
-        assertOut("/**\n * @constructor\n * @extends {spark.components.Button}\n * @implements
{IEventDispatcher}\n * @implements {ILogger}\n */\norg.apache.flex.A = function() {\n\tgoog.base(this);\n}\ngoog.inherits(org.apache.flex.A,
spark.components.Button);");
+        assertOut("/**\n * @constructor\n * @extends {spark.components.Button}\n * @implements
{flash.events.IEventDispatcher}\n * @implements {mx.logging.ILogger}\n */\norg.apache.flex.A
= function() {\n\tgoog.base(this);\n}\ngoog.inherits(org.apache.flex.A, spark.components.Button);");
     }
 
 	@Override
@@ -132,7 +132,7 @@ public class TestGoogClass extends TestC
 		// TODO (erikdebruin) 'final' keyword: see 'testSimpleFinal' above
         IClassNode node = getClassNode("public final class A extends Button implements IEventDispatcher,
ILogger {public function A() {}}");
         visitor.visitClass(node);
-        assertOut("/**\n * @constructor\n * @extends {spark.components.Button}\n * @implements
{IEventDispatcher}\n * @implements {ILogger}\n */\norg.apache.flex.A = function() {\n\tgoog.base(this);\n}\ngoog.inherits(org.apache.flex.A,
spark.components.Button);");
+        assertOut("/**\n * @constructor\n * @extends {spark.components.Button}\n * @implements
{flash.events.IEventDispatcher}\n * @implements {mx.logging.ILogger}\n */\norg.apache.flex.A
= function() {\n\tgoog.base(this);\n}\ngoog.inherits(org.apache.flex.A, spark.components.Button);");
     }
 
 	@Override
@@ -141,7 +141,7 @@ public class TestGoogClass extends TestC
     {
         IClassNode node = getClassNode("public class A extends spark.components.Button implements
flash.events.IEventDispatcher, mx.logging.ILogger {public function A() {}}");
         visitor.visitClass(node);
-        assertOut("/**\n * @constructor\n * @extends {spark.components.Button}\n * @implements
{IEventDispatcher}\n * @implements {ILogger}\n */\norg.apache.flex.A = function() {\n\tgoog.base(this);\n}\ngoog.inherits(org.apache.flex.A,
spark.components.Button);");
+        assertOut("/**\n * @constructor\n * @extends {spark.components.Button}\n * @implements
{flash.events.IEventDispatcher}\n * @implements {mx.logging.ILogger}\n */\norg.apache.flex.A
= function() {\n\tgoog.base(this);\n}\ngoog.inherits(org.apache.flex.A, spark.components.Button);");
     }
 
 	@Ignore

Modified: flex/falcon/trunk/compiler.jx.tests/src/org/apache/flex/compiler/internal/js/codegen/goog/TestGoogFile.java
URL: http://svn.apache.org/viewvc/flex/falcon/trunk/compiler.jx.tests/src/org/apache/flex/compiler/internal/js/codegen/goog/TestGoogFile.java?rev=1435071&r1=1435070&r2=1435071&view=diff
==============================================================================
--- flex/falcon/trunk/compiler.jx.tests/src/org/apache/flex/compiler/internal/js/codegen/goog/TestGoogFile.java
(original)
+++ flex/falcon/trunk/compiler.jx.tests/src/org/apache/flex/compiler/internal/js/codegen/goog/TestGoogFile.java
Fri Jan 18 10:30:17 2013
@@ -23,6 +23,7 @@ import org.apache.flex.compiler.clients.
 import org.apache.flex.compiler.internal.as.codegen.TestWalkerBase;
 import org.apache.flex.compiler.internal.js.driver.goog.GoogBackend;
 import org.apache.flex.compiler.tree.as.IFileNode;
+import org.junit.Ignore;
 import org.junit.Test;
 
 /**
@@ -33,13 +34,22 @@ import org.junit.Test;
 public class TestGoogFile extends TestWalkerBase
 {
     @Test
-    public void testFile_1()
+    public void testFile_plain()
     {
         IFileNode node = getFileNode("input", true);
         visitor.visitFile(node);
         assertOut(getCodeFromFile("output", true));
     }
 
+	@Ignore
+    @Test
+    public void testFile_getset()
+    {
+        IFileNode node = getFileNode("get-set", true);
+        visitor.visitFile(node);
+        assertOut(getCodeFromFile("get-set_result", true));
+    }
+
     @Override
     protected IBackend createBackend()
     {

Modified: flex/falcon/trunk/compiler.jx.tests/test-files/output.js
URL: http://svn.apache.org/viewvc/flex/falcon/trunk/compiler.jx.tests/test-files/output.js?rev=1435071&r1=1435070&r2=1435071&view=diff
==============================================================================
--- flex/falcon/trunk/compiler.jx.tests/test-files/output.js (original)
+++ flex/falcon/trunk/compiler.jx.tests/test-files/output.js Fri Jan 18 10:30:17 2013
@@ -6,7 +6,7 @@ goog.require('spark.components.Button');
 /**
  * @constructor
  * @extends {spark.components.Button}
- * @implements {IEventDispatcher}
+ * @implements {flash.events.IEventDispatcher}
  */
 org.apache.flex.A = function() {
 	goog.base(this);

Modified: flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/js/codegen/goog/JSGoogDocEmitter.java
URL: http://svn.apache.org/viewvc/flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/js/codegen/goog/JSGoogDocEmitter.java?rev=1435071&r1=1435070&r2=1435071&view=diff
==============================================================================
--- flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/js/codegen/goog/JSGoogDocEmitter.java
(original)
+++ flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/js/codegen/goog/JSGoogDocEmitter.java
Fri Jan 18 10:30:17 2013
@@ -24,7 +24,6 @@ import org.apache.flex.compiler.constant
 import org.apache.flex.compiler.constants.IASLanguageConstants;
 import org.apache.flex.compiler.definitions.IClassDefinition;
 import org.apache.flex.compiler.definitions.ITypeDefinition;
-import org.apache.flex.compiler.definitions.references.IReference;
 import org.apache.flex.compiler.internal.as.codegen.ASEmitter;
 import org.apache.flex.compiler.internal.js.codegen.JSDocEmitter;
 import org.apache.flex.compiler.internal.js.codegen.JSSharedData;
@@ -35,6 +34,7 @@ import org.apache.flex.compiler.projects
 import org.apache.flex.compiler.tree.ASTNodeID;
 import org.apache.flex.compiler.tree.as.IASNode;
 import org.apache.flex.compiler.tree.as.IClassNode;
+import org.apache.flex.compiler.tree.as.IExpressionNode;
 import org.apache.flex.compiler.tree.as.IFunctionNode;
 import org.apache.flex.compiler.tree.as.IPackageNode;
 import org.apache.flex.compiler.tree.as.IParameterNode;
@@ -99,12 +99,12 @@ public class JSGoogDocEmitter extends JS
                 if (superClass != null && !qname.equals(IASLanguageConstants.Object))
                     emitExtends(superClass);
                 
-            	IReference[] interfaceReferences = classDefinition.getImplementedInterfaceReferences();
-                if (interfaceReferences.length > 0)
+                IExpressionNode[] inodes = cnode.getImplementedInterfaceNodes();
+                if (inodes.length > 0)
                 {
-                    for (IReference reference : interfaceReferences)
+                    for (IExpressionNode inode : inodes)
                     {
-                    	emitImplements(reference);
+                    	emitImplements(inode.resolveType(project));
                     }
                 }
             }
@@ -215,10 +215,9 @@ public class JSGoogDocEmitter extends JS
     }
 
     @Override
-    public void emitImplements(IReference reference)
+    public void emitImplements(ITypeDefinition definition)
     {
-    	// TODO (erikdebruin) we need to get the fully qualified name...
-        emitJSDocLine(IASKeywordConstants.IMPLEMENTS, reference.getName());
+        emitJSDocLine(IASKeywordConstants.IMPLEMENTS, definition.getQualifiedName());
     }
 
     @Override

Modified: flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/js/codegen/goog/JSGoogEmitter.java
URL: http://svn.apache.org/viewvc/flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/js/codegen/goog/JSGoogEmitter.java?rev=1435071&r1=1435070&r2=1435071&view=diff
==============================================================================
--- flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/js/codegen/goog/JSGoogEmitter.java
(original)
+++ flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/js/codegen/goog/JSGoogEmitter.java
Fri Jan 18 10:30:17 2013
@@ -68,6 +68,8 @@ public class JSGoogEmitter extends JSEmi
     public static final String GOOG_PROVIDE = "goog.provide";
     public static final String GOOG_REQUIRE = "goog.require";
 
+    private List<String> propertyNames = new ArrayList<String>();
+    
     IJSGoogDocEmitter getDoc()
     {
         return (IJSGoogDocEmitter) getDocEmitter();
@@ -161,21 +163,17 @@ public class JSGoogEmitter extends JSEmi
         emitMethod((IFunctionNode) definition.getConstructor().getNode());
         write(SEMICOLON);
 
-        IDefinitionNode[] members = node.getAllMemberNodes();
-        for (IDefinitionNode dnode : members)
+        IDefinitionNode[] dnodes = node.getAllMemberNodes();
+        for (IDefinitionNode dnode : dnodes)
         {
-            if (dnode instanceof IVariableNode)
+            if (dnode.getNodeID() == ASTNodeID.VariableID)
             {
                 writeNewline();
                 writeNewline();
                 emitField((IVariableNode) dnode);
                 write(SEMICOLON);
             }
-        }
-
-        for (IDefinitionNode dnode : members)
-        {
-            if (dnode instanceof IFunctionNode)
+            else if (dnode.getNodeID() == ASTNodeID.FunctionID)
             {
                 if (!((IFunctionNode) dnode).isConstructor())
                 {
@@ -185,89 +183,15 @@ public class JSGoogEmitter extends JSEmi
                     write(SEMICOLON);
                 }
             }
-        }
-
-        /*
-    	write(node.getNamespace());
-        write(" ");
-
-        if (node.hasModifier(ASModifier.FINAL))
-        {
-            write("final");
-            write(" ");
-        }
-        write("class");
-        write(" ");
-        getWalker().walk(node.getNameExpressionNode());
-        write(" ");
-
-        IExpressionNode bnode = node.getBaseClassExpressionNode();
-        if (bnode != null)
-        {
-            write("extends");
-            write(" ");
-            getWalker().walk(bnode);
-            write(" ");
-        }
-
-        IExpressionNode[] inodes = node.getImplementedInterfaceNodes();
-        final int ilen = inodes.length;
-        if (ilen != 0)
-        {
-            write("implements");
-            write(" ");
-            for (int i = 0; i < ilen; i++)
-            {
-            	getWalker().walk(inodes[i]);
-                if (i < ilen - 1)
-                {
-                    write(",");
-                    write(" ");
-                }
-            }
-            write(" ");
-        }
-
-        write("{");
-
-        // fields, methods, namespaces
-        final IDefinitionNode[] members = node.getAllMemberNodes();
-        if (members.length > 0)
-        {
-            indentPush();
-            write("\n");
-
-            final int len = members.length;
-            int i = 0;
-            for (IDefinitionNode mnode : members)
+            else if (dnode.getNodeID() == ASTNodeID.GetterID || 
+            		 dnode.getNodeID() == ASTNodeID.SetterID)
             {
-                getWalker().walk(mnode);
-                if (mnode.getNodeID() == ASTNodeID.VariableID)
-                {
-                    write(";");
-                    if (i < len - 1)
-                        write("\n");
-                }
-                else if (mnode.getNodeID() == ASTNodeID.FunctionID)
-                {
-                    if (i < len - 1)
-                        write("\n");
-                }
-                else if (mnode.getNodeID() == ASTNodeID.GetterID
-                        || mnode.getNodeID() == ASTNodeID.SetterID)
-                {
-                    if (i < len - 1)
-                        write("\n");
-                }
-                i++;
+                writeNewline();
+                writeNewline();
+            	emitAccessors((IAccessorNode) dnode);
+                write(SEMICOLON);
             }
-
-            indentPop();
         }
-
-        write("\n");
-        write("}");
-        */
     }
     
     @Override
@@ -365,6 +289,28 @@ public class JSGoogEmitter extends JSEmi
     {
         emitObjectDefineProperty(node);
     }
+    
+    private void emitAccessors(IAccessorNode node)
+    {
+    	if (!propertyNames.contains(node.getName()))
+    	{
+    		emitField(node);
+            write(SEMICOLON);
+            writeNewline();
+            writeNewline();
+            
+    		propertyNames.add(node.getName());
+    	}
+    	
+    	if (node.getNodeID() == ASTNodeID.GetterID)
+        {
+        	emitGetAccessor((IGetterNode) node);
+        }
+        else if (node.getNodeID() == ASTNodeID.SetterID)
+        {
+        	emitSetAccessor((ISetterNode) node);
+        }
+    }
 
     @Override
     public void emitMethod(IFunctionNode node)
@@ -657,6 +603,7 @@ public class JSGoogEmitter extends JSEmi
             configurable: true}
          );
         */
+    	
         // head
         write(IASLanguageConstants.Object);
         write(PERIOD);
@@ -694,8 +641,11 @@ public class JSGoogEmitter extends JSEmi
         write(FUNCTION);
         emitParamters(node.getParameterNodes());
 
+        // ToDo (erikdebruin/mschmalle) fix 'empty' function body when testing 
+        //                              accessors in the context of an entire
+        //                              class instead of only function definition
         emitMethodScope(node.getScopedNode());
-
+        
         write(COMMA);
         write(SPACE);
         write(CONFIGURABLE);

Modified: flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/js/codegen/goog/IJSGoogDocEmitter.java
URL: http://svn.apache.org/viewvc/flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/js/codegen/goog/IJSGoogDocEmitter.java?rev=1435071&r1=1435070&r2=1435071&view=diff
==============================================================================
--- flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/js/codegen/goog/IJSGoogDocEmitter.java
(original)
+++ flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/js/codegen/goog/IJSGoogDocEmitter.java
Fri Jan 18 10:30:17 2013
@@ -21,7 +21,6 @@ package org.apache.flex.compiler.js.code
 
 import org.apache.flex.compiler.definitions.IClassDefinition;
 import org.apache.flex.compiler.definitions.ITypeDefinition;
-import org.apache.flex.compiler.definitions.references.IReference;
 import org.apache.flex.compiler.js.codegen.IJSDocEmitter;
 import org.apache.flex.compiler.projects.ICompilerProject;
 import org.apache.flex.compiler.tree.as.IASNode;
@@ -119,7 +118,7 @@ public interface IJSGoogDocEmitter exten
 
     void emitExtends(IClassDefinition superDefinition);
 
-    void emitImplements(IReference reference);
+    void emitImplements(ITypeDefinition definition);
 
     void emitInheritDoc(IClassNode node);
 



Mime
View raw message