flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From erikdebr...@apache.org
Subject svn commit: r1435816 - in /flex/falcon/trunk: compiler.jx.tests/src/org/apache/flex/compiler/internal/js/codegen/goog/ compiler.jx/src/org/apache/flex/compiler/internal/js/codegen/ compiler.jx/src/org/apache/flex/compiler/internal/js/codegen/goog/ comp...
Date Sun, 20 Jan 2013 11:11:18 GMT
Author: erikdebruin
Date: Sun Jan 20 11:11:18 2013
New Revision: 1435816

URL: http://svn.apache.org/viewvc?rev=1435816&view=rev
Log:
- implemented Interface support and testing

Modified:
    flex/falcon/trunk/compiler.jx.tests/src/org/apache/flex/compiler/internal/js/codegen/goog/TestGoogInterface.java
    flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/js/codegen/JSEmitter.java
    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/js/codegen/goog/TestGoogInterface.java
URL: http://svn.apache.org/viewvc/flex/falcon/trunk/compiler.jx.tests/src/org/apache/flex/compiler/internal/js/codegen/goog/TestGoogInterface.java?rev=1435816&r1=1435815&r2=1435816&view=diff
==============================================================================
--- flex/falcon/trunk/compiler.jx.tests/src/org/apache/flex/compiler/internal/js/codegen/goog/TestGoogInterface.java
(original)
+++ flex/falcon/trunk/compiler.jx.tests/src/org/apache/flex/compiler/internal/js/codegen/goog/TestGoogInterface.java
Sun Jan 20 11:11:18 2013
@@ -23,7 +23,6 @@ import org.apache.flex.compiler.clients.
 import org.apache.flex.compiler.internal.as.codegen.TestInterface;
 import org.apache.flex.compiler.internal.js.driver.goog.GoogBackend;
 import org.apache.flex.compiler.tree.as.IInterfaceNode;
-import org.junit.Ignore;
 import org.junit.Test;
 
 /**
@@ -34,49 +33,42 @@ import org.junit.Test;
  */
 public class TestGoogInterface extends TestInterface
 {
-    // TODO (erikdebruin) test interfaces
-	
-	@Ignore
 	@Override
     @Test
     public void testSimple()
     {
         IInterfaceNode node = getInterfaceNode("public interface IA{}");
         visitor.visitInterface(node);
-        assertOut("");
+        assertOut("/**\n * @interface\n */\npublic interface IA {\n}");
     }
 
-	@Ignore
 	@Override
     @Test
     public void testSimpleExtends()
     {
         IInterfaceNode node = getInterfaceNode("public interface IA extends IB{}");
         visitor.visitInterface(node);
-        assertOut("");
+        assertOut("/**\n * @interface\n * @extends {IB}\n */\npublic interface IA {\n}");
     }
 
-	@Ignore
 	@Override
     @Test
     public void testSimpleExtendsMultiple()
     {
         IInterfaceNode node = getInterfaceNode("public interface IA extends IB, IC, ID {}");
         visitor.visitInterface(node);
-        assertOut("");
+        assertOut("/**\n * @interface\n * @extends {IB}\n * @extends {IC}\n * @extends {ID}\n
*/\npublic interface IA {\n}");
     }
 
-	@Ignore
 	@Override
     @Test
     public void testQualifiedExtendsMultiple()
     {
         IInterfaceNode node = getInterfaceNode("public interface IA extends foo.bar.IB, baz.goo.IC,
foo.ID {}");
         visitor.visitInterface(node);
-        assertOut("");
+        assertOut("/**\n * @interface\n * @extends {foo.bar.IB}\n * @extends {baz.goo.IC}\n
* @extends {foo.ID}\n */\npublic interface IA {\n}");
     }
 
-	@Ignore
 	@Override
     @Test
     public void testAccessors()
@@ -85,22 +77,20 @@ public class TestGoogInterface extends T
                 + "function get foo1():Object;"
                 + "function set foo1(value:Object):void;}");
         visitor.visitInterface(node);
-        assertOut("");
+        assertOut("/**\n * @interface\n */\npublic interface IA {\n}\nIA.prototype.foo1;");
     }
 
-	@Ignore
 	@Override
     @Test
     public void testMethods()
     {
         IInterfaceNode node = getInterfaceNode("public interface IA {"
-                + "function foo1():Object;"
-                + "function foo1(value:Object):void;}");
+                + "function baz1():Object;"
+                + "function baz2(value:Object):void;}");
         visitor.visitInterface(node);
-        assertOut("");
+        assertOut("/**\n * @interface\n */\npublic interface IA {\n}\nIA.prototype.baz1 =
function();\nIA.prototype.baz2 = function(value);");
     }
 
-	@Ignore
 	@Override
     @Test
     public void testAccessorsMethods()
@@ -111,7 +101,7 @@ public class TestGoogInterface extends T
                 + "function baz1():Object;"
                 + "function baz2(value:Object):void;}");
         visitor.visitInterface(node);
-        assertOut("");
+        assertOut("/**\n * @interface\n */\npublic interface IA {\n}\nIA.prototype.foo1;\nIA.prototype.baz1
= function();\nIA.prototype.baz2 = function(value);");
     }
 
     protected IBackend createBackend()

Modified: flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/js/codegen/JSEmitter.java
URL: http://svn.apache.org/viewvc/flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/js/codegen/JSEmitter.java?rev=1435816&r1=1435815&r2=1435816&view=diff
==============================================================================
--- flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/js/codegen/JSEmitter.java
(original)
+++ flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/js/codegen/JSEmitter.java
Sun Jan 20 11:11:18 2013
@@ -37,6 +37,7 @@ public class JSEmitter extends ASEmitter
     public static final String CONFIGURABLE = "configurable";
     public static final String CONSTRUCTOR = "constructor";
     public static final String DEFINE_PROPERTY = "defineProperty";
+    public static final String INTERFACE = "interface";
     public static final String PROTOTYPE = "prototype";
     public static final String SLICE = "slice";
 

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=1435816&r1=1435815&r2=1435816&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
Sun Jan 20 11:11:18 2013
@@ -36,6 +36,7 @@ import org.apache.flex.compiler.tree.as.
 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.IInterfaceNode;
 import org.apache.flex.compiler.tree.as.IPackageNode;
 import org.apache.flex.compiler.tree.as.IParameterNode;
 import org.apache.flex.compiler.tree.as.IVariableNode;
@@ -53,29 +54,45 @@ public class JSGoogDocEmitter extends JS
     }
     
     @Override
