@Override
 public RefactoringStatus checkNewName(String newName) {
   RefactoringStatus result = new RefactoringStatus();
   if (Objects.equal(newName, getCurrentName())) {
     result.addFatalError("Choose another name.");
   }
   return result;
 }
 @Override
 public RefactoringStatus checkFinalConditions(ProgressMonitor pm) throws Exception {
   pm = checkProgressMonitor(pm);
   pm.beginTask("Checking final conditions", 1);
   try {
     RefactoringStatus result = new RefactoringStatus();
     result.merge(analyzePossibleConflicts(new SubProgressMonitor(pm, 1)));
     return result;
   } finally {
     pm.done();
   }
 }
 public void test_checkAllConditions_fatalInitial() throws Exception {
   Refactoring refactoring = mock(RefactoringImpl.class);
   when(refactoring.checkAllConditions(any(ProgressMonitor.class))).thenCallRealMethod();
   // initial
   RefactoringStatus initialStatus = new RefactoringStatus();
   initialStatus.addFatalError("fatal-msg");
   when(refactoring.checkInitialConditions(any(ProgressMonitor.class))).thenReturn(initialStatus);
   // check all conditions
   RefactoringStatus result = refactoring.checkAllConditions(pm);
   assertTrue(result.hasFatalError());
   assertEquals("fatal-msg", result.getMessage());
   verify(refactoring, times(0)).checkFinalConditions(any(ProgressMonitor.class));
 }
 public void test_toLTK_RefactoringStatus() throws Exception {
   RefactoringStatus serviceStatus = RefactoringStatus.createErrorStatus("msg");
   org.eclipse.ltk.core.refactoring.RefactoringStatus ltkStatus =
       ServiceUtils.toLTK(serviceStatus);
   org.eclipse.ltk.core.refactoring.RefactoringStatusEntry[] ltkEntries = ltkStatus.getEntries();
   assertThat(ltkEntries).hasSize(1);
   // entry[0]
   assertEquals("msg", ltkEntries[0].getMessage());
   assertEquals(
       org.eclipse.ltk.core.refactoring.RefactoringStatus.ERROR, ltkEntries[0].getSeverity());
 }
 public void test_checkAllConditions_checkInitial_checkFinal() throws Exception {
   Refactoring refactoring = mock(RefactoringImpl.class);
   when(refactoring.checkAllConditions(any(ProgressMonitor.class))).thenCallRealMethod();
   // initial
   RefactoringStatus initialStatus = new RefactoringStatus();
   initialStatus.addWarning("warn-1");
   when(refactoring.checkInitialConditions(any(ProgressMonitor.class))).thenReturn(initialStatus);
   // initial
   RefactoringStatus finalStatus = new RefactoringStatus();
   finalStatus.addWarning("warn-2");
   when(refactoring.checkFinalConditions(any(ProgressMonitor.class))).thenReturn(finalStatus);
   // check all conditions
   RefactoringStatus result = refactoring.checkAllConditions(pm);
   assertTrue(result.hasWarning());
   List<RefactoringStatusEntry> entries = result.getEntries();
   assertThat(entries).hasSize(2);
   assertEquals("warn-1", entries.get(0).getMessage());
   assertEquals("warn-2", entries.get(1).getMessage());
 }
 @Override
 public RefactoringStatus checkNewName(String newName) {
   RefactoringStatus result = new RefactoringStatus();
   result.merge(super.checkNewName(newName));
   if (element instanceof LocalVariableElement) {
     LocalVariableElement variableElement = (LocalVariableElement) element;
     if (variableElement.isConst()) {
       result.merge(NamingConventions.validateConstantName(newName));
     } else {
       result.merge(NamingConventions.validateVariableName(newName));
     }
   } else if (element instanceof ParameterElement) {
     result.merge(NamingConventions.validateParameterName(newName));
   } else if (element instanceof FunctionElement) {
     result.merge(NamingConventions.validateFunctionName(newName));
   }
   return result;
 }