In progress: [ Issue 40 ] Add support for import resolution across multiple folders https://code.google.com/p/protobuf-dt/issues/detail?id=40 Moved ProtobufImportUriFixer to the 'com.google.eclipse.protobuf.ui' project to be able to use 'import paths' preferences.
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/scoping/ImportUriFixer_fixUri_Test.java b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/scoping/ProtobufImportUriFixer_fixUri_Test.java similarity index 91% rename from com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/scoping/ImportUriFixer_fixUri_Test.java rename to com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/scoping/ProtobufImportUriFixer_fixUri_Test.java index a168d75..4cf9927 100644 --- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/scoping/ImportUriFixer_fixUri_Test.java +++ b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/scoping/ProtobufImportUriFixer_fixUri_Test.java
@@ -6,7 +6,7 @@ * * http://www.eclipse.org/legal/epl-v10.html */ -package com.google.eclipse.protobuf.scoping; +package com.google.eclipse.protobuf.ui.scoping; import static org.eclipse.emf.common.util.URI.createURI; import static org.hamcrest.core.IsEqual.equalTo; @@ -16,12 +16,14 @@ import org.junit.Before; import org.junit.Test; +import com.google.eclipse.protobuf.scoping.ResourceChecker; + /** * Tests for <code>{@link ProtobufImportUriFixer#fixUri(String, URI, ResourceChecker)}</code>. * * @author alruiz@google.com (Alex Ruiz) */ -public class ImportUriFixer_fixUri_Test { +public class ProtobufImportUriFixer_fixUri_Test { private URI resourceUri; private ResourceCheckerStub resourceChecker; @@ -62,7 +64,7 @@ super(null); } - @Override boolean resourceExists(String uri) { + @Override public boolean resourceExists(String uri) { return resourceShouldAlwaysExist; } }
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/ProtobufUiModule.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/ProtobufUiModule.java index 8a14bb3..322cdcc 100644 --- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/ProtobufUiModule.java +++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/ProtobufUiModule.java
@@ -16,11 +16,13 @@ import org.eclipse.xtext.ui.editor.outline.actions.IOutlineContribution; import org.eclipse.xtext.ui.editor.preferences.IPreferenceStoreInitializer; +import com.google.eclipse.protobuf.scoping.ImportUriFixer; import com.google.eclipse.protobuf.ui.builder.AutoAddNatureEditorCallback; import com.google.eclipse.protobuf.ui.outline.LinkWithEditor; import com.google.eclipse.protobuf.ui.outline.ProtobufOutlinePage; import com.google.eclipse.protobuf.ui.preferences.compiler.CompilerPreferencesInitializer; import com.google.eclipse.protobuf.ui.preferences.paths.PathsPreferencesInitializer; +import com.google.eclipse.protobuf.ui.scoping.ProtobufImportUriFixer; import com.google.inject.Binder; /** @@ -61,4 +63,8 @@ Class<? extends IPreferenceStoreInitializer> initializerType) { binder.bind(IPreferenceStoreInitializer.class).annotatedWith(named(name)).to(initializerType); } + + public void configureImportUriResolver(Binder binder) { + binder.bind(ImportUriFixer.class).to(ProtobufImportUriFixer.class); + } }
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/ProtobufImportUriFixer.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/scoping/ProtobufImportUriFixer.java similarity index 92% rename from com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/ProtobufImportUriFixer.java rename to com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/scoping/ProtobufImportUriFixer.java index d1b9360..970c2fd 100644 --- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/ProtobufImportUriFixer.java +++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/scoping/ProtobufImportUriFixer.java
@@ -6,7 +6,7 @@ * * http://www.eclipse.org/legal/epl-v10.html */ -package com.google.eclipse.protobuf.scoping; +package com.google.eclipse.protobuf.ui.scoping; import static org.eclipse.emf.common.util.URI.createURI; import static org.eclipse.xtext.util.Tuples.pair; @@ -17,13 +17,14 @@ import org.eclipse.emf.common.util.URI; import org.eclipse.xtext.util.Pair; +import com.google.eclipse.protobuf.scoping.ImportUriFixer; +import com.google.eclipse.protobuf.scoping.ResourceChecker; + /** * @author alruiz@google.com (Alex Ruiz) */ -public class ProtobufImportUriFixer { +public class ProtobufImportUriFixer implements ImportUriFixer { - public static final String PREFIX = "platform:/resource"; - private static final String SEPARATOR = "/"; /*
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/ImportUriFixer.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/ImportUriFixer.java new file mode 100644 index 0000000..5337acd --- /dev/null +++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/ImportUriFixer.java
@@ -0,0 +1,35 @@ +/* + * 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.scoping; + +import org.eclipse.emf.common.util.URI; + +import com.google.eclipse.protobuf.protobuf.Import; + +/** + * Fixes partial URIs in <code>{@link Import}</code>s by resolving them to existing files with matching URIs. + * + * @author alruiz@google.com (Alex Ruiz) + */ +public interface ImportUriFixer { + + /** + * Prefix present in complete import URIs. + */ + String PREFIX = "platform:/resource"; + + /** + * Returns a "fixed" full URI based on the given partial URI. + * @param importUri the partial URI (comes from a {@code Import}.) + * @param resourceUri the URI of the resource declaring the import. + * @param checker indicates whether the resolved URI belongs to an existing file. + * @return the "fixed" full URI. + */ + String fixUri(String importUri, URI resourceUri, ResourceChecker checker); +} \ No newline at end of file
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/ProtobufImportUriResolver.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/ProtobufImportUriResolver.java index e35f303..4f4f764 100644 --- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/ProtobufImportUriResolver.java +++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/ProtobufImportUriResolver.java
@@ -8,7 +8,7 @@ */ package com.google.eclipse.protobuf.scoping; -import static com.google.eclipse.protobuf.scoping.ProtobufImportUriFixer.PREFIX; +import static com.google.eclipse.protobuf.scoping.ImportUriFixer.PREFIX; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.resource.Resource; @@ -30,7 +30,7 @@ */ public class ProtobufImportUriResolver extends ImportUriResolver { - @Inject private ProtobufImportUriFixer uriFixer; + @Inject private ImportUriFixer uriFixer; /** * Prefix used by EMF for resource URIs: "platform:/resource/".
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/ResourceChecker.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/ResourceChecker.java index 4742208..5231cd3 100644 --- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/ResourceChecker.java +++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/ResourceChecker.java
@@ -14,17 +14,24 @@ import org.eclipse.emf.ecore.resource.ResourceSet; /** + * Verifies that resources exist. + * * @author alruiz@google.com (Alex Ruiz) */ -class ResourceChecker { +public class ResourceChecker { private final ResourceSet resourceSet; - ResourceChecker(ResourceSet resourceSet) { + public ResourceChecker(ResourceSet resourceSet) { this.resourceSet = resourceSet; } - boolean resourceExists(String uri) { + /** + * Indicates whether the given URI belongs to an existing resource. + * @param uri the URI to check, as a {@code String}. + * @return {@code true} if the given URI belongs to an existing resource, {@code false} otherwise. + */ + public boolean resourceExists(String uri) { Resource resource = resourceSet.getResource(createURI(uri), true); return resource != null && resource.getErrors().isEmpty(); }