Search in sources :

Example 1 with SearchManager

use of org.eclipse.che.plugin.java.server.search.SearchManager in project che by eclipse.

the class FindReferencesTest method testSearchCantFindElement.

@Test(expected = SearchException.class)
public void testSearchCantFindElement() throws Exception {
    IPackageFragmentRoot root = ((JavaProject) JUnitSourceSetup.getProject()).getPackageFragmentRoot(new Path(JUnitSourceSetup.SRC_CONTAINER));
    IPackageFragment packageFragment = root.createPackageFragment("che", true, null);
    StringBuilder a = new StringBuilder();
    a.append("package che;\n");
    a.append("public class A{}\n");
    ICompilationUnit compilationUnitA = packageFragment.createCompilationUnit("A.java", a.toString(), true, null);
    SearchManager manager = new SearchManager();
    manager.findUsage(JUnitSourceSetup.getProject(), compilationUnitA.getResource().getFullPath().toOSString(), 24);
}
Also used : Path(org.eclipse.core.runtime.Path) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) JavaProject(org.eclipse.jdt.internal.core.JavaProject) IJavaProject(org.eclipse.jdt.core.IJavaProject) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) SearchManager(org.eclipse.che.plugin.java.server.search.SearchManager) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot) Test(org.junit.Test) BaseTest(org.eclipse.che.plugin.java.server.che.BaseTest)

Example 2 with SearchManager

use of org.eclipse.che.plugin.java.server.search.SearchManager in project che by eclipse.

the class FindReferencesTest method testSearchManagerFindUsage.

@Test
public void testSearchManagerFindUsage() throws Exception {
    IJavaProject aProject = JUnitSourceSetup.getProject();
    IPackageFragmentRoot root = ((JavaProject) aProject).getPackageFragmentRoot(new Path(JUnitSourceSetup.SRC_CONTAINER));
    IPackageFragment packageFragment = root.createPackageFragment("che", true, null);
    StringBuilder a = new StringBuilder();
    a.append("package che;\n");
    a.append("public class A{}\n");
    ICompilationUnit compilationUnitA = packageFragment.createCompilationUnit("A.java", a.toString(), true, null);
    StringBuilder b = new StringBuilder();
    b.append("package che;\n");
    b.append("import java.util.Comparator;\n");
    b.append("import che.A;\n");
    b.append("public class B extends A implements Comparator<A>{\n");
    b.append("   private A a = null;\n");
    b.append("   static{\n");
    b.append("       A ddd = null;\n");
    b.append("   }\n");
    b.append("   @Override\n");
    b.append("   public int compare(A o1, A o2) {\n");
    b.append("       A bb = null;\n");
    b.append("       return 0;\n");
    b.append("   }\n");
    b.append("   class SubB{\n");
    b.append("     public A ccc = null;\n");
    b.append("   }\n");
    b.append("}\n");
    b.append("class SubB2{\n");
    b.append("    private final A foo = null;\n");
    b.append("}\n");
    packageFragment.createCompilationUnit("B.java", b.toString(), true, null);
    SearchManager manager = new SearchManager();
    FindUsagesResponse response = manager.findUsage(aProject, "che.A", 26);
    Assertions.assertThat(response.getSearchElementLabel()).isEqualTo("A");
    List<org.eclipse.che.ide.ext.java.shared.dto.model.JavaProject> projects = response.getProjects();
    Assertions.assertThat(projects).isNotNull().isNotEmpty().hasSize(1);
    String expectedProjectPath = JUnitSourceSetup.getProject().getPath().toOSString();
    org.eclipse.che.ide.ext.java.shared.dto.model.JavaProject project = projects.get(0);
    Assertions.assertThat(project.getName()).isEqualTo(JUnitSourceSetup.PROJECT_NAME);
    Assertions.assertThat(project.getPath()).isEqualTo(expectedProjectPath);
    Assertions.assertThat(project.getPackageFragmentRoots()).isNotNull().isNotEmpty().hasSize(1);
    PackageFragmentRoot fragmentRoot = project.getPackageFragmentRoots().get(0);
    Assertions.assertThat(fragmentRoot.getElementName()).isEqualTo(JUnitSourceSetup.SRC_CONTAINER);
    Assertions.assertThat(fragmentRoot.getProjectPath()).isEqualTo(expectedProjectPath);
    Assertions.assertThat(fragmentRoot.getPackageFragments()).isNotNull().isNotEmpty().hasSize(1);
    PackageFragment fragment = fragmentRoot.getPackageFragments().get(0);
    Assertions.assertThat(fragment.getElementName()).isEqualTo("che");
    Assertions.assertThat(fragment.getProjectPath()).isEqualTo(expectedProjectPath);
    Assertions.assertThat(fragment.getPath()).isEqualTo(expectedProjectPath + "/" + JUnitSourceSetup.SRC_CONTAINER + "/che");
    Assertions.assertThat(fragment.getClassFiles()).isNotNull().isEmpty();
    Assertions.assertThat(fragment.getCompilationUnits()).isNotNull().isNotEmpty().hasSize(1);
    CompilationUnit compilationUnit = fragment.getCompilationUnits().get(0);
    Assertions.assertThat(compilationUnit.getElementName()).isEqualTo("B.java");
    Assertions.assertThat(compilationUnit.getPath()).isEqualTo(expectedProjectPath + "/" + JUnitSourceSetup.SRC_CONTAINER + "/che/B.java");
    Assertions.assertThat(compilationUnit.getImports()).hasSize(1);
    Assertions.assertThat(compilationUnit.getTypes()).hasSize(2);
}
Also used : Path(org.eclipse.core.runtime.Path) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) CompilationUnit(org.eclipse.che.ide.ext.java.shared.dto.model.CompilationUnit) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) PackageFragment(org.eclipse.che.ide.ext.java.shared.dto.model.PackageFragment) JavaProject(org.eclipse.jdt.internal.core.JavaProject) IJavaProject(org.eclipse.jdt.core.IJavaProject) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) PackageFragmentRoot(org.eclipse.che.ide.ext.java.shared.dto.model.PackageFragmentRoot) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot) FindUsagesResponse(org.eclipse.che.ide.ext.java.shared.dto.search.FindUsagesResponse) SearchManager(org.eclipse.che.plugin.java.server.search.SearchManager) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot) IJavaProject(org.eclipse.jdt.core.IJavaProject) Test(org.junit.Test) BaseTest(org.eclipse.che.plugin.java.server.che.BaseTest)

Aggregations

BaseTest (org.eclipse.che.plugin.java.server.che.BaseTest)2 SearchManager (org.eclipse.che.plugin.java.server.search.SearchManager)2 Path (org.eclipse.core.runtime.Path)2 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)2 IJavaProject (org.eclipse.jdt.core.IJavaProject)2 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)2 IPackageFragmentRoot (org.eclipse.jdt.core.IPackageFragmentRoot)2 JavaProject (org.eclipse.jdt.internal.core.JavaProject)2 Test (org.junit.Test)2 CompilationUnit (org.eclipse.che.ide.ext.java.shared.dto.model.CompilationUnit)1 PackageFragment (org.eclipse.che.ide.ext.java.shared.dto.model.PackageFragment)1 PackageFragmentRoot (org.eclipse.che.ide.ext.java.shared.dto.model.PackageFragmentRoot)1 FindUsagesResponse (org.eclipse.che.ide.ext.java.shared.dto.search.FindUsagesResponse)1