X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.structural2%2Fsrc%2Forg%2Fsimantics%2Fstructural2%2Fscl%2FAbstractCompileStructuralValueRequest.java;h=5e8538a69a80aca2ca8560577d6df868175bf332;hp=283e1b5ddcadd6f836fef90a811ce8392bac97a7;hb=844ae73ef4a9109b12d4d810b9d3bc5e147e298f;hpb=5c5ee43928133ae99fcb693a6980d86f088b2cb5 diff --git a/bundles/org.simantics.structural2/src/org/simantics/structural2/scl/AbstractCompileStructuralValueRequest.java b/bundles/org.simantics.structural2/src/org/simantics/structural2/scl/AbstractCompileStructuralValueRequest.java index 283e1b5dd..5e8538a69 100644 --- a/bundles/org.simantics.structural2/src/org/simantics/structural2/scl/AbstractCompileStructuralValueRequest.java +++ b/bundles/org.simantics.structural2/src/org/simantics/structural2/scl/AbstractCompileStructuralValueRequest.java @@ -9,12 +9,11 @@ import org.simantics.db.Resource; import org.simantics.db.common.procedure.adapter.TransientCacheListener; import org.simantics.db.common.request.PossibleIndexRoot; import org.simantics.db.common.request.ResourceRead2; +import org.simantics.db.common.request.RuntimeEnvironmentRequest; import org.simantics.db.exception.DatabaseException; import org.simantics.db.layer0.scl.AbstractExpressionCompilationContext; import org.simantics.db.layer0.scl.AbstractExpressionCompilationRequest; -import org.simantics.db.layer0.util.RuntimeEnvironmentRequest; import org.simantics.db.layer0.util.RuntimeEnvironmentRequest2; -import org.simantics.db.layer0.variable.Variable; import org.simantics.layer0.Layer0; import org.simantics.scl.compiler.elaboration.expressions.EApply; import org.simantics.scl.compiler.elaboration.expressions.EConstant; @@ -27,6 +26,8 @@ import org.simantics.scl.compiler.runtime.RuntimeEnvironment; import org.simantics.scl.compiler.top.SCLExpressionCompilationException; import org.simantics.scl.compiler.types.Type; import org.simantics.structural2.scl.AbstractCompileStructuralValueRequest.CompilationContext; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Compiles an SCL expression that is attached to a literal @@ -34,8 +35,10 @@ import org.simantics.structural2.scl.AbstractCompileStructuralValueRequest.Compi * * @author Antti Villberg */ -abstract public class AbstractCompileStructuralValueRequest extends AbstractExpressionCompilationRequest { +public abstract class AbstractCompileStructuralValueRequest extends AbstractExpressionCompilationRequest { + private static final Logger LOGGER = LoggerFactory.getLogger(AbstractCompileStructuralValueRequest.class); + protected final Resource relation; public static class CompilationContext extends AbstractExpressionCompilationContext { @@ -54,8 +57,27 @@ abstract public class AbstractCompileStructuralValueRequest extends AbstractExpr @Override abstract protected String getExpressionText(ReadGraph graph) throws DatabaseException; + + /* + * @throws DatabaseException is an index root could not be found + */ abstract protected Resource getIndexRoot(ReadGraph graph) throws DatabaseException; + /* + * Does not throw if the graph is valid. + * + * @return null if component type was not availble + * + */ abstract protected Resource getComponentType(ReadGraph graph) throws DatabaseException; + + protected Resource getPossibleIndexRoot(ReadGraph graph) throws DatabaseException { + try { + return getIndexRoot(graph); + } catch (DatabaseException e) { + LOGGER.error("Error while resolving index root during structural value compilation", e); + return null; + } + } @Override protected Type getExpectedType(ReadGraph graph, CompilationContext context) @@ -136,4 +158,23 @@ abstract public class AbstractCompileStructuralValueRequest extends AbstractExpr return null; } + @Override + protected String getContextDescription(ReadGraph graph) throws DatabaseException { + Resource componentType = getComponentType(graph); + if(componentType != null) { + String uri = graph.getPossibleURI(componentType); + if(uri != null) + return uri; + } + // OK, no component type - report index root then + Resource indexRoot = getPossibleIndexRoot(graph); + if(indexRoot != null) { + String uri = graph.getPossibleURI(componentType); + if(uri != null) + return uri; + } + // OK, nothing - report default + return super.getContextDescription(graph); + } + }