Skip to content

Instantly share code, notes, and snippets.

@abelhegedus
Created May 17, 2012 18:48
Show Gist options
  • Save abelhegedus/2720857 to your computer and use it in GitHub Desktop.
Save abelhegedus/2720857 to your computer and use it in GitHub Desktop.
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());
results.append(match.prettyPrint());
}
} catch (IncQueryRuntimeException e) {
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment