Ecore Query & Helper

Ecore EMF Search comes with several helpers for query building & launching :

//// Non Case Sensitive Joker expression matching all text beginning with either 'a' or 'A'//privatestaticfinalString ELEMENT_NAME_VALUATION_BEGINS_WITH_A ="A*";//// In this case IModelSearchScope associated to// "org.eclipse.emf.search.ecoreSearchEngine" search engine// will collect any files with *.ecore extension from the current// workspace.//
IModelSearchScope scope =
ModelSearchWorkspaceScopeFactory.getInstance().
createModelSearchWorkspaceScope("org.eclipse.emf.search.ecoreSearchEngine");//// Creates a new query to apply on the whole workspace.// This query will open any *.ecore collected in the// IModelSearchScope built upper in the code//
IModelSearchQuery query =
EcoreTextualModelSearchQueryBuilderHelper.getInstance().
buildGlobalTextualModelSearchQuery(
ELEMENT_NAME_VALUATION_BEGINING_WITH_A,
scope,
EcorePackage.eNS_URI);//// Run the query with Eclise Search infrastructure in backgroud.// Using a progress monitor allows to cancel this query if executed// in Eclipse UI & having acces to Job view.//
query.run(new NullProgressMonitor());
ISearchResult result = query.getModelSearchResult();if(result instanceof IModelSearchResult){//// Model result is a match occurences hierarchical tree mixing matches leaves and intermediate parent nodes// In this case a vistor flatten leaves in a collection of match occurences//
Collection<IModelResultEntry> resultEntries =((IModelSearchResult)result).getResultsFlatenned();if(resultEntries.getSource()instanceof EObject){//// User to process this occurence//}}

//// Non Case Sensitive Joker expression matching all text beginning with either 'a' or 'A'//privatestaticfinalString ELEMENT_NAME_VALUATION_BEGINS_WITH_A ="A*";//// In this case IModelSearchScope associated to// "org.eclipse.emf.search.ecoreSearchEngine" search engine// will collect any files with *.ecore extension from the current// workspace.//
IModelSearchScope scope =
ModelSearchWorkspaceScopeFactory.getInstance().
createModelSearchWorkspaceScope("org.eclipse.emf.search.ecoreSearchEngine");//// 1)//// Creates & launches a new query to apply on the whole workspace.// This query will open any *.ecore collected in the// IModelSearchScope built upper in the code.//// 2)//// Run the query with Eclise Search infrastructure in backgroud.// Using a progress monitor allows to cancel this query if executed// in Eclipse UI & having acces to Job view.//
IModelSearchResult query =
EcoreTextualModelSearchQueryLauncheerHelper.getInstance().
launchGlobalTextualModelSearchQuery(
ELEMENT_NAME_VALUATION_BEGINING_WITH_A,
scope,
EcorePackage.eNS_URI);////
query.run(new NullProgressMonitor());
ISearchResult result = query.getModelSearchResult();if(result instanceof IModelSearchResult){//// Model result is a match occurences hierarchical tree mixing matches leaves and intermediate parent nodes// In this case a vistor flatten leaves in a collection of match occurences//
Collection<IModelResultEntry> resultEntries =((IModelSearchResult)result).getResultsFlatenned();if(resultEntries.getSource()instanceof EObject){//// User to process this occurence//}}