Search in sources :

Example 1 with RenamePackageChange

use of org.eclipse.jdt.internal.corext.refactoring.changes.RenamePackageChange in project che by eclipse.

the class RefactoringSession method prepareRenamePackageChange.

private void prepareRenamePackageChange(List<ChangeInfo> changesInfo, ChangeInfo changeInfo, Change ch) {
    changeInfo.setName(ChangeInfo.ChangeName.RENAME_PACKAGE);
    RenamePackageChange renameChange = (RenamePackageChange) ch;
    IPath oldPackageName = new Path(renameChange.getOldName().replace('.', IPath.SEPARATOR));
    IPath newPackageName = new Path(renameChange.getNewName().replace('.', IPath.SEPARATOR));
    changeInfo.setOldPath(renameChange.getResourcePath().removeLastSegments(oldPackageName.segmentCount()).append(newPackageName).toString());
    changeInfo.setPath(renameChange.getResourcePath().toString());
    Set<IResource> compilationUnits = renameChange.getFCompilationUnitStamps().keySet();
    for (IResource iResource : compilationUnits) {
        ChangeInfo change = DtoFactory.newDto(ChangeInfo.class);
        change.setName(ChangeInfo.ChangeName.UPDATE);
        IPath fullPathOldPath = iResource.getFullPath();
        IPath newPath = renameChange.getResourcePath().append(fullPathOldPath.toFile().getName());
        change.setOldPath(fullPathOldPath.toString());
        change.setPath(newPath.toString());
        changesInfo.add(change);
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) ChangeInfo(org.eclipse.che.ide.ext.java.shared.dto.refactoring.ChangeInfo) RenamePackageChange(org.eclipse.jdt.internal.corext.refactoring.changes.RenamePackageChange) IResource(org.eclipse.core.resources.IResource)

Example 2 with RenamePackageChange

use of org.eclipse.jdt.internal.corext.refactoring.changes.RenamePackageChange in project che by eclipse.

the class RefactoringSession method prepareChangesInfo.

/**
     * Prepare the information about changes which were applied.
     *
     * @param changes array of the applied changes
     * @param changesInfo prepared list of {@link ChangeInfo}
     */
public void prepareChangesInfo(Change[] changes, List<ChangeInfo> changesInfo) {
    for (Change ch : changes) {
        if (ch instanceof DynamicValidationStateChange) {
            prepareChangesInfo(((DynamicValidationStateChange) ch).getChildren(), changesInfo);
        } else {
            ChangeInfo changeInfo = DtoFactory.newDto(ChangeInfo.class);
            String refactoringName = ch.getName();
            if (ch instanceof UndoTextFileChange) {
                changeInfo.setName(ChangeInfo.ChangeName.UPDATE);
                changeInfo.setPath(((CompilationUnit) ch.getModifiedElement()).getPath().toString());
            }
            if (refactoringName.startsWith("Rename")) {
                if (ch instanceof RenameCompilationUnitChange) {
                    prepareRenameCompilationUnitChange(changeInfo, ch);
                } else if (ch instanceof RenamePackageChange) {
                    prepareRenamePackageChange(changesInfo, changeInfo, ch);
                }
            }
            if (refactoringName.startsWith("Move")) {
                prepareMoveChange(changeInfo, ch);
            }
            changesInfo.add(changeInfo);
        }
    }
}
Also used : CompilationUnit(org.eclipse.jdt.internal.core.CompilationUnit) ChangeInfo(org.eclipse.che.ide.ext.java.shared.dto.refactoring.ChangeInfo) RenamePackageChange(org.eclipse.jdt.internal.corext.refactoring.changes.RenamePackageChange) 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) UndoTextFileChange(org.eclipse.ltk.core.refactoring.UndoTextFileChange) DynamicValidationStateChange(org.eclipse.jdt.internal.corext.refactoring.changes.DynamicValidationStateChange) RenameCompilationUnitChange(org.eclipse.jdt.internal.corext.refactoring.changes.RenameCompilationUnitChange)

Example 3 with RenamePackageChange

use of org.eclipse.jdt.internal.corext.refactoring.changes.RenamePackageChange in project che by eclipse.

the class RenamePackageProcessor method createChange.

@Override
public Change createChange(IProgressMonitor monitor) throws CoreException {
    try {
        monitor.beginTask(RefactoringCoreMessages.RenamePackageRefactoring_creating_change, 1);
        final RenameJavaElementDescriptor descriptor = createRefactoringDescriptor();
        final DynamicValidationRefactoringChange result = new DynamicValidationRefactoringChange(descriptor, RefactoringCoreMessages.RenamePackageRefactoring_change_name);
        result.addAll(fChangeManager.getAllChanges());
        fRenamePackageChange = new RenamePackageChange(fPackage, getNewElementName(), fRenameSubpackages);
        result.add(fRenamePackageChange);
        monitor.worked(1);
        return result;
    } finally {
        fChangeManager = null;
        fImportsManager = null;
        monitor.done();
    }
}
Also used : DynamicValidationRefactoringChange(org.eclipse.jdt.internal.corext.refactoring.changes.DynamicValidationRefactoringChange) RenamePackageChange(org.eclipse.jdt.internal.corext.refactoring.changes.RenamePackageChange) RenameJavaElementDescriptor(org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor)

Aggregations

RenamePackageChange (org.eclipse.jdt.internal.corext.refactoring.changes.RenamePackageChange)3 ChangeInfo (org.eclipse.che.ide.ext.java.shared.dto.refactoring.ChangeInfo)2 IResource (org.eclipse.core.resources.IResource)1 IPath (org.eclipse.core.runtime.IPath)1 Path (org.eclipse.core.runtime.Path)1 RenameJavaElementDescriptor (org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor)1 CompilationUnit (org.eclipse.jdt.internal.core.CompilationUnit)1 DynamicValidationRefactoringChange (org.eclipse.jdt.internal.corext.refactoring.changes.DynamicValidationRefactoringChange)1 DynamicValidationStateChange (org.eclipse.jdt.internal.corext.refactoring.changes.DynamicValidationStateChange)1 MoveCompilationUnitChange (org.eclipse.jdt.internal.corext.refactoring.changes.MoveCompilationUnitChange)1 RenameCompilationUnitChange (org.eclipse.jdt.internal.corext.refactoring.changes.RenameCompilationUnitChange)1 Change (org.eclipse.ltk.core.refactoring.Change)1 CompositeChange (org.eclipse.ltk.core.refactoring.CompositeChange)1 UndoTextFileChange (org.eclipse.ltk.core.refactoring.UndoTextFileChange)1