Search in sources :

Example 16 with Path

use of org.eclipse.xtend.lib.macro.file.Path in project xtext-xtend by eclipse.

the class FileProcessor method doGenerateCode.

@Override
public void doGenerateCode(final ClassDeclaration annotatedClass, @Extension final CodeGenerationContext context) {
    final Path path = annotatedClass.getCompilationUnit().getFilePath();
    final Path result = context.getTargetFolder(path).append("out.txt");
    final String[] segments = context.getContents(context.getProjectFolder(path).append("res/template.txt")).toString().split(",");
    StringConcatenation _builder = new StringConcatenation();
    {
        boolean _hasElements = false;
        for (final String seg : segments) {
            if (!_hasElements) {
                _hasElements = true;
            } else {
                _builder.appendImmediate("|", "");
            }
            _builder.append(seg);
        }
    }
    context.setContents(result, _builder);
}
Also used : Path(org.eclipse.xtend.lib.macro.file.Path) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation)

Example 17 with Path

use of org.eclipse.xtend.lib.macro.file.Path in project xtext-xtend by eclipse.

the class EclipseFileSystemTest method testGetURIForImportedProject.

@Test
public void testGetURIForImportedProject() {
    try {
        final IWorkspace ws = ResourcesPlugin.getWorkspace();
        final IWorkspaceRoot root = ws.getRoot();
        final IProjectDescription description = ws.newProjectDescription("bar");
        description.setLocation(root.getLocation().append("foo/bar"));
        final IProject project = root.getProject("bar");
        project.create(description, null);
        project.open(null);
        final Path file = new Path("/bar/Foo.text");
        Assert.assertFalse(this.fs.exists(file));
        Assert.assertNull(this.fs.toURI(file));
        try {
            this.fs.setContents(file, "Hello Foo");
            Assert.fail();
        } catch (final Throwable _t) {
            if (_t instanceof IllegalArgumentException) {
            } else {
                throw Exceptions.sneakyThrow(_t);
            }
        }
        Assert.assertFalse(this.fs.exists(file));
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : Path(org.eclipse.xtend.lib.macro.file.Path) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IWorkspace(org.eclipse.core.resources.IWorkspace) IProjectDescription(org.eclipse.core.resources.IProjectDescription) IProject(org.eclipse.core.resources.IProject) Test(org.junit.Test) JavaIoFileSystemTest(org.eclipse.xtend.ide.tests.macros.JavaIoFileSystemTest)

Example 18 with Path

use of org.eclipse.xtend.lib.macro.file.Path in project xtext-xtend by eclipse.

the class JavaIoFileSystemTest method createProject.

protected Object createProject(final String name) {
    URI _uRI = this.fs.toURI(new Path(name));
    final File file = new File(_uRI);
    file.mkdirs();
    return file;
}
Also used : Path(org.eclipse.xtend.lib.macro.file.Path) URI(java.net.URI) File(java.io.File)

Example 19 with Path

use of org.eclipse.xtend.lib.macro.file.Path in project xtext-xtend by eclipse.

the class JavaIoFileSystemTest method testGetFileChildren.

@Test
public void testGetFileChildren() {
    final Path file = new Path("/foo/bar/Foo.text");
    Assert.assertFalse(this.fs.exists(file));
    Assert.assertEquals(0, IterableExtensions.size(this.fs.getChildren(file)));
    this.fs.setContents(file, "Hello Foo");
    Assert.assertTrue(this.fs.exists(file));
    Assert.assertEquals(0, IterableExtensions.size(this.fs.getChildren(file)));
}
Also used : Path(org.eclipse.xtend.lib.macro.file.Path) Test(org.junit.Test)

Example 20 with Path

use of org.eclipse.xtend.lib.macro.file.Path in project xtext-xtend by eclipse.

the class JavaIoFileSystemTest method testModificationStamp_02.

@Test
public void testModificationStamp_02() {
    try {
        final Path path = new Path("/foo/src/my/pack/Foo.txt");
        Assert.assertEquals(0L, this.fs.getLastModification(path));
        this.fs.setContents(path, "Hello Foo");
        final long mod = this.fs.getLastModification(path);
        Assert.assertEquals("Hello Foo", this.fs.getContents(path));
        Assert.assertEquals(mod, this.fs.getLastModification(path));
        Thread.sleep(1000);
        this.fs.setContents(path, "Hello Bar");
        long _lastModification = this.fs.getLastModification(path);
        boolean _lessThan = (mod < _lastModification);
        Assert.assertTrue(_lessThan);
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : Path(org.eclipse.xtend.lib.macro.file.Path) Test(org.junit.Test)

Aggregations

Path (org.eclipse.xtend.lib.macro.file.Path)42 Test (org.junit.Test)31 File (java.io.File)3 URI (java.net.URI)2 IProject (org.eclipse.core.resources.IProject)2 URI (org.eclipse.emf.common.util.URI)2 JavaIoFileSystemTest (org.eclipse.xtend.ide.tests.macros.JavaIoFileSystemTest)2 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)2 List (java.util.List)1 IProjectDescription (org.eclipse.core.resources.IProjectDescription)1 IWorkspace (org.eclipse.core.resources.IWorkspace)1 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)1 Resource (org.eclipse.emf.ecore.resource.Resource)1 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)1 AbstractFileSystemSupport (org.eclipse.xtend.core.macro.AbstractFileSystemSupport)1 ChangeListenerAddingFileSystemSupport (org.eclipse.xtend.core.macro.declaration.ChangeListenerAddingFileSystemSupport)1 UIResourceChangeRegistry (org.eclipse.xtend.ide.builder.UIResourceChangeRegistry)1 MutableFieldDeclaration (org.eclipse.xtend.lib.macro.declaration.MutableFieldDeclaration)1 OutputConfiguration (org.eclipse.xtext.generator.OutputConfiguration)1 Before (org.junit.Before)1