Search in sources :

Example 41 with NullProgressMonitor

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

the class RenameMethodInInterfaceTest method helper2_0.

private void helper2_0(String methodName, String newMethodName, String[] signatures, boolean shouldPass, boolean updateReferences, boolean createDelegate) throws Exception {
    ICompilationUnit cu = createCUfromTestFile(getPackageP(), "A");
    IType interfaceI = getType(cu, "I");
    IMethod method = interfaceI.getMethod(methodName, signatures);
    RenameJavaElementDescriptor descriptor = RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(IJavaRefactorings.RENAME_METHOD);
    descriptor.setJavaElement(method);
    descriptor.setUpdateReferences(updateReferences);
    descriptor.setNewName(newMethodName);
    descriptor.setKeepOriginal(createDelegate);
    descriptor.setDeprecateDelegate(true);
    assertEquals("was supposed to pass", null, performRefactoring(descriptor));
    if (!shouldPass) {
        assertTrue("incorrect renaming because of a java model bug", !getFileContents(getOutputTestFileName("A")).equals(cu.getSource()));
        return;
    }
    assertEqualLines("incorrect renaming", getFileContents(getOutputTestFileName("A")), cu.getSource());
    assertTrue("anythingToUndo", RefactoringCore.getUndoManager().anythingToUndo());
    assertTrue("! anythingToRedo", !RefactoringCore.getUndoManager().anythingToRedo());
    //assertEquals("1 to undo", 1, Refactoring.getUndoManager().getRefactoringLog().size());
    RefactoringCore.getUndoManager().performUndo(null, new NullProgressMonitor());
    assertEqualLines("invalid undo", getFileContents(getInputTestFileName("A")), cu.getSource());
    assertTrue("! anythingToUndo", !RefactoringCore.getUndoManager().anythingToUndo());
    assertTrue("anythingToRedo", RefactoringCore.getUndoManager().anythingToRedo());
    //assertEquals("1 to redo", 1, Refactoring.getUndoManager().getRedoStack().size());
    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) IMethod(org.eclipse.jdt.core.IMethod) RenameJavaElementDescriptor(org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor) IType(org.eclipse.jdt.core.IType)

Example 42 with NullProgressMonitor

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

the class RenameVirtualMethodInClassTest method helper2_0.

private void helper2_0(String methodName, String newMethodName, String[] signatures, boolean shouldPass, boolean updateReferences, boolean createDelegate) throws Exception {
    final ICompilationUnit cu = createCUfromTestFile(getPackageP(), "A");
    final IType classA = getType(cu, "A");
    final IMethod method = classA.getMethod(methodName, signatures);
    final RenameJavaElementDescriptor descriptor = RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(IJavaRefactorings.RENAME_METHOD);
    descriptor.setJavaElement(method);
    descriptor.setNewName(newMethodName);
    descriptor.setUpdateReferences(updateReferences);
    descriptor.setKeepOriginal(createDelegate);
    descriptor.setDeprecateDelegate(createDelegate);
    final RefactoringStatus status = new RefactoringStatus();
    final Refactoring refactoring = descriptor.createRefactoring(status);
    assertNotNull("Refactoring should not be null", refactoring);
    assertTrue("status should be ok", status.isOK());
    assertEquals("was supposed to pass", null, performRefactoring(refactoring));
    if (!shouldPass) {
        assertTrue("incorrect renaming because of java model", !getFileContents(getOutputTestFileName("A")).equals(cu.getSource()));
        return;
    }
    String expectedRenaming = getFileContents(getOutputTestFileName("A"));
    String actuaRenaming = cu.getSource();
    assertEqualLines("incorrect renaming", expectedRenaming, actuaRenaming);
    assertTrue("anythingToUndo", RefactoringCore.getUndoManager().anythingToUndo());
    assertTrue("! anythingToRedo", !RefactoringCore.getUndoManager().anythingToRedo());
    //assertEquals("1 to undo", 1, Refactoring.getUndoManager().getRefactoringLog().size());
    RefactoringCore.getUndoManager().performUndo(null, new NullProgressMonitor());
    assertEqualLines("invalid undo", getFileContents(getInputTestFileName("A")), cu.getSource());
    assertTrue("! anythingToUndo", !RefactoringCore.getUndoManager().anythingToUndo());
    assertTrue("anythingToRedo", RefactoringCore.getUndoManager().anythingToRedo());
    //assertEquals("1 to redo", 1, Refactoring.getUndoManager().getRedoStack().size());
    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) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) IMethod(org.eclipse.jdt.core.IMethod) RenameJavaElementDescriptor(org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor) Refactoring(org.eclipse.ltk.core.refactoring.Refactoring) RenameRefactoring(org.eclipse.ltk.core.refactoring.participants.RenameRefactoring) IType(org.eclipse.jdt.core.IType)

