You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by ms...@apache.org on 2015/05/30 23:41:18 UTC
[1/3] git commit: [flex-falcon] [refs/heads/develop] - - Refactored
Class emitting into shared jx package for future use. - Refactored Bindable
class level emittion;
- Refactored GetSet class level emition - Created a shared model for each
emitter sessio
Repository: flex-falcon
Updated Branches:
refs/heads/develop 6209a2416 -> b2097f4e9
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/b2097f4e/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/ClassEmitter.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/ClassEmitter.java b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/ClassEmitter.java
new file mode 100644
index 0000000..1800afa
--- /dev/null
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/ClassEmitter.java
@@ -0,0 +1,156 @@
+/*
+ *
+ * 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.asdoc.flexjs.ASDocComment;
+import org.apache.flex.compiler.clients.MXMLJSC;
+import org.apache.flex.compiler.codegen.ISubEmitter;
+import org.apache.flex.compiler.codegen.js.IJSEmitter;
+import org.apache.flex.compiler.definitions.IClassDefinition;
+import org.apache.flex.compiler.definitions.IFunctionDefinition;
+import org.apache.flex.compiler.internal.codegen.as.ASEmitterTokens;
+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.DocEmitterUtils;
+import org.apache.flex.compiler.tree.ASTNodeID;
+import org.apache.flex.compiler.tree.as.IAccessorNode;
+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.IVariableNode;
+
+public class ClassEmitter extends JSSubEmitter implements
+ ISubEmitter<IClassNode>
+{
+ private BindableEmitter bindableEmitter;
+ private GetSetEmitter getSetEmitter;
+
+ public BindableEmitter getBindableEmitter()
+ {
+ return bindableEmitter;
+ }
+
+ public GetSetEmitter getGetSetEmitter()
+ {
+ return getSetEmitter;
+ }
+
+ public ClassEmitter(IJSEmitter emitter)
+ {
+ super(emitter);
+
+ bindableEmitter = new BindableEmitter(emitter);
+ getSetEmitter = new GetSetEmitter(emitter);
+ }
+
+ @Override
+ public void emit(IClassNode node)
+ {
+ getModel().setCurrentClass(node.getDefinition());
+
+ // TODO (mschmalle) will remove this cast as more things get abstracted
+ JSFlexJSEmitter fjs = (JSFlexJSEmitter) getEmitter();
+
+ ASDocComment asDoc = (ASDocComment) node.getASDocComment();
+ if (asDoc != null && MXMLJSC.keepASDoc)
+ DocEmitterUtils.loadImportIgnores(fjs, asDoc.commentNoEnd());
+
+ IClassDefinition definition = node.getDefinition();
+
+ IFunctionDefinition ctorDefinition = definition.getConstructor();
+
+ // Static-only (Singleton) classes may not have a constructor
+ if (ctorDefinition != null)
+ {
+ IFunctionNode ctorNode = (IFunctionNode) ctorDefinition.getNode();
+ if (ctorNode != null)
+ {
+ // constructor
+ getEmitter().emitMethod(ctorNode);
+ write(ASEmitterTokens.SEMICOLON);
+ }
+ else
+ {
+ String qname = definition.getQualifiedName();
+ if (qname != null && !qname.equals(""))
+ {
+ write(fjs.formatQualifiedName(qname));
+ write(ASEmitterTokens.SPACE);
+ writeToken(ASEmitterTokens.EQUAL);
+ write(ASEmitterTokens.FUNCTION);
+ write(ASEmitterTokens.PAREN_OPEN);
+ write(ASEmitterTokens.PAREN_CLOSE);
+ write(ASEmitterTokens.SPACE);
+ write(ASEmitterTokens.BLOCK_OPEN);
+ writeNewline();
+ write(ASEmitterTokens.BLOCK_CLOSE);
+ write(ASEmitterTokens.SEMICOLON);
+ }
+ }
+ }
+
+ IDefinitionNode[] dnodes = node.getAllMemberNodes();
+ for (IDefinitionNode dnode : dnodes)
+ {
+ if (dnode.getNodeID() == ASTNodeID.VariableID)
+ {
+ writeNewline();
+ writeNewline();
+ writeNewline();
+ getEmitter().emitField((IVariableNode) dnode);
+ write(ASEmitterTokens.SEMICOLON);
+ }
+ else if (dnode.getNodeID() == ASTNodeID.FunctionID)
+ {
+ if (!((IFunctionNode) dnode).isConstructor())
+ {
+ writeNewline();
+ writeNewline();
+ writeNewline();
+ getEmitter().emitMethod((IFunctionNode) dnode);
+ write(ASEmitterTokens.SEMICOLON);
+ }
+ }
+ else if (dnode.getNodeID() == ASTNodeID.GetterID
+ || dnode.getNodeID() == ASTNodeID.SetterID)
+ {
+ //writeNewline();
+ //writeNewline();
+ //writeNewline();
+ fjs.emitAccessors((IAccessorNode) dnode);
+ //this shouldn't write anything, just set up
+ //a data structure for emitASGettersAndSetters
+ //write(ASEmitterTokens.SEMICOLON);
+ }
+ else if (dnode.getNodeID() == ASTNodeID.BindableVariableID)
+ {
+ writeNewline();
+ writeNewline();
+ writeNewline();
+ getEmitter().emitField((IVariableNode) dnode);
+ write(ASEmitterTokens.SEMICOLON);
+ }
+ }
+
+ bindableEmitter.emit(definition);
+
+ getSetEmitter.emit(definition);
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/b2097f4e/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/GetSetEmitter.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/GetSetEmitter.java b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/GetSetEmitter.java
new file mode 100644
index 0000000..c4db6fa
--- /dev/null
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/GetSetEmitter.java
@@ -0,0 +1,195 @@
+/*
+ *
+ * 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 java.util.Set;
+
+import org.apache.flex.compiler.codegen.ISubEmitter;
+import org.apache.flex.compiler.codegen.js.IJSEmitter;
+import org.apache.flex.compiler.definitions.IClassDefinition;
+import org.apache.flex.compiler.internal.codegen.as.ASEmitterTokens;
+import org.apache.flex.compiler.internal.codegen.js.JSDocEmitterTokens;
+import org.apache.flex.compiler.internal.codegen.js.JSEmitterTokens;
+import org.apache.flex.compiler.internal.codegen.js.JSSessionModel.PropertyNodes;
+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.goog.JSGoogEmitterTokens;
+
+public class GetSetEmitter extends JSSubEmitter implements
+ ISubEmitter<IClassDefinition>
+{
+
+ public GetSetEmitter(IJSEmitter emitter)
+ {
+ super(emitter);
+ }
+
+ @Override
+ public void emit(IClassDefinition definition)
+ {
+ // TODO (mschmalle) will remove this cast as more things get abstracted
+ JSFlexJSEmitter fjs = (JSFlexJSEmitter) getEmitter();
+
+ if (!getModel().getPropertyMap().isEmpty())
+ {
+ writeNewline();
+ writeNewline();
+ writeNewline();
+ write(JSGoogEmitterTokens.OBJECT);
+ write(ASEmitterTokens.MEMBER_ACCESS);
+ write(JSEmitterTokens.DEFINE_PROPERTIES);
+ write(ASEmitterTokens.PAREN_OPEN);
+ String qname = definition.getQualifiedName();
+ write(fjs.formatQualifiedName(qname));
+ write(ASEmitterTokens.MEMBER_ACCESS);
+ write(JSEmitterTokens.PROTOTYPE);
+ write(ASEmitterTokens.COMMA);
+ write(ASEmitterTokens.SPACE);
+ write("/** @lends {" + fjs.formatQualifiedName(qname)
+ + ".prototype} */ ");
+ writeNewline(ASEmitterTokens.BLOCK_OPEN);
+
+ Set<String> propertyNames = getModel().getPropertyMap().keySet();
+ boolean firstTime = true;
+ for (String propName : propertyNames)
+ {
+ if (firstTime)
+ firstTime = false;
+ else
+ writeNewline(ASEmitterTokens.COMMA);
+
+ PropertyNodes p = getModel().getPropertyMap().get(propName);
+ writeNewline("/** @expose */");
+ write(propName);
+ write(ASEmitterTokens.COLON);
+ write(ASEmitterTokens.SPACE);
+ writeNewline(ASEmitterTokens.BLOCK_OPEN);
+ if (p.getter != null)
+ {
+ write(ASEmitterTokens.GET);
+ write(ASEmitterTokens.COLON);
+ write(ASEmitterTokens.SPACE);
+ write(JSDocEmitterTokens.JSDOC_OPEN);
+ write(ASEmitterTokens.SPACE);
+ write(ASEmitterTokens.ATSIGN);
+ write(ASEmitterTokens.THIS);
+ write(ASEmitterTokens.SPACE);
+ write(ASEmitterTokens.BLOCK_OPEN);
+ write(fjs.formatQualifiedName(qname));
+ write(ASEmitterTokens.BLOCK_CLOSE);
+ write(ASEmitterTokens.SPACE);
+ write(JSDocEmitterTokens.JSDOC_CLOSE);
+ write(ASEmitterTokens.SPACE);
+ write(ASEmitterTokens.FUNCTION);
+ fjs.emitParameters(p.getter.getParameterNodes());
+
+ fjs.emitDefinePropertyFunction(p.getter);
+ }
+ if (p.setter != null)
+ {
+ if (p.getter != null)
+ writeNewline(ASEmitterTokens.COMMA);
+
+ write(ASEmitterTokens.SET);
+ write(ASEmitterTokens.COLON);
+ write(ASEmitterTokens.SPACE);
+ write(JSDocEmitterTokens.JSDOC_OPEN);
+ write(ASEmitterTokens.SPACE);
+ write(ASEmitterTokens.ATSIGN);
+ write(ASEmitterTokens.THIS);
+ write(ASEmitterTokens.SPACE);
+ write(ASEmitterTokens.BLOCK_OPEN);
+ write(fjs.formatQualifiedName(qname));
+ write(ASEmitterTokens.BLOCK_CLOSE);
+ write(ASEmitterTokens.SPACE);
+ write(JSDocEmitterTokens.JSDOC_CLOSE);
+ write(ASEmitterTokens.SPACE);
+ write(ASEmitterTokens.FUNCTION);
+ fjs.emitParameters(p.setter.getParameterNodes());
+
+ fjs.emitDefinePropertyFunction(p.setter);
+ }
+ write(ASEmitterTokens.BLOCK_CLOSE);
+ }
+ writeNewline(ASEmitterTokens.BLOCK_CLOSE);
+ write(ASEmitterTokens.PAREN_CLOSE);
+ write(ASEmitterTokens.SEMICOLON);
+ }
+ if (!getModel().getStaticPropertyMap().isEmpty())
+ {
+ write(JSGoogEmitterTokens.OBJECT);
+ write(ASEmitterTokens.MEMBER_ACCESS);
+ write(JSEmitterTokens.DEFINE_PROPERTIES);
+ write(ASEmitterTokens.PAREN_OPEN);
+ String qname = definition.getQualifiedName();
+ write(fjs.formatQualifiedName(qname));
+ write(ASEmitterTokens.COMMA);
+ write(ASEmitterTokens.SPACE);
+ write("/** @lends {" + fjs.formatQualifiedName(qname) + "} */ ");
+ writeNewline(ASEmitterTokens.BLOCK_OPEN);
+
+ Set<String> propertyNames = getModel().getStaticPropertyMap()
+ .keySet();
+ boolean firstTime = true;
+ for (String propName : propertyNames)
+ {
+ if (firstTime)
+ firstTime = false;
+ else
+ writeNewline(ASEmitterTokens.COMMA);
+
+ PropertyNodes p = getModel().getStaticPropertyMap().get(
+ propName);
+ writeNewline("/** @expose */");
+ write(propName);
+ write(ASEmitterTokens.COLON);
+ write(ASEmitterTokens.SPACE);
+ writeNewline(ASEmitterTokens.BLOCK_OPEN);
+ if (p.getter != null)
+ {
+ write(ASEmitterTokens.GET);
+ write(ASEmitterTokens.COLON);
+ write(ASEmitterTokens.SPACE);
+ write(ASEmitterTokens.FUNCTION);
+ fjs.emitParameters(p.getter.getParameterNodes());
+
+ fjs.emitDefinePropertyFunction(p.getter);
+ }
+ if (p.setter != null)
+ {
+ if (p.getter != null)
+ writeNewline(ASEmitterTokens.COMMA);
+
+ write(ASEmitterTokens.SET);
+ write(ASEmitterTokens.COLON);
+ write(ASEmitterTokens.SPACE);
+ write(ASEmitterTokens.FUNCTION);
+ fjs.emitParameters(p.setter.getParameterNodes());
+
+ fjs.emitDefinePropertyFunction(p.setter);
+ }
+ write(ASEmitterTokens.BLOCK_CLOSE);
+ }
+ writeNewline(ASEmitterTokens.BLOCK_CLOSE);
+ write(ASEmitterTokens.PAREN_CLOSE);
+ write(ASEmitterTokens.SEMICOLON);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/b2097f4e/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/utils/DocEmitterUtils.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/utils/DocEmitterUtils.java b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/utils/DocEmitterUtils.java
new file mode 100644
index 0000000..7d7bf16
--- /dev/null
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/utils/DocEmitterUtils.java
@@ -0,0 +1,49 @@
+/*
+ *
+ * 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.utils;
+
+import java.util.ArrayList;
+
+import org.apache.flex.compiler.internal.codegen.js.flexjs.JSFlexJSDocEmitter;
+import org.apache.flex.compiler.internal.codegen.js.flexjs.JSFlexJSEmitter;
+import org.apache.flex.compiler.internal.codegen.js.flexjs.JSFlexJSEmitterTokens;
+
+public class DocEmitterUtils
+{
+ public static void loadImportIgnores(JSFlexJSEmitter emitter, String doc)
+ {
+ ArrayList<String> ignoreList = new ArrayList<String>();
+ String ignoreToken = JSFlexJSEmitterTokens.IGNORE_IMPORT.getToken();
+ int index = doc.indexOf(ignoreToken);
+ while (index != -1)
+ {
+ String ignorable = doc.substring(index + ignoreToken.length());
+ int endIndex = ignorable.indexOf("\n");
+ ignorable = ignorable.substring(0, endIndex);
+ ignorable = ignorable.trim();
+ ignoreList.add(ignorable);
+ System.out.println("Found ignorable: " + ignorable);
+ index = doc.indexOf(ignoreToken, index + endIndex);
+ }
+
+ // TODO (mschmalle)
+ ((JSFlexJSDocEmitter)emitter.getDocEmitter()).setClassIgnoreList(ignoreList);
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/b2097f4e/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
new file mode 100644
index 0000000..94a2120
--- /dev/null
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/utils/EmitterUtils.java
@@ -0,0 +1,121 @@
+/*
+ *
+ * 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.utils;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.flex.compiler.constants.IASLanguageConstants;
+import org.apache.flex.compiler.definitions.IClassDefinition;
+import org.apache.flex.compiler.definitions.IDefinition;
+import org.apache.flex.compiler.definitions.ITypeDefinition;
+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.IDefinitionNode;
+import org.apache.flex.compiler.tree.as.IFunctionNode;
+import org.apache.flex.compiler.tree.as.IScopedNode;
+
+/**
+ * Various static methods used in shared emitter logic.
+ */
+public class EmitterUtils
+{
+ public static boolean isSameClass(IDefinition pdef, IDefinition thisClass,
+ ICompilerProject project)
+ {
+ if (pdef == thisClass)
+ return true;
+
+ IDefinition cdef = ((ClassDefinition) thisClass)
+ .resolveBaseClass(project);
+ while (cdef != null)
+ {
+ // needs to be a loop
+ if (cdef == pdef)
+ return true;
+ cdef = ((ClassDefinition) cdef).resolveBaseClass(project);
+ }
+ return false;
+ }
+
+ public static boolean hasSuperClass(ICompilerProject project,
+ IDefinitionNode node)
+ {
+ IClassDefinition superClassDefinition = getSuperClassDefinition(node,
+ project);
+ // XXX (mschmalle) this is nulling for MXML super class, figure out why
+ if (superClassDefinition == null)
+ return false;
+ String qname = superClassDefinition.getQualifiedName();
+ return superClassDefinition != null
+ && !qname.equals(IASLanguageConstants.Object);
+ }
+
+ public static boolean hasSuperCall(IScopedNode node)
+ {
+ for (int i = node.getChildCount() - 1; i > -1; i--)
+ {
+ IASNode cnode = node.getChild(i);
+ if (cnode.getNodeID() == ASTNodeID.FunctionCallID
+ && cnode.getChild(0).getNodeID() == ASTNodeID.SuperID)
+ return true;
+ }
+
+ return false;
+ }
+
+ public static boolean hasBody(IFunctionNode node)
+ {
+ IScopedNode scope = node.getScopedNode();
+ return scope.getChildCount() > 0;
+ }
+
+ public static IClassDefinition getSuperClassDefinition(
+ IDefinitionNode node, ICompilerProject project)
+ {
+ IClassDefinition parent = (IClassDefinition) node.getDefinition()
+ .getParent();
+ IClassDefinition superClass = parent.resolveBaseClass(project);
+ return superClass;
+ }
+
+ public static List<String> resolveImports(ITypeDefinition type)
+ {
+ ArrayList<String> list = new ArrayList<String>();
+ IScopedNode scopeNode = type.getContainedScope().getScopeNode();
+ if (scopeNode != null)
+ {
+ scopeNode.getAllImports(list);
+ }
+ else
+ {
+ // MXML
+ ClassDefinition cdefinition = (ClassDefinition) type;
+ String[] implicitImports = cdefinition.getImplicitImports();
+ for (String imp : implicitImports)
+ {
+ list.add(imp);
+ }
+ }
+ return list;
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/b2097f4e/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 9a9a2c5..ea68760 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
@@ -111,8 +111,6 @@ public class JSVF2JSEmitter extends JSGoogEmitter implements IJSVF2JSEmitter
super(out);
}
- public IDefinition thisClass;
-
@Override
protected String getIndent(int numIndent)
{
@@ -131,12 +129,11 @@ public class JSVF2JSEmitter extends JSGoogEmitter implements IJSVF2JSEmitter
@Override
public void emitClass(IClassNode node)
{
- thisClass = node.getDefinition();
+ IClassDefinition definition = node.getDefinition();
+ getModel().setCurrentClass(definition);
project = getWalker().getProject();
- IClassDefinition definition = node.getDefinition();
-
IFunctionDefinition ctorDefinition = definition.getConstructor();
// Static-only (Singleton) classes may not have a constructor
@@ -291,7 +288,7 @@ public class JSVF2JSEmitter extends JSGoogEmitter implements IJSVF2JSEmitter
// (erikdebruin): If the initial value of a variable is set using
// a method, JS needs this initialization to be done
// in the constructor
- IClassNode cdnode = (IClassNode) thisClass.getNode();
+ IClassNode cdnode = (IClassNode) getModel().getCurrentClass().getNode();
IDefinitionNode[] dnodes = cdnode.getAllMemberNodes();
for (IDefinitionNode dnode : dnodes)
{
@@ -697,6 +694,7 @@ public class JSVF2JSEmitter extends JSGoogEmitter implements IJSVF2JSEmitter
ASTNodeID parentNodeId = parentNode.getNodeID();
IASNode firstChild = parentNode.getChild(0);
+ IClassDefinition thisClass = getModel().getCurrentClass();
boolean identifierIsMemberAccess = parentNodeId == ASTNodeID.MemberAccessExpressionID;
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/b2097f4e/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSEmitter.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSEmitter.java b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSEmitter.java
index f7d9c55..4efa7a6 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSEmitter.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSEmitter.java
@@ -114,7 +114,7 @@ public class MXMLFlexJSEmitter extends MXMLEmitter implements
private StringBuilder subDocuments = new StringBuilder();
private ArrayList<String> subDocumentNames = new ArrayList<String>();
-
+
/**
* This keeps track of the entries in our temporary array of
* DeferredInstanceFromFunction objects that we CG to help with
@@ -184,7 +184,7 @@ public class MXMLFlexJSEmitter extends MXMLEmitter implements
classDefinition = cdef;
IASEmitter asEmitter = ((IMXMLBlockWalker) getMXMLWalker())
.getASEmitter();
- ((JSFlexJSEmitter) asEmitter).thisClass = cdef;
+ ((JSFlexJSEmitter) asEmitter).getModel().setCurrentClass(cdef);
// visit tags
final int len = node.getChildCount();
@@ -210,8 +210,8 @@ public class MXMLFlexJSEmitter extends MXMLEmitter implements
emitScripts();
- ((JSFlexJSEmitter)asEmitter).emitBindableVariables(cdef);
- ((JSFlexJSEmitter)asEmitter).emitASGettersAndSetters(cdef);
+ ((JSFlexJSEmitter)asEmitter).getClassEmiter().getBindableEmitter().emit(cdef);
+ ((JSFlexJSEmitter)asEmitter).getClassEmiter().getGetSetEmitter().emit(cdef);
emitEvents(cname);
@@ -267,8 +267,8 @@ public class MXMLFlexJSEmitter extends MXMLEmitter implements
classDefinition = cdef;
IASEmitter asEmitter = ((IMXMLBlockWalker) getMXMLWalker())
.getASEmitter();
- IDefinition oldThisClass = ((JSFlexJSEmitter) asEmitter).thisClass;
- ((JSFlexJSEmitter) asEmitter).thisClass = cdef;
+ IClassDefinition oldThisClass = ((JSFlexJSEmitter) asEmitter).getModel().getCurrentClass();
+ ((JSFlexJSEmitter) asEmitter).getModel().setCurrentClass(cdef);
IASNode classNode = node.getContainedClassDefinitionNode();
// visit tags
@@ -312,7 +312,7 @@ public class MXMLFlexJSEmitter extends MXMLEmitter implements
idCounter = oldIdCounter;
inMXMLContent = oldInMXMLContent;
classDefinition = oldClassDef;
- ((JSFlexJSEmitter) asEmitter).thisClass = oldThisClass;
+ ((JSFlexJSEmitter) asEmitter).getModel().setCurrentClass(oldThisClass);
}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/b2097f4e/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/vf2js/MXMLVF2JSEmitter.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/vf2js/MXMLVF2JSEmitter.java b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/vf2js/MXMLVF2JSEmitter.java
index 60702a8..5c2aae0 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/vf2js/MXMLVF2JSEmitter.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/vf2js/MXMLVF2JSEmitter.java
@@ -144,7 +144,7 @@ public class MXMLVF2JSEmitter extends MXMLEmitter implements
IClassDefinition cdef = node.getClassDefinition();
IASEmitter asEmitter = ((IMXMLBlockWalker) getMXMLWalker())
.getASEmitter();
- ((JSVF2JSEmitter) asEmitter).thisClass = cdef;
+ ((JSVF2JSEmitter) asEmitter).getModel().setCurrentClass(cdef);
// visit tags
final int len = node.getChildCount();
@@ -218,7 +218,7 @@ public class MXMLVF2JSEmitter extends MXMLEmitter implements
IClassDefinition cdef = node.getContainedClassDefinition();
IASEmitter asEmitter = ((IMXMLBlockWalker) getMXMLWalker())
.getASEmitter();
- ((JSVF2JSEmitter) asEmitter).thisClass = cdef;
+ ((JSVF2JSEmitter) asEmitter).getModel().setCurrentClass(cdef);
IASNode classNode = node.getContainedClassDefinitionNode();
// visit tags
[2/3] git commit: [flex-falcon] [refs/heads/develop] - - Refactored
Class emitting into shared jx package for future use. - Refactored Bindable
class level emittion;
- Refactored GetSet class level emition - Created a shared model for each
emitter sessio
Posted by ms...@apache.org.
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/b2097f4e/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 ff44ab3..c6ba8d8 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
@@ -44,10 +44,11 @@ import org.apache.flex.compiler.definitions.INamespaceDefinition;
import org.apache.flex.compiler.definitions.IPackageDefinition;
import org.apache.flex.compiler.definitions.ITypeDefinition;
import org.apache.flex.compiler.internal.codegen.as.ASEmitterTokens;
-import org.apache.flex.compiler.internal.codegen.js.JSDocEmitterTokens;
import org.apache.flex.compiler.internal.codegen.js.JSEmitterTokens;
+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.definitions.AccessorDefinition;
import org.apache.flex.compiler.internal.definitions.ClassDefinition;
import org.apache.flex.compiler.internal.definitions.FunctionDefinition;
@@ -108,29 +109,28 @@ import org.apache.flex.compiler.utils.NativeUtils;
public class JSFlexJSEmitter extends JSGoogEmitter implements IJSFlexJSEmitter
{
- public JSFlexJSEmitter(FilterWriter out)
+ private int foreachLoopCounter = 0;
+
+ private ClassEmitter classEmitter;
+
+ public ClassEmitter getClassEmiter()
{
- super(out);
+ return classEmitter;
}
- public IDefinition thisClass;
-
- class PropertyNodes
+ public JSFlexJSEmitter(FilterWriter out)
{
- public IGetterNode getter;
- public ISetterNode setter;
+ super(out);
+
+ classEmitter = new ClassEmitter(this);
}
-
- HashMap<String, PropertyNodes> propertyMap = new HashMap<String, PropertyNodes>();
- HashMap<String, PropertyNodes> staticPropertyMap = new HashMap<String, PropertyNodes>();
- ArrayList<String> bindableVars = new ArrayList<String>();
-
+
@Override
protected void writeIndent()
{
write(JSFlexJSEmitterTokens.INDENT);
}
-
+
@Override
protected String getIndent(int numIndent)
{
@@ -149,318 +149,9 @@ public class JSFlexJSEmitter extends JSGoogEmitter implements IJSFlexJSEmitter
@Override
public void emitClass(IClassNode node)
{
- thisClass = node.getDefinition();
-
- ASDocComment asDoc = (ASDocComment) node.getASDocComment();
- if (asDoc != null && MXMLJSC.keepASDoc)
- loadImportIgnores(asDoc.commentNoEnd());
-
- project = getWalker().getProject();
-
- IClassDefinition definition = node.getDefinition();
-
- IFunctionDefinition ctorDefinition = definition.getConstructor();
-
- // Static-only (Singleton) classes may not have a constructor
- if (ctorDefinition != null)
- {
- IFunctionNode ctorNode = (IFunctionNode) ctorDefinition.getNode();
- if (ctorNode != null)
- {
- // constructor
- emitMethod(ctorNode);
- write(ASEmitterTokens.SEMICOLON);
- }
- else
- {
- String qname = definition.getQualifiedName();
- if (qname != null && !qname.equals(""))
- {
- write(formatQualifiedName(qname));
- write(ASEmitterTokens.SPACE);
- writeToken(ASEmitterTokens.EQUAL);
- write(ASEmitterTokens.FUNCTION);
- write(ASEmitterTokens.PAREN_OPEN);
- write(ASEmitterTokens.PAREN_CLOSE);
- write(ASEmitterTokens.SPACE);
- write(ASEmitterTokens.BLOCK_OPEN);
- writeNewline();
- write(ASEmitterTokens.BLOCK_CLOSE);
- write(ASEmitterTokens.SEMICOLON);
- }
- }
- }
-
- IDefinitionNode[] dnodes = node.getAllMemberNodes();
- for (IDefinitionNode dnode : dnodes)
- {
- if (dnode.getNodeID() == ASTNodeID.VariableID)
- {
- writeNewline();
- writeNewline();
- writeNewline();
- emitField((IVariableNode) dnode);
- write(ASEmitterTokens.SEMICOLON);
- }
- else if (dnode.getNodeID() == ASTNodeID.FunctionID)
- {
- if (!((IFunctionNode) dnode).isConstructor())
- {
- writeNewline();
- writeNewline();
- writeNewline();
- emitMethod((IFunctionNode) dnode);
- write(ASEmitterTokens.SEMICOLON);
- }
- }
- else if (dnode.getNodeID() == ASTNodeID.GetterID
- || dnode.getNodeID() == ASTNodeID.SetterID)
- {
- //writeNewline();
- //writeNewline();
- //writeNewline();
- emitAccessors((IAccessorNode) dnode);
- //this shouldn't write anything, just set up
- //a data structure for emitASGettersAndSetters
- //write(ASEmitterTokens.SEMICOLON);
- }
- else if (dnode.getNodeID() == ASTNodeID.BindableVariableID)
- {
- writeNewline();
- writeNewline();
- writeNewline();
- emitField((IVariableNode) dnode);
- write(ASEmitterTokens.SEMICOLON);
- }
- }
-
- emitBindableVariables(node.getDefinition());
-
- emitASGettersAndSetters(node.getDefinition());
+ classEmitter.emit(node);
}
-
- public void emitASGettersAndSetters(IClassDefinition definition)
- {
- if (!propertyMap.isEmpty())
- {
- writeNewline();
- writeNewline();
- writeNewline();
- write(JSGoogEmitterTokens.OBJECT);
- write(ASEmitterTokens.MEMBER_ACCESS);
- write(JSEmitterTokens.DEFINE_PROPERTIES);
- write(ASEmitterTokens.PAREN_OPEN);
- String qname = definition.getQualifiedName();
- write(formatQualifiedName(qname));
- write(ASEmitterTokens.MEMBER_ACCESS);
- write(JSEmitterTokens.PROTOTYPE);
- write(ASEmitterTokens.COMMA);
- write(ASEmitterTokens.SPACE);
- write("/** @lends {" + formatQualifiedName(qname) + ".prototype} */ ");
- writeNewline(ASEmitterTokens.BLOCK_OPEN);
-
- Set<String> propertyNames = propertyMap.keySet();
- boolean firstTime = true;
- for (String propName : propertyNames)
- {
- if (firstTime)
- firstTime = false;
- else
- writeNewline(ASEmitterTokens.COMMA);
-
- PropertyNodes p = propertyMap.get(propName);
- writeNewline("/** @expose */");
- write(propName);
- write(ASEmitterTokens.COLON);
- write(ASEmitterTokens.SPACE);
- writeNewline(ASEmitterTokens.BLOCK_OPEN);
- if (p.getter != null)
- {
- write(ASEmitterTokens.GET);
- write(ASEmitterTokens.COLON);
- write(ASEmitterTokens.SPACE);
- write(JSDocEmitterTokens.JSDOC_OPEN);
- write(ASEmitterTokens.SPACE);
- write(ASEmitterTokens.ATSIGN);
- write(ASEmitterTokens.THIS);
- write(ASEmitterTokens.SPACE);
- write(ASEmitterTokens.BLOCK_OPEN);
- write(formatQualifiedName(qname));
- write(ASEmitterTokens.BLOCK_CLOSE);
- write(ASEmitterTokens.SPACE);
- write(JSDocEmitterTokens.JSDOC_CLOSE);
- write(ASEmitterTokens.SPACE);
- write(ASEmitterTokens.FUNCTION);
- emitParameters(p.getter.getParameterNodes());
-
- emitDefinePropertyFunction(p.getter);
- }
- if (p.setter != null)
- {
- if (p.getter != null)
- writeNewline(ASEmitterTokens.COMMA);
-
- write(ASEmitterTokens.SET);
- write(ASEmitterTokens.COLON);
- write(ASEmitterTokens.SPACE);
- write(JSDocEmitterTokens.JSDOC_OPEN);
- write(ASEmitterTokens.SPACE);
- write(ASEmitterTokens.ATSIGN);
- write(ASEmitterTokens.THIS);
- write(ASEmitterTokens.SPACE);
- write(ASEmitterTokens.BLOCK_OPEN);
- write(formatQualifiedName(qname));
- write(ASEmitterTokens.BLOCK_CLOSE);
- write(ASEmitterTokens.SPACE);
- write(JSDocEmitterTokens.JSDOC_CLOSE);
- write(ASEmitterTokens.SPACE);
- write(ASEmitterTokens.FUNCTION);
- emitParameters(p.setter.getParameterNodes());
-
- emitDefinePropertyFunction(p.setter);
- }
- write(ASEmitterTokens.BLOCK_CLOSE);
- }
- writeNewline(ASEmitterTokens.BLOCK_CLOSE);
- write(ASEmitterTokens.PAREN_CLOSE);
- write(ASEmitterTokens.SEMICOLON);
- }
- if (!staticPropertyMap.isEmpty())
- {
- write(JSGoogEmitterTokens.OBJECT);
- write(ASEmitterTokens.MEMBER_ACCESS);
- write(JSEmitterTokens.DEFINE_PROPERTIES);
- write(ASEmitterTokens.PAREN_OPEN);
- String qname = definition.getQualifiedName();
- write(formatQualifiedName(qname));
- write(ASEmitterTokens.COMMA);
- write(ASEmitterTokens.SPACE);
- write("/** @lends {" + formatQualifiedName(qname) + "} */ ");
- writeNewline(ASEmitterTokens.BLOCK_OPEN);
-
- Set<String> propertyNames = staticPropertyMap.keySet();
- boolean firstTime = true;
- for (String propName : propertyNames)
- {
- if (firstTime)
- firstTime = false;
- else
- writeNewline(ASEmitterTokens.COMMA);
-
- PropertyNodes p = staticPropertyMap.get(propName);
- writeNewline("/** @expose */");
- write(propName);
- write(ASEmitterTokens.COLON);
- write(ASEmitterTokens.SPACE);
- writeNewline(ASEmitterTokens.BLOCK_OPEN);
- if (p.getter != null)
- {
- write(ASEmitterTokens.GET);
- write(ASEmitterTokens.COLON);
- write(ASEmitterTokens.SPACE);
- write(ASEmitterTokens.FUNCTION);
- emitParameters(p.getter.getParameterNodes());
-
- emitDefinePropertyFunction(p.getter);
- }
- if (p.setter != null)
- {
- if (p.getter != null)
- writeNewline(ASEmitterTokens.COMMA);
-
- write(ASEmitterTokens.SET);
- write(ASEmitterTokens.COLON);
- write(ASEmitterTokens.SPACE);
- write(ASEmitterTokens.FUNCTION);
- emitParameters(p.setter.getParameterNodes());
-
- emitDefinePropertyFunction(p.setter);
- }
- write(ASEmitterTokens.BLOCK_CLOSE);
- }
- writeNewline(ASEmitterTokens.BLOCK_CLOSE);
- write(ASEmitterTokens.PAREN_CLOSE);
- write(ASEmitterTokens.SEMICOLON);
- }
- }
-
- private void loadImportIgnores(String doc)
- {
- ArrayList<String> ignoreList = new ArrayList<String>();
- String ignoreToken = JSFlexJSEmitterTokens.IGNORE_IMPORT.getToken();
- int index = doc.indexOf(ignoreToken);
- while (index != -1)
- {
- String ignorable = doc.substring(index + ignoreToken.length());
- int endIndex = ignorable.indexOf("\n");
- ignorable = ignorable.substring(0, endIndex);
- ignorable = ignorable.trim();
- ignoreList.add(ignorable);
- System.out.println("Found ignorable: " + ignorable);
- index = doc.indexOf(ignoreToken, index + endIndex);
- }
- this.getDocEmitter();
- docEmitter.classIgnoreList = ignoreList;
- }
-
- /*
- @Override
- public void emitInterface(IInterfaceNode node)
- {
- ICompilerProject project = getWalker().getProject();
-
- getDoc().emitInterfaceDoc(node, project);
-
- String qname = node.getQualifiedName();
- if (qname != null && !qname.equals(""))
- {
- write(formatQualifiedName(qname));
- write(ASEmitterTokens.SPACE);
- writeToken(ASEmitterTokens.EQUAL);
- write(ASEmitterTokens.FUNCTION);
- write(ASEmitterTokens.PAREN_OPEN);
- write(ASEmitterTokens.PAREN_CLOSE);
- write(ASEmitterTokens.SPACE);
- write(ASEmitterTokens.BLOCK_OPEN);
- writeNewline();
- write(ASEmitterTokens.BLOCK_CLOSE);
- write(ASEmitterTokens.SEMICOLON);
- }
-
- final IDefinitionNode[] members = node.getAllMemberDefinitionNodes();
- for (IDefinitionNode mnode : members)
- {
- boolean isAccessor = mnode.getNodeID() == ASTNodeID.GetterID
- || mnode.getNodeID() == ASTNodeID.SetterID;
-
- writeNewline();
- writeNewline();
- writeNewline();
-
- getDoc().emitInterfaceMemberDoc((IFunctionNode) mnode, project);
-
- write(formatQualifiedName(qname));
- write(ASEmitterTokens.MEMBER_ACCESS);
- write(JSEmitterTokens.PROTOTYPE);
- write(ASEmitterTokens.MEMBER_ACCESS);
- if (isAccessor)
- {
- writeGetSetPrefix(mnode.getNodeID() == ASTNodeID.GetterID);
- }
- write(mnode.getQualifiedName());
- write(ASEmitterTokens.SPACE);
- writeToken(ASEmitterTokens.EQUAL);
- write(ASEmitterTokens.FUNCTION);
- emitParameters(((IFunctionNode) mnode).getParameterNodes());
- write(ASEmitterTokens.SPACE);
- write(ASEmitterTokens.BLOCK_OPEN);
- write(ASEmitterTokens.BLOCK_CLOSE);
- write(ASEmitterTokens.SEMICOLON);
- }
- }
- */
-
@Override
public void emitField(IVariableNode node)
{
@@ -519,85 +210,64 @@ public class JSFlexJSEmitter extends JSGoogEmitter implements IJSFlexJSEmitter
}
if (node.getNodeID() == ASTNodeID.BindableVariableID)
{
- bindableVars.add(node.getName());
+ getModel().getBindableVars().add(node.getName());
}
}
- public void emitBindableVariables(IClassDefinition cdef)
+ public void emitBindableVarDefineProperty(String name, IClassDefinition cdef)
{
- if (bindableVars.size() > 0)
- {
- write(JSGoogEmitterTokens.OBJECT);
- write(ASEmitterTokens.MEMBER_ACCESS);
- write(JSEmitterTokens.DEFINE_PROPERTIES);
- write(ASEmitterTokens.PAREN_OPEN);
- String qname = cdef.getQualifiedName();
- write(formatQualifiedName(qname));
- write(ASEmitterTokens.MEMBER_ACCESS);
- write(JSEmitterTokens.PROTOTYPE);
- write(ASEmitterTokens.COMMA);
- write(ASEmitterTokens.SPACE);
- write("/** @lends {" + formatQualifiedName(qname) + ".prototype} */ ");
- writeNewline(ASEmitterTokens.BLOCK_OPEN);
-
- boolean firstTime = true;
- for (String varName : bindableVars)
- {
- if (firstTime)
- firstTime = false;
- else
- write(ASEmitterTokens.COMMA);
-
- emitBindableVarDefineProperty(varName, cdef);
- }
- writeNewline(ASEmitterTokens.BLOCK_CLOSE);
- write(ASEmitterTokens.PAREN_CLOSE);
- write(ASEmitterTokens.SEMICOLON);
-
- }
- }
-
- private void emitBindableVarDefineProperty(String name, IClassDefinition cdef)
- {
- // 'PropName': {
- writeNewline("/** @expose */");
- writeNewline(name +
- ASEmitterTokens.COLON.getToken() +
- ASEmitterTokens.SPACE.getToken() +
- ASEmitterTokens.BLOCK_OPEN.getToken());
- indentPush();
- writeNewline("/** @this {" + formatQualifiedName(cdef.getQualifiedName()) + "} */");
- writeNewline(ASEmitterTokens.GET.getToken() + ASEmitterTokens.COLON.getToken()
- + ASEmitterTokens.SPACE.getToken() + ASEmitterTokens.FUNCTION.getToken()
- + ASEmitterTokens.PAREN_OPEN.getToken() + ASEmitterTokens.PAREN_CLOSE.getToken()
- + ASEmitterTokens.SPACE.getToken() + ASEmitterTokens.BLOCK_OPEN.getToken());
- writeNewline(ASEmitterTokens.RETURN.getToken() + ASEmitterTokens.SPACE.getToken()
- + ASEmitterTokens.THIS.getToken() + ASEmitterTokens.MEMBER_ACCESS.getToken()
- + name + "_" + ASEmitterTokens.SEMICOLON.getToken());
- indentPop();
- writeNewline(ASEmitterTokens.BLOCK_CLOSE.getToken() + ASEmitterTokens.COMMA.getToken());
- writeNewline();
- writeNewline("/** @this {" + formatQualifiedName(cdef.getQualifiedName()) + "} */");
- writeNewline(ASEmitterTokens.SET.getToken() + ASEmitterTokens.COLON.getToken()
- + ASEmitterTokens.SPACE.getToken() + ASEmitterTokens.FUNCTION.getToken()
- + ASEmitterTokens.PAREN_OPEN.getToken() + "value" + ASEmitterTokens.PAREN_CLOSE.getToken()
- + ASEmitterTokens.SPACE.getToken() + ASEmitterTokens.BLOCK_OPEN.getToken());
- writeNewline("if (value != " + ASEmitterTokens.THIS.getToken()
- + ASEmitterTokens.MEMBER_ACCESS.getToken() + name + "_) {");
- writeNewline(" var oldValue = "
- + ASEmitterTokens.THIS.getToken() + ASEmitterTokens.MEMBER_ACCESS.getToken()
- + name + "_" + ASEmitterTokens.SEMICOLON.getToken());
- writeNewline(" " + ASEmitterTokens.THIS.getToken() + ASEmitterTokens.MEMBER_ACCESS.getToken()
- + name + "_ = value;");
- writeNewline(" this.dispatchEvent(org_apache_flex_events_ValueChangeEvent.createUpdateEvent(");
- writeNewline(" this, \"" + name + "\", oldValue, value));");
- writeNewline("}");
- write(ASEmitterTokens.BLOCK_CLOSE.getToken());
- write(ASEmitterTokens.BLOCK_CLOSE.getToken());
+ // 'PropName': {
+ writeNewline("/** @expose */");
+ writeNewline(name + ASEmitterTokens.COLON.getToken()
+ + ASEmitterTokens.SPACE.getToken()
+ + ASEmitterTokens.BLOCK_OPEN.getToken());
+ indentPush();
+ writeNewline("/** @this {"
+ + formatQualifiedName(cdef.getQualifiedName()) + "} */");
+ writeNewline(ASEmitterTokens.GET.getToken()
+ + ASEmitterTokens.COLON.getToken()
+ + ASEmitterTokens.SPACE.getToken()
+ + ASEmitterTokens.FUNCTION.getToken()
+ + ASEmitterTokens.PAREN_OPEN.getToken()
+ + ASEmitterTokens.PAREN_CLOSE.getToken()
+ + ASEmitterTokens.SPACE.getToken()
+ + ASEmitterTokens.BLOCK_OPEN.getToken());
+ writeNewline(ASEmitterTokens.RETURN.getToken()
+ + ASEmitterTokens.SPACE.getToken()
+ + ASEmitterTokens.THIS.getToken()
+ + ASEmitterTokens.MEMBER_ACCESS.getToken() + name + "_"
+ + ASEmitterTokens.SEMICOLON.getToken());
+ indentPop();
+ writeNewline(ASEmitterTokens.BLOCK_CLOSE.getToken()
+ + ASEmitterTokens.COMMA.getToken());
+ writeNewline();
+ writeNewline("/** @this {"
+ + formatQualifiedName(cdef.getQualifiedName()) + "} */");
+ writeNewline(ASEmitterTokens.SET.getToken()
+ + ASEmitterTokens.COLON.getToken()
+ + ASEmitterTokens.SPACE.getToken()
+ + ASEmitterTokens.FUNCTION.getToken()
+ + ASEmitterTokens.PAREN_OPEN.getToken() + "value"
+ + ASEmitterTokens.PAREN_CLOSE.getToken()
+ + ASEmitterTokens.SPACE.getToken()
+ + ASEmitterTokens.BLOCK_OPEN.getToken());
+ writeNewline("if (value != " + ASEmitterTokens.THIS.getToken()
+ + ASEmitterTokens.MEMBER_ACCESS.getToken() + name + "_) {");
+ writeNewline(" var oldValue = " + ASEmitterTokens.THIS.getToken()
+ + ASEmitterTokens.MEMBER_ACCESS.getToken() + name + "_"
+ + ASEmitterTokens.SEMICOLON.getToken());
+ writeNewline(" " + ASEmitterTokens.THIS.getToken()
+ + ASEmitterTokens.MEMBER_ACCESS.getToken() + name
+ + "_ = value;");
+ writeNewline(" this.dispatchEvent(org_apache_flex_events_ValueChangeEvent.createUpdateEvent(");
+ writeNewline(" this, \"" + name + "\", oldValue, value));");
+ writeNewline("}");
+ write(ASEmitterTokens.BLOCK_CLOSE.getToken());
+ write(ASEmitterTokens.BLOCK_CLOSE.getToken());
}
@Override
- protected void emitAccessors(IAccessorNode node)
+ public void emitAccessors(IAccessorNode node)
{
if (node.getNodeID() == ASTNodeID.GetterID)
{
@@ -608,73 +278,6 @@ public class JSFlexJSEmitter extends JSGoogEmitter implements IJSFlexJSEmitter
emitSetAccessor((ISetterNode) node);
}
}
-
- /*
- @Override
- public void emitMethod(IFunctionNode node)
- {
- FunctionNode fn = (FunctionNode) node;
- fn.parseFunctionBody(getProblems());
-
- ICompilerProject project = getWalker().getProject();
-
- getDoc().emitMethodDoc(node, project);
-
- boolean isConstructor = node.isConstructor();
-
- String qname = getTypeDefinition(node).getQualifiedName();
- if (qname != null && !qname.equals(""))
- {
- write(formatQualifiedName(qname));
- if (!isConstructor)
- {
- write(ASEmitterTokens.MEMBER_ACCESS);
- if (!fn.hasModifier(ASModifier.STATIC))
- {
- write(JSEmitterTokens.PROTOTYPE);
- write(ASEmitterTokens.MEMBER_ACCESS);
- }
- }
- }
-
- if (!isConstructor)
- emitMemberName(node);
-
- write(ASEmitterTokens.SPACE);
- writeToken(ASEmitterTokens.EQUAL);
- write(ASEmitterTokens.FUNCTION);
-
- emitParameters(node.getParameterNodes());
-
- boolean hasSuperClass = hasSuperClass(node);
-
- if (isConstructor && node.getScopedNode().getChildCount() == 0)
- {
- write(ASEmitterTokens.SPACE);
- write(ASEmitterTokens.BLOCK_OPEN);
- if (hasSuperClass)
- emitSuperCall(node, CONSTRUCTOR_EMPTY);
- writeNewline();
- write(ASEmitterTokens.BLOCK_CLOSE);
- }
-
- if (!isConstructor || node.getScopedNode().getChildCount() > 0)
- emitMethodScope(node.getScopedNode());
-
- if (isConstructor && hasSuperClass)
- {
- writeNewline(ASEmitterTokens.SEMICOLON);
- write(JSGoogEmitterTokens.GOOG_INHERITS);
- write(ASEmitterTokens.PAREN_OPEN);
- write(formatQualifiedName(qname));
- writeToken(ASEmitterTokens.COMMA);
- String sname = getSuperClassDefinition(node, project)
- .getQualifiedName();
- write(formatQualifiedName(sname));
- write(ASEmitterTokens.PAREN_CLOSE);
- }
- }
- */
@Override
public void emitFunctionCall(IFunctionCallNode node)
@@ -703,9 +306,8 @@ public class JSFlexJSEmitter extends JSGoogEmitter implements IJSFlexJSEmitter
def = node.getNameNode().resolve(project);
- isClassCast = (def instanceof ClassDefinition ||
- def instanceof InterfaceDefinition) &&
- !(NativeUtils.isJSNative(def.getBaseName()));
+ isClassCast = (def instanceof ClassDefinition || def instanceof InterfaceDefinition)
+ && !(NativeUtils.isJSNative(def.getBaseName()));
}
if (node.isNewExpression())
@@ -728,15 +330,18 @@ public class JSFlexJSEmitter extends JSGoogEmitter implements IJSFlexJSEmitter
{
if (def != null)
{
- boolean isInt = def.getBaseName().equals(IASGlobalFunctionConstants._int);
- if (isInt ||
- def.getBaseName().equals(IASGlobalFunctionConstants.trace) ||
- def.getBaseName().equals(IASGlobalFunctionConstants.uint))
+ boolean isInt = def.getBaseName().equals(
+ IASGlobalFunctionConstants._int);
+ if (isInt
+ || def.getBaseName().equals(
+ IASGlobalFunctionConstants.trace)
+ || def.getBaseName().equals(
+ IASGlobalFunctionConstants.uint))
{
write(JSFlexJSEmitterTokens.LANGUAGE_QNAME);
write(ASEmitterTokens.MEMBER_ACCESS);
if (isInt)
- write(JSFlexJSEmitterTokens.UNDERSCORE);
+ write(JSFlexJSEmitterTokens.UNDERSCORE);
}
}
getWalker().walk(node.getNameNode());
@@ -746,7 +351,8 @@ public class JSFlexJSEmitter extends JSGoogEmitter implements IJSFlexJSEmitter
}
else
{
- emitIsAs(node.getArgumentNodes()[0], node.getNameNode(), ASTNodeID.Op_AsID, true);
+ emitIsAs(node.getArgumentNodes()[0], node.getNameNode(),
+ ASTNodeID.Op_AsID, true);
}
}
else
@@ -761,9 +367,9 @@ public class JSFlexJSEmitter extends JSGoogEmitter implements IJSFlexJSEmitter
protected void emitSelfReference(IFunctionNode node)
{
// we don't want 'var self = this;' in FlexJS
- // unless there are anonymous functions
- if (node.containsAnonymousFunctions())
- super.emitSelfReference(node);
+ // unless there are anonymous functions
+ if (node.containsAnonymousFunctions())
+ super.emitSelfReference(node);
}
private boolean writeThis(IIdentifierNode node)
@@ -778,13 +384,15 @@ public class JSFlexJSEmitter extends JSGoogEmitter implements IJSFlexJSEmitter
IASNode firstChild = parentNode.getChild(0);
+ final IClassDefinition thisClass = getModel().getCurrentClass();
+
boolean identifierIsMemberAccess = parentNodeId == ASTNodeID.MemberAccessExpressionID;
if (classNode == null) // script in MXML and AS interface definitions
{
if (nodeDef instanceof ParameterDefinition)
return false;
-
+
if (nodeDef instanceof VariableDefinition)
{
IDefinition pdef = ((VariableDefinition) nodeDef).getParent();
@@ -825,8 +433,7 @@ public class JSFlexJSEmitter extends JSGoogEmitter implements IJSFlexJSEmitter
}
else
{
- if (nodeDef != null
- && !nodeDef.isInternal()
+ if (nodeDef != null && !nodeDef.isInternal()
&& isClassMember(nodeDef, classNode))
{
if (identifierIsMemberAccess)
@@ -876,7 +483,8 @@ public class JSFlexJSEmitter extends JSGoogEmitter implements IJSFlexJSEmitter
if (pdef == thisClass)
return true;
- IDefinition cdef = ((ClassDefinition) thisClass).resolveBaseClass(project);
+ IDefinition cdef = ((ClassDefinition) thisClass)
+ .resolveBaseClass(project);
while (cdef != null)
{
// needs to be a loop
@@ -904,8 +512,7 @@ public class JSFlexJSEmitter extends JSGoogEmitter implements IJSFlexJSEmitter
boolean emitName = true;
- if (nodeDef != null
- && nodeDef.isStatic())
+ if (nodeDef != null && nodeDef.isStatic())
{
String sname = nodeDef.getParent().getQualifiedName();
if (sname.length() > 0)
@@ -932,13 +539,14 @@ public class JSFlexJSEmitter extends JSGoogEmitter implements IJSFlexJSEmitter
if (writeThis(node))
{
- IFunctionObjectNode functionObjectNode = (IFunctionObjectNode) node.getParent()
- .getAncestorOfType(IFunctionObjectNode.class);
+ IFunctionObjectNode functionObjectNode = (IFunctionObjectNode) node
+ .getParent().getAncestorOfType(
+ IFunctionObjectNode.class);
if (functionObjectNode != null)
- write(JSGoogEmitterTokens.SELF);
+ write(JSGoogEmitterTokens.SELF);
else
- write(ASEmitterTokens.THIS);
+ write(ASEmitterTokens.THIS);
write(ASEmitterTokens.MEMBER_ACCESS);
}
@@ -955,13 +563,12 @@ public class JSFlexJSEmitter extends JSGoogEmitter implements IJSFlexJSEmitter
}
}
-
//IDefinition parentDef = (nodeDef != null) ? nodeDef.getParent() : null;
//boolean isNative = (parentDef != null)
// && NativeUtils.isNative(parentDef.getBaseName());
if (emitName)
{
- if (nodeDef != null)
+ if (nodeDef != null)
write(formatQualifiedName(nodeDef.getQualifiedName()));
else
write(node.getName());
@@ -969,8 +576,8 @@ public class JSFlexJSEmitter extends JSGoogEmitter implements IJSFlexJSEmitter
}
//--------------------------------------------------------------------------
-
- @Override
+
+ @Override
protected void emitSuperCall(IASNode node, String type)
{
IFunctionNode fnode = (node instanceof IFunctionNode) ? (IFunctionNode) node
@@ -978,6 +585,8 @@ public class JSFlexJSEmitter extends JSGoogEmitter implements IJSFlexJSEmitter
IFunctionCallNode fcnode = (node instanceof IFunctionCallNode) ? (FunctionCallNode) node
: null;
+ final IClassDefinition thisClass = getModel().getCurrentClass();
+
if (type == SUPER_FUNCTION_CALL)
{
if (fnode == null)
@@ -987,145 +596,81 @@ public class JSFlexJSEmitter extends JSGoogEmitter implements IJSFlexJSEmitter
if (fnode != null && fnode.isConstructor() && !hasSuperClass(fnode))
return;
- IClassNode cnode = (IClassNode) node
- .getAncestorOfType(IClassNode.class);
-
- // ToDo (erikdebruin): add VF2JS conditional -> only use check during full SDK compilation
- if (cnode == null && MXMLJSC.jsOutputType == JSOutputType.VF2JS)
- return;
-
- if (fnode != null && (fnode.getNodeID() == ASTNodeID.GetterID
- || fnode.getNodeID() == ASTNodeID.SetterID))
- {
- write(JSFlexJSEmitterTokens.LANGUAGE_QNAME);
- write(ASEmitterTokens.MEMBER_ACCESS);
- if (fnode.getNodeID() == ASTNodeID.GetterID)
- write(JSFlexJSEmitterTokens.SUPERGETTER);
- else
- write(JSFlexJSEmitterTokens.SUPERSETTER);
- write(ASEmitterTokens.PAREN_OPEN);
- if (cnode == null && thisClass != null)
- write(formatQualifiedName(thisClass.getQualifiedName()));
- else
- write(formatQualifiedName(cnode.getQualifiedName()));
- writeToken(ASEmitterTokens.COMMA);
- write(ASEmitterTokens.THIS);
- writeToken(ASEmitterTokens.COMMA);
- write(ASEmitterTokens.SINGLE_QUOTE);
- write(fnode.getName());
- write(ASEmitterTokens.SINGLE_QUOTE);
-
- IASNode[] anodes = null;
- boolean writeArguments = false;
- if (fcnode != null)
- {
- anodes = fcnode.getArgumentNodes();
-
- writeArguments = anodes.length > 0;
- }
- else if (fnode != null && fnode.isConstructor())
- {
- anodes = fnode.getParameterNodes();
-
- writeArguments = (anodes != null && anodes.length > 0);
- }
- else if (node instanceof IFunctionNode && node instanceof BinaryOperatorAssignmentNode)
- {
- BinaryOperatorAssignmentNode bnode = (BinaryOperatorAssignmentNode) node;
-
- IFunctionNode pnode = (IFunctionNode) bnode.getAncestorOfType(IFunctionNode.class);
-
- if (pnode.getNodeID() == ASTNodeID.SetterID)
- {
- writeToken(ASEmitterTokens.COMMA);
- getWalker().walk(bnode.getRightOperandNode());
- }
- }
-
- if (writeArguments)
- {
- int len = anodes.length;
- for (int i = 0; i < len; i++)
- {
- writeToken(ASEmitterTokens.COMMA);
-
- getWalker().walk(anodes[i]);
- }
- }
-
- write(ASEmitterTokens.PAREN_CLOSE);
- return;
- }
- }
- super.emitSuperCall(node, type);
- }
-
- /*
- @Override
- protected void emitDefaultParameterCodeBlock(IFunctionNode node)
- {
- IParameterNode[] pnodes = node.getParameterNodes();
- if (pnodes.length == 0)
- return;
-
- Map<Integer, IParameterNode> defaults = getDefaults(pnodes);
+ IClassNode cnode = (IClassNode) node
+ .getAncestorOfType(IClassNode.class);
- if (defaults != null)
- {
- final StringBuilder code = new StringBuilder();
+ // ToDo (erikdebruin): add VF2JS conditional -> only use check during full SDK compilation
+ if (cnode == null && MXMLJSC.jsOutputType == JSOutputType.VF2JS)
+ return;
- if (!hasBody(node))
+ if (fnode != null
+ && (fnode.getNodeID() == ASTNodeID.GetterID || fnode
+ .getNodeID() == ASTNodeID.SetterID))
{
- indentPush();
- write(JSFlexJSEmitterTokens.INDENT);
- }
+ write(JSFlexJSEmitterTokens.LANGUAGE_QNAME);
+ write(ASEmitterTokens.MEMBER_ACCESS);
+ if (fnode.getNodeID() == ASTNodeID.GetterID)
+ write(JSFlexJSEmitterTokens.SUPERGETTER);
+ else
+ write(JSFlexJSEmitterTokens.SUPERSETTER);
+ write(ASEmitterTokens.PAREN_OPEN);
+ if (cnode == null && thisClass != null)
+ write(formatQualifiedName(thisClass.getQualifiedName()));
+ else
+ write(formatQualifiedName(cnode.getQualifiedName()));
+ writeToken(ASEmitterTokens.COMMA);
+ write(ASEmitterTokens.THIS);
+ writeToken(ASEmitterTokens.COMMA);
+ write(ASEmitterTokens.SINGLE_QUOTE);
+ write(fnode.getName());
+ write(ASEmitterTokens.SINGLE_QUOTE);
+
+ IASNode[] anodes = null;
+ boolean writeArguments = false;
+ if (fcnode != null)
+ {
+ anodes = fcnode.getArgumentNodes();
- List<IParameterNode> parameters = new ArrayList<IParameterNode>(
- defaults.values());
+ writeArguments = anodes.length > 0;
+ }
+ else if (fnode != null && fnode.isConstructor())
+ {
+ anodes = fnode.getParameterNodes();
- for (int i = 0, n = parameters.size(); i < n; i++)
- {
- IParameterNode pnode = parameters.get(i);
+ writeArguments = (anodes != null && anodes.length > 0);
+ }
+ else if (node instanceof IFunctionNode
+ && node instanceof BinaryOperatorAssignmentNode)
+ {
+ BinaryOperatorAssignmentNode bnode = (BinaryOperatorAssignmentNode) node;
- if (pnode != null)
+ IFunctionNode pnode = (IFunctionNode) bnode
+ .getAncestorOfType(IFunctionNode.class);
+
+ if (pnode.getNodeID() == ASTNodeID.SetterID)
+ {
+ writeToken(ASEmitterTokens.COMMA);
+ getWalker().walk(bnode.getRightOperandNode());
+ }
+ }
+
+ if (writeArguments)
{
- code.setLength(0);
-
- // x = typeof y !== 'undefined' ? y : z;\n
- code.append(pnode.getName());
- code.append(ASEmitterTokens.SPACE.getToken());
- code.append(ASEmitterTokens.EQUAL.getToken());
- code.append(ASEmitterTokens.SPACE.getToken());
- code.append(ASEmitterTokens.TYPEOF.getToken());
- code.append(ASEmitterTokens.SPACE.getToken());
- code.append(pnode.getName());
- code.append(ASEmitterTokens.SPACE.getToken());
- code.append(ASEmitterTokens.STRICT_NOT_EQUAL.getToken());
- code.append(ASEmitterTokens.SPACE.getToken());
- code.append(ASEmitterTokens.SINGLE_QUOTE.getToken());
- code.append(ASEmitterTokens.UNDEFINED.getToken());
- code.append(ASEmitterTokens.SINGLE_QUOTE.getToken());
- code.append(ASEmitterTokens.SPACE.getToken());
- code.append(ASEmitterTokens.TERNARY.getToken());
- code.append(ASEmitterTokens.SPACE.getToken());
- code.append(pnode.getName());
- code.append(ASEmitterTokens.SPACE.getToken());
- code.append(ASEmitterTokens.COLON.getToken());
- code.append(ASEmitterTokens.SPACE.getToken());
- code.append(pnode.getDefaultValue());
- code.append(ASEmitterTokens.SEMICOLON.getToken());
-
- write(code.toString());
-
- if (i == n - 1 && !hasBody(node))
- indentPop();
+ int len = anodes.length;
+ for (int i = 0; i < len; i++)
+ {
+ writeToken(ASEmitterTokens.COMMA);
- writeNewline();
+ getWalker().walk(anodes[i]);
+ }
}
+
+ write(ASEmitterTokens.PAREN_CLOSE);
+ return;
}
}
+ super.emitSuperCall(node, type);
}
- */
@Override
public void emitBinaryOperator(IBinaryOperatorNode node)
@@ -1138,9 +683,10 @@ public class JSFlexJSEmitter extends JSGoogEmitter implements IJSFlexJSEmitter
{
super.emitBinaryOperator(node);
}
- else */ if (id == ASTNodeID.Op_IsID || id == ASTNodeID.Op_AsID)
+ else */if (id == ASTNodeID.Op_IsID || id == ASTNodeID.Op_AsID)
{
- emitIsAs(node.getLeftOperandNode(), node.getRightOperandNode(), id, false);
+ emitIsAs(node.getLeftOperandNode(), node.getRightOperandNode(), id,
+ false);
}
else if (id == ASTNodeID.Op_InstanceOfID)
{
@@ -1148,7 +694,7 @@ public class JSFlexJSEmitter extends JSGoogEmitter implements IJSFlexJSEmitter
write(ASEmitterTokens.SPACE);
writeToken(ASEmitterTokens.INSTANCEOF);
-
+
IDefinition dnode = (node.getRightOperandNode()).resolve(project);
if (dnode != null)
write(formatQualifiedName(dnode.getQualifiedName()));
@@ -1162,56 +708,57 @@ public class JSFlexJSEmitter extends JSGoogEmitter implements IJSFlexJSEmitter
{
IASNode lnode = leftSide.getChild(0);
IASNode rnode = leftSide.getChild(1);
- IDefinition rnodeDef = ((IIdentifierNode) rnode).resolve(getWalker().getProject());
- if (lnode.getNodeID() == ASTNodeID.SuperID &&
- rnodeDef instanceof AccessorDefinition)
+ IDefinition rnodeDef = ((IIdentifierNode) rnode)
+ .resolve(getWalker().getProject());
+ if (lnode.getNodeID() == ASTNodeID.SuperID
+ && rnodeDef instanceof AccessorDefinition)
{
String op = node.getOperator().getOperatorText();
- boolean isAssignment = op.contains("=") && !op.contains("==") &&
- !(op.startsWith("<") ||
- op.startsWith(">") ||
- op.startsWith("!"));
- if (isAssignment)
- {
+ boolean isAssignment = op.contains("=")
+ && !op.contains("==")
+ && !(op.startsWith("<") || op.startsWith(">") || op
+ .startsWith("!"));
+ if (isAssignment)
+ {
write(JSFlexJSEmitterTokens.LANGUAGE_QNAME);
write(ASEmitterTokens.MEMBER_ACCESS);
- write(JSFlexJSEmitterTokens.SUPERSETTER);
- write(ASEmitterTokens.PAREN_OPEN);
- IClassNode cnode = (IClassNode) node
- .getAncestorOfType(IClassNode.class);
- write(formatQualifiedName(cnode.getQualifiedName()));
- writeToken(ASEmitterTokens.COMMA);
- write(ASEmitterTokens.THIS);
- writeToken(ASEmitterTokens.COMMA);
- write(ASEmitterTokens.SINGLE_QUOTE);
- write(rnodeDef.getBaseName());
- write(ASEmitterTokens.SINGLE_QUOTE);
- writeToken(ASEmitterTokens.COMMA);
-
- if (op.length() > 1) // += and things like that
- {
+ write(JSFlexJSEmitterTokens.SUPERSETTER);
+ write(ASEmitterTokens.PAREN_OPEN);
+ IClassNode cnode = (IClassNode) node
+ .getAncestorOfType(IClassNode.class);
+ write(formatQualifiedName(cnode.getQualifiedName()));
+ writeToken(ASEmitterTokens.COMMA);
+ write(ASEmitterTokens.THIS);
+ writeToken(ASEmitterTokens.COMMA);
+ write(ASEmitterTokens.SINGLE_QUOTE);
+ write(rnodeDef.getBaseName());
+ write(ASEmitterTokens.SINGLE_QUOTE);
+ writeToken(ASEmitterTokens.COMMA);
+
+ if (op.length() > 1) // += and things like that
+ {
write(JSFlexJSEmitterTokens.LANGUAGE_QNAME);
write(ASEmitterTokens.MEMBER_ACCESS);
- write(JSFlexJSEmitterTokens.SUPERSETTER);
- write(ASEmitterTokens.PAREN_OPEN);
- write(formatQualifiedName(cnode.getQualifiedName()));
- writeToken(ASEmitterTokens.COMMA);
- write(ASEmitterTokens.THIS);
- writeToken(ASEmitterTokens.COMMA);
- write(ASEmitterTokens.SINGLE_QUOTE);
- write(rnodeDef.getBaseName());
- write(ASEmitterTokens.SINGLE_QUOTE);
- write(ASEmitterTokens.PAREN_CLOSE);
- write(op.substring(0, 1));
- }
+ write(JSFlexJSEmitterTokens.SUPERSETTER);
+ write(ASEmitterTokens.PAREN_OPEN);
+ write(formatQualifiedName(cnode.getQualifiedName()));
+ writeToken(ASEmitterTokens.COMMA);
+ write(ASEmitterTokens.THIS);
+ writeToken(ASEmitterTokens.COMMA);
+ write(ASEmitterTokens.SINGLE_QUOTE);
+ write(rnodeDef.getBaseName());
+ write(ASEmitterTokens.SINGLE_QUOTE);
+ write(ASEmitterTokens.PAREN_CLOSE);
+ write(op.substring(0, 1));
+ }
getWalker().walk(node.getRightOperandNode());
- write(ASEmitterTokens.PAREN_CLOSE);
+ write(ASEmitterTokens.PAREN_CLOSE);
return;
- }
+ }
}
}
-
+
super.emitBinaryOperator(node);
/*
IExpressionNode leftSide = node.getLeftOperandNode();
@@ -1279,47 +826,51 @@ public class JSFlexJSEmitter extends JSGoogEmitter implements IJSFlexJSEmitter
}
}
- private void emitIsAs(IExpressionNode left, IExpressionNode right,
+ private void emitIsAs(IExpressionNode left, IExpressionNode right,
ASTNodeID id, boolean coercion)
{
- // project is null in unit tests
+ // project is null in unit tests
IDefinition dnode = project != null ? (right).resolve(project) : null;
- if (id != ASTNodeID.Op_IsID && dnode != null)
- {
- // find the function node
+ if (id != ASTNodeID.Op_IsID && dnode != null)
+ {
+ // find the function node
IFunctionNode functionNode = (IFunctionNode) left
- .getAncestorOfType(IFunctionNode.class);
+ .getAncestorOfType(IFunctionNode.class);
if (functionNode != null) // can be null in synthesized binding code
{
- ASDocComment asDoc = (ASDocComment) functionNode.getASDocComment();
- if (asDoc != null)
- {
- String asDocString = asDoc.commentNoEnd();
- String ignoreToken = JSFlexJSEmitterTokens.IGNORE_COERCION.getToken();
- boolean ignore = false;
- int ignoreIndex = asDocString.indexOf(ignoreToken);
- while (ignoreIndex != -1)
- {
- String ignorable = asDocString.substring(ignoreIndex + ignoreToken.length());
- int endIndex = ignorable.indexOf("\n");
- ignorable = ignorable.substring(0, endIndex);
- ignorable = ignorable.trim();
- String rightSide = dnode.getQualifiedName();
- if (ignorable.equals(rightSide))
- {
- ignore = true;
- break;
- }
- ignoreIndex = asDocString.indexOf(ignoreToken, ignoreIndex + ignoreToken.length());
- }
- if (ignore)
- {
- getWalker().walk(left);
- return;
- }
- }
+ ASDocComment asDoc = (ASDocComment) functionNode
+ .getASDocComment();
+ if (asDoc != null)
+ {
+ String asDocString = asDoc.commentNoEnd();
+ String ignoreToken = JSFlexJSEmitterTokens.IGNORE_COERCION
+ .getToken();
+ boolean ignore = false;
+ int ignoreIndex = asDocString.indexOf(ignoreToken);
+ while (ignoreIndex != -1)
+ {
+ String ignorable = asDocString.substring(ignoreIndex
+ + ignoreToken.length());
+ int endIndex = ignorable.indexOf("\n");
+ ignorable = ignorable.substring(0, endIndex);
+ ignorable = ignorable.trim();
+ String rightSide = dnode.getQualifiedName();
+ if (ignorable.equals(rightSide))
+ {
+ ignore = true;
+ break;
+ }
+ ignoreIndex = asDocString.indexOf(ignoreToken,
+ ignoreIndex + ignoreToken.length());
+ }
+ if (ignore)
+ {
+ getWalker().walk(left);
+ return;
+ }
+ }
}
- }
+ }
write(JSFlexJSEmitterTokens.LANGUAGE_QNAME);
write(ASEmitterTokens.MEMBER_ACCESS);
if (id == ASTNodeID.Op_IsID)
@@ -1334,22 +885,22 @@ public class JSFlexJSEmitter extends JSGoogEmitter implements IJSFlexJSEmitter
write(formatQualifiedName(dnode.getQualifiedName()));
else
getWalker().walk(right);
-
- if (coercion)
+
+ if (coercion)
{
writeToken(ASEmitterTokens.COMMA);
write(ASEmitterTokens.TRUE);
}
-
+
write(ASEmitterTokens.PAREN_CLOSE);
}
-
+
@Override
public void emitMemberAccessExpression(IMemberAccessExpressionNode node)
{
if (ASNodeUtils.hasParenOpen(node))
write(ASEmitterTokens.PAREN_OPEN);
-
+
IASNode leftNode = node.getLeftOperandNode();
IASNode rightNode = node.getRightOperandNode();
@@ -1365,16 +916,16 @@ public class JSFlexJSEmitter extends JSGoogEmitter implements IJSFlexJSEmitter
if (!isStatic)
{
if (!(leftNode instanceof ILanguageIdentifierNode && ((ILanguageIdentifierNode) leftNode)
- .getKind() == ILanguageIdentifierNode.LanguageIdentifierKind.THIS))
+ .getKind() == ILanguageIdentifierNode.LanguageIdentifierKind.THIS))
{
IDefinition rightDef = null;
if (rightNode instanceof IIdentifierNode)
- rightDef = ((IIdentifierNode) rightNode).resolve(project);
-
- if (rightNode instanceof UnaryOperatorAtNode)
+ rightDef = ((IIdentifierNode) rightNode).resolve(project);
+
+ if (rightNode instanceof UnaryOperatorAtNode)
{
- // ToDo (erikdebruin): properly handle E4X
-
+ // ToDo (erikdebruin): properly handle E4X
+
write(ASEmitterTokens.THIS);
write(ASEmitterTokens.MEMBER_ACCESS);
getWalker().walk(node.getLeftOperandNode());
@@ -1385,10 +936,10 @@ public class JSFlexJSEmitter extends JSGoogEmitter implements IJSFlexJSEmitter
write(ASEmitterTokens.SQUARE_CLOSE);
continueWalk = false;
}
- else if (node.getNodeID() == ASTNodeID.Op_DescendantsID)
- {
- // ToDo (erikdebruin): properly handle E4X
-
+ else if (node.getNodeID() == ASTNodeID.Op_DescendantsID)
+ {
+ // ToDo (erikdebruin): properly handle E4X
+
write(ASEmitterTokens.THIS);
write(ASEmitterTokens.MEMBER_ACCESS);
getWalker().walk(node.getLeftOperandNode());
@@ -1398,118 +949,105 @@ public class JSFlexJSEmitter extends JSGoogEmitter implements IJSFlexJSEmitter
write(ASEmitterTokens.SINGLE_QUOTE);
write(ASEmitterTokens.SQUARE_CLOSE);
continueWalk = false;
- }
- else if (leftNode.getNodeID() != ASTNodeID.SuperID)
+ }
+ else if (leftNode.getNodeID() != ASTNodeID.SuperID)
{
getWalker().walk(node.getLeftOperandNode());
write(node.getOperator().getOperatorText());
}
- else if (leftNode.getNodeID() == ASTNodeID.SuperID &&
- (rightNode.getNodeID() == ASTNodeID.GetterID ||
- (rightDef != null && rightDef instanceof AccessorDefinition)))
- {
- // setter is handled in binaryOperator
+ else if (leftNode.getNodeID() == ASTNodeID.SuperID
+ && (rightNode.getNodeID() == ASTNodeID.GetterID || (rightDef != null && rightDef instanceof AccessorDefinition)))
+ {
+ // setter is handled in binaryOperator
write(JSFlexJSEmitterTokens.LANGUAGE_QNAME);
write(ASEmitterTokens.MEMBER_ACCESS);
- write(JSFlexJSEmitterTokens.SUPERGETTER);
- write(ASEmitterTokens.PAREN_OPEN);
- IClassNode cnode = (IClassNode) node
- .getAncestorOfType(IClassNode.class);
- write(formatQualifiedName(cnode.getQualifiedName()));
- writeToken(ASEmitterTokens.COMMA);
- write(ASEmitterTokens.THIS);
- writeToken(ASEmitterTokens.COMMA);
- write(ASEmitterTokens.SINGLE_QUOTE);
- if (rightDef != null)
- write(rightDef.getBaseName());
- else
- write(((GetterNode)rightNode).getName());
- write(ASEmitterTokens.SINGLE_QUOTE);
- write(ASEmitterTokens.PAREN_CLOSE);
- continueWalk = false;
- }
+ write(JSFlexJSEmitterTokens.SUPERGETTER);
+ write(ASEmitterTokens.PAREN_OPEN);
+ IClassNode cnode = (IClassNode) node
+ .getAncestorOfType(IClassNode.class);
+ write(formatQualifiedName(cnode.getQualifiedName()));
+ writeToken(ASEmitterTokens.COMMA);
+ write(ASEmitterTokens.THIS);
+ writeToken(ASEmitterTokens.COMMA);
+ write(ASEmitterTokens.SINGLE_QUOTE);
+ if (rightDef != null)
+ write(rightDef.getBaseName());
+ else
+ write(((GetterNode) rightNode).getName());
+ write(ASEmitterTokens.SINGLE_QUOTE);
+ write(ASEmitterTokens.PAREN_CLOSE);
+ continueWalk = false;
+ }
}
else
{
write(ASEmitterTokens.THIS);
write(node.getOperator().getOperatorText());
}
-
+
}
-
+
if (continueWalk)
- getWalker().walk(node.getRightOperandNode());
-
+ getWalker().walk(node.getRightOperandNode());
+
if (ASNodeUtils.hasParenClose(node))
write(ASEmitterTokens.PAREN_CLOSE);
}
- /*
- private static ITypeDefinition getTypeDefinition(IDefinitionNode node)
- {
- ITypeNode tnode = (ITypeNode) node.getAncestorOfType(ITypeNode.class);
- return (ITypeDefinition) tnode.getDefinition();
- }
-
- private static IClassDefinition getSuperClassDefinition(
- IDefinitionNode node, ICompilerProject project)
- {
- IClassDefinition parent = (IClassDefinition) node.getDefinition()
- .getParent();
- IClassDefinition superClass = parent.resolveBaseClass(project);
- return superClass;
- }
- */
-
@Override
public void emitGetAccessor(IGetterNode node)
{
ModifiersSet modifierSet = node.getDefinition().getModifiers();
- boolean isStatic = (modifierSet != null && modifierSet.hasModifier(ASModifier.STATIC));
- HashMap<String, PropertyNodes> map = isStatic ? staticPropertyMap : propertyMap;
- String name = node.getName();
- PropertyNodes p = map.get(name);
- if (p == null)
- {
- p = new PropertyNodes();
- map.put(name, p);
- }
- p.getter = node;
+ boolean isStatic = (modifierSet != null && modifierSet
+ .hasModifier(ASModifier.STATIC));
+ HashMap<String, PropertyNodes> map = isStatic ? getModel()
+ .getStaticPropertyMap() : getModel().getPropertyMap();
+ String name = node.getName();
+ PropertyNodes p = map.get(name);
+ if (p == null)
+ {
+ p = new PropertyNodes();
+ map.put(name, p);
+ }
+ p.getter = node;
FunctionNode fn = (FunctionNode) node;
- fn.parseFunctionBody(getProblems());
+ fn.parseFunctionBody(getProblems());
}
@Override
public void emitSetAccessor(ISetterNode node)
{
ModifiersSet modifierSet = node.getDefinition().getModifiers();
- boolean isStatic = (modifierSet != null && modifierSet.hasModifier(ASModifier.STATIC));
- HashMap<String, PropertyNodes> map = isStatic ? staticPropertyMap : propertyMap;
- String name = node.getName();
- PropertyNodes p = map.get(name);
- if (p == null)
- {
- p = new PropertyNodes();
- map.put(name, p);
- }
- p.setter = node;
+ boolean isStatic = (modifierSet != null && modifierSet
+ .hasModifier(ASModifier.STATIC));
+ HashMap<String, PropertyNodes> map = isStatic ? getModel()
+ .getStaticPropertyMap() : getModel().getPropertyMap();
+ String name = node.getName();
+ PropertyNodes p = map.get(name);
+ if (p == null)
+ {
+ p = new PropertyNodes();
+ map.put(name, p);
+ }
+ p.setter = node;
FunctionNode fn = (FunctionNode) node;
fn.parseFunctionBody(getProblems());
-
+
boolean isBindableSetter = false;
if (node instanceof SetterNode)
{
- IMetaInfo[] metaInfos = null;
- metaInfos = node.getMetaInfos();
- for (IMetaInfo metaInfo : metaInfos)
- {
- name = metaInfo.getTagName();
- if (name.equals("Bindable") && metaInfo.getAllAttributes().length == 0)
- {
- isBindableSetter = true;
- break;
- }
- }
+ IMetaInfo[] metaInfos = null;
+ metaInfos = node.getMetaInfos();
+ for (IMetaInfo metaInfo : metaInfos)
+ {
+ name = metaInfo.getTagName();
+ if (name.equals("Bindable")
+ && metaInfo.getAllAttributes().length == 0)
+ {
+ isBindableSetter = true;
+ break;
+ }
+ }
}
if (isBindableSetter)
{
@@ -1533,12 +1071,12 @@ public class JSFlexJSEmitter extends JSGoogEmitter implements IJSFlexJSEmitter
emitMethodScope(node.getScopedNode());
}
}
-
+
@Override
protected void emitObjectDefineProperty(IAccessorNode node)
{
- //TODO: ajh is this method needed anymore?
-
+ //TODO: ajh is this method needed anymore?
+
FunctionNode fn = (FunctionNode) node;
fn.parseFunctionBody(getProblems());
@@ -1548,21 +1086,22 @@ public class JSFlexJSEmitter extends JSGoogEmitter implements IJSFlexJSEmitter
// ToDo (erikdebruin): add VF2JS conditional -> only use check during full SDK compilation
if (type == null)
return;
-
+
boolean isBindableSetter = false;
if (node instanceof SetterNode)
{
- IMetaInfo[] metaInfos = null;
- metaInfos = node.getMetaInfos();
- for (IMetaInfo metaInfo : metaInfos)
- {
- String name = metaInfo.getTagName();
- if (name.equals("Bindable") && metaInfo.getAllAttributes().length == 0)
- {
- isBindableSetter = true;
- break;
- }
- }
+ IMetaInfo[] metaInfos = null;
+ metaInfos = node.getMetaInfos();
+ for (IMetaInfo metaInfo : metaInfos)
+ {
+ String name = metaInfo.getTagName();
+ if (name.equals("Bindable")
+ && metaInfo.getAllAttributes().length == 0)
+ {
+ isBindableSetter = true;
+ break;
+ }
+ }
}
if (isBindableSetter)
{
@@ -1585,24 +1124,25 @@ public class JSFlexJSEmitter extends JSGoogEmitter implements IJSFlexJSEmitter
}
super.emitObjectDefineProperty(node);
}
-
+
@Override
- protected void emitDefinePropertyFunction(IAccessorNode node)
+ public void emitDefinePropertyFunction(IAccessorNode node)
{
boolean isBindableSetter = false;
if (node instanceof SetterNode)
{
- IMetaInfo[] metaInfos = null;
- metaInfos = node.getMetaInfos();
- for (IMetaInfo metaInfo : metaInfos)
- {
- String name = metaInfo.getTagName();
- if (name.equals("Bindable") && metaInfo.getAllAttributes().length == 0)
- {
- isBindableSetter = true;
- break;
- }
- }
+ IMetaInfo[] metaInfos = null;
+ metaInfos = node.getMetaInfos();
+ for (IMetaInfo metaInfo : metaInfos)
+ {
+ String name = metaInfo.getTagName();
+ if (name.equals("Bindable")
+ && metaInfo.getAllAttributes().length == 0)
+ {
+ isBindableSetter = true;
+ break;
+ }
+ }
}
if (isBindableSetter)
{
@@ -1623,7 +1163,7 @@ public class JSFlexJSEmitter extends JSGoogEmitter implements IJSFlexJSEmitter
//write(ASEmitterTokens.PAREN_OPEN);
//write(ASEmitterTokens.PAREN_CLOSE);
writeNewline(ASEmitterTokens.SEMICOLON);
-
+
// add change check
write(ASEmitterTokens.IF);
write(ASEmitterTokens.SPACE);
@@ -1646,37 +1186,27 @@ public class JSFlexJSEmitter extends JSGoogEmitter implements IJSFlexJSEmitter
write(params[0].getName());
write(ASEmitterTokens.PAREN_CLOSE);
writeNewline(ASEmitterTokens.SEMICOLON);
-
- // add dispatch of change event
+
+ // add dispatch of change event
writeNewline(" this.dispatchEvent(org_apache_flex_events_ValueChangeEvent.createUpdateEvent(");
- writeNewline(" this, \"" + node.getName() + "\", oldValue, " + params[0].getName() + "));");
+ writeNewline(" this, \"" + node.getName()
+ + "\", oldValue, " + params[0].getName() + "));");
write(ASEmitterTokens.BLOCK_CLOSE);
//writeNewline(ASEmitterTokens.SEMICOLON);
writeNewline();
writeNewline();
}
else
- super.emitDefinePropertyFunction(node);
- }
-
- /*
- private void writeGetSetPrefix(boolean isGet)
- {
- if (isGet)
- write(ASEmitterTokens.GET);
- else
- write(ASEmitterTokens.SET);
- write("_");
+ super.emitDefinePropertyFunction(node);
}
- */
-
+
private JSFlexJSDocEmitter docEmitter = null;
-
+
@Override
public IDocEmitter getDocEmitter()
{
if (docEmitter == null)
- docEmitter = new JSFlexJSDocEmitter(this);
+ docEmitter = new JSFlexJSDocEmitter(this);
return docEmitter;
}
@@ -1696,7 +1226,7 @@ public class JSFlexJSEmitter extends JSGoogEmitter implements IJSFlexJSEmitter
writeNewline(" * @suppress {checkTypes}");
writeNewline(" */");
writeNewline();
-
+
/* goog.provide('x');\n\n */
write(JSGoogEmitterTokens.GOOG_PROVIDE);
write(ASEmitterTokens.PAREN_OPEN);
@@ -1713,7 +1243,7 @@ public class JSFlexJSEmitter extends JSGoogEmitter implements IJSFlexJSEmitter
{
PackageScope containedScope = (PackageScope) definition
.getContainedScope();
-
+
ArrayList<String> writtenRequires = new ArrayList<String>();
ITypeDefinition type = findType(containedScope.getAllLocalDefinitions());
@@ -1723,29 +1253,32 @@ public class JSFlexJSEmitter extends JSGoogEmitter implements IJSFlexJSEmitter
ITypeNode typeNode = type.getNode();
if (typeNode instanceof ClassNode)
{
- ClassNode classNode = (ClassNode) typeNode;
- if (classNode != null)
- {
- ASDocComment asDoc = (ASDocComment) classNode.getASDocComment();
- if (asDoc != null)
- {
- String asDocString = asDoc.commentNoEnd();
- String ignoreToken = JSFlexJSEmitterTokens.IGNORE_IMPORT.getToken();
- int ignoreIndex = asDocString.indexOf(ignoreToken);
- while (ignoreIndex != -1)
- {
- String ignorable = asDocString.substring(ignoreIndex + ignoreToken.length());
- int endIndex = ignorable.indexOf("\n");
- ignorable = ignorable.substring(0, endIndex);
- ignorable = ignorable.trim();
- // pretend we've already written the goog.requires for this
- writtenRequires.add(ignorable);
- ignoreIndex = asDocString.indexOf(ignoreToken, ignoreIndex + ignoreToken.length());
- }
- }
- }
+ ClassNode classNode = (ClassNode) typeNode;
+ if (classNode != null)
+ {
+ ASDocComment asDoc = (ASDocComment) classNode.getASDocComment();
+ if (asDoc != null)
+ {
+ String asDocString = asDoc.commentNoEnd();
+ String ignoreToken = JSFlexJSEmitterTokens.IGNORE_IMPORT
+ .getToken();
+ int ignoreIndex = asDocString.indexOf(ignoreToken);
+ while (ignoreIndex != -1)
+ {
+ String ignorable = asDocString.substring(ignoreIndex
+ + ignoreToken.length());
+ int endIndex = ignorable.indexOf("\n");
+ ignorable = ignorable.substring(0, endIndex);
+ ignorable = ignorable.trim();
+ // pretend we've already written the goog.requires for this
+ writtenRequires.add(ignorable);
+ ignoreIndex = asDocString.indexOf(ignoreToken,
+ ignoreIndex + ignoreToken.length());
+ }
+ }
+ }
}
-
+
if (project == null)
project = getWalker().getProject();
@@ -1784,14 +1317,14 @@ public class JSFlexJSEmitter extends JSGoogEmitter implements IJSFlexJSEmitter
write(ASEmitterTokens.SINGLE_QUOTE);
write(ASEmitterTokens.PAREN_CLOSE);
writeNewline(ASEmitterTokens.SEMICOLON);
-
+
writtenRequires.add(imp);
-
+
emitsRequires = true;
}
}
}
-
+
boolean emitsInterfaces = false;
if (interfacesList != null)
{
@@ -1799,25 +1332,25 @@ public class JSFlexJSEmitter extends JSGoogEmitter implements IJSFlexJSEmitter
{
if (writtenRequires.indexOf(imp) == -1)
{
- write(JSGoogEmitterTokens.GOOG_REQUIRE);
- write(ASEmitterTokens.PAREN_OPEN);
- write(ASEmitterTokens.SINGLE_QUOTE);
- write(formatQualifiedName(imp));
- write(ASEmitterTokens.SINGLE_QUOTE);
- write(ASEmitterTokens.PAREN_CLOSE);
- writeNewline(ASEmitterTokens.SEMICOLON);
-
- emitsInterfaces = true;
+ write(JSGoogEmitterTokens.GOOG_REQUIRE);
+ write(ASEmitterTokens.PAREN_OPEN);
+ write(ASEmitterTokens.SINGLE_QUOTE);
+ write(formatQualifiedName(imp));
+ write(ASEmitterTokens.SINGLE_QUOTE);
+ write(ASEmitterTokens.PAREN_CLOSE);
+ writeNewline(ASEmitterTokens.SEMICOLON);
+
+ emitsInterfaces = true;
}
}
}
-
+
// erikdebruin: Add missing language feature support, with e.g. 'is' and
// 'as' operators. We don't need to worry about requiring
// this in every project: ADVANCED_OPTIMISATIONS will NOT
// include any of the code if it is not used in the project.
- boolean isMainCU = flexProject.mainCU != null &&
- cu.getName().equals(flexProject.mainCU.getName());
+ boolean isMainCU = flexProject.mainCU != null
+ && cu.getName().equals(flexProject.mainCU.getName());
if (isMainCU)
{
write(JSGoogEmitterTokens.GOOG_REQUIRE);
@@ -1871,7 +1404,7 @@ public class JSFlexJSEmitter extends JSGoogEmitter implements IJSFlexJSEmitter
writeToken(JSFlexJSEmitterTokens.FLEXJS_CLASS_INFO);
writeToken(ASEmitterTokens.EQUAL);
writeToken(ASEmitterTokens.BLOCK_OPEN);
-
+
// names: [{ name: '', qName: '' }]
write(JSFlexJSEmitterTokens.NAMES);
writeToken(ASEmitterTokens.COLON);
@@ -1896,7 +1429,7 @@ public class JSFlexJSEmitter extends JSGoogEmitter implements IJSFlexJSEmitter
enodes = ((IClassNode) tnode).getImplementedInterfaceNodes();
else
enodes = ((IInterfaceNode) tnode).getExtendedInterfaceNodes();
-
+
if (enodes.length > 0)
{
writeToken(ASEmitterTokens.COMMA);
@@ -1907,8 +1440,9 @@ public class JSFlexJSEmitter extends JSGoogEmitter implements IJSFlexJSEmitter
write(ASEmitterTokens.SQUARE_OPEN);
int i = 0;
for (IExpressionNode enode : enodes)
- {
- write(formatQualifiedName(enode.resolve(project).getQualifiedName()));
+ {
+ write(formatQualifiedName(enode.resolve(project)
+ .getQualifiedName()));
if (i < enodes.length - 1)
writeToken(ASEmitterTokens.COMMA);
i++;
@@ -1922,8 +1456,6 @@ public class JSFlexJSEmitter extends JSGoogEmitter implements IJSFlexJSEmitter
}
}
- private int foreachLoopCounter = 0;
-
@Override
public void emitForEachLoop(IForLoopNode node)
{
@@ -2068,16 +1600,16 @@ public class JSFlexJSEmitter extends JSGoogEmitter implements IJSFlexJSEmitter
public void emitLiteral(ILiteralNode node)
{
boolean isWritten = false;
-
+
String s = node.getValue(true);
if (!(node instanceof RegExpLiteralNode))
{
if (node.getLiteralType() == LiteralType.XML)
{
// ToDo (erikdebruin): VF2JS -> handle XML output properly...
-
+
write("'" + s + "'");
-
+
isWritten = true;
}
s = s.replaceAll("\n", "__NEWLINE_PLACEHOLDER__");
@@ -2096,22 +1628,22 @@ public class JSFlexJSEmitter extends JSGoogEmitter implements IJSFlexJSEmitter
s = s.replaceAll("__CR_PLACEHOLDER__", "\\\\r");
s = s.replaceAll("__NEWLINE_PLACEHOLDER__", "\\\\n");
}
-
+
if (!isWritten)
{
write(s);
}
}
-
+
@Override
public void emitE4XFilter(IMemberAccessExpressionNode node)
{
- // ToDo (erikdebruin): implement E4X replacement !?!
+ // ToDo (erikdebruin): implement E4X replacement !?!
write(ASEmitterTokens.SINGLE_QUOTE);
write("E4XFilter");
write(ASEmitterTokens.SINGLE_QUOTE);
}
-
+
/*
@Override
public void emitUnaryOperator(IUnaryOperatorNode node)
@@ -2156,10 +1688,10 @@ public class JSFlexJSEmitter extends JSGoogEmitter implements IJSFlexJSEmitter
((MemberAccessExpressionNode)parentNode).getLeftOperandNode() == node)
{
// GCC wanted parens around foo++.toString(). As in (foo++).toString();
- write(ASEmitterTokens.PAREN_OPEN);
- super.emitUnaryOperator(node);
- write(ASEmitterTokens.PAREN_CLOSE);
- return;
+ write(ASEmitterTokens.PAREN_OPEN);
+ super.emitUnaryOperator(node);
+ write(ASEmitterTokens.PAREN_CLOSE);
+ return;
}
}
@@ -2167,19 +1699,217 @@ public class JSFlexJSEmitter extends JSGoogEmitter implements IJSFlexJSEmitter
super.emitUnaryOperator(node);
}
*/
-
+
@Override
- protected String formatQualifiedName(String name)
+ public String formatQualifiedName(String name)
+ {
+ if (name.contains("goog.") || name.startsWith("Vector."))
+ return name;
+ name = name.replaceAll("\\.", "_");
+ return name;
+ }
+
+}
+
+/*
+@Override
+public void emitInterface(IInterfaceNode node)
+{
+ ICompilerProject project = getWalker().getProject();
+
+ getDoc().emitInterfaceDoc(node, project);
+
+ String qname = node.getQualifiedName();
+ if (qname != null && !qname.equals(""))
{
- if (name.contains("goog.") || name.startsWith("Vector."))
- return name;
- name = name.replaceAll("\\.", "_");
- return name;
+ write(formatQualifiedName(qname));
+ write(ASEmitterTokens.SPACE);
+ writeToken(ASEmitterTokens.EQUAL);
+ write(ASEmitterTokens.FUNCTION);
+ write(ASEmitterTokens.PAREN_OPEN);
+ write(ASEmitterTokens.PAREN_CLOSE);
+ write(ASEmitterTokens.SPACE);
+ write(ASEmitterTokens.BLOCK_OPEN);
+ writeNewline();
+ write(ASEmitterTokens.BLOCK_CLOSE);
+ write(ASEmitterTokens.SEMICOLON);
}
+
- @Override
- protected IDefinition getClassDefinition()
+ final IDefinitionNode[] members = node.getAllMemberDefinitionNodes();
+ for (IDefinitionNode mnode : members)
+ {
+ boolean isAccessor = mnode.getNodeID() == ASTNodeID.GetterID
+ || mnode.getNodeID() == ASTNodeID.SetterID;
+
+ writeNewline();
+ writeNewline();
+ writeNewline();
+
+ getDoc().emitInterfaceMemberDoc((IFunctionNode) mnode, project);
+
+ write(formatQualifiedName(qname));
+ write(ASEmitterTokens.MEMBER_ACCESS);
+ write(JSEmitterTokens.PROTOTYPE);
+ write(ASEmitterTokens.MEMBER_ACCESS);
+ if (isAccessor)
+ {
+ writeGetSetPrefix(mnode.getNodeID() == ASTNodeID.GetterID);
+ }
+ write(mnode.getQualifiedName());
+ write(ASEmitterTokens.SPACE);
+ writeToken(ASEmitterTokens.EQUAL);
+ write(ASEmitterTokens.FUNCTION);
+ emitParameters(((IFunctionNode) mnode).getParameterNodes());
+ write(ASEmitterTokens.SPACE);
+ write(ASEmitterTokens.BLOCK_OPEN);
+ write(ASEmitterTokens.BLOCK_CLOSE);
+ write(ASEmitterTokens.SEMICOLON);
+ }
+}
+*/
+
+/*
+@Override
+public void emitMethod(IFunctionNode node)
+{
+ FunctionNode fn = (FunctionNode) node;
+ fn.parseFunctionBody(getProblems());
+
+ ICompilerProject project = getWalker().getProject();
+
+ getDoc().emitMethodDoc(node, project);
+
+ boolean isConstructor = node.isConstructor();
+
+ String qname = getTypeDefinition(node).getQualifiedName();
+ if (qname != null && !qname.equals(""))
+ {
+ write(formatQualifiedName(qname));
+ if (!isConstructor)
+ {
+ write(ASEmitterTokens.MEMBER_ACCESS);
+ if (!fn.hasModifier(ASModifier.STATIC))
+ {
+ write(JSEmitterTokens.PROTOTYPE);
+ write(ASEmitterTokens.MEMBER_ACCESS);
+ }
+ }
+ }
+
+ if (!isConstructor)
+ emitMemberName(node);
+
+ write(ASEmitterTokens.SPACE);
+ writeToken(ASEmitterTokens.EQUAL);
+ write(ASEmitterTokens.FUNCTION);
+
+ emitParameters(node.getParameterNodes());
+
+ boolean hasSuperClass = hasSuperClass(node);
+
+ if (isConstructor && node.getScopedNode().getChildCount() == 0)
+ {
+ write(ASEmitterTokens.SPACE);
+ write(ASEmitterTokens.BLOCK_OPEN);
+ if (hasSuperClass)
+ emitSuperCall(node, CONSTRUCTOR_EMPTY);
+ writeNewline();
+ write(ASEmitterTokens.BLOCK_CLOSE);
+ }
+
+ if (!isConstructor || node.getScopedNode().getChildCount() > 0)
+ emitMethodScope(node.getScopedNode());
+
+ if (isConstructor && hasSuperClass)
{
- return thisClass;
+ writeNewline(ASEmitterTokens.SEMICOLON);
+ write(JSGoogEmitterTokens.GOOG_INHERITS);
+ write(ASEmitterTokens.PAREN_OPEN);
+ write(formatQualifiedName(qname));
+ writeToken(ASEmitterTokens.COMMA);
+ String sname = getSuperClassDefinition(node, project)
+ .getQualifiedName();
+ write(formatQualifiedName(sname));
+ write(ASEmitterTokens.PAREN_CLOSE);
}
}
+*/
+
+/*
+@Override
+protected void emitDefaultParameterCodeBlock(IFunctionNode node)
+{
+ IParameterNode[] pnodes = node.getParameterNodes();
+ if (pnodes.length == 0)
+ return;
+
+ Map<Integer, IParameterNode> defaults = getDefaults(pnodes);
+
+ if (defaults != null)
+ {
+ final StringBuilder code = new StringBuilder();
+
+ if (!hasBody(node))
+ {
+ indentPush();
+ write(JSFlexJSEmitterTokens.INDENT);
+ }
+
+ List<IParameterNode> parameters = new ArrayList<IParameterNode>(
+ defaults.values());
+
+ for (int i = 0, n = parameters.size(); i < n; i++)
+ {
+ IParameterNode pnode = parameters.get(i);
+
+ if (pnode != null)
+ {
+ code.setLength(0);
+
+ // x = typeof y !== 'undefined' ? y : z;\n
+ code.append(pnode.getName());
+ code.append(ASEmitterTokens.SPACE.getToken());
+ code.append(ASEmitterTokens.EQUAL.getToken());
+ code.append(ASEmitterTokens.SPACE.getToken());
+ code.append(ASEmitterTokens.TYPEOF.getToken());
+ code.append(ASEmitterTokens.SPACE.getToken());
+ code.append(pnode.getName());
+ code.append(ASEmitterTokens.SPACE.getToken());
+ code.append(ASEmitterTokens.STRICT_NOT_EQUAL.getToken());
+ code.append(ASEmitterTokens.SPACE.getToken());
+ code.append(ASEmitterTokens.SINGLE_QUOTE.getToken());
+ code.append(ASEmitterTokens.UNDEFINED.getToken());
+ code.append(ASEmitterTokens.SINGLE_QUOTE.getToken());
+ code.append(ASEmitterTokens.SPACE.getToken());
+ code.append(ASEmitterTokens.TERNARY.getToken());
+ code.append(ASEmitterTokens.SPACE.getToken());
+ code.append(pnode.getName());
+ code.append(ASEmitterTokens.SPACE.getToken());
+ code.append(ASEmitterTokens.COLON.getToken());
+ code.append(ASEmitterTokens.SPACE.getToken());
+ code.append(pnode.getDefaultValue());
+ code.append(ASEmitterTokens.SEMICOLON.getToken());
+
+ write(code.toString());
+
+ if (i == n - 1 && !hasBody(node))
+ indentPop();
+
+ writeNewline();
+ }
+ }
+ }
+}
+*/
+
+/*
+private void writeGetSetPrefix(boolean isGet)
+{
+ if (isGet)
+ write(ASEmitterTokens.GET);
+ else
+ write(ASEmitterTokens.SET);
+ write("_");
+}
+*/
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/b2097f4e/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 ebe7c4e..d9ca745 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
@@ -105,7 +105,7 @@ public class JSGoogEmitter extends JSEmitter implements IJSGoogEmitter
{
write(ASEmitterTokens.INDENT);
}
-
+
//--------------------------------------------------------------------------
//
//--------------------------------------------------------------------------
@@ -193,6 +193,7 @@ public class JSGoogEmitter extends JSEmitter implements IJSGoogEmitter
public void emitClass(IClassNode node)
{
IClassDefinition definition = node.getDefinition();
+ getModel().setCurrentClass(definition);
IFunctionDefinition ctorDefinition = definition.getConstructor();
@@ -392,7 +393,7 @@ public class JSGoogEmitter extends JSEmitter implements IJSGoogEmitter
emitDeclarationName(node);
if (!(avnode instanceof IEmbedNode))
- emitAssignedValue(avnode);
+ emitAssignedValue(avnode);
if (!(node instanceof ChainedVariableNode))
{
@@ -593,8 +594,7 @@ public class JSGoogEmitter extends JSEmitter implements IJSGoogEmitter
else
{
String pname = (type != null) ? type.getPackageName() : "";
- if (cnode != null
- && pname != ""
+ if (cnode != null && pname != ""
&& !pname.equalsIgnoreCase(cnode.getPackageName())
&& inode != ASTNodeID.ArgumentID
&& inode != ASTNodeID.VariableID
@@ -621,8 +621,8 @@ public class JSGoogEmitter extends JSEmitter implements IJSGoogEmitter
if (hasBody(node) && !isStatic && !isLocal)
emitSelfReference(node);
- if (node.isConstructor()
- && hasSuperClass(node) && !hasSuperCall(node.getScopedNode()))
+ if (node.isConstructor() && hasSuperClass(node)
+ && !hasSuperCall(node.getScopedNode()))
emitSuperCall(node, CONSTRUCTOR_FULL);
emitRestParameterCodeBlock(node);
@@ -667,11 +667,11 @@ public class JSGoogEmitter extends JSEmitter implements IJSGoogEmitter
if (cnode == null)
{
- IDefinition cdef = getClassDefinition();
+ IDefinition cdef = getModel().getCurrentClass();
write(formatQualifiedName(cdef.getQualifiedName()));
}
else
- write(formatQualifiedName(cnode.getQualifiedName()));
+ write(formatQualifiedName(cnode.getQualifiedName()));
write(ASEmitterTokens.MEMBER_ACCESS);
write(JSGoogEmitterTokens.GOOG_BASE);
write(ASEmitterTokens.PAREN_OPEN);
@@ -1049,15 +1049,16 @@ public class JSGoogEmitter extends JSEmitter implements IJSGoogEmitter
protected void emitDefinePropertyFunction(IAccessorNode node)
{
- emitMethodScope(node.getScopedNode());
+ emitMethodScope(node.getScopedNode());
}
-
+
//--------------------------------------------------------------------------
// Operators
//--------------------------------------------------------------------------
@Override
- public void emitNamespaceAccessExpression(INamespaceAccessExpressionNode node)
+ public void emitNamespaceAccessExpression(
+ INamespaceAccessExpressionNode node)
{
getWalker().walk(node.getLeftOperandNode());
write(ASEmitterTokens.MEMBER_ACCESS);
@@ -1167,15 +1168,9 @@ public class JSGoogEmitter extends JSEmitter implements IJSGoogEmitter
}
return list;
}
-
+
protected String formatQualifiedName(String name)
{
- return name;
+ return name;
}
-
- protected IDefinition getClassDefinition()
- {
- return null;
- }
-
}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/b2097f4e/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/BindableEmitter.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/BindableEmitter.java b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/BindableEmitter.java
new file mode 100644
index 0000000..310bf6b
--- /dev/null
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/BindableEmitter.java
@@ -0,0 +1,76 @@
+/*
+ *
+ * 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.definitions.IClassDefinition;
+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.goog.JSGoogEmitterTokens;
+
+public class BindableEmitter extends JSSubEmitter implements
+ ISubEmitter<IClassDefinition>
+{
+ public BindableEmitter(IJSEmitter emitter)
+ {
+ super(emitter);
+ }
+
+ @Override
+ public void emit(IClassDefinition definition)
+ {
+ // TODO (mschmalle) will remove this cast as more things get abstracted
+ JSFlexJSEmitter fjs = (JSFlexJSEmitter) getEmitter();
+
+ if (getModel().hasBindableVars())
+ {
+ write(JSGoogEmitterTokens.OBJECT);
+ write(ASEmitterTokens.MEMBER_ACCESS);
+ write(JSEmitterTokens.DEFINE_PROPERTIES);
+ write(ASEmitterTokens.PAREN_OPEN);
+ String qname = definition.getQualifiedName();
+ write(fjs.formatQualifiedName(qname));
+ write(ASEmitterTokens.MEMBER_ACCESS);
+ write(JSEmitterTokens.PROTOTYPE);
+ write(ASEmitterTokens.COMMA);
+ write(ASEmitterTokens.SPACE);
+ write("/** @lends {" + fjs.formatQualifiedName(qname)
+ + ".prototype} */ ");
+ writeNewline(ASEmitterTokens.BLOCK_OPEN);
+
+ boolean firstTime = true;
+ for (String varName : getModel().getBindableVars())
+ {
+ if (firstTime)
+ firstTime = false;
+ else
+ write(ASEmitterTokens.COMMA);
+
+ fjs.emitBindableVarDefineProperty(varName, definition);
+ }
+ writeNewline(ASEmitterTokens.BLOCK_CLOSE);
+ write(ASEmitterTokens.PAREN_CLOSE);
+ write(ASEmitterTokens.SEMICOLON);
+ }
+ }
+}
[3/3] git commit: [flex-falcon] [refs/heads/develop] - - Refactored
Class emitting into shared jx package for future use. - Refactored Bindable
class level emittion;
- Refactored GetSet class level emition - Created a shared model for each
emitter sessio
Posted by ms...@apache.org.
- Refactored Class emitting into shared jx package for future use.
- Refactored Bindable class level emittion;
- Refactored GetSet class level emition
- Created a shared model for each emitter session.
Project: http://git-wip-us.apache.org/repos/asf/flex-falcon/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-falcon/commit/b2097f4e
Tree: http://git-wip-us.apache.org/repos/asf/flex-falcon/tree/b2097f4e
Diff: http://git-wip-us.apache.org/repos/asf/flex-falcon/diff/b2097f4e
Branch: refs/heads/develop
Commit: b2097f4e9dd112339369a278c4638b5d7d83a182
Parents: 6209a24
Author: Michael Schmalle <ms...@apache.org>
Authored: Sat May 30 17:40:46 2015 -0400
Committer: Michael Schmalle <ms...@apache.org>
Committed: Sat May 30 17:40:46 2015 -0400
----------------------------------------------------------------------
.../js/flexjs/TestFlexJSExpressions.java | 18 +-
.../mxml/flexjs/TestFlexJSMXMLScript.java | 2 +-
.../flex/compiler/codegen/ISubEmitter.java | 45 +
.../flex/compiler/codegen/js/IJSEmitter.java | 3 +-
.../compiler/internal/codegen/as/ASEmitter.java | 2 +-
.../compiler/internal/codegen/js/JSEmitter.java | 9 +
.../internal/codegen/js/JSSessionModel.java | 79 +
.../internal/codegen/js/JSSubEmitter.java | 99 ++
.../internal/codegen/js/amd/JSAMDEmitter.java | 2 +
.../codegen/js/flexjs/JSFlexJSDocEmitter.java | 134 +-
.../codegen/js/flexjs/JSFlexJSEmitter.java | 1524 +++++++-----------
.../internal/codegen/js/goog/JSGoogEmitter.java | 33 +-
.../internal/codegen/js/jx/BindableEmitter.java | 76 +
.../internal/codegen/js/jx/ClassEmitter.java | 156 ++
.../internal/codegen/js/jx/GetSetEmitter.java | 195 +++
.../codegen/js/utils/DocEmitterUtils.java | 49 +
.../internal/codegen/js/utils/EmitterUtils.java | 121 ++
.../codegen/js/vf2js/JSVF2JSEmitter.java | 10 +-
.../codegen/mxml/flexjs/MXMLFlexJSEmitter.java | 14 +-
.../codegen/mxml/vf2js/MXMLVF2JSEmitter.java | 4 +-
20 files changed, 1573 insertions(+), 1002 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/b2097f4e/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSExpressions.java
----------------------------------------------------------------------
diff --git a/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSExpressions.java b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSExpressions.java
index 9691b70..99fc70f 100644
--- a/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSExpressions.java
+++ b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSExpressions.java
@@ -19,7 +19,7 @@
package org.apache.flex.compiler.internal.codegen.js.flexjs;
-import org.apache.flex.compiler.definitions.IDefinition;
+import org.apache.flex.compiler.definitions.IClassDefinition;
import org.apache.flex.compiler.driver.IBackend;
import org.apache.flex.compiler.internal.codegen.js.goog.TestGoogExpressions;
import org.apache.flex.compiler.internal.driver.js.flexjs.FlexJSBackend;
@@ -164,9 +164,9 @@ public class TestFlexJSExpressions extends TestGoogExpressions
IBinaryOperatorNode bnode = (IBinaryOperatorNode) findFirstDescendantOfType(
fnode, IBinaryOperatorNode.class);
((NodeBase)fnode).setParent(null);
- IDefinition def = classnode.getDefinition();
+ IClassDefinition def = classnode.getDefinition();
- ((JSFlexJSEmitter)asEmitter).thisClass = def;
+ ((JSFlexJSEmitter)asEmitter).getModel().setCurrentClass(def);
asBlockWalker.visitBinaryOperator(bnode);
assertOut("this.b = 1");
}
@@ -188,9 +188,9 @@ public class TestFlexJSExpressions extends TestGoogExpressions
IBinaryOperatorNode bnode = (IBinaryOperatorNode) findFirstDescendantOfType(
fnode, IBinaryOperatorNode.class);
((NodeBase)fnode).setParent(null);
- IDefinition def = classnode.getDefinition();
+ IClassDefinition def = classnode.getDefinition();
- ((JSFlexJSEmitter)asEmitter).thisClass = def;
+ ((JSFlexJSEmitter)asEmitter).getModel().setCurrentClass(def);
asBlockWalker.visitBinaryOperator(bnode);
assertOut("this.b = 1");
}
@@ -478,9 +478,9 @@ public class TestFlexJSExpressions extends TestGoogExpressions
IBinaryOperatorNode bnode = (IBinaryOperatorNode) findFirstDescendantOfType(
fnode, IBinaryOperatorNode.class);
((NodeBase)fnode).setParent(null);
- IDefinition def = classnode.getDefinition();
+ IClassDefinition def = classnode.getDefinition();
- ((JSFlexJSEmitter)asEmitter).thisClass = def;
+ ((JSFlexJSEmitter)asEmitter).getModel().setCurrentClass(def);
asBlockWalker.visitBinaryOperator(bnode);
assertOut("foo_bar_B.d.b = 1");
}
@@ -538,9 +538,9 @@ public class TestFlexJSExpressions extends TestGoogExpressions
IBinaryOperatorNode bnode = (IBinaryOperatorNode) findFirstDescendantOfType(
fnode, IBinaryOperatorNode.class);
((NodeBase)fnode).setParent(null);
- IDefinition def = classnode.getDefinition();
+ IClassDefinition def = classnode.getDefinition();
- ((JSFlexJSEmitter)asEmitter).thisClass = def;
+ ((JSFlexJSEmitter)asEmitter).getModel().setCurrentClass(def);
asBlockWalker.visitBinaryOperator(bnode);
assertOut("org_apache_flex_utils_Language.as(this.model, foo_bar_E, true).labelText = null");
}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/b2097f4e/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/mxml/flexjs/TestFlexJSMXMLScript.java
----------------------------------------------------------------------
diff --git a/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/mxml/flexjs/TestFlexJSMXMLScript.java b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/mxml/flexjs/TestFlexJSMXMLScript.java
index 8984cd4..6d79603 100644
--- a/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/mxml/flexjs/TestFlexJSMXMLScript.java
+++ b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/mxml/flexjs/TestFlexJSMXMLScript.java
@@ -40,7 +40,7 @@ public class TestFlexJSMXMLScript extends FlexJSTestBase
IMXMLDocumentNode dnode = (IMXMLDocumentNode) node
.getAncestorOfType(IMXMLDocumentNode.class);
- ((JSFlexJSEmitter)(mxmlBlockWalker.getASEmitter())).thisClass = dnode.getDefinition();
+ ((JSFlexJSEmitter)(mxmlBlockWalker.getASEmitter())).getModel().setCurrentClass(dnode.getDefinition());
mxmlBlockWalker.visitDocument(dnode);
String appName = dnode.getQualifiedName();
String outTemplate = "/**\n * AppName\n *\n * @fileoverview\n *\n * @suppress {checkTypes}\n */\n\ngoog.provide('AppName');\n\ngoog.require('org_apache_flex_core_Application');\n\n\n\n\n/**\n * @constructor\n * @extends {org_apache_flex_core_Application}\n */\nAppName = function() {\n AppName.base(this, 'constructor');\n \n /**\n * @private\n * @type {Array}\n */\n this.mxmldd;\n \n /**\n * @private\n * @type {Array}\n */\n this.mxmldp;\n};\ngoog.inherits(AppName, org_apache_flex_core_Application);\n\n\n/**\n * Metadata\n *\n * @type {Object.<string, Array.<Object>>}\n */\nAppName.prototype.FLEXJS_CLASS_INFO = { names: [{ name: 'AppName', qName: 'AppName' }] };\n\n\n/**\n * @expose\n * @override\n */\nAppName.prototype.addedToParent = function() {\n AppName.base(this, 'addedToParent');\n};\n\n\n";
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/b2097f4e/compiler.jx/src/org/apache/flex/compiler/codegen/ISubEmitter.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/codegen/ISubEmitter.java b/compiler.jx/src/org/apache/flex/compiler/codegen/ISubEmitter.java
new file mode 100644
index 0000000..1431c4b
--- /dev/null
+++ b/compiler.jx/src/org/apache/flex/compiler/codegen/ISubEmitter.java
@@ -0,0 +1,45 @@
+/*
+ *
+ * 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.codegen;
+
+import org.apache.flex.compiler.tree.as.IASNode;
+
+/**
+ * The {@link IEmitter} emitter can use composition for it's more
+ * complicated production sequences with member, dynamic, binary expressions and
+ * identifiers etc.
+ *
+ * @author Michael Schmalle
+ */
+public interface ISubEmitter<T>
+{
+ /**
+ * The main emitter will call this method of the sub emitter with the
+ * correct generic type implemented.
+ * <p>
+ * The main idea here is abstraction. Producing JavaScript can get
+ * complicated, the best way to avoid bugs is to avoid as much state and
+ * interdependence between emit() calls of the main emitter.
+ *
+ * @param node The current {@link IASNode} being emitted by the
+ * {@link IEmitter}.
+ */
+ void emit(T node);
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/b2097f4e/compiler.jx/src/org/apache/flex/compiler/codegen/js/IJSEmitter.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/codegen/js/IJSEmitter.java b/compiler.jx/src/org/apache/flex/compiler/codegen/js/IJSEmitter.java
index 09bb858..01444e7 100644
--- a/compiler.jx/src/org/apache/flex/compiler/codegen/js/IJSEmitter.java
+++ b/compiler.jx/src/org/apache/flex/compiler/codegen/js/IJSEmitter.java
@@ -22,6 +22,7 @@ package org.apache.flex.compiler.codegen.js;
import java.io.Writer;
import org.apache.flex.compiler.codegen.as.IASEmitter;
+import org.apache.flex.compiler.internal.codegen.js.JSSessionModel;
import org.apache.flex.compiler.visitor.IASNodeStrategy;
/**
@@ -32,5 +33,5 @@ import org.apache.flex.compiler.visitor.IASNodeStrategy;
*/
public interface IJSEmitter extends IASEmitter
{
-
+ JSSessionModel getModel();
}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/b2097f4e/compiler.jx/src/org/apache/flex/compiler/internal/codegen/as/ASEmitter.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/as/ASEmitter.java b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/as/ASEmitter.java
index b7db495..423571b 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/as/ASEmitter.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/as/ASEmitter.java
@@ -717,7 +717,7 @@ public class ASEmitter implements IASEmitter, IEmitter
getWalker().walk(node.getNameExpressionNode());
}
- protected void emitParameters(IParameterNode[] nodes)
+ public void emitParameters(IParameterNode[] nodes)
{
write(ASEmitterTokens.PAREN_OPEN);
int len = nodes.length;
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/b2097f4e/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/JSEmitter.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/JSEmitter.java b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/JSEmitter.java
index 6fb5576..4eb6ccb 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/JSEmitter.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/JSEmitter.java
@@ -33,10 +33,19 @@ import org.apache.flex.compiler.tree.as.IFunctionObjectNode;
*/
public class JSEmitter extends ASEmitter implements IJSEmitter
{
+ private JSSessionModel model;
+
+ @Override
+ public JSSessionModel getModel()
+ {
+ return model;
+ }
public JSEmitter(FilterWriter out)
{
super(out);
+
+ model = new JSSessionModel();
}
@Override
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/b2097f4e/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/JSSessionModel.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/JSSessionModel.java b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/JSSessionModel.java
new file mode 100644
index 0000000..97cc52b
--- /dev/null
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/JSSessionModel.java
@@ -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.compiler.internal.codegen.js;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
+import org.apache.flex.compiler.definitions.IClassDefinition;
+import org.apache.flex.compiler.tree.as.IGetterNode;
+import org.apache.flex.compiler.tree.as.ISetterNode;
+
+/**
+ * @author Michael Schmalle
+ */
+public class JSSessionModel
+{
+ private IClassDefinition currentClass;
+
+ public static class PropertyNodes
+ {
+ public IGetterNode getter;
+ public ISetterNode setter;
+ }
+
+ private HashMap<String, PropertyNodes> propertyMap = new HashMap<String, PropertyNodes>();
+
+ private HashMap<String, PropertyNodes> staticPropertyMap = new HashMap<String, PropertyNodes>();
+
+ private ArrayList<String> bindableVars = new ArrayList<String>();
+
+ public IClassDefinition getCurrentClass()
+ {
+ return currentClass;
+ }
+
+ public void setCurrentClass(IClassDefinition currentClass)
+ {
+ this.currentClass = currentClass;
+ }
+
+ public HashMap<String, PropertyNodes> getPropertyMap()
+ {
+ return propertyMap;
+ }
+
+ public HashMap<String, PropertyNodes> getStaticPropertyMap()
+ {
+ return staticPropertyMap;
+ }
+
+ public boolean hasBindableVars()
+ {
+ return bindableVars.size() > 0;
+ }
+
+ public List<String> getBindableVars()
+ {
+ return bindableVars;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/b2097f4e/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/JSSubEmitter.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/JSSubEmitter.java b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/JSSubEmitter.java
new file mode 100644
index 0000000..00ed207
--- /dev/null
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/JSSubEmitter.java
@@ -0,0 +1,99 @@
+/*
+ *
+ * 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;
+
+import org.apache.flex.compiler.codegen.IEmitterTokens;
+import org.apache.flex.compiler.codegen.js.IJSEmitter;
+import org.apache.flex.compiler.projects.ICompilerProject;
+
+public class JSSubEmitter
+{
+ private IJSEmitter emitter;
+
+ protected IJSEmitter getEmitter()
+ {
+ return emitter;
+ }
+
+ protected ICompilerProject getProject()
+ {
+ return emitter.getWalker().getProject();
+ }
+
+ protected JSSessionModel getModel()
+ {
+ return emitter.getModel();
+ }
+
+ public JSSubEmitter(IJSEmitter emitter)
+ {
+ this.emitter = emitter;
+ }
+
+ protected void write(IEmitterTokens value)
+ {
+ emitter.write(value);
+ }
+
+ protected void write(String value)
+ {
+ emitter.write(value);
+ }
+
+ protected void writeToken(IEmitterTokens value)
+ {
+ emitter.writeToken(value);
+ }
+
+ protected void writeToken(String value)
+ {
+ emitter.writeToken(value);
+ }
+
+ protected void writeNewline()
+ {
+ emitter.writeNewline();
+ }
+
+ protected void writeNewline(IEmitterTokens value)
+ {
+ emitter.writeNewline(value);
+ }
+
+ protected void writeNewline(String value)
+ {
+ emitter.writeNewline(value);
+ }
+
+ protected void writeNewline(String value, boolean pushIndent)
+ {
+ emitter.writeNewline(value, pushIndent);
+ }
+
+ protected void indentPush()
+ {
+ emitter.indentPush();
+ }
+
+ protected void indentPop()
+ {
+ emitter.indentPop();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/b2097f4e/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/amd/JSAMDEmitter.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/amd/JSAMDEmitter.java b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/amd/JSAMDEmitter.java
index bc45058..8dcbb2c 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/amd/JSAMDEmitter.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/amd/JSAMDEmitter.java
@@ -251,6 +251,8 @@ public class JSAMDEmitter extends JSEmitter implements IJSAMDEmitter
//ICompilerProject project = getWalker().getProject();
IClassDefinition definition = node.getDefinition();
+ getModel().setCurrentClass(definition);
+
final String className = definition.getBaseName();
write("AS3.compilationUnit($exports, function($primaryDeclaration){");
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/b2097f4e/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSDocEmitter.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSDocEmitter.java b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSDocEmitter.java
index 701bb99..b7ba9bd 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSDocEmitter.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSDocEmitter.java
@@ -20,6 +20,7 @@
package org.apache.flex.compiler.internal.codegen.js.flexjs;
import java.util.ArrayList;
+import java.util.List;
import org.apache.flex.compiler.asdoc.flexjs.ASDocComment;
import org.apache.flex.compiler.clients.MXMLJSC;
@@ -46,50 +47,59 @@ import org.apache.flex.compiler.tree.as.IVariableNode;
public class JSFlexJSDocEmitter extends JSGoogDocEmitter
{
+ private List<String> classIgnoreList;
+ private List<String> ignoreList;
public JSFlexJSDocEmitter(IJSEmitter emitter)
{
super(emitter);
}
- public ArrayList<String> classIgnoreList;
- private ArrayList<String> ignoreList;
+ public List<String> getClassIgnoreList()
+ {
+ return classIgnoreList;
+ }
+ public void setClassIgnoreList(List<String> value)
+ {
+ this.classIgnoreList = value;
+ }
+
@Override
protected String convertASTypeToJS(String name, String pname)
{
- if (ignoreList != null)
- {
- if (ignoreList.contains(pname + "." + name))
- return IASLanguageConstants.Object;
- }
- if (classIgnoreList != null)
- {
- if (classIgnoreList.contains(pname + "." + name))
- return IASLanguageConstants.Object;
- }
- name = super.convertASTypeToJS(name, pname);
- return formatQualifiedName(name);
+ if (ignoreList != null)
+ {
+ if (ignoreList.contains(pname + "." + name))
+ return IASLanguageConstants.Object;
+ }
+ if (classIgnoreList != null)
+ {
+ if (classIgnoreList.contains(pname + "." + name))
+ return IASLanguageConstants.Object;
+ }
+ name = super.convertASTypeToJS(name, pname);
+ return formatQualifiedName(name);
}
-
+
@Override
protected String formatQualifiedName(String name)
{
- if (name.contains("goog.") || name.startsWith("Vector."))
- return name;
- name = name.replaceAll("\\.", "_");
- return name;
+ if (name.contains("goog.") || name.startsWith("Vector."))
+ return name;
+ name = name.replaceAll("\\.", "_");
+ return name;
}
@Override
public void emitMethodDoc(IFunctionNode node, ICompilerProject project)
{
ignoreList = null;
-
+
IClassDefinition classDefinition = resolveClassDefinition(node);
ASDocComment asDoc = (ASDocComment) node.getASDocComment();
-
+
if (node instanceof IFunctionNode)
{
boolean hasDoc = false;
@@ -122,7 +132,9 @@ public class JSFlexJSDocEmitter extends JSGoogDocEmitter
.getContainingScope(),
DependencyType.INHERITANCE, true);
if (type == null)
- System.out.println(iReference.getDisplayString() + " not resolved in " + classDefinition.getQualifiedName());
+ System.out.println(iReference.getDisplayString()
+ + " not resolved in "
+ + classDefinition.getQualifiedName());
emitImplements(type, type.getPackageName());
}
}
@@ -133,10 +145,11 @@ public class JSFlexJSDocEmitter extends JSGoogDocEmitter
{
if (asDoc != null && MXMLJSC.keepASDoc)
{
- String docText = asDoc.commentNoEnd();
- String ignoreToken = JSFlexJSEmitterTokens.IGNORE_COERCION.getToken();
- if (docText.contains(ignoreToken))
- loadIgnores(docText);
+ String docText = asDoc.commentNoEnd();
+ String ignoreToken = JSFlexJSEmitterTokens.IGNORE_COERCION
+ .getToken();
+ if (docText.contains(ignoreToken))
+ loadIgnores(docText);
write(changeAnnotations(asDoc.commentNoEnd()));
}
else
@@ -166,7 +179,7 @@ public class JSFlexJSDocEmitter extends JSGoogDocEmitter
ITypeDefinition tdef = enode.resolveType(project);
if (tdef == null)
continue;
-
+
emitParam(pnode, tdef.getPackageName());
}
@@ -187,12 +200,12 @@ public class JSFlexJSDocEmitter extends JSGoogDocEmitter
hasDoc = true;
}
- ITypeDefinition tdef = ((IFunctionDefinition)node.getDefinition())
- .resolveReturnType(project);
+ ITypeDefinition tdef = ((IFunctionDefinition) node
+ .getDefinition()).resolveReturnType(project);
String packageName = "";
packageName = tdef.getPackageName();
-
+
emitReturn(node, packageName);
}
@@ -221,38 +234,40 @@ public class JSFlexJSDocEmitter extends JSGoogDocEmitter
private void loadIgnores(String doc)
{
- ignoreList = new ArrayList<String>();
- String ignoreToken = JSFlexJSEmitterTokens.IGNORE_COERCION.getToken();
- int index = doc.indexOf(ignoreToken);
- while (index != -1)
- {
- String ignorable = doc.substring(index + ignoreToken.length());
- int endIndex = ignorable.indexOf("\n");
- ignorable = ignorable.substring(0, endIndex);
- ignorable = ignorable.trim();
- ignoreList.add(ignorable);
- index = doc.indexOf(ignoreToken, index + endIndex);
- }
+ ignoreList = new ArrayList<String>();
+ String ignoreToken = JSFlexJSEmitterTokens.IGNORE_COERCION.getToken();
+ int index = doc.indexOf(ignoreToken);
+ while (index != -1)
+ {
+ String ignorable = doc.substring(index + ignoreToken.length());
+ int endIndex = ignorable.indexOf("\n");
+ ignorable = ignorable.substring(0, endIndex);
+ ignorable = ignorable.trim();
+ ignoreList.add(ignorable);
+ index = doc.indexOf(ignoreToken, index + endIndex);
+ }
}
+
private String changeAnnotations(String doc)
{
- // rename these tags so they don't conflict with generated
- // jsdoc tags
- String pass1 = doc.replaceAll("@param", "@asparam");
- String pass2 = pass1.replaceAll("@return", "@asreturn");
- String pass3 = pass2.replaceAll("@private", "@asprivate");
- return pass3;
+ // rename these tags so they don't conflict with generated
+ // jsdoc tags
+ String pass1 = doc.replaceAll("@param", "@asparam");
+ String pass2 = pass1.replaceAll("@return", "@asreturn");
+ String pass3 = pass2.replaceAll("@private", "@asprivate");
+ return pass3;
}
-
- public void emitInterfaceMemberDoc(IDefinitionNode node, ICompilerProject project)
+
+ public void emitInterfaceMemberDoc(IDefinitionNode node,
+ ICompilerProject project)
{
boolean hasDoc = false;
-
- ASDocComment asDoc = (ASDocComment) ((IFunctionNode) node).getASDocComment();
-
+
+ ASDocComment asDoc = (ASDocComment) ((IFunctionNode) node)
+ .getASDocComment();
+
String returnType = ((IFunctionNode) node).getReturnType();
- if (returnType != ""
- && returnType != ASEmitterTokens.VOID.getToken()) // has return
+ if (returnType != "" && returnType != ASEmitterTokens.VOID.getToken()) // has return
{
if (asDoc != null && MXMLJSC.keepASDoc)
write(changeAnnotations(asDoc.commentNoEnd()));
@@ -260,13 +275,14 @@ public class JSFlexJSDocEmitter extends JSGoogDocEmitter
begin();
hasDoc = true;
- ITypeDefinition tdef = ((IFunctionDefinition)node.getDefinition())
+ ITypeDefinition tdef = ((IFunctionDefinition) node.getDefinition())
.resolveReturnType(project);
emitReturn((IFunctionNode) node, tdef.getPackageName());
}
- IParameterNode[] parameters = ((IFunctionNode) node).getParameterNodes();
+ IParameterNode[] parameters = ((IFunctionNode) node)
+ .getParameterNodes();
for (IParameterNode pnode : parameters)
{
if (!hasDoc)
@@ -303,7 +319,7 @@ public class JSFlexJSDocEmitter extends JSGoogDocEmitter
emitPublic(node);
}
}
-
+
@Override
public void emitFieldDoc(IVariableNode node, IDefinition def)
{
@@ -320,7 +336,7 @@ public class JSFlexJSDocEmitter extends JSGoogDocEmitter
}
else
{
- emitPublic(node);
+ emitPublic(node);
}
if (node.isConst())