Skip to content

Commit 54b058a

Browse files
authored
Merge pull request #1245 from Haehnchen/feature/missing-class-yaml-named-1239
Provide class existing inspection for class named service #1239
2 parents fd5ed2a + fed03dc commit 54b058a

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

src/main/java/fr/adrienbrault/idea/symfony2plugin/dic/inspection/YamlClassInspection.java

+12-5
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
import fr.adrienbrault.idea.symfony2plugin.util.PhpElementsUtil;
1515
import fr.adrienbrault.idea.symfony2plugin.util.PsiElementUtils;
1616
import fr.adrienbrault.idea.symfony2plugin.util.yaml.YamlHelper;
17+
import org.apache.commons.lang.StringUtils;
1718
import org.jetbrains.annotations.NotNull;
19+
import org.jetbrains.yaml.YAMLTokenTypes;
1820

1921
/**
2022
* Check if class exists
@@ -35,13 +37,18 @@ public PsiElementVisitor buildVisitor(final @NotNull ProblemsHolder holder, bool
3537
return new PsiElementVisitor() {
3638
@Override
3739
public void visitElement(PsiElement psiElement) {
38-
if (!((YamlElementPatternHelper.getSingleLineScalarKey("class", "factory_class").accepts(psiElement) || YamlElementPatternHelper.getParameterClassPattern().accepts(psiElement)) && YamlElementPatternHelper.getInsideServiceKeyPattern().accepts(psiElement))) {
39-
super.visitElement(psiElement);
40-
return;
40+
if ((YamlElementPatternHelper.getSingleLineScalarKey("class", "factory_class").accepts(psiElement) || YamlElementPatternHelper.getParameterClassPattern().accepts(psiElement)) && YamlElementPatternHelper.getInsideServiceKeyPattern().accepts(psiElement)) {
41+
// foobar.foo:
42+
// class: Foobar\Foo
43+
invoke(psiElement, holder);
44+
} else if (psiElement.getNode().getElementType() == YAMLTokenTypes.SCALAR_KEY && YamlElementPatternHelper.getServiceIdKeyValuePattern().accepts(psiElement.getParent())) {
45+
// Foobar\Foo: ~
46+
String text = PsiElementUtils.getText(psiElement);
47+
if (StringUtils.isNotBlank(text) && YamlHelper.isClassServiceId(text) && text.contains("\\")) {
48+
invoke(psiElement, holder);
49+
}
4150
}
4251

43-
invoke(psiElement, holder);
44-
4552
super.visitElement(psiElement);
4653
}
4754
};

src/test/java/fr/adrienbrault/idea/symfony2plugin/tests/dic/inspection/YamlClassInspectionTest.java

+3
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,8 @@ public void testInspectionForClass() {
4040
assertLocalInspectionContains("services.yml", "parameters:\n foo.class: 'Args\\Fo<caret>O'", YamlClassInspection.MESSAGE_WRONG_CASING);
4141
assertLocalInspectionContains("services.yml", "parameters:\n foo.class: \"Args\\Fo<caret>O\"", YamlClassInspection.MESSAGE_WRONG_CASING);
4242
assertLocalInspectionNotContains("services.yml", "parameters:\n foo.class: Args\\Fo<caret>o", YamlClassInspection.MESSAGE_WRONG_CASING);
43+
44+
assertLocalInspectionContains("services.yml", "services:\n Args\\Fo<caret>oBar: ~", YamlClassInspection.MESSAGE_MISSING_CLASS);
45+
assertLocalInspectionNotContains("services.yml", "services:\n foo.class: Args\\Fo<caret>o", YamlClassInspection.MESSAGE_WRONG_CASING);
4346
}
4447
}

0 commit comments

Comments
 (0)