Search in sources :

Example 1 with RefactoringException

use of org.eclipse.che.plugin.java.server.refactoring.RefactoringException in project che by eclipse.

the class RefactoringSession method createChange.

public ChangeCreationResult createChange() throws RefactoringException {
    Change change = createChange(new CreateChangeOperation(new CheckConditionsOperation(refactoring, CheckConditionsOperation.FINAL_CONDITIONS), RefactoringStatus.FATAL), true);
    // Status has been updated since we have passed true
    RefactoringStatus status = conditionCheckingStatus;
    // Creating the change has been canceled
    if (change == null && status == null) {
        internalSetChange(change);
        throw new RefactoringException("Creating the change has been canceled");
    }
    // Set change if we don't have fatal errors.
    if (!status.hasFatalError()) {
        internalSetChange(change);
    }
    ChangeCreationResult result = DtoFactory.newDto(ChangeCreationResult.class);
    result.setStatus(DtoConverter.toRefactoringStatusDto(status));
    result.setCanShowPreviewPage(status.isOK());
    return result;
}
Also used : CreateChangeOperation(org.eclipse.ltk.core.refactoring.CreateChangeOperation) CheckConditionsOperation(org.eclipse.ltk.core.refactoring.CheckConditionsOperation) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) ChangeCreationResult(org.eclipse.che.ide.ext.java.shared.dto.refactoring.ChangeCreationResult) CompositeChange(org.eclipse.ltk.core.refactoring.CompositeChange) MoveCompilationUnitChange(org.eclipse.jdt.internal.corext.refactoring.changes.MoveCompilationUnitChange) UndoTextFileChange(org.eclipse.ltk.core.refactoring.UndoTextFileChange) Change(org.eclipse.ltk.core.refactoring.Change) DynamicValidationStateChange(org.eclipse.jdt.internal.corext.refactoring.changes.DynamicValidationStateChange) RenameCompilationUnitChange(org.eclipse.jdt.internal.corext.refactoring.changes.RenameCompilationUnitChange) RenamePackageChange(org.eclipse.jdt.internal.corext.refactoring.changes.RenamePackageChange) RefactoringException(org.eclipse.che.plugin.java.server.refactoring.RefactoringException)

Example 2 with RefactoringException

use of org.eclipse.che.plugin.java.server.refactoring.RefactoringException in project che by eclipse.

the class RefactoringSession method updateChangeEnabled.

public void updateChangeEnabled(String changeId, boolean enabled) throws RefactoringException {
    PreviewNode node = findNode(previewNode, changeId);
    if (node == null) {
        throw new RefactoringException("Can't find refactoring change to update enabled state.");
    }
    node.setEnabled(enabled);
}
Also used : PreviewNode(org.eclipse.ltk.internal.ui.refactoring.PreviewNode) RefactoringException(org.eclipse.che.plugin.java.server.refactoring.RefactoringException)

Example 3 with RefactoringException

use of org.eclipse.che.plugin.java.server.refactoring.RefactoringException in project che by eclipse.

the class RefactoringService method createRenameRefactoring.

/**
     * Create rename refactoring session.
     *
     * @param settings
     *         rename settings
     * @return the rename refactoring session
     * @throws CoreException
     *         when RenameSupport can't be created
     * @throws RefactoringException
     *         when Java element was not found
     */
