Search in sources :

Example 1 with SerializableReferenceDescription

use of org.eclipse.xtext.resource.persistence.SerializableReferenceDescription in project xtext-core by eclipse.

the class SerializableResourceDescriptionTest method testSerialization.

@Test
public void testSerialization() {
    try {
        final URI uri = URI.createURI("file:/foo/bar.baz.foo");
        SerializableResourceDescription _serializableResourceDescription = new SerializableResourceDescription();
        final Procedure1<SerializableResourceDescription> _function = (SerializableResourceDescription it) -> {
            it.setURI(uri);
            SerializableReferenceDescription _serializableReferenceDescription = new SerializableReferenceDescription();
            final Procedure1<SerializableReferenceDescription> _function_1 = (SerializableReferenceDescription it_1) -> {
                it_1.setSourceEObjectUri(uri.appendFragment("foo"));
                it_1.setTargetEObjectUri(uri.appendFragment("hubble"));
                it_1.setContainerEObjectURI(uri.appendFragment("baz"));
                it_1.setEReference(EcorePackage.eINSTANCE.getEAnnotation_Contents());
                it_1.setIndexInList(1);
            };
            SerializableReferenceDescription _doubleArrow = ObjectExtensions.<SerializableReferenceDescription>operator_doubleArrow(_serializableReferenceDescription, _function_1);
            SerializableReferenceDescription _serializableReferenceDescription_1 = new SerializableReferenceDescription();
            final Procedure1<SerializableReferenceDescription> _function_2 = (SerializableReferenceDescription it_1) -> {
                it_1.setSourceEObjectUri(uri.appendFragment("foo2"));
                it_1.setTargetEObjectUri(uri.appendFragment("hubble2"));
                it_1.setContainerEObjectURI(uri.appendFragment("baz2"));
                it_1.setEReference(EcorePackage.eINSTANCE.getEAnnotation_Contents());
                it_1.setIndexInList(2);
            };
            SerializableReferenceDescription _doubleArrow_1 = ObjectExtensions.<SerializableReferenceDescription>operator_doubleArrow(_serializableReferenceDescription_1, _function_2);
            it.setReferences(Collections.<SerializableReferenceDescription>unmodifiableList(CollectionLiterals.<SerializableReferenceDescription>newArrayList(_doubleArrow, _doubleArrow_1)));
            SerializableEObjectDescription _serializableEObjectDescription = new SerializableEObjectDescription();
            final Procedure1<SerializableEObjectDescription> _function_3 = (SerializableEObjectDescription it_1) -> {
                it_1.setEObjectURI(uri.appendFragment("baz"));
                it_1.qualifiedName = QualifiedName.create("foo", "baz");
                it_1.setEClass(EcorePackage.eINSTANCE.getEAttribute());
                Pair<String, String> _mappedTo = Pair.<String, String>of("myKey", "myValue");
                it_1.userData = CollectionLiterals.<String, String>newHashMap(_mappedTo);
            };
            SerializableEObjectDescription _doubleArrow_2 = ObjectExtensions.<SerializableEObjectDescription>operator_doubleArrow(_serializableEObjectDescription, _function_3);
            it.setDescriptions(Collections.<SerializableEObjectDescription>unmodifiableList(CollectionLiterals.<SerializableEObjectDescription>newArrayList(_doubleArrow_2)));
            QualifiedName _create = QualifiedName.create("foo");
            QualifiedName _create_1 = QualifiedName.create("foo", "bar");
            it.setImportedNames(Collections.<QualifiedName>unmodifiableList(CollectionLiterals.<QualifiedName>newArrayList(_create, _create_1)));
        };
        final SerializableResourceDescription before = ObjectExtensions.<SerializableResourceDescription>operator_doubleArrow(_serializableResourceDescription, _function);
        final ByteArrayOutputStream bout = new ByteArrayOutputStream();
        final ObjectOutputStream objectOut = new ObjectOutputStream(bout);
        objectOut.writeObject(before);
        byte[] _byteArray = bout.toByteArray();
        ByteArrayInputStream _byteArrayInputStream = new ByteArrayInputStream(_byteArray);
        final ObjectInputStream in = new ObjectInputStream(_byteArrayInputStream);
        Object _readObject = in.readObject();
        final SerializableResourceDescription after = ((SerializableResourceDescription) _readObject);
        this.assertDescriptionsEqual(before, after);
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : SerializableReferenceDescription(org.eclipse.xtext.resource.persistence.SerializableReferenceDescription) QualifiedName(org.eclipse.xtext.naming.QualifiedName) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) URI(org.eclipse.emf.common.util.URI) SerializableEObjectDescription(org.eclipse.xtext.resource.persistence.SerializableEObjectDescription) ByteArrayInputStream(java.io.ByteArrayInputStream) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) SerializableResourceDescription(org.eclipse.xtext.resource.persistence.SerializableResourceDescription) ObjectInputStream(java.io.ObjectInputStream) Test(org.junit.Test)

