In progress: [Issue 155] Editor does not support complex custom options.
Code cleanup.
diff --git a/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/model/util/FieldOptions_propertyFrom_Test.java b/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/model/util/FieldOptions_sourceOf_Test.java
similarity index 87%
rename from com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/model/util/FieldOptions_propertyFrom_Test.java
rename to com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/model/util/FieldOptions_sourceOf_Test.java
index 52d524c..c9a5470 100644
--- a/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/model/util/FieldOptions_propertyFrom_Test.java
+++ b/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/model/util/FieldOptions_sourceOf_Test.java
@@ -19,11 +19,11 @@
import org.junit.*;
/**
- * Tests for <code>{@link FieldOptions#propertyFrom(FieldOption)}</code>.
+ * Tests for <code>{@link FieldOptions#sourceOf(FieldOption)}</code>.
*
* @author alruiz@google.com (Alex Ruiz)
*/
-public class FieldOptions_propertyFrom_Test {
+public class FieldOptions_sourceOf_Test {
@Rule public XtextRule xtext = createWith(integrationTestSetup());
@@ -38,7 +38,7 @@
// }
@Test public void should_return_property_of_native_field_option() {
FieldOption option = xtext.find("deprecated", FieldOption.class);
- Property p = fieldOptions.propertyFrom(option);
+ Property p = (Property) fieldOptions.sourceOf(option);
assertThat(p.getName(), equalTo("deprecated"));
}
@@ -53,7 +53,7 @@
// }
@Test public void should_return_property_of_custom_field_option() {
FieldOption option = xtext.find("encoding", ")", FieldOption.class);
- Property p = fieldOptions.propertyFrom(option);
+ Property p = (Property) fieldOptions.sourceOf(option);
assertThat(p.getName(), equalTo("encoding"));
}
}
diff --git a/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/model/util/Options_propertyFrom_Test.java b/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/model/util/Options_sourceOf_Test.java
similarity index 88%
rename from com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/model/util/Options_propertyFrom_Test.java
rename to com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/model/util/Options_sourceOf_Test.java
index af538ea..55a084b 100644
--- a/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/model/util/Options_propertyFrom_Test.java
+++ b/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/model/util/Options_sourceOf_Test.java
@@ -19,11 +19,11 @@
import org.junit.*;
/**
- * Tests for <code>{@link Options#propertyFrom(Option)}</code>.
+ * Tests for <code>{@link Options#sourceOf(Option)}</code>.
*
* @author alruiz@google.com (Alex Ruiz)
*/
-public class Options_propertyFrom_Test {
+public class Options_sourceOf_Test {
@Rule public XtextRule xtext = createWith(integrationTestSetup());
@@ -36,7 +36,7 @@
// option java_package = 'com.google.eclipse.protobuf.tests';
@Test public void should_return_property_of_native_option() {
Option option = xtext.find("java_package", Option.class);
- Property p = options.propertyFrom(option);
+ Property p = (Property) options.sourceOf(option);
assertThat(p.getName(), equalTo("java_package"));
}
@@ -49,7 +49,7 @@
// option (encoding) = 'UTF-8';
@Test public void should_return_property_of_custom_option() {
Option option = xtext.find("encoding", ")", Option.class);
- Property p = options.propertyFrom(option);
+ Property p = (Property) options.sourceOf(option);
assertThat(p.getName(), equalTo("encoding"));
}
}
diff --git a/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/scoping/Issue131_AddOptionsForService_Test.java b/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/scoping/Issue131_AddOptionsForService_Test.java
index dceff51..dcd8633 100644
--- a/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/scoping/Issue131_AddOptionsForService_Test.java
+++ b/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/scoping/Issue131_AddOptionsForService_Test.java
@@ -58,7 +58,7 @@
// }
@Test public void should_support_Service_options() {
Option option = xtext.find("code", ")", Option.class);
- IScope scope = provider.scope_PropertyRef_property(option.getProperty(), reference);
+ IScope scope = provider.scope_OptionSource_optionField(option.getSource(), reference);
assertThat(descriptionsIn(scope), containAll("code", "proto.code", "google.proto.code", "com.google.proto.code",
".com.google.proto.code",
"info", "proto.info", "google.proto.info", "com.google.proto.info",
diff --git a/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/scoping/Issue147_AddSupportForGroupOptions_Test.java b/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/scoping/Issue147_AddSupportForGroupOptions_Test.java
index 99008d8..c394448 100644
--- a/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/scoping/Issue147_AddSupportForGroupOptions_Test.java
+++ b/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/scoping/Issue147_AddSupportForGroupOptions_Test.java
@@ -54,7 +54,7 @@
// }
@Test public void should_provide_Property_fields_for_native_option() {
NativeFieldOption option = xtext.find("deprecated", NativeFieldOption.class);
- IScope scope = provider.scope_PropertyRef_property(option.getProperty(), reference);
+ IScope scope = provider.scope_OptionSource_optionField(option.getSource(), reference);
Collection<Property> fieldOptions = descriptor().optionsOfType(FIELD);
assertThat(descriptionsIn(scope), containAll(fieldOptions));
}
@@ -79,7 +79,7 @@
// }
@Test public void should_provide_Property_fields_for_custom_option() {
CustomFieldOption option = xtext.find("code", ")", CustomFieldOption.class);
- IScope scope = provider.scope_PropertyRef_property(option.getProperty(), reference);
+ IScope scope = provider.scope_OptionSource_optionField(option.getSource(), reference);
assertThat(descriptionsIn(scope), containAll("code", "proto.code", "google.proto.code", "com.google.proto.code",
".com.google.proto.code",
"info", "proto.info", "google.proto.info", "com.google.proto.info",
diff --git a/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/scoping/ProtobufScopeProvider_scope_MessagePropertyRef_messageProperty_Test.java b/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/scoping/ProtobufScopeProvider_scope_OptionMessageFieldSource_optionMessageField_Test.java
similarity index 79%
rename from com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/scoping/ProtobufScopeProvider_scope_MessagePropertyRef_messageProperty_Test.java
rename to com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/scoping/ProtobufScopeProvider_scope_OptionMessageFieldSource_optionMessageField_Test.java
index 0eb89a7..b9c9687 100644
--- a/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/scoping/ProtobufScopeProvider_scope_MessagePropertyRef_messageProperty_Test.java
+++ b/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/scoping/ProtobufScopeProvider_scope_OptionMessageFieldSource_optionMessageField_Test.java
@@ -23,11 +23,11 @@
import org.junit.*;
/**
- * Tests for <code>{@link ProtobufScopeProvider#scope_MessagePropertyRef_messageProperty(MessagePropertyRef, EReference)}</code>.
+ * Tests for <code>{@link ProtobufScopeProvider#scope_OptionMessageFieldSource_optionMessageField(OptionMessageFieldSource, EReference)}</code>.
*
* @author alruiz@google.com (Alex Ruiz)
*/
-public class ProtobufScopeProvider_scope_MessagePropertyRef_messageProperty_Test {
+public class ProtobufScopeProvider_scope_OptionMessageFieldSource_optionMessageField_Test {
private static EReference reference;
@@ -57,8 +57,8 @@
// option (type).code = 68;
@Test public void should_provide_Property_fields_for_custom_option_field() {
CustomOption option = xtext.find("type", ")", CustomOption.class);
- MessagePropertyRef optionField = (MessagePropertyRef) option.getOptionFields().get(0);
- IScope scope = provider.scope_MessagePropertyRef_messageProperty(optionField, reference);
+ OptionMessageFieldSource optionField = (OptionMessageFieldSource) option.getOptionFields().get(0);
+ IScope scope = provider.scope_OptionMessageFieldSource_optionMessageField(optionField, reference);
Message typeMessage = xtext.find("Type", " {", Message.class);
assertThat(descriptionsIn(scope), containAllPropertiesIn(typeMessage));
}
@@ -79,8 +79,8 @@
// }
@Test public void should_provide_Property_fields_for_custom_field_option_field() {
CustomFieldOption option = xtext.find("type", ")", CustomFieldOption.class);
- MessagePropertyRef optionField = (MessagePropertyRef) option.getOptionFields().get(0);
- IScope scope = provider.scope_MessagePropertyRef_messageProperty(optionField, reference);
+ OptionMessageFieldSource optionField = (OptionMessageFieldSource) option.getOptionFields().get(0);
+ IScope scope = provider.scope_OptionMessageFieldSource_optionMessageField(optionField, reference);
Message typeMessage = xtext.find("Type", " {", Message.class);
assertThat(descriptionsIn(scope), containAllPropertiesIn(typeMessage));
}
diff --git a/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/scoping/ProtobufScopeProvider_scope_PropertyRef_property_Test.java b/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/scoping/ProtobufScopeProvider_scope_OptionSource_optionField_Test.java
similarity index 88%
rename from com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/scoping/ProtobufScopeProvider_scope_PropertyRef_property_Test.java
rename to com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/scoping/ProtobufScopeProvider_scope_OptionSource_optionField_Test.java
index 9ab54a2..c7f9721 100644
--- a/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/scoping/ProtobufScopeProvider_scope_PropertyRef_property_Test.java
+++ b/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/scoping/ProtobufScopeProvider_scope_OptionSource_optionField_Test.java
@@ -27,11 +27,11 @@
import java.util.Collection;
/**
- * Tests for <code>{@link ProtobufScopeProvider#scope_PropertyRef_property(PropertyRef, EReference)}</code>
+ * Tests for <code>{@link ProtobufScopeProvider#scope_OptionSource_optionField(OptionSource, EReference)}</code>
*
* @author alruiz@google.com (Alex Ruiz)
*/
-public class ProtobufScopeProvider_scope_PropertyRef_property_Test {
+public class ProtobufScopeProvider_scope_OptionSource_optionField_Test {
private static EReference reference;
@@ -50,7 +50,7 @@
// option optimize_for = SPEED;
@Test public void should_provide_Property_fields_for_native_option() {
Option option = xtext.find("optimize_for", Option.class);
- IScope scope = provider.scope_PropertyRef_property(option.getProperty(), reference);
+ IScope scope = provider.scope_OptionSource_optionField(option.getSource(), reference);
Collection<Property> fileOptions = descriptor().optionsOfType(FILE);
assertThat(descriptionsIn(scope), containAll(fileOptions));
}
@@ -60,7 +60,7 @@
// }
@Test public void should_provide_Property_fields_for_native_field_option() {
NativeFieldOption option = xtext.find("ctype", NativeFieldOption.class);
- IScope scope = provider.scope_PropertyRef_property(option.getProperty(), reference);
+ IScope scope = provider.scope_OptionSource_optionField(option.getSource(), reference);
Collection<Property> fieldOptions = descriptor().optionsOfType(FIELD);
assertThat(descriptionsIn(scope), containAll(fieldOptions));
}
@@ -81,7 +81,7 @@
// option (code) = 68;
@Test public void should_provide_Property_fields_for_custom_option() {
Option option = xtext.find("code", ")", Option.class);
- IScope scope = provider.scope_PropertyRef_property(option.getProperty(), reference);
+ IScope scope = provider.scope_OptionSource_optionField(option.getSource(), reference);
assertThat(descriptionsIn(scope), containAll("code", "proto.code", "google.proto.code", "com.google.proto.code",
".com.google.proto.code",
"info", "proto.info", "google.proto.info", "com.google.proto.info",
@@ -106,7 +106,7 @@
// option (test.proto.code) = 68;
@Test public void should_provide_imported_Property_fields_for_custom_option() {
Option option = xtext.find("code", ")", Option.class);
- IScope scope = provider.scope_PropertyRef_property(option.getProperty(), reference);
+ IScope scope = provider.scope_OptionSource_optionField(option.getSource(), reference);
assertThat(descriptionsIn(scope), containAll("test.proto.code", ".test.proto.code",
"test.proto.info", ".test.proto.info"));
}
@@ -129,7 +129,7 @@
// option (code) = 68;
@Test public void should_provide_imported_Property_fields_for_custom_option_with_equal_package() {
Option option = xtext.find("code", ")", Option.class);
- IScope scope = provider.scope_PropertyRef_property(option.getProperty(), reference);
+ IScope scope = provider.scope_OptionSource_optionField(option.getSource(), reference);
assertThat(descriptionsIn(scope), containAll("code", "proto.code", "google.proto.code", "com.google.proto.code",
".com.google.proto.code",
"info", "proto.info", "google.proto.info", "com.google.proto.info",
@@ -149,7 +149,7 @@
// }
@Test public void should_provide_Property_fields_for_custom_field_option() {
CustomFieldOption option = xtext.find("code", ")", CustomFieldOption.class);
- IScope scope = provider.scope_PropertyRef_property(option.getProperty(), reference);
+ IScope scope = provider.scope_OptionSource_optionField(option.getSource(), reference);
assertThat(descriptionsIn(scope), containAll("code", "proto.code", "google.proto.code", "com.google.proto.code",
".com.google.proto.code",
"info", "proto.info", "google.proto.info", "com.google.proto.info",
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/core/Finder.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/core/Finder.java
index ad6c527..3360420 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/core/Finder.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/core/Finder.java
@@ -22,7 +22,7 @@
*/
class Finder {
- private static final String[] FEATURE_NAMES = { "name", "property", "message", "type" };
+ private static final String[] FEATURE_NAMES = { "name", "message", "type", "source", "optionField" };
private final String protoAsText;
private final AbstractNode root;
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 f15b361..5efc73c 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
@@ -73,8 +73,8 @@
String proposal = SYNTAX + space() + EQUAL_PROTO2_IN_QUOTES;
proposeAndAccept(proposal, imageHelper.getImage(images.imageFor(Syntax.class)), context, acceptor);
}
-
- @Override public void completeNativeOption_Property(EObject model, Assignment assignment,
+
+ @Override public void completeNativeOption_Source(EObject model, Assignment assignment,
ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
ProtoDescriptor descriptor = descriptorProvider.primaryDescriptor();
Collection<Property> optionProperties = descriptor.availableOptionsFor(model);
@@ -89,7 +89,7 @@
@Override public void completeNativeOption_Value(EObject model, Assignment assignment,
ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
NativeOption option = (NativeOption) model;
- Property property = options.propertyFrom(option);
+ Property property = (Property) options.sourceOf(option);
if (property == null) return;
ProtoDescriptor descriptor = descriptorProvider.primaryDescriptor();
Enum enumType = descriptor.enumTypeOf(property);
@@ -167,11 +167,13 @@
if (model instanceof Property) return (Property) model;
if (model instanceof Option) {
Option option = (Option) model;
- return options.propertyFrom(option);
+ Field source = options.sourceOf(option);
+ if (source instanceof Property) return (Property) source;
}
if (model instanceof FieldOption) {
FieldOption option = (FieldOption) model;
- return fieldOptions.propertyFrom(option);
+ Field source = fieldOptions.sourceOf(option);
+ if (source instanceof Property) return (Property) source;
}
return null;
}
@@ -263,7 +265,7 @@
return imageHelper.getImage(images.defaultImage());
}
- @Override public void completeNativeFieldOption_Property(EObject model, Assignment assignment,
+ @Override public void completeNativeFieldOption_Source(EObject model, Assignment assignment,
ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
Property p = extractElementFromContext(context, Property.class);
if (p != null) {
@@ -338,7 +340,7 @@
return;
}
ProtoDescriptor descriptor = descriptorProvider.primaryDescriptor();
- Property property = fieldOptions.propertyFrom(option);
+ Property property = (Property) fieldOptions.sourceOf(option);
Enum enumType = descriptor.enumTypeOf(property);
if (enumType != null) {
proposeAndAccept(enumType, context, acceptor);
@@ -401,27 +403,23 @@
return word.equals(previousWord);
}
- @Override public void completePropertyRef_Property(EObject model, Assignment assignment,
+ @Override public void completeOptionSource_OptionField(EObject model, Assignment assignment,
ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
}
- @Override public void completeMessagePropertyRef_MessageProperty(EObject model, Assignment assignment,
- ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
- }
-
- @Override public void completeCustomOption_Property(EObject model, Assignment assignment,
+ @Override public void completeCustomOption_Source(EObject model, Assignment assignment,
ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
if (!(model instanceof CustomOption)) return;
CustomOption option = (CustomOption) model;
- IScope scope = scopes.scope_PropertyRef_property(option.getProperty(), null);
+ IScope scope = scopes.scope_OptionSource_optionField(option.getSource(), null);
proposeAndAcceptOptions(scope, context, acceptor);
}
- @Override public void completeCustomFieldOption_Property(EObject model, Assignment assignment,
+ @Override public void completeCustomFieldOption_Source(EObject model, Assignment assignment,
ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
if (!(model instanceof CustomFieldOption)) return;
CustomFieldOption option = (CustomFieldOption) model;
- IScope scope = scopes.scope_PropertyRef_property(option.getProperty(), null);
+ IScope scope = scopes.scope_OptionSource_optionField(option.getSource(), null);
proposeAndAcceptOptions(scope, context, acceptor);
}
@@ -453,11 +451,7 @@
ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
super.completeCustomFieldOption_OptionFields(model, assignment, context, acceptor);
}
-
- @Override public void complete_MessagePropertyRef(EObject model, RuleCall ruleCall, ContentAssistContext context,
- ICompletionProposalAcceptor acceptor) {
- super.complete_MessagePropertyRef(model, ruleCall, context, acceptor);
- }
+
// @Override public void completeCustomOption_PropertyField(EObject model, Assignment assignment,
// ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
@@ -487,9 +481,11 @@
ICompletionProposalAcceptor acceptor) {
if (!(model instanceof CustomOption)) return;
CustomOption option = (CustomOption) model;
- Property property = options.fieldFrom(option);
- if (property == null) property = options.propertyFrom(option);
- proposeAndAcceptOptionFieldValue(property, context, acceptor);
+ Field f = options.fieldFrom(option);
+ if (f == null) f = options.sourceOf(option);
+ if (f instanceof Property) {
+ proposeAndAcceptOptionFieldValue((Property) f, context, acceptor);
+ }
}
@Override public void completeCustomFieldOption_Value(EObject model, Assignment assignment,
@@ -498,7 +494,7 @@
if (!(model instanceof CustomFieldOption)) return;
CustomFieldOption option = (CustomFieldOption) model;
Property property = fieldOptions.fieldFrom(option);
- if (property == null) property = fieldOptions.propertyFrom(option);
+ if (property == null) property = fieldOptions.fieldFrom(option);
proposeAndAcceptOptionFieldValue(property, context, acceptor);
}
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/documentation/SLCommentDocumentationProvider.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/documentation/SLCommentDocumentationProvider.java
index 43a0409..85a234c 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/documentation/SLCommentDocumentationProvider.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/documentation/SLCommentDocumentationProvider.java
@@ -59,11 +59,11 @@
private EObject findRealTarget(EObject o) {
if (o instanceof Option) {
- Property p = options.propertyFrom((Option) o);
+ Field p = options.sourceOf((Option) o);
return p != null ? p : o;
}
if (o instanceof FieldOption) {
- Property p = fieldOptions.propertyFrom((FieldOption) o);
+ Field p = fieldOptions.sourceOf((FieldOption) o);
return p != null ? p : o;
}
return o;
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 ccc663d..8f1134b 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
@@ -203,9 +203,9 @@
}
private void highlight(Option option, IHighlightedPositionAcceptor acceptor) {
- Property property = options.propertyFrom(option);
- if (property != null) {
- highlightFirstFeature(option, OPTION__PROPERTY, acceptor, DEFAULT_ID);
+ Field field = options.sourceOf(option);
+ if (field != null) {
+ highlightFirstFeature(option, OPTION__SOURCE, acceptor, DEFAULT_ID);
}
ValueRef ref = option.getValue();
if (ref instanceof LiteralRef) {
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/labeling/Labels.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/labeling/Labels.java
index 8eb7508..b901d76 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/labeling/Labels.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/labeling/Labels.java
@@ -64,8 +64,9 @@
}
private Object labelFor(Option o) {
- Property p = options.propertyFrom(o);
- return p == null ? null : p.getName();
+ Field f = options.sourceOf(o);
+ if (f instanceof Property) return ((Property) f).getName();
+ return null;
}
private Object labelFor(ExtendMessage e) {
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 1698f3f..33cb82a 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
@@ -197,11 +197,11 @@
NativeOption | CustomOption;
NativeOption:
- 'option' property=PropertyRef '=' value=ValueRef ';';
+ 'option' source=OptionSource '=' value=ValueRef ';';
CustomOption:
- 'option' '(' property=PropertyRef ')'
- ('.' optionFields+=OptionField ('.' optionFields+=OptionField)*)? '=' value=ValueRef ';';
+ 'option' '(' source=OptionSource ')'
+ ('.' optionFields+=OptionFieldSource ('.' optionFields+=OptionFieldSource)*)? '=' value=ValueRef ';';
FieldOption:
DefaultValueFieldOption | NativeFieldOption | CustomFieldOption;
@@ -210,21 +210,21 @@
'default' '=' value=ValueRef;
NativeFieldOption:
- property=PropertyRef '=' value=ValueRef;
+ source=OptionSource '=' value=ValueRef;
CustomFieldOption:
- '(' property=PropertyRef ')'
- ('.' optionFields+=OptionField ('.' optionFields+=OptionField)*)? '=' value=ValueRef;
+ '(' source=OptionSource ')'
+ ('.' optionFields+=OptionFieldSource ('.' optionFields+=OptionFieldSource)*)? '=' value=ValueRef;
-PropertyRef:
- property=[Property|QualifiedName];
+OptionSource:
+ optionField=[Field|QualifiedName];
-OptionField:
- MessagePropertyRef | ExtendMessagePropertyRef;
+OptionFieldSource:
+ OptionMessageFieldSource | OptionExtendMessageFieldSource;
-MessagePropertyRef:
- messageProperty=[Property];
+OptionMessageFieldSource:
+ optionMessageField=[Field];
-ExtendMessagePropertyRef:
- '(' extendMessageProperty=[Property|QualifiedName] ')';
+OptionExtendMessageFieldSource:
+ '(' optionExtendMessageField=[Field|QualifiedName] ')';
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/model/util/FieldOptions.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/model/util/FieldOptions.java
index 2b6cac0..9717eb6 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/model/util/FieldOptions.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/model/util/FieldOptions.java
@@ -34,8 +34,9 @@
* @return the name of the given option.
*/
public String nameOf(FieldOption option) {
- Property p = propertyFrom(option);
- return (p == null) ? null : p.getName();
+ Field f = sourceOf(option);
+ if (f instanceof Property) return ((Property) f).getName();
+ return null;
}
/**
@@ -44,33 +45,32 @@
* <pre>
* [(myFieldOption) = true]
* </pre>
- * this method will return the <code>{@link Property}</code> "myFieldOption" is pointing to.
+ * this method will return the <code>{@link Field}</code> "myFieldOption" is pointing to.
* @param option the given {@code FieldOption}.
- * @return the {@code Property} the given {@code FieldOption} is referring to, or {@code null} if it cannot be
- * found.
+ * @return the {@code Property} the given {@code FieldOption} is referring to, or {@code null} if it cannot be found.
*/
- public Property propertyFrom(FieldOption option) {
- PropertyRef ref = null;
+ public Field sourceOf(FieldOption option) {
+ OptionSource source = null;
if (option instanceof NativeFieldOption) {
NativeFieldOption nativeOption = (NativeFieldOption) option;
- ref = nativeOption.getProperty();
+ source = nativeOption.getSource();
}
if (option instanceof CustomFieldOption) {
CustomFieldOption customOption = (CustomFieldOption) option;
- ref = customOption.getProperty();
+ source = customOption.getSource();
}
- return (ref == null) ? null : ref.getProperty();
+ return (source == null) ? null : source.getOptionField();
}
/**
- * Returns the field of the <code>{@link Property}</code> the given <code>{@link CustomFieldOption}</code> is
- * referring to. In the following example
+ * Returns the field of the <code>{@link Field}</code> the given <code>{@link CustomFieldOption}</code> is referring
+ * to. In the following example
* <pre>
* [(myFieldOption).field = true]
* </pre>
- * this method will return the <code>{@link Property}</code> "field" is pointing to.
+ * this method will return the <code>{@link Field}</code> "field" is pointing to.
* @param option the given {@code FieldOption}.
- * @return the field of the {@code Property} the given {@code CustomFieldOption} is referring to, or {@code null} if
+ * @return the field of the {@code Field} the given {@code CustomFieldOption} is referring to, or {@code null} if
* one cannot be found.
*/
public Property fieldFrom(CustomFieldOption option) {
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/model/util/Options.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/model/util/Options.java
index afa0b5a..d199747 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/model/util/Options.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/model/util/Options.java
@@ -20,19 +20,19 @@
public class Options {
/**
- * Returns the <code>{@link Property}</code> the given <code>{@link Option}</code> is referring to. In the
+ * Returns the <code>{@link Field}</code> the given <code>{@link Option}</code> is referring to. In the
* following example
* <pre>
* option (myOption) = true;
* </pre>
- * this method will return the <code>{@link Property}</code> "myOption" is pointing to.
+ * this method will return the <code>{@link Field}</code> "myOption" is pointing to.
* @param option the given {@code Option}.
- * @return the {@code Property} the given {@code Option} is referring to, or {@code null} if it cannot be
+ * @return the {@code Field} the given {@code Option} is referring to, or {@code null} if it cannot be
* found.
*/
- public Property propertyFrom(Option option) {
- PropertyRef ref = option.getProperty();
- return (ref == null) ? null : ref.getProperty();
+ public Field sourceOf(Option option) {
+ OptionSource source = option.getSource();
+ return (source == null) ? null : source.getOptionField();
}
/**
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/CustomOptionFieldScopeFinder.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/CustomOptionFieldScopeFinder.java
index 7a72d69..21a625f 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/CustomOptionFieldScopeFinder.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/CustomOptionFieldScopeFinder.java
@@ -30,34 +30,36 @@
@Inject private Options options;
@Inject private QualifiedNameDescriptions qualifiedNamesDescriptions;
- Collection<IEObjectDescription> findScope(MessagePropertyRef ref) {
- return findScope(ref, new IEObjectDescriptionsProvider() {
- @Override public Collection<IEObjectDescription> fieldsInType(Property p) {
- Message propertyType = modelFinder.messageTypeOf(p);
+ Collection<IEObjectDescription> findScope(OptionMessageFieldSource fieldSource) {
+ return findScope(fieldSource, new IEObjectDescriptionsProvider() {
+ @Override public Collection<IEObjectDescription> fieldsInType(Field f) {
+ if (!(f instanceof Property)) return emptyList();
+ Message propertyType = modelFinder.messageTypeOf((Property) f);
if (propertyType == null) return emptyList();
Set<IEObjectDescription> descriptions = new HashSet<IEObjectDescription>();
for (MessageElement e : propertyType.getElements()) {
if (!(e instanceof Property)) continue;
- Property f = (Property) e;
- descriptions.add(create(f.getName(), f));
+ Property current = (Property) e;
+ descriptions.add(create(current.getName(), current));
}
return descriptions;
}
});
}
- Collection<IEObjectDescription> findScope(ExtendMessagePropertyRef ref) {
- return findScope(ref, new IEObjectDescriptionsProvider() {
- @Override public Collection<IEObjectDescription> fieldsInType(Property p) {
- Message propertyType = modelFinder.messageTypeOf(p);
+ Collection<IEObjectDescription> findScope(OptionExtendMessageFieldSource fieldSource) {
+ return findScope(fieldSource, new IEObjectDescriptionsProvider() {
+ @Override public Collection<IEObjectDescription> fieldsInType(Field f) {
+ if (!(f instanceof Property)) return emptyList();
+ Message propertyType = modelFinder.messageTypeOf((Property) f);
if (propertyType == null) return emptyList();
Set<IEObjectDescription> descriptions = new HashSet<IEObjectDescription>();
for (ExtendMessage extend : modelFinder.extensionsOf(propertyType)) {
for (MessageElement e : extend.getElements()) {
if (!(e instanceof Property)) continue;
- Property f = (Property) e;
- descriptions.addAll(qualifiedNamesDescriptions.qualifiedNames(f));
- descriptions.add(create(f.getName(), f));
+ Property current = (Property) e;
+ descriptions.addAll(qualifiedNamesDescriptions.qualifiedNames(current));
+ descriptions.add(create(current.getName(), current));
}
}
return descriptions;
@@ -65,63 +67,64 @@
});
}
- private Collection<IEObjectDescription> findScope(EObject ref, IEObjectDescriptionsProvider provider) {
- EObject container = ref.eContainer();
- Property p = null;
+ private Collection<IEObjectDescription> findScope(EObject fieldSource, IEObjectDescriptionsProvider provider) {
+ EObject container = fieldSource.eContainer();
+ Field f = null;
if (container instanceof CustomOption) {
CustomOption option = (CustomOption) container;
- p = referredProperty(ref, option);
+ f = referredField(fieldSource, option);
}
if (container instanceof CustomFieldOption) {
CustomFieldOption option = (CustomFieldOption) container;
- p = referredProperty(ref, option);
+ f = referredField(fieldSource, option);
}
- if (p != null) return provider.fieldsInType(p);
+ if (f != null) return provider.fieldsInType(f);
return emptySet();
}
- private Property referredProperty(EObject ref, final CustomOption option) {
- return referredProperty(ref, option.getOptionFields(), new Provider<Property>() {
- @Override public Property get() {
- return options.propertyFrom(option);
+ private Field referredField(EObject fieldSource, final CustomOption option) {
+ return referredField(fieldSource, option.getOptionFields(), new Provider<Field>() {
+ @Override public Field get() {
+ return options.sourceOf(option);
}
});
}
- private Property referredProperty(EObject ref, final CustomFieldOption option) {
- return referredProperty(ref, option.getOptionFields(), new Provider<Property>() {
- @Override public Property get() {
- return fieldOptions.propertyFrom(option);
+ private Field referredField(EObject fieldSource, final CustomFieldOption option) {
+ return referredField(fieldSource, option.getOptionFields(), new Provider<Field>() {
+ @Override public Field get() {
+ return fieldOptions.fieldFrom(option);
}
});
}
- private Property referredProperty(EObject ref, List<OptionField> fields, Provider<Property> provider) {
- OptionField previous = null;
+ private Field referredField(EObject fieldSource, List<OptionFieldSource> allFieldSources,
+ Provider<Field> provider) {
+ OptionFieldSource previous = null;
boolean isFirstField = true;
- for (OptionField field : fields) {
- if (field == ref) {
- return (isFirstField) ? provider.get() : propertyFrom(previous);
+ for (OptionFieldSource s : allFieldSources) {
+ if (s == fieldSource) {
+ return (isFirstField) ? provider.get() : fieldFrom(previous);
}
- previous = field;
+ previous = s;
isFirstField = false;
}
return null;
}
- private Property propertyFrom(OptionField field) {
- if (field instanceof MessagePropertyRef) {
- MessagePropertyRef ref = (MessagePropertyRef) field;
- return ref.getMessageProperty();
+ private Field fieldFrom(OptionFieldSource fieldSource) {
+ if (fieldSource instanceof OptionMessageFieldSource) {
+ OptionMessageFieldSource source = (OptionMessageFieldSource) fieldSource;
+ return source.getOptionMessageField();
}
- if (field instanceof ExtendMessagePropertyRef) {
- ExtendMessagePropertyRef ref = (ExtendMessagePropertyRef) field;
- return ref.getExtendMessageProperty();
+ if (fieldSource instanceof OptionExtendMessageFieldSource) {
+ OptionExtendMessageFieldSource source = (OptionExtendMessageFieldSource) fieldSource;
+ return source.getOptionExtendMessageField();
}
return null;
}
private static interface IEObjectDescriptionsProvider {
- Collection<IEObjectDescription> fieldsInType(Property p);
+ Collection<IEObjectDescription> fieldsInType(Field f);
}
}
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/CustomOptionScopeFinder.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/CustomOptionScopeFinder.java
index 74b9f96..7906fc8 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/CustomOptionScopeFinder.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/CustomOptionScopeFinder.java
@@ -8,23 +8,60 @@
*/
package com.google.eclipse.protobuf.scoping;
+import static java.util.Collections.emptySet;
+import static org.eclipse.xtext.resource.EObjectDescription.create;
+
+import com.google.eclipse.protobuf.model.util.ModelFinder;
+import com.google.eclipse.protobuf.protobuf.*;
+import com.google.inject.Inject;
+
+import org.eclipse.xtext.naming.QualifiedName;
import org.eclipse.xtext.resource.IEObjectDescription;
-import java.util.Collection;
+import java.util.*;
/**
* @author alruiz@google.com (Alex Ruiz)
*/
-class CustomOptionScopeFinder extends ExtendMessageScopeFinder {
+class CustomOptionScopeFinder implements ScopeFinder {
+
+ @Inject private LocalNamesProvider localNamesProvider;
+ @Inject private ModelFinder modelFinder;
+ @Inject private QualifiedNameDescriptions qualifiedNamesDescriptions;
+
+ @Override public Collection<IEObjectDescription> fromProtoDescriptor(Import anImport, Object criteria) {
+ return emptySet();
+ }
@Override public Collection<IEObjectDescription> descriptions(Object target, Object criteria) {
OptionType optionType = optionTypeFrom(criteria);
- return super.descriptions(target, optionType.messageName());
+ if (!isExtendingOptionMessage(target, optionType)) return emptySet();
+ Set<IEObjectDescription> descriptions = new HashSet<IEObjectDescription>();
+ ExtendMessage extend = (ExtendMessage) target;
+ for (MessageElement e : extend.getElements()) {
+ if (!(e instanceof Property)) continue;
+ Property p = (Property) e;
+ descriptions.addAll(qualifiedNamesDescriptions.qualifiedNames(p));
+ }
+ return descriptions;
}
@Override public Collection<IEObjectDescription> descriptions(Object target, Object criteria, int level) {
OptionType optionType = optionTypeFrom(criteria);
- return super.descriptions(target, optionType.messageName(), level);
+ if (!isExtendingOptionMessage(target, optionType)) return emptySet();
+ Set<IEObjectDescription> descriptions = new HashSet<IEObjectDescription>();
+ ExtendMessage extend = (ExtendMessage) target;
+ for (MessageElement e : extend.getElements()) {
+ if (!(e instanceof Property)) continue;
+ Property p = (Property) e;
+ List<QualifiedName> names = localNamesProvider.namesOf(p);
+ int nameCount = names.size();
+ for (int i = level; i < nameCount; i++) {
+ descriptions.add(create(names.get(i), p));
+ }
+ descriptions.addAll(qualifiedNamesDescriptions.qualifiedNames(p));
+ }
+ return descriptions;
}
private OptionType optionTypeFrom(Object criteria) {
@@ -32,4 +69,11 @@
throw new IllegalArgumentException("Search criteria should be OptionType");
return (OptionType) criteria;
}
+
+ private boolean isExtendingOptionMessage(Object o, OptionType optionType) {
+ if (!(o instanceof ExtendMessage)) return false;
+ Message message = modelFinder.messageFrom((ExtendMessage) o);
+ if (message == null) return false;
+ return optionType.messageName().equals(message.getName());
+ }
}
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/ExtendMessageScopeFinder.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/ExtendMessageScopeFinder.java
deleted file mode 100644
index d1729c8..0000000
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/ExtendMessageScopeFinder.java
+++ /dev/null
@@ -1,79 +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 com.google.eclipse.protobuf.model.util.ModelFinder;
-import com.google.eclipse.protobuf.protobuf.*;
-import com.google.inject.Inject;
-
-import org.eclipse.xtext.naming.QualifiedName;
-import org.eclipse.xtext.resource.IEObjectDescription;
-
-import java.util.*;
-
-/**
- * @author alruiz@google.com (Alex Ruiz)
- */
-class ExtendMessageScopeFinder implements ScopeFinder {
-
- @Inject private LocalNamesProvider localNamesProvider;
- @Inject private ModelFinder modelFinder;
- @Inject private QualifiedNameDescriptions qualifiedNamesDescriptions;
-
- @Override public Collection<IEObjectDescription> fromProtoDescriptor(Import anImport, Object criteria) {
- return emptySet();
- }
-
- @Override public Collection<IEObjectDescription> descriptions(Object target, Object criteria) {
- String messageName = messageNameFrom(criteria);
- if (!isExtendingOptionMessage(target, messageName)) return emptySet();
- Set<IEObjectDescription> descriptions = new HashSet<IEObjectDescription>();
- ExtendMessage extend = (ExtendMessage) target;
- for (MessageElement e : extend.getElements()) {
- if (!(e instanceof Property)) continue;
- Property p = (Property) e;
- descriptions.addAll(qualifiedNamesDescriptions.qualifiedNames(p));
- }
- return descriptions;
- }
-
- @Override public Collection<IEObjectDescription> descriptions(Object target, Object criteria, int level) {
- String messageName = messageNameFrom(criteria);
- if (!isExtendingOptionMessage(target, messageName)) return emptySet();
- Set<IEObjectDescription> descriptions = new HashSet<IEObjectDescription>();
- ExtendMessage extend = (ExtendMessage) target;
- for (MessageElement e : extend.getElements()) {
- if (!(e instanceof Property)) continue;
- Property p = (Property) e;
- List<QualifiedName> names = localNamesProvider.namesOf(p);
- int nameCount = names.size();
- for (int i = level; i < nameCount; i++) {
- descriptions.add(create(names.get(i), p));
- }
- descriptions.addAll(qualifiedNamesDescriptions.qualifiedNames(p));
- }
- return descriptions;
- }
-
- private String messageNameFrom(Object criteria) {
- if (!(criteria instanceof String))
- throw new IllegalArgumentException("Search criteria should be String");
- return (String) criteria;
- }
-
- private boolean isExtendingOptionMessage(Object o, String messageName) {
- if (!(o instanceof ExtendMessage)) return false;
- Message message = modelFinder.messageFrom((ExtendMessage) o);
- if (message == null) return false;
- return messageName.equals(message.getName());
- }
-}
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 89023d1..33c7d1c 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
@@ -72,23 +72,23 @@
}
if (c instanceof NativeOption) {
ProtoDescriptor descriptor = descriptorProvider.primaryDescriptor();
- Property p = options.propertyFrom((Option) c);
- anEnum = descriptor.enumTypeOf(p);
+ Field f = options.sourceOf((Option) c);
+ if (f instanceof Property) anEnum = descriptor.enumTypeOf((Property) f);
}
if (c instanceof CustomOption) {
CustomOption option = (CustomOption) c;
c = options.fieldFrom(option);
- if (c == null) c = options.propertyFrom(option);
+ if (c == null) c = options.sourceOf(option);
}
if (c instanceof NativeFieldOption) {
ProtoDescriptor descriptor = descriptorProvider.primaryDescriptor();
- Property p = fieldOptions.propertyFrom((FieldOption) c);
- anEnum = descriptor.enumTypeOf(p);
+ Field f = fieldOptions.sourceOf((FieldOption) c);
+ if (f instanceof Property) anEnum = descriptor.enumTypeOf((Property) f);
}
if (c instanceof CustomFieldOption) {
CustomFieldOption option = (CustomFieldOption) c;
c = fieldOptions.fieldFrom(option);
- if (c == null) c = fieldOptions.propertyFrom(option);
+ if (c == null) c = fieldOptions.fieldFrom(option);
}
if (c instanceof Property) {
anEnum = modelFinder.enumTypeOf((Property) c);
@@ -97,8 +97,8 @@
}
@SuppressWarnings("unused")
- public IScope scope_PropertyRef_property(PropertyRef propertyRef, EReference reference) {
- EObject c = propertyRef.eContainer();
+ public IScope scope_OptionSource_optionField(OptionSource optionSource, EReference reference) {
+ EObject c = optionSource.eContainer();
if (c instanceof NativeOption) {
NativeOption option = (NativeOption) c;
return createScope(nativeOptionDescriptions.properties(option));
@@ -120,14 +120,15 @@
}
@SuppressWarnings("unused")
- public IScope scope_MessagePropertyRef_messageProperty(MessagePropertyRef propertyRef, EReference reference) {
- return createScope(customOptionFieldScopeFinder.findScope(propertyRef));
+ public IScope scope_OptionMessageFieldSource_optionMessageField(OptionMessageFieldSource source,
+ EReference reference) {
+ return createScope(customOptionFieldScopeFinder.findScope(source));
}
@SuppressWarnings("unused")
- public IScope scope_ExtendMessagePropertyRef_extendMessageProperty(ExtendMessagePropertyRef propertyRef,
+ public IScope scope_OptionExtendMessageFieldSource_optionExtendMessageField(OptionExtendMessageFieldSource source,
EReference reference) {
- return createScope(customOptionFieldScopeFinder.findScope(propertyRef));
+ return createScope(customOptionFieldScopeFinder.findScope(source));
}
private static IScope createScope(Iterable<IEObjectDescription> descriptions) {