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 2017/03/21 23:11:02 UTC
[25/50] git commit: [flex-falcon] [refs/heads/master] - FLEX-35257
another scenario for EmitterUtils
FLEX-35257 another scenario for EmitterUtils
Project: http://git-wip-us.apache.org/repos/asf/flex-falcon/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-falcon/commit/da54fa92
Tree: http://git-wip-us.apache.org/repos/asf/flex-falcon/tree/da54fa92
Diff: http://git-wip-us.apache.org/repos/asf/flex-falcon/diff/da54fa92
Branch: refs/heads/master
Commit: da54fa92c506c7f725c6ad0b57f5836e6d41d9e6
Parents: 57ad9b0
Author: Alex Harui <ah...@apache.org>
Authored: Tue Feb 7 22:29:24 2017 -0800
Committer: Alex Harui <ah...@apache.org>
Committed: Tue Feb 7 22:29:42 2017 -0800
----------------------------------------------------------------------
.../internal/codegen/js/utils/EmitterUtils.java | 29 +++++
.../mxml/flexjs/TestFlexJSMXMLScript.java | 107 +++++++++++++++++++
2 files changed, 136 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/da54fa92/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/utils/EmitterUtils.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/utils/EmitterUtils.java b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/utils/EmitterUtils.java
index 766f54c..fc56f4d 100644
--- a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/utils/EmitterUtils.java
+++ b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/utils/EmitterUtils.java
@@ -371,6 +371,9 @@ public class EmitterUtils
{
isFileOrPackageMember = true;
}
+ else if (!identifierIsMemberAccess && classification == FunctionClassification.CLASS_MEMBER &&
+ isClassMember(project, nodeDef, thisClass))
+ return true;
}
return parentNodeId == ASTNodeID.FunctionCallID
&& !(nodeDef instanceof AccessorDefinition)
@@ -434,6 +437,32 @@ public class EmitterUtils
return false;
}
+ public static boolean isClassMember(ICompilerProject project,
+ IDefinition nodeDef, IClassDefinition classDef)
+ {
+ if (nodeDef.isInternal() && (!(nodeDef.getParent() instanceof ClassDefinition)))
+ return false;
+
+ TypeScope cscope = (TypeScope) classDef
+ .getContainedScope();
+
+ Set<INamespaceDefinition> nsSet = cscope.getNamespaceSet(project);
+ Collection<IDefinition> defs = new HashSet<IDefinition>();
+
+ cscope.getAllPropertiesForMemberAccess((CompilerProject) project, defs,
+ nsSet);
+
+ Iterator<IDefinition> visiblePropertiesIterator = defs.iterator();
+ while (visiblePropertiesIterator.hasNext())
+ {
+ if (nodeDef.getQualifiedName().equals(
+ visiblePropertiesIterator.next().getQualifiedName()))
+ return true;
+ }
+
+ return false;
+ }
+
public static boolean isScalar(IExpressionNode node)
{
ASTNodeID id = node.getNodeID();
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/da54fa92/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/mxml/flexjs/TestFlexJSMXMLScript.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/mxml/flexjs/TestFlexJSMXMLScript.java b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/mxml/flexjs/TestFlexJSMXMLScript.java
index 4ecfbc7..5f7f7ef 100644
--- a/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/mxml/flexjs/TestFlexJSMXMLScript.java
+++ b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/mxml/flexjs/TestFlexJSMXMLScript.java
@@ -129,6 +129,113 @@ public class TestFlexJSMXMLScript extends FlexJSTestBase
}
@Test
+ public void testFunctionAssignmentInScript()
+ {
+ String code = "" + "<fx:Script><![CDATA["
+ + " private var foo:Function = bar;"
+ + " public function bar():void {};"
+ + "]]></fx:Script>";
+
+ IMXMLScriptNode node = (IMXMLScriptNode) getNode(code,
+ IMXMLScriptNode.class, FlexJSTestBase.WRAP_LEVEL_DOCUMENT);
+
+ IMXMLDocumentNode dnode = (IMXMLDocumentNode) node
+ .getAncestorOfType(IMXMLDocumentNode.class);
+ ((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" +
+ "\n" +
+ "\n" +
+ "\n" +
+ "/**\n" +
+ " * @constructor\n" +
+ " * @extends {org.apache.flex.core.Application}\n" +
+ " */\n" +
+ "AppName = function() {\n" +
+ " AppName.base(this, 'constructor');\n" +
+ " \n" +
+ " this.foo = org.apache.flex.utils.Language.closure(this.bar, this, 'bar');\n" +
+ " /**\n" +
+ " * @private\n" +
+ " * @type {Array}\n" +
+ " */\n" +
+ " this.mxmldd;\n" +
+ " \n" +
+ " /**\n" +
+ " * @private\n" +
+ " * @type {Array}\n" +
+ " */\n" +
+ " this.mxmldp;\n" +
+ "};\n" +
+ "goog.inherits(AppName, org.apache.flex.core.Application);\n" +
+ "\n" +
+ "\n" +
+ "\n" +
+ "/**\n" +
+ " * @private\n" +
+ " * @type {Function}\n" +
+ " */\n" +
+ "AppName.prototype.foo;\n" +
+ "\n" +
+ "\n" +
+ "/**\n" +
+ " * @export\n" +
+ " */\n" +
+ "AppName.prototype.bar = function() {\n" +
+ "};\n" +
+ "\n" +
+ "\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 () {return {};},\n" +
+ " accessors: function () {return {};},\n" +
+ " methods: function () {\n" +
+ " return {\n" +
+ " 'bar': { type: 'void', declaredBy: 'AppName'},\n" +
+ " 'AppName': { type: '', declaredBy: 'AppName'}\n" +
+ " };\n" +
+ " }\n" +
+ " };\n" +
+ "};\n" +
+ "\n" +
+ "\n";
+
+ assertOutWithMetadata(outTemplate.replaceAll("AppName", appName));
+ }
+
+ @Test
public void testComplexInitializersInScript()
{
String code = "" + "<fx:Script><![CDATA["