Search in sources :

Example 1 with RefactoringResult

use of org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringResult in project che by eclipse.

the class RefactoringManager method applyLinkedRename.

/**
     * Apply linked mode rename refactoring.
     *
     * @param apply
     *         contains new element name
     * @return refactoring result
     * @throws RefactoringException
     *         when refactoring session not found.
     * @throws CoreException
     *         when impossible to apply rename refactoring
     */
public RefactoringResult applyLinkedRename(LinkedRenameRefactoringApply apply) throws RefactoringException, CoreException {
    RefactoringSession session = getRefactoringSession(apply.getSessionId());
    if (session instanceof RenameLinkedModeRefactoringSession) {
        RenameLinkedModeRefactoringSession renameSession = (RenameLinkedModeRefactoringSession) session;
        try {
            RefactoringResult refactoringResult = renameSession.doRename(apply.getNewName());
            deleteRefactoringSession(apply.getSessionId());
            return refactoringResult;
        } catch (InvocationTargetException | InterruptedException | AssertionFailedException e) {
            LOG.error(e.getMessage(), e);
            return DtoConverter.toRefactoringResultDto(org.eclipse.ltk.core.refactoring.RefactoringStatus.createFatalErrorStatus(e.getMessage()));
        }
    }
    throw new RefactoringException("There is no RenameLinkedModeRefactoringSession.");
}
Also used : RefactoringResult(org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringResult) RenameLinkedModeRefactoringSession(org.eclipse.che.plugin.java.server.refactoring.session.RenameLinkedModeRefactoringSession) MoveRefactoringSession(org.eclipse.che.plugin.java.server.refactoring.session.MoveRefactoringSession) RenameLinkedModeRefactoringSession(org.eclipse.che.plugin.java.server.refactoring.session.RenameLinkedModeRefactoringSession) ReorgRefactoringSession(org.eclipse.che.plugin.java.server.refactoring.session.ReorgRefactoringSession) RefactoringSession(org.eclipse.che.plugin.java.server.refactoring.session.RefactoringSession) RenameRefactoringSession(org.eclipse.che.ide.ext.java.shared.dto.refactoring.RenameRefactoringSession) AssertionFailedException(org.eclipse.core.runtime.AssertionFailedException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 2 with RefactoringResult

use of org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringResult in project che by eclipse.

the class RenameLinkedModeRefactoringSession method doRename.

/**
     * Make rename operation.
     * @param newName the name which will be applied
     * @return result of the rename operation
     * @throws CoreException if an error occurs while creating the refactoring instance
     * @throws InvocationTargetException if an error occurred while executing the
     * operation.
     * @throws InterruptedException if the operation has been canceled by the
     * user.
     */
public RefactoringResult doRename(String newName) throws CoreException, InvocationTargetException, InterruptedException {
    if (fOriginalName.equals(newName)) {
        return DtoConverter.toRefactoringResultDto(new RefactoringStatus());
    }
    RenameSupport renameSupport = undoAndCreateRenameSupport(newName);
    if (renameSupport == null)
        return DtoConverter.toRefactoringResultDto(RefactoringStatus.createFatalErrorStatus("Can't create rename refactoring"));
    RefactoringResult refactoringResult = DtoConverter.toRefactoringResultDto(renameSupport.perform());
    PerformChangeOperation operation = renameSupport.getfPerformChangeOperation();
    if (operation == null) {
        return refactoringResult;
    }
    CompositeChange operationChange = (CompositeChange) operation.getUndoChange();
    Change[] changes = operationChange.getChildren();
    List<ChangeInfo> changesInfo = new ArrayList<>();
    prepareChangesInfo(changes, changesInfo);
    refactoringResult.setChanges(changesInfo);
    return refactoringResult;
}
Also used : PerformChangeOperation(org.eclipse.ltk.core.refactoring.PerformChangeOperation) ChangeInfo(org.eclipse.che.ide.ext.java.shared.dto.refactoring.ChangeInfo) RefactoringResult(org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringResult) ArrayList(java.util.ArrayList) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) CompositeChange(org.eclipse.ltk.core.refactoring.CompositeChange) Change(org.eclipse.ltk.core.refactoring.Change) CompositeChange(org.eclipse.ltk.core.refactoring.CompositeChange) RenameSupport(org.eclipse.jdt.ui.refactoring.RenameSupport)

Example 3 with RefactoringResult

use of org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringResult in project che by eclipse.

the class DtoConverter method toRefactoringResultDto.

/**
     * Converts {@link org.eclipse.ltk.core.refactoring.RefactoringStatus} to {@link RefactoringResult}.
     */
