Search in sources :

Example 1 with JavaProject

use of org.eclipse.che.ide.ext.java.shared.dto.model.JavaProject in project che by eclipse.

the class MovePresenterTest method moveWizardShouldBeShowed.

@Test
public void moveWizardShouldBeShowed() throws Exception {
    List<JavaProject> javaProjects = new ArrayList<>();
    JavaProject javaProject = Mockito.mock(JavaProject.class);
    javaProjects.add(javaProject);
    when(refactorInfo.getResources()).thenReturn(new Resource[] { file });
    when(file.getParentWithMarker(eq(SourceFolderMarker.ID))).thenReturn(Optional.of(srcFolder));
    when(file.getLocation()).thenReturn(Path.valueOf("/project/src/a/b/C.java"));
    when(file.getName()).thenReturn("C.java");
    when(file.getExtension()).thenReturn("java");
    when(srcFolder.getLocation()).thenReturn(Path.valueOf("/project/src"));
    when(file.getResourceType()).thenReturn(Resource.FILE);
    when(file.getRelatedProject()).thenReturn(Optional.of(relatedProject));
    when(relatedProject.getLocation()).thenReturn(Path.valueOf("/project"));
    presenter.show(refactorInfo);
    verify(sessionPromise).then(sessionOperation.capture());
    sessionOperation.getValue().apply("sessionId");
    verify(projectsPromise).then(projectsOperation.capture());
    projectsOperation.getValue().apply(javaProjects);
    verify(moveView).setTreeOfDestinations(any());
    verify(moveView).show(refactorInfo);
}
Also used : JavaProject(org.eclipse.che.ide.ext.java.shared.dto.model.JavaProject) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 2 with JavaProject

use of org.eclipse.che.ide.ext.java.shared.dto.model.JavaProject in project che by eclipse.

the class JavaNavigation method getAllProjectsAndPackages.

public List<JavaProject> getAllProjectsAndPackages(boolean includePackages) throws JavaModelException {
    JavaModel javaModel = JavaModelManager.getJavaModelManager().getJavaModel();
    IJavaProject[] javaProjects = javaModel.getJavaProjects();
    List<JavaProject> result = new ArrayList<>();
    for (IJavaProject javaProject : javaProjects) {
        if (javaProject.exists()) {
            JavaProject project = DtoFactory.newDto(JavaProject.class);
            project.setName(javaProject.getElementName());
            project.setPath(javaProject.getPath().toOSString());
            project.setPackageFragmentRoots(toPackageRoots(javaProject, includePackages));
            result.add(project);
        }
    }
    return result;
}
Also used : IJavaProject(org.eclipse.jdt.core.IJavaProject) JavaProject(org.eclipse.che.ide.ext.java.shared.dto.model.JavaProject) IJavaProject(org.eclipse.jdt.core.IJavaProject) JavaModel(org.eclipse.jdt.internal.core.JavaModel) ArrayList(java.util.ArrayList)

Example 3 with JavaProject

use of org.eclipse.che.ide.ext.java.shared.dto.model.JavaProject in project che by eclipse.

the class SearchManager method performFindUsageSearch.

private FindUsagesResponse performFindUsageSearch(IJavaElement element) throws JavaModelException, BadLocationException {
    JavaSearchScopeFactory factory = JavaSearchScopeFactory.getInstance();
    boolean isInsideJRE = factory.isInsideJRE(element);
    JavaSearchQuery query = new JavaSearchQuery(new ElementQuerySpecification(element, IJavaSearchConstants.REFERENCES, factory.createWorkspaceScope(isInsideJRE), "workspace scope"));
    NewSearchUI.runQueryInForeground(null, query);
    ISearchResult result = query.getSearchResult();
    JavaSearchResult javaResult = ((JavaSearchResult) result);
    FindUsagesResponse response = DtoFactory.newDto(FindUsagesResponse.class);
    Map<String, List<org.eclipse.che.ide.ext.java.shared.dto.search.Match>> mapMaches = new HashMap<>();
    JavaElementToDtoConverter converter = new JavaElementToDtoConverter(javaResult);
    for (Object o : javaResult.getElements()) {
        IJavaElement javaElement = (IJavaElement) o;
        IDocument document = null;
        if (javaElement instanceof IMember) {
            IMember member = ((IMember) javaElement);
            if (member.isBinary()) {
                if (member.getClassFile().getSource() != null) {
                    document = new Document(member.getClassFile().getSource());
                }
            } else {
                document = getDocument(member.getCompilationUnit());
            }
        } else if (javaElement instanceof IPackageDeclaration) {
            ICompilationUnit ancestor = (ICompilationUnit) (javaElement).getAncestor(IJavaElement.COMPILATION_UNIT);
            document = getDocument(ancestor);
        }
        converter.addElementToProjectHierarchy(javaElement);
        Match[] matches = javaResult.getMatches(o);
        List<org.eclipse.che.ide.ext.java.shared.dto.search.Match> matchList = new ArrayList<>();
        for (Match match : matches) {
            org.eclipse.che.ide.ext.java.shared.dto.search.Match dtoMatch = DtoFactory.newDto(org.eclipse.che.ide.ext.java.shared.dto.search.Match.class);
            if (document != null) {
                IRegion lineInformation = document.getLineInformationOfOffset(match.getOffset());
                int offsetInLine = match.getOffset() - lineInformation.getOffset();
                Region matchInLine = DtoFactory.newDto(Region.class).withOffset(offsetInLine).withLength(match.getLength());
                dtoMatch.setMatchInLine(matchInLine);
                dtoMatch.setMatchLineNumber(document.getLineOfOffset(match.getOffset()));
                dtoMatch.setMatchedLine(document.get(lineInformation.getOffset(), lineInformation.getLength()));
            }
            dtoMatch.setFileMatchRegion(DtoFactory.newDto(Region.class).withOffset(match.getOffset()).withLength(match.getLength()));
            matchList.add(dtoMatch);
        }
        mapMaches.put(javaElement.getHandleIdentifier(), matchList);
    }
    List<JavaProject> projects = converter.getProjects();
    response.setProjects(projects);
    response.setMatches(mapMaches);
    response.setSearchElementLabel(JavaElementLabels.getElementLabel(element, JavaElementLabels.ALL_DEFAULT));
    return response;
}
Also used : ISearchResult(org.eclipse.search.ui.ISearchResult) FindUsagesResponse(org.eclipse.che.ide.ext.java.shared.dto.search.FindUsagesResponse) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument) IMember(org.eclipse.jdt.core.IMember) IRegion(org.eclipse.jface.text.IRegion) Match(org.eclipse.search.ui.text.Match) JavaSearchResult(org.eclipse.jdt.internal.ui.search.JavaSearchResult) ArrayList(java.util.ArrayList) List(java.util.List) JavaSearchScopeFactory(org.eclipse.jdt.internal.ui.search.JavaSearchScopeFactory) IJavaElement(org.eclipse.jdt.core.IJavaElement) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) JavaProject(org.eclipse.che.ide.ext.java.shared.dto.model.JavaProject) IJavaProject(org.eclipse.jdt.core.IJavaProject) ElementQuerySpecification(org.eclipse.jdt.ui.search.ElementQuerySpecification) JavaSearchQuery(org.eclipse.jdt.internal.ui.search.JavaSearchQuery) Region(org.eclipse.che.ide.ext.java.shared.dto.Region) IRegion(org.eclipse.jface.text.IRegion) IPackageDeclaration(org.eclipse.jdt.core.IPackageDeclaration) IDocument(org.eclipse.jface.text.IDocument)

