|
| 1 | +/* |
| 2 | + * Copyright © Magento, Inc. All rights reserved. |
| 3 | + * See COPYING.txt for license details. |
| 4 | + */ |
| 5 | + |
| 6 | +package com.magento.idea.magento2plugin.inspections.graphqls; |
| 7 | + |
| 8 | +import com.intellij.codeInspection.LocalInspectionTool; |
| 9 | +import com.intellij.codeInspection.ProblemHighlightType; |
| 10 | +import com.intellij.codeInspection.ProblemsHolder; |
| 11 | +import com.intellij.lang.jsgraphql.psi.GraphQLValue; |
| 12 | +import com.intellij.lang.jsgraphql.psi.GraphQLVisitor; |
| 13 | +import com.jetbrains.php.lang.psi.elements.PhpClass; |
| 14 | +import com.magento.idea.magento2plugin.bundles.InspectionBundle; |
| 15 | +import com.magento.idea.magento2plugin.util.GetPhpClassByFQN; |
| 16 | +import com.magento.idea.magento2plugin.util.magento.graphql.GraphQlUtil; |
| 17 | +import org.jetbrains.annotations.NotNull; |
| 18 | + |
| 19 | +public class SchemaResolverInspection extends LocalInspectionTool { |
| 20 | + |
| 21 | + private final InspectionBundle inspectionBundle = new InspectionBundle(); |
| 22 | + |
| 23 | + @NotNull |
| 24 | + @Override |
| 25 | + public GraphQLVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly) { |
| 26 | + return new GraphQLVisitor() { |
| 27 | + @Override |
| 28 | + public void visitValue(@NotNull GraphQLValue element) { |
| 29 | + String getVisitedElementValue = element.getText(); |
| 30 | + if (getVisitedElementValue == null) { |
| 31 | + return; |
| 32 | + } |
| 33 | + |
| 34 | + String resolverFQN = GraphQlUtil.resolverStringToPhpFQN(getVisitedElementValue); |
| 35 | + GetPhpClassByFQN getPhpClassByFQN = GetPhpClassByFQN.getInstance(holder.getProject()); |
| 36 | + PhpClass resolverClass = getPhpClassByFQN.execute(resolverFQN); |
| 37 | + 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); |
| 51 | + } |
| 52 | + } |
| 53 | + }; |
| 54 | + } |
| 55 | +} |
0 commit comments