Search in sources :

Example 26 with IResource

use of org.eclipse.core.resources.IResource in project che by eclipse.

the class RefactoringModifications method getClasspathFile.

protected IFile getClasspathFile(IResource resource) {
    IProject project = resource.getProject();
    if (project == null)
        return null;
    //$NON-NLS-1$
    IResource result = project.findMember(".classpath");
    if (result instanceof IFile)
        return (IFile) result;
    return null;
}
Also used : IFile(org.eclipse.core.resources.IFile) IProject(org.eclipse.core.resources.IProject) IResource(org.eclipse.core.resources.IResource)

Example 27 with IResource

use of org.eclipse.core.resources.IResource in project che by eclipse.

the class StandardJavaElementContentProvider method internalGetParent.

/**
     * Note: This method is for internal use only. Clients should not call this method.
     *
     * @param element the element
     * @return the parent of the element
     *
     * @noreference This method is not intended to be referenced by clients.
     */
protected Object internalGetParent(Object element) {
    // try to map resources to the containing package fragment
    if (element instanceof IResource) {
        IResource parent = ((IResource) element).getParent();
        IJavaElement jParent = JavaCore.create(parent);
        // http://bugs.eclipse.org/bugs/show_bug.cgi?id=31374
        if (jParent != null && jParent.exists())
            return jParent;
        return parent;
    } else if (element instanceof IJavaElement) {
        IJavaElement parent = ((IJavaElement) element).getParent();
        // we have to skip the package fragment root as the parent.
        if (element instanceof IPackageFragment) {
            return skipProjectPackageFragmentRoot((IPackageFragmentRoot) parent);
        }
        return parent;
    } else if (element instanceof IJarEntryResource) {
        return ((IJarEntryResource) element).getParent();
    }
    return null;
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) IJarEntryResource(org.eclipse.jdt.core.IJarEntryResource) IResource(org.eclipse.core.resources.IResource) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot)

Example 28 with IResource

use of org.eclipse.core.resources.IResource in project che by eclipse.

the class StandardJavaElementContentProvider method getFolderContent.

/**
     * Evaluates all children of a given {@link IFolder}. Clients can override this method.
     * @param folder The folder to evaluate the children for.
     * @return The children of the given folder.
     * @exception CoreException if the folder does not exist.
     *
     * @since 3.3
     */
protected Object[] getFolderContent(IFolder folder) throws CoreException {
    IResource[] members = folder.members();
    IJavaProject javaProject = JavaCore.create(folder.getProject());
    if (javaProject == null || !javaProject.exists())
        return members;
    boolean isFolderOnClasspath = javaProject.isOnClasspath(folder);
    List<IResource> nonJavaResources = new ArrayList<IResource>();
    // Can be on classpath but as a member of non-java resource folder
    for (int i = 0; i < members.length; i++) {
        IResource member = members[i];
        // of non-Java resources.
        if (isFolderOnClasspath) {
            if (javaProject.findPackageFragmentRoot(member.getFullPath()) == null) {
                nonJavaResources.add(member);
            }
        } else if (!javaProject.isOnClasspath(member)) {
            nonJavaResources.add(member);
        } else {
            IJavaElement element = JavaCore.create(member, javaProject);
            if (element instanceof IPackageFragmentRoot && javaProject.equals(element.getJavaProject()) && ((IPackageFragmentRoot) element).getKind() != IPackageFragmentRoot.K_SOURCE) {
                // don't skip libs and class folders on the classpath of their project
                nonJavaResources.add(member);
            }
        }
    }
    return nonJavaResources.toArray();
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) IJavaProject(org.eclipse.jdt.core.IJavaProject) ArrayList(java.util.ArrayList) IResource(org.eclipse.core.resources.IResource) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot)

Example 29 with IResource

use of org.eclipse.core.resources.IResource in project che by eclipse.

the class RefactoringService method createMoveRefactoring.

/**
     * Create move refactoring session.
     *
     * @param cmr
     *         move settings, contains resource paths to move.
     * @return refactoring session id.
     * @throws JavaModelException
     *         when JavaModel has a failure
     * @throws RefactoringException
     *         when impossible to create move refactoring session
     */