Example 4 with JavaProject

use of org.eclipse.che.ide.ext.java.shared.dto.model.JavaProject in project che by eclipse.

the class JarNavigationTest method testAllProjectsWithoutPackages.

@Test
public void testAllProjectsWithoutPackages() throws Exception {
    List<JavaProject> packages = navigation.getAllProjectsAndPackages(false);
    assertThat(packages).isNotNull().isNotEmpty();
    JavaProject project = packages.get(0);
    assertThat(project.getPackageFragmentRoots()).isNotNull().isNotEmpty();
    PackageFragmentRoot fragmentRoot = project.getPackageFragmentRoots().get(0);
    assertThat(fragmentRoot.getPackageFragments()).isNullOrEmpty();
}
Also used : JavaProject(org.eclipse.che.ide.ext.java.shared.dto.model.JavaProject) PackageFragmentRoot(org.eclipse.che.ide.ext.java.shared.dto.model.PackageFragmentRoot) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot) Test(org.junit.Test)

Example 5 with JavaProject

use of org.eclipse.che.ide.ext.java.shared.dto.model.JavaProject in project che by eclipse.

the class JarNavigationTest method testAllProjectsAndPackages.

@Test
public void testAllProjectsAndPackages() throws Exception {
    List<JavaProject> packages = navigation.getAllProjectsAndPackages(true);
    assertThat(packages).isNotNull().isNotEmpty();
    JavaProject project = packages.get(0);
    assertThat(packages.get(0).getPackageFragmentRoots()).isNotNull().isNotEmpty();
    assertThat(project.getPackageFragmentRoots()).isNotNull().isNotEmpty();
    PackageFragmentRoot fragmentRoot = project.getPackageFragmentRoots().get(0);
    assertThat(fragmentRoot.getPackageFragments()).isNotEmpty();
}
Also used : JavaProject(org.eclipse.che.ide.ext.java.shared.dto.model.JavaProject) PackageFragmentRoot(org.eclipse.che.ide.ext.java.shared.dto.model.PackageFragmentRoot) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot) Test(org.junit.Test)

Aggregations

JavaProject (org.eclipse.che.ide.ext.java.shared.dto.model.JavaProject)8 ArrayList (java.util.ArrayList)5 PackageFragmentRoot (org.eclipse.che.ide.ext.java.shared.dto.model.PackageFragmentRoot)3 IJavaProject (org.eclipse.jdt.core.IJavaProject)3 Test (org.junit.Test)3 List (java.util.List)2 IPackageFragmentRoot (org.eclipse.jdt.core.IPackageFragmentRoot)2 CellTree (com.google.gwt.user.cellview.client.CellTree)1 SelectionChangeEvent (com.google.gwt.view.client.SelectionChangeEvent)1 SingleSelectionModel (com.google.gwt.view.client.SingleSelectionModel)1 HashMap (java.util.HashMap)1 Operation (org.eclipse.che.api.promises.client.Operation)1 OperationException (org.eclipse.che.api.promises.client.OperationException)1 PromiseError (org.eclipse.che.api.promises.client.PromiseError)1 Region (org.eclipse.che.ide.ext.java.shared.dto.Region)1 PackageFragment (org.eclipse.che.ide.ext.java.shared.dto.model.PackageFragment)1 FindUsagesResponse (org.eclipse.che.ide.ext.java.shared.dto.search.FindUsagesResponse)1 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)1 IJavaElement (org.eclipse.jdt.core.IJavaElement)1 IMember (org.eclipse.jdt.core.IMember)1