Search in sources :

Example 6 with PackageDeclaration

use of org.eclipse.xtext.testlanguages.fileAware.fileAware.PackageDeclaration in project xtext-core by eclipse.

the class FileAwareTestLanguageReferenceUpdater method update.

@Override
public void update(final IReferenceUpdaterContext context) {
    super.update(context);
    EObject _head = IterableExtensions.<EObject>head(context.getResource().getContents());
    final PackageDeclaration pkg = ((PackageDeclaration) _head);
    final QualifiedName pkgName = this.names.getFullyQualifiedName(pkg);
    final Function1<Import, Element> _function = (Import it) -> {
        return it.getElement();
    };
    final Map<Element, Import> actual = IterableExtensions.<Element, Import>toMap(pkg.getImports(), _function);
    final Function1<IUpdatableReference, EObject> _function_1 = (IUpdatableReference it) -> {
        return it.getTargetEObject();
    };
    final Iterable<Element> targets = Iterables.<Element>filter(ListExtensions.<IUpdatableReference, EObject>map(context.getUpdatableReferences(), _function_1), Element.class);
    final Function1<Element, Boolean> _function_2 = (Element it) -> {
        boolean _startsWith = this.names.getFullyQualifiedName(it).startsWith(pkgName);
        return Boolean.valueOf((!_startsWith));
    };
    final Set<Element> expected = IterableExtensions.<Element>toSet(IterableExtensions.<Element>filter(targets, _function_2));
    final Function1<Element, Boolean> _function_3 = (Element it) -> {
        boolean _containsKey = actual.containsKey(it);
        return Boolean.valueOf((!_containsKey));
    };
    final Set<Element> toAdd = IterableExtensions.<Element>toSet(IterableExtensions.<Element>filter(expected, _function_3));
    final Function2<Element, Import, Boolean> _function_4 = (Element $0, Import $1) -> {
        boolean _contains = expected.contains($0);
        return Boolean.valueOf((!_contains));
    };
    final Map<Element, Import> toDelete = MapExtensions.<Element, Import>filter(actual, _function_4);
    if (((!toAdd.isEmpty()) || (!toDelete.isEmpty()))) {
        final Runnable _function_5 = () -> {
            final Consumer<Import> _function_6 = (Import it) -> {
                EcoreUtil.remove(it);
            };
            toDelete.values().forEach(_function_6);
            final Consumer<Element> _function_7 = (Element e) -> {
                EList<Import> _imports = pkg.getImports();
                Import _createImport = this._fileAwareFactory.createImport();
                final Procedure1<Import> _function_8 = (Import it) -> {
                    it.setElement(e);
                };
                Import _doubleArrow = ObjectExtensions.<Import>operator_doubleArrow(_createImport, _function_8);
                _imports.add(_doubleArrow);
            };
            toAdd.forEach(_function_7);
        };
        context.modifyModel(_function_5);
    }
}
Also used : Import(org.eclipse.xtext.testlanguages.fileAware.fileAware.Import) IUpdatableReference(org.eclipse.xtext.ide.serializer.hooks.IUpdatableReference) QualifiedName(org.eclipse.xtext.naming.QualifiedName) Element(org.eclipse.xtext.testlanguages.fileAware.fileAware.Element) Consumer(java.util.function.Consumer) EObject(org.eclipse.emf.ecore.EObject) PackageDeclaration(org.eclipse.xtext.testlanguages.fileAware.fileAware.PackageDeclaration)

Example 7 with PackageDeclaration

use of org.eclipse.xtext.testlanguages.fileAware.fileAware.PackageDeclaration in project xtext-core by eclipse.

the class FileAwareTestLanguageImportTest method testMoveToNewPackage.

