From 947cdc62f1d9a353726d29693c339edd1d0cacf6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Hannu=20Niemist=C3=B6?= Date: Tue, 20 Mar 2018 14:07:13 +0200 Subject: [PATCH] Added a function to read the module source text refs #7811 Change-Id: I62a37e226b1f7b531d69e8446bbff805c67825ec --- .../scl/SCL/ModuleRepository.scl | 10 ++++++++-- .../source/repository/ModuleSourceRepository.java | 11 +++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) 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); + } } -- 2.47.1