Search in sources :

Example 26 with ResourceSet

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

the class XtendFileRenameParticipant method createRenameElementContexts.

@Override
protected List<? extends IRenameElementContext> createRenameElementContexts(Object element) {
    if (super.getNewName().endsWith(".xtend")) {
        IFile file = (IFile) element;
        final IPath filePath = file.getFullPath();
        final IPath newPath = file.getFullPath().removeLastSegments(1).append(getNewName() + ".xtend");
        String className = trimFileExtension(file.getName());
        if (className != null) {
            ResourceSet resourceSet = resourceSetProvider.get(file.getProject());
            URI resourceURI = URI.createPlatformResourceURI(file.getFullPath().toString(), true);
            Resource resource = resourceSet.getResource(resourceURI, true);
            if (resource != null && !resource.getContents().isEmpty()) {
                for (XtendTypeDeclaration type : EcoreUtil2.eAllOfType(resource.getContents().get(0), XtendTypeDeclaration.class)) {
                    if (equal(className, type.getName())) {
                        IRenameElementContext renameElementContext = renameContextFactory.createRenameElementContext(type, null, null, (XtextResource) resource);
                        if (renameElementContext instanceof IChangeRedirector.Aware)
                            ((IChangeRedirector.Aware) renameElementContext).setChangeRedirector(new IChangeRedirector() {

                                @Override
                                public IPath getRedirectedPath(IPath source) {
                                    return source.equals(filePath) ? newPath : source;
                                }
                            });
                        return singletonList(renameElementContext);
                    }
                }
            }
        }
    }
    return super.createRenameElementContexts(element);
}
Also used : IFile(org.eclipse.core.resources.IFile) IChangeRedirector(org.eclipse.xtext.ui.refactoring.IChangeRedirector) IPath(org.eclipse.core.runtime.IPath) XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) IRenameElementContext(org.eclipse.xtext.ui.refactoring.ui.IRenameElementContext) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) URI(org.eclipse.emf.common.util.URI)

Example 27 with ResourceSet

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

the class MavenProjectResourceSetProvider method get.

public ResourceSet get() {
    ResourceSet rs = new XtextResourceSet();
    MavenProjectAdapter.install(rs, project);
    return rs;
}
Also used : XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet)

Example 28 with ResourceSet

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

the class ActiveAnnotationsProcessingInIDETest method assertProcessing.

@Override
public void assertProcessing(final Pair<String, String> macroContent, final Pair<String, String> clientContent, final Procedure1<? super CompilationUnitImpl> expectations) {
    try {
        this.macroFile = this.newSource(ActiveAnnotationsProcessingInIDETest.macroProject, macroContent.getKey(), macroContent.getValue().toString());
        final int lidx = macroContent.getKey().lastIndexOf("/");
        if ((lidx != (-1))) {
            this.exportedPackage = macroContent.getKey().substring(0, lidx).replace("/", ".");
            boolean _addExportedPackages = WorkbenchTestHelper.addExportedPackages(ActiveAnnotationsProcessingInIDETest.macroProject.getProject(), this.exportedPackage);
            if (_addExportedPackages) {
                IResourcesSetupUtil.reallyWaitForAutoBuild();
            }
        }
        this.clientFile = this.newSource(ActiveAnnotationsProcessingInIDETest.userProject, clientContent.getKey(), clientContent.getValue().toString());
        IResourcesSetupUtil.waitForBuild();
        final ResourceSet resourceSet = this.resourceSetProvider.get(ActiveAnnotationsProcessingInIDETest.userProject.getProject());
        final Resource resource = resourceSet.getResource(URI.createPlatformResourceURI(this.clientFile.getFullPath().toString(), true), true);
        EcoreUtil2.resolveLazyCrossReferences(resource, CancelIndicator.NullImpl);
        this.validator.validate(resource, CheckMode.FAST_ONLY, CancelIndicator.NullImpl);
        final CompilationUnitImpl unit = this.compilationUnitProvider.get();
        unit.setXtendFile(IterableExtensions.<XtendFile>head(Iterables.<XtendFile>filter(resource.getContents(), XtendFile.class)));
        expectations.apply(unit);
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) CompilationUnitImpl(org.eclipse.xtend.core.macro.declaration.CompilationUnitImpl) Resource(org.eclipse.emf.ecore.resource.Resource) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet)

Example 29 with ResourceSet

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

the class ResourceStorageTest method testUpstreamResourcesAreLoadedFromStorage.

