Fixed: [Issue 131] option for service is broken.
diff --git a/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/bugs/Issue131AddOptionsForService.java b/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/bugs/Issue131AddOptionsForService.java
new file mode 100644
index 0000000..2ea0af1
--- /dev/null
+++ b/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/bugs/Issue131AddOptionsForService.java
@@ -0,0 +1,67 @@
+/*
+ * 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.bugs;
+
+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 com.google.eclipse.protobuf.junit.core.XtextRule;
+import com.google.eclipse.protobuf.protobuf.Option;
+import com.google.eclipse.protobuf.scoping.ProtobufScopeProvider;
+
+import org.eclipse.emf.ecore.EReference;
+import org.eclipse.xtext.scoping.IScope;
+import org.junit.*;
+
+/**
+ * Tests fix for <a href="http://code.google.com/p/protobuf-dt/issues/detail?id=131">Issue 131</a>.
+ *
+ * @author alruiz@google.com (Alex Ruiz)
+ */
+public class Issue131AddOptionsForService {
+
+ 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);
+ }
+
+ // package com.google.proto;
+ //
+ // import 'google/protobuf/descriptor.proto';
+ //
+ // extend google.protobuf.ServiceOptions {
+ // optional int32 code = 1000;
+ // optional int32 info = 1002;
+ // }
+ //
+ // service ABC {
+ // option (code) = 68;
+ // }
+ @Test public void should_support_Service_options() {
+ Option option = xtext.find("code", ")", Option.class);
+ IScope scope = provider.scope_PropertyRef_property(option.getProperty(), 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",
+ ".com.google.proto.info"));
+ }
+}
diff --git a/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/scoping/ContainAllNames.java b/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/scoping/ContainAllNames.java
index 00fabfb..18eb315 100644
--- a/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/scoping/ContainAllNames.java
+++ b/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/scoping/ContainAllNames.java
@@ -15,11 +15,11 @@
/**
* @author alruiz@google.com (Alex Ruiz)
*/
-class ContainAllNames extends BaseMatcher<IEObjectDescriptions> {
+public class ContainAllNames extends BaseMatcher<IEObjectDescriptions> {
private final String[] expectedNames;
- static ContainAllNames containAll(String... names) {
+ public static ContainAllNames containAll(String... names) {
return new ContainAllNames(names);
}
diff --git a/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/scoping/IEObjectDescriptions.java b/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/scoping/IEObjectDescriptions.java
index 6dab125..0b0df69 100644
--- a/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/scoping/IEObjectDescriptions.java
+++ b/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/scoping/IEObjectDescriptions.java
@@ -20,13 +20,13 @@
/**
* @author alruiz@google.com (Alex Ruiz)
*/
-class IEObjectDescriptions {
+public class IEObjectDescriptions {
- static IEObjectDescriptions descriptionsIn(IScope scope) {
+ public static IEObjectDescriptions descriptionsIn(IScope scope) {
return descriptions(scope.getAllElements());
}
- static IEObjectDescriptions descriptions(Iterable<IEObjectDescription> elements) {
+ public static IEObjectDescriptions descriptions(Iterable<IEObjectDescription> elements) {
return new IEObjectDescriptions(elements);
}
@@ -39,16 +39,16 @@
}
}
- EObject objectDescribedAs(String name) {
+ public EObject objectDescribedAs(String name) {
IEObjectDescription d = descriptions.get(name);
return d.getEObjectOrProxy();
}
- int size() {
+ public int size() {
return descriptions.size();
}
- Collection<String> names() {
+ public Collection<String> names() {
return unmodifiableSet(descriptions.keySet());
}
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 df82389..386fb4a 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
@@ -182,8 +182,14 @@
private void highlight(Service service, IHighlightedPositionAcceptor acceptor) {
highlightName(service, acceptor, SERVICE_DEFINITION_ID);
- for (Rpc rpc : service.getRpcs()) {
- highlight(rpc, acceptor);
+ for (ServiceElement e : service.getElements()) {
+ if (e instanceof Rpc) {
+ highlight((Rpc) e, acceptor);
+ continue;
+ }
+ if (e instanceof Option) {
+ highlight((Option) e, 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 7b9a5fe..f642363 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
@@ -174,9 +174,12 @@
Service:
'service' name=Name '{'
- rpcs+=Rpc*
+ (elements+=ServiceElement)*
'}' (';')?;
+ServiceElement:
+ Option | Rpc;
+
Rpc:
'rpc' name=Name '(' argType=MessageRef ')' 'returns' '(' returnType=MessageRef ')'
(('{' options+=Option* '}') (';')? | ';');