void (PsiElement ref, PsiNewExpression newExpression) { PsiElement tmp; final PsiClass javaUtilCollectionClass = JavaPsiFacade.getInstance(myManager.getProject()).findClass("java.util.Collection", ref.getResolveScope()); if (javaUtilCollectionClass == null) return; tmp = newExpression.getParent(); if (!(tmp instanceof PsiExpressionList)) return; tmp = tmp.getParent(); if (!(tmp instanceof PsiMethodCallExpression methodCall)) return; tmp = tmp.getParent(); if (!(tmp instanceof PsiTypeCastExpression typeCast)) return; PsiReferenceExpression methodRef = methodCall.getMethodExpression(); tmp = methodRef.resolve(); if (!(tmp instanceof PsiMethod method)) return; @NonNls final String name = method.getName(); if (!name.equals("toArray")) return; PsiClass methodClass = method.getContainingClass(); if (!methodClass.isInheritor(javaUtilCollectionClass, true)) return; // ok, this is an implementation of java.util.Collection.toArray addLink(typeCast, ref); }