diff --git a/.travis.yml b/.travis.yml index f67006dfb..dc1cfb991 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,7 +23,7 @@ before_install: - "export ORG_GRADLE_PROJECT_annotationPluginVersion=${ANNOTATION_PLUGIN_VERSION}" env: - - PHPSTORM_ENV="skip incomplete" IDEA_VERSION="IU-2020.1" PHP_PLUGIN_VERSION="201.6668.153" TWIG_PLUGIN_VERSION="201.6668.153" TOOLBOX_PLUGIN_VERSION="0.4.6" ANNOTATION_PLUGIN_VERSION="5.3" DQL_PLUGIN_VERSION="201.6668.60" + - PHPSTORM_ENV="skip incomplete" IDEA_VERSION="IU-2020.2" PHP_PLUGIN_VERSION="202.6397.115" TWIG_PLUGIN_VERSION="202.6397.21" TOOLBOX_PLUGIN_VERSION="0.4.6" ANNOTATION_PLUGIN_VERSION="5.3" DQL_PLUGIN_VERSION="202.6397.59" script: - "./gradlew check verifyPlugin buildPlugin" diff --git a/build.gradle b/build.gradle index eafadf464..55d9cc1a9 100644 --- a/build.gradle +++ b/build.gradle @@ -45,7 +45,7 @@ intellij { } patchPluginXml { - sinceBuild '201' + sinceBuild '202' changeNotes = htmlFixer('src/main/resources/META-INF/change-notes.html') } diff --git a/gradle.properties b/gradle.properties index 989b0b4fe..a1e40601b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ -ideaVersion = IU-2020.1 -phpPluginVersion = 201.6668.153 -twigPluginVersion = 201.6668.153 -dqlPluginVersion = 201.6668.60 +ideaVersion = IU-2020.2 +phpPluginVersion = 202.6397.115 +twigPluginVersion = 202.6397.21 +dqlPluginVersion = 202.6397.59 toolboxPluginVersion = 0.4.6 annotationPluginVersion = 5.3 diff --git a/src/main/java/fr/adrienbrault/idea/symfony2plugin/config/ConfigLineMarkerProvider.java b/src/main/java/fr/adrienbrault/idea/symfony2plugin/config/ConfigLineMarkerProvider.java index 2f0efc0cb..7c299ccc8 100644 --- a/src/main/java/fr/adrienbrault/idea/symfony2plugin/config/ConfigLineMarkerProvider.java +++ b/src/main/java/fr/adrienbrault/idea/symfony2plugin/config/ConfigLineMarkerProvider.java @@ -25,12 +25,12 @@ public class ConfigLineMarkerProvider implements LineMarkerProvider { @Nullable @Override - public LineMarkerInfo getLineMarkerInfo(@NotNull PsiElement psiElement) { + public LineMarkerInfo getLineMarkerInfo(@NotNull PsiElement psiElement) { return null; } @Override - public void collectSlowLineMarkers(@NotNull List psiElements, @NotNull Collection result) { + public void collectSlowLineMarkers(@NotNull List psiElements, @NotNull Collection> result) { if(psiElements.size() == 0 || !Symfony2ProjectComponent.isEnabled(psiElements.get(0))) { return; } @@ -47,7 +47,7 @@ public void collectSlowLineMarkers(@NotNull List psiElements, @NotNu } } - private void visitRootElements(@NotNull Collection result, @NotNull PsiElement psiElement, @NotNull LazyConfigTreeSignatures function) { + private void visitRootElements(@NotNull Collection> result, @NotNull PsiElement psiElement, @NotNull LazyConfigTreeSignatures function) { PsiElement parent = psiElement.getParent(); if(!(parent instanceof YAMLKeyValue)) { return; diff --git a/src/main/java/fr/adrienbrault/idea/symfony2plugin/config/ServiceLineMarkerProvider.java b/src/main/java/fr/adrienbrault/idea/symfony2plugin/config/ServiceLineMarkerProvider.java index a8bd5640b..d83d4f6f6 100644 --- a/src/main/java/fr/adrienbrault/idea/symfony2plugin/config/ServiceLineMarkerProvider.java +++ b/src/main/java/fr/adrienbrault/idea/symfony2plugin/config/ServiceLineMarkerProvider.java @@ -49,12 +49,12 @@ public class ServiceLineMarkerProvider implements LineMarkerProvider { @Nullable @Override - public LineMarkerInfo getLineMarkerInfo(@NotNull PsiElement element) { + public LineMarkerInfo getLineMarkerInfo(@NotNull PsiElement element) { return null; } @Override - public void collectSlowLineMarkers(@NotNull List psiElements, @NotNull Collection results) { + public void collectSlowLineMarkers(@NotNull List psiElements, @NotNull Collection> results) { // we need project element; so get it from first item if(psiElements.size() == 0) { @@ -95,7 +95,7 @@ public void collectSlowLineMarkers(@NotNull List psiElements, @NotNu } } - private void classNameMarker(PsiElement psiElement, Collection result) { + private void classNameMarker(PsiElement psiElement, Collection> result) { PsiElement phpClassContext = psiElement.getContext(); if(!(phpClassContext instanceof PhpClass) || ((PhpClass) phpClassContext).isAbstract()) { return; @@ -161,7 +161,7 @@ private void classNameMarker(PsiElement psiElement, Collection result) { + private void entityClassMarker(PsiElement psiElement, Collection> result) { PsiElement phpClassContext = psiElement.getContext(); if(!(phpClassContext instanceof PhpClass)) { @@ -197,7 +197,7 @@ private void entityClassMarker(PsiElement psiElement, Collection result) { + private void repositoryClassMarker(PsiElement psiElement, Collection> result) { PsiElement phpClassContext = psiElement.getContext(); if(!(phpClassContext instanceof PhpClass)) { @@ -225,7 +225,7 @@ private void repositoryClassMarker(PsiElement psiElement, Collection result) { + private void formNameMarker(PsiElement psiElement, Collection> result) { if(!(psiElement instanceof StringLiteralExpression)) { return; @@ -257,7 +257,7 @@ private void formNameMarker(PsiElement psiElement, Collection results) { + private void routeAnnotationFileResource(@NotNull PsiFile psiFile, Collection> results) { RelatedItemLineMarkerInfo lineMarker = FileResourceUtil.getFileImplementsLineMarkerInFolderScope(psiFile); if(lineMarker != null) { results.add(lineMarker); @@ -267,7 +267,7 @@ private void routeAnnotationFileResource(@NotNull PsiFile psiFile, Collection results) { + private void validatorClassMarker(PsiElement psiElement, Collection> results) { PsiElement phpClassContext = psiElement.getContext(); if(!(phpClassContext instanceof PhpClass) || !PhpElementsUtil.isInstanceOf((PhpClass) phpClassContext, "\\Symfony\\Component\\Validator\\Constraint")) { return; @@ -293,7 +293,7 @@ private void validatorClassMarker(PsiElement psiElement, Collection results) { + private void constraintValidatorClassMarker(PsiElement psiElement, Collection> results) { PsiElement phpClass = psiElement.getContext(); if(!(phpClass instanceof PhpClass) || !PhpElementsUtil.isInstanceOf((PhpClass) phpClass, "Symfony\\Component\\Validator\\ConstraintValidatorInterface")) { return; @@ -319,7 +319,7 @@ private void constraintValidatorClassMarker(PsiElement psiElement, Collection
  • results) { + private void autowireConstructorMarker(PsiElement psiElement, Collection> results) { PsiElement method = psiElement.getParent(); if (!(method instanceof Method)) { return; @@ -381,7 +381,7 @@ private void autowireConstructorMarker(PsiElement psiElement, Collection results) { + private void constraintMessagePropertyMarker(@NotNull PsiElement psiElement, @NotNull Collection> results) { PsiElement parent = psiElement.getParent(); if (parent instanceof StringLiteralExpression && TranslationUtil.isConstraintPropertyField((StringLiteralExpression) parent)) { String contents = ((StringLiteralExpression) parent).getContents(); diff --git a/src/main/java/fr/adrienbrault/idea/symfony2plugin/config/yaml/inspection/EventMethodCallInspection.java b/src/main/java/fr/adrienbrault/idea/symfony2plugin/config/yaml/inspection/EventMethodCallInspection.java index d5a106d7b..3f5aa3f5b 100644 --- a/src/main/java/fr/adrienbrault/idea/symfony2plugin/config/yaml/inspection/EventMethodCallInspection.java +++ b/src/main/java/fr/adrienbrault/idea/symfony2plugin/config/yaml/inspection/EventMethodCallInspection.java @@ -36,6 +36,9 @@ import org.jetbrains.yaml.YAMLTokenTypes; import org.jetbrains.yaml.psi.*; +import java.util.Collection; +import java.util.stream.Collectors; + /** * @author Daniel Espendiller */ @@ -199,18 +202,24 @@ private String getEventTypeHint(@NotNull ProblemDescriptor problemDescriptor, @N return null; } - String taggedEventMethodParameter = EventSubscriberUtil.getTaggedEventMethodParameter(problemDescriptor.getPsiElement().getProject(), eventName); - if (taggedEventMethodParameter == null) { + Collection taggedEventMethodParameter = EventSubscriberUtil.getTaggedEventMethodParameter(problemDescriptor.getPsiElement().getProject(), eventName); + if (taggedEventMethodParameter.isEmpty()) { return null; } - String qualifiedName = AnnotationBackportUtil.getQualifiedName(phpClass, taggedEventMethodParameter); - if (qualifiedName != null && !qualifiedName.equals(StringUtils.stripStart(taggedEventMethodParameter, "\\"))) { + return taggedEventMethodParameter.stream() + .map(fqn -> importIfNecessary(phpClass, fqn)) + .collect(Collectors.joining("|")); + } + + private String importIfNecessary(@NotNull PhpClass phpClass, String fqn) { + String qualifiedName = AnnotationBackportUtil.getQualifiedName(phpClass, fqn); + if (qualifiedName != null && !qualifiedName.equals(StringUtils.stripStart(fqn, "\\"))) { // class already imported return qualifiedName; } - return PhpElementsUtil.insertUseIfNecessary(phpClass, taggedEventMethodParameter); + return PhpElementsUtil.insertUseIfNecessary(phpClass, fqn); } } diff --git a/src/main/java/fr/adrienbrault/idea/symfony2plugin/dic/ControllerMethodLineMarkerProvider.java b/src/main/java/fr/adrienbrault/idea/symfony2plugin/dic/ControllerMethodLineMarkerProvider.java index 8ed72f7e0..6ebf17816 100644 --- a/src/main/java/fr/adrienbrault/idea/symfony2plugin/dic/ControllerMethodLineMarkerProvider.java +++ b/src/main/java/fr/adrienbrault/idea/symfony2plugin/dic/ControllerMethodLineMarkerProvider.java @@ -31,12 +31,12 @@ public class ControllerMethodLineMarkerProvider implements LineMarkerProvider { @Nullable @Override - public LineMarkerInfo getLineMarkerInfo(@NotNull PsiElement psiElement) { + public LineMarkerInfo getLineMarkerInfo(@NotNull PsiElement psiElement) { return null; } @Nullable - public LineMarkerInfo collect(PsiElement psiElement) { + public LineMarkerInfo collect(PsiElement psiElement) { if(!Symfony2ProjectComponent.isEnabled(psiElement) || psiElement.getNode().getElementType() != PhpTokenTypes.IDENTIFIER) { return null; } @@ -102,10 +102,10 @@ public static List getGotoRelatedItems(Method method) { } @Override - public void collectSlowLineMarkers(@NotNull List psiElements, @NotNull Collection results) { + public void collectSlowLineMarkers(@NotNull List psiElements, @NotNull Collection> results) { for(PsiElement psiElement: psiElements) { - LineMarkerInfo lineMarkerInfo = collect(psiElement); + LineMarkerInfo lineMarkerInfo = collect(psiElement); if(lineMarkerInfo != null) { results.add(lineMarkerInfo); } diff --git a/src/main/java/fr/adrienbrault/idea/symfony2plugin/dic/linemarker/XmlLineMarkerProvider.java b/src/main/java/fr/adrienbrault/idea/symfony2plugin/dic/linemarker/XmlLineMarkerProvider.java index fb246e0f9..81ba370ee 100644 --- a/src/main/java/fr/adrienbrault/idea/symfony2plugin/dic/linemarker/XmlLineMarkerProvider.java +++ b/src/main/java/fr/adrienbrault/idea/symfony2plugin/dic/linemarker/XmlLineMarkerProvider.java @@ -23,12 +23,12 @@ public class XmlLineMarkerProvider implements LineMarkerProvider { @Nullable @Override - public LineMarkerInfo getLineMarkerInfo(@NotNull PsiElement psiElement) { + public LineMarkerInfo getLineMarkerInfo(@NotNull PsiElement psiElement) { return null; } @Override - public void collectSlowLineMarkers(@NotNull List psiElements, @NotNull Collection result) { + public void collectSlowLineMarkers(@NotNull List psiElements, @NotNull Collection> result) { if(psiElements.size() == 0 || !Symfony2ProjectComponent.isEnabled(psiElements.get(0))) { return; } @@ -57,7 +57,7 @@ public void collectSlowLineMarkers(@NotNull List psiElements, @NotNu /** * */ - private void visitServiceId(@NotNull PsiElement leafTarget, @NotNull XmlTag xmlTag, @NotNull Collection result, @NotNull LazyDecoratedParentServiceValues lazyDecoratedParentServiceValues) { + private void visitServiceId(@NotNull PsiElement leafTarget, @NotNull XmlTag xmlTag, @NotNull Collection> result, @NotNull LazyDecoratedParentServiceValues lazyDecoratedParentServiceValues) { String id = xmlTag.getAttributeValue("id"); if(StringUtils.isBlank(id)) { return; diff --git a/src/main/java/fr/adrienbrault/idea/symfony2plugin/dic/linemarker/YamlLineMarkerProvider.java b/src/main/java/fr/adrienbrault/idea/symfony2plugin/dic/linemarker/YamlLineMarkerProvider.java index 1dfe43243..2c64c742a 100644 --- a/src/main/java/fr/adrienbrault/idea/symfony2plugin/dic/linemarker/YamlLineMarkerProvider.java +++ b/src/main/java/fr/adrienbrault/idea/symfony2plugin/dic/linemarker/YamlLineMarkerProvider.java @@ -26,12 +26,12 @@ public class YamlLineMarkerProvider implements LineMarkerProvider { @Nullable @Override - public LineMarkerInfo getLineMarkerInfo(@NotNull PsiElement psiElement) { + public LineMarkerInfo getLineMarkerInfo(@NotNull PsiElement psiElement) { return null; } @Override - public void collectSlowLineMarkers(@NotNull List psiElements, @NotNull Collection result) { + public void collectSlowLineMarkers(@NotNull List psiElements, @NotNull Collection> result) { if(psiElements.size() == 0 || !Symfony2ProjectComponent.isEnabled(psiElements.get(0))) { return; } @@ -63,7 +63,7 @@ public void collectSlowLineMarkers(@NotNull List psiElements, @NotNu } } - private void visitServiceIdForResources(PsiElement leafTarget, YAMLKeyValue yamlKeyValue, @NotNull Collection result) { + private void visitServiceIdForResources(PsiElement leafTarget, YAMLKeyValue yamlKeyValue, @NotNull Collection> result) { String resource = YamlHelper.getYamlKeyValueAsString(yamlKeyValue, "resource"); if (resource == null) { return; @@ -81,7 +81,7 @@ protected Collection compute() { .createLineMarkerInfo(leafTarget)); } - private void visitServiceId(@NotNull PsiElement leafTarget, @NotNull YAMLKeyValue yamlKeyValue, @NotNull Collection result, @NotNull LazyDecoratedParentServiceValues lazyDecoratedServices) { + private void visitServiceId(@NotNull PsiElement leafTarget, @NotNull YAMLKeyValue yamlKeyValue, @NotNull Collection> result, @NotNull LazyDecoratedParentServiceValues lazyDecoratedServices) { String id = yamlKeyValue.getKeyText(); if(StringUtils.isBlank(id)) { return; diff --git a/src/main/java/fr/adrienbrault/idea/symfony2plugin/doctrine/metadata/DoctrineMetadataLineMarkerProvider.java b/src/main/java/fr/adrienbrault/idea/symfony2plugin/doctrine/metadata/DoctrineMetadataLineMarkerProvider.java index 65db6bc3e..1b8ee8a48 100644 --- a/src/main/java/fr/adrienbrault/idea/symfony2plugin/doctrine/metadata/DoctrineMetadataLineMarkerProvider.java +++ b/src/main/java/fr/adrienbrault/idea/symfony2plugin/doctrine/metadata/DoctrineMetadataLineMarkerProvider.java @@ -25,12 +25,12 @@ public class DoctrineMetadataLineMarkerProvider implements LineMarkerProvider { @Nullable @Override - public LineMarkerInfo getLineMarkerInfo(@NotNull PsiElement element) { + public LineMarkerInfo getLineMarkerInfo(@NotNull PsiElement element) { return null; } @Override - public void collectSlowLineMarkers(@NotNull List psiElements, @NotNull Collection results) { + public void collectSlowLineMarkers(@NotNull List psiElements, @NotNull Collection> results) { // we need project element; so get it from first item if(psiElements.size() == 0) { return; @@ -53,7 +53,7 @@ public void collectSlowLineMarkers(@NotNull List psiElements, @NotNu } } - private void attachXmlRelationMarker(@NotNull PsiElement target, @NotNull XmlAttributeValue psiElement, @NotNull Collection results) { + private void attachXmlRelationMarker(@NotNull PsiElement target, @NotNull XmlAttributeValue psiElement, @NotNull Collection> results) { String value = psiElement.getValue(); if(StringUtils.isBlank(value)) { return; diff --git a/src/main/java/fr/adrienbrault/idea/symfony2plugin/routing/XmlLineMarkerProvider.java b/src/main/java/fr/adrienbrault/idea/symfony2plugin/routing/XmlLineMarkerProvider.java index 39af3d0e3..ef2458aca 100644 --- a/src/main/java/fr/adrienbrault/idea/symfony2plugin/routing/XmlLineMarkerProvider.java +++ b/src/main/java/fr/adrienbrault/idea/symfony2plugin/routing/XmlLineMarkerProvider.java @@ -26,7 +26,7 @@ public class XmlLineMarkerProvider implements LineMarkerProvider { @Override - public void collectSlowLineMarkers(@NotNull List psiElements, @NotNull Collection lineMarkerInfos) { + public void collectSlowLineMarkers(@NotNull List psiElements, @NotNull Collection> lineMarkerInfos) { if(psiElements.size() == 0 || !Symfony2ProjectComponent.isEnabled(psiElements.get(0))) { return; } @@ -44,7 +44,7 @@ public void collectSlowLineMarkers(@NotNull List psiElements, @NotNu } - private void attachRouteActions(@NotNull PsiElement psiElement, @NotNull Collection lineMarkerInfos) { + private void attachRouteActions(@NotNull PsiElement psiElement, @NotNull Collection> lineMarkerInfos) { PsiElement xmlTag = psiElement.getParent(); if(!(xmlTag instanceof XmlTag) || !Pattern.getRouteTag().accepts(xmlTag)) { return; @@ -65,7 +65,7 @@ private void attachRouteActions(@NotNull PsiElement psiElement, @NotNull Collect @Nullable @Override - public LineMarkerInfo getLineMarkerInfo(@NotNull PsiElement psiElement) { + public LineMarkerInfo getLineMarkerInfo(@NotNull PsiElement psiElement) { return null; } diff --git a/src/main/java/fr/adrienbrault/idea/symfony2plugin/routing/YamlLineMarkerProvider.java b/src/main/java/fr/adrienbrault/idea/symfony2plugin/routing/YamlLineMarkerProvider.java index c71f8f047..3d2bef5c9 100644 --- a/src/main/java/fr/adrienbrault/idea/symfony2plugin/routing/YamlLineMarkerProvider.java +++ b/src/main/java/fr/adrienbrault/idea/symfony2plugin/routing/YamlLineMarkerProvider.java @@ -28,7 +28,7 @@ public class YamlLineMarkerProvider implements LineMarkerProvider { @Override - public void collectSlowLineMarkers(@NotNull List psiElements, @NotNull Collection lineMarkerInfos) { + public void collectSlowLineMarkers(@NotNull List psiElements, @NotNull Collection> lineMarkerInfos) { if(psiElements.size() == 0 || !Symfony2ProjectComponent.isEnabled(psiElements.get(0))) { return; } @@ -47,7 +47,7 @@ public void collectSlowLineMarkers(@NotNull List psiElements, @NotNu } } - private void attachEntityClass(@NotNull Collection lineMarkerInfos, @NotNull PsiElement psiElement) { + private void attachEntityClass(@NotNull Collection> lineMarkerInfos, @NotNull PsiElement psiElement) { if(psiElement.getNode().getElementType() != YAMLTokenTypes.SCALAR_KEY) { return; } @@ -89,7 +89,7 @@ private void attachEntityClass(@NotNull Collection lineMarkerInf * defaults: { _controller: "Bundle:Foo:Bar" } * controller: "Bundle:Foo:Bar" */ - private void attachRouteActions(@NotNull Collection lineMarkerInfos, @NotNull PsiElement psiElement) { + private void attachRouteActions(@NotNull Collection> lineMarkerInfos, @NotNull PsiElement psiElement) { if(psiElement.getNode().getElementType() != YAMLTokenTypes.SCALAR_KEY) { return; } @@ -114,7 +114,7 @@ private void attachRouteActions(@NotNull Collection lineMarkerIn @Nullable @Override - public LineMarkerInfo getLineMarkerInfo(@NotNull PsiElement psiElement) { + public LineMarkerInfo getLineMarkerInfo(@NotNull PsiElement psiElement) { return null; } @@ -124,7 +124,7 @@ public LineMarkerInfo getLineMarkerInfo(@NotNull PsiElement psiElement) { * foo: * targetEntity: Class */ - private void attachRelationClass(@NotNull Collection lineMarkerInfos, @NotNull PsiElement psiElement) { + private void attachRelationClass(@NotNull Collection> lineMarkerInfos, @NotNull PsiElement psiElement) { if(psiElement.getNode().getElementType() != YAMLTokenTypes.SCALAR_KEY) { return; } diff --git a/src/main/java/fr/adrienbrault/idea/symfony2plugin/templating/TwigLineMarkerProvider.java b/src/main/java/fr/adrienbrault/idea/symfony2plugin/templating/TwigLineMarkerProvider.java index e2edc3f55..89f65f3e1 100644 --- a/src/main/java/fr/adrienbrault/idea/symfony2plugin/templating/TwigLineMarkerProvider.java +++ b/src/main/java/fr/adrienbrault/idea/symfony2plugin/templating/TwigLineMarkerProvider.java @@ -54,7 +54,7 @@ */ public class TwigLineMarkerProvider implements LineMarkerProvider { @Override - public void collectSlowLineMarkers(@NotNull List psiElements, @NotNull Collection results) { + public void collectSlowLineMarkers(@NotNull List psiElements, @NotNull Collection> results) { if(psiElements.size() == 0 || !Symfony2ProjectComponent.isEnabled(psiElements.get(0))) { return; } @@ -69,18 +69,18 @@ public void collectSlowLineMarkers(@NotNull List psiElements, @NotNu // find foreign file references tags like: // include, embed, source, from, import, ... - LineMarkerInfo lineIncludes = attachIncludes((TwigFile) psiElement); + LineMarkerInfo lineIncludes = attachIncludes((TwigFile) psiElement); if(lineIncludes != null) { results.add(lineIncludes); } - LineMarkerInfo extending = attachExtends((TwigFile) psiElement); + LineMarkerInfo extending = attachExtends((TwigFile) psiElement); if(extending != null) { results.add(extending); } // eg bundle overwrites - LineMarkerInfo overwrites = attachOverwrites((TwigFile) psiElement); + LineMarkerInfo overwrites = attachOverwrites((TwigFile) psiElement); if(overwrites != null) { results.add(overwrites); } @@ -92,7 +92,7 @@ public void collectSlowLineMarkers(@NotNull List psiElements, @NotNu implementsMap.put(virtualFile, new FileImplementsLazyLoader(psiElement.getProject(), virtualFile)); } - LineMarkerInfo lineImpl = attachBlockImplements(psiElement, implementsMap.get(virtualFile)); + LineMarkerInfo lineImpl = attachBlockImplements(psiElement, implementsMap.get(virtualFile)); if(lineImpl != null) { results.add(lineImpl); } @@ -101,12 +101,12 @@ public void collectSlowLineMarkers(@NotNull List psiElements, @NotNu fileOverwritesLazyLoader = new FileOverwritesLazyLoader(psiElements.get(0).getProject()); } - LineMarkerInfo lineOverwrites = attachBlockOverwrites(psiElement, fileOverwritesLazyLoader); + LineMarkerInfo lineOverwrites = attachBlockOverwrites(psiElement, fileOverwritesLazyLoader); if(lineOverwrites != null) { results.add(lineOverwrites); } } else if(TwigPattern.getFunctionPattern("form_start", "form").accepts(psiElement)) { - LineMarkerInfo lineOverwrites = attachFormType(psiElement); + LineMarkerInfo lineOverwrites = attachFormType(psiElement); if(lineOverwrites != null) { results.add(lineOverwrites); } @@ -114,7 +114,7 @@ public void collectSlowLineMarkers(@NotNull List psiElements, @NotNu } } - private void attachController(@NotNull TwigFile twigFile, @NotNull Collection result) { + private void attachController(@NotNull TwigFile twigFile, @NotNull Collection> result) { Set methods = new HashSet<>(); @@ -134,7 +134,7 @@ private void attachController(@NotNull TwigFile twigFile, @NotNull Collection attachIncludes(@NotNull TwigFile twigFile) { Collection templateNames = TwigUtil.getTemplateNamesForFile(twigFile); boolean found = false; @@ -165,7 +165,7 @@ private LineMarkerInfo attachIncludes(@NotNull TwigFile twigFile) { } @Nullable - private LineMarkerInfo attachExtends(@NotNull TwigFile twigFile) { + private LineMarkerInfo attachExtends(@NotNull TwigFile twigFile) { Collection templateNames = TwigUtil.getTemplateNamesForFile(twigFile); boolean found = false; @@ -196,7 +196,7 @@ private LineMarkerInfo attachExtends(@NotNull TwigFile twigFile) { } @Nullable - private LineMarkerInfo attachOverwrites(@NotNull TwigFile twigFile) { + private LineMarkerInfo attachOverwrites(@NotNull TwigFile twigFile) { Collection targets = new ArrayList<>(); for (String templateName: TwigUtil.getTemplateNamesForFile(twigFile)) { @@ -222,7 +222,7 @@ private LineMarkerInfo attachOverwrites(@NotNull TwigFile twigFile) { return getRelatedPopover("Overwrites", "Overwrite", twigFile, gotoRelatedItems, Symfony2Icons.TWIG_LINE_OVERWRITE); } - private LineMarkerInfo getRelatedPopover(String singleItemTitle, String singleItemTooltipPrefix, PsiElement lineMarkerTarget, List gotoRelatedItems, Icon icon) { + private LineMarkerInfo getRelatedPopover(String singleItemTitle, String singleItemTooltipPrefix, PsiElement lineMarkerTarget, List gotoRelatedItems, Icon icon) { // single item has no popup String title = singleItemTitle; @@ -245,7 +245,7 @@ private LineMarkerInfo getRelatedPopover(String singleItemTitle, String singleIt } @Nullable - private LineMarkerInfo attachBlockImplements(@NotNull PsiElement psiElement, @NotNull FileImplementsLazyLoader implementsLazyLoader) { + private LineMarkerInfo attachBlockImplements(@NotNull PsiElement psiElement, @NotNull FileImplementsLazyLoader implementsLazyLoader) { if(!TwigBlockUtil.hasBlockImplementations(psiElement, implementsLazyLoader)) { return null; } @@ -292,7 +292,7 @@ protected Collection compute() { } @Nullable - private LineMarkerInfo attachBlockOverwrites(@NotNull PsiElement psiElement, @NotNull FileOverwritesLazyLoader loader) { + private LineMarkerInfo attachBlockOverwrites(@NotNull PsiElement psiElement, @NotNull FileOverwritesLazyLoader loader) { if(!TwigBlockUtil.hasBlockOverwrites(psiElement, loader)) { return null; } @@ -306,7 +306,7 @@ private LineMarkerInfo attachBlockOverwrites(@NotNull PsiElement psiElement, @No } @Nullable - private LineMarkerInfo attachFormType(@NotNull PsiElement psiElement) { + private LineMarkerInfo attachFormType(@NotNull PsiElement psiElement) { PsiElement firstChild = psiElement.getFirstChild(); if (firstChild == null) { return null; @@ -342,7 +342,7 @@ private LineMarkerInfo attachFormType(@NotNull PsiElement psiElement) { @Nullable @Override - public LineMarkerInfo getLineMarkerInfo(@NotNull PsiElement psiElement) { + public LineMarkerInfo getLineMarkerInfo(@NotNull PsiElement psiElement) { return null; } diff --git a/src/main/java/fr/adrienbrault/idea/symfony2plugin/templating/TwigPattern.java b/src/main/java/fr/adrienbrault/idea/symfony2plugin/templating/TwigPattern.java index f751a9dfd..ed44eac03 100644 --- a/src/main/java/fr/adrienbrault/idea/symfony2plugin/templating/TwigPattern.java +++ b/src/main/java/fr/adrienbrault/idea/symfony2plugin/templating/TwigPattern.java @@ -49,7 +49,7 @@ public class TwigPattern { PlatformPatterns.psiElement(TwigTokenTypes.SINGLE_QUOTE) ); - public static final String DOC_SEE_REGEX = "\\{#[\\s]+@see[\\s]+([-@\\./\\:\\w\\\\\\[\\]]+)[\\s]*#}"; + public static final String DOC_SEE_REGEX = "@see[\\s]+([-@\\./\\:\\w\\\\\\[\\]]+)[\\s]*"; /** * {% trans with {'%name%': 'Fabien'} from "app" %} @@ -883,7 +883,7 @@ public static ElementPattern getTwigTypeDocBlockPattern() { Collection patterns = new ArrayList<>(); for (String s : TwigTypeResolveUtil.DOC_TYPE_PATTERN_SINGLE) { - patterns.add(PlatformPatterns.psiComment().withText(PlatformPatterns.string().matches(s)).withLanguage(TwigLanguage.INSTANCE)); + patterns.add(PlatformPatterns.psiElement(TwigTokenTypes.COMMENT_TEXT).withText(PlatformPatterns.string().matches(s)).withLanguage(TwigLanguage.INSTANCE)); } return PlatformPatterns.or(patterns.toArray(new ElementPattern[patterns.size()])); @@ -895,10 +895,10 @@ public static ElementPattern getTwigTypeDocBlockPattern() { * {# \Class #} */ @NotNull - public static ElementPattern getTwigDocSeePattern() { + public static ElementPattern getTwigDocSeePattern() { return PlatformPatterns.or( - PlatformPatterns.psiComment().withText(PlatformPatterns.string().matches(DOC_SEE_REGEX)).withLanguage(TwigLanguage.INSTANCE), - PlatformPatterns.psiComment().withText(PlatformPatterns.string().matches(TwigUtil.DOC_SEE_REGEX_WITHOUT_SEE)).withLanguage(TwigLanguage.INSTANCE) + PlatformPatterns.psiElement(TwigTokenTypes.COMMENT_TEXT).withText(PlatformPatterns.string().matches(DOC_SEE_REGEX)).withLanguage(TwigLanguage.INSTANCE), + PlatformPatterns.psiElement(TwigTokenTypes.COMMENT_TEXT).withText(PlatformPatterns.string().matches(TwigUtil.DOC_SEE_REGEX_WITHOUT_SEE)).withLanguage(TwigLanguage.INSTANCE) ); } diff --git a/src/main/java/fr/adrienbrault/idea/symfony2plugin/templating/util/TwigTypeResolveUtil.java b/src/main/java/fr/adrienbrault/idea/symfony2plugin/templating/util/TwigTypeResolveUtil.java index 80be58640..e4943d0f6 100644 --- a/src/main/java/fr/adrienbrault/idea/symfony2plugin/templating/util/TwigTypeResolveUtil.java +++ b/src/main/java/fr/adrienbrault/idea/symfony2plugin/templating/util/TwigTypeResolveUtil.java @@ -69,9 +69,9 @@ public class TwigTypeResolveUtil { // for supporting completion and navigation of one line element public static final String[] DOC_TYPE_PATTERN_SINGLE = new String[] { - "\\{#[\\s]+(?[\\w]+)[\\s]+(?[\\w\\\\\\[\\]]+)[\\s]+#}", - "\\{#[\\s]+"+ DOC_TYPE_PATTERN_CLASS_SECOND + "[\\s]+#}", - "\\{#[\\s]+"+ DOC_TYPE_PATTERN_CLASS_FIRST + "[\\s]+#}", + "^(?[\\w]+)[\\s]+(?[\\w\\\\\\[\\]]+)[\\s]*$", + DOC_TYPE_PATTERN_CLASS_SECOND, + DOC_TYPE_PATTERN_CLASS_FIRST }; private static String[] PROPERTY_SHORTCUTS = new String[] {"get", "is", "has"}; diff --git a/src/main/java/fr/adrienbrault/idea/symfony2plugin/templating/util/TwigUtil.java b/src/main/java/fr/adrienbrault/idea/symfony2plugin/templating/util/TwigUtil.java index 3c869ae60..12c686bfe 100644 --- a/src/main/java/fr/adrienbrault/idea/symfony2plugin/templating/util/TwigUtil.java +++ b/src/main/java/fr/adrienbrault/idea/symfony2plugin/templating/util/TwigUtil.java @@ -79,7 +79,7 @@ * @author Daniel Espendiller */ public class TwigUtil { - public static final String DOC_SEE_REGEX_WITHOUT_SEE = "\\{#[\\s]+([-@\\./\\:\\w\\\\\\[\\]]+)[\\s]*#}"; + public static final String DOC_SEE_REGEX_WITHOUT_SEE = "([-@\\./\\:\\w\\\\\\[\\]]+)[\\s]*"; /** * Twig namespace for "non namespace"; its also a reserved value in Twig library diff --git a/src/main/java/fr/adrienbrault/idea/symfony2plugin/util/EventSubscriberUtil.java b/src/main/java/fr/adrienbrault/idea/symfony2plugin/util/EventSubscriberUtil.java index 59c81473c..c6f629a02 100644 --- a/src/main/java/fr/adrienbrault/idea/symfony2plugin/util/EventSubscriberUtil.java +++ b/src/main/java/fr/adrienbrault/idea/symfony2plugin/util/EventSubscriberUtil.java @@ -21,6 +21,7 @@ import org.jetbrains.annotations.Nullable; import java.util.Collection; +import java.util.Collections; /** * @author Daniel Espendiller @@ -49,12 +50,12 @@ public static void visitNamedTag(@NotNull Project project, @NotNull String tagNa /** * @TODO: implement collection with prio */ - @Nullable - public static String getTaggedEventMethodParameter(@NotNull Project project, @NotNull String eventName) { + @NotNull + public static Collection getTaggedEventMethodParameter(@NotNull Project project, @NotNull String eventName) { // Static list if(ServiceUtil.TAGS.containsKey(eventName)) { - return ServiceUtil.TAGS.get(eventName); + return Collections.singletonList(ServiceUtil.TAGS.get(eventName)); } // @Event annotation @@ -65,7 +66,7 @@ public static String getTaggedEventMethodParameter(@NotNull Project project, @No ); if(dispatcherEvent != null && StringUtils.isNotBlank(dispatcherEvent.getInstance())) { - return dispatcherEvent.getInstance(); + return Collections.singletonList(dispatcherEvent.getInstance()); } // Extract from directly from EventSubscriberInterface @@ -77,9 +78,9 @@ public static String getTaggedEventMethodParameter(@NotNull Project project, @No Method method = PhpElementsUtil.getClassMethod(project, event.getFqnClassName(), methodName); if(method != null) { - String methodParameterClassHint = PhpElementsUtil.getMethodParameterTypeHint(method); - if(methodParameterClassHint != null) { - return methodParameterClassHint; + Collection methodParameterClassHints = PhpElementsUtil.getMethodParameterTypeHints(method); + if(!methodParameterClassHints.isEmpty()) { + return methodParameterClassHints; } } } @@ -109,9 +110,9 @@ public static String getTaggedEventMethodParameter(@NotNull Project project, @No if(phpClass != null) { Method method = phpClass.findMethodByName(methodName); if(method != null) { - String methodParameterTypeHint = PhpElementsUtil.getMethodParameterTypeHint(method); - if(methodParameterTypeHint != null) { - return methodParameterTypeHint; + Collection methodParameterTypeHints = PhpElementsUtil.getMethodParameterTypeHints(method); + if(!methodParameterTypeHints.isEmpty()) { + return methodParameterTypeHints; } } @@ -121,6 +122,6 @@ public static String getTaggedEventMethodParameter(@NotNull Project project, @No } } - return null; + return Collections.emptyList(); } } diff --git a/src/main/java/fr/adrienbrault/idea/symfony2plugin/util/PhpElementsUtil.java b/src/main/java/fr/adrienbrault/idea/symfony2plugin/util/PhpElementsUtil.java index 6270ff25b..d10e4cc9e 100644 --- a/src/main/java/fr/adrienbrault/idea/symfony2plugin/util/PhpElementsUtil.java +++ b/src/main/java/fr/adrienbrault/idea/symfony2plugin/util/PhpElementsUtil.java @@ -36,6 +36,7 @@ import org.jetbrains.annotations.Nullable; import java.util.*; +import java.util.stream.Collectors; /** * @author Daniel Espendiller @@ -1050,24 +1051,23 @@ public static boolean isTestClass(@NotNull PhpClass phpClass) { * * function foo(\FooClass $class) */ - @Nullable - public static String getMethodParameterTypeHint(@NotNull Method method) { + @NotNull + public static Collection getMethodParameterTypeHints(@NotNull Method method) { ParameterList childOfType = PsiTreeUtil.getChildOfType(method, ParameterList.class); if(childOfType == null) { - return null; + return Collections.emptyList(); } PsiElement[] parameters = childOfType.getParameters(); if(parameters.length == 0) { - return null; - } - - ClassReference classReference = PsiTreeUtil.getChildOfType(parameters[0], ClassReference.class); - if(classReference == null) { - return null; + return Collections.emptyList(); } - - return classReference.getFQN(); + + PhpTypeDeclaration typeDeclaration = PsiTreeUtil.getChildOfType(parameters[0], PhpTypeDeclaration.class); + if (typeDeclaration == null) return Collections.emptyList(); + return typeDeclaration.getClassReferences().stream() + .map(PhpReference::getFQN) + .collect(Collectors.toList()); } /** diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index 4f9daaf20..5833b6127 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -97,7 +97,7 @@ ]]> - + diff --git a/src/test/java/fr/adrienbrault/idea/symfony2plugin/tests/templating/util/TwigTypeResolveUtilTest.java b/src/test/java/fr/adrienbrault/idea/symfony2plugin/tests/templating/util/TwigTypeResolveUtilTest.java index e1110d097..78e22401e 100644 --- a/src/test/java/fr/adrienbrault/idea/symfony2plugin/tests/templating/util/TwigTypeResolveUtilTest.java +++ b/src/test/java/fr/adrienbrault/idea/symfony2plugin/tests/templating/util/TwigTypeResolveUtilTest.java @@ -54,9 +54,9 @@ public void testFindFileVariableDocBlock() { } public void testReqExForInlineDocVariables() { - assertMatches("{# @var foo_1 \\AppBundle\\Entity\\MeterValueDTO #}", TwigTypeResolveUtil.DOC_TYPE_PATTERN_SINGLE); - assertMatches("{# @var \\AppBundle\\Entity\\MeterValueDTO foo_1 #}", TwigTypeResolveUtil.DOC_TYPE_PATTERN_SINGLE); - assertMatches("{# foo_1 \\AppBundle\\Entity\\MeterValueDTO #}", TwigTypeResolveUtil.DOC_TYPE_PATTERN_SINGLE); + assertMatches("@var foo_1 \\AppBundle\\Entity\\MeterValueDTO", TwigTypeResolveUtil.DOC_TYPE_PATTERN_SINGLE); + assertMatches("@var \\AppBundle\\Entity\\MeterValueDTO foo_1", TwigTypeResolveUtil.DOC_TYPE_PATTERN_SINGLE); + assertMatches("foo_1 \\AppBundle\\Entity\\MeterValueDTO", TwigTypeResolveUtil.DOC_TYPE_PATTERN_SINGLE); } /** diff --git a/src/test/java/fr/adrienbrault/idea/symfony2plugin/tests/util/EventSubscriberUtilTest.java b/src/test/java/fr/adrienbrault/idea/symfony2plugin/tests/util/EventSubscriberUtilTest.java index db6235fe6..d8a38f5f7 100644 --- a/src/test/java/fr/adrienbrault/idea/symfony2plugin/tests/util/EventSubscriberUtilTest.java +++ b/src/test/java/fr/adrienbrault/idea/symfony2plugin/tests/util/EventSubscriberUtilTest.java @@ -3,6 +3,9 @@ import fr.adrienbrault.idea.symfony2plugin.tests.SymfonyLightCodeInsightFixtureTestCase; import fr.adrienbrault.idea.symfony2plugin.util.EventSubscriberUtil; +import java.util.Arrays; +import java.util.Collections; + /** * @author Daniel Espendiller */ @@ -21,20 +24,21 @@ public String getTestDataPath() { * @see EventSubscriberUtil#getTaggedEventMethodParameter */ public void testGetTaggedEventMethodParameterWithInternals() { - assertEquals("\\Symfony\\Component\\HttpKernel\\Event\\GetResponseEvent", EventSubscriberUtil.getTaggedEventMethodParameter(getProject(), "kernel.request")); + assertEquals(Collections.singletonList("\\Symfony\\Component\\HttpKernel\\Event\\GetResponseEvent"), EventSubscriberUtil.getTaggedEventMethodParameter(getProject(), "kernel.request")); } /** * @see EventSubscriberUtil#getTaggedEventMethodParameter */ public void testGetTaggedEventMethodParameterWithSubscriberInterface() { - assertEquals("\\DateTime", EventSubscriberUtil.getTaggedEventMethodParameter(getProject(), "pre.foo")); - assertNull(EventSubscriberUtil.getTaggedEventMethodParameter(getProject(), "pre.foo_doh")); + assertEquals(Collections.singletonList("\\DateTime"), EventSubscriberUtil.getTaggedEventMethodParameter(getProject(), "pre.foo")); + assertEquals(Arrays.asList("\\DateTime", "\\DateInterval"), EventSubscriberUtil.getTaggedEventMethodParameter(getProject(), "union.types")); + assertEmpty(EventSubscriberUtil.getTaggedEventMethodParameter(getProject(), "pre.foo_doh")); } /** * @see EventSubscriberUtil#getTaggedEventMethodParameter */ public void testGetTaggedEventMethodParameterWithIndexEventAnnotation() { - assertEquals("Foo\\Event\\MyEvent", EventSubscriberUtil.getTaggedEventMethodParameter(getProject(), "my.foo.event")); + assertEquals(Collections.singletonList("Foo\\Event\\MyEvent"), EventSubscriberUtil.getTaggedEventMethodParameter(getProject(), "my.foo.event")); } } diff --git a/src/test/java/fr/adrienbrault/idea/symfony2plugin/tests/util/PhpElementsUtilTest.java b/src/test/java/fr/adrienbrault/idea/symfony2plugin/tests/util/PhpElementsUtilTest.java index eaa237f20..7b5bf7f41 100644 --- a/src/test/java/fr/adrienbrault/idea/symfony2plugin/tests/util/PhpElementsUtilTest.java +++ b/src/test/java/fr/adrienbrault/idea/symfony2plugin/tests/util/PhpElementsUtilTest.java @@ -10,7 +10,9 @@ import fr.adrienbrault.idea.symfony2plugin.util.PhpElementsUtil; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; +import java.util.Collections; /** * @author Daniel Espendiller @@ -27,18 +29,22 @@ public String getTestDataPath() { } /** - * @see fr.adrienbrault.idea.symfony2plugin.util.PhpElementsUtil#getMethodParameterTypeHint + * @see fr.adrienbrault.idea.symfony2plugin.util.PhpElementsUtil#getMethodParameterTypeHints */ public void testGetMethodParameterClassHint() { - assertEquals("\\DateTime", PhpElementsUtil.getMethodParameterTypeHint( + assertEquals(Collections.singletonList("\\DateTime"), PhpElementsUtil.getMethodParameterTypeHints( PhpPsiElementFactory.createMethod(getProject(), "function foo(\\DateTime $e) {}") )); - assertEquals("\\Iterator", PhpElementsUtil.getMethodParameterTypeHint( + assertEquals(Arrays.asList("\\DateTime", "\\DateInterval"), PhpElementsUtil.getMethodParameterTypeHints( + PhpPsiElementFactory.createMethod(getProject(), "function foo(\\DateTime|\\DateInterval $e) {}") + )); + + assertEquals(Collections.singletonList("\\Iterator"), PhpElementsUtil.getMethodParameterTypeHints( PhpPsiElementFactory.createMethod(getProject(), "function foo(/* foo */ \\Iterator $a, \\DateTime $b") )); - assertNull(PhpElementsUtil.getMethodParameterTypeHint( + assertEmpty(PhpElementsUtil.getMethodParameterTypeHints( PhpPsiElementFactory.createMethod(getProject(), "function foo(/* foo */ $a, \\DateTime $b") )); } diff --git a/src/test/java/fr/adrienbrault/idea/symfony2plugin/tests/util/fixtures/EventSubscriber.php b/src/test/java/fr/adrienbrault/idea/symfony2plugin/tests/util/fixtures/EventSubscriber.php index e824a8a72..6bbacc11c 100644 --- a/src/test/java/fr/adrienbrault/idea/symfony2plugin/tests/util/fixtures/EventSubscriber.php +++ b/src/test/java/fr/adrienbrault/idea/symfony2plugin/tests/util/fixtures/EventSubscriber.php @@ -19,11 +19,13 @@ public static function getSubscribedEvents() { return array( 'pre.foo' => 'preFoo', + 'union.types' => 'unionTypes', 'kernel.request' => 'FOO', ); } public function preFoo(\DateTime $d) {} + public function unionTypes(\DateTime|\DateInterval $d) {} } }