-
-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#1984 support service inside "Autowire" attribute
- Loading branch information
Showing
9 changed files
with
209 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
.../idea/symfony2plugin/dic/container/suggestion/PhpAttributeServiceSuggestionCollector.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package fr.adrienbrault.idea.symfony2plugin.dic.container.suggestion; | ||
|
||
import com.intellij.psi.PsiElement; | ||
import fr.adrienbrault.idea.symfony2plugin.dic.ContainerService; | ||
import fr.adrienbrault.idea.symfony2plugin.dic.container.suggestion.utils.ServiceSuggestionUtil; | ||
import fr.adrienbrault.idea.symfony2plugin.dic.container.util.ServiceContainerUtil; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.Collection; | ||
|
||
/** | ||
* @author Daniel Espendiller <daniel@espendiller.net> | ||
*/ | ||
public class PhpAttributeServiceSuggestionCollector implements ServiceSuggestionCollector { | ||
|
||
@NotNull | ||
public Collection<String> collect(@NotNull PsiElement psiElement, @NotNull Collection<ContainerService> serviceMap) { | ||
return ServiceSuggestionUtil.createSuggestions(ServiceContainerUtil.getPhpAttributeConstructorTypeHint(psiElement), serviceMap); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,6 @@ services: | |
Foo\Bar: | ||
tags: | ||
- { name: yaml_type_tag } | ||
|
||
foo_bar_service: | ||
class: Foo\Bar |
45 changes: 45 additions & 0 deletions
45
.../idea/symfony2plugin/tests/dic/suggestion/PhpAttributeServiceSuggestionCollectorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package fr.adrienbrault.idea.symfony2plugin.tests.dic.suggestion; | ||
|
||
import com.jetbrains.php.lang.psi.PhpPsiElementFactory; | ||
import com.jetbrains.php.lang.psi.elements.StringLiteralExpression; | ||
import fr.adrienbrault.idea.symfony2plugin.dic.container.suggestion.PhpAttributeServiceSuggestionCollector; | ||
import fr.adrienbrault.idea.symfony2plugin.stubs.ContainerCollectionResolver; | ||
import fr.adrienbrault.idea.symfony2plugin.tests.SymfonyLightCodeInsightFixtureTestCase; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
/** | ||
* @author Daniel Espendiller <daniel@espendiller.net> | ||
*/ | ||
public class PhpAttributeServiceSuggestionCollectorTest extends SymfonyLightCodeInsightFixtureTestCase { | ||
public void setUp() throws Exception { | ||
super.setUp(); | ||
myFixture.configureFromExistingVirtualFile(myFixture.copyFileToProject("classes.php")); | ||
myFixture.copyFileToProject("services.yml"); | ||
} | ||
|
||
public String getTestDataPath() { | ||
return "src/test/java/fr/adrienbrault/idea/symfony2plugin/tests/dic/suggestion/fixtures"; | ||
} | ||
|
||
public void testParameterContributor() { | ||
@Nullable StringLiteralExpression stringLiteralExpression = PhpPsiElementFactory.createFromText(getProject(), StringLiteralExpression.class, | ||
"<?php\n" + | ||
"use Symfony\\Component\\DependencyInjection\\Attribute\\Autowire;\n" + | ||
"\n" + | ||
"class HandlerCollection\n" + | ||
"{\n" + | ||
" public function __construct(\n" + | ||
" #[Autowire(service: '<caret>')] \\Foo\\Bar $test\n" + | ||
" ) {}\n" + | ||
"}" | ||
); | ||
|
||
assert stringLiteralExpression != null; | ||
|
||
PhpAttributeServiceSuggestionCollector collector = new PhpAttributeServiceSuggestionCollector(); | ||
assertContainsElements( | ||
collector.collect(stringLiteralExpression, ContainerCollectionResolver.getServices(getProject()).values()), | ||
"foo_bar_service" | ||
); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/test/java/fr/adrienbrault/idea/symfony2plugin/tests/dic/suggestion/fixtures/classes.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
|
||
namespace Foo | ||
{ | ||
class Bar | ||
{ | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
src/test/java/fr/adrienbrault/idea/symfony2plugin/tests/dic/suggestion/fixtures/services.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
services: | ||
foo_bar_service: | ||
class: Foo\Bar |