1 /*
   2  * Copyright (c) 1998, 2004, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.jdi;
  27 
  28 /**
  29  * A class or instance variable in the target VM.
  30  * See {@link TypeComponent}
  31  * for general information about Field and Method mirrors.
  32  *
  33  * @see ObjectReference
  34  * @see ReferenceType
  35  *
  36  * @author Robert Field
  37  * @author Gordon Hirsch
  38  * @author James McIlree
  39  * @since  1.3
  40  */
  41 @jdk.Supported
  42 public interface Field extends TypeComponent, Comparable<Field> {
  43 
  44     /**
  45      * Returns a text representation of the type
  46      * of this field.
  47      * Where the type is the type specified in the declaration
  48      * of this field.
  49      * <P>
  50      * This type name is always available even if
  51      * the type has not yet been created or loaded.
  52      *
  53      * @return a String representing the
  54      * type of this field.
  55      */
  56     String typeName();
  57 
  58     /**
  59      * Returns the type of this field.
  60      * Where the type is the type specified in the declaration
  61      * of this field.
  62      * <P>
  63      * For example, if a target class defines:
  64      * <PRE>
  65      *    short s;
  66      *    Date d;
  67      *    byte[] ba;</PRE>
  68      * And the JDI client defines these <CODE>Field</CODE> objects:
  69      * <PRE>
  70      *    Field sField = targetClass.fieldByName("s");
  71      *    Field dField = targetClass.fieldByName("d");
  72      *    Field baField = targetClass.fieldByName("ba");</PRE>
  73      * to mirror the corresponding fields, then <CODE>sField.type()</CODE>
  74      * is a {@link ShortType}, <CODE>dField.type()</CODE> is the
  75      * {@link ReferenceType} for <CODE>java.util.Date</CODE> and
  76      * <CODE>((ArrayType)(baField.type())).componentType()</CODE> is a
  77      * {@link ByteType}.
  78      * <P>
  79      * Note: if the type of this field is a reference type (class,
  80      * interface, or array) and it has not been created or loaded
  81      * by the declaring type's class loader - that is,
  82      * {@link TypeComponent#declaringType <CODE>declaringType()</CODE>}
  83      * <CODE>.classLoader()</CODE>,
  84      * then ClassNotLoadedException will be thrown.
  85      * Also, a reference type may have been loaded but not yet prepared,
  86      * in which case the type will be returned
  87      * but attempts to perform some operations on the returned type
  88      * (e.g. {@link ReferenceType#fields() fields()}) will throw
  89      * a {@link ClassNotPreparedException}.
  90      * Use {@link ReferenceType#isPrepared()} to determine if
  91      * a reference type is prepared.
  92      *
  93      * @see Type
  94      * @return the {@link Type} of this field.
  95      * @throws ClassNotLoadedException if the type has not yet been loaded
  96      * or created through the appropriate class loader.
  97      */
  98     Type type() throws ClassNotLoadedException;
  99 
 100     /**
 101      * Determine if this is a transient field.
 102      *
 103      * @return <code>true</code> if this field is transient; false otherwise.
 104      */
 105     boolean isTransient();
 106 
 107     /**
 108      * Determine if this is a volatile field.
 109      *
 110      * @return <code>true</code> if this field is volatile; false otherwise.
 111      */
 112     boolean isVolatile();
 113 
 114     /**
 115      * Determine if this is a field that represents an enum constant.
 116      * @return <code>true</code> if this field represents an enum constant;
 117      * false otherwise.
 118      */
 119     boolean isEnumConstant();
 120 
 121     /**
 122      * Compares the specified Object with this field for equality.
 123      *
 124      * @return true if the Object is a Field and if both
 125      * mirror the same field (declared in the same class or interface, in
 126      * the same VM).
 127      */
 128     boolean equals(Object obj);
 129 
 130     /**
 131      * Returns the hash code value for this Field.
 132      *
 133      * @return the integer hash code
 134      */
 135     int hashCode();
 136 }