From: jsimomaa Date: Wed, 1 Nov 2017 08:25:36 +0000 (+0200) Subject: Create separate requests for validating SCL values X-Git-Tag: v1.31.0~70 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F77%2F1177%2F1;p=simantics%2Fplatform.git Create separate requests for validating SCL values refs #7575 Change-Id: I47f9402407c0084e6a5f4859c7b05ef5557619b6 --- diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/scl/AbstractExpressionCompilationRequest.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/scl/AbstractExpressionCompilationRequest.java index b12d0258e..d40f82d4d 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/scl/AbstractExpressionCompilationRequest.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/scl/AbstractExpressionCompilationRequest.java @@ -1,7 +1,5 @@ package org.simantics.db.layer0.scl; -import gnu.trove.map.hash.THashMap; - import java.util.ArrayList; import java.util.List; @@ -37,6 +35,8 @@ import org.simantics.scl.runtime.SCLContext; import org.simantics.scl.runtime.function.Function1; import org.simantics.utils.datastructures.Pair; +import gnu.trove.map.hash.THashMap; + /** *

This is a base implementation for compiling expressions stored into * graph. It provides a skeleton and a set of methods that must be diff --git a/bundles/org.simantics.document.server/src/org/simantics/document/server/Functions.java b/bundles/org.simantics.document.server/src/org/simantics/document/server/Functions.java index a6e9d6ab6..9c6292415 100644 --- a/bundles/org.simantics.document.server/src/org/simantics/document/server/Functions.java +++ b/bundles/org.simantics.document.server/src/org/simantics/document/server/Functions.java @@ -1312,7 +1312,7 @@ public class Functions { public static String compileDocumentSCLValueExpression(ReadGraph graph, Variable context) { try { - ServerSCLValueRequest.compile(graph, context); + ServerSCLValueRequest.validate(graph, context); return ""; } catch (Exception e) { return resolveIssueMessage(e); diff --git a/bundles/org.simantics.document.server/src/org/simantics/document/server/request/ServerSCLHandlerValueRequest.java b/bundles/org.simantics.document.server/src/org/simantics/document/server/request/ServerSCLHandlerValueRequest.java index 286cae272..4a4164303 100644 --- a/bundles/org.simantics.document.server/src/org/simantics/document/server/request/ServerSCLHandlerValueRequest.java +++ b/bundles/org.simantics.document.server/src/org/simantics/document/server/request/ServerSCLHandlerValueRequest.java @@ -22,10 +22,8 @@ import org.simantics.scl.compiler.elaboration.expressions.EVariable; import org.simantics.scl.compiler.elaboration.expressions.Expression; import org.simantics.scl.compiler.elaboration.modules.SCLValue; import org.simantics.scl.compiler.environment.Environment; -import org.simantics.scl.compiler.environment.Environments; import org.simantics.scl.compiler.environment.specification.EnvironmentSpecification; import org.simantics.scl.compiler.runtime.RuntimeEnvironment; -import org.simantics.scl.compiler.top.SCLExpressionCompilationException; import org.simantics.scl.compiler.types.TCon; import org.simantics.scl.compiler.types.Type; import org.simantics.scl.compiler.types.Types; @@ -36,13 +34,9 @@ import org.simantics.structural2.scl.ComponentTypeProperty; import org.simantics.structural2.scl.FindPossibleComponentTypeRequest; import org.simantics.structural2.scl.ReadComponentTypeInterfaceRequest; import org.simantics.utils.datastructures.Pair; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; public class ServerSCLHandlerValueRequest extends AbstractExpressionCompilationRequest { - private static final Logger LOGGER = LoggerFactory.getLogger(ServerSCLHandlerValueRequest.class); - private final Variable context; private final Pair componentTypeAndRoot; private final Resource literal; @@ -230,17 +224,9 @@ public class ServerSCLHandlerValueRequest extends AbstractExpressionCompilationR @Override protected Type getExpectedType(ReadGraph graph, CompilationContext context) throws DatabaseException { - if(possibleExpectedValueType != null) { - try { - return Environments.getType(context.runtimeEnvironment.getEnvironment(), possibleExpectedValueType); - } catch (SCLExpressionCompilationException e) { - LOGGER.error("Could not get type for " + String.valueOf(possibleExpectedValueType), e); - } - } return super.getExpectedType(graph, context); } - @Override public int hashCode() { final int prime = 31; diff --git a/bundles/org.simantics.document.server/src/org/simantics/document/server/request/ServerSCLValueRequest.java b/bundles/org.simantics.document.server/src/org/simantics/document/server/request/ServerSCLValueRequest.java index b4d4d2c1f..f9181d271 100644 --- a/bundles/org.simantics.document.server/src/org/simantics/document/server/request/ServerSCLValueRequest.java +++ b/bundles/org.simantics.document.server/src/org/simantics/document/server/request/ServerSCLValueRequest.java @@ -42,8 +42,6 @@ import org.slf4j.LoggerFactory; public class ServerSCLValueRequest extends AbstractExpressionCompilationRequest { - private static final Logger LOGGER = LoggerFactory.getLogger(ServerSCLValueRequest.class); - private final Pair componentTypeAndRoot; private final Resource literal; protected String possibleExpectedValueType; @@ -206,13 +204,6 @@ public class ServerSCLValueRequest extends AbstractExpressionCompilationRequest< @Override protected Type getExpectedType(ReadGraph graph, CompilationContext context) throws DatabaseException { - if(possibleExpectedValueType != null) { - try { - return Environments.getType(context.runtimeEnvironment.getEnvironment(), possibleExpectedValueType); - } catch (SCLExpressionCompilationException e) { - LOGGER.error("Could not get type for " + String.valueOf(possibleExpectedValueType), e); - } - } return super.getExpectedType(graph, context); } @@ -231,4 +222,29 @@ public class ServerSCLValueRequest extends AbstractExpressionCompilationRequest< ServerSCLValueRequest other = (ServerSCLValueRequest)obj; return literal.equals(other.literal) && componentTypeAndRoot.equals(other.componentTypeAndRoot); } + + public static Function1 validate(ReadGraph graph, Variable context) throws DatabaseException { + return graph.syncRequest(new ServerSCLValueValidationRequest(graph, context), TransientCacheListener.>instance()); + } + + public static class ServerSCLValueValidationRequest extends ServerSCLValueRequest { + + private static final Logger LOGGER = LoggerFactory.getLogger(ServerSCLHandlerValueRequest.class); + + public ServerSCLValueValidationRequest(ReadGraph graph, Variable context) throws DatabaseException { + super(graph, context); + } + + @Override + protected Type getExpectedType(ReadGraph graph, CompilationContext context) throws DatabaseException { + if(possibleExpectedValueType != null) { + try { + return Environments.getType(context.runtimeEnvironment.getEnvironment(), possibleExpectedValueType); + } catch (SCLExpressionCompilationException e) { + LOGGER.error("Could not get type for " + String.valueOf(possibleExpectedValueType), e); + } + } + return super.getExpectedType(graph, context); + } + } }