flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aha...@apache.org
Subject [10/42] git commit: [flex-falcon] [refs/heads/develop] - - Refactored filed emittion into FieldEmitter.
Date Thu, 04 Jun 2015 06:06:16 GMT
- Refactored filed emittion into FieldEmitter.


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

Branch: refs/heads/develop
Commit: 1b8640271d67be12f0fff5b846e017fc69482a3a
Parents: ab1c421
Author: Michael Schmalle <mschmalle@apache.org>
Authored: Sat May 30 17:51:56 2015 -0400
Committer: Frédéric THOMAS <webdoublefx@gmail.com>
Committed: Tue Jun 2 13:40:09 2015 +0100

----------------------------------------------------------------------
 .../codegen/js/flexjs/JSFlexJSEmitter.java      |  62 +---------
 .../internal/codegen/js/goog/JSGoogEmitter.java |  10 +-
 .../internal/codegen/js/jx/FieldEmitter.java    | 112 +++++++++++++++++++
 .../internal/codegen/js/utils/EmitterUtils.java |   8 ++
 .../codegen/js/vf2js/JSVF2JSEmitter.java        |   3 +-
 5 files changed, 128 insertions(+), 67 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/1b864027/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSEmitter.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSEmitter.java
b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSEmitter.java
index c6ba8d8..ec5c2db 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSEmitter.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSEmitter.java
@@ -49,6 +49,7 @@ import org.apache.flex.compiler.internal.codegen.js.JSSessionModel.PropertyNodes
 import org.apache.flex.compiler.internal.codegen.js.goog.JSGoogEmitter;
 import org.apache.flex.compiler.internal.codegen.js.goog.JSGoogEmitterTokens;
 import org.apache.flex.compiler.internal.codegen.js.jx.ClassEmitter;
+import org.apache.flex.compiler.internal.codegen.js.jx.FieldEmitter;
 import org.apache.flex.compiler.internal.definitions.AccessorDefinition;
 import org.apache.flex.compiler.internal.definitions.ClassDefinition;
 import org.apache.flex.compiler.internal.definitions.FunctionDefinition;
@@ -61,7 +62,6 @@ import org.apache.flex.compiler.internal.scopes.ASProjectScope;
 import org.apache.flex.compiler.internal.scopes.PackageScope;
 import org.apache.flex.compiler.internal.scopes.TypeScope;
 import org.apache.flex.compiler.internal.tree.as.BinaryOperatorAssignmentNode;
-import org.apache.flex.compiler.internal.tree.as.ChainedVariableNode;
 import org.apache.flex.compiler.internal.tree.as.ClassNode;
 import org.apache.flex.compiler.internal.tree.as.FunctionCallNode;
 import org.apache.flex.compiler.internal.tree.as.FunctionNode;
@@ -112,6 +112,7 @@ public class JSFlexJSEmitter extends JSGoogEmitter implements IJSFlexJSEmitter
     private int foreachLoopCounter = 0;
     
     private ClassEmitter classEmitter;
+    private FieldEmitter fieldEmitter;
 
     public ClassEmitter getClassEmiter()
     {
@@ -123,6 +124,7 @@ public class JSFlexJSEmitter extends JSGoogEmitter implements IJSFlexJSEmitter
         super(out);
 
         classEmitter = new ClassEmitter(this);
+        fieldEmitter = new FieldEmitter(this);
     }
 
     @Override
