本文整理了Java中org.eclipse.viatra.query.runtime.api.ViatraQueryEngine
类的一些代码示例,展示了ViatraQueryEngine
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ViatraQueryEngine
类的具体详情如下:
包路径:org.eclipse.viatra.query.runtime.api.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:
代码示例来源: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);
内容来源于网络,如有侵权,请联系作者删除!