Skip to content

Commit f9b1120

Browse files
#39: Validate groups for proto3 (illegal)
1 parent 118ea23 commit f9b1120

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-1
lines changed

src/main/java/io/protostuff/jetbrains/plugin/annotator/ProtoErrorsAnnotator.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import io.protostuff.jetbrains.plugin.psi.EnumNode;
1616
import io.protostuff.jetbrains.plugin.psi.FieldLabel;
1717
import io.protostuff.jetbrains.plugin.psi.FieldNode;
18+
import io.protostuff.jetbrains.plugin.psi.GroupNode;
1819
import io.protostuff.jetbrains.plugin.psi.MessageField;
1920
import io.protostuff.jetbrains.plugin.psi.MessageNode;
2021
import io.protostuff.jetbrains.plugin.psi.OptionNode;
@@ -64,6 +65,8 @@ public void annotate(@NotNull PsiElement element, @NotNull AnnotationHolder hold
6465
checkDuplicateFieldNames(fields);
6566
checkReservedFieldTags(message, fields);
6667
checkReservedFieldNames(message, fields);
68+
} else if (element instanceof GroupNode) {
69+
checkGroupNodeDeprecated((GroupNode)element, syntax);
6770
} else if (element instanceof FieldNode) {
6871
FieldNode field = (FieldNode) element;
6972
checkFieldLabel(field, syntax);
@@ -84,6 +87,14 @@ public void annotate(@NotNull PsiElement element, @NotNull AnnotationHolder hold
8487
}
8588
}
8689

90+
private void checkGroupNodeDeprecated(GroupNode element, Syntax syntax) {
91+
if (syntax != Syntax.PROTO3) {
92+
return;
93+
}
94+
String message = message("error.groups.not.supported");
95+
markError(element.getNode(), null, message);
96+
}
97+
8798
private void checkDefaultValue(@NotNull OptionNode option, Syntax syntax) {
8899
if (syntax != Syntax.PROTO3) {
89100
return;

src/main/resources/io/protostuff/protobuf-jetbrains-plugin/messages/ProtostuffBundle.properties

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ action.disable.conflicting.plugins=We detected that you have other plugins for \
1010
</ul>\
1111
<p>It might lead to stability issues.\
1212
<p><p>Please <a href="disable">disable other plugins and restart IDE</a>.
13+
14+
element.context.display={0} in {1}
15+
1316
error.invalid.tag.not.in.range=Invalid tag: {0}, allowed range is [{1} ... {2}) and ({3} ... {4}]
1417
error.duplicate.field.tag=Duplicate field tag: {0}
1518
error.duplicate.field.name=Duplicate field name: {0}
@@ -20,5 +23,5 @@ error.duplicate.constant.value=Duplicate constant value: {0}
2023
error.duplicate.method.name=Duplicate RPC method name: {0}
2124
error.missing.field.label=Missing field label
2225
error.illegal.field.label=Field label "{0}" is not allowed in proto3
23-
element.context.display={0} in {1}
2426
error.default.value.not.supported=Default values are not supported in proto3
27+
error.groups.not.supported=Groups are not supported in proto3

src/test/java/io/protostuff/jetbrains/plugin/annotator/ProtoErrorsAnnotatorTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ public void testProto3IllegalDefaultValueOption() {
8282
check();
8383
}
8484

85+
public void testProto3IllegalGroup() {
86+
check();
87+
}
88+
8589
private void check() {
8690
String file = getTestName(false) + ".proto";
8791
myFixture.configureByFiles(file);
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
syntax = "proto3";
2+
3+
package annotator;
4+
5+
message TestMessage {
6+
<error descr="Groups are not supported in proto3">optional group group = 1 {
7+
8+
}</error>
9+
}

0 commit comments

Comments
 (0)