Search in sources :

Example 36 with NullProgressMonitor

use of org.eclipse.core.runtime.NullProgressMonitor in project che by eclipse.

the class RefactoringHistoryService method deleteRefactoringHistory.

/**
	 * Deletes the refactoring history of a project. Refactorings associated
	 * with the workspace are not deleted.
	 * <p>
	 * If a refactoring history is deleted, all files stored in the hidden
	 * refactoring history folder of the project folder are removed. If no
	 * shared refactoring history is enabled, the refactoring history
	 * information is removed from the internal workspace refactoring history.
	 * </p>
	 *
	 * @param project
	 *            the project to delete its history
	 * @param monitor
	 *            the progress monitor to use, or <code>null</code>
	 * @throws CoreException
	 *             if an error occurs while deleting the refactoring history.
	 *             Reasons include:
	 *             <ul>
	 *             <li>An I/O error occurs while deleting the refactoring
	 *             history.</li>
	 *             </ul>
	 */
public void deleteRefactoringHistory(final IProject project, IProgressMonitor monitor) throws CoreException {
    Assert.isNotNull(project);
    if (monitor == null)
        monitor = new NullProgressMonitor();
    try {
        monitor.beginTask(RefactoringCoreMessages.RefactoringHistoryService_deleting_refactorings, 100);
        final String name = project.getName();
        final IFileStore stateStore = EFS.getLocalFileSystem().getStore(RefactoringCorePlugin.getDefault().getStateLocation());
        if (name.equals(NAME_WORKSPACE_PROJECT)) {
            final IFileStore metaStore = stateStore.getChild(NAME_HISTORY_FOLDER).getChild(name);
            metaStore.delete(EFS.NONE, new SubProgressMonitor(monitor, 100));
        } else {
            final URI uri = project.getLocationURI();
            if (uri != null && project.isAccessible()) {
                try {
                    final IFileStore metaStore = stateStore.getChild(NAME_HISTORY_FOLDER).getChild(name);
                    metaStore.delete(EFS.NONE, new SubProgressMonitor(monitor, 20));
                    final IFileStore projectStore = EFS.getStore(uri).getChild(NAME_HISTORY_FOLDER);
                    projectStore.delete(EFS.NONE, new SubProgressMonitor(monitor, 20));
                } finally {
                    project.refreshLocal(IResource.DEPTH_INFINITE, new SubProgressMonitor(monitor, 60));
                }
            }
        }
    } finally {
        monitor.done();
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFileStore(org.eclipse.core.filesystem.IFileStore) URI(java.net.URI) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

Example 37 with NullProgressMonitor

use of org.eclipse.core.runtime.NullProgressMonitor in project che by eclipse.

the class UndoableOperation2ChangeAdapter method execute.

public IStatus execute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
    if (monitor == null)
        monitor = new NullProgressMonitor();
    try {
        ExecuteResult result = executeChange(getQuery(info, RefactoringCoreMessages.Refactoring_execute_label), monitor);
        if (!result.changeExecuted) {
            return createStatus(result);
        }
        fUndoChange = result.reverseChange;
        fActiveChange = fUndoChange;
        fExecuteChange = null;
        return Status.OK_STATUS;
    } catch (CoreException e) {
        throw new ExecutionException(e.getStatus().getMessage(), e);
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) ExecutionException(org.eclipse.core.commands.ExecutionException)

Example 38 with NullProgressMonitor

use of org.eclipse.core.runtime.NullProgressMonitor in project che by eclipse.

the class RenameNonPrivateFieldTest method helper2.

private void helper2(String fieldName, String newFieldName, boolean createDelegates) throws Exception {
    ParticipantTesting.reset();
    ICompilationUnit cu = createCUfromTestFile(getPackageP(), "A");
    IType classA = getType(cu, "A");
    IField field = classA.getField(fieldName);
    boolean isEnum = JdtFlags.isEnum(field);
    String id = isEnum ? IJavaRefactorings.RENAME_ENUM_CONSTANT : IJavaRefactorings.RENAME_FIELD;
    RenameJavaElementDescriptor descriptor = RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(id);
    descriptor.setJavaElement(field);
    descriptor.setNewName(newFieldName);
    descriptor.setUpdateReferences(fUpdateReferences);
    descriptor.setUpdateTextualOccurrences(fUpdateTextualMatches);
    if (!isEnum) {
        descriptor.setRenameGetters(fRenameGetter);
        descriptor.setRenameSetters(fRenameSetter);
        descriptor.setKeepOriginal(createDelegates);
        descriptor.setDeprecateDelegate(true);
    }
    RenameRefactoring refactoring = (RenameRefactoring) createRefactoring(descriptor);
    RenameFieldProcessor processor = (RenameFieldProcessor) refactoring.getProcessor();
    List elements = new ArrayList();
    elements.add(field);
    List args = new ArrayList();
    args.add(new RenameArguments(newFieldName, fUpdateReferences));
    if (fRenameGetter) {
        elements.add(processor.getGetter());
        args.add(new RenameArguments(processor.getNewGetterName(), fUpdateReferences));
    }
    if (fRenameSetter) {
        elements.add(processor.getSetter());
        args.add(new RenameArguments(processor.getNewSetterName(), fUpdateReferences));
    }
    String[] renameHandles = ParticipantTesting.createHandles(elements.toArray());
    RefactoringStatus result = performRefactoring(refactoring);
    assertEquals("was supposed to pass", null, result);
    assertEqualLines("invalid renaming", getFileContents(getOutputTestFileName("A")), cu.getSource());
    ParticipantTesting.testRename(renameHandles, (RenameArguments[]) args.toArray(new RenameArguments[args.size()]));
    assertTrue("anythingToUndo", RefactoringCore.getUndoManager().anythingToUndo());
    assertTrue("! anythingToRedo", !RefactoringCore.getUndoManager().anythingToRedo());
    RefactoringCore.getUndoManager().performUndo(null, new NullProgressMonitor());
    assertEqualLines("invalid undo", getFileContents(getInputTestFileName("A")), cu.getSource());
    assertTrue("! anythingToUndo", !RefactoringCore.getUndoManager().anythingToUndo());
    assertTrue("anythingToRedo", RefactoringCore.getUndoManager().anythingToRedo());
    RefactoringCore.getUndoManager().performRedo(null, new NullProgressMonitor());
    assertEqualLines("invalid redo", getFileContents(getOutputTestFileName("A")), cu.getSource());
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) RenameArguments(org.eclipse.ltk.core.refactoring.participants.RenameArguments) RenameRefactoring(org.eclipse.ltk.core.refactoring.participants.RenameRefactoring) ArrayList(java.util.ArrayList) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) RenameFieldProcessor(org.eclipse.jdt.internal.corext.refactoring.rename.RenameFieldProcessor) IField(org.eclipse.jdt.core.IField) IType(org.eclipse.jdt.core.IType) ArrayList(java.util.ArrayList) List(java.util.List) RenameJavaElementDescriptor(org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor)

Example 39 with NullProgressMonitor

use of org.eclipse.core.runtime.NullProgressMonitor in project che by eclipse.

the class RenamePackageTest method performUndo.

private void performUndo() throws Exception {
    IUndoManager um = RefactoringCore.getUndoManager();
    assertTrue(um.anythingToUndo());
    um.performUndo(null, new NullProgressMonitor());
    assertFalse(um.anythingToUndo());
    assertTrue(um.anythingToRedo());
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IUndoManager(org.eclipse.ltk.core.refactoring.IUndoManager)

Example 40 with NullProgressMonitor

use of org.eclipse.core.runtime.NullProgressMonitor in project che by eclipse.

the class Rename18Test method renameLocalVariable.

private void renameLocalVariable(String newFieldName, boolean updateReferences) throws Exception {
    ParticipantTesting.reset();
    ICompilationUnit cu = createCUfromTestFile(getPackageP(), "A");
    ISourceRange selection = getSelection(cu);
    IJavaElement[] elements = cu.codeSelect(selection.getOffset(), selection.getLength());
    assertEquals(1, elements.length);
    RenameJavaElementDescriptor descriptor = RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(IJavaRefactorings.RENAME_LOCAL_VARIABLE);
    descriptor.setJavaElement(elements[0]);
    descriptor.setNewName(newFieldName);
    descriptor.setUpdateReferences(updateReferences);
    descriptor.setUpdateTextualOccurrences(false);
    RenameRefactoring refactoring = (RenameRefactoring) createRefactoring(descriptor);
    List list = new ArrayList();
    list.add(elements[0]);
    List args = new ArrayList();
    args.add(new RenameArguments(newFieldName, updateReferences));
    String[] renameHandles = ParticipantTesting.createHandles(list.toArray());
    RefactoringStatus result = performRefactoring(refactoring);
    assertEquals("was supposed to pass", null, result);
    assertEqualLines("invalid renaming", getFileContents(getOutputTestFileName("A")), cu.getSource());
    ParticipantTesting.testRename(renameHandles, (RenameArguments[]) args.toArray(new RenameArguments[args.size()]));
    assertTrue("anythingToUndo", RefactoringCore.getUndoManager().anythingToUndo());
    assertTrue("! anythingToRedo", !RefactoringCore.getUndoManager().anythingToRedo());
    RefactoringCore.getUndoManager().performUndo(null, new NullProgressMonitor());
    assertEqualLines("invalid undo", getFileContents(getInputTestFileName("A")), cu.getSource());
    assertTrue("! anythingToUndo", !RefactoringCore.getUndoManager().anythingToUndo());
    assertTrue("anythingToRedo", RefactoringCore.getUndoManager().anythingToRedo());
    RefactoringCore.getUndoManager().performRedo(null, new NullProgressMonitor());
    assertEqualLines("invalid redo", getFileContents(getOutputTestFileName("A")), cu.getSource());
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IJavaElement(org.eclipse.jdt.core.IJavaElement) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) RenameArguments(org.eclipse.ltk.core.refactoring.participants.RenameArguments) RenameRefactoring(org.eclipse.ltk.core.refactoring.participants.RenameRefactoring) ArrayList(java.util.ArrayList) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) ArrayList(java.util.ArrayList) List(java.util.List) RenameJavaElementDescriptor(org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor) ISourceRange(org.eclipse.jdt.core.ISourceRange)

Aggregations

NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1626 CoreException (org.eclipse.core.runtime.CoreException)430 Test (org.junit.Test)353 IFile (org.eclipse.core.resources.IFile)316 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)276 IProject (org.eclipse.core.resources.IProject)261 File (java.io.File)213 IPath (org.eclipse.core.runtime.IPath)184 IOException (java.io.IOException)162 Path (org.eclipse.core.runtime.Path)141 ArrayList (java.util.ArrayList)125 IStatus (org.eclipse.core.runtime.IStatus)116 IFolder (org.eclipse.core.resources.IFolder)90 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)70 List (java.util.List)63 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)63 InvocationTargetException (java.lang.reflect.InvocationTargetException)61 IProjectDescription (org.eclipse.core.resources.IProjectDescription)58 Status (org.eclipse.core.runtime.Status)57 IResource (org.eclipse.core.resources.IResource)56