You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by cd...@apache.org on 2016/09/29 08:35:50 UTC

[2/3] git commit: [flex-asjs] [refs/heads/feature-autobuild/maven-archetypes] - [FIXES] Fixed interfaces getter in TypeDefinition, added extra tests, and fixed issues with Alias support

[FIXES] Fixed interfaces getter in TypeDefinition, added extra tests, and fixed issues with Alias support


Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/58e255cd
Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/58e255cd
Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/58e255cd

Branch: refs/heads/feature-autobuild/maven-archetypes
Commit: 58e255cd9790666ff3a54ac4b4b6dc1ed73b5b91
Parents: 5b6f4ec
Author: greg-dove <gr...@gmail.com>
Authored: Thu Sep 29 17:57:31 2016 +1300
Committer: greg-dove <gr...@gmail.com>
Committed: Thu Sep 29 17:57:31 2016 +1300

----------------------------------------------------------------------
 RELEASE_NOTES                                   | 12 ++-
 .../apache/flex/reflection/TypeDefinition.as    | 13 +--
 .../apache/flex/reflection/getAliasByClass.as   |  8 +-
 .../apache/flex/reflection/getClassByAlias.as   |  1 +
 .../flex/reflection/registerClassAlias.as       |  2 +-
 .../src/flexUnitTests/ReflectionTester.as       |  6 ++
 .../reflection/ReflectionTesterTest.as          |  7 +-
 .../reflection/ReflectionTesterTestAlias.as     | 90 +++++++++++++++++++
 .../reflection/ReflectionTesterTestUseCache.as  | 93 ++++++++++++++++++++
 9 files changed, 220 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/58e255cd/RELEASE_NOTES
----------------------------------------------------------------------
diff --git a/RELEASE_NOTES b/RELEASE_NOTES
index ea1ea2d..f768112 100644
--- a/RELEASE_NOTES
+++ b/RELEASE_NOTES
@@ -1,4 +1,4 @@
-Apache FlexJS 0.7.0
+Apache FlexJS 0.8.0
 =================
 
 Apache FlexJS is a next-generation Flex SDK that provides the capability
@@ -10,7 +10,17 @@ It is an \u2018beta\u2019 type of release.   Expect to find lots of bugs and missing
 features.
 
 New Features
+=================
+-more complete Reflection implementation with access to static members, kept metadata and method parameters
+-added cross-platform registerClassAlias/getAliasByClass/getClassByAlias implementations (reflection package)
+
+
+Bug Fixes
 ---------
