incubator-flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mschma...@apache.org
Subject svn commit: r1423235 - in /incubator/flex/whiteboard/mschmalle/falconjx: compiler.jx.tests/src/org/apache/flex/js/internal/driver/ compiler.jx/src/org/apache/flex/as/ compiler.jx/src/org/apache/flex/compiler/internal/as/codegen/
Date Tue, 18 Dec 2012 00:36:09 GMT
Author: mschmalle
Date: Tue Dec 18 00:36:08 2012
New Revision: 1423235

URL: http://svn.apache.org/viewvc?rev=1423235&view=rev
Log:
Flex:FalconJx
- Added TestAccessorMembers tests
- Added get/set accessors to the ASEmitter

Added:
    incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/js/internal/driver/TestAccessorMembers.java
  (with props)
Modified:
    incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/as/IASEmitter.java
    incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/as/codegen/ASEmitter.java

Added: incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/js/internal/driver/TestAccessorMembers.java
URL: http://svn.apache.org/viewvc/incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/js/internal/driver/TestAccessorMembers.java?rev=1423235&view=auto
==============================================================================
--- incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/js/internal/driver/TestAccessorMembers.java
(added)
+++ incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/js/internal/driver/TestAccessorMembers.java
Tue Dec 18 00:36:08 2012
@@ -0,0 +1,79 @@
+/*
+ *
+ *  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.js.internal.driver;
+
+import org.apache.flex.compiler.tree.as.IAccessorNode;
+import org.apache.flex.compiler.tree.as.IFileNode;
+import org.apache.flex.compiler.tree.as.IFunctionNode;
+import org.junit.Test;
+
+/**
+ * This class tests the production of valid ActionScript3 code for Class
+ * Accessor members.
+ * 
+ * @author Michael Schmalle
+ */
+public class TestAccessorMembers extends TestWalkerBase
+{
+    //--------------------------------------------------------------------------
+    // Accessor
+    //--------------------------------------------------------------------------
+
+    @Test
+    public void testGetAccessor()
+    {
+        IFunctionNode node = getAccessor("function get foo():int{return -1;}");
+        visitor.visitFunction(node);
+        assertOut("function get foo():int {\n\treturn -1;\n}");
+    }
+
+    @Test
+    public void testGetAccessor_withNamespace()
+    {
+        IFunctionNode node = getAccessor("public function get foo():int{return -1;}");
+        visitor.visitFunction(node);
+        assertOut("public function get foo():int {\n\treturn -1;\n}");
+    }
+
+    @Test
+    public void testSetAccessor()
+    {
+        IFunctionNode node = getAccessor("function set foo(value:int):void{}");
+        visitor.visitFunction(node);
+        assertOut("function set foo(value:int):void {\n}");
+    }
+
+    @Test
+    public void testSetAccessor_withNamespace()
+    {
+        IFunctionNode node = getAccessor("public function set foo(value:int):void{}");
+        visitor.visitFunction(node);
+        assertOut("public function set foo(value:int):void {\n}");
+    }
+
+    protected IAccessorNode getAccessor(String code)
+    {
+        String source = "package {public class A {" + code + "}}";
+        IFileNode node = getFileNode(source);
+        IAccessorNode child = (IAccessorNode) findFirstDescendantOfType(node,
+                IAccessorNode.class);
+        return child;
+    }
+}

Propchange: incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/js/internal/driver/TestAccessorMembers.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/as/IASEmitter.java
URL: http://svn.apache.org/viewvc/incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/as/IASEmitter.java?rev=1423235&r1=1423234&r2=1423235&view=diff
==============================================================================
--- incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/as/IASEmitter.java
(original)
+++ incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/as/IASEmitter.java
Tue Dec 18 00:36:08 2012
@@ -22,6 +22,8 @@ package org.apache.flex.as;
 import java.io.Writer;
 
 import org.apache.flex.compiler.tree.as.IFunctionNode;
+import org.apache.flex.compiler.tree.as.IGetterNode;
+import org.apache.flex.compiler.tree.as.ISetterNode;
 import org.apache.flex.compiler.tree.as.IVariableNode;
 import org.apache.flex.compiler.visitor.IASNodeStrategy;
 
@@ -80,4 +82,32 @@ public interface IASEmitter
      * @param node The {@link IFunctionNode} class method member.
      */
     void emitMethod(IFunctionNode node);
