Search in sources :

Example 61 with ResourceSet

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

the class JavaIoFileSystemTest method setUp.

@Before
public void setUp() {
    try {
        final File tempDir = this.temporaryFolder.newFolder();
        JavaIOFileSystemSupport _javaIOFileSystemSupport = new JavaIOFileSystemSupport();
        final Procedure1<JavaIOFileSystemSupport> _function = (JavaIOFileSystemSupport it) -> {
            final IProjectConfigProvider _function_1 = (ResourceSet it_1) -> {
                File _file = new File(tempDir, "foo");
                FileProjectConfig _fileProjectConfig = new FileProjectConfig(_file);
                final Procedure1<FileProjectConfig> _function_2 = (FileProjectConfig it_2) -> {
                    it_2.addSourceFolder("src");
                };
                return ObjectExtensions.<FileProjectConfig>operator_doubleArrow(_fileProjectConfig, _function_2);
            };
            it.setProjectConfigProvider(_function_1);
            IEncodingProvider.Runtime _runtime = new IEncodingProvider.Runtime();
            it.setEncodingProvider(_runtime);
            XtextResourceSet _xtextResourceSet = new XtextResourceSet();
            it.setContext(_xtextResourceSet);
        };
        JavaIOFileSystemSupport _doubleArrow = ObjectExtensions.<JavaIOFileSystemSupport>operator_doubleArrow(_javaIOFileSystemSupport, _function);
        this.fs = _doubleArrow;
        this.createProject("foo");
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : JavaIOFileSystemSupport(org.eclipse.xtend.core.macro.JavaIOFileSystemSupport) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) IEncodingProvider(org.eclipse.xtext.parser.IEncodingProvider) IProjectConfigProvider(org.eclipse.xtext.workspace.IProjectConfigProvider) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) FileProjectConfig(org.eclipse.xtext.workspace.FileProjectConfig) File(java.io.File) Before(org.junit.Before)

Example 62 with ResourceSet

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

the class AccessRestrictionInWorkspaceTest method parse.

public XtendFile parse(final IFile file) {
    final ResourceSet resourceSet = this._iResourceSetProvider.get(file.getProject());
    final URI uri = URI.createPlatformResourceURI(file.getFullPath().toString(), true);
    final Resource resource = resourceSet.getResource(uri, true);
    EObject _head = IterableExtensions.<EObject>head(resource.getContents());
    return ((XtendFile) _head);
}
Also used : 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 63 with ResourceSet

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

the class ResourceStorageTest method testShouldLoadFromStorage.

@Test
public void testShouldLoadFromStorage() {
    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("mypack/MyClass.xtend", _builder.toString());
        IResourcesSetupUtil.waitForBuild();
        final URI uri = this.uriMapper.getUri(file);
        final ResourceSet resourceSet = this.resourceSetProvider.get(file.getProject());
        SourceLevelURIsAdapter.setSourceLevelUris(resourceSet, Collections.<URI>unmodifiableList(CollectionLiterals.<URI>newArrayList()));
        Resource _createResource = resourceSet.createResource(uri);
        final StorageAwareResource resource = ((StorageAwareResource) _createResource);
        final Procedure0 _function = () -> {
            Assert.assertTrue(resource.getResourceStorageFacade().shouldLoadFromStorage(resource));
        };
        this.doWorkInJob(_function);
        NullProgressMonitor _nullProgressMonitor = new NullProgressMonitor();
        file.delete(true, _nullProgressMonitor);
        IResourcesSetupUtil.waitForBuild();
        final Procedure0 _function_1 = () -> {
            Assert.assertFalse(resource.getResourceStorageFacade().shouldLoadFromStorage(resource));
        };
        this.doWorkInJob(_function_1);
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFile(org.eclipse.core.resources.IFile) Procedure0(org.eclipse.xtext.xbase.lib.Procedures.Procedure0) 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) Test(org.junit.Test)

Example 64 with ResourceSet

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

the class Declarators method getDeclaratorData.

