1111import fr .adrienbrault .idea .symfony2plugin .doctrine .querybuilder .dict .QueryBuilderPropertyAlias ;
1212import fr .adrienbrault .idea .symfony2plugin .doctrine .querybuilder .dict .QueryBuilderRelation ;
1313import fr .adrienbrault .idea .symfony2plugin .doctrine .querybuilder .util .MatcherUtil ;
14+ import fr .adrienbrault .idea .symfony2plugin .doctrine .querybuilder .util .QueryBuilderUtil ;
1415import fr .adrienbrault .idea .symfony2plugin .util .MethodMatcher ;
1516import fr .adrienbrault .idea .symfony2plugin .util .PhpElementsUtil ;
1617import org .apache .commons .lang .StringUtils ;
18+ import org .jetbrains .annotations .NotNull ;
1719import org .jetbrains .annotations .Nullable ;
1820
1921import java .util .ArrayList ;
@@ -27,26 +29,56 @@ public class QueryBuilderGotoDeclarationHandler implements GotoDeclarationHandle
2729
2830 @ Nullable
2931 @ Override
30- public PsiElement [] getGotoDeclarationTargets (PsiElement psiElement , int i , Editor editor ) {
32+ public PsiElement [] getGotoDeclarationTargets (PsiElement psiElement , int offset , Editor editor ) {
3133
3234 if (!Symfony2ProjectComponent .isEnabled (psiElement ) || !(psiElement .getContext () instanceof StringLiteralExpression )) {
3335 return new PsiElement [0 ];
3436 }
3537
3638 List <PsiElement > psiElements = new ArrayList <>();
3739
38- attachPropertyGoto ((StringLiteralExpression ) psiElement .getContext (), psiElements );
39- attachJoinGoto ((StringLiteralExpression ) psiElement .getContext (), psiElements );
40+ StringLiteralExpression context = (StringLiteralExpression ) psiElement .getContext ();
41+ attachPropertyGoto (context , psiElements );
42+ attachJoinGoto (context , psiElements );
43+ attachPartialGoto (context , psiElements , offset );
4044
4145 // $qb->expr()->in('')
42- attachExprGoto (( StringLiteralExpression ) psiElement . getContext () , psiElements );
46+ attachExprGoto (context , psiElements );
4347
4448 // $qb->from('', '', '<foo>');
45- attachFromIndexGoto (( StringLiteralExpression ) psiElement . getContext () , psiElements );
49+ attachFromIndexGoto (context , psiElements );
4650
4751 return psiElements .toArray (new PsiElement [psiElements .size ()]);
4852 }
4953
54+ private void attachPartialGoto (@ NotNull StringLiteralExpression psiElement , @ NotNull List <PsiElement > targets , int offset ) {
55+ MethodMatcher .MethodMatchParameter methodMatchParameter = MatcherUtil .matchWhere (psiElement );
56+ if (methodMatchParameter == null ) {
57+ return ;
58+ }
59+
60+ int calulatedOffset = offset - psiElement .getTextRange ().getStartOffset ();
61+ if (calulatedOffset < 0 ) {
62+ calulatedOffset = 0 ;
63+ }
64+
65+ String contents = psiElement .getContents ();
66+ String fieldString = QueryBuilderUtil .getFieldString (contents , calulatedOffset );
67+ if (fieldString != null ) {
68+ QueryBuilderMethodReferenceParser qb = QueryBuilderCompletionContributor .getQueryBuilderParser (methodMatchParameter .getMethodReference ());
69+ if (qb == null ) {
70+ return ;
71+ }
72+
73+ QueryBuilderScopeContext collect = qb .collect ();
74+ for (Map .Entry <String , QueryBuilderPropertyAlias > entry : collect .getPropertyAliasMap ().entrySet ()) {
75+ if (entry .getKey ().equals (fieldString )) {
76+ targets .addAll (entry .getValue ().getPsiTargets ());
77+ }
78+ }
79+ }
80+ }
81+
5082 private void attachJoinGoto (StringLiteralExpression psiElement , List <PsiElement > targets ) {
5183
5284 MethodMatcher .MethodMatchParameter methodMatchParameter = MatcherUtil .matchJoin (psiElement );
@@ -76,11 +108,8 @@ private void attachJoinGoto(StringLiteralExpression psiElement, List<PsiElement>
76108 if (phpClass != null ) {
77109 targets .add (phpClass );
78110 }
79-
80111 }
81112 }
82-
83-
84113 }
85114
86115 private void attachPropertyGoto (StringLiteralExpression psiElement , List <PsiElement > targets ) {
0 commit comments