Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » VIATRA » Create CheckConstraint(How to create a CheckConstraint and a XExpression for it.)
Create CheckConstraint [message #1821457] Thu, 13 February 2020 11:25 Go to next message
Julian Barthel is currently offline Julian BarthelFriend
Messages: 6
Registered: November 2019
Location: Germany
Junior Member
Hi,

i want to manually add a CheckConstraint to a PatternBody, for this it needs a XExpression.
Currently i create a XExpression for the constraint with:

XbaseInjectorProvider xbaseInjectorProvider = new XbaseInjectorProvider();
injector = xbaseInjectorProvider.getInjector();
ParseHelper<XExpression> parseHelper = injector.getInstance(ParseHelper.class);
XBinaryOperation operation = (XBinaryOperation)
//stringForXExpression is something like: "a < 0"
parseHelper.parse(stringForXExpression);
CheckConstraint checkConstr = PatternLanguageFactory.eINSTANCE.createCheckConstraint();
checkConstr.setExpression(operation);

but everytime Viatra tries to get the matcher from the Pattern
(engine.getMatcher(builder.getOrCreateSpecification(pattern, true));) i get a error message

[main] WARN ime.api.ViatraQueryEngine.864864095 - The incremental pattern matcher encountered an error during check() evaluation for pattern(s) [findAllGamesLowerThan0] over values T(GamesSimple.impl.FPSImpl@26586b74 (name: CS:GO, isDLC: false, basicNumber: 0);0;). Error message: Segment cannot be null. (Developer note: IllegalArgumentException in [29]OutputCachingEvaluatorNode->[findAllGamesLowerThan0])
java.lang.IllegalArgumentException: Segment cannot be null
at org.eclipse.xtext.naming.QualifiedName.create(QualifiedName.java:239)
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._invokeFeature(XbaseInterpreter.java:1098)
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.invokeFeature(XbaseInterpreter.java:1083)
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._doEvaluate(XbaseInterpreter.java:991)
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._doEvaluate(XbaseInterpreter.java:954)
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.doEvaluate(XbaseInterpreter.java:235)
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.internalEvaluate(XbaseInterpreter.java:215)
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._doEvaluate(XbaseInterpreter.java:990)
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.doEvaluate(XbaseInterpreter.java:237)
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.internalEvaluate(XbaseInterpreter.java:215)
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.evaluate(XbaseInterpreter.java:201)
at org.eclipse.viatra.query.patternlanguage.emf.specification.XBaseEvaluator.evaluateExpression(XBaseEvaluator.java:90)
at org.eclipse.viatra.query.runtime.matchers.psystem.rewriters.VariableMappingExpressionEvaluatorWrapper.evaluateExpression(VariableMappingExpressionEvaluatorWrapper.java:81)
at org.eclipse.viatra.query.runtime.rete.eval.EvaluatorCore.evaluateTerm(EvaluatorCore.java:63)
at org.eclipse.viatra.query.runtime.rete.eval.EvaluatorCore.performEvaluation(EvaluatorCore.java:55)
at org.eclipse.viatra.query.runtime.rete.eval.OutputCachingEvaluatorNode$1.update(OutputCachingEvaluatorNode.java:148)
at org.eclipse.viatra.query.runtime.rete.eval.OutputCachingEvaluatorNode.update(OutputCachingEvaluatorNode.java:115)
at org.eclipse.viatra.query.runtime.rete.network.mailbox.timeless.BehaviorChangingMailbox.postMessage(BehaviorChangingMailbox.java:53)
at org.eclipse.viatra.query.runtime.rete.network.StandardNode.propagateUpdate(StandardNode.java:49)
at org.eclipse.viatra.query.runtime.rete.boundary.ExternalInputEnumeratorNode.update(ExternalInputEnumeratorNode.java:182)
at org.eclipse.viatra.query.runtime.rete.boundary.ExternalInputEnumeratorNode.update(ExternalInputEnumeratorNode.java:167)
at org.eclipse.viatra.query.runtime.emf.EMFQueryRuntimeContext$EStructuralFeatureInstancesKeyAdapter.featureInserted(EMFQueryRuntimeContext.java:745)
at org.eclipse.viatra.query.runtime.base.core.NavigationHelperImpl.notifyFeatureListeners(NavigationHelperImpl.java:701)
at org.eclipse.viatra.query.runtime.base.core.EMFBaseIndexInstanceStore.insertFeatureTuple(EMFBaseIndexInstanceStore.java:276)
at org.eclipse.viatra.query.runtime.base.core.NavigationHelperVisitor.visitAttribute(NavigationHelperVisitor.java:304)
at org.eclipse.viatra.query.runtime.base.comprehension.EMFModelComprehension.traverseFeatureInternal(EMFModelComprehension.java:268)
at org.eclipse.viatra.query.runtime.base.comprehension.EMFModelComprehension.traverseFeatureTargets(EMFModelComprehension.java:222)
at org.eclipse.viatra.query.runtime.base.comprehension.EMFModelComprehension.traverseObject(EMFModelComprehension.java:203)
at org.eclipse.viatra.query.runtime.base.comprehension.EMFModelComprehension.traverseObjectIfUnfiltered(EMFModelComprehension.java:188)
at org.eclipse.viatra.query.runtime.base.comprehension.EMFModelComprehension.traverseFeatureInternal(EMFModelComprehension.java:292)
at org.eclipse.viatra.query.runtime.base.comprehension.EMFModelComprehension.traverseFeatureTargets(EMFModelComprehension.java:217)
at org.eclipse.viatra.query.runtime.base.comprehension.EMFModelComprehension.traverseObject(EMFModelComprehension.java:203)
at org.eclipse.viatra.query.runtime.base.comprehension.EMFModelComprehension.traverseObjectIfUnfiltered(EMFModelComprehension.java:188)
at org.eclipse.viatra.query.runtime.base.comprehension.EMFModelComprehension.traverseResource(EMFModelComprehension.java:178)
at org.eclipse.viatra.query.runtime.base.comprehension.EMFModelComprehension.traverseModel(EMFModelComprehension.java:145)
at org.eclipse.viatra.query.runtime.base.core.NavigationHelperImpl.traverse(NavigationHelperImpl.java:1304)
at org.eclipse.viatra.query.runtime.base.core.NavigationHelperImpl$1.call(NavigationHelperImpl.java:1278)
at org.eclipse.viatra.query.runtime.base.core.NavigationHelperImpl.coalesceTraversals(NavigationHelperImpl.java:1152)
at org.eclipse.viatra.query.runtime.emf.EMFQueryRuntimeContext.coalesceTraversals(EMFQueryRuntimeContext.java:115)
at org.eclipse.viatra.query.runtime.rete.matcher.ReteEngine.constructionWrapper(ReteEngine.java:276)
at org.eclipse.viatra.query.runtime.rete.matcher.ReteEngine.accessMatcher(ReteEngine.java:229)
at org.eclipse.viatra.query.runtime.rete.matcher.ReteEngine.getResultProvider(ReteEngine.java:558)
at org.eclipse.viatra.query.runtime.internal.apiimpl.ViatraQueryEngineImpl.getResultProviderInternal(ViatraQueryEngineImpl.java:577)
at org.eclipse.viatra.query.runtime.internal.apiimpl.ViatraQueryEngineImpl.getResultProviderInternal(ViatraQueryEngineImpl.java:563)
at org.eclipse.viatra.query.runtime.internal.apiimpl.ViatraQueryEngineImpl.getResultProvider(ViatraQueryEngineImpl.java:552)
at org.eclipse.viatra.query.runtime.internal.apiimpl.ViatraQueryEngineImpl.getMatcher(ViatraQueryEngineImpl.java:219)
at org.eclipse.viatra.query.runtime.internal.apiimpl.ViatraQueryEngineImpl.getMatcher(ViatraQueryEngineImpl.java:204)
at viatra.pattern.transformation.ViatraGTEngine.setMatchers(ViatraGTEngine.java:215)
at viatra.pattern.transformation.ViatraGTEngine.monitor(ViatraGTEngine.java:203)
at viatra.pattern.transformation.ViatraGTEngine.main(ViatraGTEngine.java:304)

So i would like to ask you if you know a solution for the problem or maybe help me to understand how you create a XExpression for CheckConstraint?
Re: Create CheckConstraint [message #1821464 is a reply to message #1821457] Thu, 13 February 2020 12:40 Go to previous messageGo to next message
Zoltan Ujhelyi is currently offline Zoltan UjhelyiFriend
Messages: 392
Registered: July 2015
Senior Member
Hi Julian,

to be entirely honest, providing check expressions manually is really hard, the internal APIs are a bit hard to reuse. We usually either build the entire pattern from the textual syntax or work on a lower abstraction level, manually creating the PQuery structure where it is possible to add any Java code wrapped into IExpressionEvaluator instances. Neither solution is perfect - parsing the patterns is a bit more expensive, building PQuery instances manually results in validation rules are not executed (basically, you are expected to always provide well-formed query definitions using the API). Nonetheless, if either of these approaches work for you, I suggest going that way.

If not, I can only guess what is the error here. Most likely the problem with your case relies on some context not being set for the Xbase parser/interpreter - an expression like 'a < 0' would get to be translated to something like 'org.eclipse.xtext.xbase.lib.IntegerExtensions.operator_lessThan(a, 0)' - for that to work Xbase must know what is the type of the variable 'a'. To solve such issues with our Sirius-based graphical editor for graph patterns, we create a virtual pattern definition that has the minimum content necessary for the check/eval expression to compile and give that file to an embedded Xtext editor [1]. However, in this case we did not try to copy the XExpression to another resource or evaluate the created pattern so I am not sure whether such an approach would work for you.


Whichever direction you take, I have to warn you that we do not consider the EMF metamodel of the query language part of the API of VIATRA - in other words, it can change in future releases without warning. We make sure that the textual syntax remains compatible (a pattern written in the textual syntax will stay compatible with future VIATRA releases, but the same does not go for the internal EMF representation). Because of this reason, I'd like to ask your use case for building these EMF representations manually - I'd like to either understand what is missing from VIATRA or possibly suggest some alternative approach.

Best regards,
Zoltán

[1] https://git.eclipse.org/c/viatra/org.eclipse.viatra.git/tree/query/plugins/org.eclipse.viatra.query.patternlanguage.emf.sirius/src/org/eclipse/viatra/query/patternlanguage/emf/sirius/util/XtextEmbeddedEditor.java#n205
Re: Create CheckConstraint [message #1821684 is a reply to message #1821464] Tue, 18 February 2020 16:11 Go to previous messageGo to next message
Julian Barthel is currently offline Julian BarthelFriend
Messages: 6
Registered: November 2019
Location: Germany
Junior Member
Hi Zoltán,

thank you for your reply. I decided to go the way over the PatternParserBuilder, its a bit slower but it should fit to my purpose.

Best regards,
Julian
Re: Create CheckConstraint [message #1822247 is a reply to message #1821684] Mon, 02 March 2020 14:14 Go to previous messageGo to next message
Julian Barthel is currently offline Julian BarthelFriend
Messages: 6
Registered: November 2019
Location: Germany
Junior Member
Hi Zoltán,

i have another Question, when i am using the PatternParserBuilder with a Pattern which contains a check expressions with my own implemented method, i get an error that the function can not be resolved. When im using the exact same Pattern in an Vql-File, the method can be resolved and i get the expected matches. (the method is static and annotated with @pure).
Is it possible to use the PatternParserBuilder with patterns that contains check expressions with specific implemented methods?

Best regards,
Julian
Re: Create CheckConstraint [message #1822311 is a reply to message #1822247] Tue, 03 March 2020 18:26 Go to previous messageGo to next message
Zoltan Ujhelyi is currently offline Zoltan UjhelyiFriend
Messages: 392
Registered: July 2015
Senior Member
Hi Julian,

sadly it seems you have stumbled upon a missing feature (thanks for pointing it out for us). I have opened bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=560742 and already added a test case that illustrates the issue. I will need some more time to figure out what additional configuration is necessary to make this work, but I will report back if I know anything.

Thanks again,
Zoltán
Re: Create CheckConstraint [message #1822463 is a reply to message #1822311] Sat, 07 March 2020 15:21 Go to previous message
Zoltan Ujhelyi is currently offline Zoltan UjhelyiFriend
Messages: 392
Registered: July 2015
Senior Member
Hi Julian,

I have some good news and some bad news about your original.

The good news is that I have figured out what is the issue and how to solve it: you have set up a classloader as context for the XtextResourceSet that can load the types/static methods required by the pattern definitions (using XtextResourceSet#setClasspathURIContext method, see https://javadoc.io/static/org.eclipse.xtext/org.eclipse.xtext/2.21.0/org/eclipse/xtext/resource/XtextResourceSet.html#setClasspathURIContext-java.lang.Object-), and after that point, the class gets resolved. This is not required in simple Java applications as usually there every class is available from the same classloader or when accessing methods from the Java Standard Library as those are always available from the default classpath.

The problem is that the Pattern Parser API does not expose the underlying Xtext Resource Set by design, so there is no easy way to set it up in the current release. For the upcoming 2.4 version, I have added a new method to PatternParserBuilder to specify a custom classloader that can be used. For an example of how this could work, have a look at the Gerrit change https://git.eclipse.org/r/#/c/158759/2/query/tests/org.eclipse.viatra.query.patternlanguage.emf.tests/src/org/eclipse/viatra/query/patternlanguage/emf/tests/standalone/PatternParserTest.xtend - If this would not work for you, feel free to add your thoughts.

Pre-release builds with this change should be available next week (after we review it internally), and it should be part of the first milestone build for version 2.4 coming later in March as well.

Best regards,
Zoltán
Previous Topic:IExpressionEvaluator Questions
Next Topic:How to import Viatra via Maven
Goto Forum:
  


Current Time: Fri Apr 26 09:43:19 GMT 2024

Powered by FUDForum. Page generated in 0.03603 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top