Java Code Examples for org.eclipse.xtend.lib.macro.file.Path#append()

The following examples show how to use org.eclipse.xtend.lib.macro.file.Path#append() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JavaIoFileSystemTest.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testMakeAndDeleteFolder() {
  final Path someFolder = new Path("/foo/bar");
  final Path someFile = someFolder.append("Foo.txt");
  Assert.assertFalse(this.fs.exists(someFolder));
  Assert.assertFalse(this.fs.isFile(someFolder));
  Assert.assertFalse(this.fs.isFolder(someFolder));
  this.fs.setContents(someFile, "Hello Foo");
  Assert.assertFalse(this.fs.isFile(someFolder));
  Assert.assertTrue(this.fs.isFolder(someFolder));
  Assert.assertTrue(this.fs.exists(someFolder));
  this.fs.delete(someFolder);
  Assert.assertTrue(this.fs.exists(someFolder));
  this.fs.delete(someFile);
  this.fs.delete(someFolder);
  Assert.assertFalse(this.fs.exists(someFolder));
}
 
Example 2
Source File: ExternalizedProcessor.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void doGenerateCode(final List<? extends ClassDeclaration> annotatedSourceElements, @Extension final CodeGenerationContext context) {
  for (final ClassDeclaration clazz : annotatedSourceElements) {
    {
      final Path filePath = clazz.getCompilationUnit().getFilePath();
      Path _targetFolder = context.getTargetFolder(filePath);
      String _replace = clazz.getQualifiedName().replace(".", "/");
      String _plus = (_replace + ".properties");
      final Path file = _targetFolder.append(_plus);
      StringConcatenation _builder = new StringConcatenation();
      {
        Iterable<? extends FieldDeclaration> _declaredFields = clazz.getDeclaredFields();
        for(final FieldDeclaration field : _declaredFields) {
          String _simpleName = field.getSimpleName();
          _builder.append(_simpleName);
          _builder.append(" = ");
          String _initializerAsString = this.getInitializerAsString(field);
          _builder.append(_initializerAsString);
          _builder.newLineIfNotEmpty();
        }
      }
      context.setContents(file, _builder);
    }
  }
}
 
Example 3
Source File: JavaIoFileSystemTest.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testMakeAndDeleteFolder() {
  final Path someFolder = new Path("/foo/bar");
  final Path someFile = someFolder.append("Foo.txt");
  Assert.assertFalse(this.fs.exists(someFolder));
  Assert.assertFalse(this.fs.isFile(someFolder));
  Assert.assertFalse(this.fs.isFolder(someFolder));
  this.fs.setContents(someFile, "Hello Foo");
  Assert.assertFalse(this.fs.isFile(someFolder));
  Assert.assertTrue(this.fs.isFolder(someFolder));
  Assert.assertTrue(this.fs.exists(someFolder));
  this.fs.delete(someFolder);
  Assert.assertTrue(this.fs.exists(someFolder));
  this.fs.delete(someFile);
  this.fs.delete(someFolder);
  Assert.assertFalse(this.fs.exists(someFolder));
}
 
Example 4
Source File: FileLocationsImpl.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public Path getTargetFolder(final Path path) {
  Path _xblockexpression = null;
  {
    final Path projectFolder = this.getProjectFolder(path);
    if ((projectFolder == null)) {
      return null;
    }
    final OutputConfiguration outputConfiguration = IterableExtensions.<OutputConfiguration>head(this.outputConfigurationProvider.getOutputConfigurations(this.context));
    final Path sourceFolder = this.getSourceFolder(path);
    String _xifexpression = null;
    if ((sourceFolder == null)) {
      _xifexpression = outputConfiguration.getOutputDirectory();
    } else {
      String _xblockexpression_1 = null;
      {
        final String projectRelativeSourceFolder = IterableExtensions.join(IterableExtensions.<String>tail(sourceFolder.getSegments()), "/");
        _xblockexpression_1 = outputConfiguration.getOutputDirectory(projectRelativeSourceFolder);
      }
      _xifexpression = _xblockexpression_1;
    }
    final String outputFolder = _xifexpression;
    _xblockexpression = projectFolder.append(outputFolder);
  }
  return _xblockexpression;
}
 
