8
8
import com .intellij .codeInspection .LocalInspectionTool ;
9
9
import com .intellij .codeInspection .ProblemHighlightType ;
10
10
import com .intellij .codeInspection .ProblemsHolder ;
11
+ import com .intellij .lang .jsgraphql .psi .GraphQLNamedElement ;
11
12
import com .intellij .lang .jsgraphql .psi .GraphQLValue ;
12
13
import com .intellij .lang .jsgraphql .psi .GraphQLVisitor ;
14
+ import com .intellij .psi .PsiElement ;
13
15
import com .jetbrains .php .lang .psi .elements .PhpClass ;
14
16
import com .magento .idea .magento2plugin .bundles .InspectionBundle ;
15
17
import com .magento .idea .magento2plugin .inspections .graphqls .fix .CreateResolverClassQuickFix ;
18
+ import com .magento .idea .magento2plugin .magento .files .GraphQlResolver ;
16
19
import com .magento .idea .magento2plugin .util .GetPhpClassByFQN ;
20
+ import com .magento .idea .magento2plugin .util .RegExUtil ;
17
21
import com .magento .idea .magento2plugin .util .magento .graphql .GraphQlUtil ;
18
22
import org .jetbrains .annotations .NotNull ;
19
23
@@ -31,20 +35,41 @@ public GraphQLVisitor buildVisitor(
31
35
@ Override
32
36
public void visitValue (@ NotNull final GraphQLValue element ) {
33
37
final String getVisitedElementValue = element .getText ();
34
- if (getVisitedElementValue == null ) {
38
+ final PsiElement parentElementValue = element .getParent ();
39
+ if (getVisitedElementValue == null
40
+ || !(parentElementValue instanceof GraphQLNamedElement )) {
41
+ return ;
42
+ }
43
+
44
+ final String attributeName = ((GraphQLNamedElement ) parentElementValue ).getName ();
45
+ if (!GraphQlResolver .CLASS_ARGUMENT .equals (attributeName )) {
35
46
return ;
36
47
}
37
48
38
49
final String resolverFQN
39
50
= GraphQlUtil .resolverStringToPhpFQN (getVisitedElementValue );
51
+ if (!resolverFQN .matches (RegExUtil .PhpRegex .FQN )) {
52
+ holder .registerProblem (
53
+ element ,
54
+ inspectionBundle .message (
55
+ "inspection.warning.class.invalidFormat" ,
56
+ resolverFQN
57
+ ),
58
+ ProblemHighlightType .WARNING
59
+ );
60
+
61
+ return ;
62
+ }
63
+
40
64
final GetPhpClassByFQN getPhpClassByFQN
41
65
= GetPhpClassByFQN .getInstance (holder .getProject ());
42
66
final PhpClass resolverClass = getPhpClassByFQN .execute (resolverFQN );
67
+
43
68
if (resolverClass == null ) {
44
69
holder .registerProblem (
45
70
element ,
46
71
inspectionBundle .message (
47
- "inspection.graphql.resolver.notExist"
72
+ "inspection.graphql.resolver.notExist"
48
73
),
49
74
ProblemHighlightType .ERROR ,
50
75
new CreateResolverClassQuickFix ());
0 commit comments