use of org.eclipse.xtext.resource.XtextResourceSet in project xtext-xtend by eclipse.
the class AbstractXtendTestCase method file.
protected XtendFile file(String string, boolean validate, boolean shouldBeSyntacticallyValid) throws Exception {
XtextResourceSet set = getResourceSet();
String fileName = getFileName(string);
Resource resource = set.createResource(URI.createURI(fileName + ".xtend"));
resource.load(new StringInputStream(string), null);
if (shouldBeSyntacticallyValid) {
assertEquals(resource.getErrors().toString(), 0, resource.getErrors().size());
}
if (validate) {
List<Issue> issues = Lists.newArrayList(Iterables.filter(((XtextResource) resource).getResourceServiceProvider().getResourceValidator().validate(resource, CheckMode.ALL, CancelIndicator.NullImpl), new Predicate<Issue>() {
@Override
public boolean apply(Issue issue) {
return issue.getSeverity() == Severity.ERROR;
}
}));
assertTrue("Resource contained errors : " + issues.toString(), issues.isEmpty());
}
XtendFile file = (XtendFile) resource.getContents().get(0);
return file;
}
use of org.eclipse.xtext.resource.XtextResourceSet in project xtext-xtend by eclipse.
the class PartialParserTest method compareWithNewResource.
protected void compareWithNewResource(XtextResource resource, String model, int offset, int length, String newText, String fileName) throws IOException {
resource.update(offset, length, newText);
XtextResourceSet secondResourceSet = getResourceSet();
XtextResource newResource = (XtextResource) secondResourceSet.createResource(URI.createURI(fileName));
String newModel = new StringBuilder(model).replace(offset, offset + length, newText).toString();
assertEquals(newModel, resource.getParseResult().getRootNode().getText());
newResource.load(new StringInputStream(newModel), null);
assertEquals(newResource.getContents().size(), resource.getContents().size());
EcoreUtil.resolveAll(resource);
EcoreUtil.resolveAll(newResource);
for (int i = 0; i < resource.getContents().size(); i++) {
assertEquals(EmfFormatter.objToStr(newResource.getContents().get(i)), EmfFormatter.objToStr(resource.getContents().get(i)));
}
assertEqualNodes(newResource, resource);
}
use of org.eclipse.xtext.resource.XtextResourceSet in project xtext-xtend by eclipse.
the class UTF8ParserTest method file.
@Override
protected XtendFile file(String string, boolean validate) throws Exception {
XtextResourceSet set = getResourceSet();
String fileName = getFileName(string);
Resource resource = set.createResource(URI.createURI(fileName + ".xtend"));
resource.load(new StringInputStream(string, "UTF-8"), Collections.singletonMap(XtextResource.OPTION_ENCODING, "UTF-8"));
assertEquals(resource.getErrors().toString(), 0, resource.getErrors().size());
XtendFile file = (XtendFile) resource.getContents().get(0);
return file;
}
use of org.eclipse.xtext.resource.XtextResourceSet in project xtext-xtend by eclipse.
the class IndexingTest method doTestResourceDescriptionWithoutGetContents.
private void doTestResourceDescriptionWithoutGetContents(final String input) throws IOException {
XtextResourceSet resourceSet = getResourceSet();
new ClasspathTypeProvider(classLoader, resourceSet, null, null);
final Wrapper<Boolean> wrapper = Wrapper.wrap(Boolean.FALSE);
for (int i = 0; i < 10; i++) {
DerivedStateAwareResource resource = (DerivedStateAwareResource) resourceSet.createResource(URI.createURI("Dummy" + i + ".xtend"));
resource.setDerivedStateComputer(new IDerivedStateComputer() {
@Override
public void installDerivedState(DerivedStateAwareResource resource, boolean preLinkingPhase) {
if (!preLinkingPhase) {
wrapper.set(Boolean.TRUE);
}
derivedStateComputer.installDerivedState(resource, preLinkingPhase);
}
@Override
public void discardDerivedState(DerivedStateAwareResource resource) {
derivedStateComputer.discardDerivedState(resource);
}
});
String actualInput = input;
if (i != 0) {
actualInput = "import C" + (i + 1) + " " + actualInput;
actualInput = "import C" + (i - 1) + " " + actualInput;
}
actualInput = String.format(actualInput, i, i + 1);
resource.load(new StringInputStream(actualInput), null);
}
for (int i = 0; i < 10; i++) {
Resource resource = resourceSet.getResources().get(i);
for (IEObjectDescription description : resourceDescriptionManager.getResourceDescription(resource).getExportedObjects()) {
description.getEObjectOrProxy();
}
}
assertFalse(wrapper.get());
}
use of org.eclipse.xtext.resource.XtextResourceSet in project xtext-xtend by eclipse.
the class RichStringEvaluationTest method file.
protected XtendFile file(String string, boolean validate) throws Exception {
XtextResourceSet set = resourceSetProvider.get();
String fileName = getFileName(string);
Resource resource = set.createResource(URI.createURI(fileName + ".xtend"));
resource.load(new StringInputStream(string), null);
assertEquals(resource.getErrors().toString(), 0, resource.getErrors().size());
if (validate) {
List<Issue> issues = ((XtextResource) resource).getResourceServiceProvider().getResourceValidator().validate(resource, CheckMode.ALL, CancelIndicator.NullImpl);
assertTrue("Resource contained errors : " + issues.toString(), issues.isEmpty());
}
XtendFile file = (XtendFile) resource.getContents().get(0);
return file;
}
Aggregations