From bf61329ab8be1aa339b0a7e0433a785efa5a6810 Mon Sep 17 00:00:00 2001 From: Tuukka Lehtonen Date: Mon, 8 Nov 2021 12:41:33 +0200 Subject: [PATCH] Add InvertBasicExpressionVisitor.parseInvertibleExpression gitlab #770 --- .../InvertBasicExpressionVisitor.java | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) 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) -- 2.47.1