From: Tuukka Lehtonen Date: Mon, 8 Nov 2021 10:41:33 +0000 (+0200) Subject: Add InvertBasicExpressionVisitor.parseInvertibleExpression X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=bf61329ab8be1aa339b0a7e0433a785efa5a6810;p=simantics%2Fplatform.git Add InvertBasicExpressionVisitor.parseInvertibleExpression gitlab #770 --- diff --git a/bundles/org.simantics.modeling/src/org/simantics/modeling/InvertBasicExpressionVisitor.java b/bundles/org.simantics.modeling/src/org/simantics/modeling/InvertBasicExpressionVisitor.java index 6293cbac9..e390e19a2 100644 --- a/bundles/org.simantics.modeling/src/org/simantics/modeling/InvertBasicExpressionVisitor.java +++ b/bundles/org.simantics.modeling/src/org/simantics/modeling/InvertBasicExpressionVisitor.java @@ -105,11 +105,10 @@ public class InvertBasicExpressionVisitor extends InvertBasicExpressionVisitorBa } @SuppressWarnings("unchecked") - private static Triple possibleInvertibleExpression(ReadGraph graph, Variable base, String expression) throws DatabaseException { - if (base == null || expression == null || expression.isEmpty()) + private static Triple possibleInvertibleExpression(String expression) { + if (expression == null || expression.isEmpty()) return null; InvertBasicExpressionVisitor visitor = new InvertBasicExpressionVisitor(); - //System.out.println("invert : " + expression + " -> " + replaced(expression) + " for " + base.getURI(graph)); Expressions.evaluate(replaced(expression), visitor); Object result = visitor.getResult(); if (result instanceof Triple) @@ -117,6 +116,21 @@ public class InvertBasicExpressionVisitor extends InvertBasicExpressionVisitorBa return null; } + public static Triple parseInvertibleExpression(String expression) { + Triple data = possibleInvertibleExpression(expression); + if (data == null) + return null; + String key = data.third.replace(MAGIC, "."); + return Triple.make(data.first, data.second, key); + } + + private static Triple possibleInvertibleExpression(ReadGraph graph, Variable base, String expression) throws DatabaseException { + if (base == null) + return null; + //System.out.println("invert : " + expression + " -> " + replaced(expression) + " for " + base.getURI(graph)); + return possibleInvertibleExpression(expression); + } + public static Variable possibleInvertibleExpressionReferencedProperty(ReadGraph graph, Variable base, String expression) throws DatabaseException { Triple data = possibleInvertibleExpression(graph, base, expression); if (data == null)