JavaVariableCompletion { @SuppressWarnings("try") Optional<LocalVariable> createLocalVariable( final AccessSymbol accessSymbol, final String returnType) { try (TelemetryUtils.ScopedSpan scope = TelemetryUtils.startScopedSpan("JavaVariableCompletion.createLocalVariable")) { if (returnType.equals("void")) { return Optional.of(new LocalVariable(returnType, new ArrayList<>(0))); } final List<String> candidates = new ArrayList<>(4); final List<String> fromTypes = this.fromType(returnType); candidates.addAll(fromTypes); final List<String> fromNames = this.fromName(accessSymbol); candidates.addAll(fromNames); if (returnType.startsWith("java.lang") || ClassNameUtils.isPrimitive(returnType)) { final String initial = fromInitial(returnType); candidates.add(initial); } final List<String> results = candidates.stream().map(s -> removeMatcher.removeFrom(s)).collect(Collectors.toList()); return Optional.of(new LocalVariable(returnType, results)); } } JavaVariableCompletion(final Supplier<Project> supplier); @SuppressWarnings("try") Optional<LocalVariable> localVariable(final File file, final int line);  }
@Test public void createLocalVariable1() throws Exception { JavaVariableCompletion completion = getCompilation(); Optional<LocalVariable> olv = debugIt( () -> { final Range range = new Range(0, 0, 0, 0); final Range nameRange = new Range(0, 0, 0, 0); final MethodCall mc = new MethodCall("mkdir", 0, nameRange, range); return completion.createLocalVariable(mc, "boolean"); }); LocalVariable lv = olv.get(); System.out.println(lv); assertEquals(2, lv.getCandidates().size()); }
@Test public void createLocalVariable2() throws Exception { JavaVariableCompletion completion = getCompilation(); Optional<LocalVariable> olv = timeIt( () -> { final Range range = new Range(0, 0, 0, 0); final Range nameRange = new Range(0, 0, 0, 0); final MethodCall mc = new MethodCall("file", "getFileName", 0, nameRange, range); return completion.createLocalVariable(mc, "String"); }); LocalVariable lv = olv.get(); System.out.println(lv); assertEquals(4, lv.getCandidates().size()); }
@Test public void createLocalVariable3() throws Exception { JavaVariableCompletion completion = getCompilation(); Optional<LocalVariable> olv = timeIt( () -> { final Range range = new Range(0, 0, 0, 0); final Range nameRange = new Range(0, 0, 0, 0); final MethodCall mc = new MethodCall("list", "subList", 0, nameRange, range); return completion.createLocalVariable(mc, "java.util.List<String>"); }); LocalVariable lv = olv.get(); System.out.println(lv); assertEquals(5, lv.getCandidates().size()); }
@Test public void createLocalVariable4() throws Exception { JavaVariableCompletion completion = getCompilation(); Optional<LocalVariable> olv = timeIt( () -> { final Range range = new Range(0, 0, 0, 0); final Range nameRange = new Range(0, 0, 0, 0); final MethodCall mc = new MethodCall("list", "subList", 0, nameRange, range); return completion.createLocalVariable(mc, "java.util.List<MemberDescriptor>"); }); LocalVariable lv = olv.get(); System.out.println(lv); assertEquals(6, lv.getCandidates().size()); }
@Test public void createLocalVariable5() throws Exception { JavaVariableCompletion completion = getCompilation(); Optional<LocalVariable> olv = timeIt( () -> { final Range range = new Range(0, 0, 0, 0); final Range nameRange = new Range(0, 0, 0, 0); final MethodCall mcs = new MethodCall("parser", "parse", 0, nameRange, range); return completion.createLocalVariable(mcs, "org.apache.commons.cli.CommandLine"); }); LocalVariable lv = olv.get(); System.out.println(lv); assertEquals(4, lv.getCandidates().size()); }