JavaVariableCompletion { @SuppressWarnings("try") public Optional<LocalVariable> localVariable(final File file, final int line) throws ExecutionException, IOException { try (TelemetryUtils.ScopedSpan scope = TelemetryUtils.startScopedSpan("JavaVariableCompletion.localVariable")) { final Source source = JavaVariableCompletion.getSource(file); return source .getExpressionReturn(line) .filter(as -> as.returnType != null) .flatMap(as -> createLocalVariable(as, as.returnType)); } } JavaVariableCompletion(final Supplier<Project> supplier); @SuppressWarnings("try") Optional<LocalVariable> localVariable(final File file, final int line);  }
@Test public void localVariable() throws Exception { JavaVariableCompletion completion = getCompilation(); File file = new File(project.getProjectRootPath(), "./src/test/java/meghanada/Gen1.java"); Optional<LocalVariable> olv = timeIt( () -> { return completion.localVariable(file, 24); }); LocalVariable lv = olv.get(); System.out.println(lv); assertEquals("java.lang.String", lv.getReturnFQCN()); assertEquals(4, lv.getCandidates().size()); }