use of org.eclipse.xtend.XtendResourceParser in project xtext-core by eclipse.
the class XtendXtext2EcorePostProcessor method loadXtendFile.
/**
* Expects an Xtend file named <code>MyDsl</code>PostProcessor.ext with an extension with signature
* process(xtext::GeneratedMetamodel) in the same folder as the grammar file.
*
* @param metamodel
* the metamodel to augment
* @return the xtendFile to execute
*/
protected Resource loadXtendFile(GeneratedMetamodel metamodel) {
if (xtendFile == null) {
final String extension = getExtensionName(metamodel);
try {
URI uri = getXtendFileLocation(metamodel);
if (uri != null) {
URIConverter uriConverter = metamodel.eResource().getResourceSet().getURIConverter();
if (uriConverter.exists(uri, null)) {
InputStream in = uriConverter.createInputStream(uri);
try {
XtendResourceParser parser = new XtendResourceParser();
xtendFile = parser.parse(new InputStreamReader(in), extension + '.' + XtendFile.FILE_EXTENSION);
fireXtendFileLoaded();
} finally {
if (in != null)
in.close();
}
}
}
} catch (ClasspathUriResolutionException ignored) {
// no xtend file found
} catch (Exception e) {
logger.error("Could not parse " + extension, e);
}
}
return xtendFile;
}
Aggregations