This is an automated email from the ASF dual-hosted git repository.

gregdove pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-asjs.git

commit 6cce56f26414653c33cc79cc772b066400db3e5b
Author: greg-dove <[email protected]>
AuthorDate: Wed Jul 3 20:00:47 2019 +1200

    Reflection updates - minor improvements, and addition of new utility methods
---
 .../src/main/royale/ReflectionClasses.as           |   5 +
 .../apache/royale/reflection/AccessorDefinition.as |  12 ++-
 .../apache/royale/reflection/CompilationData.as    |  29 +++++-
 .../org/apache/royale/reflection/TypeDefinition.as |  23 ++++-
 .../org/apache/royale/reflection/describeType.as   |   8 +-
 .../royale/reflection/getQualifiedClassName.as     |   2 +-
 .../reflection/getQualifiedSuperclassName.as       |   2 +-
 .../apache/royale/reflection/isDynamicObject.as    |   2 +-
 .../defaultConstantConventionCheck.as}             |  35 ++-----
 .../filterForMetaTags.as}                          |  47 +++++-----
 .../reflection/utils/getMembersWithMetadata.as     |  55 +++++++++++
 .../getMembersWithNameMatch.as}                    |  52 ++++++-----
 .../utils/getStaticConstantsByConvention.as        | 103 +++++++++++++++++++++
 13 files changed, 290 insertions(+), 85 deletions(-)

diff --git 
a/frameworks/projects/Reflection/src/main/royale/ReflectionClasses.as 
b/frameworks/projects/Reflection/src/main/royale/ReflectionClasses.as
index 3a7df74..640e170 100644
--- a/frameworks/projects/Reflection/src/main/royale/ReflectionClasses.as
+++ b/frameworks/projects/Reflection/src/main/royale/ReflectionClasses.as
@@ -45,6 +45,11 @@ internal class ReflectionClasses
        import org.apache.royale.reflection.getQualifiedClassName; 
getQualifiedClassName;
        import org.apache.royale.reflection.getQualifiedSuperclassName; 
getQualifiedSuperclassName;
        import org.apache.royale.reflection.registerClassAlias; 
registerClassAlias;
+       //utils
+       import org.apache.royale.reflection.utils.getMembersWithMetadata; 
getMembersWithMetadata;
+       import 
org.apache.royale.reflection.utils.getStaticConstantsByConvention; 
getStaticConstantsByConvention;
+       import org.apache.royale.reflection.utils.getMembersWithNameMatch; 
getMembersWithNameMatch;
+       import org.apache.royale.reflection.utils.filterForMetaTags; 
filterForMetaTags;
        
        import org.apache.royale.reflection.ExtraData; ExtraData;
        import org.apache.royale.reflection.AccessorDefinition; 
AccessorDefinition;
diff --git 
a/frameworks/projects/Reflection/src/main/royale/org/apache/royale/reflection/AccessorDefinition.as
 
