001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: *
023: * Free Software Foundation, Inc.
024: * 59 Temple Place, Suite 330
025: * Boston, MA 02111-1307 USA
026: *
027: * @author Scott Ferguson
028: */
029:
030: package com.caucho.bytecode;
031:
032: import java.lang.reflect.Field;
033: import java.lang.reflect.Modifier;
034: import java.lang.reflect.ParameterizedType;
035: import java.lang.reflect.Type;
036:
037: /**
038: * Wrapper around the Java field for a JField.
039: */
040: public class JFieldWrapper extends JField {
041: private JClassLoader _loader;
042:
043: private Field _field;
044:
045: public JFieldWrapper(Field field, JClassLoader loader) {
046: _loader = loader;
047: _field = field;
048: }
049:
050: /**
051: * Returns the field name.
052: */
053: public String getName() {
054: return _field.getName();
055: }
056:
057: /**
058: * Returns the declaring type.
059: */
060: public JClass getDeclaringClass() {
061: return _loader.forName(_field.getDeclaringClass().getName());
062: }
063:
064: /**
065: * Returns the return type.
066: */
067: public JClass getType() {
068: return _loader.forName(_field.getType().getName());
069: }
070:
071: /**
072: * Returns the return type.
073: */
074: public JType getGenericType() {
075: try {
076: Type type = _field.getGenericType();
077:
078: if (type instanceof Class)
079: return getType();
080: else
081: return new JTypeWrapper(_loader,
082: (ParameterizedType) type);
083: } catch (NoSuchMethodError e) {
084: return getType();
085: }
086: }
087:
088: /**
089: * Returns true for a static field.
090: */
091: public boolean isStatic() {
092: return Modifier.isStatic(_field.getModifiers());
093: }
094:
095: /**
096: * Returns true for a private field.
097: */
098: public boolean isPrivate() {
099: return Modifier.isPrivate(_field.getModifiers());
100: }
101:
102: /**
103: * Returns true for a transient field.
104: */
105: public boolean isTransient() {
106: return Modifier.isTransient(_field.getModifiers());
107: }
108: }
|