incubator-flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mschma...@apache.org
Subject svn commit: r1425084 - in /incubator/flex/whiteboard/mschmalle/falconjx: compiler.jx.tests/src/org/apache/flex/js/internal/driver/TestClass.java compiler.jx/src/org/apache/flex/compiler/internal/js/codgen/ASBlockWalker.java
Date Fri, 21 Dec 2012 18:54:14 GMT
Author: mschmalle
Date: Fri Dec 21 18:54:14 2012
New Revision: 1425084

URL: http://svn.apache.org/viewvc?rev=1425084&view=rev
Log:
Flex:FalconJx
- Class production implemented, final, extends and implements simple and qualified names

Modified:
    incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/js/internal/driver/TestClass.java
    incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/js/codgen/ASBlockWalker.java

Modified: incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/js/internal/driver/TestClass.java
URL: http://svn.apache.org/viewvc/incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/js/internal/driver/TestClass.java?rev=1425084&r1=1425083&r2=1425084&view=diff
==============================================================================
--- incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/js/internal/driver/TestClass.java
(original)
+++ incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/js/internal/driver/TestClass.java
Fri Dec 21 18:54:14 2012
@@ -19,6 +19,8 @@
 
 package org.apache.flex.js.internal.driver;
 
+import org.apache.flex.compiler.tree.as.IClassNode;
+import org.apache.flex.compiler.tree.as.IFileNode;
 import org.junit.Test;
 
 /**
@@ -34,8 +36,91 @@ public class TestClass extends TestWalke
     //--------------------------------------------------------------------------
 
     @Test
-    public void testGetAccessor()
+    public void testSimple()
     {
+        IClassNode node = getClassNode("public class A{}");
+        visitor.visitClass(node);
+        assertOut("public class A {\n}");
+    }
+
+    @Test
+    public void testSimpleInternal()
+    {
+        IClassNode node = getClassNode("internal class A{}");
+        visitor.visitClass(node);
+        assertOut("internal class A {\n}");
+    }
+    
+    @Test
+    public void testSimpleFinal()
+    {
+        IClassNode node = getClassNode("public final class A{}");
+        visitor.visitClass(node);
+        assertOut("public final class A {\n}");
+    }
+
+    @Test
+    public void testSimpleExtends()
+    {
+        IClassNode node = getClassNode("public class A extends B {}");
+        visitor.visitClass(node);
+        assertOut("public class A extends B {\n}");
+    }
+
+    @Test
+    public void testSimpleImplements()
+    {
+        IClassNode node = getClassNode("public class A implements IA {}");
+        visitor.visitClass(node);
+        assertOut("public class A implements IA {\n}");
+    }
+
+    @Test
+    public void testSimpleImplementsMultiple()
+    {
+        IClassNode node = getClassNode("public class A implements IA, IB, IC {}");
+        visitor.visitClass(node);
+        assertOut("public class A implements IA, IB, IC {\n}");
+    }
+
+    @Test
+    public void testSimpleExtendsImplements()
+    {
+        IClassNode node = getClassNode("public class A extends B implements IA {}");
+        visitor.visitClass(node);
+        assertOut("public class A extends B implements IA {\n}");
+    }
+
+    @Test
+    public void testSimpleExtendsImplementsMultiple()
+    {
+        IClassNode node = getClassNode("public class A extends B implements IA, IB, IC {}");
+        visitor.visitClass(node);
+        assertOut("public class A extends B implements IA, IB, IC {\n}");
+    }
+
+    @Test
+    public void testSimpleFinalExtendsImplementsMultiple()
+    {
+        IClassNode node = getClassNode("public final class A extends B implements IA, IB,
IC {}");
+        visitor.visitClass(node);
+        assertOut("public final class A extends B implements IA, IB, IC {\n}");
+    }
 
+    @Test
+    public void testQualifiedExtendsImplementsMultiple()
+    {
+        IClassNode node = getClassNode("public class A extends goo.B implements foo.bar.IA,
goo.foo.IB, baz.boo.IC {}");
+        visitor.visitClass(node);
+        assertOut("public class A extends goo.B implements foo.bar.IA, goo.foo.IB, baz.boo.IC
{\n}");
+    }
+    
+    protected IClassNode getClassNode(String code)
+    {
+        String source = "package {" + code + "}";
+        IFileNode node = getFileNode(source);
+        IClassNode child = (IClassNode) findFirstDescendantOfType(node,
+                IClassNode.class);
+        return child;
     }
 }

Modified: incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/js/codgen/ASBlockWalker.java
URL: http://svn.apache.org/viewvc/incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/js/codgen/ASBlockWalker.java?rev=1425084&r1=1425083&r2=1425084&view=diff
==============================================================================
--- incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/js/codgen/ASBlockWalker.java
(original)
+++ incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/js/codgen/ASBlockWalker.java
Fri Dec 21 18:54:14 2012
@@ -24,6 +24,7 @@ import java.util.List;
 import java.util.Stack;
 
 import org.apache.flex.compiler.as.IASEmitter;
+import org.apache.flex.compiler.common.ASModifier;
 import org.apache.flex.compiler.definitions.IClassDefinition;
 import org.apache.flex.compiler.definitions.IInterfaceDefinition;
 import org.apache.flex.compiler.definitions.ITypeDefinition;
@@ -39,7 +40,6 @@ import org.apache.flex.compiler.problems
 import org.apache.flex.compiler.projects.IASProject;
 import org.apache.flex.compiler.tree.ASTNodeID;
 import org.apache.flex.compiler.tree.as.IASNode;
-import org.apache.flex.compiler.tree.as.IAccessorNode;
 import org.apache.flex.compiler.tree.as.IBinaryOperatorNode;
 import org.apache.flex.compiler.tree.as.IBlockNode;
 import org.apache.flex.compiler.tree.as.ICatchNode;
@@ -259,14 +259,17 @@ public class ASBlockWalker implements IA
     {
         debug("visitPackage()");
         emitter.write("package");
+
         String name = node.getQualifiedName();
         if (name != null && !name.equals(""))
         {
             emitter.write(" ");
-            emitter.write(name);
+            walk(node.getNameExpressionNode());
         }
+
         emitter.write(" ");
         emitter.write("{");
+
         ITypeNode tnode = findTypeNode(node);
         if (tnode != null)
         {
@@ -274,6 +277,7 @@ public class ASBlockWalker implements IA
             emitter.write("\n");
             walk(tnode); // IClassNode | IInterfaceNode
         }
+
         emitter.indentPop();
         emitter.write("\n");
         emitter.write("}");
@@ -286,16 +290,47 @@ public class ASBlockWalker implements IA
 
         debug("visitClass()");
 
-        emitter.write("public");
+        emitter.write(node.getNamespace());
         emitter.write(" ");
+
+        if (node.hasModifier(ASModifier.FINAL))
+        {
+            emitter.write("final");
+            emitter.write(" ");
+        }
         emitter.write("class");
         emitter.write(" ");
-        emitter.write(typeDefinition.getBaseName());
+        walk(node.getNameExpressionNode());
         emitter.write(" ");
-        emitter.write("{");
 
-        //        emitter.emitProvide(typeDefinition);
-        //        emitter.emitRequire(typeDefinition);
+        IExpressionNode bnode = node.getBaseClassExpressionNode();
+        if (bnode != null)
+        {
+            emitter.write("extends");
+            emitter.write(" ");
+            walk(bnode);
+            emitter.write(" ");
+        }
+
+        IExpressionNode[] inodes = node.getImplementedInterfaceNodes();
+        final int ilen = inodes.length;
+        if (ilen != 0)
+        {
+            emitter.write("implements");
+            emitter.write(" ");
+            for (int i = 0; i < ilen; i++)
+            {
+                walk(inodes[i]);
+                if (i < ilen - 1)
+                {
+                    emitter.write(",");
+                    emitter.write(" ");
+                }
+            }
+            emitter.write(" ");
+        }
+
+        emitter.write("{");
 
         // fields, methods, namespaces
         final IDefinitionNode[] members = node.getAllMemberNodes();
@@ -303,18 +338,19 @@ public class ASBlockWalker implements IA
         {
             emitter.indentPush();
             emitter.write("\n");
-
+            
+            // there is always an implicit constructor if not explicit
             currentConstructor = getConstructor(members);
             if (currentConstructor == null)
             {
                 // TODO (mschmalle) handle null constructor
             }
-
-            //        emitter.emitConstructor(currentConstructor);
-            //        emitter.emitInherits(typeDefinition, project);
-
-            emitFields(members);
-            emitMethods(members);
+            
+            // TODO (mschmalle) Check to see if the node order is the order of member parsed
+            for (IDefinitionNode mnode : members)
+            {
+                walk(mnode);
+            }
 
             emitter.indentPop();
         }
@@ -1080,33 +1116,6 @@ public class ASBlockWalker implements IA
     // 
     //--------------------------------------------------------------------------
 
-    protected void emitFields(IDefinitionNode[] members)
-    {
-        for (IDefinitionNode node : members)
-        {
-            if (node instanceof IVariableNode
-                    && !(node instanceof IAccessorNode))
-            {
-                walk(node);
-            }
-        }
-    }
-
-    protected void emitMethods(IDefinitionNode[] members)
-    {
-        for (IDefinitionNode node : members)
-        {
-            if (node instanceof IFunctionNode)
-            {
-                IFunctionNode fnode = (IFunctionNode) node;
-                if (!fnode.isConstructor())
-                    walk(node);
-                else
-                    visitConstructor(fnode);
-            }
-        }
-    }
-
     protected IFunctionNode getConstructor(IDefinitionNode[] members)
     {
         for (IDefinitionNode node : members)



Mime
View raw message