Skip to content

Commit 8706666

Browse files
#39: Validate extensions for proto3 (illegal)
1 parent f9b1120 commit 8706666

File tree

4 files changed

+26
-1
lines changed

4 files changed

+26
-1
lines changed

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import io.protostuff.jetbrains.plugin.psi.AntlrParserRuleNode;
1414
import io.protostuff.jetbrains.plugin.psi.EnumConstantNode;
1515
import io.protostuff.jetbrains.plugin.psi.EnumNode;
16+
import io.protostuff.jetbrains.plugin.psi.ExtendNode;
1617
import io.protostuff.jetbrains.plugin.psi.FieldLabel;
1718
import io.protostuff.jetbrains.plugin.psi.FieldNode;
1819
import io.protostuff.jetbrains.plugin.psi.GroupNode;
@@ -66,7 +67,9 @@ public void annotate(@NotNull PsiElement element, @NotNull AnnotationHolder hold
6667
checkReservedFieldTags(message, fields);
6768
checkReservedFieldNames(message, fields);
6869
} else if (element instanceof GroupNode) {
69-
checkGroupNodeDeprecated((GroupNode)element, syntax);
70+
checkGroupNodeDeprecated((GroupNode) element, syntax);
71+
} else if (element instanceof ExtendNode) {
72+
checkExtendNodeDeprecated((ExtendNode) element, syntax);
7073
} else if (element instanceof FieldNode) {
7174
FieldNode field = (FieldNode) element;
7275
checkFieldLabel(field, syntax);
@@ -87,6 +90,14 @@ public void annotate(@NotNull PsiElement element, @NotNull AnnotationHolder hold
8790
}
8891
}
8992

93+
private void checkExtendNodeDeprecated(ExtendNode element, Syntax syntax) {
94+
if (syntax != Syntax.PROTO3) {
95+
return;
96+
}
97+
String message = message("error.extensions.not.supported");
98+
markError(element.getNode(), null, message);
99+
}
100+
90101
private void checkGroupNodeDeprecated(GroupNode element, Syntax syntax) {
91102
if (syntax != Syntax.PROTO3) {
92103
return;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@ error.missing.field.label=Missing field label
2525
error.illegal.field.label=Field label "{0}" is not allowed in proto3
2626
error.default.value.not.supported=Default values are not supported in proto3
2727
error.groups.not.supported=Groups are not supported in proto3
28+
error.extensions.not.supported=Extensions 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
@@ -86,6 +86,10 @@ public void testProto3IllegalGroup() {
8686
check();
8787
}
8888

89+
public void testProto3IllegalExtend() {
90+
check();
91+
}
92+
8993
private void check() {
9094
String file = getTestName(false) + ".proto";
9195
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+
import "google/protobuf/descriptor.proto";
6+
7+
<error descr="Extensions are not supported in proto3">extend google.protobuf.MessageOptions {
8+
9+
}</error>

0 commit comments

Comments
 (0)