-    public void emitFieldDoc(IVariableNode node)
+    public void emitInterfaceDoc(IInterfaceNode node)
     {
         begin();
         
-        String ns = node.getNamespace();
-        if (ns == IASKeywordConstants.PRIVATE)
+        emitJSDocLine(JSGoogEmitter.INTERFACE); 
+        
+        String[] inodes = node.getExtendedInterfaces();
+        for (String inode : inodes)
         {
-        	emitPrivate(node);
+            emitJSDocLine(IASKeywordConstants.EXTENDS, inode);
         }
-        else if (ns == IASKeywordConstants.PROTECTED)
-        {	
-        	emitProtected(node);
-        }
-        
-        if (node.isConst())
-        	emitConst(node);
-        
-        emitType(node);
         
         end();
     }
     
     @Override
+    public void emitFieldDoc(IVariableNode node)
+    {
+    	begin();
+    	
+    	String ns = node.getNamespace();
+    	if (ns == IASKeywordConstants.PRIVATE)
+    	{
+    		emitPrivate(node);
+    	}
+    	else if (ns == IASKeywordConstants.PROTECTED)
+    	{	
+    		emitProtected(node);
+    	}
+    	
+    	if (node.isConst())
+    		emitConst(node);
+    	
+    	emitType(node);
+    	
+    	end();
+    }
+    
+    @Override
     public void emitMethodDoc(IFunctionNode node, ICompilerProject project)
     {
         IClassNode cnode = (IClassNode) node.getAncestorOfType(IClassNode.class);

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=1435816&r1=1435815&r2=1435816&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
Sun Jan 20 11:11:18 2013
@@ -51,6 +51,7 @@ import org.apache.flex.compiler.tree.as.
 import org.apache.flex.compiler.tree.as.IFunctionNode;
 import org.apache.flex.compiler.tree.as.IGetterNode;
 import org.apache.flex.compiler.tree.as.IIdentifierNode;
+import org.apache.flex.compiler.tree.as.IInterfaceNode;
 import org.apache.flex.compiler.tree.as.IPackageNode;
 import org.apache.flex.compiler.tree.as.IParameterNode;
 import org.apache.flex.compiler.tree.as.IScopedNode;
@@ -74,6 +75,12 @@ public class JSGoogEmitter extends JSEmi
     public static final String GOOG_PROVIDE = "goog.provide";
     public static final String GOOG_REQUIRE = "goog.require";
 
+    // TODO (erikdebruin) I needed some state to remember if an accessor is
+    //                    accompanied by it's counterpart, as 'goog' likes having
+    //                    a property with a type declaration to go with them. We
+    //                    only want one declaration per property, so we need to
+    //                    know if we visited the complementary instance already...
+    //                    Q for (mschmalle): do we need to reset this at some point? 
     private List<String> propertyNames = new ArrayList<String>();
     
     IJSGoogDocEmitter getDoc()
@@ -201,6 +208,60 @@ public class JSGoogEmitter extends JSEmi
     }
     
     @Override
