JavaImportCompletion { public Optional<Map<String, List<String>>> importAtPoint( final File file, final int line, final int column, final String symbol) throws ExecutionException, IOException { if (!file.exists()) { return Optional.empty(); } return FileUtils.getSource(file).flatMap(src -> execFunctions(src, line, column, symbol)); } JavaImportCompletion(Supplier<Project> supplier); Optional<Map<String, List<String>>> importAtPoint(
      final File file, final int line, final int column, final String symbol);  }
@Ignore @Test public void testImportAtPoint1() throws IOException, ExecutionException { JavaImportCompletion completion = new JavaImportCompletion(GradleTestBase::getProject); File file = new File(project.getProjectRootPath(), "./src/test/java/meghanada/TopClass.java") .getCanonicalFile(); assertTrue(file.exists()); Optional<Map<String, List<String>>> res = completion.importAtPoint(file, 13, 13, "String"); assertFalse(res.isPresent()); }
@Ignore @Test public void testImportAtPoint2() throws IOException, ExecutionException { JavaImportCompletion completion = new JavaImportCompletion(GradleTestBase::getProject); File file = new File(project.getProjectRootPath(), "./src/test/resources/meghanada/AnnoTest2.java") .getCanonicalFile(); assertTrue(file.exists()); Optional<Map<String, List<String>>> res = completion.importAtPoint(file, 10, 2, "RunWith"); assertTrue(res.isPresent()); Map<String, List<String>> map = res.get(); assertEquals(1, map.get("class").size()); System.out.println(map); }
@Ignore @Test public void testImportAtPoint3() throws Exception { JavaAnalyzer analyzer = getAnalyzer(); JavaImportCompletion completion = new JavaImportCompletion(GradleTestBase::getProject); String cp = getClasspath(); List<File> files = new ArrayList<>(); File file = new File(project.getProjectRootPath(), "./src/test/resources/MissingImport5.java") .getCanonicalFile(); assertTrue(file.exists()); files.add(file); String tmp = System.getProperty("java.io.tmpdir"); CompileResult compileResult = analyzer.analyzeAndCompile(files, cp, tmp, false); Optional<Map<String, List<String>>> res = completion.importAtPoint(file, 5, 5, "assertEquals"); assertTrue(res.isPresent()); List<String> methods = res.get().get("method"); System.out.println(methods); assertEquals(3, methods.size()); }
@Ignore @Test public void testImportAtPoint4() throws Exception { JavaAnalyzer analyzer = getAnalyzer(); JavaImportCompletion completion = new JavaImportCompletion(GradleTestBase::getProject); String cp = getClasspath(); File file = new File(project.getProjectRootPath(), "./src/test/resources/MissingImport5.java") .getCanonicalFile(); assertTrue(file.exists()); Optional<Map<String, List<String>>> map = completion.importAtPoint(file, 0, 0, "CASE_INSENSITIVE_ORDER"); assertTrue(map.isPresent()); System.out.println(map.get()); }
@Ignore @Test public void testImportAtPoint5() throws Exception { JavaAnalyzer analyzer = getAnalyzer(); JavaImportCompletion completion = new JavaImportCompletion(GradleTestBase::getProject); String cp = getClasspath(); File file = new File(project.getProjectRootPath(), "./src/test/resources/MissingImport6.java") .getCanonicalFile(); assertTrue(file.exists()); Optional<Map<String, List<String>>> map = completion.importAtPoint(file, 4, 5, "timeIt"); assertTrue(map.isPresent()); System.out.println(map.get()); }