
j.ProgramReflection Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jtransc-rt-core Show documentation
Show all versions of jtransc-rt-core Show documentation
JVM AOT compiler currently generating JavaScript, C++, Haxe, with initial focus on Kotlin and games.
package j;
import com.jtransc.annotation.JTranscMethodBody;
import com.jtransc.annotation.haxe.HaxeMethodBody;
import com.jtransc.ds.FastIntMap;
import com.jtransc.ds.FastStringMap;
import com.jtransc.io.JTranscConsole;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
/**
* MetaReflectionPlugin set those methods
*/
@SuppressWarnings({"unused", "WeakerAccess", "ConstantConditions"})
public class ProgramReflection {
static public ClassInfo[] _classInfos;
static public String[] _classNames;
static public FastStringMap _classInfosByName;
static public FastIntMap> _constructorsInfo;
static public FastIntMap> _methodInfos;
static public FastIntMap> _fieldsInfos;
@SuppressWarnings("ConstantConditions")
static public void _ensure() {
if (_classInfos != null) return;
_classInfosByName = new FastStringMap<>();
_classInfos = ProgramReflection.getAllClasses();
_classNames = new String[_classInfos.length];
for (ClassInfo info : _classInfos) {
if (info == null) continue;
//if (info.name == null) JTranscConsole.error("ProgramReflection.ensure: info.name==null");
_classInfosByName.set(info.name, info);
_classNames[info.id] = info.name;
}
}
static public void _ensureConstructors() {
if (_constructorsInfo != null) return;
_ensure();
_constructorsInfo = new FastIntMap<>();
for (ClassInfo info : _classInfos) {
if (info == null) continue;
FastIntMap map = new FastIntMap<>();
_constructorsInfo.set(info.id, map);
MemberInfo[] minfo = getConstructors(info.id);
if (minfo != null) for (MemberInfo i : minfo) map.set(i.id, i);
}
}
static public void _ensureFields() {
if (_fieldsInfos != null) return;
_ensure();
_fieldsInfos = new FastIntMap<>();
for (ClassInfo info : _classInfos) {
if (info == null) continue;
FastIntMap map = new FastIntMap<>();
_fieldsInfos.set(info.id, map);
MemberInfo[] minfo = getFields(info.id);
if (minfo != null) for (MemberInfo i : minfo) map.set(i.id, i);
}
}
static public void _ensureMethods() {
if (_methodInfos != null) return;
_ensure();
_methodInfos = new FastIntMap<>();
for (ClassInfo info : _classInfos) {
if (info == null) continue;
FastIntMap map = new FastIntMap<>();
_methodInfos.set(info.id, map);
MemberInfo[] minfo = getMethods(info.id);
if (minfo != null) for (MemberInfo i : minfo) map.set(i.id, i);
}
}
static public boolean hasClassWithName(String name) {
ProgramReflection._ensure();
return ProgramReflection._classInfosByName.has(name);
}
static public ClassInfo getClassInfoWithName(String name) {
ProgramReflection._ensure();
return hasClassWithName(name) ? ProgramReflection._classInfosByName.get(name) : null;
}
// Class
static public ClassInfo[] getAllClasses() {
return new ClassInfo[0];
}
// @NOTE: This will be replaced by MetaReflectionPlugin
static public MemberInfo[] getConstructors(int classId) {
return new MemberInfo[0];
}
// @NOTE: This will be replaced by MetaReflectionPlugin
static public MemberInfo[] getMethods(int classId) {
return new MemberInfo[0];
}
// @NOTE: This will be replaced by MetaReflectionPlugin
static public MemberInfo[] getFields(int classId) {
return new MemberInfo[0];
}
// Constructor
static public Object dynamicNew(int classId, int constructorId, Object[] params) {
return null;
}
// Method
static public Object dynamicInvoke(int classId, int methodId, Object object, Object[] params) {
return null;
}
// Field
static public Object dynamicGet(int classId, int fieldId, Object object) {
return null;
}
static public void dynamicSet(int classId, int fieldId, Object object, Object value) {
}
static public Annotation[] getClassAnnotations(int classId) {
return new Annotation[0];
}
static public Annotation[] getFieldAnnotations(int classId, int fieldId) {
return new Annotation[0];
}
static public Annotation[] getMethodAnnotations(int classId, int methodId) {
return new Annotation[0];
}
static public Annotation[] getMethodArgumentAnnotations(int classId, int methodId, int argIndex) {
return new Annotation[0];
}
static public MemberInfo getMethodInfo(int classId, int methodId) {
_ensureMethods();
return _methodInfos.get(classId).get(methodId);
}
//native static public Class> getClassByInfo(ClassInfo info);
native static public Method getMethodByInfo(Class> clazz, MemberInfo info);
static public Class> getClassById(int classId) {
ProgramReflection._ensure();
try {
return Class.forName(_classNames[classId]);
} catch (ClassNotFoundException e) {
e.printStackTrace();
return null;
}
}
static public Method getDirectMethod(int classId, int methodId) {
return getMethodByInfo(getClassById(classId), getMethodInfo(classId, methodId));
}
//static public long dynamicFieldPtr(int fieldId, Object object) {
// return 0L;
//}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy