Search in sources :

Example 1 with JavaModel

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;
}
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 2 with JavaModel

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.");
}
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 3 with JavaModel

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());
}
Also used : IJavaProject(org.eclipse.jdt.core.IJavaProject) JavaModel(org.eclipse.jdt.internal.core.JavaModel) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 4 with JavaModel

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);
}
Also used : JavaProject(org.eclipse.jdt.internal.core.JavaProject) IJavaProject(org.eclipse.jdt.core.IJavaProject) JavaModelException(org.eclipse.jdt.core.JavaModelException) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) JavaModel(org.eclipse.jdt.internal.core.JavaModel) ClasspathEntry(org.eclipse.jdt.internal.core.ClasspathEntry) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry)

Aggregations

IJavaProject (org.eclipse.jdt.core.IJavaProject)4 JavaModel (org.eclipse.jdt.internal.core.JavaModel)4 Consumes (javax.ws.rs.Consumes)2 POST (javax.ws.rs.POST)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 JavaModelException (org.eclipse.jdt.core.JavaModelException)2 Inject (com.google.inject.Inject)1 ArrayList (java.util.ArrayList)1 Function (java.util.function.Function)1 GET (javax.ws.rs.GET)1 QueryParam (javax.ws.rs.QueryParam)1 Response (javax.ws.rs.core.Response)1 JavaProject (org.eclipse.che.ide.ext.java.shared.dto.model.JavaProject)1 ChangeCreationResult (org.eclipse.che.ide.ext.java.shared.dto.refactoring.ChangeCreationResult)1 ChangeEnabledState (org.eclipse.che.ide.ext.java.shared.dto.refactoring.ChangeEnabledState)1 ChangePreview (org.eclipse.che.ide.ext.java.shared.dto.refactoring.ChangePreview)1 CreateMoveRefactoring (org.eclipse.che.ide.ext.java.shared.dto.refactoring.CreateMoveRefactoring)1 CreateRenameRefactoring (org.eclipse.che.ide.ext.java.shared.dto.refactoring.CreateRenameRefactoring)1 ElementToMove (org.eclipse.che.ide.ext.java.shared.dto.refactoring.ElementToMove)1