Handle the scoping case where a LiteralLink is the child of a ValueField
Change-Id: Ib6f2d2bcf30b0aa667133c6c7421408b2f6178d6
Signed-off-by: Alexander Rookey <atrookey@google.com>
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/scoping/ProtobufScopeProvider_scope_LiteralLink_target_Test.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/scoping/ProtobufScopeProvider_scope_LiteralLink_target_Test.java
index a341d0b..33123c9 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/scoping/ProtobufScopeProvider_scope_LiteralLink_target_Test.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/scoping/ProtobufScopeProvider_scope_LiteralLink_target_Test.java
@@ -22,6 +22,8 @@
import org.junit.Test;
import com.google.eclipse.protobuf.junit.core.XtextRule;
+import com.google.eclipse.protobuf.protobuf.ComplexValueCurlyBracket;
+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.FieldOption;
@@ -30,6 +32,7 @@
import com.google.eclipse.protobuf.protobuf.Message;
import com.google.eclipse.protobuf.protobuf.MessageField;
import com.google.eclipse.protobuf.protobuf.Option;
+import com.google.eclipse.protobuf.protobuf.SimpleValueField;
import com.google.inject.Inject;
/**
@@ -256,6 +259,43 @@
// // Create file sample_proto.proto
// syntax = "proto2";
+ // package sample;
+ //
+ // extend proto2.MethodOptions {
+ // optional Foo method = 2910611;
+ // }
+ //
+ // message Foo {
+ // enum Kind {
+ // CUSTOM = 1;
+ // CREATE = 2;
+ // }
+ // optional Kind kind = 1 [default = CUSTOM];
+
+ // syntax = "proto2";
+ // package example;
+ // import "sample_proto.proto";
+ //
+ // message Example {
+ // option (sample.method) = {
+ // kind: CREATE
+ // };
+ // }
+ @Test
+ public void should_provide_Literals_for_source_of_simple_value_field() {
+ Message message = xtext.find("Example", " {", Message.class);
+ CustomOption customFieldOption = (CustomOption) message.getElements().get(0);
+ ComplexValueCurlyBracket complexValueCurlyBracket =
+ (ComplexValueCurlyBracket) customFieldOption.getValue();
+ SimpleValueField simpleValueField =
+ (SimpleValueField) complexValueCurlyBracket.getFields().get(0);
+ LiteralLink literalLink = (LiteralLink) simpleValueField.getValues().get(0);
+ IScope scope = scopeProvider.getScope(literalLink, LITERAL_LINK__TARGET);
+ assertThat(descriptionsIn(scope), contain("CREATE"));
+ }
+
+ // // Create file sample_proto.proto
+ // syntax = "proto2";
// package example;
//
// enum Status {
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 ab63d3b..c69fa05 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
@@ -34,6 +34,7 @@
import com.google.eclipse.protobuf.protobuf.OptionSource;
import com.google.eclipse.protobuf.protobuf.Package;
import com.google.eclipse.protobuf.protobuf.Protobuf;
+import com.google.eclipse.protobuf.protobuf.SimpleValueField;
import com.google.eclipse.protobuf.protobuf.TypeLink;
import com.google.eclipse.protobuf.protobuf.ValueField;
import com.google.eclipse.protobuf.util.EResources;
@@ -340,6 +341,9 @@
indexedElement = ((CustomOption) container).getSource().getTarget();
}
}
+ if (container instanceof SimpleValueField) {
+ indexedElement = ((SimpleValueField) container).getName().getTarget();
+ }
return createNormalizedScopeForIndexedElement(indexedElement, reference);
}