X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.scl.compiler%2Fscl%2FSCL%2FReflection.scl;h=e32401d502c79aada0291d3c510b91a28b0ffc14;hp=cf8b88eeac1aa42ded978b60a4b6cd77d735d98a;hb=f238db98a6075e59973c5c391a1946eb7972c7a5;hpb=908f3683f6cd21dcff70a8f3b1a9d1e3368ca5af diff --git a/bundles/org.simantics.scl.compiler/scl/SCL/Reflection.scl b/bundles/org.simantics.scl.compiler/scl/SCL/Reflection.scl index cf8b88eea..e32401d50 100644 --- a/bundles/org.simantics.scl.compiler/scl/SCL/Reflection.scl +++ b/bundles/org.simantics.scl.compiler/scl/SCL/Reflection.scl @@ -1,5 +1,6 @@ module { - export = [possibleUnsafeSclValueByName, unsafeSclValueByName, sclModuleNames] + export = [possibleUnsafeSclValueByName, unsafeSclValueByName, sclModuleNames, moduleByName, + moduleOf, nameOf, createName, valueNamesOf] } include "SCL/ReflectionJava" @@ -11,11 +12,47 @@ importJava "org.simantics.scl.compiler.module.repository.ModuleRepository" where @JavaName getSourceRepository moduleSourceRepositoryOf :: ModuleRepository -> ModuleSourceRepository + @JavaName getModule + moduleByName_ :: ModuleRepository -> String -> Failable Module + importJava "org.simantics.scl.compiler.source.repository.ModuleSourceRepository" where data ModuleSourceRepository @JavaName getModuleNames sclModuleNames_ :: ModuleSourceRepository -> [String] + +importJava "org.simantics.scl.compiler.errors.Failable" where + data Failable a + + didSucceed :: Failable a -> Boolean + getResult :: Failable a -> Maybe a + +importJava "org.simantics.scl.compiler.module.Module" where + data Module + + @JavaName getValueNames + valueNamesOf_ :: Module -> [String] + +importJava "org.simantics.scl.compiler.common.names.Name" where + data Name + + @JavaName module + moduleOf_ :: Name -> String + @JavaName name + nameOf_ :: Name -> String + + @JavaName create + createName_ :: String -> String -> Name + +instance Show Name where + sb <+ n = sb << moduleOf n << "/" << nameOf n + +moduleOf = moduleOf_ +nameOf = nameOf_ +createName = createName_ +valueNamesOf = valueNamesOf_ + +type Location = Long unsafeSclValueByName :: String -> a unsafeSclValueByName = unsafeSclValueByName_ MODULE_REPOSITORY @@ -25,3 +62,8 @@ possibleUnsafeSclValueByName name = Just (unsafeSclValueByName name) `catch` \(_ sclModuleNames :: [String] sclModuleNames = sclModuleNames_ (moduleSourceRepositoryOf MODULE_REPOSITORY) + +moduleByName :: String -> Maybe Module +moduleByName name = getResult failable + where + failable = moduleByName_ MODULE_REPOSITORY name \ No newline at end of file