KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > bytecode > JFieldWrapper


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  *
23  * Free Software Foundation, Inc.
24  * 59 Temple Place, Suite 330
25  * Boston, MA 02111-1307 USA
26  *
27  * @author Scott Ferguson
28  */

29
30 package com.caucho.bytecode;
31
32 import java.lang.reflect.Field JavaDoc;
33 import java.lang.reflect.Modifier JavaDoc;
34 import java.lang.reflect.ParameterizedType JavaDoc;
35 import java.lang.reflect.Type JavaDoc;
36
37 /**
38  * Wrapper around the Java field for a JField.
39  */

40 public class JFieldWrapper extends JField {
41   private JClassLoader _loader;
42
43   private Field JavaDoc _field;
44
45   public JFieldWrapper(Field JavaDoc field, JClassLoader loader)
46   {
47     _loader = loader;
48     _field = field;
49   }
50
51   /**
52    * Returns the field name.
53    */

54   public String JavaDoc getName()
55   {
56     return _field.getName();
57   }
58
59   /**
60    * Returns the declaring type.
61    */

62   public JClass getDeclaringClass()
63   {
64     return _loader.forName(_field.getDeclaringClass().getName());
65   }
66
67   /**
68    * Returns the return type.
69    */

70   public JClass getType()
71   {
72     return _loader.forName(_field.getType().getName());
73   }
74
75   /**
76    * Returns the return type.
77    */

78   public JType getGenericType()
79   {
80     try {
81       Type JavaDoc type = _field.getGenericType();
82
83       if (type instanceof Class JavaDoc)
84   return getType();
85       else
86   return new JTypeWrapper(_loader, (ParameterizedType JavaDoc) type);
87     } catch (NoSuchMethodError JavaDoc e) {
88       return getType();
89     }
90   }
91
92   /**
93    * Returns true for a static field.
94    */

95   public boolean isStatic()
96   {
97     return Modifier.isStatic(_field.getModifiers());
98   }
99
100   /**
101    * Returns true for a private field.
102    */

103   public boolean isPrivate()
104   {
105     return Modifier.isPrivate(_field.getModifiers());
106   }
107
108   /**
109    * Returns true for a transient field.
110    */

111   public boolean isTransient()
112   {
113     return Modifier.isTransient(_field.getModifiers());
114   }
115 }
116
Popular Tags