KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > soot > jimple > spark > fieldrw > FieldRWTag


1 /* Soot - a J*va Optimization Framework
2  * Copyright (C) 2003 Ondrej Lhotak
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */

19
20 package soot.jimple.spark.fieldrw;
21 import soot.tagkit.*;
22 import java.util.*;
23 import soot.*;
24
25 /** Implements a tag that holds a list of fields read or written by a call. */
26 public abstract class FieldRWTag implements Tag {
27     String JavaDoc fieldNames = new String JavaDoc();
28     FieldRWTag( Set fields ) {
29         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
30         boolean first = true;
31         for( Iterator fieldIt = fields.iterator(); fieldIt.hasNext(); ) {
32             final SootField field = (SootField) fieldIt.next();
33             if( !first ) sb.append( "%" );
34             first = false;
35             sb.append( field.getDeclaringClass().getName() );
36             sb.append( ":" );
37             sb.append( field.getName() );
38         }
39         fieldNames = sb.toString();
40     }
41     public abstract String JavaDoc getName();
42     public byte[] getValue() {
43         byte[] bytes = fieldNames.getBytes();
44         byte[] ret = new byte[bytes.length+2];
45         ret[0] = (byte)( bytes.length/256 );
46         ret[1] = (byte)( bytes.length%256 );
47         System.arraycopy( bytes, 0, ret, 2, bytes.length );
48         return ret;
49     }
50     public String JavaDoc toString() {
51         return getName()+fieldNames;
52     }
53 }
54
55
Popular Tags