mirror of
https://github.com/sigmasternchen/xtext-core
synced 2025-03-15 16:28:56 +00:00
Merge pull request #51 from eclipse/cd/issue49
improved uri handling on windows
This commit is contained in:
commit
3d49daa819
6 changed files with 52 additions and 26 deletions
|
@ -25,7 +25,7 @@ class DocumentTest {
|
|||
hello world
|
||||
foo
|
||||
bar
|
||||
''') => [
|
||||
'''.normalize) => [
|
||||
assertEquals(0, getOffSet(position(0,0)))
|
||||
assertEquals(11, getOffSet(position(0,11)))
|
||||
try {
|
||||
|
@ -59,11 +59,11 @@ class DocumentTest {
|
|||
hello world
|
||||
foo
|
||||
bar
|
||||
''') => [
|
||||
'''.normalize) => [
|
||||
assertEquals('''
|
||||
hello world
|
||||
bar
|
||||
'''.toString, applyChanges(#[
|
||||
'''.normalize, applyChanges(#[
|
||||
change(position(1,0), position(2,0), "")
|
||||
]).contents)
|
||||
]
|
||||
|
@ -74,12 +74,12 @@ class DocumentTest {
|
|||
hello world
|
||||
foo
|
||||
bar
|
||||
''') => [
|
||||
'''.normalize) => [
|
||||
assertEquals('''
|
||||
hello world
|
||||
future
|
||||
bar
|
||||
'''.toString, applyChanges(#[
|
||||
'''.normalize, applyChanges(#[
|
||||
change(position(1,1), position(1,3), "uture")
|
||||
]).contents)
|
||||
]
|
||||
|
@ -89,7 +89,7 @@ class DocumentTest {
|
|||
new Document(1, '''
|
||||
hello world
|
||||
foo
|
||||
bar''') => [
|
||||
bar'''.normalize) => [
|
||||
assertEquals('', applyChanges(#[
|
||||
change(position(0,0), position(2,3), "")
|
||||
]).contents)
|
||||
|
@ -100,7 +100,7 @@ class DocumentTest {
|
|||
new Document(1, '''
|
||||
hello world
|
||||
foo
|
||||
bar''') => [
|
||||
bar'''.normalize) => [
|
||||
assertEquals(' foo ', applyChanges(#[
|
||||
change(null, null, " foo ")
|
||||
]).contents)
|
||||
|
@ -119,6 +119,10 @@ class DocumentTest {
|
|||
]
|
||||
}
|
||||
|
||||
private def normalize(CharSequence s) {
|
||||
return s.toString.replaceAll("\r", "")
|
||||
}
|
||||
|
||||
private def position(int l, int c) {
|
||||
new PositionImpl => [line=l character=c]
|
||||
}
|
||||
|
|
|
@ -35,7 +35,8 @@ public class DocumentTest {
|
|||
_builder.newLine();
|
||||
_builder.append("bar");
|
||||
_builder.newLine();
|
||||
Document _document = new Document(1, _builder.toString());
|
||||
String _normalize = this.normalize(_builder);
|
||||
Document _document = new Document(1, _normalize);
|
||||
final Procedure1<Document> _function = (Document it) -> {
|
||||
PositionImpl _position = this.position(0, 0);
|
||||
int _offSet = it.getOffSet(_position);
|
||||
|
@ -104,21 +105,22 @@ public class DocumentTest {
|
|||
_builder.newLine();
|
||||
_builder.append("bar");
|
||||
_builder.newLine();
|
||||
Document _document = new Document(1, _builder.toString());
|
||||
String _normalize = this.normalize(_builder);
|
||||
Document _document = new Document(1, _normalize);
|
||||
final Procedure1<Document> _function = (Document it) -> {
|
||||
StringConcatenation _builder_1 = new StringConcatenation();
|
||||
_builder_1.append("hello world");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("bar");
|
||||
_builder_1.newLine();
|
||||
String _string = _builder_1.toString();
|
||||
String _normalize_1 = this.normalize(_builder_1);
|
||||
PositionImpl _position = this.position(1, 0);
|
||||
PositionImpl _position_1 = this.position(2, 0);
|
||||
TextEditImpl _change = this.change(_position, _position_1, "");
|
||||
Document _applyChanges = it.applyChanges(
|
||||
Collections.<TextEdit>unmodifiableList(CollectionLiterals.<TextEdit>newArrayList(_change)));
|
||||
String _contents = _applyChanges.getContents();
|
||||
Assert.assertEquals(_string, _contents);
|
||||
Assert.assertEquals(_normalize_1, _contents);
|
||||
};
|
||||
ObjectExtensions.<Document>operator_doubleArrow(_document, _function);
|
||||
}
|
||||
|
@ -132,7 +134,8 @@ public class DocumentTest {
|
|||
_builder.newLine();
|
||||
_builder.append("bar");
|
||||
_builder.newLine();
|
||||
Document _document = new Document(1, _builder.toString());
|
||||
String _normalize = this.normalize(_builder);
|
||||
Document _document = new Document(1, _normalize);
|
||||
final Procedure1<Document> _function = (Document it) -> {
|
||||
StringConcatenation _builder_1 = new StringConcatenation();
|
||||
_builder_1.append("hello world");
|
||||
|
@ -141,14 +144,14 @@ public class DocumentTest {
|
|||
_builder_1.newLine();
|
||||
_builder_1.append("bar");
|
||||
_builder_1.newLine();
|
||||
String _string = _builder_1.toString();
|
||||
String _normalize_1 = this.normalize(_builder_1);
|
||||
PositionImpl _position = this.position(1, 1);
|
||||
PositionImpl _position_1 = this.position(1, 3);
|
||||
TextEditImpl _change = this.change(_position, _position_1, "uture");
|
||||
Document _applyChanges = it.applyChanges(
|
||||
Collections.<TextEdit>unmodifiableList(CollectionLiterals.<TextEdit>newArrayList(_change)));
|
||||
String _contents = _applyChanges.getContents();
|
||||
Assert.assertEquals(_string, _contents);
|
||||
Assert.assertEquals(_normalize_1, _contents);
|
||||
};
|
||||
ObjectExtensions.<Document>operator_doubleArrow(_document, _function);
|
||||
}
|
||||
|
@ -161,7 +164,8 @@ public class DocumentTest {
|
|||
_builder.append("foo");
|
||||
_builder.newLine();
|
||||
_builder.append("bar");
|
||||
Document _document = new Document(1, _builder.toString());
|
||||
String _normalize = this.normalize(_builder);
|
||||
Document _document = new Document(1, _normalize);
|
||||
final Procedure1<Document> _function = (Document it) -> {
|
||||
PositionImpl _position = this.position(0, 0);
|
||||
PositionImpl _position_1 = this.position(2, 3);
|
||||
|
@ -182,7 +186,8 @@ public class DocumentTest {
|
|||
_builder.append("foo");
|
||||
_builder.newLine();
|
||||
_builder.append("bar");
|
||||
Document _document = new Document(1, _builder.toString());
|
||||
String _normalize = this.normalize(_builder);
|
||||
Document _document = new Document(1, _normalize);
|
||||
final Procedure1<Document> _function = (Document it) -> {
|
||||
TextEditImpl _change = this.change(null, null, " foo ");
|
||||
Document _applyChanges = it.applyChanges(
|
||||
|
@ -210,6 +215,11 @@ public class DocumentTest {
|
|||
return ObjectExtensions.<TextEditImpl>operator_doubleArrow(_textEditImpl, _function);
|
||||
}
|
||||
|
||||
private String normalize(final CharSequence s) {
|
||||
String _string = s.toString();
|
||||
return _string.replaceAll("\r", "");
|
||||
}
|
||||
|
||||
private PositionImpl position(final int l, final int c) {
|
||||
PositionImpl _positionImpl = new PositionImpl();
|
||||
final Procedure1<PositionImpl> _function = (PositionImpl it) -> {
|
||||
|
|
|
@ -19,7 +19,7 @@ import org.eclipse.emf.common.util.URI
|
|||
class UriExtensions {
|
||||
|
||||
def URI toUri(String path) {
|
||||
return URI.createURI(Paths.get(path).toString)
|
||||
return URI.createURI(java.net.URI.create(path).toPath)
|
||||
}
|
||||
|
||||
def String toPath(URI uri) {
|
||||
|
|
|
@ -20,9 +20,9 @@ import org.eclipse.emf.common.util.URI;
|
|||
@SuppressWarnings("all")
|
||||
public class UriExtensions {
|
||||
public URI toUri(final String path) {
|
||||
Path _get = Paths.get(path);
|
||||
String _string = _get.toString();
|
||||
return URI.createURI(_string);
|
||||
java.net.URI _create = java.net.URI.create(path);
|
||||
String _path = this.toPath(_create);
|
||||
return URI.createURI(_path);
|
||||
}
|
||||
|
||||
public String toPath(final URI uri) {
|
||||
|
|
|
@ -7,10 +7,10 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.xtext.util
|
||||
|
||||
import org.eclipse.xtext.util.IAcceptor
|
||||
import org.eclipse.emf.common.util.URI
|
||||
import com.google.inject.ImplementedBy
|
||||
import java.io.File
|
||||
import java.nio.file.Paths
|
||||
import org.eclipse.emf.common.util.URI
|
||||
|
||||
/**
|
||||
* @author Sven Efftinge - Initial contribution and API
|
||||
|
@ -29,7 +29,12 @@ interface IFileSystemScanner {
|
|||
}
|
||||
|
||||
def void scanRec(File file, IAcceptor<URI> acceptor) {
|
||||
acceptor.accept(URI.createFileURI(file.absolutePath))
|
||||
// we need to convert the given file to a decoded emf file uri
|
||||
// e.g. file:///Users/x/y/z
|
||||
// or file:///C:/x/y/z
|
||||
val path = Paths.get(file.absoluteFile.toURI)
|
||||
val uri = URI.createURI(path.toUri.toString)
|
||||
acceptor.accept(uri)
|
||||
if (file.isDirectory) {
|
||||
for (f : file.listFiles) {
|
||||
scanRec(f, acceptor)
|
||||
|
@ -38,4 +43,5 @@ interface IFileSystemScanner {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -9,6 +9,8 @@ package org.eclipse.xtext.util;
|
|||
|
||||
import com.google.inject.ImplementedBy;
|
||||
import java.io.File;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import org.eclipse.emf.common.util.URI;
|
||||
import org.eclipse.xtext.util.IAcceptor;
|
||||
|
||||
|
@ -28,9 +30,13 @@ public interface IFileSystemScanner {
|
|||
}
|
||||
|
||||
public void scanRec(final File file, final IAcceptor<URI> acceptor) {
|
||||
String _absolutePath = file.getAbsolutePath();
|
||||
URI _createFileURI = URI.createFileURI(_absolutePath);
|
||||
acceptor.accept(_createFileURI);
|
||||
File _absoluteFile = file.getAbsoluteFile();
|
||||
java.net.URI _uRI = _absoluteFile.toURI();
|
||||
final Path path = Paths.get(_uRI);
|
||||
java.net.URI _uri = path.toUri();
|
||||
String _string = _uri.toString();
|
||||
final URI uri = URI.createURI(_string);
|
||||
acceptor.accept(uri);
|
||||
boolean _isDirectory = file.isDirectory();
|
||||
if (_isDirectory) {
|
||||
File[] _listFiles = file.listFiles();
|
||||
|
|
Loading…
Reference in a new issue