+    public void emitInterface(IInterfaceNode node)
+    {
+    	getDoc().emitInterfaceDoc(node);
+
+    	write(node.getNamespace());
+        write(SPACE);
+
+        writeToken(IASKeywordConstants.INTERFACE);
+        write(SPACE);
+        getWalker().walk(node.getNameExpressionNode());
+        write(SPACE);
+
+        write(CURLYBRACE_OPEN);
+        writeNewline();
+        write(CURLYBRACE_CLOSE);
+
+        final IDefinitionNode[] members = node.getAllMemberDefinitionNodes();
+    	for (IDefinitionNode mnode : members)
+    	{
+    		boolean isAccessor = mnode.getNodeID() == ASTNodeID.GetterID ||
+    			mnode.getNodeID() == ASTNodeID.SetterID;
+        	
+			String qname = node.getQualifiedName();
+
+			if (!isAccessor || !propertyNames.contains(qname))
+	    	{
+	    		writeNewline();
+	
+	    		emitMemberName(node);
+				write(PERIOD);
+				write(PROTOTYPE);
+				write(PERIOD);
+				write(mnode.getQualifiedName());
+				
+				if (isAccessor && !propertyNames.contains(qname))
+				{
+					propertyNames.add(qname);
+		    	}
+		    	else
+				{
+		    		write(SPACE);
+		    		write(EQUALS);
+		    		write(SPACE);
+		    		write(FUNCTION);
+	
+		    		emitParamters(((IFunctionNode) mnode).getParameterNodes());
+				}
+    		
+				write(SEMICOLON);
+	    	}
+    	}
+    }
+
+    @Override
     public void emitField(IVariableNode node)
     {
         IClassDefinition definition = getClassDefinition(node);
@@ -298,14 +359,15 @@ public class JSGoogEmitter extends JSEmi
     
     private void emitAccessors(IAccessorNode node)
     {
-    	if (!propertyNames.contains(node.getName()))
+    	String qname = node.getQualifiedName();
+    	if (!propertyNames.contains(qname))
     	{
     		emitField(node);
             write(SEMICOLON);
             writeNewline();
             writeNewline();
             
-    		propertyNames.add(node.getName());
+    		propertyNames.add(qname);
     	}
     	
     	if (node.getNodeID() == ASTNodeID.GetterID)

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=1435816&r1=1435815&r2=1435816&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
Sun Jan 20 11:11:18 2013
@@ -26,6 +26,7 @@ import org.apache.flex.compiler.projects
 import org.apache.flex.compiler.tree.as.IASNode;
 import org.apache.flex.compiler.tree.as.IClassNode;
 import org.apache.flex.compiler.tree.as.IFunctionNode;
+import org.apache.flex.compiler.tree.as.IInterfaceNode;
 import org.apache.flex.compiler.tree.as.IParameterNode;
 import org.apache.flex.compiler.tree.as.IVariableNode;
 
@@ -48,6 +49,8 @@ import org.apache.flex.compiler.tree.as.
 public interface IJSGoogDocEmitter extends IJSDocEmitter
 {
 	
+    void emitInterfaceDoc(IInterfaceNode node);
+
     void emitFieldDoc(IVariableNode node);
 
     void emitMethodDoc(IFunctionNode node, ICompilerProject project);



Mime
View raw message