@@ -155,63 +157,7 @@ public class JSFlexJSEmitter extends JSGoogEmitter implements IJSFlexJSEmitter
     @Override
     public void emitField(IVariableNode node)
     {
-        IDefinition definition = getClassDefinition(node);
-
-        IDefinition def = null;
-        IExpressionNode enode = node.getVariableTypeNode();//getAssignedValueNode();
-        if (enode != null)
-        {
-            if (project == null)
-                project = getWalker().getProject();
-
-            def = enode.resolveType(project);
-        }
-
-        getDoc().emitFieldDoc(node, def);
-
-        IDefinition ndef = node.getDefinition();
-
-        ModifiersSet modifierSet = ndef.getModifiers();
-        String root = "";
-        if (modifierSet != null && !modifierSet.hasModifier(ASModifier.STATIC))
-        {
-            root = JSEmitterTokens.PROTOTYPE.getToken();
-            root += ASEmitterTokens.MEMBER_ACCESS.getToken();
-        }
-
-        if (definition == null)
-            definition = ndef.getContainingScope().getDefinition();
-
-        write(formatQualifiedName(definition.getQualifiedName())
-                + ASEmitterTokens.MEMBER_ACCESS.getToken() + root
-                + node.getName());
-
-        IExpressionNode vnode = node.getAssignedValueNode();
-        if (vnode != null)
-        {
-            write(ASEmitterTokens.SPACE);
-            writeToken(ASEmitterTokens.EQUAL);
-            getWalker().walk(vnode);
-        }
-
-        if (!(node instanceof ChainedVariableNode))
-        {
-            int len = node.getChildCount();
-            for (int i = 0; i < len; i++)
-            {
-                IASNode child = node.getChild(i);
-                if (child instanceof ChainedVariableNode)
-                {
-                    writeNewline(ASEmitterTokens.SEMICOLON);
-                    writeNewline();
-                    emitField((IVariableNode) child);
-                }
-            }
-        }
-        if (node.getNodeID() == ASTNodeID.BindableVariableID)
-        {
-            getModel().getBindableVars().add(node.getName());
-        }
+        fieldEmitter.emit(node);
     }
 
     public void emitBindableVarDefineProperty(String name, IClassDefinition cdef)

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/1b864027/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/goog/JSGoogEmitter.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/goog/JSGoogEmitter.java
b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/goog/JSGoogEmitter.java
index d9ca745..db88672 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/goog/JSGoogEmitter.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/goog/JSGoogEmitter.java
@@ -40,6 +40,7 @@ import org.apache.flex.compiler.definitions.ITypeDefinition;
 import org.apache.flex.compiler.internal.codegen.as.ASEmitterTokens;
 import org.apache.flex.compiler.internal.codegen.js.JSEmitter;
 import org.apache.flex.compiler.internal.codegen.js.JSEmitterTokens;
+import org.apache.flex.compiler.internal.codegen.js.utils.EmitterUtils;
 import org.apache.flex.compiler.internal.definitions.ClassDefinition;
 import org.apache.flex.compiler.internal.scopes.PackageScope;
 import org.apache.flex.compiler.internal.tree.as.ChainedVariableNode;
@@ -323,7 +324,7 @@ public class JSGoogEmitter extends JSEmitter implements IJSGoogEmitter
     @Override
     public void emitField(IVariableNode node)
     {
-        IClassDefinition definition = getClassDefinition(node);
+        IClassDefinition definition = EmitterUtils.getClassDefinition(node);
 
         IDefinition def = null;
         IExpressionNode enode = node.getVariableTypeNode();//getAssignedValueNode();
@@ -939,13 +940,6 @@ public class JSGoogEmitter extends JSEmitter implements IJSGoogEmitter
         return (ITypeDefinition) tnode.getDefinition();
     }
 
