KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > soot > tagkit > AnnotationTag


1 /* Soot - a J*va Optimization Framework
2  * Copyright (C) 2005 Jennifer 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 /*
21  * Modified by the Sable Research Group and others 1997-1999.
22  * See the 'credits' file distributed with Soot for the complete list of
23  * contributors. (Soot is distributed at http://www.sable.mcgill.ca/soot)
24  */

25
26 package soot.tagkit;
27 import soot.*;
28 import java.util.*;
29
30
31 /** Represents the annotation attribute attatched to a class, method, field,
32  * method param - they could have many annotations each
33  * for Java 1.5.
34  */

35
36 public class AnnotationTag implements Tag
37 {
38     
39     // type - the question here is the class of the type is potentially
40
// not loaded -- Does it need to be ??? - If it does then this may
41
// be something difficult (if just passing the attributes through
42
// then it maybe doesn't need to - but if they are runtime visible
43
// attributes then won't the annotation class need to be created
44
// in the set of output classes for use by tools when using
45
// reflection ???
46

47     // number of elem value pairs
48
// a bunch of element value pairs
49
// a type B C D F I J S Z s e c @ [
50
// for B C D F I J S Z s elem is a constant value (entry to cp)
51
// in Soot rep as
52
// for e elem is a type and the simple name of the enum class
53
// rep in Soot as a type and SootClass or as two strings
54
// for c elem is a descriptor of the class represented
55
// rep in Soot as a SootClass ?? or a string ??
56
// for @ (nested annotation)
57
// for [ elem is num values and array of values
58
// should probably make a bunch of subclasses for all the
59
// different kinds - with second level for the constant kinds
60

61     private String JavaDoc type;
62     private int visibility = 0;
63     private int numElems = 0;
64     private ArrayList elems;
65     
66     /*public AnnotationTag(int vis, int numElems){
67         this.visibility = vis;
68         this.numElems = numElems;
69     }*/

70     
71     public AnnotationTag(String JavaDoc type, int numElems){
72         this.type = type;
73         this.numElems = numElems;
74     }
75     
76     // should also print here number of annotations and perhaps the annotations themselves
77
public String JavaDoc toString() {
78         StringBuffer JavaDoc sb = new StringBuffer JavaDoc("Annotation: type: "+type+" num elems: "+numElems+" elems: ");
79         if (elems != null){
80             Iterator it = elems.iterator();
81             while (it.hasNext()){
82                 sb.append("\n");
83                 sb.append((AnnotationElem)it.next());
84             }
85         }
86         sb.append("\n");
87         return sb.toString();
88     }
89
90     /** Returns the tag name. */
91     public String JavaDoc getName() {
92         return "AnnotationTag";
93     }
94
95     public String JavaDoc getInfo(){
96         return "Annotation";
97     }
98    
99     public String JavaDoc getType(){
100         return type;
101     }
102     
103     public int getVisibility(){
104         return visibility;
105     }
106
107     public int getNumElems(){
108         return numElems;
109     }
110     
111     /** Returns the tag raw data. */
112     public byte[] getValue() {
113         throw new RuntimeException JavaDoc( "AnnotationTag has no value for bytecode" );
114     }
115
116     public void addElem(AnnotationElem elem){
117         if (elems == null){
118             elems = new ArrayList();
119         }
120         elems.add(elem);
121     }
122     
123     public void setElems(ArrayList list){
124         this.elems = list;
125     }
126
127     public AnnotationElem getElemAt(int i){
128         return (AnnotationElem)elems.get(i);
129     }
130 }
131
132
Popular Tags