25using System.Collections.Generic;
39#if FIRST_PASS == false
41 static ClassLoaderAccessor classLoaderAccessor;
43 static ClassLoaderAccessor ClassLoaderAccessor =>
JVM.
Internal.BaseAccessors.Get(
ref classLoaderAccessor);
57 public static global::java.lang.Class
forName0(
string name,
bool initialize, global::java.lang.ClassLoader loader, global::java.lang.Class caller)
60 throw new NotImplementedException();
63 throw new global::java.lang.NullPointerException();
65 RuntimeJavaType javaType =
null;
66 if (name.IndexOf(
',') > 0)
70 var sm = global::java.lang.System.getSecurityManager();
71 sm?.checkPermission(
new global::java.lang.RuntimePermission(
"createClassLoader"));
73 var type =
Type.GetType(name);
79 global::java.lang.Throwable.suppressFillInStackTrace =
true;
80 throw new global::java.lang.ClassNotFoundException(name);
91 global::java.lang.Throwable.suppressFillInStackTrace =
true;
92 throw new global::java.lang.ClassNotFoundException(e.Message);
96 throw e.InnerException;
104 if (loader !=
null && caller !=
null &&
getProtectionDomain0(caller) is global::java.security.ProtectionDomain pd)
105 ClassLoaderAccessor.InvokeCheckPackageAccess(loader, javaType.ClassObject, pd);
107 if (initialize && javaType.IsArray ==
false)
118 javaType.RunClassInit();
121 return javaType.ClassObject;
132 return RuntimeJavaType.FromClass(thisClass).GetRawTypeAnnotations();
137 sealed class ConstantPoolImpl : global::sun.reflect.ConstantPool
140 readonly
object[] constantPool;
146 internal ConstantPoolImpl(
object[] constantPool)
148 this.constantPool = constantPool;
151 public override string getUTF8At(
int index)
153 return (
string)constantPool[index];
156 public override int getIntAt(
int index)
158 return (
int)constantPool[index];
161 public override long getLongAt(
int index)
163 return (
long)constantPool[index];
166 public override float getFloatAt(
int index)
168 return (
float)constantPool[index];
171 public override double getDoubleAt(
int index)
173 return (
double)constantPool[index];
187 throw new NotImplementedException();
189 return new ConstantPoolImpl(RuntimeJavaType.FromClass(
self).GetConstantPool());
199 public static bool isInstance(global::java.lang.Class
self,
object obj)
201 return RuntimeJavaType.FromClass(
self).IsInstance(obj);
211 public static bool isAssignableFrom(global::java.lang.Class
self, global::java.lang.Class otherClass)
214 throw new NotImplementedException();
216 if (otherClass ==
null)
217 throw new global::java.lang.NullPointerException();
219 return RuntimeJavaType.FromClass(otherClass).IsAssignableTo(RuntimeJavaType.FromClass(
self));
230 return RuntimeJavaType.FromClass(
self).IsInterface;
233 public static bool isArray(global::java.lang.Class thisClass)
235 return RuntimeJavaType.FromClass(thisClass).IsArray;
240 return RuntimeJavaType.FromClass(thisClass).IsPrimitive;
243 public static string getName0(global::java.lang.Class thisClass)
246 throw new NotImplementedException();
248 var type = RuntimeJavaType.FromClass(thisClass);
249 if (type.IsPrimitive)
271 if (type.IsUnsafeAnonymous)
275 return type.Name +
"/" + global::java.lang.System.identityHashCode(thisClass);
282 public static string getSigName(global::java.lang.Class thisClass)
284 return RuntimeJavaType.FromClass(thisClass).SigName;
287 public static global::java.lang.ClassLoader
getClassLoader0(global::java.lang.Class thisClass)
289 return RuntimeJavaType.FromClass(thisClass).ClassLoader.GetJavaClassLoader();
292 public static global::java.lang.Class
getSuperclass(global::java.lang.Class thisClass)
294 return RuntimeJavaType.FromClass(thisClass).BaseTypeWrapper?.ClassObject;
297 public static global::java.lang.Class[]
getInterfaces0(global::java.lang.Class thisClass)
300 throw new NotImplementedException();
302 var ifaces = RuntimeJavaType.FromClass(thisClass).Interfaces;
303 var interfaces =
new global::java.lang.Class[ifaces.Length];
304 for (
int i = 0; i < ifaces.Length; i++)
305 interfaces[i] = ifaces[i].ClassObject;
313 var type = RuntimeJavaType.FromClass(thisClass);
314 return type.IsArray ? type.ElementTypeWrapper.ClassObject :
null;
322 return (
int)RuntimeJavaType.FromClass(thisClass).ReflectiveModifiers & mask;
325 public static object[]
getSigners(global::java.lang.Class thisClass)
328 throw new NotImplementedException();
330 return thisClass.signers;
334 public static void setSigners(global::java.lang.Class thisClass,
object[] signers)
337 thisClass.signers = signers;
345 var type = RuntimeJavaType.FromClass(thisClass);
348 var enc = type.GetEnclosingMethod();
352 return [type.ClassLoader.LoadClassByName(enc[0]).ClassObject, enc[1], enc[2]?.Replace(
'.',
'/')];
364 var type = RuntimeJavaType.FromClass(thisClass);
367 var declaringType = type.DeclaringTypeWrapper;
368 if (declaringType ==
null)
371 declaringType = declaringType.EnsureLoadable(type.ClassLoader);
372 if (declaringType.IsAccessibleFrom(type) ==
false)
373 throw new IllegalAccessError(
string.Format(
"tried to access class {0} from class {1}", declaringType.Name, type.Name));
375 declaringType.Finish();
377 foreach (var declaringTypeInnerType
in declaringType.InnerClasses)
378 if (declaringTypeInnerType.Name == type.Name && declaringTypeInnerType.EnsureLoadable(declaringType.ClassLoader) == type)
379 return declaringType.ClassObject;
392 throw new NotImplementedException();
394 var type = RuntimeJavaType.FromClass(thisClass);
398 var pd = type.ClassObject.pd;
403 if (type.ClassLoader is RuntimeAssemblyClassLoader acl)
405 pd = acl.GetProtectionDomain();
411 pd =
JVM.Context.
ClassLoaderFactory.GetJavaTypeFromType(type.TypeAsTBD.DeclaringType).ClassObject.pd;
432 throw new NotImplementedException();
445 _ =>
throw new ArgumentException(name),
452 var type = RuntimeJavaType.FromClass(thisClass);
454 return type.GetGenericSignature();
460 throw new NotImplementedException();
462 var map =
new global::java.util.LinkedHashMap();
465 foreach (
object obj
in objAnn)
467 var a = obj as global::java.lang.annotation.Annotation;
470 map.put(a.annotationType(), FreezeOrWrapAttribute(a));
476 map.put(a.annotationType(), a);
487 internal static global::java.lang.annotation.Annotation FreezeOrWrapAttribute(global::java.lang.annotation.Annotation ann)
489 var attr = ann as global::ikvm.@
internal.AnnotationAttributeBase;
492#if DONT_WRAP_ANNOTATION_ATTRIBUTES
497 ann = global::sun.reflect.annotation.AnnotationParser.annotationForMap(attr.annotationType(), attr.getValues());
507 throw new NotImplementedException();
509 var type = RuntimeJavaType.FromClass(thisClass);
520 return AnnotationsToMap(type.ClassLoader, type.GetDeclaredAnnotations());
527 throw new NotImplementedException();
531 var type = RuntimeJavaType.FromClass(thisClass);
534 var fields = type.GetFields();
535 var list =
new List<global::java.lang.reflect.Field>(fields.Length);
537 for (
int i = 0; i < fields.Length; i++)
539 if (fields[i].IsHideFromReflection)
543 else if (publicOnly && !fields[i].IsPublic)
549 list.Add((global::java.lang.reflect.Field)fields[i].ToField(
false, i));
553 return list.ToArray();
565 throw new NotImplementedException();
569 var type = RuntimeJavaType.FromClass(thisClass);
572 if (type.HasVerifyError)
575 if (type.HasClassFormatError)
578 var methods = type.GetMethods();
579 var list =
new List<global::java.lang.reflect.Method>(methods.Length);
580 foreach (var method
in methods)
583 if (!method.IsHideFromReflection && !method.IsConstructor && !method.IsClassInitializer && (!publicOnly || method.IsPublic))
584 list.Add((global::java.lang.reflect.Method)method.ToMethodOrConstructor(
false));
587 return list.ToArray();
599 throw new NotImplementedException();
603 var type = RuntimeJavaType.FromClass(thisClass);
606 if (type.HasVerifyError)
609 if (type.HasClassFormatError)
612 var methods = type.GetMethods();
613 var list =
new List<global::java.lang.reflect.Constructor>(methods.Length);
614 foreach (var method
in methods)
617 if (method.IsHideFromReflection ==
false && method.IsConstructor)
618 if (publicOnly ==
false || method.IsPublic)
619 list.Add((global::java.lang.reflect.Constructor)method.ToMethodOrConstructor(
false));
622 return list.ToArray();
634 throw new NotImplementedException();
638 var type = RuntimeJavaType.FromClass(thisClass);
641 var innerTypes = type.InnerClasses;
642 var list =
new global::java.lang.Class[innerTypes.Length];
643 for (
int i = 0; i < list.Length; i++)
645 var innerType = innerTypes[i].EnsureLoadable(type.ClassLoader);
646 if (innerType.IsAccessibleFrom(type) ==
false)
647 throw new IllegalAccessError(
string.Format(
"tried to access class {0} from class {1}", innerType.Name, type.Name));
650 list[i] = innerType.ClassObject;
IKVM.Reflection.Type Type
Implements the native methods for 'java.lang.Class'.
static object getDeclaredConstructors0(global::java.lang.Class thisClass, bool publicOnly)
static global::java.lang.Class forName0(string name, bool initialize, global::java.lang.ClassLoader loader, global::java.lang.Class caller)
Implements the native method 'forName0'.
static global::java.lang.Class getPrimitiveClass(string name)
Implements the native method for 'getPrimitiveClass'.
static global::java.lang.Class[] getInterfaces0(global::java.lang.Class thisClass)
static object getDeclaredFields0(global::java.lang.Class thisClass, bool publicOnly)
static object getDeclaredAnnotationsImpl(global::java.lang.Class thisClass)
static global::java.security.ProtectionDomain getProtectionDomain0(global::java.lang.Class thisClass)
static global::java.lang.Class[] getDeclaredClasses0(global::java.lang.Class thisClass)
static bool isArray(global::java.lang.Class thisClass)
static object getConstantPool(global::java.lang.Class self)
Implements the native method 'getConstantPool'.
static int getModifiers(global::java.lang.Class thisClass)
static global::java.lang.Class getComponentType(global::java.lang.Class thisClass)
static object[] getEnclosingMethod0(global::java.lang.Class thisClass)
static byte[] getRawTypeAnnotations(global::java.lang.Class thisClass)
Implements the native method 'getRawTypeAnnotations'.
static bool isInstance(global::java.lang.Class self, object obj)
Implements the native method 'isInstance'.
static void setSigners(global::java.lang.Class thisClass, object[] signers)
static object getDeclaredMethods0(global::java.lang.Class thisClass, bool publicOnly)
static string getName0(global::java.lang.Class thisClass)
static global::java.lang.ClassLoader getClassLoader0(global::java.lang.Class thisClass)
static bool isAssignableFrom(global::java.lang.Class self, global::java.lang.Class otherClass)
Implements the native method 'isAssignableFrom'.
static string getGenericSignature0(global::java.lang.Class thisClass)
static global::java.lang.Class getSuperclass(global::java.lang.Class thisClass)
static object[] getSigners(global::java.lang.Class thisClass)
static bool isPrimitive(global::java.lang.Class thisClass)
static bool isInterface(global::java.lang.Class self)
Implements the native method 'isInterface'.
static global::java.lang.Class getDeclaringClass0(global::java.lang.Class thisClass)
static bool desiredAssertionStatus0(global::java.lang.Class clazz)
static string getSigName(global::java.lang.Class thisClass)
This is not a Java exception, but instead it wraps a Java exception that was thrown by a class loader...
Main state of the running JVM.
.NET exception that corresponds to a Java exception.
Represents an intrinsified anonymous class. Currently only used by LambdaMetafactory.
Runtime support for a class loader.
RuntimePrimitiveJavaTypeFactory PrimitiveJavaTypeFactory
Gets the RuntimePrimitiveJavaTypeFactory associated with this instance of the runtime.
RuntimeClassLoaderFactory ClassLoaderFactory
Gets the RuntimeClassLoaderFactory associated with this instance of the runtime.
@ IncompatibleClassChangeError