@POST
@Path("rename/create")
@Produces("application/json")
@Consumes("application/json")
public RenameRefactoringSession createRenameRefactoring(CreateRenameRefactoring settings) throws CoreException, RefactoringException {
    IJavaProject javaProject = model.getJavaProject(settings.getProjectPath());
    IJavaElement elementToRename;
    ICompilationUnit cu = null;
    switch(settings.getType()) {
        case COMPILATION_UNIT:
            elementToRename = javaProject.findType(settings.getPath()).getCompilationUnit();
            break;
        case PACKAGE:
            elementToRename = javaProject.findPackageFragment(new org.eclipse.core.runtime.Path(settings.getPath()));
            break;
        case JAVA_ELEMENT:
            cu = javaProject.findType(settings.getPath()).getCompilationUnit();
            elementToRename = getSelectionElement(cu, settings.getOffset());
            break;
        default:
            elementToRename = null;
    }
    if (elementToRename == null) {
        throw new RefactoringException("Can't find java element to rename.");
    }
    return manager.createRenameRefactoring(elementToRename, cu, settings.getOffset(), settings.isRefactorLightweight());
}
Also used : Path(javax.ws.rs.Path) IJavaElement(org.eclipse.jdt.core.IJavaElement) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IJavaProject(org.eclipse.jdt.core.IJavaProject) RefactoringException(org.eclipse.che.plugin.java.server.refactoring.RefactoringException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes)

Example 4 with RefactoringException

use of org.eclipse.che.plugin.java.server.refactoring.RefactoringException 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 5 with RefactoringException

use of org.eclipse.che.plugin.java.server.refactoring.RefactoringException in project che by eclipse.

the class RefactoringSession method createChange.

private Change createChange(CreateChangeOperation operation, boolean updateStatus) throws RefactoringException {
    CoreException exception = null;
    try {
        ResourcesPlugin.getWorkspace().run(operation, new NullProgressMonitor());
    } catch (CoreException e) {
        exception = e;
    }
    if (updateStatus) {
        RefactoringStatus status = null;
        if (exception != null) {
            status = new RefactoringStatus();
            String msg = exception.getMessage();
            if (msg != null) {
                status.addFatalError(Messages.format("{0}. See the error log for more details.", msg));
            } else {
                status.addFatalError("An unexpected exception occurred while creating a change object. See the error log for more details.");
            }
            JavaPlugin.log(exception);
        } else {
            status = operation.getConditionCheckingStatus();
        }
        setConditionCheckingStatus(status);
    } else {
        if (exception != null)
            throw new RefactoringException(exception);
    }
    Change change = operation.getChange();
    return change;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) RefactoringException(org.eclipse.che.plugin.java.server.refactoring.RefactoringException) CompositeChange(org.eclipse.ltk.core.refactoring.CompositeChange) MoveCompilationUnitChange(org.eclipse.jdt.internal.corext.refactoring.changes.MoveCompilationUnitChange) UndoTextFileChange(org.eclipse.ltk.core.refactoring.UndoTextFileChange) Change(org.eclipse.ltk.core.refactoring.Change) DynamicValidationStateChange(org.eclipse.jdt.internal.corext.refactoring.changes.DynamicValidationStateChange) RenameCompilationUnitChange(org.eclipse.jdt.internal.corext.refactoring.changes.RenameCompilationUnitChange) RenamePackageChange(org.eclipse.jdt.internal.corext.refactoring.changes.RenamePackageChange)

Aggregations

RefactoringException (org.eclipse.che.plugin.java.server.refactoring.RefactoringException)5 Consumes (javax.ws.rs.Consumes)2 POST (javax.ws.rs.POST)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 ChangeCreationResult (org.eclipse.che.ide.ext.java.shared.dto.refactoring.ChangeCreationResult)2 CoreException (org.eclipse.core.runtime.CoreException)2 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)2 IJavaElement (org.eclipse.jdt.core.IJavaElement)2 IJavaProject (org.eclipse.jdt.core.IJavaProject)2 DynamicValidationStateChange (org.eclipse.jdt.internal.corext.refactoring.changes.DynamicValidationStateChange)2 MoveCompilationUnitChange (org.eclipse.jdt.internal.corext.refactoring.changes.MoveCompilationUnitChange)2 RenameCompilationUnitChange (org.eclipse.jdt.internal.corext.refactoring.changes.RenameCompilationUnitChange)2 Inject (com.google.inject.Inject)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 ChangeEnabledState (org.eclipse.che.ide.ext.java.shared.dto.refactoring.ChangeEnabledState)1 ChangePreview (org.eclipse.che.ide.ext.java.shared.dto.refactoring.ChangePreview)1