ReferenceSearcher { public List<Reference> searchReference(File file, int line, int column, String symbol) throws ExecutionException, IOException { if (!file.exists()) { return Collections.emptyList(); } log.trace("search symbol={}", symbol); Optional<SearchCondition> cond = getSource(file).flatMap(src -> getSearchCondition(src, line, column, symbol)); if (!cond.isPresent()) { return Collections.emptyList(); } SearchCondition sc = cond.get(); List<Reference> list = ReferenceSearcher.searchReferences(sc); if (nonNull(list)) { return list; } return Collections.emptyList(); } ReferenceSearcher(Supplier<Project> supplier); List<Reference> searchReference(File file, int line, int column, String symbol);  }
@Test public void testSearchField01() throws Exception { File f = new File(project.getProjectRootPath(), "./src/main/java/meghanada/analyze/BlockScope.java") .getCanonicalFile(); assertTrue(f.exists()); final ReferenceSearcher searcher = getSearcher(); final List<Reference> result = timeIt(() -> searcher.searchReference(f, 145, 45, "scopes")); assertNotNull(result); assertEquals(31, result.size()); }
@Test public void testSearchField02() throws Exception { File f = new File(project.getProjectRootPath(), "./src/main/java/meghanada/reflect/ClassIndex.java") .getCanonicalFile(); assertTrue(f.exists()); final ReferenceSearcher searcher = getSearcher(); final List<Reference> result = timeIt(() -> searcher.searchReference(f, 44, 10, "name")); assertNotNull(result); assertEquals(4, result.size()); }
@Test public void testSearchField03() throws Exception { File f = new File(project.getProjectRootPath(), "./src/main/java/meghanada/analyze/BlockScope.java") .getCanonicalFile(); assertTrue(f.exists()); final ReferenceSearcher searcher = getSearcher(); final List<Reference> result = timeIt(() -> searcher.searchReference(f, 22, 33, "scopes")); assertNotNull(result); assertEquals(31, result.size()); }
@Test public void testSearchField04() throws Exception { File f = new File(project.getProjectRootPath(), "./src/main/java/meghanada/reflect/ClassIndex.java") .getCanonicalFile(); assertTrue(f.exists()); final ReferenceSearcher searcher = getSearcher(); final List<Reference> result = timeIt(() -> searcher.searchReference(f, 21, 30, "ENTITY_TYPE")); assertNotNull(result); assertEquals(12, result.size()); }
@Test public void testSearchMethod01() throws Exception { File f = new File(project.getProjectRootPath(), "./src/main/java/meghanada/utils/FileUtils.java") .getCanonicalFile(); assertTrue(f.exists()); final ReferenceSearcher searcher = getSearcher(); final List<Reference> result = timeIt(() -> searcher.searchReference(f, 443, 22, "formatJavaFile")); assertNotNull(result); assertEquals(1, result.size()); Reference reference = result.get(0); assertEquals(838, reference.getLine()); }
@Test public void testSearchMethod02() throws Exception { File f = new File(project.getProjectRootPath(), "./src/main/java/meghanada/analyze/BlockScope.java") .getCanonicalFile(); assertTrue(f.exists()); final ReferenceSearcher searcher = getSearcher(); final List<Reference> result = timeIt(() -> searcher.searchReference(f, 77, 41, "getCurrentBlock")); assertNotNull(result); assertEquals(3, result.size()); }
@Test public void testSearchMethod03() throws Exception { File f = new File(project.getProjectRootPath(), "./src/main/java/meghanada/analyze/Variable.java") .getCanonicalFile(); assertTrue(f.exists()); final ReferenceSearcher searcher = getSearcher(); final List<Reference> result = timeIt(() -> searcher.searchReference(f, 40, 24, "toStringHelper")); assertNotNull(result); assertEquals(39, result.size()); }
@Test public void testSearchConstructor01() throws Exception { File f = new File( project.getProjectRootPath(), "./src/main/java/meghanada/project/ProjectParseException.java") .getCanonicalFile(); assertTrue(f.exists()); final ReferenceSearcher searcher = getSearcher(); final List<Reference> result = timeIt(() -> searcher.searchReference(f, 9, 9, "ProjectParseException")); assertNotNull(result); assertEquals(4, result.size()); }
@Test public void testSearchClass01() throws Exception { File f = new File(project.getProjectRootPath(), "./src/main/java/meghanada/utils/FileUtils.java") .getCanonicalFile(); assertTrue(f.exists()); final ReferenceSearcher searcher = getSearcher(); final List<Reference> result = timeIt(() -> searcher.searchReference(f, 45, 20, "FileUtils")); assertNotNull(result); assertEquals(67, result.size()); }
@Test public void testManyMethod() throws Exception { File f = new File(project.getProjectRootPath(), "./src/main/java/meghanada/reflect/ClassIndex.java") .getCanonicalFile(); assertTrue(f.exists()); final ReferenceSearcher searcher = getSearcher(); final List<Reference> result = timeIt(() -> searcher.searchReference(f, 86, 47, "toString")); assertNotNull(result); assertEquals(44, result.size()); }
@Test public void testLocalVariable01() throws Exception { File f = new File(project.getProjectRootPath(), "./src/main/java/meghanada/analyze/Scope.java") .getCanonicalFile(); assertTrue(f.exists()); final ReferenceSearcher searcher = getSearcher(); final List<Reference> result = timeIt(() -> searcher.searchReference(f, 61, 16, "scope")); assertNotNull(result); assertEquals(7, result.size()); Reference reference = result.get(0); assertEquals(45, reference.getLine()); }