Adding ArrayList to Collections framework.
Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/e2eac34d Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/e2eac34d Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/e2eac34d Branch: refs/heads/core_js_to_as Commit: e2eac34d27c83e2d33920ae61479682202af84e3 Parents: 657ce8b Author: Peter Ent <p...@apache.org> Authored: Wed Oct 7 15:46:20 2015 -0400 Committer: Peter Ent <p...@apache.org> Committed: Wed Oct 7 15:46:20 2015 -0400 ---------------------------------------------------------------------- frameworks/build.xml | 4 +- .../Collections/as/src/CollectionsClasses.as | 1 + .../asjs/src/CollectionsASJSClasses.as | 33 ++ .../org/apache/flex/collections/ArrayList.as | 396 +++++++++++++++++++ .../projects/Collections/basic-manifest.xml | 1 + frameworks/projects/Collections/build.xml | 20 +- .../projects/Collections/compile-config.xml | 2 + .../org/apache/flex/collections/ICollection.js | 50 +++ 8 files changed, 504 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/e2eac34d/frameworks/build.xml ---------------------------------------------------------------------- diff --git a/frameworks/build.xml b/frameworks/build.xml index e66b008..ab9196d 100644 --- a/frameworks/build.xml +++ b/frameworks/build.xml @@ -79,10 +79,10 @@ <antcall target="Core"/> <antcall target="Graphics"/> <antcall target="Binding"/> + <antcall target="Collections"/> <antcall target="HTML"/> <antcall target="Flat"/> <antcall target="Charts"/> - <antcall target="Collections"/> <antcall target="CreateJS"/> <antcall target="DragDrop"/> <antcall target="Effects"/> @@ -136,10 +136,10 @@ <ant dir="${basedir}/projects/Core" target="compile"/> <ant dir="${basedir}/projects/Graphics" target="compile"/> <ant dir="${basedir}/projects/Binding" target="compile"/> + <ant dir="${basedir}/projects/Collections" target="compile"/> <ant dir="${basedir}/projects/HTML" target="compile"/> <ant dir="${basedir}/projects/Flat" target="compile"/> <ant dir="${basedir}/projects/Charts" target="compile"/> - <ant dir="${basedir}/projects/Collections" target="compile"/> <ant dir="${basedir}/projects/CreateJS" target="compile"/> <ant dir="${basedir}/projects/DragDrop" target="compile"/> <ant dir="${basedir}/projects/Effects" target="compile"/> http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/e2eac34d/frameworks/projects/Collections/as/src/CollectionsClasses.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Collections/as/src/CollectionsClasses.as b/frameworks/projects/Collections/as/src/CollectionsClasses.as index dcbf02c..f2b02c3 100644 --- a/frameworks/projects/Collections/as/src/CollectionsClasses.as +++ b/frameworks/projects/Collections/as/src/CollectionsClasses.as @@ -27,6 +27,7 @@ package */ internal class CollectionsClasses { + import org.apache.flex.collections.LazyCollection; LazyCollection; } } http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/e2eac34d/frameworks/projects/Collections/asjs/src/CollectionsASJSClasses.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Collections/asjs/src/CollectionsASJSClasses.as b/frameworks/projects/Collections/asjs/src/CollectionsASJSClasses.as new file mode 100644 index 0000000..e631e8a --- /dev/null +++ b/frameworks/projects/Collections/asjs/src/CollectionsASJSClasses.as @@ -0,0 +1,33 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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 +{ + +/** + * @private + * This class is used to link additional classes into rpc.swc + * beyond those that are found by dependecy analysis starting + * from the classes specified in manifest.xml. + */ +internal class CollectionsASJSClasses +{ + import org.apache.flex.collections.ArrayList; ArrayList; +} + +} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/e2eac34d/frameworks/projects/Collections/asjs/src/org/apache/flex/collections/ArrayList.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Collections/asjs/src/org/apache/flex/collections/ArrayList.as b/frameworks/projects/Collections/asjs/src/org/apache/flex/collections/ArrayList.as new file mode 100644 index 0000000..58d44e8 --- /dev/null +++ b/frameworks/projects/Collections/asjs/src/org/apache/flex/collections/ArrayList.as @@ -0,0 +1,396 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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.flex.collections +{ + import org.apache.flex.core.IBead; + import org.apache.flex.core.IStrand; + import org.apache.flex.events.Event; + import org.apache.flex.events.EventDispatcher; + import org.apache.flex.events.IEventDispatcher; + import org.apache.flex.collections.parsers.IInputParser; + import org.apache.flex.collections.converters.IItemConverter; + + //-------------------------------------- + // Events + //-------------------------------------- + + /** + * Dispatched when the collection's underlying source array + * is changed. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + [Event(name="collectionChanged", type="org.apache.flex.events.Event")] + + /** + * Dispatched when the collection has added an item. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + [Event(name="itemAdded", type="org.apache.flex.events.Event")] + + /** + * Dispatched when the collection has removed an item. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + [Event(name="itemRemoved", type="org.apache.flex.events.Event")] + + /** + * Dispatched when the collection has updated an item. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + [Event(name="itemUpdated", type="org.apache.flex.events.Event")] + + /** + * The ArrayList class provides an event-driven wrapper for the + * standard Array. Events are dispatched when items are added, removed, + * or changed. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public class ArrayList extends EventDispatcher implements IBead, ICollection + { + /** + * Constructor. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function ArrayList(initialSource:Array=null) + { + super(); + if (initialSource) _source = initialSource; + else _source = []; + } + + private var _id:String; + + /** + * @copy org.apache.flex.core.UIBase#id + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function get id():String + { + return _id; + } + + /** + * @private + */ + public function set id(value:String):void + { + if (_id != value) + { + _id = value; + dispatchEvent(new Event("idChanged")); + } + } + + private var _strand:IStrand; + + /** + * @copy org.apache.flex.core.UIBase#strand + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function set strand(value:IStrand):void + { + _strand = value; + _source = new Array(); + } + + private var _source:Array; + + /** + * The array of raw data needing conversion. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function get source():Array + { + return _source; + } + + public function set source(value:Array):void + { + if (_source != value) { + if (value == null) _source = []; + else _source = value; + dispatchEvent(new Event("collectionChanged")); + } + } + + /** + * Returns a copy of the source array. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function toArray():Array + { + return _source.concat(); + } + + /** + * Fetches an item from the collection + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function getItemAt(index:int):Object + { + return _source[index]; + } + + /** + * Fetches an item from the collection given an index. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function getItemIndex(item:Object):int + { + for (var index:int=0; index < _source.length; index++) { + if (item == _source[index]) { + return index; + } + } + return -1; + } + + /** + * Adds an item to the end of the array. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function addItem(item:Object):void + { + addItemAt(item, length); + } + + /** + * Inserts an item to a specific location within the array. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function addItemAt(item:Object, index:int):void + { + const spliceUpperBound:int = length; + + if (index < spliceUpperBound && index > 0) + { + source.splice(index, 0, item); + } + else if (index == spliceUpperBound) + { + source.push(item); + } + else if (index == 0) + { + source.unshift(item); + } + else + { + // error + return; + } + + dispatchEvent(new Event("itemAdded")); + } + + /** + * Replaces the item at the given index with a new item and + * returns the old item. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function setItemAt(item:Object, index:int):Object + { + const spliceUpperBound:int = length; + var oldItem:Object; + + if (index >= 0 && index < spliceUpperBound) { + oldItem = source[index]; + source[index] = item; + dispatchEvent(new Event("itemUpdated")); + } + else { + // error + } + + return oldItem; + } + + /** + * Removed an item from the array and returns it. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function removeItem(item:Object):Boolean + { + var index:int = getItemIndex(item); + var result:Boolean = index >= 0; + if (result) { + removeItemAt(index); + } + return result; + } + + /** + * Removes an item from a specific location within the array and + * returns it. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function removeItemAt(index:int):Object + { + const spliceUpperBound:int = length - 1; + var removed:Object; + + if (index > 0 && index < spliceUpperBound) + { + removed = source.splice(index, 1)[0]; + } + else if (index == spliceUpperBound) + { + removed = source.pop(); + } + else if (index == 0) + { + removed = source.shift(); + } + else { + // error + return null; + } + + dispatchEvent(new Event("itemRemoved")); + return removed; + } + + /** + * Removes all of the items from the array. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function removeAll():void + { + if (length > 0) { + source.splice(0, length); + dispatchEvent(new Event("itemRemoved")); + } + } + + /** + * Signals that an item in the array has been updated. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function itemUpdated(item:Object):void + { + var index:int = getItemIndex(item); + if (index >= 0) { + dispatchEvent(new Event("itemUpdated")); + } + } + + /** + * Signals that an item in the array has been updated. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function itemUpdatedAt(index:int):void + { + dispatchEvent(new Event("itemUpdated")); + } + + /** + * The number of items. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function get length():int + { + return _source ? _source.length : 0; + } + + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/e2eac34d/frameworks/projects/Collections/basic-manifest.xml ---------------------------------------------------------------------- diff --git a/frameworks/projects/Collections/basic-manifest.xml b/frameworks/projects/Collections/basic-manifest.xml index 2b2f0e5..5ea77b7 100644 --- a/frameworks/projects/Collections/basic-manifest.xml +++ b/frameworks/projects/Collections/basic-manifest.xml @@ -21,6 +21,7 @@ <componentPackage> + <component id="ArrayList" class="org.apache.flex.collections.ArrayList"/> <component id="LazyCollection" class="org.apache.flex.collections.LazyCollection"/> <component id="JSONInputParser" class="org.apache.flex.collections.parsers.JSONInputParser"/> <component id="JSONItemConverter" class="org.apache.flex.collections.converters.JSONItemConverter"/> http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/e2eac34d/frameworks/projects/Collections/build.xml ---------------------------------------------------------------------- diff --git a/frameworks/projects/Collections/build.xml b/frameworks/projects/Collections/build.xml index a2f2db7..d6c1e77 100644 --- a/frameworks/projects/Collections/build.xml +++ b/frameworks/projects/Collections/build.xml @@ -99,7 +99,22 @@ </target> <target name="compile-asjs" > - <!-- nothing to cross-compile yet --> + <echo message="Cross-compiling Collections/asjs"/> + <echo message="FALCONJX_HOME: ${FALCONJX_HOME}"/> + <java jar="${FALCONJX_HOME}/lib/compc.jar" fork="true" > + <jvmarg value="-Xmx384m" /> + <jvmarg value="-Dsun.io.useCanonCaches=false" /> + <jvmarg value="-Dflexcompiler=${FALCONJX_HOME}/../compiler" /> + <jvmarg value="-Dflexlib=${FLEXJS_HOME}/frameworks" /> + <arg value="+flexlib=${FLEX_HOME}/frameworks" /> + <arg value="-js-output-type=FLEXJS" /> + <arg value="-keep-asdoc" /><!-- allows compiler to see @flexjsignorecoercion annotations --> + <arg value="-output=${basedir}/js/out" /> + <arg value="-load-config=${basedir}/compile-asjs-config.xml" /> + <arg value="+playerglobal.version=${playerglobal.version}" /> + <arg value="+env.PLAYERGLOBAL_HOME=${env.PLAYERGLOBAL_HOME}" /> + <arg value="+env.AIR_HOME=${env.AIR_HOME}" /> + </java> </target> <target name="lint-js" depends="gjslint, jshint, copy-js" /> @@ -108,6 +123,9 @@ <fileset dir="${basedir}/js/src"> <include name="**/**" /> </fileset> + <fileset dir="${basedir}/js/out"> + <include name="**/**" /> + </fileset> </copy> </target> http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/e2eac34d/frameworks/projects/Collections/compile-config.xml ---------------------------------------------------------------------- diff --git a/frameworks/projects/Collections/compile-config.xml b/frameworks/projects/Collections/compile-config.xml index fdb1921..a34040a 100644 --- a/frameworks/projects/Collections/compile-config.xml +++ b/frameworks/projects/Collections/compile-config.xml @@ -54,6 +54,7 @@ <source-path> <path-element>as/src</path-element> + <path-element>asjs/src</path-element> </source-path> <warn-no-constructor>false</warn-no-constructor> @@ -66,6 +67,7 @@ <include-classes> <class>CollectionsClasses</class> + <class>CollectionsASJSClasses</class> </include-classes> <include-namespaces> http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/e2eac34d/frameworks/projects/Collections/js/src/org/apache/flex/collections/ICollection.js ---------------------------------------------------------------------- diff --git a/frameworks/projects/Collections/js/src/org/apache/flex/collections/ICollection.js b/frameworks/projects/Collections/js/src/org/apache/flex/collections/ICollection.js new file mode 100644 index 0000000..749c80b --- /dev/null +++ b/frameworks/projects/Collections/js/src/org/apache/flex/collections/ICollection.js @@ -0,0 +1,50 @@ +/** + * Licensed 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. + */ + +/** + * org.apache.flex.collections.ICollection + * + * @fileoverview + * + * @suppress {checkTypes} + */ + +goog.provide('org.apache.flex.collections.ICollection'); + + + +/** + * @interface + */ +org.apache.flex.collections.ICollection = +function() { +}; + + +/** + * @export + * @param {number} index The item to fetch. + * @return {Object} The object at the index. + */ +org.apache.flex.collections.ICollection.prototype.getItemAt = function(index) {}; + + +/** + * Metadata + * + * @type {Object.<string, Array.<Object>>} + */ +org.apache.flex.collections.ICollection.prototype.FLEXJS_CLASS_INFO = { + names: [{ name: 'ICollection', + qName: 'org.apache.flex.collections.ICollection'}]};