+
+    /**
+     * Emit a documentation comment for a Class method {@link IGetterNode}.
+     * 
+     * @param node The {@link IGetterNode} class accessor member.
+     */
+    void emitGetAccessorDocumentation(IGetterNode node);
+
+    /**
+     * Emit a full Class getter member.
+     * 
+     * @param node The {@link IVariableNode} class getter member.
+     */
+    void emitGetAccessor(IGetterNode node);
+
+    /**
+     * Emit a documentation comment for a Class accessor {@link IGetterNode}.
+     * 
+     * @param node The {@link ISetterNode} class accessor member.
+     */
+    void emitSetAccessorDocumentation(ISetterNode node);
+
+    /**
+     * Emit a full Class setter member.
+     * 
+     * @param node The {@link ISetterNode} class setter member.
+     */
+    void emitSetAccessor(ISetterNode node);
 }

Modified: incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/as/codegen/ASEmitter.java
URL: http://svn.apache.org/viewvc/incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/as/codegen/ASEmitter.java?rev=1423235&r1=1423234&r2=1423235&view=diff
==============================================================================
--- incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/as/codegen/ASEmitter.java
(original)
+++ incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/as/codegen/ASEmitter.java
Tue Dec 18 00:36:08 2012
@@ -32,11 +32,15 @@ import org.apache.flex.compiler.definiti
 import org.apache.flex.compiler.definitions.references.INamespaceReference;
 import org.apache.flex.compiler.internal.tree.as.FunctionNode;
 import org.apache.flex.compiler.problems.ICompilerProblem;
+import org.apache.flex.compiler.tree.as.IAccessorNode;
 import org.apache.flex.compiler.tree.as.IDefinitionNode;
 import org.apache.flex.compiler.tree.as.IExpressionNode;
 import org.apache.flex.compiler.tree.as.IFunctionNode;
+import org.apache.flex.compiler.tree.as.IGetterNode;
+import org.apache.flex.compiler.tree.as.IKeywordNode;
 import org.apache.flex.compiler.tree.as.IParameterNode;
 import org.apache.flex.compiler.tree.as.IScopedNode;
+import org.apache.flex.compiler.tree.as.ISetterNode;
 import org.apache.flex.compiler.tree.as.IVariableNode;
 import org.apache.flex.compiler.visitor.IASBlockWalker;
 
@@ -181,6 +185,16 @@ public class ASEmitter implements IASEmi
         emitNamespace(definition);
         emitModifiers(definition);
         emitMemberKeyword(node);
+
+        // TODO (mschmalle) I'm cheating right here, I haven't "seen" the light
+        // on how to properly and efficiently deal with accessors since they are SO alike
+        // I don't want to lump them in with methods because implementations in the
+        // future need to know the difference without loopholes
+        if (node instanceof IAccessorNode)
+        {
+            emitAccessorKeyword(((IAccessorNode) node).getAccessorKeywordNode());
+        }
+
         emitMemberName(node);
         emitParamters(node.getParameterNodes());
         emitType(node.getReturnTypeNode());
@@ -189,6 +203,30 @@ public class ASEmitter implements IASEmi
         // semi-colon and newline handling
     }
 
+    @Override
+    public void emitGetAccessorDocumentation(IGetterNode node)
+    {
+    }
+
+    @Override
+    public void emitGetAccessor(IGetterNode node)
+    {
+        // just cheat for now, IGetterNode is a IFunctionNode
+        emitMethod(node);
+    }
+
+    @Override
+    public void emitSetAccessorDocumentation(ISetterNode node)
+    {
+    }
+
+    @Override
+    public void emitSetAccessor(ISetterNode node)
+    {
+        // just cheat for now, ISetterNode is a IFunctionNode
+        emitMethod(node);
+    }
+
     protected void emitNamespace(IDefinition definition)
     {
         // namespace (public, protected, private, foo_bar)
@@ -217,14 +255,14 @@ public class ASEmitter implements IASEmi
 
     protected void emitMemberKeyword(IDefinitionNode node)
     {
-        if (node instanceof IVariableNode)
+        if (node instanceof IFunctionNode)
         {
-            write(((IVariableNode) node).isConst() ? "const" : "var");
+            write("function");
             write(" ");
         }
-        else if (node instanceof IFunctionNode)
+        else if (node instanceof IVariableNode)
         {
-            write("function");
+            write(((IVariableNode) node).isConst() ? "const" : "var");
             write(" ");
         }
     }
@@ -275,4 +313,10 @@ public class ASEmitter implements IASEmi
         write(" ");
         getVisitor().walk(node);
     }
+
+    protected void emitAccessorKeyword(IKeywordNode node)
+    {
+        getVisitor().walk(node);
+        write(" ");
+    }
 }



Mime
View raw message