12
12
import com .intellij .lang .jsgraphql .psi .GraphQLVisitor ;
13
13
import com .jetbrains .php .lang .psi .elements .PhpClass ;
14
14
import com .magento .idea .magento2plugin .bundles .InspectionBundle ;
15
+ import com .magento .idea .magento2plugin .inspections .graphqls .fix .CreateResolverClassQuickFix ;
15
16
import com .magento .idea .magento2plugin .util .GetPhpClassByFQN ;
16
17
import com .magento .idea .magento2plugin .util .magento .graphql .GraphQlUtil ;
17
18
import org .jetbrains .annotations .NotNull ;
@@ -22,32 +23,39 @@ public class SchemaResolverInspection extends LocalInspectionTool {
22
23
23
24
@ NotNull
24
25
@ Override
25
- public GraphQLVisitor buildVisitor (@ NotNull final ProblemsHolder holder , boolean isOnTheFly ) {
26
+ public GraphQLVisitor buildVisitor (
27
+ @ NotNull final ProblemsHolder holder ,
28
+ final boolean isOnTheFly
29
+ ) {
26
30
return new GraphQLVisitor () {
27
31
@ Override
28
- public void visitValue (@ NotNull GraphQLValue element ) {
29
- String getVisitedElementValue = element .getText ();
32
+ public void visitValue (@ NotNull final GraphQLValue element ) {
33
+ final String getVisitedElementValue = element .getText ();
30
34
if (getVisitedElementValue == null ) {
31
35
return ;
32
36
}
33
37
34
- String resolverFQN = GraphQlUtil .resolverStringToPhpFQN (getVisitedElementValue );
35
- GetPhpClassByFQN getPhpClassByFQN = GetPhpClassByFQN .getInstance (holder .getProject ());
36
- PhpClass resolverClass = getPhpClassByFQN .execute (resolverFQN );
38
+ final String resolverFQN
39
+ = GraphQlUtil .resolverStringToPhpFQN (getVisitedElementValue );
40
+ final GetPhpClassByFQN getPhpClassByFQN
41
+ = GetPhpClassByFQN .getInstance (holder .getProject ());
42
+ final PhpClass resolverClass = getPhpClassByFQN .execute (resolverFQN );
37
43
if (resolverClass == null ) {
38
- holder .registerProblem (element ,
39
- inspectionBundle .message (
40
- "inspection.graphql.resolver.notExist"
41
- ),
42
- ProblemHighlightType .ERROR );
43
- return ;
44
- }
45
- if (!GraphQlUtil .isResolver (resolverClass )) {
46
- holder .registerProblem (element ,
47
- inspectionBundle .message (
48
- "inspection.graphql.resolver.mustImplement"
49
- ),
50
- ProblemHighlightType .ERROR );
44
+ holder .registerProblem (
45
+ element ,
46
+ inspectionBundle .message (
47
+ "inspection.graphql.resolver.notExist"
48
+ ),
49
+ ProblemHighlightType .ERROR ,
50
+ new CreateResolverClassQuickFix ());
51
+ } else if (!GraphQlUtil .isResolver (resolverClass )) {
52
+ holder .registerProblem (
53
+ element ,
54
+ inspectionBundle .message (
55
+ "inspection.graphql.resolver.mustImplement"
56
+ ),
57
+ ProblemHighlightType .ERROR
58
+ );
51
59
}
52
60
}
53
61
};
0 commit comments