public static RefactoringResult toRefactoringResultDto(org.eclipse.ltk.core.refactoring.RefactoringStatus refactoringStatus) {
    RefactoringResult result = DtoFactory.newDto(RefactoringResult.class);
    convertRefactoringStatus(result, refactoringStatus);
    return result;
}
Also used : RefactoringResult(org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringResult)

Example 4 with RefactoringResult

use of org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringResult in project che by eclipse.

the class RefactoringManager method applyRefactoring.

/**
     * Apply refactoring.
     *
     * @param sessionId
     *         id of the refactoring session
     * @return refactoring result
     * @throws RefactoringException
     *         when refactoring session not found.
     */
public RefactoringResult applyRefactoring(String sessionId) throws RefactoringException {
    RefactoringSession session = getRefactoringSession(sessionId);
    RefactoringResult result = session.apply();
    deleteRefactoringSession(sessionId);
    return result;
}
Also used : RefactoringResult(org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringResult) MoveRefactoringSession(org.eclipse.che.plugin.java.server.refactoring.session.MoveRefactoringSession) RenameLinkedModeRefactoringSession(org.eclipse.che.plugin.java.server.refactoring.session.RenameLinkedModeRefactoringSession) ReorgRefactoringSession(org.eclipse.che.plugin.java.server.refactoring.session.ReorgRefactoringSession) RefactoringSession(org.eclipse.che.plugin.java.server.refactoring.session.RefactoringSession) RenameRefactoringSession(org.eclipse.che.ide.ext.java.shared.dto.refactoring.RenameRefactoringSession)

Example 5 with RefactoringResult

use of org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringResult in project che by eclipse.

the class RefactoringSession method apply.

/**
     * @return instance of {@link org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringStatus}.
     * That describes status of the refactoring operation.
     */
public RefactoringResult apply() {
    PerformChangeOperation operation = new PerformChangeOperation(change);
    FinishResult result = internalPerformFinish(operation);
    if (result.isException()) {
        return DtoConverter.toRefactoringResultDto(RefactoringStatus.createErrorStatus("Refactoring failed with Exception."));
    }
    CompositeChange operationChange = (CompositeChange) operation.getUndoChange();
    Change[] changes = operationChange.getChildren();
    RefactoringStatus validationStatus = operation.getValidationStatus();
    if (validationStatus != null) {
        List<ChangeInfo> changesInfo = new ArrayList<>();
        prepareChangesInfo(changes, changesInfo);
        RefactoringResult status = DtoConverter.toRefactoringResultDto(validationStatus);
        status.setChanges(changesInfo);
        return status;
    }
    return DtoConverter.toRefactoringResultDto(new RefactoringStatus());
}
Also used : PerformChangeOperation(org.eclipse.ltk.core.refactoring.PerformChangeOperation) FinishResult(org.eclipse.ltk.internal.ui.refactoring.FinishResult) ChangeInfo(org.eclipse.che.ide.ext.java.shared.dto.refactoring.ChangeInfo) RefactoringResult(org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringResult) ArrayList(java.util.ArrayList) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) 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) CompositeChange(org.eclipse.ltk.core.refactoring.CompositeChange)

Aggregations

RefactoringResult (org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringResult)7 ChangeInfo (org.eclipse.che.ide.ext.java.shared.dto.refactoring.ChangeInfo)3 ArrayList (java.util.ArrayList)2 Operation (org.eclipse.che.api.promises.client.Operation)2 OperationException (org.eclipse.che.api.promises.client.OperationException)2 PromiseError (org.eclipse.che.api.promises.client.PromiseError)2 RenameRefactoringSession (org.eclipse.che.ide.ext.java.shared.dto.refactoring.RenameRefactoringSession)2 MoveRefactoringSession (org.eclipse.che.plugin.java.server.refactoring.session.MoveRefactoringSession)2 RefactoringSession (org.eclipse.che.plugin.java.server.refactoring.session.RefactoringSession)2 RenameLinkedModeRefactoringSession (org.eclipse.che.plugin.java.server.refactoring.session.RenameLinkedModeRefactoringSession)2 ReorgRefactoringSession (org.eclipse.che.plugin.java.server.refactoring.session.ReorgRefactoringSession)2 Change (org.eclipse.ltk.core.refactoring.Change)2 CompositeChange (org.eclipse.ltk.core.refactoring.CompositeChange)2 PerformChangeOperation (org.eclipse.ltk.core.refactoring.PerformChangeOperation)2 RefactoringStatus (org.eclipse.ltk.core.refactoring.RefactoringStatus)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Project (org.eclipse.che.ide.api.resources.Project)1 Resource (org.eclipse.che.ide.api.resources.Resource)1 VirtualFile (org.eclipse.che.ide.api.resources.VirtualFile)1 ChangeCreationResult (org.eclipse.che.ide.ext.java.shared.dto.refactoring.ChangeCreationResult)1