<commit_before>/* Soot - a J*va Optimization Framework
 * Copyright (C) 1997-1999 <NAME>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

/*
 * Modified by the Sable Research Group and others 1997-1999.  
 * See the 'credits' file distributed with Soot for the complete list of
 * contributors.  (Soot is distributed at http://www.sable.mcgill.ca/soot)
 */

package soot;

import java.util.*;
import soot.util.*;

/** An implementation of a Chain which can contain only Units,
 * and handles patching to deal with element insertions and removals.
 * This is done by calling Unit.redirectJumpsToThisTo at strategic
 * times. */
public class PatchingChain extends AbstractCollection implements Chain 
{
    protected Chain innerChain;

    /** Constructs a PatchingChain from the given Chain. */
    public PatchingChain(Chain aChain)
    {
        innerChain = aChain;
    }

    /**
     * Returns the inner chain used by the PatchingChain.  In general,
     * this should not be used.  However, direct access to the inner
     * chain may be necessary if you wish to perform certain
     * operations (such as control-flow manipulations) without
     * interference from the patching algorithms.
     **/
    public Chain getNonPatchingChain()
    {
        return innerChain;
    }
    
    /** Adds the given object to this Chain. */
    public boolean add(Object o)
    {
        return innerChain.add(o);
    }

    /** Replaces <code>out</code> in the Chain by <code>in</code>. */
    public void swapWith(Object out, Object in)
    {
        insertBefore(in, out);
        remove(out);
    }

    /** Inserts <code>toInsert</code> in the Chain after <code>point</code>. */
    public void insertAfter(Object toInsert, Object point)
    {
        innerChain.insertAfter(toInsert, point);
    }

    /** Inserts <code>toInsert</code> in the Chain after <code>point</code>. */
    public void insertAfter(List toInsert, Object point)
    {
        innerChain.insertAfter(toInsert, point);
    }
    
    public void insertAfter(Chain toInsert, Object point)
    {
        innerChain.insertAfter(toInsert, point);
    }

    /** Inserts <code>toInsert</code> in the Chain before <code>point</code>. */
    public void insertBefore(List toInsert, Object point)
    {
        LinkedList backwardList = new LinkedList();
        // Insert toInsert backwards into the list
        {
            Iterator it = toInsert.iterator();
            
            while(it.hasNext())
                backwardList.addFirst(it.next());
        }
                
        Object previousPoint = point;
        Iterator it = backwardList.iterator();
        while (it.hasNext())
        {
            Object o = it.next();
            insertBefore(o, previousPoint);
            previousPoint = o;
        }
    }
    
    /** Inserts <code>toInsert</code> in the Chain before <code>point</code>. */
    public void insertBefore(Chain toInsert, Object point)
    {
        LinkedList backwardList = new LinkedList();
        // Insert toInsert backwards into the list
        {
            Iterator it = toInsert.iterator();
            
            while(it.hasNext())
                backwardList.addFirst(it.next());
        }
                
        Object previousPoint = point;
        Iterator it = backwardList.iterator();
        while (it.hasNext())
        {
            Object o = it.next();
            insertBefore(o, previousPoint);
            previousPoint = o;
        }
    }

    /** Inserts <code>toInsert</code> in the Chain before <code>point</code>. */
    public void insertBefore(Object toInsert, Object point)
    {
        ((Unit) point).redirectJumpsToThisTo((Unit) toInsert);
        innerChain.insertBefore(toInsert, point);
    }

    /** Returns true if object <code>a</code> follows object <code>b</code> in the Chain. */
    public boolean follows(Object a, Object b)
    {
        return innerChain.follows(a,b);
    }

