Cleanup code no longer used by scoping.
Change-Id: I226bb1b158b1e0e671097772939aa7d27efa3937
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/contentassist/ProtobufProposalProvider.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/contentassist/ProtobufProposalProvider.java
index 9bed2d8..9f87e74 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/contentassist/ProtobufProposalProvider.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/contentassist/ProtobufProposalProvider.java
@@ -34,9 +34,7 @@
import static com.google.eclipse.protobuf.util.CommonWords.space;
import static java.lang.String.valueOf;
import static java.util.Collections.emptyList;
-import static java.util.Collections.emptySet;
import static org.eclipse.xtext.EcoreUtil2.getAllContentsOfType;
-import static org.eclipse.xtext.util.Strings.isEmpty;
import static org.eclipse.xtext.util.Strings.toFirstLower;
import com.google.eclipse.protobuf.grammar.CommonKeyword;
@@ -44,7 +42,6 @@
import com.google.eclipse.protobuf.model.util.Literals;
import com.google.eclipse.protobuf.model.util.MessageFields;
import com.google.eclipse.protobuf.model.util.Options;
-import com.google.eclipse.protobuf.protobuf.AbstractCustomOption;
import com.google.eclipse.protobuf.protobuf.AbstractOption;
import com.google.eclipse.protobuf.protobuf.ComplexValue;
import com.google.eclipse.protobuf.protobuf.CustomFieldOption;
@@ -60,14 +57,9 @@
import com.google.eclipse.protobuf.protobuf.NativeFieldOption;
import com.google.eclipse.protobuf.protobuf.NativeOption;
import com.google.eclipse.protobuf.protobuf.Option;
-import com.google.eclipse.protobuf.protobuf.Rpc;
import com.google.eclipse.protobuf.protobuf.SimpleValueField;
-import com.google.eclipse.protobuf.protobuf.Stream;
-import com.google.eclipse.protobuf.protobuf.TypeExtension;
import com.google.eclipse.protobuf.scoping.ProtoDescriptor;
import com.google.eclipse.protobuf.scoping.ProtoDescriptorProvider;
-import com.google.eclipse.protobuf.scoping.ProtobufScopeProvider;
-import com.google.eclipse.protobuf.scoping.ScopeProvider;
import com.google.eclipse.protobuf.ui.grammar.CompoundElement;
import com.google.eclipse.protobuf.ui.labeling.Images;
import com.google.eclipse.protobuf.util.EResources;
@@ -81,8 +73,6 @@
import org.eclipse.xtext.Assignment;
import org.eclipse.xtext.Keyword;
import org.eclipse.xtext.RuleCall;
-import org.eclipse.xtext.naming.QualifiedName;
-import org.eclipse.xtext.resource.IEObjectDescription;
import org.eclipse.xtext.ui.PluginImageHelper;
import org.eclipse.xtext.ui.editor.contentassist.ConfigurableCompletionProposal;
import org.eclipse.xtext.ui.editor.contentassist.ContentAssistContext;
@@ -95,10 +85,9 @@
/**
* @author alruiz@google.com (Alex Ruiz)
*
- * @see <a href="http://www.eclipse.org/Xtext/documentation/latest/xtext.html#contentAssist">Xtext Content Assist</a>
+ * @see <a href="http://www.eclipse.org/Xtext/documentation/310_eclipse_support.html#content-assist">Xtext Content Assist</a>
*/
public class ProtobufProposalProvider extends AbstractProtobufProposalProvider {
- @Inject private IEObjectDescriptionChooser descriptionChooser;
@Inject private ProtoDescriptorProvider descriptorProvider;
@Inject private Images images;
@Inject private IndexedElements indexedElements;
@@ -125,47 +114,6 @@
proposeAndAccept(proposal, imageHelper.getImage(images.imageFor(SYNTAX)), context, acceptor);
}
- @Override public void completeComplexTypeLink_Target(EObject model, Assignment assignment,
- ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
- if (model instanceof MessageField) {
- Collection<IEObjectDescription> scope = scopeProvider().potentialComplexTypesFor((MessageField) model);
- for (IEObjectDescription d : descriptionChooser.shortestQualifiedNamesIn(scope)) {
- Image image = imageHelper.getImage(images.imageFor(d.getEObjectOrProxy()));
- proposeAndAccept(d, image, context, acceptor);
- }
- }
- }
-
- @Override public void completeExtensibleTypeLink_Target(EObject model, Assignment assignment,
- ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
- Collection<IEObjectDescription> scope = emptySet();
- if (model instanceof TypeExtension) {
- TypeExtension typeExtension = (TypeExtension) model;
- scope = scopeProvider().potentialExtensibleTypesFor(typeExtension);
- }
- for (IEObjectDescription d : descriptionChooser.shortestQualifiedNamesIn(scope)) {
- Image image = imageHelper.getImage(images.imageFor(d.getEObjectOrProxy()));
- proposeAndAccept(d, image, context, acceptor);
- }
- }
-
- @Override public void completeMessageLink_Target(EObject model, Assignment assignment, ContentAssistContext context,
- ICompletionProposalAcceptor acceptor) {
- Collection<IEObjectDescription> scope = emptySet();
- if (model instanceof Rpc) {
- Rpc rpc = (Rpc) model;
- scope = scopeProvider().potentialMessagesFor(rpc);
- }
- if (model instanceof Stream) {
- Stream stream = (Stream) model;
- scope = scopeProvider().potentialMessagesFor(stream);
- }
- for (IEObjectDescription d : descriptionChooser.shortestQualifiedNamesIn(scope)) {
- Image image = imageHelper.getImage(images.imageFor(d.getEObjectOrProxy()));
- proposeAndAccept(d, image, context, acceptor);
- }
- }
-
@Override public void completeNativeOption_Source(EObject model, Assignment assignment,
ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
ProtoDescriptor descriptor =
@@ -565,71 +513,10 @@
acceptor.accept(proposal);
}
- @Override public void completeCustomOption_Source(EObject model, Assignment assignment,
- ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
- completeAbstractCustomOptionSource(model, context, acceptor);
- }
-
- @Override public void completeCustomFieldOption_Source(EObject model, Assignment assignment,
- ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
- completeAbstractCustomOptionSource(model, context, acceptor);
- }
-
- private void completeAbstractCustomOptionSource(EObject model, ContentAssistContext context,
- ICompletionProposalAcceptor acceptor) {
- if (model instanceof AbstractCustomOption) {
- AbstractCustomOption option = (AbstractCustomOption) model;
- Collection<IEObjectDescription> scope = scopeProvider().potentialSourcesFor(option);
- proposeAndAcceptOptions(scope, context, acceptor);
- }
- }
-
- private void proposeAndAcceptOptions(Collection<IEObjectDescription> scope, ContentAssistContext context,
- ICompletionProposalAcceptor acceptor) {
- Image image = imageForOption();
- for (IEObjectDescription d : descriptionChooser.shortestQualifiedNamesIn(scope)) {
- proposeAndAccept(d, image, context, acceptor);
- }
- }
-
private Image imageForOption() {
return imageHelper.getImage(images.imageFor(OPTION));
}
- private void proposeAndAccept(IEObjectDescription d, Image image, ContentAssistContext context,
- ICompletionProposalAcceptor acceptor) {
- proposeAndAccept(d, null, null, image, context, acceptor);
- }
-
- @Override public void completeCustomOption_Fields(EObject model, Assignment assignment,
- ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
- if (model instanceof CustomOption) {
- CustomOption option = (CustomOption) model;
- proposeAndAccept(scopeProvider().potentialMessageFieldsFor(option), context, acceptor);
- proposeAndAccept(scopeProvider().potentialExtensionFieldsFor(option), "(%s)", "(%s)", context, acceptor);
- }
- }
-
- @Override public void completeCustomFieldOption_Fields(EObject model, Assignment assignment,
- ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
- if (model instanceof CustomFieldOption) {
- CustomFieldOption option = (CustomFieldOption) model;
- proposeAndAccept(scopeProvider().potentialMessageFieldsFor(option), context, acceptor);
- proposeExtensionFields(scopeProvider().potentialExtensionFieldsFor(option), context, acceptor);
- }
- }
-
- private void proposeExtensionFields(Collection<IEObjectDescription> scope, ContentAssistContext context,
- ICompletionProposalAcceptor acceptor) {
- String format = "(%s)";
- proposeAndAccept(scope, format, format, context, acceptor);
- }
-
- private void proposeAndAccept(Collection<IEObjectDescription> scope, ContentAssistContext context,
- ICompletionProposalAcceptor acceptor) {
- proposeAndAccept(scope, null, null, context, acceptor);
- }
-
@Override public void completeOptionSource_Target(EObject model, Assignment assignment,
ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
}
@@ -719,49 +606,12 @@
}
}
- @Override public void completeSimpleValueField_Name(EObject model, Assignment assignment,
- ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
- if (model instanceof ComplexValue) {
- ComplexValue value = (ComplexValue) model;
- proposeAndAccept(scopeProvider().potentialNormalFieldNames(value), "%s:", null, context, acceptor);
- proposeAndAccept(scopeProvider().potentialExtensionFieldNames(value), "[%s]:", "[%s]", context, acceptor);
- }
- }
-
- private void proposeAndAccept(Collection<IEObjectDescription> scope, String proposalFormat, String displayFormat,
- ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
- for (IEObjectDescription d : descriptionChooser.shortestQualifiedNamesIn(scope)) {
- Image image = imageHelper.getImage(images.imageFor(d.getEObjectOrProxy()));
- proposeAndAccept(d, proposalFormat, displayFormat, image, context, acceptor);
- }
- }
-
- private void proposeAndAccept(IEObjectDescription d, String proposalFormat, String displayFormat, Image image,
- ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
- QualifiedName name = d.getName();
- String proposalText = name.toString();
- if (!isEmpty(proposalFormat)) {
- proposalText = String.format(proposalFormat, proposalText);
- }
- String lastSegment = name.getLastSegment();
- if (!isEmpty(displayFormat)) {
- lastSegment = String.format(displayFormat, lastSegment);
- }
- String display = String.format("%s - %s", lastSegment, name.toString());
- ICompletionProposal proposal = createCompletionProposal(proposalText, display, image, context);
- acceptor.accept(proposal);
- }
-
private void proposeAndAccept(String proposalText, Image image, ContentAssistContext context,
ICompletionProposalAcceptor acceptor) {
ICompletionProposal proposal = createCompletionProposal(proposalText, proposalText, image, context);
acceptor.accept(proposal);
}
- private ScopeProvider scopeProvider() {
- return (ProtobufScopeProvider) super.getScopeProvider();
- }
-
@Override public ICompletionProposal createCompletionProposal(String proposal, String displayString, Image image,
ContentAssistContext contentAssistContext) {
StyledString styled = null;
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/ComplexTypeFinderStrategy.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/ComplexTypeFinderStrategy.java
deleted file mode 100644
index 6b8b932..0000000
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/ComplexTypeFinderStrategy.java
+++ /dev/null
@@ -1,85 +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 static com.google.common.collect.Sets.newHashSet;
-import static java.util.Collections.emptySet;
-import static org.eclipse.xtext.resource.EObjectDescription.create;
-
-import com.google.eclipse.protobuf.model.util.Imports;
-import com.google.eclipse.protobuf.naming.LocalNamesProvider;
-import com.google.eclipse.protobuf.naming.NormalNamingStrategy;
-import com.google.eclipse.protobuf.protobuf.ComplexType;
-import com.google.eclipse.protobuf.protobuf.Import;
-import com.google.eclipse.protobuf.protobuf.Package;
-import com.google.eclipse.protobuf.util.EResources;
-import com.google.inject.Inject;
-
-import org.eclipse.core.resources.IProject;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.xtext.naming.QualifiedName;
-import org.eclipse.xtext.resource.IEObjectDescription;
-
-import java.util.Collection;
-import java.util.List;
-import java.util.Set;
-
-/**
- * @author alruiz@google.com (Alex Ruiz)
- */
-class ComplexTypeFinderStrategy implements ModelElementFinder.FinderStrategy<Class<? extends ComplexType>> {
- @Inject private PackageIntersectionDescriptions packageIntersectionDescriptions;
- @Inject private ProtoDescriptorProvider descriptorProvider;
- @Inject private LocalNamesProvider localNamesProvider;
- @Inject private NormalNamingStrategy namingStrategy;
- @Inject private QualifiedNameDescriptions qualifiedNamesDescriptions;
- @Inject private Imports imports;
-
- @Override public Collection<IEObjectDescription> imported(Package fromImporter, Package fromImported, Object target,
- Class<? extends ComplexType> typeOfComplexType) {
- if (!typeOfComplexType.isInstance(target)) {
- return emptySet();
- }
- Set<IEObjectDescription> descriptions = newHashSet();
- EObject e = (EObject) target;
- descriptions.addAll(qualifiedNamesDescriptions.qualifiedNames(e, namingStrategy));
- descriptions.addAll(packageIntersectionDescriptions.intersection(fromImporter, fromImported, e));
- return descriptions;
- }
-
- @Override public Collection<IEObjectDescription> inDescriptor(Import anImport,
- Class<? extends ComplexType> typeOfComplexType) {
- IProject project = EResources.getProjectOf(anImport.eResource());
- Set<IEObjectDescription> descriptions = newHashSet();
- ProtoDescriptor descriptor = descriptorProvider.descriptor(project, imports.getPath(anImport));
- for (ComplexType complexType : descriptor.allTypes()) {
- if (!typeOfComplexType.isInstance(complexType)) {
- continue;
- }
- descriptions.addAll(qualifiedNamesDescriptions.qualifiedNames(complexType, namingStrategy));
- }
- return descriptions;
- }
-
- @Override public Collection<IEObjectDescription> local(Object target, Class<? extends ComplexType> typeOfComplexType,
- int level) {
- if (!typeOfComplexType.isInstance(target)) {
- return emptySet();
- }
- EObject e = (EObject) target;
- Set<IEObjectDescription> descriptions = newHashSet();
- List<QualifiedName> names = localNamesProvider.localNames(e, namingStrategy);
- int nameCount = names.size();
- for (int i = level; i < nameCount; i++) {
- descriptions.add(create(names.get(i), e));
- }
- descriptions.addAll(qualifiedNamesDescriptions.qualifiedNames(e, namingStrategy));
- return descriptions;
- }
-}
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/CustomOptionFieldFinder.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/CustomOptionFieldFinder.java
deleted file mode 100644
index 26a2941..0000000
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/CustomOptionFieldFinder.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * 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 static java.util.Collections.emptySet;
-
-import java.util.Collection;
-
-import org.eclipse.xtext.resource.IEObjectDescription;
-
-import com.google.eclipse.protobuf.model.util.OptionFields;
-import com.google.eclipse.protobuf.model.util.Options;
-import com.google.eclipse.protobuf.protobuf.AbstractCustomOption;
-import com.google.eclipse.protobuf.protobuf.AbstractOption;
-import com.google.eclipse.protobuf.protobuf.IndexedElement;
-import com.google.eclipse.protobuf.protobuf.OptionField;
-import com.google.inject.Inject;
-import com.google.inject.Provider;
-
-/**
- * @author alruiz@google.com (Alex Ruiz)
- */
-class CustomOptionFieldFinder {
- @Inject private OptionFields optionFields;
- @Inject private Options options;
-
- Collection<IEObjectDescription> findOptionFields(AbstractCustomOption customOption, FinderStrategy strategy) {
- return findOptionFields(customOption, strategy, null);
- }
-
- Collection<IEObjectDescription> findOptionFields(AbstractCustomOption customOption, FinderStrategy strategy,
- OptionField field) {
- // TODO(alruiz): remove Provider of IndexedElement.
- final AbstractOption option = (AbstractOption) customOption;
- IndexedElement e = referredField(customOption, field, new Provider<IndexedElement>() {
- @Override public IndexedElement get() {
- return options.rootSourceOf(option);
- }
- });
- if (e != null) {
- return strategy.findOptionFields(e);
- }
- return emptySet();
- }
-
- private IndexedElement referredField(AbstractCustomOption customOption, OptionField field,
- Provider<IndexedElement> provider) {
- OptionField previous = null;
- boolean isFirstField = true;
- for (OptionField current : options.fieldsOf(customOption)) {
- if (current == field) {
- return (isFirstField) ? provider.get() : optionFields.sourceOf(previous);
- }
- previous = current;
- isFirstField = false;
- }
- if (field == null) {
- if (previous == null) {
- return provider.get();
- }
- return optionFields.sourceOf(previous);
- }
- return null;
- }
-
- static interface FinderStrategy {
- Collection<IEObjectDescription> findOptionFields(IndexedElement reference);
- }
-}
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/CustomOptionFieldNameFinder.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/CustomOptionFieldNameFinder.java
deleted file mode 100644
index c5c7ff0..0000000
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/CustomOptionFieldNameFinder.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * 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 static java.util.Collections.emptySet;
-
-import com.google.eclipse.protobuf.model.util.Options;
-import com.google.eclipse.protobuf.protobuf.AbstractCustomOption;
-import com.google.eclipse.protobuf.protobuf.ComplexValue;
-import com.google.eclipse.protobuf.protobuf.ComplexValueField;
-import com.google.eclipse.protobuf.protobuf.FieldName;
-import com.google.eclipse.protobuf.protobuf.IndexedElement;
-import com.google.inject.Inject;
-
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.xtext.resource.IEObjectDescription;
-
-import java.util.Collection;
-
-/**
- * @author alruiz@google.com (Alex Ruiz)
- */
-class CustomOptionFieldNameFinder {
- @Inject private Options options;
-
- Collection<IEObjectDescription> findFieldNamesSources(ComplexValue value, FinderStrategy strategy) {
- IndexedElement source = sourceOf(value);
- if (source == null) {
- return emptySet();
- }
- return strategy.findMessageFields(source);
- }
-
- private IndexedElement sourceOf(ComplexValue value) {
- IndexedElement source = null;
- EObject container = value.eContainer();
- if (container instanceof AbstractCustomOption) {
- AbstractCustomOption option = (AbstractCustomOption) container;
- source = options.sourceOf(option);
- }
- if (container instanceof ComplexValueField) {
- source = sourceOfNameOf((ComplexValueField) container);
- }
- return source;
- }
-
- private IndexedElement sourceOfNameOf(ComplexValueField field) {
- FieldName name = field.getName();
- return (name == null) ? null : name.getTarget();
- }
-
- static interface FinderStrategy {
- Collection<IEObjectDescription> findMessageFields(IndexedElement reference);
- }
-}
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/CustomOptionFinderStrategy.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/CustomOptionFinderStrategy.java
deleted file mode 100644
index bae454f..0000000
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/CustomOptionFinderStrategy.java
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * Copyright (c) 2011, 2015 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 static java.util.Collections.emptySet;
-
-import static org.eclipse.xtext.resource.EObjectDescription.create;
-
-import static com.google.common.collect.Sets.newHashSet;
-
-import java.util.Collection;
-import java.util.List;
-import java.util.Set;
-
-import org.eclipse.xtext.naming.QualifiedName;
-import org.eclipse.xtext.resource.IEObjectDescription;
-
-import com.google.eclipse.protobuf.model.util.TypeExtensions;
-import com.google.eclipse.protobuf.naming.LocalNamesProvider;
-import com.google.eclipse.protobuf.naming.OptionNamingStrategy;
-import com.google.eclipse.protobuf.protobuf.Import;
-import com.google.eclipse.protobuf.protobuf.IndexedElement;
-import com.google.eclipse.protobuf.protobuf.Message;
-import com.google.eclipse.protobuf.protobuf.Package;
-import com.google.eclipse.protobuf.protobuf.TypeExtension;
-import com.google.inject.Inject;
-
-/**
- * @author alruiz@google.com (Alex Ruiz)
- */
-class CustomOptionFinderStrategy implements ModelElementFinder.FinderStrategy<OptionType> {
- @Inject private LocalNamesProvider localNamesProvider;
- @Inject private OptionNamingStrategy namingStrategy;
- @Inject private QualifiedNameDescriptions qualifiedNamesDescriptions;
- @Inject private TypeExtensions typeExtensions;
-
- @Override public Collection<IEObjectDescription> imported(Package fromImporter, Package fromImported, Object target,
- OptionType optionType) {
- if (!isExtendingOptionMessage(target, optionType)) {
- return emptySet();
- }
- Set<IEObjectDescription> descriptions = newHashSet();
- TypeExtension extension = (TypeExtension) target;
- for (IndexedElement e : extension.getElements()) {
- descriptions.addAll(qualifiedNamesDescriptions.qualifiedNames(e, namingStrategy));
- }
- return descriptions;
- }
-
- @Override public Collection<IEObjectDescription> inDescriptor(Import anImport, OptionType criteria) {
- return emptySet();
- }
-
- @Override public Collection<IEObjectDescription> local(Object target, OptionType optionType, int level) {
- if (!isExtendingOptionMessage(target, optionType)) {
- return emptySet();
- }
- Set<IEObjectDescription> descriptions = newHashSet();
- TypeExtension extension = (TypeExtension) target;
- for (IndexedElement e : extension.getElements()) {
- List<QualifiedName> names = localNamesProvider.localNames(e, namingStrategy);
- int nameCount = names.size();
- for (int i = level; i < nameCount; i++) {
- descriptions.add(create(names.get(i), e));
- }
- descriptions.addAll(qualifiedNamesDescriptions.qualifiedNames(e, namingStrategy));
- }
- return descriptions;
- }
-
- private boolean isExtendingOptionMessage(Object o, OptionType optionType) {
- if (!(o instanceof TypeExtension)) {
- return false;
- }
- Message message = typeExtensions.messageFrom((TypeExtension) o);
- if (message == null) {
- return false;
- }
- String name = message.getName();
- return optionType.messageName().equals(name);
- }
-}
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/ExtensionFieldFinderStrategy.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/ExtensionFieldFinderStrategy.java
deleted file mode 100644
index eca6a62..0000000
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/ExtensionFieldFinderStrategy.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Copyright (c) 2011, 2015 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 static java.util.Collections.emptyList;
-
-import static org.eclipse.xtext.resource.EObjectDescription.create;
-
-import static com.google.common.collect.Sets.newHashSet;
-
-import java.util.Collection;
-import java.util.Set;
-
-import org.eclipse.xtext.resource.IEObjectDescription;
-
-import com.google.eclipse.protobuf.model.util.MessageFields;
-import com.google.eclipse.protobuf.model.util.Messages;
-import com.google.eclipse.protobuf.model.util.Options;
-import com.google.eclipse.protobuf.naming.OptionNamingStrategy;
-import com.google.eclipse.protobuf.protobuf.IndexedElement;
-import com.google.eclipse.protobuf.protobuf.Message;
-import com.google.eclipse.protobuf.protobuf.MessageField;
-import com.google.eclipse.protobuf.protobuf.TypeExtension;
-import com.google.inject.Inject;
-
-/**
- * @author alruiz@google.com (Alex Ruiz)
- */
-class ExtensionFieldFinderStrategy implements CustomOptionFieldFinder.FinderStrategy {
- @Inject private MessageFields messageFields;
- @Inject private Messages messages;
- @Inject private OptionNamingStrategy namingStrategy;
- @Inject private Options options;
- @Inject private QualifiedNameDescriptions qualifiedNameDescriptions;
-
- @Override public Collection<IEObjectDescription> findOptionFields(IndexedElement reference) {
- if (!(reference instanceof MessageField)) {
- return emptyList();
- }
- Message fieldType = messageFields.messageTypeOf((MessageField) reference);
- if (fieldType == null) {
- return emptyList();
- }
- Set<IEObjectDescription> descriptions = newHashSet();
- for (TypeExtension extension : messages.localExtensionsOf(fieldType)) {
- for (IndexedElement element : extension.getElements()) {
- descriptions.addAll(qualifiedNameDescriptions.qualifiedNames(element, namingStrategy));
- String name = options.nameForOption(element);
- descriptions.add(create(name, element));
- }
- }
- return descriptions;
- }
-}
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/ExtensionFieldNameFinderStrategy.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/ExtensionFieldNameFinderStrategy.java
deleted file mode 100644
index 4d84140..0000000
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/ExtensionFieldNameFinderStrategy.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Copyright (c) 2012, 2015 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 static com.google.common.collect.Sets.newHashSet;
-
-import java.util.Collection;
-import java.util.Set;
-
-import org.eclipse.xtext.resource.IEObjectDescription;
-
-import com.google.common.base.Strings;
-import com.google.eclipse.protobuf.model.util.MessageFields;
-import com.google.eclipse.protobuf.model.util.Messages;
-import com.google.eclipse.protobuf.model.util.ModelObjects;
-import com.google.eclipse.protobuf.naming.NormalNamingStrategy;
-import com.google.eclipse.protobuf.protobuf.Group;
-import com.google.eclipse.protobuf.protobuf.IndexedElement;
-import com.google.eclipse.protobuf.protobuf.Message;
-import com.google.eclipse.protobuf.protobuf.MessageField;
-import com.google.eclipse.protobuf.protobuf.TypeExtension;
-import com.google.inject.Inject;
-
-/**
- * @author alruiz@google.com (Alex Ruiz)
- */
-class ExtensionFieldNameFinderStrategy implements CustomOptionFieldNameFinder.FinderStrategy {
- @Inject private MessageFields messageFields;
- @Inject private Messages messages;
- @Inject private ModelObjects modelObjects;
- @Inject private NormalNamingStrategy namingStrategy;
- @Inject private QualifiedNameDescriptions qualifiedNameDescriptions;
-
- @Override public Collection<IEObjectDescription> findMessageFields(IndexedElement reference) {
- Set<IEObjectDescription> descriptions = newHashSet();
- if (reference instanceof MessageField) {
- Message type = messageFields.messageTypeOf((MessageField) reference);
- // check first in descriptor.proto
- for (TypeExtension extension : messages.extensionsOf(type, modelObjects.rootOf(reference))) {
- for (IndexedElement element : extension.getElements()) {
- descriptions.addAll(qualifiedNameDescriptions.qualifiedNames(element, namingStrategy));
- }
- }
- } else if (reference instanceof Group) {
- String name = ((Group) reference).getName();
- if (!Strings.isNullOrEmpty(name)) {
- descriptions.addAll(qualifiedNameDescriptions.qualifiedNames(reference, namingStrategy));
- }
- }
- return descriptions;
- }
-}
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/LiteralDescriptions.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/LiteralDescriptions.java
deleted file mode 100644
index 588d262..0000000
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/LiteralDescriptions.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * 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 static java.util.Collections.emptyList;
-
-import static org.eclipse.xtext.EcoreUtil2.getAllContentsOfType;
-import static org.eclipse.xtext.resource.EObjectDescription.create;
-
-import static com.google.common.collect.Lists.newArrayList;
-
-import java.util.Collection;
-import java.util.List;
-
-import org.eclipse.xtext.resource.IEObjectDescription;
-
-import com.google.eclipse.protobuf.protobuf.Enum;
-import com.google.eclipse.protobuf.protobuf.Literal;
-
-/**
- * @author alruiz@google.com (Alex Ruiz)
- */
-class LiteralDescriptions {
- Collection<IEObjectDescription> literalsOf(Enum anEnum) {
- if (anEnum == null) {
- return emptyList();
- }
- List<IEObjectDescription> descriptions = newArrayList();
- for (Literal literal : getAllContentsOfType(anEnum, Literal.class)) {
- String name = literal.getName();
- descriptions.add(create(name, literal));
- }
- return descriptions;
- }
-}
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/MessageFieldFinderStrategy.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/MessageFieldFinderStrategy.java
deleted file mode 100644
index 0a847c4..0000000
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/MessageFieldFinderStrategy.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * 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 static org.eclipse.xtext.resource.EObjectDescription.create;
-
-import static com.google.common.collect.Sets.newHashSet;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Set;
-
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.xtext.resource.IEObjectDescription;
-
-import com.google.eclipse.protobuf.model.util.MessageFields;
-import com.google.eclipse.protobuf.model.util.Options;
-import com.google.eclipse.protobuf.protobuf.Group;
-import com.google.eclipse.protobuf.protobuf.IndexedElement;
-import com.google.eclipse.protobuf.protobuf.Message;
-import com.google.eclipse.protobuf.protobuf.MessageField;
-import com.google.eclipse.protobuf.protobuf.OneOf;
-import com.google.inject.Inject;
-
-/**
- * @author alruiz@google.com (Alex Ruiz)
- */
-class MessageFieldFinderStrategy implements CustomOptionFieldFinder.FinderStrategy {
- @Inject private MessageFields messageFields;
- @Inject private Options options;
-
- @Override public Collection<IEObjectDescription> findOptionFields(IndexedElement reference) {
- Collection<? extends EObject> elements;
- if (reference instanceof MessageField) {
- Message fieldType = messageFields.mapEntryTypeOf((MessageField) reference);
- if (fieldType == null) {
- fieldType = messageFields.messageTypeOf((MessageField) reference);
- }
-
- if (fieldType != null) {
- elements = fieldType.getElements();
- } else {
- elements = Collections.emptySet();
- }
- } else if (reference instanceof Group) {
- elements = ((Group) reference).getElements();
- } else {
- elements = Collections.emptySet();
- }
-
- Set<IEObjectDescription> descriptions = newHashSet();
- Collection<EObject> expandedElements = expandOneOfs(elements);
- for (EObject element : expandedElements) {
- IEObjectDescription d = describe(element);
- if (d != null) {
- descriptions.add(d);
- }
- }
- return descriptions;
- }
-
- private Collection<EObject> expandOneOfs(Collection<? extends EObject> elements) {
- Collection<EObject> expandedElements = new ArrayList<>(elements.size());
- for (EObject element : elements) {
- if (element instanceof OneOf) {
- expandedElements.addAll(((OneOf) element).getElements());
- }
- else {
- expandedElements.add(element);
- }
- }
- return expandedElements;
- }
-
- private IEObjectDescription describe(EObject e) {
- if (!(e instanceof IndexedElement)) {
- return null;
- }
- String name = options.nameForOption((IndexedElement) e);
- return create(name, e);
- }
-}
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/ModelElementFinder.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/ModelElementFinder.java
deleted file mode 100644
index 4520d67..0000000
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/ModelElementFinder.java
+++ /dev/null
@@ -1,214 +0,0 @@
-/*
- * 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 static java.util.Collections.emptyList;
-import static java.util.Collections.emptySet;
-import static java.util.Collections.unmodifiableSet;
-import static org.eclipse.emf.ecore.util.EcoreUtil.getAllContents;
-
-import com.google.eclipse.protobuf.model.util.Imports;
-import com.google.eclipse.protobuf.model.util.ModelObjects;
-import com.google.eclipse.protobuf.model.util.Packages;
-import com.google.eclipse.protobuf.model.util.Protobufs;
-import com.google.eclipse.protobuf.model.util.Resources;
-import com.google.eclipse.protobuf.protobuf.Group;
-import com.google.eclipse.protobuf.protobuf.Import;
-import com.google.eclipse.protobuf.protobuf.Message;
-import com.google.eclipse.protobuf.protobuf.Package;
-import com.google.eclipse.protobuf.protobuf.Protobuf;
-import com.google.eclipse.protobuf.resource.ResourceSets;
-import com.google.inject.Inject;
-
-import org.eclipse.emf.common.util.TreeIterator;
-import org.eclipse.emf.common.util.URI;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.emf.ecore.resource.ResourceSet;
-import org.eclipse.jdt.annotation.Nullable;
-import org.eclipse.xtext.resource.IEObjectDescription;
-import org.eclipse.xtext.util.OnChangeEvictingCache;
-import org.eclipse.xtext.util.OnChangeEvictingCache.CacheAdapter;
-
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-/**
- * @author alruiz@google.com (Alex Ruiz)
- */
-class ModelElementFinder {
- @Inject private Imports imports;
- @Inject private ModelObjects modelObjects;
- @Inject private Packages packages;
- @Inject private Protobufs protobufs;
- @Inject private Resources resources;
- @Inject private ResourceSets resourceSets;
-
- <T> Collection<IEObjectDescription> find(EObject start, FinderStrategy<T> strategy, T criteria) {
- Set<IEObjectDescription> descriptions = new HashSet<>();
- descriptions.addAll(getDescriptionsFromObjectAncestors(start, strategy, criteria));
- Protobuf root = modelObjects.rootOf(start);
- descriptions.addAll(getDescriptionsFromAllImports(root, strategy, criteria));
- return unmodifiableSet(descriptions);
- }
-
- private <T> Collection<IEObjectDescription> getDescriptionsFromObjectAncestors(
- EObject start, FinderStrategy<T> strategy, T criteria) {
- UniqueDescriptions descriptions = new UniqueDescriptions();
- EObject current = start.eContainer();
- while (current != null) {
- descriptions.addAll(getDescriptionsFromObjectDescendants(current, strategy, criteria, 0));
- current = current.eContainer();
- }
- return descriptions.values();
- }
-
- <T> Collection<IEObjectDescription> find(Protobuf start, FinderStrategy<T> strategy, T criteria) {
- Set<IEObjectDescription> descriptions = new HashSet<>();
- descriptions.addAll(getDescriptionsFromObjectDescendants(start, strategy, criteria, 0));
- descriptions.addAll(getDescriptionsFromAllImports(start, strategy, criteria));
- return unmodifiableSet(descriptions);
- }
-
- private <T> Collection<IEObjectDescription> getDescriptionsFromObjectDescendants(
- EObject start, FinderStrategy<T> strategy, T criteria, int level) {
- UniqueDescriptions descriptions = new UniqueDescriptions();
- for (EObject element : start.eContents()) {
- descriptions.addAll(strategy.local(element, criteria, level));
- if (element instanceof Message || element instanceof Group) {
- descriptions.addAll(
- getDescriptionsFromObjectDescendants(element, strategy, criteria, level + 1));
- }
- }
- return descriptions.values();
- }
-
- private <T> Collection<IEObjectDescription> getDescriptionsFromAllImports(
- Protobuf start, FinderStrategy<T> strategy, T criteria) {
- List<Import> allImports = protobufs.importsIn(start);
- if (allImports.isEmpty()) {
- return emptyList();
- }
- ResourceSet resourceSet = start.eResource().getResourceSet();
- return getDescriptionsFromImports(
- allImports, modelObjects.packageOf(start), resourceSet, strategy, criteria);
- }
-
- private <T> Collection<IEObjectDescription> getDescriptionsFromImports(
- List<Import> allImports,
- Package fromImporter,
- ResourceSet resourceSet,
- FinderStrategy<T> strategy,
- T criteria) {
- Set<IEObjectDescription> descriptions = new HashSet<>();
- for (Import anImport : allImports) {
- if (imports.isImportingDescriptor(anImport)) {
- descriptions.addAll(strategy.inDescriptor(anImport, criteria));
- continue;
- }
- URI resolvedUri = imports.resolvedUriOf(anImport);
- if (resolvedUri == null) {
- continue;
- }
- Resource imported = resourceSets.findResource(resourceSet, resolvedUri);
- if (imported == null) {
- continue;
- }
- Protobuf rootOfImported = resources.rootOf(imported);
- if (!protobufs.hasKnownSyntax(rootOfImported)) {
- continue;
- }
- if (rootOfImported != null) {
- CacheAdapter cache = new OnChangeEvictingCache().getOrCreate(imported);
- Set<IEObjectDescription> descriptionsFromImport =
- getFromCache(cache, resolvedUri, strategy, criteria);
- if (descriptionsFromImport == null) {
- descriptionsFromImport = new HashSet<>();
- descriptionsFromImport.addAll(
- getDescriptionsFromPublicImports(rootOfImported, strategy, criteria));
- if (arePackagesRelated(fromImporter, rootOfImported)) {
- descriptionsFromImport.addAll(
- getDescriptionsFromObjectDescendants(rootOfImported, strategy, criteria, 0));
- } else {
- Package packageOfImported = modelObjects.packageOf(rootOfImported);
- TreeIterator<Object> contents = getAllContents(imported, true);
- while (contents.hasNext()) {
- Object next = contents.next();
- descriptionsFromImport.addAll(
- strategy.imported(fromImporter, packageOfImported, next, criteria));
- }
- }
- putToCache(cache, resolvedUri, strategy, criteria, descriptionsFromImport);
- }
- descriptions.addAll(descriptionsFromImport);
- }
- }
- return descriptions;
- }
-
- private <T> Collection<IEObjectDescription> getDescriptionsFromPublicImports(
- Protobuf start, FinderStrategy<T> strategy, T criteria) {
- if (!protobufs.hasKnownSyntax(start)) {
- return emptySet();
- }
- List<Import> allImports = protobufs.publicImportsIn(start);
- if (allImports.isEmpty()) {
- return emptyList();
- }
- ResourceSet resourceSet = start.eResource().getResourceSet();
- return getDescriptionsFromImports(
- allImports, modelObjects.packageOf(start), resourceSet, strategy, criteria);
- }
-
- private <T> @Nullable Set<IEObjectDescription> getFromCache(
- CacheAdapter cache, URI uri, FinderStrategy<T> strategy, T criteria) {
- Map<FinderStrategy<T>, Map<T, Set<IEObjectDescription>>> strategyMap = cache.get(uri);
- if (strategyMap != null) {
- Map<T, Set<IEObjectDescription>> criteriaMap = strategyMap.get(strategy);
- if (criteriaMap != null) {
- return criteriaMap.get(criteria);
- }
- }
- return null;
- }
-
- private <T> void putToCache(
- CacheAdapter cache, URI uri, FinderStrategy<T> strategy, T criteria,
- Set<IEObjectDescription> descriptions) {
- Map<FinderStrategy<T>, Map<T, Set<IEObjectDescription>>> strategyMap = cache.get(uri);
- if (strategyMap == null) {
- strategyMap = new HashMap<>();
- cache.set(uri, strategyMap);
- }
- Map<T, Set<IEObjectDescription>> criteriaMap = strategyMap.get(strategy);
- if (criteriaMap == null) {
- criteriaMap = new HashMap<>();
- strategyMap.put(strategy, criteriaMap);
- }
- criteriaMap.put(criteria, descriptions);
- }
-
- private boolean arePackagesRelated(Package aPackage, EObject root) {
- Package p = modelObjects.packageOf(root);
- return packages.areRelated(aPackage, p);
- }
-
- static interface FinderStrategy<T> {
- Collection<IEObjectDescription> imported(
- Package fromImporter, Package fromImported, Object target, T criteria);
-
- Collection<IEObjectDescription> inDescriptor(Import anImport, T criteria);
-
- Collection<IEObjectDescription> local(Object target, T criteria, int level);
- }
-}
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/NativeOptionDescriptions.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/NativeOptionDescriptions.java
deleted file mode 100644
index 174445f..0000000
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/NativeOptionDescriptions.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * 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 static java.util.Collections.emptyList;
-import static java.util.Collections.unmodifiableList;
-import static org.eclipse.xtext.resource.EObjectDescription.create;
-import static com.google.common.collect.Lists.newArrayList;
-
-import java.util.Collection;
-import java.util.List;
-
-import org.eclipse.core.resources.IProject;
-import org.eclipse.xtext.resource.IEObjectDescription;
-
-import com.google.eclipse.protobuf.protobuf.AbstractOption;
-import com.google.eclipse.protobuf.protobuf.MessageField;
-import com.google.eclipse.protobuf.util.EResources;
-import com.google.inject.Inject;
-
-/**
- * @author alruiz@google.com (Alex Ruiz)
- */
-class NativeOptionDescriptions {
- @Inject private ProtoDescriptorProvider descriptorProvider;
-
- Collection<IEObjectDescription> sources(AbstractOption option) {
- IProject project = EResources.getProjectOf(option.eResource());
- ProtoDescriptor descriptor = descriptorProvider.primaryDescriptor(project);
- Collection<MessageField> optionSources = descriptor.availableOptionsFor(option.eContainer());
- if (optionSources.isEmpty()) {
- return emptyList();
- }
- return describe(optionSources);
- }
-
- private Collection<IEObjectDescription> describe(Collection<MessageField> fields) {
- List<IEObjectDescription> descriptions = newArrayList();
- for (MessageField field : fields) {
- String name = field.getName();
- descriptions.add(create(name, field));
- }
- return unmodifiableList(descriptions);
- }
-}
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/NormalFieldNameFinderStrategy.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/NormalFieldNameFinderStrategy.java
deleted file mode 100644
index c220a72..0000000
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/NormalFieldNameFinderStrategy.java
+++ /dev/null
@@ -1,73 +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 static com.google.common.collect.Sets.newHashSet;
-import static org.eclipse.xtext.resource.EObjectDescription.create;
-
-import com.google.common.base.Strings;
-import com.google.common.collect.ImmutableSet;
-import com.google.eclipse.protobuf.model.util.MessageFields;
-import com.google.eclipse.protobuf.protobuf.Group;
-import com.google.eclipse.protobuf.protobuf.IndexedElement;
-import com.google.eclipse.protobuf.protobuf.Message;
-import com.google.eclipse.protobuf.protobuf.MessageField;
-import com.google.eclipse.protobuf.protobuf.OneOf;
-import com.google.inject.Inject;
-
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.xtext.resource.IEObjectDescription;
-
-import java.util.Collection;
-import java.util.Set;
-
-/**
- * @author alruiz@google.com (Alex Ruiz)
- */
-class NormalFieldNameFinderStrategy implements CustomOptionFieldNameFinder.FinderStrategy {
- @Inject private MessageFields messageFields;
-
- @Override public Collection<IEObjectDescription> findMessageFields(IndexedElement reference) {
- Iterable<? extends EObject> elements;
- if (reference instanceof Group) {
- elements = ((Group) reference).getElements();
- } else if (reference instanceof MessageField) {
- MessageField field = (MessageField) reference;
- Message fieldType = messageFields.mapEntryTypeOf(field);
- if (fieldType == null) {
- fieldType = messageFields.messageTypeOf(field);
- }
- elements = fieldType.getElements();
- } else {
- elements = null;
- }
- return getDescriptions(elements);
- }
-
- private Set<IEObjectDescription> getDescriptions(Iterable<? extends EObject> elements) {
- if (elements == null) {
- return ImmutableSet.of();
- }
- Set<IEObjectDescription> descriptions = newHashSet();
- for (EObject element : elements) {
- if (element instanceof MessageField) {
- String name = ((MessageField) element).getName();
- descriptions.add(create(name, element));
- } else if (element instanceof Group) {
- String name = ((Group) element).getName();
- if (!Strings.isNullOrEmpty(name)) {
- descriptions.add(create(name, element));
- }
- } else if (element instanceof OneOf) {
- descriptions.addAll(getDescriptions(((OneOf) element).getElements()));
- }
- }
- return descriptions;
- }
-}
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/PackageIntersectionDescriptions.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/PackageIntersectionDescriptions.java
deleted file mode 100644
index 65f7e36..0000000
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/PackageIntersectionDescriptions.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * 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 static java.util.Collections.emptySet;
-
-import static org.eclipse.xtext.resource.EObjectDescription.create;
-
-import static com.google.common.collect.Lists.newArrayList;
-import static com.google.common.collect.Sets.newHashSet;
-
-import java.util.Collection;
-import java.util.List;
-import java.util.Set;
-
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.xtext.naming.IQualifiedNameProvider;
-import org.eclipse.xtext.naming.QualifiedName;
-import org.eclipse.xtext.resource.IEObjectDescription;
-
-import com.google.eclipse.protobuf.model.util.Packages;
-import com.google.eclipse.protobuf.model.util.QualifiedNames;
-import com.google.eclipse.protobuf.protobuf.Package;
-import com.google.inject.Inject;
-
-/**
- * @author alruiz@google.com (Alex Ruiz)
- */
-class PackageIntersectionDescriptions {
- @Inject private Packages packages;
- @Inject private QualifiedNames qualifiedNames;
- @Inject private IQualifiedNameProvider nameProvider;
-
- // See issue 161
- Collection<IEObjectDescription> intersection(Package fromImporter, Package fromImported, EObject e) {
- if (fromImporter == null || fromImported == null) {
- return emptySet();
- }
- return intersection2(segmentNames(fromImporter), segmentNames(fromImported), e);
- }
-
- private List<String> segmentNames(Package aPackage) {
- return packages.segmentsOf(aPackage);
- }
-
- private Collection<IEObjectDescription> intersection2(List<String> packageInImporter, List<String> packageInImported,
- EObject e) {
- int n1Count = packageInImporter.size();
- int n2Count = packageInImported.size();
- int start = -1;
- for (int i = 0; (i < n1Count && i < n2Count); i++) {
- if (!packageInImporter.get(i).equals(packageInImported.get(i))) {
- start = i;
- break;
- }
- }
- if (start == 0) {
- return emptySet(); // no intersection found.
- }
- Set<IEObjectDescription> descriptions = newHashSet();
- QualifiedName qualifiedName = nameProvider.getFullyQualifiedName(e);
- List<String> segments = newArrayList(qualifiedName.getSegments());
- for (int i = 0; i < start; i++) {
- segments.remove(0);
- QualifiedName newQualifiedName = qualifiedNames.createQualifiedName(segments);
- descriptions.add(create(newQualifiedName, e));
- }
- return descriptions;
- }
-}
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/ProtobufScopeProvider.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/ProtobufScopeProvider.java
index 12ce4d4..1fb9d27 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/ProtobufScopeProvider.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/ProtobufScopeProvider.java
@@ -9,23 +9,18 @@
package com.google.eclipse.protobuf.scoping;
import static com.google.eclipse.protobuf.protobuf.ProtobufPackage.Literals.OPTION_SOURCE__TARGET;
-import static com.google.eclipse.protobuf.scoping.OptionType.typeOf;
import static com.google.eclipse.protobuf.util.Encodings.UTF_8;
import static com.google.eclipse.protobuf.util.Tracer.DEBUG_SCOPING;
import static com.google.eclipse.protobuf.validation.ProtobufResourceValidator.getScopeProviderTimingCollector;
-import static java.util.Collections.emptySet;
import static java.util.Collections.singletonMap;
import static org.eclipse.emf.ecore.resource.ContentHandler.UNSPECIFIED_CONTENT_TYPE;
import static org.eclipse.xtext.EcoreUtil2.resolveLazyCrossReferences;
import static org.eclipse.xtext.resource.XtextResource.OPTION_ENCODING;
import static org.eclipse.xtext.util.CancelIndicator.NullImpl;
-import com.google.eclipse.protobuf.model.util.ModelObjects;
import com.google.eclipse.protobuf.naming.ProtobufQualifiedNameConverter;
import com.google.eclipse.protobuf.naming.ProtobufQualifiedNameProvider;
import com.google.eclipse.protobuf.preferences.general.PreferenceNames;
-import com.google.eclipse.protobuf.protobuf.AbstractCustomOption;
-import com.google.eclipse.protobuf.protobuf.AbstractOption;
import com.google.eclipse.protobuf.protobuf.ComplexType;
import com.google.eclipse.protobuf.protobuf.ComplexTypeLink;
import com.google.eclipse.protobuf.protobuf.ComplexValue;
@@ -34,7 +29,6 @@
import com.google.eclipse.protobuf.protobuf.CustomOption;
import com.google.eclipse.protobuf.protobuf.DefaultValueFieldOption;
import com.google.eclipse.protobuf.protobuf.Enum;
-import com.google.eclipse.protobuf.protobuf.ExtensibleType;
import com.google.eclipse.protobuf.protobuf.FieldName;
import com.google.eclipse.protobuf.protobuf.FieldOption;
import com.google.eclipse.protobuf.protobuf.Group;
@@ -52,7 +46,6 @@
import com.google.eclipse.protobuf.protobuf.Protobuf;
import com.google.eclipse.protobuf.protobuf.Rpc;
import com.google.eclipse.protobuf.protobuf.Stream;
-import com.google.eclipse.protobuf.protobuf.TypeExtension;
import com.google.eclipse.protobuf.protobuf.TypeLink;
import com.google.eclipse.protobuf.protobuf.ValueField;
import com.google.eclipse.protobuf.util.EResources;
@@ -83,25 +76,13 @@
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
-import java.util.Collection;
/**
* A scope provider for the Protobuf language.
*
* @author atrookey@google.com (Alexander Rookey)
*/
-public class ProtobufScopeProvider extends AbstractDeclarativeScopeProvider
- implements ScopeProvider {
- @Inject private ComplexTypeFinderStrategy complexTypeFinderDelegate;
- @Inject private CustomOptionFieldFinder customOptionFieldFinder;
- @Inject private CustomOptionFieldNameFinder customOptionFieldNameFinder;
- @Inject private CustomOptionFinderStrategy customOptionFinderDelegate;
- @Inject private ExtensionFieldFinderStrategy extensionFieldFinderDelegate;
- @Inject private ExtensionFieldNameFinderStrategy extensionFieldNameFinderDelegate;
- @Inject private MessageFieldFinderStrategy messageFieldFinderDelegate;
- @Inject private ModelElementFinder modelElementFinder;
- @Inject private ModelObjects modelObjects;
- @Inject private NormalFieldNameFinderStrategy normalFieldNameFinderDelegate;
+public class ProtobufScopeProvider extends AbstractDeclarativeScopeProvider {
@Inject private LinkingHelper linkingHelper;
@Inject private IPreferenceStoreAccess storeAccess;
@Inject private IUriResolver uriResolver;
@@ -141,10 +122,6 @@
return getOptionType(context.eContainer());
}
- private Collection<IEObjectDescription> allMessages(Protobuf root) {
- return modelElementFinder.find(root, complexTypeFinderDelegate, Message.class);
- }
-
/**
* Returns the InputStream associated with the resource at location {@code descriptorLocation}.
*/
@@ -211,7 +188,7 @@
return (ProtobufImportedNamespaceAwareLocalScopeProvider) super.getDelegate();
}
- /** Returns the local scope provider. */
+ /** Returns the global scope provider. */
private ProtobufImportUriGlobalScopeProvider getGlobalScopeProvider() {
return getLocalScopeProvider().getGlobalScopeProvider();
}
@@ -307,60 +284,6 @@
return retval;
}
- @Override
- public Collection<IEObjectDescription> potentialComplexTypesFor(MessageField field) {
- return modelElementFinder.find(field, complexTypeFinderDelegate, ComplexType.class);
- }
-
- @Override
- public Collection<IEObjectDescription> potentialExtensibleTypesFor(TypeExtension extension) {
- Protobuf root = modelObjects.rootOf(extension);
- return modelElementFinder.find(root, complexTypeFinderDelegate, ExtensibleType.class);
- }
-
- @Override
- public Collection<IEObjectDescription> potentialExtensionFieldNames(ComplexValue value) {
- return customOptionFieldNameFinder.findFieldNamesSources(
- value, extensionFieldNameFinderDelegate);
- }
-
- @Override
- public Collection<IEObjectDescription> potentialExtensionFieldsFor(AbstractCustomOption option) {
- return customOptionFieldFinder.findOptionFields(option, extensionFieldFinderDelegate);
- }
-
- @Override
- public Collection<IEObjectDescription> potentialMessageFieldsFor(AbstractCustomOption option) {
- return customOptionFieldFinder.findOptionFields(option, messageFieldFinderDelegate);
- }
-
- @Override
- public Collection<IEObjectDescription> potentialMessagesFor(Rpc rpc) {
- Protobuf root = modelObjects.rootOf(rpc);
- return allMessages(root);
- }
-
- @Override
- public Collection<IEObjectDescription> potentialMessagesFor(Stream stream) {
- Protobuf root = modelObjects.rootOf(stream);
- return allMessages(root);
- }
-
- @Override
- public Collection<IEObjectDescription> potentialNormalFieldNames(ComplexValue value) {
- return customOptionFieldNameFinder.findFieldNamesSources(value, normalFieldNameFinderDelegate);
- }
-
- @Override
- public Collection<IEObjectDescription> potentialSourcesFor(AbstractCustomOption option) {
- OptionType optionType = typeOf((AbstractOption) option);
- Collection<IEObjectDescription> descriptions = emptySet();
- if (optionType != null) {
- descriptions = modelElementFinder.find(option, customOptionFinderDelegate, optionType);
- }
- return descriptions;
- }
-
/**
* Recursively scopes the {@code FieldName} starting with the {@code OptionSource}.
*
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/QualifiedNameDescriptions.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/QualifiedNameDescriptions.java
deleted file mode 100644
index 65528f4..0000000
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/QualifiedNameDescriptions.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * 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 static java.util.Collections.unmodifiableList;
-
-import static org.eclipse.xtext.resource.EObjectDescription.create;
-
-import static com.google.common.collect.Lists.newArrayList;
-
-import java.util.Collection;
-import java.util.List;
-
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.xtext.naming.QualifiedName;
-import org.eclipse.xtext.resource.IEObjectDescription;
-
-import com.google.eclipse.protobuf.model.util.QualifiedNames;
-import com.google.eclipse.protobuf.naming.IProtobufQualifiedNameProvider;
-import com.google.eclipse.protobuf.naming.NamingStrategy;
-import com.google.inject.Inject;
-
-/**
- * @author alruiz@google.com (Alex Ruiz)
- */
-class QualifiedNameDescriptions {
- @Inject private IProtobufQualifiedNameProvider nameProvider;
- @Inject private QualifiedNames qualifiedNames;
-
- Collection<IEObjectDescription> qualifiedNames(EObject e, NamingStrategy namingStrategy) {
- QualifiedName fqn = nameProvider.getFullyQualifiedName(e, namingStrategy);
- return allQualifiedNames(e, fqn);
- }
-
- private Collection<IEObjectDescription> allQualifiedNames(EObject e, QualifiedName fqn) {
- List<IEObjectDescription> descriptions = newArrayList();
- descriptions.add(create(fqn, e));
- descriptions.add(create(qualifiedNames.addLeadingDot(fqn), e));
- return unmodifiableList(descriptions);
- }
-}
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/ScopeProvider.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/ScopeProvider.java
deleted file mode 100644
index a568949..0000000
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/ScopeProvider.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * 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 java.util.Collection;
-
-import org.eclipse.xtext.resource.IEObjectDescription;
-
-import com.google.eclipse.protobuf.protobuf.AbstractCustomOption;
-import com.google.eclipse.protobuf.protobuf.ComplexValue;
-import com.google.eclipse.protobuf.protobuf.MessageField;
-import com.google.eclipse.protobuf.protobuf.Rpc;
-import com.google.eclipse.protobuf.protobuf.Stream;
-import com.google.eclipse.protobuf.protobuf.TypeExtension;
-
-/**
- * @author alruiz@google.com (Alex Ruiz)
- */
-public interface ScopeProvider {
- Collection<IEObjectDescription> potentialComplexTypesFor(MessageField field);
-
- Collection<IEObjectDescription> potentialExtensibleTypesFor(TypeExtension extension);
-
- Collection<IEObjectDescription> potentialMessagesFor(Rpc rpc);
-
- Collection<IEObjectDescription> potentialMessagesFor(Stream stream);
-
- Collection<IEObjectDescription> potentialSourcesFor(AbstractCustomOption option);
-
- Collection<IEObjectDescription> potentialMessageFieldsFor(AbstractCustomOption option);
-
- Collection<IEObjectDescription> potentialExtensionFieldsFor(AbstractCustomOption option);
-
- Collection<IEObjectDescription> potentialNormalFieldNames(ComplexValue value);
-
- Collection<IEObjectDescription> potentialExtensionFieldNames(ComplexValue value);
-}
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/UniqueDescriptions.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/UniqueDescriptions.java
deleted file mode 100644
index c4ab188..0000000
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/UniqueDescriptions.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Copyright (c) 2012 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 static com.google.common.collect.Maps.newHashMap;
-
-import java.util.Collection;
-import java.util.Map;
-
-import org.eclipse.xtext.resource.IEObjectDescription;
-
-/**
- * @author alruiz@google.com (Alex Ruiz)
- */
-class UniqueDescriptions {
-
- private final Map<String, IEObjectDescription> descriptionsByName = newHashMap();
-
- void addAll(Collection<IEObjectDescription> descriptions) {
- for (IEObjectDescription description : descriptions) {
- String name = description.getName().toString();
- if (!descriptionsByName.containsKey(name)) {
- descriptionsByName.put(name, description);
- }
- }
- }
-
- Collection<IEObjectDescription> values() {
- return descriptionsByName.values();
- }
-}