File tree Expand file tree Collapse file tree 5 files changed +52
-2
lines changed
main/java/io/protostuff/jetbrains/plugin/psi
java/io/protostuff/jetbrains/plugin/reference Expand file tree Collapse file tree 5 files changed +52
-2
lines changed Original file line number Diff line number Diff line change @@ -38,6 +38,12 @@ public String getQualifiedName() {
3838 }
3939 return "." + packageName + "." + getName ();
4040 }
41+ if (parent instanceof OneOfNode ) {
42+ OneOfNode oneOfNode = (OneOfNode ) parent ;
43+ MessageNode parentMessage = (MessageNode ) oneOfNode .getParent ();
44+ String parentMessageQualifiedName = parentMessage .getQualifiedName ();
45+ return parentMessageQualifiedName + "." + getName ();
46+ }
4147 if (parent instanceof MessageNode ) {
4248 MessageNode parentMessage = (MessageNode ) parent ;
4349 String parentMessageQualifiedName = parentMessage .getQualifiedName ();
Original file line number Diff line number Diff line change 55import com .intellij .navigation .ItemPresentationProviders ;
66import com .intellij .psi .PsiElement ;
77import com .intellij .util .IncorrectOperationException ;
8- import io .protostuff .compiler .parser .ProtoParser ;
98import java .util .ArrayList ;
109import java .util .Arrays ;
1110import java .util .Collection ;
11+ import java .util .Collections ;
1212import java .util .List ;
1313import java .util .Set ;
1414import java .util .stream .Collectors ;
@@ -51,7 +51,14 @@ public String getNamespace() {
5151
5252 @ Override
5353 public Collection <DataType > getDeclaredDataTypes () {
54- return Arrays .asList (findChildrenByClass (DataType .class ));
54+ List <DataType > types = new ArrayList <>();
55+ DataType [] direct = findChildrenByClass (DataType .class );
56+ Collections .addAll (types , direct );
57+ OneOfNode [] oneOfNodes = findChildrenByClass (OneOfNode .class );
58+ for (OneOfNode oneOfNode : oneOfNodes ) {
59+ Collections .addAll (types , oneOfNode .getDeclaredDataTypes ());
60+ }
61+ return types ;
5562 }
5663
5764 @ Override
Original file line number Diff line number Diff line change @@ -20,4 +20,9 @@ public Collection<MessageField> getFields() {
2020 MessageField [] fields = findChildrenByClass (FieldNode .class );
2121 return Arrays .asList (fields );
2222 }
23+
24+ @ NotNull
25+ public DataType [] getDeclaredDataTypes () {
26+ return findChildrenByClass (DataType .class );
27+ }
2328}
Original file line number Diff line number Diff line change @@ -76,6 +76,15 @@ public void testReferenceInsideOfGroup() {
7676 checkReferenceToDataType (".reference.Message.Group.NestedMessage" , "reference/GroupReference.proto" );
7777 }
7878
79+ /**
80+ * Check that type references work correctly inside of oneof+group block.
81+ *
82+ * https://github.com/protostuff/protobuf-jetbrains-plugin/issues/72
83+ */
84+ public void testReferenceInsideOfOneof () {
85+ checkReferenceToDataType (".reference.Message.Group2.NestedMessage" , "reference/OneofReference.proto" );
86+ }
87+
7988 public void testProtoFileImportsItself () {
8089 // referenced type does not exist, so we expect that it is not resolvable
8190 // the only thing that we check here - is that we do not get StackOverflowError
Original file line number Diff line number Diff line change 1+ syntax = "proto2" ;
2+
3+ package reference ;
4+
5+ message Message {
6+
7+
8+ oneof OneOf {
9+
10+ group Group1 = 1 {
11+ message NestedMessage {
12+ optional Group2.<caret>NestedMessage n = 1;
13+ }
14+ }
15+
16+ group Group2 = 2 {
17+ message NestedMessage {
18+ optional Group1.NestedMessage n = 1 ;
19+ }
20+ }
21+ }
22+
23+ }
You can’t perform that action at this time.
0 commit comments