Class SpecificationBuilder


  • public final class SpecificationBuilder
    extends java.lang.Object
    An instance class to initialize PBody instances from Pattern definitions. A single instance of this builder is used during construction, that maintains the mapping between Pattern and PQuery objects, and can be initialized with a pre-defined set of mappings.

    The SpecificationBuilder is stateful: it stores all previously built specifications, allowing further re-use.

    Since:
    2.0
    • Constructor Detail

      • SpecificationBuilder

        public SpecificationBuilder()
        Initializes a query builder with no previously known query specifications
      • SpecificationBuilder

        public SpecificationBuilder​(IQuerySpecification<?>... specifications)
        Sets up a query builder with a predefined set of specifications
      • SpecificationBuilder

        public SpecificationBuilder​(org.eclipse.viatra.query.patternlanguage.emf.specification.internal.NameToSpecificationMap patternMap)
    • Method Detail

      • getOrCreateSpecification

        public IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>> getOrCreateSpecification​(Pattern pattern)
        Creates a new or returns an existing query specification for the pattern. It is expected, that the builder will not be called with different patterns having the same fqn over its entire lifecycle.
        Parameters:
        pattern -
        Throws:
        ViatraQueryRuntimeException
        Since:
        2.0
      • getOrCreateSpecification

        public IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>> getOrCreateSpecification​(Pattern pattern,
                                                                                                                   boolean skipPatternValidation)
        Creates a new or returns an existing query specification for the pattern. It is expected, that the builder will not be called with different patterns having the same fqn over its entire lifecycle.
        Parameters:
        pattern -
        skipPatternValidation - if set to true, detailed pattern validation is skipped - true for model inferrer; not recommended for generic API
        Throws:
        ViatraQueryRuntimeException
        Since:
        2.0
      • buildErroneousSpecification

        public IQuerySpecification<?> buildErroneousSpecification​(Pattern pattern,
                                                                  java.lang.String errorMessage,
                                                                  boolean storeInMaps)
        Creates an erroneous query specification from a given pattern object with a stream of precalculated issues. The resulting query specification may or may not be stored for future reference in this specification.
        Parameters:
        pattern - the pattern definition to start from
        errorMessage - an error message to fill the erroneous specification
        storeInMaps - if true, all future references for this query, including references by fqn; if a query is already stored with this name, an IllegalStateException is thrown.
        Since:
        2.0
      • buildErroneousSpecification

        public IQuerySpecification<?> buildErroneousSpecification​(Pattern pattern,
                                                                  java.util.stream.Stream<org.eclipse.xtext.validation.Issue> issues,
                                                                  boolean storeInMaps)
        Creates an erroneous query specification from a given pattern object with a stream of precalculated issues. The resulting query specification may or may not be stored for future reference in this specification.
        Parameters:
        pattern - the pattern definition to start from
        issues - a stream of issues that are to be stored in the created specification
        storeInMaps - if true, all future references for this query, including references by fqn; if a query is already stored with this name, an IllegalStateException is thrown.
        Since:
        2.0
      • hasSpecification

        public boolean hasSpecification​(Pattern pattern)
        Returns whether the builder knows a specification with the selected name
        Since:
        2.0
      • hasSpecification

        public boolean hasSpecification​(java.lang.String fqn)
        Returns whether the builder knows a specification with the selected name
        Since:
        2.0
      • getSpecification

        public java.util.Optional<IQuerySpecification<?>> getSpecification​(java.lang.String fqn)
        Since:
        2.0
      • forgetSpecification

        public void forgetSpecification​(IQuerySpecification<?> specification)
        Forgets a specification in the builder.

        Warning! Removing a specification does not change any specification created previously, even if they are referring to the old version of the specification. Only use this if you are sure all dependant queries are also removed, otherwise use forgetSpecificationTransitively(IQuerySpecification) instead.

      • forgetURI

        public void forgetURI​(org.eclipse.emf.common.util.URI uri)
        Removes IQuerySpecification objects from the cache that originate from a given URI
        Since:
        2.1
      • forgetSpecificationTransitively

        public java.util.Set<IQuerySpecification<?>> forgetSpecificationTransitively​(IQuerySpecification<?> specification)
        Forgets a specification in the builder, and also removes anything that depends on it.
        Parameters:
        specification -