|
6 | 6 | import com.intellij.psi.PsiElement;
|
7 | 7 | import com.intellij.psi.PsiElementVisitor;
|
8 | 8 | import com.jetbrains.php.lang.PhpLanguage;
|
| 9 | +import com.jetbrains.php.lang.lexer.PhpTokenTypes; |
9 | 10 | import com.jetbrains.php.lang.psi.elements.MethodReference;
|
10 | 11 | import com.jetbrains.php.lang.psi.elements.StringLiteralExpression;
|
11 | 12 | import fr.adrienbrault.idea.symfony2plugin.Symfony2ProjectComponent;
|
|
19 | 20 | import org.jetbrains.annotations.NotNull;
|
20 | 21 | import org.jetbrains.yaml.YAMLLanguage;
|
21 | 22 |
|
| 23 | +import java.util.Arrays; |
| 24 | + |
22 | 25 | /**
|
23 | 26 | * @author Daniel Espendiller <daniel@espendiller.net>
|
24 | 27 | */
|
@@ -50,23 +53,34 @@ public void visitElement(PsiElement element) {
|
50 | 53 | MethodReference methodReference = PsiElementUtils.getMethodReferenceWithFirstStringParameter((StringLiteralExpression) element);
|
51 | 54 | if (methodReference != null && PhpElementsUtil.isMethodReferenceInstanceOf(methodReference, ServiceContainerUtil.SERVICE_GET_SIGNATURES)) {
|
52 | 55 | String serviceName = PhpElementsUtil.getFirstArgumentStringValue(methodReference);
|
53 |
| - if(StringUtils.isNotBlank(serviceName)) { |
54 |
| - if(!hasService(serviceName)) { |
55 |
| - holder.registerProblem(element, INSPECTION_MESSAGE, ProblemHighlightType.GENERIC_ERROR_OR_WARNING); |
56 |
| - } |
| 56 | + if (StringUtils.isNotBlank(serviceName) && !hasService(serviceName)) { |
| 57 | + holder.registerProblem(element, INSPECTION_MESSAGE, ProblemHighlightType.GENERIC_ERROR_OR_WARNING); |
| 58 | + } |
| 59 | + } |
| 60 | + |
| 61 | + // #[Autowire(service: 'foobar')] |
| 62 | + // get leaf element |
| 63 | + PsiElement leafText = Arrays.stream(YamlHelper.getChildrenFix(element)) |
| 64 | + .filter(p -> p.getNode().getElementType() == PhpTokenTypes.STRING_LITERAL_SINGLE_QUOTE || p.getNode().getElementType() == PhpTokenTypes.STRING_LITERAL) |
| 65 | + .findFirst() |
| 66 | + .orElse(null); |
| 67 | + |
| 68 | + if (leafText != null && PhpElementsUtil.getAttributeNamedArgumentStringPattern(ServiceContainerUtil.AUTOWIRE_ATTRIBUTE_CLASS, "service").accepts(leafText)) { |
| 69 | + String serviceName = ((StringLiteralExpression) element).getContents(); |
| 70 | + if (StringUtils.isNotBlank(serviceName) && !hasService(serviceName)) { |
| 71 | + holder.registerProblem(element, INSPECTION_MESSAGE, ProblemHighlightType.GENERIC_ERROR_OR_WARNING); |
57 | 72 | }
|
58 | 73 | }
|
| 74 | + |
59 | 75 | } else if(element.getLanguage() == YAMLLanguage.INSTANCE) {
|
60 | 76 | // yaml
|
61 | 77 |
|
62 |
| - if(YamlElementPatternHelper.getServiceDefinition().accepts(element) && YamlElementPatternHelper.getInsideServiceKeyPattern().accepts(element)) { |
| 78 | + if (YamlElementPatternHelper.getServiceDefinition().accepts(element) && YamlElementPatternHelper.getInsideServiceKeyPattern().accepts(element)) { |
63 | 79 | String serviceName = YamlHelper.trimSpecialSyntaxServiceName(PsiElementUtils.getText(element));
|
64 | 80 |
|
65 | 81 | // dont mark "@", "@?", "@@" escaping and expressions
|
66 |
| - if(serviceName.length() > 2 && !serviceName.startsWith("=") && !serviceName.startsWith("@")) { |
67 |
| - if(!hasService(serviceName)) { |
68 |
| - holder.registerProblem(element, INSPECTION_MESSAGE, ProblemHighlightType.GENERIC_ERROR_OR_WARNING); |
69 |
| - } |
| 82 | + if (serviceName.length() > 2 && !serviceName.startsWith("=") && !serviceName.startsWith("@") && !hasService(serviceName)) { |
| 83 | + holder.registerProblem(element, INSPECTION_MESSAGE, ProblemHighlightType.GENERIC_ERROR_OR_WARNING); |
70 | 84 | }
|
71 | 85 | }
|
72 | 86 | }
|
|
0 commit comments