KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > google > gwt > core > ext > typeinfo > JField


1 /*
2  * Copyright 2006 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy of
6  * the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13  * License for the specific language governing permissions and limitations under
14  * the License.
15  */

16 package com.google.gwt.core.ext.typeinfo;
17
18 /**
19  * Represents a field declaration.
20  */

21 public class JField implements HasMetaData {
22
23   private final JClassType enclosingType;
24
25   private final HasMetaData metaData = new MetaData();
26
27   private int modifierBits;
28
29   private final String JavaDoc name;
30
31   private JType type;
32
33   public JField(JClassType enclosingType, String JavaDoc name) {
34     this.enclosingType = enclosingType;
35     this.name = name;
36
37     assert (enclosingType != null);
38     enclosingType.addField(this);
39   }
40
41   public void addMetaData(String JavaDoc tagName, String JavaDoc[] values) {
42     metaData.addMetaData(tagName, values);
43   }
44
45   public void addModifierBits(int modifierBits) {
46     this.modifierBits |= modifierBits;
47   }
48
49   public JClassType getEnclosingType() {
50     return enclosingType;
51   }
52
53   public String JavaDoc[][] getMetaData(String JavaDoc tagName) {
54     return metaData.getMetaData(tagName);
55   }
56
57   public String JavaDoc[] getMetaDataTags() {
58     return metaData.getMetaDataTags();
59   }
60
61   public String JavaDoc getName() {
62     assert (name != null);
63     return name;
64   }
65
66   public JType getType() {
67     assert (type != null);
68     return type;
69   }
70
71   public boolean isDefaultAccess() {
72     return 0 == (modifierBits & (TypeOracle.MOD_PUBLIC | TypeOracle.MOD_PRIVATE | TypeOracle.MOD_PROTECTED));
73   }
74
75   public boolean isFinal() {
76     return 0 != (modifierBits & TypeOracle.MOD_FINAL);
77   }
78
79   public boolean isPrivate() {
80     return 0 != (modifierBits & TypeOracle.MOD_PRIVATE);
81   }
82
83   public boolean isProtected() {
84     return 0 != (modifierBits & TypeOracle.MOD_PROTECTED);
85   }
86
87   public boolean isPublic() {
88     return 0 != (modifierBits & TypeOracle.MOD_PUBLIC);
89   }
90
91   public boolean isStatic() {
92     return 0 != (modifierBits & TypeOracle.MOD_STATIC);
93   }
94
95   public boolean isTransient() {
96     return 0 != (modifierBits & TypeOracle.MOD_TRANSIENT);
97   }
98
99   public boolean isVolatile() {
100     return 0 != (modifierBits & TypeOracle.MOD_VOLATILE);
101   }
102
103   public void setType(JType type) {
104     this.type = type;
105   }
106
107   public String JavaDoc toString() {
108     String JavaDoc[] names = TypeOracle.modifierBitsToNames(modifierBits);
109     StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
110     for (int i = 0; i < names.length; i++) {
111       if (i > 0) {
112         sb.append(" ");
113       }
114       sb.append(names[i]);
115     }
116     if (names.length > 0) {
117       sb.append(" ");
118     }
119     sb.append(type.getQualifiedSourceName());
120     sb.append(" ");
121     sb.append(getName());
122     return sb.toString();
123   }
124 }
125
Popular Tags