| /** |
| * |
| * Copyright (c) 2010-2015, Andras Szabolcs Nagy, Abel Hegedus, Akos Horvath, Zoltan Ujhelyi and Daniel Varro |
| * 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: |
| * Andras Szabolcs Nagy - initial API and implementation |
| * |
| */ |
| package org.eclipse.viatra.dse.examples.bpmn.patterns.util; |
| |
| import com.google.common.collect.Sets; |
| import java.util.Arrays; |
| import java.util.Collections; |
| import java.util.List; |
| import java.util.Set; |
| import org.eclipse.emf.ecore.EClass; |
| import org.eclipse.viatra.dse.examples.bpmn.patterns.TaskOrderMatch; |
| import org.eclipse.viatra.dse.examples.bpmn.patterns.TaskOrderMatcher; |
| import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; |
| import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; |
| import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification; |
| import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; |
| import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey; |
| import org.eclipse.viatra.query.runtime.exception.ViatraQueryException; |
| import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; |
| import org.eclipse.viatra.query.runtime.matchers.psystem.IExpressionEvaluator; |
| import org.eclipse.viatra.query.runtime.matchers.psystem.IValueProvider; |
| import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; |
| import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; |
| import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality; |
| import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; |
| import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExpressionEvaluation; |
| import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; |
| import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; |
| import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; |
| import org.eclipse.viatra.query.runtime.matchers.psystem.queries.QueryInitializationException; |
| import org.eclipse.viatra.query.runtime.matchers.tuple.FlatTuple; |
| |
| /** |
| * A pattern-specific query specification that can instantiate TaskOrderMatcher in a type-safe way. |
| * |
| * @see TaskOrderMatcher |
| * @see TaskOrderMatch |
| * |
| */ |
| @SuppressWarnings("all") |
| public final class TaskOrderQuerySpecification extends BaseGeneratedEMFQuerySpecification<TaskOrderMatcher> { |
| private TaskOrderQuerySpecification() { |
| super(GeneratedPQuery.INSTANCE); |
| } |
| |
| /** |
| * @return the singleton instance of the query specification |
| * @throws ViatraQueryException if the pattern definition could not be loaded |
| * |
| */ |
| public static TaskOrderQuerySpecification instance() throws ViatraQueryException { |
| try{ |
| return LazyHolder.INSTANCE; |
| } catch (ExceptionInInitializerError err) { |
| throw processInitializerError(err); |
| } |
| } |
| |
| @Override |
| protected TaskOrderMatcher instantiate(final ViatraQueryEngine engine) throws ViatraQueryException { |
| return TaskOrderMatcher.on(engine); |
| } |
| |
| @Override |
| public TaskOrderMatcher instantiate() throws ViatraQueryException { |
| return TaskOrderMatcher.create(); |
| } |
| |
| @Override |
| public TaskOrderMatch newEmptyMatch() { |
| return TaskOrderMatch.newEmptyMatch(); |
| } |
| |
| @Override |
| public TaskOrderMatch newMatch(final Object... parameters) { |
| return TaskOrderMatch.newMatch((org.eclipse.viatra.dse.examples.simplifiedbpmn.Task) parameters[0], (org.eclipse.viatra.dse.examples.simplifiedbpmn.Task) parameters[1]); |
| } |
| |
| /** |
| * Inner class allowing the singleton instance of {@link TaskOrderQuerySpecification} to be created |
| * <b>not</b> at the class load time of the outer class, |
| * but rather at the first call to {@link TaskOrderQuerySpecification#instance()}. |
| * |
| * <p> This workaround is required e.g. to support recursion. |
| * |
| */ |
| private static class LazyHolder { |
| private final static TaskOrderQuerySpecification INSTANCE = new TaskOrderQuerySpecification(); |
| |
| /** |
| * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned. |
| * This initialization order is required to support indirect recursion. |
| * |
| * <p> The static initializer is defined using a helper field to work around limitations of the code generator. |
| * |
| */ |
| private final static Object STATIC_INITIALIZER = ensureInitialized(); |
| |
| public static Object ensureInitialized() { |
| INSTANCE.ensureInitializedInternalSneaky(); |
| return null; |
| } |
| } |
| |
| private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { |
| private final static TaskOrderQuerySpecification.GeneratedPQuery INSTANCE = new GeneratedPQuery(); |
| |
| private final PParameter parameter_pT1 = new PParameter("T1", "org.eclipse.viatra.dse.examples.simplifiedbpmn.Task", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("org.eclipse.viatra.dse.examples.bpmn", "Task")), PParameterDirection.INOUT); |
| |
| private final PParameter parameter_pT2 = new PParameter("T2", "org.eclipse.viatra.dse.examples.simplifiedbpmn.Task", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("org.eclipse.viatra.dse.examples.bpmn", "Task")), PParameterDirection.INOUT); |
| |
| private final List<PParameter> parameters = Arrays.asList(parameter_pT1, parameter_pT2); |
| |
| @Override |
| public String getFullyQualifiedName() { |
| return "org.eclipse.viatra.dse.examples.bpmn.patterns.taskOrder"; |
| } |
| |
| @Override |
| public List<String> getParameterNames() { |
| return Arrays.asList("T1","T2"); |
| } |
| |
| @Override |
| public List<PParameter> getParameters() { |
| return parameters; |
| } |
| |
| @Override |
| public Set<PBody> doGetContainedBodies() throws QueryInitializationException { |
| setEvaluationHints(new QueryEvaluationHint(null, Collections.<String,Object>emptyMap())); |
| Set<PBody> bodies = Sets.newLinkedHashSet(); |
| try { |
| { |
| PBody body = new PBody(this); |
| PVariable var_T1 = body.getOrCreateVariableByName("T1"); |
| PVariable var_T2 = body.getOrCreateVariableByName("T2"); |
| PVariable var_name1 = body.getOrCreateVariableByName("name1"); |
| PVariable var_name2 = body.getOrCreateVariableByName("name2"); |
| new TypeConstraint(body, new FlatTuple(var_T1), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("org.eclipse.viatra.dse.examples.bpmn", "Task"))); |
| new TypeConstraint(body, new FlatTuple(var_T2), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("org.eclipse.viatra.dse.examples.bpmn", "Task"))); |
| body.setSymbolicParameters(Arrays.<ExportedParameter>asList( |
| new ExportedParameter(body, var_T1, parameter_pT1), |
| new ExportedParameter(body, var_T2, parameter_pT2) |
| )); |
| // Task.name(T1,name1) |
| new TypeConstraint(body, new FlatTuple(var_T1), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("org.eclipse.viatra.dse.examples.bpmn", "Task"))); |
| PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); |
| new TypeConstraint(body, new FlatTuple(var_T1, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("org.eclipse.viatra.dse.examples.bpmn", "NamedElement", "name"))); |
| new Equality(body, var__virtual_0_, var_name1); |
| // Task.name(T2,name2) |
| new TypeConstraint(body, new FlatTuple(var_T2), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("org.eclipse.viatra.dse.examples.bpmn", "Task"))); |
| PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}"); |
| new TypeConstraint(body, new FlatTuple(var_T2, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("org.eclipse.viatra.dse.examples.bpmn", "NamedElement", "name"))); |
| new Equality(body, var__virtual_1_, var_name2); |
| // check(name1 > name2) |
| new ExpressionEvaluation(body, new IExpressionEvaluator() { |
| |
| @Override |
| public String getShortDescription() { |
| return "Expression evaluation from pattern taskOrder"; |
| } |
| |
| @Override |
| public Iterable<String> getInputParameterNames() { |
| return Arrays.asList("name1", "name2");} |
| |
| @Override |
| public Object evaluateExpression(IValueProvider provider) throws Exception { |
| String name1 = (String) provider.getValue("name1"); |
| String name2 = (String) provider.getValue("name2"); |
| return evaluateExpression_1_1(name1, name2); |
| } |
| }, null); |
| bodies.add(body); |
| } |
| // to silence compiler error |
| if (false) throw new ViatraQueryException("Never", "happens"); |
| } catch (ViatraQueryException ex) { |
| throw processDependencyException(ex); |
| } |
| return bodies; |
| } |
| } |
| |
| private static boolean evaluateExpression_1_1(final String name1, final String name2) { |
| boolean _greaterThan = (name1.compareTo(name2) > 0); |
| return _greaterThan; |
| } |
| } |