Repository: flex-falcon Updated Branches: refs/heads/develop 2fc5068c1 -> 1d760a484
FLEX-35116 handle private setters Project: http://git-wip-us.apache.org/repos/asf/flex-falcon/repo Commit: http://git-wip-us.apache.org/repos/asf/flex-falcon/commit/1d760a48 Tree: http://git-wip-us.apache.org/repos/asf/flex-falcon/tree/1d760a48 Diff: http://git-wip-us.apache.org/repos/asf/flex-falcon/diff/1d760a48 Branch: refs/heads/develop Commit: 1d760a48472ff7543f5fec4ab208e07b2e15337f Parents: 2fc5068 Author: Alex Harui <[email protected]> Authored: Tue Nov 15 16:19:17 2016 -0800 Committer: Alex Harui <[email protected]> Committed: Tue Nov 15 16:19:17 2016 -0800 ---------------------------------------------------------------------- .../codegen/js/flexjs/JSFlexJSEmitter.java | 3 +- .../codegen/js/jx/MemberAccessEmitter.java | 34 +++--- .../js/flexjs/TestFlexJSExpressions.java | 20 ++++ .../internal/semantics/SemanticUtils.java | 5 +- compiler/src/test/java/as/ASVariableTests.java | 108 +++++++++++++++++++ 5 files changed, 155 insertions(+), 15 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/1d760a48/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSEmitter.java ---------------------------------------------------------------------- diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSEmitter.java b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSEmitter.java index a7c0184..61b41e3 100644 --- a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSEmitter.java +++ b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSEmitter.java @@ -487,7 +487,8 @@ public class JSFlexJSEmitter extends JSGoogEmitter implements IJSFlexJSEmitter { INamespaceDefinition nsDef = def.getNamespaceReference().resolveNamespaceReference(getWalker().getProject()); String uri = nsDef.getURI(); - if (!def.getNamespaceReference().isLanguageNamespace() && !uri.equals(INamespaceConstants.AS3URI)) + if (!def.getNamespaceReference().isLanguageNamespace() && !uri.equals(INamespaceConstants.AS3URI) && + !nsDef.getBaseName().equals(ASEmitterTokens.PRIVATE.getToken())) return true; return false; } http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/1d760a48/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/MemberAccessEmitter.java ---------------------------------------------------------------------- diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/MemberAccessEmitter.java b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/MemberAccessEmitter.java index 105dec9..afe5d95 100644 --- a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/MemberAccessEmitter.java +++ b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/MemberAccessEmitter.java @@ -201,19 +201,27 @@ public class MemberAccessEmitter extends JSSubEmitter implements IdentifierNode r = (IdentifierNode)(naen.getRightOperandNode()); // output bracket access with QName writeLeftSide(node, leftNode, rightNode); - write(ASEmitterTokens.SQUARE_OPEN); - write(ASEmitterTokens.NEW); - write(ASEmitterTokens.SPACE); - write(IASLanguageConstants.QName); - write(ASEmitterTokens.PAREN_OPEN); - write(fjs.formatQualifiedName(d.getBaseName())); - write(ASEmitterTokens.COMMA); - write(ASEmitterTokens.SPACE); - write(ASEmitterTokens.SINGLE_QUOTE); - write(r.getName()); - write(ASEmitterTokens.SINGLE_QUOTE); - write(ASEmitterTokens.PAREN_CLOSE); - write(ASEmitterTokens.SQUARE_CLOSE); + if (!d.getBaseName().equals(ASEmitterTokens.PRIVATE.getToken())) + { + write(ASEmitterTokens.SQUARE_OPEN); + write(ASEmitterTokens.NEW); + write(ASEmitterTokens.SPACE); + write(IASLanguageConstants.QName); + write(ASEmitterTokens.PAREN_OPEN); + write(fjs.formatQualifiedName(d.getBaseName())); + write(ASEmitterTokens.COMMA); + write(ASEmitterTokens.SPACE); + write(ASEmitterTokens.SINGLE_QUOTE); + write(r.getName()); + write(ASEmitterTokens.SINGLE_QUOTE); + write(ASEmitterTokens.PAREN_CLOSE); + write(ASEmitterTokens.SQUARE_CLOSE); + } + else + { + write(node.getOperator().getOperatorText()); + write(r.getName()); + } return; } boolean isCustomNamespace = false; http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/1d760a48/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSExpressions.java ---------------------------------------------------------------------- diff --git a/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSExpressions.java b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSExpressions.java index 153e648..3240840 100644 --- a/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSExpressions.java +++ b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSExpressions.java @@ -179,6 +179,26 @@ public class TestFlexJSExpressions extends TestGoogExpressions } @Test + public void testVisitBinaryOperatorNode_setterAssignmentPrivate() + { + IBinaryOperatorNode node = (IBinaryOperatorNode) getNode( + "public class B {public function get b():int { return 0; } private function set b(value:int):void {}; public function test() { this.b = 1; }}", + IBinaryOperatorNode.class, WRAP_LEVEL_PACKAGE); + asBlockWalker.visitBinaryOperator(node); + assertOut("this.b = 1"); + } + + @Test + public void testVisitBinaryOperatorNode_setterAssignmentPrivateWithNamespace() + { + IBinaryOperatorNode node = (IBinaryOperatorNode) getNode( + "public class B {public function get b():int { return 0; } private function set b(value:int):void {}; public function test() { this.private::b = 1; }}", + IBinaryOperatorNode.class, WRAP_LEVEL_PACKAGE); + asBlockWalker.visitBinaryOperator(node); + assertOut("this.b = 1"); + } + + @Test public void testVisitBinaryOperatorNode_setterAssignmentWithThisMXML() { // simulate MXML script conditions. http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/1d760a48/compiler/src/main/java/org/apache/flex/compiler/internal/semantics/SemanticUtils.java ---------------------------------------------------------------------- diff --git a/compiler/src/main/java/org/apache/flex/compiler/internal/semantics/SemanticUtils.java b/compiler/src/main/java/org/apache/flex/compiler/internal/semantics/SemanticUtils.java index eaf0e6c..189ee5b 100644 --- a/compiler/src/main/java/org/apache/flex/compiler/internal/semantics/SemanticUtils.java +++ b/compiler/src/main/java/org/apache/flex/compiler/internal/semantics/SemanticUtils.java @@ -755,7 +755,10 @@ public class SemanticUtils if ( def instanceof GetterDefinition ) { - result = resolveCorrespondingAccessor(def) == null; + IDefinition otherDef = resolveCorrespondingAccessor(def); + if (otherDef == null) return true; + if (otherDef.getNamespaceReference() != def.getNamespaceReference()) + return true; } else if ( def instanceof ConstantDefinition ) { http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/1d760a48/compiler/src/test/java/as/ASVariableTests.java ---------------------------------------------------------------------- diff --git a/compiler/src/test/java/as/ASVariableTests.java b/compiler/src/test/java/as/ASVariableTests.java index 0e3a454..e091883 100644 --- a/compiler/src/test/java/as/ASVariableTests.java +++ b/compiler/src/test/java/as/ASVariableTests.java @@ -188,6 +188,114 @@ public class ASVariableTests extends ASFeatureTestsBase compileAndRun(source, false, false, false, new String[]{ "-compiler.mxml.compatibility-version=4.6.0" } ); } + @Test + public void ASVariableTests_setter() + { + // all tests can assume that flash.display.Sprite + // flash.system.System and flash.events.Event have been imported + String[] imports = new String[] + { + }; + String[] declarations = new String[] + { + "private var _hello:String;", + "public function get hello():String {", + " return _hello; }", + "public function set hello(value:String):void {", + " _hello = value; }", + "public function test():void {", + " this.hello = 'bye'; }", + }; + String[] testCode = new String[] + { + "test();", + "assertEqual('hello', hello, 'bye');", + }; + String source = getAS(imports, declarations, testCode, new String[0]); + compileAndRun(source); + } + + @Test + public void ASVariableTests_setterBothPrivate() + { + // all tests can assume that flash.display.Sprite + // flash.system.System and flash.events.Event have been imported + String[] imports = new String[] + { + }; + String[] declarations = new String[] + { + "private var _hello:String;", + "private function get hello():String {", + " return _hello; }", + "private function set hello(value:String):void {", + " _hello = value; }", + "public function test():void {", + " this.hello = 'bye'; }", + }; + String[] testCode = new String[] + { + "test();", + "assertEqual('hello', hello, 'bye');", + }; + String source = getAS(imports, declarations, testCode, new String[0]); + compileAndRun(source); + } + + @Test + public void ASVariableTests_setterPrivateGetterPublic() + { + // all tests can assume that flash.display.Sprite + // flash.system.System and flash.events.Event have been imported + String[] imports = new String[] + { + }; + String[] declarations = new String[] + { + "private var _hello:String;", + "public function get hello():String {", + " return _hello; }", + "private function set hello(value:String):void {", + " _hello = value; }", + "public function test():void {", + " this.hello = 'bye'; }", + }; + String[] testCode = new String[] + { + "test();", + "assertEqual('hello', hello, 'bye');", + }; + String source = getAS(imports, declarations, testCode, new String[0]); + compileAndExpectErrors(source, false, false, false, new String[0], "Property hello is read-only.\n"); + } + + @Test + public void ASVariableTests_setterPrivateGetterPublicWithNamespace() + { + // all tests can assume that flash.display.Sprite + // flash.system.System and flash.events.Event have been imported + String[] imports = new String[] + { + }; + String[] declarations = new String[] + { + "private var _hello:String;", + "public function get hello():String {", + " return _hello; }", + "private function set hello(value:String):void {", + " _hello = value; }", + "public function test():void {", + " this.private::hello = 'bye'; }", + }; + String[] testCode = new String[] + { + "test();", + "assertEqual('hello', hello, 'bye');", + }; + String source = getAS(imports, declarations, testCode, new String[0]); + compileAndRun(source); + } + /* public void ASVariableTests_VectorInitializer() {
