OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libjava/] [classpath/] [vm/] [reference/] [java/] [lang/] [reflect/] [VMMethod.java] - Blame information for rev 780

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 780 jeremybenn
/* java.lang.reflect.VMMethod - VM interface for reflection of Java methods
2
   Copyright (C) 1998, 2001, 2002, 2005, 2007, 2008 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
independent module, the terms and conditions of the license of that
32
module.  An independent module is a module which is not derived from
33
or based on this library.  If you modify this library, you may extend
34
this exception to your version of the library, but you are not
35
obligated to do so.  If you do not wish to do so, delete this
36
exception statement from your version. */
37
 
38
 
39
package java.lang.reflect;
40
 
41
import java.lang.annotation.Annotation;
42
 
43
import java.util.Arrays;
44
 
45
final class VMMethod
46
{
47
  Class clazz;
48
  String name;
49
  int slot;
50
 
51
  /**
52
   * This field allows us to refer back to the main constructor instance.
53
   *  It is set by the constructor of Field.
54
   */
55
  Method m;
56
 
57
  public Class getDeclaringClass()
58
  {
59
    return clazz;
60
  }
61
 
62
  public String getName()
63
  {
64
    return name;
65
  }
66
 
67
  /**
68
   * Return the raw modifiers for this method.
69
   * @return the method's modifiers
70
   */
71
  native int getModifiersInternal();
72
 
73
  /**
74
   * Gets the return type of this method.
75
   * @return the type of this method
76
   */
77
  native Class getReturnType();
78
 
79
  /**
80
   * Get the parameter list for this method, in declaration order. If the
81
   * method takes no parameters, returns a 0-length array (not null).
82
   *
83
   * @return a list of the types of the method's parameters
84
   */
85
  native Class[] getParameterTypes();
86
 
87
  /**
88
   * Get the exception types this method says it throws, in no particular
89
   * order. If the method has no throws clause, returns a 0-length array
90
   * (not null).
91
   *
92
   * @return a list of the types in the method's throws clause
93
   */
94
  native Class[] getExceptionTypes();
95
 
96
  native Object invoke(Object o, Object[] args)
97
    throws IllegalAccessException, InvocationTargetException;
98
 
99
  /**
100
   * Return the String in the Signature attribute for this method. If there
101
   * is no Signature attribute, return null.
102
   */
103
  native String getSignature();
104
 
105
  /**
106
   * If this method is an annotation method, returns the default
107
   * value for the method.  If there is no default value, or if the
108
   * method is not a member of an annotation type, returns null.
109
   * Primitive types are wrapped.
110
   *
111
   * @throws TypeNotPresentException if the method returns a Class,
112
   * and the class cannot be found
113
   *
114
   * @since 1.5
115
   */
116
  native Object getDefaultValue();
117
 
118
  /**
119
   * <p>
120
   * Return an array of arrays representing the annotations on each
121
   * of the method's parameters.  The outer array is aligned against
122
   * the parameters of the method and is thus equal in length to
123
   * the number of parameters (thus having a length zero if there are none).
124
   * Each array element in the outer array contains an inner array which
125
   * holds the annotations.  This array has a length of zero if the parameter
126
   * has no annotations.
127
   * </p>
128
   * <p>
129
   * The returned annotations are serialized.  Changing the annotations has
130
   * no affect on the return value of future calls to this method.
131
   * </p>
132
   *
133
   * @return an array of arrays which represents the annotations used on the
134
   *         parameters of this method.  The order of the array elements
135
   *         matches the declaration order of the parameters.
136
   * @since 1.5
137
   */
138
  native Annotation[][] getParameterAnnotations();
139
 
140
  /**
141
   * Compare two objects to see if they are semantically equivalent.
142
   * Two Methods are semantically equivalent if they have the same declaring
143
   * class, name, parameter list, and return type.
144
   *
145
   * @param o the object to compare to
146
   * @return <code>true</code> if they are equal; <code>false</code> if not
147
   */
148
  public boolean equals(Object o)
149
  {
150
      // Implementation note:
151
      // The following is a correct but possibly slow implementation.
152
      //
153
      // This class has a private field 'slot' that could be used by
154
      // the VM implementation to "link" a particular method to a Class.
155
      // In that case equals could be simply implemented as:
156
      //
157
      // if (o instanceof Method)
158
      // {
159
      //    Method m = (Method)o;
160
      //    return m.declaringClass == this.declaringClass
161
      //           && m.slot == this.slot;
162
      // }
163
      // return false;
164
      //
165
      // If a VM uses the Method class as their native/internal representation
166
      // then just using the following would be optimal:
167
      //
168
      // return this == o;
169
      //
170
    if (!(o instanceof Method))
171
      return false;
172
    Method that = (Method)o;
173
    if (clazz != that.getDeclaringClass())
174
      return false;
175
    if (!name.equals(that.getName()))
176
      return false;
177
    if (getReturnType() != that.getReturnType())
178
      return false;
179
    if (!Arrays.equals(getParameterTypes(), that.getParameterTypes()))
180
      return false;
181
    return true;
182
  }
183
 
184
  /**
185
   * Returns the element's annotation for the specified annotation type,
186
   * or <code>null</code> if no such annotation exists.
187
   *
188
   * @param annotationClass the type of annotation to look for.
189
   * @return this element's annotation for the specified type, or
190
   *         <code>null</code> if no such annotation exists.
191
   * @throws NullPointerException if the annotation class is <code>null</code>.
192
   */
193
  native Annotation getAnnotation(Class annotationClass);
194
 
195
  /**
196
   * Returns all annotations directly defined by the element.  If there are
197
   * no annotations directly associated with the element, then a zero-length
198
   * array will be returned.  The returned array may be modified by the client
199
   * code, but this will have no effect on the annotation content of this
200
   * class, and hence no effect on the return value of this method for
201
   * future callers.
202
   *
203
   * @return the annotations directly defined by the element.
204
   * @since 1.5
205
   */
206
  native Annotation[] getDeclaredAnnotations();
207
 
208
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.