Fixed: [Issue 127] Scoping/content-assist cannot not find built-in
service and rpc options.
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/scoping/Descriptor_fileOptions_Test.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/scoping/Descriptor_availableOptionPropertiesFor_Test.java
similarity index 75%
rename from com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/scoping/Descriptor_fileOptions_Test.java
rename to com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/scoping/Descriptor_availableOptionPropertiesFor_Test.java
index 72b65ed..259fff2 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/scoping/Descriptor_fileOptions_Test.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/scoping/Descriptor_availableOptionPropertiesFor_Test.java
@@ -11,32 +11,35 @@
import static com.google.eclipse.protobuf.junit.matchers.PropertyHasType.hasType;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.mock;
import java.util.*;
+import org.eclipse.emf.ecore.EObject;
import org.junit.*;
import com.google.eclipse.protobuf.junit.core.XtextRule;
-import com.google.eclipse.protobuf.protobuf.Property;
+import com.google.eclipse.protobuf.protobuf.*;
/**
- * Tests for <code>{@link ProtoDescriptor#fileOptions()}</code>.
+ * Tests for <code>{@link ProtoDescriptor#availableOptionPropertiesFor(EObject)}</code>.
*
* @author alruiz@google.com (Alex Ruiz)
*/
-@Ignore("This test requires to be executed as a 'JUnit plug-in test'. I haven't found a way to register PlatformURLHandler with the JVM")
-public class Descriptor_fileOptions_Test {
+// @Ignore("This test requires to be executed as a 'JUnit plug-in test'. I haven't found a way to register PlatformURLHandler with the JVM")
+public class Descriptor_availableOptionPropertiesFor_Test {
@Rule public XtextRule xtext = new XtextRule();
private ProtoDescriptor descriptor;
-
+
@Before public void setUp() {
descriptor = xtext.getInstanceOf(ProtoDescriptorProvider.class).get();
}
@Test public void should_return_all_file_options() {
- Map<String, Property> fileOptions = mapByName(descriptor.fileOptions());
+ Protobuf optionContainer = mock(Protobuf.class);
+ Map<String, Property> fileOptions = mapByName(descriptor.availableOptionPropertiesFor(optionContainer));
assertThat(fileOptions.get("java_package"), hasType("string"));
assertThat(fileOptions.get("java_outer_classname"), hasType("string"));
assertThat(fileOptions.get("java_multiple_files"), hasType("bool"));
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 5bfa135..f5893a3 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
@@ -13,7 +13,7 @@
*/
enum OptionType {
FILE("FileOptions"), MESSAGE("MessageOptions"), FIELD("FieldOptions"), ENUM("EnumOptions"),
- ENUM_LITERAL("EnumValueOptions"), SERVICE("ServiceOptions"), RPC("MethodOptions");
+ LITERAL("EnumValueOptions"), SERVICE("ServiceOptions"), RPC("MethodOptions");
final String messageName;
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/ProtoDescriptor.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/ProtoDescriptor.java
index fc0ca3e..70bdd4c 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/ProtoDescriptor.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/ProtoDescriptor.java
@@ -46,11 +46,11 @@
private static final Map<String, OptionType> OPTION_DEFINITION_BY_NAME = new HashMap<String, OptionType>();
static {
- addOptionTypes(FILE, MESSAGE, FIELD, ENUM);
+ addOptionTypeMappings();
}
- private static void addOptionTypes(OptionType...types) {
- for (OptionType type : types) {
+ private static void addOptionTypeMappings() {
+ for (OptionType type : OptionType.values()) {
OPTION_DEFINITION_BY_NAME.put(type.messageName, type);
}
}
@@ -133,30 +133,23 @@
}
/**
- * Returns the options available for the given option container. For example, if the given object is an
- * <code>{@link Enum}</code>, this method will return <code>{@link #enumOptions()}</code>.
+ * Returns the options available for the given option container. The returned options are defined in
+ * {@code google/protobuf/descriptor.proto} (more details can be found
+ * <a href=http://code.google.com/apis/protocolbuffers/docs/proto.html#options" target="_blank">here</a>.)
* @param optionContainer the given container of an option.
* @return the options available for the given option container, or an empty collection if the are not any
* options available for the given option container.
*/
public Collection<Property> availableOptionPropertiesFor(EObject optionContainer) {
- if (optionContainer instanceof Protobuf) return fileOptions();
- if (optionContainer instanceof Enum) return enumOptions();
- if (optionContainer instanceof Message) return messageOptions();
+ if (optionContainer instanceof Protobuf) return optionsOfType(FILE);
+ if (optionContainer instanceof Enum) return optionsOfType(ENUM);
+ if (optionContainer instanceof Message) return optionsOfType(MESSAGE);
+ if (optionContainer instanceof Service) return optionsOfType(SERVICE);
+ if (optionContainer instanceof Rpc) return optionsOfType(RPC);
return emptyList();
}
/**
- * Returns all the file-level options available. These are the options defined in
- * {@code google/protobuf/descriptor.proto} (more details can be found
- * <a href=http://code.google.com/apis/protocolbuffers/docs/proto.html#options" target="_blank">here</a>.)
- * @return all the file-level options available.
- */
- public Collection<Property> fileOptions() {
- return optionsOfType(FILE);
- }
-
- /**
* Looks up an option per name, as defined in {@code google/protobuf/descriptor.proto}
* (more details can be found <a
* href=http://code.google.com/apis/protocolbuffers/docs/proto.html#options" target="_blank">here</a>.)
@@ -191,16 +184,6 @@
}
/**
- * Returns all the message-level options available. These are the options defined in
- * {@code google/protobuf/descriptor.proto} (more details can be found
- * <a href=http://code.google.com/apis/protocolbuffers/docs/proto.html#options" target="_blank">here</a>.)
- * @return all the message-level options available.
- */
- public Collection<Property> messageOptions() {
- return optionsOfType(MESSAGE);
- }
-
- /**
* Returns all the field-level options available. These are the options defined in
* {@code google/protobuf/descriptor.proto} (more details can be found
* <a href=http://code.google.com/apis/protocolbuffers/docs/proto.html#options" target="_blank">here</a>.)
@@ -209,17 +192,7 @@
public Collection<Property> fieldOptions() {
return optionsOfType(FIELD);
}
-
- /**
- * Returns all the enum-level options available. These are the options defined in
- * {@code google/protobuf/descriptor.proto} (more details can be found
- * <a href=http://code.google.com/apis/protocolbuffers/docs/proto.html#options" target="_blank">here</a>.)
- * @return all the enum-level options available.
- */
- public Collection<Property> enumOptions() {
- return optionsOfType(ENUM);
- }
-
+
private Collection<Property> optionsOfType(OptionType type) {
return unmodifiableCollection(optionsByType.get(type).values());
}