+
+
+Apache FlexJS 0.7.0
+=================
 - Support for XML contructors and literals as well as E4X.
 See here for limitations: https://cwiki.apache.org/confluence/display/FLEX/Using+XML+in+FlexJS
 - Support for Typed Node.js

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/58e255cd/frameworks/projects/Reflection/src/main/flex/org/apache/flex/reflection/TypeDefinition.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Reflection/src/main/flex/org/apache/flex/reflection/TypeDefinition.as b/frameworks/projects/Reflection/src/main/flex/org/apache/flex/reflection/TypeDefinition.as
index 7070e5a..346c6ed 100755
--- a/frameworks/projects/Reflection/src/main/flex/org/apache/flex/reflection/TypeDefinition.as
+++ b/frameworks/projects/Reflection/src/main/flex/org/apache/flex/reflection/TypeDefinition.as
@@ -33,17 +33,18 @@ COMPILE::SWF {
     public class TypeDefinition extends DefinitionWithMetaData
 	{
 
-        COMPILE::JS {
+            COMPILE::JS
             //js storage support for class aliases
             private static var _aliasMappings:Object={};
 
+            COMPILE::JS
             /**
              * @private
              * @param aliasName
              * @param classObject
              */
             internal static function registerClassAlias(aliasName:String, classObject:Class ) :void{
-                var info:* = classObject.FLEXJS_CLASS_INFO;
+                var info:* = classObject.prototype.FLEXJS_CLASS_INFO;
                 if (info) {
                     //a class may have more than one alias point to it, but only the most recently registered
                     //alias is retained for reflection (applying same approach as swf)
@@ -57,14 +58,16 @@ COMPILE::SWF {
                     //from the other class's FLEXJS_CLASS_INFO
                     var altClass:Class = _aliasMappings[aliasName];
                     if (altClass) {
-                        var altInfo:* = altClass.FLEXJS_CLASS_INFO;
+                        var altInfo:* = altClass.prototype.FLEXJS_CLASS_INFO;
                         delete altInfo.alias;
                     }
                     _aliasMappings[aliasName] = classObject;
                     info.alias = aliasName;
+
                 } else throw new Error("registerClassAlias error: classObject is not Reflectable "+classObject);
             }
 
+            COMPILE::JS
             /**
              * @private
              * @param aliasName
@@ -74,8 +77,6 @@ COMPILE::SWF {
                 return _aliasMappings[aliasName];
             }
 
-        }
-
 
 
         //special cases
@@ -392,7 +393,7 @@ COMPILE::SWF {
                 var i:uint, n:int;
                 if (data !== undefined)
                 {
-                    var collect:Array = data.interfaces || [];
+                    var collect:Array = data.interfaces ?  data.interfaces.slice() : [];
                     var qname:String = data.names[0].qName;
                     var def:Object = getDefinitionByName(qname);
                     if ((_kind || kind) == "interface") {

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/58e255cd/frameworks/projects/Reflection/src/main/flex/org/apache/flex/reflection/getAliasByClass.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Reflection/src/main/flex/org/apache/flex/reflection/getAliasByClass.as b/frameworks/projects/Reflection/src/main/flex/org/apache/flex/reflection/getAliasByClass.as
index aebb4c6..6a0f85b 100644
--- a/frameworks/projects/Reflection/src/main/flex/org/apache/flex/reflection/getAliasByClass.as
+++ b/frameworks/projects/Reflection/src/main/flex/org/apache/flex/reflection/getAliasByClass.as
@@ -34,13 +34,15 @@ COMPILE::SWF {
         if (classObject == null) throw new TypeError("Parameter classObject must be non-null.");
         COMPILE::SWF {
             ret= flash.utils.describeType(classObject).@alias;
+            if (ret.length==0) ret = null;
         }
 
         COMPILE::JS {
-            var info:* = classObject.FLEXJS_CLASS_INFO;
+            var info:* = classObject.prototype.FLEXJS_CLASS_INFO;
             if (info) {
-                ret = info.alias || "";
-            } else ret="";
+                ret = info.alias;
+                if (ret == '') ret = null;
+            } else ret=null;
         }
         return ret;
     }

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/58e255cd/frameworks/projects/Reflection/src/main/flex/org/apache/flex/reflection/getClassByAlias.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Reflection/src/main/flex/org/apache/flex/reflection/getClassByAlias.as b/frameworks/projects/Reflection/src/main/flex/org/apache/flex/reflection/getClassByAlias.as
index e59a61b..52604a4 100644
--- a/frameworks/projects/Reflection/src/main/flex/org/apache/flex/reflection/getClassByAlias.as
+++ b/frameworks/projects/Reflection/src/main/flex/org/apache/flex/reflection/getClassByAlias.as
@@ -35,6 +35,7 @@ COMPILE::SWF {
 
         COMPILE::JS {
             if (aliasName == null) throw new TypeError("Parameter aliasName must be non-null.");
+            if (aliasName.length==0) throw new TypeError("Parameter aliasName must be non-empty string.");
             var klazz:Class = TypeDefinition.getClassByAlias(aliasName);
             if (!klazz) throw new ReferenceError("Class "+aliasName+" could not be found.");
             return klazz;

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/58e255cd/frameworks/projects/Reflection/src/main/flex/org/apache/flex/reflection/registerClassAlias.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Reflection/src/main/flex/org/apache/flex/reflection/registerClassAlias.as b/frameworks/projects/Reflection/src/main/flex/org/apache/flex/reflection/registerClassAlias.as
index c06bd42..7d2cf16 100644
--- a/frameworks/projects/Reflection/src/main/flex/org/apache/flex/reflection/registerClassAlias.as
+++ b/frameworks/projects/Reflection/src/main/flex/org/apache/flex/reflection/registerClassAlias.as
@@ -31,13 +31,13 @@ COMPILE::SWF {
      */
     public function registerClassAlias(aliasName:String, classObject:Class):void {
         COMPILE::SWF {
-
             flash.net.registerClassAlias(aliasName,classObject);
         }
 
         COMPILE::JS {
             if (classObject == null) throw new TypeError("Parameter classObject must be non-null.");
             if (aliasName == null) throw new TypeError("Parameter aliasName must be non-null.");
+            if (aliasName.length==0) throw new TypeError("Parameter aliasName must be non-empty string.");
             TypeDefinition.registerClassAlias(aliasName , classObject);
         }
     }

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/58e255cd/manualtests/GenericTests/src/flexUnitTests/ReflectionTester.as
----------------------------------------------------------------------
diff --git a/manualtests/GenericTests/src/flexUnitTests/ReflectionTester.as b/manualtests/GenericTests/src/flexUnitTests/ReflectionTester.as
index 2feaa14..14a7aa6 100644
--- a/manualtests/GenericTests/src/flexUnitTests/ReflectionTester.as
+++ b/manualtests/GenericTests/src/flexUnitTests/ReflectionTester.as
@@ -24,6 +24,12 @@ package flexUnitTests
     [RunWith("org.flexunit.runners.Suite")]
     public class ReflectionTester
     {
+
+
+        public var reflectionTesterCacheTest:ReflectionTesterTestUseCache;
+
         public var reflectionTesterTest:ReflectionTesterTest;
+        
+        public var reflectionTesterAliasTest:ReflectionTesterTestAlias;
     }
 }

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/58e255cd/manualtests/GenericTests/src/flexUnitTests/reflection/ReflectionTesterTest.as
----------------------------------------------------------------------
diff --git a/manualtests/GenericTests/src/flexUnitTests/reflection/ReflectionTesterTest.as b/manualtests/GenericTests/src/flexUnitTests/reflection/ReflectionTesterTest.as
index 0ea5126..951e782 100644
--- a/manualtests/GenericTests/src/flexUnitTests/reflection/ReflectionTesterTest.as
+++ b/manualtests/GenericTests/src/flexUnitTests/reflection/ReflectionTesterTest.as
@@ -52,6 +52,8 @@ package flexUnitTests.reflection
 		 [Before]
         public function setUp():void
         {
+            TestClass2.testStaticVar = "testStaticVar_val";
+            TestClass2.testStaticWriteOnly = "staticAccessor_initial_value";
         }
         
         [After]
@@ -284,6 +286,7 @@ package flexUnitTests.reflection
             /** static vars **/
             variables = def.staticVariables;
 
+            
             variable = variables[0];
             Assert.assertEquals("unexpected variable name","testStaticVar",variable.name);
             meta = variable.retrieveMetaDataByName("TestMeta")[0];
@@ -298,6 +301,8 @@ package flexUnitTests.reflection
             /** static accessors **/
 
             accessors = def.staticAccessors;
+
+            
             testReadOnly = retrieveItemWithName(accessors,"testStaticReadOnly") as AccessorDefinition;
             meta = testReadOnly.retrieveMetaDataByName("TestMeta")[0];
             Assert.assertEquals("unexpected meta name","TestMeta",meta.name);
@@ -348,7 +353,7 @@ package flexUnitTests.reflection
 
 
 		[Test]
-        public function testIntefaceReflection():void{
+        public function testInterfaceReflection():void{
             var def:TypeDefinition = describeType(ITestInterface4);
             Assert.assertEquals("unexpected kind value","interface",def.kind);
             Assert.assertEquals("unexpected interfaces length",3,def.interfaces.length);

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/58e255cd/manualtests/GenericTests/src/flexUnitTests/reflection/ReflectionTesterTestAlias.as
----------------------------------------------------------------------
diff --git a/manualtests/GenericTests/src/flexUnitTests/reflection/ReflectionTesterTestAlias.as b/manualtests/GenericTests/src/flexUnitTests/reflection/ReflectionTesterTestAlias.as
new file mode 100644
index 0000000..7fd5984
--- /dev/null
+++ b/manualtests/GenericTests/src/flexUnitTests/reflection/ReflectionTesterTestAlias.as
@@ -0,0 +1,90 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  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 flexUnitTests.reflection
+{
+    import flexunit.framework.Assert;
+	import flexUnitTests.reflection.support.*;
+    import org.apache.flex.reflection.*;
+    
+    public class ReflectionTesterTestAlias
+    {		
+       
+        public static var isJS:Boolean;
+        [BeforeClass]
+        public static function setUpBeforeClass():void
+        {
+            var js:Boolean = false;
+            try {
+                var check:* = getDefinitionByName("flash.system.Capabilities");
+            } catch (e:Error) {
+                js = true;
+            }
+            //if this next reference to 'check' is not included, then the above try/catch code
+            //appears to be optimized away in js-release mode
+            //a separate test has been created for this
+            if (check == null) {
+                js = true;
+            }
+            isJS = js;
+        }
+        
+        [AfterClass]
+        public static function tearDownAfterClass():void
+        {
+        }
+		
+		 [Before]
+        public function setUp():void
+        {
+
+        }
+        
+        [After]
+        public function tearDown():void
+        {
+
+        }
+
+
+
+
+        [Test]
+        public function testBasicAlias():void {
+            //no initial alias
+            Assert.assertNull(getAliasByClass(TestClass2));
+            registerClassAlias("fjsTest", TestClass2);
+            //alias is registered
+            Assert.assertEquals("unexpected Alias value","fjsTest",getAliasByClass(TestClass2));
+            //register same alias for another class
+            registerClassAlias("fjsTest", TestClass3);
+            //original alias mapping is deregistered
+            Assert.assertNull(getAliasByClass(TestClass2));
+            //alias is registered for new class
+            Assert.assertEquals("unexpected Alias value","fjsTest",getAliasByClass(TestClass3));
+
+            //class is retrievable by alias
+            Assert.assertEquals("unexpected Class value",TestClass3,getClassByAlias("fjsTest"));
+
+
+        }
+
+
+
+    }
+}

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/58e255cd/manualtests/GenericTests/src/flexUnitTests/reflection/ReflectionTesterTestUseCache.as
----------------------------------------------------------------------
diff --git a/manualtests/GenericTests/src/flexUnitTests/reflection/ReflectionTesterTestUseCache.as b/manualtests/GenericTests/src/flexUnitTests/reflection/ReflectionTesterTestUseCache.as
new file mode 100644
index 0000000..9722647
--- /dev/null
+++ b/manualtests/GenericTests/src/flexUnitTests/reflection/ReflectionTesterTestUseCache.as
@@ -0,0 +1,93 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  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 flexUnitTests.reflection
+{
+    import flexunit.framework.Assert;
+	import flexUnitTests.reflection.support.*;
+    import org.apache.flex.reflection.*;
+    
+    public class ReflectionTesterTestUseCache
+    {		
+       
+        public static var isJS:Boolean;
+        [BeforeClass]
+        public static function setUpBeforeClass():void
+        {
+            var js:Boolean = false;
+            try {
+                var check:* = getDefinitionByName("flash.system.Capabilities");
+            } catch (e:Error) {
+                js = true;
+            }
+            //if this next reference to 'check' is not included, then the above try/catch code
+            //appears to be optimized away in js-release mode
+            //a separate test has been created for this
+            if (check == null) {
+                js = true;
+            }
+            isJS = js;
+        }
+        
+        [AfterClass]
+        public static function tearDownAfterClass():void
+        {
+        }
+		
+		 [Before]
+        public function setUp():void
+        {
+            TypeDefinition.useCache = true;
+            TestClass2.testStaticVar = "testStaticVar_val";
+            TestClass2.testStaticWriteOnly = "staticAccessor_initial_value";
+        }
+        
+        [After]
+        public function tearDown():void
+        {
+            TypeDefinition.useCache = false;
+        }
+
+        private static function retrieveItemWithName(collection:Array, name:String):DefinitionBase {
+            var ret:DefinitionBase;
+            var i:uint=0,l:uint=collection.length;
+            for (;i<l;i++) {
+                if (collection[i].name==name) {
+                    ret = collection[i];
+                    break;
+                }
+            }
+
+            return ret;
+        }
+
+
+        [Test]
+        public function testBasicCache():void {
+            var def:TypeDefinition = describeType(TestClass2);
+
+            var def2:TypeDefinition = describeType(TestClass2);
+
+            Assert.assertEquals("cache not working",def,def2);
+
+        }
+
+
+
+    }
+}