public static PsiElement findArrayKeyValueInsideReference( PsiElement psiElement, String methodReferenceName, String keyName) { if (psiElement == null) { return null; } Collection<MethodReference> tests = PsiTreeUtil.findChildrenOfType(psiElement, MethodReference.class); for (MethodReference methodReference : tests) { // instance check // methodReference.getSignature().equals("#M#C\\Symfony\\Component\\OptionsResolver\\OptionsResolverInterface.setDefaults") if (PhpElementsUtil.isEqualMethodReferenceName(methodReference, methodReferenceName)) { PsiElement[] parameters = methodReference.getParameters(); if (parameters.length > 0 && parameters[0] instanceof ArrayCreationExpression) { PsiElement keyValue = PhpElementsUtil.getArrayValue((ArrayCreationExpression) parameters[0], keyName); if (keyValue != null) { return keyValue; } } } } return null; }
@Nullable public static PsiElement getArrayKeyValueInsideSignaturePsi( Project project, String signature, String methodName, String keyName) { PsiElement psiElement = PhpElementsUtil.getPsiElementsBySignatureSingle(project, signature); if (psiElement == null) { return null; } for (MethodReference methodReference : PsiTreeUtil.findChildrenOfType(psiElement, MethodReference.class)) { if (PhpElementsUtil.isEqualMethodReferenceName(methodReference, methodName)) { PsiElement[] parameters = methodReference.getParameters(); if (parameters.length > 0 && parameters[0] instanceof ArrayCreationExpression) { return PhpElementsUtil.getArrayValue((ArrayCreationExpression) parameters[0], keyName); } } } return null; }