<commit_before>////////////////////////////////////////////////////////////////////////////////
//
//  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.utils
{

import org.apache.flex.core.IBead;
import org.apache.flex.core.IContainer;
import org.apache.flex.core.IDocument;
import org.apache.flex.core.IParent;
import org.apache.flex.core.IStrand;
import org.apache.flex.events.Event;
import org.apache.flex.events.IEventDispatcher;

/**
 *  The MXMLDataInterpreter class is the class that interprets the
 *  encoded information generated by the compiler that describes
 *  the contents of an MXML document.
 *  
 *  @langversion 3.0
 *  @playerversion Flash 10.2
 *  @playerversion AIR 2.6
 *  @productversion FlexJS 0.0
 */
public class MXMLDataInterpreter
{
    /**
     *  Constructor.  All methods are static so should not be instantiated.
     *  
     *  @langversion 3.0
     *  @playerversion Flash 10.2
     *  @playerversion AIR 2.6
     *  @productversion FlexJS 0.0
     */
    public function MXMLDataInterpreter()
    {
        super();
    }
    	
    
    /**
     *  Generates an object based on the encoded data.
     *  
     *  @param document The MXML document.  If the object has an id
     *  it will be assigned in this document in this method.
     *  @param data The encoded data.
     *  @return The object.
     *  
     *  @langversion 3.0
     *  @playerversion Flash 10.2
     *  @playerversion AIR 2.6
     *  @productversion FlexJS 0.0
     */
    public static function generateMXMLObject(document:Object, data:Array):Object
    {
        var i:int = 0;
        var cls:Class = data[i++];
        var comp:Object = new cls();
        
        var m:int;
        var j:int;
        var name:String;
        var simple:*;
        var value:Object;
        var id:String;
        
        m = data[i++]; // num props
        for (j = 0; j < m; j++)
        {
            name = data[i++];
            simple = data[i++];
            value = data[i++];
            if (simple == null)
                value = generateMXMLArray(document, null, value as Array);
            else if (simple == false)
                value = generateMXMLObject(document, value as Array);
            if (name == "id")
            {
                document[value] = comp;
                id = value as String;
            }
            else if (name == "_id")
            {
                document[value] = comp;
                id = value as String;
                continue; // skip assignment to comp
            }
            comp[name] = value;
        }
        if (comp is IDocument)
            comp.setDocument(document, id);
        return comp;
    }
    
    /**
     *  Generates an Array of objects based on the encoded data.
     *  
     *  @param document The MXML document.  If the object has an id
     *  it will be assigned in this document in this method.
     *  @param parent The parent for any display objects encoded in the array.
     *  @param data The encoded data.
     *  @param recursive Whether to interpret a child's array of encoded data.
     *  @return The Array.
     *  
     *  @langversion 3.0
     *  @playerversion Flash 10.2
     *  @playerversion AIR 2.6
     *  @productversion FlexJS 0.0
     */
    public static function generateMXMLArray(document:Object, parent:IParent, data:Array, recursive:Boolean = true):Array
    {
        var comps:Array = [];
        
        var n:int = data.length;
        var i:int = 0;
        while (i < n)
        {
            var cls:Class = data[i++];
            var comp:Object = new cls();
                        
            var m:int;
            var j:int;
            var name:String;
            var simple:*;
            var value:Object;
            var id:String = null;
			var dispatchBeadsAdded:Boolean = false;
            
            m = data[i++]; // num props
            if (m > 0 && data[0] == "model")
            {
                m--;
                name = data[i++];
                simple = data[i++];
                value = data[i++];
                if (simple == null)
                    value = generateMXMLArray(document, parent, value as Array, recursive);
                else if (simple == false)
                    value = generateMXMLObject(document, value as Array);
                comp[name] = value;
                if (value is IBead && comp is IStrand)
                    IStrand(comp).addBead(value as IBead);
            }
            var beadOffset:int = i + (m - 1) * 3;
            //if (beadOffset >= -1)
            //    trace(beadOffset, data[beadOffset]);
            if (m > 0 && data[beadOffset] == "beads")
            {
                m--;
            }
            else
                beadOffset = -1;
            for (j = 0; j < m; j++)
            {
                name = data[i++];
                simple = data[i++];
                value = data[i++];
                if (simple == null)
                    value = generateMXMLArray(document, null, value as Array, recursive);
                else if (simple == false)
                    value = generateMXMLObject(document, value as Array);
                if (name == "id")
                    id = value as String;
                if (name == "document" && !comp.document)
                    comp.document = document;
                else if (name == "_id")
                    id = value as String; // and don't assign to comp
                else
                    comp[name] = value;
            }
            if (beadOffset > -1)
            {
                name = data[i++];<commit_msg>don't require all objects to have id properties<commit_after>////////////////////////////////////////////////////////////////////////////////
//
//  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.utils
{

import org.apache.flex.core.IBead;
import org.apache.flex.core.IContainer;
import org.apache.flex.core.IDocument;
import org.apache.flex.core.IParent;
import org.apache.flex.core.IStrand;
import org.apache.flex.events.Event;
import org.apache.flex.events.IEventDispatcher;

/**
 *  The MXMLDataInterpreter class is the class that interprets the
 *  encoded information generated by the compiler that describes
 *  the contents of an MXML document.
 *  
 *  @langversion 3.0
 *  @playerversion Flash 10.2
 *  @playerversion AIR 2.6
 *  @productversion FlexJS 0.0
 */
public class MXMLDataInterpreter
{
    /**
     *  Constructor.  All methods are static so should not be instantiated.
     *  
     *  @langversion 3.0
     *  @playerversion Flash 10.2
     *  @playerversion AIR 2.6
     *  @productversion FlexJS 0.0
     */
    public function MXMLDataInterpreter()
    {
        super();
    }
    	
    
    /**
     *  Generates an object based on the encoded data.
     *  
     *  @param document The MXML document.  If the object has an id
     *  it will be assigned in this document in this method.
     *  @param data The encoded data.
     *  @return The object.
     *  
     *  @langversion 3.0
     *  @playerversion Flash 10.2
     *  @playerversion AIR 2.6
     *  @productversion FlexJS 0.0
     */
    public static function generateMXMLObject(document:Object, data:Array):Object
    {
        var i:int = 0;
        var cls:Class = data[i++];
        var comp:Object = new cls();
        
        var m:int;
        var j:int;
        var name:String;
        var simple:*;
        var value:Object;
        var id:String;
        
        m = data[i++]; // num props
        for (j = 0; j < m; j++)
        {
            name = data[i++];
            simple = data[i++];
            value = data[i++];
            if (simple == null)
                value = generateMXMLArray(document, null, value as Array);
            else if (simple == false)
                value = generateMXMLObject(document, value as Array);
            if (name == "id")
            {
                document[value] = comp;
                id = value as String;
            }
            else if (name == "_id")
            {
                document[value] = comp;
                id = value as String;
                continue; // skip assignment to comp
            }
            comp[name] = value;
        }
        if (comp is IDocument)
            comp.setDocument(document, id);
        return comp;
    }
    
    /**
     *  Generates an Array of objects based on the encoded data.
     *  
     *  @param document The MXML document.  If the object has an id
     *  it will be assigned in this document in this method.
     *  @param parent The parent for any display objects encoded in the array.
     *  @param data The encoded data.
     *  @param recursive Whether to interpret a child's array of encoded data.
     *  @return The Array.
     *  
     *  @langversion 3.0
     *  @playerversion Flash 10.2
     *  @playerversion AIR 2.6
     *  @productversion FlexJS 0.0
     */
    public static function generateMXMLArray(document:Object, parent:IParent, data:Array, recursive:Boolean = true):Array
    {
        var comps:Array = [];
        
        var n:int = data.length;
        var i:int = 0;
        while (i < n)
        {
            var cls:Class = data[i++];
            var comp:Object = new cls();
                        
            var m:int;
            var j:int;
            var name:String;
            var simple:*;
            var value:Object;
            var id:String = null;
			var dispatchBeadsAdded:Boolean = false;
            
            m = data[i++]; // num props
            if (m > 0 && data[0] == "model")
            {
                m--;
                name = data[i++];
                simple = data[i++];
                value = data[i++];
                if (simple == null)
                    value = generateMXMLArray(document, parent, value as Array, recursive);
                else if (simple == false)
                    value = generateMXMLObject(document, value as Array);
                comp[name] = value;
                if (value is IBead && comp is IStrand)
                    IStrand(comp).addBead(value as IBead);
            }
            var beadOffset:int = i + (m - 1) * 3;
            //if (beadOffset >= -1)
            //    trace(beadOffset, data[beadOffset]);
            if (m > 0 && data[beadOffset] == "beads")
            {
                m--;
            }
            else
                beadOffset = -1;
            for (j = 0; j < m; j++)
            {
                name = data[i++];
                simple = data[i++];
                value = data[i++];
                if (simple == null)
                    value = generateMXMLArray(document, null, value as Array, recursive);
                else if (simple == false)
                    value = generateMXMLObject(document, value as Array);
                if (name == "id")
                    id = value as String;
                if (name == "document" && !comp.document)
                    comp.document = document;
                else if (name == "_id")
                    id = value as String; // and don't assign to comp
                else if (name == "id")
                {
                    // not all objects have to have their own id property
                    try {
                        comp["id"] = value;
                    } catch (e:Error)
                    {
                        
                    }
                }
                else
                    comp[name] = value;
            }
            if (beadOffset > -1)
            {
                name = data[i++];
{'fraction_non_alphanumeric': 0.12012012012012012, 'fraction_numerical': 0.007807807807807808, 'mean_word_length': 1.418043202033037, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5714333', 'n_tokens_mistral': 3673, 'n_tokens_neox': 3507, 'n_words': 1187}