KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > spoon > support > reflect > code > CtLocalVariableImpl


1 package spoon.support.reflect.code;
2
3 import java.util.Set JavaDoc;
4 import java.util.TreeSet JavaDoc;
5
6 import spoon.reflect.code.CtExpression;
7 import spoon.reflect.code.CtLocalVariable;
8 import spoon.reflect.declaration.ModifierKind;
9 import spoon.reflect.reference.CtLocalVariableReference;
10 import spoon.reflect.reference.CtTypeReference;
11 import spoon.reflect.visitor.CtVisitor;
12
13 public class CtLocalVariableImpl<T> extends CtStatementImpl implements
14         CtLocalVariable<T> {
15     private static final long serialVersionUID = 1L;
16
17     CtExpression<T> defaultExpression;
18
19     String JavaDoc docComment;
20
21     Set JavaDoc<ModifierKind> modifiers = new TreeSet JavaDoc<ModifierKind>();
22
23     String JavaDoc name;
24
25     CtTypeReference<T> type;
26
27     public void accept(CtVisitor visitor) {
28         visitor.visitCtLocalVariable(this);
29     }
30
31     public CtExpression<T> getDefaultExpression() {
32         return defaultExpression;
33     }
34
35     public String JavaDoc getDocComment() {
36         return docComment;
37     }
38
39     public Set JavaDoc<ModifierKind> getModifiers() {
40         return modifiers;
41     }
42
43     public CtLocalVariableReference<T> getReference() {
44         return getFactory().Code().createLocalVariableReference(this);
45     }
46
47     public String JavaDoc getSimpleName() {
48         return name;
49     }
50
51     public CtTypeReference<T> getType() {
52         return type;
53     }
54
55     public ModifierKind getVisibility() {
56         if (getModifiers().contains(ModifierKind.PUBLIC))
57             return ModifierKind.PUBLIC;
58         if (getModifiers().contains(ModifierKind.PROTECTED))
59             return ModifierKind.PROTECTED;
60         if (getModifiers().contains(ModifierKind.PRIVATE))
61             return ModifierKind.PRIVATE;
62         return null;
63     }
64
65     public boolean hasModifier(ModifierKind modifier) {
66         return modifiers.contains(modifier);
67     }
68
69     public void setDefaultExpression(CtExpression<T> defaultExpression) {
70         this.defaultExpression = (CtExpression<T>) defaultExpression;
71     }
72
73     public void setDocComment(String JavaDoc docComment) {
74         this.docComment = docComment;
75     }
76
77     public void setModifiers(Set JavaDoc<ModifierKind> modifiers) {
78         this.modifiers = modifiers;
79     }
80
81     public void setSimpleName(String JavaDoc simpleName) {
82         this.name = simpleName;
83     }
84
85     public void setType(CtTypeReference<T> type) {
86         this.type = (CtTypeReference<T>) type;
87     }
88
89     public void setVisibility(ModifierKind visibility) {
90         getModifiers().remove(ModifierKind.PUBLIC);
91         getModifiers().remove(ModifierKind.PROTECTED);
92         getModifiers().remove(ModifierKind.PRIVATE);
93         getModifiers().add(visibility);
94     }
95
96 }
97
Popular Tags