public Declarators.DeclaratorsData getDeclaratorData(final TargetURIs targetURIs, final IReferenceFinder.IResourceAccess resourceAccess) {
    Declarators.DeclaratorsData result = targetURIs.<Declarators.DeclaratorsData>getUserData(Declarators.KEY);
    if ((result != null)) {
        return result;
    }
    final HashSet<QualifiedName> declaratorNames = CollectionLiterals.<QualifiedName>newHashSet();
    final Consumer<URI> _function = (URI uri) -> {
        final IUnitOfWork<Object, ResourceSet> _function_1 = (ResourceSet it) -> {
            Object _xblockexpression = null;
            {
                final Consumer<URI> _function_2 = (URI objectURI) -> {
                    final EObject object = it.getEObject(objectURI, true);
                    if ((object != null)) {
                        final JvmType type = EcoreUtil2.<JvmType>getContainerOfType(object, JvmType.class);
                        if ((type != null)) {
                            QualifiedName _lowerCase = this.nameConverter.toQualifiedName(type.getIdentifier()).toLowerCase();
                            declaratorNames.add(_lowerCase);
                            QualifiedName _lowerCase_1 = this.nameConverter.toQualifiedName(type.getQualifiedName('.')).toLowerCase();
                            declaratorNames.add(_lowerCase_1);
                        }
                    }
                };
                targetURIs.getEObjectURIs(uri).forEach(_function_2);
                _xblockexpression = null;
            }
            return _xblockexpression;
        };
        resourceAccess.<Object>readOnly(uri, _function_1);
    };
    targetURIs.getTargetResourceURIs().forEach(_function);
    Declarators.DeclaratorsData _declaratorsData = new Declarators.DeclaratorsData(declaratorNames);
    result = _declaratorsData;
    targetURIs.<Declarators.DeclaratorsData>putUserData(Declarators.KEY, result);
    return result;
}
Also used : QualifiedName(org.eclipse.xtext.naming.QualifiedName) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) JvmType(org.eclipse.xtext.common.types.JvmType) URI(org.eclipse.emf.common.util.URI) IUnitOfWork(org.eclipse.xtext.util.concurrent.IUnitOfWork) Consumer(java.util.function.Consumer) EObject(org.eclipse.emf.ecore.EObject) EObject(org.eclipse.emf.ecore.EObject)

Example 65 with ResourceSet

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

the class XtendBatchCompiler method configureWorkspace.

private boolean configureWorkspace(ResourceSet resourceSet) {
    List<File> sourceFileList = getSourcePathFileList();
    File outputFile = getOutputPathFile();
    if (sourceFileList == null || outputFile == null) {
        return false;
    }
    File commonRoot = determineCommonRoot(outputFile, sourceFileList);
    // We don't want to use root ("/") as a workspace folder, didn't we?
    if (commonRoot == null || commonRoot.getParent() == null || commonRoot.getParentFile().getParent() == null) {
        log.error("All source folders and the output folder should have " + "a common parent non-top level folder (like project folder)");
        for (File sourceFile : sourceFileList) {
            log.error("(Source folder: '" + sourceFile + "')");
        }
        log.error("(Output folder: '" + outputFile + "')");
        return false;
    }
    projectConfig = new FileProjectConfig(commonRoot, commonRoot.getName());
    java.net.URI commonURI = commonRoot.toURI();
    java.net.URI relativizedTarget = commonURI.relativize(outputFile.toURI());
    if (relativizedTarget.isAbsolute()) {
        log.error("Target folder '" + outputFile + "' must be a child of the project folder '" + commonRoot + "'");
        return false;
    }
    CharMatcher slash = CharMatcher.is('/');
    String relativeTargetFolder = slash.trimTrailingFrom(relativizedTarget.getPath());
    outputConfiguration = Iterables.getOnlyElement(outputConfigurationProvider.getOutputConfigurations());
    outputConfiguration.setOutputDirectory(relativeTargetFolder);
    for (File source : sourceFileList) {
        java.net.URI relativizedSrc = commonURI.relativize(source.toURI());
        if (relativizedSrc.isAbsolute()) {
            log.error("Source folder '" + source + "' must be a child of the project folder '" + commonRoot + "'");
            return false;
        }
        projectConfig.addSourceFolder(slash.trimTrailingFrom(relativizedSrc.getPath()));
    }
    Map<String, Set<OutputConfiguration>> outputConfigurations = newHashMap();
    outputConfigurations.put(languageName, newHashSet(outputConfiguration));
    ProjectConfigAdapter.install(resourceSet, projectConfig);
    resourceSet.eAdapters().add(new OutputConfigurationAdapter(outputConfigurations));
    return true;
}
Also used : Set(java.util.Set) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) CharMatcher(com.google.common.base.CharMatcher) FileProjectConfig(org.eclipse.xtext.workspace.FileProjectConfig) OutputConfigurationAdapter(org.eclipse.xtext.generator.OutputConfigurationAdapter) XtendFile(org.eclipse.xtend.core.xtend.XtendFile) File(java.io.File)

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