String (PsiClass targetClass, PsiElementFactory elementFactory, PsiType functionalInterfaceType, String parameters) { PsiMethod interfaceMethod = LambdaUtil.getFunctionalInterfaceMethod(functionalInterfaceType); String initialMethodName = interfaceMethod != null ? interfaceMethod.getName() : "name"; return UniqueNameGenerator.generateUniqueName(initialMethodName, methodName -> { String methodText = "private void " + methodName + parameters; PsiMethod patternMethod = elementFactory.createMethodFromText(methodText, targetClass); return targetClass.findMethodBySignature(patternMethod, true) == null; }); }