    /** Removes the given object from this Chain. */
    public boolean remove(Object obj)
    {
        boolean res = false;

        if(contains(obj))
        {
            Unit successor;
            <commit_msg>Added PatchingChain.insertBeforeNoRedirect for inserting without redirecting jumps<commit_after>/* Soot - a J*va Optimization Framework
 * Copyright (C) 1997-1999 <NAME>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

/*
 * Modified by the Sable Research Group and others 1997-1999.  
 * See the 'credits' file distributed with Soot for the complete list of
 * contributors.  (Soot is distributed at http://www.sable.mcgill.ca/soot)
 */

package soot;

import java.util.*;
import soot.util.*;

/** An implementation of a Chain which can contain only Units,
 * and handles patching to deal with element insertions and removals.
 * This is done by calling Unit.redirectJumpsToThisTo at strategic
 * times. */
public class PatchingChain extends AbstractCollection implements Chain 
{
    protected Chain innerChain;

    /** Constructs a PatchingChain from the given Chain. */
    public PatchingChain(Chain aChain)
    {
        innerChain = aChain;
    }

    /**
     * Returns the inner chain used by the PatchingChain.  In general,
     * this should not be used.  However, direct access to the inner
     * chain may be necessary if you wish to perform certain
     * operations (such as control-flow manipulations) without
     * interference from the patching algorithms.
     **/
    public Chain getNonPatchingChain()
    {
        return innerChain;
    }
    
    /** Adds the given object to this Chain. */
    public boolean add(Object o)
    {
        return innerChain.add(o);
    }

    /** Replaces <code>out</code> in the Chain by <code>in</code>. */
    public void swapWith(Object out, Object in)
    {
        insertBefore(in, out);
        remove(out);
    }

    /** Inserts <code>toInsert</code> in the Chain after <code>point</code>. */
    public void insertAfter(Object toInsert, Object point)
    {
        innerChain.insertAfter(toInsert, point);
    }

    /** Inserts <code>toInsert</code> in the Chain after <code>point</code>. */
    public void insertAfter(List toInsert, Object point)
    {
        innerChain.insertAfter(toInsert, point);
    }
    
    public void insertAfter(Chain toInsert, Object point)
    {
        innerChain.insertAfter(toInsert, point);
    }

    /** Inserts <code>toInsert</code> in the Chain before <code>point</code>. */
    public void insertBefore(List toInsert, Object point)
    {
        LinkedList backwardList = new LinkedList();
        // Insert toInsert backwards into the list
        {
            Iterator it = toInsert.iterator();
            
            while(it.hasNext())
                backwardList.addFirst(it.next());
        }
                
        Object previousPoint = point;
        Iterator it = backwardList.iterator();
        while (it.hasNext())
        {
            Object o = it.next();
            insertBefore(o, previousPoint);
            previousPoint = o;
        }
    }
    
    /** Inserts <code>toInsert</code> in the Chain before <code>point</code>. */
    public void insertBefore(Chain toInsert, Object point)
    {
        LinkedList backwardList = new LinkedList();
        // Insert toInsert backwards into the list
        {
            Iterator it = toInsert.iterator();
            
            while(it.hasNext())
                backwardList.addFirst(it.next());
        }
                
        Object previousPoint = point;
        Iterator it = backwardList.iterator();
        while (it.hasNext())
        {
            Object o = it.next();
            insertBefore(o, previousPoint);
            previousPoint = o;
        }
    }

    /** Inserts <code>toInsert</code> in the Chain before <code>point</code>. */
    public void insertBefore(Object toInsert, Object point)
    {
        ((Unit) point).redirectJumpsToThisTo((Unit) toInsert);
        innerChain.insertBefore(toInsert, point);
    }
    
    /** Inserts <code>toInsert</code> in the Chain before <code>point</code> WITHOUT redirecting jumps. */
    public void insertBeforeNoRedirect(Object toInsert, Object point)
    {
        innerChain.insertBefore(toInsert, point);
    }

    /** Returns true if object <code>a</code> follows object <code>b</code> in the Chain. */
    public boolean follows(Object a, Object b)
    {
        return innerChain.follows(a,b);
    }

    /** Removes the given object from this Chain. */
    public boolean remove(Object obj)
    {
        boolean res = false;

        if(contains(obj))
        {
            Unit successor;
            
{'fraction_non_alphanumeric': 0.0940460755958911, 'fraction_numerical': 0.006382766530368006, 'mean_word_length': 2.3889827644474484, 'pattern_counts': {'":': 0, '<': 65, '<?xml version=': 0, '>': 65, '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': '787331', 'n_tokens_mistral': 2742, 'n_tokens_neox': 2629, 'n_words': 952}