viatra / EMF-IncQuery

This repository is only kept for historic reasons. All development happens on eclipse.org
http://eclipse.org/viatra
13 stars 4 forks source link

Pattern builder interface similar to ExtensionGenerator.xtend #363

Closed abelhegedus closed 11 years ago

abelhegedus commented 11 years ago

Although we don't consider it as a public API at the moment, it would be nice to have a concise way of creating patterns from code. I think this could work similarly to the ExtensionGenerator used by the generator fragments.

Syntax ideas:

val pattern = patternBuilder.pattern("myRuntimePackage.myRuntimePattern")[
  patternBuilder.parameter("MyParam", EcorePackage::eInstance.EClass)
  patternBuilder.eClassifierConstraint("MyVar", EcorePackage::eInstance.EReference)
  patternBuilder.pathExpression("MyParam", "MyVar", EcorePackage::eInstance.EClass_EAttributes)
  patternBuilder.patternCall("someOtherPackage.otherPattern", "MyVar")
]
if(patternBuilder.validate(pattern)){
  val fact = MatcherFactoryRegistry::getOrCreateMatcherFactory(pattern)
  fact.getMatcher(resourceSet).forEachMatch[
    println(prettyPrintMatch())
  ] 
}

Of course, it allows for nice tricks like:

While it also brings up questions like:

The above examples didn't cover equality checks, count find, and annotations (although the later is probably not needed).

abelhegedus commented 11 years ago

Moved to Eclipse.org BugZilla https://bugs.eclipse.org/bugs/show_bug.cgi?id=398810