import java.util.ArrayList;
import java.util.List;
+import org.simantics.databoard.Bindings;
import org.simantics.db.ReadGraph;
import org.simantics.db.exception.DatabaseException;
import org.simantics.db.exception.RuntimeDatabaseException;
import org.simantics.db.request.Read;
+import org.simantics.layer0.Layer0;
import org.simantics.scl.compiler.common.names.Name;
import org.simantics.scl.compiler.constants.StringConstant;
import org.simantics.scl.compiler.elaboration.expressions.EApply;
else
return base;
}
+
+ protected static String resolveExpectedValueType(ReadGraph graph, org.simantics.db.layer0.variable.Variable context) throws DatabaseException {
+ Layer0 L0 = Layer0.getInstance(graph);
+ String valueType = graph.getPossibleRelatedValue(context.getPredicateResource(graph), L0.RequiresValueType, Bindings.STRING);
+ return valueType;
+ }
}
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;
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<CompilationContext, Variable> {
+ private static final Logger LOGGER = LoggerFactory.getLogger(ServerSCLHandlerValueRequest.class);
+
private final Variable context;
private final Pair<Resource,Resource> componentTypeAndRoot;
private final Resource literal;
+ protected String possibleExpectedValueType;
public static class CompilationContext extends AbstractExpressionCompilationContext {
public final Map<String, ComponentTypeProperty> propertyMap;
}
}
- private ServerSCLHandlerValueRequest(Variable context, Pair<Resource,Resource> componentTypeAndRoot, Resource literal) {
+ private ServerSCLHandlerValueRequest(Variable context, Pair<Resource,Resource> componentTypeAndRoot, Resource literal, String possibleExpectedValueType) {
assert(literal != null);
this.context = context;
this.literal = literal;
this.componentTypeAndRoot = componentTypeAndRoot;
+ this.possibleExpectedValueType = possibleExpectedValueType;
}
public ServerSCLHandlerValueRequest(ReadGraph graph, Variable context) throws DatabaseException {
- this(context, getComponentTypeAndRoot(graph, context), context.getRepresents(graph));
+ this(context, getComponentTypeAndRoot(graph, context), context.getRepresents(graph), resolveExpectedValueType(graph, context));
}
private static Pair<Resource,Resource> getComponentTypeAndRoot(ReadGraph graph, Variable property) throws DatabaseException {
return null;
}
+ @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;
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.Type;
import org.simantics.scl.compiler.types.Types;
import org.simantics.scl.compiler.types.kinds.Kinds;
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 ServerSCLValueRequest extends AbstractExpressionCompilationRequest<CompilationContext, Variable> {
+ private static final Logger LOGGER = LoggerFactory.getLogger(ServerSCLValueRequest.class);
+
private final Pair<Resource,Resource> componentTypeAndRoot;
private final Resource literal;
+ protected String possibleExpectedValueType;
public static class CompilationContext extends AbstractExpressionCompilationContext {
public final Map<String, ComponentTypeProperty> propertyMap;
}
}
- private ServerSCLValueRequest(Pair<Resource,Resource> componentTypeAndRoot, Resource literal) {
+ private ServerSCLValueRequest(Pair<Resource,Resource> componentTypeAndRoot, Resource literal, String possibleExpectedValueType) {
assert(literal != null);
this.literal = literal;
this.componentTypeAndRoot = componentTypeAndRoot;
+ this.possibleExpectedValueType = possibleExpectedValueType;
}
public ServerSCLValueRequest(ReadGraph graph, Variable context) throws DatabaseException {
- this(getComponentTypeAndRoot(graph, context), context.getRepresents(graph));
+ this(getComponentTypeAndRoot(graph, context), context.getRepresents(graph), resolveExpectedValueType(graph, context));
}
private static Pair<Resource,Resource> getComponentTypeAndRoot(ReadGraph graph, Variable property) throws DatabaseException {
else
return null;
}
+
+ @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() {