Search in sources :

Example 21 with ResourceSet

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

the class AddProcessingResourceSpecification 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 22 with ResourceSet

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

the class ResourceSelectorPage method getResult.

protected EObject getResult(Session session) {
    EObject result = null;
    URI uri = URI.createURI(path, true);
    TransactionalEditingDomain domain = session.getTransactionalEditingDomain();
    ResourceSet resourceSet = domain.getResourceSet();
    try {
        Resource resource = resourceSet.getResource(uri, true);
        result = (EObject) resource.getContents().get(0);
    } catch (WrappedException ex) {
    // do nothing
    }
    return result;
}
Also used : WrappedException(org.eclipse.emf.common.util.WrappedException) TransactionalEditingDomain(org.eclipse.emf.transaction.TransactionalEditingDomain) EObject(org.eclipse.emf.ecore.EObject) Resource(org.eclipse.emf.ecore.resource.Resource) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) URI(org.eclipse.emf.common.util.URI)

Example 23 with ResourceSet

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

the class ConvertJavaCode method createResource.

private Resource createResource(IFile file, String content) throws ExecutionException {
    ResourceSet set = resourceSetProvider.get(file.getProject());
    Resource resource = set.createResource(URI.createPlatformResourceURI(file.getFullPath().toString(), false));
    try {
        resource.load(new LazyStringInputStream(content, file.getCharset()), null);
    } catch (CoreException e) {
        handleException("Failed to read file content", e, file);
    } catch (IOException e) {
        handleException("Failed to load resource.", e, file);
    }
    return resource;
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) Resource(org.eclipse.emf.ecore.resource.Resource) XtextResource(org.eclipse.xtext.resource.XtextResource) IResource(org.eclipse.core.resources.IResource) LazyStringInputStream(org.eclipse.xtext.util.LazyStringInputStream) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) IOException(java.io.IOException)

Example 24 with ResourceSet

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

the class DispatchMethodRenameStrategy method initialize.

@Override
public boolean initialize(EObject xtendMethod, IRenameElementContext context) {
    Assert.isLegal(xtendMethod instanceof XtendFunction);
    Assert.isLegal(((XtendFunction) xtendMethod).isDispatch());
    Assert.isLegal(context instanceof DispatchMethodRenameContext);
    ResourceSet resourceSet = xtendMethod.eResource().getResourceSet();
    Map<URI, IJavaElement> jvm2JavaElements = ((DispatchMethodRenameContext) context).getJvm2JavaElements();
    for (URI dispatchOperationURI : jvm2JavaElements.keySet()) {
        JvmOperation dispatchOperation = (JvmOperation) resourceSet.getEObject(dispatchOperationURI, true);
        XtendFunction xtendDispatchMethod = associations.getXtendFunction(dispatchOperation);
        if (xtendDispatchMethod != null) {
            if (equal(xtendDispatchMethod.getName(), dispatchOperation.getSimpleName())) {
                // synthetic dispatcher
                dispatchers.add(dispatchOperation);
            } else {
                // xtend dispatch method
                XtendDispatchMethodChildStrategy xtendChildStrategy = childStrategyProvider.get();
                xtendChildStrategy.initialize(xtendDispatchMethod, context);
                children.add(xtendChildStrategy);
            }
        } else {
            // a dispatch method form a Java class
            JavaDispatchMethodChildStrategy jvmChildStrategy = javaStrategyProvider.get();
            jvmChildStrategy.initialize(dispatchOperation, context);
            children.add(jvmChildStrategy);
        }
    }
    return !children.isEmpty();
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) IJavaElement(org.eclipse.jdt.core.IJavaElement) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) URI(org.eclipse.emf.common.util.URI)

Example 25 with ResourceSet

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

the class ExtractMethodUserInputPage method createSignaturePreview.

protected void createSignaturePreview(Composite composite) {
    Label previewLabel = new Label(composite, SWT.NONE);
    previewLabel.setText("Method signature preview:");
    GridData gridData = new GridData(SWT.FILL);
    gridData.horizontalSpan = 2;
    previewLabel.setLayoutData(gridData);
    signaturePreview = editorFactory.newEditor(new IEditedResourceProvider() {

        @Override
        public XtextResource createResource() {
            URI resourceURI = EcoreUtil2.getPlatformResourceOrNormalizedURI(refactoring.getXtendClass()).trimFragment();
            IProject project = projectUtil.getProject(resourceURI);
            ResourceSet resourceSet = resourceSetProvider.get(project);
            return (XtextResource) resourceSet.getResource(resourceURI, true);
        }
    }).readOnly().withParent(composite);
    GridData gridData2 = new GridData(GridData.FILL_HORIZONTAL);
    gridData2.horizontalSpan = 2;
    signaturePreview.getViewer().getControl().setLayoutData(gridData2);
    partialEditor = signaturePreview.createPartialEditor(getPartialEditorModelPrefix(), refactoring.getMethodSignature(), getPartialEditorModelSuffix(), true);
}
Also used : IEditedResourceProvider(org.eclipse.xtext.ui.editor.embedded.IEditedResourceProvider) Label(org.eclipse.swt.widgets.Label) GridData(org.eclipse.swt.layout.GridData) XtextResource(org.eclipse.xtext.resource.XtextResource) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) URI(org.eclipse.emf.common.util.URI) IProject(org.eclipse.core.resources.IProject)

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