From acd1e60ab4b3dae34884aedcab359fcb61b73523 Mon Sep 17 00:00:00 2001 From: Christian Dietrich Date: Fri, 22 Jul 2016 21:49:39 +0200 Subject: [PATCH] improved uri handling on windows. fixes #49 Signed-off-by: Christian Dietrich --- .../xtext/ide/tests/server/DocumentTest.xtend | 18 +++++++----- .../xtext/ide/tests/server/DocumentTest.java | 28 +++++++++++++------ .../xtext/ide/server/UriExtensions.xtend | 2 +- .../xtext/ide/server/UriExtensions.java | 6 ++-- .../xtext/util/IFileSystemScanner.xtend | 12 ++++++-- .../xtext/util/IFileSystemScanner.java | 12 ++++++-- 6 files changed, 52 insertions(+), 26 deletions(-) diff --git a/org.eclipse.xtext.ide.tests/src/org/eclipse/xtext/ide/tests/server/DocumentTest.xtend b/org.eclipse.xtext.ide.tests/src/org/eclipse/xtext/ide/tests/server/DocumentTest.xtend index e466376d4..e6702bbc6 100644 --- a/org.eclipse.xtext.ide.tests/src/org/eclipse/xtext/ide/tests/server/DocumentTest.xtend +++ b/org.eclipse.xtext.ide.tests/src/org/eclipse/xtext/ide/tests/server/DocumentTest.xtend @@ -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] } diff --git a/org.eclipse.xtext.ide.tests/xtend-gen/org/eclipse/xtext/ide/tests/server/DocumentTest.java b/org.eclipse.xtext.ide.tests/xtend-gen/org/eclipse/xtext/ide/tests/server/DocumentTest.java index 9f2083747..b1b525012 100644 --- a/org.eclipse.xtext.ide.tests/xtend-gen/org/eclipse/xtext/ide/tests/server/DocumentTest.java +++ b/org.eclipse.xtext.ide.tests/xtend-gen/org/eclipse/xtext/ide/tests/server/DocumentTest.java @@ -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 _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 _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.unmodifiableList(CollectionLiterals.newArrayList(_change))); String _contents = _applyChanges.getContents(); - Assert.assertEquals(_string, _contents); + Assert.assertEquals(_normalize_1, _contents); }; ObjectExtensions.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 _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.unmodifiableList(CollectionLiterals.newArrayList(_change))); String _contents = _applyChanges.getContents(); - Assert.assertEquals(_string, _contents); + Assert.assertEquals(_normalize_1, _contents); }; ObjectExtensions.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 _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 _function = (Document it) -> { TextEditImpl _change = this.change(null, null, " foo "); Document _applyChanges = it.applyChanges( @@ -210,6 +215,11 @@ public class DocumentTest { return ObjectExtensions.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 _function = (PositionImpl it) -> { diff --git a/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/server/UriExtensions.xtend b/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/server/UriExtensions.xtend index a2db79764..32e7ef306 100644 --- a/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/server/UriExtensions.xtend +++ b/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/server/UriExtensions.xtend @@ -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) { diff --git a/org.eclipse.xtext.ide/xtend-gen/org/eclipse/xtext/ide/server/UriExtensions.java b/org.eclipse.xtext.ide/xtend-gen/org/eclipse/xtext/ide/server/UriExtensions.java index 30bcc09ef..7d1a98baa 100644 --- a/org.eclipse.xtext.ide/xtend-gen/org/eclipse/xtext/ide/server/UriExtensions.java +++ b/org.eclipse.xtext.ide/xtend-gen/org/eclipse/xtext/ide/server/UriExtensions.java @@ -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) { diff --git a/org.eclipse.xtext.util/src/org/eclipse/xtext/util/IFileSystemScanner.xtend b/org.eclipse.xtext.util/src/org/eclipse/xtext/util/IFileSystemScanner.xtend index 8eacdd73f..c0b873e10 100644 --- a/org.eclipse.xtext.util/src/org/eclipse/xtext/util/IFileSystemScanner.xtend +++ b/org.eclipse.xtext.util/src/org/eclipse/xtext/util/IFileSystemScanner.xtend @@ -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 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 { } } + } \ No newline at end of file diff --git a/org.eclipse.xtext.util/xtend-gen/org/eclipse/xtext/util/IFileSystemScanner.java b/org.eclipse.xtext.util/xtend-gen/org/eclipse/xtext/util/IFileSystemScanner.java index 9bce130cc..6c12981f8 100644 --- a/org.eclipse.xtext.util/xtend-gen/org/eclipse/xtext/util/IFileSystemScanner.java +++ b/org.eclipse.xtext.util/xtend-gen/org/eclipse/xtext/util/IFileSystemScanner.java @@ -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 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();