@POST
@Path("move/create")
@Consumes("application/json")
@Produces("text/plain")
public String createMoveRefactoring(CreateMoveRefactoring cmr) throws JavaModelException, RefactoringException {
    IJavaProject javaProject = model.getJavaProject(cmr.getProjectPath());
    IJavaElement[] javaElements;
    try {
        Function<ElementToMove, IJavaElement> map = javaElement -> {
            try {
                if (javaElement.isPack()) {
                    return javaProject.findPackageFragment(new org.eclipse.core.runtime.Path(javaElement.getPath()));
                } else {
                    return javaProject.findType(javaElement.getPath()).getCompilationUnit();
                }
            } catch (JavaModelException e) {
                throw new IllegalArgumentException(e);
            }
        };
        javaElements = cmr.getElements().stream().map(map).toArray(IJavaElement[]::new);
    } catch (IllegalArgumentException e) {
        if (e.getCause() instanceof JavaModelException) {
            throw (JavaModelException) e.getCause();
        } else {
            throw e;
        }
    }
    if (RefactoringAvailabilityTester.isMoveAvailable(new IResource[0], javaElements)) {
        return manager.createMoveRefactoringSession(javaElements);
    }
    throw new RefactoringException("Can't create move refactoring.");
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) Produces(javax.ws.rs.Produces) JavaModelException(org.eclipse.jdt.core.JavaModelException) GET(javax.ws.rs.GET) ReorgDestination(org.eclipse.che.ide.ext.java.shared.dto.refactoring.ReorgDestination) Inject(com.google.inject.Inject) MoveSettings(org.eclipse.che.ide.ext.java.shared.dto.refactoring.MoveSettings) RefactoringStatus(org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringStatus) Path(javax.ws.rs.Path) CoreException(org.eclipse.core.runtime.CoreException) Function(java.util.function.Function) LinkedRenameRefactoringApply(org.eclipse.che.ide.ext.java.shared.dto.refactoring.LinkedRenameRefactoringApply) RefactoringChange(org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringChange) JavaModelManager(org.eclipse.jdt.internal.core.JavaModelManager) RefactoringPreview(org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringPreview) JavaModel(org.eclipse.jdt.internal.core.JavaModel) QueryParam(javax.ws.rs.QueryParam) Consumes(javax.ws.rs.Consumes) RefactoringException(org.eclipse.che.plugin.java.server.refactoring.RefactoringException) RenameSettings(org.eclipse.che.ide.ext.java.shared.dto.refactoring.RenameSettings) ChangeEnabledState(org.eclipse.che.ide.ext.java.shared.dto.refactoring.ChangeEnabledState) RefactoringManager(org.eclipse.che.plugin.java.server.refactoring.RefactoringManager) ValidateNewName(org.eclipse.che.ide.ext.java.shared.dto.refactoring.ValidateNewName) ChangePreview(org.eclipse.che.ide.ext.java.shared.dto.refactoring.ChangePreview) POST(javax.ws.rs.POST) IJavaProject(org.eclipse.jdt.core.IJavaProject) RefactoringAvailabilityTester(org.eclipse.jdt.internal.corext.refactoring.RefactoringAvailabilityTester) ChangeCreationResult(org.eclipse.che.ide.ext.java.shared.dto.refactoring.ChangeCreationResult) CreateRenameRefactoring(org.eclipse.che.ide.ext.java.shared.dto.refactoring.CreateRenameRefactoring) RefactoringSession(org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringSession) ElementToMove(org.eclipse.che.ide.ext.java.shared.dto.refactoring.ElementToMove) CreateMoveRefactoring(org.eclipse.che.ide.ext.java.shared.dto.refactoring.CreateMoveRefactoring) RefactoringResult(org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringResult) IJavaElement(org.eclipse.jdt.core.IJavaElement) Response(javax.ws.rs.core.Response) RenameRefactoringSession(org.eclipse.che.ide.ext.java.shared.dto.refactoring.RenameRefactoringSession) IResource(org.eclipse.core.resources.IResource) Path(javax.ws.rs.Path) IJavaElement(org.eclipse.jdt.core.IJavaElement) JavaModelException(org.eclipse.jdt.core.JavaModelException) IJavaProject(org.eclipse.jdt.core.IJavaProject) ElementToMove(org.eclipse.che.ide.ext.java.shared.dto.refactoring.ElementToMove) RefactoringException(org.eclipse.che.plugin.java.server.refactoring.RefactoringException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 30 with IResource

use of org.eclipse.core.resources.IResource in project che by eclipse.

the class MavenTestClasspathProviderTest method buildMocks.

private void buildMocks(List<ClasspathEntry> entries) throws JavaModelException {
    when(classpathService.getClasspath(anyString())).thenReturn(entries.stream().map(ClasspathEntry::dto).collect(Collectors.toList()));
    for (ClasspathEntry entry : entries) {
        if (!entry.external && entry.kind == IClasspathEntry.CPE_LIBRARY) {
            IPath resourceLocation = new Path(entry.fileSystemPath);
            IResource result = mock(IResource.class);
            when(result.getLocation()).thenReturn(resourceLocation);
            when(workspaceRoot.findMember(new Path(entry.fullPath))).thenReturn(result);
        }
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) IResource(org.eclipse.core.resources.IResource)

Aggregations

IResource (org.eclipse.core.resources.IResource)1487 IFile (org.eclipse.core.resources.IFile)390 CoreException (org.eclipse.core.runtime.CoreException)390 IPath (org.eclipse.core.runtime.IPath)315 IProject (org.eclipse.core.resources.IProject)286 ArrayList (java.util.ArrayList)237 IFolder (org.eclipse.core.resources.IFolder)187 IContainer (org.eclipse.core.resources.IContainer)175 Path (org.eclipse.core.runtime.Path)141 File (java.io.File)124 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)109 IOException (java.io.IOException)103 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)95 IStatus (org.eclipse.core.runtime.IStatus)89 List (java.util.List)83 IJavaProject (org.eclipse.jdt.core.IJavaProject)75 HashSet (java.util.HashSet)71 Status (org.eclipse.core.runtime.Status)66 HashMap (java.util.HashMap)60 IAdaptable (org.eclipse.core.runtime.IAdaptable)59