Example 2 with SerializableReferenceDescription

use of org.eclipse.xtext.resource.persistence.SerializableReferenceDescription in project xtext-core by eclipse.

the class ResourceStorageWritable method convertExternalURIsToPortableURIs.

protected void convertExternalURIsToPortableURIs(final SerializableResourceDescription description, final StorageAwareResource resource) {
    Iterable<IReferenceDescription> _referenceDescriptions = description.getReferenceDescriptions();
    for (final IReferenceDescription ref : _referenceDescriptions) {
        URI _trimFragment = ref.getTargetEObjectUri().trimFragment();
        URI _uRI = resource.getURI();
        boolean _notEquals = (!Objects.equal(_trimFragment, _uRI));
        if (_notEquals) {
            URI _elvis = null;
            URI _portableURI = resource.getPortableURIs().toPortableURI(resource, ref.getTargetEObjectUri());
            if (_portableURI != null) {
                _elvis = _portableURI;
            } else {
                URI _targetEObjectUri = ref.getTargetEObjectUri();
                _elvis = _targetEObjectUri;
            }
            ((SerializableReferenceDescription) ref).setTargetEObjectUri(_elvis);
        }
    }
}
Also used : SerializableReferenceDescription(org.eclipse.xtext.resource.persistence.SerializableReferenceDescription) URI(org.eclipse.emf.common.util.URI) IReferenceDescription(org.eclipse.xtext.resource.IReferenceDescription)

Example 3 with SerializableReferenceDescription

use of org.eclipse.xtext.resource.persistence.SerializableReferenceDescription in project xtext-core by eclipse.

the class SerializableResourceDescription method readExternal.

@Override
public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
    this.setURI(SerializationExtensions.readURI(in));
    final int descriptionsSize = in.readInt();
    ArrayList<SerializableEObjectDescription> _arrayList = new ArrayList<SerializableEObjectDescription>(descriptionsSize);
    this.descriptions = _arrayList;
    ExclusiveRange _doubleDotLessThan = new ExclusiveRange(0, descriptionsSize, true);
    for (final Integer i : _doubleDotLessThan) {
        this.descriptions.add(SerializationExtensions.<SerializableEObjectDescription>readCastedObject(in));
    }
    final int referencesSize = in.readInt();
    ArrayList<SerializableReferenceDescription> _arrayList_1 = new ArrayList<SerializableReferenceDescription>(referencesSize);
    this.references = _arrayList_1;
    ExclusiveRange _doubleDotLessThan_1 = new ExclusiveRange(0, referencesSize, true);
    for (final Integer i_1 : _doubleDotLessThan_1) {
        this.references.add(SerializationExtensions.<SerializableReferenceDescription>readCastedObject(in));
    }
    final int importedNamesSize = in.readInt();
    ArrayList<QualifiedName> _arrayList_2 = new ArrayList<QualifiedName>(importedNamesSize);
    this.importedNames = _arrayList_2;
    ExclusiveRange _doubleDotLessThan_2 = new ExclusiveRange(0, importedNamesSize, true);
    for (final Integer i_2 : _doubleDotLessThan_2) {
        this.importedNames.add(SerializationExtensions.readQualifiedName(in));
    }
}
Also used : SerializableEObjectDescription(org.eclipse.xtext.resource.persistence.SerializableEObjectDescription) SerializableReferenceDescription(org.eclipse.xtext.resource.persistence.SerializableReferenceDescription) QualifiedName(org.eclipse.xtext.naming.QualifiedName) ArrayList(java.util.ArrayList) ExclusiveRange(org.eclipse.xtext.xbase.lib.ExclusiveRange)

