Search in sources :

Example 71 with ResourceSet

use of org.eclipse.emf.ecore.resource.ResourceSet in project Palladio-Editors-Sirius by PalladioSimulator.

the class AddHDDProcessingResourceSpecification method getSchedulingPolicy.

private SchedulingPolicy getSchedulingPolicy(final ProcessingResourceSpecification processingResourceSpecification) {
    final ResourceSet set = (processingResourceSpecification.getResourceContainer_ProcessingResourceSpecification()).eResource().getResourceSet();
    // positive filter
    final ArrayList<Object> filterList = new ArrayList<Object>();
    // Set types to show and their super types
    filterList.add(SchedulingPolicy.class);
    filterList.add(ResourceRepository.class);
    final ArrayList<EReference> additionalReferences = new ArrayList<EReference>();
    // set EReference that should be set (in this case: SchedulingPolicy)
    additionalReferences.add(ResourceenvironmentPackage.eINSTANCE.getProcessingResourceSpecification_SchedulingPolicy());
    final PalladioSelectEObjectDialog dialog = new PalladioSelectEObjectDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), filterList, additionalReferences, set);
    dialog.setProvidedService(SchedulingPolicy.class);
    dialog.open();
    if (dialog.getResult() == null || !(dialog.getResult() instanceof SchedulingPolicy)) {
        return null;
    }
    return (SchedulingPolicy) dialog.getResult();
}
Also used : PalladioSelectEObjectDialog(org.palladiosimulator.editors.commons.dialogs.selection.PalladioSelectEObjectDialog) ArrayList(java.util.ArrayList) EObject(org.eclipse.emf.ecore.EObject) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) SchedulingPolicy(org.palladiosimulator.pcm.resourcetype.SchedulingPolicy) EReference(org.eclipse.emf.ecore.EReference)

Example 72 with ResourceSet

use of org.eclipse.emf.ecore.resource.ResourceSet in project Palladio-Editors-Sirius by PalladioSimulator.

the class ResourceSelectorPage method resolveSelection.

/**
 * checks if the selected file is a valid resource.
 */
private void resolveSelection() {
    myResolvedObject = null;
    URI uri = URI.createURI(mySelectionText.getText(), true);
    TransactionalEditingDomain editingDomain = EditingDomainFactoryService.INSTANCE.getEditingDomainFactory().createEditingDomain();
    ResourceSet resourceSet = editingDomain.getResourceSet();
    try {
        Resource resource = resourceSet.getResource(uri, true);
        myResolvedObject = (EObject) resource.getContents().get(0);
        path = mySelectionText.getText();
    } catch (WrappedException ex) {
    // do nothing
    }
}
Also used : WrappedException(org.eclipse.emf.common.util.WrappedException) TransactionalEditingDomain(org.eclipse.emf.transaction.TransactionalEditingDomain) Resource(org.eclipse.emf.ecore.resource.Resource) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) URI(org.eclipse.emf.common.util.URI)

Example 73 with ResourceSet

use of org.eclipse.emf.ecore.resource.ResourceSet in project xtext-xtend by eclipse.

the class ResourceStorageTest method testConstantValueIsPersisted.

@Test
public void testConstantValueIsPersisted() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("class C {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("static val CONSTANT = \'a\' + \'b\' + 0");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final String contents = _builder.toString();
        final XtendFile file = this.file(contents);
        final ByteArrayOutputStream bout = new ByteArrayOutputStream();
        ((ResourceStorageFacade) this.resourceStorageFacade).setStoreNodeModel(true);
        Resource _eResource = file.eResource();
        this.resourceStorageFacade.createResourceStorageWritable(bout).writeResource(((StorageAwareResource) _eResource));
        byte[] _byteArray = bout.toByteArray();
        ByteArrayInputStream _byteArrayInputStream = new ByteArrayInputStream(_byteArray);
        final ResourceStorageLoadable in = this.resourceStorageFacade.createResourceStorageLoadable(_byteArrayInputStream);
        Resource _createResource = file.eResource().getResourceSet().createResource(URI.createURI("synthetic:/test/MyClass.xtend"));
        final StorageAwareResource resource = ((StorageAwareResource) _createResource);
        final InMemoryURIConverter converter = new InMemoryURIConverter();
        converter.addModel(resource.getURI().toString(), contents);
        ResourceSet _resourceSet = resource.getResourceSet();
        _resourceSet.setURIConverter(converter);
        EList<Resource> _resources = file.eResource().getResourceSet().getResources();
        _resources.add(resource);
        resource.loadFromStorage(in);
        EObject _get = resource.getContents().get(1);
        final JvmGenericType jvmClass = ((JvmGenericType) _get);
        JvmMember _last = IterableExtensions.<JvmMember>last(jvmClass.getMembers());
        final JvmField field = ((JvmField) _last);
        Assert.assertTrue(field.isConstant());
        Assert.assertTrue(field.isSetConstant());
        Assert.assertEquals("ab0", field.getConstantValue());
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) InMemoryURIConverter(org.eclipse.xtend.core.tests.util.InMemoryURIConverter) ResourceStorageFacade(org.eclipse.xtext.resource.persistence.ResourceStorageFacade) IResourceStorageFacade(org.eclipse.xtext.resource.persistence.IResourceStorageFacade) Resource(org.eclipse.emf.ecore.resource.Resource) BatchLinkableResource(org.eclipse.xtext.xbase.resource.BatchLinkableResource) StorageAwareResource(org.eclipse.xtext.resource.persistence.StorageAwareResource) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) ByteArrayOutputStream(java.io.ByteArrayOutputStream) StorageAwareResource(org.eclipse.xtext.resource.persistence.StorageAwareResource) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) ResourceStorageLoadable(org.eclipse.xtext.resource.persistence.ResourceStorageLoadable) ByteArrayInputStream(java.io.ByteArrayInputStream) EObject(org.eclipse.emf.ecore.EObject) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) JvmMember(org.eclipse.xtext.common.types.JvmMember) JvmField(org.eclipse.xtext.common.types.JvmField) Test(org.junit.Test)

