org.eclipse.xtend.lib.macro.file.Path Java Examples

The following examples show how to use org.eclipse.xtend.lib.macro.file.Path. 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: FileProcessor.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@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);
}
 
Example #2
Source File: EclipseFileSystemTest.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testIssue383() {
  if ((this.fs instanceof AbstractFileSystemSupport)) {
    final AbstractFileSystemSupport afs = ((AbstractFileSystemSupport)this.fs);
    final IProject px = this.createProject("px");
    this.createProject("py");
    final ResourceSet rs = this.resourceSetProvider.get(px);
    final Resource rx = rs.createResource(URI.createPlatformResourceURI("px/foo/xxxx", true));
    final Resource rxb = rs.createResource(URI.createPlatformResourceURI("px/bar/yyyy", true));
    final Resource ry = rs.createResource(URI.createPlatformResourceURI("py/bar/xxxx", true));
    Path pathx = afs.getPath(rx);
    Assert.assertEquals("/px/foo/xxxx", pathx.toString());
    Path pathxb = afs.getPath(rxb);
    Assert.assertEquals("/px/bar/yyyy", pathxb.toString());
    Path pathy = afs.getPath(ry);
    Assert.assertEquals("/py/bar/xxxx", pathy.toString());
  } else {
    Assert.fail("fs is no AbstractFileSystemSupport");
  }
}
 
Example #3
Source File: JavaIoFileSystemTest.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@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);
  }
}
 
Example #4
Source File: JavaIoFileSystemTest.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@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);
  }
}
 
Example #5
Source File: PathTest.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testPathStartsWith() {
  Path _path = new Path("/foo/bar/baz.txt");
  Path _path_1 = new Path("/");
  Assert.assertTrue(_path.startsWith(_path_1));
  Path _path_2 = new Path("/foo/bar/baz.txt");
  Path _path_3 = new Path("/foo");
  Assert.assertTrue(_path_2.startsWith(_path_3));
  Path _path_4 = new Path("/foo/bar/baz.txt");
  Path _path_5 = new Path("/foo/bar");
  Assert.assertTrue(_path_4.startsWith(_path_5));
  Path _path_6 = new Path("/foo/bar/baz.txt");
  Path _path_7 = new Path("/foo/bar/baz.txt");
  Assert.assertTrue(_path_6.startsWith(_path_7));
  Path _path_8 = new Path("/foo/bar/baz.txt");
  Path _path_9 = new Path("foo");
  Assert.assertFalse(_path_8.startsWith(_path_9));
  Path _path_10 = new Path("/foo/bar/baz.txt");
  Path _path_11 = new Path("foo/bar/baz.txt");
  Assert.assertFalse(_path_10.startsWith(_path_11));
  Path _path_12 = new Path("/foo/bar/baz.txt");
  Path _path_13 = new Path("/foo/bar/baz");
  Assert.assertFalse(_path_12.startsWith(_path_13));
}
 
