Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZoltan Ujhelyi2018-10-16 13:49:09 +0000
committerZoltan Ujhelyi2018-10-16 14:09:43 +0000
commitd05566e2707ac727bfa6f88e2eb1c11b42399e33 (patch)
treebbe5fcef8568a2bf2665cc5704560a75f367e3c4
parent5d01a859492e5d55a06726fc521e330c363bf6e9 (diff)
downloadorg.eclipse.viatra-d05566e2707ac727bfa6f88e2eb1c11b42399e33.tar.gz
org.eclipse.viatra-d05566e2707ac727bfa6f88e2eb1c11b42399e33.tar.xz
org.eclipse.viatra-d05566e2707ac727bfa6f88e2eb1c11b42399e33.zip
[539915] Updates transformation rule builder typing
The rule builders used for batch and event-driven transformations required explicit match and matcher type declarations to work in Java, as the builder was defined before the query specification providing the type information was added. This posed no problem in Xtend, as the extended type inferring capabilities could forward the type information. This change provides an alternative rule builder that instead of loading the specification in the `precondition` method of the builder receives it during construction, thus providing the required type information in a way appropriate for Java sources as well. The test case includes a previously appropriate workaround as well (explicitly providing the type parameters of the built rule), but no fix is available yet, as it requires a big rewrite of the typing rules to avoid the necessity of these type parameters. Change-Id: Icdda8ea95de9e3230ec3bd2668fd4febe5ecc7bf Signed-off-by: Zoltan Ujhelyi <zoltan.ujhelyi@incquerylabs.com>
-rw-r--r--transformation/plugins/org.eclipse.viatra.transformation.runtime.emf/src/org/eclipse/viatra/transformation/runtime/emf/rules/batch/BatchTransformationRuleFactory.java15
-rw-r--r--transformation/plugins/org.eclipse.viatra.transformation.runtime.emf/src/org/eclipse/viatra/transformation/runtime/emf/rules/eventdriven/EventDrivenTransformationRuleFactory.java15
-rw-r--r--transformation/tests/org.eclipse.viatra.transformation.runtime.emf.tests/test/org/eclipse/viatra/transformation/evm/test/BatchTransformationWithFilterJava.java72
-rw-r--r--transformation/tests/org.eclipse.viatra.transformation.runtime.emf.tests/test/org/eclipse/viatra/transformation/evm/test/TransformationTest.java10
4 files changed, 112 insertions, 0 deletions
diff --git a/transformation/plugins/org.eclipse.viatra.transformation.runtime.emf/src/org/eclipse/viatra/transformation/runtime/emf/rules/batch/BatchTransformationRuleFactory.java b/transformation/plugins/org.eclipse.viatra.transformation.runtime.emf/src/org/eclipse/viatra/transformation/runtime/emf/rules/batch/BatchTransformationRuleFactory.java
index d6a9906e9..6e732c73f 100644
--- a/transformation/plugins/org.eclipse.viatra.transformation.runtime.emf/src/org/eclipse/viatra/transformation/runtime/emf/rules/batch/BatchTransformationRuleFactory.java
+++ b/transformation/plugins/org.eclipse.viatra.transformation.runtime.emf/src/org/eclipse/viatra/transformation/runtime/emf/rules/batch/BatchTransformationRuleFactory.java
@@ -26,6 +26,15 @@ public class BatchTransformationRuleFactory {
private String fName = "";
private EventFilter<Match> fFilter;
+ public BatchTransformationRuleBuilder() {}
+
+ /**
+ * @since 2.1
+ */
+ public BatchTransformationRuleBuilder(IQuerySpecification<Matcher> precondition) {
+ fPrecondition = precondition;
+ }
+
/**
* Sets the user-understandable name of the rule. Should be unique if set.
*/
@@ -85,4 +94,10 @@ public class BatchTransformationRuleFactory {
return new BatchTransformationRuleBuilder<>();
}
+ /**
+ * @since 2.1
+ */
+ public <Match extends IPatternMatch, Matcher extends ViatraQueryMatcher<Match>> BatchTransformationRuleBuilder<Match, Matcher> createRule(IQuerySpecification<Matcher> precondition) {
+ return new BatchTransformationRuleBuilder<>(precondition);
+ }
}
diff --git a/transformation/plugins/org.eclipse.viatra.transformation.runtime.emf/src/org/eclipse/viatra/transformation/runtime/emf/rules/eventdriven/EventDrivenTransformationRuleFactory.java b/transformation/plugins/org.eclipse.viatra.transformation.runtime.emf/src/org/eclipse/viatra/transformation/runtime/emf/rules/eventdriven/EventDrivenTransformationRuleFactory.java
index 4abf0b363..05ebecf7f 100644
--- a/transformation/plugins/org.eclipse.viatra.transformation.runtime.emf/src/org/eclipse/viatra/transformation/runtime/emf/rules/eventdriven/EventDrivenTransformationRuleFactory.java
+++ b/transformation/plugins/org.eclipse.viatra.transformation.runtime.emf/src/org/eclipse/viatra/transformation/runtime/emf/rules/eventdriven/EventDrivenTransformationRuleFactory.java
@@ -37,6 +37,14 @@ public class EventDrivenTransformationRuleFactory {
private boolean isDeleteJobAdded = false;
private ActivationLifeCycle lifeCycle = null;
+ public EventDrivenTransformationRuleBuilder() {}
+
+ /**
+ * @since 2.1
+ */
+ public EventDrivenTransformationRuleBuilder(IQuerySpecification<Matcher> precondition) {
+ this.precondition = precondition;
+ }
public EventDrivenTransformationRuleBuilder<Match, Matcher> name(String name) {
this.name = name;
@@ -110,6 +118,13 @@ public class EventDrivenTransformationRuleFactory {
return new EventDrivenTransformationRuleBuilder<Match, Matcher>();
}
+ /**
+ * @since 2.1
+ */
+ public <Match extends IPatternMatch, Matcher extends ViatraQueryMatcher<Match>> EventDrivenTransformationRuleBuilder<Match, Matcher> createRule(IQuerySpecification<Matcher> precondition) {
+ return new EventDrivenTransformationRuleBuilder<Match, Matcher>(precondition);
+ }
+
private <Match extends IPatternMatch, Matcher extends ViatraQueryMatcher<Match>> EventDrivenTransformationRule<Match, Matcher> createRule(
String name, IQuerySpecification<Matcher> precondition,
Map<CRUDActivationStateEnum, Consumer<Match>> stateActions, ActivationLifeCycle lifeCycle,
diff --git a/transformation/tests/org.eclipse.viatra.transformation.runtime.emf.tests/test/org/eclipse/viatra/transformation/evm/test/BatchTransformationWithFilterJava.java b/transformation/tests/org.eclipse.viatra.transformation.runtime.emf.tests/test/org/eclipse/viatra/transformation/evm/test/BatchTransformationWithFilterJava.java
new file mode 100644
index 000000000..4992c3947
--- /dev/null
+++ b/transformation/tests/org.eclipse.viatra.transformation.runtime.emf.tests/test/org/eclipse/viatra/transformation/evm/test/BatchTransformationWithFilterJava.java
@@ -0,0 +1,72 @@
+/*******************************************************************************
+ * Copyright (c) 2010-2018, Zoltan Ujhelyi, IncQuery Labs Ltd.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Zoltan Ujhelyi - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.viatra.transformation.evm.test;
+
+import java.util.Collections;
+
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine;
+import org.eclipse.viatra.query.runtime.emf.EMFScope;
+import org.eclipse.viatra.transformation.runtime.emf.rules.batch.BatchTransformationRule;
+import org.eclipse.viatra.transformation.runtime.emf.rules.batch.BatchTransformationRuleFactory;
+import org.eclipse.viatra.transformation.runtime.emf.transformation.batch.BatchTransformation;
+import org.eclipse.viatra.transformation.runtime.emf.transformation.batch.BatchTransformationStatements;
+import org.eclipse.viatra.query.runtime.cps.tests.queries.HostInstanceMatch;
+import org.eclipse.viatra.query.runtime.cps.tests.queries.HostInstanceMatcher;
+import org.eclipse.viatra.query.runtime.cps.tests.queries.util.HostInstanceQuerySpecification;
+import org.eclipse.viatra.examples.cps.cyberPhysicalSystem.HostInstance;
+import org.eclipse.viatra.transformation.runtime.emf.filters.MatchParameterFilter;
+
+public class BatchTransformationWithFilterJava {
+
+ private BatchTransformation transformation;
+ private BatchTransformationStatements statements;
+
+ private BatchTransformationRuleFactory factory = new BatchTransformationRuleFactory();
+
+ private int counter = 0;
+
+ private BatchTransformationRule<HostInstanceMatch, HostInstanceMatcher> typeInferredRule = factory
+ .createRule(HostInstanceQuerySpecification.instance())
+ .name("CounterRule")
+ .action(m -> counter++)
+ .build();
+
+ private BatchTransformationRule<HostInstanceMatch, HostInstanceMatcher> castTypedRule = factory
+ .<HostInstanceMatch, HostInstanceMatcher>createRule()
+ .name("CounterRule")
+ .precondition(HostInstanceQuerySpecification.instance())
+ .action(m -> counter++)
+ .build();
+
+ public BatchTransformationWithFilterJava(Resource resource) {
+ EMFScope scope = new EMFScope(resource);
+ ViatraQueryEngine engine = ViatraQueryEngine.on(scope);
+
+ transformation = BatchTransformation.forEngine(engine).build();
+ statements = transformation.getTransformationStatements();
+ }
+
+ public int callTypeInferredRule(HostInstance instance) {
+ counter = 0;
+ final MatchParameterFilter filter = new MatchParameterFilter(Collections.singletonMap("host", instance));
+ statements.fireAllCurrent(typeInferredRule, filter);
+ return counter;
+ }
+
+ public int callCastTypeRule(HostInstance instance) {
+ counter = 0;
+ final MatchParameterFilter filter = new MatchParameterFilter(Collections.singletonMap("host", instance));
+ statements.fireAllCurrent(castTypedRule, filter);
+ return counter;
+ }
+
+}
diff --git a/transformation/tests/org.eclipse.viatra.transformation.runtime.emf.tests/test/org/eclipse/viatra/transformation/evm/test/TransformationTest.java b/transformation/tests/org.eclipse.viatra.transformation.runtime.emf.tests/test/org/eclipse/viatra/transformation/evm/test/TransformationTest.java
index 0963e5044..a6cfac6e0 100644
--- a/transformation/tests/org.eclipse.viatra.transformation.runtime.emf.tests/test/org/eclipse/viatra/transformation/evm/test/TransformationTest.java
+++ b/transformation/tests/org.eclipse.viatra.transformation.runtime.emf.tests/test/org/eclipse/viatra/transformation/evm/test/TransformationTest.java
@@ -43,4 +43,14 @@ public class TransformationTest {
Assert.assertEquals(1, new BatchTransformationWithFilter(resource).countMatches(instance));
}
+
+ @Test
+ public void javaBasedTransformationTest() {
+ ResourceSet rs = new ResourceSetImpl();
+ Resource resource = rs.getResource(URI.createPlatformPluginURI("org.eclipse.viatra.query.runtime.cps.tests/models/instances/demo.cyberphysicalsystem", true), true);
+ HostInstance instance = (HostInstance) resource.getEObject("simple.cps.host.FirstHostClass0.inst0");
+
+ Assert.assertEquals(1, new BatchTransformationWithFilterJava(resource).callCastTypeRule(instance));
+ Assert.assertEquals(1, new BatchTransformationWithFilterJava(resource).callTypeInferredRule(instance));
+ }
}

Back to the top