You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by ah...@apache.org on 2017/01/17 21:36:15 UTC
git commit: [flex-falcon] [refs/heads/develop] - add test for and fix
chain binding in output
Repository: flex-falcon
Updated Branches:
refs/heads/develop 1fc24a703 -> eb2da04ac
add test for and fix chain binding in output
Project: http://git-wip-us.apache.org/repos/asf/flex-falcon/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-falcon/commit/eb2da04a
Tree: http://git-wip-us.apache.org/repos/asf/flex-falcon/tree/eb2da04a
Diff: http://git-wip-us.apache.org/repos/asf/flex-falcon/diff/eb2da04a
Branch: refs/heads/develop
Commit: eb2da04ac99da81cf1d85ce1afab3ad5aa414345
Parents: 1fc24a7
Author: Alex Harui <ah...@apache.org>
Authored: Tue Jan 17 13:36:03 2017 -0800
Committer: Alex Harui <ah...@apache.org>
Committed: Tue Jan 17 13:36:10 2017 -0800
----------------------------------------------------------------------
.../mxml/flexjs/TestFlexJSMXMLApplication.java | 158 +++++++++++++++++++
.../flexjs/files/binding/ComplexValueObject.as | 46 ++++++
.../flexjs/files/binding/SimpleValueObject.as | 26 +++
.../codegen/databinding/BindingInfo.java | 42 ++++-
4 files changed, 269 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/eb2da04a/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/mxml/flexjs/TestFlexJSMXMLApplication.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/mxml/flexjs/TestFlexJSMXMLApplication.java b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/mxml/flexjs/TestFlexJSMXMLApplication.java
index d3f1302..e740b6e 100644
--- a/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/mxml/flexjs/TestFlexJSMXMLApplication.java
+++ b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/mxml/flexjs/TestFlexJSMXMLApplication.java
@@ -34,6 +34,7 @@ import org.junit.Test;
import java.io.File;
import java.util.ArrayList;
+import java.util.List;
public class TestFlexJSMXMLApplication extends FlexJSTestBase
{
@@ -519,4 +520,161 @@ public class TestFlexJSMXMLApplication extends FlexJSTestBase
assertOutWithMetadata(outTemplate.replaceAll("AppName", appName));
}
+
+ @Test
+ public void testChainBinding()
+ {
+ String code = "<basic:Application xmlns:fx=\"http://ns.adobe.com/mxml/2009\" xmlns:basic=\"library://ns.apache.org/flexjs/basic\">"
+ + "<fx:Script><![CDATA["
+ + " import binding.ComplexValueObject;\n"
+ + " public var firstOne:ComplexValueObject;\n"
+ + "]]></fx:Script><basic:initialView><basic:Label text=\"{firstOne.subObject.labelText}\"/></basic:initialView></basic:Application>";
+
+ IMXMLDocumentNode dnode = (IMXMLDocumentNode) getNode(code,
+ IMXMLDocumentNode.class, FlexJSTestBase.WRAP_LEVEL_NONE);
+
+ ((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|accessControls}\n" +
+ " */\n" +
+ "\n" +
+ "goog.provide('AppName');\n" +
+ "\n" +
+ "goog.require('org.apache.flex.core.Application');\n" +
+ "goog.require('org.apache.flex.html.Label');\n" +
+ "goog.require('binding.ComplexValueObject');\n" +
+ "\n" +
+ "\n" +
+ "\n" +
+ "/**\n" +
+ " * @constructor\n" +
+ " * @extends {org.apache.flex.core.Application}\n" +
+ " */\n" +
+ "AppName = function() {\n" +
+ " AppName.base(this, 'constructor');\n" +
+ " \n" +
+ " /**\n" +
+ " * @private\n" +
+ " * @type {org.apache.flex.html.Label}\n" +
+ " */\n" +
+ " this.$ID0_;\n" +
+ " \n" +
+ " /**\n" +
+ " * @private\n" +
+ " * @type {Array}\n" +
+ " */\n" +
+ " this.mxmldd;\n" +
+ " \n" +
+ " /**\n" +
+ " * @private\n" +
+ " * @type {Array}\n" +
+ " */\n" +
+ " this.mxmldp;\n" +
+ "\n" +
+ " this.generateMXMLAttributes\n" +
+ " ([1,\n" +
+ "'initialView',\n" +
+ "false,\n" +
+ "[org.apache.flex.html.Label, 1, '_id', true, '$ID0', 0, 0, null],\n" +
+ "0,\n" +
+ "0\n" +
+ " ]);\n" +
+ " \n" +
+ "};\n" +
+ "goog.inherits(AppName, org.apache.flex.core.Application);\n" +
+ "\n" +
+ "\n" +
+ "\n" +
+ "/**\n" +
+ " * @export\n" +
+ " * @type {binding.ComplexValueObject}\n" +
+ " */\n" +
+ "AppName.prototype.firstOne;\n" +
+ "\n" +
+ "\n" +
+ "/**\n" +
+ " * @export\n" +
+ " */\n" +
+ "AppName.prototype._bindings = [\n" +
+ "1,\n" +
+ "[\"firstOne\", \"subObject\", \"labelText\"],\n" +
+ "null,\n" +
+ "[\"$ID0\", \"text\"],\n" +
+ "0,\n" +
+ "2,\n" +
+ "\"firstOne\",\n" +
+ "null,\n" +
+ "0,\n" +
+ "null,\n" +
+ "[\n" +
+ "1,\n" +
+ "2,\n" +
+ "\"subObject\",\n" +
+ "\"subObjectChanged\",\n" +
+ "0,\n" +
+ "null,\n" +
+ "[\n" +
+ "2,\n" +
+ "2,\n" +
+ "\"labelText\",\n" +
+ "\"propertyChange\",\n" +
+ "0,\n" +
+ "null,\n" +
+ "null,\n" +
+ "null],\n" +
+ "null]];\n" +
+ "/**\n" +
+ " * Metadata\n" +
+ " *\n" +
+ " * @type {Object.<string, Array.<Object>>}\n" +
+ " */\n" +
+ "AppName.prototype.FLEXJS_CLASS_INFO = { names: [{ name: 'AppName', qName: 'AppName', kind: 'class' }] };\n" +
+ "\n" +
+ "\n" +
+ "/**\n" +
+ " * Prevent renaming of class. Needed for reflection.\n" +
+ " */\n" +
+ "goog.exportSymbol('AppName', AppName);\n" +
+ "\n" +
+ "\n" +
+ "\n" +
+ "/**\n" +
+ " * Reflection\n" +
+ " *\n" +
+ " * @return {Object.<string, Function>}\n" +
+ " */\n" +
+ "AppName.prototype.FLEXJS_REFLECTION_INFO = function () {\n" +
+ " return {\n" +
+ " variables: function () {\n" +
+ " return {\n" +
+ " 'firstOne': { type: 'binding.ComplexValueObject'}\n" +
+ " };\n" +
+ " },\n" +
+ " accessors: function () {return {};},\n" +
+ " methods: function () {\n" +
+ " return {\n" +
+ " 'AppName': { type: '', declaredBy: 'AppName'}\n"+
+ " };\n" +
+ " }\n" +
+ " };\n" +
+ "};\n" +
+ "\n" +
+ "\n";
+
+ assertOutWithMetadata(outTemplate.replaceAll("AppName", appName));
+ }
+
+ @Override
+ protected void addSourcePaths(List<File> sourcePaths)
+ {
+ sourcePaths.add(new File(testAdapter.getUnitTestBaseDir(), "flexjs/files"));
+ super.addSourcePaths(sourcePaths);
+ }
+
}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/eb2da04a/compiler-jx/src/test/resources/flexjs/files/binding/ComplexValueObject.as
----------------------------------------------------------------------
diff --git a/compiler-jx/src/test/resources/flexjs/files/binding/ComplexValueObject.as b/compiler-jx/src/test/resources/flexjs/files/binding/ComplexValueObject.as
new file mode 100644
index 0000000..dfedbdc
--- /dev/null
+++ b/compiler-jx/src/test/resources/flexjs/files/binding/ComplexValueObject.as
@@ -0,0 +1,46 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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 binding
+{
+
+ public class ComplexValueObject
+ {
+ public function ComplexValueObject()
+ {
+ }
+
+ private var _subObject:SimpleValueObject;
+
+ [Bindable("subObjectChanged")]
+ public function get subObject():SimpleValueObject
+ {
+ return _subObject;
+ }
+
+ public function set subObject(value:SimpleValueObject):void
+ {
+ if (value != _subObject)
+ {
+ _subObject = value;
+ dispatchEvent(new Event("subObjectChanged"));
+ }
+ }
+
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/eb2da04a/compiler-jx/src/test/resources/flexjs/files/binding/SimpleValueObject.as
----------------------------------------------------------------------
diff --git a/compiler-jx/src/test/resources/flexjs/files/binding/SimpleValueObject.as b/compiler-jx/src/test/resources/flexjs/files/binding/SimpleValueObject.as
new file mode 100644
index 0000000..fc6f3c1
--- /dev/null
+++ b/compiler-jx/src/test/resources/flexjs/files/binding/SimpleValueObject.as
@@ -0,0 +1,26 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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 binding
+{
+ [Bindable]
+ public class SimpleValueObject
+ {
+ public var labelText:String;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/eb2da04a/compiler/src/main/java/org/apache/flex/compiler/internal/codegen/databinding/BindingInfo.java
----------------------------------------------------------------------
diff --git a/compiler/src/main/java/org/apache/flex/compiler/internal/codegen/databinding/BindingInfo.java b/compiler/src/main/java/org/apache/flex/compiler/internal/codegen/databinding/BindingInfo.java
index 2946dd4..de4dd58 100644
--- a/compiler/src/main/java/org/apache/flex/compiler/internal/codegen/databinding/BindingInfo.java
+++ b/compiler/src/main/java/org/apache/flex/compiler/internal/codegen/databinding/BindingInfo.java
@@ -37,9 +37,11 @@ import org.apache.flex.compiler.internal.definitions.ClassDefinition;
import org.apache.flex.compiler.internal.definitions.NamespaceDefinition;
import org.apache.flex.compiler.internal.scopes.ASScope;
import org.apache.flex.compiler.internal.scopes.TypeScope;
+import org.apache.flex.compiler.internal.tree.as.IdentifierNode;
import org.apache.flex.compiler.internal.tree.as.MemberAccessExpressionNode;
import org.apache.flex.compiler.internal.tree.as.NodeBase;
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.IExpressionNode;
import org.apache.flex.compiler.tree.as.IFunctionCallNode;
@@ -509,9 +511,20 @@ public class BindingInfo implements Comparable<BindingInfo>
if (leftDef.isPublic())
{
if (leftDef instanceof ClassDefinition)
+ {
classDef = (ClassDefinition)leftDef;
- sourceString = leftDef.getBaseName() + "." + def.getBaseName();
- isSimplePublicProperty = true;
+ sourceString = leftDef.getBaseName() + "." + def.getBaseName();
+ isSimplePublicProperty = true;
+ }
+ else
+ {
+ sourceString = buildChain((MemberAccessExpressionNode) leftSide);
+ if (sourceString != null)
+ {
+ sourceString += "." + def.getBaseName();
+ isSimplePublicProperty = true;
+ }
+ }
}
}
else if (leftSide instanceof IFunctionCallNode)
@@ -534,6 +547,29 @@ public class BindingInfo implements Comparable<BindingInfo>
}
}
}
-
+ }
+
+ private String buildChain(MemberAccessExpressionNode mae)
+ {
+ IExpressionNode left = mae.getLeftOperandNode();
+ if (left.getNodeID() == ASTNodeID.IdentifierID)
+ {
+ IExpressionNode right = mae.getRightOperandNode();
+ if (right.getNodeID() == ASTNodeID.IdentifierID)
+ {
+ return ((IdentifierNode)left).getName() + "." + ((IdentifierNode)right).getName();
+ }
+ }
+ else if (left.getNodeID() == ASTNodeID.MemberAccessExpressionID)
+ {
+ IExpressionNode right = mae.getRightOperandNode();
+ if (right.getNodeID() == ASTNodeID.IdentifierID)
+ {
+ String l = buildChain((MemberAccessExpressionNode)left);
+ if (l == null) return null;
+ return l + "." + ((IdentifierNode)right).getName();
+ }
+ }
+ return null;
}
}