@Test
public void testUpstreamResourcesAreLoadedFromStorage() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("package mypack");
        _builder.newLine();
        _builder.newLine();
        _builder.append("class MyClass {");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        this.helper.createFile("mypack/MyClass.xtend", _builder.toString());
        final IProject downStreamProject = WorkbenchTestHelper.createPluginProject("downstream", this.helper.getProject().getName());
        StringConcatenation _builder_1 = new StringConcatenation();
        _builder_1.append("package downstream");
        _builder_1.newLine();
        _builder_1.newLine();
        _builder_1.append("class SomeClass {");
        _builder_1.newLine();
        _builder_1.append("\t");
        _builder_1.newLine();
        _builder_1.append("\t");
        _builder_1.append("def void foo(mypack.MyClass myClass) {");
        _builder_1.newLine();
        _builder_1.append("\t");
        _builder_1.append("}");
        _builder_1.newLine();
        _builder_1.append("}");
        _builder_1.newLine();
        final IFile downstreamFile = this.helper.createFileImpl("/downstream/src/downstream/SomeClass.xtend", _builder_1.toString());
        IResourcesSetupUtil.waitForBuild();
        final URI downstreamUri = this.uriMapper.getUri(downstreamFile);
        final ResourceSet resourceSet = this.resourceSetProvider.get(downStreamProject);
        SourceLevelURIsAdapter.setSourceLevelUris(resourceSet, Collections.<URI>unmodifiableList(CollectionLiterals.<URI>newArrayList(downstreamUri)));
        Resource _resource = resourceSet.getResource(downstreamUri, true);
        final StorageAwareResource downstreamResource = ((StorageAwareResource) _resource);
        EObject _get = downstreamResource.getContents().get(1);
        final JvmGenericType type = ((JvmGenericType) _get);
        final JvmType parameterType = IterableExtensions.<JvmFormalParameter>head(IterableExtensions.<JvmOperation>head(Iterables.<JvmOperation>filter(type.getMembers(), JvmOperation.class)).getParameters()).getParameterType().getType();
        Assert.assertNotNull(parameterType);
        Resource _eResource = parameterType.eResource();
        Assert.assertTrue(((StorageAwareResource) _eResource).isLoadedFromStorage());
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) Resource(org.eclipse.emf.ecore.resource.Resource) StorageAwareResource(org.eclipse.xtext.resource.persistence.StorageAwareResource) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) StorageAwareResource(org.eclipse.xtext.resource.persistence.StorageAwareResource) JvmType(org.eclipse.xtext.common.types.JvmType) URI(org.eclipse.emf.common.util.URI) AbsoluteURI(org.eclipse.xtext.generator.trace.AbsoluteURI) SourceRelativeURI(org.eclipse.xtext.generator.trace.SourceRelativeURI) IProject(org.eclipse.core.resources.IProject) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) JvmFormalParameter(org.eclipse.xtext.common.types.JvmFormalParameter) EObject(org.eclipse.emf.ecore.EObject) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Test(org.junit.Test)

Example 30 with ResourceSet

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

the class ResourceStorageTest method testLoadFromStorage.

@Test
public void testLoadFromStorage() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("package mypack");
        _builder.newLine();
        _builder.newLine();
        _builder.append("class MyClass {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("public def void foo() {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final IFile file = this.helper.createFile("src/mypack/MyClass.xtend", _builder.toString());
        StringConcatenation _builder_1 = new StringConcatenation();
        _builder_1.append("package mypack");
        _builder_1.newLine();
        _builder_1.newLine();
        _builder_1.append("class OtherClass extends MyClass {");
        _builder_1.newLine();
        _builder_1.append("\t");
        _builder_1.append("override foo() {");
        _builder_1.newLine();
        _builder_1.append("\t");
        _builder_1.append("}");
        _builder_1.newLine();
        _builder_1.append("}");
        _builder_1.newLine();
        final IFile file2 = this.helper.createFile("src/mypack/OtherClass.xtend", _builder_1.toString());
        IResourcesSetupUtil.waitForBuild();
        final URI uri = this.uriMapper.getUri(file);
        final URI uri2 = this.uriMapper.getUri(file2);
        final ResourceSet resourceSet = this.resourceSetProvider.get(file.getProject());
        SourceLevelURIsAdapter.setSourceLevelUris(resourceSet, Collections.<URI>unmodifiableList(CollectionLiterals.<URI>newArrayList()));
        Resource _resource = resourceSet.getResource(uri2, true);
        final StorageAwareResource resource2 = ((StorageAwareResource) _resource);
        Assert.assertTrue(resource2.isLoadedFromStorage());
        EcoreUtil.resolveAll(resource2);
        final Function1<IEObjectDescription, String> _function = (IEObjectDescription it) -> {
            return it.getName().toString();
        };
        Assert.assertEquals("mypack.OtherClass", IterableExtensions.join(IterableExtensions.<IEObjectDescription, String>map(resource2.getResourceDescription().getExportedObjects(), _function), ","));
        Resource _resource_1 = resourceSet.getResource(uri, false);
        final StorageAwareResource resource = ((StorageAwareResource) _resource_1);
        Assert.assertTrue(resource.isLoadedFromStorage());
        final Function1<IEObjectDescription, String> _function_1 = (IEObjectDescription it) -> {
            return it.getName().toString();
        };
        Assert.assertEquals("mypack.MyClass", IterableExtensions.join(IterableExtensions.<IEObjectDescription, String>map(resource.getResourceDescription().getExportedObjects(), _function_1), ","));
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Resource(org.eclipse.emf.ecore.resource.Resource) StorageAwareResource(org.eclipse.xtext.resource.persistence.StorageAwareResource) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) StorageAwareResource(org.eclipse.xtext.resource.persistence.StorageAwareResource) URI(org.eclipse.emf.common.util.URI) AbsoluteURI(org.eclipse.xtext.generator.trace.AbsoluteURI) SourceRelativeURI(org.eclipse.xtext.generator.trace.SourceRelativeURI) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription) 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