Finished cleaning up the grammar.
diff --git a/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/scoping/ProtobufScopeProvider_scope_ExtensionFieldNotationNameSource_extension_Test.java b/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/scoping/ProtobufScopeProvider_scope_ExtensionFieldName_target_Test.java
similarity index 79%
rename from com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/scoping/ProtobufScopeProvider_scope_ExtensionFieldNotationNameSource_extension_Test.java
rename to com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/scoping/ProtobufScopeProvider_scope_ExtensionFieldName_target_Test.java
index 46e8709..47bd44a 100644
--- a/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/scoping/ProtobufScopeProvider_scope_ExtensionFieldNotationNameSource_extension_Test.java
+++ b/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/scoping/ProtobufScopeProvider_scope_ExtensionFieldName_target_Test.java
@@ -23,11 +23,11 @@
import org.junit.*;
/**
- * Tests for <code>{@link ProtobufScopeProvider#scope_ExtensionFieldNotationNameSource_extension(ExtensionFieldNotationNameSource, EReference)}</code>.
+ * Tests for <code>{@link ProtobufScopeProvider#scope_FieldName_target(FieldName, EReference)}</code>.
*
* @author alruiz@google.com (Alex Ruiz)
*/
-public class ProtobufScopeProvider_scope_ExtensionFieldNotationNameSource_extension_Test {
+public class ProtobufScopeProvider_scope_ExtensionFieldName_target_Test {
private static EReference reference;
@@ -66,9 +66,9 @@
// }
// };
@Test public void should_provide_sources_for_aggregate_field() {
- AggregateField field = xtext.find("google.proto.test.fileopt", "]", AggregateField.class);
- ExtensionFieldNotationNameSource s = (ExtensionFieldNotationNameSource) field.getName();
- IScope scope = provider.scope_ExtensionFieldNotationNameSource_extension(s, reference);
+ ValueField field = xtext.find("google.proto.test.fileopt", "]", ValueField.class);
+ ExtensionFieldName name = (ExtensionFieldName) field.getName();
+ IScope scope = provider.scope_FieldName_target(name, reference);
assertThat(descriptionsIn(scope), containAll("google.proto.test.fileopt", ".google.proto.test.fileopt"));
}
}
diff --git a/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/scoping/ProtobufScopeProvider_scope_NormalFieldNotationNameSource_property_Test.java b/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/scoping/ProtobufScopeProvider_scope_NormalFieldName_target_Test.java
similarity index 74%
rename from com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/scoping/ProtobufScopeProvider_scope_NormalFieldNotationNameSource_property_Test.java
rename to com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/scoping/ProtobufScopeProvider_scope_NormalFieldName_target_Test.java
index 4d10274..15c7562 100644
--- a/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/scoping/ProtobufScopeProvider_scope_NormalFieldNotationNameSource_property_Test.java
+++ b/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/scoping/ProtobufScopeProvider_scope_NormalFieldName_target_Test.java
@@ -23,11 +23,11 @@
import org.junit.*;
/**
- * Tests for <code>{@link ProtobufScopeProvider#scope_NormalFieldNotationNameSource_property(NormalFieldNotationNameSource, EReference)}</code>
+ * Tests for <code>{@link ProtobufScopeProvider#scope_FieldName_target(FieldName, EReference)}</code>
*
* @author alruiz@google.com (Alex Ruiz)
*/
-public class ProtobufScopeProvider_scope_NormalFieldNotationNameSource_property_Test {
+public class ProtobufScopeProvider_scope_NormalFieldName_target_Test {
private static EReference reference;
@@ -59,9 +59,9 @@
// code: 68
// };
@Test public void should_provide_sources_for_aggregate_field() {
- AggregateField field = xtext.find("code", ":", AggregateField.class);
- NormalFieldNotationNameSource s = (NormalFieldNotationNameSource) field.getName();
- IScope scope = provider.scope_NormalFieldNotationNameSource_property(s, reference);
+ ValueField field = xtext.find("code", ":", ValueField.class);
+ NormalFieldName name = (NormalFieldName) field.getName();
+ IScope scope = provider.scope_FieldName_target(name, reference);
Message message = xtext.find("Type", " {", Message.class);
assertThat(descriptionsIn(scope), containAllFieldsIn(message));
}
@@ -87,9 +87,9 @@
// name { value: 'Address' }
// };
@Test public void should_provide_sources_for_nested_field_notation_in_option() {
- AggregateField field = xtext.find("value", ":", AggregateField.class);
- NormalFieldNotationNameSource s = (NormalFieldNotationNameSource) field.getName();
- IScope scope = provider.scope_NormalFieldNotationNameSource_property(s, reference);
+ ValueField field = xtext.find("value", ":", ValueField.class);
+ NormalFieldName name = (NormalFieldName) field.getName();
+ IScope scope = provider.scope_FieldName_target(name, reference);
Message message = xtext.find("Names", " {", Message.class);
assertThat(descriptionsIn(scope), containAllFieldsIn(message));
}
@@ -110,9 +110,9 @@
// optional int target = 1 [(type) = { code: 68 }];
// }
@Test public void should_provide_sources_for_field_notation_in_field_option() {
- AggregateField field = xtext.find("code", ":", AggregateField.class);
- NormalFieldNotationNameSource s = (NormalFieldNotationNameSource) field.getName();
- IScope scope = provider.scope_NormalFieldNotationNameSource_property(s, reference);
+ ValueField field = xtext.find("code", ":", ValueField.class);
+ NormalFieldName name = (NormalFieldName) field.getName();
+ IScope scope = provider.scope_FieldName_target(name, reference);
Message message = xtext.find("Type", " {", Message.class);
assertThat(descriptionsIn(scope), containAllFieldsIn(message));
}
@@ -138,9 +138,9 @@
// optional int target = 1 [(type) = { name: { value: 'Address' } }];
// }
@Test public void should_provide_sources_for_nested_field_notation_in_field_option() {
- AggregateField field = xtext.find("value", ":", AggregateField.class);
- NormalFieldNotationNameSource s = (NormalFieldNotationNameSource) field.getName();
- IScope scope = provider.scope_NormalFieldNotationNameSource_property(s, reference);
+ ValueField field = xtext.find("value", ":", ValueField.class);
+ NormalFieldName name = (NormalFieldName) field.getName();
+ IScope scope = provider.scope_FieldName_target(name, reference);
Message message = xtext.find("Names", " {", Message.class);
assertThat(descriptionsIn(scope), containAllFieldsIn(message));
}
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 d4424c1..da7d2ea 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
@@ -33,7 +33,6 @@
import com.google.eclipse.protobuf.grammar.CommonKeyword;
import com.google.eclipse.protobuf.model.util.*;
-import com.google.eclipse.protobuf.model.util.Fields;
import com.google.eclipse.protobuf.protobuf.*;
import com.google.eclipse.protobuf.protobuf.Enum;
import com.google.eclipse.protobuf.scoping.*;
@@ -85,7 +84,8 @@
@Override public void completeMessageLink_Target(EObject model, Assignment assignment, ContentAssistContext context,
ICompletionProposalAcceptor acceptor) {
- Collection<IEObjectDescription> scope = scoping().findTypeScope(model);
+ if (!(model instanceof MessageField)) return;
+ Collection<IEObjectDescription> scope = scoping().findScope((MessageField) model);
for (IEObjectDescription d : descriptionChooser.shortestQualifiedNamesIn(scope)) {
Image image = imageHelper.getImage(images.imageFor(d.getEObjectOrProxy()));
proposeAndAccept(d, image, context, acceptor);
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/Protobuf.xtext b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/Protobuf.xtext
index fbed3c2..1c76d53 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/Protobuf.xtext
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/Protobuf.xtext
@@ -169,31 +169,31 @@
MessageField | Group;
Value:
- AggregateValue | SimpleValueLink;
+ ComplexValue | SimpleValueLink;
// { foo: 1, bar: 2 }
-AggregateValue:
+ComplexValue:
'{'
- fields+=AggregateField ((',')? fields+=AggregateField)*
+ fields+=ValueField ((',')? fields+=ValueField)*
'}';
-AggregateField:
+ValueField:
SimpleFieldNotation | ComplexFieldNotation;
SimpleFieldNotation:
- name=FieldNotationNameSource ':' value=SimpleValueLink;
+ name=FieldName ':' value=SimpleValueLink;
ComplexFieldNotation:
- name=FieldNotationNameSource ':'? values=AggregateValue;
+ name=FieldName ':'? values=ComplexValue;
-FieldNotationNameSource:
- NormalFieldNotationNameSource | ExtensionFieldNotationNameSource;
+FieldName:
+ NormalFieldName | ExtensionFieldName;
-NormalFieldNotationNameSource:
- property=[MessageField];
+NormalFieldName:
+ target=[MessageField];
-ExtensionFieldNotationNameSource:
- '[' extension=[MessageField|QualifiedName] ']';
+ExtensionFieldName:
+ '[' target=[MessageField|QualifiedName] ']';
SimpleValueLink:
LiteralLink | BooleanLink | NumberLink | StringLink;
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/FieldNotationScopeFinder.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/FieldNotationScopeFinder.java
index 0c90c7d..967478f 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/FieldNotationScopeFinder.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/FieldNotationScopeFinder.java
@@ -30,21 +30,21 @@
@Inject private ModelFinder modelFinder;
@Inject private QualifiedNameDescriptions qualifiedNameDescriptions;
- Collection<IEObjectDescription> sourceOf(FieldNotationNameSource s) {
- EObject container = s.eContainer();
- if (!(container instanceof AggregateField)) return emptySet();
- MessageField field = sourceOf((AggregateField) container);
+ Collection<IEObjectDescription> sourceOf(FieldName name) {
+ EObject container = name.eContainer();
+ if (!(container instanceof ValueField)) return emptySet();
+ MessageField field = sourceOf((ValueField) container);
if (field == null) return emptySet();
- if (s instanceof NormalFieldNotationNameSource) {
+ if (name instanceof NormalFieldName) {
return propertiesInTypeOf(field);
}
return propertiesInExtendMessageOf(field);
}
- private MessageField sourceOf(AggregateField field) {
+ private MessageField sourceOf(ValueField field) {
EObject container = field.eContainer();
IndexedElement source = null;
- if (container instanceof AggregateValue) {
+ if (container instanceof ComplexValue) {
container = container.eContainer();
if (container instanceof CustomOption) {
CustomOption option = (CustomOption) container;
@@ -63,16 +63,8 @@
}
private MessageField sourceOf(ComplexFieldNotation n) {
- FieldNotationNameSource s = n.getName();
- if (s instanceof NormalFieldNotationNameSource) {
- NormalFieldNotationNameSource normal = (NormalFieldNotationNameSource) s;
- return normal.getProperty();
- }
- if (s instanceof ExtensionFieldNotationNameSource) {
- ExtensionFieldNotationNameSource normal = (ExtensionFieldNotationNameSource) s;
- return normal.getExtension();
- }
- return null;
+ FieldName name = n.getName();
+ return (name == null) ? null : name.getTarget();
}
private Collection<IEObjectDescription> propertiesInTypeOf(MessageField field) {
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 012bf69..010a499 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
@@ -50,14 +50,14 @@
public IScope scope_ComplexTypeLink_target(ComplexTypeLink link, EReference r) {
EObject c = link.eContainer();
if (c instanceof MessageField) {
- return createScope(findTypeScope(c));
+ return createScope(findScope((MessageField) c));
}
Set<IEObjectDescription> descriptions = emptySet();
return createScope(descriptions);
}
- @Override public Collection<IEObjectDescription> findTypeScope(EObject o) {
- return astWalker.traverseAst(o, typeScopeFinder, ComplexType.class);
+ @Override public Collection<IEObjectDescription> findScope(MessageField field) {
+ return astWalker.traverseAst(field, typeScopeFinder, ComplexType.class);
}
@SuppressWarnings("unused")
@@ -102,8 +102,8 @@
}
@SuppressWarnings("unused")
- public IScope scope_OptionSource_target(OptionSource s, EReference r) {
- EObject c = s.eContainer();
+ public IScope scope_OptionSource_target(OptionSource source, EReference r) {
+ EObject c = source.eContainer();
if (c instanceof NativeOption) {
NativeOption option = (NativeOption) c;
return createScope(nativeOptionDescriptions.properties(option));
@@ -175,17 +175,12 @@
}
@SuppressWarnings("unused")
- public IScope scope_NormalFieldNotationNameSource_property(NormalFieldNotationNameSource s, EReference r) {
- return findScope(s);
+ public IScope scope_FieldName_target(FieldName name, EReference r) {
+ return findScope(name);
}
- @SuppressWarnings("unused")
- public IScope scope_ExtensionFieldNotationNameSource_extension(ExtensionFieldNotationNameSource s, EReference r) {
- return findScope(s);
- }
-
- private IScope findScope(FieldNotationNameSource s) {
- return createScope(fieldNotationScopeFinder.sourceOf(s));
+ private IScope findScope(FieldName name) {
+ return createScope(fieldNotationScopeFinder.sourceOf(name));
}
private static IScope createScope(Iterable<IEObjectDescription> descriptions) {
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/Scoping.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/Scoping.java
index 5deda46..b74f062 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/Scoping.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/Scoping.java
@@ -20,17 +20,18 @@
*/
public interface Scoping {
- Collection<IEObjectDescription> findScope(CustomOption option);
-
- Collection<IEObjectDescription> findScope(CustomFieldOption option);
-
- Collection<IEObjectDescription> findScope(OptionField field);
+ // TODO redo this interface taking same parameters as ProtobufScopeProvider
+ Collection<IEObjectDescription> findFieldScope(CustomFieldOption option);
Collection<IEObjectDescription> findFieldScope(CustomOption option);
- Collection<IEObjectDescription> findFieldScope(CustomFieldOption option);
-
- Collection<IEObjectDescription> findTypeScope(EObject o);
-
Collection<IEObjectDescription> findMessageScope(EObject o);
+
+ Collection<IEObjectDescription> findScope(CustomFieldOption option);
+
+ Collection<IEObjectDescription> findScope(CustomOption option);
+
+ Collection<IEObjectDescription> findScope(MessageField o);
+
+ Collection<IEObjectDescription> findScope(OptionField field);
}