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:19 UTC
[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
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);
+ }
+ }
+}