In progress: [ Issue 40 ] Add support for import resolution across multiple folders
https://code.google.com/p/protobuf-dt/issues/detail?id=40
Fixed tests.
diff --git a/com.google.eclipse.protobuf.junit/src/com/google/eclipse/protobuf/junit/stubs/FileStub.java b/com.google.eclipse.protobuf.junit/src/com/google/eclipse/protobuf/junit/stubs/FileStub.java
index e6dcec0..d3b036d 100644
--- a/com.google.eclipse.protobuf.junit/src/com/google/eclipse/protobuf/junit/stubs/FileStub.java
+++ b/com.google.eclipse.protobuf.junit/src/com/google/eclipse/protobuf/junit/stubs/FileStub.java
@@ -28,38 +28,38 @@
private final Map<String, List<MarkerStub>> markersByType = new HashMap<String, List<MarkerStub>>();
/** {@inheritDoc} */
- public void accept(IResourceProxyVisitor visitor, int memberFlags) throws CoreException {
+ public void accept(IResourceProxyVisitor visitor, int memberFlags) {
throw new UnsupportedOperationException();
}
/** {@inheritDoc} */
- public void accept(IResourceVisitor visitor) throws CoreException {
+ public void accept(IResourceVisitor visitor) {
throw new UnsupportedOperationException();
}
/** {@inheritDoc} */
- public void accept(IResourceVisitor visitor, int depth, boolean includePhantoms) throws CoreException {
+ public void accept(IResourceVisitor visitor, int depth, boolean includePhantoms) {
throw new UnsupportedOperationException();
}
/** {@inheritDoc} */
- public void accept(IResourceVisitor visitor, int depth, int memberFlags) throws CoreException {
+ public void accept(IResourceVisitor visitor, int depth, int memberFlags) {
throw new UnsupportedOperationException();
}
/** {@inheritDoc} */
public void appendContents(InputStream source, boolean force, boolean keepHistory, IProgressMonitor monitor)
- throws CoreException {
+ {
throw new UnsupportedOperationException();
}
/** {@inheritDoc} */
- public void appendContents(InputStream source, int updateFlags, IProgressMonitor monitor) throws CoreException {
+ public void appendContents(InputStream source, int updateFlags, IProgressMonitor monitor) {
throw new UnsupportedOperationException();
}
/** {@inheritDoc} */
- public void clearHistory(IProgressMonitor monitor) throws CoreException {
+ public void clearHistory(IProgressMonitor monitor) {
throw new UnsupportedOperationException();
}
@@ -69,47 +69,47 @@
}
/** {@inheritDoc} */
- public void copy(IPath destination, boolean force, IProgressMonitor monitor) throws CoreException {
+ public void copy(IPath destination, boolean force, IProgressMonitor monitor) {
throw new UnsupportedOperationException();
}
/** {@inheritDoc} */
- public void copy(IPath destination, int updateFlags, IProgressMonitor monitor) throws CoreException {
+ public void copy(IPath destination, int updateFlags, IProgressMonitor monitor) {
throw new UnsupportedOperationException();
}
/** {@inheritDoc} */
- public void copy(IProjectDescription description, boolean force, IProgressMonitor monitor) throws CoreException {
+ public void copy(IProjectDescription description, boolean force, IProgressMonitor monitor) {
throw new UnsupportedOperationException();
}
/** {@inheritDoc} */
- public void copy(IProjectDescription description, int updateFlags, IProgressMonitor monitor) throws CoreException {
+ public void copy(IProjectDescription description, int updateFlags, IProgressMonitor monitor) {
throw new UnsupportedOperationException();
}
/** {@inheritDoc} */
- public void create(InputStream source, boolean force, IProgressMonitor monitor) throws CoreException {
+ public void create(InputStream source, boolean force, IProgressMonitor monitor) {
throw new UnsupportedOperationException();
}
/** {@inheritDoc} */
- public void create(InputStream source, int updateFlags, IProgressMonitor monitor) throws CoreException {
+ public void create(InputStream source, int updateFlags, IProgressMonitor monitor) {
throw new UnsupportedOperationException();
}
/** {@inheritDoc} */
- public void createLink(IPath localLocation, int updateFlags, IProgressMonitor monitor) throws CoreException {
+ public void createLink(IPath localLocation, int updateFlags, IProgressMonitor monitor) {
throw new UnsupportedOperationException();
}
/** {@inheritDoc} */
- public void createLink(URI location, int updateFlags, IProgressMonitor monitor) throws CoreException {
+ public void createLink(URI location, int updateFlags, IProgressMonitor monitor) {
throw new UnsupportedOperationException();
}
/** {@inheritDoc} */
- public IMarker createMarker(String type) throws CoreException {
+ public IMarker createMarker(String type) {
MarkerStub marker = new MarkerStub(type);
addMarker(marker);
return marker;
@@ -121,22 +121,22 @@
}
/** {@inheritDoc} */
- public void delete(boolean force, boolean keepHistory, IProgressMonitor monitor) throws CoreException {
+ public void delete(boolean force, boolean keepHistory, IProgressMonitor monitor) {
throw new UnsupportedOperationException();
}
/** {@inheritDoc} */
- public void delete(boolean force, IProgressMonitor monitor) throws CoreException {
+ public void delete(boolean force, IProgressMonitor monitor) {
throw new UnsupportedOperationException();
}
/** {@inheritDoc} */
- public void delete(int updateFlags, IProgressMonitor monitor) throws CoreException {
+ public void delete(int updateFlags, IProgressMonitor monitor) {
throw new UnsupportedOperationException();
}
/** {@inheritDoc} */
- public void deleteMarkers(String type, boolean includeSubtypes, int depth) throws CoreException {
+ public void deleteMarkers(String type, boolean includeSubtypes, int depth) {
List<MarkerStub> markers = markersByType.get(type);
if (markers != null) markers.clear();
}
@@ -147,19 +147,19 @@
}
/** {@inheritDoc} */
- public IMarker findMarker(long id) throws CoreException {
+ public IMarker findMarker(long id) {
throw new UnsupportedOperationException();
}
/** {@inheritDoc} */
- public IMarker[] findMarkers(String type, boolean includeSubtypes, int depth) throws CoreException {
+ public IMarker[] findMarkers(String type, boolean includeSubtypes, int depth) {
List<MarkerStub> markers = markersByType.get(type);
if (markers == null) return new IMarker[0];
return markers.toArray(new IMarker[markers.size()]);
}
/** {@inheritDoc} */
- public int findMaxProblemSeverity(String type, boolean includeSubtypes, int depth) throws CoreException {
+ public int findMaxProblemSeverity(String type, boolean includeSubtypes, int depth) {
throw new UnsupportedOperationException();
}
@@ -169,37 +169,37 @@
}
/** {@inheritDoc} */
- public String getCharset() throws CoreException {
+ public String getCharset() {
throw new UnsupportedOperationException();
}
/** {@inheritDoc} */
- public String getCharset(boolean checkImplicit) throws CoreException {
+ public String getCharset(boolean checkImplicit) {
throw new UnsupportedOperationException();
}
/** {@inheritDoc} */
- public String getCharsetFor(Reader reader) throws CoreException {
+ public String getCharsetFor(Reader reader) {
throw new UnsupportedOperationException();
}
/** {@inheritDoc} */
- public IContentDescription getContentDescription() throws CoreException {
+ public IContentDescription getContentDescription() {
throw new UnsupportedOperationException();
}
/** {@inheritDoc} */
- public InputStream getContents() throws CoreException {
+ public InputStream getContents() {
throw new UnsupportedOperationException();
}
/** {@inheritDoc} */
- public InputStream getContents(boolean force) throws CoreException {
+ public InputStream getContents(boolean force) {
throw new UnsupportedOperationException();
}
/** {@inheritDoc} */
- public int getEncoding() throws CoreException {
+ @Deprecated public int getEncoding() {
throw new UnsupportedOperationException();
}
@@ -214,7 +214,7 @@
}
/** {@inheritDoc} */
- public IFileState[] getHistory(IProgressMonitor monitor) throws CoreException {
+ public IFileState[] getHistory(IProgressMonitor monitor) {
throw new UnsupportedOperationException();
}
@@ -259,12 +259,12 @@
}
/** {@inheritDoc} */
- public Map<QualifiedName, String> getPersistentProperties() throws CoreException {
+ public Map<QualifiedName, String> getPersistentProperties() {
throw new UnsupportedOperationException();
}
/** {@inheritDoc} */
- public String getPersistentProperty(QualifiedName key) throws CoreException {
+ public String getPersistentProperty(QualifiedName key) {
throw new UnsupportedOperationException();
}
@@ -294,12 +294,12 @@
}
/** {@inheritDoc} */
- public Map<QualifiedName, Object> getSessionProperties() throws CoreException {
+ public Map<QualifiedName, Object> getSessionProperties() {
throw new UnsupportedOperationException();
}
/** {@inheritDoc} */
- public Object getSessionProperty(QualifiedName key) throws CoreException {
+ public Object getSessionProperty(QualifiedName key) {
throw new UnsupportedOperationException();
}
@@ -354,7 +354,7 @@
}
/** {@inheritDoc} */
- public boolean isLocal(int depth) {
+ @Deprecated public boolean isLocal(int depth) {
throw new UnsupportedOperationException();
}
@@ -390,125 +390,125 @@
/** {@inheritDoc} */
public void move(IPath destination, boolean force, boolean keepHistory, IProgressMonitor monitor)
- throws CoreException {
+ {
throw new UnsupportedOperationException();
}
/** {@inheritDoc} */
- public void move(IPath destination, boolean force, IProgressMonitor monitor) throws CoreException {
+ public void move(IPath destination, boolean force, IProgressMonitor monitor) {
throw new UnsupportedOperationException();
}
/** {@inheritDoc} */
- public void move(IPath destination, int updateFlags, IProgressMonitor monitor) throws CoreException {
+ public void move(IPath destination, int updateFlags, IProgressMonitor monitor) {
throw new UnsupportedOperationException();
}
/** {@inheritDoc} */
public void move(IProjectDescription description, boolean force, boolean keepHistory, IProgressMonitor monitor)
- throws CoreException {
+ {
throw new UnsupportedOperationException();
}
/** {@inheritDoc} */
- public void move(IProjectDescription description, int updateFlags, IProgressMonitor monitor) throws CoreException {
+ public void move(IProjectDescription description, int updateFlags, IProgressMonitor monitor) {
throw new UnsupportedOperationException();
}
/** {@inheritDoc} */
- public void refreshLocal(int depth, IProgressMonitor monitor) throws CoreException {
+ public void refreshLocal(int depth, IProgressMonitor monitor) {
throw new UnsupportedOperationException();
}
/** {@inheritDoc} */
- public void revertModificationStamp(long value) throws CoreException {
+ public void revertModificationStamp(long value) {
throw new UnsupportedOperationException();
}
/** {@inheritDoc} */
- public void setCharset(String newCharset) throws CoreException {
+ @Deprecated public void setCharset(String newCharset) {
throw new UnsupportedOperationException();
}
/** {@inheritDoc} */
- public void setCharset(String newCharset, IProgressMonitor monitor) throws CoreException {
+ public void setCharset(String newCharset, IProgressMonitor monitor) {
throw new UnsupportedOperationException();
}
/** {@inheritDoc} */
public void setContents(IFileState source, boolean force, boolean keepHistory, IProgressMonitor monitor)
- throws CoreException {
+ {
throw new UnsupportedOperationException();
}
/** {@inheritDoc} */
- public void setContents(IFileState source, int updateFlags, IProgressMonitor monitor) throws CoreException {
+ public void setContents(IFileState source, int updateFlags, IProgressMonitor monitor) {
throw new UnsupportedOperationException();
}
/** {@inheritDoc} */
public void setContents(InputStream source, boolean force, boolean keepHistory, IProgressMonitor monitor)
- throws CoreException {
+ {
throw new UnsupportedOperationException();
}
/** {@inheritDoc} */
- public void setContents(InputStream source, int updateFlags, IProgressMonitor monitor) throws CoreException {
+ public void setContents(InputStream source, int updateFlags, IProgressMonitor monitor) {
throw new UnsupportedOperationException();
}
/** {@inheritDoc} */
- public void setDerived(boolean isDerived) throws CoreException {
+ @Deprecated public void setDerived(boolean isDerived) {
throw new UnsupportedOperationException();
}
/** {@inheritDoc} */
- public void setDerived(boolean isDerived, IProgressMonitor monitor) throws CoreException {
+ public void setDerived(boolean isDerived, IProgressMonitor monitor) {
throw new UnsupportedOperationException();
}
/** {@inheritDoc} */
- public void setHidden(boolean isHidden) throws CoreException {
+ public void setHidden(boolean isHidden) {
throw new UnsupportedOperationException();
}
/** {@inheritDoc} */
- public void setLocal(boolean flag, int depth, IProgressMonitor monitor) throws CoreException {
+ @Deprecated public void setLocal(boolean flag, int depth, IProgressMonitor monitor) {
throw new UnsupportedOperationException();
}
/** {@inheritDoc} */
- public long setLocalTimeStamp(long value) throws CoreException {
+ public long setLocalTimeStamp(long value) {
throw new UnsupportedOperationException();
}
/** {@inheritDoc} */
- public void setPersistentProperty(QualifiedName key, String value) throws CoreException {
+ public void setPersistentProperty(QualifiedName key, String value) {
throw new UnsupportedOperationException();
}
/** {@inheritDoc} */
- public void setReadOnly(boolean readOnly) {
+ @Deprecated public void setReadOnly(boolean readOnly) {
throw new UnsupportedOperationException();
}
/** {@inheritDoc} */
- public void setResourceAttributes(ResourceAttributes attributes) throws CoreException {
+ public void setResourceAttributes(ResourceAttributes attributes) {
throw new UnsupportedOperationException();
}
/** {@inheritDoc} */
- public void setSessionProperty(QualifiedName key, Object value) throws CoreException {
+ public void setSessionProperty(QualifiedName key, Object value) {
throw new UnsupportedOperationException();
}
/** {@inheritDoc} */
- public void setTeamPrivateMember(boolean isTeamPrivate) throws CoreException {
+ public void setTeamPrivateMember(boolean isTeamPrivate) {
throw new UnsupportedOperationException();
}
/** {@inheritDoc} */
- public void touch(IProgressMonitor monitor) throws CoreException {
+ public void touch(IProgressMonitor monitor) {
throw new UnsupportedOperationException();
}
@@ -523,7 +523,7 @@
return unmodifiableList(markers);
}
- public void addMarker(MarkerStub marker) throws CoreException {
+ public void addMarker(MarkerStub marker) {
String type = marker.getType();
List<MarkerStub> markers = markersByType.get(type);
if (markers == null) {
diff --git a/com.google.eclipse.protobuf.junit/src/com/google/eclipse/protobuf/junit/stubs/MarkerStub.java b/com.google.eclipse.protobuf.junit/src/com/google/eclipse/protobuf/junit/stubs/MarkerStub.java
index ee384e6..8386a8a 100644
--- a/com.google.eclipse.protobuf.junit/src/com/google/eclipse/protobuf/junit/stubs/MarkerStub.java
+++ b/com.google.eclipse.protobuf.junit/src/com/google/eclipse/protobuf/junit/stubs/MarkerStub.java
@@ -1,6 +1,9 @@
/*
- * Copyright (c) 2011 Google Inc. All rights reserved. This program and the accompanying materials are made available
- * under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at
+ * Copyright (c) 2011 Google Inc.
+ *
+ * All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse
+ * Public License v1.0 which accompanies this distribution, and is available at
+ *
* http://www.eclipse.org/legal/epl-v10.html
*/
package com.google.eclipse.protobuf.junit.stubs;
@@ -11,7 +14,6 @@
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IResource;
-import org.eclipse.core.runtime.CoreException;
/**
* @author alruiz@google.com (Alex Ruiz)
@@ -22,7 +24,7 @@
private final String type;
private final long creationTime;
- public static MarkerStub error(String type, String description, int lineNumber) throws CoreException {
+ public static MarkerStub error(String type, String description, int lineNumber) {
MarkerStub marker = new MarkerStub(type);
marker.setAttribute(SEVERITY, SEVERITY_ERROR);
marker.setAttribute(MESSAGE, description);
@@ -41,7 +43,7 @@
}
/** {@inheritDoc} */
- public void delete() throws CoreException {
+ public void delete() {
throw new UnsupportedOperationException();
}
@@ -51,7 +53,7 @@
}
/** {@inheritDoc} */
- public Object getAttribute(String attributeName) throws CoreException {
+ public Object getAttribute(String attributeName) {
return attributes.get(attributeName);
}
@@ -77,12 +79,12 @@
}
/** {@inheritDoc} */
- public Map<String, Object> getAttributes() throws CoreException {
+ public Map<String, Object> getAttributes() {
return unmodifiableMap(attributes);
}
/** {@inheritDoc} */
- public Object[] getAttributes(String[] attributeNames) throws CoreException {
+ public Object[] getAttributes(String[] attributeNames) {
List<Object> values = new ArrayList<Object>();
for (String name : attributeNames)
values.add(attributes.get(name));
@@ -90,7 +92,7 @@
}
/** {@inheritDoc} */
- public long getCreationTime() throws CoreException {
+ public long getCreationTime() {
return creationTime;
}
@@ -105,49 +107,49 @@
}
/** {@inheritDoc} */
- public String getType() throws CoreException {
+ public String getType() {
return type;
}
/** {@inheritDoc} */
- public boolean isSubtypeOf(String superType) throws CoreException {
+ public boolean isSubtypeOf(String superType) {
throw new UnsupportedOperationException();
}
/** {@inheritDoc} */
- public void setAttribute(String attributeName, int value) throws CoreException {
+ public void setAttribute(String attributeName, int value) {
attributes.put(attributeName, value);
}
/** {@inheritDoc} */
- public void setAttribute(String attributeName, Object value) throws CoreException {
+ public void setAttribute(String attributeName, Object value) {
attributes.put(attributeName, value);
}
/** {@inheritDoc} */
- public void setAttribute(String attributeName, boolean value) throws CoreException {
+ public void setAttribute(String attributeName, boolean value) {
attributes.put(attributeName, value);
}
/** {@inheritDoc} */
- public void setAttributes(String[] attributeNames, Object[] values) throws CoreException {
+ public void setAttributes(String[] attributeNames, Object[] values) {
throw new UnsupportedOperationException();
}
/** {@inheritDoc} */
- public void setAttributes(Map<String, ? extends Object> attributes) throws CoreException {
+ public void setAttributes(Map<String, ? extends Object> attributes) {
this.attributes.putAll(attributes);
}
- public int severity() throws CoreException {
+ public int severity() {
return getAttribute(SEVERITY, -1);
}
- public String message() throws CoreException {
+ public String message() {
return (String) getAttribute(MESSAGE);
}
- public int lineNumber() throws CoreException {
+ public int lineNumber() {
return getAttribute(LINE_NUMBER, -1);
}
diff --git a/com.google.eclipse.protobuf.junit/src/com/google/eclipse/protobuf/junit/stubs/ResourceStub.java b/com.google.eclipse.protobuf.junit/src/com/google/eclipse/protobuf/junit/stubs/ResourceStub.java
new file mode 100644
index 0000000..3da6b23
--- /dev/null
+++ b/com.google.eclipse.protobuf.junit/src/com/google/eclipse/protobuf/junit/stubs/ResourceStub.java
@@ -0,0 +1,167 @@
+/*
+ * Copyright (c) 2011 Google Inc.
+ *
+ * All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse
+ * Public License v1.0 which accompanies this distribution, and is available at
+ *
+ * http://www.eclipse.org/legal/epl-v10.html
+ */
+package com.google.eclipse.protobuf.junit.stubs;
+
+import static org.eclipse.emf.common.util.URI.createURI;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.Map;
+
+import org.eclipse.emf.common.notify.Adapter;
+import org.eclipse.emf.common.notify.Notification;
+import org.eclipse.emf.common.util.*;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+
+/**
+ * @author alruiz@google.com (Alex Ruiz)
+ */
+public class ResourceStub implements Resource {
+
+ private URI uri;
+
+ public ResourceStub() {}
+
+ public ResourceStub(String uri) {
+ setURI(createURI(uri));
+ }
+
+ /** {@inheritDoc} */
+ public EList<Adapter> eAdapters() {
+ throw new UnsupportedOperationException();
+ }
+
+ /** {@inheritDoc} */
+ public boolean eDeliver() {
+ throw new UnsupportedOperationException();
+ }
+
+ /** {@inheritDoc} */
+ public void eSetDeliver(boolean deliver) {
+ throw new UnsupportedOperationException();
+ }
+
+ /** {@inheritDoc} */
+ public void eNotify(Notification notification) {
+ throw new UnsupportedOperationException();
+ }
+
+ /** {@inheritDoc} */
+ public ResourceSet getResourceSet() {
+ throw new UnsupportedOperationException();
+ }
+
+ /** {@inheritDoc} */
+ public URI getURI() {
+ return uri;
+ }
+
+ /** {@inheritDoc} */
+ public void setURI(URI uri) {
+ this.uri = uri;
+ }
+
+ /** {@inheritDoc} */
+ public long getTimeStamp() {
+ throw new UnsupportedOperationException();
+ }
+
+ /** {@inheritDoc} */
+ public void setTimeStamp(long timeStamp) {
+ throw new UnsupportedOperationException();
+ }
+
+ /** {@inheritDoc} */
+ public EList<EObject> getContents() {
+ throw new UnsupportedOperationException();
+ }
+
+ /** {@inheritDoc} */
+ public TreeIterator<EObject> getAllContents() {
+ throw new UnsupportedOperationException();
+ }
+
+ /** {@inheritDoc} */
+ public String getURIFragment(EObject eObject) {
+ throw new UnsupportedOperationException();
+ }
+
+ /** {@inheritDoc} */
+ public EObject getEObject(String uriFragment) {
+ throw new UnsupportedOperationException();
+ }
+
+ /** {@inheritDoc} */
+ public void save(Map<?, ?> options) {
+ throw new UnsupportedOperationException();
+ }
+
+ /** {@inheritDoc} */
+ public void load(Map<?, ?> options) {
+ throw new UnsupportedOperationException();
+ }
+
+ /** {@inheritDoc} */
+ public void save(OutputStream outputStream, Map<?, ?> options) {
+ throw new UnsupportedOperationException();
+ }
+
+ /** {@inheritDoc} */
+ public void load(InputStream inputStream, Map<?, ?> options) {
+ throw new UnsupportedOperationException();
+ }
+
+ /** {@inheritDoc} */
+ public boolean isTrackingModification() {
+ throw new UnsupportedOperationException();
+ }
+
+ /** {@inheritDoc} */
+ public void setTrackingModification(boolean isTrackingModification) {
+ throw new UnsupportedOperationException();
+ }
+
+ /** {@inheritDoc} */
+ public boolean isModified() {
+ throw new UnsupportedOperationException();
+ }
+
+ /** {@inheritDoc} */
+ public void setModified(boolean isModified) {
+ throw new UnsupportedOperationException();
+ }
+
+ /** {@inheritDoc} */
+ public boolean isLoaded() {
+ throw new UnsupportedOperationException();
+ }
+
+ /** {@inheritDoc} */
+ public void unload() {
+ throw new UnsupportedOperationException();
+ }
+
+ /** {@inheritDoc} */
+ public void delete(Map<?, ?> options) {
+ throw new UnsupportedOperationException();
+ }
+
+ /** {@inheritDoc} */
+ public EList<Diagnostic> getErrors() {
+ throw new UnsupportedOperationException();
+ }
+
+ /** {@inheritDoc} */
+ public EList<Diagnostic> getWarnings() {
+ throw new UnsupportedOperationException();
+ }
+
+}
diff --git a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/scoping/FileUriResolver_resolveUri_Test.java b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/scoping/FileUriResolver_resolveUri_Test.java
index 73a3305..bd05dac 100644
--- a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/scoping/FileUriResolver_resolveUri_Test.java
+++ b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/scoping/FileUriResolver_resolveUri_Test.java
@@ -8,14 +8,21 @@
*/
package com.google.eclipse.protobuf.ui.scoping;
-import static org.eclipse.emf.common.util.URI.createURI;
+import static com.google.eclipse.protobuf.ui.preferences.paths.FileResolutionType.SINGLE_FOLDER;
+import static org.hamcrest.core.IsEqual.equalTo;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.*;
+import org.eclipse.core.resources.IProject;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.junit.*;
import com.google.eclipse.protobuf.junit.core.XtextRule;
+import com.google.eclipse.protobuf.junit.stubs.ResourceStub;
import com.google.eclipse.protobuf.scoping.IFileUriResolver;
+import com.google.eclipse.protobuf.ui.preferences.paths.*;
import com.google.inject.*;
/**
@@ -27,51 +34,60 @@
@Rule public XtextRule xtext = new XtextRule();
- private URI resourceUri;
- private ResourcesStub resources;
+ private Resource resource;
+ private PreferenceReader preferenceReader;
+ private Preferences preferences;
+ private IProject project;
+ private Resources resources;
+
private FileUriResolver resolver;
@Before public void setUp() {
- resources = new ResourcesStub();
- resources.resourceShouldAlwaysExist = true;
+ resource = new ResourceStub("platform:/resource/src/proto/person.proto");
+ preferenceReader = mock(PreferenceReader.class);
+ preferences = mock(Preferences.class);
+ project = mock(IProject.class);
+ resources = mock(Resources.class);
Module module = new Module() {
public void configure(Binder binder) {
+ binder.bind(PreferenceReader.class).toInstance(preferenceReader);
binder.bind(Resources.class).toInstance(resources);
binder.bind(IFileUriResolver.class).to(FileUriResolver.class);
}
};
Injector injector = xtext.injector().createChildInjector(module);
- resourceUri = createURI("platform:/resource/src/proto/person.proto");
resolver = (FileUriResolver) injector.getInstance(IFileUriResolver.class);
}
@Test public void should_resolve_import_URI_if_missing_scheme() {
- resolver.resolveUri("folder1/address.proto", null);
-// String uri = resolver.resolveUri("folder1/address.proto", resourceUri);
-// assertThat(uri, equalTo("platform:/resource/src/proto/folder1/address.proto"));
+ callStubs(SINGLE_FOLDER, true);
+ String resolved = resolver.resolveUri("folder1/address.proto", resource);
+ assertThat(resolved, equalTo("platform:/resource/src/proto/folder1/address.proto"));
}
-//
-// @Test public void should_not_resolve_import_URI_if_not_missing_scheme() {
-// String originalUri = "platform:/resource/src/proto/folder1/address.proto";
-// String uri = resolver.resolveUri(originalUri, resourceUri, resources);
-// assertThat(uri, equalTo(originalUri));
-// }
-//
-// @Test public void should_resolve_import_URI_even_if_overlapping_folders_with_resource_URI() {
-// String uri = resolver.resolveUri("src/proto/folder1/address.proto", resourceUri);
-// assertThat(uri, equalTo("platform:/resource/src/proto/folder1/address.proto"));
-// }
-//
-// @Test public void should_resolve_import_URI_even_if_overlapping_one_folder_only_with_resource_URI() {
-// String uri = resolver.resolveUri("src/proto/read-only/address.proto", resourceUri);
-// assertThat(uri, equalTo("platform:/resource/src/proto/read-only/address.proto"));
-// }
-//
- private static class ResourcesStub extends Resources {
- boolean resourceShouldAlwaysExist;
-
- @Override public boolean fileExists(URI uri) {
- return resourceShouldAlwaysExist;
- }
+
+ @Test public void should_not_resolve_import_URI_if_not_missing_scheme() {
+ callStubs(SINGLE_FOLDER, true);
+ String original = "platform:/resource/src/proto/folder1/address.proto";
+ String resolved = resolver.resolveUri(original, resource);
+ assertThat(resolved, equalTo(original));
+ }
+
+ @Test public void should_resolve_import_URI_even_if_overlapping_folders_with_resource_URI() {
+ callStubs(SINGLE_FOLDER, true);
+ String resolved = resolver.resolveUri("src/proto/folder1/address.proto", resource);
+ assertThat(resolved, equalTo("platform:/resource/src/proto/folder1/address.proto"));
+ }
+
+ @Test public void should_resolve_import_URI_even_if_overlapping_one_folder_only_with_resource_URI() {
+ callStubs(SINGLE_FOLDER, true);
+ String resolved = resolver.resolveUri("src/proto/read-only/address.proto", resource);
+ assertThat(resolved, equalTo("platform:/resource/src/proto/read-only/address.proto"));
+ }
+
+ private void callStubs(FileResolutionType type, boolean resolvedUriExists) {
+ when(resources.project(resource)).thenReturn(project);
+ when(preferenceReader.readFromPrefereceStore(project)).thenReturn(preferences);
+ when(preferences.fileResolutionType()).thenReturn(type);
+ when(resources.fileExists(any(URI.class))).thenReturn(resolvedUriExists);
}
}
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/PreferenceReader.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/PreferenceReader.java
new file mode 100644
index 0000000..3f7cb03
--- /dev/null
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/PreferenceReader.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2011 Google Inc.
+ *
+ * All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse
+ * Public License v1.0 which accompanies this distribution, and is available at
+ *
+ * http://www.eclipse.org/legal/epl-v10.html
+ */
+package com.google.eclipse.protobuf.ui.preferences.paths;
+
+import static com.google.eclipse.protobuf.ui.preferences.paths.PreferenceNames.ENABLE_PROJECT_SETTINGS;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.xtext.ui.editor.preferences.IPreferenceStoreAccess;
+
+import com.google.inject.Inject;
+
+/**
+ * Reads "paths" preferences.
+ *
+ * @author alruiz@google.com (Alex Ruiz)
+ */
+public class PreferenceReader {
+
+ @Inject private IPreferenceStoreAccess storeAccess;
+
+ public Preferences readFromPrefereceStore(IProject project) {
+ IPreferenceStore store = storeAccess.getWritablePreferenceStore(project);
+ boolean useProject = store.getBoolean(ENABLE_PROJECT_SETTINGS);
+ if (!useProject) store = storeAccess.getWritablePreferenceStore();
+ return new Preferences(store);
+ }
+}
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/Preferences.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/Preferences.java
index a478679..8613469 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/Preferences.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/Preferences.java
@@ -9,16 +9,14 @@
package com.google.eclipse.protobuf.ui.preferences.paths;
import static com.google.eclipse.protobuf.ui.preferences.paths.FileResolutionType.SINGLE_FOLDER;
-import static com.google.eclipse.protobuf.ui.preferences.paths.PreferenceNames.*;
+import static com.google.eclipse.protobuf.ui.preferences.paths.PreferenceNames.FOLDER_NAMES;
import static com.google.eclipse.protobuf.ui.util.Strings.CSV_PATTERN;
import static java.util.Arrays.asList;
import static java.util.Collections.*;
import java.util.List;
-import org.eclipse.core.resources.IProject;
import org.eclipse.jface.preference.IPreferenceStore;
-import org.eclipse.xtext.ui.editor.preferences.IPreferenceStoreAccess;
/**
* Paths preferences, retrieved from an <code>{@link IPreferenceStore}</code>.
@@ -27,17 +25,10 @@
*/
public class Preferences {
- public final FileResolutionType fileResolutionType;
- public final List<String> folderNames;
+ private final FileResolutionType fileResolutionType;
+ private final List<String> folderNames;
- public static Preferences loadPreferences(IPreferenceStoreAccess access, IProject project) {
- IPreferenceStore store = access.getWritablePreferenceStore(project);
- boolean useProjectPreferences = store.getBoolean(ENABLE_PROJECT_SETTINGS);
- if (!useProjectPreferences) store = access.getWritablePreferenceStore();
- return new Preferences(store);
- }
-
- private Preferences(IPreferenceStore store) {
+ Preferences(IPreferenceStore store) {
fileResolutionType = FileResolutionType.find(store);
folderNames = folderNames(fileResolutionType, store);
}
@@ -47,4 +38,12 @@
String[] folderNames = store.getString(FOLDER_NAMES).split(CSV_PATTERN);
return unmodifiableList(asList(folderNames));
}
+
+ public FileResolutionType fileResolutionType() {
+ return fileResolutionType;
+ }
+
+ public List<String> folderNames() {
+ return folderNames;
+ }
}
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 5249e26..e5e6491 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
@@ -17,10 +17,10 @@
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.xtext.ui.editor.preferences.IPreferenceStoreAccess;
import org.eclipse.xtext.util.Pair;
import com.google.eclipse.protobuf.scoping.IFileUriResolver;
+import com.google.eclipse.protobuf.ui.preferences.paths.PreferenceReader;
import com.google.eclipse.protobuf.ui.preferences.paths.Preferences;
import com.google.inject.Inject;
@@ -31,7 +31,7 @@
private static final String SEPARATOR = "/";
- @Inject private IPreferenceStoreAccess access;
+ @Inject private PreferenceReader preferenceReader;
@Inject private Resources resources;
/*
@@ -52,23 +52,22 @@
public String resolveUri(String importUri, Resource declaringResource) {
if (importUri.startsWith(PREFIX)) return importUri;
Pair<String, List<String>> importUriPair = pair(importUri, createURI(importUri).segmentsList());
+ Preferences preferences = preferenceReader.readFromPrefereceStore(resources.project(declaringResource));
URI resourceUri = declaringResource.getURI();
- Preferences preferences = Preferences.loadPreferences(access, resources.project(resourceUri));
- String fixed = fixUri(importUriPair, resourceUri, preferences);
+ String fixed = resolveUri(importUriPair, resourceUri, preferences);
System.out.println(resourceUri + " : " + importUri + " : " + fixed);
if (fixed == null) return importUri;
return fixed;
}
- private String fixUri(Pair<String, List<String>> importUri, URI resourceUri, Preferences preferences) {
+ private String resolveUri(Pair<String, List<String>> importUri, URI resourceUri, Preferences preferences) {
List<String> segments = removeFirstAndLast(resourceUri.segmentsList());
- if (preferences.fileResolutionType.equals(SINGLE_FOLDER)) {
- return fixUri(importUri, segments);
+ if (preferences.fileResolutionType().equals(SINGLE_FOLDER)) {
+ return resolveUri(importUri, segments);
}
- List<String> folderNames = preferences.folderNames;
- for (String folderName : folderNames) {
+ for (String folderName : preferences.folderNames()) {
segments.set(1, folderName);
- String fixed = fixUri(importUri, segments);
+ String fixed = resolveUri(importUri, segments);
if (fixed != null) return fixed;
}
return null;
@@ -82,7 +81,7 @@
return newList;
}
- private String fixUri(Pair<String, List<String>> importUri, List<String> resourceUri) {
+ private String resolveUri(Pair<String, List<String>> importUri, List<String> resourceUri) {
StringBuilder prefix = new StringBuilder();
// prefix.append(PREFIX);
String firstSegment = importUri.getSecond().get(0);
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/scoping/Resources.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/scoping/Resources.java
index b252395..876f0d4 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/scoping/Resources.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/scoping/Resources.java
@@ -12,6 +12,7 @@
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.Resource;
/**
* Utility methods related to resources (e.g. files, directories.)
@@ -21,12 +22,12 @@
public class Resources {
/**
- * Returns the project that contains the resource at the given URI.
- * @param fileUri the URI of a resource.
- * @return the project that contains the resource at the given URI.
+ * Returns the project that contains the given resource.
+ * @param resource the given resource.
+ * @return the project that contains the given resource.
*/
- public IProject project(URI fileUri) {
- return file(fileUri).getProject();
+ public IProject project(Resource resource) {
+ return file(resource.getURI()).getProject();
}
/**
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/IFileUriResolver.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/IFileUriResolver.java
index 044a1a2..1c0a857 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/IFileUriResolver.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/IFileUriResolver.java
@@ -32,8 +32,7 @@
*/
String resolveUri(String importUri, Resource declaringResource);
- public static class NullFileUriResolver implements IFileUriResolver {
-
+ class NullFileUriResolver implements IFileUriResolver {
public String resolveUri(String importUri, Resource declaringResource) {
throw new UnsupportedOperationException();
}