diff --git a/com.incquerylabs.magicdraw.benchmark/.gitignore b/com.incquerylabs.magicdraw.benchmark/.gitignore index 3c9acd5..098d82a 100644 --- a/com.incquerylabs.magicdraw.benchmark/.gitignore +++ b/com.incquerylabs.magicdraw.benchmark/.gitignore @@ -2,3 +2,4 @@ /target/ /build/ /.gradle/ +/src/generated/vql \ No newline at end of file diff --git a/com.incquerylabs.magicdraw.benchmark/.settings/org.eclipse.viatra.query.patternlanguage.emf.EMFPatternLanguage.prefs b/com.incquerylabs.magicdraw.benchmark/.settings/org.eclipse.viatra.query.patternlanguage.emf.EMFPatternLanguage.prefs index d42f248..277afa8 100644 --- a/com.incquerylabs.magicdraw.benchmark/.settings/org.eclipse.viatra.query.patternlanguage.emf.EMFPatternLanguage.prefs +++ b/com.incquerylabs.magicdraw.benchmark/.settings/org.eclipse.viatra.query.patternlanguage.emf.EMFPatternLanguage.prefs @@ -1,5 +1,5 @@ BuilderConfiguration.is_project_specific=true -autobuilding=true +autobuilding=false eclipse.preferences.version=1 generateEclipseExtensions=false generateGeneratedAnnotation=false @@ -9,6 +9,7 @@ generateMatchers=NESTED_CLASS generateSuppressWarnings=true generatedAnnotationComment= includeDateInGenerated=false +org.eclipse.viatra.query.patternlanguage.emf.EMFPatternLanguage.useProjectSettings=true outlet.DEFAULT_OUTPUT.cleanDirectory=false outlet.DEFAULT_OUTPUT.cleanupDerived=false outlet.DEFAULT_OUTPUT.createDirectory=true @@ -27,4 +28,3 @@ outlet.DEFAULT_OUTPUT.sourceFolder.xtend-gen.ignore= outlet.DEFAULT_OUTPUT.userOutputPerSourceFolder= targetJavaVersion=JAVA5 useJavaCompilerCompliance=true - diff --git a/com.incquerylabs.magicdraw.benchmark/build.gradle b/com.incquerylabs.magicdraw.benchmark/build.gradle index f76949e..9f27e36 100644 --- a/com.incquerylabs.magicdraw.benchmark/build.gradle +++ b/com.incquerylabs.magicdraw.benchmark/build.gradle @@ -5,6 +5,7 @@ import java.util.zip.ZipFile plugins { id "org.xtext.xtend" version "2.0.2" + id "viatra-gradle-plugin" version "2.5.0-SNAPSHOT" } xtext.version = xtextVersion @@ -29,6 +30,12 @@ String[] classpathLibraries = [ // Apply the java-library plugin to add support for Java Library +vql { + packageClassNames('com.nomagic.uml2.ext.magicdraw.metadata.UMLPackage') + inputDirectory.set(file('src/main/java')) + outputDirectory.set(file('src/generated/vql')) +} + apply plugin: 'eclipse' apply plugin: 'idea' apply plugin: 'java' diff --git a/com.incquerylabs.magicdraw.benchmark/gradle/wrapper/gradle-wrapper.jar b/com.incquerylabs.magicdraw.benchmark/gradle/wrapper/gradle-wrapper.jar index 27768f1..5c2d1cf 100644 Binary files a/com.incquerylabs.magicdraw.benchmark/gradle/wrapper/gradle-wrapper.jar and b/com.incquerylabs.magicdraw.benchmark/gradle/wrapper/gradle-wrapper.jar differ diff --git a/com.incquerylabs.magicdraw.benchmark/gradle/wrapper/gradle-wrapper.properties b/com.incquerylabs.magicdraw.benchmark/gradle/wrapper/gradle-wrapper.properties index b33419d..be52383 100644 --- a/com.incquerylabs.magicdraw.benchmark/gradle/wrapper/gradle-wrapper.properties +++ b/com.incquerylabs.magicdraw.benchmark/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.5.1-bin.zip diff --git a/com.incquerylabs.magicdraw.benchmark/gradlew b/com.incquerylabs.magicdraw.benchmark/gradlew index cccdd3d..8e25e6c 100755 --- a/com.incquerylabs.magicdraw.benchmark/gradlew +++ b/com.incquerylabs.magicdraw.benchmark/gradlew @@ -1,5 +1,21 @@ #!/usr/bin/env sh +# +# Copyright 2015 the original author or authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + ############################################################################## ## ## Gradle start up script for UN*X @@ -28,7 +44,7 @@ APP_NAME="Gradle" APP_BASE_NAME=`basename "$0"` # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS="" +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD="maximum" diff --git a/com.incquerylabs.magicdraw.benchmark/gradlew.bat b/com.incquerylabs.magicdraw.benchmark/gradlew.bat index f955316..9618d8d 100644 --- a/com.incquerylabs.magicdraw.benchmark/gradlew.bat +++ b/com.incquerylabs.magicdraw.benchmark/gradlew.bat @@ -1,3 +1,19 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + @if "%DEBUG%" == "" @echo off @rem ########################################################################## @rem @@ -14,7 +30,7 @@ set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS= +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" @rem Find java.exe if defined JAVA_HOME goto findJavaFromJavaHome diff --git a/com.incquerylabs.magicdraw.benchmark/settings.gradle b/com.incquerylabs.magicdraw.benchmark/settings.gradle index f7265b1..4e5cfeb 100644 --- a/com.incquerylabs.magicdraw.benchmark/settings.gradle +++ b/com.incquerylabs.magicdraw.benchmark/settings.gradle @@ -1,18 +1,19 @@ -/* - * This settings file was generated by the Gradle 'init' task. - * - * The settings file is used to specify which projects to include in your build. - * In a single project build this file can be empty or even removed. - * - * Detailed information about configuring a multi-project build in Gradle can be found - * in the user guide at https://docs.gradle.org/4.3/userguide/multi_project_builds.html - */ - -/* -// To declare projects as part of a multi-project build use the 'include' method -include 'shared' -include 'api' -include 'services:webservice' -*/ +pluginManagement { + repositories { + gradlePluginPortal() + mavenCentral() + maven { + url("https://repo.eclipse.org/content/groups/viatra/") + } + maven { + url "https://build.incquerylabs.com/nexus/repository/gradle-plugins" + credentials { + username = "$nexusUsername" + password = "$nexusPassword" + } + } + mavenLocal() + } +} rootProject.name = 'com.incquerylabs.magicdraw.benchmark' diff --git a/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/incrementalqueries/.ParentState.java._trace b/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/incrementalqueries/.ParentState.java._trace deleted file mode 100644 index 121bc05..0000000 Binary files a/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/incrementalqueries/.ParentState.java._trace and /dev/null differ diff --git a/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/incrementalqueries/.TransitiveSubstatesWithCheck.java._trace b/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/incrementalqueries/.TransitiveSubstatesWithCheck.java._trace deleted file mode 100644 index 63a529f..0000000 Binary files a/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/incrementalqueries/.TransitiveSubstatesWithCheck.java._trace and /dev/null differ diff --git a/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/incrementalqueries/.gitignore b/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/incrementalqueries/.gitignore deleted file mode 100644 index 4a5335e..0000000 --- a/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/incrementalqueries/.gitignore +++ /dev/null @@ -1 +0,0 @@ -*._trace \ No newline at end of file diff --git a/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/incrementalqueries/IncrementalQueries.java b/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/incrementalqueries/IncrementalQueries.java deleted file mode 100644 index 01a153c..0000000 --- a/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/incrementalqueries/IncrementalQueries.java +++ /dev/null @@ -1,86 +0,0 @@ -/** - * Generated from platform:/resource/com.incquerylabs.magicdraw.benchmark/src/main/java/com/incquerylabs/magicdraw/benchmark/incrementalqueries/IncrementalQueries.vql - */ -package com.incquerylabs.magicdraw.benchmark.incrementalqueries; - -import com.incquerylabs.magicdraw.benchmark.incrementalqueries.ParentState; -import com.incquerylabs.magicdraw.benchmark.incrementalqueries.TransitiveSubstatesWithCheck; -import com.incquerylabs.magicdraw.benchmark.incrementalqueries.TransitiveSubstatesWithCheck2; -import com.incquerylabs.magicdraw.benchmark.incrementalqueries.TransitiveSubstatesWithCheck3; -import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; -import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedPatternGroup; - -/** - * A pattern group formed of all public patterns defined in IncrementalQueries.vql. - * - *

Use the static instance as any {@link interface org.eclipse.viatra.query.runtime.api.IQueryGroup}, to conveniently prepare - * a VIATRA Query engine for matching all patterns originally defined in file IncrementalQueries.vql, - * in order to achieve better performance than one-by-one on-demand matcher initialization. - * - *

From package com.incquerylabs.magicdraw.benchmark.incrementalqueries, the group contains the definition of the following patterns:

- * - * @see IQueryGroup - * - */ -@SuppressWarnings("all") -public final class IncrementalQueries extends BaseGeneratedPatternGroup { - /** - * Access the pattern group. - * - * @return the singleton instance of the group - * @throws ViatraQueryRuntimeException if there was an error loading the generated code of pattern specifications - * - */ - public static IncrementalQueries instance() { - if (INSTANCE == null) { - INSTANCE = new IncrementalQueries(); - } - return INSTANCE; - } - - private static IncrementalQueries INSTANCE; - - private IncrementalQueries() { - querySpecifications.add(ParentState.instance()); - querySpecifications.add(TransitiveSubstatesWithCheck.instance()); - querySpecifications.add(TransitiveSubstatesWithCheck2.instance()); - querySpecifications.add(TransitiveSubstatesWithCheck3.instance()); - } - - public ParentState getParentState() { - return ParentState.instance(); - } - - public ParentState.Matcher getParentState(final ViatraQueryEngine engine) { - return ParentState.Matcher.on(engine); - } - - public TransitiveSubstatesWithCheck getTransitiveSubstatesWithCheck() { - return TransitiveSubstatesWithCheck.instance(); - } - - public TransitiveSubstatesWithCheck.Matcher getTransitiveSubstatesWithCheck(final ViatraQueryEngine engine) { - return TransitiveSubstatesWithCheck.Matcher.on(engine); - } - - public TransitiveSubstatesWithCheck2 getTransitiveSubstatesWithCheck2() { - return TransitiveSubstatesWithCheck2.instance(); - } - - public TransitiveSubstatesWithCheck2.Matcher getTransitiveSubstatesWithCheck2(final ViatraQueryEngine engine) { - return TransitiveSubstatesWithCheck2.Matcher.on(engine); - } - - public TransitiveSubstatesWithCheck3 getTransitiveSubstatesWithCheck3() { - return TransitiveSubstatesWithCheck3.instance(); - } - - public TransitiveSubstatesWithCheck3.Matcher getTransitiveSubstatesWithCheck3(final ViatraQueryEngine engine) { - return TransitiveSubstatesWithCheck3.Matcher.on(engine); - } -} diff --git a/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/incrementalqueries/ParentState.java b/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/incrementalqueries/ParentState.java deleted file mode 100644 index d3e0e76..0000000 --- a/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/incrementalqueries/ParentState.java +++ /dev/null @@ -1,717 +0,0 @@ -/** - * Generated from platform:/resource/com.incquerylabs.magicdraw.benchmark/src/main/java/com/incquerylabs/magicdraw/benchmark/incrementalqueries/IncrementalQueries.vql - */ -package com.incquerylabs.magicdraw.benchmark.incrementalqueries; - -import com.nomagic.uml2.ext.magicdraw.statemachines.mdbehaviorstatemachines.State; -import java.util.Arrays; -import java.util.Collection; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.function.Consumer; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import org.apache.log4j.Logger; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.viatra.query.runtime.api.IPatternMatch; -import org.eclipse.viatra.query.runtime.api.IQuerySpecification; -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.api.impl.BaseMatcher; -import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; -import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; -import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey; -import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; -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.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.PVisibility; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; -import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; - -/** - * A pattern-specific query specification that can instantiate Matcher in a type-safe way. - * - *

Original source: - *

- *         Simple pattern for transitive closures marked incremental.
- *          
- *         incremental pattern parentState(state : State, parentState : State) {
- *         	State.region(parentState, subregion);
- *         	Region.subvertex(subregion, state);
- *         }
- * 
- * - * @see Matcher - * @see Match - * - */ -@SuppressWarnings("all") -public final class ParentState extends BaseGeneratedEMFQuerySpecification { - /** - * Pattern-specific match representation of the com.incquerylabs.magicdraw.benchmark.incrementalqueries.parentState pattern, - * to be used in conjunction with {@link Matcher}. - * - *

Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. - * Each instance is a (possibly partial) substitution of pattern parameters, - * usable to represent a match of the pattern in the result of a query, - * or to specify the bound (fixed) input parameters when issuing a query. - * - * @see Matcher - * - */ - public static abstract class Match extends BasePatternMatch { - private State fState; - - private State fParentState; - - private static List parameterNames = makeImmutableList("state", "parentState"); - - private Match(final State pState, final State pParentState) { - this.fState = pState; - this.fParentState = pParentState; - } - - @Override - public Object get(final String parameterName) { - switch(parameterName) { - case "state": return this.fState; - case "parentState": return this.fParentState; - default: return null; - } - } - - @Override - public Object get(final int index) { - switch(index) { - case 0: return this.fState; - case 1: return this.fParentState; - default: return null; - } - } - - public State getState() { - return this.fState; - } - - public State getParentState() { - return this.fParentState; - } - - @Override - public boolean set(final String parameterName, final Object newValue) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - if ("state".equals(parameterName) ) { - this.fState = (State) newValue; - return true; - } - if ("parentState".equals(parameterName) ) { - this.fParentState = (State) newValue; - return true; - } - return false; - } - - public void setState(final State pState) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fState = pState; - } - - public void setParentState(final State pParentState) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fParentState = pParentState; - } - - @Override - public String patternName() { - return "com.incquerylabs.magicdraw.benchmark.incrementalqueries.parentState"; - } - - @Override - public List parameterNames() { - return ParentState.Match.parameterNames; - } - - @Override - public Object[] toArray() { - return new Object[]{fState, fParentState}; - } - - @Override - public ParentState.Match toImmutable() { - return isMutable() ? newMatch(fState, fParentState) : this; - } - - @Override - public String prettyPrint() { - StringBuilder result = new StringBuilder(); - result.append("\"state\"=" + prettyPrintValue(fState) + ", "); - result.append("\"parentState\"=" + prettyPrintValue(fParentState)); - return result.toString(); - } - - @Override - public int hashCode() { - return Objects.hash(fState, fParentState); - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) - return true; - if (obj == null) { - return false; - } - if ((obj instanceof ParentState.Match)) { - ParentState.Match other = (ParentState.Match) obj; - return Objects.equals(fState, other.fState) && Objects.equals(fParentState, other.fParentState); - } else { - // this should be infrequent - if (!(obj instanceof IPatternMatch)) { - return false; - } - IPatternMatch otherSig = (IPatternMatch) obj; - return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); - } - } - - @Override - public ParentState specification() { - return ParentState.instance(); - } - - /** - * Returns an empty, mutable match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @return the empty match. - * - */ - public static ParentState.Match newEmptyMatch() { - return new Mutable(null, null); - } - - /** - * Returns a mutable (partial) match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pParentState the fixed value of pattern parameter parentState, or null if not bound. - * @return the new, mutable (partial) match object. - * - */ - public static ParentState.Match newMutableMatch(final State pState, final State pParentState) { - return new Mutable(pState, pParentState); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pParentState the fixed value of pattern parameter parentState, or null if not bound. - * @return the (partial) match object. - * - */ - public static ParentState.Match newMatch(final State pState, final State pParentState) { - return new Immutable(pState, pParentState); - } - - private static final class Mutable extends ParentState.Match { - Mutable(final State pState, final State pParentState) { - super(pState, pParentState); - } - - @Override - public boolean isMutable() { - return true; - } - } - - private static final class Immutable extends ParentState.Match { - Immutable(final State pState, final State pParentState) { - super(pState, pParentState); - } - - @Override - public boolean isMutable() { - return false; - } - } - } - - /** - * Generated pattern matcher API of the com.incquerylabs.magicdraw.benchmark.incrementalqueries.parentState pattern, - * providing pattern-specific query methods. - * - *

Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, - * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. - * - *

Matches of the pattern will be represented as {@link Match}. - * - *

Original source: - *

-   * Simple pattern for transitive closures marked incremental.
-   *  
-   * incremental pattern parentState(state : State, parentState : State) {
-   * 	State.region(parentState, subregion);
-   * 	Region.subvertex(subregion, state);
-   * }
-   * 
- * - * @see Match - * @see ParentState - * - */ - public static class Matcher extends BaseMatcher { - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - public static ParentState.Matcher on(final ViatraQueryEngine engine) { - // check if matcher already exists - Matcher matcher = engine.getExistingMatcher(querySpecification()); - if (matcher == null) { - matcher = (Matcher)engine.getMatcher(querySpecification()); - } - return matcher; - } - - /** - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * @return an initialized matcher - * @noreference This method is for internal matcher initialization by the framework, do not call it manually. - * - */ - public static ParentState.Matcher create() { - return new Matcher(); - } - - private static final int POSITION_STATE = 0; - - private static final int POSITION_PARENTSTATE = 1; - - private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(ParentState.Matcher.class); - - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - private Matcher() { - super(querySpecification()); - } - - /** - * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pParentState the fixed value of pattern parameter parentState, or null if not bound. - * @return matches represented as a Match object. - * - */ - public Collection getAllMatches(final State pState, final State pParentState) { - return rawStreamAllMatches(new Object[]{pState, pParentState}).collect(Collectors.toSet()); - } - - /** - * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pParentState the fixed value of pattern parameter parentState, or null if not bound. - * @return a stream of matches represented as a Match object. - * - */ - public Stream streamAllMatches(final State pState, final State pParentState) { - return rawStreamAllMatches(new Object[]{pState, pParentState}); - } - - /** - * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pParentState the fixed value of pattern parameter parentState, or null if not bound. - * @return a match represented as a Match object, or null if no match is found. - * - */ - public Optional getOneArbitraryMatch(final State pState, final State pParentState) { - return rawGetOneArbitraryMatch(new Object[]{pState, pParentState}); - } - - /** - * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, - * under any possible substitution of the unspecified parameters (if any). - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pParentState the fixed value of pattern parameter parentState, or null if not bound. - * @return true if the input is a valid (partial) match of the pattern. - * - */ - public boolean hasMatch(final State pState, final State pParentState) { - return rawHasMatch(new Object[]{pState, pParentState}); - } - - /** - * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pParentState the fixed value of pattern parameter parentState, or null if not bound. - * @return the number of pattern matches found. - * - */ - public int countMatches(final State pState, final State pParentState) { - return rawCountMatches(new Object[]{pState, pParentState}); - } - - /** - * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pParentState the fixed value of pattern parameter parentState, or null if not bound. - * @param processor the action that will process the selected match. - * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked - * - */ - public boolean forOneArbitraryMatch(final State pState, final State pParentState, final Consumer processor) { - return rawForOneArbitraryMatch(new Object[]{pState, pParentState}, processor); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pParentState the fixed value of pattern parameter parentState, or null if not bound. - * @return the (partial) match object. - * - */ - public ParentState.Match newMatch(final State pState, final State pParentState) { - return ParentState.Match.newMatch(pState, pParentState); - } - - /** - * Retrieve the set of values that occur in matches for state. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOfstate(final Object[] parameters) { - return rawStreamAllValues(POSITION_STATE, parameters).map(State.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for state. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfstate() { - return rawStreamAllValuesOfstate(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for state. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfstate() { - return rawStreamAllValuesOfstate(emptyArray()); - } - - /** - * Retrieve the set of values that occur in matches for state. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfstate(final ParentState.Match partialMatch) { - return rawStreamAllValuesOfstate(partialMatch.toArray()); - } - - /** - * Retrieve the set of values that occur in matches for state. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfstate(final State pParentState) { - return rawStreamAllValuesOfstate(new Object[]{null, pParentState}); - } - - /** - * Retrieve the set of values that occur in matches for state. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfstate(final ParentState.Match partialMatch) { - return rawStreamAllValuesOfstate(partialMatch.toArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for state. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfstate(final State pParentState) { - return rawStreamAllValuesOfstate(new Object[]{null, pParentState}).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for parentState. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOfparentState(final Object[] parameters) { - return rawStreamAllValues(POSITION_PARENTSTATE, parameters).map(State.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for parentState. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfparentState() { - return rawStreamAllValuesOfparentState(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for parentState. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfparentState() { - return rawStreamAllValuesOfparentState(emptyArray()); - } - - /** - * Retrieve the set of values that occur in matches for parentState. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfparentState(final ParentState.Match partialMatch) { - return rawStreamAllValuesOfparentState(partialMatch.toArray()); - } - - /** - * Retrieve the set of values that occur in matches for parentState. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfparentState(final State pState) { - return rawStreamAllValuesOfparentState(new Object[]{pState, null}); - } - - /** - * Retrieve the set of values that occur in matches for parentState. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfparentState(final ParentState.Match partialMatch) { - return rawStreamAllValuesOfparentState(partialMatch.toArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for parentState. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfparentState(final State pState) { - return rawStreamAllValuesOfparentState(new Object[]{pState, null}).collect(Collectors.toSet()); - } - - @Override - protected ParentState.Match tupleToMatch(final Tuple t) { - try { - return ParentState.Match.newMatch((State) t.get(POSITION_STATE), (State) t.get(POSITION_PARENTSTATE)); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in tuple not properly typed!",e); - return null; - } - } - - @Override - protected ParentState.Match arrayToMatch(final Object[] match) { - try { - return ParentState.Match.newMatch((State) match[POSITION_STATE], (State) match[POSITION_PARENTSTATE]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - @Override - protected ParentState.Match arrayToMatchMutable(final Object[] match) { - try { - return ParentState.Match.newMutableMatch((State) match[POSITION_STATE], (State) match[POSITION_PARENTSTATE]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - /** - * @return the singleton instance of the query specification of this pattern - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static IQuerySpecification querySpecification() { - return ParentState.instance(); - } - } - - private ParentState() { - super(GeneratedPQuery.INSTANCE); - } - - /** - * @return the singleton instance of the query specification - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static ParentState instance() { - try{ - return LazyHolder.INSTANCE; - } catch (ExceptionInInitializerError err) { - throw processInitializerError(err); - } - } - - @Override - protected ParentState.Matcher instantiate(final ViatraQueryEngine engine) { - return ParentState.Matcher.on(engine); - } - - @Override - public ParentState.Matcher instantiate() { - return ParentState.Matcher.create(); - } - - @Override - public ParentState.Match newEmptyMatch() { - return ParentState.Match.newEmptyMatch(); - } - - @Override - public ParentState.Match newMatch(final Object... parameters) { - return ParentState.Match.newMatch((com.nomagic.uml2.ext.magicdraw.statemachines.mdbehaviorstatemachines.State) parameters[0], (com.nomagic.uml2.ext.magicdraw.statemachines.mdbehaviorstatemachines.State) parameters[1]); - } - - /** - * Inner class allowing the singleton instance of {@link ParentState} to be created - * not at the class load time of the outer class, - * but rather at the first call to {@link ParentState#instance()}. - * - *

This workaround is required e.g. to support recursion. - * - */ - private static class LazyHolder { - private static final ParentState INSTANCE = new ParentState(); - - /** - * Statically initializes the query specification after the field {@link #INSTANCE} is assigned. - * This initialization order is required to support indirect recursion. - * - *

The static initializer is defined using a helper field to work around limitations of the code generator. - * - */ - private static final Object STATIC_INITIALIZER = ensureInitialized(); - - public static Object ensureInitialized() { - INSTANCE.ensureInitializedInternal(); - return null; - } - } - - private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { - private static final ParentState.GeneratedPQuery INSTANCE = new GeneratedPQuery(); - - private final PParameter parameter_state = new PParameter("state", "com.nomagic.uml2.ext.magicdraw.statemachines.mdbehaviorstatemachines.State", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.nomagic.com/magicdraw/UML/2.5.1", "State")), PParameterDirection.INOUT); - - private final PParameter parameter_parentState = new PParameter("parentState", "com.nomagic.uml2.ext.magicdraw.statemachines.mdbehaviorstatemachines.State", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.nomagic.com/magicdraw/UML/2.5.1", "State")), PParameterDirection.INOUT); - - private final List parameters = Arrays.asList(parameter_state, parameter_parentState); - - private GeneratedPQuery() { - super(PVisibility.PUBLIC); - } - - @Override - public String getFullyQualifiedName() { - return "com.incquerylabs.magicdraw.benchmark.incrementalqueries.parentState"; - } - - @Override - public List getParameterNames() { - return Arrays.asList("state","parentState"); - } - - @Override - public List getParameters() { - return parameters; - } - - @Override - public Set doGetContainedBodies() { - setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.DEFAULT_CACHING)); - Set bodies = new LinkedHashSet<>(); - { - PBody body = new PBody(this); - PVariable var_state = body.getOrCreateVariableByName("state"); - PVariable var_parentState = body.getOrCreateVariableByName("parentState"); - PVariable var_subregion = body.getOrCreateVariableByName("subregion"); - new TypeConstraint(body, Tuples.flatTupleOf(var_state), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "State"))); - new TypeConstraint(body, Tuples.flatTupleOf(var_parentState), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "State"))); - body.setSymbolicParameters(Arrays.asList( - new ExportedParameter(body, var_state, parameter_state), - new ExportedParameter(body, var_parentState, parameter_parentState) - )); - // State.region(parentState, subregion) - new TypeConstraint(body, Tuples.flatTupleOf(var_parentState), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "State"))); - PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_parentState, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "State", "region"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Region"))); - new Equality(body, var__virtual_0_, var_subregion); - // Region.subvertex(subregion, state) - new TypeConstraint(body, Tuples.flatTupleOf(var_subregion), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Region"))); - PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_subregion, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Region", "subvertex"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Vertex"))); - new Equality(body, var__virtual_1_, var_state); - bodies.add(body); - } - return bodies; - } - } -} diff --git a/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/incrementalqueries/TransitiveSubstatesWithCheck.java b/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/incrementalqueries/TransitiveSubstatesWithCheck.java deleted file mode 100644 index 528c9a8..0000000 --- a/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/incrementalqueries/TransitiveSubstatesWithCheck.java +++ /dev/null @@ -1,710 +0,0 @@ -/** - * Generated from platform:/resource/com.incquerylabs.magicdraw.benchmark/src/main/java/com/incquerylabs/magicdraw/benchmark/incrementalqueries/IncrementalQueries.vql - */ -package com.incquerylabs.magicdraw.benchmark.incrementalqueries; - -import com.incquerylabs.magicdraw.benchmark.incrementalqueries.ParentState; -import com.incquerylabs.magicdraw.benchmark.queries.StatesWithShortNames; -import com.nomagic.uml2.ext.magicdraw.statemachines.mdbehaviorstatemachines.State; -import java.util.Arrays; -import java.util.Collection; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.function.Consumer; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import org.apache.log4j.Logger; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.viatra.query.runtime.api.IPatternMatch; -import org.eclipse.viatra.query.runtime.api.IQuerySpecification; -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.api.impl.BaseMatcher; -import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; -import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; -import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; -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.ExportedParameter; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.BinaryTransitiveClosure; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.PositivePatternCall; -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.PVisibility; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; -import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; - -/** - * A pattern-specific query specification that can instantiate Matcher in a type-safe way. - * - *

Original source: - *

- *         Reusing a simple pattern with a check expression before the transitive closure which is an incremental pattern.
- *          
- *         pattern transitiveSubstatesWithCheck(state : State, transitiveSubstate : State) {
- *         	find statesWithShortNames(state);
- *         	find parentState+(transitiveSubstate, state); 
- *         }
- * 
- * - * @see Matcher - * @see Match - * - */ -@SuppressWarnings("all") -public final class TransitiveSubstatesWithCheck extends BaseGeneratedEMFQuerySpecification { - /** - * Pattern-specific match representation of the com.incquerylabs.magicdraw.benchmark.incrementalqueries.transitiveSubstatesWithCheck pattern, - * to be used in conjunction with {@link Matcher}. - * - *

Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. - * Each instance is a (possibly partial) substitution of pattern parameters, - * usable to represent a match of the pattern in the result of a query, - * or to specify the bound (fixed) input parameters when issuing a query. - * - * @see Matcher - * - */ - public static abstract class Match extends BasePatternMatch { - private State fState; - - private State fTransitiveSubstate; - - private static List parameterNames = makeImmutableList("state", "transitiveSubstate"); - - private Match(final State pState, final State pTransitiveSubstate) { - this.fState = pState; - this.fTransitiveSubstate = pTransitiveSubstate; - } - - @Override - public Object get(final String parameterName) { - switch(parameterName) { - case "state": return this.fState; - case "transitiveSubstate": return this.fTransitiveSubstate; - default: return null; - } - } - - @Override - public Object get(final int index) { - switch(index) { - case 0: return this.fState; - case 1: return this.fTransitiveSubstate; - default: return null; - } - } - - public State getState() { - return this.fState; - } - - public State getTransitiveSubstate() { - return this.fTransitiveSubstate; - } - - @Override - public boolean set(final String parameterName, final Object newValue) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - if ("state".equals(parameterName) ) { - this.fState = (State) newValue; - return true; - } - if ("transitiveSubstate".equals(parameterName) ) { - this.fTransitiveSubstate = (State) newValue; - return true; - } - return false; - } - - public void setState(final State pState) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fState = pState; - } - - public void setTransitiveSubstate(final State pTransitiveSubstate) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fTransitiveSubstate = pTransitiveSubstate; - } - - @Override - public String patternName() { - return "com.incquerylabs.magicdraw.benchmark.incrementalqueries.transitiveSubstatesWithCheck"; - } - - @Override - public List parameterNames() { - return TransitiveSubstatesWithCheck.Match.parameterNames; - } - - @Override - public Object[] toArray() { - return new Object[]{fState, fTransitiveSubstate}; - } - - @Override - public TransitiveSubstatesWithCheck.Match toImmutable() { - return isMutable() ? newMatch(fState, fTransitiveSubstate) : this; - } - - @Override - public String prettyPrint() { - StringBuilder result = new StringBuilder(); - result.append("\"state\"=" + prettyPrintValue(fState) + ", "); - result.append("\"transitiveSubstate\"=" + prettyPrintValue(fTransitiveSubstate)); - return result.toString(); - } - - @Override - public int hashCode() { - return Objects.hash(fState, fTransitiveSubstate); - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) - return true; - if (obj == null) { - return false; - } - if ((obj instanceof TransitiveSubstatesWithCheck.Match)) { - TransitiveSubstatesWithCheck.Match other = (TransitiveSubstatesWithCheck.Match) obj; - return Objects.equals(fState, other.fState) && Objects.equals(fTransitiveSubstate, other.fTransitiveSubstate); - } else { - // this should be infrequent - if (!(obj instanceof IPatternMatch)) { - return false; - } - IPatternMatch otherSig = (IPatternMatch) obj; - return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); - } - } - - @Override - public TransitiveSubstatesWithCheck specification() { - return TransitiveSubstatesWithCheck.instance(); - } - - /** - * Returns an empty, mutable match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @return the empty match. - * - */ - public static TransitiveSubstatesWithCheck.Match newEmptyMatch() { - return new Mutable(null, null); - } - - /** - * Returns a mutable (partial) match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pTransitiveSubstate the fixed value of pattern parameter transitiveSubstate, or null if not bound. - * @return the new, mutable (partial) match object. - * - */ - public static TransitiveSubstatesWithCheck.Match newMutableMatch(final State pState, final State pTransitiveSubstate) { - return new Mutable(pState, pTransitiveSubstate); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pTransitiveSubstate the fixed value of pattern parameter transitiveSubstate, or null if not bound. - * @return the (partial) match object. - * - */ - public static TransitiveSubstatesWithCheck.Match newMatch(final State pState, final State pTransitiveSubstate) { - return new Immutable(pState, pTransitiveSubstate); - } - - private static final class Mutable extends TransitiveSubstatesWithCheck.Match { - Mutable(final State pState, final State pTransitiveSubstate) { - super(pState, pTransitiveSubstate); - } - - @Override - public boolean isMutable() { - return true; - } - } - - private static final class Immutable extends TransitiveSubstatesWithCheck.Match { - Immutable(final State pState, final State pTransitiveSubstate) { - super(pState, pTransitiveSubstate); - } - - @Override - public boolean isMutable() { - return false; - } - } - } - - /** - * Generated pattern matcher API of the com.incquerylabs.magicdraw.benchmark.incrementalqueries.transitiveSubstatesWithCheck pattern, - * providing pattern-specific query methods. - * - *

Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, - * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. - * - *

Matches of the pattern will be represented as {@link Match}. - * - *

Original source: - *

-   * Reusing a simple pattern with a check expression before the transitive closure which is an incremental pattern.
-   *  
-   * pattern transitiveSubstatesWithCheck(state : State, transitiveSubstate : State) {
-   * 	find statesWithShortNames(state);
-   * 	find parentState+(transitiveSubstate, state); 
-   * }
-   * 
- * - * @see Match - * @see TransitiveSubstatesWithCheck - * - */ - public static class Matcher extends BaseMatcher { - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - public static TransitiveSubstatesWithCheck.Matcher on(final ViatraQueryEngine engine) { - // check if matcher already exists - Matcher matcher = engine.getExistingMatcher(querySpecification()); - if (matcher == null) { - matcher = (Matcher)engine.getMatcher(querySpecification()); - } - return matcher; - } - - /** - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * @return an initialized matcher - * @noreference This method is for internal matcher initialization by the framework, do not call it manually. - * - */ - public static TransitiveSubstatesWithCheck.Matcher create() { - return new Matcher(); - } - - private static final int POSITION_STATE = 0; - - private static final int POSITION_TRANSITIVESUBSTATE = 1; - - private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(TransitiveSubstatesWithCheck.Matcher.class); - - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - private Matcher() { - super(querySpecification()); - } - - /** - * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pTransitiveSubstate the fixed value of pattern parameter transitiveSubstate, or null if not bound. - * @return matches represented as a Match object. - * - */ - public Collection getAllMatches(final State pState, final State pTransitiveSubstate) { - return rawStreamAllMatches(new Object[]{pState, pTransitiveSubstate}).collect(Collectors.toSet()); - } - - /** - * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pTransitiveSubstate the fixed value of pattern parameter transitiveSubstate, or null if not bound. - * @return a stream of matches represented as a Match object. - * - */ - public Stream streamAllMatches(final State pState, final State pTransitiveSubstate) { - return rawStreamAllMatches(new Object[]{pState, pTransitiveSubstate}); - } - - /** - * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pTransitiveSubstate the fixed value of pattern parameter transitiveSubstate, or null if not bound. - * @return a match represented as a Match object, or null if no match is found. - * - */ - public Optional getOneArbitraryMatch(final State pState, final State pTransitiveSubstate) { - return rawGetOneArbitraryMatch(new Object[]{pState, pTransitiveSubstate}); - } - - /** - * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, - * under any possible substitution of the unspecified parameters (if any). - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pTransitiveSubstate the fixed value of pattern parameter transitiveSubstate, or null if not bound. - * @return true if the input is a valid (partial) match of the pattern. - * - */ - public boolean hasMatch(final State pState, final State pTransitiveSubstate) { - return rawHasMatch(new Object[]{pState, pTransitiveSubstate}); - } - - /** - * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pTransitiveSubstate the fixed value of pattern parameter transitiveSubstate, or null if not bound. - * @return the number of pattern matches found. - * - */ - public int countMatches(final State pState, final State pTransitiveSubstate) { - return rawCountMatches(new Object[]{pState, pTransitiveSubstate}); - } - - /** - * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pTransitiveSubstate the fixed value of pattern parameter transitiveSubstate, or null if not bound. - * @param processor the action that will process the selected match. - * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked - * - */ - public boolean forOneArbitraryMatch(final State pState, final State pTransitiveSubstate, final Consumer processor) { - return rawForOneArbitraryMatch(new Object[]{pState, pTransitiveSubstate}, processor); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pTransitiveSubstate the fixed value of pattern parameter transitiveSubstate, or null if not bound. - * @return the (partial) match object. - * - */ - public TransitiveSubstatesWithCheck.Match newMatch(final State pState, final State pTransitiveSubstate) { - return TransitiveSubstatesWithCheck.Match.newMatch(pState, pTransitiveSubstate); - } - - /** - * Retrieve the set of values that occur in matches for state. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOfstate(final Object[] parameters) { - return rawStreamAllValues(POSITION_STATE, parameters).map(State.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for state. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfstate() { - return rawStreamAllValuesOfstate(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for state. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfstate() { - return rawStreamAllValuesOfstate(emptyArray()); - } - - /** - * Retrieve the set of values that occur in matches for state. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfstate(final TransitiveSubstatesWithCheck.Match partialMatch) { - return rawStreamAllValuesOfstate(partialMatch.toArray()); - } - - /** - * Retrieve the set of values that occur in matches for state. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfstate(final State pTransitiveSubstate) { - return rawStreamAllValuesOfstate(new Object[]{null, pTransitiveSubstate}); - } - - /** - * Retrieve the set of values that occur in matches for state. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfstate(final TransitiveSubstatesWithCheck.Match partialMatch) { - return rawStreamAllValuesOfstate(partialMatch.toArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for state. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfstate(final State pTransitiveSubstate) { - return rawStreamAllValuesOfstate(new Object[]{null, pTransitiveSubstate}).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for transitiveSubstate. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOftransitiveSubstate(final Object[] parameters) { - return rawStreamAllValues(POSITION_TRANSITIVESUBSTATE, parameters).map(State.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for transitiveSubstate. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOftransitiveSubstate() { - return rawStreamAllValuesOftransitiveSubstate(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for transitiveSubstate. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOftransitiveSubstate() { - return rawStreamAllValuesOftransitiveSubstate(emptyArray()); - } - - /** - * Retrieve the set of values that occur in matches for transitiveSubstate. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOftransitiveSubstate(final TransitiveSubstatesWithCheck.Match partialMatch) { - return rawStreamAllValuesOftransitiveSubstate(partialMatch.toArray()); - } - - /** - * Retrieve the set of values that occur in matches for transitiveSubstate. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOftransitiveSubstate(final State pState) { - return rawStreamAllValuesOftransitiveSubstate(new Object[]{pState, null}); - } - - /** - * Retrieve the set of values that occur in matches for transitiveSubstate. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOftransitiveSubstate(final TransitiveSubstatesWithCheck.Match partialMatch) { - return rawStreamAllValuesOftransitiveSubstate(partialMatch.toArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for transitiveSubstate. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOftransitiveSubstate(final State pState) { - return rawStreamAllValuesOftransitiveSubstate(new Object[]{pState, null}).collect(Collectors.toSet()); - } - - @Override - protected TransitiveSubstatesWithCheck.Match tupleToMatch(final Tuple t) { - try { - return TransitiveSubstatesWithCheck.Match.newMatch((State) t.get(POSITION_STATE), (State) t.get(POSITION_TRANSITIVESUBSTATE)); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in tuple not properly typed!",e); - return null; - } - } - - @Override - protected TransitiveSubstatesWithCheck.Match arrayToMatch(final Object[] match) { - try { - return TransitiveSubstatesWithCheck.Match.newMatch((State) match[POSITION_STATE], (State) match[POSITION_TRANSITIVESUBSTATE]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - @Override - protected TransitiveSubstatesWithCheck.Match arrayToMatchMutable(final Object[] match) { - try { - return TransitiveSubstatesWithCheck.Match.newMutableMatch((State) match[POSITION_STATE], (State) match[POSITION_TRANSITIVESUBSTATE]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - /** - * @return the singleton instance of the query specification of this pattern - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static IQuerySpecification querySpecification() { - return TransitiveSubstatesWithCheck.instance(); - } - } - - private TransitiveSubstatesWithCheck() { - super(GeneratedPQuery.INSTANCE); - } - - /** - * @return the singleton instance of the query specification - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static TransitiveSubstatesWithCheck instance() { - try{ - return LazyHolder.INSTANCE; - } catch (ExceptionInInitializerError err) { - throw processInitializerError(err); - } - } - - @Override - protected TransitiveSubstatesWithCheck.Matcher instantiate(final ViatraQueryEngine engine) { - return TransitiveSubstatesWithCheck.Matcher.on(engine); - } - - @Override - public TransitiveSubstatesWithCheck.Matcher instantiate() { - return TransitiveSubstatesWithCheck.Matcher.create(); - } - - @Override - public TransitiveSubstatesWithCheck.Match newEmptyMatch() { - return TransitiveSubstatesWithCheck.Match.newEmptyMatch(); - } - - @Override - public TransitiveSubstatesWithCheck.Match newMatch(final Object... parameters) { - return TransitiveSubstatesWithCheck.Match.newMatch((com.nomagic.uml2.ext.magicdraw.statemachines.mdbehaviorstatemachines.State) parameters[0], (com.nomagic.uml2.ext.magicdraw.statemachines.mdbehaviorstatemachines.State) parameters[1]); - } - - /** - * Inner class allowing the singleton instance of {@link TransitiveSubstatesWithCheck} to be created - * not at the class load time of the outer class, - * but rather at the first call to {@link TransitiveSubstatesWithCheck#instance()}. - * - *

This workaround is required e.g. to support recursion. - * - */ - private static class LazyHolder { - private static final TransitiveSubstatesWithCheck INSTANCE = new TransitiveSubstatesWithCheck(); - - /** - * Statically initializes the query specification after the field {@link #INSTANCE} is assigned. - * This initialization order is required to support indirect recursion. - * - *

The static initializer is defined using a helper field to work around limitations of the code generator. - * - */ - private static final Object STATIC_INITIALIZER = ensureInitialized(); - - public static Object ensureInitialized() { - INSTANCE.ensureInitializedInternal(); - return null; - } - } - - private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { - private static final TransitiveSubstatesWithCheck.GeneratedPQuery INSTANCE = new GeneratedPQuery(); - - private final PParameter parameter_state = new PParameter("state", "com.nomagic.uml2.ext.magicdraw.statemachines.mdbehaviorstatemachines.State", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.nomagic.com/magicdraw/UML/2.5.1", "State")), PParameterDirection.INOUT); - - private final PParameter parameter_transitiveSubstate = new PParameter("transitiveSubstate", "com.nomagic.uml2.ext.magicdraw.statemachines.mdbehaviorstatemachines.State", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.nomagic.com/magicdraw/UML/2.5.1", "State")), PParameterDirection.INOUT); - - private final List parameters = Arrays.asList(parameter_state, parameter_transitiveSubstate); - - private GeneratedPQuery() { - super(PVisibility.PUBLIC); - } - - @Override - public String getFullyQualifiedName() { - return "com.incquerylabs.magicdraw.benchmark.incrementalqueries.transitiveSubstatesWithCheck"; - } - - @Override - public List getParameterNames() { - return Arrays.asList("state","transitiveSubstate"); - } - - @Override - public List getParameters() { - return parameters; - } - - @Override - public Set doGetContainedBodies() { - setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); - Set bodies = new LinkedHashSet<>(); - { - PBody body = new PBody(this); - PVariable var_state = body.getOrCreateVariableByName("state"); - PVariable var_transitiveSubstate = body.getOrCreateVariableByName("transitiveSubstate"); - new TypeConstraint(body, Tuples.flatTupleOf(var_state), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "State"))); - new TypeConstraint(body, Tuples.flatTupleOf(var_transitiveSubstate), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "State"))); - body.setSymbolicParameters(Arrays.asList( - new ExportedParameter(body, var_state, parameter_state), - new ExportedParameter(body, var_transitiveSubstate, parameter_transitiveSubstate) - )); - // find statesWithShortNames(state) - new PositivePatternCall(body, Tuples.flatTupleOf(var_state), StatesWithShortNames.instance().getInternalQueryRepresentation()); - // find parentState+(transitiveSubstate, state) - new BinaryTransitiveClosure(body, Tuples.flatTupleOf(var_transitiveSubstate, var_state), ParentState.instance().getInternalQueryRepresentation()); - bodies.add(body); - } - return bodies; - } - } -} diff --git a/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/incrementalqueries/TransitiveSubstatesWithCheck2.java b/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/incrementalqueries/TransitiveSubstatesWithCheck2.java deleted file mode 100644 index 26b0ef8..0000000 --- a/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/incrementalqueries/TransitiveSubstatesWithCheck2.java +++ /dev/null @@ -1,742 +0,0 @@ -/** - * Generated from platform:/resource/com.incquerylabs.magicdraw.benchmark/src/main/java/com/incquerylabs/magicdraw/benchmark/incrementalqueries/IncrementalQueries.vql - */ -package com.incquerylabs.magicdraw.benchmark.incrementalqueries; - -import com.incquerylabs.magicdraw.benchmark.incrementalqueries.ParentState; -import com.incquerylabs.magicdraw.benchmark.queries.IncomingTransitions; -import com.nomagic.uml2.ext.magicdraw.statemachines.mdbehaviorstatemachines.State; -import java.util.Arrays; -import java.util.Collection; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.function.Consumer; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import org.apache.log4j.Logger; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.viatra.query.runtime.api.IPatternMatch; -import org.eclipse.viatra.query.runtime.api.IQuerySpecification; -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.api.impl.BaseMatcher; -import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; -import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; -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.basicdeferred.PatternMatchCounter; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.BinaryTransitiveClosure; -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.PVisibility; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; -import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; - -/** - * A pattern-specific query specification that can instantiate Matcher in a type-safe way. - * - *

Original source: - *

- *         Reusing a simple pattern with a check expression before the transitive closure which is an incremental pattern.
- *          
- *         pattern transitiveSubstatesWithCheck2(state : State, transitiveSubstate : State) {
- *         	transitionCount == count find incomingTransitions(_, state);
- *         	check (transitionCount {@literal >} 1);
- *         	find parentState+(transitiveSubstate, state);
- *         }
- * 
- * - * @see Matcher - * @see Match - * - */ -@SuppressWarnings("all") -public final class TransitiveSubstatesWithCheck2 extends BaseGeneratedEMFQuerySpecification { - /** - * Pattern-specific match representation of the com.incquerylabs.magicdraw.benchmark.incrementalqueries.transitiveSubstatesWithCheck2 pattern, - * to be used in conjunction with {@link Matcher}. - * - *

Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. - * Each instance is a (possibly partial) substitution of pattern parameters, - * usable to represent a match of the pattern in the result of a query, - * or to specify the bound (fixed) input parameters when issuing a query. - * - * @see Matcher - * - */ - public static abstract class Match extends BasePatternMatch { - private State fState; - - private State fTransitiveSubstate; - - private static List parameterNames = makeImmutableList("state", "transitiveSubstate"); - - private Match(final State pState, final State pTransitiveSubstate) { - this.fState = pState; - this.fTransitiveSubstate = pTransitiveSubstate; - } - - @Override - public Object get(final String parameterName) { - switch(parameterName) { - case "state": return this.fState; - case "transitiveSubstate": return this.fTransitiveSubstate; - default: return null; - } - } - - @Override - public Object get(final int index) { - switch(index) { - case 0: return this.fState; - case 1: return this.fTransitiveSubstate; - default: return null; - } - } - - public State getState() { - return this.fState; - } - - public State getTransitiveSubstate() { - return this.fTransitiveSubstate; - } - - @Override - public boolean set(final String parameterName, final Object newValue) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - if ("state".equals(parameterName) ) { - this.fState = (State) newValue; - return true; - } - if ("transitiveSubstate".equals(parameterName) ) { - this.fTransitiveSubstate = (State) newValue; - return true; - } - return false; - } - - public void setState(final State pState) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fState = pState; - } - - public void setTransitiveSubstate(final State pTransitiveSubstate) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fTransitiveSubstate = pTransitiveSubstate; - } - - @Override - public String patternName() { - return "com.incquerylabs.magicdraw.benchmark.incrementalqueries.transitiveSubstatesWithCheck2"; - } - - @Override - public List parameterNames() { - return TransitiveSubstatesWithCheck2.Match.parameterNames; - } - - @Override - public Object[] toArray() { - return new Object[]{fState, fTransitiveSubstate}; - } - - @Override - public TransitiveSubstatesWithCheck2.Match toImmutable() { - return isMutable() ? newMatch(fState, fTransitiveSubstate) : this; - } - - @Override - public String prettyPrint() { - StringBuilder result = new StringBuilder(); - result.append("\"state\"=" + prettyPrintValue(fState) + ", "); - result.append("\"transitiveSubstate\"=" + prettyPrintValue(fTransitiveSubstate)); - return result.toString(); - } - - @Override - public int hashCode() { - return Objects.hash(fState, fTransitiveSubstate); - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) - return true; - if (obj == null) { - return false; - } - if ((obj instanceof TransitiveSubstatesWithCheck2.Match)) { - TransitiveSubstatesWithCheck2.Match other = (TransitiveSubstatesWithCheck2.Match) obj; - return Objects.equals(fState, other.fState) && Objects.equals(fTransitiveSubstate, other.fTransitiveSubstate); - } else { - // this should be infrequent - if (!(obj instanceof IPatternMatch)) { - return false; - } - IPatternMatch otherSig = (IPatternMatch) obj; - return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); - } - } - - @Override - public TransitiveSubstatesWithCheck2 specification() { - return TransitiveSubstatesWithCheck2.instance(); - } - - /** - * Returns an empty, mutable match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @return the empty match. - * - */ - public static TransitiveSubstatesWithCheck2.Match newEmptyMatch() { - return new Mutable(null, null); - } - - /** - * Returns a mutable (partial) match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pTransitiveSubstate the fixed value of pattern parameter transitiveSubstate, or null if not bound. - * @return the new, mutable (partial) match object. - * - */ - public static TransitiveSubstatesWithCheck2.Match newMutableMatch(final State pState, final State pTransitiveSubstate) { - return new Mutable(pState, pTransitiveSubstate); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pTransitiveSubstate the fixed value of pattern parameter transitiveSubstate, or null if not bound. - * @return the (partial) match object. - * - */ - public static TransitiveSubstatesWithCheck2.Match newMatch(final State pState, final State pTransitiveSubstate) { - return new Immutable(pState, pTransitiveSubstate); - } - - private static final class Mutable extends TransitiveSubstatesWithCheck2.Match { - Mutable(final State pState, final State pTransitiveSubstate) { - super(pState, pTransitiveSubstate); - } - - @Override - public boolean isMutable() { - return true; - } - } - - private static final class Immutable extends TransitiveSubstatesWithCheck2.Match { - Immutable(final State pState, final State pTransitiveSubstate) { - super(pState, pTransitiveSubstate); - } - - @Override - public boolean isMutable() { - return false; - } - } - } - - /** - * Generated pattern matcher API of the com.incquerylabs.magicdraw.benchmark.incrementalqueries.transitiveSubstatesWithCheck2 pattern, - * providing pattern-specific query methods. - * - *

Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, - * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. - * - *

Matches of the pattern will be represented as {@link Match}. - * - *

Original source: - *

-   * Reusing a simple pattern with a check expression before the transitive closure which is an incremental pattern.
-   *  
-   * pattern transitiveSubstatesWithCheck2(state : State, transitiveSubstate : State) {
-   * 	transitionCount == count find incomingTransitions(_, state);
-   * 	check (transitionCount {@literal >} 1);
-   * 	find parentState+(transitiveSubstate, state);
-   * }
-   * 
- * - * @see Match - * @see TransitiveSubstatesWithCheck2 - * - */ - public static class Matcher extends BaseMatcher { - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - public static TransitiveSubstatesWithCheck2.Matcher on(final ViatraQueryEngine engine) { - // check if matcher already exists - Matcher matcher = engine.getExistingMatcher(querySpecification()); - if (matcher == null) { - matcher = (Matcher)engine.getMatcher(querySpecification()); - } - return matcher; - } - - /** - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * @return an initialized matcher - * @noreference This method is for internal matcher initialization by the framework, do not call it manually. - * - */ - public static TransitiveSubstatesWithCheck2.Matcher create() { - return new Matcher(); - } - - private static final int POSITION_STATE = 0; - - private static final int POSITION_TRANSITIVESUBSTATE = 1; - - private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(TransitiveSubstatesWithCheck2.Matcher.class); - - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - private Matcher() { - super(querySpecification()); - } - - /** - * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pTransitiveSubstate the fixed value of pattern parameter transitiveSubstate, or null if not bound. - * @return matches represented as a Match object. - * - */ - public Collection getAllMatches(final State pState, final State pTransitiveSubstate) { - return rawStreamAllMatches(new Object[]{pState, pTransitiveSubstate}).collect(Collectors.toSet()); - } - - /** - * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pTransitiveSubstate the fixed value of pattern parameter transitiveSubstate, or null if not bound. - * @return a stream of matches represented as a Match object. - * - */ - public Stream streamAllMatches(final State pState, final State pTransitiveSubstate) { - return rawStreamAllMatches(new Object[]{pState, pTransitiveSubstate}); - } - - /** - * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pTransitiveSubstate the fixed value of pattern parameter transitiveSubstate, or null if not bound. - * @return a match represented as a Match object, or null if no match is found. - * - */ - public Optional getOneArbitraryMatch(final State pState, final State pTransitiveSubstate) { - return rawGetOneArbitraryMatch(new Object[]{pState, pTransitiveSubstate}); - } - - /** - * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, - * under any possible substitution of the unspecified parameters (if any). - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pTransitiveSubstate the fixed value of pattern parameter transitiveSubstate, or null if not bound. - * @return true if the input is a valid (partial) match of the pattern. - * - */ - public boolean hasMatch(final State pState, final State pTransitiveSubstate) { - return rawHasMatch(new Object[]{pState, pTransitiveSubstate}); - } - - /** - * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pTransitiveSubstate the fixed value of pattern parameter transitiveSubstate, or null if not bound. - * @return the number of pattern matches found. - * - */ - public int countMatches(final State pState, final State pTransitiveSubstate) { - return rawCountMatches(new Object[]{pState, pTransitiveSubstate}); - } - - /** - * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pTransitiveSubstate the fixed value of pattern parameter transitiveSubstate, or null if not bound. - * @param processor the action that will process the selected match. - * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked - * - */ - public boolean forOneArbitraryMatch(final State pState, final State pTransitiveSubstate, final Consumer processor) { - return rawForOneArbitraryMatch(new Object[]{pState, pTransitiveSubstate}, processor); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pTransitiveSubstate the fixed value of pattern parameter transitiveSubstate, or null if not bound. - * @return the (partial) match object. - * - */ - public TransitiveSubstatesWithCheck2.Match newMatch(final State pState, final State pTransitiveSubstate) { - return TransitiveSubstatesWithCheck2.Match.newMatch(pState, pTransitiveSubstate); - } - - /** - * Retrieve the set of values that occur in matches for state. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOfstate(final Object[] parameters) { - return rawStreamAllValues(POSITION_STATE, parameters).map(State.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for state. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfstate() { - return rawStreamAllValuesOfstate(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for state. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfstate() { - return rawStreamAllValuesOfstate(emptyArray()); - } - - /** - * Retrieve the set of values that occur in matches for state. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfstate(final TransitiveSubstatesWithCheck2.Match partialMatch) { - return rawStreamAllValuesOfstate(partialMatch.toArray()); - } - - /** - * Retrieve the set of values that occur in matches for state. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfstate(final State pTransitiveSubstate) { - return rawStreamAllValuesOfstate(new Object[]{null, pTransitiveSubstate}); - } - - /** - * Retrieve the set of values that occur in matches for state. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfstate(final TransitiveSubstatesWithCheck2.Match partialMatch) { - return rawStreamAllValuesOfstate(partialMatch.toArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for state. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfstate(final State pTransitiveSubstate) { - return rawStreamAllValuesOfstate(new Object[]{null, pTransitiveSubstate}).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for transitiveSubstate. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOftransitiveSubstate(final Object[] parameters) { - return rawStreamAllValues(POSITION_TRANSITIVESUBSTATE, parameters).map(State.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for transitiveSubstate. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOftransitiveSubstate() { - return rawStreamAllValuesOftransitiveSubstate(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for transitiveSubstate. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOftransitiveSubstate() { - return rawStreamAllValuesOftransitiveSubstate(emptyArray()); - } - - /** - * Retrieve the set of values that occur in matches for transitiveSubstate. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOftransitiveSubstate(final TransitiveSubstatesWithCheck2.Match partialMatch) { - return rawStreamAllValuesOftransitiveSubstate(partialMatch.toArray()); - } - - /** - * Retrieve the set of values that occur in matches for transitiveSubstate. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOftransitiveSubstate(final State pState) { - return rawStreamAllValuesOftransitiveSubstate(new Object[]{pState, null}); - } - - /** - * Retrieve the set of values that occur in matches for transitiveSubstate. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOftransitiveSubstate(final TransitiveSubstatesWithCheck2.Match partialMatch) { - return rawStreamAllValuesOftransitiveSubstate(partialMatch.toArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for transitiveSubstate. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOftransitiveSubstate(final State pState) { - return rawStreamAllValuesOftransitiveSubstate(new Object[]{pState, null}).collect(Collectors.toSet()); - } - - @Override - protected TransitiveSubstatesWithCheck2.Match tupleToMatch(final Tuple t) { - try { - return TransitiveSubstatesWithCheck2.Match.newMatch((State) t.get(POSITION_STATE), (State) t.get(POSITION_TRANSITIVESUBSTATE)); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in tuple not properly typed!",e); - return null; - } - } - - @Override - protected TransitiveSubstatesWithCheck2.Match arrayToMatch(final Object[] match) { - try { - return TransitiveSubstatesWithCheck2.Match.newMatch((State) match[POSITION_STATE], (State) match[POSITION_TRANSITIVESUBSTATE]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - @Override - protected TransitiveSubstatesWithCheck2.Match arrayToMatchMutable(final Object[] match) { - try { - return TransitiveSubstatesWithCheck2.Match.newMutableMatch((State) match[POSITION_STATE], (State) match[POSITION_TRANSITIVESUBSTATE]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - /** - * @return the singleton instance of the query specification of this pattern - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static IQuerySpecification querySpecification() { - return TransitiveSubstatesWithCheck2.instance(); - } - } - - private TransitiveSubstatesWithCheck2() { - super(GeneratedPQuery.INSTANCE); - } - - /** - * @return the singleton instance of the query specification - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static TransitiveSubstatesWithCheck2 instance() { - try{ - return LazyHolder.INSTANCE; - } catch (ExceptionInInitializerError err) { - throw processInitializerError(err); - } - } - - @Override - protected TransitiveSubstatesWithCheck2.Matcher instantiate(final ViatraQueryEngine engine) { - return TransitiveSubstatesWithCheck2.Matcher.on(engine); - } - - @Override - public TransitiveSubstatesWithCheck2.Matcher instantiate() { - return TransitiveSubstatesWithCheck2.Matcher.create(); - } - - @Override - public TransitiveSubstatesWithCheck2.Match newEmptyMatch() { - return TransitiveSubstatesWithCheck2.Match.newEmptyMatch(); - } - - @Override - public TransitiveSubstatesWithCheck2.Match newMatch(final Object... parameters) { - return TransitiveSubstatesWithCheck2.Match.newMatch((com.nomagic.uml2.ext.magicdraw.statemachines.mdbehaviorstatemachines.State) parameters[0], (com.nomagic.uml2.ext.magicdraw.statemachines.mdbehaviorstatemachines.State) parameters[1]); - } - - /** - * Inner class allowing the singleton instance of {@link TransitiveSubstatesWithCheck2} to be created - * not at the class load time of the outer class, - * but rather at the first call to {@link TransitiveSubstatesWithCheck2#instance()}. - * - *

This workaround is required e.g. to support recursion. - * - */ - private static class LazyHolder { - private static final TransitiveSubstatesWithCheck2 INSTANCE = new TransitiveSubstatesWithCheck2(); - - /** - * Statically initializes the query specification after the field {@link #INSTANCE} is assigned. - * This initialization order is required to support indirect recursion. - * - *

The static initializer is defined using a helper field to work around limitations of the code generator. - * - */ - private static final Object STATIC_INITIALIZER = ensureInitialized(); - - public static Object ensureInitialized() { - INSTANCE.ensureInitializedInternal(); - return null; - } - } - - private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { - private static final TransitiveSubstatesWithCheck2.GeneratedPQuery INSTANCE = new GeneratedPQuery(); - - private final PParameter parameter_state = new PParameter("state", "com.nomagic.uml2.ext.magicdraw.statemachines.mdbehaviorstatemachines.State", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.nomagic.com/magicdraw/UML/2.5.1", "State")), PParameterDirection.INOUT); - - private final PParameter parameter_transitiveSubstate = new PParameter("transitiveSubstate", "com.nomagic.uml2.ext.magicdraw.statemachines.mdbehaviorstatemachines.State", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.nomagic.com/magicdraw/UML/2.5.1", "State")), PParameterDirection.INOUT); - - private final List parameters = Arrays.asList(parameter_state, parameter_transitiveSubstate); - - private GeneratedPQuery() { - super(PVisibility.PUBLIC); - } - - @Override - public String getFullyQualifiedName() { - return "com.incquerylabs.magicdraw.benchmark.incrementalqueries.transitiveSubstatesWithCheck2"; - } - - @Override - public List getParameterNames() { - return Arrays.asList("state","transitiveSubstate"); - } - - @Override - public List getParameters() { - return parameters; - } - - @Override - public Set doGetContainedBodies() { - setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); - Set bodies = new LinkedHashSet<>(); - { - PBody body = new PBody(this); - PVariable var_state = body.getOrCreateVariableByName("state"); - PVariable var_transitiveSubstate = body.getOrCreateVariableByName("transitiveSubstate"); - PVariable var_transitionCount = body.getOrCreateVariableByName("transitionCount"); - PVariable var___0_ = body.getOrCreateVariableByName("_<0>"); - new TypeConstraint(body, Tuples.flatTupleOf(var_state), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "State"))); - new TypeConstraint(body, Tuples.flatTupleOf(var_transitiveSubstate), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "State"))); - body.setSymbolicParameters(Arrays.asList( - new ExportedParameter(body, var_state, parameter_state), - new ExportedParameter(body, var_transitiveSubstate, parameter_transitiveSubstate) - )); - // transitionCount == count find incomingTransitions(_, state) - PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); - new PatternMatchCounter(body, Tuples.flatTupleOf(var___0_, var_state), IncomingTransitions.instance().getInternalQueryRepresentation(), var__virtual_0_); - new Equality(body, var_transitionCount, var__virtual_0_); - // check (transitionCount > 1) - new ExpressionEvaluation(body, new IExpressionEvaluator() { - - @Override - public String getShortDescription() { - return "Expression evaluation from pattern transitiveSubstatesWithCheck2"; - } - - @Override - public Iterable getInputParameterNames() { - return Arrays.asList("transitionCount");} - - @Override - public Object evaluateExpression(IValueProvider provider) throws Exception { - Integer transitionCount = (Integer) provider.getValue("transitionCount"); - return evaluateExpression_1_1(transitionCount); - } - }, null); - // find parentState+(transitiveSubstate, state) - new BinaryTransitiveClosure(body, Tuples.flatTupleOf(var_transitiveSubstate, var_state), ParentState.instance().getInternalQueryRepresentation()); - bodies.add(body); - } - return bodies; - } - } - - private static boolean evaluateExpression_1_1(final Integer transitionCount) { - return ((transitionCount).intValue() > 1); - } -} diff --git a/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/incrementalqueries/TransitiveSubstatesWithCheck3.java b/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/incrementalqueries/TransitiveSubstatesWithCheck3.java deleted file mode 100644 index 62b3740..0000000 --- a/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/incrementalqueries/TransitiveSubstatesWithCheck3.java +++ /dev/null @@ -1,710 +0,0 @@ -/** - * Generated from platform:/resource/com.incquerylabs.magicdraw.benchmark/src/main/java/com/incquerylabs/magicdraw/benchmark/incrementalqueries/IncrementalQueries.vql - */ -package com.incquerylabs.magicdraw.benchmark.incrementalqueries; - -import com.incquerylabs.magicdraw.benchmark.incrementalqueries.ParentState; -import com.incquerylabs.magicdraw.benchmark.queries.StatesWithMoreIncomingTransitions; -import com.nomagic.uml2.ext.magicdraw.statemachines.mdbehaviorstatemachines.State; -import java.util.Arrays; -import java.util.Collection; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.function.Consumer; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import org.apache.log4j.Logger; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.viatra.query.runtime.api.IPatternMatch; -import org.eclipse.viatra.query.runtime.api.IQuerySpecification; -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.api.impl.BaseMatcher; -import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; -import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; -import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; -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.ExportedParameter; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.BinaryTransitiveClosure; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.PositivePatternCall; -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.PVisibility; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; -import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; - -/** - * A pattern-specific query specification that can instantiate Matcher in a type-safe way. - * - *

Original source: - *

- *         Reusing a simple pattern with a check expression before the transitive closure which is an incremental pattern.
- *          
- *         pattern transitiveSubstatesWithCheck3(state : State, transitiveSubstate : State) {
- *         	find statesWithMoreIncomingTransitions(state);
- *         	find parentState+(transitiveSubstate, state);
- *         }
- * 
- * - * @see Matcher - * @see Match - * - */ -@SuppressWarnings("all") -public final class TransitiveSubstatesWithCheck3 extends BaseGeneratedEMFQuerySpecification { - /** - * Pattern-specific match representation of the com.incquerylabs.magicdraw.benchmark.incrementalqueries.transitiveSubstatesWithCheck3 pattern, - * to be used in conjunction with {@link Matcher}. - * - *

Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. - * Each instance is a (possibly partial) substitution of pattern parameters, - * usable to represent a match of the pattern in the result of a query, - * or to specify the bound (fixed) input parameters when issuing a query. - * - * @see Matcher - * - */ - public static abstract class Match extends BasePatternMatch { - private State fState; - - private State fTransitiveSubstate; - - private static List parameterNames = makeImmutableList("state", "transitiveSubstate"); - - private Match(final State pState, final State pTransitiveSubstate) { - this.fState = pState; - this.fTransitiveSubstate = pTransitiveSubstate; - } - - @Override - public Object get(final String parameterName) { - switch(parameterName) { - case "state": return this.fState; - case "transitiveSubstate": return this.fTransitiveSubstate; - default: return null; - } - } - - @Override - public Object get(final int index) { - switch(index) { - case 0: return this.fState; - case 1: return this.fTransitiveSubstate; - default: return null; - } - } - - public State getState() { - return this.fState; - } - - public State getTransitiveSubstate() { - return this.fTransitiveSubstate; - } - - @Override - public boolean set(final String parameterName, final Object newValue) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - if ("state".equals(parameterName) ) { - this.fState = (State) newValue; - return true; - } - if ("transitiveSubstate".equals(parameterName) ) { - this.fTransitiveSubstate = (State) newValue; - return true; - } - return false; - } - - public void setState(final State pState) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fState = pState; - } - - public void setTransitiveSubstate(final State pTransitiveSubstate) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fTransitiveSubstate = pTransitiveSubstate; - } - - @Override - public String patternName() { - return "com.incquerylabs.magicdraw.benchmark.incrementalqueries.transitiveSubstatesWithCheck3"; - } - - @Override - public List parameterNames() { - return TransitiveSubstatesWithCheck3.Match.parameterNames; - } - - @Override - public Object[] toArray() { - return new Object[]{fState, fTransitiveSubstate}; - } - - @Override - public TransitiveSubstatesWithCheck3.Match toImmutable() { - return isMutable() ? newMatch(fState, fTransitiveSubstate) : this; - } - - @Override - public String prettyPrint() { - StringBuilder result = new StringBuilder(); - result.append("\"state\"=" + prettyPrintValue(fState) + ", "); - result.append("\"transitiveSubstate\"=" + prettyPrintValue(fTransitiveSubstate)); - return result.toString(); - } - - @Override - public int hashCode() { - return Objects.hash(fState, fTransitiveSubstate); - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) - return true; - if (obj == null) { - return false; - } - if ((obj instanceof TransitiveSubstatesWithCheck3.Match)) { - TransitiveSubstatesWithCheck3.Match other = (TransitiveSubstatesWithCheck3.Match) obj; - return Objects.equals(fState, other.fState) && Objects.equals(fTransitiveSubstate, other.fTransitiveSubstate); - } else { - // this should be infrequent - if (!(obj instanceof IPatternMatch)) { - return false; - } - IPatternMatch otherSig = (IPatternMatch) obj; - return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); - } - } - - @Override - public TransitiveSubstatesWithCheck3 specification() { - return TransitiveSubstatesWithCheck3.instance(); - } - - /** - * Returns an empty, mutable match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @return the empty match. - * - */ - public static TransitiveSubstatesWithCheck3.Match newEmptyMatch() { - return new Mutable(null, null); - } - - /** - * Returns a mutable (partial) match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pTransitiveSubstate the fixed value of pattern parameter transitiveSubstate, or null if not bound. - * @return the new, mutable (partial) match object. - * - */ - public static TransitiveSubstatesWithCheck3.Match newMutableMatch(final State pState, final State pTransitiveSubstate) { - return new Mutable(pState, pTransitiveSubstate); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pTransitiveSubstate the fixed value of pattern parameter transitiveSubstate, or null if not bound. - * @return the (partial) match object. - * - */ - public static TransitiveSubstatesWithCheck3.Match newMatch(final State pState, final State pTransitiveSubstate) { - return new Immutable(pState, pTransitiveSubstate); - } - - private static final class Mutable extends TransitiveSubstatesWithCheck3.Match { - Mutable(final State pState, final State pTransitiveSubstate) { - super(pState, pTransitiveSubstate); - } - - @Override - public boolean isMutable() { - return true; - } - } - - private static final class Immutable extends TransitiveSubstatesWithCheck3.Match { - Immutable(final State pState, final State pTransitiveSubstate) { - super(pState, pTransitiveSubstate); - } - - @Override - public boolean isMutable() { - return false; - } - } - } - - /** - * Generated pattern matcher API of the com.incquerylabs.magicdraw.benchmark.incrementalqueries.transitiveSubstatesWithCheck3 pattern, - * providing pattern-specific query methods. - * - *

Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, - * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. - * - *

Matches of the pattern will be represented as {@link Match}. - * - *

Original source: - *

-   * Reusing a simple pattern with a check expression before the transitive closure which is an incremental pattern.
-   *  
-   * pattern transitiveSubstatesWithCheck3(state : State, transitiveSubstate : State) {
-   * 	find statesWithMoreIncomingTransitions(state);
-   * 	find parentState+(transitiveSubstate, state);
-   * }
-   * 
- * - * @see Match - * @see TransitiveSubstatesWithCheck3 - * - */ - public static class Matcher extends BaseMatcher { - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - public static TransitiveSubstatesWithCheck3.Matcher on(final ViatraQueryEngine engine) { - // check if matcher already exists - Matcher matcher = engine.getExistingMatcher(querySpecification()); - if (matcher == null) { - matcher = (Matcher)engine.getMatcher(querySpecification()); - } - return matcher; - } - - /** - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * @return an initialized matcher - * @noreference This method is for internal matcher initialization by the framework, do not call it manually. - * - */ - public static TransitiveSubstatesWithCheck3.Matcher create() { - return new Matcher(); - } - - private static final int POSITION_STATE = 0; - - private static final int POSITION_TRANSITIVESUBSTATE = 1; - - private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(TransitiveSubstatesWithCheck3.Matcher.class); - - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - private Matcher() { - super(querySpecification()); - } - - /** - * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pTransitiveSubstate the fixed value of pattern parameter transitiveSubstate, or null if not bound. - * @return matches represented as a Match object. - * - */ - public Collection getAllMatches(final State pState, final State pTransitiveSubstate) { - return rawStreamAllMatches(new Object[]{pState, pTransitiveSubstate}).collect(Collectors.toSet()); - } - - /** - * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pTransitiveSubstate the fixed value of pattern parameter transitiveSubstate, or null if not bound. - * @return a stream of matches represented as a Match object. - * - */ - public Stream streamAllMatches(final State pState, final State pTransitiveSubstate) { - return rawStreamAllMatches(new Object[]{pState, pTransitiveSubstate}); - } - - /** - * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pTransitiveSubstate the fixed value of pattern parameter transitiveSubstate, or null if not bound. - * @return a match represented as a Match object, or null if no match is found. - * - */ - public Optional getOneArbitraryMatch(final State pState, final State pTransitiveSubstate) { - return rawGetOneArbitraryMatch(new Object[]{pState, pTransitiveSubstate}); - } - - /** - * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, - * under any possible substitution of the unspecified parameters (if any). - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pTransitiveSubstate the fixed value of pattern parameter transitiveSubstate, or null if not bound. - * @return true if the input is a valid (partial) match of the pattern. - * - */ - public boolean hasMatch(final State pState, final State pTransitiveSubstate) { - return rawHasMatch(new Object[]{pState, pTransitiveSubstate}); - } - - /** - * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pTransitiveSubstate the fixed value of pattern parameter transitiveSubstate, or null if not bound. - * @return the number of pattern matches found. - * - */ - public int countMatches(final State pState, final State pTransitiveSubstate) { - return rawCountMatches(new Object[]{pState, pTransitiveSubstate}); - } - - /** - * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pTransitiveSubstate the fixed value of pattern parameter transitiveSubstate, or null if not bound. - * @param processor the action that will process the selected match. - * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked - * - */ - public boolean forOneArbitraryMatch(final State pState, final State pTransitiveSubstate, final Consumer processor) { - return rawForOneArbitraryMatch(new Object[]{pState, pTransitiveSubstate}, processor); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pTransitiveSubstate the fixed value of pattern parameter transitiveSubstate, or null if not bound. - * @return the (partial) match object. - * - */ - public TransitiveSubstatesWithCheck3.Match newMatch(final State pState, final State pTransitiveSubstate) { - return TransitiveSubstatesWithCheck3.Match.newMatch(pState, pTransitiveSubstate); - } - - /** - * Retrieve the set of values that occur in matches for state. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOfstate(final Object[] parameters) { - return rawStreamAllValues(POSITION_STATE, parameters).map(State.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for state. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfstate() { - return rawStreamAllValuesOfstate(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for state. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfstate() { - return rawStreamAllValuesOfstate(emptyArray()); - } - - /** - * Retrieve the set of values that occur in matches for state. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfstate(final TransitiveSubstatesWithCheck3.Match partialMatch) { - return rawStreamAllValuesOfstate(partialMatch.toArray()); - } - - /** - * Retrieve the set of values that occur in matches for state. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfstate(final State pTransitiveSubstate) { - return rawStreamAllValuesOfstate(new Object[]{null, pTransitiveSubstate}); - } - - /** - * Retrieve the set of values that occur in matches for state. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfstate(final TransitiveSubstatesWithCheck3.Match partialMatch) { - return rawStreamAllValuesOfstate(partialMatch.toArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for state. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfstate(final State pTransitiveSubstate) { - return rawStreamAllValuesOfstate(new Object[]{null, pTransitiveSubstate}).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for transitiveSubstate. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOftransitiveSubstate(final Object[] parameters) { - return rawStreamAllValues(POSITION_TRANSITIVESUBSTATE, parameters).map(State.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for transitiveSubstate. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOftransitiveSubstate() { - return rawStreamAllValuesOftransitiveSubstate(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for transitiveSubstate. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOftransitiveSubstate() { - return rawStreamAllValuesOftransitiveSubstate(emptyArray()); - } - - /** - * Retrieve the set of values that occur in matches for transitiveSubstate. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOftransitiveSubstate(final TransitiveSubstatesWithCheck3.Match partialMatch) { - return rawStreamAllValuesOftransitiveSubstate(partialMatch.toArray()); - } - - /** - * Retrieve the set of values that occur in matches for transitiveSubstate. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOftransitiveSubstate(final State pState) { - return rawStreamAllValuesOftransitiveSubstate(new Object[]{pState, null}); - } - - /** - * Retrieve the set of values that occur in matches for transitiveSubstate. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOftransitiveSubstate(final TransitiveSubstatesWithCheck3.Match partialMatch) { - return rawStreamAllValuesOftransitiveSubstate(partialMatch.toArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for transitiveSubstate. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOftransitiveSubstate(final State pState) { - return rawStreamAllValuesOftransitiveSubstate(new Object[]{pState, null}).collect(Collectors.toSet()); - } - - @Override - protected TransitiveSubstatesWithCheck3.Match tupleToMatch(final Tuple t) { - try { - return TransitiveSubstatesWithCheck3.Match.newMatch((State) t.get(POSITION_STATE), (State) t.get(POSITION_TRANSITIVESUBSTATE)); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in tuple not properly typed!",e); - return null; - } - } - - @Override - protected TransitiveSubstatesWithCheck3.Match arrayToMatch(final Object[] match) { - try { - return TransitiveSubstatesWithCheck3.Match.newMatch((State) match[POSITION_STATE], (State) match[POSITION_TRANSITIVESUBSTATE]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - @Override - protected TransitiveSubstatesWithCheck3.Match arrayToMatchMutable(final Object[] match) { - try { - return TransitiveSubstatesWithCheck3.Match.newMutableMatch((State) match[POSITION_STATE], (State) match[POSITION_TRANSITIVESUBSTATE]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - /** - * @return the singleton instance of the query specification of this pattern - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static IQuerySpecification querySpecification() { - return TransitiveSubstatesWithCheck3.instance(); - } - } - - private TransitiveSubstatesWithCheck3() { - super(GeneratedPQuery.INSTANCE); - } - - /** - * @return the singleton instance of the query specification - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static TransitiveSubstatesWithCheck3 instance() { - try{ - return LazyHolder.INSTANCE; - } catch (ExceptionInInitializerError err) { - throw processInitializerError(err); - } - } - - @Override - protected TransitiveSubstatesWithCheck3.Matcher instantiate(final ViatraQueryEngine engine) { - return TransitiveSubstatesWithCheck3.Matcher.on(engine); - } - - @Override - public TransitiveSubstatesWithCheck3.Matcher instantiate() { - return TransitiveSubstatesWithCheck3.Matcher.create(); - } - - @Override - public TransitiveSubstatesWithCheck3.Match newEmptyMatch() { - return TransitiveSubstatesWithCheck3.Match.newEmptyMatch(); - } - - @Override - public TransitiveSubstatesWithCheck3.Match newMatch(final Object... parameters) { - return TransitiveSubstatesWithCheck3.Match.newMatch((com.nomagic.uml2.ext.magicdraw.statemachines.mdbehaviorstatemachines.State) parameters[0], (com.nomagic.uml2.ext.magicdraw.statemachines.mdbehaviorstatemachines.State) parameters[1]); - } - - /** - * Inner class allowing the singleton instance of {@link TransitiveSubstatesWithCheck3} to be created - * not at the class load time of the outer class, - * but rather at the first call to {@link TransitiveSubstatesWithCheck3#instance()}. - * - *

This workaround is required e.g. to support recursion. - * - */ - private static class LazyHolder { - private static final TransitiveSubstatesWithCheck3 INSTANCE = new TransitiveSubstatesWithCheck3(); - - /** - * Statically initializes the query specification after the field {@link #INSTANCE} is assigned. - * This initialization order is required to support indirect recursion. - * - *

The static initializer is defined using a helper field to work around limitations of the code generator. - * - */ - private static final Object STATIC_INITIALIZER = ensureInitialized(); - - public static Object ensureInitialized() { - INSTANCE.ensureInitializedInternal(); - return null; - } - } - - private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { - private static final TransitiveSubstatesWithCheck3.GeneratedPQuery INSTANCE = new GeneratedPQuery(); - - private final PParameter parameter_state = new PParameter("state", "com.nomagic.uml2.ext.magicdraw.statemachines.mdbehaviorstatemachines.State", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.nomagic.com/magicdraw/UML/2.5.1", "State")), PParameterDirection.INOUT); - - private final PParameter parameter_transitiveSubstate = new PParameter("transitiveSubstate", "com.nomagic.uml2.ext.magicdraw.statemachines.mdbehaviorstatemachines.State", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.nomagic.com/magicdraw/UML/2.5.1", "State")), PParameterDirection.INOUT); - - private final List parameters = Arrays.asList(parameter_state, parameter_transitiveSubstate); - - private GeneratedPQuery() { - super(PVisibility.PUBLIC); - } - - @Override - public String getFullyQualifiedName() { - return "com.incquerylabs.magicdraw.benchmark.incrementalqueries.transitiveSubstatesWithCheck3"; - } - - @Override - public List getParameterNames() { - return Arrays.asList("state","transitiveSubstate"); - } - - @Override - public List getParameters() { - return parameters; - } - - @Override - public Set doGetContainedBodies() { - setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); - Set bodies = new LinkedHashSet<>(); - { - PBody body = new PBody(this); - PVariable var_state = body.getOrCreateVariableByName("state"); - PVariable var_transitiveSubstate = body.getOrCreateVariableByName("transitiveSubstate"); - new TypeConstraint(body, Tuples.flatTupleOf(var_state), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "State"))); - new TypeConstraint(body, Tuples.flatTupleOf(var_transitiveSubstate), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "State"))); - body.setSymbolicParameters(Arrays.asList( - new ExportedParameter(body, var_state, parameter_state), - new ExportedParameter(body, var_transitiveSubstate, parameter_transitiveSubstate) - )); - // find statesWithMoreIncomingTransitions(state) - new PositivePatternCall(body, Tuples.flatTupleOf(var_state), StatesWithMoreIncomingTransitions.instance().getInternalQueryRepresentation()); - // find parentState+(transitiveSubstate, state) - new BinaryTransitiveClosure(body, Tuples.flatTupleOf(var_transitiveSubstate, var_state), ParentState.instance().getInternalQueryRepresentation()); - bodies.add(body); - } - return bodies; - } - } -} diff --git a/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/.gitignore b/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/.gitignore deleted file mode 100644 index 4a5335e..0000000 --- a/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/.gitignore +++ /dev/null @@ -1 +0,0 @@ -*._trace \ No newline at end of file diff --git a/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/APerformanceQueries.java b/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/APerformanceQueries.java deleted file mode 100644 index d7db45d..0000000 --- a/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/APerformanceQueries.java +++ /dev/null @@ -1,361 +0,0 @@ -/** - * Generated from platform:/resource/com.incquerylabs.magicdraw.benchmark/src/main/java/com/incquerylabs/magicdraw/benchmark/queries/APerformanceQueries.vql - */ -package com.incquerylabs.magicdraw.benchmark.queries; - -import com.incquerylabs.magicdraw.benchmark.queries.AllBenchMarkedQueries; -import com.incquerylabs.magicdraw.benchmark.queries.AlphabeticalDependencies; -import com.incquerylabs.magicdraw.benchmark.queries.Blocks; -import com.incquerylabs.magicdraw.benchmark.queries.BlocksOrRequirements; -import com.incquerylabs.magicdraw.benchmark.queries.BlocksOrRequirementsOrConstraints; -import com.incquerylabs.magicdraw.benchmark.queries.CircularDependencies; -import com.incquerylabs.magicdraw.benchmark.queries.Classes; -import com.incquerylabs.magicdraw.benchmark.queries.ComplexNameOfElements; -import com.incquerylabs.magicdraw.benchmark.queries.Dependencies; -import com.incquerylabs.magicdraw.benchmark.queries.DependencyChains; -import com.incquerylabs.magicdraw.benchmark.queries.ElementsWithShortNames; -import com.incquerylabs.magicdraw.benchmark.queries.IncomingTransitions; -import com.incquerylabs.magicdraw.benchmark.queries.LoopTransitionWithTriggerEffectEventNoGuard; -import com.incquerylabs.magicdraw.benchmark.queries.NamedElement; -import com.incquerylabs.magicdraw.benchmark.queries.NamesOfDependencyEndpoints; -import com.incquerylabs.magicdraw.benchmark.queries.NonBlockClasses; -import com.incquerylabs.magicdraw.benchmark.queries.NumberOfSubregions; -import com.incquerylabs.magicdraw.benchmark.queries.NumberOfTransitiveSubstates; -import com.incquerylabs.magicdraw.benchmark.queries.ParentState; -import com.incquerylabs.magicdraw.benchmark.queries.Requirements; -import com.incquerylabs.magicdraw.benchmark.queries.StateWithMostSubstates; -import com.incquerylabs.magicdraw.benchmark.queries.StatesWithMoreIncomingTransitions; -import com.incquerylabs.magicdraw.benchmark.queries.StatesWithShortNames; -import com.incquerylabs.magicdraw.benchmark.queries.Subregions; -import com.incquerylabs.magicdraw.benchmark.queries.TransitionPointingOutOfCompState; -import com.incquerylabs.magicdraw.benchmark.queries.TransitiveSubstates; -import com.incquerylabs.magicdraw.benchmark.queries.TransitiveSubstatesWithCheck; -import com.incquerylabs.magicdraw.benchmark.queries.TransitiveSubstatesWithCheck2; -import com.incquerylabs.magicdraw.benchmark.queries.TransitiveSubstatesWithCheck3; -import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; -import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedPatternGroup; - -/** - * A pattern group formed of all public patterns defined in APerformanceQueries.vql. - * - *

Use the static instance as any {@link interface org.eclipse.viatra.query.runtime.api.IQueryGroup}, to conveniently prepare - * a VIATRA Query engine for matching all patterns originally defined in file APerformanceQueries.vql, - * in order to achieve better performance than one-by-one on-demand matcher initialization. - * - *

From package com.incquerylabs.magicdraw.benchmark.queries, the group contains the definition of the following patterns:

    - *
  • classes
  • - *
  • nonBlockClasses
  • - *
  • blocks
  • - *
  • requirements
  • - *
  • blocksOrRequirements
  • - *
  • blocksOrRequirementsOrConstraints
  • - *
  • namedElement
  • - *
  • complexNameOfElements
  • - *
  • dependencyChains
  • - *
  • circularDependencies
  • - *
  • dependencies
  • - *
  • namesOfDependencyEndpoints
  • - *
  • alphabeticalDependencies
  • - *
  • elementsWithShortNames
  • - *
  • transitionPointingOutOfCompState
  • - *
  • loopTransitionWithTriggerEffectEventNoGuard
  • - *
  • parentState
  • - *
  • subregions
  • - *
  • numberOfSubregions
  • - *
  • statesWithShortNames
  • - *
  • incomingTransitions
  • - *
  • transitiveSubstates
  • - *
  • transitiveSubstatesWithCheck
  • - *
  • statesWithMoreIncomingTransitions
  • - *
  • transitiveSubstatesWithCheck2
  • - *
  • transitiveSubstatesWithCheck3
  • - *
  • numberOfTransitiveSubstates
  • - *
  • stateWithMostSubstates
  • - *
  • allBenchMarkedQueries
  • - *
- * - * @see IQueryGroup - * - */ -@SuppressWarnings("all") -public final class APerformanceQueries extends BaseGeneratedPatternGroup { - /** - * Access the pattern group. - * - * @return the singleton instance of the group - * @throws ViatraQueryRuntimeException if there was an error loading the generated code of pattern specifications - * - */ - public static APerformanceQueries instance() { - if (INSTANCE == null) { - INSTANCE = new APerformanceQueries(); - } - return INSTANCE; - } - - private static APerformanceQueries INSTANCE; - - private APerformanceQueries() { - querySpecifications.add(Classes.instance()); - querySpecifications.add(NonBlockClasses.instance()); - querySpecifications.add(Blocks.instance()); - querySpecifications.add(Requirements.instance()); - querySpecifications.add(BlocksOrRequirements.instance()); - querySpecifications.add(BlocksOrRequirementsOrConstraints.instance()); - querySpecifications.add(NamedElement.instance()); - querySpecifications.add(ComplexNameOfElements.instance()); - querySpecifications.add(DependencyChains.instance()); - querySpecifications.add(CircularDependencies.instance()); - querySpecifications.add(Dependencies.instance()); - querySpecifications.add(NamesOfDependencyEndpoints.instance()); - querySpecifications.add(AlphabeticalDependencies.instance()); - querySpecifications.add(ElementsWithShortNames.instance()); - querySpecifications.add(TransitionPointingOutOfCompState.instance()); - querySpecifications.add(LoopTransitionWithTriggerEffectEventNoGuard.instance()); - querySpecifications.add(ParentState.instance()); - querySpecifications.add(Subregions.instance()); - querySpecifications.add(NumberOfSubregions.instance()); - querySpecifications.add(StatesWithShortNames.instance()); - querySpecifications.add(IncomingTransitions.instance()); - querySpecifications.add(TransitiveSubstates.instance()); - querySpecifications.add(TransitiveSubstatesWithCheck.instance()); - querySpecifications.add(StatesWithMoreIncomingTransitions.instance()); - querySpecifications.add(TransitiveSubstatesWithCheck2.instance()); - querySpecifications.add(TransitiveSubstatesWithCheck3.instance()); - querySpecifications.add(NumberOfTransitiveSubstates.instance()); - querySpecifications.add(StateWithMostSubstates.instance()); - querySpecifications.add(AllBenchMarkedQueries.instance()); - } - - public Classes getClasses() { - return Classes.instance(); - } - - public Classes.Matcher getClasses(final ViatraQueryEngine engine) { - return Classes.Matcher.on(engine); - } - - public NonBlockClasses getNonBlockClasses() { - return NonBlockClasses.instance(); - } - - public NonBlockClasses.Matcher getNonBlockClasses(final ViatraQueryEngine engine) { - return NonBlockClasses.Matcher.on(engine); - } - - public Blocks getBlocks() { - return Blocks.instance(); - } - - public Blocks.Matcher getBlocks(final ViatraQueryEngine engine) { - return Blocks.Matcher.on(engine); - } - - public Requirements getRequirements() { - return Requirements.instance(); - } - - public Requirements.Matcher getRequirements(final ViatraQueryEngine engine) { - return Requirements.Matcher.on(engine); - } - - public BlocksOrRequirements getBlocksOrRequirements() { - return BlocksOrRequirements.instance(); - } - - public BlocksOrRequirements.Matcher getBlocksOrRequirements(final ViatraQueryEngine engine) { - return BlocksOrRequirements.Matcher.on(engine); - } - - public BlocksOrRequirementsOrConstraints getBlocksOrRequirementsOrConstraints() { - return BlocksOrRequirementsOrConstraints.instance(); - } - - public BlocksOrRequirementsOrConstraints.Matcher getBlocksOrRequirementsOrConstraints(final ViatraQueryEngine engine) { - return BlocksOrRequirementsOrConstraints.Matcher.on(engine); - } - - public NamedElement getNamedElement() { - return NamedElement.instance(); - } - - public NamedElement.Matcher getNamedElement(final ViatraQueryEngine engine) { - return NamedElement.Matcher.on(engine); - } - - public ComplexNameOfElements getComplexNameOfElements() { - return ComplexNameOfElements.instance(); - } - - public ComplexNameOfElements.Matcher getComplexNameOfElements(final ViatraQueryEngine engine) { - return ComplexNameOfElements.Matcher.on(engine); - } - - public DependencyChains getDependencyChains() { - return DependencyChains.instance(); - } - - public DependencyChains.Matcher getDependencyChains(final ViatraQueryEngine engine) { - return DependencyChains.Matcher.on(engine); - } - - public CircularDependencies getCircularDependencies() { - return CircularDependencies.instance(); - } - - public CircularDependencies.Matcher getCircularDependencies(final ViatraQueryEngine engine) { - return CircularDependencies.Matcher.on(engine); - } - - public Dependencies getDependencies() { - return Dependencies.instance(); - } - - public Dependencies.Matcher getDependencies(final ViatraQueryEngine engine) { - return Dependencies.Matcher.on(engine); - } - - public NamesOfDependencyEndpoints getNamesOfDependencyEndpoints() { - return NamesOfDependencyEndpoints.instance(); - } - - public NamesOfDependencyEndpoints.Matcher getNamesOfDependencyEndpoints(final ViatraQueryEngine engine) { - return NamesOfDependencyEndpoints.Matcher.on(engine); - } - - public AlphabeticalDependencies getAlphabeticalDependencies() { - return AlphabeticalDependencies.instance(); - } - - public AlphabeticalDependencies.Matcher getAlphabeticalDependencies(final ViatraQueryEngine engine) { - return AlphabeticalDependencies.Matcher.on(engine); - } - - public ElementsWithShortNames getElementsWithShortNames() { - return ElementsWithShortNames.instance(); - } - - public ElementsWithShortNames.Matcher getElementsWithShortNames(final ViatraQueryEngine engine) { - return ElementsWithShortNames.Matcher.on(engine); - } - - public TransitionPointingOutOfCompState getTransitionPointingOutOfCompState() { - return TransitionPointingOutOfCompState.instance(); - } - - public TransitionPointingOutOfCompState.Matcher getTransitionPointingOutOfCompState(final ViatraQueryEngine engine) { - return TransitionPointingOutOfCompState.Matcher.on(engine); - } - - public LoopTransitionWithTriggerEffectEventNoGuard getLoopTransitionWithTriggerEffectEventNoGuard() { - return LoopTransitionWithTriggerEffectEventNoGuard.instance(); - } - - public LoopTransitionWithTriggerEffectEventNoGuard.Matcher getLoopTransitionWithTriggerEffectEventNoGuard(final ViatraQueryEngine engine) { - return LoopTransitionWithTriggerEffectEventNoGuard.Matcher.on(engine); - } - - public ParentState getParentState() { - return ParentState.instance(); - } - - public ParentState.Matcher getParentState(final ViatraQueryEngine engine) { - return ParentState.Matcher.on(engine); - } - - public Subregions getSubregions() { - return Subregions.instance(); - } - - public Subregions.Matcher getSubregions(final ViatraQueryEngine engine) { - return Subregions.Matcher.on(engine); - } - - public NumberOfSubregions getNumberOfSubregions() { - return NumberOfSubregions.instance(); - } - - public NumberOfSubregions.Matcher getNumberOfSubregions(final ViatraQueryEngine engine) { - return NumberOfSubregions.Matcher.on(engine); - } - - public StatesWithShortNames getStatesWithShortNames() { - return StatesWithShortNames.instance(); - } - - public StatesWithShortNames.Matcher getStatesWithShortNames(final ViatraQueryEngine engine) { - return StatesWithShortNames.Matcher.on(engine); - } - - public IncomingTransitions getIncomingTransitions() { - return IncomingTransitions.instance(); - } - - public IncomingTransitions.Matcher getIncomingTransitions(final ViatraQueryEngine engine) { - return IncomingTransitions.Matcher.on(engine); - } - - public TransitiveSubstates getTransitiveSubstates() { - return TransitiveSubstates.instance(); - } - - public TransitiveSubstates.Matcher getTransitiveSubstates(final ViatraQueryEngine engine) { - return TransitiveSubstates.Matcher.on(engine); - } - - public TransitiveSubstatesWithCheck getTransitiveSubstatesWithCheck() { - return TransitiveSubstatesWithCheck.instance(); - } - - public TransitiveSubstatesWithCheck.Matcher getTransitiveSubstatesWithCheck(final ViatraQueryEngine engine) { - return TransitiveSubstatesWithCheck.Matcher.on(engine); - } - - public StatesWithMoreIncomingTransitions getStatesWithMoreIncomingTransitions() { - return StatesWithMoreIncomingTransitions.instance(); - } - - public StatesWithMoreIncomingTransitions.Matcher getStatesWithMoreIncomingTransitions(final ViatraQueryEngine engine) { - return StatesWithMoreIncomingTransitions.Matcher.on(engine); - } - - public TransitiveSubstatesWithCheck2 getTransitiveSubstatesWithCheck2() { - return TransitiveSubstatesWithCheck2.instance(); - } - - public TransitiveSubstatesWithCheck2.Matcher getTransitiveSubstatesWithCheck2(final ViatraQueryEngine engine) { - return TransitiveSubstatesWithCheck2.Matcher.on(engine); - } - - public TransitiveSubstatesWithCheck3 getTransitiveSubstatesWithCheck3() { - return TransitiveSubstatesWithCheck3.instance(); - } - - public TransitiveSubstatesWithCheck3.Matcher getTransitiveSubstatesWithCheck3(final ViatraQueryEngine engine) { - return TransitiveSubstatesWithCheck3.Matcher.on(engine); - } - - public NumberOfTransitiveSubstates getNumberOfTransitiveSubstates() { - return NumberOfTransitiveSubstates.instance(); - } - - public NumberOfTransitiveSubstates.Matcher getNumberOfTransitiveSubstates(final ViatraQueryEngine engine) { - return NumberOfTransitiveSubstates.Matcher.on(engine); - } - - public StateWithMostSubstates getStateWithMostSubstates() { - return StateWithMostSubstates.instance(); - } - - public StateWithMostSubstates.Matcher getStateWithMostSubstates(final ViatraQueryEngine engine) { - return StateWithMostSubstates.Matcher.on(engine); - } - - public AllBenchMarkedQueries getAllBenchMarkedQueries() { - return AllBenchMarkedQueries.instance(); - } - - public AllBenchMarkedQueries.Matcher getAllBenchMarkedQueries(final ViatraQueryEngine engine) { - return AllBenchMarkedQueries.Matcher.on(engine); - } -} diff --git a/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/Activitites.java b/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/Activitites.java deleted file mode 100644 index fe96abf..0000000 --- a/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/Activitites.java +++ /dev/null @@ -1,942 +0,0 @@ -/** - * Generated from platform:/resource/com.incquerylabs.magicdraw.benchmark/src/main/java/com/incquerylabs/magicdraw/benchmark/queries/WarmUpQueries.vql - */ -package com.incquerylabs.magicdraw.benchmark.queries; - -import com.nomagic.uml2.ext.magicdraw.activities.mdfundamentalactivities.Activity; -import com.nomagic.uml2.ext.magicdraw.commonbehaviors.mdcommunications.Event; -import com.nomagic.uml2.ext.magicdraw.commonbehaviors.mdcommunications.Trigger; -import java.util.Arrays; -import java.util.Collection; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.function.Consumer; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import org.apache.log4j.Logger; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.emf.ecore.EDataType; -import org.eclipse.viatra.query.runtime.api.IPatternMatch; -import org.eclipse.viatra.query.runtime.api.IQuerySpecification; -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.api.impl.BaseMatcher; -import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; -import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; -import org.eclipse.viatra.query.runtime.emf.types.EDataTypeInSlotsKey; -import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey; -import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; -import org.eclipse.viatra.query.runtime.matchers.context.common.JavaTransitiveInstancesKey; -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.TypeFilterConstraint; -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.PVisibility; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; -import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; - -/** - * A pattern-specific query specification that can instantiate Matcher in a type-safe way. - * - *

Original source: - *

- *         pattern activitites(activity : Activity, event : Event, eventName : java ^java.lang.String, trigger : Trigger) {
- *         	Activity.event(activity, event);
- *         	Event.name(event, eventName);
- *         	Event._triggerOfEvent(event, trigger);
- *         }
- * 
- * - * @see Matcher - * @see Match - * - */ -@SuppressWarnings("all") -public final class Activitites extends BaseGeneratedEMFQuerySpecification { - /** - * Pattern-specific match representation of the com.incquerylabs.magicdraw.benchmark.queries.activitites pattern, - * to be used in conjunction with {@link Matcher}. - * - *

Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. - * Each instance is a (possibly partial) substitution of pattern parameters, - * usable to represent a match of the pattern in the result of a query, - * or to specify the bound (fixed) input parameters when issuing a query. - * - * @see Matcher - * - */ - public static abstract class Match extends BasePatternMatch { - private Activity fActivity; - - private Event fEvent; - - private String fEventName; - - private Trigger fTrigger; - - private static List parameterNames = makeImmutableList("activity", "event", "eventName", "trigger"); - - private Match(final Activity pActivity, final Event pEvent, final String pEventName, final Trigger pTrigger) { - this.fActivity = pActivity; - this.fEvent = pEvent; - this.fEventName = pEventName; - this.fTrigger = pTrigger; - } - - @Override - public Object get(final String parameterName) { - switch(parameterName) { - case "activity": return this.fActivity; - case "event": return this.fEvent; - case "eventName": return this.fEventName; - case "trigger": return this.fTrigger; - default: return null; - } - } - - @Override - public Object get(final int index) { - switch(index) { - case 0: return this.fActivity; - case 1: return this.fEvent; - case 2: return this.fEventName; - case 3: return this.fTrigger; - default: return null; - } - } - - public Activity getActivity() { - return this.fActivity; - } - - public Event getEvent() { - return this.fEvent; - } - - public String getEventName() { - return this.fEventName; - } - - public Trigger getTrigger() { - return this.fTrigger; - } - - @Override - public boolean set(final String parameterName, final Object newValue) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - if ("activity".equals(parameterName) ) { - this.fActivity = (Activity) newValue; - return true; - } - if ("event".equals(parameterName) ) { - this.fEvent = (Event) newValue; - return true; - } - if ("eventName".equals(parameterName) ) { - this.fEventName = (String) newValue; - return true; - } - if ("trigger".equals(parameterName) ) { - this.fTrigger = (Trigger) newValue; - return true; - } - return false; - } - - public void setActivity(final Activity pActivity) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fActivity = pActivity; - } - - public void setEvent(final Event pEvent) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fEvent = pEvent; - } - - public void setEventName(final String pEventName) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fEventName = pEventName; - } - - public void setTrigger(final Trigger pTrigger) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fTrigger = pTrigger; - } - - @Override - public String patternName() { - return "com.incquerylabs.magicdraw.benchmark.queries.activitites"; - } - - @Override - public List parameterNames() { - return Activitites.Match.parameterNames; - } - - @Override - public Object[] toArray() { - return new Object[]{fActivity, fEvent, fEventName, fTrigger}; - } - - @Override - public Activitites.Match toImmutable() { - return isMutable() ? newMatch(fActivity, fEvent, fEventName, fTrigger) : this; - } - - @Override - public String prettyPrint() { - StringBuilder result = new StringBuilder(); - result.append("\"activity\"=" + prettyPrintValue(fActivity) + ", "); - result.append("\"event\"=" + prettyPrintValue(fEvent) + ", "); - result.append("\"eventName\"=" + prettyPrintValue(fEventName) + ", "); - result.append("\"trigger\"=" + prettyPrintValue(fTrigger)); - return result.toString(); - } - - @Override - public int hashCode() { - return Objects.hash(fActivity, fEvent, fEventName, fTrigger); - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) - return true; - if (obj == null) { - return false; - } - if ((obj instanceof Activitites.Match)) { - Activitites.Match other = (Activitites.Match) obj; - return Objects.equals(fActivity, other.fActivity) && Objects.equals(fEvent, other.fEvent) && Objects.equals(fEventName, other.fEventName) && Objects.equals(fTrigger, other.fTrigger); - } else { - // this should be infrequent - if (!(obj instanceof IPatternMatch)) { - return false; - } - IPatternMatch otherSig = (IPatternMatch) obj; - return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); - } - } - - @Override - public Activitites specification() { - return Activitites.instance(); - } - - /** - * Returns an empty, mutable match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @return the empty match. - * - */ - public static Activitites.Match newEmptyMatch() { - return new Mutable(null, null, null, null); - } - - /** - * Returns a mutable (partial) match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @param pActivity the fixed value of pattern parameter activity, or null if not bound. - * @param pEvent the fixed value of pattern parameter event, or null if not bound. - * @param pEventName the fixed value of pattern parameter eventName, or null if not bound. - * @param pTrigger the fixed value of pattern parameter trigger, or null if not bound. - * @return the new, mutable (partial) match object. - * - */ - public static Activitites.Match newMutableMatch(final Activity pActivity, final Event pEvent, final String pEventName, final Trigger pTrigger) { - return new Mutable(pActivity, pEvent, pEventName, pTrigger); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pActivity the fixed value of pattern parameter activity, or null if not bound. - * @param pEvent the fixed value of pattern parameter event, or null if not bound. - * @param pEventName the fixed value of pattern parameter eventName, or null if not bound. - * @param pTrigger the fixed value of pattern parameter trigger, or null if not bound. - * @return the (partial) match object. - * - */ - public static Activitites.Match newMatch(final Activity pActivity, final Event pEvent, final String pEventName, final Trigger pTrigger) { - return new Immutable(pActivity, pEvent, pEventName, pTrigger); - } - - private static final class Mutable extends Activitites.Match { - Mutable(final Activity pActivity, final Event pEvent, final String pEventName, final Trigger pTrigger) { - super(pActivity, pEvent, pEventName, pTrigger); - } - - @Override - public boolean isMutable() { - return true; - } - } - - private static final class Immutable extends Activitites.Match { - Immutable(final Activity pActivity, final Event pEvent, final String pEventName, final Trigger pTrigger) { - super(pActivity, pEvent, pEventName, pTrigger); - } - - @Override - public boolean isMutable() { - return false; - } - } - } - - /** - * Generated pattern matcher API of the com.incquerylabs.magicdraw.benchmark.queries.activitites pattern, - * providing pattern-specific query methods. - * - *

Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, - * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. - * - *

Matches of the pattern will be represented as {@link Match}. - * - *

Original source: - *

-   * pattern activitites(activity : Activity, event : Event, eventName : java ^java.lang.String, trigger : Trigger) {
-   * 	Activity.event(activity, event);
-   * 	Event.name(event, eventName);
-   * 	Event._triggerOfEvent(event, trigger);
-   * }
-   * 
- * - * @see Match - * @see Activitites - * - */ - public static class Matcher extends BaseMatcher { - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - public static Activitites.Matcher on(final ViatraQueryEngine engine) { - // check if matcher already exists - Matcher matcher = engine.getExistingMatcher(querySpecification()); - if (matcher == null) { - matcher = (Matcher)engine.getMatcher(querySpecification()); - } - return matcher; - } - - /** - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * @return an initialized matcher - * @noreference This method is for internal matcher initialization by the framework, do not call it manually. - * - */ - public static Activitites.Matcher create() { - return new Matcher(); - } - - private static final int POSITION_ACTIVITY = 0; - - private static final int POSITION_EVENT = 1; - - private static final int POSITION_EVENTNAME = 2; - - private static final int POSITION_TRIGGER = 3; - - private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(Activitites.Matcher.class); - - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - private Matcher() { - super(querySpecification()); - } - - /** - * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pActivity the fixed value of pattern parameter activity, or null if not bound. - * @param pEvent the fixed value of pattern parameter event, or null if not bound. - * @param pEventName the fixed value of pattern parameter eventName, or null if not bound. - * @param pTrigger the fixed value of pattern parameter trigger, or null if not bound. - * @return matches represented as a Match object. - * - */ - public Collection getAllMatches(final Activity pActivity, final Event pEvent, final String pEventName, final Trigger pTrigger) { - return rawStreamAllMatches(new Object[]{pActivity, pEvent, pEventName, pTrigger}).collect(Collectors.toSet()); - } - - /** - * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * @param pActivity the fixed value of pattern parameter activity, or null if not bound. - * @param pEvent the fixed value of pattern parameter event, or null if not bound. - * @param pEventName the fixed value of pattern parameter eventName, or null if not bound. - * @param pTrigger the fixed value of pattern parameter trigger, or null if not bound. - * @return a stream of matches represented as a Match object. - * - */ - public Stream streamAllMatches(final Activity pActivity, final Event pEvent, final String pEventName, final Trigger pTrigger) { - return rawStreamAllMatches(new Object[]{pActivity, pEvent, pEventName, pTrigger}); - } - - /** - * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pActivity the fixed value of pattern parameter activity, or null if not bound. - * @param pEvent the fixed value of pattern parameter event, or null if not bound. - * @param pEventName the fixed value of pattern parameter eventName, or null if not bound. - * @param pTrigger the fixed value of pattern parameter trigger, or null if not bound. - * @return a match represented as a Match object, or null if no match is found. - * - */ - public Optional getOneArbitraryMatch(final Activity pActivity, final Event pEvent, final String pEventName, final Trigger pTrigger) { - return rawGetOneArbitraryMatch(new Object[]{pActivity, pEvent, pEventName, pTrigger}); - } - - /** - * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, - * under any possible substitution of the unspecified parameters (if any). - * @param pActivity the fixed value of pattern parameter activity, or null if not bound. - * @param pEvent the fixed value of pattern parameter event, or null if not bound. - * @param pEventName the fixed value of pattern parameter eventName, or null if not bound. - * @param pTrigger the fixed value of pattern parameter trigger, or null if not bound. - * @return true if the input is a valid (partial) match of the pattern. - * - */ - public boolean hasMatch(final Activity pActivity, final Event pEvent, final String pEventName, final Trigger pTrigger) { - return rawHasMatch(new Object[]{pActivity, pEvent, pEventName, pTrigger}); - } - - /** - * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pActivity the fixed value of pattern parameter activity, or null if not bound. - * @param pEvent the fixed value of pattern parameter event, or null if not bound. - * @param pEventName the fixed value of pattern parameter eventName, or null if not bound. - * @param pTrigger the fixed value of pattern parameter trigger, or null if not bound. - * @return the number of pattern matches found. - * - */ - public int countMatches(final Activity pActivity, final Event pEvent, final String pEventName, final Trigger pTrigger) { - return rawCountMatches(new Object[]{pActivity, pEvent, pEventName, pTrigger}); - } - - /** - * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pActivity the fixed value of pattern parameter activity, or null if not bound. - * @param pEvent the fixed value of pattern parameter event, or null if not bound. - * @param pEventName the fixed value of pattern parameter eventName, or null if not bound. - * @param pTrigger the fixed value of pattern parameter trigger, or null if not bound. - * @param processor the action that will process the selected match. - * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked - * - */ - public boolean forOneArbitraryMatch(final Activity pActivity, final Event pEvent, final String pEventName, final Trigger pTrigger, final Consumer processor) { - return rawForOneArbitraryMatch(new Object[]{pActivity, pEvent, pEventName, pTrigger}, processor); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pActivity the fixed value of pattern parameter activity, or null if not bound. - * @param pEvent the fixed value of pattern parameter event, or null if not bound. - * @param pEventName the fixed value of pattern parameter eventName, or null if not bound. - * @param pTrigger the fixed value of pattern parameter trigger, or null if not bound. - * @return the (partial) match object. - * - */ - public Activitites.Match newMatch(final Activity pActivity, final Event pEvent, final String pEventName, final Trigger pTrigger) { - return Activitites.Match.newMatch(pActivity, pEvent, pEventName, pTrigger); - } - - /** - * Retrieve the set of values that occur in matches for activity. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOfactivity(final Object[] parameters) { - return rawStreamAllValues(POSITION_ACTIVITY, parameters).map(Activity.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for activity. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfactivity() { - return rawStreamAllValuesOfactivity(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for activity. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfactivity() { - return rawStreamAllValuesOfactivity(emptyArray()); - } - - /** - * Retrieve the set of values that occur in matches for activity. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfactivity(final Activitites.Match partialMatch) { - return rawStreamAllValuesOfactivity(partialMatch.toArray()); - } - - /** - * Retrieve the set of values that occur in matches for activity. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfactivity(final Event pEvent, final String pEventName, final Trigger pTrigger) { - return rawStreamAllValuesOfactivity(new Object[]{null, pEvent, pEventName, pTrigger}); - } - - /** - * Retrieve the set of values that occur in matches for activity. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfactivity(final Activitites.Match partialMatch) { - return rawStreamAllValuesOfactivity(partialMatch.toArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for activity. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfactivity(final Event pEvent, final String pEventName, final Trigger pTrigger) { - return rawStreamAllValuesOfactivity(new Object[]{null, pEvent, pEventName, pTrigger}).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for event. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOfevent(final Object[] parameters) { - return rawStreamAllValues(POSITION_EVENT, parameters).map(Event.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for event. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfevent() { - return rawStreamAllValuesOfevent(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for event. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfevent() { - return rawStreamAllValuesOfevent(emptyArray()); - } - - /** - * Retrieve the set of values that occur in matches for event. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfevent(final Activitites.Match partialMatch) { - return rawStreamAllValuesOfevent(partialMatch.toArray()); - } - - /** - * Retrieve the set of values that occur in matches for event. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfevent(final Activity pActivity, final String pEventName, final Trigger pTrigger) { - return rawStreamAllValuesOfevent(new Object[]{pActivity, null, pEventName, pTrigger}); - } - - /** - * Retrieve the set of values that occur in matches for event. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfevent(final Activitites.Match partialMatch) { - return rawStreamAllValuesOfevent(partialMatch.toArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for event. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfevent(final Activity pActivity, final String pEventName, final Trigger pTrigger) { - return rawStreamAllValuesOfevent(new Object[]{pActivity, null, pEventName, pTrigger}).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for eventName. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOfeventName(final Object[] parameters) { - return rawStreamAllValues(POSITION_EVENTNAME, parameters).map(String.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for eventName. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfeventName() { - return rawStreamAllValuesOfeventName(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for eventName. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfeventName() { - return rawStreamAllValuesOfeventName(emptyArray()); - } - - /** - * Retrieve the set of values that occur in matches for eventName. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfeventName(final Activitites.Match partialMatch) { - return rawStreamAllValuesOfeventName(partialMatch.toArray()); - } - - /** - * Retrieve the set of values that occur in matches for eventName. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfeventName(final Activity pActivity, final Event pEvent, final Trigger pTrigger) { - return rawStreamAllValuesOfeventName(new Object[]{pActivity, pEvent, null, pTrigger}); - } - - /** - * Retrieve the set of values that occur in matches for eventName. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfeventName(final Activitites.Match partialMatch) { - return rawStreamAllValuesOfeventName(partialMatch.toArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for eventName. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfeventName(final Activity pActivity, final Event pEvent, final Trigger pTrigger) { - return rawStreamAllValuesOfeventName(new Object[]{pActivity, pEvent, null, pTrigger}).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for trigger. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOftrigger(final Object[] parameters) { - return rawStreamAllValues(POSITION_TRIGGER, parameters).map(Trigger.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for trigger. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOftrigger() { - return rawStreamAllValuesOftrigger(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for trigger. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOftrigger() { - return rawStreamAllValuesOftrigger(emptyArray()); - } - - /** - * Retrieve the set of values that occur in matches for trigger. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOftrigger(final Activitites.Match partialMatch) { - return rawStreamAllValuesOftrigger(partialMatch.toArray()); - } - - /** - * Retrieve the set of values that occur in matches for trigger. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOftrigger(final Activity pActivity, final Event pEvent, final String pEventName) { - return rawStreamAllValuesOftrigger(new Object[]{pActivity, pEvent, pEventName, null}); - } - - /** - * Retrieve the set of values that occur in matches for trigger. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOftrigger(final Activitites.Match partialMatch) { - return rawStreamAllValuesOftrigger(partialMatch.toArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for trigger. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOftrigger(final Activity pActivity, final Event pEvent, final String pEventName) { - return rawStreamAllValuesOftrigger(new Object[]{pActivity, pEvent, pEventName, null}).collect(Collectors.toSet()); - } - - @Override - protected Activitites.Match tupleToMatch(final Tuple t) { - try { - return Activitites.Match.newMatch((Activity) t.get(POSITION_ACTIVITY), (Event) t.get(POSITION_EVENT), (String) t.get(POSITION_EVENTNAME), (Trigger) t.get(POSITION_TRIGGER)); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in tuple not properly typed!",e); - return null; - } - } - - @Override - protected Activitites.Match arrayToMatch(final Object[] match) { - try { - return Activitites.Match.newMatch((Activity) match[POSITION_ACTIVITY], (Event) match[POSITION_EVENT], (String) match[POSITION_EVENTNAME], (Trigger) match[POSITION_TRIGGER]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - @Override - protected Activitites.Match arrayToMatchMutable(final Object[] match) { - try { - return Activitites.Match.newMutableMatch((Activity) match[POSITION_ACTIVITY], (Event) match[POSITION_EVENT], (String) match[POSITION_EVENTNAME], (Trigger) match[POSITION_TRIGGER]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - /** - * @return the singleton instance of the query specification of this pattern - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static IQuerySpecification querySpecification() { - return Activitites.instance(); - } - } - - private Activitites() { - super(GeneratedPQuery.INSTANCE); - } - - /** - * @return the singleton instance of the query specification - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static Activitites instance() { - try{ - return LazyHolder.INSTANCE; - } catch (ExceptionInInitializerError err) { - throw processInitializerError(err); - } - } - - @Override - protected Activitites.Matcher instantiate(final ViatraQueryEngine engine) { - return Activitites.Matcher.on(engine); - } - - @Override - public Activitites.Matcher instantiate() { - return Activitites.Matcher.create(); - } - - @Override - public Activitites.Match newEmptyMatch() { - return Activitites.Match.newEmptyMatch(); - } - - @Override - public Activitites.Match newMatch(final Object... parameters) { - return Activitites.Match.newMatch((com.nomagic.uml2.ext.magicdraw.activities.mdfundamentalactivities.Activity) parameters[0], (com.nomagic.uml2.ext.magicdraw.commonbehaviors.mdcommunications.Event) parameters[1], (java.lang.String) parameters[2], (com.nomagic.uml2.ext.magicdraw.commonbehaviors.mdcommunications.Trigger) parameters[3]); - } - - /** - * Inner class allowing the singleton instance of {@link Activitites} to be created - * not at the class load time of the outer class, - * but rather at the first call to {@link Activitites#instance()}. - * - *

This workaround is required e.g. to support recursion. - * - */ - private static class LazyHolder { - private static final Activitites INSTANCE = new Activitites(); - - /** - * Statically initializes the query specification after the field {@link #INSTANCE} is assigned. - * This initialization order is required to support indirect recursion. - * - *

The static initializer is defined using a helper field to work around limitations of the code generator. - * - */ - private static final Object STATIC_INITIALIZER = ensureInitialized(); - - public static Object ensureInitialized() { - INSTANCE.ensureInitializedInternal(); - return null; - } - } - - private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { - private static final Activitites.GeneratedPQuery INSTANCE = new GeneratedPQuery(); - - private final PParameter parameter_activity = new PParameter("activity", "com.nomagic.uml2.ext.magicdraw.activities.mdfundamentalactivities.Activity", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.nomagic.com/magicdraw/UML/2.5.1", "Activity")), PParameterDirection.INOUT); - - private final PParameter parameter_event = new PParameter("event", "com.nomagic.uml2.ext.magicdraw.commonbehaviors.mdcommunications.Event", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.nomagic.com/magicdraw/UML/2.5.1", "Event")), PParameterDirection.INOUT); - - private final PParameter parameter_eventName = new PParameter("eventName", "java.lang.String", new JavaTransitiveInstancesKey(java.lang.String.class), PParameterDirection.INOUT); - - private final PParameter parameter_trigger = new PParameter("trigger", "com.nomagic.uml2.ext.magicdraw.commonbehaviors.mdcommunications.Trigger", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.nomagic.com/magicdraw/UML/2.5.1", "Trigger")), PParameterDirection.INOUT); - - private final List parameters = Arrays.asList(parameter_activity, parameter_event, parameter_eventName, parameter_trigger); - - private GeneratedPQuery() { - super(PVisibility.PUBLIC); - } - - @Override - public String getFullyQualifiedName() { - return "com.incquerylabs.magicdraw.benchmark.queries.activitites"; - } - - @Override - public List getParameterNames() { - return Arrays.asList("activity","event","eventName","trigger"); - } - - @Override - public List getParameters() { - return parameters; - } - - @Override - public Set doGetContainedBodies() { - setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); - Set bodies = new LinkedHashSet<>(); - { - PBody body = new PBody(this); - PVariable var_activity = body.getOrCreateVariableByName("activity"); - PVariable var_event = body.getOrCreateVariableByName("event"); - PVariable var_eventName = body.getOrCreateVariableByName("eventName"); - PVariable var_trigger = body.getOrCreateVariableByName("trigger"); - new TypeConstraint(body, Tuples.flatTupleOf(var_activity), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Activity"))); - new TypeConstraint(body, Tuples.flatTupleOf(var_event), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Event"))); - new TypeFilterConstraint(body, Tuples.flatTupleOf(var_eventName), new JavaTransitiveInstancesKey(java.lang.String.class)); - new TypeConstraint(body, Tuples.flatTupleOf(var_trigger), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Trigger"))); - body.setSymbolicParameters(Arrays.asList( - new ExportedParameter(body, var_activity, parameter_activity), - new ExportedParameter(body, var_event, parameter_event), - new ExportedParameter(body, var_eventName, parameter_eventName), - new ExportedParameter(body, var_trigger, parameter_trigger) - )); - // Activity.event(activity, event) - new TypeConstraint(body, Tuples.flatTupleOf(var_activity), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Activity"))); - PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_activity, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Behavior", "event"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Event"))); - new Equality(body, var__virtual_0_, var_event); - // Event.name(event, eventName) - new TypeConstraint(body, Tuples.flatTupleOf(var_event), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Event"))); - PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_event, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "NamedElement", "name"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "String"))); - new Equality(body, var__virtual_1_, var_eventName); - // Event._triggerOfEvent(event, trigger) - new TypeConstraint(body, Tuples.flatTupleOf(var_event), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Event"))); - PVariable var__virtual_2_ = body.getOrCreateVariableByName(".virtual{2}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_event, var__virtual_2_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Event", "_triggerOfEvent"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_2_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Trigger"))); - new Equality(body, var__virtual_2_, var_trigger); - bodies.add(body); - } - return bodies; - } - } -} diff --git a/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/ActorGeneralization.java b/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/ActorGeneralization.java deleted file mode 100644 index ecc2250..0000000 --- a/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/ActorGeneralization.java +++ /dev/null @@ -1,708 +0,0 @@ -/** - * Generated from platform:/resource/com.incquerylabs.magicdraw.benchmark/src/main/java/com/incquerylabs/magicdraw/benchmark/queries/WarmUpQueries.vql - */ -package com.incquerylabs.magicdraw.benchmark.queries; - -import com.nomagic.uml2.ext.magicdraw.classes.mdpowertypes.GeneralizationSet; -import com.nomagic.uml2.ext.magicdraw.mdusecases.Actor; -import java.util.Arrays; -import java.util.Collection; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.function.Consumer; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import org.apache.log4j.Logger; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.viatra.query.runtime.api.IPatternMatch; -import org.eclipse.viatra.query.runtime.api.IQuerySpecification; -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.api.impl.BaseMatcher; -import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; -import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; -import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey; -import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; -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.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.PVisibility; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; -import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; - -/** - * A pattern-specific query specification that can instantiate Matcher in a type-safe way. - * - *

Original source: - *

- *         pattern actorGeneralization(actor : Actor, generalActor : GeneralizationSet) {
- *         	Actor.generalization.generalizationSet(actor, generalActor);
- *         }
- * 
- * - * @see Matcher - * @see Match - * - */ -@SuppressWarnings("all") -public final class ActorGeneralization extends BaseGeneratedEMFQuerySpecification { - /** - * Pattern-specific match representation of the com.incquerylabs.magicdraw.benchmark.queries.actorGeneralization pattern, - * to be used in conjunction with {@link Matcher}. - * - *

Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. - * Each instance is a (possibly partial) substitution of pattern parameters, - * usable to represent a match of the pattern in the result of a query, - * or to specify the bound (fixed) input parameters when issuing a query. - * - * @see Matcher - * - */ - public static abstract class Match extends BasePatternMatch { - private Actor fActor; - - private GeneralizationSet fGeneralActor; - - private static List parameterNames = makeImmutableList("actor", "generalActor"); - - private Match(final Actor pActor, final GeneralizationSet pGeneralActor) { - this.fActor = pActor; - this.fGeneralActor = pGeneralActor; - } - - @Override - public Object get(final String parameterName) { - switch(parameterName) { - case "actor": return this.fActor; - case "generalActor": return this.fGeneralActor; - default: return null; - } - } - - @Override - public Object get(final int index) { - switch(index) { - case 0: return this.fActor; - case 1: return this.fGeneralActor; - default: return null; - } - } - - public Actor getActor() { - return this.fActor; - } - - public GeneralizationSet getGeneralActor() { - return this.fGeneralActor; - } - - @Override - public boolean set(final String parameterName, final Object newValue) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - if ("actor".equals(parameterName) ) { - this.fActor = (Actor) newValue; - return true; - } - if ("generalActor".equals(parameterName) ) { - this.fGeneralActor = (GeneralizationSet) newValue; - return true; - } - return false; - } - - public void setActor(final Actor pActor) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fActor = pActor; - } - - public void setGeneralActor(final GeneralizationSet pGeneralActor) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fGeneralActor = pGeneralActor; - } - - @Override - public String patternName() { - return "com.incquerylabs.magicdraw.benchmark.queries.actorGeneralization"; - } - - @Override - public List parameterNames() { - return ActorGeneralization.Match.parameterNames; - } - - @Override - public Object[] toArray() { - return new Object[]{fActor, fGeneralActor}; - } - - @Override - public ActorGeneralization.Match toImmutable() { - return isMutable() ? newMatch(fActor, fGeneralActor) : this; - } - - @Override - public String prettyPrint() { - StringBuilder result = new StringBuilder(); - result.append("\"actor\"=" + prettyPrintValue(fActor) + ", "); - result.append("\"generalActor\"=" + prettyPrintValue(fGeneralActor)); - return result.toString(); - } - - @Override - public int hashCode() { - return Objects.hash(fActor, fGeneralActor); - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) - return true; - if (obj == null) { - return false; - } - if ((obj instanceof ActorGeneralization.Match)) { - ActorGeneralization.Match other = (ActorGeneralization.Match) obj; - return Objects.equals(fActor, other.fActor) && Objects.equals(fGeneralActor, other.fGeneralActor); - } else { - // this should be infrequent - if (!(obj instanceof IPatternMatch)) { - return false; - } - IPatternMatch otherSig = (IPatternMatch) obj; - return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); - } - } - - @Override - public ActorGeneralization specification() { - return ActorGeneralization.instance(); - } - - /** - * Returns an empty, mutable match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @return the empty match. - * - */ - public static ActorGeneralization.Match newEmptyMatch() { - return new Mutable(null, null); - } - - /** - * Returns a mutable (partial) match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @param pActor the fixed value of pattern parameter actor, or null if not bound. - * @param pGeneralActor the fixed value of pattern parameter generalActor, or null if not bound. - * @return the new, mutable (partial) match object. - * - */ - public static ActorGeneralization.Match newMutableMatch(final Actor pActor, final GeneralizationSet pGeneralActor) { - return new Mutable(pActor, pGeneralActor); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pActor the fixed value of pattern parameter actor, or null if not bound. - * @param pGeneralActor the fixed value of pattern parameter generalActor, or null if not bound. - * @return the (partial) match object. - * - */ - public static ActorGeneralization.Match newMatch(final Actor pActor, final GeneralizationSet pGeneralActor) { - return new Immutable(pActor, pGeneralActor); - } - - private static final class Mutable extends ActorGeneralization.Match { - Mutable(final Actor pActor, final GeneralizationSet pGeneralActor) { - super(pActor, pGeneralActor); - } - - @Override - public boolean isMutable() { - return true; - } - } - - private static final class Immutable extends ActorGeneralization.Match { - Immutable(final Actor pActor, final GeneralizationSet pGeneralActor) { - super(pActor, pGeneralActor); - } - - @Override - public boolean isMutable() { - return false; - } - } - } - - /** - * Generated pattern matcher API of the com.incquerylabs.magicdraw.benchmark.queries.actorGeneralization pattern, - * providing pattern-specific query methods. - * - *

Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, - * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. - * - *

Matches of the pattern will be represented as {@link Match}. - * - *

Original source: - *

-   * pattern actorGeneralization(actor : Actor, generalActor : GeneralizationSet) {
-   * 	Actor.generalization.generalizationSet(actor, generalActor);
-   * }
-   * 
- * - * @see Match - * @see ActorGeneralization - * - */ - public static class Matcher extends BaseMatcher { - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - public static ActorGeneralization.Matcher on(final ViatraQueryEngine engine) { - // check if matcher already exists - Matcher matcher = engine.getExistingMatcher(querySpecification()); - if (matcher == null) { - matcher = (Matcher)engine.getMatcher(querySpecification()); - } - return matcher; - } - - /** - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * @return an initialized matcher - * @noreference This method is for internal matcher initialization by the framework, do not call it manually. - * - */ - public static ActorGeneralization.Matcher create() { - return new Matcher(); - } - - private static final int POSITION_ACTOR = 0; - - private static final int POSITION_GENERALACTOR = 1; - - private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(ActorGeneralization.Matcher.class); - - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - private Matcher() { - super(querySpecification()); - } - - /** - * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pActor the fixed value of pattern parameter actor, or null if not bound. - * @param pGeneralActor the fixed value of pattern parameter generalActor, or null if not bound. - * @return matches represented as a Match object. - * - */ - public Collection getAllMatches(final Actor pActor, final GeneralizationSet pGeneralActor) { - return rawStreamAllMatches(new Object[]{pActor, pGeneralActor}).collect(Collectors.toSet()); - } - - /** - * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * @param pActor the fixed value of pattern parameter actor, or null if not bound. - * @param pGeneralActor the fixed value of pattern parameter generalActor, or null if not bound. - * @return a stream of matches represented as a Match object. - * - */ - public Stream streamAllMatches(final Actor pActor, final GeneralizationSet pGeneralActor) { - return rawStreamAllMatches(new Object[]{pActor, pGeneralActor}); - } - - /** - * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pActor the fixed value of pattern parameter actor, or null if not bound. - * @param pGeneralActor the fixed value of pattern parameter generalActor, or null if not bound. - * @return a match represented as a Match object, or null if no match is found. - * - */ - public Optional getOneArbitraryMatch(final Actor pActor, final GeneralizationSet pGeneralActor) { - return rawGetOneArbitraryMatch(new Object[]{pActor, pGeneralActor}); - } - - /** - * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, - * under any possible substitution of the unspecified parameters (if any). - * @param pActor the fixed value of pattern parameter actor, or null if not bound. - * @param pGeneralActor the fixed value of pattern parameter generalActor, or null if not bound. - * @return true if the input is a valid (partial) match of the pattern. - * - */ - public boolean hasMatch(final Actor pActor, final GeneralizationSet pGeneralActor) { - return rawHasMatch(new Object[]{pActor, pGeneralActor}); - } - - /** - * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pActor the fixed value of pattern parameter actor, or null if not bound. - * @param pGeneralActor the fixed value of pattern parameter generalActor, or null if not bound. - * @return the number of pattern matches found. - * - */ - public int countMatches(final Actor pActor, final GeneralizationSet pGeneralActor) { - return rawCountMatches(new Object[]{pActor, pGeneralActor}); - } - - /** - * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pActor the fixed value of pattern parameter actor, or null if not bound. - * @param pGeneralActor the fixed value of pattern parameter generalActor, or null if not bound. - * @param processor the action that will process the selected match. - * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked - * - */ - public boolean forOneArbitraryMatch(final Actor pActor, final GeneralizationSet pGeneralActor, final Consumer processor) { - return rawForOneArbitraryMatch(new Object[]{pActor, pGeneralActor}, processor); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pActor the fixed value of pattern parameter actor, or null if not bound. - * @param pGeneralActor the fixed value of pattern parameter generalActor, or null if not bound. - * @return the (partial) match object. - * - */ - public ActorGeneralization.Match newMatch(final Actor pActor, final GeneralizationSet pGeneralActor) { - return ActorGeneralization.Match.newMatch(pActor, pGeneralActor); - } - - /** - * Retrieve the set of values that occur in matches for actor. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOfactor(final Object[] parameters) { - return rawStreamAllValues(POSITION_ACTOR, parameters).map(Actor.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for actor. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfactor() { - return rawStreamAllValuesOfactor(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for actor. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfactor() { - return rawStreamAllValuesOfactor(emptyArray()); - } - - /** - * Retrieve the set of values that occur in matches for actor. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfactor(final ActorGeneralization.Match partialMatch) { - return rawStreamAllValuesOfactor(partialMatch.toArray()); - } - - /** - * Retrieve the set of values that occur in matches for actor. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfactor(final GeneralizationSet pGeneralActor) { - return rawStreamAllValuesOfactor(new Object[]{null, pGeneralActor}); - } - - /** - * Retrieve the set of values that occur in matches for actor. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfactor(final ActorGeneralization.Match partialMatch) { - return rawStreamAllValuesOfactor(partialMatch.toArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for actor. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfactor(final GeneralizationSet pGeneralActor) { - return rawStreamAllValuesOfactor(new Object[]{null, pGeneralActor}).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for generalActor. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOfgeneralActor(final Object[] parameters) { - return rawStreamAllValues(POSITION_GENERALACTOR, parameters).map(GeneralizationSet.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for generalActor. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfgeneralActor() { - return rawStreamAllValuesOfgeneralActor(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for generalActor. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfgeneralActor() { - return rawStreamAllValuesOfgeneralActor(emptyArray()); - } - - /** - * Retrieve the set of values that occur in matches for generalActor. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfgeneralActor(final ActorGeneralization.Match partialMatch) { - return rawStreamAllValuesOfgeneralActor(partialMatch.toArray()); - } - - /** - * Retrieve the set of values that occur in matches for generalActor. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfgeneralActor(final Actor pActor) { - return rawStreamAllValuesOfgeneralActor(new Object[]{pActor, null}); - } - - /** - * Retrieve the set of values that occur in matches for generalActor. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfgeneralActor(final ActorGeneralization.Match partialMatch) { - return rawStreamAllValuesOfgeneralActor(partialMatch.toArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for generalActor. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfgeneralActor(final Actor pActor) { - return rawStreamAllValuesOfgeneralActor(new Object[]{pActor, null}).collect(Collectors.toSet()); - } - - @Override - protected ActorGeneralization.Match tupleToMatch(final Tuple t) { - try { - return ActorGeneralization.Match.newMatch((Actor) t.get(POSITION_ACTOR), (GeneralizationSet) t.get(POSITION_GENERALACTOR)); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in tuple not properly typed!",e); - return null; - } - } - - @Override - protected ActorGeneralization.Match arrayToMatch(final Object[] match) { - try { - return ActorGeneralization.Match.newMatch((Actor) match[POSITION_ACTOR], (GeneralizationSet) match[POSITION_GENERALACTOR]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - @Override - protected ActorGeneralization.Match arrayToMatchMutable(final Object[] match) { - try { - return ActorGeneralization.Match.newMutableMatch((Actor) match[POSITION_ACTOR], (GeneralizationSet) match[POSITION_GENERALACTOR]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - /** - * @return the singleton instance of the query specification of this pattern - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static IQuerySpecification querySpecification() { - return ActorGeneralization.instance(); - } - } - - private ActorGeneralization() { - super(GeneratedPQuery.INSTANCE); - } - - /** - * @return the singleton instance of the query specification - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static ActorGeneralization instance() { - try{ - return LazyHolder.INSTANCE; - } catch (ExceptionInInitializerError err) { - throw processInitializerError(err); - } - } - - @Override - protected ActorGeneralization.Matcher instantiate(final ViatraQueryEngine engine) { - return ActorGeneralization.Matcher.on(engine); - } - - @Override - public ActorGeneralization.Matcher instantiate() { - return ActorGeneralization.Matcher.create(); - } - - @Override - public ActorGeneralization.Match newEmptyMatch() { - return ActorGeneralization.Match.newEmptyMatch(); - } - - @Override - public ActorGeneralization.Match newMatch(final Object... parameters) { - return ActorGeneralization.Match.newMatch((com.nomagic.uml2.ext.magicdraw.mdusecases.Actor) parameters[0], (com.nomagic.uml2.ext.magicdraw.classes.mdpowertypes.GeneralizationSet) parameters[1]); - } - - /** - * Inner class allowing the singleton instance of {@link ActorGeneralization} to be created - * not at the class load time of the outer class, - * but rather at the first call to {@link ActorGeneralization#instance()}. - * - *

This workaround is required e.g. to support recursion. - * - */ - private static class LazyHolder { - private static final ActorGeneralization INSTANCE = new ActorGeneralization(); - - /** - * Statically initializes the query specification after the field {@link #INSTANCE} is assigned. - * This initialization order is required to support indirect recursion. - * - *

The static initializer is defined using a helper field to work around limitations of the code generator. - * - */ - private static final Object STATIC_INITIALIZER = ensureInitialized(); - - public static Object ensureInitialized() { - INSTANCE.ensureInitializedInternal(); - return null; - } - } - - private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { - private static final ActorGeneralization.GeneratedPQuery INSTANCE = new GeneratedPQuery(); - - private final PParameter parameter_actor = new PParameter("actor", "com.nomagic.uml2.ext.magicdraw.mdusecases.Actor", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.nomagic.com/magicdraw/UML/2.5.1", "Actor")), PParameterDirection.INOUT); - - private final PParameter parameter_generalActor = new PParameter("generalActor", "com.nomagic.uml2.ext.magicdraw.classes.mdpowertypes.GeneralizationSet", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.nomagic.com/magicdraw/UML/2.5.1", "GeneralizationSet")), PParameterDirection.INOUT); - - private final List parameters = Arrays.asList(parameter_actor, parameter_generalActor); - - private GeneratedPQuery() { - super(PVisibility.PUBLIC); - } - - @Override - public String getFullyQualifiedName() { - return "com.incquerylabs.magicdraw.benchmark.queries.actorGeneralization"; - } - - @Override - public List getParameterNames() { - return Arrays.asList("actor","generalActor"); - } - - @Override - public List getParameters() { - return parameters; - } - - @Override - public Set doGetContainedBodies() { - setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); - Set bodies = new LinkedHashSet<>(); - { - PBody body = new PBody(this); - PVariable var_actor = body.getOrCreateVariableByName("actor"); - PVariable var_generalActor = body.getOrCreateVariableByName("generalActor"); - new TypeConstraint(body, Tuples.flatTupleOf(var_actor), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Actor"))); - new TypeConstraint(body, Tuples.flatTupleOf(var_generalActor), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "GeneralizationSet"))); - body.setSymbolicParameters(Arrays.asList( - new ExportedParameter(body, var_actor, parameter_actor), - new ExportedParameter(body, var_generalActor, parameter_generalActor) - )); - // Actor.generalization.generalizationSet(actor, generalActor) - new TypeConstraint(body, Tuples.flatTupleOf(var_actor), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Actor"))); - PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_actor, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Classifier", "generalization"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Generalization"))); - PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}"); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Generalization", "generalizationSet"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "GeneralizationSet"))); - new Equality(body, var__virtual_1_, var_generalActor); - bodies.add(body); - } - return bodies; - } - } -} diff --git a/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/AllBenchMarkedQueries.java b/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/AllBenchMarkedQueries.java deleted file mode 100644 index 146a77a..0000000 --- a/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/AllBenchMarkedQueries.java +++ /dev/null @@ -1,634 +0,0 @@ -/** - * Generated from platform:/resource/com.incquerylabs.magicdraw.benchmark/src/main/java/com/incquerylabs/magicdraw/benchmark/queries/APerformanceQueries.vql - */ -package com.incquerylabs.magicdraw.benchmark.queries; - -import com.incquerylabs.magicdraw.benchmark.queries.AlphabeticalDependencies; -import com.incquerylabs.magicdraw.benchmark.queries.BlocksOrRequirementsOrConstraints; -import com.incquerylabs.magicdraw.benchmark.queries.CircularDependencies; -import com.incquerylabs.magicdraw.benchmark.queries.LoopTransitionWithTriggerEffectEventNoGuard; -import com.incquerylabs.magicdraw.benchmark.queries.TransitionPointingOutOfCompState; -import com.incquerylabs.magicdraw.benchmark.queries.TransitiveSubstatesWithCheck3; -import com.nomagic.uml2.ext.magicdraw.classes.mdkernel.NamedElement; -import java.util.Arrays; -import java.util.Collection; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.function.Consumer; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import org.apache.log4j.Logger; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.viatra.query.runtime.api.IPatternMatch; -import org.eclipse.viatra.query.runtime.api.IQuerySpecification; -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.api.impl.BaseMatcher; -import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; -import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; -import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; -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.ExportedParameter; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.PositivePatternCall; -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.PVisibility; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; -import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; - -/** - * A pattern-specific query specification that can instantiate Matcher in a type-safe way. - * - *

Original source: - *

- *         pattern allBenchMarkedQueries(param : NamedElement) {
- *         	find blocksOrRequirementsOrConstraints(param);
- *         } or {
- *         	find transitiveSubstatesWithCheck3(param, _);
- *         } or {
- *         	find alphabeticalDependencies(param, _);
- *         } or {
- *         	find circularDependencies(param);
- *         } or {
- *         	find loopTransitionWithTriggerEffectEventNoGuard(param, _, _, _, _);
- *         } or {
- *         	find transitionPointingOutOfCompState(param, _, _);
- *         }
- * 
- * - * @see Matcher - * @see Match - * - */ -@SuppressWarnings("all") -public final class AllBenchMarkedQueries extends BaseGeneratedEMFQuerySpecification { - /** - * Pattern-specific match representation of the com.incquerylabs.magicdraw.benchmark.queries.allBenchMarkedQueries pattern, - * to be used in conjunction with {@link Matcher}. - * - *

Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. - * Each instance is a (possibly partial) substitution of pattern parameters, - * usable to represent a match of the pattern in the result of a query, - * or to specify the bound (fixed) input parameters when issuing a query. - * - * @see Matcher - * - */ - public static abstract class Match extends BasePatternMatch { - private NamedElement fParam; - - private static List parameterNames = makeImmutableList("param"); - - private Match(final NamedElement pParam) { - this.fParam = pParam; - } - - @Override - public Object get(final String parameterName) { - switch(parameterName) { - case "param": return this.fParam; - default: return null; - } - } - - @Override - public Object get(final int index) { - switch(index) { - case 0: return this.fParam; - default: return null; - } - } - - public NamedElement getParam() { - return this.fParam; - } - - @Override - public boolean set(final String parameterName, final Object newValue) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - if ("param".equals(parameterName) ) { - this.fParam = (NamedElement) newValue; - return true; - } - return false; - } - - public void setParam(final NamedElement pParam) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fParam = pParam; - } - - @Override - public String patternName() { - return "com.incquerylabs.magicdraw.benchmark.queries.allBenchMarkedQueries"; - } - - @Override - public List parameterNames() { - return AllBenchMarkedQueries.Match.parameterNames; - } - - @Override - public Object[] toArray() { - return new Object[]{fParam}; - } - - @Override - public AllBenchMarkedQueries.Match toImmutable() { - return isMutable() ? newMatch(fParam) : this; - } - - @Override - public String prettyPrint() { - StringBuilder result = new StringBuilder(); - result.append("\"param\"=" + prettyPrintValue(fParam)); - return result.toString(); - } - - @Override - public int hashCode() { - return Objects.hash(fParam); - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) - return true; - if (obj == null) { - return false; - } - if ((obj instanceof AllBenchMarkedQueries.Match)) { - AllBenchMarkedQueries.Match other = (AllBenchMarkedQueries.Match) obj; - return Objects.equals(fParam, other.fParam); - } else { - // this should be infrequent - if (!(obj instanceof IPatternMatch)) { - return false; - } - IPatternMatch otherSig = (IPatternMatch) obj; - return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); - } - } - - @Override - public AllBenchMarkedQueries specification() { - return AllBenchMarkedQueries.instance(); - } - - /** - * Returns an empty, mutable match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @return the empty match. - * - */ - public static AllBenchMarkedQueries.Match newEmptyMatch() { - return new Mutable(null); - } - - /** - * Returns a mutable (partial) match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @param pParam the fixed value of pattern parameter param, or null if not bound. - * @return the new, mutable (partial) match object. - * - */ - public static AllBenchMarkedQueries.Match newMutableMatch(final NamedElement pParam) { - return new Mutable(pParam); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pParam the fixed value of pattern parameter param, or null if not bound. - * @return the (partial) match object. - * - */ - public static AllBenchMarkedQueries.Match newMatch(final NamedElement pParam) { - return new Immutable(pParam); - } - - private static final class Mutable extends AllBenchMarkedQueries.Match { - Mutable(final NamedElement pParam) { - super(pParam); - } - - @Override - public boolean isMutable() { - return true; - } - } - - private static final class Immutable extends AllBenchMarkedQueries.Match { - Immutable(final NamedElement pParam) { - super(pParam); - } - - @Override - public boolean isMutable() { - return false; - } - } - } - - /** - * Generated pattern matcher API of the com.incquerylabs.magicdraw.benchmark.queries.allBenchMarkedQueries pattern, - * providing pattern-specific query methods. - * - *

Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, - * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. - * - *

Matches of the pattern will be represented as {@link Match}. - * - *

Original source: - *

-   * pattern allBenchMarkedQueries(param : NamedElement) {
-   * 	find blocksOrRequirementsOrConstraints(param);
-   * } or {
-   * 	find transitiveSubstatesWithCheck3(param, _);
-   * } or {
-   * 	find alphabeticalDependencies(param, _);
-   * } or {
-   * 	find circularDependencies(param);
-   * } or {
-   * 	find loopTransitionWithTriggerEffectEventNoGuard(param, _, _, _, _);
-   * } or {
-   * 	find transitionPointingOutOfCompState(param, _, _);
-   * }
-   * 
- * - * @see Match - * @see AllBenchMarkedQueries - * - */ - public static class Matcher extends BaseMatcher { - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - public static AllBenchMarkedQueries.Matcher on(final ViatraQueryEngine engine) { - // check if matcher already exists - Matcher matcher = engine.getExistingMatcher(querySpecification()); - if (matcher == null) { - matcher = (Matcher)engine.getMatcher(querySpecification()); - } - return matcher; - } - - /** - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * @return an initialized matcher - * @noreference This method is for internal matcher initialization by the framework, do not call it manually. - * - */ - public static AllBenchMarkedQueries.Matcher create() { - return new Matcher(); - } - - private static final int POSITION_PARAM = 0; - - private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(AllBenchMarkedQueries.Matcher.class); - - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - private Matcher() { - super(querySpecification()); - } - - /** - * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pParam the fixed value of pattern parameter param, or null if not bound. - * @return matches represented as a Match object. - * - */ - public Collection getAllMatches(final NamedElement pParam) { - return rawStreamAllMatches(new Object[]{pParam}).collect(Collectors.toSet()); - } - - /** - * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * @param pParam the fixed value of pattern parameter param, or null if not bound. - * @return a stream of matches represented as a Match object. - * - */ - public Stream streamAllMatches(final NamedElement pParam) { - return rawStreamAllMatches(new Object[]{pParam}); - } - - /** - * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pParam the fixed value of pattern parameter param, or null if not bound. - * @return a match represented as a Match object, or null if no match is found. - * - */ - public Optional getOneArbitraryMatch(final NamedElement pParam) { - return rawGetOneArbitraryMatch(new Object[]{pParam}); - } - - /** - * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, - * under any possible substitution of the unspecified parameters (if any). - * @param pParam the fixed value of pattern parameter param, or null if not bound. - * @return true if the input is a valid (partial) match of the pattern. - * - */ - public boolean hasMatch(final NamedElement pParam) { - return rawHasMatch(new Object[]{pParam}); - } - - /** - * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pParam the fixed value of pattern parameter param, or null if not bound. - * @return the number of pattern matches found. - * - */ - public int countMatches(final NamedElement pParam) { - return rawCountMatches(new Object[]{pParam}); - } - - /** - * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pParam the fixed value of pattern parameter param, or null if not bound. - * @param processor the action that will process the selected match. - * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked - * - */ - public boolean forOneArbitraryMatch(final NamedElement pParam, final Consumer processor) { - return rawForOneArbitraryMatch(new Object[]{pParam}, processor); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pParam the fixed value of pattern parameter param, or null if not bound. - * @return the (partial) match object. - * - */ - public AllBenchMarkedQueries.Match newMatch(final NamedElement pParam) { - return AllBenchMarkedQueries.Match.newMatch(pParam); - } - - /** - * Retrieve the set of values that occur in matches for param. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOfparam(final Object[] parameters) { - return rawStreamAllValues(POSITION_PARAM, parameters).map(NamedElement.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for param. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfparam() { - return rawStreamAllValuesOfparam(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for param. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfparam() { - return rawStreamAllValuesOfparam(emptyArray()); - } - - @Override - protected AllBenchMarkedQueries.Match tupleToMatch(final Tuple t) { - try { - return AllBenchMarkedQueries.Match.newMatch((NamedElement) t.get(POSITION_PARAM)); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in tuple not properly typed!",e); - return null; - } - } - - @Override - protected AllBenchMarkedQueries.Match arrayToMatch(final Object[] match) { - try { - return AllBenchMarkedQueries.Match.newMatch((NamedElement) match[POSITION_PARAM]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - @Override - protected AllBenchMarkedQueries.Match arrayToMatchMutable(final Object[] match) { - try { - return AllBenchMarkedQueries.Match.newMutableMatch((NamedElement) match[POSITION_PARAM]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - /** - * @return the singleton instance of the query specification of this pattern - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static IQuerySpecification querySpecification() { - return AllBenchMarkedQueries.instance(); - } - } - - private AllBenchMarkedQueries() { - super(GeneratedPQuery.INSTANCE); - } - - /** - * @return the singleton instance of the query specification - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static AllBenchMarkedQueries instance() { - try{ - return LazyHolder.INSTANCE; - } catch (ExceptionInInitializerError err) { - throw processInitializerError(err); - } - } - - @Override - protected AllBenchMarkedQueries.Matcher instantiate(final ViatraQueryEngine engine) { - return AllBenchMarkedQueries.Matcher.on(engine); - } - - @Override - public AllBenchMarkedQueries.Matcher instantiate() { - return AllBenchMarkedQueries.Matcher.create(); - } - - @Override - public AllBenchMarkedQueries.Match newEmptyMatch() { - return AllBenchMarkedQueries.Match.newEmptyMatch(); - } - - @Override - public AllBenchMarkedQueries.Match newMatch(final Object... parameters) { - return AllBenchMarkedQueries.Match.newMatch((com.nomagic.uml2.ext.magicdraw.classes.mdkernel.NamedElement) parameters[0]); - } - - /** - * Inner class allowing the singleton instance of {@link AllBenchMarkedQueries} to be created - * not at the class load time of the outer class, - * but rather at the first call to {@link AllBenchMarkedQueries#instance()}. - * - *

This workaround is required e.g. to support recursion. - * - */ - private static class LazyHolder { - private static final AllBenchMarkedQueries INSTANCE = new AllBenchMarkedQueries(); - - /** - * Statically initializes the query specification after the field {@link #INSTANCE} is assigned. - * This initialization order is required to support indirect recursion. - * - *

The static initializer is defined using a helper field to work around limitations of the code generator. - * - */ - private static final Object STATIC_INITIALIZER = ensureInitialized(); - - public static Object ensureInitialized() { - INSTANCE.ensureInitializedInternal(); - return null; - } - } - - private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { - private static final AllBenchMarkedQueries.GeneratedPQuery INSTANCE = new GeneratedPQuery(); - - private final PParameter parameter_param = new PParameter("param", "com.nomagic.uml2.ext.magicdraw.classes.mdkernel.NamedElement", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.nomagic.com/magicdraw/UML/2.5.1", "NamedElement")), PParameterDirection.INOUT); - - private final List parameters = Arrays.asList(parameter_param); - - private GeneratedPQuery() { - super(PVisibility.PUBLIC); - } - - @Override - public String getFullyQualifiedName() { - return "com.incquerylabs.magicdraw.benchmark.queries.allBenchMarkedQueries"; - } - - @Override - public List getParameterNames() { - return Arrays.asList("param"); - } - - @Override - public List getParameters() { - return parameters; - } - - @Override - public Set doGetContainedBodies() { - setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); - Set bodies = new LinkedHashSet<>(); - { - PBody body = new PBody(this); - PVariable var_param = body.getOrCreateVariableByName("param"); - new TypeConstraint(body, Tuples.flatTupleOf(var_param), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "NamedElement"))); - body.setSymbolicParameters(Arrays.asList( - new ExportedParameter(body, var_param, parameter_param) - )); - // find blocksOrRequirementsOrConstraints(param) - new PositivePatternCall(body, Tuples.flatTupleOf(var_param), BlocksOrRequirementsOrConstraints.instance().getInternalQueryRepresentation()); - bodies.add(body); - } - { - PBody body = new PBody(this); - PVariable var_param = body.getOrCreateVariableByName("param"); - PVariable var___0_ = body.getOrCreateVariableByName("_<0>"); - new TypeConstraint(body, Tuples.flatTupleOf(var_param), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "NamedElement"))); - body.setSymbolicParameters(Arrays.asList( - new ExportedParameter(body, var_param, parameter_param) - )); - // find transitiveSubstatesWithCheck3(param, _) - new PositivePatternCall(body, Tuples.flatTupleOf(var_param, var___0_), TransitiveSubstatesWithCheck3.instance().getInternalQueryRepresentation()); - bodies.add(body); - } - { - PBody body = new PBody(this); - PVariable var_param = body.getOrCreateVariableByName("param"); - PVariable var___0_ = body.getOrCreateVariableByName("_<0>"); - new TypeConstraint(body, Tuples.flatTupleOf(var_param), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "NamedElement"))); - body.setSymbolicParameters(Arrays.asList( - new ExportedParameter(body, var_param, parameter_param) - )); - // find alphabeticalDependencies(param, _) - new PositivePatternCall(body, Tuples.flatTupleOf(var_param, var___0_), AlphabeticalDependencies.instance().getInternalQueryRepresentation()); - bodies.add(body); - } - { - PBody body = new PBody(this); - PVariable var_param = body.getOrCreateVariableByName("param"); - new TypeConstraint(body, Tuples.flatTupleOf(var_param), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "NamedElement"))); - body.setSymbolicParameters(Arrays.asList( - new ExportedParameter(body, var_param, parameter_param) - )); - // find circularDependencies(param) - new PositivePatternCall(body, Tuples.flatTupleOf(var_param), CircularDependencies.instance().getInternalQueryRepresentation()); - bodies.add(body); - } - { - PBody body = new PBody(this); - PVariable var_param = body.getOrCreateVariableByName("param"); - PVariable var___0_ = body.getOrCreateVariableByName("_<0>"); - PVariable var___1_ = body.getOrCreateVariableByName("_<1>"); - PVariable var___2_ = body.getOrCreateVariableByName("_<2>"); - PVariable var___3_ = body.getOrCreateVariableByName("_<3>"); - new TypeConstraint(body, Tuples.flatTupleOf(var_param), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "NamedElement"))); - body.setSymbolicParameters(Arrays.asList( - new ExportedParameter(body, var_param, parameter_param) - )); - // find loopTransitionWithTriggerEffectEventNoGuard(param, _, _, _, _) - new PositivePatternCall(body, Tuples.flatTupleOf(var_param, var___0_, var___1_, var___2_, var___3_), LoopTransitionWithTriggerEffectEventNoGuard.instance().getInternalQueryRepresentation()); - bodies.add(body); - } - { - PBody body = new PBody(this); - PVariable var_param = body.getOrCreateVariableByName("param"); - PVariable var___0_ = body.getOrCreateVariableByName("_<0>"); - PVariable var___1_ = body.getOrCreateVariableByName("_<1>"); - new TypeConstraint(body, Tuples.flatTupleOf(var_param), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "NamedElement"))); - body.setSymbolicParameters(Arrays.asList( - new ExportedParameter(body, var_param, parameter_param) - )); - // find transitionPointingOutOfCompState(param, _, _) - new PositivePatternCall(body, Tuples.flatTupleOf(var_param, var___0_, var___1_), TransitionPointingOutOfCompState.instance().getInternalQueryRepresentation()); - bodies.add(body); - } - return bodies; - } - } -} diff --git a/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/AlphabeticalDependencies.java b/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/AlphabeticalDependencies.java deleted file mode 100644 index f33a44d..0000000 --- a/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/AlphabeticalDependencies.java +++ /dev/null @@ -1,735 +0,0 @@ -/** - * Generated from platform:/resource/com.incquerylabs.magicdraw.benchmark/src/main/java/com/incquerylabs/magicdraw/benchmark/queries/APerformanceQueries.vql - */ -package com.incquerylabs.magicdraw.benchmark.queries; - -import com.incquerylabs.magicdraw.benchmark.queries.NamesOfDependencyEndpoints; -import com.nomagic.uml2.ext.magicdraw.classes.mdkernel.NamedElement; -import java.util.Arrays; -import java.util.Collection; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.function.Consumer; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import org.apache.log4j.Logger; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.viatra.query.runtime.api.IPatternMatch; -import org.eclipse.viatra.query.runtime.api.IQuerySpecification; -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.api.impl.BaseMatcher; -import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; -import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; -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.ExportedParameter; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExpressionEvaluation; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.PositivePatternCall; -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.PVisibility; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; -import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; - -/** - * A pattern-specific query specification that can instantiate Matcher in a type-safe way. - * - *

Original source: - *

- *         Reusing the namesOfDependencyEndpoints pattern and filtering with a check.
- *          
- *         pattern alphabeticalDependencies(source : NamedElement, target : NamedElement) {
- *         	find namesOfDependencyEndpoints(source, sourceName, target, targetName);
- *         	check (sourceName {@literal <} targetName);
- *         }
- * 
- * - * @see Matcher - * @see Match - * - */ -@SuppressWarnings("all") -public final class AlphabeticalDependencies extends BaseGeneratedEMFQuerySpecification { - /** - * Pattern-specific match representation of the com.incquerylabs.magicdraw.benchmark.queries.alphabeticalDependencies pattern, - * to be used in conjunction with {@link Matcher}. - * - *

Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. - * Each instance is a (possibly partial) substitution of pattern parameters, - * usable to represent a match of the pattern in the result of a query, - * or to specify the bound (fixed) input parameters when issuing a query. - * - * @see Matcher - * - */ - public static abstract class Match extends BasePatternMatch { - private NamedElement fSource; - - private NamedElement fTarget; - - private static List parameterNames = makeImmutableList("source", "target"); - - private Match(final NamedElement pSource, final NamedElement pTarget) { - this.fSource = pSource; - this.fTarget = pTarget; - } - - @Override - public Object get(final String parameterName) { - switch(parameterName) { - case "source": return this.fSource; - case "target": return this.fTarget; - default: return null; - } - } - - @Override - public Object get(final int index) { - switch(index) { - case 0: return this.fSource; - case 1: return this.fTarget; - default: return null; - } - } - - public NamedElement getSource() { - return this.fSource; - } - - public NamedElement getTarget() { - return this.fTarget; - } - - @Override - public boolean set(final String parameterName, final Object newValue) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - if ("source".equals(parameterName) ) { - this.fSource = (NamedElement) newValue; - return true; - } - if ("target".equals(parameterName) ) { - this.fTarget = (NamedElement) newValue; - return true; - } - return false; - } - - public void setSource(final NamedElement pSource) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fSource = pSource; - } - - public void setTarget(final NamedElement pTarget) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fTarget = pTarget; - } - - @Override - public String patternName() { - return "com.incquerylabs.magicdraw.benchmark.queries.alphabeticalDependencies"; - } - - @Override - public List parameterNames() { - return AlphabeticalDependencies.Match.parameterNames; - } - - @Override - public Object[] toArray() { - return new Object[]{fSource, fTarget}; - } - - @Override - public AlphabeticalDependencies.Match toImmutable() { - return isMutable() ? newMatch(fSource, fTarget) : this; - } - - @Override - public String prettyPrint() { - StringBuilder result = new StringBuilder(); - result.append("\"source\"=" + prettyPrintValue(fSource) + ", "); - result.append("\"target\"=" + prettyPrintValue(fTarget)); - return result.toString(); - } - - @Override - public int hashCode() { - return Objects.hash(fSource, fTarget); - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) - return true; - if (obj == null) { - return false; - } - if ((obj instanceof AlphabeticalDependencies.Match)) { - AlphabeticalDependencies.Match other = (AlphabeticalDependencies.Match) obj; - return Objects.equals(fSource, other.fSource) && Objects.equals(fTarget, other.fTarget); - } else { - // this should be infrequent - if (!(obj instanceof IPatternMatch)) { - return false; - } - IPatternMatch otherSig = (IPatternMatch) obj; - return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); - } - } - - @Override - public AlphabeticalDependencies specification() { - return AlphabeticalDependencies.instance(); - } - - /** - * Returns an empty, mutable match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @return the empty match. - * - */ - public static AlphabeticalDependencies.Match newEmptyMatch() { - return new Mutable(null, null); - } - - /** - * Returns a mutable (partial) match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @param pSource the fixed value of pattern parameter source, or null if not bound. - * @param pTarget the fixed value of pattern parameter target, or null if not bound. - * @return the new, mutable (partial) match object. - * - */ - public static AlphabeticalDependencies.Match newMutableMatch(final NamedElement pSource, final NamedElement pTarget) { - return new Mutable(pSource, pTarget); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pSource the fixed value of pattern parameter source, or null if not bound. - * @param pTarget the fixed value of pattern parameter target, or null if not bound. - * @return the (partial) match object. - * - */ - public static AlphabeticalDependencies.Match newMatch(final NamedElement pSource, final NamedElement pTarget) { - return new Immutable(pSource, pTarget); - } - - private static final class Mutable extends AlphabeticalDependencies.Match { - Mutable(final NamedElement pSource, final NamedElement pTarget) { - super(pSource, pTarget); - } - - @Override - public boolean isMutable() { - return true; - } - } - - private static final class Immutable extends AlphabeticalDependencies.Match { - Immutable(final NamedElement pSource, final NamedElement pTarget) { - super(pSource, pTarget); - } - - @Override - public boolean isMutable() { - return false; - } - } - } - - /** - * Generated pattern matcher API of the com.incquerylabs.magicdraw.benchmark.queries.alphabeticalDependencies pattern, - * providing pattern-specific query methods. - * - *

Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, - * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. - * - *

Matches of the pattern will be represented as {@link Match}. - * - *

Original source: - *

-   * Reusing the namesOfDependencyEndpoints pattern and filtering with a check.
-   *  
-   * pattern alphabeticalDependencies(source : NamedElement, target : NamedElement) {
-   * 	find namesOfDependencyEndpoints(source, sourceName, target, targetName);
-   * 	check (sourceName {@literal <} targetName);
-   * }
-   * 
- * - * @see Match - * @see AlphabeticalDependencies - * - */ - public static class Matcher extends BaseMatcher { - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - public static AlphabeticalDependencies.Matcher on(final ViatraQueryEngine engine) { - // check if matcher already exists - Matcher matcher = engine.getExistingMatcher(querySpecification()); - if (matcher == null) { - matcher = (Matcher)engine.getMatcher(querySpecification()); - } - return matcher; - } - - /** - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * @return an initialized matcher - * @noreference This method is for internal matcher initialization by the framework, do not call it manually. - * - */ - public static AlphabeticalDependencies.Matcher create() { - return new Matcher(); - } - - private static final int POSITION_SOURCE = 0; - - private static final int POSITION_TARGET = 1; - - private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(AlphabeticalDependencies.Matcher.class); - - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - private Matcher() { - super(querySpecification()); - } - - /** - * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pSource the fixed value of pattern parameter source, or null if not bound. - * @param pTarget the fixed value of pattern parameter target, or null if not bound. - * @return matches represented as a Match object. - * - */ - public Collection getAllMatches(final NamedElement pSource, final NamedElement pTarget) { - return rawStreamAllMatches(new Object[]{pSource, pTarget}).collect(Collectors.toSet()); - } - - /** - * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * @param pSource the fixed value of pattern parameter source, or null if not bound. - * @param pTarget the fixed value of pattern parameter target, or null if not bound. - * @return a stream of matches represented as a Match object. - * - */ - public Stream streamAllMatches(final NamedElement pSource, final NamedElement pTarget) { - return rawStreamAllMatches(new Object[]{pSource, pTarget}); - } - - /** - * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pSource the fixed value of pattern parameter source, or null if not bound. - * @param pTarget the fixed value of pattern parameter target, or null if not bound. - * @return a match represented as a Match object, or null if no match is found. - * - */ - public Optional getOneArbitraryMatch(final NamedElement pSource, final NamedElement pTarget) { - return rawGetOneArbitraryMatch(new Object[]{pSource, pTarget}); - } - - /** - * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, - * under any possible substitution of the unspecified parameters (if any). - * @param pSource the fixed value of pattern parameter source, or null if not bound. - * @param pTarget the fixed value of pattern parameter target, or null if not bound. - * @return true if the input is a valid (partial) match of the pattern. - * - */ - public boolean hasMatch(final NamedElement pSource, final NamedElement pTarget) { - return rawHasMatch(new Object[]{pSource, pTarget}); - } - - /** - * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pSource the fixed value of pattern parameter source, or null if not bound. - * @param pTarget the fixed value of pattern parameter target, or null if not bound. - * @return the number of pattern matches found. - * - */ - public int countMatches(final NamedElement pSource, final NamedElement pTarget) { - return rawCountMatches(new Object[]{pSource, pTarget}); - } - - /** - * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pSource the fixed value of pattern parameter source, or null if not bound. - * @param pTarget the fixed value of pattern parameter target, or null if not bound. - * @param processor the action that will process the selected match. - * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked - * - */ - public boolean forOneArbitraryMatch(final NamedElement pSource, final NamedElement pTarget, final Consumer processor) { - return rawForOneArbitraryMatch(new Object[]{pSource, pTarget}, processor); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pSource the fixed value of pattern parameter source, or null if not bound. - * @param pTarget the fixed value of pattern parameter target, or null if not bound. - * @return the (partial) match object. - * - */ - public AlphabeticalDependencies.Match newMatch(final NamedElement pSource, final NamedElement pTarget) { - return AlphabeticalDependencies.Match.newMatch(pSource, pTarget); - } - - /** - * Retrieve the set of values that occur in matches for source. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOfsource(final Object[] parameters) { - return rawStreamAllValues(POSITION_SOURCE, parameters).map(NamedElement.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for source. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfsource() { - return rawStreamAllValuesOfsource(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for source. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfsource() { - return rawStreamAllValuesOfsource(emptyArray()); - } - - /** - * Retrieve the set of values that occur in matches for source. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfsource(final AlphabeticalDependencies.Match partialMatch) { - return rawStreamAllValuesOfsource(partialMatch.toArray()); - } - - /** - * Retrieve the set of values that occur in matches for source. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfsource(final NamedElement pTarget) { - return rawStreamAllValuesOfsource(new Object[]{null, pTarget}); - } - - /** - * Retrieve the set of values that occur in matches for source. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfsource(final AlphabeticalDependencies.Match partialMatch) { - return rawStreamAllValuesOfsource(partialMatch.toArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for source. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfsource(final NamedElement pTarget) { - return rawStreamAllValuesOfsource(new Object[]{null, pTarget}).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for target. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOftarget(final Object[] parameters) { - return rawStreamAllValues(POSITION_TARGET, parameters).map(NamedElement.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for target. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOftarget() { - return rawStreamAllValuesOftarget(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for target. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOftarget() { - return rawStreamAllValuesOftarget(emptyArray()); - } - - /** - * Retrieve the set of values that occur in matches for target. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOftarget(final AlphabeticalDependencies.Match partialMatch) { - return rawStreamAllValuesOftarget(partialMatch.toArray()); - } - - /** - * Retrieve the set of values that occur in matches for target. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOftarget(final NamedElement pSource) { - return rawStreamAllValuesOftarget(new Object[]{pSource, null}); - } - - /** - * Retrieve the set of values that occur in matches for target. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOftarget(final AlphabeticalDependencies.Match partialMatch) { - return rawStreamAllValuesOftarget(partialMatch.toArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for target. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOftarget(final NamedElement pSource) { - return rawStreamAllValuesOftarget(new Object[]{pSource, null}).collect(Collectors.toSet()); - } - - @Override - protected AlphabeticalDependencies.Match tupleToMatch(final Tuple t) { - try { - return AlphabeticalDependencies.Match.newMatch((NamedElement) t.get(POSITION_SOURCE), (NamedElement) t.get(POSITION_TARGET)); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in tuple not properly typed!",e); - return null; - } - } - - @Override - protected AlphabeticalDependencies.Match arrayToMatch(final Object[] match) { - try { - return AlphabeticalDependencies.Match.newMatch((NamedElement) match[POSITION_SOURCE], (NamedElement) match[POSITION_TARGET]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - @Override - protected AlphabeticalDependencies.Match arrayToMatchMutable(final Object[] match) { - try { - return AlphabeticalDependencies.Match.newMutableMatch((NamedElement) match[POSITION_SOURCE], (NamedElement) match[POSITION_TARGET]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - /** - * @return the singleton instance of the query specification of this pattern - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static IQuerySpecification querySpecification() { - return AlphabeticalDependencies.instance(); - } - } - - private AlphabeticalDependencies() { - super(GeneratedPQuery.INSTANCE); - } - - /** - * @return the singleton instance of the query specification - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static AlphabeticalDependencies instance() { - try{ - return LazyHolder.INSTANCE; - } catch (ExceptionInInitializerError err) { - throw processInitializerError(err); - } - } - - @Override - protected AlphabeticalDependencies.Matcher instantiate(final ViatraQueryEngine engine) { - return AlphabeticalDependencies.Matcher.on(engine); - } - - @Override - public AlphabeticalDependencies.Matcher instantiate() { - return AlphabeticalDependencies.Matcher.create(); - } - - @Override - public AlphabeticalDependencies.Match newEmptyMatch() { - return AlphabeticalDependencies.Match.newEmptyMatch(); - } - - @Override - public AlphabeticalDependencies.Match newMatch(final Object... parameters) { - return AlphabeticalDependencies.Match.newMatch((com.nomagic.uml2.ext.magicdraw.classes.mdkernel.NamedElement) parameters[0], (com.nomagic.uml2.ext.magicdraw.classes.mdkernel.NamedElement) parameters[1]); - } - - /** - * Inner class allowing the singleton instance of {@link AlphabeticalDependencies} to be created - * not at the class load time of the outer class, - * but rather at the first call to {@link AlphabeticalDependencies#instance()}. - * - *

This workaround is required e.g. to support recursion. - * - */ - private static class LazyHolder { - private static final AlphabeticalDependencies INSTANCE = new AlphabeticalDependencies(); - - /** - * Statically initializes the query specification after the field {@link #INSTANCE} is assigned. - * This initialization order is required to support indirect recursion. - * - *

The static initializer is defined using a helper field to work around limitations of the code generator. - * - */ - private static final Object STATIC_INITIALIZER = ensureInitialized(); - - public static Object ensureInitialized() { - INSTANCE.ensureInitializedInternal(); - return null; - } - } - - private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { - private static final AlphabeticalDependencies.GeneratedPQuery INSTANCE = new GeneratedPQuery(); - - private final PParameter parameter_source = new PParameter("source", "com.nomagic.uml2.ext.magicdraw.classes.mdkernel.NamedElement", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.nomagic.com/magicdraw/UML/2.5.1", "NamedElement")), PParameterDirection.INOUT); - - private final PParameter parameter_target = new PParameter("target", "com.nomagic.uml2.ext.magicdraw.classes.mdkernel.NamedElement", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.nomagic.com/magicdraw/UML/2.5.1", "NamedElement")), PParameterDirection.INOUT); - - private final List parameters = Arrays.asList(parameter_source, parameter_target); - - private GeneratedPQuery() { - super(PVisibility.PUBLIC); - } - - @Override - public String getFullyQualifiedName() { - return "com.incquerylabs.magicdraw.benchmark.queries.alphabeticalDependencies"; - } - - @Override - public List getParameterNames() { - return Arrays.asList("source","target"); - } - - @Override - public List getParameters() { - return parameters; - } - - @Override - public Set doGetContainedBodies() { - setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); - Set bodies = new LinkedHashSet<>(); - { - PBody body = new PBody(this); - PVariable var_source = body.getOrCreateVariableByName("source"); - PVariable var_target = body.getOrCreateVariableByName("target"); - PVariable var_sourceName = body.getOrCreateVariableByName("sourceName"); - PVariable var_targetName = body.getOrCreateVariableByName("targetName"); - new TypeConstraint(body, Tuples.flatTupleOf(var_source), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "NamedElement"))); - new TypeConstraint(body, Tuples.flatTupleOf(var_target), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "NamedElement"))); - body.setSymbolicParameters(Arrays.asList( - new ExportedParameter(body, var_source, parameter_source), - new ExportedParameter(body, var_target, parameter_target) - )); - // find namesOfDependencyEndpoints(source, sourceName, target, targetName) - new PositivePatternCall(body, Tuples.flatTupleOf(var_source, var_sourceName, var_target, var_targetName), NamesOfDependencyEndpoints.instance().getInternalQueryRepresentation()); - // check (sourceName < targetName) - new ExpressionEvaluation(body, new IExpressionEvaluator() { - - @Override - public String getShortDescription() { - return "Expression evaluation from pattern alphabeticalDependencies"; - } - - @Override - public Iterable getInputParameterNames() { - return Arrays.asList("sourceName", "targetName");} - - @Override - public Object evaluateExpression(IValueProvider provider) throws Exception { - String sourceName = (String) provider.getValue("sourceName"); - String targetName = (String) provider.getValue("targetName"); - return evaluateExpression_1_1(sourceName, targetName); - } - }, null); - bodies.add(body); - } - return bodies; - } - } - - private static boolean evaluateExpression_1_1(final String sourceName, final String targetName) { - boolean _lessThan = (sourceName.compareTo(targetName) < 0); - return _lessThan; - } -} diff --git a/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/AssociationClasses.java b/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/AssociationClasses.java deleted file mode 100644 index 0611908..0000000 --- a/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/AssociationClasses.java +++ /dev/null @@ -1,705 +0,0 @@ -/** - * Generated from platform:/resource/com.incquerylabs.magicdraw.benchmark/src/main/java/com/incquerylabs/magicdraw/benchmark/queries/WarmUpQueries.vql - */ -package com.incquerylabs.magicdraw.benchmark.queries; - -import com.nomagic.uml2.ext.magicdraw.classes.mdassociationclasses.AssociationClass; -import com.nomagic.uml2.ext.magicdraw.mdusecases.UseCase; -import java.util.Arrays; -import java.util.Collection; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.function.Consumer; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import org.apache.log4j.Logger; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.viatra.query.runtime.api.IPatternMatch; -import org.eclipse.viatra.query.runtime.api.IQuerySpecification; -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.api.impl.BaseMatcher; -import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; -import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; -import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey; -import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; -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.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.PVisibility; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; -import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; - -/** - * A pattern-specific query specification that can instantiate Matcher in a type-safe way. - * - *

Original source: - *

- *         pattern associationClasses(associationClass : AssociationClass, useCase : UseCase) {
- *         	AssociationClass.ownedUseCase(associationClass, useCase);
- *         }
- * 
- * - * @see Matcher - * @see Match - * - */ -@SuppressWarnings("all") -public final class AssociationClasses extends BaseGeneratedEMFQuerySpecification { - /** - * Pattern-specific match representation of the com.incquerylabs.magicdraw.benchmark.queries.associationClasses pattern, - * to be used in conjunction with {@link Matcher}. - * - *

Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. - * Each instance is a (possibly partial) substitution of pattern parameters, - * usable to represent a match of the pattern in the result of a query, - * or to specify the bound (fixed) input parameters when issuing a query. - * - * @see Matcher - * - */ - public static abstract class Match extends BasePatternMatch { - private AssociationClass fAssociationClass; - - private UseCase fUseCase; - - private static List parameterNames = makeImmutableList("associationClass", "useCase"); - - private Match(final AssociationClass pAssociationClass, final UseCase pUseCase) { - this.fAssociationClass = pAssociationClass; - this.fUseCase = pUseCase; - } - - @Override - public Object get(final String parameterName) { - switch(parameterName) { - case "associationClass": return this.fAssociationClass; - case "useCase": return this.fUseCase; - default: return null; - } - } - - @Override - public Object get(final int index) { - switch(index) { - case 0: return this.fAssociationClass; - case 1: return this.fUseCase; - default: return null; - } - } - - public AssociationClass getAssociationClass() { - return this.fAssociationClass; - } - - public UseCase getUseCase() { - return this.fUseCase; - } - - @Override - public boolean set(final String parameterName, final Object newValue) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - if ("associationClass".equals(parameterName) ) { - this.fAssociationClass = (AssociationClass) newValue; - return true; - } - if ("useCase".equals(parameterName) ) { - this.fUseCase = (UseCase) newValue; - return true; - } - return false; - } - - public void setAssociationClass(final AssociationClass pAssociationClass) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fAssociationClass = pAssociationClass; - } - - public void setUseCase(final UseCase pUseCase) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fUseCase = pUseCase; - } - - @Override - public String patternName() { - return "com.incquerylabs.magicdraw.benchmark.queries.associationClasses"; - } - - @Override - public List parameterNames() { - return AssociationClasses.Match.parameterNames; - } - - @Override - public Object[] toArray() { - return new Object[]{fAssociationClass, fUseCase}; - } - - @Override - public AssociationClasses.Match toImmutable() { - return isMutable() ? newMatch(fAssociationClass, fUseCase) : this; - } - - @Override - public String prettyPrint() { - StringBuilder result = new StringBuilder(); - result.append("\"associationClass\"=" + prettyPrintValue(fAssociationClass) + ", "); - result.append("\"useCase\"=" + prettyPrintValue(fUseCase)); - return result.toString(); - } - - @Override - public int hashCode() { - return Objects.hash(fAssociationClass, fUseCase); - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) - return true; - if (obj == null) { - return false; - } - if ((obj instanceof AssociationClasses.Match)) { - AssociationClasses.Match other = (AssociationClasses.Match) obj; - return Objects.equals(fAssociationClass, other.fAssociationClass) && Objects.equals(fUseCase, other.fUseCase); - } else { - // this should be infrequent - if (!(obj instanceof IPatternMatch)) { - return false; - } - IPatternMatch otherSig = (IPatternMatch) obj; - return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); - } - } - - @Override - public AssociationClasses specification() { - return AssociationClasses.instance(); - } - - /** - * Returns an empty, mutable match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @return the empty match. - * - */ - public static AssociationClasses.Match newEmptyMatch() { - return new Mutable(null, null); - } - - /** - * Returns a mutable (partial) match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @param pAssociationClass the fixed value of pattern parameter associationClass, or null if not bound. - * @param pUseCase the fixed value of pattern parameter useCase, or null if not bound. - * @return the new, mutable (partial) match object. - * - */ - public static AssociationClasses.Match newMutableMatch(final AssociationClass pAssociationClass, final UseCase pUseCase) { - return new Mutable(pAssociationClass, pUseCase); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pAssociationClass the fixed value of pattern parameter associationClass, or null if not bound. - * @param pUseCase the fixed value of pattern parameter useCase, or null if not bound. - * @return the (partial) match object. - * - */ - public static AssociationClasses.Match newMatch(final AssociationClass pAssociationClass, final UseCase pUseCase) { - return new Immutable(pAssociationClass, pUseCase); - } - - private static final class Mutable extends AssociationClasses.Match { - Mutable(final AssociationClass pAssociationClass, final UseCase pUseCase) { - super(pAssociationClass, pUseCase); - } - - @Override - public boolean isMutable() { - return true; - } - } - - private static final class Immutable extends AssociationClasses.Match { - Immutable(final AssociationClass pAssociationClass, final UseCase pUseCase) { - super(pAssociationClass, pUseCase); - } - - @Override - public boolean isMutable() { - return false; - } - } - } - - /** - * Generated pattern matcher API of the com.incquerylabs.magicdraw.benchmark.queries.associationClasses pattern, - * providing pattern-specific query methods. - * - *

Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, - * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. - * - *

Matches of the pattern will be represented as {@link Match}. - * - *

Original source: - *

-   * pattern associationClasses(associationClass : AssociationClass, useCase : UseCase) {
-   * 	AssociationClass.ownedUseCase(associationClass, useCase);
-   * }
-   * 
- * - * @see Match - * @see AssociationClasses - * - */ - public static class Matcher extends BaseMatcher { - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - public static AssociationClasses.Matcher on(final ViatraQueryEngine engine) { - // check if matcher already exists - Matcher matcher = engine.getExistingMatcher(querySpecification()); - if (matcher == null) { - matcher = (Matcher)engine.getMatcher(querySpecification()); - } - return matcher; - } - - /** - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * @return an initialized matcher - * @noreference This method is for internal matcher initialization by the framework, do not call it manually. - * - */ - public static AssociationClasses.Matcher create() { - return new Matcher(); - } - - private static final int POSITION_ASSOCIATIONCLASS = 0; - - private static final int POSITION_USECASE = 1; - - private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(AssociationClasses.Matcher.class); - - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - private Matcher() { - super(querySpecification()); - } - - /** - * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pAssociationClass the fixed value of pattern parameter associationClass, or null if not bound. - * @param pUseCase the fixed value of pattern parameter useCase, or null if not bound. - * @return matches represented as a Match object. - * - */ - public Collection getAllMatches(final AssociationClass pAssociationClass, final UseCase pUseCase) { - return rawStreamAllMatches(new Object[]{pAssociationClass, pUseCase}).collect(Collectors.toSet()); - } - - /** - * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * @param pAssociationClass the fixed value of pattern parameter associationClass, or null if not bound. - * @param pUseCase the fixed value of pattern parameter useCase, or null if not bound. - * @return a stream of matches represented as a Match object. - * - */ - public Stream streamAllMatches(final AssociationClass pAssociationClass, final UseCase pUseCase) { - return rawStreamAllMatches(new Object[]{pAssociationClass, pUseCase}); - } - - /** - * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pAssociationClass the fixed value of pattern parameter associationClass, or null if not bound. - * @param pUseCase the fixed value of pattern parameter useCase, or null if not bound. - * @return a match represented as a Match object, or null if no match is found. - * - */ - public Optional getOneArbitraryMatch(final AssociationClass pAssociationClass, final UseCase pUseCase) { - return rawGetOneArbitraryMatch(new Object[]{pAssociationClass, pUseCase}); - } - - /** - * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, - * under any possible substitution of the unspecified parameters (if any). - * @param pAssociationClass the fixed value of pattern parameter associationClass, or null if not bound. - * @param pUseCase the fixed value of pattern parameter useCase, or null if not bound. - * @return true if the input is a valid (partial) match of the pattern. - * - */ - public boolean hasMatch(final AssociationClass pAssociationClass, final UseCase pUseCase) { - return rawHasMatch(new Object[]{pAssociationClass, pUseCase}); - } - - /** - * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pAssociationClass the fixed value of pattern parameter associationClass, or null if not bound. - * @param pUseCase the fixed value of pattern parameter useCase, or null if not bound. - * @return the number of pattern matches found. - * - */ - public int countMatches(final AssociationClass pAssociationClass, final UseCase pUseCase) { - return rawCountMatches(new Object[]{pAssociationClass, pUseCase}); - } - - /** - * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pAssociationClass the fixed value of pattern parameter associationClass, or null if not bound. - * @param pUseCase the fixed value of pattern parameter useCase, or null if not bound. - * @param processor the action that will process the selected match. - * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked - * - */ - public boolean forOneArbitraryMatch(final AssociationClass pAssociationClass, final UseCase pUseCase, final Consumer processor) { - return rawForOneArbitraryMatch(new Object[]{pAssociationClass, pUseCase}, processor); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pAssociationClass the fixed value of pattern parameter associationClass, or null if not bound. - * @param pUseCase the fixed value of pattern parameter useCase, or null if not bound. - * @return the (partial) match object. - * - */ - public AssociationClasses.Match newMatch(final AssociationClass pAssociationClass, final UseCase pUseCase) { - return AssociationClasses.Match.newMatch(pAssociationClass, pUseCase); - } - - /** - * Retrieve the set of values that occur in matches for associationClass. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOfassociationClass(final Object[] parameters) { - return rawStreamAllValues(POSITION_ASSOCIATIONCLASS, parameters).map(AssociationClass.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for associationClass. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfassociationClass() { - return rawStreamAllValuesOfassociationClass(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for associationClass. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfassociationClass() { - return rawStreamAllValuesOfassociationClass(emptyArray()); - } - - /** - * Retrieve the set of values that occur in matches for associationClass. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfassociationClass(final AssociationClasses.Match partialMatch) { - return rawStreamAllValuesOfassociationClass(partialMatch.toArray()); - } - - /** - * Retrieve the set of values that occur in matches for associationClass. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfassociationClass(final UseCase pUseCase) { - return rawStreamAllValuesOfassociationClass(new Object[]{null, pUseCase}); - } - - /** - * Retrieve the set of values that occur in matches for associationClass. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfassociationClass(final AssociationClasses.Match partialMatch) { - return rawStreamAllValuesOfassociationClass(partialMatch.toArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for associationClass. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfassociationClass(final UseCase pUseCase) { - return rawStreamAllValuesOfassociationClass(new Object[]{null, pUseCase}).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for useCase. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOfuseCase(final Object[] parameters) { - return rawStreamAllValues(POSITION_USECASE, parameters).map(UseCase.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for useCase. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfuseCase() { - return rawStreamAllValuesOfuseCase(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for useCase. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfuseCase() { - return rawStreamAllValuesOfuseCase(emptyArray()); - } - - /** - * Retrieve the set of values that occur in matches for useCase. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfuseCase(final AssociationClasses.Match partialMatch) { - return rawStreamAllValuesOfuseCase(partialMatch.toArray()); - } - - /** - * Retrieve the set of values that occur in matches for useCase. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfuseCase(final AssociationClass pAssociationClass) { - return rawStreamAllValuesOfuseCase(new Object[]{pAssociationClass, null}); - } - - /** - * Retrieve the set of values that occur in matches for useCase. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfuseCase(final AssociationClasses.Match partialMatch) { - return rawStreamAllValuesOfuseCase(partialMatch.toArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for useCase. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfuseCase(final AssociationClass pAssociationClass) { - return rawStreamAllValuesOfuseCase(new Object[]{pAssociationClass, null}).collect(Collectors.toSet()); - } - - @Override - protected AssociationClasses.Match tupleToMatch(final Tuple t) { - try { - return AssociationClasses.Match.newMatch((AssociationClass) t.get(POSITION_ASSOCIATIONCLASS), (UseCase) t.get(POSITION_USECASE)); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in tuple not properly typed!",e); - return null; - } - } - - @Override - protected AssociationClasses.Match arrayToMatch(final Object[] match) { - try { - return AssociationClasses.Match.newMatch((AssociationClass) match[POSITION_ASSOCIATIONCLASS], (UseCase) match[POSITION_USECASE]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - @Override - protected AssociationClasses.Match arrayToMatchMutable(final Object[] match) { - try { - return AssociationClasses.Match.newMutableMatch((AssociationClass) match[POSITION_ASSOCIATIONCLASS], (UseCase) match[POSITION_USECASE]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - /** - * @return the singleton instance of the query specification of this pattern - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static IQuerySpecification querySpecification() { - return AssociationClasses.instance(); - } - } - - private AssociationClasses() { - super(GeneratedPQuery.INSTANCE); - } - - /** - * @return the singleton instance of the query specification - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static AssociationClasses instance() { - try{ - return LazyHolder.INSTANCE; - } catch (ExceptionInInitializerError err) { - throw processInitializerError(err); - } - } - - @Override - protected AssociationClasses.Matcher instantiate(final ViatraQueryEngine engine) { - return AssociationClasses.Matcher.on(engine); - } - - @Override - public AssociationClasses.Matcher instantiate() { - return AssociationClasses.Matcher.create(); - } - - @Override - public AssociationClasses.Match newEmptyMatch() { - return AssociationClasses.Match.newEmptyMatch(); - } - - @Override - public AssociationClasses.Match newMatch(final Object... parameters) { - return AssociationClasses.Match.newMatch((com.nomagic.uml2.ext.magicdraw.classes.mdassociationclasses.AssociationClass) parameters[0], (com.nomagic.uml2.ext.magicdraw.mdusecases.UseCase) parameters[1]); - } - - /** - * Inner class allowing the singleton instance of {@link AssociationClasses} to be created - * not at the class load time of the outer class, - * but rather at the first call to {@link AssociationClasses#instance()}. - * - *

This workaround is required e.g. to support recursion. - * - */ - private static class LazyHolder { - private static final AssociationClasses INSTANCE = new AssociationClasses(); - - /** - * Statically initializes the query specification after the field {@link #INSTANCE} is assigned. - * This initialization order is required to support indirect recursion. - * - *

The static initializer is defined using a helper field to work around limitations of the code generator. - * - */ - private static final Object STATIC_INITIALIZER = ensureInitialized(); - - public static Object ensureInitialized() { - INSTANCE.ensureInitializedInternal(); - return null; - } - } - - private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { - private static final AssociationClasses.GeneratedPQuery INSTANCE = new GeneratedPQuery(); - - private final PParameter parameter_associationClass = new PParameter("associationClass", "com.nomagic.uml2.ext.magicdraw.classes.mdassociationclasses.AssociationClass", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.nomagic.com/magicdraw/UML/2.5.1", "AssociationClass")), PParameterDirection.INOUT); - - private final PParameter parameter_useCase = new PParameter("useCase", "com.nomagic.uml2.ext.magicdraw.mdusecases.UseCase", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.nomagic.com/magicdraw/UML/2.5.1", "UseCase")), PParameterDirection.INOUT); - - private final List parameters = Arrays.asList(parameter_associationClass, parameter_useCase); - - private GeneratedPQuery() { - super(PVisibility.PUBLIC); - } - - @Override - public String getFullyQualifiedName() { - return "com.incquerylabs.magicdraw.benchmark.queries.associationClasses"; - } - - @Override - public List getParameterNames() { - return Arrays.asList("associationClass","useCase"); - } - - @Override - public List getParameters() { - return parameters; - } - - @Override - public Set doGetContainedBodies() { - setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); - Set bodies = new LinkedHashSet<>(); - { - PBody body = new PBody(this); - PVariable var_associationClass = body.getOrCreateVariableByName("associationClass"); - PVariable var_useCase = body.getOrCreateVariableByName("useCase"); - new TypeConstraint(body, Tuples.flatTupleOf(var_associationClass), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "AssociationClass"))); - new TypeConstraint(body, Tuples.flatTupleOf(var_useCase), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "UseCase"))); - body.setSymbolicParameters(Arrays.asList( - new ExportedParameter(body, var_associationClass, parameter_associationClass), - new ExportedParameter(body, var_useCase, parameter_useCase) - )); - // AssociationClass.ownedUseCase(associationClass, useCase) - new TypeConstraint(body, Tuples.flatTupleOf(var_associationClass), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "AssociationClass"))); - PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_associationClass, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Classifier", "ownedUseCase"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "UseCase"))); - new Equality(body, var__virtual_0_, var_useCase); - bodies.add(body); - } - return bodies; - } - } -} diff --git a/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/Blocks.java b/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/Blocks.java deleted file mode 100644 index df0c55b..0000000 --- a/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/Blocks.java +++ /dev/null @@ -1,564 +0,0 @@ -/** - * Generated from platform:/resource/com.incquerylabs.magicdraw.benchmark/src/main/java/com/incquerylabs/magicdraw/benchmark/queries/APerformanceQueries.vql - */ -package com.incquerylabs.magicdraw.benchmark.queries; - -import java.util.Arrays; -import java.util.Collection; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.function.Consumer; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import org.apache.log4j.Logger; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.emf.ecore.EDataType; -import org.eclipse.viatra.query.runtime.api.IPatternMatch; -import org.eclipse.viatra.query.runtime.api.IQuerySpecification; -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.api.impl.BaseMatcher; -import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; -import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; -import org.eclipse.viatra.query.runtime.emf.types.EDataTypeInSlotsKey; -import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey; -import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; -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.basicenumerables.ConstantValue; -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.PVisibility; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; -import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; - -/** - * A pattern-specific query specification that can instantiate Matcher in a type-safe way. - * - *

Original source: - *

- *         Querying all instances of an EClass that have a short "reference chain".
- *          
- *         pattern blocks(class : Class) {
- *             Class.appliedStereotypeInstance.classifier.name(class, "Block"); 
- *         }
- * 
- * - * @see Matcher - * @see Match - * - */ -@SuppressWarnings("all") -public final class Blocks extends BaseGeneratedEMFQuerySpecification { - /** - * Pattern-specific match representation of the com.incquerylabs.magicdraw.benchmark.queries.blocks pattern, - * to be used in conjunction with {@link Matcher}. - * - *

Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. - * Each instance is a (possibly partial) substitution of pattern parameters, - * usable to represent a match of the pattern in the result of a query, - * or to specify the bound (fixed) input parameters when issuing a query. - * - * @see Matcher - * - */ - public static abstract class Match extends BasePatternMatch { - private com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class fClass; - - private static List parameterNames = makeImmutableList("class"); - - private Match(final com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class pClass) { - this.fClass = pClass; - } - - @Override - public Object get(final String parameterName) { - switch(parameterName) { - case "class": return this.fClass; - default: return null; - } - } - - @Override - public Object get(final int index) { - switch(index) { - case 0: return this.fClass; - default: return null; - } - } - - public com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class getValueOfClass() { - return this.fClass; - } - - @Override - public boolean set(final String parameterName, final Object newValue) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - if ("class".equals(parameterName) ) { - this.fClass = (com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class) newValue; - return true; - } - return false; - } - - public void setClass(final com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class pClass) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fClass = pClass; - } - - @Override - public String patternName() { - return "com.incquerylabs.magicdraw.benchmark.queries.blocks"; - } - - @Override - public List parameterNames() { - return Blocks.Match.parameterNames; - } - - @Override - public Object[] toArray() { - return new Object[]{fClass}; - } - - @Override - public Blocks.Match toImmutable() { - return isMutable() ? newMatch(fClass) : this; - } - - @Override - public String prettyPrint() { - StringBuilder result = new StringBuilder(); - result.append("\"class\"=" + prettyPrintValue(fClass)); - return result.toString(); - } - - @Override - public int hashCode() { - return Objects.hash(fClass); - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) - return true; - if (obj == null) { - return false; - } - if ((obj instanceof Blocks.Match)) { - Blocks.Match other = (Blocks.Match) obj; - return Objects.equals(fClass, other.fClass); - } else { - // this should be infrequent - if (!(obj instanceof IPatternMatch)) { - return false; - } - IPatternMatch otherSig = (IPatternMatch) obj; - return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); - } - } - - @Override - public Blocks specification() { - return Blocks.instance(); - } - - /** - * Returns an empty, mutable match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @return the empty match. - * - */ - public static Blocks.Match newEmptyMatch() { - return new Mutable(null); - } - - /** - * Returns a mutable (partial) match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @param pClass the fixed value of pattern parameter class, or null if not bound. - * @return the new, mutable (partial) match object. - * - */ - public static Blocks.Match newMutableMatch(final com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class pClass) { - return new Mutable(pClass); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pClass the fixed value of pattern parameter class, or null if not bound. - * @return the (partial) match object. - * - */ - public static Blocks.Match newMatch(final com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class pClass) { - return new Immutable(pClass); - } - - private static final class Mutable extends Blocks.Match { - Mutable(final com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class pClass) { - super(pClass); - } - - @Override - public boolean isMutable() { - return true; - } - } - - private static final class Immutable extends Blocks.Match { - Immutable(final com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class pClass) { - super(pClass); - } - - @Override - public boolean isMutable() { - return false; - } - } - } - - /** - * Generated pattern matcher API of the com.incquerylabs.magicdraw.benchmark.queries.blocks pattern, - * providing pattern-specific query methods. - * - *

Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, - * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. - * - *

Matches of the pattern will be represented as {@link Match}. - * - *

Original source: - *

-   * Querying all instances of an EClass that have a short "reference chain".
-   *  
-   * pattern blocks(class : Class) {
-   *     Class.appliedStereotypeInstance.classifier.name(class, "Block"); 
-   * }
-   * 
- * - * @see Match - * @see Blocks - * - */ - public static class Matcher extends BaseMatcher { - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - public static Blocks.Matcher on(final ViatraQueryEngine engine) { - // check if matcher already exists - Matcher matcher = engine.getExistingMatcher(querySpecification()); - if (matcher == null) { - matcher = (Matcher)engine.getMatcher(querySpecification()); - } - return matcher; - } - - /** - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * @return an initialized matcher - * @noreference This method is for internal matcher initialization by the framework, do not call it manually. - * - */ - public static Blocks.Matcher create() { - return new Matcher(); - } - - private static final int POSITION_CLASS = 0; - - private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(Blocks.Matcher.class); - - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - private Matcher() { - super(querySpecification()); - } - - /** - * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pClass the fixed value of pattern parameter class, or null if not bound. - * @return matches represented as a Match object. - * - */ - public Collection getAllMatches(final com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class pClass) { - return rawStreamAllMatches(new Object[]{pClass}).collect(Collectors.toSet()); - } - - /** - * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * @param pClass the fixed value of pattern parameter class, or null if not bound. - * @return a stream of matches represented as a Match object. - * - */ - public Stream streamAllMatches(final com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class pClass) { - return rawStreamAllMatches(new Object[]{pClass}); - } - - /** - * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pClass the fixed value of pattern parameter class, or null if not bound. - * @return a match represented as a Match object, or null if no match is found. - * - */ - public Optional getOneArbitraryMatch(final com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class pClass) { - return rawGetOneArbitraryMatch(new Object[]{pClass}); - } - - /** - * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, - * under any possible substitution of the unspecified parameters (if any). - * @param pClass the fixed value of pattern parameter class, or null if not bound. - * @return true if the input is a valid (partial) match of the pattern. - * - */ - public boolean hasMatch(final com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class pClass) { - return rawHasMatch(new Object[]{pClass}); - } - - /** - * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pClass the fixed value of pattern parameter class, or null if not bound. - * @return the number of pattern matches found. - * - */ - public int countMatches(final com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class pClass) { - return rawCountMatches(new Object[]{pClass}); - } - - /** - * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pClass the fixed value of pattern parameter class, or null if not bound. - * @param processor the action that will process the selected match. - * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked - * - */ - public boolean forOneArbitraryMatch(final com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class pClass, final Consumer processor) { - return rawForOneArbitraryMatch(new Object[]{pClass}, processor); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pClass the fixed value of pattern parameter class, or null if not bound. - * @return the (partial) match object. - * - */ - public Blocks.Match newMatch(final com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class pClass) { - return Blocks.Match.newMatch(pClass); - } - - /** - * Retrieve the set of values that occur in matches for class. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOfclass(final Object[] parameters) { - return rawStreamAllValues(POSITION_CLASS, parameters).map(com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for class. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfclass() { - return rawStreamAllValuesOfclass(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for class. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfclass() { - return rawStreamAllValuesOfclass(emptyArray()); - } - - @Override - protected Blocks.Match tupleToMatch(final Tuple t) { - try { - return Blocks.Match.newMatch((com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class) t.get(POSITION_CLASS)); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in tuple not properly typed!",e); - return null; - } - } - - @Override - protected Blocks.Match arrayToMatch(final Object[] match) { - try { - return Blocks.Match.newMatch((com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class) match[POSITION_CLASS]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - @Override - protected Blocks.Match arrayToMatchMutable(final Object[] match) { - try { - return Blocks.Match.newMutableMatch((com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class) match[POSITION_CLASS]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - /** - * @return the singleton instance of the query specification of this pattern - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static IQuerySpecification querySpecification() { - return Blocks.instance(); - } - } - - private Blocks() { - super(GeneratedPQuery.INSTANCE); - } - - /** - * @return the singleton instance of the query specification - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static Blocks instance() { - try{ - return LazyHolder.INSTANCE; - } catch (ExceptionInInitializerError err) { - throw processInitializerError(err); - } - } - - @Override - protected Blocks.Matcher instantiate(final ViatraQueryEngine engine) { - return Blocks.Matcher.on(engine); - } - - @Override - public Blocks.Matcher instantiate() { - return Blocks.Matcher.create(); - } - - @Override - public Blocks.Match newEmptyMatch() { - return Blocks.Match.newEmptyMatch(); - } - - @Override - public Blocks.Match newMatch(final Object... parameters) { - return Blocks.Match.newMatch((com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class) parameters[0]); - } - - /** - * Inner class allowing the singleton instance of {@link Blocks} to be created - * not at the class load time of the outer class, - * but rather at the first call to {@link Blocks#instance()}. - * - *

This workaround is required e.g. to support recursion. - * - */ - private static class LazyHolder { - private static final Blocks INSTANCE = new Blocks(); - - /** - * Statically initializes the query specification after the field {@link #INSTANCE} is assigned. - * This initialization order is required to support indirect recursion. - * - *

The static initializer is defined using a helper field to work around limitations of the code generator. - * - */ - private static final Object STATIC_INITIALIZER = ensureInitialized(); - - public static Object ensureInitialized() { - INSTANCE.ensureInitializedInternal(); - return null; - } - } - - private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { - private static final Blocks.GeneratedPQuery INSTANCE = new GeneratedPQuery(); - - private final PParameter parameter_class = new PParameter("class", "com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.nomagic.com/magicdraw/UML/2.5.1", "Class")), PParameterDirection.INOUT); - - private final List parameters = Arrays.asList(parameter_class); - - private GeneratedPQuery() { - super(PVisibility.PUBLIC); - } - - @Override - public String getFullyQualifiedName() { - return "com.incquerylabs.magicdraw.benchmark.queries.blocks"; - } - - @Override - public List getParameterNames() { - return Arrays.asList("class"); - } - - @Override - public List getParameters() { - return parameters; - } - - @Override - public Set doGetContainedBodies() { - setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); - Set bodies = new LinkedHashSet<>(); - { - PBody body = new PBody(this); - PVariable var_class = body.getOrCreateVariableByName("class"); - new TypeConstraint(body, Tuples.flatTupleOf(var_class), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Class"))); - body.setSymbolicParameters(Arrays.asList( - new ExportedParameter(body, var_class, parameter_class) - )); - // Class.appliedStereotypeInstance.classifier.name(class, "Block") - PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); - new ConstantValue(body, var__virtual_0_, "Block"); - new TypeConstraint(body, Tuples.flatTupleOf(var_class), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Class"))); - PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_class, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Element", "appliedStereotypeInstance"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "InstanceSpecification"))); - PVariable var__virtual_2_ = body.getOrCreateVariableByName(".virtual{2}"); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_, var__virtual_2_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "InstanceSpecification", "classifier"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_2_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Classifier"))); - PVariable var__virtual_3_ = body.getOrCreateVariableByName(".virtual{3}"); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_2_, var__virtual_3_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "NamedElement", "name"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_3_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "String"))); - new Equality(body, var__virtual_3_, var__virtual_0_); - bodies.add(body); - } - return bodies; - } - } -} diff --git a/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/BlocksOrRequirements.java b/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/BlocksOrRequirements.java deleted file mode 100644 index 5083e1e..0000000 --- a/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/BlocksOrRequirements.java +++ /dev/null @@ -1,565 +0,0 @@ -/** - * Generated from platform:/resource/com.incquerylabs.magicdraw.benchmark/src/main/java/com/incquerylabs/magicdraw/benchmark/queries/APerformanceQueries.vql - */ -package com.incquerylabs.magicdraw.benchmark.queries; - -import com.incquerylabs.magicdraw.benchmark.queries.Blocks; -import com.incquerylabs.magicdraw.benchmark.queries.Requirements; -import java.util.Arrays; -import java.util.Collection; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.function.Consumer; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import org.apache.log4j.Logger; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.viatra.query.runtime.api.IPatternMatch; -import org.eclipse.viatra.query.runtime.api.IQuerySpecification; -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.api.impl.BaseMatcher; -import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; -import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; -import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; -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.ExportedParameter; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.PositivePatternCall; -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.PVisibility; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; -import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; - -/** - * A pattern-specific query specification that can instantiate Matcher in a type-safe way. - * - *

Original source: - *

- *         Disjunction of blocks and requirements.
- *          
- *         pattern blocksOrRequirements(class : Class) {
- *         	find blocks(class);
- *         } or {
- *         	find requirements(class);
- *         }
- * 
- * - * @see Matcher - * @see Match - * - */ -@SuppressWarnings("all") -public final class BlocksOrRequirements extends BaseGeneratedEMFQuerySpecification { - /** - * Pattern-specific match representation of the com.incquerylabs.magicdraw.benchmark.queries.blocksOrRequirements pattern, - * to be used in conjunction with {@link Matcher}. - * - *

Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. - * Each instance is a (possibly partial) substitution of pattern parameters, - * usable to represent a match of the pattern in the result of a query, - * or to specify the bound (fixed) input parameters when issuing a query. - * - * @see Matcher - * - */ - public static abstract class Match extends BasePatternMatch { - private com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class fClass; - - private static List parameterNames = makeImmutableList("class"); - - private Match(final com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class pClass) { - this.fClass = pClass; - } - - @Override - public Object get(final String parameterName) { - switch(parameterName) { - case "class": return this.fClass; - default: return null; - } - } - - @Override - public Object get(final int index) { - switch(index) { - case 0: return this.fClass; - default: return null; - } - } - - public com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class getValueOfClass() { - return this.fClass; - } - - @Override - public boolean set(final String parameterName, final Object newValue) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - if ("class".equals(parameterName) ) { - this.fClass = (com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class) newValue; - return true; - } - return false; - } - - public void setClass(final com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class pClass) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fClass = pClass; - } - - @Override - public String patternName() { - return "com.incquerylabs.magicdraw.benchmark.queries.blocksOrRequirements"; - } - - @Override - public List parameterNames() { - return BlocksOrRequirements.Match.parameterNames; - } - - @Override - public Object[] toArray() { - return new Object[]{fClass}; - } - - @Override - public BlocksOrRequirements.Match toImmutable() { - return isMutable() ? newMatch(fClass) : this; - } - - @Override - public String prettyPrint() { - StringBuilder result = new StringBuilder(); - result.append("\"class\"=" + prettyPrintValue(fClass)); - return result.toString(); - } - - @Override - public int hashCode() { - return Objects.hash(fClass); - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) - return true; - if (obj == null) { - return false; - } - if ((obj instanceof BlocksOrRequirements.Match)) { - BlocksOrRequirements.Match other = (BlocksOrRequirements.Match) obj; - return Objects.equals(fClass, other.fClass); - } else { - // this should be infrequent - if (!(obj instanceof IPatternMatch)) { - return false; - } - IPatternMatch otherSig = (IPatternMatch) obj; - return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); - } - } - - @Override - public BlocksOrRequirements specification() { - return BlocksOrRequirements.instance(); - } - - /** - * Returns an empty, mutable match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @return the empty match. - * - */ - public static BlocksOrRequirements.Match newEmptyMatch() { - return new Mutable(null); - } - - /** - * Returns a mutable (partial) match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @param pClass the fixed value of pattern parameter class, or null if not bound. - * @return the new, mutable (partial) match object. - * - */ - public static BlocksOrRequirements.Match newMutableMatch(final com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class pClass) { - return new Mutable(pClass); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pClass the fixed value of pattern parameter class, or null if not bound. - * @return the (partial) match object. - * - */ - public static BlocksOrRequirements.Match newMatch(final com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class pClass) { - return new Immutable(pClass); - } - - private static final class Mutable extends BlocksOrRequirements.Match { - Mutable(final com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class pClass) { - super(pClass); - } - - @Override - public boolean isMutable() { - return true; - } - } - - private static final class Immutable extends BlocksOrRequirements.Match { - Immutable(final com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class pClass) { - super(pClass); - } - - @Override - public boolean isMutable() { - return false; - } - } - } - - /** - * Generated pattern matcher API of the com.incquerylabs.magicdraw.benchmark.queries.blocksOrRequirements pattern, - * providing pattern-specific query methods. - * - *

Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, - * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. - * - *

Matches of the pattern will be represented as {@link Match}. - * - *

Original source: - *

-   * Disjunction of blocks and requirements.
-   *  
-   * pattern blocksOrRequirements(class : Class) {
-   * 	find blocks(class);
-   * } or {
-   * 	find requirements(class);
-   * }
-   * 
- * - * @see Match - * @see BlocksOrRequirements - * - */ - public static class Matcher extends BaseMatcher { - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - public static BlocksOrRequirements.Matcher on(final ViatraQueryEngine engine) { - // check if matcher already exists - Matcher matcher = engine.getExistingMatcher(querySpecification()); - if (matcher == null) { - matcher = (Matcher)engine.getMatcher(querySpecification()); - } - return matcher; - } - - /** - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * @return an initialized matcher - * @noreference This method is for internal matcher initialization by the framework, do not call it manually. - * - */ - public static BlocksOrRequirements.Matcher create() { - return new Matcher(); - } - - private static final int POSITION_CLASS = 0; - - private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(BlocksOrRequirements.Matcher.class); - - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - private Matcher() { - super(querySpecification()); - } - - /** - * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pClass the fixed value of pattern parameter class, or null if not bound. - * @return matches represented as a Match object. - * - */ - public Collection getAllMatches(final com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class pClass) { - return rawStreamAllMatches(new Object[]{pClass}).collect(Collectors.toSet()); - } - - /** - * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * @param pClass the fixed value of pattern parameter class, or null if not bound. - * @return a stream of matches represented as a Match object. - * - */ - public Stream streamAllMatches(final com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class pClass) { - return rawStreamAllMatches(new Object[]{pClass}); - } - - /** - * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pClass the fixed value of pattern parameter class, or null if not bound. - * @return a match represented as a Match object, or null if no match is found. - * - */ - public Optional getOneArbitraryMatch(final com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class pClass) { - return rawGetOneArbitraryMatch(new Object[]{pClass}); - } - - /** - * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, - * under any possible substitution of the unspecified parameters (if any). - * @param pClass the fixed value of pattern parameter class, or null if not bound. - * @return true if the input is a valid (partial) match of the pattern. - * - */ - public boolean hasMatch(final com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class pClass) { - return rawHasMatch(new Object[]{pClass}); - } - - /** - * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pClass the fixed value of pattern parameter class, or null if not bound. - * @return the number of pattern matches found. - * - */ - public int countMatches(final com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class pClass) { - return rawCountMatches(new Object[]{pClass}); - } - - /** - * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pClass the fixed value of pattern parameter class, or null if not bound. - * @param processor the action that will process the selected match. - * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked - * - */ - public boolean forOneArbitraryMatch(final com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class pClass, final Consumer processor) { - return rawForOneArbitraryMatch(new Object[]{pClass}, processor); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pClass the fixed value of pattern parameter class, or null if not bound. - * @return the (partial) match object. - * - */ - public BlocksOrRequirements.Match newMatch(final com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class pClass) { - return BlocksOrRequirements.Match.newMatch(pClass); - } - - /** - * Retrieve the set of values that occur in matches for class. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOfclass(final Object[] parameters) { - return rawStreamAllValues(POSITION_CLASS, parameters).map(com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for class. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfclass() { - return rawStreamAllValuesOfclass(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for class. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfclass() { - return rawStreamAllValuesOfclass(emptyArray()); - } - - @Override - protected BlocksOrRequirements.Match tupleToMatch(final Tuple t) { - try { - return BlocksOrRequirements.Match.newMatch((com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class) t.get(POSITION_CLASS)); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in tuple not properly typed!",e); - return null; - } - } - - @Override - protected BlocksOrRequirements.Match arrayToMatch(final Object[] match) { - try { - return BlocksOrRequirements.Match.newMatch((com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class) match[POSITION_CLASS]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - @Override - protected BlocksOrRequirements.Match arrayToMatchMutable(final Object[] match) { - try { - return BlocksOrRequirements.Match.newMutableMatch((com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class) match[POSITION_CLASS]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - /** - * @return the singleton instance of the query specification of this pattern - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static IQuerySpecification querySpecification() { - return BlocksOrRequirements.instance(); - } - } - - private BlocksOrRequirements() { - super(GeneratedPQuery.INSTANCE); - } - - /** - * @return the singleton instance of the query specification - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static BlocksOrRequirements instance() { - try{ - return LazyHolder.INSTANCE; - } catch (ExceptionInInitializerError err) { - throw processInitializerError(err); - } - } - - @Override - protected BlocksOrRequirements.Matcher instantiate(final ViatraQueryEngine engine) { - return BlocksOrRequirements.Matcher.on(engine); - } - - @Override - public BlocksOrRequirements.Matcher instantiate() { - return BlocksOrRequirements.Matcher.create(); - } - - @Override - public BlocksOrRequirements.Match newEmptyMatch() { - return BlocksOrRequirements.Match.newEmptyMatch(); - } - - @Override - public BlocksOrRequirements.Match newMatch(final Object... parameters) { - return BlocksOrRequirements.Match.newMatch((com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class) parameters[0]); - } - - /** - * Inner class allowing the singleton instance of {@link BlocksOrRequirements} to be created - * not at the class load time of the outer class, - * but rather at the first call to {@link BlocksOrRequirements#instance()}. - * - *

This workaround is required e.g. to support recursion. - * - */ - private static class LazyHolder { - private static final BlocksOrRequirements INSTANCE = new BlocksOrRequirements(); - - /** - * Statically initializes the query specification after the field {@link #INSTANCE} is assigned. - * This initialization order is required to support indirect recursion. - * - *

The static initializer is defined using a helper field to work around limitations of the code generator. - * - */ - private static final Object STATIC_INITIALIZER = ensureInitialized(); - - public static Object ensureInitialized() { - INSTANCE.ensureInitializedInternal(); - return null; - } - } - - private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { - private static final BlocksOrRequirements.GeneratedPQuery INSTANCE = new GeneratedPQuery(); - - private final PParameter parameter_class = new PParameter("class", "com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.nomagic.com/magicdraw/UML/2.5.1", "Class")), PParameterDirection.INOUT); - - private final List parameters = Arrays.asList(parameter_class); - - private GeneratedPQuery() { - super(PVisibility.PUBLIC); - } - - @Override - public String getFullyQualifiedName() { - return "com.incquerylabs.magicdraw.benchmark.queries.blocksOrRequirements"; - } - - @Override - public List getParameterNames() { - return Arrays.asList("class"); - } - - @Override - public List getParameters() { - return parameters; - } - - @Override - public Set doGetContainedBodies() { - setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); - Set bodies = new LinkedHashSet<>(); - { - PBody body = new PBody(this); - PVariable var_class = body.getOrCreateVariableByName("class"); - new TypeConstraint(body, Tuples.flatTupleOf(var_class), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Class"))); - body.setSymbolicParameters(Arrays.asList( - new ExportedParameter(body, var_class, parameter_class) - )); - // find blocks(class) - new PositivePatternCall(body, Tuples.flatTupleOf(var_class), Blocks.instance().getInternalQueryRepresentation()); - bodies.add(body); - } - { - PBody body = new PBody(this); - PVariable var_class = body.getOrCreateVariableByName("class"); - new TypeConstraint(body, Tuples.flatTupleOf(var_class), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Class"))); - body.setSymbolicParameters(Arrays.asList( - new ExportedParameter(body, var_class, parameter_class) - )); - // find requirements(class) - new PositivePatternCall(body, Tuples.flatTupleOf(var_class), Requirements.instance().getInternalQueryRepresentation()); - bodies.add(body); - } - return bodies; - } - } -} diff --git a/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/BlocksOrRequirementsOrConstraints.java b/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/BlocksOrRequirementsOrConstraints.java deleted file mode 100644 index 2d6f435..0000000 --- a/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/BlocksOrRequirementsOrConstraints.java +++ /dev/null @@ -1,577 +0,0 @@ -/** - * Generated from platform:/resource/com.incquerylabs.magicdraw.benchmark/src/main/java/com/incquerylabs/magicdraw/benchmark/queries/APerformanceQueries.vql - */ -package com.incquerylabs.magicdraw.benchmark.queries; - -import com.incquerylabs.magicdraw.benchmark.queries.BlocksOrRequirements; -import com.incquerylabs.magicdraw.benchmark.queries.Dependencies; -import com.incquerylabs.magicdraw.benchmark.queries.internal.ConstraintBlocks; -import java.util.Arrays; -import java.util.Collection; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.function.Consumer; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import org.apache.log4j.Logger; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.viatra.query.runtime.api.IPatternMatch; -import org.eclipse.viatra.query.runtime.api.IQuerySpecification; -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.api.impl.BaseMatcher; -import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; -import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; -import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; -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.ExportedParameter; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.NegativePatternCall; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.PositivePatternCall; -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.PVisibility; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; -import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; - -/** - * A pattern-specific query specification that can instantiate Matcher in a type-safe way. - * - *

Original source: - *

- *         Disjunction reusing the blocksOrRequirements and constraintBlocks patterns and the negation of dependencies.
- *          
- *         pattern blocksOrRequirementsOrConstraints(class : Class) {
- *         	find blocksOrRequirements(class);
- *         } or {
- *         	find constraintBlocks(class);
- *         	neg find dependencies(class, _);
- *         	neg find dependencies(_, class);
- *         }
- * 
- * - * @see Matcher - * @see Match - * - */ -@SuppressWarnings("all") -public final class BlocksOrRequirementsOrConstraints extends BaseGeneratedEMFQuerySpecification { - /** - * Pattern-specific match representation of the com.incquerylabs.magicdraw.benchmark.queries.blocksOrRequirementsOrConstraints pattern, - * to be used in conjunction with {@link Matcher}. - * - *

Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. - * Each instance is a (possibly partial) substitution of pattern parameters, - * usable to represent a match of the pattern in the result of a query, - * or to specify the bound (fixed) input parameters when issuing a query. - * - * @see Matcher - * - */ - public static abstract class Match extends BasePatternMatch { - private com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class fClass; - - private static List parameterNames = makeImmutableList("class"); - - private Match(final com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class pClass) { - this.fClass = pClass; - } - - @Override - public Object get(final String parameterName) { - switch(parameterName) { - case "class": return this.fClass; - default: return null; - } - } - - @Override - public Object get(final int index) { - switch(index) { - case 0: return this.fClass; - default: return null; - } - } - - public com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class getValueOfClass() { - return this.fClass; - } - - @Override - public boolean set(final String parameterName, final Object newValue) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - if ("class".equals(parameterName) ) { - this.fClass = (com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class) newValue; - return true; - } - return false; - } - - public void setClass(final com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class pClass) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fClass = pClass; - } - - @Override - public String patternName() { - return "com.incquerylabs.magicdraw.benchmark.queries.blocksOrRequirementsOrConstraints"; - } - - @Override - public List parameterNames() { - return BlocksOrRequirementsOrConstraints.Match.parameterNames; - } - - @Override - public Object[] toArray() { - return new Object[]{fClass}; - } - - @Override - public BlocksOrRequirementsOrConstraints.Match toImmutable() { - return isMutable() ? newMatch(fClass) : this; - } - - @Override - public String prettyPrint() { - StringBuilder result = new StringBuilder(); - result.append("\"class\"=" + prettyPrintValue(fClass)); - return result.toString(); - } - - @Override - public int hashCode() { - return Objects.hash(fClass); - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) - return true; - if (obj == null) { - return false; - } - if ((obj instanceof BlocksOrRequirementsOrConstraints.Match)) { - BlocksOrRequirementsOrConstraints.Match other = (BlocksOrRequirementsOrConstraints.Match) obj; - return Objects.equals(fClass, other.fClass); - } else { - // this should be infrequent - if (!(obj instanceof IPatternMatch)) { - return false; - } - IPatternMatch otherSig = (IPatternMatch) obj; - return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); - } - } - - @Override - public BlocksOrRequirementsOrConstraints specification() { - return BlocksOrRequirementsOrConstraints.instance(); - } - - /** - * Returns an empty, mutable match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @return the empty match. - * - */ - public static BlocksOrRequirementsOrConstraints.Match newEmptyMatch() { - return new Mutable(null); - } - - /** - * Returns a mutable (partial) match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @param pClass the fixed value of pattern parameter class, or null if not bound. - * @return the new, mutable (partial) match object. - * - */ - public static BlocksOrRequirementsOrConstraints.Match newMutableMatch(final com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class pClass) { - return new Mutable(pClass); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pClass the fixed value of pattern parameter class, or null if not bound. - * @return the (partial) match object. - * - */ - public static BlocksOrRequirementsOrConstraints.Match newMatch(final com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class pClass) { - return new Immutable(pClass); - } - - private static final class Mutable extends BlocksOrRequirementsOrConstraints.Match { - Mutable(final com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class pClass) { - super(pClass); - } - - @Override - public boolean isMutable() { - return true; - } - } - - private static final class Immutable extends BlocksOrRequirementsOrConstraints.Match { - Immutable(final com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class pClass) { - super(pClass); - } - - @Override - public boolean isMutable() { - return false; - } - } - } - - /** - * Generated pattern matcher API of the com.incquerylabs.magicdraw.benchmark.queries.blocksOrRequirementsOrConstraints pattern, - * providing pattern-specific query methods. - * - *

Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, - * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. - * - *

Matches of the pattern will be represented as {@link Match}. - * - *

Original source: - *

-   * Disjunction reusing the blocksOrRequirements and constraintBlocks patterns and the negation of dependencies.
-   *  
-   * pattern blocksOrRequirementsOrConstraints(class : Class) {
-   * 	find blocksOrRequirements(class);
-   * } or {
-   * 	find constraintBlocks(class);
-   * 	neg find dependencies(class, _);
-   * 	neg find dependencies(_, class);
-   * }
-   * 
- * - * @see Match - * @see BlocksOrRequirementsOrConstraints - * - */ - public static class Matcher extends BaseMatcher { - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - public static BlocksOrRequirementsOrConstraints.Matcher on(final ViatraQueryEngine engine) { - // check if matcher already exists - Matcher matcher = engine.getExistingMatcher(querySpecification()); - if (matcher == null) { - matcher = (Matcher)engine.getMatcher(querySpecification()); - } - return matcher; - } - - /** - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * @return an initialized matcher - * @noreference This method is for internal matcher initialization by the framework, do not call it manually. - * - */ - public static BlocksOrRequirementsOrConstraints.Matcher create() { - return new Matcher(); - } - - private static final int POSITION_CLASS = 0; - - private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(BlocksOrRequirementsOrConstraints.Matcher.class); - - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - private Matcher() { - super(querySpecification()); - } - - /** - * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pClass the fixed value of pattern parameter class, or null if not bound. - * @return matches represented as a Match object. - * - */ - public Collection getAllMatches(final com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class pClass) { - return rawStreamAllMatches(new Object[]{pClass}).collect(Collectors.toSet()); - } - - /** - * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * @param pClass the fixed value of pattern parameter class, or null if not bound. - * @return a stream of matches represented as a Match object. - * - */ - public Stream streamAllMatches(final com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class pClass) { - return rawStreamAllMatches(new Object[]{pClass}); - } - - /** - * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pClass the fixed value of pattern parameter class, or null if not bound. - * @return a match represented as a Match object, or null if no match is found. - * - */ - public Optional getOneArbitraryMatch(final com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class pClass) { - return rawGetOneArbitraryMatch(new Object[]{pClass}); - } - - /** - * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, - * under any possible substitution of the unspecified parameters (if any). - * @param pClass the fixed value of pattern parameter class, or null if not bound. - * @return true if the input is a valid (partial) match of the pattern. - * - */ - public boolean hasMatch(final com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class pClass) { - return rawHasMatch(new Object[]{pClass}); - } - - /** - * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pClass the fixed value of pattern parameter class, or null if not bound. - * @return the number of pattern matches found. - * - */ - public int countMatches(final com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class pClass) { - return rawCountMatches(new Object[]{pClass}); - } - - /** - * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pClass the fixed value of pattern parameter class, or null if not bound. - * @param processor the action that will process the selected match. - * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked - * - */ - public boolean forOneArbitraryMatch(final com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class pClass, final Consumer processor) { - return rawForOneArbitraryMatch(new Object[]{pClass}, processor); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pClass the fixed value of pattern parameter class, or null if not bound. - * @return the (partial) match object. - * - */ - public BlocksOrRequirementsOrConstraints.Match newMatch(final com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class pClass) { - return BlocksOrRequirementsOrConstraints.Match.newMatch(pClass); - } - - /** - * Retrieve the set of values that occur in matches for class. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOfclass(final Object[] parameters) { - return rawStreamAllValues(POSITION_CLASS, parameters).map(com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for class. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfclass() { - return rawStreamAllValuesOfclass(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for class. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfclass() { - return rawStreamAllValuesOfclass(emptyArray()); - } - - @Override - protected BlocksOrRequirementsOrConstraints.Match tupleToMatch(final Tuple t) { - try { - return BlocksOrRequirementsOrConstraints.Match.newMatch((com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class) t.get(POSITION_CLASS)); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in tuple not properly typed!",e); - return null; - } - } - - @Override - protected BlocksOrRequirementsOrConstraints.Match arrayToMatch(final Object[] match) { - try { - return BlocksOrRequirementsOrConstraints.Match.newMatch((com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class) match[POSITION_CLASS]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - @Override - protected BlocksOrRequirementsOrConstraints.Match arrayToMatchMutable(final Object[] match) { - try { - return BlocksOrRequirementsOrConstraints.Match.newMutableMatch((com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class) match[POSITION_CLASS]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - /** - * @return the singleton instance of the query specification of this pattern - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static IQuerySpecification querySpecification() { - return BlocksOrRequirementsOrConstraints.instance(); - } - } - - private BlocksOrRequirementsOrConstraints() { - super(GeneratedPQuery.INSTANCE); - } - - /** - * @return the singleton instance of the query specification - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static BlocksOrRequirementsOrConstraints instance() { - try{ - return LazyHolder.INSTANCE; - } catch (ExceptionInInitializerError err) { - throw processInitializerError(err); - } - } - - @Override - protected BlocksOrRequirementsOrConstraints.Matcher instantiate(final ViatraQueryEngine engine) { - return BlocksOrRequirementsOrConstraints.Matcher.on(engine); - } - - @Override - public BlocksOrRequirementsOrConstraints.Matcher instantiate() { - return BlocksOrRequirementsOrConstraints.Matcher.create(); - } - - @Override - public BlocksOrRequirementsOrConstraints.Match newEmptyMatch() { - return BlocksOrRequirementsOrConstraints.Match.newEmptyMatch(); - } - - @Override - public BlocksOrRequirementsOrConstraints.Match newMatch(final Object... parameters) { - return BlocksOrRequirementsOrConstraints.Match.newMatch((com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class) parameters[0]); - } - - /** - * Inner class allowing the singleton instance of {@link BlocksOrRequirementsOrConstraints} to be created - * not at the class load time of the outer class, - * but rather at the first call to {@link BlocksOrRequirementsOrConstraints#instance()}. - * - *

This workaround is required e.g. to support recursion. - * - */ - private static class LazyHolder { - private static final BlocksOrRequirementsOrConstraints INSTANCE = new BlocksOrRequirementsOrConstraints(); - - /** - * Statically initializes the query specification after the field {@link #INSTANCE} is assigned. - * This initialization order is required to support indirect recursion. - * - *

The static initializer is defined using a helper field to work around limitations of the code generator. - * - */ - private static final Object STATIC_INITIALIZER = ensureInitialized(); - - public static Object ensureInitialized() { - INSTANCE.ensureInitializedInternal(); - return null; - } - } - - private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { - private static final BlocksOrRequirementsOrConstraints.GeneratedPQuery INSTANCE = new GeneratedPQuery(); - - private final PParameter parameter_class = new PParameter("class", "com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.nomagic.com/magicdraw/UML/2.5.1", "Class")), PParameterDirection.INOUT); - - private final List parameters = Arrays.asList(parameter_class); - - private GeneratedPQuery() { - super(PVisibility.PUBLIC); - } - - @Override - public String getFullyQualifiedName() { - return "com.incquerylabs.magicdraw.benchmark.queries.blocksOrRequirementsOrConstraints"; - } - - @Override - public List getParameterNames() { - return Arrays.asList("class"); - } - - @Override - public List getParameters() { - return parameters; - } - - @Override - public Set doGetContainedBodies() { - setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); - Set bodies = new LinkedHashSet<>(); - { - PBody body = new PBody(this); - PVariable var_class = body.getOrCreateVariableByName("class"); - new TypeConstraint(body, Tuples.flatTupleOf(var_class), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Class"))); - body.setSymbolicParameters(Arrays.asList( - new ExportedParameter(body, var_class, parameter_class) - )); - // find blocksOrRequirements(class) - new PositivePatternCall(body, Tuples.flatTupleOf(var_class), BlocksOrRequirements.instance().getInternalQueryRepresentation()); - bodies.add(body); - } - { - PBody body = new PBody(this); - PVariable var_class = body.getOrCreateVariableByName("class"); - PVariable var___0_ = body.getOrCreateVariableByName("_<0>"); - PVariable var___1_ = body.getOrCreateVariableByName("_<1>"); - new TypeConstraint(body, Tuples.flatTupleOf(var_class), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Class"))); - body.setSymbolicParameters(Arrays.asList( - new ExportedParameter(body, var_class, parameter_class) - )); - // find constraintBlocks(class) - new PositivePatternCall(body, Tuples.flatTupleOf(var_class), ConstraintBlocks.instance().getInternalQueryRepresentation()); - // neg find dependencies(class, _) - new NegativePatternCall(body, Tuples.flatTupleOf(var_class, var___0_), Dependencies.instance().getInternalQueryRepresentation()); - // neg find dependencies(_, class) - new NegativePatternCall(body, Tuples.flatTupleOf(var___1_, var_class), Dependencies.instance().getInternalQueryRepresentation()); - bodies.add(body); - } - return bodies; - } - } -} diff --git a/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/CircularDependencies.java b/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/CircularDependencies.java deleted file mode 100644 index fcefebe..0000000 --- a/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/CircularDependencies.java +++ /dev/null @@ -1,550 +0,0 @@ -/** - * Generated from platform:/resource/com.incquerylabs.magicdraw.benchmark/src/main/java/com/incquerylabs/magicdraw/benchmark/queries/APerformanceQueries.vql - */ -package com.incquerylabs.magicdraw.benchmark.queries; - -import com.incquerylabs.magicdraw.benchmark.queries.DependencyChains; -import com.nomagic.uml2.ext.magicdraw.classes.mddependencies.Dependency; -import java.util.Arrays; -import java.util.Collection; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.function.Consumer; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import org.apache.log4j.Logger; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.viatra.query.runtime.api.IPatternMatch; -import org.eclipse.viatra.query.runtime.api.IQuerySpecification; -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.api.impl.BaseMatcher; -import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; -import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; -import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; -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.ExportedParameter; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.BinaryTransitiveClosure; -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.PVisibility; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; -import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; - -/** - * A pattern-specific query specification that can instantiate Matcher in a type-safe way. - * - *

Original source: - *

- *         Pattern responsible for detecting circular dependency chains.
- *          
- *         pattern circularDependencies(dependency : Dependency) {
- *             find dependencyChains+(dependency, dependency);
- *         }
- * 
- * - * @see Matcher - * @see Match - * - */ -@SuppressWarnings("all") -public final class CircularDependencies extends BaseGeneratedEMFQuerySpecification { - /** - * Pattern-specific match representation of the com.incquerylabs.magicdraw.benchmark.queries.circularDependencies pattern, - * to be used in conjunction with {@link Matcher}. - * - *

Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. - * Each instance is a (possibly partial) substitution of pattern parameters, - * usable to represent a match of the pattern in the result of a query, - * or to specify the bound (fixed) input parameters when issuing a query. - * - * @see Matcher - * - */ - public static abstract class Match extends BasePatternMatch { - private Dependency fDependency; - - private static List parameterNames = makeImmutableList("dependency"); - - private Match(final Dependency pDependency) { - this.fDependency = pDependency; - } - - @Override - public Object get(final String parameterName) { - switch(parameterName) { - case "dependency": return this.fDependency; - default: return null; - } - } - - @Override - public Object get(final int index) { - switch(index) { - case 0: return this.fDependency; - default: return null; - } - } - - public Dependency getDependency() { - return this.fDependency; - } - - @Override - public boolean set(final String parameterName, final Object newValue) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - if ("dependency".equals(parameterName) ) { - this.fDependency = (Dependency) newValue; - return true; - } - return false; - } - - public void setDependency(final Dependency pDependency) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fDependency = pDependency; - } - - @Override - public String patternName() { - return "com.incquerylabs.magicdraw.benchmark.queries.circularDependencies"; - } - - @Override - public List parameterNames() { - return CircularDependencies.Match.parameterNames; - } - - @Override - public Object[] toArray() { - return new Object[]{fDependency}; - } - - @Override - public CircularDependencies.Match toImmutable() { - return isMutable() ? newMatch(fDependency) : this; - } - - @Override - public String prettyPrint() { - StringBuilder result = new StringBuilder(); - result.append("\"dependency\"=" + prettyPrintValue(fDependency)); - return result.toString(); - } - - @Override - public int hashCode() { - return Objects.hash(fDependency); - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) - return true; - if (obj == null) { - return false; - } - if ((obj instanceof CircularDependencies.Match)) { - CircularDependencies.Match other = (CircularDependencies.Match) obj; - return Objects.equals(fDependency, other.fDependency); - } else { - // this should be infrequent - if (!(obj instanceof IPatternMatch)) { - return false; - } - IPatternMatch otherSig = (IPatternMatch) obj; - return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); - } - } - - @Override - public CircularDependencies specification() { - return CircularDependencies.instance(); - } - - /** - * Returns an empty, mutable match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @return the empty match. - * - */ - public static CircularDependencies.Match newEmptyMatch() { - return new Mutable(null); - } - - /** - * Returns a mutable (partial) match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @param pDependency the fixed value of pattern parameter dependency, or null if not bound. - * @return the new, mutable (partial) match object. - * - */ - public static CircularDependencies.Match newMutableMatch(final Dependency pDependency) { - return new Mutable(pDependency); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pDependency the fixed value of pattern parameter dependency, or null if not bound. - * @return the (partial) match object. - * - */ - public static CircularDependencies.Match newMatch(final Dependency pDependency) { - return new Immutable(pDependency); - } - - private static final class Mutable extends CircularDependencies.Match { - Mutable(final Dependency pDependency) { - super(pDependency); - } - - @Override - public boolean isMutable() { - return true; - } - } - - private static final class Immutable extends CircularDependencies.Match { - Immutable(final Dependency pDependency) { - super(pDependency); - } - - @Override - public boolean isMutable() { - return false; - } - } - } - - /** - * Generated pattern matcher API of the com.incquerylabs.magicdraw.benchmark.queries.circularDependencies pattern, - * providing pattern-specific query methods. - * - *

Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, - * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. - * - *

Matches of the pattern will be represented as {@link Match}. - * - *

Original source: - *

-   * Pattern responsible for detecting circular dependency chains.
-   *  
-   * pattern circularDependencies(dependency : Dependency) {
-   *     find dependencyChains+(dependency, dependency);
-   * }
-   * 
- * - * @see Match - * @see CircularDependencies - * - */ - public static class Matcher extends BaseMatcher { - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - public static CircularDependencies.Matcher on(final ViatraQueryEngine engine) { - // check if matcher already exists - Matcher matcher = engine.getExistingMatcher(querySpecification()); - if (matcher == null) { - matcher = (Matcher)engine.getMatcher(querySpecification()); - } - return matcher; - } - - /** - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * @return an initialized matcher - * @noreference This method is for internal matcher initialization by the framework, do not call it manually. - * - */ - public static CircularDependencies.Matcher create() { - return new Matcher(); - } - - private static final int POSITION_DEPENDENCY = 0; - - private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(CircularDependencies.Matcher.class); - - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - private Matcher() { - super(querySpecification()); - } - - /** - * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pDependency the fixed value of pattern parameter dependency, or null if not bound. - * @return matches represented as a Match object. - * - */ - public Collection getAllMatches(final Dependency pDependency) { - return rawStreamAllMatches(new Object[]{pDependency}).collect(Collectors.toSet()); - } - - /** - * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * @param pDependency the fixed value of pattern parameter dependency, or null if not bound. - * @return a stream of matches represented as a Match object. - * - */ - public Stream streamAllMatches(final Dependency pDependency) { - return rawStreamAllMatches(new Object[]{pDependency}); - } - - /** - * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pDependency the fixed value of pattern parameter dependency, or null if not bound. - * @return a match represented as a Match object, or null if no match is found. - * - */ - public Optional getOneArbitraryMatch(final Dependency pDependency) { - return rawGetOneArbitraryMatch(new Object[]{pDependency}); - } - - /** - * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, - * under any possible substitution of the unspecified parameters (if any). - * @param pDependency the fixed value of pattern parameter dependency, or null if not bound. - * @return true if the input is a valid (partial) match of the pattern. - * - */ - public boolean hasMatch(final Dependency pDependency) { - return rawHasMatch(new Object[]{pDependency}); - } - - /** - * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pDependency the fixed value of pattern parameter dependency, or null if not bound. - * @return the number of pattern matches found. - * - */ - public int countMatches(final Dependency pDependency) { - return rawCountMatches(new Object[]{pDependency}); - } - - /** - * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pDependency the fixed value of pattern parameter dependency, or null if not bound. - * @param processor the action that will process the selected match. - * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked - * - */ - public boolean forOneArbitraryMatch(final Dependency pDependency, final Consumer processor) { - return rawForOneArbitraryMatch(new Object[]{pDependency}, processor); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pDependency the fixed value of pattern parameter dependency, or null if not bound. - * @return the (partial) match object. - * - */ - public CircularDependencies.Match newMatch(final Dependency pDependency) { - return CircularDependencies.Match.newMatch(pDependency); - } - - /** - * Retrieve the set of values that occur in matches for dependency. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOfdependency(final Object[] parameters) { - return rawStreamAllValues(POSITION_DEPENDENCY, parameters).map(Dependency.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for dependency. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfdependency() { - return rawStreamAllValuesOfdependency(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for dependency. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfdependency() { - return rawStreamAllValuesOfdependency(emptyArray()); - } - - @Override - protected CircularDependencies.Match tupleToMatch(final Tuple t) { - try { - return CircularDependencies.Match.newMatch((Dependency) t.get(POSITION_DEPENDENCY)); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in tuple not properly typed!",e); - return null; - } - } - - @Override - protected CircularDependencies.Match arrayToMatch(final Object[] match) { - try { - return CircularDependencies.Match.newMatch((Dependency) match[POSITION_DEPENDENCY]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - @Override - protected CircularDependencies.Match arrayToMatchMutable(final Object[] match) { - try { - return CircularDependencies.Match.newMutableMatch((Dependency) match[POSITION_DEPENDENCY]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - /** - * @return the singleton instance of the query specification of this pattern - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static IQuerySpecification querySpecification() { - return CircularDependencies.instance(); - } - } - - private CircularDependencies() { - super(GeneratedPQuery.INSTANCE); - } - - /** - * @return the singleton instance of the query specification - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static CircularDependencies instance() { - try{ - return LazyHolder.INSTANCE; - } catch (ExceptionInInitializerError err) { - throw processInitializerError(err); - } - } - - @Override - protected CircularDependencies.Matcher instantiate(final ViatraQueryEngine engine) { - return CircularDependencies.Matcher.on(engine); - } - - @Override - public CircularDependencies.Matcher instantiate() { - return CircularDependencies.Matcher.create(); - } - - @Override - public CircularDependencies.Match newEmptyMatch() { - return CircularDependencies.Match.newEmptyMatch(); - } - - @Override - public CircularDependencies.Match newMatch(final Object... parameters) { - return CircularDependencies.Match.newMatch((com.nomagic.uml2.ext.magicdraw.classes.mddependencies.Dependency) parameters[0]); - } - - /** - * Inner class allowing the singleton instance of {@link CircularDependencies} to be created - * not at the class load time of the outer class, - * but rather at the first call to {@link CircularDependencies#instance()}. - * - *

This workaround is required e.g. to support recursion. - * - */ - private static class LazyHolder { - private static final CircularDependencies INSTANCE = new CircularDependencies(); - - /** - * Statically initializes the query specification after the field {@link #INSTANCE} is assigned. - * This initialization order is required to support indirect recursion. - * - *

The static initializer is defined using a helper field to work around limitations of the code generator. - * - */ - private static final Object STATIC_INITIALIZER = ensureInitialized(); - - public static Object ensureInitialized() { - INSTANCE.ensureInitializedInternal(); - return null; - } - } - - private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { - private static final CircularDependencies.GeneratedPQuery INSTANCE = new GeneratedPQuery(); - - private final PParameter parameter_dependency = new PParameter("dependency", "com.nomagic.uml2.ext.magicdraw.classes.mddependencies.Dependency", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.nomagic.com/magicdraw/UML/2.5.1", "Dependency")), PParameterDirection.INOUT); - - private final List parameters = Arrays.asList(parameter_dependency); - - private GeneratedPQuery() { - super(PVisibility.PUBLIC); - } - - @Override - public String getFullyQualifiedName() { - return "com.incquerylabs.magicdraw.benchmark.queries.circularDependencies"; - } - - @Override - public List getParameterNames() { - return Arrays.asList("dependency"); - } - - @Override - public List getParameters() { - return parameters; - } - - @Override - public Set doGetContainedBodies() { - setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); - Set bodies = new LinkedHashSet<>(); - { - PBody body = new PBody(this); - PVariable var_dependency = body.getOrCreateVariableByName("dependency"); - new TypeConstraint(body, Tuples.flatTupleOf(var_dependency), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Dependency"))); - body.setSymbolicParameters(Arrays.asList( - new ExportedParameter(body, var_dependency, parameter_dependency) - )); - // find dependencyChains+(dependency, dependency) - new BinaryTransitiveClosure(body, Tuples.flatTupleOf(var_dependency, var_dependency), DependencyChains.instance().getInternalQueryRepresentation()); - bodies.add(body); - } - return bodies; - } - } -} diff --git a/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/Classes.java b/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/Classes.java deleted file mode 100644 index f3afc1a..0000000 --- a/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/Classes.java +++ /dev/null @@ -1,547 +0,0 @@ -/** - * Generated from platform:/resource/com.incquerylabs.magicdraw.benchmark/src/main/java/com/incquerylabs/magicdraw/benchmark/queries/APerformanceQueries.vql - */ -package com.incquerylabs.magicdraw.benchmark.queries; - -import java.util.Arrays; -import java.util.Collection; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.function.Consumer; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import org.apache.log4j.Logger; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.viatra.query.runtime.api.IPatternMatch; -import org.eclipse.viatra.query.runtime.api.IQuerySpecification; -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.api.impl.BaseMatcher; -import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; -import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; -import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; -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.ExportedParameter; -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.PVisibility; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; -import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; - -/** - * A pattern-specific query specification that can instantiate Matcher in a type-safe way. - * - *

Original source: - *

- *         Querying all instances of an EClass. 
- *          
- *         pattern classes(class : Class) {
- *         	Class(class);
- *         }
- * 
- * - * @see Matcher - * @see Match - * - */ -@SuppressWarnings("all") -public final class Classes extends BaseGeneratedEMFQuerySpecification { - /** - * Pattern-specific match representation of the com.incquerylabs.magicdraw.benchmark.queries.classes pattern, - * to be used in conjunction with {@link Matcher}. - * - *

Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. - * Each instance is a (possibly partial) substitution of pattern parameters, - * usable to represent a match of the pattern in the result of a query, - * or to specify the bound (fixed) input parameters when issuing a query. - * - * @see Matcher - * - */ - public static abstract class Match extends BasePatternMatch { - private com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class fClass; - - private static List parameterNames = makeImmutableList("class"); - - private Match(final com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class pClass) { - this.fClass = pClass; - } - - @Override - public Object get(final String parameterName) { - switch(parameterName) { - case "class": return this.fClass; - default: return null; - } - } - - @Override - public Object get(final int index) { - switch(index) { - case 0: return this.fClass; - default: return null; - } - } - - public com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class getValueOfClass() { - return this.fClass; - } - - @Override - public boolean set(final String parameterName, final Object newValue) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - if ("class".equals(parameterName) ) { - this.fClass = (com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class) newValue; - return true; - } - return false; - } - - public void setClass(final com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class pClass) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fClass = pClass; - } - - @Override - public String patternName() { - return "com.incquerylabs.magicdraw.benchmark.queries.classes"; - } - - @Override - public List parameterNames() { - return Classes.Match.parameterNames; - } - - @Override - public Object[] toArray() { - return new Object[]{fClass}; - } - - @Override - public Classes.Match toImmutable() { - return isMutable() ? newMatch(fClass) : this; - } - - @Override - public String prettyPrint() { - StringBuilder result = new StringBuilder(); - result.append("\"class\"=" + prettyPrintValue(fClass)); - return result.toString(); - } - - @Override - public int hashCode() { - return Objects.hash(fClass); - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) - return true; - if (obj == null) { - return false; - } - if ((obj instanceof Classes.Match)) { - Classes.Match other = (Classes.Match) obj; - return Objects.equals(fClass, other.fClass); - } else { - // this should be infrequent - if (!(obj instanceof IPatternMatch)) { - return false; - } - IPatternMatch otherSig = (IPatternMatch) obj; - return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); - } - } - - @Override - public Classes specification() { - return Classes.instance(); - } - - /** - * Returns an empty, mutable match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @return the empty match. - * - */ - public static Classes.Match newEmptyMatch() { - return new Mutable(null); - } - - /** - * Returns a mutable (partial) match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @param pClass the fixed value of pattern parameter class, or null if not bound. - * @return the new, mutable (partial) match object. - * - */ - public static Classes.Match newMutableMatch(final com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class pClass) { - return new Mutable(pClass); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pClass the fixed value of pattern parameter class, or null if not bound. - * @return the (partial) match object. - * - */ - public static Classes.Match newMatch(final com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class pClass) { - return new Immutable(pClass); - } - - private static final class Mutable extends Classes.Match { - Mutable(final com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class pClass) { - super(pClass); - } - - @Override - public boolean isMutable() { - return true; - } - } - - private static final class Immutable extends Classes.Match { - Immutable(final com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class pClass) { - super(pClass); - } - - @Override - public boolean isMutable() { - return false; - } - } - } - - /** - * Generated pattern matcher API of the com.incquerylabs.magicdraw.benchmark.queries.classes pattern, - * providing pattern-specific query methods. - * - *

Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, - * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. - * - *

Matches of the pattern will be represented as {@link Match}. - * - *

Original source: - *

-   * Querying all instances of an EClass. 
-   *  
-   * pattern classes(class : Class) {
-   * 	Class(class);
-   * }
-   * 
- * - * @see Match - * @see Classes - * - */ - public static class Matcher extends BaseMatcher { - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - public static Classes.Matcher on(final ViatraQueryEngine engine) { - // check if matcher already exists - Matcher matcher = engine.getExistingMatcher(querySpecification()); - if (matcher == null) { - matcher = (Matcher)engine.getMatcher(querySpecification()); - } - return matcher; - } - - /** - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * @return an initialized matcher - * @noreference This method is for internal matcher initialization by the framework, do not call it manually. - * - */ - public static Classes.Matcher create() { - return new Matcher(); - } - - private static final int POSITION_CLASS = 0; - - private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(Classes.Matcher.class); - - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - private Matcher() { - super(querySpecification()); - } - - /** - * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pClass the fixed value of pattern parameter class, or null if not bound. - * @return matches represented as a Match object. - * - */ - public Collection getAllMatches(final com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class pClass) { - return rawStreamAllMatches(new Object[]{pClass}).collect(Collectors.toSet()); - } - - /** - * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * @param pClass the fixed value of pattern parameter class, or null if not bound. - * @return a stream of matches represented as a Match object. - * - */ - public Stream streamAllMatches(final com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class pClass) { - return rawStreamAllMatches(new Object[]{pClass}); - } - - /** - * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pClass the fixed value of pattern parameter class, or null if not bound. - * @return a match represented as a Match object, or null if no match is found. - * - */ - public Optional getOneArbitraryMatch(final com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class pClass) { - return rawGetOneArbitraryMatch(new Object[]{pClass}); - } - - /** - * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, - * under any possible substitution of the unspecified parameters (if any). - * @param pClass the fixed value of pattern parameter class, or null if not bound. - * @return true if the input is a valid (partial) match of the pattern. - * - */ - public boolean hasMatch(final com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class pClass) { - return rawHasMatch(new Object[]{pClass}); - } - - /** - * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pClass the fixed value of pattern parameter class, or null if not bound. - * @return the number of pattern matches found. - * - */ - public int countMatches(final com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class pClass) { - return rawCountMatches(new Object[]{pClass}); - } - - /** - * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pClass the fixed value of pattern parameter class, or null if not bound. - * @param processor the action that will process the selected match. - * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked - * - */ - public boolean forOneArbitraryMatch(final com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class pClass, final Consumer processor) { - return rawForOneArbitraryMatch(new Object[]{pClass}, processor); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pClass the fixed value of pattern parameter class, or null if not bound. - * @return the (partial) match object. - * - */ - public Classes.Match newMatch(final com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class pClass) { - return Classes.Match.newMatch(pClass); - } - - /** - * Retrieve the set of values that occur in matches for class. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOfclass(final Object[] parameters) { - return rawStreamAllValues(POSITION_CLASS, parameters).map(com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for class. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfclass() { - return rawStreamAllValuesOfclass(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for class. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfclass() { - return rawStreamAllValuesOfclass(emptyArray()); - } - - @Override - protected Classes.Match tupleToMatch(final Tuple t) { - try { - return Classes.Match.newMatch((com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class) t.get(POSITION_CLASS)); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in tuple not properly typed!",e); - return null; - } - } - - @Override - protected Classes.Match arrayToMatch(final Object[] match) { - try { - return Classes.Match.newMatch((com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class) match[POSITION_CLASS]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - @Override - protected Classes.Match arrayToMatchMutable(final Object[] match) { - try { - return Classes.Match.newMutableMatch((com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class) match[POSITION_CLASS]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - /** - * @return the singleton instance of the query specification of this pattern - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static IQuerySpecification querySpecification() { - return Classes.instance(); - } - } - - private Classes() { - super(GeneratedPQuery.INSTANCE); - } - - /** - * @return the singleton instance of the query specification - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static Classes instance() { - try{ - return LazyHolder.INSTANCE; - } catch (ExceptionInInitializerError err) { - throw processInitializerError(err); - } - } - - @Override - protected Classes.Matcher instantiate(final ViatraQueryEngine engine) { - return Classes.Matcher.on(engine); - } - - @Override - public Classes.Matcher instantiate() { - return Classes.Matcher.create(); - } - - @Override - public Classes.Match newEmptyMatch() { - return Classes.Match.newEmptyMatch(); - } - - @Override - public Classes.Match newMatch(final Object... parameters) { - return Classes.Match.newMatch((com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class) parameters[0]); - } - - /** - * Inner class allowing the singleton instance of {@link Classes} to be created - * not at the class load time of the outer class, - * but rather at the first call to {@link Classes#instance()}. - * - *

This workaround is required e.g. to support recursion. - * - */ - private static class LazyHolder { - private static final Classes INSTANCE = new Classes(); - - /** - * Statically initializes the query specification after the field {@link #INSTANCE} is assigned. - * This initialization order is required to support indirect recursion. - * - *

The static initializer is defined using a helper field to work around limitations of the code generator. - * - */ - private static final Object STATIC_INITIALIZER = ensureInitialized(); - - public static Object ensureInitialized() { - INSTANCE.ensureInitializedInternal(); - return null; - } - } - - private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { - private static final Classes.GeneratedPQuery INSTANCE = new GeneratedPQuery(); - - private final PParameter parameter_class = new PParameter("class", "com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.nomagic.com/magicdraw/UML/2.5.1", "Class")), PParameterDirection.INOUT); - - private final List parameters = Arrays.asList(parameter_class); - - private GeneratedPQuery() { - super(PVisibility.PUBLIC); - } - - @Override - public String getFullyQualifiedName() { - return "com.incquerylabs.magicdraw.benchmark.queries.classes"; - } - - @Override - public List getParameterNames() { - return Arrays.asList("class"); - } - - @Override - public List getParameters() { - return parameters; - } - - @Override - public Set doGetContainedBodies() { - setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); - Set bodies = new LinkedHashSet<>(); - { - PBody body = new PBody(this); - PVariable var_class = body.getOrCreateVariableByName("class"); - new TypeConstraint(body, Tuples.flatTupleOf(var_class), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Class"))); - body.setSymbolicParameters(Arrays.asList( - new ExportedParameter(body, var_class, parameter_class) - )); - // Class(class) - new TypeConstraint(body, Tuples.flatTupleOf(var_class), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Class"))); - bodies.add(body); - } - return bodies; - } - } -} diff --git a/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/ComplexNameOfElements.java b/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/ComplexNameOfElements.java deleted file mode 100644 index 3ae7e85..0000000 --- a/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/ComplexNameOfElements.java +++ /dev/null @@ -1,750 +0,0 @@ -/** - * Generated from platform:/resource/com.incquerylabs.magicdraw.benchmark/src/main/java/com/incquerylabs/magicdraw/benchmark/queries/APerformanceQueries.vql - */ -package com.incquerylabs.magicdraw.benchmark.queries; - -import com.nomagic.uml2.ext.magicdraw.classes.mdkernel.NamedElement; -import java.util.Arrays; -import java.util.Collection; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.function.Consumer; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import org.apache.log4j.Logger; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.viatra.query.runtime.api.IPatternMatch; -import org.eclipse.viatra.query.runtime.api.IQuerySpecification; -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.api.impl.BaseMatcher; -import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; -import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; -import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; -import org.eclipse.viatra.query.runtime.matchers.context.common.JavaTransitiveInstancesKey; -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.basicdeferred.TypeFilterConstraint; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.PositivePatternCall; -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.PVisibility; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; -import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; -import org.eclipse.xtext.xbase.lib.StringExtensions; - -/** - * A pattern-specific query specification that can instantiate Matcher in a type-safe way. - * - *

Original source: - *

- *         Reusing namedElement and eval the names.
- *          
- *         pattern complexNameOfElements(element : NamedElement, complexName : java ^java.lang.String) {
- *         	find namedElement(element, name);
- *         	complexName == eval(name.toFirstUpper + ". "+ name.toFirstLower + "." + name.toUpperCase + "." + name.toLowerCase + "." + name.length); 
- *         }
- * 
- * - * @see Matcher - * @see Match - * - */ -@SuppressWarnings("all") -public final class ComplexNameOfElements extends BaseGeneratedEMFQuerySpecification { - /** - * Pattern-specific match representation of the com.incquerylabs.magicdraw.benchmark.queries.complexNameOfElements pattern, - * to be used in conjunction with {@link Matcher}. - * - *

Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. - * Each instance is a (possibly partial) substitution of pattern parameters, - * usable to represent a match of the pattern in the result of a query, - * or to specify the bound (fixed) input parameters when issuing a query. - * - * @see Matcher - * - */ - public static abstract class Match extends BasePatternMatch { - private NamedElement fElement; - - private String fComplexName; - - private static List parameterNames = makeImmutableList("element", "complexName"); - - private Match(final NamedElement pElement, final String pComplexName) { - this.fElement = pElement; - this.fComplexName = pComplexName; - } - - @Override - public Object get(final String parameterName) { - switch(parameterName) { - case "element": return this.fElement; - case "complexName": return this.fComplexName; - default: return null; - } - } - - @Override - public Object get(final int index) { - switch(index) { - case 0: return this.fElement; - case 1: return this.fComplexName; - default: return null; - } - } - - public NamedElement getElement() { - return this.fElement; - } - - public String getComplexName() { - return this.fComplexName; - } - - @Override - public boolean set(final String parameterName, final Object newValue) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - if ("element".equals(parameterName) ) { - this.fElement = (NamedElement) newValue; - return true; - } - if ("complexName".equals(parameterName) ) { - this.fComplexName = (String) newValue; - return true; - } - return false; - } - - public void setElement(final NamedElement pElement) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fElement = pElement; - } - - public void setComplexName(final String pComplexName) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fComplexName = pComplexName; - } - - @Override - public String patternName() { - return "com.incquerylabs.magicdraw.benchmark.queries.complexNameOfElements"; - } - - @Override - public List parameterNames() { - return ComplexNameOfElements.Match.parameterNames; - } - - @Override - public Object[] toArray() { - return new Object[]{fElement, fComplexName}; - } - - @Override - public ComplexNameOfElements.Match toImmutable() { - return isMutable() ? newMatch(fElement, fComplexName) : this; - } - - @Override - public String prettyPrint() { - StringBuilder result = new StringBuilder(); - result.append("\"element\"=" + prettyPrintValue(fElement) + ", "); - result.append("\"complexName\"=" + prettyPrintValue(fComplexName)); - return result.toString(); - } - - @Override - public int hashCode() { - return Objects.hash(fElement, fComplexName); - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) - return true; - if (obj == null) { - return false; - } - if ((obj instanceof ComplexNameOfElements.Match)) { - ComplexNameOfElements.Match other = (ComplexNameOfElements.Match) obj; - return Objects.equals(fElement, other.fElement) && Objects.equals(fComplexName, other.fComplexName); - } else { - // this should be infrequent - if (!(obj instanceof IPatternMatch)) { - return false; - } - IPatternMatch otherSig = (IPatternMatch) obj; - return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); - } - } - - @Override - public ComplexNameOfElements specification() { - return ComplexNameOfElements.instance(); - } - - /** - * Returns an empty, mutable match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @return the empty match. - * - */ - public static ComplexNameOfElements.Match newEmptyMatch() { - return new Mutable(null, null); - } - - /** - * Returns a mutable (partial) match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @param pElement the fixed value of pattern parameter element, or null if not bound. - * @param pComplexName the fixed value of pattern parameter complexName, or null if not bound. - * @return the new, mutable (partial) match object. - * - */ - public static ComplexNameOfElements.Match newMutableMatch(final NamedElement pElement, final String pComplexName) { - return new Mutable(pElement, pComplexName); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pElement the fixed value of pattern parameter element, or null if not bound. - * @param pComplexName the fixed value of pattern parameter complexName, or null if not bound. - * @return the (partial) match object. - * - */ - public static ComplexNameOfElements.Match newMatch(final NamedElement pElement, final String pComplexName) { - return new Immutable(pElement, pComplexName); - } - - private static final class Mutable extends ComplexNameOfElements.Match { - Mutable(final NamedElement pElement, final String pComplexName) { - super(pElement, pComplexName); - } - - @Override - public boolean isMutable() { - return true; - } - } - - private static final class Immutable extends ComplexNameOfElements.Match { - Immutable(final NamedElement pElement, final String pComplexName) { - super(pElement, pComplexName); - } - - @Override - public boolean isMutable() { - return false; - } - } - } - - /** - * Generated pattern matcher API of the com.incquerylabs.magicdraw.benchmark.queries.complexNameOfElements pattern, - * providing pattern-specific query methods. - * - *

Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, - * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. - * - *

Matches of the pattern will be represented as {@link Match}. - * - *

Original source: - *

-   * Reusing namedElement and eval the names.
-   *  
-   * pattern complexNameOfElements(element : NamedElement, complexName : java ^java.lang.String) {
-   * 	find namedElement(element, name);
-   * 	complexName == eval(name.toFirstUpper + ". "+ name.toFirstLower + "." + name.toUpperCase + "." + name.toLowerCase + "." + name.length); 
-   * }
-   * 
- * - * @see Match - * @see ComplexNameOfElements - * - */ - public static class Matcher extends BaseMatcher { - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - public static ComplexNameOfElements.Matcher on(final ViatraQueryEngine engine) { - // check if matcher already exists - Matcher matcher = engine.getExistingMatcher(querySpecification()); - if (matcher == null) { - matcher = (Matcher)engine.getMatcher(querySpecification()); - } - return matcher; - } - - /** - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * @return an initialized matcher - * @noreference This method is for internal matcher initialization by the framework, do not call it manually. - * - */ - public static ComplexNameOfElements.Matcher create() { - return new Matcher(); - } - - private static final int POSITION_ELEMENT = 0; - - private static final int POSITION_COMPLEXNAME = 1; - - private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(ComplexNameOfElements.Matcher.class); - - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - private Matcher() { - super(querySpecification()); - } - - /** - * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pElement the fixed value of pattern parameter element, or null if not bound. - * @param pComplexName the fixed value of pattern parameter complexName, or null if not bound. - * @return matches represented as a Match object. - * - */ - public Collection getAllMatches(final NamedElement pElement, final String pComplexName) { - return rawStreamAllMatches(new Object[]{pElement, pComplexName}).collect(Collectors.toSet()); - } - - /** - * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * @param pElement the fixed value of pattern parameter element, or null if not bound. - * @param pComplexName the fixed value of pattern parameter complexName, or null if not bound. - * @return a stream of matches represented as a Match object. - * - */ - public Stream streamAllMatches(final NamedElement pElement, final String pComplexName) { - return rawStreamAllMatches(new Object[]{pElement, pComplexName}); - } - - /** - * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pElement the fixed value of pattern parameter element, or null if not bound. - * @param pComplexName the fixed value of pattern parameter complexName, or null if not bound. - * @return a match represented as a Match object, or null if no match is found. - * - */ - public Optional getOneArbitraryMatch(final NamedElement pElement, final String pComplexName) { - return rawGetOneArbitraryMatch(new Object[]{pElement, pComplexName}); - } - - /** - * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, - * under any possible substitution of the unspecified parameters (if any). - * @param pElement the fixed value of pattern parameter element, or null if not bound. - * @param pComplexName the fixed value of pattern parameter complexName, or null if not bound. - * @return true if the input is a valid (partial) match of the pattern. - * - */ - public boolean hasMatch(final NamedElement pElement, final String pComplexName) { - return rawHasMatch(new Object[]{pElement, pComplexName}); - } - - /** - * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pElement the fixed value of pattern parameter element, or null if not bound. - * @param pComplexName the fixed value of pattern parameter complexName, or null if not bound. - * @return the number of pattern matches found. - * - */ - public int countMatches(final NamedElement pElement, final String pComplexName) { - return rawCountMatches(new Object[]{pElement, pComplexName}); - } - - /** - * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pElement the fixed value of pattern parameter element, or null if not bound. - * @param pComplexName the fixed value of pattern parameter complexName, or null if not bound. - * @param processor the action that will process the selected match. - * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked - * - */ - public boolean forOneArbitraryMatch(final NamedElement pElement, final String pComplexName, final Consumer processor) { - return rawForOneArbitraryMatch(new Object[]{pElement, pComplexName}, processor); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pElement the fixed value of pattern parameter element, or null if not bound. - * @param pComplexName the fixed value of pattern parameter complexName, or null if not bound. - * @return the (partial) match object. - * - */ - public ComplexNameOfElements.Match newMatch(final NamedElement pElement, final String pComplexName) { - return ComplexNameOfElements.Match.newMatch(pElement, pComplexName); - } - - /** - * Retrieve the set of values that occur in matches for element. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOfelement(final Object[] parameters) { - return rawStreamAllValues(POSITION_ELEMENT, parameters).map(NamedElement.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for element. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfelement() { - return rawStreamAllValuesOfelement(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for element. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfelement() { - return rawStreamAllValuesOfelement(emptyArray()); - } - - /** - * Retrieve the set of values that occur in matches for element. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfelement(final ComplexNameOfElements.Match partialMatch) { - return rawStreamAllValuesOfelement(partialMatch.toArray()); - } - - /** - * Retrieve the set of values that occur in matches for element. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfelement(final String pComplexName) { - return rawStreamAllValuesOfelement(new Object[]{null, pComplexName}); - } - - /** - * Retrieve the set of values that occur in matches for element. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfelement(final ComplexNameOfElements.Match partialMatch) { - return rawStreamAllValuesOfelement(partialMatch.toArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for element. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfelement(final String pComplexName) { - return rawStreamAllValuesOfelement(new Object[]{null, pComplexName}).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for complexName. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOfcomplexName(final Object[] parameters) { - return rawStreamAllValues(POSITION_COMPLEXNAME, parameters).map(String.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for complexName. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfcomplexName() { - return rawStreamAllValuesOfcomplexName(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for complexName. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfcomplexName() { - return rawStreamAllValuesOfcomplexName(emptyArray()); - } - - /** - * Retrieve the set of values that occur in matches for complexName. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfcomplexName(final ComplexNameOfElements.Match partialMatch) { - return rawStreamAllValuesOfcomplexName(partialMatch.toArray()); - } - - /** - * Retrieve the set of values that occur in matches for complexName. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfcomplexName(final NamedElement pElement) { - return rawStreamAllValuesOfcomplexName(new Object[]{pElement, null}); - } - - /** - * Retrieve the set of values that occur in matches for complexName. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfcomplexName(final ComplexNameOfElements.Match partialMatch) { - return rawStreamAllValuesOfcomplexName(partialMatch.toArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for complexName. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfcomplexName(final NamedElement pElement) { - return rawStreamAllValuesOfcomplexName(new Object[]{pElement, null}).collect(Collectors.toSet()); - } - - @Override - protected ComplexNameOfElements.Match tupleToMatch(final Tuple t) { - try { - return ComplexNameOfElements.Match.newMatch((NamedElement) t.get(POSITION_ELEMENT), (String) t.get(POSITION_COMPLEXNAME)); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in tuple not properly typed!",e); - return null; - } - } - - @Override - protected ComplexNameOfElements.Match arrayToMatch(final Object[] match) { - try { - return ComplexNameOfElements.Match.newMatch((NamedElement) match[POSITION_ELEMENT], (String) match[POSITION_COMPLEXNAME]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - @Override - protected ComplexNameOfElements.Match arrayToMatchMutable(final Object[] match) { - try { - return ComplexNameOfElements.Match.newMutableMatch((NamedElement) match[POSITION_ELEMENT], (String) match[POSITION_COMPLEXNAME]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - /** - * @return the singleton instance of the query specification of this pattern - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static IQuerySpecification querySpecification() { - return ComplexNameOfElements.instance(); - } - } - - private ComplexNameOfElements() { - super(GeneratedPQuery.INSTANCE); - } - - /** - * @return the singleton instance of the query specification - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static ComplexNameOfElements instance() { - try{ - return LazyHolder.INSTANCE; - } catch (ExceptionInInitializerError err) { - throw processInitializerError(err); - } - } - - @Override - protected ComplexNameOfElements.Matcher instantiate(final ViatraQueryEngine engine) { - return ComplexNameOfElements.Matcher.on(engine); - } - - @Override - public ComplexNameOfElements.Matcher instantiate() { - return ComplexNameOfElements.Matcher.create(); - } - - @Override - public ComplexNameOfElements.Match newEmptyMatch() { - return ComplexNameOfElements.Match.newEmptyMatch(); - } - - @Override - public ComplexNameOfElements.Match newMatch(final Object... parameters) { - return ComplexNameOfElements.Match.newMatch((com.nomagic.uml2.ext.magicdraw.classes.mdkernel.NamedElement) parameters[0], (java.lang.String) parameters[1]); - } - - /** - * Inner class allowing the singleton instance of {@link ComplexNameOfElements} to be created - * not at the class load time of the outer class, - * but rather at the first call to {@link ComplexNameOfElements#instance()}. - * - *

This workaround is required e.g. to support recursion. - * - */ - private static class LazyHolder { - private static final ComplexNameOfElements INSTANCE = new ComplexNameOfElements(); - - /** - * Statically initializes the query specification after the field {@link #INSTANCE} is assigned. - * This initialization order is required to support indirect recursion. - * - *

The static initializer is defined using a helper field to work around limitations of the code generator. - * - */ - private static final Object STATIC_INITIALIZER = ensureInitialized(); - - public static Object ensureInitialized() { - INSTANCE.ensureInitializedInternal(); - return null; - } - } - - private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { - private static final ComplexNameOfElements.GeneratedPQuery INSTANCE = new GeneratedPQuery(); - - private final PParameter parameter_element = new PParameter("element", "com.nomagic.uml2.ext.magicdraw.classes.mdkernel.NamedElement", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.nomagic.com/magicdraw/UML/2.5.1", "NamedElement")), PParameterDirection.INOUT); - - private final PParameter parameter_complexName = new PParameter("complexName", "java.lang.String", new JavaTransitiveInstancesKey(java.lang.String.class), PParameterDirection.INOUT); - - private final List parameters = Arrays.asList(parameter_element, parameter_complexName); - - private GeneratedPQuery() { - super(PVisibility.PUBLIC); - } - - @Override - public String getFullyQualifiedName() { - return "com.incquerylabs.magicdraw.benchmark.queries.complexNameOfElements"; - } - - @Override - public List getParameterNames() { - return Arrays.asList("element","complexName"); - } - - @Override - public List getParameters() { - return parameters; - } - - @Override - public Set doGetContainedBodies() { - setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); - Set bodies = new LinkedHashSet<>(); - { - PBody body = new PBody(this); - PVariable var_element = body.getOrCreateVariableByName("element"); - PVariable var_complexName = body.getOrCreateVariableByName("complexName"); - PVariable var_name = body.getOrCreateVariableByName("name"); - new TypeConstraint(body, Tuples.flatTupleOf(var_element), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "NamedElement"))); - new TypeFilterConstraint(body, Tuples.flatTupleOf(var_complexName), new JavaTransitiveInstancesKey(java.lang.String.class)); - body.setSymbolicParameters(Arrays.asList( - new ExportedParameter(body, var_element, parameter_element), - new ExportedParameter(body, var_complexName, parameter_complexName) - )); - // find namedElement(element, name) - new PositivePatternCall(body, Tuples.flatTupleOf(var_element, var_name), com.incquerylabs.magicdraw.benchmark.queries.NamedElement.instance().getInternalQueryRepresentation()); - // complexName == eval(name.toFirstUpper + ". "+ name.toFirstLower + "." + name.toUpperCase + "." + name.toLowerCase + "." + name.length) - PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); - new ExpressionEvaluation(body, new IExpressionEvaluator() { - - @Override - public String getShortDescription() { - return "Expression evaluation from pattern complexNameOfElements"; - } - - @Override - public Iterable getInputParameterNames() { - return Arrays.asList("name");} - - @Override - public Object evaluateExpression(IValueProvider provider) throws Exception { - String name = (String) provider.getValue("name"); - return evaluateExpression_1_1(name); - } - }, var__virtual_0_ ); - new Equality(body, var_complexName, var__virtual_0_); - bodies.add(body); - } - return bodies; - } - } - - private static String evaluateExpression_1_1(final String name) { - String _firstUpper = StringExtensions.toFirstUpper(name); - String _plus = (_firstUpper + ". "); - String _firstLower = StringExtensions.toFirstLower(name); - String _plus_1 = (_plus + _firstLower); - String _plus_2 = (_plus_1 + "."); - String _upperCase = name.toUpperCase(); - String _plus_3 = (_plus_2 + _upperCase); - String _plus_4 = (_plus_3 + "."); - String _lowerCase = name.toLowerCase(); - String _plus_5 = (_plus_4 + _lowerCase); - String _plus_6 = (_plus_5 + "."); - int _length = name.length(); - String _plus_7 = (_plus_6 + Integer.valueOf(_length)); - return _plus_7; - } -} diff --git a/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/Dependencies.java b/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/Dependencies.java deleted file mode 100644 index af317c4..0000000 --- a/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/Dependencies.java +++ /dev/null @@ -1,717 +0,0 @@ -/** - * Generated from platform:/resource/com.incquerylabs.magicdraw.benchmark/src/main/java/com/incquerylabs/magicdraw/benchmark/queries/APerformanceQueries.vql - */ -package com.incquerylabs.magicdraw.benchmark.queries; - -import com.nomagic.uml2.ext.magicdraw.classes.mdkernel.NamedElement; -import java.util.Arrays; -import java.util.Collection; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.function.Consumer; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import org.apache.log4j.Logger; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.viatra.query.runtime.api.IPatternMatch; -import org.eclipse.viatra.query.runtime.api.IQuerySpecification; -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.api.impl.BaseMatcher; -import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; -import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; -import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey; -import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; -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.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.PVisibility; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; -import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; - -/** - * A pattern-specific query specification that can instantiate Matcher in a type-safe way. - * - *

Original source: - *

- *         Source and target of a dependency element.
- *          
- *         pattern dependencies(source : NamedElement, target : NamedElement) {
- *         	Dependency.supplier(dependency, target);
- *         	Dependency.client(dependency, source);
- *         }
- * 
- * - * @see Matcher - * @see Match - * - */ -@SuppressWarnings("all") -public final class Dependencies extends BaseGeneratedEMFQuerySpecification { - /** - * Pattern-specific match representation of the com.incquerylabs.magicdraw.benchmark.queries.dependencies pattern, - * to be used in conjunction with {@link Matcher}. - * - *

Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. - * Each instance is a (possibly partial) substitution of pattern parameters, - * usable to represent a match of the pattern in the result of a query, - * or to specify the bound (fixed) input parameters when issuing a query. - * - * @see Matcher - * - */ - public static abstract class Match extends BasePatternMatch { - private NamedElement fSource; - - private NamedElement fTarget; - - private static List parameterNames = makeImmutableList("source", "target"); - - private Match(final NamedElement pSource, final NamedElement pTarget) { - this.fSource = pSource; - this.fTarget = pTarget; - } - - @Override - public Object get(final String parameterName) { - switch(parameterName) { - case "source": return this.fSource; - case "target": return this.fTarget; - default: return null; - } - } - - @Override - public Object get(final int index) { - switch(index) { - case 0: return this.fSource; - case 1: return this.fTarget; - default: return null; - } - } - - public NamedElement getSource() { - return this.fSource; - } - - public NamedElement getTarget() { - return this.fTarget; - } - - @Override - public boolean set(final String parameterName, final Object newValue) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - if ("source".equals(parameterName) ) { - this.fSource = (NamedElement) newValue; - return true; - } - if ("target".equals(parameterName) ) { - this.fTarget = (NamedElement) newValue; - return true; - } - return false; - } - - public void setSource(final NamedElement pSource) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fSource = pSource; - } - - public void setTarget(final NamedElement pTarget) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fTarget = pTarget; - } - - @Override - public String patternName() { - return "com.incquerylabs.magicdraw.benchmark.queries.dependencies"; - } - - @Override - public List parameterNames() { - return Dependencies.Match.parameterNames; - } - - @Override - public Object[] toArray() { - return new Object[]{fSource, fTarget}; - } - - @Override - public Dependencies.Match toImmutable() { - return isMutable() ? newMatch(fSource, fTarget) : this; - } - - @Override - public String prettyPrint() { - StringBuilder result = new StringBuilder(); - result.append("\"source\"=" + prettyPrintValue(fSource) + ", "); - result.append("\"target\"=" + prettyPrintValue(fTarget)); - return result.toString(); - } - - @Override - public int hashCode() { - return Objects.hash(fSource, fTarget); - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) - return true; - if (obj == null) { - return false; - } - if ((obj instanceof Dependencies.Match)) { - Dependencies.Match other = (Dependencies.Match) obj; - return Objects.equals(fSource, other.fSource) && Objects.equals(fTarget, other.fTarget); - } else { - // this should be infrequent - if (!(obj instanceof IPatternMatch)) { - return false; - } - IPatternMatch otherSig = (IPatternMatch) obj; - return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); - } - } - - @Override - public Dependencies specification() { - return Dependencies.instance(); - } - - /** - * Returns an empty, mutable match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @return the empty match. - * - */ - public static Dependencies.Match newEmptyMatch() { - return new Mutable(null, null); - } - - /** - * Returns a mutable (partial) match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @param pSource the fixed value of pattern parameter source, or null if not bound. - * @param pTarget the fixed value of pattern parameter target, or null if not bound. - * @return the new, mutable (partial) match object. - * - */ - public static Dependencies.Match newMutableMatch(final NamedElement pSource, final NamedElement pTarget) { - return new Mutable(pSource, pTarget); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pSource the fixed value of pattern parameter source, or null if not bound. - * @param pTarget the fixed value of pattern parameter target, or null if not bound. - * @return the (partial) match object. - * - */ - public static Dependencies.Match newMatch(final NamedElement pSource, final NamedElement pTarget) { - return new Immutable(pSource, pTarget); - } - - private static final class Mutable extends Dependencies.Match { - Mutable(final NamedElement pSource, final NamedElement pTarget) { - super(pSource, pTarget); - } - - @Override - public boolean isMutable() { - return true; - } - } - - private static final class Immutable extends Dependencies.Match { - Immutable(final NamedElement pSource, final NamedElement pTarget) { - super(pSource, pTarget); - } - - @Override - public boolean isMutable() { - return false; - } - } - } - - /** - * Generated pattern matcher API of the com.incquerylabs.magicdraw.benchmark.queries.dependencies pattern, - * providing pattern-specific query methods. - * - *

Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, - * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. - * - *

Matches of the pattern will be represented as {@link Match}. - * - *

Original source: - *

-   * Source and target of a dependency element.
-   *  
-   * pattern dependencies(source : NamedElement, target : NamedElement) {
-   * 	Dependency.supplier(dependency, target);
-   * 	Dependency.client(dependency, source);
-   * }
-   * 
- * - * @see Match - * @see Dependencies - * - */ - public static class Matcher extends BaseMatcher { - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - public static Dependencies.Matcher on(final ViatraQueryEngine engine) { - // check if matcher already exists - Matcher matcher = engine.getExistingMatcher(querySpecification()); - if (matcher == null) { - matcher = (Matcher)engine.getMatcher(querySpecification()); - } - return matcher; - } - - /** - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * @return an initialized matcher - * @noreference This method is for internal matcher initialization by the framework, do not call it manually. - * - */ - public static Dependencies.Matcher create() { - return new Matcher(); - } - - private static final int POSITION_SOURCE = 0; - - private static final int POSITION_TARGET = 1; - - private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(Dependencies.Matcher.class); - - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - private Matcher() { - super(querySpecification()); - } - - /** - * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pSource the fixed value of pattern parameter source, or null if not bound. - * @param pTarget the fixed value of pattern parameter target, or null if not bound. - * @return matches represented as a Match object. - * - */ - public Collection getAllMatches(final NamedElement pSource, final NamedElement pTarget) { - return rawStreamAllMatches(new Object[]{pSource, pTarget}).collect(Collectors.toSet()); - } - - /** - * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * @param pSource the fixed value of pattern parameter source, or null if not bound. - * @param pTarget the fixed value of pattern parameter target, or null if not bound. - * @return a stream of matches represented as a Match object. - * - */ - public Stream streamAllMatches(final NamedElement pSource, final NamedElement pTarget) { - return rawStreamAllMatches(new Object[]{pSource, pTarget}); - } - - /** - * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pSource the fixed value of pattern parameter source, or null if not bound. - * @param pTarget the fixed value of pattern parameter target, or null if not bound. - * @return a match represented as a Match object, or null if no match is found. - * - */ - public Optional getOneArbitraryMatch(final NamedElement pSource, final NamedElement pTarget) { - return rawGetOneArbitraryMatch(new Object[]{pSource, pTarget}); - } - - /** - * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, - * under any possible substitution of the unspecified parameters (if any). - * @param pSource the fixed value of pattern parameter source, or null if not bound. - * @param pTarget the fixed value of pattern parameter target, or null if not bound. - * @return true if the input is a valid (partial) match of the pattern. - * - */ - public boolean hasMatch(final NamedElement pSource, final NamedElement pTarget) { - return rawHasMatch(new Object[]{pSource, pTarget}); - } - - /** - * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pSource the fixed value of pattern parameter source, or null if not bound. - * @param pTarget the fixed value of pattern parameter target, or null if not bound. - * @return the number of pattern matches found. - * - */ - public int countMatches(final NamedElement pSource, final NamedElement pTarget) { - return rawCountMatches(new Object[]{pSource, pTarget}); - } - - /** - * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pSource the fixed value of pattern parameter source, or null if not bound. - * @param pTarget the fixed value of pattern parameter target, or null if not bound. - * @param processor the action that will process the selected match. - * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked - * - */ - public boolean forOneArbitraryMatch(final NamedElement pSource, final NamedElement pTarget, final Consumer processor) { - return rawForOneArbitraryMatch(new Object[]{pSource, pTarget}, processor); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pSource the fixed value of pattern parameter source, or null if not bound. - * @param pTarget the fixed value of pattern parameter target, or null if not bound. - * @return the (partial) match object. - * - */ - public Dependencies.Match newMatch(final NamedElement pSource, final NamedElement pTarget) { - return Dependencies.Match.newMatch(pSource, pTarget); - } - - /** - * Retrieve the set of values that occur in matches for source. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOfsource(final Object[] parameters) { - return rawStreamAllValues(POSITION_SOURCE, parameters).map(NamedElement.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for source. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfsource() { - return rawStreamAllValuesOfsource(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for source. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfsource() { - return rawStreamAllValuesOfsource(emptyArray()); - } - - /** - * Retrieve the set of values that occur in matches for source. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfsource(final Dependencies.Match partialMatch) { - return rawStreamAllValuesOfsource(partialMatch.toArray()); - } - - /** - * Retrieve the set of values that occur in matches for source. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfsource(final NamedElement pTarget) { - return rawStreamAllValuesOfsource(new Object[]{null, pTarget}); - } - - /** - * Retrieve the set of values that occur in matches for source. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfsource(final Dependencies.Match partialMatch) { - return rawStreamAllValuesOfsource(partialMatch.toArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for source. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfsource(final NamedElement pTarget) { - return rawStreamAllValuesOfsource(new Object[]{null, pTarget}).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for target. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOftarget(final Object[] parameters) { - return rawStreamAllValues(POSITION_TARGET, parameters).map(NamedElement.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for target. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOftarget() { - return rawStreamAllValuesOftarget(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for target. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOftarget() { - return rawStreamAllValuesOftarget(emptyArray()); - } - - /** - * Retrieve the set of values that occur in matches for target. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOftarget(final Dependencies.Match partialMatch) { - return rawStreamAllValuesOftarget(partialMatch.toArray()); - } - - /** - * Retrieve the set of values that occur in matches for target. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOftarget(final NamedElement pSource) { - return rawStreamAllValuesOftarget(new Object[]{pSource, null}); - } - - /** - * Retrieve the set of values that occur in matches for target. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOftarget(final Dependencies.Match partialMatch) { - return rawStreamAllValuesOftarget(partialMatch.toArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for target. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOftarget(final NamedElement pSource) { - return rawStreamAllValuesOftarget(new Object[]{pSource, null}).collect(Collectors.toSet()); - } - - @Override - protected Dependencies.Match tupleToMatch(final Tuple t) { - try { - return Dependencies.Match.newMatch((NamedElement) t.get(POSITION_SOURCE), (NamedElement) t.get(POSITION_TARGET)); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in tuple not properly typed!",e); - return null; - } - } - - @Override - protected Dependencies.Match arrayToMatch(final Object[] match) { - try { - return Dependencies.Match.newMatch((NamedElement) match[POSITION_SOURCE], (NamedElement) match[POSITION_TARGET]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - @Override - protected Dependencies.Match arrayToMatchMutable(final Object[] match) { - try { - return Dependencies.Match.newMutableMatch((NamedElement) match[POSITION_SOURCE], (NamedElement) match[POSITION_TARGET]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - /** - * @return the singleton instance of the query specification of this pattern - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static IQuerySpecification querySpecification() { - return Dependencies.instance(); - } - } - - private Dependencies() { - super(GeneratedPQuery.INSTANCE); - } - - /** - * @return the singleton instance of the query specification - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static Dependencies instance() { - try{ - return LazyHolder.INSTANCE; - } catch (ExceptionInInitializerError err) { - throw processInitializerError(err); - } - } - - @Override - protected Dependencies.Matcher instantiate(final ViatraQueryEngine engine) { - return Dependencies.Matcher.on(engine); - } - - @Override - public Dependencies.Matcher instantiate() { - return Dependencies.Matcher.create(); - } - - @Override - public Dependencies.Match newEmptyMatch() { - return Dependencies.Match.newEmptyMatch(); - } - - @Override - public Dependencies.Match newMatch(final Object... parameters) { - return Dependencies.Match.newMatch((com.nomagic.uml2.ext.magicdraw.classes.mdkernel.NamedElement) parameters[0], (com.nomagic.uml2.ext.magicdraw.classes.mdkernel.NamedElement) parameters[1]); - } - - /** - * Inner class allowing the singleton instance of {@link Dependencies} to be created - * not at the class load time of the outer class, - * but rather at the first call to {@link Dependencies#instance()}. - * - *

This workaround is required e.g. to support recursion. - * - */ - private static class LazyHolder { - private static final Dependencies INSTANCE = new Dependencies(); - - /** - * Statically initializes the query specification after the field {@link #INSTANCE} is assigned. - * This initialization order is required to support indirect recursion. - * - *

The static initializer is defined using a helper field to work around limitations of the code generator. - * - */ - private static final Object STATIC_INITIALIZER = ensureInitialized(); - - public static Object ensureInitialized() { - INSTANCE.ensureInitializedInternal(); - return null; - } - } - - private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { - private static final Dependencies.GeneratedPQuery INSTANCE = new GeneratedPQuery(); - - private final PParameter parameter_source = new PParameter("source", "com.nomagic.uml2.ext.magicdraw.classes.mdkernel.NamedElement", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.nomagic.com/magicdraw/UML/2.5.1", "NamedElement")), PParameterDirection.INOUT); - - private final PParameter parameter_target = new PParameter("target", "com.nomagic.uml2.ext.magicdraw.classes.mdkernel.NamedElement", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.nomagic.com/magicdraw/UML/2.5.1", "NamedElement")), PParameterDirection.INOUT); - - private final List parameters = Arrays.asList(parameter_source, parameter_target); - - private GeneratedPQuery() { - super(PVisibility.PUBLIC); - } - - @Override - public String getFullyQualifiedName() { - return "com.incquerylabs.magicdraw.benchmark.queries.dependencies"; - } - - @Override - public List getParameterNames() { - return Arrays.asList("source","target"); - } - - @Override - public List getParameters() { - return parameters; - } - - @Override - public Set doGetContainedBodies() { - setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); - Set bodies = new LinkedHashSet<>(); - { - PBody body = new PBody(this); - PVariable var_source = body.getOrCreateVariableByName("source"); - PVariable var_target = body.getOrCreateVariableByName("target"); - PVariable var_dependency = body.getOrCreateVariableByName("dependency"); - new TypeConstraint(body, Tuples.flatTupleOf(var_source), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "NamedElement"))); - new TypeConstraint(body, Tuples.flatTupleOf(var_target), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "NamedElement"))); - body.setSymbolicParameters(Arrays.asList( - new ExportedParameter(body, var_source, parameter_source), - new ExportedParameter(body, var_target, parameter_target) - )); - // Dependency.supplier(dependency, target) - new TypeConstraint(body, Tuples.flatTupleOf(var_dependency), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Dependency"))); - PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_dependency, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Dependency", "supplier"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "NamedElement"))); - new Equality(body, var__virtual_0_, var_target); - // Dependency.client(dependency, source) - new TypeConstraint(body, Tuples.flatTupleOf(var_dependency), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Dependency"))); - PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_dependency, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Dependency", "client"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "NamedElement"))); - new Equality(body, var__virtual_1_, var_source); - bodies.add(body); - } - return bodies; - } - } -} diff --git a/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/DependencyChains.java b/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/DependencyChains.java deleted file mode 100644 index 6cb8dae..0000000 --- a/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/DependencyChains.java +++ /dev/null @@ -1,717 +0,0 @@ -/** - * Generated from platform:/resource/com.incquerylabs.magicdraw.benchmark/src/main/java/com/incquerylabs/magicdraw/benchmark/queries/APerformanceQueries.vql - */ -package com.incquerylabs.magicdraw.benchmark.queries; - -import com.nomagic.uml2.ext.magicdraw.classes.mddependencies.Dependency; -import java.util.Arrays; -import java.util.Collection; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.function.Consumer; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import org.apache.log4j.Logger; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.viatra.query.runtime.api.IPatternMatch; -import org.eclipse.viatra.query.runtime.api.IQuerySpecification; -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.api.impl.BaseMatcher; -import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; -import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; -import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey; -import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; -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.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.PVisibility; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; -import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; - -/** - * A pattern-specific query specification that can instantiate Matcher in a type-safe way. - * - *

Original source: - *

- *         Pattern describing succession relation between two dependencies.
- *          
- *         pattern dependencyChains(source : Dependency, target : Dependency) {
- *             Dependency.supplier(source, elem);
- *             Dependency.client(target, elem);
- *         }
- * 
- * - * @see Matcher - * @see Match - * - */ -@SuppressWarnings("all") -public final class DependencyChains extends BaseGeneratedEMFQuerySpecification { - /** - * Pattern-specific match representation of the com.incquerylabs.magicdraw.benchmark.queries.dependencyChains pattern, - * to be used in conjunction with {@link Matcher}. - * - *

Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. - * Each instance is a (possibly partial) substitution of pattern parameters, - * usable to represent a match of the pattern in the result of a query, - * or to specify the bound (fixed) input parameters when issuing a query. - * - * @see Matcher - * - */ - public static abstract class Match extends BasePatternMatch { - private Dependency fSource; - - private Dependency fTarget; - - private static List parameterNames = makeImmutableList("source", "target"); - - private Match(final Dependency pSource, final Dependency pTarget) { - this.fSource = pSource; - this.fTarget = pTarget; - } - - @Override - public Object get(final String parameterName) { - switch(parameterName) { - case "source": return this.fSource; - case "target": return this.fTarget; - default: return null; - } - } - - @Override - public Object get(final int index) { - switch(index) { - case 0: return this.fSource; - case 1: return this.fTarget; - default: return null; - } - } - - public Dependency getSource() { - return this.fSource; - } - - public Dependency getTarget() { - return this.fTarget; - } - - @Override - public boolean set(final String parameterName, final Object newValue) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - if ("source".equals(parameterName) ) { - this.fSource = (Dependency) newValue; - return true; - } - if ("target".equals(parameterName) ) { - this.fTarget = (Dependency) newValue; - return true; - } - return false; - } - - public void setSource(final Dependency pSource) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fSource = pSource; - } - - public void setTarget(final Dependency pTarget) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fTarget = pTarget; - } - - @Override - public String patternName() { - return "com.incquerylabs.magicdraw.benchmark.queries.dependencyChains"; - } - - @Override - public List parameterNames() { - return DependencyChains.Match.parameterNames; - } - - @Override - public Object[] toArray() { - return new Object[]{fSource, fTarget}; - } - - @Override - public DependencyChains.Match toImmutable() { - return isMutable() ? newMatch(fSource, fTarget) : this; - } - - @Override - public String prettyPrint() { - StringBuilder result = new StringBuilder(); - result.append("\"source\"=" + prettyPrintValue(fSource) + ", "); - result.append("\"target\"=" + prettyPrintValue(fTarget)); - return result.toString(); - } - - @Override - public int hashCode() { - return Objects.hash(fSource, fTarget); - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) - return true; - if (obj == null) { - return false; - } - if ((obj instanceof DependencyChains.Match)) { - DependencyChains.Match other = (DependencyChains.Match) obj; - return Objects.equals(fSource, other.fSource) && Objects.equals(fTarget, other.fTarget); - } else { - // this should be infrequent - if (!(obj instanceof IPatternMatch)) { - return false; - } - IPatternMatch otherSig = (IPatternMatch) obj; - return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); - } - } - - @Override - public DependencyChains specification() { - return DependencyChains.instance(); - } - - /** - * Returns an empty, mutable match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @return the empty match. - * - */ - public static DependencyChains.Match newEmptyMatch() { - return new Mutable(null, null); - } - - /** - * Returns a mutable (partial) match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @param pSource the fixed value of pattern parameter source, or null if not bound. - * @param pTarget the fixed value of pattern parameter target, or null if not bound. - * @return the new, mutable (partial) match object. - * - */ - public static DependencyChains.Match newMutableMatch(final Dependency pSource, final Dependency pTarget) { - return new Mutable(pSource, pTarget); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pSource the fixed value of pattern parameter source, or null if not bound. - * @param pTarget the fixed value of pattern parameter target, or null if not bound. - * @return the (partial) match object. - * - */ - public static DependencyChains.Match newMatch(final Dependency pSource, final Dependency pTarget) { - return new Immutable(pSource, pTarget); - } - - private static final class Mutable extends DependencyChains.Match { - Mutable(final Dependency pSource, final Dependency pTarget) { - super(pSource, pTarget); - } - - @Override - public boolean isMutable() { - return true; - } - } - - private static final class Immutable extends DependencyChains.Match { - Immutable(final Dependency pSource, final Dependency pTarget) { - super(pSource, pTarget); - } - - @Override - public boolean isMutable() { - return false; - } - } - } - - /** - * Generated pattern matcher API of the com.incquerylabs.magicdraw.benchmark.queries.dependencyChains pattern, - * providing pattern-specific query methods. - * - *

Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, - * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. - * - *

Matches of the pattern will be represented as {@link Match}. - * - *

Original source: - *

-   * Pattern describing succession relation between two dependencies.
-   *  
-   * pattern dependencyChains(source : Dependency, target : Dependency) {
-   *     Dependency.supplier(source, elem);
-   *     Dependency.client(target, elem);
-   * }
-   * 
- * - * @see Match - * @see DependencyChains - * - */ - public static class Matcher extends BaseMatcher { - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - public static DependencyChains.Matcher on(final ViatraQueryEngine engine) { - // check if matcher already exists - Matcher matcher = engine.getExistingMatcher(querySpecification()); - if (matcher == null) { - matcher = (Matcher)engine.getMatcher(querySpecification()); - } - return matcher; - } - - /** - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * @return an initialized matcher - * @noreference This method is for internal matcher initialization by the framework, do not call it manually. - * - */ - public static DependencyChains.Matcher create() { - return new Matcher(); - } - - private static final int POSITION_SOURCE = 0; - - private static final int POSITION_TARGET = 1; - - private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(DependencyChains.Matcher.class); - - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - private Matcher() { - super(querySpecification()); - } - - /** - * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pSource the fixed value of pattern parameter source, or null if not bound. - * @param pTarget the fixed value of pattern parameter target, or null if not bound. - * @return matches represented as a Match object. - * - */ - public Collection getAllMatches(final Dependency pSource, final Dependency pTarget) { - return rawStreamAllMatches(new Object[]{pSource, pTarget}).collect(Collectors.toSet()); - } - - /** - * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * @param pSource the fixed value of pattern parameter source, or null if not bound. - * @param pTarget the fixed value of pattern parameter target, or null if not bound. - * @return a stream of matches represented as a Match object. - * - */ - public Stream streamAllMatches(final Dependency pSource, final Dependency pTarget) { - return rawStreamAllMatches(new Object[]{pSource, pTarget}); - } - - /** - * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pSource the fixed value of pattern parameter source, or null if not bound. - * @param pTarget the fixed value of pattern parameter target, or null if not bound. - * @return a match represented as a Match object, or null if no match is found. - * - */ - public Optional getOneArbitraryMatch(final Dependency pSource, final Dependency pTarget) { - return rawGetOneArbitraryMatch(new Object[]{pSource, pTarget}); - } - - /** - * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, - * under any possible substitution of the unspecified parameters (if any). - * @param pSource the fixed value of pattern parameter source, or null if not bound. - * @param pTarget the fixed value of pattern parameter target, or null if not bound. - * @return true if the input is a valid (partial) match of the pattern. - * - */ - public boolean hasMatch(final Dependency pSource, final Dependency pTarget) { - return rawHasMatch(new Object[]{pSource, pTarget}); - } - - /** - * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pSource the fixed value of pattern parameter source, or null if not bound. - * @param pTarget the fixed value of pattern parameter target, or null if not bound. - * @return the number of pattern matches found. - * - */ - public int countMatches(final Dependency pSource, final Dependency pTarget) { - return rawCountMatches(new Object[]{pSource, pTarget}); - } - - /** - * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pSource the fixed value of pattern parameter source, or null if not bound. - * @param pTarget the fixed value of pattern parameter target, or null if not bound. - * @param processor the action that will process the selected match. - * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked - * - */ - public boolean forOneArbitraryMatch(final Dependency pSource, final Dependency pTarget, final Consumer processor) { - return rawForOneArbitraryMatch(new Object[]{pSource, pTarget}, processor); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pSource the fixed value of pattern parameter source, or null if not bound. - * @param pTarget the fixed value of pattern parameter target, or null if not bound. - * @return the (partial) match object. - * - */ - public DependencyChains.Match newMatch(final Dependency pSource, final Dependency pTarget) { - return DependencyChains.Match.newMatch(pSource, pTarget); - } - - /** - * Retrieve the set of values that occur in matches for source. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOfsource(final Object[] parameters) { - return rawStreamAllValues(POSITION_SOURCE, parameters).map(Dependency.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for source. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfsource() { - return rawStreamAllValuesOfsource(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for source. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfsource() { - return rawStreamAllValuesOfsource(emptyArray()); - } - - /** - * Retrieve the set of values that occur in matches for source. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfsource(final DependencyChains.Match partialMatch) { - return rawStreamAllValuesOfsource(partialMatch.toArray()); - } - - /** - * Retrieve the set of values that occur in matches for source. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfsource(final Dependency pTarget) { - return rawStreamAllValuesOfsource(new Object[]{null, pTarget}); - } - - /** - * Retrieve the set of values that occur in matches for source. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfsource(final DependencyChains.Match partialMatch) { - return rawStreamAllValuesOfsource(partialMatch.toArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for source. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfsource(final Dependency pTarget) { - return rawStreamAllValuesOfsource(new Object[]{null, pTarget}).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for target. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOftarget(final Object[] parameters) { - return rawStreamAllValues(POSITION_TARGET, parameters).map(Dependency.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for target. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOftarget() { - return rawStreamAllValuesOftarget(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for target. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOftarget() { - return rawStreamAllValuesOftarget(emptyArray()); - } - - /** - * Retrieve the set of values that occur in matches for target. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOftarget(final DependencyChains.Match partialMatch) { - return rawStreamAllValuesOftarget(partialMatch.toArray()); - } - - /** - * Retrieve the set of values that occur in matches for target. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOftarget(final Dependency pSource) { - return rawStreamAllValuesOftarget(new Object[]{pSource, null}); - } - - /** - * Retrieve the set of values that occur in matches for target. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOftarget(final DependencyChains.Match partialMatch) { - return rawStreamAllValuesOftarget(partialMatch.toArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for target. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOftarget(final Dependency pSource) { - return rawStreamAllValuesOftarget(new Object[]{pSource, null}).collect(Collectors.toSet()); - } - - @Override - protected DependencyChains.Match tupleToMatch(final Tuple t) { - try { - return DependencyChains.Match.newMatch((Dependency) t.get(POSITION_SOURCE), (Dependency) t.get(POSITION_TARGET)); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in tuple not properly typed!",e); - return null; - } - } - - @Override - protected DependencyChains.Match arrayToMatch(final Object[] match) { - try { - return DependencyChains.Match.newMatch((Dependency) match[POSITION_SOURCE], (Dependency) match[POSITION_TARGET]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - @Override - protected DependencyChains.Match arrayToMatchMutable(final Object[] match) { - try { - return DependencyChains.Match.newMutableMatch((Dependency) match[POSITION_SOURCE], (Dependency) match[POSITION_TARGET]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - /** - * @return the singleton instance of the query specification of this pattern - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static IQuerySpecification querySpecification() { - return DependencyChains.instance(); - } - } - - private DependencyChains() { - super(GeneratedPQuery.INSTANCE); - } - - /** - * @return the singleton instance of the query specification - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static DependencyChains instance() { - try{ - return LazyHolder.INSTANCE; - } catch (ExceptionInInitializerError err) { - throw processInitializerError(err); - } - } - - @Override - protected DependencyChains.Matcher instantiate(final ViatraQueryEngine engine) { - return DependencyChains.Matcher.on(engine); - } - - @Override - public DependencyChains.Matcher instantiate() { - return DependencyChains.Matcher.create(); - } - - @Override - public DependencyChains.Match newEmptyMatch() { - return DependencyChains.Match.newEmptyMatch(); - } - - @Override - public DependencyChains.Match newMatch(final Object... parameters) { - return DependencyChains.Match.newMatch((com.nomagic.uml2.ext.magicdraw.classes.mddependencies.Dependency) parameters[0], (com.nomagic.uml2.ext.magicdraw.classes.mddependencies.Dependency) parameters[1]); - } - - /** - * Inner class allowing the singleton instance of {@link DependencyChains} to be created - * not at the class load time of the outer class, - * but rather at the first call to {@link DependencyChains#instance()}. - * - *

This workaround is required e.g. to support recursion. - * - */ - private static class LazyHolder { - private static final DependencyChains INSTANCE = new DependencyChains(); - - /** - * Statically initializes the query specification after the field {@link #INSTANCE} is assigned. - * This initialization order is required to support indirect recursion. - * - *

The static initializer is defined using a helper field to work around limitations of the code generator. - * - */ - private static final Object STATIC_INITIALIZER = ensureInitialized(); - - public static Object ensureInitialized() { - INSTANCE.ensureInitializedInternal(); - return null; - } - } - - private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { - private static final DependencyChains.GeneratedPQuery INSTANCE = new GeneratedPQuery(); - - private final PParameter parameter_source = new PParameter("source", "com.nomagic.uml2.ext.magicdraw.classes.mddependencies.Dependency", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.nomagic.com/magicdraw/UML/2.5.1", "Dependency")), PParameterDirection.INOUT); - - private final PParameter parameter_target = new PParameter("target", "com.nomagic.uml2.ext.magicdraw.classes.mddependencies.Dependency", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.nomagic.com/magicdraw/UML/2.5.1", "Dependency")), PParameterDirection.INOUT); - - private final List parameters = Arrays.asList(parameter_source, parameter_target); - - private GeneratedPQuery() { - super(PVisibility.PUBLIC); - } - - @Override - public String getFullyQualifiedName() { - return "com.incquerylabs.magicdraw.benchmark.queries.dependencyChains"; - } - - @Override - public List getParameterNames() { - return Arrays.asList("source","target"); - } - - @Override - public List getParameters() { - return parameters; - } - - @Override - public Set doGetContainedBodies() { - setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); - Set bodies = new LinkedHashSet<>(); - { - PBody body = new PBody(this); - PVariable var_source = body.getOrCreateVariableByName("source"); - PVariable var_target = body.getOrCreateVariableByName("target"); - PVariable var_elem = body.getOrCreateVariableByName("elem"); - new TypeConstraint(body, Tuples.flatTupleOf(var_source), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Dependency"))); - new TypeConstraint(body, Tuples.flatTupleOf(var_target), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Dependency"))); - body.setSymbolicParameters(Arrays.asList( - new ExportedParameter(body, var_source, parameter_source), - new ExportedParameter(body, var_target, parameter_target) - )); - // Dependency.supplier(source, elem) - new TypeConstraint(body, Tuples.flatTupleOf(var_source), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Dependency"))); - PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_source, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Dependency", "supplier"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "NamedElement"))); - new Equality(body, var__virtual_0_, var_elem); - // Dependency.client(target, elem) - new TypeConstraint(body, Tuples.flatTupleOf(var_target), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Dependency"))); - PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_target, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Dependency", "client"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "NamedElement"))); - new Equality(body, var__virtual_1_, var_elem); - bodies.add(body); - } - return bodies; - } - } -} diff --git a/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/ElementsWithShortNames.java b/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/ElementsWithShortNames.java deleted file mode 100644 index ecc83c7..0000000 --- a/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/ElementsWithShortNames.java +++ /dev/null @@ -1,586 +0,0 @@ -/** - * Generated from platform:/resource/com.incquerylabs.magicdraw.benchmark/src/main/java/com/incquerylabs/magicdraw/benchmark/queries/APerformanceQueries.vql - */ -package com.incquerylabs.magicdraw.benchmark.queries; - -import com.nomagic.uml2.ext.magicdraw.classes.mdkernel.NamedElement; -import java.util.Arrays; -import java.util.Collection; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.function.Consumer; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import org.apache.log4j.Logger; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.emf.ecore.EDataType; -import org.eclipse.viatra.query.runtime.api.IPatternMatch; -import org.eclipse.viatra.query.runtime.api.IQuerySpecification; -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.api.impl.BaseMatcher; -import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; -import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; -import org.eclipse.viatra.query.runtime.emf.types.EDataTypeInSlotsKey; -import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey; -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.PVisibility; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; -import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; - -/** - * A pattern-specific query specification that can instantiate Matcher in a type-safe way. - * - *

Original source: - *

- *         Simple filtering with a check on all instances of an EClass.
- *          
- *         pattern elementsWithShortNames(class : NamedElement) {
- *         	NamedElement.name(class, name);
- *         	check (name.length {@literal <} 10); 
- *         }
- * 
- * - * @see Matcher - * @see Match - * - */ -@SuppressWarnings("all") -public final class ElementsWithShortNames extends BaseGeneratedEMFQuerySpecification { - /** - * Pattern-specific match representation of the com.incquerylabs.magicdraw.benchmark.queries.elementsWithShortNames pattern, - * to be used in conjunction with {@link Matcher}. - * - *

Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. - * Each instance is a (possibly partial) substitution of pattern parameters, - * usable to represent a match of the pattern in the result of a query, - * or to specify the bound (fixed) input parameters when issuing a query. - * - * @see Matcher - * - */ - public static abstract class Match extends BasePatternMatch { - private NamedElement fClass; - - private static List parameterNames = makeImmutableList("class"); - - private Match(final NamedElement pClass) { - this.fClass = pClass; - } - - @Override - public Object get(final String parameterName) { - switch(parameterName) { - case "class": return this.fClass; - default: return null; - } - } - - @Override - public Object get(final int index) { - switch(index) { - case 0: return this.fClass; - default: return null; - } - } - - public NamedElement getValueOfClass() { - return this.fClass; - } - - @Override - public boolean set(final String parameterName, final Object newValue) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - if ("class".equals(parameterName) ) { - this.fClass = (NamedElement) newValue; - return true; - } - return false; - } - - public void setClass(final NamedElement pClass) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fClass = pClass; - } - - @Override - public String patternName() { - return "com.incquerylabs.magicdraw.benchmark.queries.elementsWithShortNames"; - } - - @Override - public List parameterNames() { - return ElementsWithShortNames.Match.parameterNames; - } - - @Override - public Object[] toArray() { - return new Object[]{fClass}; - } - - @Override - public ElementsWithShortNames.Match toImmutable() { - return isMutable() ? newMatch(fClass) : this; - } - - @Override - public String prettyPrint() { - StringBuilder result = new StringBuilder(); - result.append("\"class\"=" + prettyPrintValue(fClass)); - return result.toString(); - } - - @Override - public int hashCode() { - return Objects.hash(fClass); - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) - return true; - if (obj == null) { - return false; - } - if ((obj instanceof ElementsWithShortNames.Match)) { - ElementsWithShortNames.Match other = (ElementsWithShortNames.Match) obj; - return Objects.equals(fClass, other.fClass); - } else { - // this should be infrequent - if (!(obj instanceof IPatternMatch)) { - return false; - } - IPatternMatch otherSig = (IPatternMatch) obj; - return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); - } - } - - @Override - public ElementsWithShortNames specification() { - return ElementsWithShortNames.instance(); - } - - /** - * Returns an empty, mutable match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @return the empty match. - * - */ - public static ElementsWithShortNames.Match newEmptyMatch() { - return new Mutable(null); - } - - /** - * Returns a mutable (partial) match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @param pClass the fixed value of pattern parameter class, or null if not bound. - * @return the new, mutable (partial) match object. - * - */ - public static ElementsWithShortNames.Match newMutableMatch(final NamedElement pClass) { - return new Mutable(pClass); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pClass the fixed value of pattern parameter class, or null if not bound. - * @return the (partial) match object. - * - */ - public static ElementsWithShortNames.Match newMatch(final NamedElement pClass) { - return new Immutable(pClass); - } - - private static final class Mutable extends ElementsWithShortNames.Match { - Mutable(final NamedElement pClass) { - super(pClass); - } - - @Override - public boolean isMutable() { - return true; - } - } - - private static final class Immutable extends ElementsWithShortNames.Match { - Immutable(final NamedElement pClass) { - super(pClass); - } - - @Override - public boolean isMutable() { - return false; - } - } - } - - /** - * Generated pattern matcher API of the com.incquerylabs.magicdraw.benchmark.queries.elementsWithShortNames pattern, - * providing pattern-specific query methods. - * - *

Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, - * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. - * - *

Matches of the pattern will be represented as {@link Match}. - * - *

Original source: - *

-   * Simple filtering with a check on all instances of an EClass.
-   *  
-   * pattern elementsWithShortNames(class : NamedElement) {
-   * 	NamedElement.name(class, name);
-   * 	check (name.length {@literal <} 10); 
-   * }
-   * 
- * - * @see Match - * @see ElementsWithShortNames - * - */ - public static class Matcher extends BaseMatcher { - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - public static ElementsWithShortNames.Matcher on(final ViatraQueryEngine engine) { - // check if matcher already exists - Matcher matcher = engine.getExistingMatcher(querySpecification()); - if (matcher == null) { - matcher = (Matcher)engine.getMatcher(querySpecification()); - } - return matcher; - } - - /** - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * @return an initialized matcher - * @noreference This method is for internal matcher initialization by the framework, do not call it manually. - * - */ - public static ElementsWithShortNames.Matcher create() { - return new Matcher(); - } - - private static final int POSITION_CLASS = 0; - - private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(ElementsWithShortNames.Matcher.class); - - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - private Matcher() { - super(querySpecification()); - } - - /** - * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pClass the fixed value of pattern parameter class, or null if not bound. - * @return matches represented as a Match object. - * - */ - public Collection getAllMatches(final NamedElement pClass) { - return rawStreamAllMatches(new Object[]{pClass}).collect(Collectors.toSet()); - } - - /** - * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * @param pClass the fixed value of pattern parameter class, or null if not bound. - * @return a stream of matches represented as a Match object. - * - */ - public Stream streamAllMatches(final NamedElement pClass) { - return rawStreamAllMatches(new Object[]{pClass}); - } - - /** - * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pClass the fixed value of pattern parameter class, or null if not bound. - * @return a match represented as a Match object, or null if no match is found. - * - */ - public Optional getOneArbitraryMatch(final NamedElement pClass) { - return rawGetOneArbitraryMatch(new Object[]{pClass}); - } - - /** - * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, - * under any possible substitution of the unspecified parameters (if any). - * @param pClass the fixed value of pattern parameter class, or null if not bound. - * @return true if the input is a valid (partial) match of the pattern. - * - */ - public boolean hasMatch(final NamedElement pClass) { - return rawHasMatch(new Object[]{pClass}); - } - - /** - * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pClass the fixed value of pattern parameter class, or null if not bound. - * @return the number of pattern matches found. - * - */ - public int countMatches(final NamedElement pClass) { - return rawCountMatches(new Object[]{pClass}); - } - - /** - * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pClass the fixed value of pattern parameter class, or null if not bound. - * @param processor the action that will process the selected match. - * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked - * - */ - public boolean forOneArbitraryMatch(final NamedElement pClass, final Consumer processor) { - return rawForOneArbitraryMatch(new Object[]{pClass}, processor); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pClass the fixed value of pattern parameter class, or null if not bound. - * @return the (partial) match object. - * - */ - public ElementsWithShortNames.Match newMatch(final NamedElement pClass) { - return ElementsWithShortNames.Match.newMatch(pClass); - } - - /** - * Retrieve the set of values that occur in matches for class. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOfclass(final Object[] parameters) { - return rawStreamAllValues(POSITION_CLASS, parameters).map(NamedElement.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for class. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfclass() { - return rawStreamAllValuesOfclass(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for class. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfclass() { - return rawStreamAllValuesOfclass(emptyArray()); - } - - @Override - protected ElementsWithShortNames.Match tupleToMatch(final Tuple t) { - try { - return ElementsWithShortNames.Match.newMatch((NamedElement) t.get(POSITION_CLASS)); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in tuple not properly typed!",e); - return null; - } - } - - @Override - protected ElementsWithShortNames.Match arrayToMatch(final Object[] match) { - try { - return ElementsWithShortNames.Match.newMatch((NamedElement) match[POSITION_CLASS]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - @Override - protected ElementsWithShortNames.Match arrayToMatchMutable(final Object[] match) { - try { - return ElementsWithShortNames.Match.newMutableMatch((NamedElement) match[POSITION_CLASS]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - /** - * @return the singleton instance of the query specification of this pattern - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static IQuerySpecification querySpecification() { - return ElementsWithShortNames.instance(); - } - } - - private ElementsWithShortNames() { - super(GeneratedPQuery.INSTANCE); - } - - /** - * @return the singleton instance of the query specification - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static ElementsWithShortNames instance() { - try{ - return LazyHolder.INSTANCE; - } catch (ExceptionInInitializerError err) { - throw processInitializerError(err); - } - } - - @Override - protected ElementsWithShortNames.Matcher instantiate(final ViatraQueryEngine engine) { - return ElementsWithShortNames.Matcher.on(engine); - } - - @Override - public ElementsWithShortNames.Matcher instantiate() { - return ElementsWithShortNames.Matcher.create(); - } - - @Override - public ElementsWithShortNames.Match newEmptyMatch() { - return ElementsWithShortNames.Match.newEmptyMatch(); - } - - @Override - public ElementsWithShortNames.Match newMatch(final Object... parameters) { - return ElementsWithShortNames.Match.newMatch((com.nomagic.uml2.ext.magicdraw.classes.mdkernel.NamedElement) parameters[0]); - } - - /** - * Inner class allowing the singleton instance of {@link ElementsWithShortNames} to be created - * not at the class load time of the outer class, - * but rather at the first call to {@link ElementsWithShortNames#instance()}. - * - *

This workaround is required e.g. to support recursion. - * - */ - private static class LazyHolder { - private static final ElementsWithShortNames INSTANCE = new ElementsWithShortNames(); - - /** - * Statically initializes the query specification after the field {@link #INSTANCE} is assigned. - * This initialization order is required to support indirect recursion. - * - *

The static initializer is defined using a helper field to work around limitations of the code generator. - * - */ - private static final Object STATIC_INITIALIZER = ensureInitialized(); - - public static Object ensureInitialized() { - INSTANCE.ensureInitializedInternal(); - return null; - } - } - - private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { - private static final ElementsWithShortNames.GeneratedPQuery INSTANCE = new GeneratedPQuery(); - - private final PParameter parameter_class = new PParameter("class", "com.nomagic.uml2.ext.magicdraw.classes.mdkernel.NamedElement", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.nomagic.com/magicdraw/UML/2.5.1", "NamedElement")), PParameterDirection.INOUT); - - private final List parameters = Arrays.asList(parameter_class); - - private GeneratedPQuery() { - super(PVisibility.PUBLIC); - } - - @Override - public String getFullyQualifiedName() { - return "com.incquerylabs.magicdraw.benchmark.queries.elementsWithShortNames"; - } - - @Override - public List getParameterNames() { - return Arrays.asList("class"); - } - - @Override - public List getParameters() { - return parameters; - } - - @Override - public Set doGetContainedBodies() { - setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); - Set bodies = new LinkedHashSet<>(); - { - PBody body = new PBody(this); - PVariable var_class = body.getOrCreateVariableByName("class"); - PVariable var_name = body.getOrCreateVariableByName("name"); - new TypeConstraint(body, Tuples.flatTupleOf(var_class), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "NamedElement"))); - body.setSymbolicParameters(Arrays.asList( - new ExportedParameter(body, var_class, parameter_class) - )); - // NamedElement.name(class, name) - new TypeConstraint(body, Tuples.flatTupleOf(var_class), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "NamedElement"))); - PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_class, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "NamedElement", "name"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "String"))); - new Equality(body, var__virtual_0_, var_name); - // check (name.length < 10) - new ExpressionEvaluation(body, new IExpressionEvaluator() { - - @Override - public String getShortDescription() { - return "Expression evaluation from pattern elementsWithShortNames"; - } - - @Override - public Iterable getInputParameterNames() { - return Arrays.asList("name");} - - @Override - public Object evaluateExpression(IValueProvider provider) throws Exception { - String name = (String) provider.getValue("name"); - return evaluateExpression_1_1(name); - } - }, null); - bodies.add(body); - } - return bodies; - } - } - - private static boolean evaluateExpression_1_1(final String name) { - int _length = name.length(); - boolean _lessThan = (_length < 10); - return _lessThan; - } -} diff --git a/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/IncomingTransitions.java b/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/IncomingTransitions.java deleted file mode 100644 index 1475654..0000000 --- a/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/IncomingTransitions.java +++ /dev/null @@ -1,709 +0,0 @@ -/** - * Generated from platform:/resource/com.incquerylabs.magicdraw.benchmark/src/main/java/com/incquerylabs/magicdraw/benchmark/queries/APerformanceQueries.vql - */ -package com.incquerylabs.magicdraw.benchmark.queries; - -import com.nomagic.uml2.ext.magicdraw.statemachines.mdbehaviorstatemachines.State; -import com.nomagic.uml2.ext.magicdraw.statemachines.mdbehaviorstatemachines.Transition; -import java.util.Arrays; -import java.util.Collection; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.function.Consumer; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import org.apache.log4j.Logger; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.viatra.query.runtime.api.IPatternMatch; -import org.eclipse.viatra.query.runtime.api.IQuerySpecification; -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.api.impl.BaseMatcher; -import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; -import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; -import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey; -import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; -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.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.PVisibility; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; -import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; - -/** - * A pattern-specific query specification that can instantiate Matcher in a type-safe way. - * - *

Original source: - *

- *         Returns transitions with their targets. Made for reuse.
- *          
- *         pattern incomingTransitions(transition : Transition, targetState : State) {
- *         	Transition.target(transition, targetState);
- *         }
- * 
- * - * @see Matcher - * @see Match - * - */ -@SuppressWarnings("all") -public final class IncomingTransitions extends BaseGeneratedEMFQuerySpecification { - /** - * Pattern-specific match representation of the com.incquerylabs.magicdraw.benchmark.queries.incomingTransitions pattern, - * to be used in conjunction with {@link Matcher}. - * - *

Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. - * Each instance is a (possibly partial) substitution of pattern parameters, - * usable to represent a match of the pattern in the result of a query, - * or to specify the bound (fixed) input parameters when issuing a query. - * - * @see Matcher - * - */ - public static abstract class Match extends BasePatternMatch { - private Transition fTransition; - - private State fTargetState; - - private static List parameterNames = makeImmutableList("transition", "targetState"); - - private Match(final Transition pTransition, final State pTargetState) { - this.fTransition = pTransition; - this.fTargetState = pTargetState; - } - - @Override - public Object get(final String parameterName) { - switch(parameterName) { - case "transition": return this.fTransition; - case "targetState": return this.fTargetState; - default: return null; - } - } - - @Override - public Object get(final int index) { - switch(index) { - case 0: return this.fTransition; - case 1: return this.fTargetState; - default: return null; - } - } - - public Transition getTransition() { - return this.fTransition; - } - - public State getTargetState() { - return this.fTargetState; - } - - @Override - public boolean set(final String parameterName, final Object newValue) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - if ("transition".equals(parameterName) ) { - this.fTransition = (Transition) newValue; - return true; - } - if ("targetState".equals(parameterName) ) { - this.fTargetState = (State) newValue; - return true; - } - return false; - } - - public void setTransition(final Transition pTransition) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fTransition = pTransition; - } - - public void setTargetState(final State pTargetState) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fTargetState = pTargetState; - } - - @Override - public String patternName() { - return "com.incquerylabs.magicdraw.benchmark.queries.incomingTransitions"; - } - - @Override - public List parameterNames() { - return IncomingTransitions.Match.parameterNames; - } - - @Override - public Object[] toArray() { - return new Object[]{fTransition, fTargetState}; - } - - @Override - public IncomingTransitions.Match toImmutable() { - return isMutable() ? newMatch(fTransition, fTargetState) : this; - } - - @Override - public String prettyPrint() { - StringBuilder result = new StringBuilder(); - result.append("\"transition\"=" + prettyPrintValue(fTransition) + ", "); - result.append("\"targetState\"=" + prettyPrintValue(fTargetState)); - return result.toString(); - } - - @Override - public int hashCode() { - return Objects.hash(fTransition, fTargetState); - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) - return true; - if (obj == null) { - return false; - } - if ((obj instanceof IncomingTransitions.Match)) { - IncomingTransitions.Match other = (IncomingTransitions.Match) obj; - return Objects.equals(fTransition, other.fTransition) && Objects.equals(fTargetState, other.fTargetState); - } else { - // this should be infrequent - if (!(obj instanceof IPatternMatch)) { - return false; - } - IPatternMatch otherSig = (IPatternMatch) obj; - return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); - } - } - - @Override - public IncomingTransitions specification() { - return IncomingTransitions.instance(); - } - - /** - * Returns an empty, mutable match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @return the empty match. - * - */ - public static IncomingTransitions.Match newEmptyMatch() { - return new Mutable(null, null); - } - - /** - * Returns a mutable (partial) match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @param pTransition the fixed value of pattern parameter transition, or null if not bound. - * @param pTargetState the fixed value of pattern parameter targetState, or null if not bound. - * @return the new, mutable (partial) match object. - * - */ - public static IncomingTransitions.Match newMutableMatch(final Transition pTransition, final State pTargetState) { - return new Mutable(pTransition, pTargetState); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pTransition the fixed value of pattern parameter transition, or null if not bound. - * @param pTargetState the fixed value of pattern parameter targetState, or null if not bound. - * @return the (partial) match object. - * - */ - public static IncomingTransitions.Match newMatch(final Transition pTransition, final State pTargetState) { - return new Immutable(pTransition, pTargetState); - } - - private static final class Mutable extends IncomingTransitions.Match { - Mutable(final Transition pTransition, final State pTargetState) { - super(pTransition, pTargetState); - } - - @Override - public boolean isMutable() { - return true; - } - } - - private static final class Immutable extends IncomingTransitions.Match { - Immutable(final Transition pTransition, final State pTargetState) { - super(pTransition, pTargetState); - } - - @Override - public boolean isMutable() { - return false; - } - } - } - - /** - * Generated pattern matcher API of the com.incquerylabs.magicdraw.benchmark.queries.incomingTransitions pattern, - * providing pattern-specific query methods. - * - *

Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, - * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. - * - *

Matches of the pattern will be represented as {@link Match}. - * - *

Original source: - *

-   * Returns transitions with their targets. Made for reuse.
-   *  
-   * pattern incomingTransitions(transition : Transition, targetState : State) {
-   * 	Transition.target(transition, targetState);
-   * }
-   * 
- * - * @see Match - * @see IncomingTransitions - * - */ - public static class Matcher extends BaseMatcher { - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - public static IncomingTransitions.Matcher on(final ViatraQueryEngine engine) { - // check if matcher already exists - Matcher matcher = engine.getExistingMatcher(querySpecification()); - if (matcher == null) { - matcher = (Matcher)engine.getMatcher(querySpecification()); - } - return matcher; - } - - /** - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * @return an initialized matcher - * @noreference This method is for internal matcher initialization by the framework, do not call it manually. - * - */ - public static IncomingTransitions.Matcher create() { - return new Matcher(); - } - - private static final int POSITION_TRANSITION = 0; - - private static final int POSITION_TARGETSTATE = 1; - - private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(IncomingTransitions.Matcher.class); - - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - private Matcher() { - super(querySpecification()); - } - - /** - * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pTransition the fixed value of pattern parameter transition, or null if not bound. - * @param pTargetState the fixed value of pattern parameter targetState, or null if not bound. - * @return matches represented as a Match object. - * - */ - public Collection getAllMatches(final Transition pTransition, final State pTargetState) { - return rawStreamAllMatches(new Object[]{pTransition, pTargetState}).collect(Collectors.toSet()); - } - - /** - * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * @param pTransition the fixed value of pattern parameter transition, or null if not bound. - * @param pTargetState the fixed value of pattern parameter targetState, or null if not bound. - * @return a stream of matches represented as a Match object. - * - */ - public Stream streamAllMatches(final Transition pTransition, final State pTargetState) { - return rawStreamAllMatches(new Object[]{pTransition, pTargetState}); - } - - /** - * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pTransition the fixed value of pattern parameter transition, or null if not bound. - * @param pTargetState the fixed value of pattern parameter targetState, or null if not bound. - * @return a match represented as a Match object, or null if no match is found. - * - */ - public Optional getOneArbitraryMatch(final Transition pTransition, final State pTargetState) { - return rawGetOneArbitraryMatch(new Object[]{pTransition, pTargetState}); - } - - /** - * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, - * under any possible substitution of the unspecified parameters (if any). - * @param pTransition the fixed value of pattern parameter transition, or null if not bound. - * @param pTargetState the fixed value of pattern parameter targetState, or null if not bound. - * @return true if the input is a valid (partial) match of the pattern. - * - */ - public boolean hasMatch(final Transition pTransition, final State pTargetState) { - return rawHasMatch(new Object[]{pTransition, pTargetState}); - } - - /** - * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pTransition the fixed value of pattern parameter transition, or null if not bound. - * @param pTargetState the fixed value of pattern parameter targetState, or null if not bound. - * @return the number of pattern matches found. - * - */ - public int countMatches(final Transition pTransition, final State pTargetState) { - return rawCountMatches(new Object[]{pTransition, pTargetState}); - } - - /** - * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pTransition the fixed value of pattern parameter transition, or null if not bound. - * @param pTargetState the fixed value of pattern parameter targetState, or null if not bound. - * @param processor the action that will process the selected match. - * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked - * - */ - public boolean forOneArbitraryMatch(final Transition pTransition, final State pTargetState, final Consumer processor) { - return rawForOneArbitraryMatch(new Object[]{pTransition, pTargetState}, processor); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pTransition the fixed value of pattern parameter transition, or null if not bound. - * @param pTargetState the fixed value of pattern parameter targetState, or null if not bound. - * @return the (partial) match object. - * - */ - public IncomingTransitions.Match newMatch(final Transition pTransition, final State pTargetState) { - return IncomingTransitions.Match.newMatch(pTransition, pTargetState); - } - - /** - * Retrieve the set of values that occur in matches for transition. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOftransition(final Object[] parameters) { - return rawStreamAllValues(POSITION_TRANSITION, parameters).map(Transition.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for transition. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOftransition() { - return rawStreamAllValuesOftransition(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for transition. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOftransition() { - return rawStreamAllValuesOftransition(emptyArray()); - } - - /** - * Retrieve the set of values that occur in matches for transition. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOftransition(final IncomingTransitions.Match partialMatch) { - return rawStreamAllValuesOftransition(partialMatch.toArray()); - } - - /** - * Retrieve the set of values that occur in matches for transition. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOftransition(final State pTargetState) { - return rawStreamAllValuesOftransition(new Object[]{null, pTargetState}); - } - - /** - * Retrieve the set of values that occur in matches for transition. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOftransition(final IncomingTransitions.Match partialMatch) { - return rawStreamAllValuesOftransition(partialMatch.toArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for transition. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOftransition(final State pTargetState) { - return rawStreamAllValuesOftransition(new Object[]{null, pTargetState}).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for targetState. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOftargetState(final Object[] parameters) { - return rawStreamAllValues(POSITION_TARGETSTATE, parameters).map(State.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for targetState. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOftargetState() { - return rawStreamAllValuesOftargetState(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for targetState. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOftargetState() { - return rawStreamAllValuesOftargetState(emptyArray()); - } - - /** - * Retrieve the set of values that occur in matches for targetState. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOftargetState(final IncomingTransitions.Match partialMatch) { - return rawStreamAllValuesOftargetState(partialMatch.toArray()); - } - - /** - * Retrieve the set of values that occur in matches for targetState. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOftargetState(final Transition pTransition) { - return rawStreamAllValuesOftargetState(new Object[]{pTransition, null}); - } - - /** - * Retrieve the set of values that occur in matches for targetState. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOftargetState(final IncomingTransitions.Match partialMatch) { - return rawStreamAllValuesOftargetState(partialMatch.toArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for targetState. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOftargetState(final Transition pTransition) { - return rawStreamAllValuesOftargetState(new Object[]{pTransition, null}).collect(Collectors.toSet()); - } - - @Override - protected IncomingTransitions.Match tupleToMatch(final Tuple t) { - try { - return IncomingTransitions.Match.newMatch((Transition) t.get(POSITION_TRANSITION), (State) t.get(POSITION_TARGETSTATE)); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in tuple not properly typed!",e); - return null; - } - } - - @Override - protected IncomingTransitions.Match arrayToMatch(final Object[] match) { - try { - return IncomingTransitions.Match.newMatch((Transition) match[POSITION_TRANSITION], (State) match[POSITION_TARGETSTATE]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - @Override - protected IncomingTransitions.Match arrayToMatchMutable(final Object[] match) { - try { - return IncomingTransitions.Match.newMutableMatch((Transition) match[POSITION_TRANSITION], (State) match[POSITION_TARGETSTATE]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - /** - * @return the singleton instance of the query specification of this pattern - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static IQuerySpecification querySpecification() { - return IncomingTransitions.instance(); - } - } - - private IncomingTransitions() { - super(GeneratedPQuery.INSTANCE); - } - - /** - * @return the singleton instance of the query specification - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static IncomingTransitions instance() { - try{ - return LazyHolder.INSTANCE; - } catch (ExceptionInInitializerError err) { - throw processInitializerError(err); - } - } - - @Override - protected IncomingTransitions.Matcher instantiate(final ViatraQueryEngine engine) { - return IncomingTransitions.Matcher.on(engine); - } - - @Override - public IncomingTransitions.Matcher instantiate() { - return IncomingTransitions.Matcher.create(); - } - - @Override - public IncomingTransitions.Match newEmptyMatch() { - return IncomingTransitions.Match.newEmptyMatch(); - } - - @Override - public IncomingTransitions.Match newMatch(final Object... parameters) { - return IncomingTransitions.Match.newMatch((com.nomagic.uml2.ext.magicdraw.statemachines.mdbehaviorstatemachines.Transition) parameters[0], (com.nomagic.uml2.ext.magicdraw.statemachines.mdbehaviorstatemachines.State) parameters[1]); - } - - /** - * Inner class allowing the singleton instance of {@link IncomingTransitions} to be created - * not at the class load time of the outer class, - * but rather at the first call to {@link IncomingTransitions#instance()}. - * - *

This workaround is required e.g. to support recursion. - * - */ - private static class LazyHolder { - private static final IncomingTransitions INSTANCE = new IncomingTransitions(); - - /** - * Statically initializes the query specification after the field {@link #INSTANCE} is assigned. - * This initialization order is required to support indirect recursion. - * - *

The static initializer is defined using a helper field to work around limitations of the code generator. - * - */ - private static final Object STATIC_INITIALIZER = ensureInitialized(); - - public static Object ensureInitialized() { - INSTANCE.ensureInitializedInternal(); - return null; - } - } - - private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { - private static final IncomingTransitions.GeneratedPQuery INSTANCE = new GeneratedPQuery(); - - private final PParameter parameter_transition = new PParameter("transition", "com.nomagic.uml2.ext.magicdraw.statemachines.mdbehaviorstatemachines.Transition", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.nomagic.com/magicdraw/UML/2.5.1", "Transition")), PParameterDirection.INOUT); - - private final PParameter parameter_targetState = new PParameter("targetState", "com.nomagic.uml2.ext.magicdraw.statemachines.mdbehaviorstatemachines.State", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.nomagic.com/magicdraw/UML/2.5.1", "State")), PParameterDirection.INOUT); - - private final List parameters = Arrays.asList(parameter_transition, parameter_targetState); - - private GeneratedPQuery() { - super(PVisibility.PUBLIC); - } - - @Override - public String getFullyQualifiedName() { - return "com.incquerylabs.magicdraw.benchmark.queries.incomingTransitions"; - } - - @Override - public List getParameterNames() { - return Arrays.asList("transition","targetState"); - } - - @Override - public List getParameters() { - return parameters; - } - - @Override - public Set doGetContainedBodies() { - setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); - Set bodies = new LinkedHashSet<>(); - { - PBody body = new PBody(this); - PVariable var_transition = body.getOrCreateVariableByName("transition"); - PVariable var_targetState = body.getOrCreateVariableByName("targetState"); - new TypeConstraint(body, Tuples.flatTupleOf(var_transition), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Transition"))); - new TypeConstraint(body, Tuples.flatTupleOf(var_targetState), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "State"))); - body.setSymbolicParameters(Arrays.asList( - new ExportedParameter(body, var_transition, parameter_transition), - new ExportedParameter(body, var_targetState, parameter_targetState) - )); - // Transition.target(transition, targetState) - new TypeConstraint(body, Tuples.flatTupleOf(var_transition), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Transition"))); - PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_transition, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Transition", "target"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Vertex"))); - new Equality(body, var__virtual_0_, var_targetState); - bodies.add(body); - } - return bodies; - } - } -} diff --git a/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/LoopTransitionWithTriggerEffectEventNoGuard.java b/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/LoopTransitionWithTriggerEffectEventNoGuard.java deleted file mode 100644 index 3111071..0000000 --- a/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/LoopTransitionWithTriggerEffectEventNoGuard.java +++ /dev/null @@ -1,1098 +0,0 @@ -/** - * Generated from platform:/resource/com.incquerylabs.magicdraw.benchmark/src/main/java/com/incquerylabs/magicdraw/benchmark/queries/APerformanceQueries.vql - */ -package com.incquerylabs.magicdraw.benchmark.queries; - -import com.incquerylabs.magicdraw.benchmark.queries.internal.TransitionWithGuard; -import com.nomagic.uml2.ext.magicdraw.activities.mdfundamentalactivities.Activity; -import com.nomagic.uml2.ext.magicdraw.commonbehaviors.mdcommunications.Event; -import com.nomagic.uml2.ext.magicdraw.commonbehaviors.mdcommunications.Trigger; -import com.nomagic.uml2.ext.magicdraw.statemachines.mdbehaviorstatemachines.State; -import com.nomagic.uml2.ext.magicdraw.statemachines.mdbehaviorstatemachines.Transition; -import java.util.Arrays; -import java.util.Collection; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.function.Consumer; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import org.apache.log4j.Logger; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.emf.ecore.EDataType; -import org.eclipse.viatra.query.runtime.api.IPatternMatch; -import org.eclipse.viatra.query.runtime.api.IQuerySpecification; -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.api.impl.BaseMatcher; -import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; -import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; -import org.eclipse.viatra.query.runtime.emf.types.EDataTypeInSlotsKey; -import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey; -import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; -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.NegativePatternCall; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.ConstantValue; -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.PVisibility; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; -import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; - -/** - * A pattern-specific query specification that can instantiate Matcher in a type-safe way. - * - *

Original source: - *

- *         A loop transition that
- *           - Has a trigger
- *           - Has some effect that is an activity
- *           - Has no guard
- *           - defines an event
- *           
- *          
- *         pattern loopTransitionWithTriggerEffectEventNoGuard(state : State, transition : Transition, trigger : Trigger, event : Event, effect : Activity) {
- *         	Transition.source(transition, state);
- *         	Transition.target(transition, state);
- *         	Transition.kind(transition, ::external);
- *         	Transition.trigger(transition, trigger);
- *         	Transition.effect(transition, effect);
- *         	neg find transitionWithGuard(transition, _);
- *         	Trigger.event(trigger, event);
- *         }
- * 
- * - * @see Matcher - * @see Match - * - */ -@SuppressWarnings("all") -public final class LoopTransitionWithTriggerEffectEventNoGuard extends BaseGeneratedEMFQuerySpecification { - /** - * Pattern-specific match representation of the com.incquerylabs.magicdraw.benchmark.queries.loopTransitionWithTriggerEffectEventNoGuard pattern, - * to be used in conjunction with {@link Matcher}. - * - *

Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. - * Each instance is a (possibly partial) substitution of pattern parameters, - * usable to represent a match of the pattern in the result of a query, - * or to specify the bound (fixed) input parameters when issuing a query. - * - * @see Matcher - * - */ - public static abstract class Match extends BasePatternMatch { - private State fState; - - private Transition fTransition; - - private Trigger fTrigger; - - private Event fEvent; - - private Activity fEffect; - - private static List parameterNames = makeImmutableList("state", "transition", "trigger", "event", "effect"); - - private Match(final State pState, final Transition pTransition, final Trigger pTrigger, final Event pEvent, final Activity pEffect) { - this.fState = pState; - this.fTransition = pTransition; - this.fTrigger = pTrigger; - this.fEvent = pEvent; - this.fEffect = pEffect; - } - - @Override - public Object get(final String parameterName) { - switch(parameterName) { - case "state": return this.fState; - case "transition": return this.fTransition; - case "trigger": return this.fTrigger; - case "event": return this.fEvent; - case "effect": return this.fEffect; - default: return null; - } - } - - @Override - public Object get(final int index) { - switch(index) { - case 0: return this.fState; - case 1: return this.fTransition; - case 2: return this.fTrigger; - case 3: return this.fEvent; - case 4: return this.fEffect; - default: return null; - } - } - - public State getState() { - return this.fState; - } - - public Transition getTransition() { - return this.fTransition; - } - - public Trigger getTrigger() { - return this.fTrigger; - } - - public Event getEvent() { - return this.fEvent; - } - - public Activity getEffect() { - return this.fEffect; - } - - @Override - public boolean set(final String parameterName, final Object newValue) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - if ("state".equals(parameterName) ) { - this.fState = (State) newValue; - return true; - } - if ("transition".equals(parameterName) ) { - this.fTransition = (Transition) newValue; - return true; - } - if ("trigger".equals(parameterName) ) { - this.fTrigger = (Trigger) newValue; - return true; - } - if ("event".equals(parameterName) ) { - this.fEvent = (Event) newValue; - return true; - } - if ("effect".equals(parameterName) ) { - this.fEffect = (Activity) newValue; - return true; - } - return false; - } - - public void setState(final State pState) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fState = pState; - } - - public void setTransition(final Transition pTransition) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fTransition = pTransition; - } - - public void setTrigger(final Trigger pTrigger) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fTrigger = pTrigger; - } - - public void setEvent(final Event pEvent) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fEvent = pEvent; - } - - public void setEffect(final Activity pEffect) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fEffect = pEffect; - } - - @Override - public String patternName() { - return "com.incquerylabs.magicdraw.benchmark.queries.loopTransitionWithTriggerEffectEventNoGuard"; - } - - @Override - public List parameterNames() { - return LoopTransitionWithTriggerEffectEventNoGuard.Match.parameterNames; - } - - @Override - public Object[] toArray() { - return new Object[]{fState, fTransition, fTrigger, fEvent, fEffect}; - } - - @Override - public LoopTransitionWithTriggerEffectEventNoGuard.Match toImmutable() { - return isMutable() ? newMatch(fState, fTransition, fTrigger, fEvent, fEffect) : this; - } - - @Override - public String prettyPrint() { - StringBuilder result = new StringBuilder(); - result.append("\"state\"=" + prettyPrintValue(fState) + ", "); - result.append("\"transition\"=" + prettyPrintValue(fTransition) + ", "); - result.append("\"trigger\"=" + prettyPrintValue(fTrigger) + ", "); - result.append("\"event\"=" + prettyPrintValue(fEvent) + ", "); - result.append("\"effect\"=" + prettyPrintValue(fEffect)); - return result.toString(); - } - - @Override - public int hashCode() { - return Objects.hash(fState, fTransition, fTrigger, fEvent, fEffect); - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) - return true; - if (obj == null) { - return false; - } - if ((obj instanceof LoopTransitionWithTriggerEffectEventNoGuard.Match)) { - LoopTransitionWithTriggerEffectEventNoGuard.Match other = (LoopTransitionWithTriggerEffectEventNoGuard.Match) obj; - return Objects.equals(fState, other.fState) && Objects.equals(fTransition, other.fTransition) && Objects.equals(fTrigger, other.fTrigger) && Objects.equals(fEvent, other.fEvent) && Objects.equals(fEffect, other.fEffect); - } else { - // this should be infrequent - if (!(obj instanceof IPatternMatch)) { - return false; - } - IPatternMatch otherSig = (IPatternMatch) obj; - return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); - } - } - - @Override - public LoopTransitionWithTriggerEffectEventNoGuard specification() { - return LoopTransitionWithTriggerEffectEventNoGuard.instance(); - } - - /** - * Returns an empty, mutable match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @return the empty match. - * - */ - public static LoopTransitionWithTriggerEffectEventNoGuard.Match newEmptyMatch() { - return new Mutable(null, null, null, null, null); - } - - /** - * Returns a mutable (partial) match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pTransition the fixed value of pattern parameter transition, or null if not bound. - * @param pTrigger the fixed value of pattern parameter trigger, or null if not bound. - * @param pEvent the fixed value of pattern parameter event, or null if not bound. - * @param pEffect the fixed value of pattern parameter effect, or null if not bound. - * @return the new, mutable (partial) match object. - * - */ - public static LoopTransitionWithTriggerEffectEventNoGuard.Match newMutableMatch(final State pState, final Transition pTransition, final Trigger pTrigger, final Event pEvent, final Activity pEffect) { - return new Mutable(pState, pTransition, pTrigger, pEvent, pEffect); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pTransition the fixed value of pattern parameter transition, or null if not bound. - * @param pTrigger the fixed value of pattern parameter trigger, or null if not bound. - * @param pEvent the fixed value of pattern parameter event, or null if not bound. - * @param pEffect the fixed value of pattern parameter effect, or null if not bound. - * @return the (partial) match object. - * - */ - public static LoopTransitionWithTriggerEffectEventNoGuard.Match newMatch(final State pState, final Transition pTransition, final Trigger pTrigger, final Event pEvent, final Activity pEffect) { - return new Immutable(pState, pTransition, pTrigger, pEvent, pEffect); - } - - private static final class Mutable extends LoopTransitionWithTriggerEffectEventNoGuard.Match { - Mutable(final State pState, final Transition pTransition, final Trigger pTrigger, final Event pEvent, final Activity pEffect) { - super(pState, pTransition, pTrigger, pEvent, pEffect); - } - - @Override - public boolean isMutable() { - return true; - } - } - - private static final class Immutable extends LoopTransitionWithTriggerEffectEventNoGuard.Match { - Immutable(final State pState, final Transition pTransition, final Trigger pTrigger, final Event pEvent, final Activity pEffect) { - super(pState, pTransition, pTrigger, pEvent, pEffect); - } - - @Override - public boolean isMutable() { - return false; - } - } - } - - /** - * Generated pattern matcher API of the com.incquerylabs.magicdraw.benchmark.queries.loopTransitionWithTriggerEffectEventNoGuard pattern, - * providing pattern-specific query methods. - * - *

Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, - * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. - * - *

Matches of the pattern will be represented as {@link Match}. - * - *

Original source: - *

-   * A loop transition that
-   *   - Has a trigger
-   *   - Has some effect that is an activity
-   *   - Has no guard
-   *   - defines an event
-   *   
-   *  
-   * pattern loopTransitionWithTriggerEffectEventNoGuard(state : State, transition : Transition, trigger : Trigger, event : Event, effect : Activity) {
-   * 	Transition.source(transition, state);
-   * 	Transition.target(transition, state);
-   * 	Transition.kind(transition, ::external);
-   * 	Transition.trigger(transition, trigger);
-   * 	Transition.effect(transition, effect);
-   * 	neg find transitionWithGuard(transition, _);
-   * 	Trigger.event(trigger, event);
-   * }
-   * 
- * - * @see Match - * @see LoopTransitionWithTriggerEffectEventNoGuard - * - */ - public static class Matcher extends BaseMatcher { - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - public static LoopTransitionWithTriggerEffectEventNoGuard.Matcher on(final ViatraQueryEngine engine) { - // check if matcher already exists - Matcher matcher = engine.getExistingMatcher(querySpecification()); - if (matcher == null) { - matcher = (Matcher)engine.getMatcher(querySpecification()); - } - return matcher; - } - - /** - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * @return an initialized matcher - * @noreference This method is for internal matcher initialization by the framework, do not call it manually. - * - */ - public static LoopTransitionWithTriggerEffectEventNoGuard.Matcher create() { - return new Matcher(); - } - - private static final int POSITION_STATE = 0; - - private static final int POSITION_TRANSITION = 1; - - private static final int POSITION_TRIGGER = 2; - - private static final int POSITION_EVENT = 3; - - private static final int POSITION_EFFECT = 4; - - private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(LoopTransitionWithTriggerEffectEventNoGuard.Matcher.class); - - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - private Matcher() { - super(querySpecification()); - } - - /** - * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pTransition the fixed value of pattern parameter transition, or null if not bound. - * @param pTrigger the fixed value of pattern parameter trigger, or null if not bound. - * @param pEvent the fixed value of pattern parameter event, or null if not bound. - * @param pEffect the fixed value of pattern parameter effect, or null if not bound. - * @return matches represented as a Match object. - * - */ - public Collection getAllMatches(final State pState, final Transition pTransition, final Trigger pTrigger, final Event pEvent, final Activity pEffect) { - return rawStreamAllMatches(new Object[]{pState, pTransition, pTrigger, pEvent, pEffect}).collect(Collectors.toSet()); - } - - /** - * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pTransition the fixed value of pattern parameter transition, or null if not bound. - * @param pTrigger the fixed value of pattern parameter trigger, or null if not bound. - * @param pEvent the fixed value of pattern parameter event, or null if not bound. - * @param pEffect the fixed value of pattern parameter effect, or null if not bound. - * @return a stream of matches represented as a Match object. - * - */ - public Stream streamAllMatches(final State pState, final Transition pTransition, final Trigger pTrigger, final Event pEvent, final Activity pEffect) { - return rawStreamAllMatches(new Object[]{pState, pTransition, pTrigger, pEvent, pEffect}); - } - - /** - * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pTransition the fixed value of pattern parameter transition, or null if not bound. - * @param pTrigger the fixed value of pattern parameter trigger, or null if not bound. - * @param pEvent the fixed value of pattern parameter event, or null if not bound. - * @param pEffect the fixed value of pattern parameter effect, or null if not bound. - * @return a match represented as a Match object, or null if no match is found. - * - */ - public Optional getOneArbitraryMatch(final State pState, final Transition pTransition, final Trigger pTrigger, final Event pEvent, final Activity pEffect) { - return rawGetOneArbitraryMatch(new Object[]{pState, pTransition, pTrigger, pEvent, pEffect}); - } - - /** - * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, - * under any possible substitution of the unspecified parameters (if any). - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pTransition the fixed value of pattern parameter transition, or null if not bound. - * @param pTrigger the fixed value of pattern parameter trigger, or null if not bound. - * @param pEvent the fixed value of pattern parameter event, or null if not bound. - * @param pEffect the fixed value of pattern parameter effect, or null if not bound. - * @return true if the input is a valid (partial) match of the pattern. - * - */ - public boolean hasMatch(final State pState, final Transition pTransition, final Trigger pTrigger, final Event pEvent, final Activity pEffect) { - return rawHasMatch(new Object[]{pState, pTransition, pTrigger, pEvent, pEffect}); - } - - /** - * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pTransition the fixed value of pattern parameter transition, or null if not bound. - * @param pTrigger the fixed value of pattern parameter trigger, or null if not bound. - * @param pEvent the fixed value of pattern parameter event, or null if not bound. - * @param pEffect the fixed value of pattern parameter effect, or null if not bound. - * @return the number of pattern matches found. - * - */ - public int countMatches(final State pState, final Transition pTransition, final Trigger pTrigger, final Event pEvent, final Activity pEffect) { - return rawCountMatches(new Object[]{pState, pTransition, pTrigger, pEvent, pEffect}); - } - - /** - * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pTransition the fixed value of pattern parameter transition, or null if not bound. - * @param pTrigger the fixed value of pattern parameter trigger, or null if not bound. - * @param pEvent the fixed value of pattern parameter event, or null if not bound. - * @param pEffect the fixed value of pattern parameter effect, or null if not bound. - * @param processor the action that will process the selected match. - * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked - * - */ - public boolean forOneArbitraryMatch(final State pState, final Transition pTransition, final Trigger pTrigger, final Event pEvent, final Activity pEffect, final Consumer processor) { - return rawForOneArbitraryMatch(new Object[]{pState, pTransition, pTrigger, pEvent, pEffect}, processor); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pTransition the fixed value of pattern parameter transition, or null if not bound. - * @param pTrigger the fixed value of pattern parameter trigger, or null if not bound. - * @param pEvent the fixed value of pattern parameter event, or null if not bound. - * @param pEffect the fixed value of pattern parameter effect, or null if not bound. - * @return the (partial) match object. - * - */ - public LoopTransitionWithTriggerEffectEventNoGuard.Match newMatch(final State pState, final Transition pTransition, final Trigger pTrigger, final Event pEvent, final Activity pEffect) { - return LoopTransitionWithTriggerEffectEventNoGuard.Match.newMatch(pState, pTransition, pTrigger, pEvent, pEffect); - } - - /** - * Retrieve the set of values that occur in matches for state. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOfstate(final Object[] parameters) { - return rawStreamAllValues(POSITION_STATE, parameters).map(State.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for state. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfstate() { - return rawStreamAllValuesOfstate(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for state. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfstate() { - return rawStreamAllValuesOfstate(emptyArray()); - } - - /** - * Retrieve the set of values that occur in matches for state. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfstate(final LoopTransitionWithTriggerEffectEventNoGuard.Match partialMatch) { - return rawStreamAllValuesOfstate(partialMatch.toArray()); - } - - /** - * Retrieve the set of values that occur in matches for state. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfstate(final Transition pTransition, final Trigger pTrigger, final Event pEvent, final Activity pEffect) { - return rawStreamAllValuesOfstate(new Object[]{null, pTransition, pTrigger, pEvent, pEffect}); - } - - /** - * Retrieve the set of values that occur in matches for state. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfstate(final LoopTransitionWithTriggerEffectEventNoGuard.Match partialMatch) { - return rawStreamAllValuesOfstate(partialMatch.toArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for state. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfstate(final Transition pTransition, final Trigger pTrigger, final Event pEvent, final Activity pEffect) { - return rawStreamAllValuesOfstate(new Object[]{null, pTransition, pTrigger, pEvent, pEffect}).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for transition. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOftransition(final Object[] parameters) { - return rawStreamAllValues(POSITION_TRANSITION, parameters).map(Transition.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for transition. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOftransition() { - return rawStreamAllValuesOftransition(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for transition. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOftransition() { - return rawStreamAllValuesOftransition(emptyArray()); - } - - /** - * Retrieve the set of values that occur in matches for transition. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOftransition(final LoopTransitionWithTriggerEffectEventNoGuard.Match partialMatch) { - return rawStreamAllValuesOftransition(partialMatch.toArray()); - } - - /** - * Retrieve the set of values that occur in matches for transition. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOftransition(final State pState, final Trigger pTrigger, final Event pEvent, final Activity pEffect) { - return rawStreamAllValuesOftransition(new Object[]{pState, null, pTrigger, pEvent, pEffect}); - } - - /** - * Retrieve the set of values that occur in matches for transition. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOftransition(final LoopTransitionWithTriggerEffectEventNoGuard.Match partialMatch) { - return rawStreamAllValuesOftransition(partialMatch.toArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for transition. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOftransition(final State pState, final Trigger pTrigger, final Event pEvent, final Activity pEffect) { - return rawStreamAllValuesOftransition(new Object[]{pState, null, pTrigger, pEvent, pEffect}).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for trigger. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOftrigger(final Object[] parameters) { - return rawStreamAllValues(POSITION_TRIGGER, parameters).map(Trigger.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for trigger. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOftrigger() { - return rawStreamAllValuesOftrigger(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for trigger. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOftrigger() { - return rawStreamAllValuesOftrigger(emptyArray()); - } - - /** - * Retrieve the set of values that occur in matches for trigger. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOftrigger(final LoopTransitionWithTriggerEffectEventNoGuard.Match partialMatch) { - return rawStreamAllValuesOftrigger(partialMatch.toArray()); - } - - /** - * Retrieve the set of values that occur in matches for trigger. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOftrigger(final State pState, final Transition pTransition, final Event pEvent, final Activity pEffect) { - return rawStreamAllValuesOftrigger(new Object[]{pState, pTransition, null, pEvent, pEffect}); - } - - /** - * Retrieve the set of values that occur in matches for trigger. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOftrigger(final LoopTransitionWithTriggerEffectEventNoGuard.Match partialMatch) { - return rawStreamAllValuesOftrigger(partialMatch.toArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for trigger. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOftrigger(final State pState, final Transition pTransition, final Event pEvent, final Activity pEffect) { - return rawStreamAllValuesOftrigger(new Object[]{pState, pTransition, null, pEvent, pEffect}).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for event. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOfevent(final Object[] parameters) { - return rawStreamAllValues(POSITION_EVENT, parameters).map(Event.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for event. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfevent() { - return rawStreamAllValuesOfevent(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for event. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfevent() { - return rawStreamAllValuesOfevent(emptyArray()); - } - - /** - * Retrieve the set of values that occur in matches for event. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfevent(final LoopTransitionWithTriggerEffectEventNoGuard.Match partialMatch) { - return rawStreamAllValuesOfevent(partialMatch.toArray()); - } - - /** - * Retrieve the set of values that occur in matches for event. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfevent(final State pState, final Transition pTransition, final Trigger pTrigger, final Activity pEffect) { - return rawStreamAllValuesOfevent(new Object[]{pState, pTransition, pTrigger, null, pEffect}); - } - - /** - * Retrieve the set of values that occur in matches for event. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfevent(final LoopTransitionWithTriggerEffectEventNoGuard.Match partialMatch) { - return rawStreamAllValuesOfevent(partialMatch.toArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for event. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfevent(final State pState, final Transition pTransition, final Trigger pTrigger, final Activity pEffect) { - return rawStreamAllValuesOfevent(new Object[]{pState, pTransition, pTrigger, null, pEffect}).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for effect. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOfeffect(final Object[] parameters) { - return rawStreamAllValues(POSITION_EFFECT, parameters).map(Activity.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for effect. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfeffect() { - return rawStreamAllValuesOfeffect(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for effect. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfeffect() { - return rawStreamAllValuesOfeffect(emptyArray()); - } - - /** - * Retrieve the set of values that occur in matches for effect. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfeffect(final LoopTransitionWithTriggerEffectEventNoGuard.Match partialMatch) { - return rawStreamAllValuesOfeffect(partialMatch.toArray()); - } - - /** - * Retrieve the set of values that occur in matches for effect. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfeffect(final State pState, final Transition pTransition, final Trigger pTrigger, final Event pEvent) { - return rawStreamAllValuesOfeffect(new Object[]{pState, pTransition, pTrigger, pEvent, null}); - } - - /** - * Retrieve the set of values that occur in matches for effect. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfeffect(final LoopTransitionWithTriggerEffectEventNoGuard.Match partialMatch) { - return rawStreamAllValuesOfeffect(partialMatch.toArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for effect. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfeffect(final State pState, final Transition pTransition, final Trigger pTrigger, final Event pEvent) { - return rawStreamAllValuesOfeffect(new Object[]{pState, pTransition, pTrigger, pEvent, null}).collect(Collectors.toSet()); - } - - @Override - protected LoopTransitionWithTriggerEffectEventNoGuard.Match tupleToMatch(final Tuple t) { - try { - return LoopTransitionWithTriggerEffectEventNoGuard.Match.newMatch((State) t.get(POSITION_STATE), (Transition) t.get(POSITION_TRANSITION), (Trigger) t.get(POSITION_TRIGGER), (Event) t.get(POSITION_EVENT), (Activity) t.get(POSITION_EFFECT)); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in tuple not properly typed!",e); - return null; - } - } - - @Override - protected LoopTransitionWithTriggerEffectEventNoGuard.Match arrayToMatch(final Object[] match) { - try { - return LoopTransitionWithTriggerEffectEventNoGuard.Match.newMatch((State) match[POSITION_STATE], (Transition) match[POSITION_TRANSITION], (Trigger) match[POSITION_TRIGGER], (Event) match[POSITION_EVENT], (Activity) match[POSITION_EFFECT]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - @Override - protected LoopTransitionWithTriggerEffectEventNoGuard.Match arrayToMatchMutable(final Object[] match) { - try { - return LoopTransitionWithTriggerEffectEventNoGuard.Match.newMutableMatch((State) match[POSITION_STATE], (Transition) match[POSITION_TRANSITION], (Trigger) match[POSITION_TRIGGER], (Event) match[POSITION_EVENT], (Activity) match[POSITION_EFFECT]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - /** - * @return the singleton instance of the query specification of this pattern - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static IQuerySpecification querySpecification() { - return LoopTransitionWithTriggerEffectEventNoGuard.instance(); - } - } - - private LoopTransitionWithTriggerEffectEventNoGuard() { - super(GeneratedPQuery.INSTANCE); - } - - /** - * @return the singleton instance of the query specification - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static LoopTransitionWithTriggerEffectEventNoGuard instance() { - try{ - return LazyHolder.INSTANCE; - } catch (ExceptionInInitializerError err) { - throw processInitializerError(err); - } - } - - @Override - protected LoopTransitionWithTriggerEffectEventNoGuard.Matcher instantiate(final ViatraQueryEngine engine) { - return LoopTransitionWithTriggerEffectEventNoGuard.Matcher.on(engine); - } - - @Override - public LoopTransitionWithTriggerEffectEventNoGuard.Matcher instantiate() { - return LoopTransitionWithTriggerEffectEventNoGuard.Matcher.create(); - } - - @Override - public LoopTransitionWithTriggerEffectEventNoGuard.Match newEmptyMatch() { - return LoopTransitionWithTriggerEffectEventNoGuard.Match.newEmptyMatch(); - } - - @Override - public LoopTransitionWithTriggerEffectEventNoGuard.Match newMatch(final Object... parameters) { - return LoopTransitionWithTriggerEffectEventNoGuard.Match.newMatch((com.nomagic.uml2.ext.magicdraw.statemachines.mdbehaviorstatemachines.State) parameters[0], (com.nomagic.uml2.ext.magicdraw.statemachines.mdbehaviorstatemachines.Transition) parameters[1], (com.nomagic.uml2.ext.magicdraw.commonbehaviors.mdcommunications.Trigger) parameters[2], (com.nomagic.uml2.ext.magicdraw.commonbehaviors.mdcommunications.Event) parameters[3], (com.nomagic.uml2.ext.magicdraw.activities.mdfundamentalactivities.Activity) parameters[4]); - } - - /** - * Inner class allowing the singleton instance of {@link LoopTransitionWithTriggerEffectEventNoGuard} to be created - * not at the class load time of the outer class, - * but rather at the first call to {@link LoopTransitionWithTriggerEffectEventNoGuard#instance()}. - * - *

This workaround is required e.g. to support recursion. - * - */ - private static class LazyHolder { - private static final LoopTransitionWithTriggerEffectEventNoGuard INSTANCE = new LoopTransitionWithTriggerEffectEventNoGuard(); - - /** - * Statically initializes the query specification after the field {@link #INSTANCE} is assigned. - * This initialization order is required to support indirect recursion. - * - *

The static initializer is defined using a helper field to work around limitations of the code generator. - * - */ - private static final Object STATIC_INITIALIZER = ensureInitialized(); - - public static Object ensureInitialized() { - INSTANCE.ensureInitializedInternal(); - return null; - } - } - - private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { - private static final LoopTransitionWithTriggerEffectEventNoGuard.GeneratedPQuery INSTANCE = new GeneratedPQuery(); - - private final PParameter parameter_state = new PParameter("state", "com.nomagic.uml2.ext.magicdraw.statemachines.mdbehaviorstatemachines.State", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.nomagic.com/magicdraw/UML/2.5.1", "State")), PParameterDirection.INOUT); - - private final PParameter parameter_transition = new PParameter("transition", "com.nomagic.uml2.ext.magicdraw.statemachines.mdbehaviorstatemachines.Transition", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.nomagic.com/magicdraw/UML/2.5.1", "Transition")), PParameterDirection.INOUT); - - private final PParameter parameter_trigger = new PParameter("trigger", "com.nomagic.uml2.ext.magicdraw.commonbehaviors.mdcommunications.Trigger", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.nomagic.com/magicdraw/UML/2.5.1", "Trigger")), PParameterDirection.INOUT); - - private final PParameter parameter_event = new PParameter("event", "com.nomagic.uml2.ext.magicdraw.commonbehaviors.mdcommunications.Event", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.nomagic.com/magicdraw/UML/2.5.1", "Event")), PParameterDirection.INOUT); - - private final PParameter parameter_effect = new PParameter("effect", "com.nomagic.uml2.ext.magicdraw.activities.mdfundamentalactivities.Activity", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.nomagic.com/magicdraw/UML/2.5.1", "Activity")), PParameterDirection.INOUT); - - private final List parameters = Arrays.asList(parameter_state, parameter_transition, parameter_trigger, parameter_event, parameter_effect); - - private GeneratedPQuery() { - super(PVisibility.PUBLIC); - } - - @Override - public String getFullyQualifiedName() { - return "com.incquerylabs.magicdraw.benchmark.queries.loopTransitionWithTriggerEffectEventNoGuard"; - } - - @Override - public List getParameterNames() { - return Arrays.asList("state","transition","trigger","event","effect"); - } - - @Override - public List getParameters() { - return parameters; - } - - @Override - public Set doGetContainedBodies() { - setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); - Set bodies = new LinkedHashSet<>(); - { - PBody body = new PBody(this); - PVariable var_state = body.getOrCreateVariableByName("state"); - PVariable var_transition = body.getOrCreateVariableByName("transition"); - PVariable var_trigger = body.getOrCreateVariableByName("trigger"); - PVariable var_event = body.getOrCreateVariableByName("event"); - PVariable var_effect = body.getOrCreateVariableByName("effect"); - PVariable var___0_ = body.getOrCreateVariableByName("_<0>"); - new TypeConstraint(body, Tuples.flatTupleOf(var_state), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "State"))); - new TypeConstraint(body, Tuples.flatTupleOf(var_transition), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Transition"))); - new TypeConstraint(body, Tuples.flatTupleOf(var_trigger), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Trigger"))); - new TypeConstraint(body, Tuples.flatTupleOf(var_event), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Event"))); - new TypeConstraint(body, Tuples.flatTupleOf(var_effect), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Activity"))); - body.setSymbolicParameters(Arrays.asList( - new ExportedParameter(body, var_state, parameter_state), - new ExportedParameter(body, var_transition, parameter_transition), - new ExportedParameter(body, var_trigger, parameter_trigger), - new ExportedParameter(body, var_event, parameter_event), - new ExportedParameter(body, var_effect, parameter_effect) - )); - // Transition.source(transition, state) - new TypeConstraint(body, Tuples.flatTupleOf(var_transition), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Transition"))); - PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_transition, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Transition", "source"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Vertex"))); - new Equality(body, var__virtual_0_, var_state); - // Transition.target(transition, state) - new TypeConstraint(body, Tuples.flatTupleOf(var_transition), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Transition"))); - PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_transition, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Transition", "target"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Vertex"))); - new Equality(body, var__virtual_1_, var_state); - // Transition.kind(transition, ::external) - PVariable var__virtual_2_ = body.getOrCreateVariableByName(".virtual{2}"); - new ConstantValue(body, var__virtual_2_, com.nomagic.uml2.ext.magicdraw.statemachines.mdbehaviorstatemachines.TransitionKindEnum.get("external")); - new TypeConstraint(body, Tuples.flatTupleOf(var_transition), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Transition"))); - PVariable var__virtual_3_ = body.getOrCreateVariableByName(".virtual{3}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_transition, var__virtual_3_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Transition", "kind"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_3_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "TransitionKind"))); - new Equality(body, var__virtual_3_, var__virtual_2_); - // Transition.trigger(transition, trigger) - new TypeConstraint(body, Tuples.flatTupleOf(var_transition), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Transition"))); - PVariable var__virtual_4_ = body.getOrCreateVariableByName(".virtual{4}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_transition, var__virtual_4_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Transition", "trigger"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_4_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Trigger"))); - new Equality(body, var__virtual_4_, var_trigger); - // Transition.effect(transition, effect) - new TypeConstraint(body, Tuples.flatTupleOf(var_transition), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Transition"))); - PVariable var__virtual_5_ = body.getOrCreateVariableByName(".virtual{5}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_transition, var__virtual_5_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Transition", "effect"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_5_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Behavior"))); - new Equality(body, var__virtual_5_, var_effect); - // neg find transitionWithGuard(transition, _) - new NegativePatternCall(body, Tuples.flatTupleOf(var_transition, var___0_), TransitionWithGuard.instance().getInternalQueryRepresentation()); - // Trigger.event(trigger, event) - new TypeConstraint(body, Tuples.flatTupleOf(var_trigger), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Trigger"))); - PVariable var__virtual_6_ = body.getOrCreateVariableByName(".virtual{6}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_trigger, var__virtual_6_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Trigger", "event"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_6_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Event"))); - new Equality(body, var__virtual_6_, var_event); - bodies.add(body); - } - return bodies; - } - } -} diff --git a/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/NamedElement.java b/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/NamedElement.java deleted file mode 100644 index 1218452..0000000 --- a/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/NamedElement.java +++ /dev/null @@ -1,711 +0,0 @@ -/** - * Generated from platform:/resource/com.incquerylabs.magicdraw.benchmark/src/main/java/com/incquerylabs/magicdraw/benchmark/queries/APerformanceQueries.vql - */ -package com.incquerylabs.magicdraw.benchmark.queries; - -import java.util.Arrays; -import java.util.Collection; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.function.Consumer; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import org.apache.log4j.Logger; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.emf.ecore.EDataType; -import org.eclipse.viatra.query.runtime.api.IPatternMatch; -import org.eclipse.viatra.query.runtime.api.IQuerySpecification; -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.api.impl.BaseMatcher; -import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; -import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; -import org.eclipse.viatra.query.runtime.emf.types.EDataTypeInSlotsKey; -import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey; -import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; -import org.eclipse.viatra.query.runtime.matchers.context.common.JavaTransitiveInstancesKey; -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.TypeFilterConstraint; -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.PVisibility; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; -import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; - -/** - * A pattern-specific query specification that can instantiate Matcher in a type-safe way. - * - *

Original source: - *

- *         Querying all instances of an EClass with an attribute. 
- *          
- *         pattern namedElement(element : NamedElement, name : java ^java.lang.String) {
- *         	NamedElement.name(element, name);
- *         }
- * 
- * - * @see Matcher - * @see Match - * - */ -@SuppressWarnings("all") -public final class NamedElement extends BaseGeneratedEMFQuerySpecification { - /** - * Pattern-specific match representation of the com.incquerylabs.magicdraw.benchmark.queries.namedElement pattern, - * to be used in conjunction with {@link Matcher}. - * - *

Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. - * Each instance is a (possibly partial) substitution of pattern parameters, - * usable to represent a match of the pattern in the result of a query, - * or to specify the bound (fixed) input parameters when issuing a query. - * - * @see Matcher - * - */ - public static abstract class Match extends BasePatternMatch { - private com.nomagic.uml2.ext.magicdraw.classes.mdkernel.NamedElement fElement; - - private String fName; - - private static List parameterNames = makeImmutableList("element", "name"); - - private Match(final com.nomagic.uml2.ext.magicdraw.classes.mdkernel.NamedElement pElement, final String pName) { - this.fElement = pElement; - this.fName = pName; - } - - @Override - public Object get(final String parameterName) { - switch(parameterName) { - case "element": return this.fElement; - case "name": return this.fName; - default: return null; - } - } - - @Override - public Object get(final int index) { - switch(index) { - case 0: return this.fElement; - case 1: return this.fName; - default: return null; - } - } - - public com.nomagic.uml2.ext.magicdraw.classes.mdkernel.NamedElement getElement() { - return this.fElement; - } - - public String getName() { - return this.fName; - } - - @Override - public boolean set(final String parameterName, final Object newValue) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - if ("element".equals(parameterName) ) { - this.fElement = (com.nomagic.uml2.ext.magicdraw.classes.mdkernel.NamedElement) newValue; - return true; - } - if ("name".equals(parameterName) ) { - this.fName = (String) newValue; - return true; - } - return false; - } - - public void setElement(final com.nomagic.uml2.ext.magicdraw.classes.mdkernel.NamedElement pElement) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fElement = pElement; - } - - public void setName(final String pName) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fName = pName; - } - - @Override - public String patternName() { - return "com.incquerylabs.magicdraw.benchmark.queries.namedElement"; - } - - @Override - public List parameterNames() { - return NamedElement.Match.parameterNames; - } - - @Override - public Object[] toArray() { - return new Object[]{fElement, fName}; - } - - @Override - public NamedElement.Match toImmutable() { - return isMutable() ? newMatch(fElement, fName) : this; - } - - @Override - public String prettyPrint() { - StringBuilder result = new StringBuilder(); - result.append("\"element\"=" + prettyPrintValue(fElement) + ", "); - result.append("\"name\"=" + prettyPrintValue(fName)); - return result.toString(); - } - - @Override - public int hashCode() { - return Objects.hash(fElement, fName); - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) - return true; - if (obj == null) { - return false; - } - if ((obj instanceof NamedElement.Match)) { - NamedElement.Match other = (NamedElement.Match) obj; - return Objects.equals(fElement, other.fElement) && Objects.equals(fName, other.fName); - } else { - // this should be infrequent - if (!(obj instanceof IPatternMatch)) { - return false; - } - IPatternMatch otherSig = (IPatternMatch) obj; - return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); - } - } - - @Override - public NamedElement specification() { - return NamedElement.instance(); - } - - /** - * Returns an empty, mutable match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @return the empty match. - * - */ - public static NamedElement.Match newEmptyMatch() { - return new Mutable(null, null); - } - - /** - * Returns a mutable (partial) match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @param pElement the fixed value of pattern parameter element, or null if not bound. - * @param pName the fixed value of pattern parameter name, or null if not bound. - * @return the new, mutable (partial) match object. - * - */ - public static NamedElement.Match newMutableMatch(final com.nomagic.uml2.ext.magicdraw.classes.mdkernel.NamedElement pElement, final String pName) { - return new Mutable(pElement, pName); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pElement the fixed value of pattern parameter element, or null if not bound. - * @param pName the fixed value of pattern parameter name, or null if not bound. - * @return the (partial) match object. - * - */ - public static NamedElement.Match newMatch(final com.nomagic.uml2.ext.magicdraw.classes.mdkernel.NamedElement pElement, final String pName) { - return new Immutable(pElement, pName); - } - - private static final class Mutable extends NamedElement.Match { - Mutable(final com.nomagic.uml2.ext.magicdraw.classes.mdkernel.NamedElement pElement, final String pName) { - super(pElement, pName); - } - - @Override - public boolean isMutable() { - return true; - } - } - - private static final class Immutable extends NamedElement.Match { - Immutable(final com.nomagic.uml2.ext.magicdraw.classes.mdkernel.NamedElement pElement, final String pName) { - super(pElement, pName); - } - - @Override - public boolean isMutable() { - return false; - } - } - } - - /** - * Generated pattern matcher API of the com.incquerylabs.magicdraw.benchmark.queries.namedElement pattern, - * providing pattern-specific query methods. - * - *

Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, - * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. - * - *

Matches of the pattern will be represented as {@link Match}. - * - *

Original source: - *

-   * Querying all instances of an EClass with an attribute. 
-   *  
-   * pattern namedElement(element : NamedElement, name : java ^java.lang.String) {
-   * 	NamedElement.name(element, name);
-   * }
-   * 
- * - * @see Match - * @see NamedElement - * - */ - public static class Matcher extends BaseMatcher { - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - public static NamedElement.Matcher on(final ViatraQueryEngine engine) { - // check if matcher already exists - Matcher matcher = engine.getExistingMatcher(querySpecification()); - if (matcher == null) { - matcher = (Matcher)engine.getMatcher(querySpecification()); - } - return matcher; - } - - /** - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * @return an initialized matcher - * @noreference This method is for internal matcher initialization by the framework, do not call it manually. - * - */ - public static NamedElement.Matcher create() { - return new Matcher(); - } - - private static final int POSITION_ELEMENT = 0; - - private static final int POSITION_NAME = 1; - - private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(NamedElement.Matcher.class); - - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - private Matcher() { - super(querySpecification()); - } - - /** - * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pElement the fixed value of pattern parameter element, or null if not bound. - * @param pName the fixed value of pattern parameter name, or null if not bound. - * @return matches represented as a Match object. - * - */ - public Collection getAllMatches(final com.nomagic.uml2.ext.magicdraw.classes.mdkernel.NamedElement pElement, final String pName) { - return rawStreamAllMatches(new Object[]{pElement, pName}).collect(Collectors.toSet()); - } - - /** - * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * @param pElement the fixed value of pattern parameter element, or null if not bound. - * @param pName the fixed value of pattern parameter name, or null if not bound. - * @return a stream of matches represented as a Match object. - * - */ - public Stream streamAllMatches(final com.nomagic.uml2.ext.magicdraw.classes.mdkernel.NamedElement pElement, final String pName) { - return rawStreamAllMatches(new Object[]{pElement, pName}); - } - - /** - * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pElement the fixed value of pattern parameter element, or null if not bound. - * @param pName the fixed value of pattern parameter name, or null if not bound. - * @return a match represented as a Match object, or null if no match is found. - * - */ - public Optional getOneArbitraryMatch(final com.nomagic.uml2.ext.magicdraw.classes.mdkernel.NamedElement pElement, final String pName) { - return rawGetOneArbitraryMatch(new Object[]{pElement, pName}); - } - - /** - * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, - * under any possible substitution of the unspecified parameters (if any). - * @param pElement the fixed value of pattern parameter element, or null if not bound. - * @param pName the fixed value of pattern parameter name, or null if not bound. - * @return true if the input is a valid (partial) match of the pattern. - * - */ - public boolean hasMatch(final com.nomagic.uml2.ext.magicdraw.classes.mdkernel.NamedElement pElement, final String pName) { - return rawHasMatch(new Object[]{pElement, pName}); - } - - /** - * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pElement the fixed value of pattern parameter element, or null if not bound. - * @param pName the fixed value of pattern parameter name, or null if not bound. - * @return the number of pattern matches found. - * - */ - public int countMatches(final com.nomagic.uml2.ext.magicdraw.classes.mdkernel.NamedElement pElement, final String pName) { - return rawCountMatches(new Object[]{pElement, pName}); - } - - /** - * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pElement the fixed value of pattern parameter element, or null if not bound. - * @param pName the fixed value of pattern parameter name, or null if not bound. - * @param processor the action that will process the selected match. - * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked - * - */ - public boolean forOneArbitraryMatch(final com.nomagic.uml2.ext.magicdraw.classes.mdkernel.NamedElement pElement, final String pName, final Consumer processor) { - return rawForOneArbitraryMatch(new Object[]{pElement, pName}, processor); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pElement the fixed value of pattern parameter element, or null if not bound. - * @param pName the fixed value of pattern parameter name, or null if not bound. - * @return the (partial) match object. - * - */ - public NamedElement.Match newMatch(final com.nomagic.uml2.ext.magicdraw.classes.mdkernel.NamedElement pElement, final String pName) { - return NamedElement.Match.newMatch(pElement, pName); - } - - /** - * Retrieve the set of values that occur in matches for element. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOfelement(final Object[] parameters) { - return rawStreamAllValues(POSITION_ELEMENT, parameters).map(com.nomagic.uml2.ext.magicdraw.classes.mdkernel.NamedElement.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for element. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfelement() { - return rawStreamAllValuesOfelement(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for element. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfelement() { - return rawStreamAllValuesOfelement(emptyArray()); - } - - /** - * Retrieve the set of values that occur in matches for element. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfelement(final NamedElement.Match partialMatch) { - return rawStreamAllValuesOfelement(partialMatch.toArray()); - } - - /** - * Retrieve the set of values that occur in matches for element. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfelement(final String pName) { - return rawStreamAllValuesOfelement(new Object[]{null, pName}); - } - - /** - * Retrieve the set of values that occur in matches for element. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfelement(final NamedElement.Match partialMatch) { - return rawStreamAllValuesOfelement(partialMatch.toArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for element. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfelement(final String pName) { - return rawStreamAllValuesOfelement(new Object[]{null, pName}).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for name. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOfname(final Object[] parameters) { - return rawStreamAllValues(POSITION_NAME, parameters).map(String.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for name. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfname() { - return rawStreamAllValuesOfname(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for name. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfname() { - return rawStreamAllValuesOfname(emptyArray()); - } - - /** - * Retrieve the set of values that occur in matches for name. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfname(final NamedElement.Match partialMatch) { - return rawStreamAllValuesOfname(partialMatch.toArray()); - } - - /** - * Retrieve the set of values that occur in matches for name. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfname(final com.nomagic.uml2.ext.magicdraw.classes.mdkernel.NamedElement pElement) { - return rawStreamAllValuesOfname(new Object[]{pElement, null}); - } - - /** - * Retrieve the set of values that occur in matches for name. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfname(final NamedElement.Match partialMatch) { - return rawStreamAllValuesOfname(partialMatch.toArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for name. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfname(final com.nomagic.uml2.ext.magicdraw.classes.mdkernel.NamedElement pElement) { - return rawStreamAllValuesOfname(new Object[]{pElement, null}).collect(Collectors.toSet()); - } - - @Override - protected NamedElement.Match tupleToMatch(final Tuple t) { - try { - return NamedElement.Match.newMatch((com.nomagic.uml2.ext.magicdraw.classes.mdkernel.NamedElement) t.get(POSITION_ELEMENT), (String) t.get(POSITION_NAME)); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in tuple not properly typed!",e); - return null; - } - } - - @Override - protected NamedElement.Match arrayToMatch(final Object[] match) { - try { - return NamedElement.Match.newMatch((com.nomagic.uml2.ext.magicdraw.classes.mdkernel.NamedElement) match[POSITION_ELEMENT], (String) match[POSITION_NAME]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - @Override - protected NamedElement.Match arrayToMatchMutable(final Object[] match) { - try { - return NamedElement.Match.newMutableMatch((com.nomagic.uml2.ext.magicdraw.classes.mdkernel.NamedElement) match[POSITION_ELEMENT], (String) match[POSITION_NAME]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - /** - * @return the singleton instance of the query specification of this pattern - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static IQuerySpecification querySpecification() { - return NamedElement.instance(); - } - } - - private NamedElement() { - super(GeneratedPQuery.INSTANCE); - } - - /** - * @return the singleton instance of the query specification - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static NamedElement instance() { - try{ - return LazyHolder.INSTANCE; - } catch (ExceptionInInitializerError err) { - throw processInitializerError(err); - } - } - - @Override - protected NamedElement.Matcher instantiate(final ViatraQueryEngine engine) { - return NamedElement.Matcher.on(engine); - } - - @Override - public NamedElement.Matcher instantiate() { - return NamedElement.Matcher.create(); - } - - @Override - public NamedElement.Match newEmptyMatch() { - return NamedElement.Match.newEmptyMatch(); - } - - @Override - public NamedElement.Match newMatch(final Object... parameters) { - return NamedElement.Match.newMatch((com.nomagic.uml2.ext.magicdraw.classes.mdkernel.NamedElement) parameters[0], (java.lang.String) parameters[1]); - } - - /** - * Inner class allowing the singleton instance of {@link NamedElement} to be created - * not at the class load time of the outer class, - * but rather at the first call to {@link NamedElement#instance()}. - * - *

This workaround is required e.g. to support recursion. - * - */ - private static class LazyHolder { - private static final NamedElement INSTANCE = new NamedElement(); - - /** - * Statically initializes the query specification after the field {@link #INSTANCE} is assigned. - * This initialization order is required to support indirect recursion. - * - *

The static initializer is defined using a helper field to work around limitations of the code generator. - * - */ - private static final Object STATIC_INITIALIZER = ensureInitialized(); - - public static Object ensureInitialized() { - INSTANCE.ensureInitializedInternal(); - return null; - } - } - - private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { - private static final NamedElement.GeneratedPQuery INSTANCE = new GeneratedPQuery(); - - private final PParameter parameter_element = new PParameter("element", "com.nomagic.uml2.ext.magicdraw.classes.mdkernel.NamedElement", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.nomagic.com/magicdraw/UML/2.5.1", "NamedElement")), PParameterDirection.INOUT); - - private final PParameter parameter_name = new PParameter("name", "java.lang.String", new JavaTransitiveInstancesKey(java.lang.String.class), PParameterDirection.INOUT); - - private final List parameters = Arrays.asList(parameter_element, parameter_name); - - private GeneratedPQuery() { - super(PVisibility.PUBLIC); - } - - @Override - public String getFullyQualifiedName() { - return "com.incquerylabs.magicdraw.benchmark.queries.namedElement"; - } - - @Override - public List getParameterNames() { - return Arrays.asList("element","name"); - } - - @Override - public List getParameters() { - return parameters; - } - - @Override - public Set doGetContainedBodies() { - setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); - Set bodies = new LinkedHashSet<>(); - { - PBody body = new PBody(this); - PVariable var_element = body.getOrCreateVariableByName("element"); - PVariable var_name = body.getOrCreateVariableByName("name"); - new TypeConstraint(body, Tuples.flatTupleOf(var_element), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "NamedElement"))); - new TypeFilterConstraint(body, Tuples.flatTupleOf(var_name), new JavaTransitiveInstancesKey(java.lang.String.class)); - body.setSymbolicParameters(Arrays.asList( - new ExportedParameter(body, var_element, parameter_element), - new ExportedParameter(body, var_name, parameter_name) - )); - // NamedElement.name(element, name) - new TypeConstraint(body, Tuples.flatTupleOf(var_element), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "NamedElement"))); - PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_element, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "NamedElement", "name"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "String"))); - new Equality(body, var__virtual_0_, var_name); - bodies.add(body); - } - return bodies; - } - } -} diff --git a/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/NamesOfDependencyEndpoints.java b/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/NamesOfDependencyEndpoints.java deleted file mode 100644 index 07d5239..0000000 --- a/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/NamesOfDependencyEndpoints.java +++ /dev/null @@ -1,942 +0,0 @@ -/** - * Generated from platform:/resource/com.incquerylabs.magicdraw.benchmark/src/main/java/com/incquerylabs/magicdraw/benchmark/queries/APerformanceQueries.vql - */ -package com.incquerylabs.magicdraw.benchmark.queries; - -import com.incquerylabs.magicdraw.benchmark.queries.Dependencies; -import com.nomagic.uml2.ext.magicdraw.classes.mdkernel.NamedElement; -import java.util.Arrays; -import java.util.Collection; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.function.Consumer; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import org.apache.log4j.Logger; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.emf.ecore.EDataType; -import org.eclipse.viatra.query.runtime.api.IPatternMatch; -import org.eclipse.viatra.query.runtime.api.IQuerySpecification; -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.api.impl.BaseMatcher; -import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; -import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; -import org.eclipse.viatra.query.runtime.emf.types.EDataTypeInSlotsKey; -import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey; -import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; -import org.eclipse.viatra.query.runtime.matchers.context.common.JavaTransitiveInstancesKey; -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.TypeFilterConstraint; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.PositivePatternCall; -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.PVisibility; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; -import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; - -/** - * A pattern-specific query specification that can instantiate Matcher in a type-safe way. - * - *

Original source: - *

- *         Reusing the dependency pattern and querying simple attributes.
- *          
- *         pattern namesOfDependencyEndpoints(source : NamedElement, sourceName : java ^java.lang.String, target : NamedElement, targetName : java ^java.lang.String) {
- *         	find dependencies(source, target);
- *         	NamedElement.name(source, sourceName);
- *         	NamedElement.name(target, targetName);
- *         }
- * 
- * - * @see Matcher - * @see Match - * - */ -@SuppressWarnings("all") -public final class NamesOfDependencyEndpoints extends BaseGeneratedEMFQuerySpecification { - /** - * Pattern-specific match representation of the com.incquerylabs.magicdraw.benchmark.queries.namesOfDependencyEndpoints pattern, - * to be used in conjunction with {@link Matcher}. - * - *

Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. - * Each instance is a (possibly partial) substitution of pattern parameters, - * usable to represent a match of the pattern in the result of a query, - * or to specify the bound (fixed) input parameters when issuing a query. - * - * @see Matcher - * - */ - public static abstract class Match extends BasePatternMatch { - private NamedElement fSource; - - private String fSourceName; - - private NamedElement fTarget; - - private String fTargetName; - - private static List parameterNames = makeImmutableList("source", "sourceName", "target", "targetName"); - - private Match(final NamedElement pSource, final String pSourceName, final NamedElement pTarget, final String pTargetName) { - this.fSource = pSource; - this.fSourceName = pSourceName; - this.fTarget = pTarget; - this.fTargetName = pTargetName; - } - - @Override - public Object get(final String parameterName) { - switch(parameterName) { - case "source": return this.fSource; - case "sourceName": return this.fSourceName; - case "target": return this.fTarget; - case "targetName": return this.fTargetName; - default: return null; - } - } - - @Override - public Object get(final int index) { - switch(index) { - case 0: return this.fSource; - case 1: return this.fSourceName; - case 2: return this.fTarget; - case 3: return this.fTargetName; - default: return null; - } - } - - public NamedElement getSource() { - return this.fSource; - } - - public String getSourceName() { - return this.fSourceName; - } - - public NamedElement getTarget() { - return this.fTarget; - } - - public String getTargetName() { - return this.fTargetName; - } - - @Override - public boolean set(final String parameterName, final Object newValue) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - if ("source".equals(parameterName) ) { - this.fSource = (NamedElement) newValue; - return true; - } - if ("sourceName".equals(parameterName) ) { - this.fSourceName = (String) newValue; - return true; - } - if ("target".equals(parameterName) ) { - this.fTarget = (NamedElement) newValue; - return true; - } - if ("targetName".equals(parameterName) ) { - this.fTargetName = (String) newValue; - return true; - } - return false; - } - - public void setSource(final NamedElement pSource) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fSource = pSource; - } - - public void setSourceName(final String pSourceName) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fSourceName = pSourceName; - } - - public void setTarget(final NamedElement pTarget) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fTarget = pTarget; - } - - public void setTargetName(final String pTargetName) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fTargetName = pTargetName; - } - - @Override - public String patternName() { - return "com.incquerylabs.magicdraw.benchmark.queries.namesOfDependencyEndpoints"; - } - - @Override - public List parameterNames() { - return NamesOfDependencyEndpoints.Match.parameterNames; - } - - @Override - public Object[] toArray() { - return new Object[]{fSource, fSourceName, fTarget, fTargetName}; - } - - @Override - public NamesOfDependencyEndpoints.Match toImmutable() { - return isMutable() ? newMatch(fSource, fSourceName, fTarget, fTargetName) : this; - } - - @Override - public String prettyPrint() { - StringBuilder result = new StringBuilder(); - result.append("\"source\"=" + prettyPrintValue(fSource) + ", "); - result.append("\"sourceName\"=" + prettyPrintValue(fSourceName) + ", "); - result.append("\"target\"=" + prettyPrintValue(fTarget) + ", "); - result.append("\"targetName\"=" + prettyPrintValue(fTargetName)); - return result.toString(); - } - - @Override - public int hashCode() { - return Objects.hash(fSource, fSourceName, fTarget, fTargetName); - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) - return true; - if (obj == null) { - return false; - } - if ((obj instanceof NamesOfDependencyEndpoints.Match)) { - NamesOfDependencyEndpoints.Match other = (NamesOfDependencyEndpoints.Match) obj; - return Objects.equals(fSource, other.fSource) && Objects.equals(fSourceName, other.fSourceName) && Objects.equals(fTarget, other.fTarget) && Objects.equals(fTargetName, other.fTargetName); - } else { - // this should be infrequent - if (!(obj instanceof IPatternMatch)) { - return false; - } - IPatternMatch otherSig = (IPatternMatch) obj; - return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); - } - } - - @Override - public NamesOfDependencyEndpoints specification() { - return NamesOfDependencyEndpoints.instance(); - } - - /** - * Returns an empty, mutable match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @return the empty match. - * - */ - public static NamesOfDependencyEndpoints.Match newEmptyMatch() { - return new Mutable(null, null, null, null); - } - - /** - * Returns a mutable (partial) match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @param pSource the fixed value of pattern parameter source, or null if not bound. - * @param pSourceName the fixed value of pattern parameter sourceName, or null if not bound. - * @param pTarget the fixed value of pattern parameter target, or null if not bound. - * @param pTargetName the fixed value of pattern parameter targetName, or null if not bound. - * @return the new, mutable (partial) match object. - * - */ - public static NamesOfDependencyEndpoints.Match newMutableMatch(final NamedElement pSource, final String pSourceName, final NamedElement pTarget, final String pTargetName) { - return new Mutable(pSource, pSourceName, pTarget, pTargetName); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pSource the fixed value of pattern parameter source, or null if not bound. - * @param pSourceName the fixed value of pattern parameter sourceName, or null if not bound. - * @param pTarget the fixed value of pattern parameter target, or null if not bound. - * @param pTargetName the fixed value of pattern parameter targetName, or null if not bound. - * @return the (partial) match object. - * - */ - public static NamesOfDependencyEndpoints.Match newMatch(final NamedElement pSource, final String pSourceName, final NamedElement pTarget, final String pTargetName) { - return new Immutable(pSource, pSourceName, pTarget, pTargetName); - } - - private static final class Mutable extends NamesOfDependencyEndpoints.Match { - Mutable(final NamedElement pSource, final String pSourceName, final NamedElement pTarget, final String pTargetName) { - super(pSource, pSourceName, pTarget, pTargetName); - } - - @Override - public boolean isMutable() { - return true; - } - } - - private static final class Immutable extends NamesOfDependencyEndpoints.Match { - Immutable(final NamedElement pSource, final String pSourceName, final NamedElement pTarget, final String pTargetName) { - super(pSource, pSourceName, pTarget, pTargetName); - } - - @Override - public boolean isMutable() { - return false; - } - } - } - - /** - * Generated pattern matcher API of the com.incquerylabs.magicdraw.benchmark.queries.namesOfDependencyEndpoints pattern, - * providing pattern-specific query methods. - * - *

Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, - * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. - * - *

Matches of the pattern will be represented as {@link Match}. - * - *

Original source: - *

-   * Reusing the dependency pattern and querying simple attributes.
-   *  
-   * pattern namesOfDependencyEndpoints(source : NamedElement, sourceName : java ^java.lang.String, target : NamedElement, targetName : java ^java.lang.String) {
-   * 	find dependencies(source, target);
-   * 	NamedElement.name(source, sourceName);
-   * 	NamedElement.name(target, targetName);
-   * }
-   * 
- * - * @see Match - * @see NamesOfDependencyEndpoints - * - */ - public static class Matcher extends BaseMatcher { - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - public static NamesOfDependencyEndpoints.Matcher on(final ViatraQueryEngine engine) { - // check if matcher already exists - Matcher matcher = engine.getExistingMatcher(querySpecification()); - if (matcher == null) { - matcher = (Matcher)engine.getMatcher(querySpecification()); - } - return matcher; - } - - /** - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * @return an initialized matcher - * @noreference This method is for internal matcher initialization by the framework, do not call it manually. - * - */ - public static NamesOfDependencyEndpoints.Matcher create() { - return new Matcher(); - } - - private static final int POSITION_SOURCE = 0; - - private static final int POSITION_SOURCENAME = 1; - - private static final int POSITION_TARGET = 2; - - private static final int POSITION_TARGETNAME = 3; - - private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(NamesOfDependencyEndpoints.Matcher.class); - - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - private Matcher() { - super(querySpecification()); - } - - /** - * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pSource the fixed value of pattern parameter source, or null if not bound. - * @param pSourceName the fixed value of pattern parameter sourceName, or null if not bound. - * @param pTarget the fixed value of pattern parameter target, or null if not bound. - * @param pTargetName the fixed value of pattern parameter targetName, or null if not bound. - * @return matches represented as a Match object. - * - */ - public Collection getAllMatches(final NamedElement pSource, final String pSourceName, final NamedElement pTarget, final String pTargetName) { - return rawStreamAllMatches(new Object[]{pSource, pSourceName, pTarget, pTargetName}).collect(Collectors.toSet()); - } - - /** - * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * @param pSource the fixed value of pattern parameter source, or null if not bound. - * @param pSourceName the fixed value of pattern parameter sourceName, or null if not bound. - * @param pTarget the fixed value of pattern parameter target, or null if not bound. - * @param pTargetName the fixed value of pattern parameter targetName, or null if not bound. - * @return a stream of matches represented as a Match object. - * - */ - public Stream streamAllMatches(final NamedElement pSource, final String pSourceName, final NamedElement pTarget, final String pTargetName) { - return rawStreamAllMatches(new Object[]{pSource, pSourceName, pTarget, pTargetName}); - } - - /** - * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pSource the fixed value of pattern parameter source, or null if not bound. - * @param pSourceName the fixed value of pattern parameter sourceName, or null if not bound. - * @param pTarget the fixed value of pattern parameter target, or null if not bound. - * @param pTargetName the fixed value of pattern parameter targetName, or null if not bound. - * @return a match represented as a Match object, or null if no match is found. - * - */ - public Optional getOneArbitraryMatch(final NamedElement pSource, final String pSourceName, final NamedElement pTarget, final String pTargetName) { - return rawGetOneArbitraryMatch(new Object[]{pSource, pSourceName, pTarget, pTargetName}); - } - - /** - * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, - * under any possible substitution of the unspecified parameters (if any). - * @param pSource the fixed value of pattern parameter source, or null if not bound. - * @param pSourceName the fixed value of pattern parameter sourceName, or null if not bound. - * @param pTarget the fixed value of pattern parameter target, or null if not bound. - * @param pTargetName the fixed value of pattern parameter targetName, or null if not bound. - * @return true if the input is a valid (partial) match of the pattern. - * - */ - public boolean hasMatch(final NamedElement pSource, final String pSourceName, final NamedElement pTarget, final String pTargetName) { - return rawHasMatch(new Object[]{pSource, pSourceName, pTarget, pTargetName}); - } - - /** - * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pSource the fixed value of pattern parameter source, or null if not bound. - * @param pSourceName the fixed value of pattern parameter sourceName, or null if not bound. - * @param pTarget the fixed value of pattern parameter target, or null if not bound. - * @param pTargetName the fixed value of pattern parameter targetName, or null if not bound. - * @return the number of pattern matches found. - * - */ - public int countMatches(final NamedElement pSource, final String pSourceName, final NamedElement pTarget, final String pTargetName) { - return rawCountMatches(new Object[]{pSource, pSourceName, pTarget, pTargetName}); - } - - /** - * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pSource the fixed value of pattern parameter source, or null if not bound. - * @param pSourceName the fixed value of pattern parameter sourceName, or null if not bound. - * @param pTarget the fixed value of pattern parameter target, or null if not bound. - * @param pTargetName the fixed value of pattern parameter targetName, or null if not bound. - * @param processor the action that will process the selected match. - * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked - * - */ - public boolean forOneArbitraryMatch(final NamedElement pSource, final String pSourceName, final NamedElement pTarget, final String pTargetName, final Consumer processor) { - return rawForOneArbitraryMatch(new Object[]{pSource, pSourceName, pTarget, pTargetName}, processor); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pSource the fixed value of pattern parameter source, or null if not bound. - * @param pSourceName the fixed value of pattern parameter sourceName, or null if not bound. - * @param pTarget the fixed value of pattern parameter target, or null if not bound. - * @param pTargetName the fixed value of pattern parameter targetName, or null if not bound. - * @return the (partial) match object. - * - */ - public NamesOfDependencyEndpoints.Match newMatch(final NamedElement pSource, final String pSourceName, final NamedElement pTarget, final String pTargetName) { - return NamesOfDependencyEndpoints.Match.newMatch(pSource, pSourceName, pTarget, pTargetName); - } - - /** - * Retrieve the set of values that occur in matches for source. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOfsource(final Object[] parameters) { - return rawStreamAllValues(POSITION_SOURCE, parameters).map(NamedElement.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for source. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfsource() { - return rawStreamAllValuesOfsource(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for source. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfsource() { - return rawStreamAllValuesOfsource(emptyArray()); - } - - /** - * Retrieve the set of values that occur in matches for source. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfsource(final NamesOfDependencyEndpoints.Match partialMatch) { - return rawStreamAllValuesOfsource(partialMatch.toArray()); - } - - /** - * Retrieve the set of values that occur in matches for source. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfsource(final String pSourceName, final NamedElement pTarget, final String pTargetName) { - return rawStreamAllValuesOfsource(new Object[]{null, pSourceName, pTarget, pTargetName}); - } - - /** - * Retrieve the set of values that occur in matches for source. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfsource(final NamesOfDependencyEndpoints.Match partialMatch) { - return rawStreamAllValuesOfsource(partialMatch.toArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for source. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfsource(final String pSourceName, final NamedElement pTarget, final String pTargetName) { - return rawStreamAllValuesOfsource(new Object[]{null, pSourceName, pTarget, pTargetName}).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for sourceName. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOfsourceName(final Object[] parameters) { - return rawStreamAllValues(POSITION_SOURCENAME, parameters).map(String.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for sourceName. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfsourceName() { - return rawStreamAllValuesOfsourceName(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for sourceName. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfsourceName() { - return rawStreamAllValuesOfsourceName(emptyArray()); - } - - /** - * Retrieve the set of values that occur in matches for sourceName. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfsourceName(final NamesOfDependencyEndpoints.Match partialMatch) { - return rawStreamAllValuesOfsourceName(partialMatch.toArray()); - } - - /** - * Retrieve the set of values that occur in matches for sourceName. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfsourceName(final NamedElement pSource, final NamedElement pTarget, final String pTargetName) { - return rawStreamAllValuesOfsourceName(new Object[]{pSource, null, pTarget, pTargetName}); - } - - /** - * Retrieve the set of values that occur in matches for sourceName. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfsourceName(final NamesOfDependencyEndpoints.Match partialMatch) { - return rawStreamAllValuesOfsourceName(partialMatch.toArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for sourceName. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfsourceName(final NamedElement pSource, final NamedElement pTarget, final String pTargetName) { - return rawStreamAllValuesOfsourceName(new Object[]{pSource, null, pTarget, pTargetName}).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for target. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOftarget(final Object[] parameters) { - return rawStreamAllValues(POSITION_TARGET, parameters).map(NamedElement.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for target. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOftarget() { - return rawStreamAllValuesOftarget(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for target. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOftarget() { - return rawStreamAllValuesOftarget(emptyArray()); - } - - /** - * Retrieve the set of values that occur in matches for target. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOftarget(final NamesOfDependencyEndpoints.Match partialMatch) { - return rawStreamAllValuesOftarget(partialMatch.toArray()); - } - - /** - * Retrieve the set of values that occur in matches for target. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOftarget(final NamedElement pSource, final String pSourceName, final String pTargetName) { - return rawStreamAllValuesOftarget(new Object[]{pSource, pSourceName, null, pTargetName}); - } - - /** - * Retrieve the set of values that occur in matches for target. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOftarget(final NamesOfDependencyEndpoints.Match partialMatch) { - return rawStreamAllValuesOftarget(partialMatch.toArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for target. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOftarget(final NamedElement pSource, final String pSourceName, final String pTargetName) { - return rawStreamAllValuesOftarget(new Object[]{pSource, pSourceName, null, pTargetName}).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for targetName. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOftargetName(final Object[] parameters) { - return rawStreamAllValues(POSITION_TARGETNAME, parameters).map(String.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for targetName. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOftargetName() { - return rawStreamAllValuesOftargetName(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for targetName. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOftargetName() { - return rawStreamAllValuesOftargetName(emptyArray()); - } - - /** - * Retrieve the set of values that occur in matches for targetName. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOftargetName(final NamesOfDependencyEndpoints.Match partialMatch) { - return rawStreamAllValuesOftargetName(partialMatch.toArray()); - } - - /** - * Retrieve the set of values that occur in matches for targetName. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOftargetName(final NamedElement pSource, final String pSourceName, final NamedElement pTarget) { - return rawStreamAllValuesOftargetName(new Object[]{pSource, pSourceName, pTarget, null}); - } - - /** - * Retrieve the set of values that occur in matches for targetName. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOftargetName(final NamesOfDependencyEndpoints.Match partialMatch) { - return rawStreamAllValuesOftargetName(partialMatch.toArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for targetName. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOftargetName(final NamedElement pSource, final String pSourceName, final NamedElement pTarget) { - return rawStreamAllValuesOftargetName(new Object[]{pSource, pSourceName, pTarget, null}).collect(Collectors.toSet()); - } - - @Override - protected NamesOfDependencyEndpoints.Match tupleToMatch(final Tuple t) { - try { - return NamesOfDependencyEndpoints.Match.newMatch((NamedElement) t.get(POSITION_SOURCE), (String) t.get(POSITION_SOURCENAME), (NamedElement) t.get(POSITION_TARGET), (String) t.get(POSITION_TARGETNAME)); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in tuple not properly typed!",e); - return null; - } - } - - @Override - protected NamesOfDependencyEndpoints.Match arrayToMatch(final Object[] match) { - try { - return NamesOfDependencyEndpoints.Match.newMatch((NamedElement) match[POSITION_SOURCE], (String) match[POSITION_SOURCENAME], (NamedElement) match[POSITION_TARGET], (String) match[POSITION_TARGETNAME]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - @Override - protected NamesOfDependencyEndpoints.Match arrayToMatchMutable(final Object[] match) { - try { - return NamesOfDependencyEndpoints.Match.newMutableMatch((NamedElement) match[POSITION_SOURCE], (String) match[POSITION_SOURCENAME], (NamedElement) match[POSITION_TARGET], (String) match[POSITION_TARGETNAME]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - /** - * @return the singleton instance of the query specification of this pattern - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static IQuerySpecification querySpecification() { - return NamesOfDependencyEndpoints.instance(); - } - } - - private NamesOfDependencyEndpoints() { - super(GeneratedPQuery.INSTANCE); - } - - /** - * @return the singleton instance of the query specification - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static NamesOfDependencyEndpoints instance() { - try{ - return LazyHolder.INSTANCE; - } catch (ExceptionInInitializerError err) { - throw processInitializerError(err); - } - } - - @Override - protected NamesOfDependencyEndpoints.Matcher instantiate(final ViatraQueryEngine engine) { - return NamesOfDependencyEndpoints.Matcher.on(engine); - } - - @Override - public NamesOfDependencyEndpoints.Matcher instantiate() { - return NamesOfDependencyEndpoints.Matcher.create(); - } - - @Override - public NamesOfDependencyEndpoints.Match newEmptyMatch() { - return NamesOfDependencyEndpoints.Match.newEmptyMatch(); - } - - @Override - public NamesOfDependencyEndpoints.Match newMatch(final Object... parameters) { - return NamesOfDependencyEndpoints.Match.newMatch((com.nomagic.uml2.ext.magicdraw.classes.mdkernel.NamedElement) parameters[0], (java.lang.String) parameters[1], (com.nomagic.uml2.ext.magicdraw.classes.mdkernel.NamedElement) parameters[2], (java.lang.String) parameters[3]); - } - - /** - * Inner class allowing the singleton instance of {@link NamesOfDependencyEndpoints} to be created - * not at the class load time of the outer class, - * but rather at the first call to {@link NamesOfDependencyEndpoints#instance()}. - * - *

This workaround is required e.g. to support recursion. - * - */ - private static class LazyHolder { - private static final NamesOfDependencyEndpoints INSTANCE = new NamesOfDependencyEndpoints(); - - /** - * Statically initializes the query specification after the field {@link #INSTANCE} is assigned. - * This initialization order is required to support indirect recursion. - * - *

The static initializer is defined using a helper field to work around limitations of the code generator. - * - */ - private static final Object STATIC_INITIALIZER = ensureInitialized(); - - public static Object ensureInitialized() { - INSTANCE.ensureInitializedInternal(); - return null; - } - } - - private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { - private static final NamesOfDependencyEndpoints.GeneratedPQuery INSTANCE = new GeneratedPQuery(); - - private final PParameter parameter_source = new PParameter("source", "com.nomagic.uml2.ext.magicdraw.classes.mdkernel.NamedElement", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.nomagic.com/magicdraw/UML/2.5.1", "NamedElement")), PParameterDirection.INOUT); - - private final PParameter parameter_sourceName = new PParameter("sourceName", "java.lang.String", new JavaTransitiveInstancesKey(java.lang.String.class), PParameterDirection.INOUT); - - private final PParameter parameter_target = new PParameter("target", "com.nomagic.uml2.ext.magicdraw.classes.mdkernel.NamedElement", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.nomagic.com/magicdraw/UML/2.5.1", "NamedElement")), PParameterDirection.INOUT); - - private final PParameter parameter_targetName = new PParameter("targetName", "java.lang.String", new JavaTransitiveInstancesKey(java.lang.String.class), PParameterDirection.INOUT); - - private final List parameters = Arrays.asList(parameter_source, parameter_sourceName, parameter_target, parameter_targetName); - - private GeneratedPQuery() { - super(PVisibility.PUBLIC); - } - - @Override - public String getFullyQualifiedName() { - return "com.incquerylabs.magicdraw.benchmark.queries.namesOfDependencyEndpoints"; - } - - @Override - public List getParameterNames() { - return Arrays.asList("source","sourceName","target","targetName"); - } - - @Override - public List getParameters() { - return parameters; - } - - @Override - public Set doGetContainedBodies() { - setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); - Set bodies = new LinkedHashSet<>(); - { - PBody body = new PBody(this); - PVariable var_source = body.getOrCreateVariableByName("source"); - PVariable var_sourceName = body.getOrCreateVariableByName("sourceName"); - PVariable var_target = body.getOrCreateVariableByName("target"); - PVariable var_targetName = body.getOrCreateVariableByName("targetName"); - new TypeConstraint(body, Tuples.flatTupleOf(var_source), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "NamedElement"))); - new TypeFilterConstraint(body, Tuples.flatTupleOf(var_sourceName), new JavaTransitiveInstancesKey(java.lang.String.class)); - new TypeConstraint(body, Tuples.flatTupleOf(var_target), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "NamedElement"))); - new TypeFilterConstraint(body, Tuples.flatTupleOf(var_targetName), new JavaTransitiveInstancesKey(java.lang.String.class)); - body.setSymbolicParameters(Arrays.asList( - new ExportedParameter(body, var_source, parameter_source), - new ExportedParameter(body, var_sourceName, parameter_sourceName), - new ExportedParameter(body, var_target, parameter_target), - new ExportedParameter(body, var_targetName, parameter_targetName) - )); - // find dependencies(source, target) - new PositivePatternCall(body, Tuples.flatTupleOf(var_source, var_target), Dependencies.instance().getInternalQueryRepresentation()); - // NamedElement.name(source, sourceName) - new TypeConstraint(body, Tuples.flatTupleOf(var_source), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "NamedElement"))); - PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_source, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "NamedElement", "name"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "String"))); - new Equality(body, var__virtual_0_, var_sourceName); - // NamedElement.name(target, targetName) - new TypeConstraint(body, Tuples.flatTupleOf(var_target), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "NamedElement"))); - PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_target, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "NamedElement", "name"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "String"))); - new Equality(body, var__virtual_1_, var_targetName); - bodies.add(body); - } - return bodies; - } - } -} diff --git a/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/NonBlockClasses.java b/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/NonBlockClasses.java deleted file mode 100644 index 919b07a..0000000 --- a/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/NonBlockClasses.java +++ /dev/null @@ -1,549 +0,0 @@ -/** - * Generated from platform:/resource/com.incquerylabs.magicdraw.benchmark/src/main/java/com/incquerylabs/magicdraw/benchmark/queries/APerformanceQueries.vql - */ -package com.incquerylabs.magicdraw.benchmark.queries; - -import com.incquerylabs.magicdraw.benchmark.queries.Blocks; -import java.util.Arrays; -import java.util.Collection; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.function.Consumer; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import org.apache.log4j.Logger; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.viatra.query.runtime.api.IPatternMatch; -import org.eclipse.viatra.query.runtime.api.IQuerySpecification; -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.api.impl.BaseMatcher; -import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; -import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; -import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; -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.ExportedParameter; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.NegativePatternCall; -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.PVisibility; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; -import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; - -/** - * A pattern-specific query specification that can instantiate Matcher in a type-safe way. - * - *

Original source: - *

- *         Querying elements that are not the specified type: single negation.
- *          
- *         pattern nonBlockClasses(class : Class) {
- *         	neg find blocks(class);
- *         }
- * 
- * - * @see Matcher - * @see Match - * - */ -@SuppressWarnings("all") -public final class NonBlockClasses extends BaseGeneratedEMFQuerySpecification { - /** - * Pattern-specific match representation of the com.incquerylabs.magicdraw.benchmark.queries.nonBlockClasses pattern, - * to be used in conjunction with {@link Matcher}. - * - *

Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. - * Each instance is a (possibly partial) substitution of pattern parameters, - * usable to represent a match of the pattern in the result of a query, - * or to specify the bound (fixed) input parameters when issuing a query. - * - * @see Matcher - * - */ - public static abstract class Match extends BasePatternMatch { - private com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class fClass; - - private static List parameterNames = makeImmutableList("class"); - - private Match(final com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class pClass) { - this.fClass = pClass; - } - - @Override - public Object get(final String parameterName) { - switch(parameterName) { - case "class": return this.fClass; - default: return null; - } - } - - @Override - public Object get(final int index) { - switch(index) { - case 0: return this.fClass; - default: return null; - } - } - - public com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class getValueOfClass() { - return this.fClass; - } - - @Override - public boolean set(final String parameterName, final Object newValue) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - if ("class".equals(parameterName) ) { - this.fClass = (com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class) newValue; - return true; - } - return false; - } - - public void setClass(final com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class pClass) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fClass = pClass; - } - - @Override - public String patternName() { - return "com.incquerylabs.magicdraw.benchmark.queries.nonBlockClasses"; - } - - @Override - public List parameterNames() { - return NonBlockClasses.Match.parameterNames; - } - - @Override - public Object[] toArray() { - return new Object[]{fClass}; - } - - @Override - public NonBlockClasses.Match toImmutable() { - return isMutable() ? newMatch(fClass) : this; - } - - @Override - public String prettyPrint() { - StringBuilder result = new StringBuilder(); - result.append("\"class\"=" + prettyPrintValue(fClass)); - return result.toString(); - } - - @Override - public int hashCode() { - return Objects.hash(fClass); - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) - return true; - if (obj == null) { - return false; - } - if ((obj instanceof NonBlockClasses.Match)) { - NonBlockClasses.Match other = (NonBlockClasses.Match) obj; - return Objects.equals(fClass, other.fClass); - } else { - // this should be infrequent - if (!(obj instanceof IPatternMatch)) { - return false; - } - IPatternMatch otherSig = (IPatternMatch) obj; - return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); - } - } - - @Override - public NonBlockClasses specification() { - return NonBlockClasses.instance(); - } - - /** - * Returns an empty, mutable match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @return the empty match. - * - */ - public static NonBlockClasses.Match newEmptyMatch() { - return new Mutable(null); - } - - /** - * Returns a mutable (partial) match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @param pClass the fixed value of pattern parameter class, or null if not bound. - * @return the new, mutable (partial) match object. - * - */ - public static NonBlockClasses.Match newMutableMatch(final com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class pClass) { - return new Mutable(pClass); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pClass the fixed value of pattern parameter class, or null if not bound. - * @return the (partial) match object. - * - */ - public static NonBlockClasses.Match newMatch(final com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class pClass) { - return new Immutable(pClass); - } - - private static final class Mutable extends NonBlockClasses.Match { - Mutable(final com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class pClass) { - super(pClass); - } - - @Override - public boolean isMutable() { - return true; - } - } - - private static final class Immutable extends NonBlockClasses.Match { - Immutable(final com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class pClass) { - super(pClass); - } - - @Override - public boolean isMutable() { - return false; - } - } - } - - /** - * Generated pattern matcher API of the com.incquerylabs.magicdraw.benchmark.queries.nonBlockClasses pattern, - * providing pattern-specific query methods. - * - *

Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, - * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. - * - *

Matches of the pattern will be represented as {@link Match}. - * - *

Original source: - *

-   * Querying elements that are not the specified type: single negation.
-   *  
-   * pattern nonBlockClasses(class : Class) {
-   * 	neg find blocks(class);
-   * }
-   * 
- * - * @see Match - * @see NonBlockClasses - * - */ - public static class Matcher extends BaseMatcher { - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - public static NonBlockClasses.Matcher on(final ViatraQueryEngine engine) { - // check if matcher already exists - Matcher matcher = engine.getExistingMatcher(querySpecification()); - if (matcher == null) { - matcher = (Matcher)engine.getMatcher(querySpecification()); - } - return matcher; - } - - /** - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * @return an initialized matcher - * @noreference This method is for internal matcher initialization by the framework, do not call it manually. - * - */ - public static NonBlockClasses.Matcher create() { - return new Matcher(); - } - - private static final int POSITION_CLASS = 0; - - private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(NonBlockClasses.Matcher.class); - - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - private Matcher() { - super(querySpecification()); - } - - /** - * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pClass the fixed value of pattern parameter class, or null if not bound. - * @return matches represented as a Match object. - * - */ - public Collection getAllMatches(final com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class pClass) { - return rawStreamAllMatches(new Object[]{pClass}).collect(Collectors.toSet()); - } - - /** - * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * @param pClass the fixed value of pattern parameter class, or null if not bound. - * @return a stream of matches represented as a Match object. - * - */ - public Stream streamAllMatches(final com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class pClass) { - return rawStreamAllMatches(new Object[]{pClass}); - } - - /** - * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pClass the fixed value of pattern parameter class, or null if not bound. - * @return a match represented as a Match object, or null if no match is found. - * - */ - public Optional getOneArbitraryMatch(final com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class pClass) { - return rawGetOneArbitraryMatch(new Object[]{pClass}); - } - - /** - * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, - * under any possible substitution of the unspecified parameters (if any). - * @param pClass the fixed value of pattern parameter class, or null if not bound. - * @return true if the input is a valid (partial) match of the pattern. - * - */ - public boolean hasMatch(final com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class pClass) { - return rawHasMatch(new Object[]{pClass}); - } - - /** - * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pClass the fixed value of pattern parameter class, or null if not bound. - * @return the number of pattern matches found. - * - */ - public int countMatches(final com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class pClass) { - return rawCountMatches(new Object[]{pClass}); - } - - /** - * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pClass the fixed value of pattern parameter class, or null if not bound. - * @param processor the action that will process the selected match. - * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked - * - */ - public boolean forOneArbitraryMatch(final com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class pClass, final Consumer processor) { - return rawForOneArbitraryMatch(new Object[]{pClass}, processor); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pClass the fixed value of pattern parameter class, or null if not bound. - * @return the (partial) match object. - * - */ - public NonBlockClasses.Match newMatch(final com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class pClass) { - return NonBlockClasses.Match.newMatch(pClass); - } - - /** - * Retrieve the set of values that occur in matches for class. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOfclass(final Object[] parameters) { - return rawStreamAllValues(POSITION_CLASS, parameters).map(com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for class. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfclass() { - return rawStreamAllValuesOfclass(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for class. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfclass() { - return rawStreamAllValuesOfclass(emptyArray()); - } - - @Override - protected NonBlockClasses.Match tupleToMatch(final Tuple t) { - try { - return NonBlockClasses.Match.newMatch((com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class) t.get(POSITION_CLASS)); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in tuple not properly typed!",e); - return null; - } - } - - @Override - protected NonBlockClasses.Match arrayToMatch(final Object[] match) { - try { - return NonBlockClasses.Match.newMatch((com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class) match[POSITION_CLASS]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - @Override - protected NonBlockClasses.Match arrayToMatchMutable(final Object[] match) { - try { - return NonBlockClasses.Match.newMutableMatch((com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class) match[POSITION_CLASS]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - /** - * @return the singleton instance of the query specification of this pattern - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static IQuerySpecification querySpecification() { - return NonBlockClasses.instance(); - } - } - - private NonBlockClasses() { - super(GeneratedPQuery.INSTANCE); - } - - /** - * @return the singleton instance of the query specification - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static NonBlockClasses instance() { - try{ - return LazyHolder.INSTANCE; - } catch (ExceptionInInitializerError err) { - throw processInitializerError(err); - } - } - - @Override - protected NonBlockClasses.Matcher instantiate(final ViatraQueryEngine engine) { - return NonBlockClasses.Matcher.on(engine); - } - - @Override - public NonBlockClasses.Matcher instantiate() { - return NonBlockClasses.Matcher.create(); - } - - @Override - public NonBlockClasses.Match newEmptyMatch() { - return NonBlockClasses.Match.newEmptyMatch(); - } - - @Override - public NonBlockClasses.Match newMatch(final Object... parameters) { - return NonBlockClasses.Match.newMatch((com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class) parameters[0]); - } - - /** - * Inner class allowing the singleton instance of {@link NonBlockClasses} to be created - * not at the class load time of the outer class, - * but rather at the first call to {@link NonBlockClasses#instance()}. - * - *

This workaround is required e.g. to support recursion. - * - */ - private static class LazyHolder { - private static final NonBlockClasses INSTANCE = new NonBlockClasses(); - - /** - * Statically initializes the query specification after the field {@link #INSTANCE} is assigned. - * This initialization order is required to support indirect recursion. - * - *

The static initializer is defined using a helper field to work around limitations of the code generator. - * - */ - private static final Object STATIC_INITIALIZER = ensureInitialized(); - - public static Object ensureInitialized() { - INSTANCE.ensureInitializedInternal(); - return null; - } - } - - private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { - private static final NonBlockClasses.GeneratedPQuery INSTANCE = new GeneratedPQuery(); - - private final PParameter parameter_class = new PParameter("class", "com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.nomagic.com/magicdraw/UML/2.5.1", "Class")), PParameterDirection.INOUT); - - private final List parameters = Arrays.asList(parameter_class); - - private GeneratedPQuery() { - super(PVisibility.PUBLIC); - } - - @Override - public String getFullyQualifiedName() { - return "com.incquerylabs.magicdraw.benchmark.queries.nonBlockClasses"; - } - - @Override - public List getParameterNames() { - return Arrays.asList("class"); - } - - @Override - public List getParameters() { - return parameters; - } - - @Override - public Set doGetContainedBodies() { - setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); - Set bodies = new LinkedHashSet<>(); - { - PBody body = new PBody(this); - PVariable var_class = body.getOrCreateVariableByName("class"); - new TypeConstraint(body, Tuples.flatTupleOf(var_class), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Class"))); - body.setSymbolicParameters(Arrays.asList( - new ExportedParameter(body, var_class, parameter_class) - )); - // neg find blocks(class) - new NegativePatternCall(body, Tuples.flatTupleOf(var_class), Blocks.instance().getInternalQueryRepresentation()); - bodies.add(body); - } - return bodies; - } - } -} diff --git a/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/NumberOfSubregions.java b/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/NumberOfSubregions.java deleted file mode 100644 index d107163..0000000 --- a/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/NumberOfSubregions.java +++ /dev/null @@ -1,710 +0,0 @@ -/** - * Generated from platform:/resource/com.incquerylabs.magicdraw.benchmark/src/main/java/com/incquerylabs/magicdraw/benchmark/queries/APerformanceQueries.vql - */ -package com.incquerylabs.magicdraw.benchmark.queries; - -import com.incquerylabs.magicdraw.benchmark.queries.Subregions; -import com.nomagic.uml2.ext.magicdraw.statemachines.mdbehaviorstatemachines.State; -import java.util.Arrays; -import java.util.Collection; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.function.Consumer; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import org.apache.log4j.Logger; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.viatra.query.runtime.api.IPatternMatch; -import org.eclipse.viatra.query.runtime.api.IQuerySpecification; -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.api.impl.BaseMatcher; -import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; -import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; -import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; -import org.eclipse.viatra.query.runtime.matchers.context.common.JavaTransitiveInstancesKey; -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.PatternMatchCounter; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.TypeFilterConstraint; -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.PVisibility; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; -import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; - -/** - * A pattern-specific query specification that can instantiate Matcher in a type-safe way. - * - *

Original source: - *

- *         Reusing a simple pattern with the "count" aggregator.
- *          
- *         pattern numberOfSubregions(state : State, regionCount : java ^java.lang.Integer) {
- *           	regionCount == count find subregions(state, _subregion);
- *         }
- * 
- * - * @see Matcher - * @see Match - * - */ -@SuppressWarnings("all") -public final class NumberOfSubregions extends BaseGeneratedEMFQuerySpecification { - /** - * Pattern-specific match representation of the com.incquerylabs.magicdraw.benchmark.queries.numberOfSubregions pattern, - * to be used in conjunction with {@link Matcher}. - * - *

Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. - * Each instance is a (possibly partial) substitution of pattern parameters, - * usable to represent a match of the pattern in the result of a query, - * or to specify the bound (fixed) input parameters when issuing a query. - * - * @see Matcher - * - */ - public static abstract class Match extends BasePatternMatch { - private State fState; - - private Integer fRegionCount; - - private static List parameterNames = makeImmutableList("state", "regionCount"); - - private Match(final State pState, final Integer pRegionCount) { - this.fState = pState; - this.fRegionCount = pRegionCount; - } - - @Override - public Object get(final String parameterName) { - switch(parameterName) { - case "state": return this.fState; - case "regionCount": return this.fRegionCount; - default: return null; - } - } - - @Override - public Object get(final int index) { - switch(index) { - case 0: return this.fState; - case 1: return this.fRegionCount; - default: return null; - } - } - - public State getState() { - return this.fState; - } - - public Integer getRegionCount() { - return this.fRegionCount; - } - - @Override - public boolean set(final String parameterName, final Object newValue) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - if ("state".equals(parameterName) ) { - this.fState = (State) newValue; - return true; - } - if ("regionCount".equals(parameterName) ) { - this.fRegionCount = (Integer) newValue; - return true; - } - return false; - } - - public void setState(final State pState) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fState = pState; - } - - public void setRegionCount(final Integer pRegionCount) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fRegionCount = pRegionCount; - } - - @Override - public String patternName() { - return "com.incquerylabs.magicdraw.benchmark.queries.numberOfSubregions"; - } - - @Override - public List parameterNames() { - return NumberOfSubregions.Match.parameterNames; - } - - @Override - public Object[] toArray() { - return new Object[]{fState, fRegionCount}; - } - - @Override - public NumberOfSubregions.Match toImmutable() { - return isMutable() ? newMatch(fState, fRegionCount) : this; - } - - @Override - public String prettyPrint() { - StringBuilder result = new StringBuilder(); - result.append("\"state\"=" + prettyPrintValue(fState) + ", "); - result.append("\"regionCount\"=" + prettyPrintValue(fRegionCount)); - return result.toString(); - } - - @Override - public int hashCode() { - return Objects.hash(fState, fRegionCount); - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) - return true; - if (obj == null) { - return false; - } - if ((obj instanceof NumberOfSubregions.Match)) { - NumberOfSubregions.Match other = (NumberOfSubregions.Match) obj; - return Objects.equals(fState, other.fState) && Objects.equals(fRegionCount, other.fRegionCount); - } else { - // this should be infrequent - if (!(obj instanceof IPatternMatch)) { - return false; - } - IPatternMatch otherSig = (IPatternMatch) obj; - return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); - } - } - - @Override - public NumberOfSubregions specification() { - return NumberOfSubregions.instance(); - } - - /** - * Returns an empty, mutable match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @return the empty match. - * - */ - public static NumberOfSubregions.Match newEmptyMatch() { - return new Mutable(null, null); - } - - /** - * Returns a mutable (partial) match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pRegionCount the fixed value of pattern parameter regionCount, or null if not bound. - * @return the new, mutable (partial) match object. - * - */ - public static NumberOfSubregions.Match newMutableMatch(final State pState, final Integer pRegionCount) { - return new Mutable(pState, pRegionCount); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pRegionCount the fixed value of pattern parameter regionCount, or null if not bound. - * @return the (partial) match object. - * - */ - public static NumberOfSubregions.Match newMatch(final State pState, final Integer pRegionCount) { - return new Immutable(pState, pRegionCount); - } - - private static final class Mutable extends NumberOfSubregions.Match { - Mutable(final State pState, final Integer pRegionCount) { - super(pState, pRegionCount); - } - - @Override - public boolean isMutable() { - return true; - } - } - - private static final class Immutable extends NumberOfSubregions.Match { - Immutable(final State pState, final Integer pRegionCount) { - super(pState, pRegionCount); - } - - @Override - public boolean isMutable() { - return false; - } - } - } - - /** - * Generated pattern matcher API of the com.incquerylabs.magicdraw.benchmark.queries.numberOfSubregions pattern, - * providing pattern-specific query methods. - * - *

Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, - * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. - * - *

Matches of the pattern will be represented as {@link Match}. - * - *

Original source: - *

-   * Reusing a simple pattern with the "count" aggregator.
-   *  
-   * pattern numberOfSubregions(state : State, regionCount : java ^java.lang.Integer) {
-   *   	regionCount == count find subregions(state, _subregion);
-   * }
-   * 
- * - * @see Match - * @see NumberOfSubregions - * - */ - public static class Matcher extends BaseMatcher { - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - public static NumberOfSubregions.Matcher on(final ViatraQueryEngine engine) { - // check if matcher already exists - Matcher matcher = engine.getExistingMatcher(querySpecification()); - if (matcher == null) { - matcher = (Matcher)engine.getMatcher(querySpecification()); - } - return matcher; - } - - /** - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * @return an initialized matcher - * @noreference This method is for internal matcher initialization by the framework, do not call it manually. - * - */ - public static NumberOfSubregions.Matcher create() { - return new Matcher(); - } - - private static final int POSITION_STATE = 0; - - private static final int POSITION_REGIONCOUNT = 1; - - private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(NumberOfSubregions.Matcher.class); - - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - private Matcher() { - super(querySpecification()); - } - - /** - * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pRegionCount the fixed value of pattern parameter regionCount, or null if not bound. - * @return matches represented as a Match object. - * - */ - public Collection getAllMatches(final State pState, final Integer pRegionCount) { - return rawStreamAllMatches(new Object[]{pState, pRegionCount}).collect(Collectors.toSet()); - } - - /** - * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pRegionCount the fixed value of pattern parameter regionCount, or null if not bound. - * @return a stream of matches represented as a Match object. - * - */ - public Stream streamAllMatches(final State pState, final Integer pRegionCount) { - return rawStreamAllMatches(new Object[]{pState, pRegionCount}); - } - - /** - * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pRegionCount the fixed value of pattern parameter regionCount, or null if not bound. - * @return a match represented as a Match object, or null if no match is found. - * - */ - public Optional getOneArbitraryMatch(final State pState, final Integer pRegionCount) { - return rawGetOneArbitraryMatch(new Object[]{pState, pRegionCount}); - } - - /** - * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, - * under any possible substitution of the unspecified parameters (if any). - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pRegionCount the fixed value of pattern parameter regionCount, or null if not bound. - * @return true if the input is a valid (partial) match of the pattern. - * - */ - public boolean hasMatch(final State pState, final Integer pRegionCount) { - return rawHasMatch(new Object[]{pState, pRegionCount}); - } - - /** - * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pRegionCount the fixed value of pattern parameter regionCount, or null if not bound. - * @return the number of pattern matches found. - * - */ - public int countMatches(final State pState, final Integer pRegionCount) { - return rawCountMatches(new Object[]{pState, pRegionCount}); - } - - /** - * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pRegionCount the fixed value of pattern parameter regionCount, or null if not bound. - * @param processor the action that will process the selected match. - * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked - * - */ - public boolean forOneArbitraryMatch(final State pState, final Integer pRegionCount, final Consumer processor) { - return rawForOneArbitraryMatch(new Object[]{pState, pRegionCount}, processor); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pRegionCount the fixed value of pattern parameter regionCount, or null if not bound. - * @return the (partial) match object. - * - */ - public NumberOfSubregions.Match newMatch(final State pState, final Integer pRegionCount) { - return NumberOfSubregions.Match.newMatch(pState, pRegionCount); - } - - /** - * Retrieve the set of values that occur in matches for state. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOfstate(final Object[] parameters) { - return rawStreamAllValues(POSITION_STATE, parameters).map(State.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for state. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfstate() { - return rawStreamAllValuesOfstate(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for state. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfstate() { - return rawStreamAllValuesOfstate(emptyArray()); - } - - /** - * Retrieve the set of values that occur in matches for state. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfstate(final NumberOfSubregions.Match partialMatch) { - return rawStreamAllValuesOfstate(partialMatch.toArray()); - } - - /** - * Retrieve the set of values that occur in matches for state. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfstate(final Integer pRegionCount) { - return rawStreamAllValuesOfstate(new Object[]{null, pRegionCount}); - } - - /** - * Retrieve the set of values that occur in matches for state. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfstate(final NumberOfSubregions.Match partialMatch) { - return rawStreamAllValuesOfstate(partialMatch.toArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for state. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfstate(final Integer pRegionCount) { - return rawStreamAllValuesOfstate(new Object[]{null, pRegionCount}).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for regionCount. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOfregionCount(final Object[] parameters) { - return rawStreamAllValues(POSITION_REGIONCOUNT, parameters).map(Integer.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for regionCount. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfregionCount() { - return rawStreamAllValuesOfregionCount(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for regionCount. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfregionCount() { - return rawStreamAllValuesOfregionCount(emptyArray()); - } - - /** - * Retrieve the set of values that occur in matches for regionCount. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfregionCount(final NumberOfSubregions.Match partialMatch) { - return rawStreamAllValuesOfregionCount(partialMatch.toArray()); - } - - /** - * Retrieve the set of values that occur in matches for regionCount. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfregionCount(final State pState) { - return rawStreamAllValuesOfregionCount(new Object[]{pState, null}); - } - - /** - * Retrieve the set of values that occur in matches for regionCount. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfregionCount(final NumberOfSubregions.Match partialMatch) { - return rawStreamAllValuesOfregionCount(partialMatch.toArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for regionCount. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfregionCount(final State pState) { - return rawStreamAllValuesOfregionCount(new Object[]{pState, null}).collect(Collectors.toSet()); - } - - @Override - protected NumberOfSubregions.Match tupleToMatch(final Tuple t) { - try { - return NumberOfSubregions.Match.newMatch((State) t.get(POSITION_STATE), (Integer) t.get(POSITION_REGIONCOUNT)); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in tuple not properly typed!",e); - return null; - } - } - - @Override - protected NumberOfSubregions.Match arrayToMatch(final Object[] match) { - try { - return NumberOfSubregions.Match.newMatch((State) match[POSITION_STATE], (Integer) match[POSITION_REGIONCOUNT]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - @Override - protected NumberOfSubregions.Match arrayToMatchMutable(final Object[] match) { - try { - return NumberOfSubregions.Match.newMutableMatch((State) match[POSITION_STATE], (Integer) match[POSITION_REGIONCOUNT]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - /** - * @return the singleton instance of the query specification of this pattern - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static IQuerySpecification querySpecification() { - return NumberOfSubregions.instance(); - } - } - - private NumberOfSubregions() { - super(GeneratedPQuery.INSTANCE); - } - - /** - * @return the singleton instance of the query specification - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static NumberOfSubregions instance() { - try{ - return LazyHolder.INSTANCE; - } catch (ExceptionInInitializerError err) { - throw processInitializerError(err); - } - } - - @Override - protected NumberOfSubregions.Matcher instantiate(final ViatraQueryEngine engine) { - return NumberOfSubregions.Matcher.on(engine); - } - - @Override - public NumberOfSubregions.Matcher instantiate() { - return NumberOfSubregions.Matcher.create(); - } - - @Override - public NumberOfSubregions.Match newEmptyMatch() { - return NumberOfSubregions.Match.newEmptyMatch(); - } - - @Override - public NumberOfSubregions.Match newMatch(final Object... parameters) { - return NumberOfSubregions.Match.newMatch((com.nomagic.uml2.ext.magicdraw.statemachines.mdbehaviorstatemachines.State) parameters[0], (java.lang.Integer) parameters[1]); - } - - /** - * Inner class allowing the singleton instance of {@link NumberOfSubregions} to be created - * not at the class load time of the outer class, - * but rather at the first call to {@link NumberOfSubregions#instance()}. - * - *

This workaround is required e.g. to support recursion. - * - */ - private static class LazyHolder { - private static final NumberOfSubregions INSTANCE = new NumberOfSubregions(); - - /** - * Statically initializes the query specification after the field {@link #INSTANCE} is assigned. - * This initialization order is required to support indirect recursion. - * - *

The static initializer is defined using a helper field to work around limitations of the code generator. - * - */ - private static final Object STATIC_INITIALIZER = ensureInitialized(); - - public static Object ensureInitialized() { - INSTANCE.ensureInitializedInternal(); - return null; - } - } - - private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { - private static final NumberOfSubregions.GeneratedPQuery INSTANCE = new GeneratedPQuery(); - - private final PParameter parameter_state = new PParameter("state", "com.nomagic.uml2.ext.magicdraw.statemachines.mdbehaviorstatemachines.State", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.nomagic.com/magicdraw/UML/2.5.1", "State")), PParameterDirection.INOUT); - - private final PParameter parameter_regionCount = new PParameter("regionCount", "java.lang.Integer", new JavaTransitiveInstancesKey(java.lang.Integer.class), PParameterDirection.INOUT); - - private final List parameters = Arrays.asList(parameter_state, parameter_regionCount); - - private GeneratedPQuery() { - super(PVisibility.PUBLIC); - } - - @Override - public String getFullyQualifiedName() { - return "com.incquerylabs.magicdraw.benchmark.queries.numberOfSubregions"; - } - - @Override - public List getParameterNames() { - return Arrays.asList("state","regionCount"); - } - - @Override - public List getParameters() { - return parameters; - } - - @Override - public Set doGetContainedBodies() { - setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); - Set bodies = new LinkedHashSet<>(); - { - PBody body = new PBody(this); - PVariable var_state = body.getOrCreateVariableByName("state"); - PVariable var_regionCount = body.getOrCreateVariableByName("regionCount"); - PVariable var__subregion = body.getOrCreateVariableByName("_subregion"); - new TypeConstraint(body, Tuples.flatTupleOf(var_state), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "State"))); - new TypeFilterConstraint(body, Tuples.flatTupleOf(var_regionCount), new JavaTransitiveInstancesKey(java.lang.Integer.class)); - body.setSymbolicParameters(Arrays.asList( - new ExportedParameter(body, var_state, parameter_state), - new ExportedParameter(body, var_regionCount, parameter_regionCount) - )); - // regionCount == count find subregions(state, _subregion) - PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); - new PatternMatchCounter(body, Tuples.flatTupleOf(var_state, var__subregion), Subregions.instance().getInternalQueryRepresentation(), var__virtual_0_); - new Equality(body, var_regionCount, var__virtual_0_); - bodies.add(body); - } - return bodies; - } - } -} diff --git a/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/NumberOfTransitiveSubstates.java b/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/NumberOfTransitiveSubstates.java deleted file mode 100644 index cb9240a..0000000 --- a/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/NumberOfTransitiveSubstates.java +++ /dev/null @@ -1,710 +0,0 @@ -/** - * Generated from platform:/resource/com.incquerylabs.magicdraw.benchmark/src/main/java/com/incquerylabs/magicdraw/benchmark/queries/APerformanceQueries.vql - */ -package com.incquerylabs.magicdraw.benchmark.queries; - -import com.incquerylabs.magicdraw.benchmark.queries.TransitiveSubstates; -import com.nomagic.uml2.ext.magicdraw.statemachines.mdbehaviorstatemachines.State; -import java.util.Arrays; -import java.util.Collection; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.function.Consumer; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import org.apache.log4j.Logger; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.viatra.query.runtime.api.IPatternMatch; -import org.eclipse.viatra.query.runtime.api.IQuerySpecification; -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.api.impl.BaseMatcher; -import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; -import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; -import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; -import org.eclipse.viatra.query.runtime.matchers.context.common.JavaTransitiveInstancesKey; -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.PatternMatchCounter; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.TypeFilterConstraint; -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.PVisibility; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; -import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; - -/** - * A pattern-specific query specification that can instantiate Matcher in a type-safe way. - * - *

Original source: - *

- *         Reusing a transitive closure pattern with the count aggregator.
- *          
- *         pattern numberOfTransitiveSubstates(state : State, transitiveSubstateCount : java ^java.lang.Integer) {
- *         	transitiveSubstateCount == count find transitiveSubstates(state, _);
- *         }
- * 
- * - * @see Matcher - * @see Match - * - */ -@SuppressWarnings("all") -public final class NumberOfTransitiveSubstates extends BaseGeneratedEMFQuerySpecification { - /** - * Pattern-specific match representation of the com.incquerylabs.magicdraw.benchmark.queries.numberOfTransitiveSubstates pattern, - * to be used in conjunction with {@link Matcher}. - * - *

Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. - * Each instance is a (possibly partial) substitution of pattern parameters, - * usable to represent a match of the pattern in the result of a query, - * or to specify the bound (fixed) input parameters when issuing a query. - * - * @see Matcher - * - */ - public static abstract class Match extends BasePatternMatch { - private State fState; - - private Integer fTransitiveSubstateCount; - - private static List parameterNames = makeImmutableList("state", "transitiveSubstateCount"); - - private Match(final State pState, final Integer pTransitiveSubstateCount) { - this.fState = pState; - this.fTransitiveSubstateCount = pTransitiveSubstateCount; - } - - @Override - public Object get(final String parameterName) { - switch(parameterName) { - case "state": return this.fState; - case "transitiveSubstateCount": return this.fTransitiveSubstateCount; - default: return null; - } - } - - @Override - public Object get(final int index) { - switch(index) { - case 0: return this.fState; - case 1: return this.fTransitiveSubstateCount; - default: return null; - } - } - - public State getState() { - return this.fState; - } - - public Integer getTransitiveSubstateCount() { - return this.fTransitiveSubstateCount; - } - - @Override - public boolean set(final String parameterName, final Object newValue) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - if ("state".equals(parameterName) ) { - this.fState = (State) newValue; - return true; - } - if ("transitiveSubstateCount".equals(parameterName) ) { - this.fTransitiveSubstateCount = (Integer) newValue; - return true; - } - return false; - } - - public void setState(final State pState) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fState = pState; - } - - public void setTransitiveSubstateCount(final Integer pTransitiveSubstateCount) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fTransitiveSubstateCount = pTransitiveSubstateCount; - } - - @Override - public String patternName() { - return "com.incquerylabs.magicdraw.benchmark.queries.numberOfTransitiveSubstates"; - } - - @Override - public List parameterNames() { - return NumberOfTransitiveSubstates.Match.parameterNames; - } - - @Override - public Object[] toArray() { - return new Object[]{fState, fTransitiveSubstateCount}; - } - - @Override - public NumberOfTransitiveSubstates.Match toImmutable() { - return isMutable() ? newMatch(fState, fTransitiveSubstateCount) : this; - } - - @Override - public String prettyPrint() { - StringBuilder result = new StringBuilder(); - result.append("\"state\"=" + prettyPrintValue(fState) + ", "); - result.append("\"transitiveSubstateCount\"=" + prettyPrintValue(fTransitiveSubstateCount)); - return result.toString(); - } - - @Override - public int hashCode() { - return Objects.hash(fState, fTransitiveSubstateCount); - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) - return true; - if (obj == null) { - return false; - } - if ((obj instanceof NumberOfTransitiveSubstates.Match)) { - NumberOfTransitiveSubstates.Match other = (NumberOfTransitiveSubstates.Match) obj; - return Objects.equals(fState, other.fState) && Objects.equals(fTransitiveSubstateCount, other.fTransitiveSubstateCount); - } else { - // this should be infrequent - if (!(obj instanceof IPatternMatch)) { - return false; - } - IPatternMatch otherSig = (IPatternMatch) obj; - return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); - } - } - - @Override - public NumberOfTransitiveSubstates specification() { - return NumberOfTransitiveSubstates.instance(); - } - - /** - * Returns an empty, mutable match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @return the empty match. - * - */ - public static NumberOfTransitiveSubstates.Match newEmptyMatch() { - return new Mutable(null, null); - } - - /** - * Returns a mutable (partial) match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pTransitiveSubstateCount the fixed value of pattern parameter transitiveSubstateCount, or null if not bound. - * @return the new, mutable (partial) match object. - * - */ - public static NumberOfTransitiveSubstates.Match newMutableMatch(final State pState, final Integer pTransitiveSubstateCount) { - return new Mutable(pState, pTransitiveSubstateCount); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pTransitiveSubstateCount the fixed value of pattern parameter transitiveSubstateCount, or null if not bound. - * @return the (partial) match object. - * - */ - public static NumberOfTransitiveSubstates.Match newMatch(final State pState, final Integer pTransitiveSubstateCount) { - return new Immutable(pState, pTransitiveSubstateCount); - } - - private static final class Mutable extends NumberOfTransitiveSubstates.Match { - Mutable(final State pState, final Integer pTransitiveSubstateCount) { - super(pState, pTransitiveSubstateCount); - } - - @Override - public boolean isMutable() { - return true; - } - } - - private static final class Immutable extends NumberOfTransitiveSubstates.Match { - Immutable(final State pState, final Integer pTransitiveSubstateCount) { - super(pState, pTransitiveSubstateCount); - } - - @Override - public boolean isMutable() { - return false; - } - } - } - - /** - * Generated pattern matcher API of the com.incquerylabs.magicdraw.benchmark.queries.numberOfTransitiveSubstates pattern, - * providing pattern-specific query methods. - * - *

Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, - * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. - * - *

Matches of the pattern will be represented as {@link Match}. - * - *

Original source: - *

-   * Reusing a transitive closure pattern with the count aggregator.
-   *  
-   * pattern numberOfTransitiveSubstates(state : State, transitiveSubstateCount : java ^java.lang.Integer) {
-   * 	transitiveSubstateCount == count find transitiveSubstates(state, _);
-   * }
-   * 
- * - * @see Match - * @see NumberOfTransitiveSubstates - * - */ - public static class Matcher extends BaseMatcher { - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - public static NumberOfTransitiveSubstates.Matcher on(final ViatraQueryEngine engine) { - // check if matcher already exists - Matcher matcher = engine.getExistingMatcher(querySpecification()); - if (matcher == null) { - matcher = (Matcher)engine.getMatcher(querySpecification()); - } - return matcher; - } - - /** - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * @return an initialized matcher - * @noreference This method is for internal matcher initialization by the framework, do not call it manually. - * - */ - public static NumberOfTransitiveSubstates.Matcher create() { - return new Matcher(); - } - - private static final int POSITION_STATE = 0; - - private static final int POSITION_TRANSITIVESUBSTATECOUNT = 1; - - private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(NumberOfTransitiveSubstates.Matcher.class); - - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - private Matcher() { - super(querySpecification()); - } - - /** - * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pTransitiveSubstateCount the fixed value of pattern parameter transitiveSubstateCount, or null if not bound. - * @return matches represented as a Match object. - * - */ - public Collection getAllMatches(final State pState, final Integer pTransitiveSubstateCount) { - return rawStreamAllMatches(new Object[]{pState, pTransitiveSubstateCount}).collect(Collectors.toSet()); - } - - /** - * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pTransitiveSubstateCount the fixed value of pattern parameter transitiveSubstateCount, or null if not bound. - * @return a stream of matches represented as a Match object. - * - */ - public Stream streamAllMatches(final State pState, final Integer pTransitiveSubstateCount) { - return rawStreamAllMatches(new Object[]{pState, pTransitiveSubstateCount}); - } - - /** - * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pTransitiveSubstateCount the fixed value of pattern parameter transitiveSubstateCount, or null if not bound. - * @return a match represented as a Match object, or null if no match is found. - * - */ - public Optional getOneArbitraryMatch(final State pState, final Integer pTransitiveSubstateCount) { - return rawGetOneArbitraryMatch(new Object[]{pState, pTransitiveSubstateCount}); - } - - /** - * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, - * under any possible substitution of the unspecified parameters (if any). - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pTransitiveSubstateCount the fixed value of pattern parameter transitiveSubstateCount, or null if not bound. - * @return true if the input is a valid (partial) match of the pattern. - * - */ - public boolean hasMatch(final State pState, final Integer pTransitiveSubstateCount) { - return rawHasMatch(new Object[]{pState, pTransitiveSubstateCount}); - } - - /** - * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pTransitiveSubstateCount the fixed value of pattern parameter transitiveSubstateCount, or null if not bound. - * @return the number of pattern matches found. - * - */ - public int countMatches(final State pState, final Integer pTransitiveSubstateCount) { - return rawCountMatches(new Object[]{pState, pTransitiveSubstateCount}); - } - - /** - * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pTransitiveSubstateCount the fixed value of pattern parameter transitiveSubstateCount, or null if not bound. - * @param processor the action that will process the selected match. - * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked - * - */ - public boolean forOneArbitraryMatch(final State pState, final Integer pTransitiveSubstateCount, final Consumer processor) { - return rawForOneArbitraryMatch(new Object[]{pState, pTransitiveSubstateCount}, processor); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pTransitiveSubstateCount the fixed value of pattern parameter transitiveSubstateCount, or null if not bound. - * @return the (partial) match object. - * - */ - public NumberOfTransitiveSubstates.Match newMatch(final State pState, final Integer pTransitiveSubstateCount) { - return NumberOfTransitiveSubstates.Match.newMatch(pState, pTransitiveSubstateCount); - } - - /** - * Retrieve the set of values that occur in matches for state. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOfstate(final Object[] parameters) { - return rawStreamAllValues(POSITION_STATE, parameters).map(State.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for state. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfstate() { - return rawStreamAllValuesOfstate(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for state. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfstate() { - return rawStreamAllValuesOfstate(emptyArray()); - } - - /** - * Retrieve the set of values that occur in matches for state. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfstate(final NumberOfTransitiveSubstates.Match partialMatch) { - return rawStreamAllValuesOfstate(partialMatch.toArray()); - } - - /** - * Retrieve the set of values that occur in matches for state. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfstate(final Integer pTransitiveSubstateCount) { - return rawStreamAllValuesOfstate(new Object[]{null, pTransitiveSubstateCount}); - } - - /** - * Retrieve the set of values that occur in matches for state. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfstate(final NumberOfTransitiveSubstates.Match partialMatch) { - return rawStreamAllValuesOfstate(partialMatch.toArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for state. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfstate(final Integer pTransitiveSubstateCount) { - return rawStreamAllValuesOfstate(new Object[]{null, pTransitiveSubstateCount}).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for transitiveSubstateCount. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOftransitiveSubstateCount(final Object[] parameters) { - return rawStreamAllValues(POSITION_TRANSITIVESUBSTATECOUNT, parameters).map(Integer.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for transitiveSubstateCount. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOftransitiveSubstateCount() { - return rawStreamAllValuesOftransitiveSubstateCount(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for transitiveSubstateCount. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOftransitiveSubstateCount() { - return rawStreamAllValuesOftransitiveSubstateCount(emptyArray()); - } - - /** - * Retrieve the set of values that occur in matches for transitiveSubstateCount. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOftransitiveSubstateCount(final NumberOfTransitiveSubstates.Match partialMatch) { - return rawStreamAllValuesOftransitiveSubstateCount(partialMatch.toArray()); - } - - /** - * Retrieve the set of values that occur in matches for transitiveSubstateCount. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOftransitiveSubstateCount(final State pState) { - return rawStreamAllValuesOftransitiveSubstateCount(new Object[]{pState, null}); - } - - /** - * Retrieve the set of values that occur in matches for transitiveSubstateCount. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOftransitiveSubstateCount(final NumberOfTransitiveSubstates.Match partialMatch) { - return rawStreamAllValuesOftransitiveSubstateCount(partialMatch.toArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for transitiveSubstateCount. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOftransitiveSubstateCount(final State pState) { - return rawStreamAllValuesOftransitiveSubstateCount(new Object[]{pState, null}).collect(Collectors.toSet()); - } - - @Override - protected NumberOfTransitiveSubstates.Match tupleToMatch(final Tuple t) { - try { - return NumberOfTransitiveSubstates.Match.newMatch((State) t.get(POSITION_STATE), (Integer) t.get(POSITION_TRANSITIVESUBSTATECOUNT)); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in tuple not properly typed!",e); - return null; - } - } - - @Override - protected NumberOfTransitiveSubstates.Match arrayToMatch(final Object[] match) { - try { - return NumberOfTransitiveSubstates.Match.newMatch((State) match[POSITION_STATE], (Integer) match[POSITION_TRANSITIVESUBSTATECOUNT]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - @Override - protected NumberOfTransitiveSubstates.Match arrayToMatchMutable(final Object[] match) { - try { - return NumberOfTransitiveSubstates.Match.newMutableMatch((State) match[POSITION_STATE], (Integer) match[POSITION_TRANSITIVESUBSTATECOUNT]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - /** - * @return the singleton instance of the query specification of this pattern - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static IQuerySpecification querySpecification() { - return NumberOfTransitiveSubstates.instance(); - } - } - - private NumberOfTransitiveSubstates() { - super(GeneratedPQuery.INSTANCE); - } - - /** - * @return the singleton instance of the query specification - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static NumberOfTransitiveSubstates instance() { - try{ - return LazyHolder.INSTANCE; - } catch (ExceptionInInitializerError err) { - throw processInitializerError(err); - } - } - - @Override - protected NumberOfTransitiveSubstates.Matcher instantiate(final ViatraQueryEngine engine) { - return NumberOfTransitiveSubstates.Matcher.on(engine); - } - - @Override - public NumberOfTransitiveSubstates.Matcher instantiate() { - return NumberOfTransitiveSubstates.Matcher.create(); - } - - @Override - public NumberOfTransitiveSubstates.Match newEmptyMatch() { - return NumberOfTransitiveSubstates.Match.newEmptyMatch(); - } - - @Override - public NumberOfTransitiveSubstates.Match newMatch(final Object... parameters) { - return NumberOfTransitiveSubstates.Match.newMatch((com.nomagic.uml2.ext.magicdraw.statemachines.mdbehaviorstatemachines.State) parameters[0], (java.lang.Integer) parameters[1]); - } - - /** - * Inner class allowing the singleton instance of {@link NumberOfTransitiveSubstates} to be created - * not at the class load time of the outer class, - * but rather at the first call to {@link NumberOfTransitiveSubstates#instance()}. - * - *

This workaround is required e.g. to support recursion. - * - */ - private static class LazyHolder { - private static final NumberOfTransitiveSubstates INSTANCE = new NumberOfTransitiveSubstates(); - - /** - * Statically initializes the query specification after the field {@link #INSTANCE} is assigned. - * This initialization order is required to support indirect recursion. - * - *

The static initializer is defined using a helper field to work around limitations of the code generator. - * - */ - private static final Object STATIC_INITIALIZER = ensureInitialized(); - - public static Object ensureInitialized() { - INSTANCE.ensureInitializedInternal(); - return null; - } - } - - private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { - private static final NumberOfTransitiveSubstates.GeneratedPQuery INSTANCE = new GeneratedPQuery(); - - private final PParameter parameter_state = new PParameter("state", "com.nomagic.uml2.ext.magicdraw.statemachines.mdbehaviorstatemachines.State", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.nomagic.com/magicdraw/UML/2.5.1", "State")), PParameterDirection.INOUT); - - private final PParameter parameter_transitiveSubstateCount = new PParameter("transitiveSubstateCount", "java.lang.Integer", new JavaTransitiveInstancesKey(java.lang.Integer.class), PParameterDirection.INOUT); - - private final List parameters = Arrays.asList(parameter_state, parameter_transitiveSubstateCount); - - private GeneratedPQuery() { - super(PVisibility.PUBLIC); - } - - @Override - public String getFullyQualifiedName() { - return "com.incquerylabs.magicdraw.benchmark.queries.numberOfTransitiveSubstates"; - } - - @Override - public List getParameterNames() { - return Arrays.asList("state","transitiveSubstateCount"); - } - - @Override - public List getParameters() { - return parameters; - } - - @Override - public Set doGetContainedBodies() { - setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); - Set bodies = new LinkedHashSet<>(); - { - PBody body = new PBody(this); - PVariable var_state = body.getOrCreateVariableByName("state"); - PVariable var_transitiveSubstateCount = body.getOrCreateVariableByName("transitiveSubstateCount"); - PVariable var___0_ = body.getOrCreateVariableByName("_<0>"); - new TypeConstraint(body, Tuples.flatTupleOf(var_state), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "State"))); - new TypeFilterConstraint(body, Tuples.flatTupleOf(var_transitiveSubstateCount), new JavaTransitiveInstancesKey(java.lang.Integer.class)); - body.setSymbolicParameters(Arrays.asList( - new ExportedParameter(body, var_state, parameter_state), - new ExportedParameter(body, var_transitiveSubstateCount, parameter_transitiveSubstateCount) - )); - // transitiveSubstateCount == count find transitiveSubstates(state, _) - PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); - new PatternMatchCounter(body, Tuples.flatTupleOf(var_state, var___0_), TransitiveSubstates.instance().getInternalQueryRepresentation(), var__virtual_0_); - new Equality(body, var_transitiveSubstateCount, var__virtual_0_); - bodies.add(body); - } - return bodies; - } - } -} diff --git a/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/ParentState.java b/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/ParentState.java deleted file mode 100644 index 07958a9..0000000 --- a/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/ParentState.java +++ /dev/null @@ -1,717 +0,0 @@ -/** - * Generated from platform:/resource/com.incquerylabs.magicdraw.benchmark/src/main/java/com/incquerylabs/magicdraw/benchmark/queries/APerformanceQueries.vql - */ -package com.incquerylabs.magicdraw.benchmark.queries; - -import com.nomagic.uml2.ext.magicdraw.statemachines.mdbehaviorstatemachines.State; -import java.util.Arrays; -import java.util.Collection; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.function.Consumer; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import org.apache.log4j.Logger; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.viatra.query.runtime.api.IPatternMatch; -import org.eclipse.viatra.query.runtime.api.IQuerySpecification; -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.api.impl.BaseMatcher; -import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; -import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; -import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey; -import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; -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.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.PVisibility; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; -import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; - -/** - * A pattern-specific query specification that can instantiate Matcher in a type-safe way. - * - *

Original source: - *

- *         Simple pattern for transitive closures.
- *          
- *         pattern parentState(state : State, parentState : State) {
- *         	State.region(parentState, subregion);
- *         	Region.subvertex(subregion, state);
- *         }
- * 
- * - * @see Matcher - * @see Match - * - */ -@SuppressWarnings("all") -public final class ParentState extends BaseGeneratedEMFQuerySpecification { - /** - * Pattern-specific match representation of the com.incquerylabs.magicdraw.benchmark.queries.parentState pattern, - * to be used in conjunction with {@link Matcher}. - * - *

Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. - * Each instance is a (possibly partial) substitution of pattern parameters, - * usable to represent a match of the pattern in the result of a query, - * or to specify the bound (fixed) input parameters when issuing a query. - * - * @see Matcher - * - */ - public static abstract class Match extends BasePatternMatch { - private State fState; - - private State fParentState; - - private static List parameterNames = makeImmutableList("state", "parentState"); - - private Match(final State pState, final State pParentState) { - this.fState = pState; - this.fParentState = pParentState; - } - - @Override - public Object get(final String parameterName) { - switch(parameterName) { - case "state": return this.fState; - case "parentState": return this.fParentState; - default: return null; - } - } - - @Override - public Object get(final int index) { - switch(index) { - case 0: return this.fState; - case 1: return this.fParentState; - default: return null; - } - } - - public State getState() { - return this.fState; - } - - public State getParentState() { - return this.fParentState; - } - - @Override - public boolean set(final String parameterName, final Object newValue) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - if ("state".equals(parameterName) ) { - this.fState = (State) newValue; - return true; - } - if ("parentState".equals(parameterName) ) { - this.fParentState = (State) newValue; - return true; - } - return false; - } - - public void setState(final State pState) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fState = pState; - } - - public void setParentState(final State pParentState) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fParentState = pParentState; - } - - @Override - public String patternName() { - return "com.incquerylabs.magicdraw.benchmark.queries.parentState"; - } - - @Override - public List parameterNames() { - return ParentState.Match.parameterNames; - } - - @Override - public Object[] toArray() { - return new Object[]{fState, fParentState}; - } - - @Override - public ParentState.Match toImmutable() { - return isMutable() ? newMatch(fState, fParentState) : this; - } - - @Override - public String prettyPrint() { - StringBuilder result = new StringBuilder(); - result.append("\"state\"=" + prettyPrintValue(fState) + ", "); - result.append("\"parentState\"=" + prettyPrintValue(fParentState)); - return result.toString(); - } - - @Override - public int hashCode() { - return Objects.hash(fState, fParentState); - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) - return true; - if (obj == null) { - return false; - } - if ((obj instanceof ParentState.Match)) { - ParentState.Match other = (ParentState.Match) obj; - return Objects.equals(fState, other.fState) && Objects.equals(fParentState, other.fParentState); - } else { - // this should be infrequent - if (!(obj instanceof IPatternMatch)) { - return false; - } - IPatternMatch otherSig = (IPatternMatch) obj; - return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); - } - } - - @Override - public ParentState specification() { - return ParentState.instance(); - } - - /** - * Returns an empty, mutable match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @return the empty match. - * - */ - public static ParentState.Match newEmptyMatch() { - return new Mutable(null, null); - } - - /** - * Returns a mutable (partial) match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pParentState the fixed value of pattern parameter parentState, or null if not bound. - * @return the new, mutable (partial) match object. - * - */ - public static ParentState.Match newMutableMatch(final State pState, final State pParentState) { - return new Mutable(pState, pParentState); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pParentState the fixed value of pattern parameter parentState, or null if not bound. - * @return the (partial) match object. - * - */ - public static ParentState.Match newMatch(final State pState, final State pParentState) { - return new Immutable(pState, pParentState); - } - - private static final class Mutable extends ParentState.Match { - Mutable(final State pState, final State pParentState) { - super(pState, pParentState); - } - - @Override - public boolean isMutable() { - return true; - } - } - - private static final class Immutable extends ParentState.Match { - Immutable(final State pState, final State pParentState) { - super(pState, pParentState); - } - - @Override - public boolean isMutable() { - return false; - } - } - } - - /** - * Generated pattern matcher API of the com.incquerylabs.magicdraw.benchmark.queries.parentState pattern, - * providing pattern-specific query methods. - * - *

Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, - * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. - * - *

Matches of the pattern will be represented as {@link Match}. - * - *

Original source: - *

-   * Simple pattern for transitive closures.
-   *  
-   * pattern parentState(state : State, parentState : State) {
-   * 	State.region(parentState, subregion);
-   * 	Region.subvertex(subregion, state);
-   * }
-   * 
- * - * @see Match - * @see ParentState - * - */ - public static class Matcher extends BaseMatcher { - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - public static ParentState.Matcher on(final ViatraQueryEngine engine) { - // check if matcher already exists - Matcher matcher = engine.getExistingMatcher(querySpecification()); - if (matcher == null) { - matcher = (Matcher)engine.getMatcher(querySpecification()); - } - return matcher; - } - - /** - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * @return an initialized matcher - * @noreference This method is for internal matcher initialization by the framework, do not call it manually. - * - */ - public static ParentState.Matcher create() { - return new Matcher(); - } - - private static final int POSITION_STATE = 0; - - private static final int POSITION_PARENTSTATE = 1; - - private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(ParentState.Matcher.class); - - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - private Matcher() { - super(querySpecification()); - } - - /** - * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pParentState the fixed value of pattern parameter parentState, or null if not bound. - * @return matches represented as a Match object. - * - */ - public Collection getAllMatches(final State pState, final State pParentState) { - return rawStreamAllMatches(new Object[]{pState, pParentState}).collect(Collectors.toSet()); - } - - /** - * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pParentState the fixed value of pattern parameter parentState, or null if not bound. - * @return a stream of matches represented as a Match object. - * - */ - public Stream streamAllMatches(final State pState, final State pParentState) { - return rawStreamAllMatches(new Object[]{pState, pParentState}); - } - - /** - * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pParentState the fixed value of pattern parameter parentState, or null if not bound. - * @return a match represented as a Match object, or null if no match is found. - * - */ - public Optional getOneArbitraryMatch(final State pState, final State pParentState) { - return rawGetOneArbitraryMatch(new Object[]{pState, pParentState}); - } - - /** - * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, - * under any possible substitution of the unspecified parameters (if any). - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pParentState the fixed value of pattern parameter parentState, or null if not bound. - * @return true if the input is a valid (partial) match of the pattern. - * - */ - public boolean hasMatch(final State pState, final State pParentState) { - return rawHasMatch(new Object[]{pState, pParentState}); - } - - /** - * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pParentState the fixed value of pattern parameter parentState, or null if not bound. - * @return the number of pattern matches found. - * - */ - public int countMatches(final State pState, final State pParentState) { - return rawCountMatches(new Object[]{pState, pParentState}); - } - - /** - * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pParentState the fixed value of pattern parameter parentState, or null if not bound. - * @param processor the action that will process the selected match. - * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked - * - */ - public boolean forOneArbitraryMatch(final State pState, final State pParentState, final Consumer processor) { - return rawForOneArbitraryMatch(new Object[]{pState, pParentState}, processor); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pParentState the fixed value of pattern parameter parentState, or null if not bound. - * @return the (partial) match object. - * - */ - public ParentState.Match newMatch(final State pState, final State pParentState) { - return ParentState.Match.newMatch(pState, pParentState); - } - - /** - * Retrieve the set of values that occur in matches for state. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOfstate(final Object[] parameters) { - return rawStreamAllValues(POSITION_STATE, parameters).map(State.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for state. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfstate() { - return rawStreamAllValuesOfstate(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for state. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfstate() { - return rawStreamAllValuesOfstate(emptyArray()); - } - - /** - * Retrieve the set of values that occur in matches for state. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfstate(final ParentState.Match partialMatch) { - return rawStreamAllValuesOfstate(partialMatch.toArray()); - } - - /** - * Retrieve the set of values that occur in matches for state. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfstate(final State pParentState) { - return rawStreamAllValuesOfstate(new Object[]{null, pParentState}); - } - - /** - * Retrieve the set of values that occur in matches for state. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfstate(final ParentState.Match partialMatch) { - return rawStreamAllValuesOfstate(partialMatch.toArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for state. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfstate(final State pParentState) { - return rawStreamAllValuesOfstate(new Object[]{null, pParentState}).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for parentState. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOfparentState(final Object[] parameters) { - return rawStreamAllValues(POSITION_PARENTSTATE, parameters).map(State.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for parentState. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfparentState() { - return rawStreamAllValuesOfparentState(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for parentState. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfparentState() { - return rawStreamAllValuesOfparentState(emptyArray()); - } - - /** - * Retrieve the set of values that occur in matches for parentState. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfparentState(final ParentState.Match partialMatch) { - return rawStreamAllValuesOfparentState(partialMatch.toArray()); - } - - /** - * Retrieve the set of values that occur in matches for parentState. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfparentState(final State pState) { - return rawStreamAllValuesOfparentState(new Object[]{pState, null}); - } - - /** - * Retrieve the set of values that occur in matches for parentState. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfparentState(final ParentState.Match partialMatch) { - return rawStreamAllValuesOfparentState(partialMatch.toArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for parentState. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfparentState(final State pState) { - return rawStreamAllValuesOfparentState(new Object[]{pState, null}).collect(Collectors.toSet()); - } - - @Override - protected ParentState.Match tupleToMatch(final Tuple t) { - try { - return ParentState.Match.newMatch((State) t.get(POSITION_STATE), (State) t.get(POSITION_PARENTSTATE)); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in tuple not properly typed!",e); - return null; - } - } - - @Override - protected ParentState.Match arrayToMatch(final Object[] match) { - try { - return ParentState.Match.newMatch((State) match[POSITION_STATE], (State) match[POSITION_PARENTSTATE]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - @Override - protected ParentState.Match arrayToMatchMutable(final Object[] match) { - try { - return ParentState.Match.newMutableMatch((State) match[POSITION_STATE], (State) match[POSITION_PARENTSTATE]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - /** - * @return the singleton instance of the query specification of this pattern - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static IQuerySpecification querySpecification() { - return ParentState.instance(); - } - } - - private ParentState() { - super(GeneratedPQuery.INSTANCE); - } - - /** - * @return the singleton instance of the query specification - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static ParentState instance() { - try{ - return LazyHolder.INSTANCE; - } catch (ExceptionInInitializerError err) { - throw processInitializerError(err); - } - } - - @Override - protected ParentState.Matcher instantiate(final ViatraQueryEngine engine) { - return ParentState.Matcher.on(engine); - } - - @Override - public ParentState.Matcher instantiate() { - return ParentState.Matcher.create(); - } - - @Override - public ParentState.Match newEmptyMatch() { - return ParentState.Match.newEmptyMatch(); - } - - @Override - public ParentState.Match newMatch(final Object... parameters) { - return ParentState.Match.newMatch((com.nomagic.uml2.ext.magicdraw.statemachines.mdbehaviorstatemachines.State) parameters[0], (com.nomagic.uml2.ext.magicdraw.statemachines.mdbehaviorstatemachines.State) parameters[1]); - } - - /** - * Inner class allowing the singleton instance of {@link ParentState} to be created - * not at the class load time of the outer class, - * but rather at the first call to {@link ParentState#instance()}. - * - *

This workaround is required e.g. to support recursion. - * - */ - private static class LazyHolder { - private static final ParentState INSTANCE = new ParentState(); - - /** - * Statically initializes the query specification after the field {@link #INSTANCE} is assigned. - * This initialization order is required to support indirect recursion. - * - *

The static initializer is defined using a helper field to work around limitations of the code generator. - * - */ - private static final Object STATIC_INITIALIZER = ensureInitialized(); - - public static Object ensureInitialized() { - INSTANCE.ensureInitializedInternal(); - return null; - } - } - - private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { - private static final ParentState.GeneratedPQuery INSTANCE = new GeneratedPQuery(); - - private final PParameter parameter_state = new PParameter("state", "com.nomagic.uml2.ext.magicdraw.statemachines.mdbehaviorstatemachines.State", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.nomagic.com/magicdraw/UML/2.5.1", "State")), PParameterDirection.INOUT); - - private final PParameter parameter_parentState = new PParameter("parentState", "com.nomagic.uml2.ext.magicdraw.statemachines.mdbehaviorstatemachines.State", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.nomagic.com/magicdraw/UML/2.5.1", "State")), PParameterDirection.INOUT); - - private final List parameters = Arrays.asList(parameter_state, parameter_parentState); - - private GeneratedPQuery() { - super(PVisibility.PUBLIC); - } - - @Override - public String getFullyQualifiedName() { - return "com.incquerylabs.magicdraw.benchmark.queries.parentState"; - } - - @Override - public List getParameterNames() { - return Arrays.asList("state","parentState"); - } - - @Override - public List getParameters() { - return parameters; - } - - @Override - public Set doGetContainedBodies() { - setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); - Set bodies = new LinkedHashSet<>(); - { - PBody body = new PBody(this); - PVariable var_state = body.getOrCreateVariableByName("state"); - PVariable var_parentState = body.getOrCreateVariableByName("parentState"); - PVariable var_subregion = body.getOrCreateVariableByName("subregion"); - new TypeConstraint(body, Tuples.flatTupleOf(var_state), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "State"))); - new TypeConstraint(body, Tuples.flatTupleOf(var_parentState), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "State"))); - body.setSymbolicParameters(Arrays.asList( - new ExportedParameter(body, var_state, parameter_state), - new ExportedParameter(body, var_parentState, parameter_parentState) - )); - // State.region(parentState, subregion) - new TypeConstraint(body, Tuples.flatTupleOf(var_parentState), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "State"))); - PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_parentState, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "State", "region"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Region"))); - new Equality(body, var__virtual_0_, var_subregion); - // Region.subvertex(subregion, state) - new TypeConstraint(body, Tuples.flatTupleOf(var_subregion), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Region"))); - PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_subregion, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Region", "subvertex"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Vertex"))); - new Equality(body, var__virtual_1_, var_state); - bodies.add(body); - } - return bodies; - } - } -} diff --git a/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/Requirements.java b/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/Requirements.java deleted file mode 100644 index 4825446..0000000 --- a/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/Requirements.java +++ /dev/null @@ -1,564 +0,0 @@ -/** - * Generated from platform:/resource/com.incquerylabs.magicdraw.benchmark/src/main/java/com/incquerylabs/magicdraw/benchmark/queries/APerformanceQueries.vql - */ -package com.incquerylabs.magicdraw.benchmark.queries; - -import java.util.Arrays; -import java.util.Collection; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.function.Consumer; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import org.apache.log4j.Logger; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.emf.ecore.EDataType; -import org.eclipse.viatra.query.runtime.api.IPatternMatch; -import org.eclipse.viatra.query.runtime.api.IQuerySpecification; -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.api.impl.BaseMatcher; -import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; -import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; -import org.eclipse.viatra.query.runtime.emf.types.EDataTypeInSlotsKey; -import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey; -import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; -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.basicenumerables.ConstantValue; -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.PVisibility; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; -import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; - -/** - * A pattern-specific query specification that can instantiate Matcher in a type-safe way. - * - *

Original source: - *

- *         Querying all instances of an EClass that have a short "reference chain".
- *          
- *         pattern requirements(class : Class) {
- *         	Class.appliedStereotypeInstance.classifier.name(class, "Requirement"); 
- *         }
- * 
- * - * @see Matcher - * @see Match - * - */ -@SuppressWarnings("all") -public final class Requirements extends BaseGeneratedEMFQuerySpecification { - /** - * Pattern-specific match representation of the com.incquerylabs.magicdraw.benchmark.queries.requirements pattern, - * to be used in conjunction with {@link Matcher}. - * - *

Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. - * Each instance is a (possibly partial) substitution of pattern parameters, - * usable to represent a match of the pattern in the result of a query, - * or to specify the bound (fixed) input parameters when issuing a query. - * - * @see Matcher - * - */ - public static abstract class Match extends BasePatternMatch { - private com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class fClass; - - private static List parameterNames = makeImmutableList("class"); - - private Match(final com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class pClass) { - this.fClass = pClass; - } - - @Override - public Object get(final String parameterName) { - switch(parameterName) { - case "class": return this.fClass; - default: return null; - } - } - - @Override - public Object get(final int index) { - switch(index) { - case 0: return this.fClass; - default: return null; - } - } - - public com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class getValueOfClass() { - return this.fClass; - } - - @Override - public boolean set(final String parameterName, final Object newValue) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - if ("class".equals(parameterName) ) { - this.fClass = (com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class) newValue; - return true; - } - return false; - } - - public void setClass(final com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class pClass) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fClass = pClass; - } - - @Override - public String patternName() { - return "com.incquerylabs.magicdraw.benchmark.queries.requirements"; - } - - @Override - public List parameterNames() { - return Requirements.Match.parameterNames; - } - - @Override - public Object[] toArray() { - return new Object[]{fClass}; - } - - @Override - public Requirements.Match toImmutable() { - return isMutable() ? newMatch(fClass) : this; - } - - @Override - public String prettyPrint() { - StringBuilder result = new StringBuilder(); - result.append("\"class\"=" + prettyPrintValue(fClass)); - return result.toString(); - } - - @Override - public int hashCode() { - return Objects.hash(fClass); - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) - return true; - if (obj == null) { - return false; - } - if ((obj instanceof Requirements.Match)) { - Requirements.Match other = (Requirements.Match) obj; - return Objects.equals(fClass, other.fClass); - } else { - // this should be infrequent - if (!(obj instanceof IPatternMatch)) { - return false; - } - IPatternMatch otherSig = (IPatternMatch) obj; - return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); - } - } - - @Override - public Requirements specification() { - return Requirements.instance(); - } - - /** - * Returns an empty, mutable match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @return the empty match. - * - */ - public static Requirements.Match newEmptyMatch() { - return new Mutable(null); - } - - /** - * Returns a mutable (partial) match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @param pClass the fixed value of pattern parameter class, or null if not bound. - * @return the new, mutable (partial) match object. - * - */ - public static Requirements.Match newMutableMatch(final com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class pClass) { - return new Mutable(pClass); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pClass the fixed value of pattern parameter class, or null if not bound. - * @return the (partial) match object. - * - */ - public static Requirements.Match newMatch(final com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class pClass) { - return new Immutable(pClass); - } - - private static final class Mutable extends Requirements.Match { - Mutable(final com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class pClass) { - super(pClass); - } - - @Override - public boolean isMutable() { - return true; - } - } - - private static final class Immutable extends Requirements.Match { - Immutable(final com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class pClass) { - super(pClass); - } - - @Override - public boolean isMutable() { - return false; - } - } - } - - /** - * Generated pattern matcher API of the com.incquerylabs.magicdraw.benchmark.queries.requirements pattern, - * providing pattern-specific query methods. - * - *

Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, - * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. - * - *

Matches of the pattern will be represented as {@link Match}. - * - *

Original source: - *

-   * Querying all instances of an EClass that have a short "reference chain".
-   *  
-   * pattern requirements(class : Class) {
-   * 	Class.appliedStereotypeInstance.classifier.name(class, "Requirement"); 
-   * }
-   * 
- * - * @see Match - * @see Requirements - * - */ - public static class Matcher extends BaseMatcher { - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - public static Requirements.Matcher on(final ViatraQueryEngine engine) { - // check if matcher already exists - Matcher matcher = engine.getExistingMatcher(querySpecification()); - if (matcher == null) { - matcher = (Matcher)engine.getMatcher(querySpecification()); - } - return matcher; - } - - /** - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * @return an initialized matcher - * @noreference This method is for internal matcher initialization by the framework, do not call it manually. - * - */ - public static Requirements.Matcher create() { - return new Matcher(); - } - - private static final int POSITION_CLASS = 0; - - private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(Requirements.Matcher.class); - - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - private Matcher() { - super(querySpecification()); - } - - /** - * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pClass the fixed value of pattern parameter class, or null if not bound. - * @return matches represented as a Match object. - * - */ - public Collection getAllMatches(final com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class pClass) { - return rawStreamAllMatches(new Object[]{pClass}).collect(Collectors.toSet()); - } - - /** - * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * @param pClass the fixed value of pattern parameter class, or null if not bound. - * @return a stream of matches represented as a Match object. - * - */ - public Stream streamAllMatches(final com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class pClass) { - return rawStreamAllMatches(new Object[]{pClass}); - } - - /** - * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pClass the fixed value of pattern parameter class, or null if not bound. - * @return a match represented as a Match object, or null if no match is found. - * - */ - public Optional getOneArbitraryMatch(final com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class pClass) { - return rawGetOneArbitraryMatch(new Object[]{pClass}); - } - - /** - * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, - * under any possible substitution of the unspecified parameters (if any). - * @param pClass the fixed value of pattern parameter class, or null if not bound. - * @return true if the input is a valid (partial) match of the pattern. - * - */ - public boolean hasMatch(final com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class pClass) { - return rawHasMatch(new Object[]{pClass}); - } - - /** - * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pClass the fixed value of pattern parameter class, or null if not bound. - * @return the number of pattern matches found. - * - */ - public int countMatches(final com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class pClass) { - return rawCountMatches(new Object[]{pClass}); - } - - /** - * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pClass the fixed value of pattern parameter class, or null if not bound. - * @param processor the action that will process the selected match. - * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked - * - */ - public boolean forOneArbitraryMatch(final com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class pClass, final Consumer processor) { - return rawForOneArbitraryMatch(new Object[]{pClass}, processor); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pClass the fixed value of pattern parameter class, or null if not bound. - * @return the (partial) match object. - * - */ - public Requirements.Match newMatch(final com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class pClass) { - return Requirements.Match.newMatch(pClass); - } - - /** - * Retrieve the set of values that occur in matches for class. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOfclass(final Object[] parameters) { - return rawStreamAllValues(POSITION_CLASS, parameters).map(com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for class. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfclass() { - return rawStreamAllValuesOfclass(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for class. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfclass() { - return rawStreamAllValuesOfclass(emptyArray()); - } - - @Override - protected Requirements.Match tupleToMatch(final Tuple t) { - try { - return Requirements.Match.newMatch((com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class) t.get(POSITION_CLASS)); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in tuple not properly typed!",e); - return null; - } - } - - @Override - protected Requirements.Match arrayToMatch(final Object[] match) { - try { - return Requirements.Match.newMatch((com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class) match[POSITION_CLASS]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - @Override - protected Requirements.Match arrayToMatchMutable(final Object[] match) { - try { - return Requirements.Match.newMutableMatch((com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class) match[POSITION_CLASS]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - /** - * @return the singleton instance of the query specification of this pattern - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static IQuerySpecification querySpecification() { - return Requirements.instance(); - } - } - - private Requirements() { - super(GeneratedPQuery.INSTANCE); - } - - /** - * @return the singleton instance of the query specification - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static Requirements instance() { - try{ - return LazyHolder.INSTANCE; - } catch (ExceptionInInitializerError err) { - throw processInitializerError(err); - } - } - - @Override - protected Requirements.Matcher instantiate(final ViatraQueryEngine engine) { - return Requirements.Matcher.on(engine); - } - - @Override - public Requirements.Matcher instantiate() { - return Requirements.Matcher.create(); - } - - @Override - public Requirements.Match newEmptyMatch() { - return Requirements.Match.newEmptyMatch(); - } - - @Override - public Requirements.Match newMatch(final Object... parameters) { - return Requirements.Match.newMatch((com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class) parameters[0]); - } - - /** - * Inner class allowing the singleton instance of {@link Requirements} to be created - * not at the class load time of the outer class, - * but rather at the first call to {@link Requirements#instance()}. - * - *

This workaround is required e.g. to support recursion. - * - */ - private static class LazyHolder { - private static final Requirements INSTANCE = new Requirements(); - - /** - * Statically initializes the query specification after the field {@link #INSTANCE} is assigned. - * This initialization order is required to support indirect recursion. - * - *

The static initializer is defined using a helper field to work around limitations of the code generator. - * - */ - private static final Object STATIC_INITIALIZER = ensureInitialized(); - - public static Object ensureInitialized() { - INSTANCE.ensureInitializedInternal(); - return null; - } - } - - private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { - private static final Requirements.GeneratedPQuery INSTANCE = new GeneratedPQuery(); - - private final PParameter parameter_class = new PParameter("class", "com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.nomagic.com/magicdraw/UML/2.5.1", "Class")), PParameterDirection.INOUT); - - private final List parameters = Arrays.asList(parameter_class); - - private GeneratedPQuery() { - super(PVisibility.PUBLIC); - } - - @Override - public String getFullyQualifiedName() { - return "com.incquerylabs.magicdraw.benchmark.queries.requirements"; - } - - @Override - public List getParameterNames() { - return Arrays.asList("class"); - } - - @Override - public List getParameters() { - return parameters; - } - - @Override - public Set doGetContainedBodies() { - setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); - Set bodies = new LinkedHashSet<>(); - { - PBody body = new PBody(this); - PVariable var_class = body.getOrCreateVariableByName("class"); - new TypeConstraint(body, Tuples.flatTupleOf(var_class), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Class"))); - body.setSymbolicParameters(Arrays.asList( - new ExportedParameter(body, var_class, parameter_class) - )); - // Class.appliedStereotypeInstance.classifier.name(class, "Requirement") - PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); - new ConstantValue(body, var__virtual_0_, "Requirement"); - new TypeConstraint(body, Tuples.flatTupleOf(var_class), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Class"))); - PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_class, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Element", "appliedStereotypeInstance"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "InstanceSpecification"))); - PVariable var__virtual_2_ = body.getOrCreateVariableByName(".virtual{2}"); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_, var__virtual_2_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "InstanceSpecification", "classifier"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_2_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Classifier"))); - PVariable var__virtual_3_ = body.getOrCreateVariableByName(".virtual{3}"); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_2_, var__virtual_3_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "NamedElement", "name"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_3_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "String"))); - new Equality(body, var__virtual_3_, var__virtual_0_); - bodies.add(body); - } - return bodies; - } - } -} diff --git a/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/StateWithMostSubstates.java b/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/StateWithMostSubstates.java deleted file mode 100644 index 311fa78..0000000 --- a/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/StateWithMostSubstates.java +++ /dev/null @@ -1,566 +0,0 @@ -/** - * Generated from platform:/resource/com.incquerylabs.magicdraw.benchmark/src/main/java/com/incquerylabs/magicdraw/benchmark/queries/APerformanceQueries.vql - */ -package com.incquerylabs.magicdraw.benchmark.queries; - -import com.incquerylabs.magicdraw.benchmark.queries.NumberOfTransitiveSubstates; -import com.nomagic.uml2.ext.magicdraw.statemachines.mdbehaviorstatemachines.State; -import java.util.Arrays; -import java.util.Collection; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.function.Consumer; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import org.apache.log4j.Logger; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.viatra.query.runtime.api.IPatternMatch; -import org.eclipse.viatra.query.runtime.api.IQuerySpecification; -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.api.impl.BaseMatcher; -import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; -import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; -import org.eclipse.viatra.query.runtime.matchers.aggregators.max; -import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; -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.AggregatorConstraint; -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.basicenumerables.PositivePatternCall; -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.PVisibility; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; -import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; - -/** - * A pattern-specific query specification that can instantiate Matcher in a type-safe way. - * - *

Original source: - *

- *         Reusing a transitive closure and count aggregator pattern with the max aggregator.
- *          
- *         pattern stateWithMostSubstates(state : State) {
- *             // the number of substates of this state
- *             find numberOfTransitiveSubstates(state, count);
- *             // is the maximum from all states
- *         	count == max find numberOfTransitiveSubstates(_, #substateCount);
- *         }
- * 
- * - * @see Matcher - * @see Match - * - */ -@SuppressWarnings("all") -public final class StateWithMostSubstates extends BaseGeneratedEMFQuerySpecification { - /** - * Pattern-specific match representation of the com.incquerylabs.magicdraw.benchmark.queries.stateWithMostSubstates pattern, - * to be used in conjunction with {@link Matcher}. - * - *

Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. - * Each instance is a (possibly partial) substitution of pattern parameters, - * usable to represent a match of the pattern in the result of a query, - * or to specify the bound (fixed) input parameters when issuing a query. - * - * @see Matcher - * - */ - public static abstract class Match extends BasePatternMatch { - private State fState; - - private static List parameterNames = makeImmutableList("state"); - - private Match(final State pState) { - this.fState = pState; - } - - @Override - public Object get(final String parameterName) { - switch(parameterName) { - case "state": return this.fState; - default: return null; - } - } - - @Override - public Object get(final int index) { - switch(index) { - case 0: return this.fState; - default: return null; - } - } - - public State getState() { - return this.fState; - } - - @Override - public boolean set(final String parameterName, final Object newValue) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - if ("state".equals(parameterName) ) { - this.fState = (State) newValue; - return true; - } - return false; - } - - public void setState(final State pState) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fState = pState; - } - - @Override - public String patternName() { - return "com.incquerylabs.magicdraw.benchmark.queries.stateWithMostSubstates"; - } - - @Override - public List parameterNames() { - return StateWithMostSubstates.Match.parameterNames; - } - - @Override - public Object[] toArray() { - return new Object[]{fState}; - } - - @Override - public StateWithMostSubstates.Match toImmutable() { - return isMutable() ? newMatch(fState) : this; - } - - @Override - public String prettyPrint() { - StringBuilder result = new StringBuilder(); - result.append("\"state\"=" + prettyPrintValue(fState)); - return result.toString(); - } - - @Override - public int hashCode() { - return Objects.hash(fState); - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) - return true; - if (obj == null) { - return false; - } - if ((obj instanceof StateWithMostSubstates.Match)) { - StateWithMostSubstates.Match other = (StateWithMostSubstates.Match) obj; - return Objects.equals(fState, other.fState); - } else { - // this should be infrequent - if (!(obj instanceof IPatternMatch)) { - return false; - } - IPatternMatch otherSig = (IPatternMatch) obj; - return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); - } - } - - @Override - public StateWithMostSubstates specification() { - return StateWithMostSubstates.instance(); - } - - /** - * Returns an empty, mutable match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @return the empty match. - * - */ - public static StateWithMostSubstates.Match newEmptyMatch() { - return new Mutable(null); - } - - /** - * Returns a mutable (partial) match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @return the new, mutable (partial) match object. - * - */ - public static StateWithMostSubstates.Match newMutableMatch(final State pState) { - return new Mutable(pState); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @return the (partial) match object. - * - */ - public static StateWithMostSubstates.Match newMatch(final State pState) { - return new Immutable(pState); - } - - private static final class Mutable extends StateWithMostSubstates.Match { - Mutable(final State pState) { - super(pState); - } - - @Override - public boolean isMutable() { - return true; - } - } - - private static final class Immutable extends StateWithMostSubstates.Match { - Immutable(final State pState) { - super(pState); - } - - @Override - public boolean isMutable() { - return false; - } - } - } - - /** - * Generated pattern matcher API of the com.incquerylabs.magicdraw.benchmark.queries.stateWithMostSubstates pattern, - * providing pattern-specific query methods. - * - *

Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, - * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. - * - *

Matches of the pattern will be represented as {@link Match}. - * - *

Original source: - *

-   * Reusing a transitive closure and count aggregator pattern with the max aggregator.
-   *  
-   * pattern stateWithMostSubstates(state : State) {
-   *     // the number of substates of this state
-   *     find numberOfTransitiveSubstates(state, count);
-   *     // is the maximum from all states
-   * 	count == max find numberOfTransitiveSubstates(_, #substateCount);
-   * }
-   * 
- * - * @see Match - * @see StateWithMostSubstates - * - */ - public static class Matcher extends BaseMatcher { - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - public static StateWithMostSubstates.Matcher on(final ViatraQueryEngine engine) { - // check if matcher already exists - Matcher matcher = engine.getExistingMatcher(querySpecification()); - if (matcher == null) { - matcher = (Matcher)engine.getMatcher(querySpecification()); - } - return matcher; - } - - /** - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * @return an initialized matcher - * @noreference This method is for internal matcher initialization by the framework, do not call it manually. - * - */ - public static StateWithMostSubstates.Matcher create() { - return new Matcher(); - } - - private static final int POSITION_STATE = 0; - - private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(StateWithMostSubstates.Matcher.class); - - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - private Matcher() { - super(querySpecification()); - } - - /** - * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @return matches represented as a Match object. - * - */ - public Collection getAllMatches(final State pState) { - return rawStreamAllMatches(new Object[]{pState}).collect(Collectors.toSet()); - } - - /** - * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @return a stream of matches represented as a Match object. - * - */ - public Stream streamAllMatches(final State pState) { - return rawStreamAllMatches(new Object[]{pState}); - } - - /** - * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @return a match represented as a Match object, or null if no match is found. - * - */ - public Optional getOneArbitraryMatch(final State pState) { - return rawGetOneArbitraryMatch(new Object[]{pState}); - } - - /** - * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, - * under any possible substitution of the unspecified parameters (if any). - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @return true if the input is a valid (partial) match of the pattern. - * - */ - public boolean hasMatch(final State pState) { - return rawHasMatch(new Object[]{pState}); - } - - /** - * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @return the number of pattern matches found. - * - */ - public int countMatches(final State pState) { - return rawCountMatches(new Object[]{pState}); - } - - /** - * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param processor the action that will process the selected match. - * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked - * - */ - public boolean forOneArbitraryMatch(final State pState, final Consumer processor) { - return rawForOneArbitraryMatch(new Object[]{pState}, processor); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @return the (partial) match object. - * - */ - public StateWithMostSubstates.Match newMatch(final State pState) { - return StateWithMostSubstates.Match.newMatch(pState); - } - - /** - * Retrieve the set of values that occur in matches for state. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOfstate(final Object[] parameters) { - return rawStreamAllValues(POSITION_STATE, parameters).map(State.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for state. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfstate() { - return rawStreamAllValuesOfstate(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for state. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfstate() { - return rawStreamAllValuesOfstate(emptyArray()); - } - - @Override - protected StateWithMostSubstates.Match tupleToMatch(final Tuple t) { - try { - return StateWithMostSubstates.Match.newMatch((State) t.get(POSITION_STATE)); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in tuple not properly typed!",e); - return null; - } - } - - @Override - protected StateWithMostSubstates.Match arrayToMatch(final Object[] match) { - try { - return StateWithMostSubstates.Match.newMatch((State) match[POSITION_STATE]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - @Override - protected StateWithMostSubstates.Match arrayToMatchMutable(final Object[] match) { - try { - return StateWithMostSubstates.Match.newMutableMatch((State) match[POSITION_STATE]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - /** - * @return the singleton instance of the query specification of this pattern - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static IQuerySpecification querySpecification() { - return StateWithMostSubstates.instance(); - } - } - - private StateWithMostSubstates() { - super(GeneratedPQuery.INSTANCE); - } - - /** - * @return the singleton instance of the query specification - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static StateWithMostSubstates instance() { - try{ - return LazyHolder.INSTANCE; - } catch (ExceptionInInitializerError err) { - throw processInitializerError(err); - } - } - - @Override - protected StateWithMostSubstates.Matcher instantiate(final ViatraQueryEngine engine) { - return StateWithMostSubstates.Matcher.on(engine); - } - - @Override - public StateWithMostSubstates.Matcher instantiate() { - return StateWithMostSubstates.Matcher.create(); - } - - @Override - public StateWithMostSubstates.Match newEmptyMatch() { - return StateWithMostSubstates.Match.newEmptyMatch(); - } - - @Override - public StateWithMostSubstates.Match newMatch(final Object... parameters) { - return StateWithMostSubstates.Match.newMatch((com.nomagic.uml2.ext.magicdraw.statemachines.mdbehaviorstatemachines.State) parameters[0]); - } - - /** - * Inner class allowing the singleton instance of {@link StateWithMostSubstates} to be created - * not at the class load time of the outer class, - * but rather at the first call to {@link StateWithMostSubstates#instance()}. - * - *

This workaround is required e.g. to support recursion. - * - */ - private static class LazyHolder { - private static final StateWithMostSubstates INSTANCE = new StateWithMostSubstates(); - - /** - * Statically initializes the query specification after the field {@link #INSTANCE} is assigned. - * This initialization order is required to support indirect recursion. - * - *

The static initializer is defined using a helper field to work around limitations of the code generator. - * - */ - private static final Object STATIC_INITIALIZER = ensureInitialized(); - - public static Object ensureInitialized() { - INSTANCE.ensureInitializedInternal(); - return null; - } - } - - private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { - private static final StateWithMostSubstates.GeneratedPQuery INSTANCE = new GeneratedPQuery(); - - private final PParameter parameter_state = new PParameter("state", "com.nomagic.uml2.ext.magicdraw.statemachines.mdbehaviorstatemachines.State", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.nomagic.com/magicdraw/UML/2.5.1", "State")), PParameterDirection.INOUT); - - private final List parameters = Arrays.asList(parameter_state); - - private GeneratedPQuery() { - super(PVisibility.PUBLIC); - } - - @Override - public String getFullyQualifiedName() { - return "com.incquerylabs.magicdraw.benchmark.queries.stateWithMostSubstates"; - } - - @Override - public List getParameterNames() { - return Arrays.asList("state"); - } - - @Override - public List getParameters() { - return parameters; - } - - @Override - public Set doGetContainedBodies() { - setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); - Set bodies = new LinkedHashSet<>(); - { - PBody body = new PBody(this); - PVariable var_state = body.getOrCreateVariableByName("state"); - PVariable var_count = body.getOrCreateVariableByName("count"); - PVariable var___0_ = body.getOrCreateVariableByName("_<0>"); - PVariable var__substateCount = body.getOrCreateVariableByName("#substateCount"); - new TypeConstraint(body, Tuples.flatTupleOf(var_state), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "State"))); - body.setSymbolicParameters(Arrays.asList( - new ExportedParameter(body, var_state, parameter_state) - )); - // // the number of substates of this state find numberOfTransitiveSubstates(state, count) - new PositivePatternCall(body, Tuples.flatTupleOf(var_state, var_count), NumberOfTransitiveSubstates.instance().getInternalQueryRepresentation()); - // // is the maximum from all states count == max find numberOfTransitiveSubstates(_, #substateCount) - PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); - new AggregatorConstraint(new max().getAggregatorLogic(Integer.class), body, Tuples.flatTupleOf(var___0_, var__substateCount), NumberOfTransitiveSubstates.instance().getInternalQueryRepresentation(), var__virtual_0_, 1); - new Equality(body, var_count, var__virtual_0_); - bodies.add(body); - } - return bodies; - } - } -} diff --git a/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/StatesWithMoreIncomingTransitions.java b/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/StatesWithMoreIncomingTransitions.java deleted file mode 100644 index b0e9cef..0000000 --- a/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/StatesWithMoreIncomingTransitions.java +++ /dev/null @@ -1,582 +0,0 @@ -/** - * Generated from platform:/resource/com.incquerylabs.magicdraw.benchmark/src/main/java/com/incquerylabs/magicdraw/benchmark/queries/APerformanceQueries.vql - */ -package com.incquerylabs.magicdraw.benchmark.queries; - -import com.incquerylabs.magicdraw.benchmark.queries.IncomingTransitions; -import com.nomagic.uml2.ext.magicdraw.statemachines.mdbehaviorstatemachines.State; -import java.util.Arrays; -import java.util.Collection; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.function.Consumer; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import org.apache.log4j.Logger; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.viatra.query.runtime.api.IPatternMatch; -import org.eclipse.viatra.query.runtime.api.IQuerySpecification; -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.api.impl.BaseMatcher; -import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; -import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; -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.basicdeferred.PatternMatchCounter; -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.PVisibility; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; -import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; - -/** - * A pattern-specific query specification that can instantiate Matcher in a type-safe way. - * - *

Original source: - *

- *         Reusing a simple pattern with a check expression. Made for reuse.
- *          
- *         pattern statesWithMoreIncomingTransitions(state : State)  {
- *         	transitionCount == count find incomingTransitions(_, state);
- *         	check (transitionCount {@literal >} 1);
- *         }
- * 
- * - * @see Matcher - * @see Match - * - */ -@SuppressWarnings("all") -public final class StatesWithMoreIncomingTransitions extends BaseGeneratedEMFQuerySpecification { - /** - * Pattern-specific match representation of the com.incquerylabs.magicdraw.benchmark.queries.statesWithMoreIncomingTransitions pattern, - * to be used in conjunction with {@link Matcher}. - * - *

Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. - * Each instance is a (possibly partial) substitution of pattern parameters, - * usable to represent a match of the pattern in the result of a query, - * or to specify the bound (fixed) input parameters when issuing a query. - * - * @see Matcher - * - */ - public static abstract class Match extends BasePatternMatch { - private State fState; - - private static List parameterNames = makeImmutableList("state"); - - private Match(final State pState) { - this.fState = pState; - } - - @Override - public Object get(final String parameterName) { - switch(parameterName) { - case "state": return this.fState; - default: return null; - } - } - - @Override - public Object get(final int index) { - switch(index) { - case 0: return this.fState; - default: return null; - } - } - - public State getState() { - return this.fState; - } - - @Override - public boolean set(final String parameterName, final Object newValue) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - if ("state".equals(parameterName) ) { - this.fState = (State) newValue; - return true; - } - return false; - } - - public void setState(final State pState) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fState = pState; - } - - @Override - public String patternName() { - return "com.incquerylabs.magicdraw.benchmark.queries.statesWithMoreIncomingTransitions"; - } - - @Override - public List parameterNames() { - return StatesWithMoreIncomingTransitions.Match.parameterNames; - } - - @Override - public Object[] toArray() { - return new Object[]{fState}; - } - - @Override - public StatesWithMoreIncomingTransitions.Match toImmutable() { - return isMutable() ? newMatch(fState) : this; - } - - @Override - public String prettyPrint() { - StringBuilder result = new StringBuilder(); - result.append("\"state\"=" + prettyPrintValue(fState)); - return result.toString(); - } - - @Override - public int hashCode() { - return Objects.hash(fState); - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) - return true; - if (obj == null) { - return false; - } - if ((obj instanceof StatesWithMoreIncomingTransitions.Match)) { - StatesWithMoreIncomingTransitions.Match other = (StatesWithMoreIncomingTransitions.Match) obj; - return Objects.equals(fState, other.fState); - } else { - // this should be infrequent - if (!(obj instanceof IPatternMatch)) { - return false; - } - IPatternMatch otherSig = (IPatternMatch) obj; - return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); - } - } - - @Override - public StatesWithMoreIncomingTransitions specification() { - return StatesWithMoreIncomingTransitions.instance(); - } - - /** - * Returns an empty, mutable match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @return the empty match. - * - */ - public static StatesWithMoreIncomingTransitions.Match newEmptyMatch() { - return new Mutable(null); - } - - /** - * Returns a mutable (partial) match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @return the new, mutable (partial) match object. - * - */ - public static StatesWithMoreIncomingTransitions.Match newMutableMatch(final State pState) { - return new Mutable(pState); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @return the (partial) match object. - * - */ - public static StatesWithMoreIncomingTransitions.Match newMatch(final State pState) { - return new Immutable(pState); - } - - private static final class Mutable extends StatesWithMoreIncomingTransitions.Match { - Mutable(final State pState) { - super(pState); - } - - @Override - public boolean isMutable() { - return true; - } - } - - private static final class Immutable extends StatesWithMoreIncomingTransitions.Match { - Immutable(final State pState) { - super(pState); - } - - @Override - public boolean isMutable() { - return false; - } - } - } - - /** - * Generated pattern matcher API of the com.incquerylabs.magicdraw.benchmark.queries.statesWithMoreIncomingTransitions pattern, - * providing pattern-specific query methods. - * - *

Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, - * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. - * - *

Matches of the pattern will be represented as {@link Match}. - * - *

Original source: - *

-   * Reusing a simple pattern with a check expression. Made for reuse.
-   *  
-   * pattern statesWithMoreIncomingTransitions(state : State)  {
-   * 	transitionCount == count find incomingTransitions(_, state);
-   * 	check (transitionCount {@literal >} 1);
-   * }
-   * 
- * - * @see Match - * @see StatesWithMoreIncomingTransitions - * - */ - public static class Matcher extends BaseMatcher { - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - public static StatesWithMoreIncomingTransitions.Matcher on(final ViatraQueryEngine engine) { - // check if matcher already exists - Matcher matcher = engine.getExistingMatcher(querySpecification()); - if (matcher == null) { - matcher = (Matcher)engine.getMatcher(querySpecification()); - } - return matcher; - } - - /** - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * @return an initialized matcher - * @noreference This method is for internal matcher initialization by the framework, do not call it manually. - * - */ - public static StatesWithMoreIncomingTransitions.Matcher create() { - return new Matcher(); - } - - private static final int POSITION_STATE = 0; - - private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(StatesWithMoreIncomingTransitions.Matcher.class); - - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - private Matcher() { - super(querySpecification()); - } - - /** - * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @return matches represented as a Match object. - * - */ - public Collection getAllMatches(final State pState) { - return rawStreamAllMatches(new Object[]{pState}).collect(Collectors.toSet()); - } - - /** - * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @return a stream of matches represented as a Match object. - * - */ - public Stream streamAllMatches(final State pState) { - return rawStreamAllMatches(new Object[]{pState}); - } - - /** - * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @return a match represented as a Match object, or null if no match is found. - * - */ - public Optional getOneArbitraryMatch(final State pState) { - return rawGetOneArbitraryMatch(new Object[]{pState}); - } - - /** - * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, - * under any possible substitution of the unspecified parameters (if any). - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @return true if the input is a valid (partial) match of the pattern. - * - */ - public boolean hasMatch(final State pState) { - return rawHasMatch(new Object[]{pState}); - } - - /** - * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @return the number of pattern matches found. - * - */ - public int countMatches(final State pState) { - return rawCountMatches(new Object[]{pState}); - } - - /** - * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param processor the action that will process the selected match. - * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked - * - */ - public boolean forOneArbitraryMatch(final State pState, final Consumer processor) { - return rawForOneArbitraryMatch(new Object[]{pState}, processor); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @return the (partial) match object. - * - */ - public StatesWithMoreIncomingTransitions.Match newMatch(final State pState) { - return StatesWithMoreIncomingTransitions.Match.newMatch(pState); - } - - /** - * Retrieve the set of values that occur in matches for state. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOfstate(final Object[] parameters) { - return rawStreamAllValues(POSITION_STATE, parameters).map(State.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for state. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfstate() { - return rawStreamAllValuesOfstate(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for state. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfstate() { - return rawStreamAllValuesOfstate(emptyArray()); - } - - @Override - protected StatesWithMoreIncomingTransitions.Match tupleToMatch(final Tuple t) { - try { - return StatesWithMoreIncomingTransitions.Match.newMatch((State) t.get(POSITION_STATE)); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in tuple not properly typed!",e); - return null; - } - } - - @Override - protected StatesWithMoreIncomingTransitions.Match arrayToMatch(final Object[] match) { - try { - return StatesWithMoreIncomingTransitions.Match.newMatch((State) match[POSITION_STATE]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - @Override - protected StatesWithMoreIncomingTransitions.Match arrayToMatchMutable(final Object[] match) { - try { - return StatesWithMoreIncomingTransitions.Match.newMutableMatch((State) match[POSITION_STATE]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - /** - * @return the singleton instance of the query specification of this pattern - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static IQuerySpecification querySpecification() { - return StatesWithMoreIncomingTransitions.instance(); - } - } - - private StatesWithMoreIncomingTransitions() { - super(GeneratedPQuery.INSTANCE); - } - - /** - * @return the singleton instance of the query specification - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static StatesWithMoreIncomingTransitions instance() { - try{ - return LazyHolder.INSTANCE; - } catch (ExceptionInInitializerError err) { - throw processInitializerError(err); - } - } - - @Override - protected StatesWithMoreIncomingTransitions.Matcher instantiate(final ViatraQueryEngine engine) { - return StatesWithMoreIncomingTransitions.Matcher.on(engine); - } - - @Override - public StatesWithMoreIncomingTransitions.Matcher instantiate() { - return StatesWithMoreIncomingTransitions.Matcher.create(); - } - - @Override - public StatesWithMoreIncomingTransitions.Match newEmptyMatch() { - return StatesWithMoreIncomingTransitions.Match.newEmptyMatch(); - } - - @Override - public StatesWithMoreIncomingTransitions.Match newMatch(final Object... parameters) { - return StatesWithMoreIncomingTransitions.Match.newMatch((com.nomagic.uml2.ext.magicdraw.statemachines.mdbehaviorstatemachines.State) parameters[0]); - } - - /** - * Inner class allowing the singleton instance of {@link StatesWithMoreIncomingTransitions} to be created - * not at the class load time of the outer class, - * but rather at the first call to {@link StatesWithMoreIncomingTransitions#instance()}. - * - *

This workaround is required e.g. to support recursion. - * - */ - private static class LazyHolder { - private static final StatesWithMoreIncomingTransitions INSTANCE = new StatesWithMoreIncomingTransitions(); - - /** - * Statically initializes the query specification after the field {@link #INSTANCE} is assigned. - * This initialization order is required to support indirect recursion. - * - *

The static initializer is defined using a helper field to work around limitations of the code generator. - * - */ - private static final Object STATIC_INITIALIZER = ensureInitialized(); - - public static Object ensureInitialized() { - INSTANCE.ensureInitializedInternal(); - return null; - } - } - - private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { - private static final StatesWithMoreIncomingTransitions.GeneratedPQuery INSTANCE = new GeneratedPQuery(); - - private final PParameter parameter_state = new PParameter("state", "com.nomagic.uml2.ext.magicdraw.statemachines.mdbehaviorstatemachines.State", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.nomagic.com/magicdraw/UML/2.5.1", "State")), PParameterDirection.INOUT); - - private final List parameters = Arrays.asList(parameter_state); - - private GeneratedPQuery() { - super(PVisibility.PUBLIC); - } - - @Override - public String getFullyQualifiedName() { - return "com.incquerylabs.magicdraw.benchmark.queries.statesWithMoreIncomingTransitions"; - } - - @Override - public List getParameterNames() { - return Arrays.asList("state"); - } - - @Override - public List getParameters() { - return parameters; - } - - @Override - public Set doGetContainedBodies() { - setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); - Set bodies = new LinkedHashSet<>(); - { - PBody body = new PBody(this); - PVariable var_state = body.getOrCreateVariableByName("state"); - PVariable var_transitionCount = body.getOrCreateVariableByName("transitionCount"); - PVariable var___0_ = body.getOrCreateVariableByName("_<0>"); - new TypeConstraint(body, Tuples.flatTupleOf(var_state), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "State"))); - body.setSymbolicParameters(Arrays.asList( - new ExportedParameter(body, var_state, parameter_state) - )); - // transitionCount == count find incomingTransitions(_, state) - PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); - new PatternMatchCounter(body, Tuples.flatTupleOf(var___0_, var_state), IncomingTransitions.instance().getInternalQueryRepresentation(), var__virtual_0_); - new Equality(body, var_transitionCount, var__virtual_0_); - // check (transitionCount > 1) - new ExpressionEvaluation(body, new IExpressionEvaluator() { - - @Override - public String getShortDescription() { - return "Expression evaluation from pattern statesWithMoreIncomingTransitions"; - } - - @Override - public Iterable getInputParameterNames() { - return Arrays.asList("transitionCount");} - - @Override - public Object evaluateExpression(IValueProvider provider) throws Exception { - Integer transitionCount = (Integer) provider.getValue("transitionCount"); - return evaluateExpression_1_1(transitionCount); - } - }, null); - bodies.add(body); - } - return bodies; - } - } - - private static boolean evaluateExpression_1_1(final Integer transitionCount) { - return ((transitionCount).intValue() > 1); - } -} diff --git a/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/StatesWithShortNames.java b/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/StatesWithShortNames.java deleted file mode 100644 index c9c9ba8..0000000 --- a/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/StatesWithShortNames.java +++ /dev/null @@ -1,600 +0,0 @@ -/** - * Generated from platform:/resource/com.incquerylabs.magicdraw.benchmark/src/main/java/com/incquerylabs/magicdraw/benchmark/queries/APerformanceQueries.vql - */ -package com.incquerylabs.magicdraw.benchmark.queries; - -import com.nomagic.uml2.ext.magicdraw.statemachines.mdbehaviorstatemachines.State; -import java.util.Arrays; -import java.util.Collection; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.function.Consumer; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import org.apache.log4j.Logger; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.emf.ecore.EDataType; -import org.eclipse.viatra.query.runtime.api.IPatternMatch; -import org.eclipse.viatra.query.runtime.api.IQuerySpecification; -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.api.impl.BaseMatcher; -import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; -import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; -import org.eclipse.viatra.query.runtime.emf.types.EDataTypeInSlotsKey; -import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey; -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.PVisibility; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; -import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; - -/** - * A pattern-specific query specification that can instantiate Matcher in a type-safe way. - * - *

Original source: - *

- *         Reusing a simple pattern with transitive closure.
- *          
- *         //pattern transitiveSubstates(state : State, transitiveSubstate : State) {	
- *         //	find parentState+(transitiveSubstate, state);
- *         //}
- *         
- *         
- *           Returns states with short names.
- *          
- *         pattern statesWithShortNames(state : State) {
- *         	State.name(state, name);
- *         	check(name.length {@literal <} 6);
- *         }
- * 
- * - * @see Matcher - * @see Match - * - */ -@SuppressWarnings("all") -public final class StatesWithShortNames extends BaseGeneratedEMFQuerySpecification { - /** - * Pattern-specific match representation of the com.incquerylabs.magicdraw.benchmark.queries.statesWithShortNames pattern, - * to be used in conjunction with {@link Matcher}. - * - *

Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. - * Each instance is a (possibly partial) substitution of pattern parameters, - * usable to represent a match of the pattern in the result of a query, - * or to specify the bound (fixed) input parameters when issuing a query. - * - * @see Matcher - * - */ - public static abstract class Match extends BasePatternMatch { - private State fState; - - private static List parameterNames = makeImmutableList("state"); - - private Match(final State pState) { - this.fState = pState; - } - - @Override - public Object get(final String parameterName) { - switch(parameterName) { - case "state": return this.fState; - default: return null; - } - } - - @Override - public Object get(final int index) { - switch(index) { - case 0: return this.fState; - default: return null; - } - } - - public State getState() { - return this.fState; - } - - @Override - public boolean set(final String parameterName, final Object newValue) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - if ("state".equals(parameterName) ) { - this.fState = (State) newValue; - return true; - } - return false; - } - - public void setState(final State pState) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fState = pState; - } - - @Override - public String patternName() { - return "com.incquerylabs.magicdraw.benchmark.queries.statesWithShortNames"; - } - - @Override - public List parameterNames() { - return StatesWithShortNames.Match.parameterNames; - } - - @Override - public Object[] toArray() { - return new Object[]{fState}; - } - - @Override - public StatesWithShortNames.Match toImmutable() { - return isMutable() ? newMatch(fState) : this; - } - - @Override - public String prettyPrint() { - StringBuilder result = new StringBuilder(); - result.append("\"state\"=" + prettyPrintValue(fState)); - return result.toString(); - } - - @Override - public int hashCode() { - return Objects.hash(fState); - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) - return true; - if (obj == null) { - return false; - } - if ((obj instanceof StatesWithShortNames.Match)) { - StatesWithShortNames.Match other = (StatesWithShortNames.Match) obj; - return Objects.equals(fState, other.fState); - } else { - // this should be infrequent - if (!(obj instanceof IPatternMatch)) { - return false; - } - IPatternMatch otherSig = (IPatternMatch) obj; - return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); - } - } - - @Override - public StatesWithShortNames specification() { - return StatesWithShortNames.instance(); - } - - /** - * Returns an empty, mutable match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @return the empty match. - * - */ - public static StatesWithShortNames.Match newEmptyMatch() { - return new Mutable(null); - } - - /** - * Returns a mutable (partial) match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @return the new, mutable (partial) match object. - * - */ - public static StatesWithShortNames.Match newMutableMatch(final State pState) { - return new Mutable(pState); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @return the (partial) match object. - * - */ - public static StatesWithShortNames.Match newMatch(final State pState) { - return new Immutable(pState); - } - - private static final class Mutable extends StatesWithShortNames.Match { - Mutable(final State pState) { - super(pState); - } - - @Override - public boolean isMutable() { - return true; - } - } - - private static final class Immutable extends StatesWithShortNames.Match { - Immutable(final State pState) { - super(pState); - } - - @Override - public boolean isMutable() { - return false; - } - } - } - - /** - * Generated pattern matcher API of the com.incquerylabs.magicdraw.benchmark.queries.statesWithShortNames pattern, - * providing pattern-specific query methods. - * - *

Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, - * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. - * - *

Matches of the pattern will be represented as {@link Match}. - * - *

Original source: - *

-   * Reusing a simple pattern with transitive closure.
-   *  
-   * //pattern transitiveSubstates(state : State, transitiveSubstate : State) {	
-   * //	find parentState+(transitiveSubstate, state);
-   * //}
-   * 
-   * 
-   *   Returns states with short names.
-   *  
-   * pattern statesWithShortNames(state : State) {
-   * 	State.name(state, name);
-   * 	check(name.length {@literal <} 6);
-   * }
-   * 
- * - * @see Match - * @see StatesWithShortNames - * - */ - public static class Matcher extends BaseMatcher { - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - public static StatesWithShortNames.Matcher on(final ViatraQueryEngine engine) { - // check if matcher already exists - Matcher matcher = engine.getExistingMatcher(querySpecification()); - if (matcher == null) { - matcher = (Matcher)engine.getMatcher(querySpecification()); - } - return matcher; - } - - /** - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * @return an initialized matcher - * @noreference This method is for internal matcher initialization by the framework, do not call it manually. - * - */ - public static StatesWithShortNames.Matcher create() { - return new Matcher(); - } - - private static final int POSITION_STATE = 0; - - private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(StatesWithShortNames.Matcher.class); - - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - private Matcher() { - super(querySpecification()); - } - - /** - * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @return matches represented as a Match object. - * - */ - public Collection getAllMatches(final State pState) { - return rawStreamAllMatches(new Object[]{pState}).collect(Collectors.toSet()); - } - - /** - * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @return a stream of matches represented as a Match object. - * - */ - public Stream streamAllMatches(final State pState) { - return rawStreamAllMatches(new Object[]{pState}); - } - - /** - * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @return a match represented as a Match object, or null if no match is found. - * - */ - public Optional getOneArbitraryMatch(final State pState) { - return rawGetOneArbitraryMatch(new Object[]{pState}); - } - - /** - * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, - * under any possible substitution of the unspecified parameters (if any). - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @return true if the input is a valid (partial) match of the pattern. - * - */ - public boolean hasMatch(final State pState) { - return rawHasMatch(new Object[]{pState}); - } - - /** - * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @return the number of pattern matches found. - * - */ - public int countMatches(final State pState) { - return rawCountMatches(new Object[]{pState}); - } - - /** - * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param processor the action that will process the selected match. - * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked - * - */ - public boolean forOneArbitraryMatch(final State pState, final Consumer processor) { - return rawForOneArbitraryMatch(new Object[]{pState}, processor); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @return the (partial) match object. - * - */ - public StatesWithShortNames.Match newMatch(final State pState) { - return StatesWithShortNames.Match.newMatch(pState); - } - - /** - * Retrieve the set of values that occur in matches for state. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOfstate(final Object[] parameters) { - return rawStreamAllValues(POSITION_STATE, parameters).map(State.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for state. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfstate() { - return rawStreamAllValuesOfstate(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for state. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfstate() { - return rawStreamAllValuesOfstate(emptyArray()); - } - - @Override - protected StatesWithShortNames.Match tupleToMatch(final Tuple t) { - try { - return StatesWithShortNames.Match.newMatch((State) t.get(POSITION_STATE)); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in tuple not properly typed!",e); - return null; - } - } - - @Override - protected StatesWithShortNames.Match arrayToMatch(final Object[] match) { - try { - return StatesWithShortNames.Match.newMatch((State) match[POSITION_STATE]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - @Override - protected StatesWithShortNames.Match arrayToMatchMutable(final Object[] match) { - try { - return StatesWithShortNames.Match.newMutableMatch((State) match[POSITION_STATE]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - /** - * @return the singleton instance of the query specification of this pattern - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static IQuerySpecification querySpecification() { - return StatesWithShortNames.instance(); - } - } - - private StatesWithShortNames() { - super(GeneratedPQuery.INSTANCE); - } - - /** - * @return the singleton instance of the query specification - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static StatesWithShortNames instance() { - try{ - return LazyHolder.INSTANCE; - } catch (ExceptionInInitializerError err) { - throw processInitializerError(err); - } - } - - @Override - protected StatesWithShortNames.Matcher instantiate(final ViatraQueryEngine engine) { - return StatesWithShortNames.Matcher.on(engine); - } - - @Override - public StatesWithShortNames.Matcher instantiate() { - return StatesWithShortNames.Matcher.create(); - } - - @Override - public StatesWithShortNames.Match newEmptyMatch() { - return StatesWithShortNames.Match.newEmptyMatch(); - } - - @Override - public StatesWithShortNames.Match newMatch(final Object... parameters) { - return StatesWithShortNames.Match.newMatch((com.nomagic.uml2.ext.magicdraw.statemachines.mdbehaviorstatemachines.State) parameters[0]); - } - - /** - * Inner class allowing the singleton instance of {@link StatesWithShortNames} to be created - * not at the class load time of the outer class, - * but rather at the first call to {@link StatesWithShortNames#instance()}. - * - *

This workaround is required e.g. to support recursion. - * - */ - private static class LazyHolder { - private static final StatesWithShortNames INSTANCE = new StatesWithShortNames(); - - /** - * Statically initializes the query specification after the field {@link #INSTANCE} is assigned. - * This initialization order is required to support indirect recursion. - * - *

The static initializer is defined using a helper field to work around limitations of the code generator. - * - */ - private static final Object STATIC_INITIALIZER = ensureInitialized(); - - public static Object ensureInitialized() { - INSTANCE.ensureInitializedInternal(); - return null; - } - } - - private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { - private static final StatesWithShortNames.GeneratedPQuery INSTANCE = new GeneratedPQuery(); - - private final PParameter parameter_state = new PParameter("state", "com.nomagic.uml2.ext.magicdraw.statemachines.mdbehaviorstatemachines.State", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.nomagic.com/magicdraw/UML/2.5.1", "State")), PParameterDirection.INOUT); - - private final List parameters = Arrays.asList(parameter_state); - - private GeneratedPQuery() { - super(PVisibility.PUBLIC); - } - - @Override - public String getFullyQualifiedName() { - return "com.incquerylabs.magicdraw.benchmark.queries.statesWithShortNames"; - } - - @Override - public List getParameterNames() { - return Arrays.asList("state"); - } - - @Override - public List getParameters() { - return parameters; - } - - @Override - public Set doGetContainedBodies() { - setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); - Set bodies = new LinkedHashSet<>(); - { - PBody body = new PBody(this); - PVariable var_state = body.getOrCreateVariableByName("state"); - PVariable var_name = body.getOrCreateVariableByName("name"); - new TypeConstraint(body, Tuples.flatTupleOf(var_state), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "State"))); - body.setSymbolicParameters(Arrays.asList( - new ExportedParameter(body, var_state, parameter_state) - )); - // State.name(state, name) - new TypeConstraint(body, Tuples.flatTupleOf(var_state), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "State"))); - PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_state, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "NamedElement", "name"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "String"))); - new Equality(body, var__virtual_0_, var_name); - // check(name.length < 6) - new ExpressionEvaluation(body, new IExpressionEvaluator() { - - @Override - public String getShortDescription() { - return "Expression evaluation from pattern statesWithShortNames"; - } - - @Override - public Iterable getInputParameterNames() { - return Arrays.asList("name");} - - @Override - public Object evaluateExpression(IValueProvider provider) throws Exception { - String name = (String) provider.getValue("name"); - return evaluateExpression_1_1(name); - } - }, null); - bodies.add(body); - } - return bodies; - } - } - - private static boolean evaluateExpression_1_1(final String name) { - int _length = name.length(); - boolean _lessThan = (_length < 6); - return _lessThan; - } -} diff --git a/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/Subregions.java b/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/Subregions.java deleted file mode 100644 index 1f2f65c..0000000 --- a/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/Subregions.java +++ /dev/null @@ -1,737 +0,0 @@ -/** - * Generated from platform:/resource/com.incquerylabs.magicdraw.benchmark/src/main/java/com/incquerylabs/magicdraw/benchmark/queries/APerformanceQueries.vql - */ -package com.incquerylabs.magicdraw.benchmark.queries; - -import com.nomagic.uml2.ext.magicdraw.statemachines.mdbehaviorstatemachines.Region; -import com.nomagic.uml2.ext.magicdraw.statemachines.mdbehaviorstatemachines.State; -import java.util.Arrays; -import java.util.Collection; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.function.Consumer; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import org.apache.log4j.Logger; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.viatra.query.runtime.api.IPatternMatch; -import org.eclipse.viatra.query.runtime.api.IQuerySpecification; -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.api.impl.BaseMatcher; -import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; -import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; -import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey; -import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; -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.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.PVisibility; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; -import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; - -/** - * A pattern-specific query specification that can instantiate Matcher in a type-safe way. - * - *

Original source: - *

- *         Using recursion, eval and disjunction.
- *           Cannot be evaluated using local search because of recursion!
- *          
- *         //pattern qualifiedStateName(state : State, name : java ^java.lang.String) {
- *         //	find parentState(state, parentState);
- *         //    State.name(state, simpleName);
- *         //    find qualifiedStateName(parentState, parentName);
- *         //    name == eval (parentName + "." + simpleName);
- *         //} or { 
- *         //    neg find parentState(state, _);
- *         //    State.name(state, name);
- *         //}
- *         
- *         
- *           Simple pattern for aggregators.
- *          
- *         pattern subregions(state : State, subregion : Region) {
- *           	State.region(state, subregion);
- *         }
- * 
- * - * @see Matcher - * @see Match - * - */ -@SuppressWarnings("all") -public final class Subregions extends BaseGeneratedEMFQuerySpecification { - /** - * Pattern-specific match representation of the com.incquerylabs.magicdraw.benchmark.queries.subregions pattern, - * to be used in conjunction with {@link Matcher}. - * - *

Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. - * Each instance is a (possibly partial) substitution of pattern parameters, - * usable to represent a match of the pattern in the result of a query, - * or to specify the bound (fixed) input parameters when issuing a query. - * - * @see Matcher - * - */ - public static abstract class Match extends BasePatternMatch { - private State fState; - - private Region fSubregion; - - private static List parameterNames = makeImmutableList("state", "subregion"); - - private Match(final State pState, final Region pSubregion) { - this.fState = pState; - this.fSubregion = pSubregion; - } - - @Override - public Object get(final String parameterName) { - switch(parameterName) { - case "state": return this.fState; - case "subregion": return this.fSubregion; - default: return null; - } - } - - @Override - public Object get(final int index) { - switch(index) { - case 0: return this.fState; - case 1: return this.fSubregion; - default: return null; - } - } - - public State getState() { - return this.fState; - } - - public Region getSubregion() { - return this.fSubregion; - } - - @Override - public boolean set(final String parameterName, final Object newValue) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - if ("state".equals(parameterName) ) { - this.fState = (State) newValue; - return true; - } - if ("subregion".equals(parameterName) ) { - this.fSubregion = (Region) newValue; - return true; - } - return false; - } - - public void setState(final State pState) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fState = pState; - } - - public void setSubregion(final Region pSubregion) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fSubregion = pSubregion; - } - - @Override - public String patternName() { - return "com.incquerylabs.magicdraw.benchmark.queries.subregions"; - } - - @Override - public List parameterNames() { - return Subregions.Match.parameterNames; - } - - @Override - public Object[] toArray() { - return new Object[]{fState, fSubregion}; - } - - @Override - public Subregions.Match toImmutable() { - return isMutable() ? newMatch(fState, fSubregion) : this; - } - - @Override - public String prettyPrint() { - StringBuilder result = new StringBuilder(); - result.append("\"state\"=" + prettyPrintValue(fState) + ", "); - result.append("\"subregion\"=" + prettyPrintValue(fSubregion)); - return result.toString(); - } - - @Override - public int hashCode() { - return Objects.hash(fState, fSubregion); - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) - return true; - if (obj == null) { - return false; - } - if ((obj instanceof Subregions.Match)) { - Subregions.Match other = (Subregions.Match) obj; - return Objects.equals(fState, other.fState) && Objects.equals(fSubregion, other.fSubregion); - } else { - // this should be infrequent - if (!(obj instanceof IPatternMatch)) { - return false; - } - IPatternMatch otherSig = (IPatternMatch) obj; - return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); - } - } - - @Override - public Subregions specification() { - return Subregions.instance(); - } - - /** - * Returns an empty, mutable match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @return the empty match. - * - */ - public static Subregions.Match newEmptyMatch() { - return new Mutable(null, null); - } - - /** - * Returns a mutable (partial) match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pSubregion the fixed value of pattern parameter subregion, or null if not bound. - * @return the new, mutable (partial) match object. - * - */ - public static Subregions.Match newMutableMatch(final State pState, final Region pSubregion) { - return new Mutable(pState, pSubregion); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pSubregion the fixed value of pattern parameter subregion, or null if not bound. - * @return the (partial) match object. - * - */ - public static Subregions.Match newMatch(final State pState, final Region pSubregion) { - return new Immutable(pState, pSubregion); - } - - private static final class Mutable extends Subregions.Match { - Mutable(final State pState, final Region pSubregion) { - super(pState, pSubregion); - } - - @Override - public boolean isMutable() { - return true; - } - } - - private static final class Immutable extends Subregions.Match { - Immutable(final State pState, final Region pSubregion) { - super(pState, pSubregion); - } - - @Override - public boolean isMutable() { - return false; - } - } - } - - /** - * Generated pattern matcher API of the com.incquerylabs.magicdraw.benchmark.queries.subregions pattern, - * providing pattern-specific query methods. - * - *

Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, - * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. - * - *

Matches of the pattern will be represented as {@link Match}. - * - *

Original source: - *

-   * Using recursion, eval and disjunction.
-   *   Cannot be evaluated using local search because of recursion!
-   *  
-   * //pattern qualifiedStateName(state : State, name : java ^java.lang.String) {
-   * //	find parentState(state, parentState);
-   * //    State.name(state, simpleName);
-   * //    find qualifiedStateName(parentState, parentName);
-   * //    name == eval (parentName + "." + simpleName);
-   * //} or { 
-   * //    neg find parentState(state, _);
-   * //    State.name(state, name);
-   * //}
-   * 
-   * 
-   *   Simple pattern for aggregators.
-   *  
-   * pattern subregions(state : State, subregion : Region) {
-   *   	State.region(state, subregion);
-   * }
-   * 
- * - * @see Match - * @see Subregions - * - */ - public static class Matcher extends BaseMatcher { - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - public static Subregions.Matcher on(final ViatraQueryEngine engine) { - // check if matcher already exists - Matcher matcher = engine.getExistingMatcher(querySpecification()); - if (matcher == null) { - matcher = (Matcher)engine.getMatcher(querySpecification()); - } - return matcher; - } - - /** - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * @return an initialized matcher - * @noreference This method is for internal matcher initialization by the framework, do not call it manually. - * - */ - public static Subregions.Matcher create() { - return new Matcher(); - } - - private static final int POSITION_STATE = 0; - - private static final int POSITION_SUBREGION = 1; - - private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(Subregions.Matcher.class); - - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - private Matcher() { - super(querySpecification()); - } - - /** - * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pSubregion the fixed value of pattern parameter subregion, or null if not bound. - * @return matches represented as a Match object. - * - */ - public Collection getAllMatches(final State pState, final Region pSubregion) { - return rawStreamAllMatches(new Object[]{pState, pSubregion}).collect(Collectors.toSet()); - } - - /** - * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pSubregion the fixed value of pattern parameter subregion, or null if not bound. - * @return a stream of matches represented as a Match object. - * - */ - public Stream streamAllMatches(final State pState, final Region pSubregion) { - return rawStreamAllMatches(new Object[]{pState, pSubregion}); - } - - /** - * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pSubregion the fixed value of pattern parameter subregion, or null if not bound. - * @return a match represented as a Match object, or null if no match is found. - * - */ - public Optional getOneArbitraryMatch(final State pState, final Region pSubregion) { - return rawGetOneArbitraryMatch(new Object[]{pState, pSubregion}); - } - - /** - * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, - * under any possible substitution of the unspecified parameters (if any). - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pSubregion the fixed value of pattern parameter subregion, or null if not bound. - * @return true if the input is a valid (partial) match of the pattern. - * - */ - public boolean hasMatch(final State pState, final Region pSubregion) { - return rawHasMatch(new Object[]{pState, pSubregion}); - } - - /** - * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pSubregion the fixed value of pattern parameter subregion, or null if not bound. - * @return the number of pattern matches found. - * - */ - public int countMatches(final State pState, final Region pSubregion) { - return rawCountMatches(new Object[]{pState, pSubregion}); - } - - /** - * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pSubregion the fixed value of pattern parameter subregion, or null if not bound. - * @param processor the action that will process the selected match. - * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked - * - */ - public boolean forOneArbitraryMatch(final State pState, final Region pSubregion, final Consumer processor) { - return rawForOneArbitraryMatch(new Object[]{pState, pSubregion}, processor); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pSubregion the fixed value of pattern parameter subregion, or null if not bound. - * @return the (partial) match object. - * - */ - public Subregions.Match newMatch(final State pState, final Region pSubregion) { - return Subregions.Match.newMatch(pState, pSubregion); - } - - /** - * Retrieve the set of values that occur in matches for state. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOfstate(final Object[] parameters) { - return rawStreamAllValues(POSITION_STATE, parameters).map(State.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for state. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfstate() { - return rawStreamAllValuesOfstate(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for state. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfstate() { - return rawStreamAllValuesOfstate(emptyArray()); - } - - /** - * Retrieve the set of values that occur in matches for state. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfstate(final Subregions.Match partialMatch) { - return rawStreamAllValuesOfstate(partialMatch.toArray()); - } - - /** - * Retrieve the set of values that occur in matches for state. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfstate(final Region pSubregion) { - return rawStreamAllValuesOfstate(new Object[]{null, pSubregion}); - } - - /** - * Retrieve the set of values that occur in matches for state. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfstate(final Subregions.Match partialMatch) { - return rawStreamAllValuesOfstate(partialMatch.toArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for state. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfstate(final Region pSubregion) { - return rawStreamAllValuesOfstate(new Object[]{null, pSubregion}).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for subregion. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOfsubregion(final Object[] parameters) { - return rawStreamAllValues(POSITION_SUBREGION, parameters).map(Region.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for subregion. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfsubregion() { - return rawStreamAllValuesOfsubregion(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for subregion. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfsubregion() { - return rawStreamAllValuesOfsubregion(emptyArray()); - } - - /** - * Retrieve the set of values that occur in matches for subregion. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfsubregion(final Subregions.Match partialMatch) { - return rawStreamAllValuesOfsubregion(partialMatch.toArray()); - } - - /** - * Retrieve the set of values that occur in matches for subregion. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfsubregion(final State pState) { - return rawStreamAllValuesOfsubregion(new Object[]{pState, null}); - } - - /** - * Retrieve the set of values that occur in matches for subregion. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfsubregion(final Subregions.Match partialMatch) { - return rawStreamAllValuesOfsubregion(partialMatch.toArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for subregion. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfsubregion(final State pState) { - return rawStreamAllValuesOfsubregion(new Object[]{pState, null}).collect(Collectors.toSet()); - } - - @Override - protected Subregions.Match tupleToMatch(final Tuple t) { - try { - return Subregions.Match.newMatch((State) t.get(POSITION_STATE), (Region) t.get(POSITION_SUBREGION)); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in tuple not properly typed!",e); - return null; - } - } - - @Override - protected Subregions.Match arrayToMatch(final Object[] match) { - try { - return Subregions.Match.newMatch((State) match[POSITION_STATE], (Region) match[POSITION_SUBREGION]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - @Override - protected Subregions.Match arrayToMatchMutable(final Object[] match) { - try { - return Subregions.Match.newMutableMatch((State) match[POSITION_STATE], (Region) match[POSITION_SUBREGION]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - /** - * @return the singleton instance of the query specification of this pattern - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static IQuerySpecification querySpecification() { - return Subregions.instance(); - } - } - - private Subregions() { - super(GeneratedPQuery.INSTANCE); - } - - /** - * @return the singleton instance of the query specification - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static Subregions instance() { - try{ - return LazyHolder.INSTANCE; - } catch (ExceptionInInitializerError err) { - throw processInitializerError(err); - } - } - - @Override - protected Subregions.Matcher instantiate(final ViatraQueryEngine engine) { - return Subregions.Matcher.on(engine); - } - - @Override - public Subregions.Matcher instantiate() { - return Subregions.Matcher.create(); - } - - @Override - public Subregions.Match newEmptyMatch() { - return Subregions.Match.newEmptyMatch(); - } - - @Override - public Subregions.Match newMatch(final Object... parameters) { - return Subregions.Match.newMatch((com.nomagic.uml2.ext.magicdraw.statemachines.mdbehaviorstatemachines.State) parameters[0], (com.nomagic.uml2.ext.magicdraw.statemachines.mdbehaviorstatemachines.Region) parameters[1]); - } - - /** - * Inner class allowing the singleton instance of {@link Subregions} to be created - * not at the class load time of the outer class, - * but rather at the first call to {@link Subregions#instance()}. - * - *

This workaround is required e.g. to support recursion. - * - */ - private static class LazyHolder { - private static final Subregions INSTANCE = new Subregions(); - - /** - * Statically initializes the query specification after the field {@link #INSTANCE} is assigned. - * This initialization order is required to support indirect recursion. - * - *

The static initializer is defined using a helper field to work around limitations of the code generator. - * - */ - private static final Object STATIC_INITIALIZER = ensureInitialized(); - - public static Object ensureInitialized() { - INSTANCE.ensureInitializedInternal(); - return null; - } - } - - private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { - private static final Subregions.GeneratedPQuery INSTANCE = new GeneratedPQuery(); - - private final PParameter parameter_state = new PParameter("state", "com.nomagic.uml2.ext.magicdraw.statemachines.mdbehaviorstatemachines.State", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.nomagic.com/magicdraw/UML/2.5.1", "State")), PParameterDirection.INOUT); - - private final PParameter parameter_subregion = new PParameter("subregion", "com.nomagic.uml2.ext.magicdraw.statemachines.mdbehaviorstatemachines.Region", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.nomagic.com/magicdraw/UML/2.5.1", "Region")), PParameterDirection.INOUT); - - private final List parameters = Arrays.asList(parameter_state, parameter_subregion); - - private GeneratedPQuery() { - super(PVisibility.PUBLIC); - } - - @Override - public String getFullyQualifiedName() { - return "com.incquerylabs.magicdraw.benchmark.queries.subregions"; - } - - @Override - public List getParameterNames() { - return Arrays.asList("state","subregion"); - } - - @Override - public List getParameters() { - return parameters; - } - - @Override - public Set doGetContainedBodies() { - setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); - Set bodies = new LinkedHashSet<>(); - { - PBody body = new PBody(this); - PVariable var_state = body.getOrCreateVariableByName("state"); - PVariable var_subregion = body.getOrCreateVariableByName("subregion"); - new TypeConstraint(body, Tuples.flatTupleOf(var_state), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "State"))); - new TypeConstraint(body, Tuples.flatTupleOf(var_subregion), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Region"))); - body.setSymbolicParameters(Arrays.asList( - new ExportedParameter(body, var_state, parameter_state), - new ExportedParameter(body, var_subregion, parameter_subregion) - )); - // State.region(state, subregion) - new TypeConstraint(body, Tuples.flatTupleOf(var_state), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "State"))); - PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_state, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "State", "region"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Region"))); - new Equality(body, var__virtual_0_, var_subregion); - bodies.add(body); - } - return bodies; - } - } -} diff --git a/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/TransitionPointingOutOfCompState.java b/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/TransitionPointingOutOfCompState.java deleted file mode 100644 index 288ac5d..0000000 --- a/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/TransitionPointingOutOfCompState.java +++ /dev/null @@ -1,951 +0,0 @@ -/** - * Generated from platform:/resource/com.incquerylabs.magicdraw.benchmark/src/main/java/com/incquerylabs/magicdraw/benchmark/queries/APerformanceQueries.vql - */ -package com.incquerylabs.magicdraw.benchmark.queries; - -import com.incquerylabs.magicdraw.benchmark.queries.ParentState; -import com.nomagic.uml2.ext.magicdraw.statemachines.mdbehaviorstatemachines.State; -import com.nomagic.uml2.ext.magicdraw.statemachines.mdbehaviorstatemachines.Transition; -import com.nomagic.uml2.ext.magicdraw.statemachines.mdbehaviorstatemachines.Vertex; -import java.util.Arrays; -import java.util.Collection; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.function.Consumer; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import org.apache.log4j.Logger; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.viatra.query.runtime.api.IPatternMatch; -import org.eclipse.viatra.query.runtime.api.IQuerySpecification; -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.api.impl.BaseMatcher; -import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; -import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; -import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey; -import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; -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.basicenumerables.BinaryTransitiveClosure; -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.PVisibility; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; -import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; - -/** - * A pattern-specific query specification that can instantiate Matcher in a type-safe way. - * - *

Original source: - *

- *         Cartesian product of classes.
- *          
- *         //pattern productOfClasses(lhs : Class, lhsName : java ^java.lang.String, rhs : Class, rhsName : java ^java.lang.String) {
- *         //	Class.name(lhs, lhsName);
- *         //    Class.name(rhs, rhsName);
- *         //}
- *         
- *         
- *           Cartesian product of classes and a filter using a check.
- *          
- *         //private pattern hasLongerName(lhs : Class, rhs : Class) {
- *         //    find productOfClasses(lhs, lhsName, rhs, rhsName);
- *         //    check (lhsName.length {@literal <} rhsName.length); 
- *         //}
- *         
- *         
- *           Selecting an element reusing a Cartesian product.
- *          
- *         //pattern elementWithShortestName(element : Class) {
- *         //	find requirements(element); // If this in not here, we run out of memory
- *         //	neg find hasLongerName(_, element);
- *         //}
- *         
- *         
- *           A transition that connects two states with the following properties
- *           - Source state is a member of a composite state
- *           - Target state is a member of the same state machine, however not contained in a composite state
- *           - Target state has an outgoing transition towards a final state
- *           
- *          
- *         pattern transitionPointingOutOfCompState(source : State, target : Vertex, transition : Transition) {
- *         	Transition.source(transition, source);
- *         	Transition.target(transition, target);
- *         	
- *         	//pattern for target side element
- *         	Vertex.container(target, targetRegion);
- *         	Region.stateMachine(targetRegion, _);
- *         	Vertex.outgoing(target, targetVertexTransition);
- *         	Transition.target(targetVertexTransition, finalState);
- *         	FinalState(finalState);
- *         	
- *         	//Pattern for source side element
- *         	find parentState+(source, sourceParent);
- *         	State.container.stateMachine(sourceParent, _ );
- *         	
- *         }
- * 
- * - * @see Matcher - * @see Match - * - */ -@SuppressWarnings("all") -public final class TransitionPointingOutOfCompState extends BaseGeneratedEMFQuerySpecification { - /** - * Pattern-specific match representation of the com.incquerylabs.magicdraw.benchmark.queries.transitionPointingOutOfCompState pattern, - * to be used in conjunction with {@link Matcher}. - * - *

Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. - * Each instance is a (possibly partial) substitution of pattern parameters, - * usable to represent a match of the pattern in the result of a query, - * or to specify the bound (fixed) input parameters when issuing a query. - * - * @see Matcher - * - */ - public static abstract class Match extends BasePatternMatch { - private State fSource; - - private Vertex fTarget; - - private Transition fTransition; - - private static List parameterNames = makeImmutableList("source", "target", "transition"); - - private Match(final State pSource, final Vertex pTarget, final Transition pTransition) { - this.fSource = pSource; - this.fTarget = pTarget; - this.fTransition = pTransition; - } - - @Override - public Object get(final String parameterName) { - switch(parameterName) { - case "source": return this.fSource; - case "target": return this.fTarget; - case "transition": return this.fTransition; - default: return null; - } - } - - @Override - public Object get(final int index) { - switch(index) { - case 0: return this.fSource; - case 1: return this.fTarget; - case 2: return this.fTransition; - default: return null; - } - } - - public State getSource() { - return this.fSource; - } - - public Vertex getTarget() { - return this.fTarget; - } - - public Transition getTransition() { - return this.fTransition; - } - - @Override - public boolean set(final String parameterName, final Object newValue) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - if ("source".equals(parameterName) ) { - this.fSource = (State) newValue; - return true; - } - if ("target".equals(parameterName) ) { - this.fTarget = (Vertex) newValue; - return true; - } - if ("transition".equals(parameterName) ) { - this.fTransition = (Transition) newValue; - return true; - } - return false; - } - - public void setSource(final State pSource) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fSource = pSource; - } - - public void setTarget(final Vertex pTarget) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fTarget = pTarget; - } - - public void setTransition(final Transition pTransition) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fTransition = pTransition; - } - - @Override - public String patternName() { - return "com.incquerylabs.magicdraw.benchmark.queries.transitionPointingOutOfCompState"; - } - - @Override - public List parameterNames() { - return TransitionPointingOutOfCompState.Match.parameterNames; - } - - @Override - public Object[] toArray() { - return new Object[]{fSource, fTarget, fTransition}; - } - - @Override - public TransitionPointingOutOfCompState.Match toImmutable() { - return isMutable() ? newMatch(fSource, fTarget, fTransition) : this; - } - - @Override - public String prettyPrint() { - StringBuilder result = new StringBuilder(); - result.append("\"source\"=" + prettyPrintValue(fSource) + ", "); - result.append("\"target\"=" + prettyPrintValue(fTarget) + ", "); - result.append("\"transition\"=" + prettyPrintValue(fTransition)); - return result.toString(); - } - - @Override - public int hashCode() { - return Objects.hash(fSource, fTarget, fTransition); - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) - return true; - if (obj == null) { - return false; - } - if ((obj instanceof TransitionPointingOutOfCompState.Match)) { - TransitionPointingOutOfCompState.Match other = (TransitionPointingOutOfCompState.Match) obj; - return Objects.equals(fSource, other.fSource) && Objects.equals(fTarget, other.fTarget) && Objects.equals(fTransition, other.fTransition); - } else { - // this should be infrequent - if (!(obj instanceof IPatternMatch)) { - return false; - } - IPatternMatch otherSig = (IPatternMatch) obj; - return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); - } - } - - @Override - public TransitionPointingOutOfCompState specification() { - return TransitionPointingOutOfCompState.instance(); - } - - /** - * Returns an empty, mutable match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @return the empty match. - * - */ - public static TransitionPointingOutOfCompState.Match newEmptyMatch() { - return new Mutable(null, null, null); - } - - /** - * Returns a mutable (partial) match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @param pSource the fixed value of pattern parameter source, or null if not bound. - * @param pTarget the fixed value of pattern parameter target, or null if not bound. - * @param pTransition the fixed value of pattern parameter transition, or null if not bound. - * @return the new, mutable (partial) match object. - * - */ - public static TransitionPointingOutOfCompState.Match newMutableMatch(final State pSource, final Vertex pTarget, final Transition pTransition) { - return new Mutable(pSource, pTarget, pTransition); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pSource the fixed value of pattern parameter source, or null if not bound. - * @param pTarget the fixed value of pattern parameter target, or null if not bound. - * @param pTransition the fixed value of pattern parameter transition, or null if not bound. - * @return the (partial) match object. - * - */ - public static TransitionPointingOutOfCompState.Match newMatch(final State pSource, final Vertex pTarget, final Transition pTransition) { - return new Immutable(pSource, pTarget, pTransition); - } - - private static final class Mutable extends TransitionPointingOutOfCompState.Match { - Mutable(final State pSource, final Vertex pTarget, final Transition pTransition) { - super(pSource, pTarget, pTransition); - } - - @Override - public boolean isMutable() { - return true; - } - } - - private static final class Immutable extends TransitionPointingOutOfCompState.Match { - Immutable(final State pSource, final Vertex pTarget, final Transition pTransition) { - super(pSource, pTarget, pTransition); - } - - @Override - public boolean isMutable() { - return false; - } - } - } - - /** - * Generated pattern matcher API of the com.incquerylabs.magicdraw.benchmark.queries.transitionPointingOutOfCompState pattern, - * providing pattern-specific query methods. - * - *

Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, - * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. - * - *

Matches of the pattern will be represented as {@link Match}. - * - *

Original source: - *

-   * Cartesian product of classes.
-   *  
-   * //pattern productOfClasses(lhs : Class, lhsName : java ^java.lang.String, rhs : Class, rhsName : java ^java.lang.String) {
-   * //	Class.name(lhs, lhsName);
-   * //    Class.name(rhs, rhsName);
-   * //}
-   * 
-   * 
-   *   Cartesian product of classes and a filter using a check.
-   *  
-   * //private pattern hasLongerName(lhs : Class, rhs : Class) {
-   * //    find productOfClasses(lhs, lhsName, rhs, rhsName);
-   * //    check (lhsName.length {@literal <} rhsName.length); 
-   * //}
-   * 
-   * 
-   *   Selecting an element reusing a Cartesian product.
-   *  
-   * //pattern elementWithShortestName(element : Class) {
-   * //	find requirements(element); // If this in not here, we run out of memory
-   * //	neg find hasLongerName(_, element);
-   * //}
-   * 
-   * 
-   *   A transition that connects two states with the following properties
-   *   - Source state is a member of a composite state
-   *   - Target state is a member of the same state machine, however not contained in a composite state
-   *   - Target state has an outgoing transition towards a final state
-   *   
-   *  
-   * pattern transitionPointingOutOfCompState(source : State, target : Vertex, transition : Transition) {
-   * 	Transition.source(transition, source);
-   * 	Transition.target(transition, target);
-   * 	
-   * 	//pattern for target side element
-   * 	Vertex.container(target, targetRegion);
-   * 	Region.stateMachine(targetRegion, _);
-   * 	Vertex.outgoing(target, targetVertexTransition);
-   * 	Transition.target(targetVertexTransition, finalState);
-   * 	FinalState(finalState);
-   * 	
-   * 	//Pattern for source side element
-   * 	find parentState+(source, sourceParent);
-   * 	State.container.stateMachine(sourceParent, _ );
-   * 	
-   * }
-   * 
- * - * @see Match - * @see TransitionPointingOutOfCompState - * - */ - public static class Matcher extends BaseMatcher { - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - public static TransitionPointingOutOfCompState.Matcher on(final ViatraQueryEngine engine) { - // check if matcher already exists - Matcher matcher = engine.getExistingMatcher(querySpecification()); - if (matcher == null) { - matcher = (Matcher)engine.getMatcher(querySpecification()); - } - return matcher; - } - - /** - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * @return an initialized matcher - * @noreference This method is for internal matcher initialization by the framework, do not call it manually. - * - */ - public static TransitionPointingOutOfCompState.Matcher create() { - return new Matcher(); - } - - private static final int POSITION_SOURCE = 0; - - private static final int POSITION_TARGET = 1; - - private static final int POSITION_TRANSITION = 2; - - private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(TransitionPointingOutOfCompState.Matcher.class); - - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - private Matcher() { - super(querySpecification()); - } - - /** - * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pSource the fixed value of pattern parameter source, or null if not bound. - * @param pTarget the fixed value of pattern parameter target, or null if not bound. - * @param pTransition the fixed value of pattern parameter transition, or null if not bound. - * @return matches represented as a Match object. - * - */ - public Collection getAllMatches(final State pSource, final Vertex pTarget, final Transition pTransition) { - return rawStreamAllMatches(new Object[]{pSource, pTarget, pTransition}).collect(Collectors.toSet()); - } - - /** - * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * @param pSource the fixed value of pattern parameter source, or null if not bound. - * @param pTarget the fixed value of pattern parameter target, or null if not bound. - * @param pTransition the fixed value of pattern parameter transition, or null if not bound. - * @return a stream of matches represented as a Match object. - * - */ - public Stream streamAllMatches(final State pSource, final Vertex pTarget, final Transition pTransition) { - return rawStreamAllMatches(new Object[]{pSource, pTarget, pTransition}); - } - - /** - * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pSource the fixed value of pattern parameter source, or null if not bound. - * @param pTarget the fixed value of pattern parameter target, or null if not bound. - * @param pTransition the fixed value of pattern parameter transition, or null if not bound. - * @return a match represented as a Match object, or null if no match is found. - * - */ - public Optional getOneArbitraryMatch(final State pSource, final Vertex pTarget, final Transition pTransition) { - return rawGetOneArbitraryMatch(new Object[]{pSource, pTarget, pTransition}); - } - - /** - * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, - * under any possible substitution of the unspecified parameters (if any). - * @param pSource the fixed value of pattern parameter source, or null if not bound. - * @param pTarget the fixed value of pattern parameter target, or null if not bound. - * @param pTransition the fixed value of pattern parameter transition, or null if not bound. - * @return true if the input is a valid (partial) match of the pattern. - * - */ - public boolean hasMatch(final State pSource, final Vertex pTarget, final Transition pTransition) { - return rawHasMatch(new Object[]{pSource, pTarget, pTransition}); - } - - /** - * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pSource the fixed value of pattern parameter source, or null if not bound. - * @param pTarget the fixed value of pattern parameter target, or null if not bound. - * @param pTransition the fixed value of pattern parameter transition, or null if not bound. - * @return the number of pattern matches found. - * - */ - public int countMatches(final State pSource, final Vertex pTarget, final Transition pTransition) { - return rawCountMatches(new Object[]{pSource, pTarget, pTransition}); - } - - /** - * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pSource the fixed value of pattern parameter source, or null if not bound. - * @param pTarget the fixed value of pattern parameter target, or null if not bound. - * @param pTransition the fixed value of pattern parameter transition, or null if not bound. - * @param processor the action that will process the selected match. - * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked - * - */ - public boolean forOneArbitraryMatch(final State pSource, final Vertex pTarget, final Transition pTransition, final Consumer processor) { - return rawForOneArbitraryMatch(new Object[]{pSource, pTarget, pTransition}, processor); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pSource the fixed value of pattern parameter source, or null if not bound. - * @param pTarget the fixed value of pattern parameter target, or null if not bound. - * @param pTransition the fixed value of pattern parameter transition, or null if not bound. - * @return the (partial) match object. - * - */ - public TransitionPointingOutOfCompState.Match newMatch(final State pSource, final Vertex pTarget, final Transition pTransition) { - return TransitionPointingOutOfCompState.Match.newMatch(pSource, pTarget, pTransition); - } - - /** - * Retrieve the set of values that occur in matches for source. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOfsource(final Object[] parameters) { - return rawStreamAllValues(POSITION_SOURCE, parameters).map(State.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for source. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfsource() { - return rawStreamAllValuesOfsource(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for source. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfsource() { - return rawStreamAllValuesOfsource(emptyArray()); - } - - /** - * Retrieve the set of values that occur in matches for source. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfsource(final TransitionPointingOutOfCompState.Match partialMatch) { - return rawStreamAllValuesOfsource(partialMatch.toArray()); - } - - /** - * Retrieve the set of values that occur in matches for source. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfsource(final Vertex pTarget, final Transition pTransition) { - return rawStreamAllValuesOfsource(new Object[]{null, pTarget, pTransition}); - } - - /** - * Retrieve the set of values that occur in matches for source. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfsource(final TransitionPointingOutOfCompState.Match partialMatch) { - return rawStreamAllValuesOfsource(partialMatch.toArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for source. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfsource(final Vertex pTarget, final Transition pTransition) { - return rawStreamAllValuesOfsource(new Object[]{null, pTarget, pTransition}).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for target. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOftarget(final Object[] parameters) { - return rawStreamAllValues(POSITION_TARGET, parameters).map(Vertex.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for target. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOftarget() { - return rawStreamAllValuesOftarget(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for target. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOftarget() { - return rawStreamAllValuesOftarget(emptyArray()); - } - - /** - * Retrieve the set of values that occur in matches for target. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOftarget(final TransitionPointingOutOfCompState.Match partialMatch) { - return rawStreamAllValuesOftarget(partialMatch.toArray()); - } - - /** - * Retrieve the set of values that occur in matches for target. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOftarget(final State pSource, final Transition pTransition) { - return rawStreamAllValuesOftarget(new Object[]{pSource, null, pTransition}); - } - - /** - * Retrieve the set of values that occur in matches for target. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOftarget(final TransitionPointingOutOfCompState.Match partialMatch) { - return rawStreamAllValuesOftarget(partialMatch.toArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for target. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOftarget(final State pSource, final Transition pTransition) { - return rawStreamAllValuesOftarget(new Object[]{pSource, null, pTransition}).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for transition. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOftransition(final Object[] parameters) { - return rawStreamAllValues(POSITION_TRANSITION, parameters).map(Transition.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for transition. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOftransition() { - return rawStreamAllValuesOftransition(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for transition. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOftransition() { - return rawStreamAllValuesOftransition(emptyArray()); - } - - /** - * Retrieve the set of values that occur in matches for transition. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOftransition(final TransitionPointingOutOfCompState.Match partialMatch) { - return rawStreamAllValuesOftransition(partialMatch.toArray()); - } - - /** - * Retrieve the set of values that occur in matches for transition. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOftransition(final State pSource, final Vertex pTarget) { - return rawStreamAllValuesOftransition(new Object[]{pSource, pTarget, null}); - } - - /** - * Retrieve the set of values that occur in matches for transition. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOftransition(final TransitionPointingOutOfCompState.Match partialMatch) { - return rawStreamAllValuesOftransition(partialMatch.toArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for transition. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOftransition(final State pSource, final Vertex pTarget) { - return rawStreamAllValuesOftransition(new Object[]{pSource, pTarget, null}).collect(Collectors.toSet()); - } - - @Override - protected TransitionPointingOutOfCompState.Match tupleToMatch(final Tuple t) { - try { - return TransitionPointingOutOfCompState.Match.newMatch((State) t.get(POSITION_SOURCE), (Vertex) t.get(POSITION_TARGET), (Transition) t.get(POSITION_TRANSITION)); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in tuple not properly typed!",e); - return null; - } - } - - @Override - protected TransitionPointingOutOfCompState.Match arrayToMatch(final Object[] match) { - try { - return TransitionPointingOutOfCompState.Match.newMatch((State) match[POSITION_SOURCE], (Vertex) match[POSITION_TARGET], (Transition) match[POSITION_TRANSITION]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - @Override - protected TransitionPointingOutOfCompState.Match arrayToMatchMutable(final Object[] match) { - try { - return TransitionPointingOutOfCompState.Match.newMutableMatch((State) match[POSITION_SOURCE], (Vertex) match[POSITION_TARGET], (Transition) match[POSITION_TRANSITION]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - /** - * @return the singleton instance of the query specification of this pattern - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static IQuerySpecification querySpecification() { - return TransitionPointingOutOfCompState.instance(); - } - } - - private TransitionPointingOutOfCompState() { - super(GeneratedPQuery.INSTANCE); - } - - /** - * @return the singleton instance of the query specification - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static TransitionPointingOutOfCompState instance() { - try{ - return LazyHolder.INSTANCE; - } catch (ExceptionInInitializerError err) { - throw processInitializerError(err); - } - } - - @Override - protected TransitionPointingOutOfCompState.Matcher instantiate(final ViatraQueryEngine engine) { - return TransitionPointingOutOfCompState.Matcher.on(engine); - } - - @Override - public TransitionPointingOutOfCompState.Matcher instantiate() { - return TransitionPointingOutOfCompState.Matcher.create(); - } - - @Override - public TransitionPointingOutOfCompState.Match newEmptyMatch() { - return TransitionPointingOutOfCompState.Match.newEmptyMatch(); - } - - @Override - public TransitionPointingOutOfCompState.Match newMatch(final Object... parameters) { - return TransitionPointingOutOfCompState.Match.newMatch((com.nomagic.uml2.ext.magicdraw.statemachines.mdbehaviorstatemachines.State) parameters[0], (com.nomagic.uml2.ext.magicdraw.statemachines.mdbehaviorstatemachines.Vertex) parameters[1], (com.nomagic.uml2.ext.magicdraw.statemachines.mdbehaviorstatemachines.Transition) parameters[2]); - } - - /** - * Inner class allowing the singleton instance of {@link TransitionPointingOutOfCompState} to be created - * not at the class load time of the outer class, - * but rather at the first call to {@link TransitionPointingOutOfCompState#instance()}. - * - *

This workaround is required e.g. to support recursion. - * - */ - private static class LazyHolder { - private static final TransitionPointingOutOfCompState INSTANCE = new TransitionPointingOutOfCompState(); - - /** - * Statically initializes the query specification after the field {@link #INSTANCE} is assigned. - * This initialization order is required to support indirect recursion. - * - *

The static initializer is defined using a helper field to work around limitations of the code generator. - * - */ - private static final Object STATIC_INITIALIZER = ensureInitialized(); - - public static Object ensureInitialized() { - INSTANCE.ensureInitializedInternal(); - return null; - } - } - - private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { - private static final TransitionPointingOutOfCompState.GeneratedPQuery INSTANCE = new GeneratedPQuery(); - - private final PParameter parameter_source = new PParameter("source", "com.nomagic.uml2.ext.magicdraw.statemachines.mdbehaviorstatemachines.State", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.nomagic.com/magicdraw/UML/2.5.1", "State")), PParameterDirection.INOUT); - - private final PParameter parameter_target = new PParameter("target", "com.nomagic.uml2.ext.magicdraw.statemachines.mdbehaviorstatemachines.Vertex", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.nomagic.com/magicdraw/UML/2.5.1", "Vertex")), PParameterDirection.INOUT); - - private final PParameter parameter_transition = new PParameter("transition", "com.nomagic.uml2.ext.magicdraw.statemachines.mdbehaviorstatemachines.Transition", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.nomagic.com/magicdraw/UML/2.5.1", "Transition")), PParameterDirection.INOUT); - - private final List parameters = Arrays.asList(parameter_source, parameter_target, parameter_transition); - - private GeneratedPQuery() { - super(PVisibility.PUBLIC); - } - - @Override - public String getFullyQualifiedName() { - return "com.incquerylabs.magicdraw.benchmark.queries.transitionPointingOutOfCompState"; - } - - @Override - public List getParameterNames() { - return Arrays.asList("source","target","transition"); - } - - @Override - public List getParameters() { - return parameters; - } - - @Override - public Set doGetContainedBodies() { - setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); - Set bodies = new LinkedHashSet<>(); - { - PBody body = new PBody(this); - PVariable var_source = body.getOrCreateVariableByName("source"); - PVariable var_target = body.getOrCreateVariableByName("target"); - PVariable var_transition = body.getOrCreateVariableByName("transition"); - PVariable var_targetRegion = body.getOrCreateVariableByName("targetRegion"); - PVariable var___0_ = body.getOrCreateVariableByName("_<0>"); - PVariable var_targetVertexTransition = body.getOrCreateVariableByName("targetVertexTransition"); - PVariable var_finalState = body.getOrCreateVariableByName("finalState"); - PVariable var_sourceParent = body.getOrCreateVariableByName("sourceParent"); - PVariable var___1_ = body.getOrCreateVariableByName("_<1>"); - new TypeConstraint(body, Tuples.flatTupleOf(var_source), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "State"))); - new TypeConstraint(body, Tuples.flatTupleOf(var_target), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Vertex"))); - new TypeConstraint(body, Tuples.flatTupleOf(var_transition), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Transition"))); - body.setSymbolicParameters(Arrays.asList( - new ExportedParameter(body, var_source, parameter_source), - new ExportedParameter(body, var_target, parameter_target), - new ExportedParameter(body, var_transition, parameter_transition) - )); - // Transition.source(transition, source) - new TypeConstraint(body, Tuples.flatTupleOf(var_transition), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Transition"))); - PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_transition, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Transition", "source"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Vertex"))); - new Equality(body, var__virtual_0_, var_source); - // Transition.target(transition, target) - new TypeConstraint(body, Tuples.flatTupleOf(var_transition), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Transition"))); - PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_transition, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Transition", "target"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Vertex"))); - new Equality(body, var__virtual_1_, var_target); - // //pattern for target side element Vertex.container(target, targetRegion) - new TypeConstraint(body, Tuples.flatTupleOf(var_target), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Vertex"))); - PVariable var__virtual_2_ = body.getOrCreateVariableByName(".virtual{2}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_target, var__virtual_2_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Vertex", "container"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_2_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Region"))); - new Equality(body, var__virtual_2_, var_targetRegion); - // Region.stateMachine(targetRegion, _) - new TypeConstraint(body, Tuples.flatTupleOf(var_targetRegion), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Region"))); - PVariable var__virtual_3_ = body.getOrCreateVariableByName(".virtual{3}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_targetRegion, var__virtual_3_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Region", "stateMachine"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_3_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "StateMachine"))); - new Equality(body, var__virtual_3_, var___0_); - // Vertex.outgoing(target, targetVertexTransition) - new TypeConstraint(body, Tuples.flatTupleOf(var_target), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Vertex"))); - PVariable var__virtual_4_ = body.getOrCreateVariableByName(".virtual{4}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_target, var__virtual_4_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Vertex", "outgoing"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_4_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Transition"))); - new Equality(body, var__virtual_4_, var_targetVertexTransition); - // Transition.target(targetVertexTransition, finalState) - new TypeConstraint(body, Tuples.flatTupleOf(var_targetVertexTransition), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Transition"))); - PVariable var__virtual_5_ = body.getOrCreateVariableByName(".virtual{5}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_targetVertexTransition, var__virtual_5_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Transition", "target"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_5_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Vertex"))); - new Equality(body, var__virtual_5_, var_finalState); - // FinalState(finalState) - new TypeConstraint(body, Tuples.flatTupleOf(var_finalState), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "FinalState"))); - // //Pattern for source side element find parentState+(source, sourceParent) - new BinaryTransitiveClosure(body, Tuples.flatTupleOf(var_source, var_sourceParent), ParentState.instance().getInternalQueryRepresentation()); - // State.container.stateMachine(sourceParent, _ ) - new TypeConstraint(body, Tuples.flatTupleOf(var_sourceParent), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "State"))); - PVariable var__virtual_6_ = body.getOrCreateVariableByName(".virtual{6}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_sourceParent, var__virtual_6_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Vertex", "container"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_6_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Region"))); - PVariable var__virtual_7_ = body.getOrCreateVariableByName(".virtual{7}"); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_6_, var__virtual_7_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Region", "stateMachine"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_7_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "StateMachine"))); - new Equality(body, var__virtual_7_, var___1_); - bodies.add(body); - } - return bodies; - } - } -} diff --git a/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/TransitiveSubstates.java b/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/TransitiveSubstates.java deleted file mode 100644 index 5696d4f..0000000 --- a/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/TransitiveSubstates.java +++ /dev/null @@ -1,704 +0,0 @@ -/** - * Generated from platform:/resource/com.incquerylabs.magicdraw.benchmark/src/main/java/com/incquerylabs/magicdraw/benchmark/queries/APerformanceQueries.vql - */ -package com.incquerylabs.magicdraw.benchmark.queries; - -import com.incquerylabs.magicdraw.benchmark.queries.ParentState; -import com.nomagic.uml2.ext.magicdraw.statemachines.mdbehaviorstatemachines.State; -import java.util.Arrays; -import java.util.Collection; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.function.Consumer; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import org.apache.log4j.Logger; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.viatra.query.runtime.api.IPatternMatch; -import org.eclipse.viatra.query.runtime.api.IQuerySpecification; -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.api.impl.BaseMatcher; -import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; -import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; -import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; -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.ExportedParameter; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.BinaryTransitiveClosure; -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.PVisibility; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; -import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; - -/** - * A pattern-specific query specification that can instantiate Matcher in a type-safe way. - * - *

Original source: - *

- *         Reusing a simple pattern with transitive closure.
- *          
- *         pattern transitiveSubstates(state : State, transitiveSubstate : State) {
- *         	find parentState+(transitiveSubstate, state);
- *         }
- * 
- * - * @see Matcher - * @see Match - * - */ -@SuppressWarnings("all") -public final class TransitiveSubstates extends BaseGeneratedEMFQuerySpecification { - /** - * Pattern-specific match representation of the com.incquerylabs.magicdraw.benchmark.queries.transitiveSubstates pattern, - * to be used in conjunction with {@link Matcher}. - * - *

Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. - * Each instance is a (possibly partial) substitution of pattern parameters, - * usable to represent a match of the pattern in the result of a query, - * or to specify the bound (fixed) input parameters when issuing a query. - * - * @see Matcher - * - */ - public static abstract class Match extends BasePatternMatch { - private State fState; - - private State fTransitiveSubstate; - - private static List parameterNames = makeImmutableList("state", "transitiveSubstate"); - - private Match(final State pState, final State pTransitiveSubstate) { - this.fState = pState; - this.fTransitiveSubstate = pTransitiveSubstate; - } - - @Override - public Object get(final String parameterName) { - switch(parameterName) { - case "state": return this.fState; - case "transitiveSubstate": return this.fTransitiveSubstate; - default: return null; - } - } - - @Override - public Object get(final int index) { - switch(index) { - case 0: return this.fState; - case 1: return this.fTransitiveSubstate; - default: return null; - } - } - - public State getState() { - return this.fState; - } - - public State getTransitiveSubstate() { - return this.fTransitiveSubstate; - } - - @Override - public boolean set(final String parameterName, final Object newValue) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - if ("state".equals(parameterName) ) { - this.fState = (State) newValue; - return true; - } - if ("transitiveSubstate".equals(parameterName) ) { - this.fTransitiveSubstate = (State) newValue; - return true; - } - return false; - } - - public void setState(final State pState) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fState = pState; - } - - public void setTransitiveSubstate(final State pTransitiveSubstate) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fTransitiveSubstate = pTransitiveSubstate; - } - - @Override - public String patternName() { - return "com.incquerylabs.magicdraw.benchmark.queries.transitiveSubstates"; - } - - @Override - public List parameterNames() { - return TransitiveSubstates.Match.parameterNames; - } - - @Override - public Object[] toArray() { - return new Object[]{fState, fTransitiveSubstate}; - } - - @Override - public TransitiveSubstates.Match toImmutable() { - return isMutable() ? newMatch(fState, fTransitiveSubstate) : this; - } - - @Override - public String prettyPrint() { - StringBuilder result = new StringBuilder(); - result.append("\"state\"=" + prettyPrintValue(fState) + ", "); - result.append("\"transitiveSubstate\"=" + prettyPrintValue(fTransitiveSubstate)); - return result.toString(); - } - - @Override - public int hashCode() { - return Objects.hash(fState, fTransitiveSubstate); - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) - return true; - if (obj == null) { - return false; - } - if ((obj instanceof TransitiveSubstates.Match)) { - TransitiveSubstates.Match other = (TransitiveSubstates.Match) obj; - return Objects.equals(fState, other.fState) && Objects.equals(fTransitiveSubstate, other.fTransitiveSubstate); - } else { - // this should be infrequent - if (!(obj instanceof IPatternMatch)) { - return false; - } - IPatternMatch otherSig = (IPatternMatch) obj; - return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); - } - } - - @Override - public TransitiveSubstates specification() { - return TransitiveSubstates.instance(); - } - - /** - * Returns an empty, mutable match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @return the empty match. - * - */ - public static TransitiveSubstates.Match newEmptyMatch() { - return new Mutable(null, null); - } - - /** - * Returns a mutable (partial) match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pTransitiveSubstate the fixed value of pattern parameter transitiveSubstate, or null if not bound. - * @return the new, mutable (partial) match object. - * - */ - public static TransitiveSubstates.Match newMutableMatch(final State pState, final State pTransitiveSubstate) { - return new Mutable(pState, pTransitiveSubstate); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pTransitiveSubstate the fixed value of pattern parameter transitiveSubstate, or null if not bound. - * @return the (partial) match object. - * - */ - public static TransitiveSubstates.Match newMatch(final State pState, final State pTransitiveSubstate) { - return new Immutable(pState, pTransitiveSubstate); - } - - private static final class Mutable extends TransitiveSubstates.Match { - Mutable(final State pState, final State pTransitiveSubstate) { - super(pState, pTransitiveSubstate); - } - - @Override - public boolean isMutable() { - return true; - } - } - - private static final class Immutable extends TransitiveSubstates.Match { - Immutable(final State pState, final State pTransitiveSubstate) { - super(pState, pTransitiveSubstate); - } - - @Override - public boolean isMutable() { - return false; - } - } - } - - /** - * Generated pattern matcher API of the com.incquerylabs.magicdraw.benchmark.queries.transitiveSubstates pattern, - * providing pattern-specific query methods. - * - *

Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, - * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. - * - *

Matches of the pattern will be represented as {@link Match}. - * - *

Original source: - *

-   * Reusing a simple pattern with transitive closure.
-   *  
-   * pattern transitiveSubstates(state : State, transitiveSubstate : State) {
-   * 	find parentState+(transitiveSubstate, state);
-   * }
-   * 
- * - * @see Match - * @see TransitiveSubstates - * - */ - public static class Matcher extends BaseMatcher { - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - public static TransitiveSubstates.Matcher on(final ViatraQueryEngine engine) { - // check if matcher already exists - Matcher matcher = engine.getExistingMatcher(querySpecification()); - if (matcher == null) { - matcher = (Matcher)engine.getMatcher(querySpecification()); - } - return matcher; - } - - /** - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * @return an initialized matcher - * @noreference This method is for internal matcher initialization by the framework, do not call it manually. - * - */ - public static TransitiveSubstates.Matcher create() { - return new Matcher(); - } - - private static final int POSITION_STATE = 0; - - private static final int POSITION_TRANSITIVESUBSTATE = 1; - - private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(TransitiveSubstates.Matcher.class); - - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - private Matcher() { - super(querySpecification()); - } - - /** - * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pTransitiveSubstate the fixed value of pattern parameter transitiveSubstate, or null if not bound. - * @return matches represented as a Match object. - * - */ - public Collection getAllMatches(final State pState, final State pTransitiveSubstate) { - return rawStreamAllMatches(new Object[]{pState, pTransitiveSubstate}).collect(Collectors.toSet()); - } - - /** - * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pTransitiveSubstate the fixed value of pattern parameter transitiveSubstate, or null if not bound. - * @return a stream of matches represented as a Match object. - * - */ - public Stream streamAllMatches(final State pState, final State pTransitiveSubstate) { - return rawStreamAllMatches(new Object[]{pState, pTransitiveSubstate}); - } - - /** - * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pTransitiveSubstate the fixed value of pattern parameter transitiveSubstate, or null if not bound. - * @return a match represented as a Match object, or null if no match is found. - * - */ - public Optional getOneArbitraryMatch(final State pState, final State pTransitiveSubstate) { - return rawGetOneArbitraryMatch(new Object[]{pState, pTransitiveSubstate}); - } - - /** - * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, - * under any possible substitution of the unspecified parameters (if any). - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pTransitiveSubstate the fixed value of pattern parameter transitiveSubstate, or null if not bound. - * @return true if the input is a valid (partial) match of the pattern. - * - */ - public boolean hasMatch(final State pState, final State pTransitiveSubstate) { - return rawHasMatch(new Object[]{pState, pTransitiveSubstate}); - } - - /** - * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pTransitiveSubstate the fixed value of pattern parameter transitiveSubstate, or null if not bound. - * @return the number of pattern matches found. - * - */ - public int countMatches(final State pState, final State pTransitiveSubstate) { - return rawCountMatches(new Object[]{pState, pTransitiveSubstate}); - } - - /** - * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pTransitiveSubstate the fixed value of pattern parameter transitiveSubstate, or null if not bound. - * @param processor the action that will process the selected match. - * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked - * - */ - public boolean forOneArbitraryMatch(final State pState, final State pTransitiveSubstate, final Consumer processor) { - return rawForOneArbitraryMatch(new Object[]{pState, pTransitiveSubstate}, processor); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pTransitiveSubstate the fixed value of pattern parameter transitiveSubstate, or null if not bound. - * @return the (partial) match object. - * - */ - public TransitiveSubstates.Match newMatch(final State pState, final State pTransitiveSubstate) { - return TransitiveSubstates.Match.newMatch(pState, pTransitiveSubstate); - } - - /** - * Retrieve the set of values that occur in matches for state. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOfstate(final Object[] parameters) { - return rawStreamAllValues(POSITION_STATE, parameters).map(State.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for state. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfstate() { - return rawStreamAllValuesOfstate(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for state. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfstate() { - return rawStreamAllValuesOfstate(emptyArray()); - } - - /** - * Retrieve the set of values that occur in matches for state. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfstate(final TransitiveSubstates.Match partialMatch) { - return rawStreamAllValuesOfstate(partialMatch.toArray()); - } - - /** - * Retrieve the set of values that occur in matches for state. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfstate(final State pTransitiveSubstate) { - return rawStreamAllValuesOfstate(new Object[]{null, pTransitiveSubstate}); - } - - /** - * Retrieve the set of values that occur in matches for state. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfstate(final TransitiveSubstates.Match partialMatch) { - return rawStreamAllValuesOfstate(partialMatch.toArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for state. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfstate(final State pTransitiveSubstate) { - return rawStreamAllValuesOfstate(new Object[]{null, pTransitiveSubstate}).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for transitiveSubstate. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOftransitiveSubstate(final Object[] parameters) { - return rawStreamAllValues(POSITION_TRANSITIVESUBSTATE, parameters).map(State.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for transitiveSubstate. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOftransitiveSubstate() { - return rawStreamAllValuesOftransitiveSubstate(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for transitiveSubstate. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOftransitiveSubstate() { - return rawStreamAllValuesOftransitiveSubstate(emptyArray()); - } - - /** - * Retrieve the set of values that occur in matches for transitiveSubstate. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOftransitiveSubstate(final TransitiveSubstates.Match partialMatch) { - return rawStreamAllValuesOftransitiveSubstate(partialMatch.toArray()); - } - - /** - * Retrieve the set of values that occur in matches for transitiveSubstate. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOftransitiveSubstate(final State pState) { - return rawStreamAllValuesOftransitiveSubstate(new Object[]{pState, null}); - } - - /** - * Retrieve the set of values that occur in matches for transitiveSubstate. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOftransitiveSubstate(final TransitiveSubstates.Match partialMatch) { - return rawStreamAllValuesOftransitiveSubstate(partialMatch.toArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for transitiveSubstate. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOftransitiveSubstate(final State pState) { - return rawStreamAllValuesOftransitiveSubstate(new Object[]{pState, null}).collect(Collectors.toSet()); - } - - @Override - protected TransitiveSubstates.Match tupleToMatch(final Tuple t) { - try { - return TransitiveSubstates.Match.newMatch((State) t.get(POSITION_STATE), (State) t.get(POSITION_TRANSITIVESUBSTATE)); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in tuple not properly typed!",e); - return null; - } - } - - @Override - protected TransitiveSubstates.Match arrayToMatch(final Object[] match) { - try { - return TransitiveSubstates.Match.newMatch((State) match[POSITION_STATE], (State) match[POSITION_TRANSITIVESUBSTATE]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - @Override - protected TransitiveSubstates.Match arrayToMatchMutable(final Object[] match) { - try { - return TransitiveSubstates.Match.newMutableMatch((State) match[POSITION_STATE], (State) match[POSITION_TRANSITIVESUBSTATE]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - /** - * @return the singleton instance of the query specification of this pattern - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static IQuerySpecification querySpecification() { - return TransitiveSubstates.instance(); - } - } - - private TransitiveSubstates() { - super(GeneratedPQuery.INSTANCE); - } - - /** - * @return the singleton instance of the query specification - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static TransitiveSubstates instance() { - try{ - return LazyHolder.INSTANCE; - } catch (ExceptionInInitializerError err) { - throw processInitializerError(err); - } - } - - @Override - protected TransitiveSubstates.Matcher instantiate(final ViatraQueryEngine engine) { - return TransitiveSubstates.Matcher.on(engine); - } - - @Override - public TransitiveSubstates.Matcher instantiate() { - return TransitiveSubstates.Matcher.create(); - } - - @Override - public TransitiveSubstates.Match newEmptyMatch() { - return TransitiveSubstates.Match.newEmptyMatch(); - } - - @Override - public TransitiveSubstates.Match newMatch(final Object... parameters) { - return TransitiveSubstates.Match.newMatch((com.nomagic.uml2.ext.magicdraw.statemachines.mdbehaviorstatemachines.State) parameters[0], (com.nomagic.uml2.ext.magicdraw.statemachines.mdbehaviorstatemachines.State) parameters[1]); - } - - /** - * Inner class allowing the singleton instance of {@link TransitiveSubstates} to be created - * not at the class load time of the outer class, - * but rather at the first call to {@link TransitiveSubstates#instance()}. - * - *

This workaround is required e.g. to support recursion. - * - */ - private static class LazyHolder { - private static final TransitiveSubstates INSTANCE = new TransitiveSubstates(); - - /** - * Statically initializes the query specification after the field {@link #INSTANCE} is assigned. - * This initialization order is required to support indirect recursion. - * - *

The static initializer is defined using a helper field to work around limitations of the code generator. - * - */ - private static final Object STATIC_INITIALIZER = ensureInitialized(); - - public static Object ensureInitialized() { - INSTANCE.ensureInitializedInternal(); - return null; - } - } - - private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { - private static final TransitiveSubstates.GeneratedPQuery INSTANCE = new GeneratedPQuery(); - - private final PParameter parameter_state = new PParameter("state", "com.nomagic.uml2.ext.magicdraw.statemachines.mdbehaviorstatemachines.State", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.nomagic.com/magicdraw/UML/2.5.1", "State")), PParameterDirection.INOUT); - - private final PParameter parameter_transitiveSubstate = new PParameter("transitiveSubstate", "com.nomagic.uml2.ext.magicdraw.statemachines.mdbehaviorstatemachines.State", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.nomagic.com/magicdraw/UML/2.5.1", "State")), PParameterDirection.INOUT); - - private final List parameters = Arrays.asList(parameter_state, parameter_transitiveSubstate); - - private GeneratedPQuery() { - super(PVisibility.PUBLIC); - } - - @Override - public String getFullyQualifiedName() { - return "com.incquerylabs.magicdraw.benchmark.queries.transitiveSubstates"; - } - - @Override - public List getParameterNames() { - return Arrays.asList("state","transitiveSubstate"); - } - - @Override - public List getParameters() { - return parameters; - } - - @Override - public Set doGetContainedBodies() { - setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); - Set bodies = new LinkedHashSet<>(); - { - PBody body = new PBody(this); - PVariable var_state = body.getOrCreateVariableByName("state"); - PVariable var_transitiveSubstate = body.getOrCreateVariableByName("transitiveSubstate"); - new TypeConstraint(body, Tuples.flatTupleOf(var_state), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "State"))); - new TypeConstraint(body, Tuples.flatTupleOf(var_transitiveSubstate), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "State"))); - body.setSymbolicParameters(Arrays.asList( - new ExportedParameter(body, var_state, parameter_state), - new ExportedParameter(body, var_transitiveSubstate, parameter_transitiveSubstate) - )); - // find parentState+(transitiveSubstate, state) - new BinaryTransitiveClosure(body, Tuples.flatTupleOf(var_transitiveSubstate, var_state), ParentState.instance().getInternalQueryRepresentation()); - bodies.add(body); - } - return bodies; - } - } -} diff --git a/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/TransitiveSubstatesWithCheck.java b/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/TransitiveSubstatesWithCheck.java deleted file mode 100644 index eaee554..0000000 --- a/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/TransitiveSubstatesWithCheck.java +++ /dev/null @@ -1,710 +0,0 @@ -/** - * Generated from platform:/resource/com.incquerylabs.magicdraw.benchmark/src/main/java/com/incquerylabs/magicdraw/benchmark/queries/APerformanceQueries.vql - */ -package com.incquerylabs.magicdraw.benchmark.queries; - -import com.incquerylabs.magicdraw.benchmark.queries.ParentState; -import com.incquerylabs.magicdraw.benchmark.queries.StatesWithShortNames; -import com.nomagic.uml2.ext.magicdraw.statemachines.mdbehaviorstatemachines.State; -import java.util.Arrays; -import java.util.Collection; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.function.Consumer; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import org.apache.log4j.Logger; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.viatra.query.runtime.api.IPatternMatch; -import org.eclipse.viatra.query.runtime.api.IQuerySpecification; -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.api.impl.BaseMatcher; -import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; -import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; -import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; -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.ExportedParameter; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.BinaryTransitiveClosure; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.PositivePatternCall; -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.PVisibility; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; -import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; - -/** - * A pattern-specific query specification that can instantiate Matcher in a type-safe way. - * - *

Original source: - *

- *         Reusing a simple pattern with a check expression before the transitive closure.
- *          
- *         pattern transitiveSubstatesWithCheck(state : State, transitiveSubstate : State) {
- *         	find statesWithShortNames(state);
- *         	find parentState+(transitiveSubstate, state);
- *         }
- * 
- * - * @see Matcher - * @see Match - * - */ -@SuppressWarnings("all") -public final class TransitiveSubstatesWithCheck extends BaseGeneratedEMFQuerySpecification { - /** - * Pattern-specific match representation of the com.incquerylabs.magicdraw.benchmark.queries.transitiveSubstatesWithCheck pattern, - * to be used in conjunction with {@link Matcher}. - * - *

Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. - * Each instance is a (possibly partial) substitution of pattern parameters, - * usable to represent a match of the pattern in the result of a query, - * or to specify the bound (fixed) input parameters when issuing a query. - * - * @see Matcher - * - */ - public static abstract class Match extends BasePatternMatch { - private State fState; - - private State fTransitiveSubstate; - - private static List parameterNames = makeImmutableList("state", "transitiveSubstate"); - - private Match(final State pState, final State pTransitiveSubstate) { - this.fState = pState; - this.fTransitiveSubstate = pTransitiveSubstate; - } - - @Override - public Object get(final String parameterName) { - switch(parameterName) { - case "state": return this.fState; - case "transitiveSubstate": return this.fTransitiveSubstate; - default: return null; - } - } - - @Override - public Object get(final int index) { - switch(index) { - case 0: return this.fState; - case 1: return this.fTransitiveSubstate; - default: return null; - } - } - - public State getState() { - return this.fState; - } - - public State getTransitiveSubstate() { - return this.fTransitiveSubstate; - } - - @Override - public boolean set(final String parameterName, final Object newValue) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - if ("state".equals(parameterName) ) { - this.fState = (State) newValue; - return true; - } - if ("transitiveSubstate".equals(parameterName) ) { - this.fTransitiveSubstate = (State) newValue; - return true; - } - return false; - } - - public void setState(final State pState) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fState = pState; - } - - public void setTransitiveSubstate(final State pTransitiveSubstate) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fTransitiveSubstate = pTransitiveSubstate; - } - - @Override - public String patternName() { - return "com.incquerylabs.magicdraw.benchmark.queries.transitiveSubstatesWithCheck"; - } - - @Override - public List parameterNames() { - return TransitiveSubstatesWithCheck.Match.parameterNames; - } - - @Override - public Object[] toArray() { - return new Object[]{fState, fTransitiveSubstate}; - } - - @Override - public TransitiveSubstatesWithCheck.Match toImmutable() { - return isMutable() ? newMatch(fState, fTransitiveSubstate) : this; - } - - @Override - public String prettyPrint() { - StringBuilder result = new StringBuilder(); - result.append("\"state\"=" + prettyPrintValue(fState) + ", "); - result.append("\"transitiveSubstate\"=" + prettyPrintValue(fTransitiveSubstate)); - return result.toString(); - } - - @Override - public int hashCode() { - return Objects.hash(fState, fTransitiveSubstate); - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) - return true; - if (obj == null) { - return false; - } - if ((obj instanceof TransitiveSubstatesWithCheck.Match)) { - TransitiveSubstatesWithCheck.Match other = (TransitiveSubstatesWithCheck.Match) obj; - return Objects.equals(fState, other.fState) && Objects.equals(fTransitiveSubstate, other.fTransitiveSubstate); - } else { - // this should be infrequent - if (!(obj instanceof IPatternMatch)) { - return false; - } - IPatternMatch otherSig = (IPatternMatch) obj; - return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); - } - } - - @Override - public TransitiveSubstatesWithCheck specification() { - return TransitiveSubstatesWithCheck.instance(); - } - - /** - * Returns an empty, mutable match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @return the empty match. - * - */ - public static TransitiveSubstatesWithCheck.Match newEmptyMatch() { - return new Mutable(null, null); - } - - /** - * Returns a mutable (partial) match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pTransitiveSubstate the fixed value of pattern parameter transitiveSubstate, or null if not bound. - * @return the new, mutable (partial) match object. - * - */ - public static TransitiveSubstatesWithCheck.Match newMutableMatch(final State pState, final State pTransitiveSubstate) { - return new Mutable(pState, pTransitiveSubstate); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pTransitiveSubstate the fixed value of pattern parameter transitiveSubstate, or null if not bound. - * @return the (partial) match object. - * - */ - public static TransitiveSubstatesWithCheck.Match newMatch(final State pState, final State pTransitiveSubstate) { - return new Immutable(pState, pTransitiveSubstate); - } - - private static final class Mutable extends TransitiveSubstatesWithCheck.Match { - Mutable(final State pState, final State pTransitiveSubstate) { - super(pState, pTransitiveSubstate); - } - - @Override - public boolean isMutable() { - return true; - } - } - - private static final class Immutable extends TransitiveSubstatesWithCheck.Match { - Immutable(final State pState, final State pTransitiveSubstate) { - super(pState, pTransitiveSubstate); - } - - @Override - public boolean isMutable() { - return false; - } - } - } - - /** - * Generated pattern matcher API of the com.incquerylabs.magicdraw.benchmark.queries.transitiveSubstatesWithCheck pattern, - * providing pattern-specific query methods. - * - *

Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, - * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. - * - *

Matches of the pattern will be represented as {@link Match}. - * - *

Original source: - *

-   * Reusing a simple pattern with a check expression before the transitive closure.
-   *  
-   * pattern transitiveSubstatesWithCheck(state : State, transitiveSubstate : State) {
-   * 	find statesWithShortNames(state);
-   * 	find parentState+(transitiveSubstate, state);
-   * }
-   * 
- * - * @see Match - * @see TransitiveSubstatesWithCheck - * - */ - public static class Matcher extends BaseMatcher { - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - public static TransitiveSubstatesWithCheck.Matcher on(final ViatraQueryEngine engine) { - // check if matcher already exists - Matcher matcher = engine.getExistingMatcher(querySpecification()); - if (matcher == null) { - matcher = (Matcher)engine.getMatcher(querySpecification()); - } - return matcher; - } - - /** - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * @return an initialized matcher - * @noreference This method is for internal matcher initialization by the framework, do not call it manually. - * - */ - public static TransitiveSubstatesWithCheck.Matcher create() { - return new Matcher(); - } - - private static final int POSITION_STATE = 0; - - private static final int POSITION_TRANSITIVESUBSTATE = 1; - - private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(TransitiveSubstatesWithCheck.Matcher.class); - - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - private Matcher() { - super(querySpecification()); - } - - /** - * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pTransitiveSubstate the fixed value of pattern parameter transitiveSubstate, or null if not bound. - * @return matches represented as a Match object. - * - */ - public Collection getAllMatches(final State pState, final State pTransitiveSubstate) { - return rawStreamAllMatches(new Object[]{pState, pTransitiveSubstate}).collect(Collectors.toSet()); - } - - /** - * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pTransitiveSubstate the fixed value of pattern parameter transitiveSubstate, or null if not bound. - * @return a stream of matches represented as a Match object. - * - */ - public Stream streamAllMatches(final State pState, final State pTransitiveSubstate) { - return rawStreamAllMatches(new Object[]{pState, pTransitiveSubstate}); - } - - /** - * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pTransitiveSubstate the fixed value of pattern parameter transitiveSubstate, or null if not bound. - * @return a match represented as a Match object, or null if no match is found. - * - */ - public Optional getOneArbitraryMatch(final State pState, final State pTransitiveSubstate) { - return rawGetOneArbitraryMatch(new Object[]{pState, pTransitiveSubstate}); - } - - /** - * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, - * under any possible substitution of the unspecified parameters (if any). - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pTransitiveSubstate the fixed value of pattern parameter transitiveSubstate, or null if not bound. - * @return true if the input is a valid (partial) match of the pattern. - * - */ - public boolean hasMatch(final State pState, final State pTransitiveSubstate) { - return rawHasMatch(new Object[]{pState, pTransitiveSubstate}); - } - - /** - * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pTransitiveSubstate the fixed value of pattern parameter transitiveSubstate, or null if not bound. - * @return the number of pattern matches found. - * - */ - public int countMatches(final State pState, final State pTransitiveSubstate) { - return rawCountMatches(new Object[]{pState, pTransitiveSubstate}); - } - - /** - * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pTransitiveSubstate the fixed value of pattern parameter transitiveSubstate, or null if not bound. - * @param processor the action that will process the selected match. - * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked - * - */ - public boolean forOneArbitraryMatch(final State pState, final State pTransitiveSubstate, final Consumer processor) { - return rawForOneArbitraryMatch(new Object[]{pState, pTransitiveSubstate}, processor); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pTransitiveSubstate the fixed value of pattern parameter transitiveSubstate, or null if not bound. - * @return the (partial) match object. - * - */ - public TransitiveSubstatesWithCheck.Match newMatch(final State pState, final State pTransitiveSubstate) { - return TransitiveSubstatesWithCheck.Match.newMatch(pState, pTransitiveSubstate); - } - - /** - * Retrieve the set of values that occur in matches for state. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOfstate(final Object[] parameters) { - return rawStreamAllValues(POSITION_STATE, parameters).map(State.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for state. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfstate() { - return rawStreamAllValuesOfstate(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for state. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfstate() { - return rawStreamAllValuesOfstate(emptyArray()); - } - - /** - * Retrieve the set of values that occur in matches for state. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfstate(final TransitiveSubstatesWithCheck.Match partialMatch) { - return rawStreamAllValuesOfstate(partialMatch.toArray()); - } - - /** - * Retrieve the set of values that occur in matches for state. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfstate(final State pTransitiveSubstate) { - return rawStreamAllValuesOfstate(new Object[]{null, pTransitiveSubstate}); - } - - /** - * Retrieve the set of values that occur in matches for state. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfstate(final TransitiveSubstatesWithCheck.Match partialMatch) { - return rawStreamAllValuesOfstate(partialMatch.toArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for state. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfstate(final State pTransitiveSubstate) { - return rawStreamAllValuesOfstate(new Object[]{null, pTransitiveSubstate}).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for transitiveSubstate. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOftransitiveSubstate(final Object[] parameters) { - return rawStreamAllValues(POSITION_TRANSITIVESUBSTATE, parameters).map(State.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for transitiveSubstate. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOftransitiveSubstate() { - return rawStreamAllValuesOftransitiveSubstate(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for transitiveSubstate. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOftransitiveSubstate() { - return rawStreamAllValuesOftransitiveSubstate(emptyArray()); - } - - /** - * Retrieve the set of values that occur in matches for transitiveSubstate. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOftransitiveSubstate(final TransitiveSubstatesWithCheck.Match partialMatch) { - return rawStreamAllValuesOftransitiveSubstate(partialMatch.toArray()); - } - - /** - * Retrieve the set of values that occur in matches for transitiveSubstate. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOftransitiveSubstate(final State pState) { - return rawStreamAllValuesOftransitiveSubstate(new Object[]{pState, null}); - } - - /** - * Retrieve the set of values that occur in matches for transitiveSubstate. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOftransitiveSubstate(final TransitiveSubstatesWithCheck.Match partialMatch) { - return rawStreamAllValuesOftransitiveSubstate(partialMatch.toArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for transitiveSubstate. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOftransitiveSubstate(final State pState) { - return rawStreamAllValuesOftransitiveSubstate(new Object[]{pState, null}).collect(Collectors.toSet()); - } - - @Override - protected TransitiveSubstatesWithCheck.Match tupleToMatch(final Tuple t) { - try { - return TransitiveSubstatesWithCheck.Match.newMatch((State) t.get(POSITION_STATE), (State) t.get(POSITION_TRANSITIVESUBSTATE)); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in tuple not properly typed!",e); - return null; - } - } - - @Override - protected TransitiveSubstatesWithCheck.Match arrayToMatch(final Object[] match) { - try { - return TransitiveSubstatesWithCheck.Match.newMatch((State) match[POSITION_STATE], (State) match[POSITION_TRANSITIVESUBSTATE]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - @Override - protected TransitiveSubstatesWithCheck.Match arrayToMatchMutable(final Object[] match) { - try { - return TransitiveSubstatesWithCheck.Match.newMutableMatch((State) match[POSITION_STATE], (State) match[POSITION_TRANSITIVESUBSTATE]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - /** - * @return the singleton instance of the query specification of this pattern - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static IQuerySpecification querySpecification() { - return TransitiveSubstatesWithCheck.instance(); - } - } - - private TransitiveSubstatesWithCheck() { - super(GeneratedPQuery.INSTANCE); - } - - /** - * @return the singleton instance of the query specification - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static TransitiveSubstatesWithCheck instance() { - try{ - return LazyHolder.INSTANCE; - } catch (ExceptionInInitializerError err) { - throw processInitializerError(err); - } - } - - @Override - protected TransitiveSubstatesWithCheck.Matcher instantiate(final ViatraQueryEngine engine) { - return TransitiveSubstatesWithCheck.Matcher.on(engine); - } - - @Override - public TransitiveSubstatesWithCheck.Matcher instantiate() { - return TransitiveSubstatesWithCheck.Matcher.create(); - } - - @Override - public TransitiveSubstatesWithCheck.Match newEmptyMatch() { - return TransitiveSubstatesWithCheck.Match.newEmptyMatch(); - } - - @Override - public TransitiveSubstatesWithCheck.Match newMatch(final Object... parameters) { - return TransitiveSubstatesWithCheck.Match.newMatch((com.nomagic.uml2.ext.magicdraw.statemachines.mdbehaviorstatemachines.State) parameters[0], (com.nomagic.uml2.ext.magicdraw.statemachines.mdbehaviorstatemachines.State) parameters[1]); - } - - /** - * Inner class allowing the singleton instance of {@link TransitiveSubstatesWithCheck} to be created - * not at the class load time of the outer class, - * but rather at the first call to {@link TransitiveSubstatesWithCheck#instance()}. - * - *

This workaround is required e.g. to support recursion. - * - */ - private static class LazyHolder { - private static final TransitiveSubstatesWithCheck INSTANCE = new TransitiveSubstatesWithCheck(); - - /** - * Statically initializes the query specification after the field {@link #INSTANCE} is assigned. - * This initialization order is required to support indirect recursion. - * - *

The static initializer is defined using a helper field to work around limitations of the code generator. - * - */ - private static final Object STATIC_INITIALIZER = ensureInitialized(); - - public static Object ensureInitialized() { - INSTANCE.ensureInitializedInternal(); - return null; - } - } - - private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { - private static final TransitiveSubstatesWithCheck.GeneratedPQuery INSTANCE = new GeneratedPQuery(); - - private final PParameter parameter_state = new PParameter("state", "com.nomagic.uml2.ext.magicdraw.statemachines.mdbehaviorstatemachines.State", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.nomagic.com/magicdraw/UML/2.5.1", "State")), PParameterDirection.INOUT); - - private final PParameter parameter_transitiveSubstate = new PParameter("transitiveSubstate", "com.nomagic.uml2.ext.magicdraw.statemachines.mdbehaviorstatemachines.State", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.nomagic.com/magicdraw/UML/2.5.1", "State")), PParameterDirection.INOUT); - - private final List parameters = Arrays.asList(parameter_state, parameter_transitiveSubstate); - - private GeneratedPQuery() { - super(PVisibility.PUBLIC); - } - - @Override - public String getFullyQualifiedName() { - return "com.incquerylabs.magicdraw.benchmark.queries.transitiveSubstatesWithCheck"; - } - - @Override - public List getParameterNames() { - return Arrays.asList("state","transitiveSubstate"); - } - - @Override - public List getParameters() { - return parameters; - } - - @Override - public Set doGetContainedBodies() { - setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); - Set bodies = new LinkedHashSet<>(); - { - PBody body = new PBody(this); - PVariable var_state = body.getOrCreateVariableByName("state"); - PVariable var_transitiveSubstate = body.getOrCreateVariableByName("transitiveSubstate"); - new TypeConstraint(body, Tuples.flatTupleOf(var_state), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "State"))); - new TypeConstraint(body, Tuples.flatTupleOf(var_transitiveSubstate), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "State"))); - body.setSymbolicParameters(Arrays.asList( - new ExportedParameter(body, var_state, parameter_state), - new ExportedParameter(body, var_transitiveSubstate, parameter_transitiveSubstate) - )); - // find statesWithShortNames(state) - new PositivePatternCall(body, Tuples.flatTupleOf(var_state), StatesWithShortNames.instance().getInternalQueryRepresentation()); - // find parentState+(transitiveSubstate, state) - new BinaryTransitiveClosure(body, Tuples.flatTupleOf(var_transitiveSubstate, var_state), ParentState.instance().getInternalQueryRepresentation()); - bodies.add(body); - } - return bodies; - } - } -} diff --git a/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/TransitiveSubstatesWithCheck2.java b/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/TransitiveSubstatesWithCheck2.java deleted file mode 100644 index aa1af02..0000000 --- a/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/TransitiveSubstatesWithCheck2.java +++ /dev/null @@ -1,742 +0,0 @@ -/** - * Generated from platform:/resource/com.incquerylabs.magicdraw.benchmark/src/main/java/com/incquerylabs/magicdraw/benchmark/queries/APerformanceQueries.vql - */ -package com.incquerylabs.magicdraw.benchmark.queries; - -import com.incquerylabs.magicdraw.benchmark.queries.IncomingTransitions; -import com.incquerylabs.magicdraw.benchmark.queries.ParentState; -import com.nomagic.uml2.ext.magicdraw.statemachines.mdbehaviorstatemachines.State; -import java.util.Arrays; -import java.util.Collection; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.function.Consumer; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import org.apache.log4j.Logger; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.viatra.query.runtime.api.IPatternMatch; -import org.eclipse.viatra.query.runtime.api.IQuerySpecification; -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.api.impl.BaseMatcher; -import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; -import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; -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.basicdeferred.PatternMatchCounter; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.BinaryTransitiveClosure; -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.PVisibility; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; -import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; - -/** - * A pattern-specific query specification that can instantiate Matcher in a type-safe way. - * - *

Original source: - *

- *         Reusing a simple pattern with a check expression before the transitive closure.
- *          
- *         pattern transitiveSubstatesWithCheck2(state : State, transitiveSubstate : State) {
- *         	transitionCount == count find incomingTransitions(_, state);
- *         	check (transitionCount {@literal >} 1);
- *         	find parentState+(transitiveSubstate, state);
- *         }
- * 
- * - * @see Matcher - * @see Match - * - */ -@SuppressWarnings("all") -public final class TransitiveSubstatesWithCheck2 extends BaseGeneratedEMFQuerySpecification { - /** - * Pattern-specific match representation of the com.incquerylabs.magicdraw.benchmark.queries.transitiveSubstatesWithCheck2 pattern, - * to be used in conjunction with {@link Matcher}. - * - *

Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. - * Each instance is a (possibly partial) substitution of pattern parameters, - * usable to represent a match of the pattern in the result of a query, - * or to specify the bound (fixed) input parameters when issuing a query. - * - * @see Matcher - * - */ - public static abstract class Match extends BasePatternMatch { - private State fState; - - private State fTransitiveSubstate; - - private static List parameterNames = makeImmutableList("state", "transitiveSubstate"); - - private Match(final State pState, final State pTransitiveSubstate) { - this.fState = pState; - this.fTransitiveSubstate = pTransitiveSubstate; - } - - @Override - public Object get(final String parameterName) { - switch(parameterName) { - case "state": return this.fState; - case "transitiveSubstate": return this.fTransitiveSubstate; - default: return null; - } - } - - @Override - public Object get(final int index) { - switch(index) { - case 0: return this.fState; - case 1: return this.fTransitiveSubstate; - default: return null; - } - } - - public State getState() { - return this.fState; - } - - public State getTransitiveSubstate() { - return this.fTransitiveSubstate; - } - - @Override - public boolean set(final String parameterName, final Object newValue) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - if ("state".equals(parameterName) ) { - this.fState = (State) newValue; - return true; - } - if ("transitiveSubstate".equals(parameterName) ) { - this.fTransitiveSubstate = (State) newValue; - return true; - } - return false; - } - - public void setState(final State pState) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fState = pState; - } - - public void setTransitiveSubstate(final State pTransitiveSubstate) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fTransitiveSubstate = pTransitiveSubstate; - } - - @Override - public String patternName() { - return "com.incquerylabs.magicdraw.benchmark.queries.transitiveSubstatesWithCheck2"; - } - - @Override - public List parameterNames() { - return TransitiveSubstatesWithCheck2.Match.parameterNames; - } - - @Override - public Object[] toArray() { - return new Object[]{fState, fTransitiveSubstate}; - } - - @Override - public TransitiveSubstatesWithCheck2.Match toImmutable() { - return isMutable() ? newMatch(fState, fTransitiveSubstate) : this; - } - - @Override - public String prettyPrint() { - StringBuilder result = new StringBuilder(); - result.append("\"state\"=" + prettyPrintValue(fState) + ", "); - result.append("\"transitiveSubstate\"=" + prettyPrintValue(fTransitiveSubstate)); - return result.toString(); - } - - @Override - public int hashCode() { - return Objects.hash(fState, fTransitiveSubstate); - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) - return true; - if (obj == null) { - return false; - } - if ((obj instanceof TransitiveSubstatesWithCheck2.Match)) { - TransitiveSubstatesWithCheck2.Match other = (TransitiveSubstatesWithCheck2.Match) obj; - return Objects.equals(fState, other.fState) && Objects.equals(fTransitiveSubstate, other.fTransitiveSubstate); - } else { - // this should be infrequent - if (!(obj instanceof IPatternMatch)) { - return false; - } - IPatternMatch otherSig = (IPatternMatch) obj; - return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); - } - } - - @Override - public TransitiveSubstatesWithCheck2 specification() { - return TransitiveSubstatesWithCheck2.instance(); - } - - /** - * Returns an empty, mutable match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @return the empty match. - * - */ - public static TransitiveSubstatesWithCheck2.Match newEmptyMatch() { - return new Mutable(null, null); - } - - /** - * Returns a mutable (partial) match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pTransitiveSubstate the fixed value of pattern parameter transitiveSubstate, or null if not bound. - * @return the new, mutable (partial) match object. - * - */ - public static TransitiveSubstatesWithCheck2.Match newMutableMatch(final State pState, final State pTransitiveSubstate) { - return new Mutable(pState, pTransitiveSubstate); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pTransitiveSubstate the fixed value of pattern parameter transitiveSubstate, or null if not bound. - * @return the (partial) match object. - * - */ - public static TransitiveSubstatesWithCheck2.Match newMatch(final State pState, final State pTransitiveSubstate) { - return new Immutable(pState, pTransitiveSubstate); - } - - private static final class Mutable extends TransitiveSubstatesWithCheck2.Match { - Mutable(final State pState, final State pTransitiveSubstate) { - super(pState, pTransitiveSubstate); - } - - @Override - public boolean isMutable() { - return true; - } - } - - private static final class Immutable extends TransitiveSubstatesWithCheck2.Match { - Immutable(final State pState, final State pTransitiveSubstate) { - super(pState, pTransitiveSubstate); - } - - @Override - public boolean isMutable() { - return false; - } - } - } - - /** - * Generated pattern matcher API of the com.incquerylabs.magicdraw.benchmark.queries.transitiveSubstatesWithCheck2 pattern, - * providing pattern-specific query methods. - * - *

Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, - * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. - * - *

Matches of the pattern will be represented as {@link Match}. - * - *

Original source: - *

-   * Reusing a simple pattern with a check expression before the transitive closure.
-   *  
-   * pattern transitiveSubstatesWithCheck2(state : State, transitiveSubstate : State) {
-   * 	transitionCount == count find incomingTransitions(_, state);
-   * 	check (transitionCount {@literal >} 1);
-   * 	find parentState+(transitiveSubstate, state);
-   * }
-   * 
- * - * @see Match - * @see TransitiveSubstatesWithCheck2 - * - */ - public static class Matcher extends BaseMatcher { - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - public static TransitiveSubstatesWithCheck2.Matcher on(final ViatraQueryEngine engine) { - // check if matcher already exists - Matcher matcher = engine.getExistingMatcher(querySpecification()); - if (matcher == null) { - matcher = (Matcher)engine.getMatcher(querySpecification()); - } - return matcher; - } - - /** - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * @return an initialized matcher - * @noreference This method is for internal matcher initialization by the framework, do not call it manually. - * - */ - public static TransitiveSubstatesWithCheck2.Matcher create() { - return new Matcher(); - } - - private static final int POSITION_STATE = 0; - - private static final int POSITION_TRANSITIVESUBSTATE = 1; - - private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(TransitiveSubstatesWithCheck2.Matcher.class); - - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - private Matcher() { - super(querySpecification()); - } - - /** - * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pTransitiveSubstate the fixed value of pattern parameter transitiveSubstate, or null if not bound. - * @return matches represented as a Match object. - * - */ - public Collection getAllMatches(final State pState, final State pTransitiveSubstate) { - return rawStreamAllMatches(new Object[]{pState, pTransitiveSubstate}).collect(Collectors.toSet()); - } - - /** - * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pTransitiveSubstate the fixed value of pattern parameter transitiveSubstate, or null if not bound. - * @return a stream of matches represented as a Match object. - * - */ - public Stream streamAllMatches(final State pState, final State pTransitiveSubstate) { - return rawStreamAllMatches(new Object[]{pState, pTransitiveSubstate}); - } - - /** - * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pTransitiveSubstate the fixed value of pattern parameter transitiveSubstate, or null if not bound. - * @return a match represented as a Match object, or null if no match is found. - * - */ - public Optional getOneArbitraryMatch(final State pState, final State pTransitiveSubstate) { - return rawGetOneArbitraryMatch(new Object[]{pState, pTransitiveSubstate}); - } - - /** - * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, - * under any possible substitution of the unspecified parameters (if any). - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pTransitiveSubstate the fixed value of pattern parameter transitiveSubstate, or null if not bound. - * @return true if the input is a valid (partial) match of the pattern. - * - */ - public boolean hasMatch(final State pState, final State pTransitiveSubstate) { - return rawHasMatch(new Object[]{pState, pTransitiveSubstate}); - } - - /** - * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pTransitiveSubstate the fixed value of pattern parameter transitiveSubstate, or null if not bound. - * @return the number of pattern matches found. - * - */ - public int countMatches(final State pState, final State pTransitiveSubstate) { - return rawCountMatches(new Object[]{pState, pTransitiveSubstate}); - } - - /** - * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pTransitiveSubstate the fixed value of pattern parameter transitiveSubstate, or null if not bound. - * @param processor the action that will process the selected match. - * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked - * - */ - public boolean forOneArbitraryMatch(final State pState, final State pTransitiveSubstate, final Consumer processor) { - return rawForOneArbitraryMatch(new Object[]{pState, pTransitiveSubstate}, processor); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pTransitiveSubstate the fixed value of pattern parameter transitiveSubstate, or null if not bound. - * @return the (partial) match object. - * - */ - public TransitiveSubstatesWithCheck2.Match newMatch(final State pState, final State pTransitiveSubstate) { - return TransitiveSubstatesWithCheck2.Match.newMatch(pState, pTransitiveSubstate); - } - - /** - * Retrieve the set of values that occur in matches for state. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOfstate(final Object[] parameters) { - return rawStreamAllValues(POSITION_STATE, parameters).map(State.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for state. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfstate() { - return rawStreamAllValuesOfstate(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for state. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfstate() { - return rawStreamAllValuesOfstate(emptyArray()); - } - - /** - * Retrieve the set of values that occur in matches for state. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfstate(final TransitiveSubstatesWithCheck2.Match partialMatch) { - return rawStreamAllValuesOfstate(partialMatch.toArray()); - } - - /** - * Retrieve the set of values that occur in matches for state. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfstate(final State pTransitiveSubstate) { - return rawStreamAllValuesOfstate(new Object[]{null, pTransitiveSubstate}); - } - - /** - * Retrieve the set of values that occur in matches for state. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfstate(final TransitiveSubstatesWithCheck2.Match partialMatch) { - return rawStreamAllValuesOfstate(partialMatch.toArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for state. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfstate(final State pTransitiveSubstate) { - return rawStreamAllValuesOfstate(new Object[]{null, pTransitiveSubstate}).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for transitiveSubstate. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOftransitiveSubstate(final Object[] parameters) { - return rawStreamAllValues(POSITION_TRANSITIVESUBSTATE, parameters).map(State.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for transitiveSubstate. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOftransitiveSubstate() { - return rawStreamAllValuesOftransitiveSubstate(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for transitiveSubstate. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOftransitiveSubstate() { - return rawStreamAllValuesOftransitiveSubstate(emptyArray()); - } - - /** - * Retrieve the set of values that occur in matches for transitiveSubstate. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOftransitiveSubstate(final TransitiveSubstatesWithCheck2.Match partialMatch) { - return rawStreamAllValuesOftransitiveSubstate(partialMatch.toArray()); - } - - /** - * Retrieve the set of values that occur in matches for transitiveSubstate. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOftransitiveSubstate(final State pState) { - return rawStreamAllValuesOftransitiveSubstate(new Object[]{pState, null}); - } - - /** - * Retrieve the set of values that occur in matches for transitiveSubstate. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOftransitiveSubstate(final TransitiveSubstatesWithCheck2.Match partialMatch) { - return rawStreamAllValuesOftransitiveSubstate(partialMatch.toArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for transitiveSubstate. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOftransitiveSubstate(final State pState) { - return rawStreamAllValuesOftransitiveSubstate(new Object[]{pState, null}).collect(Collectors.toSet()); - } - - @Override - protected TransitiveSubstatesWithCheck2.Match tupleToMatch(final Tuple t) { - try { - return TransitiveSubstatesWithCheck2.Match.newMatch((State) t.get(POSITION_STATE), (State) t.get(POSITION_TRANSITIVESUBSTATE)); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in tuple not properly typed!",e); - return null; - } - } - - @Override - protected TransitiveSubstatesWithCheck2.Match arrayToMatch(final Object[] match) { - try { - return TransitiveSubstatesWithCheck2.Match.newMatch((State) match[POSITION_STATE], (State) match[POSITION_TRANSITIVESUBSTATE]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - @Override - protected TransitiveSubstatesWithCheck2.Match arrayToMatchMutable(final Object[] match) { - try { - return TransitiveSubstatesWithCheck2.Match.newMutableMatch((State) match[POSITION_STATE], (State) match[POSITION_TRANSITIVESUBSTATE]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - /** - * @return the singleton instance of the query specification of this pattern - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static IQuerySpecification querySpecification() { - return TransitiveSubstatesWithCheck2.instance(); - } - } - - private TransitiveSubstatesWithCheck2() { - super(GeneratedPQuery.INSTANCE); - } - - /** - * @return the singleton instance of the query specification - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static TransitiveSubstatesWithCheck2 instance() { - try{ - return LazyHolder.INSTANCE; - } catch (ExceptionInInitializerError err) { - throw processInitializerError(err); - } - } - - @Override - protected TransitiveSubstatesWithCheck2.Matcher instantiate(final ViatraQueryEngine engine) { - return TransitiveSubstatesWithCheck2.Matcher.on(engine); - } - - @Override - public TransitiveSubstatesWithCheck2.Matcher instantiate() { - return TransitiveSubstatesWithCheck2.Matcher.create(); - } - - @Override - public TransitiveSubstatesWithCheck2.Match newEmptyMatch() { - return TransitiveSubstatesWithCheck2.Match.newEmptyMatch(); - } - - @Override - public TransitiveSubstatesWithCheck2.Match newMatch(final Object... parameters) { - return TransitiveSubstatesWithCheck2.Match.newMatch((com.nomagic.uml2.ext.magicdraw.statemachines.mdbehaviorstatemachines.State) parameters[0], (com.nomagic.uml2.ext.magicdraw.statemachines.mdbehaviorstatemachines.State) parameters[1]); - } - - /** - * Inner class allowing the singleton instance of {@link TransitiveSubstatesWithCheck2} to be created - * not at the class load time of the outer class, - * but rather at the first call to {@link TransitiveSubstatesWithCheck2#instance()}. - * - *

This workaround is required e.g. to support recursion. - * - */ - private static class LazyHolder { - private static final TransitiveSubstatesWithCheck2 INSTANCE = new TransitiveSubstatesWithCheck2(); - - /** - * Statically initializes the query specification after the field {@link #INSTANCE} is assigned. - * This initialization order is required to support indirect recursion. - * - *

The static initializer is defined using a helper field to work around limitations of the code generator. - * - */ - private static final Object STATIC_INITIALIZER = ensureInitialized(); - - public static Object ensureInitialized() { - INSTANCE.ensureInitializedInternal(); - return null; - } - } - - private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { - private static final TransitiveSubstatesWithCheck2.GeneratedPQuery INSTANCE = new GeneratedPQuery(); - - private final PParameter parameter_state = new PParameter("state", "com.nomagic.uml2.ext.magicdraw.statemachines.mdbehaviorstatemachines.State", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.nomagic.com/magicdraw/UML/2.5.1", "State")), PParameterDirection.INOUT); - - private final PParameter parameter_transitiveSubstate = new PParameter("transitiveSubstate", "com.nomagic.uml2.ext.magicdraw.statemachines.mdbehaviorstatemachines.State", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.nomagic.com/magicdraw/UML/2.5.1", "State")), PParameterDirection.INOUT); - - private final List parameters = Arrays.asList(parameter_state, parameter_transitiveSubstate); - - private GeneratedPQuery() { - super(PVisibility.PUBLIC); - } - - @Override - public String getFullyQualifiedName() { - return "com.incquerylabs.magicdraw.benchmark.queries.transitiveSubstatesWithCheck2"; - } - - @Override - public List getParameterNames() { - return Arrays.asList("state","transitiveSubstate"); - } - - @Override - public List getParameters() { - return parameters; - } - - @Override - public Set doGetContainedBodies() { - setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); - Set bodies = new LinkedHashSet<>(); - { - PBody body = new PBody(this); - PVariable var_state = body.getOrCreateVariableByName("state"); - PVariable var_transitiveSubstate = body.getOrCreateVariableByName("transitiveSubstate"); - PVariable var_transitionCount = body.getOrCreateVariableByName("transitionCount"); - PVariable var___0_ = body.getOrCreateVariableByName("_<0>"); - new TypeConstraint(body, Tuples.flatTupleOf(var_state), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "State"))); - new TypeConstraint(body, Tuples.flatTupleOf(var_transitiveSubstate), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "State"))); - body.setSymbolicParameters(Arrays.asList( - new ExportedParameter(body, var_state, parameter_state), - new ExportedParameter(body, var_transitiveSubstate, parameter_transitiveSubstate) - )); - // transitionCount == count find incomingTransitions(_, state) - PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); - new PatternMatchCounter(body, Tuples.flatTupleOf(var___0_, var_state), IncomingTransitions.instance().getInternalQueryRepresentation(), var__virtual_0_); - new Equality(body, var_transitionCount, var__virtual_0_); - // check (transitionCount > 1) - new ExpressionEvaluation(body, new IExpressionEvaluator() { - - @Override - public String getShortDescription() { - return "Expression evaluation from pattern transitiveSubstatesWithCheck2"; - } - - @Override - public Iterable getInputParameterNames() { - return Arrays.asList("transitionCount");} - - @Override - public Object evaluateExpression(IValueProvider provider) throws Exception { - Integer transitionCount = (Integer) provider.getValue("transitionCount"); - return evaluateExpression_1_1(transitionCount); - } - }, null); - // find parentState+(transitiveSubstate, state) - new BinaryTransitiveClosure(body, Tuples.flatTupleOf(var_transitiveSubstate, var_state), ParentState.instance().getInternalQueryRepresentation()); - bodies.add(body); - } - return bodies; - } - } - - private static boolean evaluateExpression_1_1(final Integer transitionCount) { - return ((transitionCount).intValue() > 1); - } -} diff --git a/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/TransitiveSubstatesWithCheck3.java b/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/TransitiveSubstatesWithCheck3.java deleted file mode 100644 index a7b376b..0000000 --- a/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/TransitiveSubstatesWithCheck3.java +++ /dev/null @@ -1,710 +0,0 @@ -/** - * Generated from platform:/resource/com.incquerylabs.magicdraw.benchmark/src/main/java/com/incquerylabs/magicdraw/benchmark/queries/APerformanceQueries.vql - */ -package com.incquerylabs.magicdraw.benchmark.queries; - -import com.incquerylabs.magicdraw.benchmark.queries.ParentState; -import com.incquerylabs.magicdraw.benchmark.queries.StatesWithMoreIncomingTransitions; -import com.nomagic.uml2.ext.magicdraw.statemachines.mdbehaviorstatemachines.State; -import java.util.Arrays; -import java.util.Collection; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.function.Consumer; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import org.apache.log4j.Logger; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.viatra.query.runtime.api.IPatternMatch; -import org.eclipse.viatra.query.runtime.api.IQuerySpecification; -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.api.impl.BaseMatcher; -import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; -import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; -import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; -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.ExportedParameter; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.BinaryTransitiveClosure; -import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.PositivePatternCall; -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.PVisibility; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; -import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; - -/** - * A pattern-specific query specification that can instantiate Matcher in a type-safe way. - * - *

Original source: - *

- *         Reusing a simple pattern with a check expression before the transitive closure.
- *          
- *         pattern transitiveSubstatesWithCheck3(state : State, transitiveSubstate : State) {
- *         	find statesWithMoreIncomingTransitions(state);
- *         	find parentState+(transitiveSubstate, state);
- *         }
- * 
- * - * @see Matcher - * @see Match - * - */ -@SuppressWarnings("all") -public final class TransitiveSubstatesWithCheck3 extends BaseGeneratedEMFQuerySpecification { - /** - * Pattern-specific match representation of the com.incquerylabs.magicdraw.benchmark.queries.transitiveSubstatesWithCheck3 pattern, - * to be used in conjunction with {@link Matcher}. - * - *

Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. - * Each instance is a (possibly partial) substitution of pattern parameters, - * usable to represent a match of the pattern in the result of a query, - * or to specify the bound (fixed) input parameters when issuing a query. - * - * @see Matcher - * - */ - public static abstract class Match extends BasePatternMatch { - private State fState; - - private State fTransitiveSubstate; - - private static List parameterNames = makeImmutableList("state", "transitiveSubstate"); - - private Match(final State pState, final State pTransitiveSubstate) { - this.fState = pState; - this.fTransitiveSubstate = pTransitiveSubstate; - } - - @Override - public Object get(final String parameterName) { - switch(parameterName) { - case "state": return this.fState; - case "transitiveSubstate": return this.fTransitiveSubstate; - default: return null; - } - } - - @Override - public Object get(final int index) { - switch(index) { - case 0: return this.fState; - case 1: return this.fTransitiveSubstate; - default: return null; - } - } - - public State getState() { - return this.fState; - } - - public State getTransitiveSubstate() { - return this.fTransitiveSubstate; - } - - @Override - public boolean set(final String parameterName, final Object newValue) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - if ("state".equals(parameterName) ) { - this.fState = (State) newValue; - return true; - } - if ("transitiveSubstate".equals(parameterName) ) { - this.fTransitiveSubstate = (State) newValue; - return true; - } - return false; - } - - public void setState(final State pState) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fState = pState; - } - - public void setTransitiveSubstate(final State pTransitiveSubstate) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fTransitiveSubstate = pTransitiveSubstate; - } - - @Override - public String patternName() { - return "com.incquerylabs.magicdraw.benchmark.queries.transitiveSubstatesWithCheck3"; - } - - @Override - public List parameterNames() { - return TransitiveSubstatesWithCheck3.Match.parameterNames; - } - - @Override - public Object[] toArray() { - return new Object[]{fState, fTransitiveSubstate}; - } - - @Override - public TransitiveSubstatesWithCheck3.Match toImmutable() { - return isMutable() ? newMatch(fState, fTransitiveSubstate) : this; - } - - @Override - public String prettyPrint() { - StringBuilder result = new StringBuilder(); - result.append("\"state\"=" + prettyPrintValue(fState) + ", "); - result.append("\"transitiveSubstate\"=" + prettyPrintValue(fTransitiveSubstate)); - return result.toString(); - } - - @Override - public int hashCode() { - return Objects.hash(fState, fTransitiveSubstate); - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) - return true; - if (obj == null) { - return false; - } - if ((obj instanceof TransitiveSubstatesWithCheck3.Match)) { - TransitiveSubstatesWithCheck3.Match other = (TransitiveSubstatesWithCheck3.Match) obj; - return Objects.equals(fState, other.fState) && Objects.equals(fTransitiveSubstate, other.fTransitiveSubstate); - } else { - // this should be infrequent - if (!(obj instanceof IPatternMatch)) { - return false; - } - IPatternMatch otherSig = (IPatternMatch) obj; - return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); - } - } - - @Override - public TransitiveSubstatesWithCheck3 specification() { - return TransitiveSubstatesWithCheck3.instance(); - } - - /** - * Returns an empty, mutable match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @return the empty match. - * - */ - public static TransitiveSubstatesWithCheck3.Match newEmptyMatch() { - return new Mutable(null, null); - } - - /** - * Returns a mutable (partial) match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pTransitiveSubstate the fixed value of pattern parameter transitiveSubstate, or null if not bound. - * @return the new, mutable (partial) match object. - * - */ - public static TransitiveSubstatesWithCheck3.Match newMutableMatch(final State pState, final State pTransitiveSubstate) { - return new Mutable(pState, pTransitiveSubstate); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pTransitiveSubstate the fixed value of pattern parameter transitiveSubstate, or null if not bound. - * @return the (partial) match object. - * - */ - public static TransitiveSubstatesWithCheck3.Match newMatch(final State pState, final State pTransitiveSubstate) { - return new Immutable(pState, pTransitiveSubstate); - } - - private static final class Mutable extends TransitiveSubstatesWithCheck3.Match { - Mutable(final State pState, final State pTransitiveSubstate) { - super(pState, pTransitiveSubstate); - } - - @Override - public boolean isMutable() { - return true; - } - } - - private static final class Immutable extends TransitiveSubstatesWithCheck3.Match { - Immutable(final State pState, final State pTransitiveSubstate) { - super(pState, pTransitiveSubstate); - } - - @Override - public boolean isMutable() { - return false; - } - } - } - - /** - * Generated pattern matcher API of the com.incquerylabs.magicdraw.benchmark.queries.transitiveSubstatesWithCheck3 pattern, - * providing pattern-specific query methods. - * - *

Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, - * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. - * - *

Matches of the pattern will be represented as {@link Match}. - * - *

Original source: - *

-   * Reusing a simple pattern with a check expression before the transitive closure.
-   *  
-   * pattern transitiveSubstatesWithCheck3(state : State, transitiveSubstate : State) {
-   * 	find statesWithMoreIncomingTransitions(state);
-   * 	find parentState+(transitiveSubstate, state);
-   * }
-   * 
- * - * @see Match - * @see TransitiveSubstatesWithCheck3 - * - */ - public static class Matcher extends BaseMatcher { - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - public static TransitiveSubstatesWithCheck3.Matcher on(final ViatraQueryEngine engine) { - // check if matcher already exists - Matcher matcher = engine.getExistingMatcher(querySpecification()); - if (matcher == null) { - matcher = (Matcher)engine.getMatcher(querySpecification()); - } - return matcher; - } - - /** - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * @return an initialized matcher - * @noreference This method is for internal matcher initialization by the framework, do not call it manually. - * - */ - public static TransitiveSubstatesWithCheck3.Matcher create() { - return new Matcher(); - } - - private static final int POSITION_STATE = 0; - - private static final int POSITION_TRANSITIVESUBSTATE = 1; - - private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(TransitiveSubstatesWithCheck3.Matcher.class); - - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - private Matcher() { - super(querySpecification()); - } - - /** - * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pTransitiveSubstate the fixed value of pattern parameter transitiveSubstate, or null if not bound. - * @return matches represented as a Match object. - * - */ - public Collection getAllMatches(final State pState, final State pTransitiveSubstate) { - return rawStreamAllMatches(new Object[]{pState, pTransitiveSubstate}).collect(Collectors.toSet()); - } - - /** - * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pTransitiveSubstate the fixed value of pattern parameter transitiveSubstate, or null if not bound. - * @return a stream of matches represented as a Match object. - * - */ - public Stream streamAllMatches(final State pState, final State pTransitiveSubstate) { - return rawStreamAllMatches(new Object[]{pState, pTransitiveSubstate}); - } - - /** - * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pTransitiveSubstate the fixed value of pattern parameter transitiveSubstate, or null if not bound. - * @return a match represented as a Match object, or null if no match is found. - * - */ - public Optional getOneArbitraryMatch(final State pState, final State pTransitiveSubstate) { - return rawGetOneArbitraryMatch(new Object[]{pState, pTransitiveSubstate}); - } - - /** - * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, - * under any possible substitution of the unspecified parameters (if any). - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pTransitiveSubstate the fixed value of pattern parameter transitiveSubstate, or null if not bound. - * @return true if the input is a valid (partial) match of the pattern. - * - */ - public boolean hasMatch(final State pState, final State pTransitiveSubstate) { - return rawHasMatch(new Object[]{pState, pTransitiveSubstate}); - } - - /** - * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pTransitiveSubstate the fixed value of pattern parameter transitiveSubstate, or null if not bound. - * @return the number of pattern matches found. - * - */ - public int countMatches(final State pState, final State pTransitiveSubstate) { - return rawCountMatches(new Object[]{pState, pTransitiveSubstate}); - } - - /** - * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pTransitiveSubstate the fixed value of pattern parameter transitiveSubstate, or null if not bound. - * @param processor the action that will process the selected match. - * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked - * - */ - public boolean forOneArbitraryMatch(final State pState, final State pTransitiveSubstate, final Consumer processor) { - return rawForOneArbitraryMatch(new Object[]{pState, pTransitiveSubstate}, processor); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pState the fixed value of pattern parameter state, or null if not bound. - * @param pTransitiveSubstate the fixed value of pattern parameter transitiveSubstate, or null if not bound. - * @return the (partial) match object. - * - */ - public TransitiveSubstatesWithCheck3.Match newMatch(final State pState, final State pTransitiveSubstate) { - return TransitiveSubstatesWithCheck3.Match.newMatch(pState, pTransitiveSubstate); - } - - /** - * Retrieve the set of values that occur in matches for state. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOfstate(final Object[] parameters) { - return rawStreamAllValues(POSITION_STATE, parameters).map(State.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for state. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfstate() { - return rawStreamAllValuesOfstate(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for state. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfstate() { - return rawStreamAllValuesOfstate(emptyArray()); - } - - /** - * Retrieve the set of values that occur in matches for state. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfstate(final TransitiveSubstatesWithCheck3.Match partialMatch) { - return rawStreamAllValuesOfstate(partialMatch.toArray()); - } - - /** - * Retrieve the set of values that occur in matches for state. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfstate(final State pTransitiveSubstate) { - return rawStreamAllValuesOfstate(new Object[]{null, pTransitiveSubstate}); - } - - /** - * Retrieve the set of values that occur in matches for state. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfstate(final TransitiveSubstatesWithCheck3.Match partialMatch) { - return rawStreamAllValuesOfstate(partialMatch.toArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for state. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfstate(final State pTransitiveSubstate) { - return rawStreamAllValuesOfstate(new Object[]{null, pTransitiveSubstate}).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for transitiveSubstate. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOftransitiveSubstate(final Object[] parameters) { - return rawStreamAllValues(POSITION_TRANSITIVESUBSTATE, parameters).map(State.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for transitiveSubstate. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOftransitiveSubstate() { - return rawStreamAllValuesOftransitiveSubstate(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for transitiveSubstate. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOftransitiveSubstate() { - return rawStreamAllValuesOftransitiveSubstate(emptyArray()); - } - - /** - * Retrieve the set of values that occur in matches for transitiveSubstate. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOftransitiveSubstate(final TransitiveSubstatesWithCheck3.Match partialMatch) { - return rawStreamAllValuesOftransitiveSubstate(partialMatch.toArray()); - } - - /** - * Retrieve the set of values that occur in matches for transitiveSubstate. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOftransitiveSubstate(final State pState) { - return rawStreamAllValuesOftransitiveSubstate(new Object[]{pState, null}); - } - - /** - * Retrieve the set of values that occur in matches for transitiveSubstate. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOftransitiveSubstate(final TransitiveSubstatesWithCheck3.Match partialMatch) { - return rawStreamAllValuesOftransitiveSubstate(partialMatch.toArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for transitiveSubstate. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOftransitiveSubstate(final State pState) { - return rawStreamAllValuesOftransitiveSubstate(new Object[]{pState, null}).collect(Collectors.toSet()); - } - - @Override - protected TransitiveSubstatesWithCheck3.Match tupleToMatch(final Tuple t) { - try { - return TransitiveSubstatesWithCheck3.Match.newMatch((State) t.get(POSITION_STATE), (State) t.get(POSITION_TRANSITIVESUBSTATE)); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in tuple not properly typed!",e); - return null; - } - } - - @Override - protected TransitiveSubstatesWithCheck3.Match arrayToMatch(final Object[] match) { - try { - return TransitiveSubstatesWithCheck3.Match.newMatch((State) match[POSITION_STATE], (State) match[POSITION_TRANSITIVESUBSTATE]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - @Override - protected TransitiveSubstatesWithCheck3.Match arrayToMatchMutable(final Object[] match) { - try { - return TransitiveSubstatesWithCheck3.Match.newMutableMatch((State) match[POSITION_STATE], (State) match[POSITION_TRANSITIVESUBSTATE]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - /** - * @return the singleton instance of the query specification of this pattern - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static IQuerySpecification querySpecification() { - return TransitiveSubstatesWithCheck3.instance(); - } - } - - private TransitiveSubstatesWithCheck3() { - super(GeneratedPQuery.INSTANCE); - } - - /** - * @return the singleton instance of the query specification - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static TransitiveSubstatesWithCheck3 instance() { - try{ - return LazyHolder.INSTANCE; - } catch (ExceptionInInitializerError err) { - throw processInitializerError(err); - } - } - - @Override - protected TransitiveSubstatesWithCheck3.Matcher instantiate(final ViatraQueryEngine engine) { - return TransitiveSubstatesWithCheck3.Matcher.on(engine); - } - - @Override - public TransitiveSubstatesWithCheck3.Matcher instantiate() { - return TransitiveSubstatesWithCheck3.Matcher.create(); - } - - @Override - public TransitiveSubstatesWithCheck3.Match newEmptyMatch() { - return TransitiveSubstatesWithCheck3.Match.newEmptyMatch(); - } - - @Override - public TransitiveSubstatesWithCheck3.Match newMatch(final Object... parameters) { - return TransitiveSubstatesWithCheck3.Match.newMatch((com.nomagic.uml2.ext.magicdraw.statemachines.mdbehaviorstatemachines.State) parameters[0], (com.nomagic.uml2.ext.magicdraw.statemachines.mdbehaviorstatemachines.State) parameters[1]); - } - - /** - * Inner class allowing the singleton instance of {@link TransitiveSubstatesWithCheck3} to be created - * not at the class load time of the outer class, - * but rather at the first call to {@link TransitiveSubstatesWithCheck3#instance()}. - * - *

This workaround is required e.g. to support recursion. - * - */ - private static class LazyHolder { - private static final TransitiveSubstatesWithCheck3 INSTANCE = new TransitiveSubstatesWithCheck3(); - - /** - * Statically initializes the query specification after the field {@link #INSTANCE} is assigned. - * This initialization order is required to support indirect recursion. - * - *

The static initializer is defined using a helper field to work around limitations of the code generator. - * - */ - private static final Object STATIC_INITIALIZER = ensureInitialized(); - - public static Object ensureInitialized() { - INSTANCE.ensureInitializedInternal(); - return null; - } - } - - private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { - private static final TransitiveSubstatesWithCheck3.GeneratedPQuery INSTANCE = new GeneratedPQuery(); - - private final PParameter parameter_state = new PParameter("state", "com.nomagic.uml2.ext.magicdraw.statemachines.mdbehaviorstatemachines.State", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.nomagic.com/magicdraw/UML/2.5.1", "State")), PParameterDirection.INOUT); - - private final PParameter parameter_transitiveSubstate = new PParameter("transitiveSubstate", "com.nomagic.uml2.ext.magicdraw.statemachines.mdbehaviorstatemachines.State", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.nomagic.com/magicdraw/UML/2.5.1", "State")), PParameterDirection.INOUT); - - private final List parameters = Arrays.asList(parameter_state, parameter_transitiveSubstate); - - private GeneratedPQuery() { - super(PVisibility.PUBLIC); - } - - @Override - public String getFullyQualifiedName() { - return "com.incquerylabs.magicdraw.benchmark.queries.transitiveSubstatesWithCheck3"; - } - - @Override - public List getParameterNames() { - return Arrays.asList("state","transitiveSubstate"); - } - - @Override - public List getParameters() { - return parameters; - } - - @Override - public Set doGetContainedBodies() { - setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); - Set bodies = new LinkedHashSet<>(); - { - PBody body = new PBody(this); - PVariable var_state = body.getOrCreateVariableByName("state"); - PVariable var_transitiveSubstate = body.getOrCreateVariableByName("transitiveSubstate"); - new TypeConstraint(body, Tuples.flatTupleOf(var_state), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "State"))); - new TypeConstraint(body, Tuples.flatTupleOf(var_transitiveSubstate), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "State"))); - body.setSymbolicParameters(Arrays.asList( - new ExportedParameter(body, var_state, parameter_state), - new ExportedParameter(body, var_transitiveSubstate, parameter_transitiveSubstate) - )); - // find statesWithMoreIncomingTransitions(state) - new PositivePatternCall(body, Tuples.flatTupleOf(var_state), StatesWithMoreIncomingTransitions.instance().getInternalQueryRepresentation()); - // find parentState+(transitiveSubstate, state) - new BinaryTransitiveClosure(body, Tuples.flatTupleOf(var_transitiveSubstate, var_state), ParentState.instance().getInternalQueryRepresentation()); - bodies.add(body); - } - return bodies; - } - } -} diff --git a/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/Variables.java b/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/Variables.java deleted file mode 100644 index 6a0f6be..0000000 --- a/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/Variables.java +++ /dev/null @@ -1,709 +0,0 @@ -/** - * Generated from platform:/resource/com.incquerylabs.magicdraw.benchmark/src/main/java/com/incquerylabs/magicdraw/benchmark/queries/WarmUpQueries.vql - */ -package com.incquerylabs.magicdraw.benchmark.queries; - -import com.nomagic.uml2.ext.magicdraw.activities.mdstructuredactivities.Variable; -import com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Type; -import java.util.Arrays; -import java.util.Collection; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.function.Consumer; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import org.apache.log4j.Logger; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.viatra.query.runtime.api.IPatternMatch; -import org.eclipse.viatra.query.runtime.api.IQuerySpecification; -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.api.impl.BaseMatcher; -import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; -import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; -import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey; -import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; -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.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.PVisibility; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; -import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; - -/** - * A pattern-specific query specification that can instantiate Matcher in a type-safe way. - * - *

Original source: - *

- *         // All these patterns are used to warm up the JVM before the real performance queries.
- *         
- *         pattern variables(variable : Variable, type : Type ) {
- *         	Variable.type(variable, type);
- *         }
- * 
- * - * @see Matcher - * @see Match - * - */ -@SuppressWarnings("all") -public final class Variables extends BaseGeneratedEMFQuerySpecification { - /** - * Pattern-specific match representation of the com.incquerylabs.magicdraw.benchmark.queries.variables pattern, - * to be used in conjunction with {@link Matcher}. - * - *

Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. - * Each instance is a (possibly partial) substitution of pattern parameters, - * usable to represent a match of the pattern in the result of a query, - * or to specify the bound (fixed) input parameters when issuing a query. - * - * @see Matcher - * - */ - public static abstract class Match extends BasePatternMatch { - private Variable fVariable; - - private Type fType; - - private static List parameterNames = makeImmutableList("variable", "type"); - - private Match(final Variable pVariable, final Type pType) { - this.fVariable = pVariable; - this.fType = pType; - } - - @Override - public Object get(final String parameterName) { - switch(parameterName) { - case "variable": return this.fVariable; - case "type": return this.fType; - default: return null; - } - } - - @Override - public Object get(final int index) { - switch(index) { - case 0: return this.fVariable; - case 1: return this.fType; - default: return null; - } - } - - public Variable getVariable() { - return this.fVariable; - } - - public Type getType() { - return this.fType; - } - - @Override - public boolean set(final String parameterName, final Object newValue) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - if ("variable".equals(parameterName) ) { - this.fVariable = (Variable) newValue; - return true; - } - if ("type".equals(parameterName) ) { - this.fType = (Type) newValue; - return true; - } - return false; - } - - public void setVariable(final Variable pVariable) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fVariable = pVariable; - } - - public void setType(final Type pType) { - if (!isMutable()) throw new java.lang.UnsupportedOperationException(); - this.fType = pType; - } - - @Override - public String patternName() { - return "com.incquerylabs.magicdraw.benchmark.queries.variables"; - } - - @Override - public List parameterNames() { - return Variables.Match.parameterNames; - } - - @Override - public Object[] toArray() { - return new Object[]{fVariable, fType}; - } - - @Override - public Variables.Match toImmutable() { - return isMutable() ? newMatch(fVariable, fType) : this; - } - - @Override - public String prettyPrint() { - StringBuilder result = new StringBuilder(); - result.append("\"variable\"=" + prettyPrintValue(fVariable) + ", "); - result.append("\"type\"=" + prettyPrintValue(fType)); - return result.toString(); - } - - @Override - public int hashCode() { - return Objects.hash(fVariable, fType); - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) - return true; - if (obj == null) { - return false; - } - if ((obj instanceof Variables.Match)) { - Variables.Match other = (Variables.Match) obj; - return Objects.equals(fVariable, other.fVariable) && Objects.equals(fType, other.fType); - } else { - // this should be infrequent - if (!(obj instanceof IPatternMatch)) { - return false; - } - IPatternMatch otherSig = (IPatternMatch) obj; - return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); - } - } - - @Override - public Variables specification() { - return Variables.instance(); - } - - /** - * Returns an empty, mutable match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @return the empty match. - * - */ - public static Variables.Match newEmptyMatch() { - return new Mutable(null, null); - } - - /** - * Returns a mutable (partial) match. - * Fields of the mutable match can be filled to create a partial match, usable as matcher input. - * - * @param pVariable the fixed value of pattern parameter variable, or null if not bound. - * @param pType the fixed value of pattern parameter type, or null if not bound. - * @return the new, mutable (partial) match object. - * - */ - public static Variables.Match newMutableMatch(final Variable pVariable, final Type pType) { - return new Mutable(pVariable, pType); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pVariable the fixed value of pattern parameter variable, or null if not bound. - * @param pType the fixed value of pattern parameter type, or null if not bound. - * @return the (partial) match object. - * - */ - public static Variables.Match newMatch(final Variable pVariable, final Type pType) { - return new Immutable(pVariable, pType); - } - - private static final class Mutable extends Variables.Match { - Mutable(final Variable pVariable, final Type pType) { - super(pVariable, pType); - } - - @Override - public boolean isMutable() { - return true; - } - } - - private static final class Immutable extends Variables.Match { - Immutable(final Variable pVariable, final Type pType) { - super(pVariable, pType); - } - - @Override - public boolean isMutable() { - return false; - } - } - } - - /** - * Generated pattern matcher API of the com.incquerylabs.magicdraw.benchmark.queries.variables pattern, - * providing pattern-specific query methods. - * - *

Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, - * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. - * - *

Matches of the pattern will be represented as {@link Match}. - * - *

Original source: - *

-   * // All these patterns are used to warm up the JVM before the real performance queries.
-   * 
-   * pattern variables(variable : Variable, type : Type ) {
-   * 	Variable.type(variable, type);
-   * }
-   * 
- * - * @see Match - * @see Variables - * - */ - public static class Matcher extends BaseMatcher { - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - public static Variables.Matcher on(final ViatraQueryEngine engine) { - // check if matcher already exists - Matcher matcher = engine.getExistingMatcher(querySpecification()); - if (matcher == null) { - matcher = (Matcher)engine.getMatcher(querySpecification()); - } - return matcher; - } - - /** - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * @return an initialized matcher - * @noreference This method is for internal matcher initialization by the framework, do not call it manually. - * - */ - public static Variables.Matcher create() { - return new Matcher(); - } - - private static final int POSITION_VARIABLE = 0; - - private static final int POSITION_TYPE = 1; - - private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(Variables.Matcher.class); - - /** - * Initializes the pattern matcher within an existing VIATRA Query engine. - * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. - * - * @param engine the existing VIATRA Query engine in which this matcher will be created. - * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation - * - */ - private Matcher() { - super(querySpecification()); - } - - /** - * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pVariable the fixed value of pattern parameter variable, or null if not bound. - * @param pType the fixed value of pattern parameter type, or null if not bound. - * @return matches represented as a Match object. - * - */ - public Collection getAllMatches(final Variable pVariable, final Type pType) { - return rawStreamAllMatches(new Object[]{pVariable, pType}).collect(Collectors.toSet()); - } - - /** - * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * @param pVariable the fixed value of pattern parameter variable, or null if not bound. - * @param pType the fixed value of pattern parameter type, or null if not bound. - * @return a stream of matches represented as a Match object. - * - */ - public Stream streamAllMatches(final Variable pVariable, final Type pType) { - return rawStreamAllMatches(new Object[]{pVariable, pType}); - } - - /** - * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pVariable the fixed value of pattern parameter variable, or null if not bound. - * @param pType the fixed value of pattern parameter type, or null if not bound. - * @return a match represented as a Match object, or null if no match is found. - * - */ - public Optional getOneArbitraryMatch(final Variable pVariable, final Type pType) { - return rawGetOneArbitraryMatch(new Object[]{pVariable, pType}); - } - - /** - * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, - * under any possible substitution of the unspecified parameters (if any). - * @param pVariable the fixed value of pattern parameter variable, or null if not bound. - * @param pType the fixed value of pattern parameter type, or null if not bound. - * @return true if the input is a valid (partial) match of the pattern. - * - */ - public boolean hasMatch(final Variable pVariable, final Type pType) { - return rawHasMatch(new Object[]{pVariable, pType}); - } - - /** - * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. - * @param pVariable the fixed value of pattern parameter variable, or null if not bound. - * @param pType the fixed value of pattern parameter type, or null if not bound. - * @return the number of pattern matches found. - * - */ - public int countMatches(final Variable pVariable, final Type pType) { - return rawCountMatches(new Object[]{pVariable, pType}); - } - - /** - * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. - * Neither determinism nor randomness of selection is guaranteed. - * @param pVariable the fixed value of pattern parameter variable, or null if not bound. - * @param pType the fixed value of pattern parameter type, or null if not bound. - * @param processor the action that will process the selected match. - * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked - * - */ - public boolean forOneArbitraryMatch(final Variable pVariable, final Type pType, final Consumer processor) { - return rawForOneArbitraryMatch(new Object[]{pVariable, pType}, processor); - } - - /** - * Returns a new (partial) match. - * This can be used e.g. to call the matcher with a partial match. - *

The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. - * @param pVariable the fixed value of pattern parameter variable, or null if not bound. - * @param pType the fixed value of pattern parameter type, or null if not bound. - * @return the (partial) match object. - * - */ - public Variables.Match newMatch(final Variable pVariable, final Type pType) { - return Variables.Match.newMatch(pVariable, pType); - } - - /** - * Retrieve the set of values that occur in matches for variable. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOfvariable(final Object[] parameters) { - return rawStreamAllValues(POSITION_VARIABLE, parameters).map(Variable.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for variable. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfvariable() { - return rawStreamAllValuesOfvariable(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for variable. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfvariable() { - return rawStreamAllValuesOfvariable(emptyArray()); - } - - /** - * Retrieve the set of values that occur in matches for variable. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfvariable(final Variables.Match partialMatch) { - return rawStreamAllValuesOfvariable(partialMatch.toArray()); - } - - /** - * Retrieve the set of values that occur in matches for variable. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOfvariable(final Type pType) { - return rawStreamAllValuesOfvariable(new Object[]{null, pType}); - } - - /** - * Retrieve the set of values that occur in matches for variable. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfvariable(final Variables.Match partialMatch) { - return rawStreamAllValuesOfvariable(partialMatch.toArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for variable. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOfvariable(final Type pType) { - return rawStreamAllValuesOfvariable(new Object[]{null, pType}).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for type. - * @return the Set of all values or empty set if there are no matches - * - */ - protected Stream rawStreamAllValuesOftype(final Object[] parameters) { - return rawStreamAllValues(POSITION_TYPE, parameters).map(Type.class::cast); - } - - /** - * Retrieve the set of values that occur in matches for type. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOftype() { - return rawStreamAllValuesOftype(emptyArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for type. - * @return the Set of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOftype() { - return rawStreamAllValuesOftype(emptyArray()); - } - - /** - * Retrieve the set of values that occur in matches for type. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOftype(final Variables.Match partialMatch) { - return rawStreamAllValuesOftype(partialMatch.toArray()); - } - - /** - * Retrieve the set of values that occur in matches for type. - *

- * NOTE: It is important not to modify the source model while the stream is being processed. - * If the match set of the pattern changes during processing, the contents of the stream is undefined. - * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. - * - * @return the Stream of all values or empty set if there are no matches - * - */ - public Stream streamAllValuesOftype(final Variable pVariable) { - return rawStreamAllValuesOftype(new Object[]{pVariable, null}); - } - - /** - * Retrieve the set of values that occur in matches for type. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOftype(final Variables.Match partialMatch) { - return rawStreamAllValuesOftype(partialMatch.toArray()).collect(Collectors.toSet()); - } - - /** - * Retrieve the set of values that occur in matches for type. - * @return the Set of all values or empty set if there are no matches - * - */ - public Set getAllValuesOftype(final Variable pVariable) { - return rawStreamAllValuesOftype(new Object[]{pVariable, null}).collect(Collectors.toSet()); - } - - @Override - protected Variables.Match tupleToMatch(final Tuple t) { - try { - return Variables.Match.newMatch((Variable) t.get(POSITION_VARIABLE), (Type) t.get(POSITION_TYPE)); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in tuple not properly typed!",e); - return null; - } - } - - @Override - protected Variables.Match arrayToMatch(final Object[] match) { - try { - return Variables.Match.newMatch((Variable) match[POSITION_VARIABLE], (Type) match[POSITION_TYPE]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - @Override - protected Variables.Match arrayToMatchMutable(final Object[] match) { - try { - return Variables.Match.newMutableMatch((Variable) match[POSITION_VARIABLE], (Type) match[POSITION_TYPE]); - } catch(ClassCastException e) { - LOGGER.error("Element(s) in array not properly typed!",e); - return null; - } - } - - /** - * @return the singleton instance of the query specification of this pattern - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static IQuerySpecification querySpecification() { - return Variables.instance(); - } - } - - private Variables() { - super(GeneratedPQuery.INSTANCE); - } - - /** - * @return the singleton instance of the query specification - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static Variables instance() { - try{ - return LazyHolder.INSTANCE; - } catch (ExceptionInInitializerError err) { - throw processInitializerError(err); - } - } - - @Override - protected Variables.Matcher instantiate(final ViatraQueryEngine engine) { - return Variables.Matcher.on(engine); - } - - @Override - public Variables.Matcher instantiate() { - return Variables.Matcher.create(); - } - - @Override - public Variables.Match newEmptyMatch() { - return Variables.Match.newEmptyMatch(); - } - - @Override - public Variables.Match newMatch(final Object... parameters) { - return Variables.Match.newMatch((com.nomagic.uml2.ext.magicdraw.activities.mdstructuredactivities.Variable) parameters[0], (com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Type) parameters[1]); - } - - /** - * Inner class allowing the singleton instance of {@link Variables} to be created - * not at the class load time of the outer class, - * but rather at the first call to {@link Variables#instance()}. - * - *

This workaround is required e.g. to support recursion. - * - */ - private static class LazyHolder { - private static final Variables INSTANCE = new Variables(); - - /** - * Statically initializes the query specification after the field {@link #INSTANCE} is assigned. - * This initialization order is required to support indirect recursion. - * - *

The static initializer is defined using a helper field to work around limitations of the code generator. - * - */ - private static final Object STATIC_INITIALIZER = ensureInitialized(); - - public static Object ensureInitialized() { - INSTANCE.ensureInitializedInternal(); - return null; - } - } - - private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { - private static final Variables.GeneratedPQuery INSTANCE = new GeneratedPQuery(); - - private final PParameter parameter_variable = new PParameter("variable", "com.nomagic.uml2.ext.magicdraw.activities.mdstructuredactivities.Variable", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.nomagic.com/magicdraw/UML/2.5.1", "Variable")), PParameterDirection.INOUT); - - private final PParameter parameter_type = new PParameter("type", "com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Type", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.nomagic.com/magicdraw/UML/2.5.1", "Type")), PParameterDirection.INOUT); - - private final List parameters = Arrays.asList(parameter_variable, parameter_type); - - private GeneratedPQuery() { - super(PVisibility.PUBLIC); - } - - @Override - public String getFullyQualifiedName() { - return "com.incquerylabs.magicdraw.benchmark.queries.variables"; - } - - @Override - public List getParameterNames() { - return Arrays.asList("variable","type"); - } - - @Override - public List getParameters() { - return parameters; - } - - @Override - public Set doGetContainedBodies() { - setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); - Set bodies = new LinkedHashSet<>(); - { - PBody body = new PBody(this); - PVariable var_variable = body.getOrCreateVariableByName("variable"); - PVariable var_type = body.getOrCreateVariableByName("type"); - new TypeConstraint(body, Tuples.flatTupleOf(var_variable), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Variable"))); - new TypeConstraint(body, Tuples.flatTupleOf(var_type), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Type"))); - body.setSymbolicParameters(Arrays.asList( - new ExportedParameter(body, var_variable, parameter_variable), - new ExportedParameter(body, var_type, parameter_type) - )); - // Variable.type(variable, type) - new TypeConstraint(body, Tuples.flatTupleOf(var_variable), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Variable"))); - PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_variable, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "TypedElement", "type"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Type"))); - new Equality(body, var__virtual_0_, var_type); - bodies.add(body); - } - return bodies; - } - } -} diff --git a/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/WarmUpQueries.java b/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/WarmUpQueries.java deleted file mode 100644 index b085388..0000000 --- a/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/WarmUpQueries.java +++ /dev/null @@ -1,86 +0,0 @@ -/** - * Generated from platform:/resource/com.incquerylabs.magicdraw.benchmark/src/main/java/com/incquerylabs/magicdraw/benchmark/queries/WarmUpQueries.vql - */ -package com.incquerylabs.magicdraw.benchmark.queries; - -import com.incquerylabs.magicdraw.benchmark.queries.Activitites; -import com.incquerylabs.magicdraw.benchmark.queries.ActorGeneralization; -import com.incquerylabs.magicdraw.benchmark.queries.AssociationClasses; -import com.incquerylabs.magicdraw.benchmark.queries.Variables; -import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; -import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedPatternGroup; - -/** - * A pattern group formed of all public patterns defined in WarmUpQueries.vql. - * - *

Use the static instance as any {@link interface org.eclipse.viatra.query.runtime.api.IQueryGroup}, to conveniently prepare - * a VIATRA Query engine for matching all patterns originally defined in file WarmUpQueries.vql, - * in order to achieve better performance than one-by-one on-demand matcher initialization. - * - *

From package com.incquerylabs.magicdraw.benchmark.queries, the group contains the definition of the following patterns:

    - *
  • variables
  • - *
  • associationClasses
  • - *
  • activitites
  • - *
  • actorGeneralization
  • - *
- * - * @see IQueryGroup - * - */ -@SuppressWarnings("all") -public final class WarmUpQueries extends BaseGeneratedPatternGroup { - /** - * Access the pattern group. - * - * @return the singleton instance of the group - * @throws ViatraQueryRuntimeException if there was an error loading the generated code of pattern specifications - * - */ - public static WarmUpQueries instance() { - if (INSTANCE == null) { - INSTANCE = new WarmUpQueries(); - } - return INSTANCE; - } - - private static WarmUpQueries INSTANCE; - - private WarmUpQueries() { - querySpecifications.add(Variables.instance()); - querySpecifications.add(AssociationClasses.instance()); - querySpecifications.add(Activitites.instance()); - querySpecifications.add(ActorGeneralization.instance()); - } - - public Variables getVariables() { - return Variables.instance(); - } - - public Variables.Matcher getVariables(final ViatraQueryEngine engine) { - return Variables.Matcher.on(engine); - } - - public AssociationClasses getAssociationClasses() { - return AssociationClasses.instance(); - } - - public AssociationClasses.Matcher getAssociationClasses(final ViatraQueryEngine engine) { - return AssociationClasses.Matcher.on(engine); - } - - public Activitites getActivitites() { - return Activitites.instance(); - } - - public Activitites.Matcher getActivitites(final ViatraQueryEngine engine) { - return Activitites.Matcher.on(engine); - } - - public ActorGeneralization getActorGeneralization() { - return ActorGeneralization.instance(); - } - - public ActorGeneralization.Matcher getActorGeneralization(final ViatraQueryEngine engine) { - return ActorGeneralization.Matcher.on(engine); - } -} diff --git a/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/internal/APerformanceQueriesAll.java b/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/internal/APerformanceQueriesAll.java deleted file mode 100644 index 7c38b02..0000000 --- a/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/internal/APerformanceQueriesAll.java +++ /dev/null @@ -1,132 +0,0 @@ -/** - * Generated from platform:/resource/com.incquerylabs.magicdraw.benchmark/src/main/java/com/incquerylabs/magicdraw/benchmark/queries/APerformanceQueries.vql - */ -package com.incquerylabs.magicdraw.benchmark.queries.internal; - -import com.incquerylabs.magicdraw.benchmark.queries.AllBenchMarkedQueries; -import com.incquerylabs.magicdraw.benchmark.queries.AlphabeticalDependencies; -import com.incquerylabs.magicdraw.benchmark.queries.Blocks; -import com.incquerylabs.magicdraw.benchmark.queries.BlocksOrRequirements; -import com.incquerylabs.magicdraw.benchmark.queries.BlocksOrRequirementsOrConstraints; -import com.incquerylabs.magicdraw.benchmark.queries.CircularDependencies; -import com.incquerylabs.magicdraw.benchmark.queries.Classes; -import com.incquerylabs.magicdraw.benchmark.queries.ComplexNameOfElements; -import com.incquerylabs.magicdraw.benchmark.queries.Dependencies; -import com.incquerylabs.magicdraw.benchmark.queries.DependencyChains; -import com.incquerylabs.magicdraw.benchmark.queries.ElementsWithShortNames; -import com.incquerylabs.magicdraw.benchmark.queries.IncomingTransitions; -import com.incquerylabs.magicdraw.benchmark.queries.LoopTransitionWithTriggerEffectEventNoGuard; -import com.incquerylabs.magicdraw.benchmark.queries.NamedElement; -import com.incquerylabs.magicdraw.benchmark.queries.NamesOfDependencyEndpoints; -import com.incquerylabs.magicdraw.benchmark.queries.NonBlockClasses; -import com.incquerylabs.magicdraw.benchmark.queries.NumberOfSubregions; -import com.incquerylabs.magicdraw.benchmark.queries.NumberOfTransitiveSubstates; -import com.incquerylabs.magicdraw.benchmark.queries.ParentState; -import com.incquerylabs.magicdraw.benchmark.queries.Requirements; -import com.incquerylabs.magicdraw.benchmark.queries.StateWithMostSubstates; -import com.incquerylabs.magicdraw.benchmark.queries.StatesWithMoreIncomingTransitions; -import com.incquerylabs.magicdraw.benchmark.queries.StatesWithShortNames; -import com.incquerylabs.magicdraw.benchmark.queries.Subregions; -import com.incquerylabs.magicdraw.benchmark.queries.TransitionPointingOutOfCompState; -import com.incquerylabs.magicdraw.benchmark.queries.TransitiveSubstates; -import com.incquerylabs.magicdraw.benchmark.queries.TransitiveSubstatesWithCheck; -import com.incquerylabs.magicdraw.benchmark.queries.TransitiveSubstatesWithCheck2; -import com.incquerylabs.magicdraw.benchmark.queries.TransitiveSubstatesWithCheck3; -import com.incquerylabs.magicdraw.benchmark.queries.internal.ConstraintBlocks; -import com.incquerylabs.magicdraw.benchmark.queries.internal.TransitionWithGuard; -import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedPatternGroup; - -/** - * A pattern group formed of all patterns defined in APerformanceQueries.vql. - * - *

A private group that includes private patterns as well. Only intended use case is for pattern testing. - * - *

From package com.incquerylabs.magicdraw.benchmark.queries, the group contains the definition of the following patterns:

    - *
  • classes
  • - *
  • nonBlockClasses
  • - *
  • blocks
  • - *
  • requirements
  • - *
  • constraintBlocks
  • - *
  • blocksOrRequirements
  • - *
  • blocksOrRequirementsOrConstraints
  • - *
  • namedElement
  • - *
  • complexNameOfElements
  • - *
  • dependencyChains
  • - *
  • circularDependencies
  • - *
  • dependencies
  • - *
  • namesOfDependencyEndpoints
  • - *
  • alphabeticalDependencies
  • - *
  • elementsWithShortNames
  • - *
  • transitionPointingOutOfCompState
  • - *
  • loopTransitionWithTriggerEffectEventNoGuard
  • - *
  • transitionWithGuard
  • - *
  • parentState
  • - *
  • subregions
  • - *
  • numberOfSubregions
  • - *
  • statesWithShortNames
  • - *
  • incomingTransitions
  • - *
  • transitiveSubstates
  • - *
  • transitiveSubstatesWithCheck
  • - *
  • statesWithMoreIncomingTransitions
  • - *
  • transitiveSubstatesWithCheck2
  • - *
  • transitiveSubstatesWithCheck3
  • - *
  • numberOfTransitiveSubstates
  • - *
  • stateWithMostSubstates
  • - *
  • allBenchMarkedQueries
  • - *
- * - * @see IQueryGroup - * - */ -@SuppressWarnings("all") -public final class APerformanceQueriesAll extends BaseGeneratedPatternGroup { - /** - * Access the pattern group. - * - * @return the singleton instance of the group - * @throws ViatraQueryRuntimeException if there was an error loading the generated code of pattern specifications - * - */ - public static APerformanceQueriesAll instance() { - if (INSTANCE == null) { - INSTANCE = new APerformanceQueriesAll(); - } - return INSTANCE; - } - - private static APerformanceQueriesAll INSTANCE; - - private APerformanceQueriesAll() { - querySpecifications.add(Classes.instance()); - querySpecifications.add(NonBlockClasses.instance()); - querySpecifications.add(Blocks.instance()); - querySpecifications.add(Requirements.instance()); - querySpecifications.add(ConstraintBlocks.instance()); - querySpecifications.add(BlocksOrRequirements.instance()); - querySpecifications.add(BlocksOrRequirementsOrConstraints.instance()); - querySpecifications.add(NamedElement.instance()); - querySpecifications.add(ComplexNameOfElements.instance()); - querySpecifications.add(DependencyChains.instance()); - querySpecifications.add(CircularDependencies.instance()); - querySpecifications.add(Dependencies.instance()); - querySpecifications.add(NamesOfDependencyEndpoints.instance()); - querySpecifications.add(AlphabeticalDependencies.instance()); - querySpecifications.add(ElementsWithShortNames.instance()); - querySpecifications.add(TransitionPointingOutOfCompState.instance()); - querySpecifications.add(LoopTransitionWithTriggerEffectEventNoGuard.instance()); - querySpecifications.add(TransitionWithGuard.instance()); - querySpecifications.add(ParentState.instance()); - querySpecifications.add(Subregions.instance()); - querySpecifications.add(NumberOfSubregions.instance()); - querySpecifications.add(StatesWithShortNames.instance()); - querySpecifications.add(IncomingTransitions.instance()); - querySpecifications.add(TransitiveSubstates.instance()); - querySpecifications.add(TransitiveSubstatesWithCheck.instance()); - querySpecifications.add(StatesWithMoreIncomingTransitions.instance()); - querySpecifications.add(TransitiveSubstatesWithCheck2.instance()); - querySpecifications.add(TransitiveSubstatesWithCheck3.instance()); - querySpecifications.add(NumberOfTransitiveSubstates.instance()); - querySpecifications.add(StateWithMostSubstates.instance()); - querySpecifications.add(AllBenchMarkedQueries.instance()); - } -} diff --git a/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/internal/ConstraintBlocks.java b/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/internal/ConstraintBlocks.java deleted file mode 100644 index e09417b..0000000 --- a/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/internal/ConstraintBlocks.java +++ /dev/null @@ -1,146 +0,0 @@ -/** - * Generated from platform:/resource/com.incquerylabs.magicdraw.benchmark/src/main/java/com/incquerylabs/magicdraw/benchmark/queries/APerformanceQueries.vql - */ -package com.incquerylabs.magicdraw.benchmark.queries.internal; - -import java.util.Arrays; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Set; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.emf.ecore.EDataType; -import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; -import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecificationWithGenericMatcher; -import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; -import org.eclipse.viatra.query.runtime.emf.types.EDataTypeInSlotsKey; -import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey; -import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; -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.basicenumerables.ConstantValue; -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.PVisibility; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; - -/** - * A pattern-specific query specification that can instantiate GenericPatternMatcher in a type-safe way. - * - *

Original source: - *

- *         Querying all instances of an EClass that have a short "reference chain".
- *          
- *         private pattern constraintBlocks(class : Class) {
- *         	Class.appliedStereotypeInstance.classifier.name(class, "Constraint"); 
- *         }
- * 
- * - * @see GenericPatternMatcher - * @see GenericPatternMatch - * - */ -@SuppressWarnings("all") -public final class ConstraintBlocks extends BaseGeneratedEMFQuerySpecificationWithGenericMatcher { - private ConstraintBlocks() { - super(GeneratedPQuery.INSTANCE); - } - - /** - * @return the singleton instance of the query specification - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static ConstraintBlocks instance() { - try{ - return LazyHolder.INSTANCE; - } catch (ExceptionInInitializerError err) { - throw processInitializerError(err); - } - } - - /** - * Inner class allowing the singleton instance of {@link ConstraintBlocks} to be created - * not at the class load time of the outer class, - * but rather at the first call to {@link ConstraintBlocks#instance()}. - * - *

This workaround is required e.g. to support recursion. - * - */ - private static class LazyHolder { - private static final ConstraintBlocks INSTANCE = new ConstraintBlocks(); - - /** - * Statically initializes the query specification after the field {@link #INSTANCE} is assigned. - * This initialization order is required to support indirect recursion. - * - *

The static initializer is defined using a helper field to work around limitations of the code generator. - * - */ - private static final Object STATIC_INITIALIZER = ensureInitialized(); - - public static Object ensureInitialized() { - INSTANCE.ensureInitializedInternal(); - return null; - } - } - - private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { - private static final ConstraintBlocks.GeneratedPQuery INSTANCE = new GeneratedPQuery(); - - private final PParameter parameter_class = new PParameter("class", "com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.nomagic.com/magicdraw/UML/2.5.1", "Class")), PParameterDirection.INOUT); - - private final List parameters = Arrays.asList(parameter_class); - - private GeneratedPQuery() { - super(PVisibility.PRIVATE); - } - - @Override - public String getFullyQualifiedName() { - return "com.incquerylabs.magicdraw.benchmark.queries.constraintBlocks"; - } - - @Override - public List getParameterNames() { - return Arrays.asList("class"); - } - - @Override - public List getParameters() { - return parameters; - } - - @Override - public Set doGetContainedBodies() { - setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); - Set bodies = new LinkedHashSet<>(); - { - PBody body = new PBody(this); - PVariable var_class = body.getOrCreateVariableByName("class"); - new TypeConstraint(body, Tuples.flatTupleOf(var_class), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Class"))); - body.setSymbolicParameters(Arrays.asList( - new ExportedParameter(body, var_class, parameter_class) - )); - // Class.appliedStereotypeInstance.classifier.name(class, "Constraint") - PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); - new ConstantValue(body, var__virtual_0_, "Constraint"); - new TypeConstraint(body, Tuples.flatTupleOf(var_class), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Class"))); - PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_class, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Element", "appliedStereotypeInstance"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "InstanceSpecification"))); - PVariable var__virtual_2_ = body.getOrCreateVariableByName(".virtual{2}"); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_, var__virtual_2_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "InstanceSpecification", "classifier"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_2_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Classifier"))); - PVariable var__virtual_3_ = body.getOrCreateVariableByName(".virtual{3}"); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_2_, var__virtual_3_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "NamedElement", "name"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_3_), new EDataTypeInSlotsKey((EDataType)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "String"))); - new Equality(body, var__virtual_3_, var__virtual_0_); - bodies.add(body); - } - return bodies; - } - } -} diff --git a/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/internal/TransitionWithGuard.java b/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/internal/TransitionWithGuard.java deleted file mode 100644 index 2017d22..0000000 --- a/com.incquerylabs.magicdraw.benchmark/src/generated/vql/com/incquerylabs/magicdraw/benchmark/queries/internal/TransitionWithGuard.java +++ /dev/null @@ -1,138 +0,0 @@ -/** - * Generated from platform:/resource/com.incquerylabs.magicdraw.benchmark/src/main/java/com/incquerylabs/magicdraw/benchmark/queries/APerformanceQueries.vql - */ -package com.incquerylabs.magicdraw.benchmark.queries.internal; - -import java.util.Arrays; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Set; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; -import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecificationWithGenericMatcher; -import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; -import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey; -import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; -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.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.PVisibility; -import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; - -/** - * A pattern-specific query specification that can instantiate GenericPatternMatcher in a type-safe way. - * - *

Original source: - *

- *         private pattern transitionWithGuard(trans : Transition, guard : Constraint){
- *         	Transition.guard(trans, guard);
- *         }
- * 
- * - * @see GenericPatternMatcher - * @see GenericPatternMatch - * - */ -@SuppressWarnings("all") -public final class TransitionWithGuard extends BaseGeneratedEMFQuerySpecificationWithGenericMatcher { - private TransitionWithGuard() { - super(GeneratedPQuery.INSTANCE); - } - - /** - * @return the singleton instance of the query specification - * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded - * - */ - public static TransitionWithGuard instance() { - try{ - return LazyHolder.INSTANCE; - } catch (ExceptionInInitializerError err) { - throw processInitializerError(err); - } - } - - /** - * Inner class allowing the singleton instance of {@link TransitionWithGuard} to be created - * not at the class load time of the outer class, - * but rather at the first call to {@link TransitionWithGuard#instance()}. - * - *

This workaround is required e.g. to support recursion. - * - */ - private static class LazyHolder { - private static final TransitionWithGuard INSTANCE = new TransitionWithGuard(); - - /** - * Statically initializes the query specification after the field {@link #INSTANCE} is assigned. - * This initialization order is required to support indirect recursion. - * - *

The static initializer is defined using a helper field to work around limitations of the code generator. - * - */ - private static final Object STATIC_INITIALIZER = ensureInitialized(); - - public static Object ensureInitialized() { - INSTANCE.ensureInitializedInternal(); - return null; - } - } - - private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { - private static final TransitionWithGuard.GeneratedPQuery INSTANCE = new GeneratedPQuery(); - - private final PParameter parameter_trans = new PParameter("trans", "com.nomagic.uml2.ext.magicdraw.statemachines.mdbehaviorstatemachines.Transition", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.nomagic.com/magicdraw/UML/2.5.1", "Transition")), PParameterDirection.INOUT); - - private final PParameter parameter_guard = new PParameter("guard", "com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Constraint", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.nomagic.com/magicdraw/UML/2.5.1", "Constraint")), PParameterDirection.INOUT); - - private final List parameters = Arrays.asList(parameter_trans, parameter_guard); - - private GeneratedPQuery() { - super(PVisibility.PRIVATE); - } - - @Override - public String getFullyQualifiedName() { - return "com.incquerylabs.magicdraw.benchmark.queries.transitionWithGuard"; - } - - @Override - public List getParameterNames() { - return Arrays.asList("trans","guard"); - } - - @Override - public List getParameters() { - return parameters; - } - - @Override - public Set doGetContainedBodies() { - setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); - Set bodies = new LinkedHashSet<>(); - { - PBody body = new PBody(this); - PVariable var_trans = body.getOrCreateVariableByName("trans"); - PVariable var_guard = body.getOrCreateVariableByName("guard"); - new TypeConstraint(body, Tuples.flatTupleOf(var_trans), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Transition"))); - new TypeConstraint(body, Tuples.flatTupleOf(var_guard), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Constraint"))); - body.setSymbolicParameters(Arrays.asList( - new ExportedParameter(body, var_trans, parameter_trans), - new ExportedParameter(body, var_guard, parameter_guard) - )); - // Transition.guard(trans, guard) - new TypeConstraint(body, Tuples.flatTupleOf(var_trans), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Transition"))); - PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); - new TypeConstraint(body, Tuples.flatTupleOf(var_trans, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Transition", "guard"))); - new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.nomagic.com/magicdraw/UML/2.5.1", "Constraint"))); - new Equality(body, var__virtual_0_, var_guard); - bodies.add(body); - } - return bodies; - } - } -}