2 * Copyright (C) 2014, United States Government, as represented by the
3 * Administrator of the National Aeronautics and Space Administration.
6 * The Java Pathfinder core (jpf-core) platform is licensed under the
7 * Apache License, Version 2.0 (the "License"); you may not use this file except
8 * in compliance with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0.
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 package gov.nasa.jpf.vm;
20 import java.io.IOException;
21 import java.io.InputStream;
22 import java.util.ArrayList;
23 import java.util.HashMap;
26 import gov.nasa.jpf.Config;
27 import gov.nasa.jpf.annotation.MJI;
30 * MJI NativePeer class for java.lang.Class library abstraction
32 public class JPF_java_lang_Class extends NativePeer {
34 static final String FIELD_CLASSNAME = "java.lang.reflect.Field";
35 static final String METHOD_CLASSNAME = "java.lang.reflect.Method";
36 static final String CONSTRUCTOR_CLASSNAME = "java.lang.reflect.Constructor";
37 // TODO: Fix for Groovy's model-checking
38 static final String TYPEVARIABLE_CLASSNAME = "java.lang.reflect.TypeVariable";
40 public static boolean init (Config conf){
41 // we create Method and Constructor objects, so we better make sure these
42 // classes are initialized (they already might be)
43 JPF_java_lang_reflect_Method.init(conf);
44 JPF_java_lang_reflect_Constructor.init(conf);
49 public boolean isArray____Z (MJIEnv env, int robj) {
50 ClassInfo ci = env.getReferredClassInfo( robj);
55 public int getComponentType____Ljava_lang_Class_2 (MJIEnv env, int robj) {
56 if (isArray____Z(env, robj)) {
57 ThreadInfo ti = env.getThreadInfo();
58 Instruction insn = ti.getPC();
59 ClassInfo ci = env.getReferredClassInfo( robj).getComponentClassInfo();
61 if (ci.initializeClass(ti)){
62 env.repeatInvocation();
66 return ci.getClassObjectRef();
73 public boolean isInstance__Ljava_lang_Object_2__Z (MJIEnv env, int robj,
75 ElementInfo sei = env.getStaticElementInfo(robj);
76 ClassInfo ci = sei.getClassInfo();
77 ClassInfo ciOther = env.getClassInfo(r1);
78 return (ciOther.isInstanceOf(ci));
82 public boolean isInterface____Z (MJIEnv env, int robj){
83 ClassInfo ci = env.getReferredClassInfo( robj);
84 return ci.isInterface();
88 public boolean isAssignableFrom__Ljava_lang_Class_2__Z (MJIEnv env, int rcls,
90 ElementInfo sei1 = env.getStaticElementInfo(rcls);
91 ClassInfo ci1 = sei1.getClassInfo();
93 ElementInfo sei2 = env.getStaticElementInfo(r1);
94 ClassInfo ci2 = sei2.getClassInfo();
96 return ci2.isInstanceOf( ci1);
100 public int getAnnotations_____3Ljava_lang_annotation_Annotation_2 (MJIEnv env, int robj){
101 ClassInfo ci = env.getReferredClassInfo( robj);
102 AnnotationInfo[] ai = ci.getAnnotations();
105 return env.newAnnotationProxies(ai);
106 } catch (ClinitRequired x){
107 env.handleClinitRequest(x.getRequiredClassInfo());
113 public int getAnnotation__Ljava_lang_Class_2__Ljava_lang_annotation_Annotation_2 (MJIEnv env, int robj,
115 ClassInfo ci = env.getReferredClassInfo( robj);
116 ClassInfo aci = env.getReferredClassInfo(annoClsRef);
118 AnnotationInfo ai = ci.getAnnotation(aci.getName());
120 ClassInfo aciProxy = aci.getAnnotationProxy();
123 return env.newAnnotationProxy(aciProxy, ai);
124 } catch (ClinitRequired x){
125 env.handleClinitRequest(x.getRequiredClassInfo());
134 public int getPrimitiveClass__Ljava_lang_String_2__Ljava_lang_Class_2 (MJIEnv env,
135 int rcls, int stringRef) {
136 // we don't really have to check for a valid class name here, since
137 // this is a package default method that just gets called from
138 // the clinit of box classes
139 // note this does NOT return the box class (e.g. java.lang.Integer), which
140 // is a normal, functional class, but a primitive class (e.g. 'int') that
141 // is rather a strange beast (not even Object derived)
143 ClassLoaderInfo scli = env.getSystemClassLoaderInfo(); // this is the one responsible for builtin classes
144 String primClsName = env.getStringObject(stringRef); // always initialized
146 ClassInfo ci = scli.getResolvedClassInfo(primClsName);
147 return ci.getClassObjectRef();
151 public boolean desiredAssertionStatus____Z (MJIEnv env, int robj) {
152 ClassInfo ci = env.getReferredClassInfo(robj);
153 return ci.desiredAssertionStatus();
156 public static int getClassObject (MJIEnv env, ClassInfo ci){
157 ThreadInfo ti = env.getThreadInfo();
158 Instruction insn = ti.getPC();
160 if (ci.initializeClass(ti)){
161 env.repeatInvocation();
165 StaticElementInfo ei = ci.getStaticElementInfo();
166 int ref = ei.getClassObjectRef();
172 public int forName__Ljava_lang_String_2__Ljava_lang_Class_2 (MJIEnv env,
175 if (clsNameRef == MJIEnv.NULL){
176 env.throwException("java.lang.NullPointerException", "no class name provided");
180 String clsName = env.getStringObject(clsNameRef);
182 if (clsName.isEmpty()){
183 env.throwException("java.lang.ClassNotFoundException", "empty class name");
187 ThreadInfo ti = env.getThreadInfo();
188 MethodInfo mi = ti.getTopFrame().getPrevious().getMethodInfo();
189 // class of the method that includes the invocation of Class.forName()
190 ClassInfo cls = mi.getClassInfo();
193 // for array type, the component terminal must be resolved
194 if(clsName.charAt(0)=='[') {
195 name = Types.getComponentTerminal(clsName);
200 // make the classloader of the class including the invocation of
201 // Class.forName() resolve the class with the given name
203 cls.resolveReferencedClass(name);
204 } catch(LoadOnJPFRequired lre) {
205 env.repeatInvocation();
209 // The class obtained here is the same as the resolved one, except
210 // if it represents an array type
211 ClassInfo ci = cls.getClassLoaderInfo().getResolvedClassInfo(clsName);
213 return getClassObject(env, ci);
217 * this is an example of a native method issuing direct calls - otherwise known
219 * We don't have to deal with class init here anymore, since this is called
220 * via the class object of the class to instantiate
223 public int newInstance____Ljava_lang_Object_2 (MJIEnv env, int robj) {
224 ThreadInfo ti = env.getThreadInfo();
225 DirectCallStackFrame frame = ti.getReturnedDirectCall();
227 ClassInfo ci = env.getReferredClassInfo(robj); // what are we
228 MethodInfo miCtor = ci.getMethod("<init>()V", true); // note there always is one since something needs to call Object()
230 if (frame == null){ // first time around
231 if(ci.isAbstract()){ // not allowed to instantiate
232 env.throwException("java.lang.InstantiationException");
236 // <2do> - still need to handle protected
237 if (miCtor.isPrivate()) {
238 env.throwException("java.lang.IllegalAccessException", "cannot access non-public member of class " + ci.getName());
242 int objRef = env.newObjectOfUncheckedClass(ci); // create the thing
244 frame = miCtor.createDirectCallStackFrame(ti, 1);
245 // note that we don't set this as a reflection call since it is supposed to propagate exceptions
246 frame.setReferenceArgument(0, objRef, null);
247 frame.setLocalReferenceVariable(0, objRef); // (1) store ref for retrieval during re-exec
250 // check if we have to push clinits
251 ci.initializeClass(ti);
253 env.repeatInvocation();
256 } else { // re-execution
257 int objRef = frame.getLocalVariable(0); // that's the object ref we set in (1)
263 public int getSuperclass____Ljava_lang_Class_2 (MJIEnv env, int robj) {
264 ClassInfo ci = env.getReferredClassInfo( robj);
265 ClassInfo sci = ci.getSuperClass();
267 return sci.getClassObjectRef();
273 int getMethod (MJIEnv env, int clsRef, ClassInfo ciMethod, String mname, int argTypesRef,
274 boolean isRecursiveLookup, boolean publicOnly) {
276 ClassInfo ci = env.getReferredClassInfo( clsRef);
278 StringBuilder sb = new StringBuilder(mname);
280 int nParams = argTypesRef != MJIEnv.NULL ? env.getArrayLength(argTypesRef) : 0;
281 for (int i=0; i<nParams; i++) {
282 int cRef = env.getReferenceArrayElement(argTypesRef, i);
283 ClassInfo cit = env.getReferredClassInfo( cRef);
284 String tname = cit.getName();
285 String tcode = tname;
286 tcode = Types.getTypeSignature(tcode, false);
290 String fullMthName = sb.toString();
292 MethodInfo mi = ci.getReflectionMethod(fullMthName, isRecursiveLookup);
293 if (mi == null || (publicOnly && !mi.isPublic())) {
294 env.throwException("java.lang.NoSuchMethodException", ci.getName() + '.' + fullMthName);
298 return createMethodObject(env, ciMethod, mi);
302 int createMethodObject (MJIEnv env, ClassInfo objectCi, MethodInfo mi) {
303 // NOTE - we rely on Constructor and Method peers being initialized
305 return JPF_java_lang_reflect_Constructor.createConstructorObject(env, objectCi, mi);
307 return JPF_java_lang_reflect_Method.createMethodObject(env, objectCi, mi);
312 public int getDeclaredMethod__Ljava_lang_String_2_3Ljava_lang_Class_2__Ljava_lang_reflect_Method_2 (MJIEnv env, int clsRef,
313 int nameRef, int argTypesRef) {
314 ClassInfo mci = getInitializedClassInfo(env, METHOD_CLASSNAME);
316 env.repeatInvocation();
320 String mname = env.getStringObject(nameRef);
321 return getMethod(env, clsRef, mci, mname, argTypesRef, false, false);
325 public int getDeclaredConstructor___3Ljava_lang_Class_2__Ljava_lang_reflect_Constructor_2 (MJIEnv env,
328 ClassInfo mci = getInitializedClassInfo(env, CONSTRUCTOR_CLASSNAME);
330 env.repeatInvocation();
334 int ctorRef = getMethod(env,clsRef, mci, "<init>",argTypesRef,false, false);
339 public int getMethod__Ljava_lang_String_2_3Ljava_lang_Class_2__Ljava_lang_reflect_Method_2 (MJIEnv env, int clsRef,
340 int nameRef, int argTypesRef) {
341 ClassInfo mci = getInitializedClassInfo(env, METHOD_CLASSNAME);
343 env.repeatInvocation();
347 String mname = env.getStringObject(nameRef);
348 return getMethod( env, clsRef, mci, mname, argTypesRef, true, true);
351 private void addDeclaredMethodsRec (boolean includeSuperClasses, HashMap<String,MethodInfo>methods, ClassInfo ci){
353 if (includeSuperClasses){ // do NOT include Object methods for interfaces
354 ClassInfo sci = ci.getSuperClass();
356 addDeclaredMethodsRec( includeSuperClasses, methods,sci);
360 ClassLoaderInfo cl = ci.getClassLoaderInfo();
361 for (String ifcName : ci.getDirectInterfaceNames()){
362 ClassInfo ici = cl.getResolvedClassInfo(ifcName); // has to be already defined, so no exception
363 addDeclaredMethodsRec( includeSuperClasses, methods,ici);
366 for (MethodInfo mi : ci.getDeclaredMethodInfos()) {
367 // filter out non-public, <clinit> and <init>
368 if (mi.isPublic() && (mi.getName().charAt(0) != '<')) {
369 String mname = mi.getUniqueName();
371 if (!(ci.isInterface() && methods.containsKey(mname))){
372 methods.put(mname, mi);
379 public int getMethods_____3Ljava_lang_reflect_Method_2 (MJIEnv env, int objref) {
380 ClassInfo mci = getInitializedClassInfo(env, METHOD_CLASSNAME);
382 env.repeatInvocation();
386 ClassInfo ci = env.getReferredClassInfo(objref);
388 // collect all the public, non-ctor instance methods
389 if (!ci.isPrimitive()) {
390 HashMap<String,MethodInfo> methods = new HashMap<String,MethodInfo>();
391 addDeclaredMethodsRec( !ci.isInterface(), methods,ci);
393 int n = methods.size();
394 int aref = env.newObjectArray("Ljava/lang/reflect/Method;", n);
397 for (MethodInfo mi : methods.values()){
398 int mref = createMethodObject(env, mci, mi);
399 env.setReferenceArrayElement(aref,i++,mref);
405 return env.newObjectArray("Ljava/lang/reflect/Method;", 0);
410 public int getDeclaredMethods_____3Ljava_lang_reflect_Method_2 (MJIEnv env, int objref) {
411 ClassInfo mci = getInitializedClassInfo(env, METHOD_CLASSNAME);
413 env.repeatInvocation();
417 ClassInfo ci = env.getReferredClassInfo(objref);
418 MethodInfo[] methodInfos = ci.getDeclaredMethodInfos();
420 // we have to filter out the ctors and the static init
421 int nMth = methodInfos.length;
422 for (int i=0; i<methodInfos.length; i++){
423 if (methodInfos[i].getName().charAt(0) == '<'){
424 methodInfos[i] = null;
429 int aref = env.newObjectArray("Ljava/lang/reflect/Method;", nMth);
431 for (int i=0, j=0; i<methodInfos.length; i++) {
432 if (methodInfos[i] != null){
433 int mref = createMethodObject(env, mci, methodInfos[i]);
434 env.setReferenceArrayElement(aref,j++,mref);
441 int getConstructors (MJIEnv env, int objref, boolean publicOnly){
442 ClassInfo mci = getInitializedClassInfo(env, CONSTRUCTOR_CLASSNAME);
444 env.repeatInvocation();
448 ClassInfo ci = env.getReferredClassInfo(objref);
449 ArrayList<MethodInfo> ctors = new ArrayList<MethodInfo>();
451 // we have to filter out the ctors and the static init
452 for (MethodInfo mi : ci.getDeclaredMethodInfos()){
453 if (mi.getName().equals("<init>")){
454 if (!publicOnly || mi.isPublic()) {
460 int nCtors = ctors.size();
461 int aref = env.newObjectArray("Ljava/lang/reflect/Constructor;", nCtors);
463 for (int i=0; i<nCtors; i++){
464 env.setReferenceArrayElement(aref, i, createMethodObject(env, mci, ctors.get(i)));
471 public int getConstructors_____3Ljava_lang_reflect_Constructor_2 (MJIEnv env, int objref){
472 return getConstructors(env, objref, true);
476 public int getDeclaredConstructors_____3Ljava_lang_reflect_Constructor_2 (MJIEnv env, int objref){
477 return getConstructors(env, objref, false);
481 public int getConstructor___3Ljava_lang_Class_2__Ljava_lang_reflect_Constructor_2 (MJIEnv env, int clsRef,
483 ClassInfo mci = getInitializedClassInfo(env, CONSTRUCTOR_CLASSNAME);
485 env.repeatInvocation();
489 // <2do> should only return a public ctor
490 return getMethod(env,clsRef, mci, "<init>",argTypesRef,false,true);
493 // this is only used for system classes such as java.lang.reflect.Method
494 ClassInfo getInitializedClassInfo (MJIEnv env, String clsName){
495 ThreadInfo ti = env.getThreadInfo();
496 Instruction insn = ti.getPC();
497 ClassInfo ci = ClassLoaderInfo.getSystemResolvedClassInfo( clsName);
499 if (ci.initializeClass(ti)){
507 public void initialize0____V (MJIEnv env, int clsObjRef){
508 ClassInfo ci = env.getReferredClassInfo( clsObjRef);
509 ci.initializeClass(ThreadInfo.currentThread);
512 Set<ClassInfo> getInitializedInterfaces (MJIEnv env, ClassInfo ci){
513 ThreadInfo ti = env.getThreadInfo();
514 Instruction insn = ti.getPC();
516 Set<ClassInfo> ifcs = ci.getAllInterfaceClassInfos();
517 for (ClassInfo ciIfc : ifcs){
518 if (ciIfc.initializeClass(ti)){
526 static int createFieldObject (MJIEnv env, FieldInfo fi, ClassInfo fci){
527 int regIdx = JPF_java_lang_reflect_Field.registerFieldInfo(fi);
529 int eidx = env.newObject(fci);
530 ElementInfo ei = env.getModifiableElementInfo(eidx);
531 ei.setIntField("regIdx", regIdx);
537 public int getDeclaredFields_____3Ljava_lang_reflect_Field_2 (MJIEnv env, int objRef) {
538 ClassInfo fci = getInitializedClassInfo(env, FIELD_CLASSNAME);
540 env.repeatInvocation();
544 ClassInfo ci = env.getReferredClassInfo(objRef);
545 int nInstance = ci.getNumberOfDeclaredInstanceFields();
546 int nStatic = ci.getNumberOfStaticFields();
547 int aref = env.newObjectArray("Ljava/lang/reflect/Field;", nInstance + nStatic);
550 for (i=0; i<nStatic; i++) {
551 FieldInfo fi = ci.getStaticField(i);
552 env.setReferenceArrayElement(aref, j++, createFieldObject(env, fi, fci));
555 for (i=0; i<nInstance; i++) {
556 FieldInfo fi = ci.getDeclaredInstanceField(i);
557 env.setReferenceArrayElement(aref, j++, createFieldObject(env, fi, fci));
564 public int getFields_____3Ljava_lang_reflect_Field_2 (MJIEnv env, int clsRef){
565 ClassInfo fci = getInitializedClassInfo(env, FIELD_CLASSNAME);
567 env.repeatInvocation();
571 ClassInfo ci = env.getReferredClassInfo(clsRef);
572 // interfaces might not be initialized yet, so we have to check first
573 Set<ClassInfo> ifcs = getInitializedInterfaces( env, ci);
575 env.repeatInvocation();
579 ArrayList<FieldInfo> fiList = new ArrayList<FieldInfo>();
580 for (; ci != null; ci = ci.getSuperClass()){
581 // the host VM returns them in order of declaration, but the spec says there is no guaranteed order so we keep it simple
582 for (FieldInfo fi : ci.getDeclaredInstanceFields()){
587 for (FieldInfo fi : ci.getDeclaredStaticFields()){
594 for (ClassInfo ciIfc : ifcs){
595 for (FieldInfo fi : ciIfc.getDeclaredStaticFields()){
596 fiList.add(fi); // there are no non-public fields in interfaces
600 int aref = env.newObjectArray("Ljava/lang/reflect/Field;", fiList.size());
602 for (FieldInfo fi : fiList){
603 env.setReferenceArrayElement(aref, j++, createFieldObject(env, fi, fci));
609 int getField (MJIEnv env, int clsRef, int nameRef, boolean isRecursiveLookup) {
610 ClassInfo ci = env.getReferredClassInfo( clsRef);
611 String fname = env.getStringObject(nameRef);
614 if (isRecursiveLookup) {
615 fi = ci.getInstanceField(fname);
617 fi = ci.getStaticField(fname);
620 fi = ci.getDeclaredInstanceField(fname);
622 fi = ci.getDeclaredStaticField(fname);
627 env.throwException("java.lang.NoSuchFieldException", fname);
631 // don't do a Field clinit before we know there is such a field
632 ClassInfo fci = getInitializedClassInfo( env, FIELD_CLASSNAME);
634 env.repeatInvocation();
638 return createFieldObject( env, fi, fci);
643 public int getDeclaredField__Ljava_lang_String_2__Ljava_lang_reflect_Field_2 (MJIEnv env, int clsRef, int nameRef) {
644 return getField(env,clsRef,nameRef, false);
648 public int getField__Ljava_lang_String_2__Ljava_lang_reflect_Field_2 (MJIEnv env, int clsRef, int nameRef) {
649 return getField(env,clsRef,nameRef, true);
653 public int getModifiers____I (MJIEnv env, int clsRef){
654 ClassInfo ci = env.getReferredClassInfo(clsRef);
655 return ci.getModifiers();
659 public int getEnumConstants_____3Ljava_lang_Object_2 (MJIEnv env, int clsRef){
660 ClassInfo ci = env.getReferredClassInfo(clsRef);
662 if (env.requiresClinitExecution(ci)){
663 env.repeatInvocation();
667 if (ci.getSuperClass().getName().equals("java.lang.Enum")) {
668 ArrayList<FieldInfo> list = new ArrayList<FieldInfo>();
669 String cName = ci.getName();
671 for (FieldInfo fi : ci.getDeclaredStaticFields()) {
672 if (fi.isFinal() && cName.equals(fi.getType())){
677 int aRef = env.newObjectArray(cName, list.size());
678 StaticElementInfo sei = ci.getStaticElementInfo();
680 for (FieldInfo fi : list){
681 env.setReferenceArrayElement( aRef, i++, sei.getReferenceField(fi));
690 public int getInterfaces_____3Ljava_lang_Class_2 (MJIEnv env, int clsRef){
691 ClassInfo ci = env.getReferredClassInfo(clsRef);
692 int aref = MJIEnv.NULL;
693 ThreadInfo ti = env.getThreadInfo();
695 // contrary to the API doc, this only returns the interfaces directly
696 // implemented by this class, not it's bases
697 // <2do> this is not exactly correct, since the interfaces should be ordered
698 Set<ClassInfo> interfaces = ci.getInterfaceClassInfos();
699 aref = env.newObjectArray("Ljava/lang/Class;", interfaces.size());
702 for (ClassInfo ifc: interfaces){
703 env.setReferenceArrayElement(aref, i++, ifc.getClassObjectRef());
711 * <2do> needs to load from the classfile location, NOT the MJIEnv (native) class
713 * @author Sebastian Gfeller (sebastian.gfeller@gmail.com)
714 * @author Tihomir Gvero (tihomir.gvero@gmail.com)
717 public int getByteArrayFromResourceStream__Ljava_lang_String_2___3B(MJIEnv env, int clsRef, int nameRef) {
718 String name = env.getStringObject(nameRef);
720 // <2do> this is not loading from the classfile location! fix it
721 InputStream is = env.getClass().getResourceAsStream(name);
725 // We assume that the entire input stream can be read at the moment,
726 // although this could break.
727 byte[] content = null;
729 content = new byte[is.available()];
731 } catch (IOException e) {
732 throw new RuntimeException(e);
734 // Now if everything worked, the content should be in the byte buffer.
735 // We put this buffer into the JPF VM.
736 return env.newByteArray(content);
740 public int getEnclosingClass____Ljava_lang_Class_2 (MJIEnv env, int clsRef) {
741 ClassInfo ciEncl = env.getReferredClassInfo( clsRef).getEnclosingClassInfo();
747 if (ciEncl.initializeClass(env.getThreadInfo())) {
748 env.repeatInvocation();
752 return ciEncl.getClassObjectRef();
756 public int getDeclaredClasses_____3Ljava_lang_Class_2 (MJIEnv env, int clsRef){
757 ClassInfo ci = env.getReferredClassInfo(clsRef);
758 String[] innerClassNames = ci.getInnerClasses();
759 int aref = MJIEnv.NULL;
760 ThreadInfo ti = env.getThreadInfo();
762 MethodInfo mi = ti.getTopFrame().getPrevious().getMethodInfo();
763 // class of the method that includes the invocation of Class.getDeclaredClasses
764 ClassInfo cls = mi.getClassInfo();
766 // first resolve all the inner classes
767 int length = innerClassNames.length;
768 ClassInfo[] resolvedInnerClass = new ClassInfo[length];
769 for(int i=0; i<length; i++) {
771 resolvedInnerClass[i] = cls.resolveReferencedClass(innerClassNames[i]);
772 } catch(LoadOnJPFRequired lre) {
773 env.repeatInvocation();
778 aref = env.newObjectArray("Ljava/lang/Class;", innerClassNames.length);
779 for (int i=0; i<length; i++){
780 ClassInfo ici = resolvedInnerClass[i];
781 if (!ici.isRegistered()) {
782 ici.registerClass(ti);
784 env.setReferenceArrayElement(aref, i, ici.getClassObjectRef());
790 private String getCanonicalName (ClassInfo ci){
792 String canonicalName = getCanonicalName(ci.getComponentClassInfo());
793 if (canonicalName != null){
794 return canonicalName + "[]";
799 if (isLocalOrAnonymousClass(ci)) {
802 if (ci.getEnclosingClassInfo() == null){
805 String enclosingName = getCanonicalName(ci.getEnclosingClassInfo());
806 if (enclosingName == null){ return null; }
807 return enclosingName + "." + ci.getSimpleName();
812 public int getCanonicalName____Ljava_lang_String_2 (MJIEnv env, int clsRef){
813 ClassInfo ci = env.getReferredClassInfo(clsRef);
814 return env.newString(getCanonicalName(ci));
818 public boolean isAnnotation____Z (MJIEnv env, int clsObjRef){
819 ClassInfo ci = env.getReferredClassInfo(clsObjRef);
820 return (ci.getModifiers() & 0x2000) != 0;
824 public boolean isAnnotationPresent__Ljava_lang_Class_2__Z (MJIEnv env, int clsObjRef, int annoClsObjRef){
825 ClassInfo ci = env.getReferredClassInfo(clsObjRef);
826 ClassInfo ciAnno = env.getReferredClassInfo(annoClsObjRef);
828 return ci.getAnnotation( ciAnno.getName()) != null;
832 public int getDeclaredAnnotations_____3Ljava_lang_annotation_Annotation_2 (MJIEnv env, int robj){
833 ClassInfo ci = env.getReferredClassInfo(robj);
836 return env.newAnnotationProxies(ci.getDeclaredAnnotations());
837 } catch (ClinitRequired x){
838 env.handleClinitRequest(x.getRequiredClassInfo());
844 public int getEnclosingConstructor____Ljava_lang_reflect_Constructor_2 (MJIEnv env, int robj){
845 ClassInfo mci = getInitializedClassInfo(env, CONSTRUCTOR_CLASSNAME);
847 env.repeatInvocation();
850 ClassInfo ci = env.getReferredClassInfo(robj);
851 MethodInfo enclosingMethod = ci.getEnclosingMethodInfo();
853 if ((enclosingMethod != null) && enclosingMethod.isCtor()){
854 return createMethodObject(env, mci, enclosingMethod);
860 public int getEnclosingMethod____Ljava_lang_reflect_Method_2 (MJIEnv env, int robj){
861 ClassInfo mci = getInitializedClassInfo(env, METHOD_CLASSNAME);
863 env.repeatInvocation();
866 ClassInfo ci = env.getReferredClassInfo(robj);
867 MethodInfo enclosingMethod = ci.getEnclosingMethodInfo();
869 if ((enclosingMethod != null) && !enclosingMethod.isCtor()){
870 return createMethodObject(env, mci, enclosingMethod);
876 public boolean isAnonymousClass____Z (MJIEnv env, int robj){
877 ClassInfo ci = env.getReferredClassInfo(robj);
879 if (ci.getName().contains("$")){
880 cname = ci.getName().substring(ci.getName().lastIndexOf('$') + 1);
882 return (cname == null) ? false : cname.matches("\\d+?");
886 public boolean isEnum____Z (MJIEnv env, int robj){
887 ClassInfo ci = env.getReferredClassInfo(robj);
891 // Similar to getEnclosingClass() except it returns null for the case of
894 public int getDeclaringClass____Ljava_lang_Class_2 (MJIEnv env, int clsRef){
895 ClassInfo ci = env.getReferredClassInfo(clsRef);
896 if (isLocalOrAnonymousClass(ci)){
899 return getEnclosingClass____Ljava_lang_Class_2(env, clsRef);
904 public boolean isLocalClass____Z (MJIEnv env, int robj){
905 ClassInfo ci = env.getReferredClassInfo(robj);
906 return isLocalOrAnonymousClass(ci) && !isAnonymousClass____Z(env, robj);
909 private boolean isLocalOrAnonymousClass (ClassInfo ci){
910 return (ci.getEnclosingMethodInfo() != null);
914 public boolean isMemberClass____Z (MJIEnv env, int robj){
915 ClassInfo ci = env.getReferredClassInfo(robj);
916 return (ci.getEnclosingClassInfo() != null) && !isLocalOrAnonymousClass(ci);
920 * Append the package name prefix of the class represented by robj, if the name is not
921 * absolute. OW, remove leading "/".
924 public int getResolvedName__Ljava_lang_String_2__Ljava_lang_String_2 (MJIEnv env, int robj, int resRef){
925 String rname = env.getStringObject(resRef);
926 ClassInfo ci = env.getReferredClassInfo(robj);
930 if (!rname.startsWith("/")) {
932 while (c.isArray()) {
933 c = c.getComponentClassInfo();
935 String baseName = c.getName();
936 int index = baseName.lastIndexOf('.');
938 rname = baseName.substring(0, index).replace('.', '/')
942 rname = rname.substring(1);
945 return env.newString(rname);