You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by jo...@apache.org on 2014/02/28 10:48:32 UTC
[35/50] git commit: [flex-falcon] [refs/heads/maven] - handle inline
itemrenderers with fx:Component
handle inline itemrenderers with fx:Component
Project: http://git-wip-us.apache.org/repos/asf/flex-falcon/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-falcon/commit/c0c0164c
Tree: http://git-wip-us.apache.org/repos/asf/flex-falcon/tree/c0c0164c
Diff: http://git-wip-us.apache.org/repos/asf/flex-falcon/diff/c0c0164c
Branch: refs/heads/maven
Commit: c0c0164cec6d297126acdb27511759493543e339
Parents: f23f182
Author: Alex Harui <ah...@apache.org>
Authored: Thu Jan 9 07:37:11 2014 -0800
Committer: Alex Harui <ah...@apache.org>
Committed: Thu Jan 9 07:37:11 2014 -0800
----------------------------------------------------------------------
.../compiler/codegen/mxml/IMXMLEmitter.java | 3 +
.../internal/codegen/mxml/MXMLBlockWalker.java | 13 +-
.../internal/codegen/mxml/MXMLEmitter.java | 14 +++
.../codegen/mxml/flexjs/MXMLFlexJSEmitter.java | 123 ++++++++++++++++++-
.../internal/visitor/mxml/MXMLNodeSwitch.java | 5 +-
.../visitor/mxml/IMXMLBlockVisitor.java | 3 +
6 files changed, 153 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c0c0164c/compiler.jx/src/org/apache/flex/compiler/codegen/mxml/IMXMLEmitter.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/codegen/mxml/IMXMLEmitter.java b/compiler.jx/src/org/apache/flex/compiler/codegen/mxml/IMXMLEmitter.java
index 566df04..28c23b8 100644
--- a/compiler.jx/src/org/apache/flex/compiler/codegen/mxml/IMXMLEmitter.java
+++ b/compiler.jx/src/org/apache/flex/compiler/codegen/mxml/IMXMLEmitter.java
@@ -25,6 +25,7 @@ import org.apache.flex.compiler.codegen.IEmitter;
import org.apache.flex.compiler.tree.mxml.IMXMLArrayNode;
import org.apache.flex.compiler.tree.mxml.IMXMLBooleanNode;
import org.apache.flex.compiler.tree.mxml.IMXMLClassDefinitionNode;
+import org.apache.flex.compiler.tree.mxml.IMXMLComponentNode;
import org.apache.flex.compiler.tree.mxml.IMXMLEventSpecifierNode;
import org.apache.flex.compiler.tree.mxml.IMXMLFactoryNode;
import org.apache.flex.compiler.tree.mxml.IMXMLFileNode;
@@ -101,4 +102,6 @@ public interface IMXMLEmitter extends IEmitter
void emitFactory(IMXMLFactoryNode node);
+ void emitComponent(IMXMLComponentNode node);
+
}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c0c0164c/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/MXMLBlockWalker.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/MXMLBlockWalker.java b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/MXMLBlockWalker.java
index 8aa2765..487579c 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/MXMLBlockWalker.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/MXMLBlockWalker.java
@@ -33,6 +33,7 @@ import org.apache.flex.compiler.tree.as.IFileNode;
import org.apache.flex.compiler.tree.mxml.IMXMLArrayNode;
import org.apache.flex.compiler.tree.mxml.IMXMLBooleanNode;
import org.apache.flex.compiler.tree.mxml.IMXMLClassDefinitionNode;
+import org.apache.flex.compiler.tree.mxml.IMXMLComponentNode;
import org.apache.flex.compiler.tree.mxml.IMXMLDeclarationsNode;
import org.apache.flex.compiler.tree.mxml.IMXMLDeferredInstanceNode;
import org.apache.flex.compiler.tree.mxml.IMXMLDocumentNode;
@@ -346,13 +347,23 @@ public class MXMLBlockWalker implements IMXMLBlockVisitor, IMXMLBlockWalker
@Override
public void visitFactory(IMXMLFactoryNode node)
{
- debug("visitLiteral()");
+ debug("visitFactory()");
mxmlEmitter.emitFactory(node);
}
//--------------------------------------------------------------------------
+ @Override
+ public void visitComponent(IMXMLComponentNode node)
+ {
+ debug("visitComponent()");
+
+ mxmlEmitter.emitComponent(node);
+ }
+
+ //--------------------------------------------------------------------------
+
protected void debug(String message)
{
//System.out.println(message);
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c0c0164c/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/MXMLEmitter.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/MXMLEmitter.java b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/MXMLEmitter.java
index 229c27f..bb1e016 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/MXMLEmitter.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/MXMLEmitter.java
@@ -31,6 +31,7 @@ import org.apache.flex.compiler.tree.mxml.IMXMLArrayNode;
import org.apache.flex.compiler.tree.mxml.IMXMLBooleanNode;
import org.apache.flex.compiler.tree.mxml.IMXMLClassDefinitionNode;
import org.apache.flex.compiler.tree.mxml.IMXMLClassNode;
+import org.apache.flex.compiler.tree.mxml.IMXMLComponentNode;
import org.apache.flex.compiler.tree.mxml.IMXMLDeclarationsNode;
import org.apache.flex.compiler.tree.mxml.IMXMLDocumentNode;
import org.apache.flex.compiler.tree.mxml.IMXMLEventSpecifierNode;
@@ -344,4 +345,17 @@ public class MXMLEmitter extends Emitter implements IMXMLEmitter
write("\"");
}
+ public void emitComponent(IMXMLComponentNode node)
+ {
+ IASNode cnode = node.getChild(0);
+
+ write("<fx:Component>");
+
+ if (cnode instanceof IMXMLClassNode)
+ {
+ getMXMLWalker().walk((IASNode) cnode); // Literal
+ }
+
+ write("</fx:Component>");
+ }
}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c0c0164c/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 e682534..f868b33 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
@@ -62,6 +62,7 @@ import org.apache.flex.compiler.tree.as.IImportNode;
import org.apache.flex.compiler.tree.mxml.IMXMLArrayNode;
import org.apache.flex.compiler.tree.mxml.IMXMLClassDefinitionNode;
import org.apache.flex.compiler.tree.mxml.IMXMLClassNode;
+import org.apache.flex.compiler.tree.mxml.IMXMLComponentNode;
import org.apache.flex.compiler.tree.mxml.IMXMLDataBindingNode;
import org.apache.flex.compiler.tree.mxml.IMXMLDocumentNode;
import org.apache.flex.compiler.tree.mxml.IMXMLEventSpecifierNode;
@@ -100,6 +101,9 @@ public class MXMLFlexJSEmitter extends MXMLEmitter implements
private boolean inMXMLContent;
private boolean inStatesOverride;
+
+ private StringBuilder subDocuments = new StringBuilder();
+ private ArrayList<String> subDocumentNames = new ArrayList<String>();
public MXMLFlexJSEmitter(FilterWriter out)
{
@@ -151,11 +155,88 @@ public class MXMLFlexJSEmitter extends MXMLEmitter implements
emitHeader(node);
- emitClassDeclStart(cname, node, false);
+ write(subDocuments.toString());
+ writeNewline();
+
+ emitClassDeclStart(cname, node.getBaseClassName(), false);
+
+ emitPropertyDecls();
+
+ emitClassDeclEnd(cname, node.getBaseClassName());
+
+ emitMetaData(cdef);
+
+ emitScripts();
+
+ emitEvents(cname);
+
+ emitPropertyGetterSetters(cname);
+
+ emitMXMLDescriptorFuncs(cname);
+
+ emitBindingData(cname, cdef);
+
+ emitEncodedCSS(cname);
+
+ }
+
+ public void emitSubDocument(IMXMLComponentNode node)
+ {
+ ArrayList<MXMLDescriptorSpecifier> oldDescriptorTree;
+ MXMLDescriptorSpecifier oldPropertiesTree;
+ ArrayList<MXMLEventSpecifier> oldEvents;
+ ArrayList<MXMLScriptSpecifier> oldScripts;
+ ArrayList<MXMLDescriptorSpecifier> oldCurrentInstances;
+ ArrayList<MXMLDescriptorSpecifier> oldCurrentPropertySpecifiers;
+ int oldEventCounter;
+ int oldIdCounter;
+
+ oldDescriptorTree = descriptorTree;
+ descriptorTree = new ArrayList<MXMLDescriptorSpecifier>();
+ oldPropertiesTree = propertiesTree;
+ propertiesTree = new MXMLDescriptorSpecifier();
+
+ oldEvents = events;
+ events = new ArrayList<MXMLEventSpecifier>();
+ // we don't save these. We want all requires to be generated at the top of the file
+ instances = new ArrayList<MXMLDescriptorSpecifier>();
+ oldScripts = scripts;
+ scripts = new ArrayList<MXMLScriptSpecifier>();
+ //styles = new ArrayList<MXMLStyleSpecifier>();
+
+ oldCurrentInstances = currentInstances;
+ currentInstances = new ArrayList<MXMLDescriptorSpecifier>();
+ oldCurrentPropertySpecifiers = currentPropertySpecifiers;
+ currentPropertySpecifiers = new ArrayList<MXMLDescriptorSpecifier>();
+
+ oldEventCounter = eventCounter;
+ eventCounter = 0;
+ oldIdCounter = idCounter;
+ idCounter = 0;
+
+ // visit MXML
+ IClassDefinition cdef = node.getContainedClassDefinition();
+ IASEmitter asEmitter = ((IMXMLBlockWalker) getMXMLWalker())
+ .getASEmitter();
+ ((JSFlexJSEmitter) asEmitter).thisClass = cdef;
+
+ IASNode classNode = node.getContainedClassDefinitionNode();
+ // visit tags
+ final int len = classNode.getChildCount();
+ for (int i = 0; i < len; i++)
+ {
+ getMXMLWalker().walk(classNode.getChild(i));
+ }
+
+ String cname = cdef.getQualifiedName();
+ subDocumentNames.add(cname);
+ String baseClassName = cdef.getBaseClassAsDisplayString();
+
+ emitClassDeclStart(cname, baseClassName, false);
emitPropertyDecls();
- emitClassDeclEnd(cname, node);
+ emitClassDeclEnd(cname, baseClassName);
emitMetaData(cdef);
@@ -170,17 +251,27 @@ public class MXMLFlexJSEmitter extends MXMLEmitter implements
emitBindingData(cname, cdef);
emitEncodedCSS(cname);
+
+ descriptorTree = oldDescriptorTree;
+ propertiesTree = oldPropertiesTree;
+ events = oldEvents;
+ scripts = oldScripts;
+ currentInstances = oldCurrentInstances;
+ currentPropertySpecifiers = oldCurrentPropertySpecifiers;
+ eventCounter = oldEventCounter;
+ idCounter = oldIdCounter;
+
}
//--------------------------------------------------------------------------
- protected void emitClassDeclStart(String cname, IMXMLDocumentNode node,
+ protected void emitClassDeclStart(String cname, String baseClassName,
boolean indent)
{
writeNewline();
writeNewline("/**");
writeNewline(" * @constructor");
- writeNewline(" * @extends {" + node.getBaseClassName() + "}");
+ writeNewline(" * @extends {" + baseClassName + "}");
writeNewline(" */");
writeToken(cname);
writeToken(ASEmitterTokens.EQUAL);
@@ -199,7 +290,7 @@ public class MXMLFlexJSEmitter extends MXMLEmitter implements
//--------------------------------------------------------------------------
- protected void emitClassDeclEnd(String cname, IMXMLDocumentNode node)
+ protected void emitClassDeclEnd(String cname, String baseClassName)
{
writeNewline();
writeNewline("/**");
@@ -224,7 +315,7 @@ public class MXMLFlexJSEmitter extends MXMLEmitter implements
write(ASEmitterTokens.PAREN_OPEN);
write(cname);
writeToken(ASEmitterTokens.COMMA);
- write(node.getBaseClassName());
+ write(baseClassName);
write(ASEmitterTokens.PAREN_CLOSE);
writeNewline(ASEmitterTokens.SEMICOLON);
writeNewline();
@@ -1361,6 +1452,24 @@ public class MXMLFlexJSEmitter extends MXMLEmitter implements
}
//--------------------------------------------------------------------------
+
+ @Override
+ public void emitComponent(IMXMLComponentNode node)
+ {
+ MXMLDescriptorSpecifier ps = getCurrentDescriptor("ps");
+ ps.value = "new mx.core.ClassFactory(";
+
+ ps.value += node.getName();
+ ps.value += ")";
+
+ setBufferWrite(true);
+ emitSubDocument(node);
+ subDocuments.append(getBuilder().toString());
+ getBuilder().setLength(0);
+ setBufferWrite(false);
+ }
+
+ //--------------------------------------------------------------------------
// JS output
//--------------------------------------------------------------------------
@@ -1408,6 +1517,8 @@ public class MXMLFlexJSEmitter extends MXMLEmitter implements
writeNewline();
emitHeaderLine(cname, true); // provide
+ for (String subDocumentName : subDocumentNames)
+ emitHeaderLine(subDocumentName, true);
writeNewline();
emitHeaderLine(bcname);
ArrayList<String> writtenInstances = new ArrayList<String>();
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c0c0164c/compiler.jx/src/org/apache/flex/compiler/internal/visitor/mxml/MXMLNodeSwitch.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/visitor/mxml/MXMLNodeSwitch.java b/compiler.jx/src/org/apache/flex/compiler/internal/visitor/mxml/MXMLNodeSwitch.java
index 459518c..a84f4da 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/visitor/mxml/MXMLNodeSwitch.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/visitor/mxml/MXMLNodeSwitch.java
@@ -22,6 +22,7 @@ package org.apache.flex.compiler.internal.visitor.mxml;
import org.apache.flex.compiler.tree.as.IASNode;
import org.apache.flex.compiler.tree.mxml.IMXMLArrayNode;
import org.apache.flex.compiler.tree.mxml.IMXMLBooleanNode;
+import org.apache.flex.compiler.tree.mxml.IMXMLComponentNode;
import org.apache.flex.compiler.tree.mxml.IMXMLDeclarationsNode;
import org.apache.flex.compiler.tree.mxml.IMXMLDeferredInstanceNode;
import org.apache.flex.compiler.tree.mxml.IMXMLDocumentNode;
@@ -117,6 +118,9 @@ public class MXMLNodeSwitch implements IASNodeStrategy
case MXMLFactoryID:
visitor.visitFactory((IMXMLFactoryNode) node);
break;
+ case MXMLComponentID:
+ visitor.visitComponent((IMXMLComponentNode) node);
+ break;
case MXMLApplicationID:
case MXMLBindingID:
@@ -124,7 +128,6 @@ public class MXMLNodeSwitch implements IASNodeStrategy
case MXMLClassID:
case MXMLClassDefinitionID:
case MXMLClearID:
- case MXMLComponentID:
case MXMLConcatenatedDataBindingID:
case MXMLDataBindingID:
case MXMLDateID:
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c0c0164c/compiler.jx/src/org/apache/flex/compiler/visitor/mxml/IMXMLBlockVisitor.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/visitor/mxml/IMXMLBlockVisitor.java b/compiler.jx/src/org/apache/flex/compiler/visitor/mxml/IMXMLBlockVisitor.java
index a31124a..6b10cd7 100644
--- a/compiler.jx/src/org/apache/flex/compiler/visitor/mxml/IMXMLBlockVisitor.java
+++ b/compiler.jx/src/org/apache/flex/compiler/visitor/mxml/IMXMLBlockVisitor.java
@@ -22,6 +22,7 @@ package org.apache.flex.compiler.visitor.mxml;
import org.apache.flex.compiler.tree.mxml.IMXMLArrayNode;
import org.apache.flex.compiler.tree.mxml.IMXMLBooleanNode;
import org.apache.flex.compiler.tree.mxml.IMXMLClassDefinitionNode;
+import org.apache.flex.compiler.tree.mxml.IMXMLComponentNode;
import org.apache.flex.compiler.tree.mxml.IMXMLDeclarationsNode;
import org.apache.flex.compiler.tree.mxml.IMXMLDeferredInstanceNode;
import org.apache.flex.compiler.tree.mxml.IMXMLDocumentNode;
@@ -97,5 +98,7 @@ public interface IMXMLBlockVisitor extends IBlockVisitor
void visitLiteral(IMXMLLiteralNode node);
void visitFactory(IMXMLFactoryNode node);
+
+ void visitComponent(IMXMLComponentNode node);
}