From: Hannu Niemistö Date: Tue, 20 Mar 2018 12:07:13 +0000 (+0200) Subject: Added a function to read the module source text X-Git-Tag: v1.43.0~136^2~535^2 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=947cdc62f1d9a353726d29693c339edd1d0cacf6;p=simantics%2Fplatform.git Added a function to read the module source text refs #7811 Change-Id: I62a37e226b1f7b531d69e8446bbff805c67825ec --- diff --git a/bundles/org.simantics.scl.compiler/scl/SCL/ModuleRepository.scl b/bundles/org.simantics.scl.compiler/scl/SCL/ModuleRepository.scl index 7d035d8cf..e8d37789b 100644 --- a/bundles/org.simantics.scl.compiler/scl/SCL/ModuleRepository.scl +++ b/bundles/org.simantics.scl.compiler/scl/SCL/ModuleRepository.scl @@ -1,6 +1,6 @@ module { export = [possibleUnsafeSclValueByName, unsafeSclValueByName, sclModuleNames, moduleByName, - documentationOfSCLValue, sclValueRef] + documentationOfSCLValue, sclValueRef, possibleModuleSourceText] } include "./CurrentModuleRepository" @@ -35,6 +35,9 @@ importJava "org.simantics.scl.compiler.source.repository.ModuleSourceRepository" @JavaName getModuleNames sclModuleNames_ :: ModuleSourceRepository -> [String] + + @JavaName getPossibleSourceText + possibleModuleSourceText_ :: ModuleSourceRepository -> String -> Maybe String importJava "org.simantics.scl.compiler.errors.Failable" where data Failable a @@ -56,4 +59,7 @@ 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 + failable = moduleByName_ MODULE_REPOSITORY name + +possibleModuleSourceText :: String -> Maybe String +possibleModuleSourceText name = possibleModuleSourceText_ (moduleSourceRepositoryOf MODULE_REPOSITORY) name \ No newline at end of file diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/source/repository/ModuleSourceRepository.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/source/repository/ModuleSourceRepository.java index c335a8aa1..fe014773c 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/source/repository/ModuleSourceRepository.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/source/repository/ModuleSourceRepository.java @@ -1,11 +1,13 @@ package org.simantics.scl.compiler.source.repository; +import java.io.IOException; import java.util.Collection; import java.util.Collections; import org.simantics.scl.compiler.module.repository.ModuleRepository; import org.simantics.scl.compiler.module.repository.UpdateListener; import org.simantics.scl.compiler.source.ModuleSource; +import org.simantics.scl.compiler.source.TextualModuleSource; import gnu.trove.procedure.TObjectProcedure; @@ -76,4 +78,13 @@ public interface ModuleSourceRepository { */ default void clear() { } + + default String getPossibleSourceText(String moduleName) throws IOException { + ModuleSource moduleSource = getModuleSource(moduleName, null); + if(moduleSource == null) + return null; + if(!(moduleSource instanceof TextualModuleSource)) + return null; + return ((TextualModuleSource)moduleSource).getSourceText(null); + } }