use of org.eclipse.xtext.ide.serializer.IEmfResourceChange in project xtext-core by eclipse.
the class ChangeSerializerWithEmfTest method testChangeRefToXML.
@Test
public void testChangeRefToXML() {
final InMemoryURIHandler fs = new InMemoryURIHandler();
StringConcatenation _builder = new StringConcatenation();
_builder.append("#21 MyPackage.MyClass1");
Pair<String, String> _mappedTo = Pair.<String, String>of("inmemory:/file1.pstl", _builder.toString());
this._changeSerializerTestHelper.operator_add(fs, _mappedTo);
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
_builder_1.newLine();
_builder_1.append("<ecore:EPackage xmi:version=\"2.0\" xmlns:xmi=\"http://www.omg.org/XMI\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"");
_builder_1.newLine();
_builder_1.append(" ");
_builder_1.append("xmlns:ecore=\"http://www.eclipse.org/emf/2002/Ecore\" name=\"MyPackage\">");
_builder_1.newLine();
_builder_1.append(" ");
_builder_1.append("<eClassifiers xsi:type=\"ecore:EClass\" name=\"MyClass1\" eSuperTypes=\"#//MyClass2\"/>");
_builder_1.newLine();
_builder_1.append(" ");
_builder_1.append("<eClassifiers xsi:type=\"ecore:EClass\" name=\"MyClass2\"/>");
_builder_1.newLine();
_builder_1.append("</ecore:EPackage>");
_builder_1.newLine();
Pair<String, String> _mappedTo_1 = Pair.<String, String>of("inmemory:/file2.ecore", _builder_1.toString());
this._changeSerializerTestHelper.operator_add(fs, _mappedTo_1);
final ResourceSet rs = this._changeSerializerTestHelper.createResourceSet(fs);
final EClassRef model = this._changeSerializerTestHelper.<EClassRef>contents(rs, "inmemory:/file1.pstl", EClassRef.class);
final ChangeSerializer serializer = this.serializerProvider.get();
final IChangeSerializer.IModification<EClassRef> _function = (EClassRef it) -> {
EClassifier _get = model.getRef().getEPackage().getEClassifiers().get(1);
model.setRef(((EClass) _get));
};
serializer.<EClassRef>addModification(model, _function);
Collection<IEmfResourceChange> _endRecordChangesToTextDocuments = this._changeSerializerTestHelper.endRecordChangesToTextDocuments(serializer);
StringConcatenation _builder_2 = new StringConcatenation();
_builder_2.append("----------------- inmemory:/file1.pstl (syntax: <offset|text>) -----------------");
_builder_2.newLine();
_builder_2.append("#21 <4:18|MyPackage.MyClass2>");
_builder_2.newLine();
_builder_2.append("--------------------------------------------------------------------------------");
_builder_2.newLine();
_builder_2.append("4 18 \"MyPackage.MyClass1\" -> \"MyPackage.MyClass2\"");
_builder_2.newLine();
this._changeSerializerTestHelper.operator_tripleEquals(_endRecordChangesToTextDocuments, _builder_2);
}
use of org.eclipse.xtext.ide.serializer.IEmfResourceChange in project xtext-core by eclipse.
the class ChangeSerializerWithEmfTest method testChangeInXML.
@Test
public void testChangeInXML() {
final InMemoryURIHandler fs = new InMemoryURIHandler();
StringConcatenation _builder = new StringConcatenation();
_builder.append("#21 MyPackage.MyClass1");
Pair<String, String> _mappedTo = Pair.<String, String>of("inmemory:/file1.pstl", _builder.toString());
this._changeSerializerTestHelper.operator_add(fs, _mappedTo);
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
_builder_1.newLine();
_builder_1.append("<ecore:EPackage xmi:version=\"2.0\" xmlns:xmi=\"http://www.omg.org/XMI\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"");
_builder_1.newLine();
_builder_1.append(" ");
_builder_1.append("xmlns:ecore=\"http://www.eclipse.org/emf/2002/Ecore\" name=\"MyPackage\">");
_builder_1.newLine();
_builder_1.append(" ");
_builder_1.append("<eClassifiers xsi:type=\"ecore:EClass\" name=\"MyClass1\"/>");
_builder_1.newLine();
_builder_1.append("</ecore:EPackage>");
_builder_1.newLine();
Pair<String, String> _mappedTo_1 = Pair.<String, String>of("inmemory:/file2.ecore", _builder_1.toString());
this._changeSerializerTestHelper.operator_add(fs, _mappedTo_1);
final ResourceSet rs = this._changeSerializerTestHelper.createResourceSet(fs);
final EPackage model = this._changeSerializerTestHelper.<EPackage>contents(rs, "inmemory:/file2.ecore", EPackage.class);
final ChangeSerializer serializer = this.serializerProvider.get();
final IChangeSerializer.IModification<EPackage> _function = (EPackage it) -> {
EClassifier _head = IterableExtensions.<EClassifier>head(model.getEClassifiers());
((EClass) _head).setName("NewClass");
};
serializer.<EPackage>addModification(model, _function);
Collection<IEmfResourceChange> _endRecordChangesToTextDocuments = this._changeSerializerTestHelper.endRecordChangesToTextDocuments(serializer);
StringConcatenation _builder_2 = new StringConcatenation();
_builder_2.append("---------------------------- inmemory:/file2.ecore -----------------------------");
_builder_2.newLine();
_builder_2.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
_builder_2.newLine();
_builder_2.append("<ecore:EPackage xmi:version=\"2.0\" xmlns:xmi=\"http://www.omg.org/XMI\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"");
_builder_2.newLine();
_builder_2.append(" ");
_builder_2.append("xmlns:ecore=\"http://www.eclipse.org/emf/2002/Ecore\" name=\"MyPackage\">");
_builder_2.newLine();
_builder_2.append(" ");
_builder_2.append("<eClassifiers xsi:type=\"ecore:EClass\" name=\"NewClass\"/>");
_builder_2.newLine();
_builder_2.append("</ecore:EPackage>");
_builder_2.newLine();
_builder_2.append("--------------------------------------------------------------------------------");
_builder_2.newLine();
_builder_2.append("----------------- inmemory:/file1.pstl (syntax: <offset|text>) -----------------");
_builder_2.newLine();
_builder_2.append("#21 <4:18|MyPackage.NewClass>");
_builder_2.newLine();
_builder_2.append("--------------------------------------------------------------------------------");
_builder_2.newLine();
_builder_2.append("4 18 \"MyPackage.MyClass1\" -> \"MyPackage.NewClass\"");
_builder_2.newLine();
this._changeSerializerTestHelper.operator_tripleEquals(_endRecordChangesToTextDocuments, _builder_2);
}
use of org.eclipse.xtext.ide.serializer.IEmfResourceChange 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.ide.serializer.IEmfResourceChange in project xtext-core by eclipse.
the class FileAwareTestLanguageImportTest method testNestedPackage.
@Test
public void testNestedPackage() {
final InMemoryURIHandler fs = new InMemoryURIHandler();
StringConcatenation _builder = new StringConcatenation();
_builder.append("package foo ");
_builder.newLine();
_builder.append("element X {}");
_builder.newLine();
Pair<String, String> _mappedTo = Pair.<String, String>of("inmemory:/foo/X.fileawaretestlanguage", _builder.toString());
this._importTestHelper.operator_add(fs, _mappedTo);
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("package foo.bar ");
_builder_1.newLine();
_builder_1.append("element Y { ref foo.X }");
_builder_1.newLine();
Pair<String, String> _mappedTo_1 = Pair.<String, String>of("inmemory:/foo/bar/Y.fileawaretestlanguage", _builder_1.toString());
this._importTestHelper.operator_add(fs, _mappedTo_1);
final ResourceSet rs = this._importTestHelper.createResourceSet(fs);
final PackageDeclaration model1 = this._importTestHelper.<PackageDeclaration>contents(rs, "inmemory:/foo/X.fileawaretestlanguage", PackageDeclaration.class);
final PackageDeclaration model2 = this._importTestHelper.<PackageDeclaration>contents(rs, "inmemory:/foo/bar/Y.fileawaretestlanguage", PackageDeclaration.class);
final ChangeSerializer serializer = this.serializerProvider.get();
final IChangeSerializer.IModification<PackageDeclaration> _function = (PackageDeclaration it) -> {
it.setName("foo2");
};
serializer.<PackageDeclaration>addModification(model1, _function);
final IChangeSerializer.IModification<PackageDeclaration> _function_1 = (PackageDeclaration it) -> {
model2.setName("foo2.bar");
model2.setName("foo2.bar");
};
serializer.<PackageDeclaration>addModification(model2, _function_1);
Collection<IEmfResourceChange> _endRecordChangesToTextDocuments = this._importTestHelper.endRecordChangesToTextDocuments(serializer);
StringConcatenation _builder_2 = new StringConcatenation();
_builder_2.append("-------- inmemory:/foo/X.fileawaretestlanguage (syntax: <offset|text>) ---------");
_builder_2.newLine();
_builder_2.append("package <8:3|foo2> ");
_builder_2.newLine();
_builder_2.append("element X {}");
_builder_2.newLine();
_builder_2.append("--------------------------------------------------------------------------------");
_builder_2.newLine();
_builder_2.append("8 3 \"foo\" -> \"foo2\"");
_builder_2.newLine();
_builder_2.append("------ inmemory:/foo/bar/Y.fileawaretestlanguage (syntax: <offset|text>) -------");
_builder_2.newLine();
_builder_2.append("package <8:7|foo2.bar> ");
_builder_2.newLine();
_builder_2.append("<17:0|import foo2.X");
_builder_2.newLine();
_builder_2.newLine();
_builder_2.append(">element Y { ref <33:5|X> }");
_builder_2.newLine();
_builder_2.append("--------------------------------------------------------------------------------");
_builder_2.newLine();
_builder_2.append(" ");
_builder_2.append("8 7 \"foo.bar\" -> \"foo2.bar\"");
_builder_2.newLine();
_builder_2.append("17 0 \"\" -> \"import foo2.X\\n\\n\"");
_builder_2.newLine();
_builder_2.append("33 5 \"foo.X\" -> \"X\"");
_builder_2.newLine();
this._importTestHelper.operator_tripleEquals(_endRecordChangesToTextDocuments, _builder_2);
}
use of org.eclipse.xtext.ide.serializer.IEmfResourceChange 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);
}
Aggregations