Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /* Soot - a J*va Optimization Framework
   * Copyright (C) 1997-1999 Raja Vallee-Rai
   *
   * 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 soot.util.*;
 import java.util.*;

A class that models Java's reference types. RefTypes are parametrized by a class name. Two RefType are equal iff they are parametrized by the same class name as a String.
 
 
 public class RefType extends RefLikeType implements Comparable
 {
     public RefTypeSingletons.Global g ) {  = ""; }
     public static RefType v() { return G.v().soot_RefType(); }

    
the class name that parametrizes this RefType
 
     private String className;
     public String getClassName() { return ; }
     private SootClass sootClass;
     private AnySubType anySubType;
 
     private RefType(String className)
     {
         ifclassName.startsWith("[") ) throw new RuntimeException("Attempt to create RefType whose name starts with [ --> " + className);
         ifclassName.indexOf("/") >= 0 ) throw new RuntimeException("Attempt to create RefType containing a / --> " + className);
         ifclassName.indexOf(";") >= 0 ) throw new RuntimeException("Attempt to create RefType containing a ; --> " + className);
         this. = className;
     }

    
Create a RefType for a class.

Parameters:
className The name of the class used to parametrize the created RefType.
Returns:
a RefType for the given class name.
 
     public static RefType v(String className)
     {
         if(Scene.v().containsType(className)) {
         	return Scene.v().getRefTypeclassName );
         } else {
 	        RefType ret = new RefType(className);
 	        Scene.v().addRefTyperet );
 	        return ret;
         }
     }
 
     public int compareTo(Object othrows ClassCastException
     {
         RefType t = (RefType)o;
         return this.toString().compareTo(t.toString());
     }
        
    
Create a RefType for a class.

Parameters:
c A SootClass for which to create a RefType.
Returns:
a RefType for the given SootClass..
 
     public static RefType v(SootClass c)
     {
         return v(c.getName());
     }
    
     
Get the SootClass object corresponding to this RefType.

Returns:
the corresponding SootClass
     
     public SootClass getSootClass()
     {
         if == null ) {
             //System.out.println( "wrning: "+this+" has no sootclass" );
              = SootResolver.v().makeClassRef();
         }
        return ;
    }
    public boolean hasSootClass() {
        return  != null;
    }
    
    public void setClassNameString className )
    {
        this. = className;
    }

     
Set the SootClass object corresponding to this RefType.

Parameters:
sootClass The SootClass corresponding to this RefType.
    
    public void setSootClassSootClass sootClass )
    {
        this. = sootClass;
    }

    
2 RefTypes are considered equal if they are parametrized by the same class name String.

Parameters:
t an object to test for equality.
:
return true if t is a RefType parametrized by the same name as this.
    public boolean equals(Object t)
    {
        return ((t instanceof RefType) && .equals(((RefTypet).));
    }
    public String toString()
    {
        return ;
    }
    public int hashCode()
    {
        return .hashCode();
    }
    public void apply(Switch sw)
    {
        ((TypeSwitchsw).caseRefType(this);
    }


    
Returns the least common superclass of this type and other.
    public Type merge(Type otherScene cm)
    {
        if(other.equals(UnknownType.v()) || this.equals(other))
            return this;
        
        if(! (other instanceof RefType))
            throw new RuntimeException("illegal type merge: "
                                       + this + " and " + other);
        {
            // Return least common superclass
            
            SootClass thisClass = cm.getSootClass((this).);
            SootClass otherClass = cm.getSootClass(((RefTypeother).);
            SootClass javalangObject = cm.getSootClass("java.lang.Object");
            LinkedList<SootClassthisHierarchy = new LinkedList<SootClass>();
            LinkedList<SootClassotherHierarchy = new LinkedList<SootClass>();
            // Build thisHierarchy
            {
                SootClass SootClass = thisClass;
                for(;;)
                {
                    thisHierarchy.addFirst(SootClass);
                    if(SootClass == javalangObject)
                        break;
                    SootClass = SootClass.getSuperclass();
                }
            }
            // Build otherHierarchy
            {
                SootClass SootClass = otherClass;
                for(;;)
                {
                    otherHierarchy.addFirst(SootClass);
                    if(SootClass == javalangObject)
                        break;
                    SootClass = SootClass.getSuperclass();
                }
            }
            // Find least common superclass
            {
                SootClass commonClass = null;
                while(!otherHierarchy.isEmpty() && !thisHierarchy.isEmpty() &&
                    otherHierarchy.getFirst() == thisHierarchy.getFirst())
                {
                    commonClass = otherHierarchy.removeFirst();
                    thisHierarchy.removeFirst();
                }
                return RefType.v(commonClass.getName());
            }
        }
        
    }
    public Type getArrayElementType() {
	if.equals"java.lang.Object" )
	    || .equals"java.io.Serializable" )
	    || .equals"java.lang.Cloneable" ) ) {
	    return RefType.v"java.lang.Object" );
	}
	throw new RuntimeException"Attempt to get array base type of a non-array" );
    }
    public AnySubType getAnySubType() { return ; }
    public void setAnySubTypeAnySubType anySubType ) {
        this. = anySubType;
    }
New to GrepCode? Check out our FAQ X