use of org.eclipse.xtext.resource.XtextResource in project xtext-xtend by eclipse.
the class PartialParserTest method createResource.
protected XtextResource createResource(String model, String fileName) throws IOException {
XtextResourceSet resourceSet = getResourceSet();
XtextResource resource = (XtextResource) resourceSet.createResource(URI.createURI(fileName));
resource.load(new StringInputStream(model), null);
return resource;
}
use of org.eclipse.xtext.resource.XtextResource in project xtext-xtend by eclipse.
the class IndexingTest method justLoad.
protected XtextResource justLoad(String contents) throws IOException {
XtextResourceSet set = getResourceSet();
String fileName = getFileName(contents);
Resource resource = set.createResource(URI.createURI(fileName + ".xtend"));
resource.load(new StringInputStream(contents), null);
return (XtextResource) resource;
}
use of org.eclipse.xtext.resource.XtextResource in project xtext-xtend by eclipse.
the class ParserTest method testAllGrammarElementsUnique.
@Test
public void testAllGrammarElementsUnique() throws Exception {
XtendClass clazz = clazz("class Foo { def m() { newArrayList() } }");
XtextResource resource = (XtextResource) clazz.eResource();
ICompositeNode root = resource.getParseResult().getRootNode();
new InvariantChecker().checkInvariant(root);
assertSame(root, root.getRootNode());
Set<EObject> grammarElements = Sets.newHashSet();
for (INode node : root.getAsTreeIterable()) {
if (node instanceof ICompositeNode) {
if (node.getGrammarElement() == null) {
fail("node without grammar element");
}
if (!grammarElements.add(node.getGrammarElement())) {
fail(node.getGrammarElement().toString());
}
}
}
}
use of org.eclipse.xtext.resource.XtextResource in project xtext-xtend by eclipse.
the class TypeUsageCollectorTest method hasUnresolvedType.
private void hasUnresolvedType(final Resource resource, final String... typeNames) {
final TypeUsages typeUsages = this.typeUsageCollector.collectTypeUsages(((XtextResource) resource));
final Function1<TypeUsage, String> _function = (TypeUsage it) -> {
return it.getUsedTypeName();
};
final Set<String> usedNames = IterableExtensions.<String>toSet(ListExtensions.<TypeUsage, String>map(typeUsages.getUnresolvedTypeUsages(), _function));
Assert.assertEquals(IterableExtensions.<String>toSet(((Iterable<String>) Conversions.doWrapArray(typeNames))), usedNames);
}
use of org.eclipse.xtext.resource.XtextResource in project xtext-xtend by eclipse.
the class ImportsCollectorTests method collect.
private ImportsAcceptor.DefaultImportsAcceptor collect(final CharSequence xtendFile) {
try {
String contentAsString = xtendFile.toString();
int start = 0;
int end = contentAsString.length();
int selector = contentAsString.indexOf("|");
if ((selector != (-1))) {
start = selector;
contentAsString = contentAsString.replaceFirst("\\|", "");
selector = contentAsString.indexOf("|");
end = contentAsString.length();
if ((selector != (-1))) {
end = selector;
contentAsString = contentAsString.replaceFirst("\\|", "");
}
}
final Resource resource = this.file(contentAsString).eResource();
final ImportsAcceptor.DefaultImportsAcceptor acceptor = new ImportsAcceptor.DefaultImportsAcceptor();
TextRegion _textRegion = new TextRegion(start, (end - start));
this.importsCollector.collectImports(((XtextResource) resource), _textRegion, acceptor);
return acceptor;
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
Aggregations