protected SarlAgent agent(String string) throws Exception {
List<XtendTypeDeclaration> decls = file(string, true).getXtendTypes();
return (SarlAgent) decls.get(decls.size() - 1);
}
protected XtendFile file(String string, boolean validate) throws Exception {
XtendFile script = this.parser.parse(string);
if (validate) {
Resource resource = script.eResource();
ResourceSet resourceSet = resource.getResourceSet();
if (resourceSet instanceof XtextResourceSet) {
((XtextResourceSet) resourceSet).setClasspathURIContext(getClass());
}
assertEquals(resource.getErrors().toString(), 0, resource.getErrors().size());
Collection<Issue> issues = Collections2.filter(issues(resource), new Predicate<Issue>() {
@Override
public boolean apply(Issue input) {
return input.getSeverity() == Severity.ERROR;
}
});
assertTrue("Resource contained errors : " + issues.toString(), issues.isEmpty());
}
return script;
}
]]>