Fixed: [ Issue 84 ] Custom options are being considered syntax errors.
https://code.google.com/p/protobuf-dt/issues/detail?id=84
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 1f4073b..62b0d98 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
@@ -34,8 +34,14 @@
'.'? Name ('.' Name)*;
Option:
+ BuiltInOption | CustomOption;
+
+BuiltInOption:
'option' name=Name '=' value=ValueRef ';';
+CustomOption:
+ 'option' '(' name=QualifiedName ')' '=' value=ValueRef ';';
+
Type:
Message | Enum;
@@ -74,8 +80,14 @@
('[' fieldOptions+=FieldOption (',' fieldOptions+=FieldOption)* ']')? ';';
FieldOption:
+ BuiltInFieldOption | CustomFieldOption;
+
+BuiltInFieldOption:
name=Name '=' value=ValueRef;
+CustomFieldOption:
+ '(' name=QualifiedName ')' '=' value=ValueRef;
+
enum Modifier:
required
| optional
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 d1b15ef..a4eb463 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
@@ -206,7 +206,7 @@
* @param option the given option.
* @return the enum type of the given option or {@code null} if the type of the given option is not enum.
*/
- public Enum enumTypeOf(Option option) {
+ public Enum enumTypeOf(BuiltInOption option) {
String name = option.getName();
return enumTypeOf(lookupOption(name));
}
@@ -218,7 +218,7 @@
* @param option the given option.
* @return the enum type of the given option or {@code null} if the type of the given option is not enum.
*/
- public Enum enumTypeOf(FieldOption option) {
+ public Enum enumTypeOf(BuiltInFieldOption option) {
String name = option.getName();
return enumTypeOf(lookupFieldOption(name));
}
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 a3ebdab..4ca87be 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
@@ -182,9 +182,11 @@
private Enum enumTypeOfOption(EObject mayBeOption) {
ProtoDescriptor descriptor = descriptorProvider.get();
- if (mayBeOption instanceof Option) return descriptor.enumTypeOf((Option) mayBeOption);
- if (mayBeOption instanceof FieldOption) {
- FieldOption option = (FieldOption) mayBeOption;
+ if (mayBeOption instanceof BuiltInOption) {
+ return descriptor.enumTypeOf((BuiltInOption) mayBeOption);
+ }
+ if (mayBeOption instanceof BuiltInFieldOption) {
+ BuiltInFieldOption option = (BuiltInFieldOption) mayBeOption;
if (fieldOptions.isDefaultValueOption(option)) {
Property property = (Property) option.eContainer();
return finder.enumTypeOf(property);