use of org.eclipse.xtext.resource.XtextResourceSet in project xtext-xtend by eclipse.
the class TypeBasedSimpleBenchmark method setUp.
@Override
protected void setUp() throws Exception {
Injector injector = new XbaseStandaloneSetup().createInjectorAndDoEMFRegistration();
XtextResourceSet resourceSet = new XtextResourceSet();
ClassLoader loader = getClass().getClassLoader();
resourceSet.setClasspathURIContext(loader);
typeProvider = new ClasspathTypeProvider(loader, resourceSet, indexedAccess, null);
CommonTypeComputationServices services = injector.getInstance(CommonTypeComputationServices.class);
owner = new StandardTypeReferenceOwner(services, resourceSet);
}
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-core by eclipse.
the class WorkspaceManager method exists.
protected boolean exists(final URI uri) {
ProjectManager _projectManager = this.getProjectManager(uri);
XtextResourceSet _resourceSet = null;
if (_projectManager != null) {
_resourceSet = _projectManager.getResourceSet();
}
final XtextResourceSet rs = _resourceSet;
if ((rs == null)) {
return false;
}
return rs.getURIConverter().exists(uri, null);
}
use of org.eclipse.xtext.resource.XtextResourceSet in project xtext-core by eclipse.
the class CodeActionService method recordWorkspaceEdit.
private WorkspaceEdit recordWorkspaceEdit(final Document doc, final XtextResource resource, final IChangeSerializer.IModification<Resource> mod) {
try {
final XtextResourceSet rs = new XtextResourceSet();
final Resource copy = rs.createResource(resource.getURI());
String _text = resource.getParseResult().getRootNode().getText();
StringInputStream _stringInputStream = new StringInputStream(_text);
copy.load(_stringInputStream, CollectionLiterals.<Object, Object>emptyMap());
this.serializer.<Resource>addModification(copy, mod);
final ArrayList<IEmfResourceChange> documentchanges = CollectionLiterals.<IEmfResourceChange>newArrayList();
this.serializer.applyModifications(CollectionBasedAcceptor.<IEmfResourceChange>of(documentchanges));
WorkspaceEdit _workspaceEdit = new WorkspaceEdit();
final Procedure1<WorkspaceEdit> _function = (WorkspaceEdit it) -> {
Iterable<ITextDocumentChange> _filter = Iterables.<ITextDocumentChange>filter(documentchanges, ITextDocumentChange.class);
for (final ITextDocumentChange documentchange : _filter) {
{
final Function1<ITextReplacement, TextEdit> _function_1 = (ITextReplacement replacement) -> {
TextEdit _textEdit = new TextEdit();
final Procedure1<TextEdit> _function_2 = (TextEdit it_1) -> {
it_1.setNewText(replacement.getReplacementText());
Position _position = doc.getPosition(replacement.getOffset());
Position _position_1 = doc.getPosition(replacement.getEndOffset());
Range _range = new Range(_position, _position_1);
it_1.setRange(_range);
};
return ObjectExtensions.<TextEdit>operator_doubleArrow(_textEdit, _function_2);
};
final List<TextEdit> edits = ListExtensions.<ITextReplacement, TextEdit>map(documentchange.getReplacements(), _function_1);
it.getChanges().put(documentchange.getNewURI().toString(), edits);
}
}
};
return ObjectExtensions.<WorkspaceEdit>operator_doubleArrow(_workspaceEdit, _function);
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtext.resource.XtextResourceSet in project xtext-core by eclipse.
the class AbstractXtextResourceSetTest method testResourcesAreInMapWithNormalizedURI_01.
@Test
public void testResourcesAreInMapWithNormalizedURI_01() {
final XtextResourceSet rs = this.createEmptyResourceSet();
Assert.assertEquals(0, rs.getURIResourceMap().size());
final XtextResource resource = new XtextResource();
resource.setURI(URI.createURI("/a/../foo"));
EList<Resource> _resources = rs.getResources();
_resources.add(resource);
Assert.assertEquals(2, rs.getURIResourceMap().size());
rs.getResources().remove(resource);
Assert.assertTrue(resource.eAdapters().isEmpty());
Assert.assertEquals(0, rs.getURIResourceMap().size());
}
Aggregations