Skip to content

Instantly share code, notes, and snippets.

View abelhegedus's full-sized avatar

Ábel Hegedüs abelhegedus

View GitHub Profile
@abelhegedus
abelhegedus / SchoolImpl.java
Created May 16, 2012 09:56
Derived feature example
// Query based features
private IncqueryFeatureHandler numberOfSchoolsHandler;
private IncqueryFeatureHandler lastYearHandler;
private IncqueryFeatureHandler teachersWithMostCourses;
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
*/
protected SchoolImpl() {
@abelhegedus
abelhegedus / IncQueryHeadless.java
Created May 17, 2012 18:48
IncQuery Headless execution
public String execute(String modelPath, String patternFQN) {
ResourceSet resourceSet = new ResourceSetImpl();
URI fileURI = URI.createFileURI(modelPath);
Resource resource = resourceSet.getResource(fileURI, true);
if (resource != null) {
try {
IncQueryMatcher matcher = MatcherFactoryRegistry.getMatcherFactory(patternFQN).getMatcher(resource);
Collection<IPatternMatch> matches = matcher.getAllMatches();
for (IPatternMatch match : matches) {
IncQueryEngine.getDefaultLogger().logError(match.prettyPrint());
@abelhegedus
abelhegedus / ClassAttributeNames
Created May 24, 2012 15:03
Small examples for EMF-IncQuery part 1
pattern ClassAttributeNames(Cls,Name) = {
EClass(Cls);
EString(Name);
// since eAttributes will refer to EAttribute, we can use its name feature
EClass.eAttributes.name(Cls,Name);
}
@abelhegedus
abelhegedus / ClassWithGivenNameAndHasAttribute
Created May 24, 2012 15:13
Small examples for EMF-IncQuery part 2
pattern ClassWithGivenNameAndHasAttribute(Cls : EClass) = {
find EClassWithGivenName(Cls);
find ClassAttributes(Cls,Attr);
}
@abelhegedus
abelhegedus / AtLeastThreeAttributes
Created May 24, 2012 15:33
Small examples for EMF-IncQuery part 3
pattern AtLeastThreeAttributes(Cls : EClass) = {
M == count find ClassAttributes(Cls,Attr);
check((M as Integer) > 2);
}
@abelhegedus
abelhegedus / ShowLocationHelper.java
Created June 1, 2012 08:25
Infinite exception with re-executed command
IEditorPart editorPart = pm.getParent().getParent().getEditorPart();
if(editorPart.getSite().getPage().getActiveEditor() != editorPart) {
//bring editor part to top
editorPart.getSite().getPage().bringToTop(editorPart); // this should make it active as well, otherwise infinite execption
IHandlerService handlerService = (IHandlerService) editorPart.getSite().getService(IHandlerService.class);
try {
handlerService.executeCommand(CommandConstants.SHOW_LOCATION_COMMAND_ID, null);
return;
} catch (Exception e) {
IncQueryEngine.getDefaultLogger().logError("Exception when activating show location!", e);
@abelhegedus
abelhegedus / ChecklistEntryFeatures
Created June 6, 2012 14:12
Query-driven soft links examples
@QueryBasedFeature(feature = "jobs")
pattern ChecklistEntryJobCorrespondence(CLE : ChecklistEntry, Job : Job) = {
Job.name(Job,JobName);
System.name(System,SysName);
Job.runsOn(Job,System);
ChecklistEntry.jobPaths(CLE,JobPath);
check((JobPath as String).equals((SysName as String).concat('/').concat(JobName as String)));
}
@QueryBasedFeature(feature = "task")
@abelhegedus
abelhegedus / test.java
Created June 18, 2012 15:47
EMf-IncQuery Testing Framework example
@Test
def shortTest(){
val patternModel = parseHelper.parse('
import "http://www.eclipse.org/viatra2/patternlanguage/core/PatternLanguage"
pattern resolutionTest(Name) = {
Pattern(Name);
} ') as PatternModel
patternModel.assertMatchResults("uri/to/test/expected")
}
@abelhegedus
abelhegedus / StrangeDeletionTest.xtend
Created November 13, 2012 18:03
Test case to reproduce ITC issue
import org.eclipse.viatra2.patternlanguage.eMFPatternLanguage.PatternModel
import org.eclipse.viatra2.patternlanguage.core.patternLanguage.PatternLanguageFactory
import org.eclipse.viatra2.patternlanguage.eMFPatternLanguage.EMFPatternLanguageFactory
import org.eclipse.emf.ecore.EcorePackage
import org.junit.Test
import org.junit.runner.RunWith
import org.eclipse.xtext.junit4.XtextRunner
import org.eclipse.xtext.junit4.InjectWith
import org.eclipse.viatra2.emf.incquery.testing.core.injector.EMFPatternLanguageInjectorProvider
import org.eclipse.emf.common.util.URI
@abelhegedus
abelhegedus / DynamicDelegates.xtend
Last active December 18, 2015 20:48
Sample code for initializing Query-based feature setting delegates in dynamic mode
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