public static ObjCClass getByType(Class<? extends ObjCObject> type) { if (type == null) { throw new NullPointerException("type"); } synchronized (typeToClass) { ObjCClass c = typeToClass.get(type); if (c == null) { NativeClass nativeClassAnno = type.getAnnotation(NativeClass.class); String name = null; if (nativeClassAnno != null) { name = nativeClassAnno.value(); name = "".equals(name) ? type.getSimpleName() : name; } else { name = getCustomClassName(type); c = register(type, name); } if (c == null) { long classPtr = ObjCRuntime.objc_getClass(VM.getStringUTFChars(name)); if (classPtr == 0L) { throw new ObjCClassNotFoundException(name); } c = new ObjCClass(classPtr, type, name, false); } typeToClass.put(type, c); nameToClass.put(name, c); } return c; } }
static { ObjCRuntime.bind(); @SuppressWarnings("unchecked") Class<? extends ObjCObject>[] classes = (Class<? extends ObjCObject>[]) VM.listClasses(ObjCObject.class, ClassLoader.getSystemClassLoader()); for (Class<? extends ObjCObject> cls : classes) { NativeClass nativeClassAnno = cls.getAnnotation(NativeClass.class); if (nativeClassAnno != null) { String name = nativeClassAnno.value(); if (name.length() == 0) { name = cls.getSimpleName(); } allNativeClasses.put(name, cls); } else { CustomClass customClassAnno = cls.getAnnotation(CustomClass.class); String name = cls.getName(); if (customClassAnno != null) { String value = customClassAnno.value(); if (value.length() > 0) { name = value; } } else if (name.indexOf('.') == -1) { name = "." + name; } allCustomClasses.put(name, cls); } if (isObjCProxy(cls)) { // Map protocol interface names to ObjC protocol proxy classes String name = cls.getName(); String protocolName = name.substring(0, name.length() - 10); allObjCProxyClasses.put(protocolName, cls); } } }