Allow "reserved" within a group.
Change-Id: Icd620b8325237976a2f09c182f961818af0894bc
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/validation/ProtobufJavaValidator_checkForIndexConflicts_Test.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/validation/ProtobufJavaValidator_checkForIndexConflicts_Test.java
index 2732377..195f33f 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/validation/ProtobufJavaValidator_checkForIndexConflicts_Test.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/validation/ProtobufJavaValidator_checkForIndexConflicts_Test.java
@@ -224,4 +224,34 @@
private void verifyError(String message, EObject errorSource, EStructuralFeature errorFeature) {
verify(messageAcceptor).acceptError(message, errorSource, errorFeature, -1, null);
}
+
+ // syntax = "proto2";
+ //
+ // message Person {
+ // group foo = 10 {
+ // reserved 1 to 3;
+ // optional bool in_same_group = 1;
+ // }
+ // optional bool outside_group = 2;
+ // group bar = 20 {
+ // optional bool in_other_group = 3;
+ // }
+ // }
+ @Test public void should_error_on_conflict_with_reserved_in_group() {
+ validator.checkForIndexConflicts(xtext.findFirst(Message.class));
+ List<MessageField> messageFields = xtext.findAll(MessageField.class);
+ verifyError(
+ "Tag number 1 conflicts with reserved 1 to 3.",
+ messageFields.get(0),
+ ProtobufPackage.Literals.MESSAGE_FIELD__INDEX);
+ verifyError(
+ "Tag number 2 conflicts with reserved 1 to 3.",
+ messageFields.get(1),
+ ProtobufPackage.Literals.MESSAGE_FIELD__INDEX);
+ verifyError(
+ "Tag number 3 conflicts with reserved 1 to 3.",
+ messageFields.get(2),
+ ProtobufPackage.Literals.MESSAGE_FIELD__INDEX);
+ verifyNoMoreInteractions(messageAcceptor);
+ }
}
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/validation/ProtobufJavaValidator_checkForReservedNameConflicts_Test.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/validation/ProtobufJavaValidator_checkForReservedNameConflicts_Test.java
index 074c5ea..c934b8a 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/validation/ProtobufJavaValidator_checkForReservedNameConflicts_Test.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/validation/ProtobufJavaValidator_checkForReservedNameConflicts_Test.java
@@ -10,6 +10,7 @@
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.verifyZeroInteractions;
import static com.google.eclipse.protobuf.junit.core.UnitTestModule.unitTestModule;
import static com.google.eclipse.protobuf.junit.core.XtextRule.overrideRuntimeModuleWith;
@@ -98,6 +99,36 @@
verifyZeroInteractions(messageAcceptor);
}
+ // syntax = "proto2";
+ //
+ // message Person {
+ // group foo = 10 {
+ // reserved "in_same_group", "outside_group", "in_other_group";
+ // optional bool in_same_group = 1;
+ // }
+ // optional bool outside_group = 2;
+ // group bar = 20 {
+ // optional bool in_other_group = 3;
+ // }
+ // }
+ @Test public void should_error_on_conflict_with_reserved_in_group() {
+ validator.checkForReservedNameConflicts(xtext.findFirst(Message.class));
+ List<MessageField> messageFields = xtext.findAll(MessageField.class);
+ verifyError(
+ "Name \"in_same_group\" conflicts with reserved \"in_same_group\".",
+ messageFields.get(0),
+ ProtobufPackage.Literals.MESSAGE_FIELD__NAME);
+ verifyError(
+ "Name \"outside_group\" conflicts with reserved \"outside_group\".",
+ messageFields.get(1),
+ ProtobufPackage.Literals.MESSAGE_FIELD__NAME);
+ verifyError(
+ "Name \"in_other_group\" conflicts with reserved \"in_other_group\".",
+ messageFields.get(2),
+ ProtobufPackage.Literals.MESSAGE_FIELD__NAME);
+ verifyNoMoreInteractions(messageAcceptor);
+ }
+
private void verifyError(String message, EObject errorSource) {
verifyError(message, errorSource, null);
}
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/Protobuf.xtext b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/Protobuf.xtext
index 05242a4..1017681 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/Protobuf.xtext
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/Protobuf.xtext
@@ -73,7 +73,7 @@
'}' (';')?;
GroupElement:
- =>Option | MessageField | ComplexType | TypeExtension | Extensions;
+ =>Option | MessageField | ComplexType | TypeExtension | Extensions | Reserved;
OneOf:
(isRepeated?='repeated')? =>'oneof' name=Name '{'