Added namespace support to scoping.
Created scoping fragment ProtobufImportNamespacesScopingFragment that
delegates local scoping to
ProtobufImportedNamespaceAwareLocalScopeProvider
and global scoping to ProtobufImportUriGlobalScopeProvider.
Change-Id: Ic7773f99845050ab10f3ca9d48359d14da8f1742
diff --git a/com.google.eclipse.protobuf.generator/META-INF/MANIFEST.MF b/com.google.eclipse.protobuf.generator/META-INF/MANIFEST.MF
index 173239d..bb2b6b6 100644
--- a/com.google.eclipse.protobuf.generator/META-INF/MANIFEST.MF
+++ b/com.google.eclipse.protobuf.generator/META-INF/MANIFEST.MF
@@ -21,3 +21,4 @@
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-ActivationPolicy: lazy
Export-Package: com.google.eclipse.protobuf
+Import-Package: com.google.eclipse.protobuf.scoping
diff --git a/com.google.eclipse.protobuf.generator/bin/.project b/com.google.eclipse.protobuf.generator/bin/.project
deleted file mode 100644
index de89a7e..0000000
--- a/com.google.eclipse.protobuf.generator/bin/.project
+++ /dev/null
@@ -1,34 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<projectDescription>
- <name>com.google.eclipse.protobuf.generator</name>
- <comment></comment>
- <projects>
- </projects>
- <buildSpec>
- <buildCommand>
- <name>org.eclipse.xtext.ui.shared.xtextBuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>org.eclipse.jdt.core.javabuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>org.eclipse.pde.ManifestBuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>org.eclipse.pde.SchemaBuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- </buildSpec>
- <natures>
- <nature>org.eclipse.pde.PluginNature</nature>
- <nature>org.eclipse.jdt.core.javanature</nature>
- <nature>org.eclipse.xtext.ui.shared.xtextNature</nature>
- </natures>
-</projectDescription>
diff --git a/com.google.eclipse.protobuf.generator/src/com/google/eclipse/protobuf/GenerateProtobuf.mwe2 b/com.google.eclipse.protobuf.generator/src/com/google/eclipse/protobuf/GenerateProtobuf.mwe2
index 097852b..473a016 100644
--- a/com.google.eclipse.protobuf.generator/src/com/google/eclipse/protobuf/GenerateProtobuf.mwe2
+++ b/com.google.eclipse.protobuf.generator/src/com/google/eclipse/protobuf/GenerateProtobuf.mwe2
@@ -42,14 +42,14 @@
uri = grammarURI
fileExtensions = file.extensions
- // Java API to access grammar elements (required by several other fragments)
+ // Java APIto access grammar elements (required by several other fragments)
fragment = grammarAccess.GrammarAccessFragment {}
- // generates Java API for the generated EPackages
+ // generates Java APIfor the generated EPackages
fragment = ecore.EMFGeneratorFragment {
// referencedGenModels = "uri to genmodel, uri to next genmodel"
}
-
+
// Serializer 2.0
fragment = serializer.SerializerFragment {
generateStub = false
@@ -58,7 +58,7 @@
// the serialization component
// fragment = parseTreeConstructor.ParseTreeConstructorFragment {}
- // a custom ResourceFactory for use with EMF
+ // a custom ResourceFactory for use with EMF
fragment = resourceFactory.ResourceFactoryFragment {
fileExtensions = file.extensions
}
@@ -70,7 +70,7 @@
// }
}
- // java-based API for validation
+ // java-based APIfor validation
fragment = validation.JavaValidatorFragment {
// composedCheck = "org.eclipse.xtext.validation.ImportUriValidator"
// composedCheck = "org.eclipse.xtext.validation.NamesAreUniqueValidator"
@@ -81,41 +81,41 @@
// fragment = scoping.ImportURIScopingFragment {}
// fragment = exporting.SimpleNamesFragment {}
- // scoping and exporting API
- fragment = scoping.ImportNamespacesScopingFragment {}
+ // scoping and exporting API
+ fragment = scoping.ProtobufImportNamespacesScopingFragment {}
fragment = exporting.QualifiedNamesFragment {}
fragment = builder.BuilderIntegrationFragment {}
- // formatter API
+ // formatter API
fragment = formatting.FormatterFragment {}
- // labeling API
+ // labeling API
fragment = labeling.LabelProviderFragment {}
- // outline API
+ // outline API
fragment = outline.OutlineTreeProviderFragment {}
fragment = outline.QuickOutlineFragment {}
- // quickfix API
+ // quickfix API
fragment = quickfix.QuickfixProviderFragment {}
// rename refactoring
fragment = refactoring.RefactorElementNameFragment {}
- // content assist API
+ // content assist API
fragment = contentAssist.JavaBasedContentAssistFragment {}
- // generates a more lightweight Antlr parser and lexer tailored for content assist
+ // generates a more lightweight Antlr parser and lexer tailored for content assist
fragment = parser.antlr.XtextAntlrUiGeneratorFragment {
// options = {
// backtrack = true
// }
}
- // project wizard (optional)
+ // project wizard (optional)
// fragment = projectWizard.SimpleProjectWizardFragment {
- // generatorProjectName = "${projectName}.generator"
- // modelFileExtension = file.extensions
+ // generatorProjectName = "${projectName}.generator"
+ // modelFileExtension = file.extensions
// }
}
}
diff --git a/com.google.eclipse.protobuf.generator/src/com/google/eclipse/protobuf/Protobuf.xtext b/com.google.eclipse.protobuf.generator/src/com/google/eclipse/protobuf/Protobuf.xtext
index 2a39ba6..2b99ea7 100644
--- a/com.google.eclipse.protobuf.generator/src/com/google/eclipse/protobuf/Protobuf.xtext
+++ b/com.google.eclipse.protobuf.generator/src/com/google/eclipse/protobuf/Protobuf.xtext
@@ -24,7 +24,7 @@
Package | Import | Option | ComplexType | TypeExtension | Service;
Package:
- 'package' name=PackageName (';')+;
+ 'package' importedNamespace=PackageName (';')+;
PackageName:
IdOrReservedWord ('.' IdOrReservedWord)*;
diff --git a/com.google.eclipse.protobuf.generator/src/com/google/eclipse/protobuf/scoping/ProtobufImportNamespacesScopingFragment.java b/com.google.eclipse.protobuf.generator/src/com/google/eclipse/protobuf/scoping/ProtobufImportNamespacesScopingFragment.java
new file mode 100644
index 0000000..497b6cc
--- /dev/null
+++ b/com.google.eclipse.protobuf.generator/src/com/google/eclipse/protobuf/scoping/ProtobufImportNamespacesScopingFragment.java
@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2016 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.xtext.generator.scoping.AbstractScopingFragment;
+import org.eclipse.xtext.scoping.IGlobalScopeProvider;
+import org.eclipse.xtext.scoping.IScopeProvider;
+
+public class ProtobufImportNamespacesScopingFragment extends AbstractScopingFragment {
+ @Override
+ protected Class<? extends IGlobalScopeProvider> getGlobalScopeProvider() {
+ return ProtobufImportUriGlobalScopeProvider.class;
+ }
+
+ @Override
+ protected Class<? extends IScopeProvider> getLocalScopeProvider() {
+ return ProtobufImportedNamespaceAwareLocalScopeProvider.class;
+ }
+}
diff --git a/com.google.eclipse.protobuf.generator/src/com/google/eclipse/protobuf/scoping/ProtobufImportNamespacesScopingFragment.xpt b/com.google.eclipse.protobuf.generator/src/com/google/eclipse/protobuf/scoping/ProtobufImportNamespacesScopingFragment.xpt
new file mode 100644
index 0000000..23c6cc5
--- /dev/null
+++ b/com.google.eclipse.protobuf.generator/src/com/google/eclipse/protobuf/scoping/ProtobufImportNamespacesScopingFragment.xpt
@@ -0,0 +1,23 @@
+«REM»
+/*******************************************************************************
+ * Copyright (c) 2008 itemis AG (http://www.itemis.eu) and others.
+ * 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
+ *
+ *******************************************************************************/
+«ENDREM»
+
+«IMPORT org::eclipse::xtext»
+
+
+«DEFINE addToPluginXmlRt(String scopeProviderSuperClassName, Boolean generateStub, Boolean generateXtendStub) FOR Grammar»«ENDDEFINE»
+
+«DEFINE addToPluginXmlUi(String scopeProviderSuperClassName, Boolean generateStub, Boolean generateXtendStub) FOR Grammar»«ENDDEFINE»
+
+«DEFINE addToStandaloneSetup(String scopeProviderSuperClassName, Boolean generateStub, Boolean generateXtendStub) FOR Grammar»«ENDDEFINE»
+
+«DEFINE generate(String scopeProviderSuperClassName, Boolean generateStub, Boolean generateXtendStub) FOR Grammar»
+ «EXPAND generator::scoping::AbstractScopingFragment::generateScopeProvider(scopeProviderSuperClassName, generateStub, generateXtendStub)»
+«ENDDEFINE»
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/ModelObjects_packageOf_Test.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/ModelObjects_packageOf_Test.java
index 01412d5..043d467 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/ModelObjects_packageOf_Test.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/ModelObjects_packageOf_Test.java
@@ -44,7 +44,7 @@
@Test public void should_return_package_if_proto_has_one() {
MessageField field = xtext.find("id", MessageField.class);
Package aPackage = modelObjects.packageOf(field);
- assertThat(aPackage.getName(), equalTo("person.test"));
+ assertThat(aPackage.getImportedNamespace(), equalTo("person.test"));
}
// syntax = "proto2";
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/Packages_areRelated_Test.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/Packages_areRelated_Test.java
index 2ebfa12..c9aeec4 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/Packages_areRelated_Test.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/Packages_areRelated_Test.java
@@ -49,36 +49,36 @@
"may"
};
p1 = mock(Package.class);
- when(p1.getName()).thenReturn(baseName);
+ when(p1.getImportedNamespace()).thenReturn(baseName);
p2 = mock(Package.class);
}
@Test public void should_return_true_if_packages_are_equal() {
- when(p2.getName()).thenReturn(baseName);
+ when(p2.getImportedNamespace()).thenReturn(baseName);
assertTrue(packages.areRelated(p1, p2));
}
@Test public void should_return_true_second_is_subPackage_of_first() {
for (String name : subpackageNames) {
- when(p2.getName()).thenReturn(name);
+ when(p2.getImportedNamespace()).thenReturn(name);
assertTrue(packages.areRelated(p1, p2));
}
}
@Test public void should_return_true_first_is_subPackage_of_second() {
for (String name : subpackageNames) {
- when(p2.getName()).thenReturn(name);
+ when(p2.getImportedNamespace()).thenReturn(name);
assertTrue(packages.areRelated(p2, p1));
}
}
@Test public void should_return_false_if_second_starts_with_few_segments_of_first_but_is_not_subpackage() {
- when(p2.getName()).thenReturn("may.the.ring");
+ when(p2.getImportedNamespace()).thenReturn("may.the.ring");
assertFalse(packages.areRelated(p1, p2));
}
@Test public void should_return_false_if_names_are_completely_different() {
- when(p2.getName()).thenReturn("peace.dog");
+ when(p2.getImportedNamespace()).thenReturn("peace.dog");
assertFalse(packages.areRelated(p1, p2));
}
}
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/validation/ImportValidator_checkUnknownSyntaxImports_withNonProto2Imports_Tests.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/validation/ImportValidator_checkUnknownSyntaxImports_withNonProto2Imports_Tests.java
index c8b91bc..47e4e6c 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/validation/ImportValidator_checkUnknownSyntaxImports_withNonProto2Imports_Tests.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/validation/ImportValidator_checkUnknownSyntaxImports_withNonProto2Imports_Tests.java
@@ -10,7 +10,7 @@
import static com.google.eclipse.protobuf.junit.core.IntegrationTestModule.integrationTestModule;
import static com.google.eclipse.protobuf.junit.core.XtextRule.overrideRuntimeModuleWith;
-import static com.google.eclipse.protobuf.protobuf.ProtobufPackage.Literals.IMPORT__PATH;
+import static com.google.eclipse.protobuf.protobuf.ProtobufPackage.Literals.PACKAGE__IMPORTED_NAMESPACE;
import static com.google.eclipse.protobuf.validation.Messages.importingUnsupportedSyntax;
import static org.eclipse.xtext.validation.ValidationMessageAcceptor.INSIGNIFICANT_INDEX;
import static org.mockito.Mockito.mock;
@@ -104,7 +104,7 @@
private void verifyThatImportingUnknownSyntaxFileCreatedWarning(Import anImport) {
verify(messageAcceptor).acceptWarning(importingUnsupportedSyntax,
anImport,
- IMPORT__PATH,
+ PACKAGE__IMPORTED_NAMESPACE,
INSIGNIFICANT_INDEX,
null,
new String[0]);
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/validation/ProtobufJavaValidator_checkOnlyOnePackageDefinition_Test.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/validation/ProtobufJavaValidator_checkOnlyOnePackageDefinition_Test.java
index df880f4..5bf5457 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/validation/ProtobufJavaValidator_checkOnlyOnePackageDefinition_Test.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/validation/ProtobufJavaValidator_checkOnlyOnePackageDefinition_Test.java
@@ -15,7 +15,7 @@
import static com.google.eclipse.protobuf.junit.core.UnitTestModule.unitTestModule;
import static com.google.eclipse.protobuf.junit.core.XtextRule.overrideRuntimeModuleWith;
-import static com.google.eclipse.protobuf.protobuf.ProtobufPackage.Literals.PACKAGE__NAME;
+import static com.google.eclipse.protobuf.protobuf.ProtobufPackage.Literals.PACKAGE__IMPORTED_NAMESPACE;
import static com.google.eclipse.protobuf.validation.Messages.multiplePackages;
import static com.google.eclipse.protobuf.validation.ProtobufJavaValidator.MORE_THAN_ONE_PACKAGE_ERROR;
@@ -51,7 +51,7 @@
@Test public void should_create_error_if_there_are_more_than_one_package_definitions() {
Package p = xtext.find("com.google.eclipse", Package.class);
validator.checkOnlyOnePackageDefinition(p);
- verify(messageAcceptor).acceptError(multiplePackages, p, PACKAGE__NAME, INSIGNIFICANT_INDEX, MORE_THAN_ONE_PACKAGE_ERROR);
+ verify(messageAcceptor).acceptError(multiplePackages, p, PACKAGE__IMPORTED_NAMESPACE, INSIGNIFICANT_INDEX, MORE_THAN_ONE_PACKAGE_ERROR);
}
// syntax = "proto2";
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 0b90171..a40d43a 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
@@ -43,6 +43,7 @@
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
import org.eclipse.xtext.documentation.IEObjectDocumentationProvider;
+import org.eclipse.xtext.ide.editor.syntaxcoloring.ISemanticHighlightingCalculator;
import org.eclipse.xtext.parser.IParser;
import org.eclipse.xtext.resource.IResourceServiceProvider;
import org.eclipse.xtext.ui.LanguageSpecific;
@@ -53,7 +54,6 @@
import org.eclipse.xtext.ui.editor.preferences.IPreferenceStoreInitializer;
import org.eclipse.xtext.ui.editor.syntaxcoloring.AbstractAntlrTokenToAttributeIdMapper;
import org.eclipse.xtext.ui.editor.syntaxcoloring.IHighlightingConfiguration;
-import org.eclipse.xtext.ui.editor.syntaxcoloring.ISemanticHighlightingCalculator;
import org.eclipse.xtext.ui.resource.IResourceSetProvider;
import org.eclipse.xtext.ui.resource.SimpleResourceSetProvider;
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/hyperlinking/ProtobufHyperlinkDetector.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/hyperlinking/ProtobufHyperlinkDetector.java
index c2482ee..e6b4aa9 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/hyperlinking/ProtobufHyperlinkDetector.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/hyperlinking/ProtobufHyperlinkDetector.java
@@ -8,7 +8,7 @@
*/
package com.google.eclipse.protobuf.ui.editor.hyperlinking;
-import static com.google.eclipse.protobuf.protobuf.ProtobufPackage.Literals.IMPORT__PATH;
+import static com.google.eclipse.protobuf.protobuf.ProtobufPackage.Literals.PACKAGE__IMPORTED_NAMESPACE;
import com.google.eclipse.protobuf.model.util.INodes;
import com.google.eclipse.protobuf.model.util.Imports;
@@ -71,7 +71,7 @@
if (!imports.isResolved(anImport)) {
return NO_HYPERLINKS;
}
- INode importUriNode = nodes.firstNodeForFeature(anImport, IMPORT__PATH);
+ INode importUriNode = nodes.firstNodeForFeature(anImport, PACKAGE__IMPORTED_NAMESPACE);
if (importUriNode.getLength() == 0) {
return NO_HYPERLINKS;
}
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/syntaxcoloring/ProtobufSemanticHighlightingCalculator.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/syntaxcoloring/ProtobufSemanticHighlightingCalculator.java
index 95ab1bb..b0046aa 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/syntaxcoloring/ProtobufSemanticHighlightingCalculator.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/syntaxcoloring/ProtobufSemanticHighlightingCalculator.java
@@ -35,10 +35,11 @@
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.xtext.ide.editor.syntaxcoloring.IHighlightedPositionAcceptor;
+import org.eclipse.xtext.ide.editor.syntaxcoloring.ISemanticHighlightingCalculator;
import org.eclipse.xtext.nodemodel.INode;
import org.eclipse.xtext.resource.XtextResource;
-import org.eclipse.xtext.ui.editor.syntaxcoloring.IHighlightedPositionAcceptor;
-import org.eclipse.xtext.ui.editor.syntaxcoloring.ISemanticHighlightingCalculator;
+import org.eclipse.xtext.util.CancelIndicator;
import com.google.eclipse.protobuf.model.util.INodes;
import com.google.eclipse.protobuf.model.util.IndexedElements;
@@ -77,7 +78,11 @@
@Inject private INodes nodes;
@Inject private Options options;
- @Override public void provideHighlightingFor(XtextResource resource, IHighlightedPositionAcceptor acceptor) {
+ @Override
+ public void provideHighlightingFor(
+ XtextResource resource,
+ IHighlightedPositionAcceptor acceptor,
+ CancelIndicator cancelIndicator) {
if (resource == null) {
return;
}
@@ -157,7 +162,8 @@
private void highlight(IndexedElement element, IHighlightedPositionAcceptor acceptor) {
highlightName(element, acceptor, DEFAULT_ID);
- highlightFirstFeature(element, indexedElements.indexFeatureOf(element), acceptor, MESSAGE_FIELD_INDEX_ID);
+ highlightFirstFeature(
+ element, indexedElements.indexFeatureOf(element), acceptor, MESSAGE_FIELD_INDEX_ID);
highlightOptions(element, acceptor);
if (element instanceof Group) {
highlight((Group) element, acceptor);
@@ -269,11 +275,18 @@
}
private void highlightName(EObject o, IHighlightedPositionAcceptor acceptor, String highlightId) {
- highlightFirstFeature(o, o.eClass().getEStructuralFeature("name"), acceptor, highlightId);
+ EStructuralFeature feature = o.eClass().getEStructuralFeature("name");
+ if (feature == null) {
+ feature = o.eClass().getEStructuralFeature("importedNamespace");
+ }
+ highlightFirstFeature(o, feature, acceptor, highlightId);
}
- private void highlightFirstFeature(EObject semantic, EStructuralFeature feature,
- IHighlightedPositionAcceptor acceptor, String highlightId) {
+ private void highlightFirstFeature(
+ EObject semantic,
+ EStructuralFeature feature,
+ IHighlightedPositionAcceptor acceptor,
+ String highlightId) {
INode node = nodes.firstNodeForFeature(semantic, feature);
if (node == null) {
return;
diff --git a/com.google.eclipse.protobuf/META-INF/MANIFEST.MF b/com.google.eclipse.protobuf/META-INF/MANIFEST.MF
index 589dac1..e76431d 100644
--- a/com.google.eclipse.protobuf/META-INF/MANIFEST.MF
+++ b/com.google.eclipse.protobuf/META-INF/MANIFEST.MF
@@ -18,8 +18,7 @@
org.eclipse.xtext,
org.eclipse.xtext.generator;resolution:=optional,
org.eclipse.xtext.ui,
- org.eclipse.xtext.util,
- com.google.eclipse.protobuf.generator;bundle-version="1.0.0"
+ org.eclipse.xtext.util
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Export-Package: com.google.eclipse.protobuf,
com.google.eclipse.protobuf.conversion,
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/ProtobufRuntimeModule.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/ProtobufRuntimeModule.java
index 541b1a1..378fe86 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/ProtobufRuntimeModule.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/ProtobufRuntimeModule.java
@@ -15,7 +15,6 @@
import com.google.eclipse.protobuf.resource.FastXtextResourceSet;
import com.google.eclipse.protobuf.resource.GlobalResourceServiceProvider;
import com.google.eclipse.protobuf.scoping.ExtensionRegistryProvider;
-import com.google.eclipse.protobuf.scoping.ProtobufGlobalScopeProvider;
import com.google.eclipse.protobuf.validation.ProtobufResourceValidator;
import com.google.eclipse.protobuf.validation.ProtobufSyntaxErrorMessageProvider;
import com.google.inject.Binder;
@@ -28,11 +27,11 @@
import org.eclipse.xtext.resource.IGlobalServiceProvider;
import org.eclipse.xtext.resource.XtextResource;
import org.eclipse.xtext.resource.XtextResourceSet;
-import org.eclipse.xtext.scoping.IGlobalScopeProvider;
import org.eclipse.xtext.validation.IResourceValidator;
/**
- * Use this class to register components to be used at runtime / without the Equinox extension registry.
+ * Use this class to register components to be used at runtime / without the Equinox extension
+ * registry.
*/
public class ProtobufRuntimeModule extends AbstractProtobufRuntimeModule {
public Class<? extends IGlobalServiceProvider> bindIGlobalServiceProvider() {
@@ -43,7 +42,8 @@
return ProtobufQualifiedNameConverter.class;
}
- @Override public Class<? extends IQualifiedNameProvider> bindIQualifiedNameProvider() {
+ @Override
+ public Class<? extends IQualifiedNameProvider> bindIQualifiedNameProvider() {
return ProtobufQualifiedNameProvider.class;
}
@@ -55,22 +55,21 @@
return ProtobufSyntaxErrorMessageProvider.class;
}
- @Override public Class<? extends IValueConverterService> bindIValueConverterService() {
+ @Override
+ public Class<? extends IValueConverterService> bindIValueConverterService() {
return ProtobufTerminalConverters.class;
}
- @Override public Class<? extends XtextResource> bindXtextResource() {
+ @Override
+ public Class<? extends XtextResource> bindXtextResource() {
return ProtobufResource.class;
}
- @Override public Class<? extends XtextResourceSet> bindXtextResourceSet() {
+ @Override
+ public Class<? extends XtextResourceSet> bindXtextResourceSet() {
return FastXtextResourceSet.class;
}
- @Override public Class<? extends IGlobalScopeProvider> bindIGlobalScopeProvider() {
- return ProtobufGlobalScopeProvider.class;
- }
-
public void configureExtensionRegistry(Binder binder) {
binder.bind(IExtensionRegistry.class).toProvider(ExtensionRegistryProvider.class);
}
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/model/util/Packages.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/model/util/Packages.java
index 66a57f6..324b9c3 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/model/util/Packages.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/model/util/Packages.java
@@ -130,7 +130,7 @@
}
private QualifiedName nameOf(Package p) {
- String name = p.getName();
+ String name = p.getImportedNamespace();
return (isEmpty(name)) ? null : qualifiedNameConverter.toQualifiedName(name);
}
}
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/ProtobufGlobalScopeProvider.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/ProtobufGlobalScopeProvider.java
deleted file mode 100644
index 9f10eb0..0000000
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/ProtobufGlobalScopeProvider.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Copyright (c) 2014 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 com.google.eclipse.protobuf.model.util.Protobufs;
-import com.google.eclipse.protobuf.model.util.Resources;
-import com.google.eclipse.protobuf.protobuf.Import;
-import com.google.eclipse.protobuf.protobuf.Protobuf;
-import com.google.inject.Inject;
-import com.google.inject.Provider;
-
-import org.eclipse.emf.common.util.URI;
-import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.xtext.EcoreUtil2;
-import org.eclipse.xtext.scoping.impl.ImportUriGlobalScopeProvider;
-import org.eclipse.xtext.util.IAcceptor;
-import org.eclipse.xtext.util.IResourceScopeCache;
-
-import java.util.Iterator;
-import java.util.LinkedHashSet;
-
-/**
- * A global scope provider that reads each {@link Import} in the protobuf file, resolves it, and
- * caches the result.
- */
-public class ProtobufGlobalScopeProvider extends ImportUriGlobalScopeProvider {
- @Inject
- private IResourceScopeCache cache;
-
- @Inject
- private Resources resources;
-
- @Inject
- private Protobufs protobufs;
-
- @Inject
- private IImportResolver importResolver;
-
- @Override
- protected LinkedHashSet<URI> getImportedUris(final Resource resource) {
- return cache.get(ProtobufGlobalScopeProvider.class.getName(), resource,
- new Provider<LinkedHashSet<URI>>() {
- @Override
- public LinkedHashSet<URI> get() {
- final LinkedHashSet<URI> uniqueImportURIs = new LinkedHashSet<>(5);
- IAcceptor<String> collector = createURICollector(resource, uniqueImportURIs);
- Protobuf protobuf = resources.rootOf(resource);
- if (protobuf == null) {
- return uniqueImportURIs;
- }
- for (Import anImport : protobufs.importsIn(protobuf)) {
- collector.accept(importResolver.resolve(anImport));
- }
- Iterator<URI> uriIter = uniqueImportURIs.iterator();
- while (uriIter.hasNext()) {
- if (!EcoreUtil2.isValidUri(resource, uriIter.next())) {
- uriIter.remove();
- }
- }
- return uniqueImportURIs;
- }
- });
- }
-}
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/ProtobufImportUriGlobalScopeProvider.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/ProtobufImportUriGlobalScopeProvider.java
new file mode 100644
index 0000000..bc84250
--- /dev/null
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/ProtobufImportUriGlobalScopeProvider.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2014 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 com.google.eclipse.protobuf.model.util.Imports;
+import com.google.eclipse.protobuf.model.util.Protobufs;
+import com.google.eclipse.protobuf.model.util.Resources;
+import com.google.eclipse.protobuf.protobuf.Import;
+import com.google.eclipse.protobuf.protobuf.Protobuf;
+import com.google.inject.Inject;
+import com.google.inject.Provider;
+
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.xtext.scoping.impl.ImportUriGlobalScopeProvider;
+import org.eclipse.xtext.util.IResourceScopeCache;
+
+import java.util.LinkedHashSet;
+
+/**
+ * A global scope provider that reads each {@link Import} in the protobuf file, resolves it, and
+ * caches the result.
+ */
+public class ProtobufImportUriGlobalScopeProvider extends ImportUriGlobalScopeProvider {
+ @Inject private Protobufs protobufs;
+ @Inject private Resources resources;
+ @Inject private Imports imports;
+ @Inject private IResourceScopeCache cache;
+
+ @Override
+ protected LinkedHashSet<URI> getImportedUris(final Resource resource) {
+ return cache.get(
+ ProtobufImportUriGlobalScopeProvider.class.getName(),
+ resource,
+ new Provider<LinkedHashSet<URI>>() {
+ @Override
+ public LinkedHashSet<URI> get() {
+ LinkedHashSet<URI> importedUris = new LinkedHashSet<>();
+ Protobuf protobuf = resources.rootOf(resource);
+ if (protobuf == null) {
+ return importedUris;
+ }
+ for (Import singleImport : protobufs.importsIn(protobuf)) {
+ resolveImport(importedUris, singleImport);
+ }
+ return importedUris;
+ }
+
+ private void addPublicImportedUris(Protobuf protobuf, LinkedHashSet<URI> importedUris) {
+ for (Import singleImport : protobufs.publicImportsIn(protobuf)) {
+ resolveImport(importedUris, singleImport);
+ }
+ }
+
+ private void resolveImport(LinkedHashSet<URI> importedUris, Import singleImport) {
+ if (imports.isResolved(singleImport)) {
+ importedUris.add(imports.resolvedUriOf(singleImport));
+ Protobuf root = resources.rootOf(imports.importedResource(singleImport));
+ if (root != null) {
+ addPublicImportedUris(root, importedUris);
+ }
+ }
+ }
+ });
+ }
+}
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/ProtobufImportedNamespaceAwareLocalScopeProvider.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/ProtobufImportedNamespaceAwareLocalScopeProvider.java
new file mode 100644
index 0000000..de3ccb1
--- /dev/null
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/ProtobufImportedNamespaceAwareLocalScopeProvider.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2016 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.xtext.naming.QualifiedName;
+import org.eclipse.xtext.scoping.impl.ImportNormalizer;
+import org.eclipse.xtext.scoping.impl.ImportedNamespaceAwareLocalScopeProvider;
+import org.eclipse.xtext.util.Strings;
+import com.google.eclipse.protobuf.naming.ProtobufQualifiedNameConverter;
+import com.google.inject.Inject;
+
+public class ProtobufImportedNamespaceAwareLocalScopeProvider
+ extends ImportedNamespaceAwareLocalScopeProvider {
+ @Inject private ProtobufQualifiedNameConverter qualifiedNameConverter;
+
+ /**
+ * Creates a new {@link ImportNormalizer} for the given namespace.
+ *
+ * @param namespace the namespace.
+ * @param ignoreCase <code>true</code> if the resolver should be case insensitive.
+ * @return a new {@link ImportNormalizer} or {@code null} if the namespace cannot be
+ * converted to a valid qualified name.
+ */
+ @Override
+ protected ImportNormalizer createImportedNamespaceResolver(
+ final String namespace, boolean ignoreCase) {
+ if (Strings.isEmpty(namespace)) {
+ return null;
+ }
+ QualifiedName importedNamespace = qualifiedNameConverter.toQualifiedName(namespace);
+ if (importedNamespace == null || importedNamespace.isEmpty()) {
+ return null;
+ }
+ return doCreateImportNormalizer(importedNamespace, true, ignoreCase);
+ }
+}
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/validation/ProtobufJavaValidator.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/validation/ProtobufJavaValidator.java
index 3c6e173..b164957 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/validation/ProtobufJavaValidator.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/validation/ProtobufJavaValidator.java
@@ -11,7 +11,7 @@
import static com.google.eclipse.protobuf.protobuf.ProtobufPackage.Literals.MAP_TYPE__KEY_TYPE;
import static com.google.eclipse.protobuf.protobuf.ProtobufPackage.Literals.MAP_TYPE__VALUE_TYPE;
import static com.google.eclipse.protobuf.protobuf.ProtobufPackage.Literals.MESSAGE_FIELD__MODIFIER;
-import static com.google.eclipse.protobuf.protobuf.ProtobufPackage.Literals.PACKAGE__NAME;
+import static com.google.eclipse.protobuf.protobuf.ProtobufPackage.Literals.PACKAGE__IMPORTED_NAMESPACE;
import static com.google.eclipse.protobuf.protobuf.ProtobufPackage.Literals.SYNTAX__NAME;
import static com.google.eclipse.protobuf.validation.Messages.expectedFieldNumber;
import static com.google.eclipse.protobuf.validation.Messages.expectedSyntaxIdentifier;
@@ -380,7 +380,7 @@
for (ProtobufElement e : root.getElements()) {
if (e == aPackage) {
if (firstFound) {
- error(multiplePackages, aPackage, PACKAGE__NAME, MORE_THAN_ONE_PACKAGE_ERROR);
+ error(multiplePackages, aPackage, PACKAGE__IMPORTED_NAMESPACE, MORE_THAN_ONE_PACKAGE_ERROR);
}
return;
}