Example 4 with SerializableReferenceDescription

use of org.eclipse.xtext.resource.persistence.SerializableReferenceDescription in project xtext-core by eclipse.

the class SerializableResourceDescription method createCopy.

private static SerializableReferenceDescription createCopy(final IReferenceDescription desc) {
    SerializableReferenceDescription _serializableReferenceDescription = new SerializableReferenceDescription();
    final Procedure1<SerializableReferenceDescription> _function = (SerializableReferenceDescription it) -> {
        it.setSourceEObjectUri(desc.getSourceEObjectUri());
        it.setTargetEObjectUri(desc.getTargetEObjectUri());
        it.setEReference(desc.getEReference());
        it.setIndexInList(desc.getIndexInList());
        it.setContainerEObjectURI(desc.getContainerEObjectURI());
    };
    return ObjectExtensions.<SerializableReferenceDescription>operator_doubleArrow(_serializableReferenceDescription, _function);
}
Also used : SerializableReferenceDescription(org.eclipse.xtext.resource.persistence.SerializableReferenceDescription)

Example 5 with SerializableReferenceDescription

use of org.eclipse.xtext.resource.persistence.SerializableReferenceDescription in project xtext-core by eclipse.

the class SerializableResourceDescription method writeExternal.

@Override
public void writeExternal(final ObjectOutput out) throws IOException {
    SerializationExtensions.writeURI(out, this.uRI);
    out.writeInt(this.descriptions.size());
    for (final SerializableEObjectDescription desc : this.descriptions) {
        out.writeObject(desc);
    }
    out.writeInt(this.references.size());
    for (final SerializableReferenceDescription ref : this.references) {
        out.writeObject(ref);
    }
    out.writeInt(this.importedNames.size());
    for (final QualifiedName name : this.importedNames) {
        SerializationExtensions.writeQualifiedName(out, name);
    }
}
Also used : SerializableEObjectDescription(org.eclipse.xtext.resource.persistence.SerializableEObjectDescription) SerializableReferenceDescription(org.eclipse.xtext.resource.persistence.SerializableReferenceDescription) QualifiedName(org.eclipse.xtext.naming.QualifiedName)

Aggregations

SerializableReferenceDescription (org.eclipse.xtext.resource.persistence.SerializableReferenceDescription)7 SerializableEObjectDescription (org.eclipse.xtext.resource.persistence.SerializableEObjectDescription)5 QualifiedName (org.eclipse.xtext.naming.QualifiedName)4 URI (org.eclipse.emf.common.util.URI)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 ObjectInputStream (java.io.ObjectInputStream)2 ObjectOutputStream (java.io.ObjectOutputStream)2 SerializableResourceDescription (org.eclipse.xtext.resource.persistence.SerializableResourceDescription)2 ExclusiveRange (org.eclipse.xtext.xbase.lib.ExclusiveRange)2 Procedure1 (org.eclipse.xtext.xbase.lib.Procedures.Procedure1)2 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1 IReferenceDescription (org.eclipse.xtext.resource.IReferenceDescription)1