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;
}
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;
}
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();
}
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.");
}
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);
}
}
}
Aggregations