Code cleanup.
diff --git a/com.google.eclipse.protobuf.cdt/src/com/google/eclipse/protobuf/cdt/actions/ProtoFilePathFinder.java b/com.google.eclipse.protobuf.cdt/src/com/google/eclipse/protobuf/cdt/actions/ProtoFilePathFinder.java
index 43cd183..2427958 100644
--- a/com.google.eclipse.protobuf.cdt/src/com/google/eclipse/protobuf/cdt/actions/ProtoFilePathFinder.java
+++ b/com.google.eclipse.protobuf.cdt/src/com/google/eclipse/protobuf/cdt/actions/ProtoFilePathFinder.java
@@ -73,6 +73,6 @@
return null;
}
String path = matcher.group(1);
- return (!isEmpty(path)) ? new Path(path) : null;
+ return (!isEmpty(path)) ? Path.fromOSString(path) : null;
}
}
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/resource/IndexLookup_areReferringToSameFile_Tests.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/resource/IndexLookup_areReferringToSameFile_Tests.java
index 29ba51d..a5c0bed 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/resource/IndexLookup_areReferringToSameFile_Tests.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/resource/IndexLookup_areReferringToSameFile_Tests.java
@@ -35,19 +35,19 @@
@Test public void should_return_true_if_both_have_exactly_equal_segments() {
String pathValue = "/usr/local/google/proto";
- IPath path = new Path(pathValue);
+ IPath path = Path.fromOSString(pathValue);
URI uri = URI.createPlatformResourceURI(pathValue, false);
assertTrue(lookup.areReferringToSameFile(path, uri));
}
@Test public void should_return_true_if_path_is_subset_of_URI() {
- IPath path = new Path("/google/proto");
+ IPath path = Path.fromOSString("/google/proto");
URI uri = URI.createPlatformResourceURI("/usr/local/google/proto", true);
assertTrue(lookup.areReferringToSameFile(path, uri));
}
@Test public void should_return_false_if_last_segments_in_path_and_URI_are_not_equal() {
- IPath path = new Path("/usr/local/google/proto");
+ IPath path = Path.fromOSString("/usr/local/google/proto");
URI uri = URI.createPlatformResourceURI("/usr/local/google/cpp", true);
assertFalse(lookup.areReferringToSameFile(path, uri));
}
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/resource/IndexLookup_resourceIn_Test.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/resource/IndexLookup_resourceIn_Test.java
index 7a95601..e33119a 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/resource/IndexLookup_resourceIn_Test.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/resource/IndexLookup_resourceIn_Test.java
@@ -46,7 +46,8 @@
XtextResource resource = xtext.resource();
addToXtextIndex(resource);
URI resourceUri = resource.getURI();
- IResourceDescription description = lookup.resourceIn(new Path(resourceUri.path()));
+ IPath path = Path.fromOSString(resourceUri.path());
+ IResourceDescription description = lookup.resourceIn(path);
assertThat(description.getURI(), equalTo(resourceUri));
}
@@ -61,7 +62,7 @@
String[] segments = resourceUri.segments();
int segmentCount = segments.length;
String path = segments[segmentCount - 2] + "/" + segments[segmentCount - 1]; // last two segments.
- IResourceDescription description = lookup.resourceIn(new Path(path));
+ IResourceDescription description = lookup.resourceIn(Path.fromOSString(path));
assertThat(description.getURI(), equalTo(resourceUri));
}
@@ -72,7 +73,7 @@
@Test public void should_return_null_if_matching_URI_was_not_found() {
XtextResource resource = xtext.resource();
addToXtextIndex(resource);
- IResourceDescription description = lookup.resourceIn(new Path("some/crazy/path"));
+ IResourceDescription description = lookup.resourceIn(Path.fromOSString("some/crazy/path"));
assertNull(description);
}
diff --git a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/util/Uris_exists_withFile_Test.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/util/Uris_exists_withFile_Test.java
similarity index 94%
rename from com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/util/Uris_exists_withFile_Test.java
rename to com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/util/Uris_exists_withFile_Test.java
index c79541d..17b4837 100644
--- a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/util/Uris_exists_withFile_Test.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/util/Uris_exists_withFile_Test.java
@@ -6,7 +6,7 @@
*
* http://www.eclipse.org/legal/epl-v10.html
*/
-package com.google.eclipse.protobuf.ui.util;
+package com.google.eclipse.protobuf.util;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@@ -23,6 +23,7 @@
import org.junit.rules.TemporaryFolder;
import com.google.eclipse.protobuf.junit.core.XtextRule;
+import com.google.eclipse.protobuf.util.Uris;
import com.google.inject.Inject;
/**
diff --git a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/util/Uris_prefixOf_Test.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/util/Uris_prefixOf_Test.java
similarity index 93%
rename from com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/util/Uris_prefixOf_Test.java
rename to com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/util/Uris_prefixOf_Test.java
index beef1bf..5f19bd5 100644
--- a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/util/Uris_prefixOf_Test.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/util/Uris_prefixOf_Test.java
@@ -6,7 +6,7 @@
*
* http://www.eclipse.org/legal/epl-v10.html
*/
-package com.google.eclipse.protobuf.ui.util;
+package com.google.eclipse.protobuf.util;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertThat;
@@ -19,6 +19,7 @@
import org.junit.Test;
import com.google.eclipse.protobuf.junit.core.XtextRule;
+import com.google.eclipse.protobuf.util.Uris;
import com.google.inject.Inject;
/**
diff --git a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/util/Uris_segmentsWithoutFileName_Test.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/util/Uris_segmentsWithoutFileName_Test.java
similarity index 94%
rename from com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/util/Uris_segmentsWithoutFileName_Test.java
rename to com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/util/Uris_segmentsWithoutFileName_Test.java
index 47cea1e..5790ba0 100644
--- a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/util/Uris_segmentsWithoutFileName_Test.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/util/Uris_segmentsWithoutFileName_Test.java
@@ -6,7 +6,7 @@
*
* http://www.eclipse.org/legal/epl-v10.html
*/
-package com.google.eclipse.protobuf.ui.util;
+package com.google.eclipse.protobuf.util;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertThat;
@@ -22,6 +22,7 @@
import org.junit.Test;
import com.google.eclipse.protobuf.junit.core.XtextRule;
+import com.google.eclipse.protobuf.util.Uris;
import com.google.inject.Inject;
/**
diff --git a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/preferences/paths/core/ProjectVariable_replaceProjectNameWithProjectVariable_Test.java b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/preferences/paths/core/ProjectVariable_replaceProjectNameWithProjectVariable_Test.java
index 24c335d..5f7324b 100644
--- a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/preferences/paths/core/ProjectVariable_replaceProjectNameWithProjectVariable_Test.java
+++ b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/preferences/paths/core/ProjectVariable_replaceProjectNameWithProjectVariable_Test.java
@@ -34,21 +34,21 @@
}
@Test public void should_use_variable_if_path_contains_project_name() {
- IPath path = new Path("/test/src/test");
+ IPath path = Path.fromOSString("/test/src/test");
when(project.getName()).thenReturn("test");
IPath newPath = ProjectVariable.replaceProjectNameWithProjectVariable(path, project);
assertThat(newPath.toPortableString(), equalTo("/${project}/src/test"));
}
@Test public void should_not_use_variable_if_path_does_not_contain_project_name() {
- IPath path = new Path("/main/src/test");
+ IPath path = Path.fromOSString("/main/src/test");
when(project.getName()).thenReturn("test");
IPath newPath = ProjectVariable.replaceProjectNameWithProjectVariable(path, project);
assertThat(newPath.toPortableString(), equalTo("/main/src/test"));
}
@Test public void should_not_use_variable_if_path_already_contains_it() {
- IPath path = new Path("/${project}/src/test");
+ IPath path = Path.fromOSString("/${project}/src/test");
when(project.getName()).thenReturn("test");
IPath newPath = ProjectVariable.replaceProjectNameWithProjectVariable(path, project);
assertThat(newPath.toPortableString(), equalTo("/${project}/src/test"));
diff --git a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/preferences/paths/core/ProjectVariable_replaceProjectVariableWithProjectName_Test.java b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/preferences/paths/core/ProjectVariable_replaceProjectVariableWithProjectName_Test.java
index c3bcd51..9ccba70 100644
--- a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/preferences/paths/core/ProjectVariable_replaceProjectVariableWithProjectName_Test.java
+++ b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/preferences/paths/core/ProjectVariable_replaceProjectVariableWithProjectName_Test.java
@@ -35,21 +35,21 @@
@Test public void should_use_project_name_if_path_contains_variable() {
when(project.getName()).thenReturn("test");
- IPath path = new Path("/${project}/src/test");
+ IPath path = Path.fromOSString("/${project}/src/test");
IPath newPath = ProjectVariable.replaceProjectVariableWithProjectName(path, project);
assertThat(newPath.toPortableString(), equalTo("/test/src/test"));
}
@Test public void should_not_use_project_name_if_path_does_not_contain_variable() {
when(project.getName()).thenReturn("test");
- IPath path = new Path("/main/src/test");
+ IPath path = Path.fromOSString("/main/src/test");
IPath newPath = ProjectVariable.replaceProjectVariableWithProjectName(path, project);
assertThat(newPath.toPortableString(), equalTo("/main/src/test"));
}
@Test public void should_not_use_project_name_if_path_already_contains_it() {
when(project.getName()).thenReturn("test");
- IPath path = new Path("/test/src/test");
+ IPath path = Path.fromOSString("/test/src/test");
IPath newPath = ProjectVariable.replaceProjectVariableWithProjectName(path, project);
assertThat(newPath.toPortableString(), equalTo("/test/src/test"));
}
diff --git a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/protoc/output/ProtocMarkerFactory_createErrorIfNecessary_Test.java b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/protoc/output/ProtocMarkerFactory_createErrorIfNecessary_Test.java
index a878315..e16e1a4 100644
--- a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/protoc/output/ProtocMarkerFactory_createErrorIfNecessary_Test.java
+++ b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/protoc/output/ProtocMarkerFactory_createErrorIfNecessary_Test.java
@@ -39,7 +39,7 @@
@Before public void setUp() throws CoreException {
marker = error(EDITOR_CHECK, "Expected field name.", 68);
file = new FileStub();
- file.setLocation(new Path("home/alex/protos/test1.proto"));
+ file.setLocation(Path.fromOSString("home/alex/protos/test1.proto"));
file.createMarker(PROTOC);
file.addMarker(marker);
markerFactory = new ProtocMarkerFactory(file);
diff --git a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/scoping/SingleDirectoryFileResolverStrategy_resolveUri_withFileUri_Test.java b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/scoping/SingleDirectoryFileResolverStrategy_resolveUri_withFileUri_Test.java
index 23ea34d..c4a269f 100644
--- a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/scoping/SingleDirectoryFileResolverStrategy_resolveUri_withFileUri_Test.java
+++ b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/scoping/SingleDirectoryFileResolverStrategy_resolveUri_withFileUri_Test.java
@@ -22,7 +22,7 @@
import com.google.eclipse.protobuf.junit.core.AbstractTestModule;
import com.google.eclipse.protobuf.junit.core.XtextRule;
-import com.google.eclipse.protobuf.ui.util.Uris;
+import com.google.eclipse.protobuf.util.Uris;
import com.google.inject.Inject;
/**
diff --git a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/scoping/SingleDirectoryFileResolverStrategy_resolveUri_withPlatformResourceUri_Test.java b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/scoping/SingleDirectoryFileResolverStrategy_resolveUri_withPlatformResourceUri_Test.java
index 78cf9e2..485cd5e 100644
--- a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/scoping/SingleDirectoryFileResolverStrategy_resolveUri_withPlatformResourceUri_Test.java
+++ b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/scoping/SingleDirectoryFileResolverStrategy_resolveUri_withPlatformResourceUri_Test.java
@@ -23,7 +23,7 @@
import com.google.eclipse.protobuf.junit.core.AbstractTestModule;
import com.google.eclipse.protobuf.junit.core.XtextRule;
-import com.google.eclipse.protobuf.ui.util.Uris;
+import com.google.eclipse.protobuf.util.Uris;
import com.google.inject.Inject;
/**
diff --git a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/scoping/UrisStub.java b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/scoping/UrisStub.java
index 04ac73c..25347c3 100644
--- a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/scoping/UrisStub.java
+++ b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/scoping/UrisStub.java
@@ -10,7 +10,7 @@
import org.eclipse.emf.common.util.URI;
-import com.google.eclipse.protobuf.ui.util.Uris;
+import com.google.eclipse.protobuf.util.Uris;
/**
* @author alruiz@google.com (Alex Ruiz)
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/protoc/ProtobufBuildParticipant.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/protoc/ProtobufBuildParticipant.java
index 7a7f968..3690f5b 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/protoc/ProtobufBuildParticipant.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/protoc/ProtobufBuildParticipant.java
@@ -38,6 +38,7 @@
import com.google.eclipse.protobuf.ui.protoc.command.ProtocCommandBuilder;
import com.google.eclipse.protobuf.ui.protoc.output.ProtocMarkerFactory;
import com.google.eclipse.protobuf.ui.protoc.output.ProtocOutputParser;
+import com.google.eclipse.protobuf.util.Uris;
import com.google.inject.Inject;
/**
@@ -48,6 +49,7 @@
public class ProtobufBuildParticipant implements IXtextBuilderParticipant {
@Inject private ProtocOutputParser outputParser;
@Inject private IPreferenceStoreAccess storeAccess;
+ @Inject private Uris uris;
@Override public void build(IBuildContext context, IProgressMonitor monitor) throws CoreException {
List<Delta> deltas = context.getDeltas();
@@ -83,7 +85,7 @@
return null;
}
URI uri = resource.getURI();
- if (uri.isPlatformResource() && "proto".equals(uri.fileExtension())) {
+ if (uris.hasProtoExtension(uri) && uri.isPlatformResource()) {
return uri.toPlatformString(true);
}
return null;
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/FileOpener.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/FileOpener.java
index 6b4c695..a50cdc3 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/FileOpener.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/FileOpener.java
@@ -22,7 +22,7 @@
import org.eclipse.ui.ide.FileStoreEditorInput;
import org.eclipse.ui.part.FileEditorInput;
-import com.google.eclipse.protobuf.ui.util.Uris;
+import com.google.eclipse.protobuf.util.Uris;
import com.google.inject.Inject;
import com.google.inject.Singleton;
@@ -49,7 +49,7 @@
if (page == null) {
return null;
}
- IFileStore fileStore = EFS.getLocalFileSystem().getStore(new Path(uri.toFileString()));
+ IFileStore fileStore = EFS.getLocalFileSystem().getStore(Path.fromOSString(uri.toFileString()));
IEditorInput editorInput = new FileStoreEditorInput(fileStore);
return openFile(editorInput, page);
}
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/DirectoryPath.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/DirectoryPath.java
index 544879d..e10a516 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/DirectoryPath.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/DirectoryPath.java
@@ -47,7 +47,7 @@
actualPath = matcher.group(1);
isWorkspacePath = true;
if (project != null) {
- IPath newPath = replaceProjectVariableWithProjectName(new Path(actualPath), project);
+ IPath newPath = replaceProjectVariableWithProjectName(Path.fromOSString(actualPath), project);
// Issue 204: we'll create an URI from this path. It must not have OS-specific path separators.
actualPath = newPath.toPortableString();
}
@@ -81,7 +81,7 @@
* @return the absolute path in the local file system, or {@code null} if no path can be determined.
*/
public String absolutePathInFileSystem() {
- IPath path = new Path(value);
+ IPath path = Path.fromOSString(value);
if (isWorkspacePath()) {
return directoryLocationInWorkspace(path);
}
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/ProjectVariable.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/ProjectVariable.java
index 5e2c341..5fa2383 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/ProjectVariable.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/ProjectVariable.java
@@ -32,7 +32,7 @@
if (!currentSegment.equals(path.segment(0))) {
return path;
}
- IPath newPath = new Path(newSegment);
+ IPath newPath = Path.fromOSString(newSegment);
newPath = newPath.append(path.removeFirstSegments(1));
if (path.isAbsolute()) {
newPath = newPath.makeAbsolute();
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/scoping/FileUriResolver.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/scoping/FileUriResolver.java
index 16cc27b..fbe27da 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/scoping/FileUriResolver.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/scoping/FileUriResolver.java
@@ -28,7 +28,7 @@
import com.google.eclipse.protobuf.scoping.IFileUriResolver;
import com.google.eclipse.protobuf.scoping.ProtoDescriptorProvider;
import com.google.eclipse.protobuf.ui.preferences.paths.PathsPreferences;
-import com.google.eclipse.protobuf.ui.util.Uris;
+import com.google.eclipse.protobuf.util.Uris;
import com.google.inject.Inject;
/**
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/scoping/ResourceLocations.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/scoping/ResourceLocations.java
index 36bcd31..0ae1fd7 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/scoping/ResourceLocations.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/scoping/ResourceLocations.java
@@ -18,7 +18,7 @@
*/
class ResourceLocations {
String directoryLocation(String workspacePath) {
- IPath path = new Path(workspacePath);
+ IPath path = Path.fromOSString(workspacePath);
return directoryLocationInWorkspace(path);
}
}
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/scoping/SingleDirectoryFileResolverStrategy.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/scoping/SingleDirectoryFileResolverStrategy.java
index 40888ba..f66dd7f 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/scoping/SingleDirectoryFileResolverStrategy.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/scoping/SingleDirectoryFileResolverStrategy.java
@@ -14,7 +14,7 @@
import org.eclipse.emf.common.util.URI;
import com.google.eclipse.protobuf.ui.preferences.paths.PathsPreferences;
-import com.google.eclipse.protobuf.ui.util.Uris;
+import com.google.eclipse.protobuf.util.Uris;
import com.google.inject.Inject;
/**
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/scoping/UriResolver.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/scoping/UriResolver.java
index 97abdd2..f6ac4b3 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/scoping/UriResolver.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/scoping/UriResolver.java
@@ -14,7 +14,7 @@
import org.eclipse.emf.common.util.URI;
import com.google.eclipse.protobuf.ui.preferences.paths.DirectoryPath;
-import com.google.eclipse.protobuf.ui.util.Uris;
+import com.google.eclipse.protobuf.util.Uris;
import com.google.inject.Inject;
import com.google.inject.Singleton;
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/resource/FastXtextResourceSet.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/resource/FastXtextResourceSet.java
index 9f8eafa..d0fa702 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/resource/FastXtextResourceSet.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/resource/FastXtextResourceSet.java
@@ -2,8 +2,6 @@
import static org.eclipse.xtext.resource.ClasspathUriUtil.isClasspathUri;
-import static com.google.eclipse.protobuf.util.Workspaces.workspaceRoot;
-
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
@@ -11,14 +9,18 @@
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.Path;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.URIConverter;
import org.eclipse.emf.ecore.resource.impl.ExtensibleURIConverterImpl;
import org.eclipse.xtext.resource.ClasspathUriResolutionException;
import org.eclipse.xtext.resource.SynchronizedXtextResourceSet;
+import com.google.eclipse.protobuf.util.Uris;
+import com.google.inject.Inject;
+
public class FastXtextResourceSet extends SynchronizedXtextResourceSet {
+ @Inject private Uris uris;
+
@Override public URIConverter getURIConverter() {
if (uriConverter == null) {
uriConverter = new ExtensibleURIConverterImpl() {
@@ -48,10 +50,9 @@
if (isClasspathUri(uri)) {
return getClass().getResourceAsStream(uri.path());
}
- if ("proto".equals(uri.fileExtension())) {
+ if (uris.hasProtoExtension(uri)) {
if (uri.isPlatformResource()) {
- String platformUri = uri.toPlatformString(true);
- IFile file = workspaceRoot().getFile(Path.fromOSString(platformUri));
+ IFile file = uris.referredFile(uri);
if (file != null && file.exists()) {
IPath location = file.getLocation();
return new FileInputStream(location.toFile());
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/util/Uris.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/util/Uris.java
similarity index 88%
rename from com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/util/Uris.java
rename to com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/util/Uris.java
index a815b4e..e12cbc8 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/util/Uris.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/util/Uris.java
@@ -6,7 +6,7 @@
*
* http://www.eclipse.org/legal/epl-v10.html
*/
-package com.google.eclipse.protobuf.ui.util;
+package com.google.eclipse.protobuf.util;
import static java.util.Collections.emptyList;
import static java.util.Collections.unmodifiableList;
@@ -33,6 +33,15 @@
*/
@Singleton public class Uris {
/**
+ * Indicates whether the resource at the given URI has extension "proto".
+ * @param uri the given URI.
+ * @return {@code true} if the resource has extension "proto", {@code false} otherwise.
+ */
+ public boolean hasProtoExtension(URI uri) {
+ return "proto".equals(uri.fileExtension());
+ }
+
+ /**
* Indicates whether the resource or file referred by the given URI exists.
* @param uri the URI to check. It may be {@code null}.
* @return {@code true} if the resource or file referred by the given URI exists, {@code false} otherwise.
@@ -123,7 +132,7 @@
}
private IPath pathOf(URI uri) {
- String uriAsText = uri.toPlatformString(true);
- return (uriAsText != null) ? new Path(uriAsText) : null;
+ String platformString = uri.toPlatformString(true);
+ return platformString != null ? Path.fromOSString(platformString) : null;
}
}