private void textModified(String text) {
   fRefactoring.setMethodName(text);
   RefactoringStatus status = validatePage(true);
   if (!status.hasFatalError()) {
     updatePreview(text);
   } else {
     fSignaturePreviewDocument.set(""); // $NON-NLS-1$
   }
   setPageComplete(status);
 }
  @Test
  public void indentFromPreviousLineShouldBeAdded() {
    document.set("    abc");
    command.offset = 7;
    command.text = "\n";

    strategy.customizeDocumentCommand(document, command);

    assertThat(command.text).isEqualTo("\n    ");
  }
  @Test
  public void indentShouldNotBeAdded_whenPreviousLineDoesNotStartFromIndent() {
    document.set("xyz");
    command.offset = 3;
    command.text = "\n";

    strategy.customizeDocumentCommand(document, command);

    assertThat(command.text).isEqualTo("\n");
  }
  @Test
  public void commandShouldNotBeChanged_whenItIsNotLineBreak() {
    document.set("x");
    command.offset = 1;
    command.text = "q";

    strategy.customizeDocumentCommand(document, command);

    assertThat(command.text).isEqualTo("q");
  }
 private void updateSignaturePreview() {
   try {
     int top = fSignaturePreview.getTextWidget().getTopPixel();
     fSignaturePreviewDocument.set(getChangeMethodSignatureProcessor().getNewMethodSignature());
     fSignaturePreview.getTextWidget().setTopPixel(top);
   } catch (JavaModelException e) {
     ExceptionHandler.handle(
         e,
         RefactoringMessages.ChangeSignatureRefactoring_modify_Parameters,
         RefactoringMessages.ChangeSignatureInputPage_exception);
   }
 }
  private void updatePreview(String text) {
    if (fSignaturePreview == null) {
      return;
    }

    if (text.length() == 0) {
      text = "someMethodName"; // $NON-NLS-1$
    }

    int top = fSignaturePreview.getTextWidget().getTopPixel();
    String signature;
    try {
      signature = fRefactoring.getSignature(text);
    } catch (IllegalArgumentException e) {
      signature = ""; // $NON-NLS-1$
    }
    fSignaturePreviewDocument.set(signature);
    fSignaturePreview.getTextWidget().setTopPixel(top);
  }
  @Before
  public void prep() throws Exception {
    proj = createProjectAndBuild("wrongDeallocTest"); // $NON-NLS-1$
    ILaunchConfiguration config = createConfiguration(proj.getProject());
    doLaunch(config, "wrongDeallocTest"); // $NON-NLS-1$

    document = new Document();
    InputStream fileInputStream =
        proj.getProject().getFile("wrongDealloc.cpp").getContents(); // $NON-NLS-1$
    try (Scanner scanner = new Scanner(fileInputStream)) {
      scanner.useDelimiter("\\A"); // $NON-NLS-1$
      String content;
      if (scanner.hasNext()) {
        content = scanner.next();
      } else {
        content = EMPTY_STRING;
      }
      document.set(content);
    }
    markers = proj.getProject().findMarkers(VALGRIND_MARKER_TYPE, true, 1);
    Arrays.sort(markers, new MarkerComparator());
  }