void (@NotNull PsiMethodReferenceExpression expression) { PsiElement qualifier = expression.getQualifier(); PsiType interfaceType = expression.getFunctionalInterfaceType(); if (!Registry.is("debugger.compiling.evaluator.method.refs") && interfaceType != null && qualifier != null) { String code = null; try { PsiElement resolved = expression.resolve(); if (resolved instanceof PsiMethod method) { PsiClass containingClass = method.getContainingClass(); if (containingClass != null) { String find; boolean bind = false; if (method.isConstructor()) { find = "findConstructor(" + containingClass.getQualifiedName() + ".class, mt)"; } else if (qualifier instanceof PsiSuperExpression) { find = "in(" + containingClass.getQualifiedName() + ".class).findSpecial(" + containingClass.getQualifiedName() + ".class, \"" + method.getName() + "\", mt, " + containingClass.getQualifiedName() + ".class)"; bind = true; } else { find = containingClass.getQualifiedName() + ".class, \"" + method.getName() + "\", mt)"; if (method.hasModifier(JvmModifier.STATIC)) { find = "findStatic(" + find; } else { find = "findVirtual(" + find; if (qualifier instanceof PsiReference) { PsiElement resolve = ((PsiReference)qualifier).resolve(); if (!(resolve instanceof PsiClass)) { bind = true; } } else { bind = true; } } } String bidStr = bind ? "mh = mh.bindTo(" + qualifier.getText() + ");\n" : ""; code = "MethodType mt = MethodType.fromMethodDescriptorString(\"" + JVMNameUtil.getJVMSignature(method) + "\", null);\n" + "MethodHandle mh = MethodHandles.lookup()." + find + ";\n" + bidStr + "MethodHandleProxies.asInterfaceInstance(" + interfaceType.getCanonicalText() + ".class, mh);"; } } else if (PsiUtil.isArrayClass(resolved)) { code = "MethodType mt = MethodType.methodType(Object.class, Class.class, int.class);\n" + "MethodHandle mh = MethodHandles.publicLookup().findStatic(Array.class, \"newInstance\", mt);\n" + "mh = mh.bindTo(" + StringUtil.substringBeforeLast(qualifier.getText(), "[]") + ".class)\n" + "MethodHandleProxies.asInterfaceInstance(" + interfaceType.getCanonicalText() + ".class, mh);"; } if (code != null) { myResult = buildFromJavaCode(code, "java.lang.invoke.MethodHandle," + "java.lang.invoke.MethodHandleProxies," + "java.lang.invoke.MethodHandles," + "java.lang.invoke.MethodType," + "java.lang.reflect.Array", expression); return; } } catch (Exception e) { LOG.error(e); } } throw new EvaluateRuntimeException( new UnsupportedExpressionException(JavaDebuggerBundle.message("evaluation.error.method.reference.evaluation.not.supported"))); }