use of org.eclipse.emf.ecore.resource.ResourceSet in project xtext-core by eclipse.
the class FileAwareTestLanguageImportTest method testRenameGlobal1.
@Test
public void testRenameGlobal1() {
final InMemoryURIHandler fs = new InMemoryURIHandler();
StringConcatenation _builder = new StringConcatenation();
_builder.append("package pkg1");
_builder.newLine();
_builder.newLine();
_builder.append("element Foo {");
_builder.newLine();
_builder.append("}");
_builder.newLine();
Pair<String, String> _mappedTo = Pair.<String, String>of("inmemory:/file1.fileawaretestlanguage", _builder.toString());
this._importTestHelper.operator_add(fs, _mappedTo);
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("package pkg2");
_builder_1.newLine();
_builder_1.newLine();
_builder_1.append("import pkg1.Foo");
_builder_1.newLine();
_builder_1.newLine();
_builder_1.append("element Bar {");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("ref Foo");
_builder_1.newLine();
_builder_1.append("}");
_builder_1.newLine();
Pair<String, String> _mappedTo_1 = Pair.<String, String>of("inmemory:/file2.fileawaretestlanguage", _builder_1.toString());
this._importTestHelper.operator_add(fs, _mappedTo_1);
final ResourceSet rs = this._importTestHelper.createResourceSet(fs);
final PackageDeclaration model = this._importTestHelper.<PackageDeclaration>contents(rs, "inmemory:/file1.fileawaretestlanguage", PackageDeclaration.class);
final ChangeSerializer serializer = this.serializerProvider.get();
final IChangeSerializer.IModification<PackageDeclaration> _function = (PackageDeclaration it) -> {
model.setName("newpackage");
};
serializer.<PackageDeclaration>addModification(model, _function);
Assert.assertEquals(1, model.eResource().getResourceSet().getResources().size());
Collection<IEmfResourceChange> _endRecordChangesToTextDocuments = this._importTestHelper.endRecordChangesToTextDocuments(serializer);
StringConcatenation _builder_2 = new StringConcatenation();
_builder_2.append("-------- inmemory:/file1.fileawaretestlanguage (syntax: <offset|text>) ---------");
_builder_2.newLine();
_builder_2.append("package <8:4|newpackage>");
_builder_2.newLine();
_builder_2.newLine();
_builder_2.append("element Foo {");
_builder_2.newLine();
_builder_2.append("}");
_builder_2.newLine();
_builder_2.append("--------------------------------------------------------------------------------");
_builder_2.newLine();
_builder_2.append("8 4 \"pkg1\" -> \"newpackage\"");
_builder_2.newLine();
_builder_2.append("-------- inmemory:/file2.fileawaretestlanguage (syntax: <offset|text>) ---------");
_builder_2.newLine();
_builder_2.append("package pkg2");
_builder_2.newLine();
_builder_2.newLine();
_builder_2.append("import <21:8|newpackage.Foo>");
_builder_2.newLine();
_builder_2.newLine();
_builder_2.append("element Bar {");
_builder_2.newLine();
_builder_2.append("\t");
_builder_2.append("ref Foo");
_builder_2.newLine();
_builder_2.append("}");
_builder_2.newLine();
_builder_2.append("--------------------------------------------------------------------------------");
_builder_2.newLine();
_builder_2.append("21 8 \"pkg1.Foo\" -> \"newpackage.Foo\"");
_builder_2.newLine();
this._importTestHelper.operator_tripleEquals(_endRecordChangesToTextDocuments, _builder_2);
}
use of org.eclipse.emf.ecore.resource.ResourceSet in project xtext-core by eclipse.
the class XtextLinkingService method getUsedGrammar.
private List<EObject> getUsedGrammar(Grammar grammar, INode node) {
try {
String grammarName = (String) valueConverterService.toValue("", "GrammarID", node);
if (grammarName != null) {
final ResourceSet resourceSet = grammar.eResource().getResourceSet();
List<Resource> resources = resourceSet.getResources();
for (int i = 0; i < resources.size(); i++) {
Resource resource = resources.get(i);
EObject rootElement = null;
if (resource instanceof XtextResource) {
IParseResult parseResult = ((XtextResource) resource).getParseResult();
if (parseResult != null)
rootElement = parseResult.getRootASTElement();
} else if (!resource.getContents().isEmpty()) {
rootElement = resource.getContents().get(0);
}
if (rootElement instanceof Grammar) {
Grammar otherGrammar = (Grammar) rootElement;
if (grammarName.equals(otherGrammar.getName())) {
if (resource instanceof DerivedStateAwareResource)
resource.getContents();
return Collections.<EObject>singletonList(otherGrammar);
}
}
}
URI classpathURI = URI.createURI(ClasspathUriUtil.CLASSPATH_SCHEME + ":/" + grammarName.replace('.', '/') + "." + fileExtension);
URI normalizedURI = null;
if (resourceSet instanceof XtextResourceSet) {
XtextResourceSet set = (XtextResourceSet) resourceSet;
normalizedURI = set.getClasspathUriResolver().resolve(set.getClasspathURIContext(), classpathURI);
} else {
normalizedURI = resourceSet.getURIConverter().normalize(classpathURI);
}
final Resource resource = resourceSet.getResource(normalizedURI, true);
if (!resource.getContents().isEmpty()) {
final Grammar usedGrammar = (Grammar) resource.getContents().get(0);
if (grammarName.equals(usedGrammar.getName()))
return Collections.<EObject>singletonList(usedGrammar);
}
}
return Collections.emptyList();
} catch (ClasspathUriResolutionException e) {
log.debug("Cannot load used grammar.", e);
return Collections.emptyList();
} catch (ValueConverterException e) {
log.debug("Cannot load used grammar.", e);
return Collections.emptyList();
}
}
use of org.eclipse.emf.ecore.resource.ResourceSet in project xtext-core by eclipse.
the class LinkingErrorTest method getContentSize.
private int getContentSize(EObject model) {
Resource resource = model.eResource();
assertNotNull(resource);
ResourceSet resourceSet = resource.getResourceSet();
assertNotNull(resourceSet);
TreeIterator<Object> iterator = EcoreUtil.getAllProperContents(resourceSet, true);
return getTreeIteratorContentSize(iterator);
}
use of org.eclipse.emf.ecore.resource.ResourceSet in project xtext-core by eclipse.
the class PartialParserCrossContainmentSingleTest method setCrossResourceContainer.
@Override
protected void setCrossResourceContainer(XtextResource resource) {
ResourceSet resourceSet = resource.getResourceSet();
Resource containerResource = resourceSet.createResource(URI.createFileURI("sample.xmi"));
CrossResourceContainerOneChild container = PartialParsingTestUtilFactory.eINSTANCE.createCrossResourceContainerOneChild();
containerResource.getContents().add(container);
assertEquals(1, resource.getContents().size());
container.setChild(resource.getContents().get(0));
}
use of org.eclipse.emf.ecore.resource.ResourceSet in project xtext-core by eclipse.
the class RuntimeResourceSetInitializer method getInitializedResourceSet.
public ResourceSet getInitializedResourceSet(List<String> pathes, UriFilter filter) {
ResourceSet resourceSet = resourceSetProvider.get();
Multimap<String, URI> pathToUriMap = getPathToUriMap(pathes, filter);
IAllContainersState containersState = factory.getContainersState(pathes, pathToUriMap);
resourceSet.eAdapters().add(new DelegatingIAllContainerAdapter(containersState));
for (URI uri : pathToUriMap.values()) {
resourceSet.createResource(uri);
}
return resourceSet;
}
Aggregations