Search in sources :

Example 76 with Resource

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

the class WorkbenchTestHelper method xtendFile.

public XtendFile xtendFile(String fileName, String content) throws Exception {
    IFile file = createFile(fileName, content);
    Resource resource = getResourceSet().createResource(uri(file));
    resource.load(new StringInputStream(content), null);
    assertEquals(resource.getErrors().toString(), 0, resource.getErrors().size());
    XtendFile xtendFile = (XtendFile) resource.getContents().get(0);
    return xtendFile;
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) StringInputStream(org.eclipse.xtext.util.StringInputStream) IFile(org.eclipse.core.resources.IFile) Resource(org.eclipse.emf.ecore.resource.Resource) IResource(org.eclipse.core.resources.IResource)

Example 77 with Resource

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

the class WorkbenchTestHelper method xtendFile.

public XtendFile xtendFile(IProject project, String fileName, String content) throws Exception {
    IFile file = createFileImpl(project.getName() + "/src/" + fileName, content);
    Resource resource = resourceSetProvider.get(project).createResource(uri(file));
    resource.load(new StringInputStream(content), null);
    assertEquals(resource.getErrors().toString(), 0, resource.getErrors().size());
    XtendFile xtendFile = (XtendFile) resource.getContents().get(0);
    return xtendFile;
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) StringInputStream(org.eclipse.xtext.util.StringInputStream) IFile(org.eclipse.core.resources.IFile) Resource(org.eclipse.emf.ecore.resource.Resource) IResource(org.eclipse.core.resources.IResource)

Example 78 with Resource

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

the class InsertionOffsetTest method checkMethodInsertionOffset.

protected void checkMethodInsertionOffset(final CharSequence model) {
    try {
        final String modelAsString = model.toString();
        final int caretOffset = modelAsString.replace("$", "").indexOf("|");
        final int expectedOffset = modelAsString.replace("|", "").indexOf("$");
        XtendTypeDeclaration _head = IterableExtensions.<XtendTypeDeclaration>head(this.parseHelper.parse(modelAsString.replace("|", "").replace("$", "")).getXtendTypes());
        final XtendClass xtendClass = ((XtendClass) _head);
        Resource _eResource = xtendClass.eResource();
        final XtextResource xtextResource = ((XtextResource) _eResource);
        final EObject caretElement = this._eObjectAtOffsetHelper.resolveContainedElementAt(xtextResource, caretOffset);
        Assert.assertEquals(expectedOffset, this._insertionOffsets.getNewMethodInsertOffset(caretElement, xtendClass));
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : XtendClass(org.eclipse.xtend.core.xtend.XtendClass) EObject(org.eclipse.emf.ecore.EObject) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource) XtextResource(org.eclipse.xtext.resource.XtextResource)

Example 79 with Resource

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

the class InsertionOffsetTest method checkFieldInsertionOffset.

protected void checkFieldInsertionOffset(final CharSequence model) {
    try {
        final String modelAsString = model.toString();
        final int caretOffset = modelAsString.replace("$", "").indexOf("|");
        final int expectedOffset = modelAsString.replace("|", "").indexOf("$");
        XtendTypeDeclaration _head = IterableExtensions.<XtendTypeDeclaration>head(this.parseHelper.parse(modelAsString.replace("|", "").replace("$", "")).getXtendTypes());
        final XtendClass xtendClass = ((XtendClass) _head);
        Resource _eResource = xtendClass.eResource();
        final XtextResource xtextResource = ((XtextResource) _eResource);
        final EObject caretElement = this._eObjectAtOffsetHelper.resolveContainedElementAt(xtextResource, caretOffset);
        Assert.assertEquals(expectedOffset, this._insertionOffsets.getNewFieldInsertOffset(caretElement, xtendClass));
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : XtendClass(org.eclipse.xtend.core.xtend.XtendClass) EObject(org.eclipse.emf.ecore.EObject) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource) XtextResource(org.eclipse.xtext.resource.XtextResource)

Example 80 with Resource

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

the class ApplyUnapplyProfileAction method execute.

@SuppressWarnings("unchecked")
@Override
public void execute(final Collection<? extends EObject> selections, final Map<String, Object> parameters) {
    final EObject target = ((DSemanticDecorator) selections.iterator().next()).getTarget();
    final Resource targetResource = target.eResource();
    final FeatureEditorDialog profileSelectionDialog = new FeatureEditorDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), LABEL_PROVIDER, target, target.eClass().getEAllStructuralFeatures().get(0).getEType(), ProfileAPI.getAppliedProfiles(targetResource), SELECT_APPLIED_PROFILES_MESSAGE, ProfileAPI.getApplicableProfiles(), false, true, true);
    if (profileSelectionDialog.open() == Dialog.OK) {
        ProfileAPI.updateProfileApplications(targetResource, (EList<Profile>) profileSelectionDialog.getResult());
    }
}
Also used : DSemanticDecorator(org.eclipse.sirius.viewpoint.DSemanticDecorator) FeatureEditorDialog(org.eclipse.emf.edit.ui.celleditor.FeatureEditorDialog) EObject(org.eclipse.emf.ecore.EObject) Resource(org.eclipse.emf.ecore.resource.Resource) Profile(org.modelversioning.emfprofile.Profile)

Aggregations

Resource (org.eclipse.emf.ecore.resource.Resource)448 Test (org.junit.Test)210 XtextResource (org.eclipse.xtext.resource.XtextResource)157 EObject (org.eclipse.emf.ecore.EObject)109 URI (org.eclipse.emf.common.util.URI)85 XtextResourceSet (org.eclipse.xtext.resource.XtextResourceSet)76 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)71 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)66 StringInputStream (org.eclipse.xtext.util.StringInputStream)50 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)45 ResourceSetImpl (org.eclipse.emf.ecore.resource.impl.ResourceSetImpl)36 IOException (java.io.IOException)26 IResourceDescription (org.eclipse.xtext.resource.IResourceDescription)24 List (java.util.List)23 EClass (org.eclipse.emf.ecore.EClass)23 EPackage (org.eclipse.emf.ecore.EPackage)23 InternalEObject (org.eclipse.emf.ecore.InternalEObject)23 DerivedStateAwareResource (org.eclipse.xtext.resource.DerivedStateAwareResource)21 ArrayList (java.util.ArrayList)19 IFile (org.eclipse.core.resources.IFile)18