Example 5
Source File: JavaIoFileSystemTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testGetFolderChildren() {
  final Path folder = new Path("/foo/bar");
  Assert.assertFalse(this.fs.exists(folder));
  Path _append = folder.append("Bar.txt");
  this.fs.setContents(_append, "Hello Bar");
  Assert.assertTrue(this.fs.exists(folder));
  Assert.assertEquals(1, IterableExtensions.size(this.fs.getChildren(folder)));
  Path _path = new Path("/foo/bar/Foo.text");
  this.fs.setContents(_path, "Hello Foo");
  Assert.assertEquals(2, IterableExtensions.size(this.fs.getChildren(folder)));
}
 
Example 6
Source File: JavaIoFileSystemTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testGetFolderURI() {
  final Path path = new Path("/foo/bar");
  Assert.assertFalse(this.fs.exists(path));
  Assert.assertNotNull(this.fs.toURI(path));
  Path _append = path.append("Foo.txt");
  this.fs.setContents(_append, "Hello Foo");
  Assert.assertTrue(this.fs.exists(path));
  Assert.assertNotNull(this.fs.toURI(path));
}
 
Example 7
Source File: ExternalizedTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testExtractAnnotation() {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("package i18n");
  _builder.newLine();
  _builder.newLine();
  _builder.append("@Externalized");
  _builder.newLine();
  _builder.append("class MyMessages {");
  _builder.newLine();
  _builder.append("\t");
  _builder.append("val GREETING = \"Hello {0}\"");
  _builder.newLine();
  _builder.append("\t");
  _builder.append("val DATE_MESSAGE = \"Today, is ${0,date}.\"");
  _builder.newLine();
  _builder.append("}");
  _builder.newLine();
  final IAcceptor<XtendCompilerTester.CompilationResult> _function = (XtendCompilerTester.CompilationResult it) -> {
    @Extension
    final TransformationContext ctx = it.getTransformationContext();
    final MutableClassDeclaration clazz = ctx.findClass("i18n.MyMessages");
    Assert.assertEquals(2, IterableExtensions.size(clazz.getDeclaredMethods()));
    final Path path = it.getCompilationUnit().getFilePath();
    Path _targetFolder = ctx.getTargetFolder(path);
    String _replace = clazz.getQualifiedName().replace(".", "/");
    String _plus = (_replace + ".properties");
    final Path properties = _targetFolder.append(_plus);
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("GREETING = Hello {0}");
    _builder_1.newLine();
    _builder_1.append("DATE_MESSAGE = Today, is ${0,date}.");
    _builder_1.newLine();
    Assert.assertEquals(_builder_1.toString(), ctx.getContents(properties).toString());
  };
  this.compilerTester.compile(_builder, _function);
}
 
Example 8
Source File: JavaIoFileSystemTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testGetFolderChildren() {
  final Path folder = new Path("/foo/bar");
  Assert.assertFalse(this.fs.exists(folder));
  Path _append = folder.append("Bar.txt");
  this.fs.setContents(_append, "Hello Bar");
  Assert.assertTrue(this.fs.exists(folder));
  Assert.assertEquals(1, IterableExtensions.size(this.fs.getChildren(folder)));
  Path _path = new Path("/foo/bar/Foo.text");
  this.fs.setContents(_path, "Hello Foo");
  Assert.assertEquals(2, IterableExtensions.size(this.fs.getChildren(folder)));
}
 
Example 9
Source File: JavaIoFileSystemTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testGetFolderURI() {
  final Path path = new Path("/foo/bar");
  Assert.assertFalse(this.fs.exists(path));
  Assert.assertNotNull(this.fs.toURI(path));
  Path _append = path.append("Foo.txt");
  this.fs.setContents(_append, "Hello Foo");
  Assert.assertTrue(this.fs.exists(path));
  Assert.assertNotNull(this.fs.toURI(path));
}
 
Example 10
Source File: _TESTDATA_InternalClassProcessor.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void doGenerateCode(final ClassDeclaration annotatedClass, @Extension final CodeGenerationContext context) {
  final Path tF = context.getTargetFolder(annotatedClass.getCompilationUnit().getFilePath());
  Path _append = tF.append("/Test.txt");
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("Hello");
  _builder.newLine();
  context.setContents(_append, _builder);
}