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/model/util/FieldOptions_fieldFrom_Test.java b/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/model/util/FieldOptions_fieldFrom_Test.java
index 18a79eb..8f2037d 100644
--- a/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/model/util/FieldOptions_fieldFrom_Test.java
+++ b/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/model/util/FieldOptions_fieldFrom_Test.java
@@ -8,9 +8,9 @@
*/
package com.google.eclipse.protobuf.model.util;
-import static com.google.eclipse.protobuf.junit.find.FieldOptionFinder.findFieldOption;
-import static com.google.eclipse.protobuf.junit.find.Name.name;
-import static com.google.eclipse.protobuf.junit.find.Root.in;
+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 org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertThat;
diff --git a/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/model/util/FieldOptions_isDefaultValueOption_Test.java b/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/model/util/FieldOptions_isDefaultValueOption_Test.java
index ea04c89..fab1af1 100644
--- a/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/model/util/FieldOptions_isDefaultValueOption_Test.java
+++ b/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/model/util/FieldOptions_isDefaultValueOption_Test.java
@@ -8,9 +8,9 @@
*/
package com.google.eclipse.protobuf.model.util;
-import static com.google.eclipse.protobuf.junit.find.FieldOptionFinder.findFieldOption;
-import static com.google.eclipse.protobuf.junit.find.Name.name;
-import static com.google.eclipse.protobuf.junit.find.Root.in;
+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 org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertThat;
diff --git a/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/model/util/FieldOptions_nameOf_Test.java b/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/model/util/FieldOptions_nameOf_Test.java
index 0c0ef93..1fe2a3c 100644
--- a/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/model/util/FieldOptions_nameOf_Test.java
+++ b/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/model/util/FieldOptions_nameOf_Test.java
@@ -8,9 +8,9 @@
*/
package com.google.eclipse.protobuf.model.util;
-import static com.google.eclipse.protobuf.junit.find.FieldOptionFinder.findFieldOption;
-import static com.google.eclipse.protobuf.junit.find.Name.name;
-import static com.google.eclipse.protobuf.junit.find.Root.in;
+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 org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertThat;
diff --git a/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/model/util/FieldOptions_propertyFrom_Test.java b/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/model/util/FieldOptions_propertyFrom_Test.java
index 1f2b873..0fb94b3 100644
--- a/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/model/util/FieldOptions_propertyFrom_Test.java
+++ b/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/model/util/FieldOptions_propertyFrom_Test.java
@@ -8,9 +8,9 @@
*/
package com.google.eclipse.protobuf.model.util;
-import static com.google.eclipse.protobuf.junit.find.FieldOptionFinder.findFieldOption;
-import static com.google.eclipse.protobuf.junit.find.Name.name;
-import static com.google.eclipse.protobuf.junit.find.Root.in;
+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 org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertThat;
diff --git a/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/model/util/Options_fieldFrom_Test.java b/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/model/util/Options_fieldFrom_Test.java
index cca1738..3ba629d 100644
--- a/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/model/util/Options_fieldFrom_Test.java
+++ b/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/model/util/Options_fieldFrom_Test.java
@@ -8,9 +8,9 @@
*/
package com.google.eclipse.protobuf.model.util;
-import static com.google.eclipse.protobuf.junit.find.Name.name;
-import static com.google.eclipse.protobuf.junit.find.OptionFinder.findOption;
-import static com.google.eclipse.protobuf.junit.find.Root.in;
+import static com.google.eclipse.protobuf.junit.model.find.Name.name;
+import static com.google.eclipse.protobuf.junit.model.find.OptionFinder.findOption;
+import static com.google.eclipse.protobuf.junit.model.find.Root.in;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertThat;
diff --git a/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/model/util/Options_isExtendingOptionMessage_Test.java b/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/model/util/Options_isExtendingOptionMessage_Test.java
new file mode 100644
index 0000000..17804d4
--- /dev/null
+++ b/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/model/util/Options_isExtendingOptionMessage_Test.java
@@ -0,0 +1,73 @@
+/*
+ * 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.model.util;
+
+import static com.google.eclipse.protobuf.junit.model.find.ExtendMessageFinder.findExtendMessage;
+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.model.OptionType.FILE;
+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.model.OptionType;
+import com.google.eclipse.protobuf.protobuf.*;
+
+import org.eclipse.emf.ecore.EObject;
+import org.junit.*;
+
+/**
+ * Tests for <code>{@link Options#isExtendingOptionMessage(EObject, OptionType)}</code>
+ *
+ * @author alruiz@google.com (Alex Ruiz)
+ */
+public class Options_isExtendingOptionMessage_Test {
+
+ @Rule public XtextRule xtext = XtextRule.integrationTestSetup();
+
+ private Options options;
+
+ @Before public void setUp() {
+ options = xtext.getInstanceOf(Options.class);
+ }
+
+ @Test public void should_return_true_if_name_of_extended_message_is_equal_to_message_name_in_OptionType() {
+ MultiLineTextBuilder proto = new MultiLineTextBuilder();
+ proto.append("import 'google/protobuf/descriptor.proto';")
+ .append(" ")
+ .append("extend google.protobuf.FileOptions { ")
+ .append(" optional string encoding = 1000; ")
+ .append("} ");
+ Protobuf root = xtext.parseText(proto);
+ ExtendMessage extend = findExtendMessage(name("FileOptions"), in(root));
+ boolean result = options.isExtendingOptionMessage(extend, FILE);
+ assertThat(result, equalTo(true));
+ }
+
+ @Test public void should_return_false_if_given_EObject_is_not_ExtendMessage() {
+ Import anImport = mock(Import.class);
+ boolean result = options.isExtendingOptionMessage(anImport, FILE);
+ assertThat(result, equalTo(false));
+ }
+
+ @Test public void should_return_false_if_name_of_extended_message_is_not_equal_to_message_name_in_OptionType() {
+ MultiLineTextBuilder proto = new MultiLineTextBuilder();
+ proto.append("import 'google/protobuf/descriptor.proto';")
+ .append(" ")
+ .append("extend google.protobuf.FieldOptions { ")
+ .append(" optional string encoding = 1000; ")
+ .append("} ");
+ Protobuf root = xtext.parseText(proto);
+ ExtendMessage extend = findExtendMessage(name("FieldOptions"), in(root));
+ boolean result = options.isExtendingOptionMessage(extend, FILE);
+ assertThat(result, equalTo(false));
+ }
+}
diff --git a/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/model/util/Options_propertyFrom_Test.java b/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/model/util/Options_propertyFrom_Test.java
index 888b8ca..a4342ac 100644
--- a/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/model/util/Options_propertyFrom_Test.java
+++ b/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/model/util/Options_propertyFrom_Test.java
@@ -8,9 +8,9 @@
*/
package com.google.eclipse.protobuf.model.util;
-import static com.google.eclipse.protobuf.junit.find.Name.name;
-import static com.google.eclipse.protobuf.junit.find.OptionFinder.findOption;
-import static com.google.eclipse.protobuf.junit.find.Root.in;
+import static com.google.eclipse.protobuf.junit.model.find.Name.name;
+import static com.google.eclipse.protobuf.junit.model.find.OptionFinder.findOption;
+import static com.google.eclipse.protobuf.junit.model.find.Root.in;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertThat;
diff --git a/com.google.eclipse.protobuf.test/META-INF/MANIFEST.MF b/com.google.eclipse.protobuf.test/META-INF/MANIFEST.MF
index 5e729b6..768f41a 100644
--- a/com.google.eclipse.protobuf.test/META-INF/MANIFEST.MF
+++ b/com.google.eclipse.protobuf.test/META-INF/MANIFEST.MF
@@ -12,7 +12,7 @@
org.eclipse.core.resources;bundle-version="3.7.100"
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Export-Package: com.google.eclipse.protobuf.junit.core,
- com.google.eclipse.protobuf.junit.find,
com.google.eclipse.protobuf.junit.matchers,
+ com.google.eclipse.protobuf.junit.model.find,
com.google.eclipse.protobuf.junit.stubs.resources,
com.google.eclipse.protobuf.junit.util
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/find/EnumFinder.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/model/find/EnumFinder.java
similarity index 92%
rename from com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/find/EnumFinder.java
rename to com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/model/find/EnumFinder.java
index dee676a..c0bd4e8 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/find/EnumFinder.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/model/find/EnumFinder.java
@@ -6,7 +6,7 @@
*
* http://www.eclipse.org/legal/epl-v10.html
*/
-package com.google.eclipse.protobuf.junit.find;
+package com.google.eclipse.protobuf.junit.model.find;
import static org.eclipse.xtext.EcoreUtil2.getAllContentsOfType;
@@ -17,11 +17,11 @@
*/
public final class EnumFinder {
- private EnumFinder() {}
-
public static Enum findEnum(Name name, Root root) {
for (Enum anEnum : getAllContentsOfType(root.value, Enum.class))
if (name.value.equals(anEnum.getName())) return anEnum;
return null;
}
+
+ private EnumFinder() {}
}
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/model/find/ExtendMessageFinder.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/model/find/ExtendMessageFinder.java
new file mode 100644
index 0000000..a0051d4
--- /dev/null
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/model/find/ExtendMessageFinder.java
@@ -0,0 +1,34 @@
+/*
+ * 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.junit.model.find;
+
+import static org.eclipse.xtext.EcoreUtil2.getAllContentsOfType;
+
+import com.google.eclipse.protobuf.protobuf.*;
+
+/**
+ * @author alruiz@google.com (Alex Ruiz)
+ */
+public final class ExtendMessageFinder {
+
+ public static ExtendMessage findExtendMessage(Name name, Root root) {
+ for (ExtendMessage extend : getAllContentsOfType(root.value, ExtendMessage.class))
+ if (name.value.equals(nameOf(extend))) return extend;
+ return null;
+ }
+
+ private static String nameOf(ExtendMessage extend) {
+ MessageRef ref = extend.getMessage();
+ if (ref == null) return null;
+ Message message = ref.getType();
+ return (message != null) ? message.getName() : null;
+ }
+
+ private ExtendMessageFinder() {}
+}
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/find/FieldOptionFinder.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/model/find/FieldOptionFinder.java
similarity index 95%
rename from com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/find/FieldOptionFinder.java
rename to com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/model/find/FieldOptionFinder.java
index 17df758..eab7d84 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/find/FieldOptionFinder.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/model/find/FieldOptionFinder.java
@@ -6,7 +6,7 @@
*
* http://www.eclipse.org/legal/epl-v10.html
*/
-package com.google.eclipse.protobuf.junit.find;
+package com.google.eclipse.protobuf.junit.model.find;
import static org.eclipse.xtext.EcoreUtil2.getAllContentsOfType;
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/find/LiteralFinder.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/model/find/LiteralFinder.java
similarity index 93%
rename from com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/find/LiteralFinder.java
rename to com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/model/find/LiteralFinder.java
index 26858fb..e2e9dff 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/find/LiteralFinder.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/model/find/LiteralFinder.java
@@ -6,7 +6,7 @@
*
* http://www.eclipse.org/legal/epl-v10.html
*/
-package com.google.eclipse.protobuf.junit.find;
+package com.google.eclipse.protobuf.junit.model.find;
import static org.eclipse.xtext.EcoreUtil2.getAllContentsOfType;
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/find/MessageFinder.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/model/find/MessageFinder.java
similarity index 93%
rename from com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/find/MessageFinder.java
rename to com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/model/find/MessageFinder.java
index 8f33100..11abc7e 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/find/MessageFinder.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/model/find/MessageFinder.java
@@ -6,7 +6,7 @@
*
* http://www.eclipse.org/legal/epl-v10.html
*/
-package com.google.eclipse.protobuf.junit.find;
+package com.google.eclipse.protobuf.junit.model.find;
import static org.eclipse.xtext.EcoreUtil2.getAllContentsOfType;
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/find/Name.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/model/find/Name.java
similarity index 90%
rename from com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/find/Name.java
rename to com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/model/find/Name.java
index eaa101c..7e55319 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/find/Name.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/model/find/Name.java
@@ -6,7 +6,7 @@
*
* http://www.eclipse.org/legal/epl-v10.html
*/
-package com.google.eclipse.protobuf.junit.find;
+package com.google.eclipse.protobuf.junit.model.find;
/**
* @author alruiz@google.com (Alex Ruiz)
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/find/OptionFinder.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/model/find/OptionFinder.java
similarity index 94%
rename from com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/find/OptionFinder.java
rename to com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/model/find/OptionFinder.java
index 81a84f4..3cbe6f1 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/find/OptionFinder.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/model/find/OptionFinder.java
@@ -6,7 +6,7 @@
*
* http://www.eclipse.org/legal/epl-v10.html
*/
-package com.google.eclipse.protobuf.junit.find;
+package com.google.eclipse.protobuf.junit.model.find;
import static org.eclipse.xtext.EcoreUtil2.getAllContentsOfType;
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/find/PropertyFinder.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/model/find/PropertyFinder.java
similarity index 94%
rename from com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/find/PropertyFinder.java
rename to com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/model/find/PropertyFinder.java
index 9457b0a..0bff62b 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/find/PropertyFinder.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/model/find/PropertyFinder.java
@@ -6,7 +6,7 @@
*
* http://www.eclipse.org/legal/epl-v10.html
*/
-package com.google.eclipse.protobuf.junit.find;
+package com.google.eclipse.protobuf.junit.model.find;
import static org.eclipse.xtext.EcoreUtil2.getAllContentsOfType;
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/find/Root.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/model/find/Root.java
similarity index 90%
rename from com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/find/Root.java
rename to com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/model/find/Root.java
index 6749f3d..f36626b 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/find/Root.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/model/find/Root.java
@@ -6,7 +6,7 @@
*
* http://www.eclipse.org/legal/epl-v10.html
*/
-package com.google.eclipse.protobuf.junit.find;
+package com.google.eclipse.protobuf.junit.model.find;
import org.eclipse.emf.ecore.EObject;
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/ModelFinder_enumTypeOf_Test.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/ModelFinder_enumTypeOf_Test.java
index afc810f..bc413a6 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/ModelFinder_enumTypeOf_Test.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/ModelFinder_enumTypeOf_Test.java
@@ -8,9 +8,9 @@
*/
package com.google.eclipse.protobuf.model.util;
-import static com.google.eclipse.protobuf.junit.find.Name.name;
-import static com.google.eclipse.protobuf.junit.find.PropertyFinder.findProperty;
-import static com.google.eclipse.protobuf.junit.find.Root.in;
+import static com.google.eclipse.protobuf.junit.model.find.Name.name;
+import static com.google.eclipse.protobuf.junit.model.find.PropertyFinder.findProperty;
+import static com.google.eclipse.protobuf.junit.model.find.Root.in;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.hamcrest.core.IsNull.nullValue;
import static org.junit.Assert.assertThat;
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/ModelFinder_packageOf_Test.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/ModelFinder_packageOf_Test.java
index 09f32c8..5c7f711 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/ModelFinder_packageOf_Test.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/ModelFinder_packageOf_Test.java
@@ -8,9 +8,9 @@
*/
package com.google.eclipse.protobuf.model.util;
-import static com.google.eclipse.protobuf.junit.find.Name.name;
-import static com.google.eclipse.protobuf.junit.find.PropertyFinder.findProperty;
-import static com.google.eclipse.protobuf.junit.find.Root.in;
+import static com.google.eclipse.protobuf.junit.model.find.Name.name;
+import static com.google.eclipse.protobuf.junit.model.find.PropertyFinder.findProperty;
+import static com.google.eclipse.protobuf.junit.model.find.Root.in;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.hamcrest.core.IsNull.nullValue;
import static org.junit.Assert.assertThat;
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/ModelFinder_rootOf_Test.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/ModelFinder_rootOf_Test.java
index ce5baca..e27164a 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/ModelFinder_rootOf_Test.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/ModelFinder_rootOf_Test.java
@@ -8,9 +8,9 @@
*/
package com.google.eclipse.protobuf.model.util;
-import static com.google.eclipse.protobuf.junit.find.Name.name;
-import static com.google.eclipse.protobuf.junit.find.PropertyFinder.findProperty;
-import static com.google.eclipse.protobuf.junit.find.Root.in;
+import static com.google.eclipse.protobuf.junit.model.find.Name.name;
+import static com.google.eclipse.protobuf.junit.model.find.PropertyFinder.findProperty;
+import static com.google.eclipse.protobuf.junit.model.find.Root.in;
import static org.hamcrest.core.IsSame.sameInstance;
import static org.junit.Assert.assertThat;
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/ModelFinder_scalarTypeOf_Test.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/ModelFinder_scalarTypeOf_Test.java
index c217d1b..b579ef8 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/ModelFinder_scalarTypeOf_Test.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/ModelFinder_scalarTypeOf_Test.java
@@ -8,9 +8,9 @@
*/
package com.google.eclipse.protobuf.model.util;
-import static com.google.eclipse.protobuf.junit.find.Name.name;
-import static com.google.eclipse.protobuf.junit.find.PropertyFinder.findProperty;
-import static com.google.eclipse.protobuf.junit.find.Root.in;
+import static com.google.eclipse.protobuf.junit.model.find.Name.name;
+import static com.google.eclipse.protobuf.junit.model.find.PropertyFinder.findProperty;
+import static com.google.eclipse.protobuf.junit.model.find.Root.in;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.hamcrest.core.IsNull.nullValue;
import static org.junit.Assert.assertThat;
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/ModelNodes_firstNodeForFeature_Test.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/ModelNodes_firstNodeForFeature_Test.java
index abcb15c..271a8b8 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/ModelNodes_firstNodeForFeature_Test.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/ModelNodes_firstNodeForFeature_Test.java
@@ -8,9 +8,9 @@
*/
package com.google.eclipse.protobuf.model.util;
-import static com.google.eclipse.protobuf.junit.find.Name.name;
-import static com.google.eclipse.protobuf.junit.find.PropertyFinder.findProperty;
-import static com.google.eclipse.protobuf.junit.find.Root.in;
+import static com.google.eclipse.protobuf.junit.model.find.Name.name;
+import static com.google.eclipse.protobuf.junit.model.find.PropertyFinder.findProperty;
+import static com.google.eclipse.protobuf.junit.model.find.Root.in;
import static com.google.eclipse.protobuf.protobuf.ProtobufPackage.Literals.FIELD__NAME;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertThat;
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/Properties_isBool_Test.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/Properties_isBool_Test.java
index bf88542..d281e4b 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/Properties_isBool_Test.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/Properties_isBool_Test.java
@@ -8,9 +8,9 @@
*/
package com.google.eclipse.protobuf.model.util;
-import static com.google.eclipse.protobuf.junit.find.Name.name;
-import static com.google.eclipse.protobuf.junit.find.PropertyFinder.findProperty;
-import static com.google.eclipse.protobuf.junit.find.Root.in;
+import static com.google.eclipse.protobuf.junit.model.find.Name.name;
+import static com.google.eclipse.protobuf.junit.model.find.PropertyFinder.findProperty;
+import static com.google.eclipse.protobuf.junit.model.find.Root.in;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertThat;
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/Properties_isPrimitive_Test.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/Properties_isPrimitive_Test.java
index f35eaec..37f4243 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/Properties_isPrimitive_Test.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/Properties_isPrimitive_Test.java
@@ -8,7 +8,7 @@
*/
package com.google.eclipse.protobuf.model.util;
-import static com.google.eclipse.protobuf.junit.find.PropertyFinder.allPropertiesIn;
+import static com.google.eclipse.protobuf.junit.model.find.PropertyFinder.allPropertiesIn;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertThat;
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/Properties_isString_Test.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/Properties_isString_Test.java
index 5777f7a..80829d6 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/Properties_isString_Test.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/Properties_isString_Test.java
@@ -8,9 +8,9 @@
*/
package com.google.eclipse.protobuf.model.util;
-import static com.google.eclipse.protobuf.junit.find.Name.name;
-import static com.google.eclipse.protobuf.junit.find.PropertyFinder.findProperty;
-import static com.google.eclipse.protobuf.junit.find.Root.in;
+import static com.google.eclipse.protobuf.junit.model.find.Name.name;
+import static com.google.eclipse.protobuf.junit.model.find.PropertyFinder.findProperty;
+import static com.google.eclipse.protobuf.junit.model.find.Root.in;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertThat;
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/Properties_typeNameOf_Test.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/Properties_typeNameOf_Test.java
index dcfb8cf..39e781f 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/Properties_typeNameOf_Test.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/Properties_typeNameOf_Test.java
@@ -8,9 +8,9 @@
*/
package com.google.eclipse.protobuf.model.util;
-import static com.google.eclipse.protobuf.junit.find.Name.name;
-import static com.google.eclipse.protobuf.junit.find.PropertyFinder.findProperty;
-import static com.google.eclipse.protobuf.junit.find.Root.in;
+import static com.google.eclipse.protobuf.junit.model.find.Name.name;
+import static com.google.eclipse.protobuf.junit.model.find.PropertyFinder.findProperty;
+import static com.google.eclipse.protobuf.junit.model.find.Root.in;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertThat;
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/naming/ProtobufQualifiedNameProvider_getFullyQualifiedName_Test.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/naming/ProtobufQualifiedNameProvider_getFullyQualifiedName_Test.java
index 6ece585..03b96c6 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/naming/ProtobufQualifiedNameProvider_getFullyQualifiedName_Test.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/naming/ProtobufQualifiedNameProvider_getFullyQualifiedName_Test.java
@@ -8,10 +8,10 @@
*/
package com.google.eclipse.protobuf.naming;
-import static com.google.eclipse.protobuf.junit.find.MessageFinder.findMessage;
-import static com.google.eclipse.protobuf.junit.find.Name.name;
-import static com.google.eclipse.protobuf.junit.find.PropertyFinder.findProperty;
-import static com.google.eclipse.protobuf.junit.find.Root.in;
+import static com.google.eclipse.protobuf.junit.model.find.MessageFinder.findMessage;
+import static com.google.eclipse.protobuf.junit.model.find.Name.name;
+import static com.google.eclipse.protobuf.junit.model.find.PropertyFinder.findProperty;
+import static com.google.eclipse.protobuf.junit.model.find.Root.in;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertThat;
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/scoping/LocalNamesProvider_namesOf_Test.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/scoping/LocalNamesProvider_namesOf_Test.java
index 3eab87e..d1636ba 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/scoping/LocalNamesProvider_namesOf_Test.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/scoping/LocalNamesProvider_namesOf_Test.java
@@ -8,9 +8,9 @@
*/
package com.google.eclipse.protobuf.scoping;
-import static com.google.eclipse.protobuf.junit.find.EnumFinder.findEnum;
-import static com.google.eclipse.protobuf.junit.find.Name.name;
-import static com.google.eclipse.protobuf.junit.find.Root.in;
+import static com.google.eclipse.protobuf.junit.model.find.EnumFinder.findEnum;
+import static com.google.eclipse.protobuf.junit.model.find.Name.name;
+import static com.google.eclipse.protobuf.junit.model.find.Root.in;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertThat;
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/validation/ProtobufJavaValidator_checkSyntaxIsProto2_Test.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/validation/ProtobufJavaValidator_checkSyntaxIsProto2_Test.java
new file mode 100644
index 0000000..a3b10fa
--- /dev/null
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/validation/ProtobufJavaValidator_checkSyntaxIsProto2_Test.java
@@ -0,0 +1,51 @@
+/*
+ * 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.validation;
+
+import static com.google.eclipse.protobuf.protobuf.ProtobufPackage.Literals.SYNTAX__NAME;
+import static com.google.eclipse.protobuf.validation.ProtobufJavaValidator.SYNTAX_IS_NOT_PROTO2_ERROR;
+import static org.eclipse.xtext.validation.ValidationMessageAcceptor.INSIGNIFICANT_INDEX;
+import static org.mockito.Mockito.*;
+
+import com.google.eclipse.protobuf.protobuf.Syntax;
+
+import org.eclipse.xtext.validation.ValidationMessageAcceptor;
+import org.junit.*;
+
+/**
+ * Tests for <code>{@link ProtobufJavaValidator#checkSyntaxIsProto2(Syntax)}</code>
+ *
+ * @author alruiz@google.com (Alex Ruiz)
+ */
+public class ProtobufJavaValidator_checkSyntaxIsProto2_Test {
+
+ private Syntax syntax;
+ private ValidationMessageAcceptor messageAcceptor;
+ private ProtobufJavaValidator validator;
+
+ @Before public void setUp() {
+ syntax = mock(Syntax.class);
+ messageAcceptor = mock(ValidationMessageAcceptor.class);
+ validator = new ProtobufJavaValidator();
+ validator.setMessageAcceptor(messageAcceptor);
+ }
+
+ @Test public void should_create_error_if_syntax_is_not_proto2() {
+ when(syntax.getName()).thenReturn("proto1");
+ validator.checkSyntaxIsProto2(syntax);
+ String message = "Unrecognized syntax identifier \"proto1\". This parser only recognizes \"proto2\".";
+ verify(messageAcceptor).acceptError(message, syntax, SYNTAX__NAME, INSIGNIFICANT_INDEX, SYNTAX_IS_NOT_PROTO2_ERROR);
+ }
+
+ @Test public void should_not_create_error_if_syntax_is_proto2() {
+ when(syntax.getName()).thenReturn("proto2");
+ validator.checkSyntaxIsProto2(syntax);
+ verifyZeroInteractions(messageAcceptor);
+ }
+}
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/validation/ProtobufJavaValidator_checkTagNumberIsGreaterThanZero_Test.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/validation/ProtobufJavaValidator_checkTagNumberIsGreaterThanZero_Test.java
new file mode 100644
index 0000000..7a01230
--- /dev/null
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/validation/ProtobufJavaValidator_checkTagNumberIsGreaterThanZero_Test.java
@@ -0,0 +1,78 @@
+/*
+ * 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.validation;
+
+import static com.google.eclipse.protobuf.junit.model.find.Name.name;
+import static com.google.eclipse.protobuf.junit.model.find.PropertyFinder.findProperty;
+import static com.google.eclipse.protobuf.junit.model.find.Root.in;
+import static com.google.eclipse.protobuf.protobuf.ProtobufPackage.Literals.FIELD__INDEX;
+import static com.google.eclipse.protobuf.validation.ProtobufJavaValidator.INVALID_FIELD_TAG_NUMBER_ERROR;
+import static org.eclipse.xtext.validation.ValidationMessageAcceptor.INSIGNIFICANT_INDEX;
+import static org.mockito.Mockito.*;
+
+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.xtext.validation.ValidationMessageAcceptor;
+import org.junit.*;
+
+/**
+ * Tests for <code>{@link ProtobufJavaValidator#checkTagNumberIsGreaterThanZero(Field)}</code>
+ *
+ * @author alruiz@google.com (Alex Ruiz)
+ */
+public class ProtobufJavaValidator_checkTagNumberIsGreaterThanZero_Test {
+
+ @Rule public XtextRule xtext = XtextRule.unitTestSetup();
+
+ private ValidationMessageAcceptor messageAcceptor;
+ private ProtobufJavaValidator validator;
+
+ @Before public void setUp() {
+ messageAcceptor = mock(ValidationMessageAcceptor.class);
+ validator = xtext.getInstanceOf(ProtobufJavaValidator.class);
+ validator.setMessageAcceptor(messageAcceptor);
+ }
+
+ @Test public void should_create_error_if_field_index_is_zero() {
+ MultiLineTextBuilder proto = new MultiLineTextBuilder();
+ proto.append("message Person { ");
+ proto.append(" optional long id = 0;");
+ proto.append("} ");
+ Protobuf root = xtext.parseText(proto);
+ Property p = findProperty(name("id"), in(root));
+ validator.checkTagNumberIsGreaterThanZero(p);
+ String message = "Field numbers must be positive integers.";
+ verify(messageAcceptor).acceptError(message, p, FIELD__INDEX, INSIGNIFICANT_INDEX, INVALID_FIELD_TAG_NUMBER_ERROR);
+ }
+
+ @Test public void should_create_error_if_field_index_is_negative() {
+ MultiLineTextBuilder proto = new MultiLineTextBuilder();
+ proto.append("message Person { ");
+ proto.append(" optional long id = -1;");
+ proto.append("} ");
+ Protobuf root = xtext.parseText(proto);
+ Property p = findProperty(name("id"), in(root));
+ validator.checkTagNumberIsGreaterThanZero(p);
+ String message = "Expected field number.";
+ verify(messageAcceptor).acceptError(message, p, FIELD__INDEX, INSIGNIFICANT_INDEX, INVALID_FIELD_TAG_NUMBER_ERROR);
+ }
+
+ @Test public void should_not_create_error_if_field_index_is_greater_than_zero() {
+ MultiLineTextBuilder proto = new MultiLineTextBuilder();
+ proto.append("message Person { ");
+ proto.append(" optional long id = 1;");
+ proto.append("} ");
+ Protobuf root = xtext.parseText(proto);
+ Property p = findProperty(name("id"), in(root));
+ validator.checkTagNumberIsGreaterThanZero(p);
+ verifyZeroInteractions(messageAcceptor);
+ }
+}
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/validation/ProtobufJavaValidator_checkTagNumberIsUnique_Test.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/validation/ProtobufJavaValidator_checkTagNumberIsUnique_Test.java
new file mode 100644
index 0000000..9d33dcd
--- /dev/null
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/validation/ProtobufJavaValidator_checkTagNumberIsUnique_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.validation;
+
+import static com.google.eclipse.protobuf.junit.model.find.Name.name;
+import static com.google.eclipse.protobuf.junit.model.find.PropertyFinder.findProperty;
+import static com.google.eclipse.protobuf.junit.model.find.Root.in;
+import static com.google.eclipse.protobuf.protobuf.ProtobufPackage.Literals.FIELD__INDEX;
+import static com.google.eclipse.protobuf.validation.ProtobufJavaValidator.INVALID_FIELD_TAG_NUMBER_ERROR;
+import static org.eclipse.xtext.validation.ValidationMessageAcceptor.INSIGNIFICANT_INDEX;
+import static org.mockito.Mockito.*;
+
+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.xtext.validation.ValidationMessageAcceptor;
+import org.junit.*;
+
+/**
+ * Tests for <code>{@link ProtobufJavaValidator#checkTagNumberIsUnique(Field)}</code>
+ *
+ * @author alruiz@google.com (Alex Ruiz)
+ */
+public class ProtobufJavaValidator_checkTagNumberIsUnique_Test {
+
+ @Rule public XtextRule xtext = XtextRule.unitTestSetup();
+
+ private ValidationMessageAcceptor messageAcceptor;
+ private ProtobufJavaValidator validator;
+
+ @Before public void setUp() {
+ messageAcceptor = mock(ValidationMessageAcceptor.class);
+ validator = xtext.getInstanceOf(ProtobufJavaValidator.class);
+ validator.setMessageAcceptor(messageAcceptor);
+ }
+
+ @Test public void should_create_error_if_field_does_not_have_unique_tag_number() {
+ MultiLineTextBuilder proto = new MultiLineTextBuilder();
+ proto.append("message Person { ");
+ proto.append(" optional long id = 1; ");
+ proto.append(" optional string name = 1;");
+ proto.append("} ");
+ Protobuf root = xtext.parseText(proto);
+ Property p = findProperty(name("name"), in(root));
+ validator.checkTagNumberIsUnique(p);
+ String message = "Field number 1 has already been used in \"Person\" by field \"id\".";
+ verify(messageAcceptor).acceptError(message, p, FIELD__INDEX, INSIGNIFICANT_INDEX, INVALID_FIELD_TAG_NUMBER_ERROR);
+ }
+
+ @Test public void should_not_create_error_if_field_has_unique_tag_number() {
+ MultiLineTextBuilder proto = new MultiLineTextBuilder();
+ proto.append("message Person { ");
+ proto.append(" optional long id = 1; ");
+ proto.append(" optional string name = 2;");
+ proto.append("} ");
+ Protobuf root = xtext.parseText(proto);
+ Property p = findProperty(name("name"), in(root));
+ validator.checkTagNumberIsUnique(p);
+ verifyZeroInteractions(messageAcceptor);
+ }
+}
diff --git a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/commands/CommentNodesFinder_matchingCommentNode_Test.java b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/commands/CommentNodesFinder_matchingCommentNode_Test.java
index 1c874aa..893796e 100644
--- a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/commands/CommentNodesFinder_matchingCommentNode_Test.java
+++ b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/commands/CommentNodesFinder_matchingCommentNode_Test.java
@@ -8,9 +8,9 @@
*/
package com.google.eclipse.protobuf.ui.commands;
-import static com.google.eclipse.protobuf.junit.find.Name.name;
-import static com.google.eclipse.protobuf.junit.find.PropertyFinder.findProperty;
-import static com.google.eclipse.protobuf.junit.find.Root.in;
+import static com.google.eclipse.protobuf.junit.model.find.Name.name;
+import static com.google.eclipse.protobuf.junit.model.find.PropertyFinder.findProperty;
+import static com.google.eclipse.protobuf.junit.model.find.Root.in;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.hamcrest.core.IsNull.*;
import static org.junit.Assert.assertThat;
diff --git a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/documentation/SingleLineCommentDocumentationProvider_getDocumentation_Test.java b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/documentation/SingleLineCommentDocumentationProvider_getDocumentation_Test.java
index e08da5f..d0450a4 100644
--- a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/documentation/SingleLineCommentDocumentationProvider_getDocumentation_Test.java
+++ b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/documentation/SingleLineCommentDocumentationProvider_getDocumentation_Test.java
@@ -8,9 +8,9 @@
*/
package com.google.eclipse.protobuf.ui.documentation;
-import static com.google.eclipse.protobuf.junit.find.Name.name;
-import static com.google.eclipse.protobuf.junit.find.PropertyFinder.findProperty;
-import static com.google.eclipse.protobuf.junit.find.Root.in;
+import static com.google.eclipse.protobuf.junit.model.find.Name.name;
+import static com.google.eclipse.protobuf.junit.model.find.PropertyFinder.findProperty;
+import static com.google.eclipse.protobuf.junit.model.find.Root.in;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertThat;
diff --git a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/util/Fields_calculateTagNumberOf_Test.java b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/util/Fields_calculateTagNumberOf_Test.java
index 6d89af3..9e46ade 100644
--- a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/util/Fields_calculateTagNumberOf_Test.java
+++ b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/util/Fields_calculateTagNumberOf_Test.java
@@ -8,9 +8,9 @@
*/
package com.google.eclipse.protobuf.ui.util;
-import static com.google.eclipse.protobuf.junit.find.Name.name;
-import static com.google.eclipse.protobuf.junit.find.PropertyFinder.findProperty;
-import static com.google.eclipse.protobuf.junit.find.Root.in;
+import static com.google.eclipse.protobuf.junit.model.find.Name.name;
+import static com.google.eclipse.protobuf.junit.model.find.PropertyFinder.findProperty;
+import static com.google.eclipse.protobuf.junit.model.find.Root.in;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertThat;
diff --git a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/util/Literals_calculateIndexOf_Test.java b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/util/Literals_calculateIndexOf_Test.java
index c855d0e..0124ff8 100644
--- a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/util/Literals_calculateIndexOf_Test.java
+++ b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/util/Literals_calculateIndexOf_Test.java
@@ -8,9 +8,9 @@
*/
package com.google.eclipse.protobuf.ui.util;
-import static com.google.eclipse.protobuf.junit.find.LiteralFinder.findLiteral;
-import static com.google.eclipse.protobuf.junit.find.Name.name;
-import static com.google.eclipse.protobuf.junit.find.Root.in;
+import static com.google.eclipse.protobuf.junit.model.find.LiteralFinder.findLiteral;
+import static com.google.eclipse.protobuf.junit.model.find.Name.name;
+import static com.google.eclipse.protobuf.junit.model.find.Root.in;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertThat;
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/contentassist/CustomOptionProperties.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/contentassist/CustomOptionProperties.java
index a232ae7..177d077 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/contentassist/CustomOptionProperties.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/contentassist/CustomOptionProperties.java
@@ -16,7 +16,6 @@
import com.google.eclipse.protobuf.model.util.*;
import com.google.eclipse.protobuf.protobuf.*;
import com.google.eclipse.protobuf.protobuf.Package;
-import com.google.eclipse.protobuf.util.*;
import com.google.inject.Inject;
import org.eclipse.emf.common.util.TreeIterator;
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/model/OptionType.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/model/OptionType.java
index 7ead38b..339cf77 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/model/OptionType.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/model/OptionType.java
@@ -37,22 +37,40 @@
OPTION_TYPES_BY_CONTAINER.put(Rpc.class, RPC);
}
- /**
- * The name of the message in descriptor.proto that specifies the type of an option.
- */
- public final String messageName;
+ // The name of the message in descriptor.proto that specifies the type of an option.
+ private final String messageName;
private OptionType(String messageName) {
this.messageName = messageName;
}
/**
+ * Returns the name of the message in descriptor.proto that specifies the type of an option.
+ * @return the name of the message in descriptor.proto that specifies the type of an option.
+ */
+ public String messageName() {
+ return messageName;
+ }
+
+ /**
* Returns the type of the given option.
* @param option the given option.
* @return the type of the given option or {@code null} if a type cannot be found.
*/
- public static OptionType typeOf(EObject option) {
- EObject container = option.eContainer();
+ public static OptionType typeOf(FieldOption option) {
+ return findType(option.eContainer());
+ }
+
+ /**
+ * Returns the type of the given option.
+ * @param option the given option.
+ * @return the type of the given option or {@code null} if a type cannot be found.
+ */
+ public static OptionType typeOf(Option option) {
+ return findType(option.eContainer());
+ }
+
+ private static OptionType findType(EObject container) {
for (Entry<Class<?>, OptionType> optionTypeByContainer : OPTION_TYPES_BY_CONTAINER.entrySet()) {
if (optionTypeByContainer.getKey().isInstance(container)) {
return optionTypeByContainer.getValue();
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/model/util/Options.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/model/util/Options.java
index 4eb677f..608f3e8 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/model/util/Options.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/model/util/Options.java
@@ -66,7 +66,7 @@
if (!(o instanceof ExtendMessage)) return false;
Message message = messageFrom((ExtendMessage) o);
if (message == null) return false;
- return optionType.messageName.equals(message.getName());
+ return optionType.messageName().equals(message.getName());
}
private Message messageFrom(ExtendMessage extend) {
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/util/Resources.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/model/util/Resources.java
similarity index 96%
rename from com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/util/Resources.java
rename to com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/model/util/Resources.java
index 1d92fc8..09679a7 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/util/Resources.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/model/util/Resources.java
@@ -7,7 +7,7 @@
*
* http://www.eclipse.org/legal/epl-v10.html
*/
-package com.google.eclipse.protobuf.util;
+package com.google.eclipse.protobuf.model.util;
import static org.eclipse.emf.common.util.URI.createURI;
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/CustomOptionDescriptions.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/CustomOptionDescriptions.java
index 3dc4220..5963194 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/CustomOptionDescriptions.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/CustomOptionDescriptions.java
@@ -25,7 +25,6 @@
import com.google.eclipse.protobuf.model.util.*;
import com.google.eclipse.protobuf.protobuf.*;
import com.google.eclipse.protobuf.protobuf.Package;
-import com.google.eclipse.protobuf.util.*;
import com.google.inject.Inject;
/**
@@ -42,9 +41,16 @@
@Inject private QualifiedNameDescriptions qualifiedNamesDescriptions;
@Inject private Resources resources;
- Collection <IEObjectDescription> properties(EObject option) {
+ Collection <IEObjectDescription> properties(CustomOption option) {
+ return allProperties(option, typeOf(option));
+ }
+
+ Collection <IEObjectDescription> properties(CustomFieldOption option) {
+ return allProperties(option, typeOf(option));
+ }
+
+ private Collection <IEObjectDescription> allProperties(EObject option, OptionType type) {
Set<IEObjectDescription> descriptions = new HashSet<IEObjectDescription>();
- OptionType type = typeOf(option);
EObject current = option.eContainer();
while (current != null) {
descriptions.addAll(local(current, type));
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/NativeOptionDescriptions.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/NativeOptionDescriptions.java
index 0f1b6e2..28fa721 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/NativeOptionDescriptions.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/NativeOptionDescriptions.java
@@ -11,7 +11,7 @@
import static java.util.Collections.emptyList;
import static org.eclipse.xtext.resource.EObjectDescription.create;
-import com.google.eclipse.protobuf.protobuf.Property;
+import com.google.eclipse.protobuf.protobuf.*;
import com.google.inject.Inject;
import org.eclipse.emf.ecore.EObject;
@@ -26,7 +26,15 @@
@Inject private ProtoDescriptorProvider descriptorProvider;
- Collection <IEObjectDescription> properties(EObject option) {
+ Collection <IEObjectDescription> properties(NativeOption option) {
+ return allProperties(option);
+ }
+
+ Collection <IEObjectDescription> properties(NativeFieldOption option) {
+ return allProperties(option);
+ }
+
+ private Collection <IEObjectDescription> allProperties(EObject option) {
ProtoDescriptor descriptor = descriptorProvider.primaryDescriptor();
Collection<Property> properties = descriptor.availableOptionsFor(option.eContainer());
if (properties.isEmpty()) return emptyList();
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 9460829..6f9b3c4 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
@@ -48,7 +48,7 @@
private static void populateMap() {
for (OptionType type : OptionType.values()) {
- OPTION_DEFINITION_BY_NAME.put(type.messageName, type);
+ OPTION_DEFINITION_BY_NAME.put(type.messageName(), type);
}
}
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 b029280..35b9742 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
@@ -102,11 +102,21 @@
@SuppressWarnings("unused")
IScope scope_PropertyRef_property(PropertyRef propertyRef, EReference reference) {
EObject c = propertyRef.eContainer();
- if (c instanceof NativeOption || c instanceof NativeFieldOption) {
- return createScope(nativeOptionDescriptions.properties(c));
+ if (c instanceof NativeOption) {
+ NativeOption option = (NativeOption) c;
+ return createScope(nativeOptionDescriptions.properties(option));
}
- if (c instanceof CustomOption || c instanceof CustomFieldOption) {
- return createScope(customOptionDescriptions.properties(c));
+ if (c instanceof NativeFieldOption) {
+ NativeFieldOption option = (NativeFieldOption) c;
+ return createScope(nativeOptionDescriptions.properties(option));
+ }
+ if (c instanceof CustomOption) {
+ CustomOption option = (CustomOption) c;
+ return createScope(customOptionDescriptions.properties(option));
+ }
+ if (c instanceof CustomFieldOption) {
+ CustomFieldOption option = (CustomFieldOption) c;
+ return createScope(customOptionDescriptions.properties(option));
}
Set<IEObjectDescription> descriptions = emptySet();
return createScope(descriptions);
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/TypeDescriptions.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/TypeDescriptions.java
index 555ed7f..c9b78e6 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/TypeDescriptions.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/TypeDescriptions.java
@@ -23,7 +23,6 @@
import com.google.eclipse.protobuf.model.util.*;
import com.google.eclipse.protobuf.protobuf.*;
import com.google.eclipse.protobuf.protobuf.Package;
-import com.google.eclipse.protobuf.util.*;
import com.google.inject.Inject;
/**
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/validation/ProtobufJavaValidator.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/validation/ProtobufJavaValidator.java
index 0b38cc9..8965d04 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/validation/ProtobufJavaValidator.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/validation/ProtobufJavaValidator.java
@@ -22,7 +22,6 @@
import com.google.eclipse.protobuf.model.util.*;
import com.google.eclipse.protobuf.protobuf.*;
import com.google.eclipse.protobuf.protobuf.Package;
-import com.google.eclipse.protobuf.util.*;
import com.google.inject.Inject;
/**