Source for gnu.classpath.jdwp.VMMethod

   1: /* VMMethod.java -- a method in a virtual machine
   2:    Copyright (C) 2006, 2007 Free Software Foundation, Inc.
   3: 
   4: This file is part of GNU Classpath.
   5: 
   6: GNU Classpath is free software; you can redistribute it and/or modify
   7: it under the terms of the GNU General Public License as published by
   8: the Free Software Foundation; either version 2, or (at your option)
   9: any later version.
  10: 
  11: GNU Classpath is distributed in the hope that it will be useful, but
  12: WITHOUT ANY WARRANTY; without even the implied warranty of
  13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14: General Public License for more details.
  15: 
  16: You should have received a copy of the GNU General Public License
  17: along with GNU Classpath; see the file COPYING.  If not, write to the
  18: Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  19: 02110-1301 USA.
  20: 
  21: Linking this library statically or dynamically with other modules is
  22: making a combined work based on this library.  Thus, the terms and
  23: conditions of the GNU General Public License cover the whole
  24: combination.
  25: 
  26: As a special exception, the copyright holders of this library give you
  27: permission to link this library with independent modules to produce an
  28: executable, regardless of the license terms of these independent
  29: modules, and to copy and distribute the resulting executable under
  30: terms of your choice, provided that you also meet, for each linked
  31: terms of your choice, provided that you also meet, for each linked
  32: independent module, the terms and conditions of the license of that
  33: module.  An independent module is a module which is not derived from
  34: or based on this library.  If you modify this library, you may extend
  35: this exception to your version of the library, but you are not
  36: obligated to do so.  If you do not wish to do so, delete this
  37: exception statement from your version. */
  38: 
  39: 
  40: package gnu.classpath.jdwp;
  41: 
  42: import java.io.DataOutputStream;
  43: import java.io.IOException;
  44: import java.nio.ByteBuffer;
  45: 
  46: import gnu.classpath.jdwp.exception.JdwpException;
  47: import gnu.classpath.jdwp.util.LineTable;
  48: import gnu.classpath.jdwp.util.VariableTable;
  49: 
  50: /**
  51:  * This class is really an amalgamation of two classes: one class
  52:  * represents a virtual machine method and the other represents
  53:  * the JDWP back-end's ID for the method.
  54:  *
  55:  * @author Keith Seitz  (keiths@redhat.com)
  56:  */
  57: public class VMMethod
  58: {
  59:   /**
  60:    * Returns the size of a JDWP method ID
  61:    * @see gnu.classpath.jdwp.id.JdwpId#SIZE
  62:    */
  63:    public static final int SIZE = 8;
  64: 
  65:   // The class in which this method is declared
  66:   private Class _class;
  67: 
  68:   // The method's ID
  69:   private long _methodId;
  70: 
  71:   /**
  72:    * Constructs a new VMMethod object. This constructor is protected
  73:    * so that only the factory methods of VMVirtualMachine can be used
  74:    * to create VMMethods.
  75:    *
  76:    * @param klass the method's containing class
  77:    * @param id    method identifier, e.g., jmethodID
  78:    * @see gnu.classpath.jdwp.VMVirtualMachine#getAllClassMethods
  79:    * @see gnu.classpath.jdwp.VMVirtualMachine#getClassMethod
  80:    */
  81:   protected VMMethod(Class klass, long id)
  82:   {
  83:     _class = klass;
  84:     _methodId = id;
  85:   }
  86: 
  87:   /**
  88:    * Returns the internal method ID for this method
  89:    */
  90:   public long getId()
  91:   {
  92:     return _methodId;
  93:   }
  94: 
  95:   /**
  96:    * Returns the method's declaring class
  97:    */
  98:   public Class getDeclaringClass()
  99:   {
 100:     return _class;
 101:   }
 102: 
 103:   /**
 104:    * Returns the name of this method
 105:    */
 106:   public native String getName();
 107: 
 108:   /**
 109:    * Returns the signature of this method
 110:    */
 111:   public native String getSignature();
 112: 
 113:   /**
 114:    * Returns the method's modifier flags
 115:    */
 116:   public native int getModifiers();
 117: 
 118:   /**
 119:    * "Returns line number information for the method, if present. The line
 120:    * table maps source line numbers to the initial code index of the line.
 121:    * The line table is ordered by code index (from lowest to highest). The
 122:    * line number information is constant unless a new class definition is
 123:    * installed using RedefineClasses."
 124:    *
 125:    * @return the line table
 126:    * @throws JdwpException
 127:    */
 128:   public native LineTable getLineTable()
 129:     throws JdwpException;
 130: 
 131:   /**
 132:    * "Returns variable information for the method. The variable table
 133:    * includes arguments and locals declared within the method. For instance
 134:    * methods, the "this" reference is included in the table. Also, synthetic
 135:    * variables may be present."
 136:    *
 137:    * @return the variable table
 138:    * @throws JdwpException
 139:    */
 140:   public native VariableTable getVariableTable()
 141:     throws JdwpException;
 142: 
 143:   /**
 144:    * Returns a string representation of this method (not
 145:    * required but nice for debugging).
 146:    */
 147:   public String toString()
 148:   {
 149:     return getDeclaringClass().getName() + "." + getName();
 150:   }
 151: 
 152:   /**
 153:    * Writes the method's ID to the output stream
 154:    *
 155:    * @param ostream the output stream to which to write
 156:    * @throws IOException for any errors writing to the stream
 157:    * @see gnu.classpath.jdwp.id.JdwpId#write
 158:    */
 159:   public void writeId(DataOutputStream ostream)
 160:     throws IOException
 161:   {
 162:     ostream.writeLong(getId());
 163:   }
 164: 
 165:   /**
 166:    * Returns a VMMethod from the ID in the byte buffer
 167:    *
 168:    * @param klass the method's declaring class
 169:    * @param bb    a ByteBuffer containing the method's ID
 170:    * @throws JdwpException for any errors creating the method
 171:    * @throws IOException for any errors reading from the buffer
 172:    */
 173:   public static VMMethod readId(Class klass, ByteBuffer bb)
 174:     throws JdwpException, IOException
 175:   {
 176:     return VMVirtualMachine.getClassMethod(klass, bb.getLong());
 177:   }
 178: 
 179:   public boolean equals(Object obj)
 180:   {
 181:     if (obj instanceof VMMethod)
 182:       {
 183:     VMMethod m = (VMMethod) obj;
 184:     return (getId() == m.getId());
 185:       }
 186: 
 187:     return false;
 188:   }
 189: }