org.eclipse.viatra.query.patternlanguage.helper

## Class CorePatternLanguageHelper

- java.lang.Object
- - org.eclipse.viatra.query.patternlanguage.helper.CorePatternLanguageHelper

-     public final class CorePatternLanguageHelper
      extends java.lang.Object

- - ### 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 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.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 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` | `getPackageName(Pattern pattern)` Returns the name of the container package of the selected pattern
    `static 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.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, com.google.common.base.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.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` | `isParameter(Expression ex)`
    `static boolean` | `isPrivate(Pattern pattern)`
    `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.

    - #### 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 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, or null if none exists
      Since:
        0.7.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,
                                                                               com.google.common.base.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:
        1.6

    - #### getFirstAnnotationByName

          public static 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:
        0.7.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

    - #### 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