b/frameworks/projects/Reflection/src/main/royale/org/apache/royale/reflection/AccessorDefinition.as
index 4a93d8b..fe113f8 100644
--- 
a/frameworks/projects/Reflection/src/main/royale/org/apache/royale/reflection/AccessorDefinition.as
+++ 
b/frameworks/projects/Reflection/src/main/royale/org/apache/royale/reflection/AccessorDefinition.as
@@ -79,7 +79,9 @@ package org.apache.royale.reflection {
         COMPILE::JS
         override public function get getValue():Function{
                        if (_getter != null) return _getter;
-            var cl:Class = getDefinitionByName(owner.qualifiedName) as Class;
+            if (isStatic || goog.DEBUG) {
+                var cl:Class = getDefinitionByName(owner.qualifiedName) as 
Class;
+            }
             var fieldName:String = name;
             if (isStatic) {
                 _getter = function():* {return cl[fieldName]}
@@ -97,7 +99,9 @@ package org.apache.royale.reflection {
                COMPILE::JS
                override public function get setValue():Function{
                        if (_setter != null) return _setter;
-                       var cl:Class = getDefinitionByName(owner.qualifiedName) 
as Class;
+            if (isStatic || goog.DEBUG) {
+                var cl:Class = getDefinitionByName(owner.qualifiedName) as 
Class;
+            }
                        var fieldName:String = name;
                        if (isStatic) {
                                _setter = function(value:*):* {
@@ -106,12 +110,12 @@ package org.apache.royale.reflection {
                        } else {
                                _setter = function(instance:Object, value:*):* {
                                        if (goog.DEBUG) {
-                                               if (arguments.length != 2 || 
(!(instance is cl))) throw 'invalidsetValue parameters';
+                                               if (arguments.length != 2 || 
(!(instance is cl))) throw 'invalid setValue parameters';
                                        }
                                        instance[fieldName] = value;
                                }
                        }
-                       return _getter;
+                       return _setter;
                }
         
 
diff --git 
a/frameworks/projects/Reflection/src/main/royale/org/apache/royale/reflection/CompilationData.as
 
b/frameworks/projects/Reflection/src/main/royale/org/apache/royale/reflection/CompilationData.as
index 9d7ba42..d1edf07 100644
--- 
a/frameworks/projects/Reflection/src/main/royale/org/apache/royale/reflection/CompilationData.as
+++ 
b/frameworks/projects/Reflection/src/main/royale/org/apache/royale/reflection/CompilationData.as
@@ -33,6 +33,7 @@ package org.apache.royale.reflection {
         *  @playerversion Flash 10.2
         *  @playerversion AIR 2.6
         *  @productversion Royale 0.0
+        *
         */
        public class CompilationData {
                COMPILE::JS{
@@ -61,7 +62,9 @@ package org.apache.royale.reflection {
                        }
                }
                
-               
+               /**
+                * @royalesuppressexport
+                */
                public static function hasCompilationOption(flags:uint, 
optionBits:uint):Boolean {
                        COMPILE::SWF{
                                return false;
@@ -70,7 +73,9 @@ package org.apache.royale.reflection {
                                return Boolean((flags & optionBits) === 
optionBits);
                        }
                }
-               
+               /**
+                * @royalesuppressexport
+                */
                public static function asStrings(flags:uint):Array {
                        var ret:Array = [];
                        COMPILE::JS{
@@ -86,6 +91,23 @@ package org.apache.royale.reflection {
                        return ret;
                }
                
+               /**
+                * @royalesuppressexport
+                */
+               public static function describeSingleFlag(flag:uint):String {
+                       var ret:String;
+                       COMPILE::JS{
+                               if (flag in _DESCRIPTIONS) {
+                                       ret = _DESCRIPTIONS[flag];
+                               }
+                       }
+                       if (!ret) {
+                               ret = 'Unknown Compilation Flag';
+                       }
+                       return ret;
+               }
+               
+               
                COMPILE::SWF
                public function CompilationData(inspect:Object) {
                        throw new Error('CompilationData not implemented for 
swf');
@@ -94,6 +116,7 @@ package org.apache.royale.reflection {
                COMPILE::JS
                /**
                 * @royaleignorecoercion Class
+                * 
                 */
                public function CompilationData(inspect:Object) {
                        if (!inspect) throw new Error('CompilationData 
constructor parameter cannot be null');
@@ -127,6 +150,8 @@ package org.apache.royale.reflection {
                 *                If not specified or less than zero, then it 
is the full set of flags on this
                 *                CompilationData.
                 * @return true if the ancestors have the same flags set, false 
otherwise
+                * 
+                * @royalesuppressexport
                 */
                public function hasSameAncestry(specificFlags:int = -1):Boolean{
 
diff --git 
a/frameworks/projects/Reflection/src/main/royale/org/apache/royale/reflection/TypeDefinition.as
 
b/frameworks/projects/Reflection/src/main/royale/org/apache/royale/reflection/TypeDefinition.as
index 51c15ad..f916e65 100755
--- 
a/frameworks/projects/Reflection/src/main/royale/org/apache/royale/reflection/TypeDefinition.as
+++ 
b/frameworks/projects/Reflection/src/main/royale/org/apache/royale/reflection/TypeDefinition.as
@@ -106,11 +106,16 @@ COMPILE::SWF {
          * is discouraged.
          * @param name the qualified name of the definition,
          * @param rawData (optional) the reflection data if already available
+         * @param clazz (optional) a class reference to store internally for 
performance of getClass method
          * @return a TypeDefinition representing the class or interface 
represented by the parameters
          */
-        public static function getDefinition(name:String, rawData:Object = 
null):TypeDefinition {
+        public static function getDefinition(name:String, rawData:Object = 
null, clazz:Class = null):TypeDefinition {
             if (rawData == null) return null;
-            return internalGetDefinition(name, rawData);
+            const def:TypeDefinition = internalGetDefinition(name, rawData);
+            if (clazz) {
+                def._class = clazz;
+            }
+            return def;
         }
         
         internal static function internalGetDefinition(name:String, 
rawData:Object = null):TypeDefinition{
@@ -226,6 +231,20 @@ COMPILE::SWF {
             if (_packageName.length) return _packageName + "." + _name;
             else return _name;
         }
+        
+        private var _class:Class;
+        
+        /**
+         * convenience method to access the class definition from this 
TypeDefinition
+         * @return the original class (or interface) described by this 
TypeDefinition
+         * 
+         * @royaleignorecoercion Class
+         */
+        public function getClass():Class{
+            if (!_class)
+                _class = getDefinitionByName(qualifiedName) as Class;
+            return _class;
+        }
 
         /**
          * @private
diff --git 
a/frameworks/projects/Reflection/src/main/royale/org/apache/royale/reflection/describeType.as
 
b/frameworks/projects/Reflection/src/main/royale/org/apache/royale/reflection/describeType.as
index 13d8cd7..ab1d7af 100755
--- 
a/frameworks/projects/Reflection/src/main/royale/org/apache/royale/reflection/describeType.as
+++ 
b/frameworks/projects/Reflection/src/main/royale/org/apache/royale/reflection/describeType.as
@@ -21,7 +21,6 @@ package org.apache.royale.reflection
 COMPILE::SWF
 {
     import flash.utils.describeType;
-    import flash.external.ExternalInterface;
 }
 COMPILE::JS
 {
@@ -35,6 +34,8 @@ COMPILE::JS
      *  @playerversion Flash 10.2
      *  @playerversion AIR 2.6
      *  @productversion Royale 0.0
+     *  
+     *  @royaleignorecoercion Class
      */
     public function describeType(value:Object):TypeDefinition
        {
@@ -50,11 +51,12 @@ COMPILE::JS
                 }
             }
             var xml:XML = flash.utils.describeType(value);
-            return TypeDefinition.getDefinition(xml.@name, xml);
+            return TypeDefinition.getDefinition(xml.@name, xml, value as 
Class);
         }
         COMPILE::JS
         {
             const qname:String = getQualifiedClassName(value);
+            var clazz:Class = value ? (value.prototype ? value : 
value.constructor) as Class : null;
             var data:Object = value.ROYALE_CLASS_INFO || (value.prototype ? 
value.prototype.ROYALE_CLASS_INFO : null);
             if (!data) {
                 if (ExtraData.hasData(qname)) {
@@ -68,7 +70,7 @@ COMPILE::JS
                     }
                 }
             }
-            return TypeDefinition.getDefinition(qname, data);
+            return TypeDefinition.getDefinition(qname, data, clazz);
         }
     }
 }
diff --git 
a/frameworks/projects/Reflection/src/main/royale/org/apache/royale/reflection/getQualifiedClassName.as
 
b/frameworks/projects/Reflection/src/main/royale/org/apache/royale/reflection/getQualifiedClassName.as
index cefb825..c4379b6 100755
--- 
a/frameworks/projects/Reflection/src/main/royale/org/apache/royale/reflection/getQualifiedClassName.as
+++ 
b/frameworks/projects/Reflection/src/main/royale/org/apache/royale/reflection/getQualifiedClassName.as
@@ -39,7 +39,7 @@ COMPILE::JS{
         COMPILE::SWF
         {
             //normalize for Vector:
-            return 
flash.utils.getQualifiedClassName(value).replace('__AS3__.vec::','');
+            return 
flash.utils.getQualifiedClassName(value).replace('__AS3__.vec::','').replace('::','.');
         }
         COMPILE::JS
         {
diff --git 
a/frameworks/projects/Reflection/src/main/royale/org/apache/royale/reflection/getQualifiedSuperclassName.as
 
b/frameworks/projects/Reflection/src/main/royale/org/apache/royale/reflection/getQualifiedSuperclassName.as
index 4e53259..8b33fc0 100755
--- 
a/frameworks/projects/Reflection/src/main/royale/org/apache/royale/reflection/getQualifiedSuperclassName.as
+++ 
b/frameworks/projects/Reflection/src/main/royale/org/apache/royale/reflection/getQualifiedSuperclassName.as
@@ -35,7 +35,7 @@ COMPILE::SWF
        {
         COMPILE::SWF
         {
-            return flash.utils.getQualifiedSuperclassName(value);
+            return 
flash.utils.getQualifiedSuperclassName(value).replace('::','.');
         }
         COMPILE::JS
         {
diff --git 
a/frameworks/projects/Reflection/src/main/royale/org/apache/royale/reflection/isDynamicObject.as
 
b/frameworks/projects/Reflection/src/main/royale/org/apache/royale/reflection/isDynamicObject.as
index 20aa884..6e1348e 100644
--- 
a/frameworks/projects/Reflection/src/main/royale/org/apache/royale/reflection/isDynamicObject.as
+++ 
b/frameworks/projects/Reflection/src/main/royale/org/apache/royale/reflection/isDynamicObject.as
@@ -72,7 +72,7 @@ COMPILE::SWF
                                        if (inspect["wootHackwoot"] == 
"wootHackwoot") dyncheck=true;
                                        delete inspect["wootHackwoot"];
                                        
-                               } catch(e:Error) {};
+                               } catch(e:Error) {}
                                return dyncheck;
             } else return true
         }
diff --git 
a/frameworks/projects/Reflection/src/main/royale/org/apache/royale/reflection/getQualifiedSuperclassName.as
 
b/frameworks/projects/Reflection/src/main/royale/org/apache/royale/reflection/utils/defaultConstantConventionCheck.as
old mode 100755
new mode 100644
similarity index 55%
copy from 
frameworks/projects/Reflection/src/main/royale/org/apache/royale/reflection/getQualifiedSuperclassName.as
copy to 
frameworks/projects/Reflection/src/main/royale/org/apache/royale/reflection/utils/defaultConstantConventionCheck.as
index 4e53259..bce9687
--- 
a/frameworks/projects/Reflection/src/main/royale/org/apache/royale/reflection/getQualifiedSuperclassName.as
+++ 
b/frameworks/projects/Reflection/src/main/royale/org/apache/royale/reflection/utils/defaultConstantConventionCheck.as
@@ -16,34 +16,17 @@
 //  limitations under the License.
 //
 
////////////////////////////////////////////////////////////////////////////////
-package org.apache.royale.reflection
-{
-COMPILE::SWF
-{
-    import flash.utils.getQualifiedSuperclassName;
-}
+package org.apache.royale.reflection.utils {
+    
+
     
     /**
-     *  The equivalent of flash.utils.getQualifiedSuperclassName.
-     * 
-     *  @langversion 3.0
-     *  @playerversion Flash 10.2
-     *  @playerversion AIR 2.6
-     *  @productversion Royale 0.0
+     * @param candidate the string name to check for conformance with naming 
convention for constants
+     * @return true if the candidate string matches the naming convention for 
constants
      */
-    public function getQualifiedSuperclassName(value:*):String
-       {
-        COMPILE::SWF
-        {
-            return flash.utils.getQualifiedSuperclassName(value);
-        }
-        COMPILE::JS
-        {
-            var constructorAsObject:Object = value["constructor"];
-            value = constructorAsObject.superClass_;
-            if (value == null || value.ROYALE_CLASS_INFO == null)
-                return null;
-            return value.ROYALE_CLASS_INFO.names[0].qName;
-        }
+    internal function defaultConstantConventionCheck(candidate:String):Boolean 
{
+        return candidate && /^[A-Z][A-Z_0-9]+$/.test(candidate);
     }
+    
+    
 }
diff --git 
a/frameworks/projects/Reflection/src/main/royale/org/apache/royale/reflection/getQualifiedSuperclassName.as
 
b/frameworks/projects/Reflection/src/main/royale/org/apache/royale/reflection/utils/filterForMetaTags.as
old mode 100755
new mode 100644
similarity index 51%
copy from 
frameworks/projects/Reflection/src/main/royale/org/apache/royale/reflection/getQualifiedSuperclassName.as
copy to 
frameworks/projects/Reflection/src/main/royale/org/apache/royale/reflection/utils/filterForMetaTags.as
index 4e53259..dd4c9b1
--- 
a/frameworks/projects/Reflection/src/main/royale/org/apache/royale/reflection/getQualifiedSuperclassName.as
+++ 
b/frameworks/projects/Reflection/src/main/royale/org/apache/royale/reflection/utils/filterForMetaTags.as
@@ -16,34 +16,33 @@
 //  limitations under the License.
 //
 
////////////////////////////////////////////////////////////////////////////////
-package org.apache.royale.reflection
-{
-COMPILE::SWF
-{
-    import flash.utils.getQualifiedSuperclassName;
-}
+package org.apache.royale.reflection.utils {
+    
+    import org.apache.royale.reflection.*;
+    
     
     /**
-     *  The equivalent of flash.utils.getQualifiedSuperclassName.
      * 
-     *  @langversion 3.0
-     *  @playerversion Flash 10.2
-     *  @playerversion AIR 2.6
-     *  @productversion Royale 0.0
+     * @param memberDefinitions the member definitions to check
+     * @param tags the metatags to search for
+     * @param intoArray optional external Array to add matching definitions to 
+     * @return array of matching members
      */
-    public function getQualifiedSuperclassName(value:*):String
-       {
-        COMPILE::SWF
-        {
-            return flash.utils.getQualifiedSuperclassName(value);
-        }
-        COMPILE::JS
-        {
-            var constructorAsObject:Object = value["constructor"];
-            value = constructorAsObject.superClass_;
-            if (value == null || value.ROYALE_CLASS_INFO == null)
-                return null;
-            return value.ROYALE_CLASS_INFO.names[0].qName;
+    public function filterForMetaTags(memberDefinitions:Array, tags:Array, 
intoArray:Array = null):Array {
+        var ret:Array = intoArray ? intoArray : [];
+        const l:uint = memberDefinitions.length;
+        var tagCount:uint = tags.length;
+        for (var i:uint = 0; i< l; i++) {
+            var memberDefintion:MemberDefinitionBase = memberDefinitions[i];
+            for (var j:uint = 0; j< tagCount; j++) {
+                if (memberDefintion.retrieveMetaDataByName(tags[j]).length) {
+                    ret.push(memberDefintion);
+                    break;
+                }
+            }
         }
+        return ret;
     }
+    
+    
 }
diff --git 
a/frameworks/projects/Reflection/src/main/royale/org/apache/royale/reflection/utils/getMembersWithMetadata.as
 
b/frameworks/projects/Reflection/src/main/royale/org/apache/royale/reflection/utils/getMembersWithMetadata.as
new file mode 100644
index 0000000..927cd1c
--- /dev/null
+++ 
b/frameworks/projects/Reflection/src/main/royale/org/apache/royale/reflection/utils/getMembersWithMetadata.as
@@ -0,0 +1,55 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  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 org.apache.royale.reflection.utils
+{
+       import org.apache.royale.reflection.*;
+       
+       
+    /**
+     *  A utility method to retrieve all members with a single metadata tag 
name (String) 
+        *  or one of various tag names (an Array of Strings)
+        *  It will return variables, accessors or methods that have the 
specified metadata (assuming it is included in the build)
+        *  
+     *  @param fromDefinition the definition to retrieve the member 
definitions from
+        *  @param tagsOrTag either a String or and Array of Strings to search 
for
+        *  @param includeStatics true if static members should be searched. 
Defaults to false, so only instance members are searched
+     *
+     *  @langversion 3.0
+     *  @playerversion Flash 10.2
+     *  @playerversion AIR 2.6
+     *  @productversion Royale 0.0
+     */
+    public function getMembersWithMetadata(fromDefinition:TypeDefinition, 
tagsOrTag:Object, includeStatics:Boolean = false):Array
+       {
+        var ret:Array = [];
+               if (!fromDefinition) return ret;
+               var search:Array = tagsOrTag is Array ? tagsOrTag as Array : 
[tagsOrTag+''];
+               if (includeStatics) {
+                       filterForMetaTags(fromDefinition.staticVariables, 
search, ret);
+                       filterForMetaTags(fromDefinition.staticAccessors, 
search, ret);
+                       filterForMetaTags(fromDefinition.staticMethods, search, 
ret);
+               }
+               filterForMetaTags(fromDefinition.variables, search, ret);
+               filterForMetaTags(fromDefinition.accessors, search, ret);
+               filterForMetaTags(fromDefinition.methods, search, ret);
+               return ret;
+    }
+       
+       
+}
diff --git 
a/frameworks/projects/Reflection/src/main/royale/org/apache/royale/reflection/getQualifiedSuperclassName.as
 
b/frameworks/projects/Reflection/src/main/royale/org/apache/royale/reflection/utils/getMembersWithNameMatch.as
old mode 100755
new mode 100644
similarity index 51%
copy from 
frameworks/projects/Reflection/src/main/royale/org/apache/royale/reflection/getQualifiedSuperclassName.as
copy to 
frameworks/projects/Reflection/src/main/royale/org/apache/royale/reflection/utils/getMembersWithNameMatch.as
index 4e53259..2fbb515
--- 
a/frameworks/projects/Reflection/src/main/royale/org/apache/royale/reflection/getQualifiedSuperclassName.as
+++ 
b/frameworks/projects/Reflection/src/main/royale/org/apache/royale/reflection/utils/getMembersWithNameMatch.as
@@ -16,34 +16,44 @@
 //  limitations under the License.
 //
 
////////////////////////////////////////////////////////////////////////////////
-package org.apache.royale.reflection
+package org.apache.royale.reflection.utils
 {
-COMPILE::SWF
-{
-    import flash.utils.getQualifiedSuperclassName;
-}
-    
+       import org.apache.royale.reflection.*;
+       
+       
     /**
-     *  The equivalent of flash.utils.getQualifiedSuperclassName.
-     * 
+     *  A utility method to retrieve all members with a name that matches via 
the matcher argument
+        *  
+     *  @param memberCollection the collection (an Array) of member 
definitions to check
+        *  @param matcher *must be* either a String or a Regexp instance to 
use for testing
+        *  @param collate an optional array to collate into, if passed 
externally
+        *  
+        *  @returns an Array (the collate parameter if it was used, otherwise 
a new Array)
+     *
      *  @langversion 3.0
      *  @playerversion Flash 10.2
      *  @playerversion AIR 2.6
      *  @productversion Royale 0.0
+        *  
+        *  @royaleignorecoercion RegExp
      */
-    public function getQualifiedSuperclassName(value:*):String
+    public function getMembersWithNameMatch(memberCollection:Array,  
matcher:Object = null, collate:Array = null):Array
        {
-        COMPILE::SWF
-        {
-            return flash.utils.getQualifiedSuperclassName(value);
-        }
-        COMPILE::JS
-        {
-            var constructorAsObject:Object = value["constructor"];
-            value = constructorAsObject.superClass_;
-            if (value == null || value.ROYALE_CLASS_INFO == null)
-                return null;
-            return value.ROYALE_CLASS_INFO.names[0].qName;
-        }
+        var ret:Array = collate ? collate : [];
+               var regexp:RegExp;
+               if (matcher is String) {
+                       regexp = new RegExp('^' + matcher + '$');
+               } else {
+                       regexp = matcher as RegExp;
+               }
+               if (memberCollection) {
+                       for each(var item:MemberDefinitionBase in 
memberCollection) {
+                               if (!regexp || regexp.test(item.name)) 
ret.push(item);
+                       }
+               }
+
+               return ret;
     }
+       
+       
 }
diff --git 
a/frameworks/projects/Reflection/src/main/royale/org/apache/royale/reflection/utils/getStaticConstantsByConvention.as
 
b/frameworks/projects/Reflection/src/main/royale/org/apache/royale/reflection/utils/getStaticConstantsByConvention.as
new file mode 100644
index 0000000..cc32805
--- /dev/null
+++ 
b/frameworks/projects/Reflection/src/main/royale/org/apache/royale/reflection/utils/getStaticConstantsByConvention.as
@@ -0,0 +1,103 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  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 org.apache.royale.reflection.utils
+{
+       import org.apache.royale.reflection.ExtraData;
+       
+       COMPILE::SWF
+       {
+               import flash.utils.describeType;
+       }
+       
+       COMPILE::JS
+       {
+               import org.apache.royale.reflection.CompilationData;
+               import goog.DEBUG;
+       }
+       
+       
+    /**
+     *  A utility method to retrieve public static constants that is only 
reliable
+        *  in a cross-target way by using a convention check.
+        *  For this to work, javascript output needs 
js-default-initializers=true
+        *  By default this assumes all candidates with names that are upper 
case only with possible underscores
+        *  
+     *  @param classRef the class reference to inspect
+        *  @param conventionCheck optional replacement check for default check 
described above
+        *              should be a function that inspects a string and returns 
true or false depending on whether it matches the convention or not.
+     *  
+        *  @langversion 3.0
+     *  @playerversion Flash 10.2
+     *  @playerversion AIR 2.6
+     *  @productversion Royale 0.0
+        *
+     */
+    public function getStaticConstantsByConvention(classRef:Class, 
conventionCheck:Function = null):Array
+       {
+        var ret:Array = [];
+               if (!conventionCheck) conventionCheck = 
defaultConstantConventionCheck;
+               var item:String;
+               
+               COMPILE::SWF {
+                       var xml:XML = flash.utils.describeType(classRef);
+                       for each(var constant:XML in xml.constant) {
+                               item = [email protected]();
+                               if (conventionCheck(item)) ret.push(item);
+                       }
+               }
+               
+               COMPILE::JS {
+                       
+                       var statics:Array;
+                       if ( classRef.prototype.ROYALE_REFLECTION_INFO) {
+                               if (CompilationData.hasCompilationOption(
+                                               
classRef.prototype.ROYALE_REFLECTION_INFO.compileFlags,
+                                               
CompilationData.WITH_DEFAULT_INITIALIZERS)) {
+                                       statics = 
classRef.prototype.ROYALE_REFLECTION_INFO.statics
+                               } else {
+                                       //debug level warning:
+                                       if (goog.DEBUG) {
+                                               if (!warningMap.get(classRef)) {
+                                                       
warningMap.set(classRef, true);
+                                                       console.warn('[WARNING] 
getStaticConstantsByConvention :: the reflection target 
'+classRef.prototype.ROYALE_CLASS_INFO.names[0].qName+' was not ' + 
CompilationData.describeSingleFlag(CompilationData.WITH_DEFAULT_INITIALIZERS))
+                                               }
+                                       }
+                                       statics = Object.keys(classRef);
+                               }
+                       } else {
+                               statics = ExtraData.hasData(classRef) ? 
ExtraData.getData(classRef)['ROYALE_REFLECTION_INFO']['statics'] : null;
+                       }
+
+                       if (statics) {
+                               statics = statics.slice();
+                               var l:uint = statics.length;
+                               for (var i:uint = 0; i < l; i++) {
+                                       item = statics[i];
+                                       if (conventionCheck(item)) 
ret.push(item);
+                               }
+                       }
+               }
+               return ret;
+    }
+}
+
+
+
+COMPILE::JS
+var warningMap:Map = new Map();

Reply via email to