Fixed: [Issue 156] Editor does not support custom options for enum
values.
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 c394448..be37f9d 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
@@ -28,21 +28,21 @@
/**
* Tests fix for <a href="http://code.google.com/p/protobuf-dt/issues/detail?id=147">Issue 147</a>.
- *
+ *
* @author alruiz@google.com (Alex Ruiz)
*/
public class Issue147_AddSupportForGroupOptions_Test {
private static EReference reference;
-
+
@BeforeClass public static void setUpOnce() {
reference = mock(EReference.class);
}
-
+
@Rule public XtextRule xtext = createWith(integrationTestSetup());
-
+
private ProtobufScopeProvider provider;
-
+
@Before public void setUp() {
provider = xtext.getInstanceOf(ProtobufScopeProvider.class);
}
@@ -52,37 +52,37 @@
// required int64 groupId = 2;
// }
// }
- @Test public void should_provide_Property_fields_for_native_option() {
+ @Test public void should_provide_fields_for_native_option() {
NativeFieldOption option = xtext.find("deprecated", NativeFieldOption.class);
IScope scope = provider.scope_OptionSource_optionField(option.getSource(), reference);
Collection<Property> fieldOptions = descriptor().optionsOfType(FIELD);
assertThat(descriptionsIn(scope), containAll(fieldOptions));
}
-
+
private ProtoDescriptor descriptor() {
ProtoDescriptorProvider descriptorProvider = xtext.getInstanceOf(ProtoDescriptorProvider.class);
return descriptorProvider.primaryDescriptor();
}
-
+
// package com.google.proto;
// import 'google/protobuf/descriptor.proto';
- //
+ //
// extend google.protobuf.FieldOptions {
// optional int32 code = 1000;
// optional int32 info = 1001;
// }
- //
+ //
// message Person {
// repeated group membership = 1 [(code) = 68] {
// required int64 groupId = 2;
// }
// }
- @Test public void should_provide_Property_fields_for_custom_option() {
+ @Test public void should_provide_fields_for_custom_option() {
CustomFieldOption option = xtext.find("code", ")", CustomFieldOption.class);
IScope scope = provider.scope_OptionSource_optionField(option.getSource(), reference);
- assertThat(descriptionsIn(scope), containAll("code", "proto.code", "google.proto.code", "com.google.proto.code",
+ 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",
+ "info", "proto.info", "google.proto.info", "com.google.proto.info",
".com.google.proto.info"));
}
}
diff --git a/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/scoping/Issue156_AddSupportForEnumValueOptions_Test.java b/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/scoping/Issue156_AddSupportForEnumValueOptions_Test.java
new file mode 100644
index 0000000..df88541
--- /dev/null
+++ b/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/scoping/Issue156_AddSupportForEnumValueOptions_Test.java
@@ -0,0 +1,60 @@
+/*
+ * 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 com.google.eclipse.protobuf.junit.core.Setups.integrationTestSetup;
+import static com.google.eclipse.protobuf.junit.core.XtextRule.createWith;
+import static com.google.eclipse.protobuf.scoping.ContainAllNames.containAll;
+import static com.google.eclipse.protobuf.scoping.IEObjectDescriptions.descriptionsIn;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.mock;
+
+import org.eclipse.emf.ecore.EReference;
+import org.eclipse.xtext.scoping.IScope;
+import org.junit.*;
+
+import com.google.eclipse.protobuf.junit.core.XtextRule;
+import com.google.eclipse.protobuf.protobuf.CustomFieldOption;
+
+/**
+ * Tests fix for <a href="http://code.google.com/p/protobuf-dt/issues/detail?id=156">Issue 156</a>.
+ *
+ * @author alruiz@google.com (Alex Ruiz)
+ */
+public class Issue156_AddSupportForEnumValueOptions_Test {
+
+ private static EReference reference;
+
+ @BeforeClass public static void setUpOnce() {
+ reference = mock(EReference.class);
+ }
+
+ @Rule public XtextRule xtext = createWith(integrationTestSetup());
+
+ private ProtobufScopeProvider provider;
+
+ @Before public void setUp() {
+ provider = xtext.getInstanceOf(ProtobufScopeProvider.class);
+ }
+
+ // import 'google/protobuf/descriptor.proto';
+ //
+ // extend google.protobuf.EnumValueOptions {
+ // optional bool active = 1000;
+ // }
+ //
+ // enum PhoneType {
+ // HOME = 0 [(active) = true];
+ // }
+ @Test public void should_provide_fields_for_custom_field_option() {
+ CustomFieldOption option = xtext.find("active", ")", CustomFieldOption.class);
+ IScope scope = provider.scope_OptionSource_optionField(option.getSource(), reference);
+ assertThat(descriptionsIn(scope), containAll("active", ".active"));
+ }
+}
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/OptionType.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/OptionType.java
index b4ea6f4..0c5a6cd 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/OptionType.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/OptionType.java
@@ -11,8 +11,6 @@
import java.util.*;
import java.util.Map.Entry;
-import org.eclipse.emf.ecore.EObject;
-
import com.google.eclipse.protobuf.protobuf.*;
import com.google.eclipse.protobuf.protobuf.Enum;
@@ -31,6 +29,7 @@
static {
OPTION_TYPES_BY_CONTAINER.put(Protobuf.class, FILE);
OPTION_TYPES_BY_CONTAINER.put(Enum.class, ENUM);
+ OPTION_TYPES_BY_CONTAINER.put(Literal.class, LITERAL);
OPTION_TYPES_BY_CONTAINER.put(Message.class, MESSAGE);
OPTION_TYPES_BY_CONTAINER.put(Field.class, FIELD);
OPTION_TYPES_BY_CONTAINER.put(Service.class, SERVICE);
@@ -70,7 +69,7 @@
return findOptionTypeForLevelOf(option.eContainer());
}
- static OptionType findOptionTypeForLevelOf(EObject container) {
+ static OptionType findOptionTypeForLevelOf(Object container) {
for (Entry<Class<?>, OptionType> optionTypeByContainer : OPTION_TYPES_BY_CONTAINER.entrySet()) {
if (optionTypeByContainer.getKey().isInstance(container)) {
return optionTypeByContainer.getValue();