Cleaned up tests. Unified all the classes for element lookup into a
single one.
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 a4d9291..63ed81e 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
@@ -10,9 +10,6 @@
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.junit.model.find.FieldOptionFinder.findCustomFieldOption;
-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;
@@ -30,11 +27,9 @@
@Rule public XtextRule xtext = createWith(integrationTestSetup());
- private Protobuf root;
private FieldOptions fieldOptions;
@Before public void setUp() {
- root = xtext.root();
fieldOptions = xtext.getInstanceOf(FieldOptions.class);
}
@@ -52,7 +47,7 @@
// optional boolean active = 1 [(custom).count = 6];
// }
@Test public void should_return_property_field() {
- CustomFieldOption option = findCustomFieldOption(name("custom"), in(root));
+ CustomFieldOption option = xtext.find("custom", ").", CustomFieldOption.class);
Property p = fieldOptions.fieldFrom(option);
assertThat(p.getName(), equalTo("count"));
}
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 89c1702..a0e4b81 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
@@ -10,9 +10,6 @@
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.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;
@@ -30,11 +27,9 @@
@Rule public XtextRule xtext = createWith(integrationTestSetup());
- private Protobuf root;
private FieldOptions fieldOptions;
@Before public void setUp() {
- root = xtext.root();
fieldOptions = xtext.getInstanceOf(FieldOptions.class);
}
@@ -42,7 +37,7 @@
// optional boolean active = 1 [default = true, deprecated = false];
// }
@Test public void should_return_true_if_FieldOption_is_default_value_one() {
- FieldOption option = findFieldOption(name("default"), in(root));
+ FieldOption option = xtext.find("default", FieldOption.class);
boolean result = fieldOptions.isDefaultValueOption(option);
assertThat(result, equalTo(true));
}
@@ -51,7 +46,7 @@
// optional boolean active = 1 [default = true, deprecated = false];
// }
@Test public void should_return_false_if_FieldOption_is_not_default_value_one() {
- FieldOption option = findFieldOption(name("deprecated"), in(root));
+ FieldOption option = xtext.find("deprecated", FieldOption.class);
boolean result = fieldOptions.isDefaultValueOption(option);
assertThat(result, equalTo(false));
}
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 034ce14..530b3d7 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
@@ -10,14 +10,11 @@
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.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;
import com.google.eclipse.protobuf.junit.core.XtextRule;
-import com.google.eclipse.protobuf.protobuf.*;
+import com.google.eclipse.protobuf.protobuf.FieldOption;
import org.junit.*;
@@ -30,11 +27,9 @@
@Rule public XtextRule xtext = createWith(integrationTestSetup());
- private Protobuf root;
private FieldOptions fieldOptions;
@Before public void setUp() {
- root = xtext.root();
fieldOptions = xtext.getInstanceOf(FieldOptions.class);
}
@@ -42,7 +37,7 @@
// optional boolean active = 1 [deprecated = false];
// }
@Test public void should_return_name_of_native_field_option() {
- FieldOption option = findFieldOption(name("deprecated"), in(root));
+ FieldOption option = xtext.find("deprecated", FieldOption.class);
String name = fieldOptions.nameOf(option);
assertThat(name, equalTo("deprecated"));
}
@@ -57,7 +52,7 @@
// optional boolean active = 1 [(encoding) = 'UTF-8'];
// }
@Test public void should_return_name_of_custom_field_option() {
- FieldOption option = findFieldOption(name("encoding"), in(root));
+ FieldOption option = xtext.find("encoding", ")", FieldOption.class);
String name = fieldOptions.nameOf(option);
assertThat(name, equalTo("encoding"));
}
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 9f222f0..52d524c 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
@@ -10,9 +10,6 @@
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.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;
@@ -30,11 +27,9 @@
@Rule public XtextRule xtext = createWith(integrationTestSetup());
- private Protobuf root;
private FieldOptions fieldOptions;
@Before public void setUp() {
- root = xtext.root();
fieldOptions = xtext.getInstanceOf(FieldOptions.class);
}
@@ -42,7 +37,7 @@
// optional boolean active = 1 [deprecated = false];
// }
@Test public void should_return_property_of_native_field_option() {
- FieldOption option = findFieldOption(name("deprecated"), in(root));
+ FieldOption option = xtext.find("deprecated", FieldOption.class);
Property p = fieldOptions.propertyFrom(option);
assertThat(p.getName(), equalTo("deprecated"));
}
@@ -57,7 +52,7 @@
// optional boolean active = 1 [(encoding) = 'UTF-8'];
// }
@Test public void should_return_property_of_custom_field_option() {
- FieldOption option = findFieldOption(name("encoding"), in(root));
+ FieldOption option = xtext.find("encoding", ")", FieldOption.class);
Property p = fieldOptions.propertyFrom(option);
assertThat(p.getName(), equalTo("encoding"));
}
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 c7cda66..4be5b3f 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
@@ -10,9 +10,6 @@
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.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;
@@ -30,11 +27,9 @@
@Rule public XtextRule xtext = createWith(integrationTestSetup());
- private Protobuf root;
private Options options;
@Before public void setUp() {
- root = xtext.root();
options = xtext.getInstanceOf(Options.class);
}
@@ -50,7 +45,7 @@
//
// option (custom).count = 6;
@Test public void should_return_property_field() {
- CustomOption option = (CustomOption) findOption(name("custom"), in(root));
+ CustomOption option = xtext.find("custom", ")", CustomOption.class);
Property p = options.fieldFrom(option);
assertThat(p.getName(), equalTo("count"));
}
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
index 57c8869..38765fb 100644
--- 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
@@ -10,9 +10,6 @@
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.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;
@@ -34,11 +31,9 @@
@Rule public XtextRule xtext = createWith(integrationTestSetup());
- private Protobuf root;
private Options options;
@Before public void setUp() {
- root = xtext.root();
options = xtext.getInstanceOf(Options.class);
}
@@ -48,7 +43,7 @@
// optional string encoding = 1000;
// }
@Test public void should_return_true_if_name_of_extended_message_is_equal_to_message_name_in_OptionType() {
- ExtendMessage extend = findExtendMessage(name("FileOptions"), in(root));
+ ExtendMessage extend = xtext.find("FileOptions", ExtendMessage.class);
boolean result = options.isExtendingOptionMessage(extend, FILE);
assertThat(result, equalTo(true));
}
@@ -65,7 +60,7 @@
// optional string encoding = 1000;
// }
@Test public void should_return_false_if_name_of_extended_message_is_not_equal_to_message_name_in_OptionType() {
- ExtendMessage extend = findExtendMessage(name("FieldOptions"), in(root));
+ ExtendMessage extend = xtext.find("FieldOptions", ExtendMessage.class);
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 2bbd2a9..af538ea 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
@@ -10,9 +10,6 @@
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.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;
@@ -30,17 +27,15 @@
@Rule public XtextRule xtext = createWith(integrationTestSetup());
- private Protobuf root;
private Options options;
@Before public void setUp() {
- root = xtext.root();
options = xtext.getInstanceOf(Options.class);
}
// option java_package = 'com.google.eclipse.protobuf.tests';
@Test public void should_return_property_of_native_option() {
- Option option = findOption(name("java_package"), in(root));
+ Option option = xtext.find("java_package", Option.class);
Property p = options.propertyFrom(option);
assertThat(p.getName(), equalTo("java_package"));
}
@@ -53,7 +48,7 @@
//
// option (encoding) = 'UTF-8';
@Test public void should_return_property_of_custom_option() {
- Option option = findOption(name("encoding"), in(root));
+ Option option = xtext.find("encoding", ")", Option.class);
Property p = options.propertyFrom(option);
assertThat(p.getName(), equalTo("encoding"));
}
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
index b9dd454..5089b0b 100644
--- 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
@@ -10,29 +10,18 @@
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.junit.model.find.EnumFinder.findEnum;
-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.OptionFinder.findOption;
-import static com.google.eclipse.protobuf.junit.model.find.Root.in;
import static com.google.eclipse.protobuf.scoping.ContainAllLiteralsInEnum.containAllLiteralsIn;
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.*;
+import com.google.eclipse.protobuf.protobuf.Enum;
+
import org.eclipse.emf.ecore.EReference;
import org.eclipse.xtext.scoping.IScope;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Rule;
-import org.junit.Test;
-
-import com.google.eclipse.protobuf.junit.core.XtextRule;
-import com.google.eclipse.protobuf.protobuf.Enum;
-import com.google.eclipse.protobuf.protobuf.FieldOption;
-import com.google.eclipse.protobuf.protobuf.LiteralRef;
-import com.google.eclipse.protobuf.protobuf.Option;
-import com.google.eclipse.protobuf.protobuf.Protobuf;
+import org.junit.*;
/**
* Tests for <code>{@link ProtobufScopeProvider#scope_LiteralRef_literal(LiteralRef, EReference)}</code>.
@@ -49,11 +38,9 @@
@Rule public XtextRule xtext = createWith(integrationTestSetup());
- private Protobuf root;
private ProtobufScopeProvider provider;
@Before public void setUp() {
- root = xtext.root();
provider = xtext.getInstanceOf(ProtobufScopeProvider.class);
}
@@ -66,15 +53,15 @@
// optional Type type = 1 [default = ONE];
// }
@Test public void should_provide_Literals_for_default_value() {
- FieldOption option = findFieldOption(name("default"), in(root));
+ FieldOption option = xtext.find("default", FieldOption.class);
IScope scope = provider.scope_LiteralRef_literal(valueOf(option), reference);
- Enum typeEnum = findEnum(name("Type"), in(root));
+ Enum typeEnum = xtext.find("Type", " {", Enum.class);
assertThat(descriptionsIn(scope), containAllLiteralsIn(typeEnum));
}
// option optimize_for = SPEED;
@Test public void should_provide_Literals_for_native_option() {
- Option option = findOption(name("optimize_for"), in(root));
+ Option option = xtext.find("optimize_for", Option.class);
IScope scope = provider.scope_LiteralRef_literal(valueOf(option), reference);
Enum optimizeModeEnum = descriptor().enumByName("OptimizeMode");
assertThat(descriptionsIn(scope), containAllLiteralsIn(optimizeModeEnum));
@@ -93,9 +80,9 @@
//
// option (type) = ONE;
@Test public void should_provide_Literals_for_custom_option() {
- Option option = findOption(name("type"), in(root));
+ Option option = xtext.find("type", ")", Option.class);
IScope scope = provider.scope_LiteralRef_literal(valueOf(option), reference);
- Enum typeEnum = findEnum(name("Type"), in(root));
+ Enum typeEnum = xtext.find("Type", " {", Enum.class);
assertThat(descriptionsIn(scope), containAllLiteralsIn(typeEnum));
}
@@ -116,9 +103,9 @@
//
// option (info).type = ONE;
@Test public void should_provide_Literals_for_property_of_custom_option() {
- Option option = findOption(name("info"), in(root));
+ Option option = xtext.find("info", ")", Option.class);
IScope scope = provider.scope_LiteralRef_literal(valueOf(option), reference);
- Enum typeEnum = findEnum(name("Type"), in(root));
+ Enum typeEnum = xtext.find("Type", " {", Enum.class);
assertThat(descriptionsIn(scope), containAllLiteralsIn(typeEnum));
}
@@ -130,7 +117,7 @@
// optional Type type = 1 [ctype = STRING];
// }
@Test public void should_provide_Literals_for_native_field_option() {
- FieldOption option = findFieldOption(name("ctype"), in(root));
+ FieldOption option = xtext.find("ctype", FieldOption.class);
IScope scope = provider.scope_LiteralRef_literal(valueOf(option), reference);
Enum cTypeEnum = descriptor().enumByName("CType");
assertThat(descriptionsIn(scope), containAllLiteralsIn(cTypeEnum));
@@ -156,9 +143,9 @@
// optional boolean active = 1 [(type) = ONE];
// }
@Test public void should_provide_Literals_for_custom_field_option() {
- FieldOption option = findFieldOption(name("type"), in(root));
+ FieldOption option = xtext.find("type", ")", FieldOption.class);
IScope scope = provider.scope_LiteralRef_literal(valueOf(option), reference);
- Enum typeEnum = findEnum(name("Type"), in(root));
+ Enum typeEnum = xtext.find("Type", " {", Enum.class);
assertThat(descriptionsIn(scope), containAllLiteralsIn(typeEnum));
}
@@ -181,9 +168,9 @@
// optional boolean active = 1 [(info).type = ONE];
// }
@Test public void should_provide_Literals_for_property_of_custom_field_option() {
- FieldOption option = findFieldOption(name("info"), in(root));
+ FieldOption option = xtext.find("info", ")", FieldOption.class);
IScope scope = provider.scope_LiteralRef_literal(valueOf(option), reference);
- Enum typeEnum = findEnum(name("Type"), in(root));
+ Enum typeEnum = xtext.find("Type", " {", Enum.class);
assertThat(descriptionsIn(scope), containAllLiteralsIn(typeEnum));
}
diff --git a/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/scoping/ProtobufScopeProvider_scope_PropertyRef_property_Test.java b/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/scoping/ProtobufScopeProvider_scope_PropertyRef_property_Test.java
index 2593c9e..64ae688 100644
--- a/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/scoping/ProtobufScopeProvider_scope_PropertyRef_property_Test.java
+++ b/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/scoping/ProtobufScopeProvider_scope_PropertyRef_property_Test.java
@@ -10,10 +10,6 @@
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.junit.model.find.FieldOptionFinder.*;
-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 com.google.eclipse.protobuf.model.OptionType.*;
import static com.google.eclipse.protobuf.scoping.ContainAllNames.containAll;
import static com.google.eclipse.protobuf.scoping.ContainAllProperties.containAll;
@@ -45,17 +41,15 @@
@Rule public XtextRule xtext = createWith(integrationTestSetup());
- private Protobuf root;
private ProtobufScopeProvider provider;
@Before public void setUp() {
- root = xtext.root();
provider = xtext.getInstanceOf(ProtobufScopeProvider.class);
}
// option optimize_for = SPEED;
@Test public void should_provide_Property_fields_for_native_option() {
- Option option = findOption(name("optimize_for"), in(root));
+ Option option = xtext.find("optimize_for", Option.class);
IScope scope = provider.scope_PropertyRef_property(option.getProperty(), reference);
Collection<Property> fileOptions = descriptor().optionsOfType(FILE);
assertThat(descriptionsIn(scope), containAll(fileOptions));
@@ -65,7 +59,7 @@
// optional Type type = 1 [ctype = STRING];
// }
@Test public void should_provide_Property_fields_for_native_field_option() {
- NativeFieldOption option = findNativeFieldOption(name("ctype"), in(root));
+ NativeFieldOption option = xtext.find("ctype", NativeFieldOption.class);
IScope scope = provider.scope_PropertyRef_property(option.getProperty(), reference);
Collection<Property> fieldOptions = descriptor().optionsOfType(FIELD);
assertThat(descriptionsIn(scope), containAll(fieldOptions));
@@ -86,7 +80,7 @@
//
// option (code) = 68;
@Test public void should_provide_Property_fields_for_custom_option() {
- Option option = findOption(name("code"), in(root));
+ 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",
@@ -100,7 +94,7 @@
//
// option (code) = 68;
@Test public void should_provide_imported_Property_fields_for_custom_option() {
- Option option = findOption(name("code"), in(root));
+ Option option = xtext.find("code", ")", Option.class);
IScope scope = provider.scope_PropertyRef_property(option.getProperty(), reference);
assertThat(descriptionsIn(scope), containAll("code", "test.code", "google.test.code", "com.google.test.code",
".com.google.test.code",
@@ -120,7 +114,7 @@
// optional boolean active = 1 [(code) = 68];
// }
@Test public void should_provide_Property_fields_for_custom_field_option() {
- CustomFieldOption option = findCustomFieldOption(name("code"), in(root));
+ CustomFieldOption option = xtext.find("code", ")", CustomFieldOption.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",
diff --git a/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/scoping/ProtobufScopeProvider_scope_SimplePropertyRef_property_Test.java b/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/scoping/ProtobufScopeProvider_scope_SimplePropertyRef_property_Test.java
index 82d0b49..13bbbc5 100644
--- a/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/scoping/ProtobufScopeProvider_scope_SimplePropertyRef_property_Test.java
+++ b/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/scoping/ProtobufScopeProvider_scope_SimplePropertyRef_property_Test.java
@@ -10,11 +10,6 @@
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.junit.model.find.FieldOptionFinder.findCustomFieldOption;
-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.OptionFinder.findCustomOption;
-import static com.google.eclipse.protobuf.junit.model.find.Root.in;
import static com.google.eclipse.protobuf.scoping.ContainAllPropertiesInMessage.containAllPropertiesIn;
import static com.google.eclipse.protobuf.scoping.IEObjectDescriptions.descriptionsIn;
import static org.junit.Assert.assertThat;
@@ -42,11 +37,9 @@
@Rule public XtextRule xtext = createWith(integrationTestSetup());
- private Protobuf root;
private ProtobufScopeProvider provider;
@Before public void setUp() {
- root = xtext.root();
provider = xtext.getInstanceOf(ProtobufScopeProvider.class);
}
@@ -63,9 +56,9 @@
//
// option (type).code = 68;
@Test public void should_provide_Property_fields_for_custom_option_field() {
- CustomOption option = findCustomOption(name("type"), in(root));
+ CustomOption option = xtext.find("type", ")", CustomOption.class);
IScope scope = provider.scope_SimplePropertyRef_property(option.getPropertyField(), reference);
- Message typeMessage = findMessage(name("Type"), in(root));
+ Message typeMessage = xtext.find("Type", " {", Message.class);
assertThat(descriptionsIn(scope), containAllPropertiesIn(typeMessage));
}
@@ -84,9 +77,9 @@
// optional boolean active = 1 [(type).code = 68];
// }
@Test public void should_provide_Property_fields_for_custom_field_option_field() {
- CustomFieldOption option = findCustomFieldOption(name("type"), in(root));
+ CustomFieldOption option = xtext.find("type", ")", CustomFieldOption.class);
IScope scope = provider.scope_SimplePropertyRef_property(option.getPropertyField(), reference);
- Message typeMessage = findMessage(name("Type"), in(root));
+ Message typeMessage = xtext.find("Type", " {", Message.class);
assertThat(descriptionsIn(scope), containAllPropertiesIn(typeMessage));
}
}
diff --git a/com.google.eclipse.protobuf.test/META-INF/MANIFEST.MF b/com.google.eclipse.protobuf.test/META-INF/MANIFEST.MF
index 768f41a..f9e6122 100644
--- a/com.google.eclipse.protobuf.test/META-INF/MANIFEST.MF
+++ b/com.google.eclipse.protobuf.test/META-INF/MANIFEST.MF
@@ -13,6 +13,5 @@
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Export-Package: com.google.eclipse.protobuf.junit.core,
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/core/ModelFinder.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/core/ModelFinder.java
new file mode 100644
index 0000000..a584ea4
--- /dev/null
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/core/ModelFinder.java
@@ -0,0 +1,80 @@
+/*
+ * 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.core;
+
+import com.google.eclipse.protobuf.protobuf.DefaultValueFieldOption;
+
+import org.eclipse.emf.ecore.*;
+import org.eclipse.xtext.nodemodel.*;
+import org.eclipse.xtext.nodemodel.impl.AbstractNode;
+
+/**
+ * @author alruiz@google.com (Alex Ruiz)
+ */
+class ModelFinder {
+
+ private static final String[] FEATURE_NAMES = { "name", "property", "message", "type" };
+
+ private final String content;
+ private final ICompositeNode root;
+
+ ModelFinder(ICompositeNode root, String content) {
+ this.root = root;
+ this.content = content;
+ }
+
+ <T extends EObject> T find(String text, int count, Class<T> type) {
+ int offset = content.indexOf(text);
+ String name = text.substring(0, count);
+ BidiTreeIterator<AbstractNode> iterator = root().basicIterator();
+ while (iterator.hasNext()) {
+ AbstractNode node = iterator.next();
+ int nodeOffset = node.getOffset();
+ if (nodeOffset > offset || (nodeOffset + node.getLength()) <= offset) continue;
+ EObject e = node.getSemanticElement();
+ if (isDefaultValueFieldOption(e, name, type)) {
+ return type.cast(e);
+ }
+ if (type.isInstance(e) && name.equals(nameOf(e))) {
+ return type.cast(e);
+ }
+ }
+ String format = "Unable to find element. Text: '%s', count: %d, type: %s";
+ throw new AssertionError(String.format(format, text, count, type.getName()));
+ }
+
+ private AbstractNode root() {
+ INode node = root;
+ while (!(node instanceof AbstractNode)) {
+ node = node.getParent();
+ }
+ return (AbstractNode) node;
+ }
+
+ private boolean isDefaultValueFieldOption(EObject e, String name, Class<?> type) {
+ return "default".equals(name) && type.isInstance(e) && e instanceof DefaultValueFieldOption;
+ }
+
+ private String nameOf(Object o) {
+ if (!(o instanceof EObject)) return null;
+ EObject e = (EObject) o;
+ for (String name : FEATURE_NAMES) {
+ Object value = feature(e, name);
+ if (value instanceof String) return (String) value;
+ if (value != null) return nameOf(value);
+ }
+ return null;
+ }
+
+ private Object feature(EObject e, String featureName) {
+ EStructuralFeature f = e.eClass().getEStructuralFeature(featureName);
+ return (f != null) ? e.eGet(f) : null;
+ }
+}
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/core/XtextRule.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/core/XtextRule.java
index cd0d72d..838d851 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/core/XtextRule.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/core/XtextRule.java
@@ -18,6 +18,7 @@
import java.io.*;
import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
import org.eclipse.xtext.ISetup;
import org.eclipse.xtext.linking.lazy.LazyLinkingResource;
import org.eclipse.xtext.nodemodel.INode;
@@ -41,6 +42,8 @@
private final TestSourceReader reader;
private Protobuf root;
+ private XtextResource resource;
+ private ModelFinder finder;
public static XtextRule createWith(ISetup setup) {
return new XtextRule(setup);
@@ -55,7 +58,8 @@
root = null;
String comments = reader.commentsIn(method);
if (!isEmpty(comments)) {
- root = parseText(comments);
+ parseText(comments);
+ finder = new ModelFinder(resource.getParseResult().getRootNode(), comments);
}
return base;
}
@@ -64,10 +68,13 @@
return injector;
}
- private Protobuf parseText(String text) {
- XtextResource resource = resourceFrom(new StringInputStream(text));
+ private void parseText(String text) {
+ resource = resourceFrom(new StringInputStream(text));
IParseResult parseResult = resource.getParseResult();
- if (!parseResult.hasSyntaxErrors()) return (Protobuf) parseResult.getRootASTElement();
+ if (!parseResult.hasSyntaxErrors()) {
+ root = (Protobuf) parseResult.getRootASTElement();
+ return;
+ }
StringBuilder builder = new StringBuilder();
builder.append("Syntax errors:");
for (INode error : parseResult.getSyntaxErrors())
@@ -104,4 +111,16 @@
public Protobuf root() {
return root;
}
+
+ public <T extends EObject> T find(String name, String extra, Class<T> type) {
+ return find(name + extra, name.length(), type);
+ }
+
+ public <T extends EObject> T find(String name, Class<T> type) {
+ return find(name, name.length(), type);
+ }
+
+ public <T extends EObject> T find(String text, int count, Class<T> type) {
+ return finder.find(text, count, type);
+ }
}
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/model/find/EnumFinder.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/model/find/EnumFinder.java
deleted file mode 100644
index c0bd4e8..0000000
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/model/find/EnumFinder.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * 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.Enum;
-
-/**
- * @author alruiz@google.com (Alex Ruiz)
- */
-public final class 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
deleted file mode 100644
index a0051d4..0000000
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/model/find/ExtendMessageFinder.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * 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/model/find/FieldOptionFinder.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/model/find/FieldOptionFinder.java
deleted file mode 100644
index 6962e11..0000000
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/model/find/FieldOptionFinder.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * 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 FieldOptionFinder {
-
- public static FieldOption findFieldOption(Name name, Root root) {
- return fieldOption(name, root, FieldOption.class);
- }
-
- public static NativeFieldOption findNativeFieldOption(Name name, Root root) {
- return fieldOption(name, root, NativeFieldOption.class);
- }
-
- public static CustomFieldOption findCustomFieldOption(Name name, Root root) {
- return fieldOption(name, root, CustomFieldOption.class);
- }
-
- private static <T extends FieldOption> T fieldOption(Name name, Root root, Class<T> optionType) {
- for (T option : getAllContentsOfType(root.value, optionType))
- 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;
- if (option instanceof NativeFieldOption) {
- ref = ((NativeFieldOption) option).getProperty();
- }
- if (option instanceof CustomFieldOption) {
- ref = ((CustomFieldOption) option).getProperty();
- }
- Property property = ref.getProperty();
- return (property == null) ? null : property.getName();
- }
-
- private FieldOptionFinder() {}
-}
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/model/find/LiteralFinder.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/model/find/LiteralFinder.java
deleted file mode 100644
index e2e9dff..0000000
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/model/find/LiteralFinder.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * 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 java.util.List;
-
-import com.google.eclipse.protobuf.protobuf.Literal;
-
-/**
- * @author alruiz@google.com (Alex Ruiz)
- */
-public final class LiteralFinder {
-
- public static Literal findLiteral(Name name, Root root) {
- List<Literal> literals = getAllContentsOfType(root.value, Literal.class);
- for (Literal literal : literals)
- if (name.value.equals(literal.getName())) return literal;
- return null;
- }
-
- private LiteralFinder() {}
-}
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/model/find/MessageFinder.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/model/find/MessageFinder.java
deleted file mode 100644
index 11abc7e..0000000
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/model/find/MessageFinder.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * 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.Message;
-
-/**
- * @author alruiz@google.com (Alex Ruiz)
- */
-public final class MessageFinder {
-
- public static Message findMessage(Name name, Root root) {
- for (Message message : getAllContentsOfType(root.value, Message.class))
- if (name.value.equals(message.getName())) return message;
- return null;
- }
-
- private MessageFinder() {}
-}
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/model/find/Name.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/model/find/Name.java
deleted file mode 100644
index 7e55319..0000000
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/model/find/Name.java
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * 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;
-
-/**
- * @author alruiz@google.com (Alex Ruiz)
- */
-public final class Name {
-
- final String value;
-
- public static Name name(String value) {
- return new Name(value);
- }
-
- private Name(String value) {
- this.value = value;
- }
-}
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/model/find/OptionFinder.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/model/find/OptionFinder.java
deleted file mode 100644
index 225b2ea..0000000
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/model/find/OptionFinder.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * 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 OptionFinder {
-
- private OptionFinder() {}
-
- public static Option findOption(Name name, Root root) {
- return option(name, root, Option.class);
- }
-
- public static CustomOption findCustomOption(Name name, Root root) {
- return option(name, root, CustomOption.class);
- }
-
- private static <T extends Option> T option(Name name, Root root, Class<T> optionType) {
- for (T option : getAllContentsOfType(root.value, optionType))
- if (name.value.equals(nameOf(option))) return option;
- return null;
- }
-
- private static String nameOf(Option option) {
- PropertyRef ref = option.getProperty();
- if (ref == null) return null;
- Property property = ref.getProperty();
- return (property == null) ? null : property.getName();
- }
-}
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/model/find/PackageFinder.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/model/find/PackageFinder.java
deleted file mode 100644
index 189f121..0000000
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/model/find/PackageFinder.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * 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.Package;
-
-/**
- * @author alruiz@google.com (Alex Ruiz)
- */
-public final class PackageFinder {
-
- public static Package findPackage(Name name, Root root) {
- for (Package aPackage : getAllContentsOfType(root.value, Package.class))
- if (name.value.equals(aPackage.getName())) return aPackage;
- return null;
- }
-
- private PackageFinder() {}
-}
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/model/find/PropertyFinder.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/model/find/PropertyFinder.java
deleted file mode 100644
index 0bff62b..0000000
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/model/find/PropertyFinder.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * 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 java.util.List;
-
-import org.eclipse.emf.ecore.EObject;
-
-import com.google.eclipse.protobuf.protobuf.Property;
-
-/**
- * @author alruiz@google.com (Alex Ruiz)
- */
-public final class PropertyFinder {
-
- public static Property findProperty(Name name, Root root) {
- for (Property property : allPropertiesIn(root.value))
- if (name.value.equals(property.getName())) return property;
- return null;
- }
-
- public static List<Property> allPropertiesIn(EObject root) {
- return getAllContentsOfType(root, Property.class);
- }
-
- private PropertyFinder() {}
-}
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/model/find/Root.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/model/find/Root.java
deleted file mode 100644
index f36626b..0000000
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/model/find/Root.java
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * 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 org.eclipse.emf.ecore.EObject;
-
-public final class Root {
-
- final EObject value;
-
- public static Root in(EObject value) {
- return new Root(value);
- }
-
- private Root(EObject value) {
- this.value = value;
- }
-}
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 e51a116..e4651ce 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
@@ -10,9 +10,6 @@
import static com.google.eclipse.protobuf.junit.core.Setups.unitTestSetup;
import static com.google.eclipse.protobuf.junit.core.XtextRule.createWith;
-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;
@@ -32,11 +29,9 @@
@Rule public XtextRule xtext = createWith(unitTestSetup());
- private Protobuf root;
private ModelFinder finder;
@Before public void setUp() {
- root = xtext.root();
finder = xtext.getInstanceOf(ModelFinder.class);
}
@@ -50,7 +45,7 @@
// optional PhoneType type = 1;
// }
@Test public void should_return_enum_if_property_type_is_enum() {
- Property type = findProperty(name("type"), in(root));
+ Property type = xtext.find("type", Property.class);
Enum phoneType = finder.enumTypeOf(type);
assertThat(phoneType.getName(), equalTo("PhoneType"));
}
@@ -59,7 +54,7 @@
// optional string name = 1;
// }
@Test public void should_return_null_if_property_type_is_not_enum() {
- Property name = findProperty(name("name"), in(root));
+ Property name = xtext.find("name", Property.class);
Enum anEnum = finder.enumTypeOf(name);
assertThat(anEnum, nullValue());
}
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 f1e4ffb..668d3d7 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
@@ -10,9 +10,6 @@
import static com.google.eclipse.protobuf.junit.core.Setups.unitTestSetup;
import static com.google.eclipse.protobuf.junit.core.XtextRule.createWith;
-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;
@@ -33,11 +30,9 @@
@Rule public XtextRule xtext = createWith(unitTestSetup());
- private Protobuf root;
private ModelFinder finder;
@Before public void setUp() {
- root = xtext.root();
finder = xtext.getInstanceOf(ModelFinder.class);
}
@@ -47,7 +42,7 @@
// optional int32 id = 1;
// }
@Test public void should_return_package_if_proto_has_one() {
- Property id = findProperty(name("id"), in(root));
+ Property id = xtext.find("id", Property.class);
Package aPackage = finder.packageOf(id);
assertThat(aPackage.getName(), equalTo("person.test"));
}
@@ -56,7 +51,7 @@
// optional int32 id = 1;
// }
@Test public void should_return_null_if_proto_does_not_have_package() {
- Property id = findProperty(name("id"), in(root));
+ Property id = xtext.find("id", Property.class);
Package aPackage = finder.packageOf(id);
assertThat(aPackage, nullValue());
}
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 3e96f8b..dcd2ec0 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
@@ -10,9 +10,6 @@
import static com.google.eclipse.protobuf.junit.core.Setups.unitTestSetup;
import static com.google.eclipse.protobuf.junit.core.XtextRule.createWith;
-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;
@@ -31,11 +28,9 @@
@Rule public XtextRule xtext = createWith(unitTestSetup());
- private Protobuf root;
private ModelFinder finder;
@Before public void setUp() {
- root = xtext.root();
finder = xtext.getInstanceOf(ModelFinder.class);
}
@@ -43,7 +38,7 @@
// optional string name = 1;
// }
@Test public void should_return_root_of_proto() {
- Property name = findProperty(name("name"), in(root));
- assertThat(finder.rootOf(name), sameInstance(root));
+ Property name = xtext.find("name", Property.class);
+ assertThat(finder.rootOf(name), sameInstance(xtext.root()));
}
}
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 6bb79b5..4e33278 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
@@ -10,9 +10,6 @@
import static com.google.eclipse.protobuf.junit.core.Setups.unitTestSetup;
import static com.google.eclipse.protobuf.junit.core.XtextRule.createWith;
-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;
@@ -31,11 +28,9 @@
@Rule public XtextRule xtext = createWith(unitTestSetup());
- private Protobuf root;
private ModelFinder finder;
@Before public void setUp() {
- root = xtext.root();
finder = xtext.getInstanceOf(ModelFinder.class);
}
@@ -43,7 +38,7 @@
// optional int32 id = 1;
// }
@Test public void should_return_scalar_if_property_type_is_scalar() {
- Property id = findProperty(name("id"), in(root));
+ Property id = xtext.find("id", Property.class);
ScalarType int32 = finder.scalarTypeOf(id);
assertThat(int32.getName(), equalTo("int32"));
}
@@ -58,7 +53,7 @@
// optional PhoneType type = 1;
// }
@Test public void should_return_null_if_property_type_is_not_scalar() {
- Property type = findProperty(name("type"), in(root));
+ Property type = xtext.find("type", Property.class);
ScalarType scalar = finder.scalarTypeOf(type);
assertThat(scalar, nullValue());
}
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 565fd7c..acbff70 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
@@ -10,15 +10,12 @@
import static com.google.eclipse.protobuf.junit.core.Setups.unitTestSetup;
import static com.google.eclipse.protobuf.junit.core.XtextRule.createWith;
-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;
import com.google.eclipse.protobuf.junit.core.XtextRule;
-import com.google.eclipse.protobuf.protobuf.*;
+import com.google.eclipse.protobuf.protobuf.Property;
import org.eclipse.emf.ecore.*;
import org.eclipse.xtext.nodemodel.INode;
@@ -33,11 +30,9 @@
@Rule public XtextRule xtext = createWith(unitTestSetup());
- private Protobuf root;
private INodes nodes;
@Before public void setUp() {
- root = xtext.root();
nodes = xtext.getInstanceOf(INodes.class);
}
@@ -45,7 +40,7 @@
// optional bool active = 1;
// }
@Test public void should_return_first_node_for_feature() {
- Property active = findProperty(name("active"), in(root));
+ Property active = xtext.find("active", Property.class);
INode node = nodes.firstNodeForFeature(active, FIELD__NAME);
assertThat(node.getText().trim(), equalTo("active"));
}
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 69cf8f6..7bb8e3d 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
@@ -10,9 +10,6 @@
import static com.google.eclipse.protobuf.junit.core.Setups.unitTestSetup;
import static com.google.eclipse.protobuf.junit.core.XtextRule.createWith;
-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;
@@ -30,11 +27,9 @@
@Rule public XtextRule xtext = createWith(unitTestSetup());
- private Protobuf root;
private Properties properties;
@Before public void setUp() {
- root = xtext.root();
properties = xtext.getInstanceOf(Properties.class);
}
@@ -42,7 +37,7 @@
// optional bool active = 1;
// }
@Test public void should_return_true_if_property_is_bool() {
- Property active = findProperty(name("active"), in(root));
+ Property active = xtext.find("active", Property.class);
assertThat(properties.isBool(active), equalTo(true));
}
@@ -50,7 +45,7 @@
// optional string name = 1;
// }
@Test public void should_return_false_if_property_is_not_bool() {
- Property name = findProperty(name("name"), in(root));
+ Property name = xtext.find("name", Property.class);
assertThat(properties.isBool(name), equalTo(false));
}
}
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 3f4ef6b..0c7cd73 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
@@ -10,7 +10,7 @@
import static com.google.eclipse.protobuf.junit.core.Setups.unitTestSetup;
import static com.google.eclipse.protobuf.junit.core.XtextRule.createWith;
-import static com.google.eclipse.protobuf.junit.model.find.PropertyFinder.allPropertiesIn;
+import static org.eclipse.xtext.EcoreUtil2.getAllContentsOfType;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertThat;
@@ -28,11 +28,9 @@
@Rule public XtextRule xtext = createWith(unitTestSetup());
- private Protobuf root;
private Properties properties;
@Before public void setUp() {
- root = xtext.root();
properties = xtext.getInstanceOf(Properties.class);
}
@@ -49,7 +47,7 @@
// optional bool bool_1 = 10;
// }
@Test public void should_return_true_if_property_is_primitive() {
- for (Property p : allPropertiesIn(root))
+ for (Property p : getAllContentsOfType(xtext.root(), Property.class))
assertThat(properties.isPrimitive(p), equalTo(true));
}
@@ -63,7 +61,7 @@
// optional string name = 1;
// }
@Test public void should_return_false_if_property_is_not_primitive() {
- for (Property p : allPropertiesIn(root))
+ for (Property p : getAllContentsOfType(xtext.root(), Property.class))
assertThat(properties.isPrimitive(p), equalTo(false));
}
}
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 ee51bde..4086f33 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
@@ -10,9 +10,6 @@
import static com.google.eclipse.protobuf.junit.core.Setups.unitTestSetup;
import static com.google.eclipse.protobuf.junit.core.XtextRule.createWith;
-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;
@@ -30,11 +27,9 @@
@Rule public XtextRule xtext = createWith(unitTestSetup());
- private Protobuf root;
private Properties properties;
@Before public void setUp() {
- root = xtext.root();
properties = xtext.getInstanceOf(Properties.class);
}
@@ -42,7 +37,7 @@
// optional string name = 1;
// }
@Test public void should_return_true_if_property_is_string() {
- Property name = findProperty(name("name"), in(root));
+ Property name = xtext.find("name", Property.class);
assertThat(properties.isString(name), equalTo(true));
}
@@ -50,7 +45,7 @@
// optional bool active = 1;
// }
@Test public void should_return_false_if_property_is_not_string() {
- Property active = findProperty(name("active"), in(root));
+ Property active = xtext.find("active", Property.class);
assertThat(properties.isString(active), equalTo(false));
}
}
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 5b36387..def0447 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
@@ -10,9 +10,6 @@
import static com.google.eclipse.protobuf.junit.core.Setups.unitTestSetup;
import static com.google.eclipse.protobuf.junit.core.XtextRule.createWith;
-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;
@@ -30,11 +27,9 @@
@Rule public XtextRule xtext = createWith(unitTestSetup());
- private Protobuf root;
private Properties properties;
@Before public void setUp() {
- root = xtext.root();
properties = xtext.getInstanceOf(Properties.class);
}
@@ -42,7 +37,7 @@
// optional string name = 1;
// }
@Test public void should_return_name_of_scalar() {
- Property name = findProperty(name("name"), in(root));
+ Property name = xtext.find("name", Property.class);
assertThat(properties.typeNameOf(name), equalTo("string"));
}
@@ -55,8 +50,7 @@
// }
// }
@Test public void should_return_name_of_type() {
- Property number = findProperty(name("number"), in(root));
+ Property number = xtext.find("number", Property.class);
assertThat(properties.typeNameOf(number), equalTo("PhoneNumber"));
}
-
}
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 c45494b..70a0fe2 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
@@ -10,10 +10,6 @@
import static com.google.eclipse.protobuf.junit.core.Setups.unitTestSetup;
import static com.google.eclipse.protobuf.junit.core.XtextRule.createWith;
-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;
@@ -32,11 +28,9 @@
@Rule public XtextRule xtext = createWith(unitTestSetup());
- private Protobuf root;
private ProtobufQualifiedNameProvider provider;
@Before public void setUp() {
- root = xtext.root();
provider = (ProtobufQualifiedNameProvider) xtext.getInstanceOf(IQualifiedNameProvider.class);
}
@@ -46,7 +40,7 @@
// optional string name = 1;
// }
@Test public void should_include_existing_package_name_as_part_of_message_FQN() {
- Message person = findMessage(name("Person"), in(root));
+ Message person = xtext.find("Person", Message.class);
QualifiedName fqn = provider.getFullyQualifiedName(person);
assertThat(fqn.toString(), equalTo("fqn.test.Person"));
}
@@ -57,7 +51,7 @@
// optional string name = 1;
// }
@Test public void should_include_existing_package_name_as_part_of_property_FQN() {
- Property name = findProperty(name("name"), in(root));
+ Property name = xtext.find("name", Property.class);
QualifiedName fqn = provider.getFullyQualifiedName(name);
assertThat(fqn.toString(), equalTo("fqn.test.Person.name"));
}
@@ -66,7 +60,7 @@
// optional string name = 1;
// }
@Test public void should_not_include_package_name_as_part_of_message_FQN_if_package_is_not_specified() {
- Message person = findMessage(name("Person"), in(root));
+ Message person = xtext.find("Person", Message.class);
QualifiedName fqn = provider.getFullyQualifiedName(person);
assertThat(fqn.toString(), equalTo("Person"));
}
@@ -75,7 +69,7 @@
// optional string name = 1;
// }
@Test public void should_not_include_package_name_as_part_of_property_FQN_if_package_is_not_specified() {
- Property name = findProperty(name("name"), in(root));
+ Property name = xtext.find("name", Property.class);
QualifiedName fqn = provider.getFullyQualifiedName(name);
assertThat(fqn.toString(), equalTo("Person.name"));
}
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 b5d5a62..da7d7ee 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
@@ -10,14 +10,10 @@
import static com.google.eclipse.protobuf.junit.core.Setups.unitTestSetup;
import static com.google.eclipse.protobuf.junit.core.XtextRule.createWith;
-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;
import com.google.eclipse.protobuf.junit.core.XtextRule;
-import com.google.eclipse.protobuf.protobuf.*;
import com.google.eclipse.protobuf.protobuf.Enum;
import org.eclipse.emf.ecore.EObject;
@@ -35,20 +31,16 @@
@Rule public XtextRule xtext = createWith(unitTestSetup());
- private Protobuf root;
private LocalNamesProvider namesProvider;
@Before public void setUp() {
- root = xtext.root();
namesProvider = xtext.getInstanceOf(LocalNamesProvider.class);
}
// package test.alternative.names;
- //
// message Person {
// message PhoneNumber {
// optional PhoneType type = 1 [default = HOME];
- //
// enum PhoneType {
// HOME = 0;
// WORK = 1;
@@ -56,7 +48,7 @@
// }
// }
@Test public void should_return_all_possible_local_names() {
- Enum phoneType = findEnum(name("PhoneType"), in(root));
+ Enum phoneType = xtext.find("PhoneType", " {", Enum.class);
List<QualifiedName> names = namesProvider.namesOf(phoneType);
assertThat(names.get(0).toString(), equalTo("PhoneType"));
assertThat(names.get(1).toString(), equalTo("PhoneNumber.PhoneType"));
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/validation/ProtobufJavaValidator_checkOnlyOnePackageDefinition_Test.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/validation/ProtobufJavaValidator_checkOnlyOnePackageDefinition_Test.java
index df0368f..90dee78 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/validation/ProtobufJavaValidator_checkOnlyOnePackageDefinition_Test.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/validation/ProtobufJavaValidator_checkOnlyOnePackageDefinition_Test.java
@@ -10,16 +10,12 @@
import static com.google.eclipse.protobuf.junit.core.Setups.unitTestSetup;
import static com.google.eclipse.protobuf.junit.core.XtextRule.createWith;
-import static com.google.eclipse.protobuf.junit.model.find.Name.name;
-import static com.google.eclipse.protobuf.junit.model.find.PackageFinder.findPackage;
-import static com.google.eclipse.protobuf.junit.model.find.Root.in;
import static com.google.eclipse.protobuf.protobuf.ProtobufPackage.Literals.PACKAGE__NAME;
import static com.google.eclipse.protobuf.validation.ProtobufJavaValidator.MORE_THAN_ONE_PACKAGE_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.protobuf.*;
import com.google.eclipse.protobuf.protobuf.Package;
import org.eclipse.xtext.validation.ValidationMessageAcceptor;
@@ -34,12 +30,10 @@
@Rule public XtextRule xtext = createWith(unitTestSetup());
- private Protobuf root;
private ValidationMessageAcceptor messageAcceptor;
private ProtobufJavaValidator validator;
@Before public void setUp() {
- root = xtext.root();
messageAcceptor = mock(ValidationMessageAcceptor.class);
validator = xtext.getInstanceOf(ProtobufJavaValidator.class);
validator.setMessageAcceptor(messageAcceptor);
@@ -48,7 +42,7 @@
// package com.google.protobuf;
// package com.google.eclipse;
@Test public void should_create_error_if_there_are_more_than_one_package_definitions() {
- Package p = findPackage(name("com.google.eclipse"), in(root));
+ Package p = xtext.find("com.google.eclipse", Package.class);
validator.checkOnlyOnePackageDefinition(p);
String message = "Multiple package definitions.";
verify(messageAcceptor).acceptError(message, p, PACKAGE__NAME, INSIGNIFICANT_INDEX, MORE_THAN_ONE_PACKAGE_ERROR);
@@ -56,7 +50,7 @@
// package com.google.eclipse;
@Test public void should_not_create_error_if_there_is_only_one_package_definition() {
- Package p = findPackage(name("com.google.eclipse"), in(root));
+ Package p = xtext.find("com.google.eclipse", Package.class);
validator.checkOnlyOnePackageDefinition(p);
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
index 732dc18..af422e1 100644
--- 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
@@ -10,9 +10,6 @@
import static com.google.eclipse.protobuf.junit.core.Setups.unitTestSetup;
import static com.google.eclipse.protobuf.junit.core.XtextRule.createWith;
-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;
@@ -33,12 +30,10 @@
@Rule public XtextRule xtext = createWith(unitTestSetup());
- private Protobuf root;
private ValidationMessageAcceptor messageAcceptor;
private ProtobufJavaValidator validator;
@Before public void setUp() {
- root = xtext.root();
messageAcceptor = mock(ValidationMessageAcceptor.class);
validator = xtext.getInstanceOf(ProtobufJavaValidator.class);
validator.setMessageAcceptor(messageAcceptor);
@@ -48,28 +43,28 @@
// optional long id = 0;
// }
@Test public void should_create_error_if_field_index_is_zero() {
- Property p = findProperty(name("id"), in(root));
- validator.checkTagNumberIsGreaterThanZero(p);
+ Property id = xtext.find("id", Property.class);
+ validator.checkTagNumberIsGreaterThanZero(id);
String message = "Field numbers must be positive integers.";
- verify(messageAcceptor).acceptError(message, p, FIELD__INDEX, INSIGNIFICANT_INDEX, INVALID_FIELD_TAG_NUMBER_ERROR);
+ verify(messageAcceptor).acceptError(message, id, FIELD__INDEX, INSIGNIFICANT_INDEX, INVALID_FIELD_TAG_NUMBER_ERROR);
}
// message Person {
// optional long id = -1;
// }
@Test public void should_create_error_if_field_index_is_negative() {
- Property p = findProperty(name("id"), in(root));
- validator.checkTagNumberIsGreaterThanZero(p);
+ Property id = xtext.find("id", Property.class);
+ validator.checkTagNumberIsGreaterThanZero(id);
String message = "Expected field number.";
- verify(messageAcceptor).acceptError(message, p, FIELD__INDEX, INSIGNIFICANT_INDEX, INVALID_FIELD_TAG_NUMBER_ERROR);
+ verify(messageAcceptor).acceptError(message, id, FIELD__INDEX, INSIGNIFICANT_INDEX, INVALID_FIELD_TAG_NUMBER_ERROR);
}
// message Person {
// optional long id = 1;
// }
@Test public void should_not_create_error_if_field_index_is_greater_than_zero() {
- Property p = findProperty(name("id"), in(root));
- validator.checkTagNumberIsGreaterThanZero(p);
+ Property id = xtext.find("id", Property.class);
+ validator.checkTagNumberIsGreaterThanZero(id);
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
index 5df4839..914be2d 100644
--- 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
@@ -10,9 +10,6 @@
import static com.google.eclipse.protobuf.junit.core.Setups.unitTestSetup;
import static com.google.eclipse.protobuf.junit.core.XtextRule.createWith;
-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;
@@ -33,12 +30,10 @@
@Rule public XtextRule xtext = createWith(unitTestSetup());
- private Protobuf root;
private ValidationMessageAcceptor messageAcceptor;
private ProtobufJavaValidator validator;
@Before public void setUp() {
- root = xtext.root();
messageAcceptor = mock(ValidationMessageAcceptor.class);
validator = xtext.getInstanceOf(ProtobufJavaValidator.class);
validator.setMessageAcceptor(messageAcceptor);
@@ -49,10 +44,10 @@
// optional string name = 1;
// }
@Test public void should_create_error_if_field_does_not_have_unique_tag_number() {
- Property p = findProperty(name("name"), in(root));
- validator.checkTagNumberIsUnique(p);
+ Property name = xtext.find("name", Property.class);
+ validator.checkTagNumberIsUnique(name);
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);
+ verify(messageAcceptor).acceptError(message, name, FIELD__INDEX, INSIGNIFICANT_INDEX, INVALID_FIELD_TAG_NUMBER_ERROR);
}
// message Person {
@@ -60,8 +55,8 @@
// optional string name = 2;
// }
@Test public void should_not_create_error_if_field_has_unique_tag_number() {
- Property p = findProperty(name("name"), in(root));
- validator.checkTagNumberIsUnique(p);
+ Property name = xtext.find("name", Property.class);
+ validator.checkTagNumberIsUnique(name);
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 c679d8d..56cb222 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
@@ -10,9 +10,6 @@
import static com.google.eclipse.protobuf.junit.core.Setups.unitTestSetup;
import static com.google.eclipse.protobuf.junit.core.XtextRule.createWith;
-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;
@@ -36,11 +33,9 @@
@Rule public XtextRule xtext = createWith(unitTestSetup());
- private Protobuf root;
private CommentNodesFinder finder;
@Before public void setUp() {
- root = xtext.root();
finder = xtext.getInstanceOf(CommentNodesFinder.class);
}
@@ -49,7 +44,7 @@
// optional bool active = 1;
// }
@Test public void should_return_matching_single_line_comment_of_element() {
- Property active = findProperty(name("active"), in(root));
+ Property active = xtext.find("active", Property.class);
Pair<INode, Matcher> match = finder.matchingCommentNode(active, "next id: [\\d]+");
INode node = match.getFirst();
assertThat(node.getText().trim(), equalTo("// Next Id: 6"));
@@ -62,7 +57,7 @@
// optional bool active = 1;
// }
@Test public void should_return_matching_multi_line_comment_of_element() {
- Property active = findProperty(name("active"), in(root));
+ Property active = xtext.find("active", Property.class);
Pair<INode, Matcher> match = finder.matchingCommentNode(active, "NEXT ID: [\\d]+");
INode node = match.getFirst();
assertThat(node, notNullValue());
@@ -73,7 +68,7 @@
// optional bool active = 1;
// }
@Test public void should_return_null_if_no_matching_node_found() {
- Property active = findProperty(name("active"), in(root));
+ Property active = xtext.find("active", Property.class);
Pair<INode, Matcher> match = finder.matchingCommentNode(active, "Hello");
assertThat(match, nullValue());
}
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 74d5b2a..0fdd4c2 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
@@ -10,9 +10,6 @@
import static com.google.eclipse.protobuf.junit.core.Setups.unitTestSetup;
import static com.google.eclipse.protobuf.junit.core.XtextRule.createWith;
-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;
@@ -31,11 +28,9 @@
@Rule public XtextRule xtext = createWith(unitTestSetup());
- private Protobuf root;
private SingleLineCommentDocumentationProvider provider;
@Before public void setUp() {
- root = xtext.root();
provider = xtext.getInstanceOf(SingleLineCommentDocumentationProvider.class);
}
@@ -44,7 +39,7 @@
// optional bool active = 1;
// }
@Test public void should_return_single_line_comment_of_element() {
- Property active = findProperty(name("active"), in(root));
+ Property active = xtext.find("active", Property.class);
String documentation = provider.getDocumentation(active);
assertThat(documentation, equalTo("Indicates whether the person is active or not."));
}
@@ -53,7 +48,7 @@
// optional bool active = 1;
// }
@Test public void should_return_empty_String_if_element_does_not_have_single_line_comment() {
- Property active = findProperty(name("active"), in(root));
+ Property active = xtext.find("active", Property.class);
String documentation = provider.getDocumentation(active);
assertThat(documentation, equalTo(""));
}
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 2dd366c..e8e2bce 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
@@ -10,9 +10,6 @@
import static com.google.eclipse.protobuf.junit.core.Setups.unitTestSetup;
import static com.google.eclipse.protobuf.junit.core.XtextRule.createWith;
-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;
@@ -30,11 +27,9 @@
@Rule public XtextRule xtext = createWith(unitTestSetup());
- private Protobuf root;
private Fields fields;
@Before public void setUp() {
- root = xtext.root();
fields = xtext.getInstanceOf(Fields.class);
}
@@ -42,7 +37,7 @@
// required string name = 2;
// }
@Test public void should_return_one_for_first_and_only_property() {
- Property name = findProperty(name("name"), in(root));
+ Property name = xtext.find("name", Property.class);
long index = fields.calculateTagNumberOf(name);
assertThat(index, equalTo(1L));
}
@@ -52,7 +47,7 @@
// required int32 id = 8;
// }
@Test public void should_return_max_tag_number_value_plus_one_for_new_property() {
- Property id = findProperty(name("id"), in(root));
+ Property id = xtext.find("id", Property.class);
long index = fields.calculateTagNumberOf(id);
assertThat(index, equalTo(7L));
}
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 0d87374..dbc766b 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
@@ -10,9 +10,6 @@
import static com.google.eclipse.protobuf.junit.core.Setups.unitTestSetup;
import static com.google.eclipse.protobuf.junit.core.XtextRule.createWith;
-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;
@@ -30,11 +27,9 @@
@Rule public XtextRule xtext = createWith(unitTestSetup());
- private Protobuf root;
private Literals literals;
@Before public void setUp() {
- root = xtext.root();
literals = xtext.getInstanceOf(Literals.class);
}
@@ -42,7 +37,7 @@
// MOBILE = 1;
// }
@Test public void should_return_zero_for_first_and_only_literal() {
- Literal mobile = findLiteral(name("MOBILE"), in(root));
+ Literal mobile = xtext.find("MOBILE", Literal.class);
long index = literals.calculateIndexOf(mobile);
assertThat(index, equalTo(0L));
}
@@ -53,7 +48,7 @@
// WORK = 9;
// }
@Test public void should_return_max_index_value_plus_one_for_new_literal() {
- Literal work = findLiteral(name("WORK"), in(root));
+ Literal work = xtext.find("WORK", Literal.class);
long index = literals.calculateIndexOf(work);
assertThat(index, equalTo(6L));
}