use of org.eclipse.jdt.internal.core.JavaModel 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;
}
use of org.eclipse.jdt.internal.core.JavaModel 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.jdt.internal.core.JavaModel in project che by eclipse.
the class SearchService method findUsages.
@POST
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
@Path("find/usages")
public FindUsagesResponse findUsages(FindUsagesRequest request) throws SearchException {
JavaModel javaModel = JavaModelManager.getJavaModelManager().getJavaModel();
IJavaProject javaProject = javaModel.getJavaProject(request.getProjectPath());
return manager.findUsage(javaProject, request.getFQN(), request.getOffset());
}
use of org.eclipse.jdt.internal.core.JavaModel in project che by eclipse.
the class IndexManager method indexAll.
/**
* Trigger addition of the entire content of a project
* Note: the actual operation is performed in background
*/
public void indexAll(IProject project) {
// determine the new children
try {
JavaModel model = JavaModelManager.getJavaModelManager().getJavaModel();
JavaProject javaProject = (JavaProject) model.getJavaProject(project);
// only consider immediate libraries - each project will do the same
// NOTE: force to resolve CP variables before calling indexer - 19303, so that initializers
// will be run in the current thread.
IClasspathEntry[] entries = javaProject.getResolvedClasspath();
for (int i = 0; i < entries.length; i++) {
IClasspathEntry entry = entries[i];
if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY)
indexLibrary(entry.getPath(), project, ((ClasspathEntry) entry).getLibraryIndexLocation());
}
} catch (JavaModelException e) {
// cannot retrieve classpath info
}
// check if the same request is not already in the queue
IndexRequest request = new IndexAllProject(project, this);
if (!isJobWaiting(request))
request(request);
}
Aggregations