diff --git a/src/main/java/fr/adrienbrault/idea/symfony2plugin/doctrine/querybuilder/QueryBuilderCompletionContributor.java b/src/main/java/fr/adrienbrault/idea/symfony2plugin/doctrine/querybuilder/QueryBuilderCompletionContributor.java index 7f80615c2..c450af0e1 100644 --- a/src/main/java/fr/adrienbrault/idea/symfony2plugin/doctrine/querybuilder/QueryBuilderCompletionContributor.java +++ b/src/main/java/fr/adrienbrault/idea/symfony2plugin/doctrine/querybuilder/QueryBuilderCompletionContributor.java @@ -213,7 +213,7 @@ protected void addCompletions(@NotNull CompletionParameters completionParameters return; } - MethodMatcher.MethodMatchParameter methodMatchParameter = new MethodMatcher.StringParameterMatcher(psiElement.getContext(), 0) + MethodMatcher.MethodMatchParameter methodMatchParameter = new MethodMatcher.StringParameterMatcher(psiElement.getContext()) .withSignature(WHERES) .match(); diff --git a/src/main/java/fr/adrienbrault/idea/symfony2plugin/doctrine/querybuilder/QueryBuilderMethodReferenceParser.java b/src/main/java/fr/adrienbrault/idea/symfony2plugin/doctrine/querybuilder/QueryBuilderMethodReferenceParser.java index bf9b78e68..193ee36d1 100644 --- a/src/main/java/fr/adrienbrault/idea/symfony2plugin/doctrine/querybuilder/QueryBuilderMethodReferenceParser.java +++ b/src/main/java/fr/adrienbrault/idea/symfony2plugin/doctrine/querybuilder/QueryBuilderMethodReferenceParser.java @@ -186,19 +186,21 @@ private void collectJoins(QueryBuilderScopeContext qb, MethodReference methodRef } private void collectParameter(QueryBuilderScopeContext qb, MethodReference methodReference, String name) { - - if(!collectParameter || !Arrays.asList("where", "andWhere").contains(name)) { + if (!collectParameter || !Arrays.asList("where", "andWhere").contains(name)) { return; } - String value = PsiElementUtils.getMethodParameterAt(methodReference, 0); - if(value != null) { + for (PsiElement parameter : methodReference.getParameters()) { + String value = PsiElementUtils.getMethodParameter(parameter); + if (value == null) { + continue; + } + Matcher matcher = Pattern.compile(":(\\w+)", Pattern.MULTILINE).matcher(value); - while(matcher.find()){ + while (matcher.find()){ qb.addParameter(matcher.group(1)); } } - } /** diff --git a/src/main/java/fr/adrienbrault/idea/symfony2plugin/doctrine/querybuilder/util/MatcherUtil.java b/src/main/java/fr/adrienbrault/idea/symfony2plugin/doctrine/querybuilder/util/MatcherUtil.java index 6f2feef80..419ef4463 100644 --- a/src/main/java/fr/adrienbrault/idea/symfony2plugin/doctrine/querybuilder/util/MatcherUtil.java +++ b/src/main/java/fr/adrienbrault/idea/symfony2plugin/doctrine/querybuilder/util/MatcherUtil.java @@ -63,7 +63,7 @@ public static MethodMatcher.MethodMatchParameter matchJoin(PsiElement psiElement @Nullable public static MethodMatcher.MethodMatchParameter matchWhere(PsiElement psiElement) { - return new MethodMatcher.StringParameterMatcher(psiElement, 0) + return new MethodMatcher.StringParameterMatcher(psiElement) .withSignature("\\Doctrine\\ORM\\QueryBuilder", "andWhere") .withSignature("\\Doctrine\\ORM\\QueryBuilder", "where") .withSignature("\\Doctrine\\ORM\\QueryBuilder", "orWhere") diff --git a/src/main/java/fr/adrienbrault/idea/symfony2plugin/util/MethodMatcher.java b/src/main/java/fr/adrienbrault/idea/symfony2plugin/util/MethodMatcher.java index 4cf1e46f2..13d93b004 100644 --- a/src/main/java/fr/adrienbrault/idea/symfony2plugin/util/MethodMatcher.java +++ b/src/main/java/fr/adrienbrault/idea/symfony2plugin/util/MethodMatcher.java @@ -117,6 +117,10 @@ public StringParameterMatcher(PsiElement psiElement, int parameterIndex) { super(psiElement, parameterIndex); } + public StringParameterMatcher(PsiElement psiElement) { + super(psiElement, -1); + } + @Nullable public MethodMatchParameter match() { @@ -124,7 +128,10 @@ public MethodMatchParameter match() { return null; } - MethodReferenceBag bag = PhpElementsUtil.getMethodParameterReferenceBag(psiElement, this.parameterIndex); + MethodReferenceBag bag = this.parameterIndex >= 0 + ? PhpElementsUtil.getMethodParameterReferenceBag(psiElement, this.parameterIndex) + : PhpElementsUtil.getMethodParameterReferenceBag(psiElement); + if(bag == null) { return null; }