"""Go to Definition on a method reference, against a real JDT LS. Arguments: jdtls home, optional bundle jar.
Each case puts the caret on a method reference's name and checks that
`openidea.java.methodReferenceDefinition` answers the referenced method's declaration (an inherited
method on its parent, not the functional interface method), and nothing elsewhere.
"""
import json
import pathlib
import platform
import queue
import subprocess
import sys
import tempfile
import threading
import time
home = pathlib.Path(sys.argv[1]).resolve()
bundle = pathlib.Path(sys.argv[2]).resolve() if len(sys.argv) > 2 else pathlib.Path(__file__).resolve().parents[1] / 'openidea-java-usages.jar'
work = pathlib.Path(tempfile.mkdtemp(prefix='openidea-method-reference-'))
config = work / 'config'
config.mkdir()
system, machine = platform.system(), platform.machine().lower()
config_name = {'Windows': 'config_win', 'Darwin': 'config_mac'}.get(system, 'config_linux')
config_names = ([config_name + '_arm'] if machine in ('arm64', 'aarch64') else []) + [config_name]
config_source = next(home / name / 'config.ini' for name in config_names if (home / name / 'config.ini').is_file())
(config / 'config.ini').write_bytes(config_source.read_bytes())
project = work / 'project'
(project / 'src/app').mkdir(parents=True)
(project / '.project').write_text('apporg.eclipse.jdt.core.javabuilderorg.eclipse.jdt.core.javanature')
(project / '.classpath').write_text('')
sources = {
'Parent.java': '''package app;
public class Parent {
public String getGoodsSpace() {
return "space";
}
public static String describe(Object o) {
return String.valueOf(o);
}
}
''',
'Child.java': '''package app;
public class Child extends Parent {
public int own() {
return 1;
}
}
''',
'Main.java': '''package app;
import java.util.List;
import java.util.function.Function;
public class Main {
void run(List children) {
Function inherited = Child::getGoodsSpace;
Function own = Child::own;
Function