예제 #1
0
  void processAction(ITextEditor textEditor, IDocument document, ITextSelection textSelection) {
    int openCommentOffset = textSelection.getOffset();
    int closeCommentOffset = openCommentOffset + textSelection.getLength();

    if (textSelection.getLength() == 0) {
      return;
    }

    IStructuredModel model =
        StructuredModelManager.getModelManager().getExistingModelForEdit(document);
    if (model != null) {
      try {
        model.beginRecording(this, PHPUIMessages.AddBlockComment_tooltip);
        model.aboutToChangeModel();

        try {
          document.replace(closeCommentOffset, 0, CLOSE_COMMENT);
          document.replace(openCommentOffset, 0, OPEN_COMMENT);
        } catch (BadLocationException e) {
          Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e);
        } finally {
          model.changedModel();
          model.endRecording(this);
        }
      } finally {
        model.releaseFromEdit();
      }
    }
  }
 /**
  * Test expectes an exception since only a changedModel sent, without beginning
  * 'aboutToChangeModel'
  *
  * @throws CoreException
  * @throws IOException
  */
 public void testChangedModel() throws IOException, CoreException {
   IStructuredModel model = getTestModel();
   try {
     try {
       model.changedModel();
     } catch (Exception e) {
       assertTrue(e instanceof IllegalStateException);
     }
   } finally {
     if (model != null) {
       model.releaseFromEdit();
     }
   }
 }