-    protected static IClassDefinition getClassDefinition(IDefinitionNode node)
-    {
-        IClassNode tnode = (IClassNode) node
-                .getAncestorOfType(IClassNode.class);
-        return (tnode != null) ? tnode.getDefinition() : null;
-    }
-
     private static IClassDefinition getSuperClassDefinition(
             IDefinitionNode node, ICompilerProject project)
     {

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/1b864027/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/FieldEmitter.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/FieldEmitter.java
b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/FieldEmitter.java
new file mode 100644
index 0000000..d63ffde
--- /dev/null
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/FieldEmitter.java
@@ -0,0 +1,112 @@
+/*
+ *
+ *  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.compiler.internal.codegen.js.jx;
+
+import org.apache.flex.compiler.codegen.ISubEmitter;
+import org.apache.flex.compiler.codegen.js.IJSEmitter;
+import org.apache.flex.compiler.codegen.js.goog.IJSGoogDocEmitter;
+import org.apache.flex.compiler.common.ASModifier;
+import org.apache.flex.compiler.common.ModifiersSet;
+import org.apache.flex.compiler.definitions.IDefinition;
+import org.apache.flex.compiler.internal.codegen.as.ASEmitterTokens;
+import org.apache.flex.compiler.internal.codegen.js.JSEmitterTokens;
+import org.apache.flex.compiler.internal.codegen.js.JSSubEmitter;
+import org.apache.flex.compiler.internal.codegen.js.flexjs.JSFlexJSEmitter;
+import org.apache.flex.compiler.internal.codegen.js.utils.EmitterUtils;
+import org.apache.flex.compiler.internal.tree.as.ChainedVariableNode;
+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.IVariableNode;
+
+public class FieldEmitter extends JSSubEmitter implements
+        ISubEmitter<IVariableNode>
+{
+    public FieldEmitter(IJSEmitter emitter)
+    {
+        super(emitter);
+    }
+
+    @Override
+    public void emit(IVariableNode node)
+    {
+        // TODO (mschmalle) will remove this cast as more things get abstracted
+        JSFlexJSEmitter fjs = (JSFlexJSEmitter) getEmitter();
+
+        IDefinition definition = EmitterUtils.getClassDefinition(node);
+
+        IDefinition def = null;
+        IExpressionNode enode = node.getVariableTypeNode();//getAssignedValueNode();
+        if (enode != null)
+        {
+            def = enode.resolveType(getProject());
+        }
+        
+        // TODO (mschmalle)
+        if (fjs.getDocEmitter() instanceof IJSGoogDocEmitter)
+        {
+            ((IJSGoogDocEmitter) fjs.getDocEmitter()).emitFieldDoc(node, def);
+        }
+
+        IDefinition ndef = node.getDefinition();
+
+        ModifiersSet modifierSet = ndef.getModifiers();
+        String root = "";
+        if (modifierSet != null && !modifierSet.hasModifier(ASModifier.STATIC))
+        {
+            root = JSEmitterTokens.PROTOTYPE.getToken();
+            root += ASEmitterTokens.MEMBER_ACCESS.getToken();
+        }
+
+        if (definition == null)
+            definition = ndef.getContainingScope().getDefinition();
+
+        write(fjs.formatQualifiedName(definition.getQualifiedName())
+                + ASEmitterTokens.MEMBER_ACCESS.getToken() + root
+                + node.getName());
+
+        IExpressionNode vnode = node.getAssignedValueNode();
+        if (vnode != null)
+        {
+            write(ASEmitterTokens.SPACE);
+            writeToken(ASEmitterTokens.EQUAL);
+            fjs.getWalker().walk(vnode);
+        }
+
+        if (!(node instanceof ChainedVariableNode))
+        {
+            int len = node.getChildCount();
+            for (int i = 0; i < len; i++)
+            {
+                IASNode child = node.getChild(i);
+                if (child instanceof ChainedVariableNode)
+                {
+                    writeNewline(ASEmitterTokens.SEMICOLON);
+                    writeNewline();
+                    fjs.emitField((IVariableNode) child);
+                }
+            }
+        }
+        if (node.getNodeID() == ASTNodeID.BindableVariableID)
+        {
+            getModel().getBindableVars().add(node.getName());
+        }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/1b864027/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/utils/EmitterUtils.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/utils/EmitterUtils.java
b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/utils/EmitterUtils.java
index 94a2120..9f6a99d 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/utils/EmitterUtils.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/utils/EmitterUtils.java
@@ -30,6 +30,7 @@ import org.apache.flex.compiler.internal.definitions.ClassDefinition;
 import org.apache.flex.compiler.projects.ICompilerProject;
 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.IDefinitionNode;
 import org.apache.flex.compiler.tree.as.IFunctionNode;
 import org.apache.flex.compiler.tree.as.IScopedNode;
@@ -118,4 +119,11 @@ public class EmitterUtils
         }
         return list;
     }
+    
+    public static IClassDefinition getClassDefinition(IDefinitionNode node)
+    {
+        IClassNode tnode = (IClassNode) node
+                .getAncestorOfType(IClassNode.class);
+        return (tnode != null) ? tnode.getDefinition() : null;
+    }
 }

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/1b864027/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/vf2js/JSVF2JSEmitter.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/vf2js/JSVF2JSEmitter.java
b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/vf2js/JSVF2JSEmitter.java
index ea68760..033215a 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/vf2js/JSVF2JSEmitter.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/vf2js/JSVF2JSEmitter.java
@@ -47,6 +47,7 @@ import org.apache.flex.compiler.internal.codegen.js.JSEmitterTokens;
 import org.apache.flex.compiler.internal.codegen.js.flexjs.JSFlexJSEmitterTokens;
 import org.apache.flex.compiler.internal.codegen.js.goog.JSGoogEmitter;
 import org.apache.flex.compiler.internal.codegen.js.goog.JSGoogEmitterTokens;
+import org.apache.flex.compiler.internal.codegen.js.utils.EmitterUtils;
 import org.apache.flex.compiler.internal.definitions.AccessorDefinition;
 import org.apache.flex.compiler.internal.definitions.ClassDefinition;
 import org.apache.flex.compiler.internal.definitions.FunctionDefinition;
@@ -384,7 +385,7 @@ public class JSVF2JSEmitter extends JSGoogEmitter implements IJSVF2JSEmitter
     @Override
     public void emitField(IVariableNode node)
     {
-        IDefinition definition = getClassDefinition(node);
+        IDefinition definition = EmitterUtils.getClassDefinition(node);
 
         IDefinition def = null;
         IExpressionNode enode = node.getVariableTypeNode();//getAssignedValueNode();


Mime
View raw message