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 5e4da6c244a1686de701d505134f0fd16a9bb24f Author: greg-dove <[email protected]> AuthorDate: Wed Nov 25 16:14:20 2020 +1300 Adding a new utility method for reflection use. This is useful in many serialization/deserialization implementations. --- .../src/main/royale/ReflectionClasses.as | 1 + .../apache/royale/reflection/utils/MemberTypes.as | 4 ++ .../utils/getInstanceVarsAndAccessors.as | 73 ++++++++++++++++++++++ 3 files changed, 78 insertions(+) diff --git a/frameworks/projects/Reflection/src/main/royale/ReflectionClasses.as b/frameworks/projects/Reflection/src/main/royale/ReflectionClasses.as index 754c3a1..24a9f62 100644 --- a/frameworks/projects/Reflection/src/main/royale/ReflectionClasses.as +++ b/frameworks/projects/Reflection/src/main/royale/ReflectionClasses.as @@ -48,6 +48,7 @@ internal class ReflectionClasses //utils import org.apache.royale.reflection.utils.getMembersWithMetadata; getMembersWithMetadata; import org.apache.royale.reflection.utils.getMembers; getMembers; + import org.apache.royale.reflection.utils.getInstanceVarsAndAccessors; getInstanceVarsAndAccessors; import org.apache.royale.reflection.utils.MemberTypes; MemberTypes; import org.apache.royale.reflection.utils.getStaticConstantsByConvention; getStaticConstantsByConvention; import org.apache.royale.reflection.utils.getMembersWithNameMatch; getMembersWithNameMatch; diff --git a/frameworks/projects/Reflection/src/main/royale/org/apache/royale/reflection/utils/MemberTypes.as b/frameworks/projects/Reflection/src/main/royale/org/apache/royale/reflection/utils/MemberTypes.as index cf2e2b4..545cd97 100644 --- a/frameworks/projects/Reflection/src/main/royale/org/apache/royale/reflection/utils/MemberTypes.as +++ b/frameworks/projects/Reflection/src/main/royale/org/apache/royale/reflection/utils/MemberTypes.as @@ -35,6 +35,10 @@ package org.apache.royale.reflection.utils { public static const ACCESSORS:uint = 2; public static const METHODS:uint = 4; public static const STATIC_ONLY:uint = 8; + + public static const ACCESS_READ_ONLY:uint=1; + public static const ACCESS_WRITE_ONLY:uint=2; + public static const ACCESS_READ_WRITE:uint=4; } diff --git a/frameworks/projects/Reflection/src/main/royale/org/apache/royale/reflection/utils/getInstanceVarsAndAccessors.as b/frameworks/projects/Reflection/src/main/royale/org/apache/royale/reflection/utils/getInstanceVarsAndAccessors.as new file mode 100644 index 0000000..3ebdd39 --- /dev/null +++ b/frameworks/projects/Reflection/src/main/royale/org/apache/royale/reflection/utils/getInstanceVarsAndAccessors.as @@ -0,0 +1,73 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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 exposed variable and accessor members + * It will return variables, and readwrite-only accessors that are public by default, but + * you can specific different options to retrieve other combinations. + * + * @param fromDefinition the definition to retrieve the member definitions from + * @param accessorFilter bitflag combination of MemberTypes.ACCESS_READ_WRITE (the default) or MemberTypes.READ_ONLY or MemberTypes.WRITE_ONLY. Set this to 0 (zero) to exclude all accessors. + * @param publicOnly true if only public namespaced members should be returned (the default) + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion Royale 0.0 + * + * @royaleignorecoercion org.apache.royale.reflection.AccessorDefinition + * @royaleignorecoercion org.apache.royale.reflection.VariableDefinition + */ + public function getInstanceVarsAndAccessors(fromDefinition:TypeDefinition, accessorFilter:uint = 4, publicOnly:Boolean=true):Array + { + var ret:Array = []; + if (!fromDefinition) return ret; + ret = ret.concat(fromDefinition.variables); + var accessors:Array = accessorFilter ? fromDefinition.accessors : []; + if (accessors.length && ((accessorFilter & 7) != 7)) { + var l:uint = accessors.length; + while(l--) { + var access:String = AccessorDefinition(accessors[l]).access; + var includeItem:Boolean = (access == 'readwrite' && (accessorFilter & MemberTypes.ACCESS_READ_WRITE)) || + (access == 'readonly' && (accessorFilter & MemberTypes.ACCESS_READ_ONLY)) || + (access == 'writeonly' && (accessorFilter & MemberTypes.ACCESS_WRITE_ONLY)); + if (includeItem) { + accessors.splice(l,1); + } + } + } + ret = ret.concat(accessors); + + if (publicOnly) { + l = ret.length; + while(l--) { + var varDef:VariableDefinition = VariableDefinition(ret[l]); + if (varDef.uri) ret.splice(l,1); + } + } + + return ret; + } + + +}