@Test
public void testMoveToNewPackage() {
    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 pkg1");
    _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 pkg1");
    _builder_2.newLine();
    _builder_2.newLine();
    _builder_2.append("<14:0|import 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("14 0 \"\" -> \"import newpackage...\"");
    _builder_2.newLine();
    this._importTestHelper.operator_tripleEquals(_endRecordChangesToTextDocuments, _builder_2);
}
Also used : IChangeSerializer(org.eclipse.xtext.ide.serializer.IChangeSerializer) ChangeSerializer(org.eclipse.xtext.ide.serializer.impl.ChangeSerializer) IChangeSerializer(org.eclipse.xtext.ide.serializer.IChangeSerializer) InMemoryURIHandler(org.eclipse.xtext.testing.util.InMemoryURIHandler) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) PackageDeclaration(org.eclipse.xtext.testlanguages.fileAware.fileAware.PackageDeclaration) IEmfResourceChange(org.eclipse.xtext.ide.serializer.IEmfResourceChange) Test(org.junit.Test)

Example 8 with PackageDeclaration

use of org.eclipse.xtext.testlanguages.fileAware.fileAware.PackageDeclaration in project xtext-core by eclipse.

the class FileAwareTestLanguageImportTest method testMoveIntoLocalPackage.

@Test
public void testMoveIntoLocalPackage() {
    final InMemoryURIHandler fs = new InMemoryURIHandler();
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("package other");
    _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 pkg1");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("import other.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("pkg1");
    };
    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:5|pkg1>");
    _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 5 \"other\" -> \"pkg1\"");
    _builder_2.newLine();
    _builder_2.append("-------- inmemory:/file2.fileawaretestlanguage (syntax: <offset|text>) ---------");
    _builder_2.newLine();
    _builder_2.append("package pkg1");
    _builder_2.newLine();
    _builder_2.newLine();
    _builder_2.append("<14:18|>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("14 18 \"import other.Foo\\n\\n\" -> \"\"");
    _builder_2.newLine();
    this._importTestHelper.operator_tripleEquals(_endRecordChangesToTextDocuments, _builder_2);
}
Also used : IChangeSerializer(org.eclipse.xtext.ide.serializer.IChangeSerializer) ChangeSerializer(org.eclipse.xtext.ide.serializer.impl.ChangeSerializer) IChangeSerializer(org.eclipse.xtext.ide.serializer.IChangeSerializer) InMemoryURIHandler(org.eclipse.xtext.testing.util.InMemoryURIHandler) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) PackageDeclaration(org.eclipse.xtext.testlanguages.fileAware.fileAware.PackageDeclaration) IEmfResourceChange(org.eclipse.xtext.ide.serializer.IEmfResourceChange) Test(org.junit.Test)

Aggregations

PackageDeclaration (org.eclipse.xtext.testlanguages.fileAware.fileAware.PackageDeclaration)8 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)4 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)4 IChangeSerializer (org.eclipse.xtext.ide.serializer.IChangeSerializer)4 IEmfResourceChange (org.eclipse.xtext.ide.serializer.IEmfResourceChange)4 ChangeSerializer (org.eclipse.xtext.ide.serializer.impl.ChangeSerializer)4 InMemoryURIHandler (org.eclipse.xtext.testing.util.InMemoryURIHandler)4 Test (org.junit.Test)4 Import (org.eclipse.xtext.testlanguages.fileAware.fileAware.Import)3 EObject (org.eclipse.emf.ecore.EObject)2 QualifiedName (org.eclipse.xtext.naming.QualifiedName)2 Element (org.eclipse.xtext.testlanguages.fileAware.fileAware.Element)2 Consumer (java.util.function.Consumer)1 EPackage (org.eclipse.emf.ecore.EPackage)1 Resource (org.eclipse.emf.ecore.resource.Resource)1 Action (org.eclipse.xtext.Action)1 Parameter (org.eclipse.xtext.Parameter)1 ParserRule (org.eclipse.xtext.ParserRule)1 ResourceRelocationChange (org.eclipse.xtext.ide.refactoring.ResourceRelocationChange)1 IUpdatableReference (org.eclipse.xtext.ide.serializer.hooks.IUpdatableReference)1