org.eclipse.viatra.query.patternlanguage.emf.helper

## Class PatternLanguageHelper

- java.lang.Object
- - org.eclipse.viatra.query.patternlanguage.emf.helper.PatternLanguageHelper

-     public final class PatternLanguageHelper
      extends java.lang.Object

  Since:
    2.0

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static java.lang.String` | `AGGREGATE_VARIABLE_PREFIX`

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static java.util.List<IInputKey>` | `calculateExpectedTypes(CallableRelation relation, ITypeSystem typeSystem, ITypeInferrer typeInferrer)` Returns the list of expected types for a given callable relation
    `static PVisibility` | `calculatePVisibility(Pattern pattern)`
    `static PatternBody` | `containerPatternBody(ValueReference val)`
    `static java.util.Map<java.lang.String,java.lang.Object>` | `evaluateAnnotationParameters(Annotation annotation)` Retains the first parameter of each parameter name.
    `static com.google.common.collect.LinkedHashMultimap<java.lang.String,java.lang.Object>` | `evaluateAnnotationParametersWithMultiplicity(Annotation annotation)` Retains all parameters, even those with duplicate names.
    `static java.util.List<PackageImport>` | `getAllPackageImports(PatternModel model)` Initializes a new list of package imports defined in a selected pattern model
    `static java.util.Collection<org.eclipse.xtext.xbase.XExpression>` | `getAllTopLevelXBaseExpressions(org.eclipse.emf.ecore.EObject patternOrBody)`
    `static java.util.Collection<ValueReference>` | `getAnnotationParameters(Annotation annotation, java.lang.String parameterName)` Returns all annotation parameters with a selected name
    `static java.util.Collection<Annotation>` | `getAnnotationsByName(Pattern pattern, java.lang.String name)` Returns the collection of annotations of a pattern by a name.
    `static java.util.List<ValueReference>` | `getCallParameters(CallableRelation relation)` Extracts the parameters from a given callable relation
    `static java.lang.Iterable<org.eclipse.emf.ecore.EPackage>` | `getEPackageImportsIterable(PatternModel model)` Returns an iterable of imported EPackages in a selected pattern model.
    `static java.util.Optional<Annotation>` | `getFirstAnnotationByName(Pattern pattern, java.lang.String name)` Returns the first annotation of a given name from a pattern.
    `static ValueReference` | `getFirstAnnotationParameter(Annotation annotation, java.lang.String parameterName)` Returns the first annotation parameter with a selected name.
    `static java.lang.String` | `getFullyQualifiedName(Pattern pattern)` Returns the name of the pattern, qualified by package name.
    `static java.util.Set<Variable>` | `getLocalReferencesOfParameter(Variable variable)`
    `static java.lang.String` | `getModelFileName(org.eclipse.emf.ecore.EObject object)`
    `static java.lang.Iterable<PackageImport>` | `getPackageImportsIterable(PatternModel model)` Returns an iterable of package imports in a selected pattern model.
    `static java.lang.String` | `getPackageName(Pattern pattern)` Returns the name of the container package of the selected pattern
    `static java.util.Optional<Variable>` | `getParameterByName(Pattern pattern, java.lang.String name)` Returns the parameter of a pattern by name
    `static java.util.Map<java.lang.String,java.lang.Integer>` | `getParameterPositionsByName(Pattern pattern)` Compiles a map for name-based lookup of symbolic parameter positions.
    `static java.util.LinkedHashMap<java.lang.String,IInputKey>` | `getParameterVariables(CallableRelation relation, ITypeSystem typeSystem, ITypeInferrer typeInferrer)` Returns the parameters required to call the mentioned patterns with their corresponding types.
    `static java.util.Optional<org.eclipse.emf.ecore.EClassifier>` | `getPathExpressionEMFTailType(PathExpressionConstraint expression)`
    `static java.util.Optional<ReferenceType>` | `getPathExpressionTailType(PathExpressionConstraint expression)`
    `static java.util.Set<Pattern>` | `getReferencedPatterns(Pattern sourcePattern)` Finds all patterns referenced from the given pattern.
    `static java.util.Set<Pattern>` | `getReferencedPatternsTransitive(Pattern pattern)` This method returns a set of patterns that are reachable from the selected pattern through various pattern composition calls.
    `static java.util.Set<Pattern>` | `getReferencedPatternsTransitive(Pattern pattern, boolean orderPatterns)` This method returns a set of patterns that are reachable from the selected pattern through various pattern composition calls.
    `static java.util.Set<Pattern>` | `getReferencedPatternsTransitive(Pattern pattern, boolean orderPatterns, java.util.function.Predicate<Pattern> filter)` This method returns a set of patterns that are reachable from the selected pattern through various pattern composition calls, while each called element fulfills the filter predicate.
    `static java.util.Set<Variable>` | `getReferencedPatternVariablesOfXExpression(org.eclipse.xtext.xbase.XExpression xExpression, org.eclipse.xtext.xbase.jvmmodel.IJvmModelAssociations associations)` Finds all pattern variables referenced from the given XExpression.
    `static java.util.stream.Stream<VariableReference>` | `getReferences(Variable var)` Returns a stream of all references from a given variable
    `static java.util.List<Variable>` | `getUnnamedRunningVariables(PatternBody patternBody)`
    `static java.util.List<Variable>` | `getUsedVariables(org.eclipse.xtext.xbase.XExpression xExpression, java.lang.Iterable<Variable> allVariables)`
    `static <T> T` | `getValue(ValueReference ref, java.lang.Class<T> clazz)` Extracts the value stored by a selected reference
    `static boolean` | `getValueOfFirstBooleanAnnotationParameter(Annotation annotation, java.lang.String parameterName, boolean defaultValue)` Returns the value of the first Boolean annotation parameter with the given name.
    `static java.util.Set<Variable>` | `getVariablesFromValueReference(ValueReference valueReference)`
    `static boolean` | `hasAggregateReference(Variable var)` Returns whether a variable has an aggregate reference.
    `static boolean` | `hasXBaseExpression(Pattern pattern)`
    `static boolean` | `isAggregateReference(VariableReference reference)` Returns whether a variable reference is an aggregate reference (e.g.
    `static boolean` | `isNamedSingleUse(Variable variable)`
    `static boolean` | `isNegative(CallableRelation call)` Decides whether a call is negative
    `static boolean` | `isNonSimpleConstraint(CallableRelation constraint)`
    `static boolean` | `isParameter(Expression ex)`
    `static boolean` | `isPrivate(Pattern pattern)`
    `static boolean` | `isTransitive(CallableRelation call)` Decides whether a call is transitive or reflexive transitive
    `static boolean` | `isUnnamedSingleUseVariable(Variable variable)`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### AGGREGATE_VARIABLE_PREFIX

          public static final java.lang.String AGGREGATE_VARIABLE_PREFIX

      Since:
        1.4
      See Also:
        Constant Field Values

  - ### Method Detail

    - #### getPackageName

          public static java.lang.String getPackageName(Pattern pattern)

      Returns the name of the container package of the selected pattern
      Returns:
        a name of the pattern; never null, but may be empty string

    - #### getFullyQualifiedName

          public static java.lang.String getFullyQualifiedName(Pattern pattern)

      Returns the name of the pattern, qualified by package name.

    - #### isPrivate

          public static boolean isPrivate(Pattern pattern)

      Parameters:
        `pattern` -
      Returns:
        true if the pattern has a private modifier, false otherwise.

    - #### calculatePVisibility

          public static PVisibility calculatePVisibility(Pattern pattern)

      Since:
        2.0

    - #### hasXBaseExpression

          public static boolean hasXBaseExpression(Pattern pattern)

      Parameters:
        `pattern` -
      Returns:
        true if the pattern contains xbase check() or eval() expressions, false otherwise.

    - #### getAllTopLevelXBaseExpressions

          public static java.util.Collection<org.eclipse.xtext.xbase.XExpression> getAllTopLevelXBaseExpressions(org.eclipse.emf.ecore.EObject patternOrBody)

      Returns:
        all xbase check() or eval() expressions in the pattern

    - #### getParameterByName

          public static java.util.Optional<Variable> getParameterByName(Pattern pattern,
                                                                        java.lang.String name)

      Returns the parameter of a pattern by name
      Parameters:
        `pattern` -
        `name` -
      Returns:
        the requested parameter of the pattern if exists
      Since:
        2.0

    - #### getParameterPositionsByName

          public static java.util.Map<java.lang.String,java.lang.Integer> getParameterPositionsByName(Pattern pattern)

      Compiles a map for name-based lookup of symbolic parameter positions.

    - #### getReferencedPatternVariablesOfXExpression

          public static java.util.Set<Variable> getReferencedPatternVariablesOfXExpression(org.eclipse.xtext.xbase.XExpression xExpression,
                                                                                           org.eclipse.xtext.xbase.jvmmodel.IJvmModelAssociations associations)

      Finds all pattern variables referenced from the given XExpression.

      Warning This method cannot be used in JvmModelInferrer, as that is used to set up the list of available local variables.

    - #### getUsedVariables

          public static java.util.List<Variable> getUsedVariables(org.eclipse.xtext.xbase.XExpression xExpression,
                                                                  java.lang.Iterable<Variable> allVariables)

    - #### getReferencedPatterns

          public static java.util.Set<Pattern> getReferencedPatterns(Pattern sourcePattern)

      Finds all patterns referenced from the given pattern.

    - #### getReferencedPatternsTransitive

          public static java.util.Set<Pattern> getReferencedPatternsTransitive(Pattern pattern)

      This method returns a set of patterns that are reachable from the selected pattern through various pattern composition calls. The patterns in the returned set not ordered.
      Parameters:
        `pattern` - the source pattern
      Since:
        1.4

    - #### getReferencedPatternsTransitive

          public static java.util.Set<Pattern> getReferencedPatternsTransitive(Pattern pattern,
                                                                               boolean orderPatterns)

      This method returns a set of patterns that are reachable from the selected pattern through various pattern composition calls.
      Parameters:
        `pattern` - the source pattern
        `orderPatterns` - if true, the returned set will be ordered based on the call edges
      Since:
        1.4

    - #### getReferencedPatternsTransitive

          public static java.util.Set<Pattern> getReferencedPatternsTransitive(Pattern pattern,
                                                                               boolean orderPatterns,
                                                                               java.util.function.Predicate<Pattern> filter)

      This method returns a set of patterns that are reachable from the selected pattern through various pattern composition calls, while each called element fulfills the filter predicate. If a pattern does not match the filter predicate, both the pattern and all patterns called by it will be absent from the returned set of the nodes.
      Parameters:
        `pattern` - the source pattern
        `orderPatterns` - if true, the returned set will be ordered based on the call edges
        `filter` - the filter predicate
      Since:
        2.0

    - #### getFirstAnnotationByName

          public static java.util.Optional<Annotation> getFirstAnnotationByName(Pattern pattern,
                                                                                java.lang.String name)

      Returns the first annotation of a given name from a pattern. This method ignores multiple defined annotations by the same name. For getting a filtered collections of annotations, see `getAnnotationsByName(Pattern, String)`
      Parameters:
        `pattern` - the pattern instance
        `name` - the name of the annotation to return
      Since:
        2.0

    - #### getAnnotationsByName

          public static java.util.Collection<Annotation> getAnnotationsByName(Pattern pattern,
                                                                              java.lang.String name)

      Returns the collection of annotations of a pattern by a name. For getting the first annotations by name, see `#getAnnotationByName(Pattern, String)`
      Parameters:
        `pattern` - the pattern instance
        `name` - the name of the annotation to return
      Since:
        0.7.0

    - #### getAnnotationParameters

          public static java.util.Collection<ValueReference> getAnnotationParameters(Annotation annotation,
                                                                                     java.lang.String parameterName)

      Returns all annotation parameters with a selected name
      Parameters:
        `annotation` -
        `parameterName` -
      Returns:
        a lazy collection of annotation parameters with the selected name. May be empty, but is never null.

    - #### getFirstAnnotationParameter

          public static ValueReference getFirstAnnotationParameter(Annotation annotation,
                                                                   java.lang.String parameterName)

      Returns the first annotation parameter with a selected name.
      Parameters:
        `annotation` -
        `parameterName` -
      Returns:
        the annotation with the selected name, or null if no such annotation exists.

    - #### getValueOfFirstBooleanAnnotationParameter

          public static boolean getValueOfFirstBooleanAnnotationParameter(Annotation annotation,
                                                                          java.lang.String parameterName,
                                                                          boolean defaultValue)

      Returns the value of the first Boolean annotation parameter with the given name. If the parameter with the given name is not Boolean or is not defined then the default value is returned.
      Parameters:
        `annotation` -
        `parameterName` -
        `defaultValue` -
      Returns:
        the value of the first boolean parameter with the given name, otherwise defaultValue

    - #### getVariablesFromValueReference

          public static java.util.Set<Variable> getVariablesFromValueReference(ValueReference valueReference)

      Parameters:
        `valueReference` -
      Returns:
        all variables from the ValueReference object. (Either referenced directly, or referenced throught an AggregatedValue.)

    - #### containerPatternBody

          public static PatternBody containerPatternBody(ValueReference val)

      Returns:
        the pattern body that contains the value reference

    - #### getUnnamedRunningVariables

          public static java.util.List<Variable> getUnnamedRunningVariables(PatternBody patternBody)

      Parameters:
        `patternBody` -
      Returns:
        A list of variables, which are running/unnamed variables in the pattern body. These variables' name starts with the "_" prefix, and can be found in find, count find calls.

    - #### evaluateAnnotationParametersWithMultiplicity

          public static com.google.common.collect.LinkedHashMultimap<java.lang.String,java.lang.Object> evaluateAnnotationParametersWithMultiplicity(Annotation annotation)

      Retains all parameters, even those with duplicate names. Parameter values of the same name are traversible in their original order.
      Since:
        1.5

    - #### evaluateAnnotationParameters

          public static java.util.Map<java.lang.String,java.lang.Object> evaluateAnnotationParameters(Annotation annotation)

      Retains the first parameter of each parameter name.

    - #### getValue

          public static <T> T getValue(ValueReference ref,
                                       java.lang.Class<T> clazz)

      Extracts the value stored by a selected reference
      Parameters:
        `ref` - The value reference to extract the value from
        `clazz` - The class to cast the results; if the value of the reference cannot be expressed with this class, an `IllegalArgumentException` is thrown.
      Since:
        1.5

    - #### isParameter

          public static boolean isParameter(Expression ex)

      Since:
        1.3

    - #### getLocalReferencesOfParameter

          public static java.util.Set<Variable> getLocalReferencesOfParameter(Variable variable)

      Since:
        1.3

    - #### isAggregateReference

          public static boolean isAggregateReference(VariableReference reference)

      Returns whether a variable reference is an aggregate reference (e.g. is started in the grammar with a '#' symbol).
      Since:
        1.4

    - #### hasAggregateReference

          public static boolean hasAggregateReference(Variable var)

      Returns whether a variable has an aggregate reference.
      Since:
        1.4

    - #### getReferences

          public static java.util.stream.Stream<VariableReference> getReferences(Variable var)

      Returns a stream of all references from a given variable
      Since:
        2.0

    - #### isNamedSingleUse

          public static boolean isNamedSingleUse(Variable variable)

      Returns:
        true if the variable is single-use a named variable
      Since:
        1.6

    - #### isUnnamedSingleUseVariable

          public static boolean isUnnamedSingleUseVariable(Variable variable)

      Returns:
        true if the variable is an unnamed single-use variable
      Since:
        1.6

    - #### getModelFileName

          public static java.lang.String getModelFileName(org.eclipse.emf.ecore.EObject object)

      Since:
        1.7

    - #### getAllPackageImports

          public static java.util.List<PackageImport> getAllPackageImports(PatternModel model)

      Initializes a new list of package imports defined in a selected pattern model
      Parameters:
        `model` -
      Since:
        2.0

    - #### getPackageImportsIterable

          public static java.lang.Iterable<PackageImport> getPackageImportsIterable(PatternModel model)

      Returns an iterable of package imports in a selected pattern model. If an import package is an unresolvable proxy, it is omitted.
      Since:
        2.0

    - #### getEPackageImportsIterable

          public static java.lang.Iterable<org.eclipse.emf.ecore.EPackage> getEPackageImportsIterable(PatternModel model)

      Returns an iterable of imported EPackages in a selected pattern model. If an import package is an unresolvable proxy, it is omitted.
      Since:
        2.0

    - #### getPathExpressionTailType

          public static java.util.Optional<ReferenceType> getPathExpressionTailType(PathExpressionConstraint expression)

    - #### getPathExpressionEMFTailType

          public static java.util.Optional<org.eclipse.emf.ecore.EClassifier> getPathExpressionEMFTailType(PathExpressionConstraint expression)

    - #### getCallParameters

          public static java.util.List<ValueReference> getCallParameters(CallableRelation relation)

      Extracts the parameters from a given callable relation
      Since:
        2.0

    - #### getParameterVariables

          public static java.util.LinkedHashMap<java.lang.String,IInputKey> getParameterVariables(CallableRelation relation,
                                                                                                  ITypeSystem typeSystem,
                                                                                                  ITypeInferrer typeInferrer)

      Returns the parameters required to call the mentioned patterns with their corresponding types. In case of embedded subpatterns, duplicate parameters are removed.
      Parameters:
        `relation` -
      Since:
        2.0

    - #### calculateExpectedTypes

          public static java.util.List<IInputKey> calculateExpectedTypes(CallableRelation relation,
                                                                         ITypeSystem typeSystem,
                                                                         ITypeInferrer typeInferrer)

      Returns the list of expected types for a given callable relation
      Since:
        2.0

    - #### isNonSimpleConstraint

          public static boolean isNonSimpleConstraint(CallableRelation constraint)

      Returns:
        true if a given call is negated, aggregated or transitive closure is calculated; false otherwise
      Since:
        2.0

    - #### isNegative

          public static boolean isNegative(CallableRelation call)

      Decides whether a call is negative
      Since:
        2.0

    - #### isTransitive

          public static boolean isTransitive(CallableRelation call)

      Decides whether a call is transitive or reflexive transitive
      Since:
        2.0