Last active
December 18, 2015 20:48
-
-
Save abelhegedus/5842642 to your computer and use it in GitHub Desktop.
Sample code for initializing Query-based feature setting delegates in dynamic mode
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package school.tests | |
import org.eclipse.core.resources.IFile | |
import org.eclipse.emf.ecore.EStructuralFeature | |
import org.eclipse.incquery.querybasedfeatures.runtime.QueryBasedFeatureSettingDelegateFactory | |
import org.eclipse.incquery.runtime.patternregistry.PatternRegistry | |
import org.eclipse.incquery.patternlanguage.patternLanguage.Pattern | |
import org.eclipse.emf.ecore.EPackage | |
import org.eclipse.emf.ecore.EcoreFactory | |
import org.eclipse.incquery.runtime.extensibility.QuerySpecificationRegistry | |
class DynamicDelegates { | |
def prepareQueryBasedFeatureDelegates(){ | |
val eiqFile = null as IFile | |
val patterns = <Pattern>newArrayList() // list of patterns required for features | |
patterns.forEach[ // we have to register the patterns that will be used | |
val qs = QuerySpecificationRegistry::getOrCreateQuerySpecification(it) | |
QuerySpecificationRegistry::registerQuerySpecification(qs) | |
// TODO use pattern registry once it is added to core | |
//PatternRegistry::INSTANCE.addPatternToRegistry(it, eiqFile) | |
] | |
// this is a factory which should use unmanaged engines as dynamic mode is required | |
val factory = new QueryBasedFeatureSettingDelegateFactory(false) | |
val reg = EStructuralFeature.Internal.SettingDelegate.Factory.Registry::INSTANCE | |
reg.put("org.eclipse.incquery.querybasedfeatures.runtime", factory) | |
// next, you can add the delegate annotation to the EPackage | |
val ePackage = null as EPackage | |
// let's say it does not exist yet, you have to check and use the existing if any | |
val delegateAnnotation = EcoreFactory::eINSTANCE.createEAnnotation => [ | |
source = "http://www.eclipse.org/emf/2002/Ecore" | |
details.put("settingDelegates", "org.eclipse.incquery.querybasedfeatures.runtime") | |
] | |
ePackage.EAnnotations.add(delegateAnnotation) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment