DeclarationSearcher { public Optional<Declaration> searchDeclaration(File file, int line, int column, String symbol) throws ExecutionException, IOException { if (!file.exists()) { return Optional.empty(); } log.trace("search symbol={}", symbol); return getSource(file).flatMap(src -> execFunctions(src, line, column, symbol)); } DeclarationSearcher(final Supplier<Project> supplier); Optional<Declaration> searchDeclaration(File file, int line, int column, String symbol);  }
@Test public void testMethodDeclaration01() throws Exception { File f = new File( project.getProjectRootPath(), "./src/main/java/meghanada/server/emacs/EmacsServer.java") .getCanonicalFile(); assertTrue(f.exists()); final DeclarationSearcher searcher = getSearcher(); final Optional<Declaration> result = debugIt(() -> searcher.searchDeclaration(f, 56, 45, "getByName")); assertNotNull(result); assertTrue(result.isPresent()); result.ifPresent( declaration -> { assertEquals("InetAddress.getByName", declaration.scopeInfo); }); }
@Test public void testMethodDeclaration02() throws Exception { File f = new File( project.getProjectRootPath(), "./src/main/java/meghanada/server/emacs/EmacsServer.java") .getCanonicalFile(); assertTrue(f.exists()); final DeclarationSearcher searcher = getSearcher(); final Optional<Declaration> result = debugIt(() -> searcher.searchDeclaration(f, 414, 10, "submit")); assertNotNull(result); assertTrue(result.isPresent()); result.ifPresent( declaration -> { assertEquals("submit.submit", declaration.scopeInfo); assertEquals("public Future<?> submit(Runnable arg0)", declaration.signature); }); }
@Test public void testMethodDeclaration03() throws Exception { File f = new File( project.getProjectRootPath(), "./src/main/java/meghanada/server/emacs/EmacsServer.java") .getCanonicalFile(); assertTrue(f.exists()); final DeclarationSearcher searcher = getSearcher(); final Optional<Declaration> result = debugIt(() -> searcher.searchDeclaration(f, 414, 24, "BufferedReader")); assertNotNull(result); assertTrue(result.isPresent()); result.ifPresent( declaration -> { assertEquals("BufferedReader", declaration.scopeInfo); }); }
@Test public void testMethodDeclaration04() throws Exception { File f = new File( project.getProjectRootPath(), "./src/main/java/meghanada/server/emacs/EmacsServer.java") .getCanonicalFile(); assertTrue(f.exists()); final DeclarationSearcher searcher = getSearcher(); final Optional<Declaration> result = debugIt(() -> searcher.searchDeclaration(f, 422, 57, "getOutputFormatter")); assertNotNull(result); assertTrue(result.isPresent()); result.ifPresent( declaration -> { assertEquals("getOutputFormatter", declaration.scopeInfo); assertEquals("private OutputFormatter getOutputFormatter()", declaration.signature); assertEquals(2, declaration.argumentIndex); }); }
@Test public void testClassDeclaration01() throws Exception { File f = new File( project.getProjectRootPath(), "./src/main/java/meghanada/server/emacs/EmacsServer.java") .getCanonicalFile(); assertTrue(f.exists()); final DeclarationSearcher searcher = getSearcher(); final Optional<Declaration> result = debugIt( () -> { return searcher.searchDeclaration(f, 31, 20, "ServerSocket"); }); assertNotNull(result); assertTrue(result.isPresent()); result.ifPresent( declaration -> { assertEquals("ServerSocket", declaration.scopeInfo); assertEquals("java.net.ServerSocket", declaration.signature); }); }
@Test public void testClassDeclaration03() throws Exception { File f = new File( project.getProjectRootPath(), "./src/main/java/meghanada/server/emacs/EmacsServer.java") .getCanonicalFile(); assertTrue(f.exists()); final DeclarationSearcher searcher = getSearcher(); final Optional<Declaration> result = timeIt( () -> { return searcher.searchDeclaration(f, 37, 19, "OUTPUT"); }); assertNotNull(result); assertTrue(result.isPresent()); result.ifPresent( declaration -> { assertEquals("OUTPUT", declaration.scopeInfo); assertEquals("meghanada.server.emacs.EmacsServer$OUTPUT", declaration.signature); }); }
@Test public void testClassDeclaration02() throws Exception { File f = new File( project.getProjectRootPath(), "./src/main/java/meghanada/server/emacs/EmacsServer.java") .getCanonicalFile(); assertTrue(f.exists()); final DeclarationSearcher searcher = getSearcher(); final Optional<Declaration> result = timeIt(() -> searcher.searchDeclaration(f, 61, 32, "SEXP")); assertNotNull(result); assertTrue(result.isPresent()); result.ifPresent( declaration -> { assertEquals("OUTPUT.SEXP", declaration.scopeInfo); assertEquals("meghanada.server.emacs.EmacsServer$OUTPUT", declaration.signature); }); }
@Test public void testVar01() throws Exception { File f = new File( project.getProjectRootPath(), "./src/main/java/meghanada/server/emacs/EmacsServer.java") .getCanonicalFile(); assertTrue(f.exists()); final DeclarationSearcher searcher = getSearcher(); final Optional<Declaration> result = timeIt(() -> searcher.searchDeclaration(f, 59, 55, "address")); assertNotNull(result); assertTrue(result.isPresent()); result.ifPresent( declaration -> { assertEquals("address", declaration.scopeInfo); assertEquals("java.net.InetAddress", declaration.signature); assertEquals(2, declaration.argumentIndex); }); }
@Test public void testVar02() throws Exception { File f = new File( project.getProjectRootPath(), "./src/main/java/meghanada/server/emacs/EmacsServer.java") .getCanonicalFile(); assertTrue(f.exists()); final DeclarationSearcher searcher = getSearcher(); final Optional<Declaration> result = timeIt(() -> searcher.searchDeclaration(f, 59, 48, "0")); assertNotNull(result); assertTrue(result.isPresent()); result.ifPresent( declaration -> { assertEquals("0", declaration.scopeInfo); assertEquals("java.lang.Integer", declaration.signature); assertEquals(1, declaration.argumentIndex); }); }
@Test public void testVar03() throws Exception { File f = new File( project.getProjectRootPath(), "./src/main/java/meghanada/server/emacs/EmacsServer.java") .getCanonicalFile(); assertTrue(f.exists()); final DeclarationSearcher searcher = getSearcher(); final Optional<Declaration> result = timeIt(() -> searcher.searchDeclaration(f, 421, 38, "handler")); assertNotNull(result); assertTrue(result.isPresent()); result.ifPresent( declaration -> { assertEquals("handler", declaration.scopeInfo); assertEquals("meghanada.server.CommandHandler", declaration.signature); assertEquals(-1, declaration.argumentIndex); }); }