Example 74 with ResourceSet

use of org.eclipse.emf.ecore.resource.ResourceSet in project xtext-xtend by eclipse.

the class XtendResourceSetBasedResourceDescriptionsTest method testUnloadedBidirectionalRef.

@Test
public void testUnloadedBidirectionalRef() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("package foo class ClassA extends bar.ClassB {}");
        Pair<String, String> _mappedTo = Pair.<String, String>of("foo/ClassA.xtend", _builder.toString());
        StringConcatenation _builder_1 = new StringConcatenation();
        _builder_1.append("package bar class ClassB { public foo.ClassA myField }");
        Pair<String, String> _mappedTo_1 = Pair.<String, String>of("bar/ClassB.xtend", _builder_1.toString());
        final ResourceSet resourceSet = this.compiler.unLoadedResourceSet(_mappedTo, _mappedTo_1);
        final List<? extends Resource> resources = resourceSet.getResources();
        ArrayList<Resource> _arrayList = new ArrayList<Resource>(resources);
        for (final Resource res : _arrayList) {
            {
                final List<Issue> issues = this.validator.validate(res, CheckMode.ALL, CancelIndicator.NullImpl);
                Assert.assertTrue(issues.toString(), issues.isEmpty());
            }
        }
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) DerivedStateAwareResource(org.eclipse.xtext.resource.DerivedStateAwareResource) Resource(org.eclipse.emf.ecore.resource.Resource) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) Test(org.junit.Test)

Example 75 with ResourceSet

use of org.eclipse.emf.ecore.resource.ResourceSet in project xtext-xtend by eclipse.

the class XtendResourceSetBasedResourceDescriptionsTest method testUnloadedInstallDerivedStateThrowsException.

@Test
public void testUnloadedInstallDerivedStateThrowsException() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("package foo class ClassA extends bar.ClassB {}");
        Pair<String, String> _mappedTo = Pair.<String, String>of("foo/ClassA.xtend", _builder.toString());
        StringConcatenation _builder_1 = new StringConcatenation();
        _builder_1.append("package bar class ClassB { public foo.ClassA myField }");
        Pair<String, String> _mappedTo_1 = Pair.<String, String>of("bar/ClassB.xtend", _builder_1.toString());
        final ResourceSet resourceSet = this.compiler.unLoadedResourceSet(_mappedTo, _mappedTo_1);
        final List<? extends Resource> resources = resourceSet.getResources();
        ArrayList<Resource> _arrayList = new ArrayList<Resource>(resources);
        for (final Resource res : _arrayList) {
            {
                Assert.assertFalse(res.isLoaded());
                try {
                    ((DerivedStateAwareResource) res).installDerivedState(true);
                    Assert.fail("expected exception");
                } catch (final Throwable _t) {
                    if (_t instanceof IllegalStateException) {
                    } else {
                        throw Exceptions.sneakyThrow(_t);
                    }
                }
            }
        }
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) DerivedStateAwareResource(org.eclipse.xtext.resource.DerivedStateAwareResource) Resource(org.eclipse.emf.ecore.resource.Resource) ArrayList(java.util.ArrayList) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) Test(org.junit.Test)

Aggregations

ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)123 Resource (org.eclipse.emf.ecore.resource.Resource)71 Test (org.junit.Test)51 EObject (org.eclipse.emf.ecore.EObject)34 URI (org.eclipse.emf.common.util.URI)32 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)32 IChangeSerializer (org.eclipse.xtext.ide.serializer.IChangeSerializer)21 InMemoryURIHandler (org.eclipse.xtext.testing.util.InMemoryURIHandler)21 IEmfResourceChange (org.eclipse.xtext.ide.serializer.IEmfResourceChange)20 ResourceSetImpl (org.eclipse.emf.ecore.resource.impl.ResourceSetImpl)17 XtextResourceSet (org.eclipse.xtext.resource.XtextResourceSet)17 XtextResource (org.eclipse.xtext.resource.XtextResource)16 EPackage (org.eclipse.emf.ecore.EPackage)12 IFile (org.eclipse.core.resources.IFile)10 Node (org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.Node)10 ArrayList (java.util.ArrayList)9 EClass (org.eclipse.emf.ecore.EClass)9 ChangeSerializer (org.eclipse.xtext.ide.serializer.impl.ChangeSerializer)9 IOException (java.io.IOException)8 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)8