@@ -38,7 +38,7 @@ public String getDisplayName() {
3838 }
3939
4040 @ Override
41- protected void doCheckFile (@ NotNull GoFile file ,
41+ protected void doCheckFile (@ NotNull final GoFile file ,
4242 @ NotNull final InspectionResult result ) {
4343 new GoRecursiveElementVisitor () {
4444 @ Override
@@ -60,24 +60,21 @@ public void visitLiteralIdentifier(GoLiteralIdentifier identifier) {
6060 boolean hasPackageReference = false ;
6161 boolean hasVarReferences = false ;
6262 for (PsiReference ref : refs ) {
63- if (ref instanceof PackageReference )
64- hasPackageReference = true ;
63+ if (ref instanceof PackageReference ) {
64+ getData ().add (new AddImportFix (identifier ));
65+ }
6566
6667 if (ref instanceof VarOrConstReference )
67- hasVarReferences = true ;
68- }
68+ if (isGlobalVariableIdentifier (identifier ))
69+ getData ().add (new CreateGlobalVariableFix (identifier ));
70+ else
71+ getData ()
72+ .add (new CreateLocalVariableFix (identifier ))
73+ .add (new CreateGlobalVariableFix (identifier ))
74+ .add (new CreateFunctionFix (identifier ))
75+ .add (new CreateClosureFunctionFix (identifier ));
6976
70- if ( hasVarReferences )
71- if ( isGlobalVariableIdentifier (identifier ) )
72- getData ().add (new CreateGlobalVariableFix (identifier ));
73- else
74- getData ()
75- .add (new CreateLocalVariableFix (identifier ))
76- .add (new CreateGlobalVariableFix (identifier ))
77- .add (new CreateFunctionFix (identifier ))
78- .add (new CreateClosureFunctionFix (identifier ));
79- else if ( hasPackageReference )
80- getData ().add (new AddImportFix (identifier ));
77+ }
8178
8279 ((GoPsiElement ) identifier .getParent ()).accept (this );
8380 }
@@ -113,7 +110,7 @@ id, message("warning.unresolved.symbol", id.getText()),
113110
114111 private static boolean isGlobalVariableIdentifier (GoLiteralIdentifier ident ) {
115112 return findParentOfType (ident , GoSelectorExpression .class ) == null &&
116- findParentOfType (ident , GoFunctionDeclaration .class ) == null &&
117- findParentOfType (ident , GoVarDeclarations .class ) != null ;
113+ findParentOfType (ident , GoFunctionDeclaration .class ) == null &&
114+ findParentOfType (ident , GoVarDeclarations .class ) != null ;
118115 }
119116}
0 commit comments