X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.scl.commands%2Fsrc%2Forg%2Fsimantics%2Fscl%2Fcommands%2Finternal%2FStringConverterFactory.java;h=5b6398b55fd527556682c46ee868511a38d55489;hb=b844ca924d129072e11f7e4c18918dd388a37e8c;hp=592bf3d2857c96aae9f83ab3ce9d16a214c787b9;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.scl.commands/src/org/simantics/scl/commands/internal/StringConverterFactory.java b/bundles/org.simantics.scl.commands/src/org/simantics/scl/commands/internal/StringConverterFactory.java index 592bf3d28..5b6398b55 100644 --- a/bundles/org.simantics.scl.commands/src/org/simantics/scl/commands/internal/StringConverterFactory.java +++ b/bundles/org.simantics.scl.commands/src/org/simantics/scl/commands/internal/StringConverterFactory.java @@ -1,49 +1,49 @@ -package org.simantics.scl.commands.internal; - -import java.util.concurrent.ConcurrentHashMap; - -import org.simantics.db.Resource; -import org.simantics.scl.compiler.environment.specification.EnvironmentSpecification; -import org.simantics.scl.compiler.module.repository.ImportFailureException; -import org.simantics.scl.compiler.runtime.RuntimeEnvironment; -import org.simantics.scl.compiler.top.ExpressionEvaluator; -import org.simantics.scl.compiler.top.SCLExpressionCompilationException; -import org.simantics.scl.compiler.top.ValueNotFound; -import org.simantics.scl.compiler.types.Type; -import org.simantics.scl.compiler.types.Types; -import org.simantics.scl.osgi.SCLOsgi; -import org.simantics.scl.runtime.function.Function2; - -@SuppressWarnings({"rawtypes", "unchecked"}) -public class StringConverterFactory { - private static final ConcurrentHashMap CONVERTER_CACHE = - new ConcurrentHashMap(); - private static RuntimeEnvironment environment; - - private static final Type ALLOWED_EFFECT = Types.union(new Type[] {Types.READ_GRAPH, Types.PROC}); - - /** - * Creates a string converter for given type. - * @throws ValueNotFound - */ - public static Function2 stringConverterFor(Type type) throws SCLExpressionCompilationException, ImportFailureException { - Function2 converter = CONVERTER_CACHE.get(type); - if(converter == null) { - if(environment == null) { - // no need to synchronize access to environment - environment = SCLOsgi.MODULE_REPOSITORY.createRuntimeEnvironment( - EnvironmentSpecification.of( - "Simantics/GShow", "", - "Simantics/RouteGraph", "", - "Prelude", "" - ), StringConverterFactory.class.getClassLoader() - ); - } - converter = (Function2)new ExpressionEvaluator(environment, "\\ctx r -> gshow ctx (Par 0 r)") - .expectedType(Types.function(Types.RESOURCE, Types.functionE(type, ALLOWED_EFFECT, Types.STRING))) - .eval(); - CONVERTER_CACHE.put(type, converter); - } - return converter; - } -} +package org.simantics.scl.commands.internal; + +import java.util.concurrent.ConcurrentHashMap; + +import org.simantics.db.Resource; +import org.simantics.scl.compiler.environment.specification.EnvironmentSpecification; +import org.simantics.scl.compiler.module.repository.ImportFailureException; +import org.simantics.scl.compiler.runtime.RuntimeEnvironment; +import org.simantics.scl.compiler.top.ExpressionEvaluator; +import org.simantics.scl.compiler.top.SCLExpressionCompilationException; +import org.simantics.scl.compiler.top.ValueNotFound; +import org.simantics.scl.compiler.types.Type; +import org.simantics.scl.compiler.types.Types; +import org.simantics.scl.osgi.SCLOsgi; +import org.simantics.scl.runtime.function.Function2; + +@SuppressWarnings({"rawtypes", "unchecked"}) +public class StringConverterFactory { + private static final ConcurrentHashMap CONVERTER_CACHE = + new ConcurrentHashMap(); + private static RuntimeEnvironment environment; + + private static final Type ALLOWED_EFFECT = Types.union(new Type[] {Types.READ_GRAPH, Types.PROC}); + + /** + * Creates a string converter for given type. + * @throws ValueNotFound + */ + public static Function2 stringConverterFor(Type type) throws SCLExpressionCompilationException, ImportFailureException { + Function2 converter = CONVERTER_CACHE.get(type); + if(converter == null) { + if(environment == null) { + // no need to synchronize access to environment + environment = SCLOsgi.MODULE_REPOSITORY.createRuntimeEnvironment( + EnvironmentSpecification.of( + "Simantics/GShow", "", + "Simantics/RouteGraph", "", + "Prelude", "" + ), StringConverterFactory.class.getClassLoader() + ); + } + converter = (Function2)new ExpressionEvaluator(environment, "\\ctx r -> gshow ctx (Par 0 r)") + .expectedType(Types.function(Types.RESOURCE, Types.functionE(type, ALLOWED_EFFECT, Types.STRING))) + .eval(); + CONVERTER_CACHE.put(type, converter); + } + return converter; + } +}