X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.g3d%2Fsrc%2Forg%2Fsimantics%2Fg3d%2Fscl%2FSCLUtil.java;h=940c244ed8d39bb368e1b7954c4a427dc7ff7396;hb=53d55c24c779745f188bdb18d32f71d20acb61b2;hp=99563462bd666779d13cce0838ba8901a5017995;hpb=f36217aeeb09c0c46f99886ee99772156ce9cfe6;p=simantics%2F3d.git diff --git a/org.simantics.g3d/src/org/simantics/g3d/scl/SCLUtil.java b/org.simantics.g3d/src/org/simantics/g3d/scl/SCLUtil.java index 99563462..940c244e 100644 --- a/org.simantics.g3d/src/org/simantics/g3d/scl/SCLUtil.java +++ b/org.simantics.g3d/src/org/simantics/g3d/scl/SCLUtil.java @@ -15,65 +15,65 @@ import org.simantics.scl.compiler.types.Type; import org.simantics.scl.osgi.SCLOsgi; public class SCLUtil { - - static Map> typeMap = new HashMap>(); - // copied from org.simantics.scl.db.SCLFunctions - public static Class possibleFromDynamic(Type expectedType, String moduleName) { - - try { + + static Map> typeMap = new HashMap>(); + // copied from org.simantics.scl.db.SCLFunctions + public static Class possibleFromDynamic(Type expectedType, String moduleName) { + + try { - - Failable failable = SCLOsgi.MODULE_REPOSITORY.getModule(moduleName); - Module module = failable.getResult(); - - RuntimeEnvironment env = SCLOsgi.MODULE_REPOSITORY.createRuntimeEnvironment( - EnvironmentSpecification.of(moduleName, ""), module.getParentClassLoader()); + + Failable failable = SCLOsgi.MODULE_REPOSITORY.getModule(moduleName); + Module module = failable.getResult(); + + RuntimeEnvironment env = SCLOsgi.MODULE_REPOSITORY.createRuntimeEnvironment( + EnvironmentSpecification.of(moduleName, ""), module.getParentClassLoader()); - JavaTypeTranslator tr = new JavaTypeTranslator(env.getEnvironment()); - TypeDesc desc = tr.toTypeDesc(expectedType); - String className = desc.getFullName(); - Class clazz = env.getMutableClassLoader().loadClass(className); - return clazz; - } catch (ImportFailureException e) { - return null; - } catch (ClassNotFoundException e) { - return null; - } - } - - public static Class possibleClass(TCon type) { - Class clazz = typeMap.get(type); - if (clazz == null) { - clazz = possibleFromDynamic(type, type.module); - typeMap.put(type, clazz); - } - return clazz; - } - - public static boolean javaIsInstanceOf(org.simantics.scl.compiler.types.Type t, Object o) { - if (t instanceof TCon) { - Class clazz = possibleClass((TCon)t); - if (clazz == null) - return false; - if (!clazz.isAssignableFrom(o.getClass())) - return false; - - return true; - } - return false; - } - - public static Object javaSafeCoerce(org.simantics.scl.compiler.types.Type t, Object o) { - if (t instanceof TCon) { - Class clazz = possibleClass((TCon)t); - if (clazz == null) - return null; - if (!clazz.isAssignableFrom(o.getClass())) - return null; - - return o; - } - return null; - } + JavaTypeTranslator tr = new JavaTypeTranslator(env.getEnvironment()); + TypeDesc desc = tr.toTypeDesc(expectedType); + String className = desc.getFullName(); + Class clazz = env.getMutableClassLoader().loadClass(className); + return clazz; + } catch (ImportFailureException e) { + return null; + } catch (ClassNotFoundException e) { + return null; + } + } + + public static Class possibleClass(TCon type) { + Class clazz = typeMap.get(type); + if (clazz == null) { + clazz = possibleFromDynamic(type, type.module); + typeMap.put(type, clazz); + } + return clazz; + } + + public static boolean javaIsInstanceOf(org.simantics.scl.compiler.types.Type t, Object o) { + if (t instanceof TCon) { + Class clazz = possibleClass((TCon)t); + if (clazz == null) + return false; + if (!clazz.isAssignableFrom(o.getClass())) + return false; + + return true; + } + return false; + } + + public static Object javaSafeCoerce(org.simantics.scl.compiler.types.Type t, Object o) { + if (t instanceof TCon) { + Class clazz = possibleClass((TCon)t); + if (clazz == null) + return null; + if (!clazz.isAssignableFrom(o.getClass())) + return null; + + return o; + } + return null; + } }