In progress [Issue 125] Support for custom options.
Adding more tests. Code cleanup.
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
new file mode 100644
index 0000000..db908a5
--- /dev/null
+++ b/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/scoping/IEObjectDescriptions.java
@@ -0,0 +1,40 @@
+/*
+ * 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 org.eclipse.emf.ecore.EObject;
+import org.eclipse.xtext.naming.QualifiedName;
+import org.eclipse.xtext.resource.IEObjectDescription;
+import org.eclipse.xtext.scoping.IScope;
+
+import java.util.*;
+
+/**
+ * @author alruiz@google.com (Alex Ruiz)
+ */
+class IEObjectDescriptions {
+
+ static IEObjectDescriptions descriptionsIn(IScope scope) {
+ return new IEObjectDescriptions(scope);
+ }
+
+ private final Map<String, IEObjectDescription> descriptions = new HashMap<String, IEObjectDescription>();
+
+ private IEObjectDescriptions(IScope scope) {
+ for (IEObjectDescription d : scope.getAllElements()) {
+ QualifiedName name = d.getName();
+ descriptions.put(name.toString(), d);
+ }
+ }
+
+ EObject objectDescribedAs(String name) {
+ IEObjectDescription d = descriptions.get(name);
+ return d.getEObjectOrProxy();
+ }
+}
diff --git a/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/scoping/ProtobufScopeProvider_scope_LiteralRef_literal_Test.java b/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/scoping/ProtobufScopeProvider_scope_LiteralRef_literal_Test.java
new file mode 100644
index 0000000..8017323
--- /dev/null
+++ b/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/scoping/ProtobufScopeProvider_scope_LiteralRef_literal_Test.java
@@ -0,0 +1,68 @@
+/*
+ * 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.model.find.FieldOptionFinder.findFieldOption;
+import static com.google.eclipse.protobuf.junit.model.find.Name.name;
+import static com.google.eclipse.protobuf.junit.model.find.Root.in;
+import static com.google.eclipse.protobuf.scoping.IEObjectDescriptions.descriptionsIn;
+import static org.hamcrest.core.IsEqual.equalTo;
+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.junit.util.MultiLineTextBuilder;
+import com.google.eclipse.protobuf.protobuf.*;
+
+import org.eclipse.emf.ecore.EReference;
+import org.eclipse.xtext.scoping.IScope;
+import org.junit.*;
+
+/**
+ * Tests for <code>{@link ProtobufScopeProvider#scope_LiteralRef_literal(LiteralRef, EReference)}</code>
+ *
+ * @author alruiz@google.com (Alex Ruiz)
+ */
+public class ProtobufScopeProvider_scope_LiteralRef_literal_Test {
+
+ private static EReference reference;
+
+ @BeforeClass public static void setUpOnce() {
+ reference = mock(EReference.class);
+ }
+
+ @Rule public XtextRule xtext = XtextRule.integrationTestSetup();
+
+ private ProtobufScopeProvider provider;
+
+ @Before public void setUp() {
+ provider = xtext.getInstanceOf(ProtobufScopeProvider.class);
+ }
+
+ @Test public void should_provide_Literals_for_default_value() {
+ MultiLineTextBuilder proto = new MultiLineTextBuilder();
+ proto.append("enum Type { ")
+ .append(" ONE = 0; ")
+ .append(" TWO = 1; ")
+ .append("} ")
+ .append(" ")
+ .append("message Person { ")
+ .append(" optional Type type = 1 [default = ONE];")
+ .append("} ");
+ Protobuf root = xtext.parseText(proto);
+ FieldOption option = findFieldOption(name("default"), in(root));
+ LiteralRef ref = (LiteralRef) option.getValue();
+ IScope scope = provider.scope_LiteralRef_literal(ref, reference);
+ IEObjectDescriptions descriptions = descriptionsIn(scope);
+ Literal one = (Literal) descriptions.objectDescribedAs("ONE");
+ assertThat(one.getName(), equalTo("ONE"));
+ Literal two = (Literal) descriptions.objectDescribedAs("TWO");
+ assertThat(two.getName(), equalTo("TWO"));
+ }
+}
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/model/find/FieldOptionFinder.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/model/find/FieldOptionFinder.java
index eab7d84..252de82 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/model/find/FieldOptionFinder.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/model/find/FieldOptionFinder.java
@@ -22,7 +22,7 @@
if (name.value.equals(nameOf(option))) return option;
return null;
}
-
+
private static String nameOf(FieldOption option) {
if (option instanceof DefaultValueFieldOption) return "default";
PropertyRef ref = null;