Example #6
Source File: JavaIoFileSystemTest.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testModificationStamp_01() {
  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 Foo");
    Assert.assertEquals(mod, this.fs.getLastModification(path));
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example #7
Source File: EclipseFileSystemSupportImpl.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public Iterable<? extends Path> getChildren(final URI uri, final Path path) {
  final IResource resource = this.findMember(uri);
  if ((resource instanceof IContainer)) {
    try {
      final Function1<IResource, Path> _function = (IResource it) -> {
        String _string = it.getFullPath().toString();
        return new Path(_string);
      };
      return ListExtensions.<IResource, Path>map(((List<IResource>)Conversions.doWrapArray(((IContainer)resource).members())), _function);
    } catch (final Throwable _t) {
      if (_t instanceof CoreException) {
        final CoreException exc = (CoreException)_t;
        String _message = exc.getMessage();
        throw new IllegalArgumentException(_message, exc);
      } else {
        throw Exceptions.sneakyThrow(_t);
      }
    }
  }
  return CollectionLiterals.<Path>emptyList();
}
 
Example #8
Source File: AbstractFileSystemSupport.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void setContentsAsStream(final Path path, final InputStream source) {
  final URI uri = this.getURI(path);
  if ((uri == null)) {
    throw new IllegalArgumentException(("The file cannot be found: " + path));
  }
  try {
    if ((this.exists(uri) && this.isFile(uri))) {
      boolean _markSupported = source.markSupported();
      if (_markSupported) {
        boolean _hasContentsChanged = this.hasContentsChanged(source, this.getContentsAsStream(path));
        boolean _not = (!_hasContentsChanged);
        if (_not) {
          return;
        }
        source.reset();
      }
    }
    final OutputStream out = this.getURIConverter().createOutputStream(uri);
    try {
      ByteStreams.copy(source, out);
    } finally {
      out.close();
    }
  } catch (final Throwable _t) {
    if (_t instanceof IOException) {
      final IOException exc = (IOException)_t;
      String _message = exc.getMessage();
      throw new IllegalArgumentException(_message, exc);
    } else {
      throw Exceptions.sneakyThrow(_t);
    }
  }
}
 
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: ParallelFileSystemSupport.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void setContents(final Path path, final CharSequence contents) {
  final Runnable _function = () -> {
    this.delegate.setContents(path, contents);
  };
  this.queue.sendAsync(this.uri, _function);
}
 
Example #11
Source File: JavaIoFileSystemTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testGetProjectChildren() {
  final Path projectFolder = new Path("/foo");
  Assert.assertTrue(this.fs.exists(projectFolder));
  int _size = IterableExtensions.size(this.fs.getChildren(projectFolder));
  final int expectedChildrenSize = (_size + 1);
  Path _path = new Path("/foo/Foo.text");
  this.fs.setContents(_path, "Hello Foo");
  Iterable<? extends Path> _children = this.fs.getChildren(projectFolder);
  String _plus = ("" + _children);
  Assert.assertEquals(_plus, expectedChildrenSize, 
    IterableExtensions.size(this.fs.getChildren(projectFolder)));
}
 
Example #12
Source File: AbstractFileSystemSupport.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void setContents(final Path path, final CharSequence contents) {
  final URI uri = this.getURI(path);
  if ((uri == null)) {
    throw new IllegalArgumentException(("The file cannot be found: " + path));
  }
  CharSequence _elvis = null;
  CharSequence _postProcess = null;
  if (this.postProcessor!=null) {
    _postProcess=this.postProcessor.postProcess(uri, contents);
  }
  if (_postProcess != null) {
    _elvis = _postProcess;
  } else {
    _elvis = contents;
  }
  final CharSequence processedContents = _elvis;
  try {
    String _string = processedContents.toString();
    String _charset = this.getCharset(path);
    StringInputStream _stringInputStream = new StringInputStream(_string, _charset);
    this.setContentsAsStream(path, _stringInputStream);
  } catch (final Throwable _t) {
    if (_t instanceof UnsupportedEncodingException) {
      final UnsupportedEncodingException exc = (UnsupportedEncodingException)_t;
      String _message = exc.getMessage();
      throw new IllegalArgumentException(_message, exc);
    } else {
      throw Exceptions.sneakyThrow(_t);
    }
  }
}
 
Example #13
Source File: PathTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testPathConstructor() {
  Assert.assertEquals("/foo/bar/baz.txt", new Path("/foo/bar/baz.txt").toString());
  Assert.assertEquals("/foo/bar/baz.txt", new Path("/foo////bar/   baz.txt").toString());
  Assert.assertEquals("foo/bar/baz.txt", new Path("foo/bar/baz.txt").toString());
  Assert.assertEquals("foo/bar/baz.txt", new Path("    foo   /bar/baz.txt").toString());
  Assert.assertEquals("/bar/baz.txt", new Path("/foo/../bar/baz.txt").toString());
  Assert.assertEquals("bar/baz.txt", new Path("foo/../bar/baz.txt").toString());
  Assert.assertEquals("../bar/baz.txt", new Path("../bar/baz.txt").toString());
  Assert.assertEquals("../..", new Path("../..").toString());
  Assert.assertEquals("../..", new Path("../foo/.././..").toString());
}
 
Example #14
Source File: AbstractFileSystemSupport.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
protected Path getPath(final URI absoluteURI, final URI baseURI, final Path basePath) {
  Path _xblockexpression = null;
  {
    URI _xifexpression = null;
    if ((baseURI.isPlatformResource() && absoluteURI.isPlatformResource())) {
      URI _xifexpression_1 = null;
      String _segment = baseURI.segment(1);
      String _segment_1 = absoluteURI.segment(1);
      boolean _notEquals = (!Objects.equal(_segment, _segment_1));
      if (_notEquals) {
        URI _xblockexpression_1 = null;
        {
          String _platformString = absoluteURI.toPlatformString(true);
          final org.eclipse.core.runtime.Path p = new org.eclipse.core.runtime.Path(_platformString);
          String _string = p.toString();
          String _plus = (".." + _string);
          _xblockexpression_1 = URI.createURI(_plus);
        }
        _xifexpression_1 = _xblockexpression_1;
      } else {
        _xifexpression_1 = absoluteURI.deresolve(baseURI);
      }
      _xifexpression = _xifexpression_1;
    } else {
      _xifexpression = absoluteURI.deresolve(baseURI);
    }
    final URI relativeURI = _xifexpression;
    if ((relativeURI.isEmpty() || Objects.equal(relativeURI, absoluteURI))) {
      return null;
    }
    _xblockexpression = basePath.getAbsolutePath(relativeURI.toString());
  }
  return _xblockexpression;
}
 
Example #15
Source File: JavaIOFileSystemSupport.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Iterable<? extends Path> getChildren(final URI uri, final Path path) {
  java.net.URI _uRI = this.toURI(uri);
  final Function1<String, Path> _function = (String it) -> {
    return path.getAbsolutePath(it);
  };
  return ListExtensions.<String, Path>map(((List<String>)Conversions.doWrapArray(new File(_uRI).list())), _function);
}
 
Example #16
Source File: PathTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testRelativizeBothDirections() {
  final Path base = new Path("/hubba/bubba");
  final Path child = new Path("/hubba/bubba/bar");
  Path _path = new Path("bar");
  Assert.assertEquals(_path, base.relativize(child));
  Path _path_1 = new Path("bar");
  Assert.assertEquals(_path_1, child.relativize(base));
}
 
Example #17
Source File: FileLocationsImpl.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Path getSourceFolder(final Path path) {
  final Function1<Path, Boolean> _function = (Path sourceFolder) -> {
    return Boolean.valueOf(path.startsWith(sourceFolder));
  };
  return IterableExtensions.<Path>findFirst(this.getProjectSourceFolders(path), _function);
}
 
Example #18
Source File: JavaIoFileSystemTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testSetWorkspaceContentsAsStream() {
  try {
    byte[] _bytes = "Hello World!".getBytes();
    ByteArrayInputStream _byteArrayInputStream = new ByteArrayInputStream(_bytes);
    this.fs.setContentsAsStream(Path.ROOT, _byteArrayInputStream);
    Assert.fail();
  } catch (final Throwable _t) {
    if (_t instanceof IllegalArgumentException) {
    } else {
      throw Exceptions.sneakyThrow(_t);
    }
  }
}
 
Example #19
Source File: ParallelFileSystemSupport.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public long getLastModification(final Path path) {
  long _xblockexpression = (long) 0;
  {
    this.queue.waitForEmptyQueue();
    _xblockexpression = this.delegate.getLastModification(path);
  }
  return _xblockexpression;
}
 
Example #20
Source File: JavaIoFileSystemTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testGetWorkspaceContent() {
  try {
    this.fs.getContents(Path.ROOT);
    Assert.fail();
  } catch (final Throwable _t) {
    if (_t instanceof IllegalArgumentException) {
    } else {
      throw Exceptions.sneakyThrow(_t);
    }
  }
}
 
Example #21
Source File: JavaIoFileSystemTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testGetWorkspaceContentAsSteam() {
  try {
    this.fs.getContentsAsStream(Path.ROOT);
    Assert.fail();
  } catch (final Throwable _t) {
    if (_t instanceof IllegalArgumentException) {
    } else {
      throw Exceptions.sneakyThrow(_t);
    }
  }
}
 
Example #22
Source File: JavaIoFileSystemTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
protected void assertToURI(final Path file, final String expectedContent) {
  final URI uri = this.fs.toURI(file);
  Assert.assertNotNull(uri);
  try {
    final File javaIoFile = new File(uri);
    Assert.assertTrue(javaIoFile.exists());
    long _length = javaIoFile.length();
    final byte[] data = new byte[((int) _length)];
    final FileInputStream fis = new FileInputStream(javaIoFile);
    fis.read(data);
    fis.close();
    String _string = new String(data);
    Assert.assertEquals(expectedContent, _string);
  } catch (final Throwable _t) {
    if (_t instanceof Exception) {
      final Exception e = (Exception)_t;
      StringConcatenation _builder = new StringConcatenation();
      _builder.append("URI: ");
      _builder.append(uri);
      _builder.append("; ");
      String _message = e.getMessage();
      _builder.append(_message);
      Assert.fail(_builder.toString());
    } else {
      throw Exceptions.sneakyThrow(_t);
    }
  }
}
 
Example #23
Source File: AbstractFileSystemSupport.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
protected Path getPath(final URI uri, final ResourceSet context) {
  final IProjectConfig projectConfig = this.projectConfigProvider.getProjectConfig(context);
  if ((projectConfig == null)) {
    return null;
  }
  return this.getPath(uri, projectConfig.getPath(), Path.ROOT.append(projectConfig.getName()));
}
 
Example #24
Source File: ParallelFileSystemSupport.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void mkdir(final Path path) {
  final Runnable _function = () -> {
    this.delegate.mkdir(path);
  };
  this.queue.sendAsync(this.uri, _function);
}
 
Example #25
Source File: ParallelFileSystemSupport.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void delete(final Path path) {
  final Runnable _function = () -> {
    this.delegate.delete(path);
  };
  this.queue.sendAsync(this.uri, _function);
}
 
Example #26
Source File: ParallelFileSystemSupport.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public boolean isFolder(final Path path) {
  boolean _xblockexpression = false;
  {
    this.queue.waitForEmptyQueue();
    _xblockexpression = this.delegate.isFolder(path);
  }
  return _xblockexpression;
}
 
Example #27
Source File: ChangeListenerAddingFileSystemSupportTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Before
public void setup() {
  UIResourceChangeRegistry _uIResourceChangeRegistry = new UIResourceChangeRegistry();
  this.registry = _uIResourceChangeRegistry;
  this.uri = org.eclipse.emf.common.util.URI.createPlatformResourceURI("myProject/src/com/acme/C.xtend", true);
  ChangeListenerAddingFileSystemSupportTest.NoopFileSystemSupport _noopFileSystemSupport = new ChangeListenerAddingFileSystemSupportTest.NoopFileSystemSupport();
  ChangeListenerAddingFileSystemSupport _changeListenerAddingFileSystemSupport = new ChangeListenerAddingFileSystemSupport(this.uri, _noopFileSystemSupport, this.registry);
  this.fsa = _changeListenerAddingFileSystemSupport;
  Path _path = new Path("a");
  this.path = _path;
}
 
Example #28
Source File: FileProcessor.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void doTransform(final MutableClassDeclaration annotatedClass, @Extension final TransformationContext context) {
  final Path path = annotatedClass.getCompilationUnit().getFilePath();
  final String contents = context.getContents(context.getProjectFolder(path).append("res/template.txt")).toString();
  final String[] segments = contents.trim().split(",");
  for (final String segment : segments) {
    final Procedure1<MutableFieldDeclaration> _function = (MutableFieldDeclaration it) -> {
      it.setType(context.getString());
    };
    annotatedClass.addField(segment, _function);
  }
}
 
Example #29
Source File: TransformationContextImpl.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
public Path getTargetFolder(final Path sourceFolder) {
  return this.getFileLocations().getTargetFolder(sourceFolder);
}
 
Example #30
Source File: CodeGenerationContextImpl.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
public void setContents(final Path path, final CharSequence contents) {
  this.getFileSystemSupport().setContents(path, contents);
}