Repository: flex-falcon Updated Branches: refs/heads/develop 498716d12 -> 3be965da1
IdentifierEmitter: identifier that isn't on the left hand side of a member access expression should not be qualified Project: http://git-wip-us.apache.org/repos/asf/flex-falcon/repo Commit: http://git-wip-us.apache.org/repos/asf/flex-falcon/commit/3be965da Tree: http://git-wip-us.apache.org/repos/asf/flex-falcon/tree/3be965da Diff: http://git-wip-us.apache.org/repos/asf/flex-falcon/diff/3be965da Branch: refs/heads/develop Commit: 3be965da1b9d056f58fc0f63e38c4b019071c6da Parents: 498716d Author: Josh Tynjala <joshtynj...@apache.org> Authored: Tue Jan 12 16:46:48 2016 -0800 Committer: Josh Tynjala <joshtynj...@apache.org> Committed: Tue Jan 12 16:46:48 2016 -0800 ---------------------------------------------------------------------- .../js/flexjs/TestFlexJSExpressions.java | 20 +++++++ .../codegen/js/jx/IdentifierEmitter.java | 61 +++++++++++++------- 2 files changed, 59 insertions(+), 22 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/3be965da/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSExpressions.java ---------------------------------------------------------------------- diff --git a/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSExpressions.java b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSExpressions.java index 8148424..61c4e8d 100644 --- a/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSExpressions.java +++ b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSExpressions.java @@ -744,6 +744,26 @@ public class TestFlexJSExpressions extends TestGoogExpressions asBlockWalker.visitFunction(node); assertOut("FalconTest_A.prototype.foo = function() {\n bar(b).text = '';\n}"); } + + @Test + public void testFunctionCallFullyQualified() + { + IFunctionNode node = (IFunctionNode) getNode( + "import goog.bind; public class B {public function b() { goog.bind(b, this); }}", + IFunctionNode.class, WRAP_LEVEL_PACKAGE, true); + asBlockWalker.visitFunction(node); + assertOut("/**\n * @export\n */\nfoo.bar.B.prototype.b = function() {\n goog.bind(org.apache.flex.utils.Language.closure(this.b, this, 'b'), this);\n}"); + } + + @Test + public void testFunctionMemberFullyQualified() + { + IFunctionNode node = (IFunctionNode) getNode( + "import flash.utils.clearTimeout; public class B {public function b() { clearTimeout.length; }}", + IFunctionNode.class, WRAP_LEVEL_PACKAGE, true); + asBlockWalker.visitFunction(node); + assertOut("/**\n * @export\n */\nfoo.bar.B.prototype.b = function() {\n flash.utils.clearTimeout.length;\n}"); + } @Test public void testComplexBooleanExpression() http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/3be965da/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/IdentifierEmitter.java ---------------------------------------------------------------------- diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/IdentifierEmitter.java b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/IdentifierEmitter.java index 174ae61..cf1faa5 100644 --- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/IdentifierEmitter.java +++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/IdentifierEmitter.java @@ -37,6 +37,7 @@ import org.apache.flex.compiler.tree.ASTNodeID; import org.apache.flex.compiler.tree.as.IASNode; import org.apache.flex.compiler.tree.as.IFunctionObjectNode; import org.apache.flex.compiler.tree.as.IIdentifierNode; +import org.apache.flex.compiler.tree.as.IMemberAccessExpressionNode; import org.apache.flex.compiler.utils.NativeUtils; public class IdentifierEmitter extends JSSubEmitter implements @@ -75,12 +76,12 @@ public class IdentifierEmitter extends JSSubEmitter implements boolean identifierIsLocalOrInstanceFunctionAsValue = false; if (identifierIsPlainFunction) { - FunctionClassification fc = ((FunctionDefinition)nodeDef).getFunctionClassification(); - identifierIsLocalOrInstanceFunctionAsValue = - (fc == FunctionClassification.LOCAL || fc == FunctionClassification.CLASS_MEMBER) && - // not a value if parent is a function call or member access expression - (!(parentNodeId == ASTNodeID.MemberAccessExpressionID || parentNodeId == ASTNodeID.FunctionCallID)); - + FunctionClassification fc = ((FunctionDefinition)nodeDef).getFunctionClassification(); + identifierIsLocalOrInstanceFunctionAsValue = + (fc == FunctionClassification.LOCAL || fc == FunctionClassification.CLASS_MEMBER) && + // not a value if parent is a function call or member access expression + (!(parentNodeId == ASTNodeID.MemberAccessExpressionID || parentNodeId == ASTNodeID.FunctionCallID)); + } // an instance method as a parameter or // a local function @@ -91,7 +92,7 @@ public class IdentifierEmitter extends JSSubEmitter implements if (generateClosure) { - getEmitter().emitClosureStart(); + getEmitter().emitClosureStart(); } if (EmitterUtils.writeThis(getProject(), getModel(), node)) @@ -114,7 +115,7 @@ public class IdentifierEmitter extends JSSubEmitter implements writeToken(ASEmitterTokens.COMMA); write(ASEmitterTokens.THIS); - getEmitter().emitClosureEnd(node); + getEmitter().emitClosureEnd(node); emitName = false; } } @@ -126,10 +127,11 @@ public class IdentifierEmitter extends JSSubEmitter implements { if (nodeDef != null) { - // this can be optimized but this way lets - // us breakpoint on the node.getName() to make - // sure it is ok to always use the short name in an MAE - String qname = nodeDef.getQualifiedName(); + // this can be optimized but this way lets + // us breakpoint on the node.getName() to make + // sure it is ok to always use the short name in an MAE + String qname = nodeDef.getQualifiedName(); + boolean isPackageOrFileMember = false; if (nodeDef instanceof IVariableDefinition) { IVariableDefinition variable = (IVariableDefinition) nodeDef; @@ -137,8 +139,7 @@ public class IdentifierEmitter extends JSSubEmitter implements if (classification == VariableClassification.PACKAGE_MEMBER || classification == VariableClassification.FILE_MEMBER) { - write(getEmitter().formatQualifiedName(qname)); - return; + isPackageOrFileMember = true; } } else if (nodeDef instanceof IFunctionDefinition) @@ -148,18 +149,34 @@ public class IdentifierEmitter extends JSSubEmitter implements if (classification == FunctionClassification.PACKAGE_MEMBER || classification == FunctionClassification.FILE_MEMBER) { - write(getEmitter().formatQualifiedName(qname)); - return; + isPackageOrFileMember = true; } } - if (parentNodeId == ASTNodeID.MemberAccessExpressionID) + boolean needsFormattedName = false; + if (isPackageOrFileMember && parentNodeId == ASTNodeID.MemberAccessExpressionID) { - write(node.getName()); + IMemberAccessExpressionNode parentMemberAccessNode = (IMemberAccessExpressionNode) parentNode; + //if the package or file member isn't on the left side of a + //member access expression, it shouldn't be fully qualified + needsFormattedName = parentMemberAccessNode.getLeftOperandNode() == node; } - else if (nodeDef instanceof TypeDefinitionBase) - write(getEmitter().formatQualifiedName(qname)); - else - write(qname); + if (parentNodeId == ASTNodeID.MemberAccessExpressionID) + { + if (needsFormattedName) + { + write(getEmitter().formatQualifiedName(qname)); + } + else + { + write(node.getName()); + } + } + else if (isPackageOrFileMember) + write(getEmitter().formatQualifiedName(qname)); + else if (nodeDef instanceof TypeDefinitionBase) + write(getEmitter().formatQualifiedName(qname)); + else + write(qname); } else write(node.getName());