org.eclipse.viatra.query.runtime.api.ViatraQueryEngine类的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(12.1k)|赞(0)|评价(0)|浏览(61)

本文整理了Java中org.eclipse.viatra.query.runtime.api.ViatraQueryEngine类的一些代码示例,展示了ViatraQueryEngine类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ViatraQueryEngine类的具体详情如下:
包路径:org.eclipse.viatra.query.runtime.api.ViatraQueryEngine
类名称:ViatraQueryEngine

ViatraQueryEngine介绍

[英]A Viatra Query (incremental) evaluation engine, attached to a model such as an EMF resource. The engine hosts pattern matchers, and will listen on model update notifications stemming from the given model in order to maintain live results.

By default, ViatraQueryEngines do not need to be separately disposed; they will be garbage collected along with the model. Advanced users: see AdvancedViatraQueryEngine if you want fine control over the lifecycle of an engine.

Pattern matchers within this engine may be instantiated in the following ways:

  • Recommended: instantiate the specific matcher class generated for the pattern by e.g. MyPatternMatcher.on(engine).
  • Use #getMatcher(IQuerySpecification) if the pattern-specific generated matcher API is not available.
  • Advanced: use the query specification associated with the generated matcher class to achieve the same.
    Additionally, a group of patterns (see IQueryGroup) can be initialized together before usage; this may improve the performance of pattern matcher construction by trying to gather all necessary information from the model in one go. Note that no such improvement is to be expected if the engine is specifically constructed in wildcard mode, an option available in some scope implementations (see EMFScope#EMFScope(Notifier,BaseIndexOptions) and BaseIndexOptions#withWildcardMode(boolean)).
    [中]Viatra查询(增量)评估引擎,附加到EMF资源等模型。引擎托管模式匹配器,并将监听来自给定模型的模型更新通知,以维护实时结果。
    默认情况下,ViatraQueryEngines不需要单独处置;它们将与模型一起被垃圾收集。高级用户:如果您想要对发动机的生命周期进行精确控制,请参阅AdvancedViatraQueryEngine。
    此引擎中的模式匹配器可以通过以下方式实例化:
    *建议:实例化MyPatternMatcher等为模式生成的特定matcher类。打开(发动机)。
    *如果特定于模式的生成的matcher API不可用,请使用#getMatcher(IQuerySpecification)。
    *高级:使用与生成的matcher类关联的查询规范来实现相同的功能。
    此外,一组模式(参见IQueryGroup)可以在使用前一起初始化;通过尝试一次性从模型中收集所有必要的信息,这可能会提高模式匹配器构造的性能。请注意,如果引擎是专门在通配符模式下构造的,则不会出现这种改进,这是一些作用域实现中可用的选项(请参阅EMFScope#EMFScope(通知程序,BaseIndexOptions)和BaseIndexOptions#withWildcardMode(布尔))。

代码示例

代码示例来源:origin: org.eclipse.viatra/org.eclipse.viatra.transformation.runtime.emf

public EventDrivenTransformationBuilder setScope(EMFScope scope) {
  this.engine = ViatraQueryEngine.on(scope);
  return this;
}

代码示例来源:origin: org.eclipse.viatra/org.eclipse.viatra.query.runtime

public Set<IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>>> getRegisteredQuerySpecifications() {
  return getCurrentMatchers().stream().map(ViatraQueryMatcher::getSpecification).collect(Collectors.toSet());
}

代码示例来源:origin: org.eclipse.viatra/org.eclipse.viatra.query.runtime

/**
 * Internal method for {@link GenericQuerySpecification}
 * @noreference
 */
static <Matcher extends GenericPatternMatcher> GenericPatternMatcher instantiate(ViatraQueryEngine engine, GenericQuerySpecification<Matcher> querySpecification) {
  // check if matcher already exists
  GenericPatternMatcher matcher = engine.getExistingMatcher(querySpecification);
  if (matcher == null) {
    matcher = engine.getMatcher(querySpecification);
  }     
  return matcher;
}

代码示例来源:origin: org.eclipse.viatra/org.eclipse.viatra.dse

try {
  EMFScope scope = new EMFScope(notifier);
  ViatraQueryEngine queryEngine = ViatraQueryEngine.on(scope);
  EMFBaseIndexWrapper baseIndex = (EMFBaseIndexWrapper) queryEngine.getBaseIndex();
  navigationHelper = baseIndex.getNavigationHelper();
  navigationHelper.registerObservedTypes(classes, null, features, IndexingLevel.FULL);

代码示例来源:origin: org.eclipse.viatra/org.eclipse.viatra.transformation.runtime.debug

private ResourceSet[] getResources(ViatraQueryEngine engine) {
  List<ResourceSet> retVal = new ArrayList<>();
  if(engine != null){
    QueryScope scope = engine.getScope();
    if (scope instanceof EMFScope) {
      for (Notifier notifier : ((EMFScope) scope).getScopeRoots()) {
        if (notifier instanceof ResourceSet) {
          retVal.add((ResourceSet) notifier);
        }
      }
    }
    return retVal.toArray(new ResourceSet[retVal.size()]);
  }else{
    return new ResourceSet[0];
  }
  
}

代码示例来源:origin: org.eclipse.viatra/org.eclipse.viatra.transformation.evm

protected AttributeMonitor<Match> prepareAttributeMonitor(){
  //return new DefaultAttributeMonitor<Match>();
  LightweightAttributeMonitor<Match> monitor = null;
  ViatraQueryEventSource<Match> eventSource = (ViatraQueryEventSource<Match>) getSource();
  try {
    monitor = new LightweightAttributeMonitor<Match>(eventSource.getMatcher().getEngine().getBaseIndex());
  } catch (ViatraQueryException e) {
    ViatraQueryLoggingUtil.getLogger(getClass()).error("Error happened while accessing base index", e);
  }
  return monitor;
}

代码示例来源:origin: org.eclipse.viatra/org.eclipse.viatra.query.runtime

/**
 * Provides access to the underlying EMF model index ({@link NavigationHelper}) from a VIATRA Query engine instantiated on an EMFScope
 * 
 * @param engine an already existing VIATRA Query engine instantiated on an EMFScope
 * @return the underlying EMF base index that indexes the contents of the EMF model
 * @throws ViatraQueryRuntimeException if base index initialization fails
 */
public static NavigationHelper extractUnderlyingEMFIndex(ViatraQueryEngine engine) {
  final QueryScope scope = engine.getScope();
   if (scope instanceof EMFScope)
     return ((EMFBaseIndexWrapper)AdvancedViatraQueryEngine.from(engine).getBaseIndex()).getNavigationHelper();
   else throw new IllegalArgumentException("Cannot extract EMF base index from VIATRA Query engine instantiated on non-EMF scope " + scope);
}

代码示例来源:origin: org.eclipse.viatra/org.eclipse.viatra.transformation.runtime.emf

public static BatchTransformationBuilder forScope(EMFScope scope) {
  return forEngine(ViatraQueryEngine.on(scope));
}

代码示例来源:origin: org.eclipse.viatra/org.eclipse.viatra.query.patternlanguage.emf

/**
 * 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. The match set will be incrementally
 * refreshed upon updates.
 * 
 * @param engine
 *            the existing VIATRA Query engine in which this matcher will be
 *            created.
 * @param querySpecification
 *            the query specification for which the matcher is to be
 *            constructed.
 * @throws ViatraQueryRuntimeException
 *             if an error occurs during pattern matcher creation
 */
public static GenericPatternMatcher on(ViatraQueryEngine engine,
    GenericQuerySpecification querySpecification) {
  // check if matcher already exists
  GenericPatternMatcher matcher = engine.getExistingMatcher(querySpecification);
  if (matcher == null) {
    matcher = engine.getMatcher(querySpecification);
  }
  return matcher;
}

代码示例来源:origin: org.eclipse.viatra/org.eclipse.viatra.query.runtime

@Override
public Matcher getMatcher(ViatraQueryEngine engine) {
  ensureInitializedInternal();
  if (wrappedPQuery.getStatus() == PQueryStatus.ERROR) {
    String errorMessages = wrappedPQuery.getPProblems().stream()
        .map(input -> (input == null) ? "" : input.getShortMessage()).collect(Collectors.joining("\n"));
    throw new ViatraQueryException(String.format("Erroneous query specification: %s %n %s", getFullyQualifiedName(), errorMessages),
        "Cannot initialize matchers on erroneous query specifications.");
  } else if (!engine.getScope().isCompatibleWithQueryScope(this.getPreferredScopeClass())) {
    throw new ViatraQueryException(
        String.format(
            "Scope class incompatibility: the query %s is formulated over query scopes of class %s, "
                + " thus the query engine formulated over scope %s of class %s cannot evaluate it.",
            this.getFullyQualifiedName(), this.getPreferredScopeClass().getCanonicalName(),
            engine.getScope(), engine.getScope().getClass().getCanonicalName()),
        "Incompatible scope classes of engine and query.");
  }
  return instantiate(engine);
}

代码示例来源:origin: org.eclipse.viatra/org.eclipse.viatra.query.patternlanguage.emf

/**
 * Initializes a pattern-specification mapping with the contents of an existing {@link ViatraQueryEngine}. </p>
 * <p>
 * <strong>Warning</strong> It is assumed that each query specification in the engine has a unique fqn - if the
 * assumption fails, the resulting map is unspecified.
 * 
 * @param engine
 */
public NameToSpecificationMap(ViatraQueryEngine engine) {
  this();
  for (ViatraQueryMatcher<?> matcher : engine.getCurrentMatchers()) {
    IQuerySpecification<?> specification = matcher.getSpecification();
    map.put(specification.getFullyQualifiedName(), specification);
  }
}

代码示例来源:origin: org.eclipse.viatra/org.eclipse.viatra.transformation.runtime.emf

public static EventDrivenTransformationBuilder forScope(EMFScope scope) {
  return forEngine(ViatraQueryEngine.on(scope));
}

代码示例来源:origin: org.eclipse.viatra/org.eclipse.viatra.dse

/**
 * Initialize this SolutionTrajectory for transforming the model along the trajectory.
 * 
 * @param model
 *            The model.
 * @throws ViatraQueryRuntimeException
 *             If the VIATRA Query fails to initialize.
 */
public void setModel(Notifier model) {
  editingDomain = null;
  EMFScope scope = new EMFScope(model);
  this.engine = ViatraQueryEngine.on(scope);
  this.model = model;
  stateCoder = stateCoderFactory.createStateCoder();
  stateCoder.init(model);
  currentIndex = 0;
  DseIdPoolHelper.INSTANCE.disposeByThread();
  DseIdPoolHelper.INSTANCE.registerRules(rule -> {
    int id = 0;
    for (BatchTransformationRule<?,?> r : transformationRules.subList(0, currentIndex)) {
      if (r.equals(rule)) {
        id ++;
      }
    }
    return id;
  }, new HashSet<BatchTransformationRule<?,?>>(transformationRules));
}

代码示例来源:origin: org.eclipse.viatra/org.eclipse.viatra.dse

@Override
  public void init(Notifier notifier, StatecodingDependencyGraph statecodingDependencyGraph) {

    try {
      EMFScope scope = new EMFScope(notifier);
      ViatraQueryEngine queryEngine = ViatraQueryEngine.on(scope);

      Set<EClass> classes = new HashSet<EClass>();
//          Set<EReference> references = new HashSet<EReference>();
      for (StatecodingNode node : statecodingDependencyGraph.getNodes()) {
        classes.add(node.getClazz());
//              for (StatecodingDependency dependency : node.getStatecodingDependencies()) {
//                  // TODO inverse reference
//                  references.add(dependency.eReference);
//              }
      }
      baseIndex = EMFScope.extractUnderlyingEMFIndex(queryEngine);
      baseIndex.registerEClasses(classes, IndexingLevel.FULL);
    } catch (ViatraQueryException e) {
      logger.error("Failed to initialize VIATRA Query engine on the given notifier", e);
      throw new DSEException("Failed to initialize VIATRA Query engine on the given notifier");
    }
  }

代码示例来源:origin: org.eclipse.viatra/org.eclipse.viatra.addon.validation.runtime

public ConstraintAdapter(IEditorPart editorPart, Notifier notifier, Logger logger) {
  this.logger = logger;
  resourceForEditor = getIResourceForEditor(editorPart);
  this.markerMap = new HashMap<IPatternMatch, IMarker>();
  this.violationMarkerMap = new HashMap<IViolation, IMarker>();
  try {
    ViatraQueryEngine queryEngine = ViatraQueryEngine.on(new EMFScope(notifier));
    engine = ValidationEngine.builder().setEngine(queryEngine).setLogger(logger).build();
    engine.initialize();
    
    MarkerManagerViolationListener markerManagerViolationListener = new MarkerManagerViolationListener(logger, this);
    Set<IConstraintSpecification> constraintSpecificationsForEditorId = ConstraintExtensionRegistry
        .getConstraintSpecificationsForEditorId(editorPart.getSite().getId());
    for (IConstraintSpecification constraint : constraintSpecificationsForEditorId) {
      IConstraint coreConstraint = engine.addConstraintSpecification(constraint);
      coreConstraint.addListener(markerManagerViolationListener);
    }
  } catch (ViatraQueryException e) {
    logger.error(String.format("Exception occured during validation initialization: %s", e.getMessage()), e);
  }
}

代码示例来源:origin: org.eclipse.viatra/org.eclipse.viatra.addon.validation.runtime

/**
 * Initializes a new validation engine implementing the IValidationEngine interface on the provided Notifier
 * instance with the constrains specified for the given editor Id.
 * 
 * @param scope
 *            The Notifier object on which the validation engine should be initialized.
 * @param editorId
 *            An editor Id for which we wish to use the registered constraint specifications at the
 *            org.eclipse.viatra.addon.livevalidation.runtime.constraintspecification extension point.
 * @return The initialized validation engine.
 */
public static IValidationEngine initializeValidationWithRegisteredConstraintsOnScope(QueryScope scope,
    String editorId) {
  ViatraQueryEngine engine = ViatraQueryEngine.on(scope);
  Logger logger = ViatraQueryLoggingUtil.getLogger(ValidationEngine.class);
  IValidationEngine validationEngine = ValidationEngine.builder().setEngine(engine).setLogger(logger).build();

  for (IConstraintSpecification constraintSpecification : ConstraintExtensionRegistry.getConstraintSpecificationsForEditorId(editorId)) {
    validationEngine.addConstraintSpecification(constraintSpecification);
  }
  validationEngine.initialize();

  return validationEngine;
}

代码示例来源:origin: org.eclipse.viatra/org.eclipse.viatra.dse

queryEngine = ViatraQueryEngine.on(scope);

相关文章