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.*;


A class that models Java's array types. ArrayTypes are parametrized by a Type and and an integer representing the array's dimension count.. Two ArrayType are 'equal' if they are parametrized equally.
 
 public class ArrayType extends RefLikeType
 {
    
baseType can be any type except for an array type, null and void What is the base type of the array? That is, for an array of type A[][][], how do I find out what the A is? The accepted way of doing this has always been to look at the public field baseType in ArrayType, ever since the very beginning of Soot.
 
     public final Type baseType;
    
    
dimension count for the array typ
 
     public final int numDimensions;
 
    
     private ArrayType(Type baseTypeint numDimensions)
     {
         if( !( baseType instanceof PrimType || baseType instanceof RefType ) )
             throw new RuntimeException"oops" );
         ifnumDimensions < 1 ) throw new RuntimeException"attempt to create array with "+numDimensions+" dimensions" );
         this. = baseType;
         this. = numDimensions;
     }

     
Creates an ArrayType parametrized by a given Type and dimension count.

Parameters:
baseType a Type to parametrize the ArrayType
numDimensions the dimension count to parametrize the ArrayType.
Returns:
an ArrayType parametrized accrodingly.
 
     public static ArrayType v(Type baseTypeint numDimensions)
     {
         ifnumDimensions < 1 ) throw new RuntimeException"attempt to create array with "+numDimensions+" dimensions" );
         ArrayType ret;
         Type elementType;
         ifnumDimensions == 1 ) {
             elementType = baseType;
         } else {
             elementType = ArrayType.vbaseTypenumDimensions-1 );
         }
         ret = elementType.getArrayType();
         ifret == null ) {
             ret = new ArrayType(baseTypenumDimensions);
             elementType.setArrayTyperet );
         }
         return ret;
     }

    
Two ArrayType are 'equal' if they are parametrized identically. (ie have same Type and dimension count.

Parameters:
t object to test for equality
Returns:
true if t is an ArrayType and is parametrized identically to this.
 
     public boolean equals(Object t)
     {
         return t == this;
         /*
         if(t instanceof ArrayType)
        {
            ArrayType arrayType = (ArrayType) t;
            return this.numDimensions == arrayType.numDimensions &&
                this.baseType.equals(arrayType.baseType);
        }
        else
            return false;
            */
    }
    public void toString(UnitPrinter up)
    {
        up.type );
        for(int i = 0; i < i++)
            up.literal("[]");
    }
    public String toString()
    {
        StringBuffer buffer = new StringBuffer();
        buffer.append(.toString());
        for(int i = 0; i < i++)
            buffer.append("[]");
        return buffer.toString();
    }
    public int hashCode()
    {
        return .hashCode() + 0x432E0341 * ;
    }
    public void apply(Switch sw)
    {
        ((TypeSwitchsw).caseArrayType(this);
    }

    
If I have a variable x of declared type t, what is a good declared type for the expression ((Object[]) x)[i]? The getArrayElementType() method in RefLikeType was introduced to answer this question for all classes implementing RefLikeType. If t is an array, then the answer is the same as getElementType(). But t could also be Object, Serializable, or Cloneable, which can all hold any array, so then the answer is Object.
    public Type getArrayElementType() {
	return getElementType();
    }
    
If I get an element of the array, what will be its type? That is, if I have an array a of type A[][][], what is the type of a[] (it's A[][])? The getElementType() method in ArrayType was introduced to answer this question.
    public Type getElementType() {
	if > 1 ) {
	    return ArrayType.v-1 );
else {
	    return ;
	}
    }
    public ArrayType makeArrayType() {
        return ArrayType.v+1 );
    }
New to GrepCode? Check out our FAQ X