Example 43 with NullProgressMonitor

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

the class RenameTypeParameterTest method helper2.

private void helper2(String parameterName, String newParameterName, String typeName, String methodName, String[] methodSignature, boolean references) throws Exception {
    ParticipantTesting.reset();
    ICompilationUnit cu = createCUfromTestFile(getPackageP(), "A");
    IType declaringType = getType(cu, typeName);
    IMethod[] declaringMethods = getMethods(declaringType, new String[] { methodName }, new String[][] { methodSignature });
    ITypeParameter typeParameter = declaringMethods[0].getTypeParameter(parameterName);
    RenameTypeParameterProcessor processor = new RenameTypeParameterProcessor(typeParameter);
    RenameRefactoring refactoring = new RenameRefactoring(processor);
    processor.setNewElementName(newParameterName);
    processor.setUpdateReferences(references);
    RefactoringStatus result = performRefactoring(refactoring);
    assertEquals("was supposed to pass", null, result);
    assertEqualLines("invalid renaming", getFileContents(getOutputTestFileName("A")), cu.getSource());
    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) RenameRefactoring(org.eclipse.ltk.core.refactoring.participants.RenameRefactoring) RenameTypeParameterProcessor(org.eclipse.jdt.internal.corext.refactoring.rename.RenameTypeParameterProcessor) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) ITypeParameter(org.eclipse.jdt.core.ITypeParameter) IMethod(org.eclipse.jdt.core.IMethod) IType(org.eclipse.jdt.core.IType)

Example 44 with NullProgressMonitor

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

the class RenameTypeParameterTest method helper2.

private void helper2(String parameterName, String newParameterName, String typeName, boolean references) throws Exception {
    ParticipantTesting.reset();
    ICompilationUnit cu = createCUfromTestFile(getPackageP(), "A");
    IType declaringType = getType(cu, typeName);
    ITypeParameter typeParameter = declaringType.getTypeParameter(parameterName);
    RenameTypeParameterProcessor processor = new RenameTypeParameterProcessor(typeParameter);
    RenameRefactoring refactoring = new RenameRefactoring(processor);
    processor.setNewElementName(newParameterName);
    processor.setUpdateReferences(references);
    RefactoringStatus result = performRefactoring(refactoring);
    assertEquals("was supposed to pass", null, result);
    assertEqualLines("invalid renaming", getFileContents(getOutputTestFileName("A")), cu.getSource());
    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) RenameRefactoring(org.eclipse.ltk.core.refactoring.participants.RenameRefactoring) RenameTypeParameterProcessor(org.eclipse.jdt.internal.corext.refactoring.rename.RenameTypeParameterProcessor) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) ITypeParameter(org.eclipse.jdt.core.ITypeParameter) IType(org.eclipse.jdt.core.IType)

Example 45 with NullProgressMonitor

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

the class RenameTypeTest method testFailRegression1GCRKMQ.

@Test
public void testFailRegression1GCRKMQ() throws Exception {
    IPackageFragment myPackage = getRoot().createPackageFragment("", true, new NullProgressMonitor());
    IType myClass = getClassFromTestFile(myPackage, "Blinky");
    RefactoringStatus result = performRefactoring(createRefactoringDescriptor(myClass, "B"));
    Assert.assertNotNull("precondition was supposed to fail", result);
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) IType(org.eclipse.jdt.core.IType) Test(org.junit.Test) BaseTest(org.eclipse.che.plugin.java.server.che.BaseTest)

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