KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > polyglot > ext > jl > types > LocalInstance_c


1 package polyglot.ext.jl.types;
2
3 import polyglot.types.*;
4 import polyglot.util.*;
5
6 /**
7  * A <code>LocalInstance</code> contains type information for a local variable.
8  */

9 public class LocalInstance_c extends VarInstance_c implements LocalInstance
10 {
11     /** Used for deserializing types. */
12     protected LocalInstance_c() { }
13
14     public LocalInstance_c(TypeSystem ts, Position pos,
15                Flags flags, Type type, String JavaDoc name) {
16         super(ts, pos, flags, type, name);
17     }
18
19     public void setConstantValue(Object JavaDoc constantValue) {
20     if (! (constantValue == null) &&
21         ! (constantValue instanceof Boolean JavaDoc) &&
22         ! (constantValue instanceof Number JavaDoc) &&
23         ! (constantValue instanceof Character JavaDoc) &&
24         ! (constantValue instanceof String JavaDoc)) {
25
26         throw new InternalCompilerError(
27         "Can only set constant value to a primitive or String.");
28     }
29
30     this.constantValue = constantValue;
31         this.isConstant = true;
32     }
33
34     public LocalInstance constantValue(Object JavaDoc constantValue) {
35         if (this.constantValue != constantValue) {
36             LocalInstance_c n = (LocalInstance_c) copy();
37             n.setConstantValue(constantValue);
38             return n;
39         }
40         return this;
41     }
42
43     public LocalInstance flags(Flags flags) {
44         if (!flags.equals(this.flags)) {
45             LocalInstance_c n = (LocalInstance_c) copy();
46             n.flags = flags;
47             return n;
48         }
49         return this;
50     }
51
52     public LocalInstance name(String JavaDoc name) {
53         if ((name != null && !name.equals(this.name)) ||
54             (name == null && name != this.name)) {
55             LocalInstance_c n = (LocalInstance_c) copy();
56             n.name = name;
57             return n;
58         }
59         return this;
60     }
61
62     public LocalInstance type(Type type) {
63         if (this.type != type) {
64             LocalInstance_c n = (LocalInstance_c) copy();
65             n.type = type;
66             return n;
67         }
68         return this;
69     }
70  
71     public boolean equalsImpl(TypeObject o) {
72         if (o instanceof LocalInstance) {
73             LocalInstance i = (LocalInstance) o;
74             return super.equalsImpl(i);
75         }
76
77         return false;
78     }
79
80     public String JavaDoc toString() {
81         return "local " + flags.translate() + type + " " + name +
82         (constantValue != null ? (" = " + constantValue) : "");
83     }
84
85     public boolean isCanonical() {
86     return type.isCanonical();
87     }
88 }
89
Popular Tags