Examples of IRewriteTarget


Examples of org.eclipse.jface.text.IRewriteTarget

            String delim;
            String insertion;
            int offset;
            int length;
            ILineRange selectionBefore = getLineRange(document, movingArea);
            IRewriteTarget target = null;
            if (pyEdit != null) {
                target = (IRewriteTarget) pyEdit.getAdapter(IRewriteTarget.class);
                if (target != null) {
                    target.beginCompoundChange();
                    if (!getMoveUp()) {
                        //When going up we'll just do a single document change, so, there's
                        //no need to set the redraw.
                        target.setRedraw(false);
                    }
                }
            }
            ILineRange selectionAfter;
            boolean isStringPartition;
            try {
                if (getMoveUp()) {
                    //check partition in the start of the skipped line
                    isStringPartition = ParsingUtils.isStringPartition(document, skippedLine.getOffset());
                    delim = document.getLineDelimiter(skippedLine.getEndLine());
                    Assert.isNotNull(delim);
                    offset = skippedLine.getOffset();
                    length = moving.length() + delim.length() + skipped.length();
                } else {
                    //check partition in the start of the line after the skipped line
                    int offsetToCheckPartition;
                    if (skippedLine.getEndLine() == document.getNumberOfLines() - 1) {
                        offsetToCheckPartition = document.getLength() - 1; //check the last document char
                    } else {
                        offsetToCheckPartition = skippedLine.getOffset() + skippedLine.getLength(); //that's always the '\n' of the line
                    }

                    isStringPartition = ParsingUtils.isStringPartition(document, offsetToCheckPartition);

                    delim = document.getLineDelimiter(movingArea.getEndLine());
                    Assert.isNotNull(delim);
                    offset = movingArea.getOffset();

                    //When going down, we need to remove the movingArea to compute the new indentation
                    //properly (otherwise we'd use that text being moved on the compute algorithm)
                    document.replace(movingArea.getOffset(), movingArea.getLength() + delim.length(), "");
                    length = skipped.length();
                    int pos = skippedPs.getAbsoluteCursorOffset() - (movingArea.getLength() + delim.length());
                    skippedPs.setSelection(pos, pos);
                }

                PyAutoIndentStrategy indentStrategy = null;
                if (pyEdit != null) {
                    indentStrategy = pyEdit.getAutoEditStrategy();
                }
                if (indentStrategy == null) {
                    indentStrategy = new PyAutoIndentStrategy();
                }

                if (!isStringPartition) {
                    if (indentStrategy.getIndentPrefs().getSmartLineMove()) {
                        String prevExpectedIndent = calculateNewIndentationString(document, skippedPs, indentStrategy);
                        if (prevExpectedIndent != null) {
                            moving = StringUtils.removeWhitespaceColumnsToLeftAndApplyIndent(moving,
                                    prevExpectedIndent, false);
                        }
                    }
                }
                if (getMoveUp()) {
                    insertion = moving + delim + skipped;

                } else {
                    insertion = skipped + delim + moving;
                }

                // modify the document
                document.replace(offset, length, insertion);

                if (getMoveUp()) {
                    selectionAfter = new LineRange(selectionBefore.getStartLine() - 1,
                            selectionBefore.getNumberOfLines());
                } else {
                    selectionAfter = new LineRange(selectionBefore.getStartLine() + 1,
                            selectionBefore.getNumberOfLines());
                }
            } finally {
                if (target != null) {
                    target.endCompoundChange();
                    if (!getMoveUp()) {
                        target.setRedraw(true);
                    }
                }
            }

            // move the selection along
View Full Code Here

Examples of org.eclipse.jface.text.IRewriteTarget

        fInformationPresenter.showInformation();
        return;
      case FORMAT:
        {
          final Point selection= rememberSelection();
          final IRewriteTarget target= getRewriteTarget();
          final IDocument document= getDocument();
          IFormattingContext context= null;
          DocumentRewriteSession rewriteSession= null;

          if (document instanceof IDocumentExtension4) {
            IDocumentExtension4 extension= (IDocumentExtension4) document;
            DocumentRewriteSessionType type= (selection.y == 0 && document.getLength() > 1000) || selection.y > 1000
              ? DocumentRewriteSessionType.SEQUENTIAL
              : DocumentRewriteSessionType.UNRESTRICTED_SMALL;
            rewriteSession= extension.startRewriteSession(type);
          } else {
            setRedraw(false);
            target.beginCompoundChange();
          }

          try {

            final String rememberedContents= document.get();

            try {

              if (fContentFormatter instanceof IContentFormatterExtension) {
                final IContentFormatterExtension extension= (IContentFormatterExtension) fContentFormatter;
                context= createFormattingContext();
                if (selection.y == 0) {
                  context.setProperty(FormattingContextProperties.CONTEXT_DOCUMENT, Boolean.TRUE);
                } else {
                  context.setProperty(FormattingContextProperties.CONTEXT_DOCUMENT, Boolean.FALSE);
                  context.setProperty(FormattingContextProperties.CONTEXT_REGION, new Region(selection.x, selection.y));
                }
                extension.format(document, context);
              } else {
                IRegion r;
                if (selection.y == 0) {
                  IRegion coverage= getModelCoverage();
                  r= coverage == null ? new Region(0, 0) : coverage;
                } else {
                  r= new Region(selection.x, selection.y);
                }
                fContentFormatter.format(document, r);
              }

              updateSlaveDocuments(document);

            } catch (RuntimeException x) {
              // fire wall for https://bugs.eclipse.org/bugs/show_bug.cgi?id=47472
              // if something went wrong we undo the changes we just did
              // TODO to be removed after 3.0 M8
              document.set(rememberedContents);
              throw x;
            }

          } finally {

            if (document instanceof IDocumentExtension4) {
              IDocumentExtension4 extension= (IDocumentExtension4) document;
              extension.stopRewriteSession(rewriteSession);
            } else {
              target.endCompoundChange();
              setRedraw(true);
            }

            restoreSelection();
            if (context != null)
View Full Code Here

Examples of org.eclipse.jface.text.IRewriteTarget

  }

  private void endCompoundChange() {
    if (fHasOpenCompoundChange) {
      ITextViewerExtension extension= (ITextViewerExtension) fCurrentTarget.getViewer();
      IRewriteTarget target= extension.getRewriteTarget();
      target.endCompoundChange();
      fHasOpenCompoundChange= false;
    }
  }
View Full Code Here

Examples of org.eclipse.jface.text.IRewriteTarget

  }

  private void beginCompoundChange() {
    if (!fHasOpenCompoundChange) {
      ITextViewerExtension extension= (ITextViewerExtension) fCurrentTarget.getViewer();
      IRewriteTarget target= extension.getRewriteTarget();
      target.beginCompoundChange();
      fHasOpenCompoundChange= true;
    }
  }
View Full Code Here

Examples of org.eclipse.jface.text.IRewriteTarget

   * @since 2.1
   */
  private void insertProposal(ICompletionProposal p, char trigger, int stateMask, final int offset) {

    fInserting= true;
    IRewriteTarget target= null;
    IEditingSupportRegistry registry= null;

    try {

      IDocument document= fViewer.getDocument();

      if (fViewer instanceof ITextViewerExtension) {
        ITextViewerExtension extension= (ITextViewerExtension) fViewer;
        target= extension.getRewriteTarget();
      }

      if (target != null)
        target.beginCompoundChange();

      if (fViewer instanceof IEditingSupportRegistry) {
        registry= (IEditingSupportRegistry) fViewer;
        registry.register(fModificationEditingSupport);
      }

      if (p instanceof ICompletionProposalExtension2) {
        ICompletionProposalExtension2 e= (ICompletionProposalExtension2) p;
        e.apply(fViewer, trigger, stateMask, offset);
      } else if (p instanceof ICompletionProposalExtension) {
        ICompletionProposalExtension e= (ICompletionProposalExtension) p;
        e.apply(document, trigger, offset);
      } else {
        p.apply(document);
      }

      Point selection= p.getSelection(document);
      if (selection != null) {
        fViewer.setSelectedRange(selection.x, selection.y);
        fViewer.revealRange(selection.x, selection.y);
      }

      IContextInformation info= p.getContextInformation();
      if (info != null) {

        int position;
        if (p instanceof ICompletionProposalExtension) {
          ICompletionProposalExtension e= (ICompletionProposalExtension) p;
          position= e.getContextInformationPosition();
        } else {
          if (selection == null)
            selection= fViewer.getSelectedRange();
          position= selection.x + selection.y;
        }

        fContentAssistant.showContextInformation(info, position);
      }

      fContentAssistant.fireProposalChosen(p);

    } finally {
      if (target != null)
        target.endCompoundChange();

      if (registry != null)
        registry.unregister(fModificationEditingSupport);

      fInserting= false;
View Full Code Here

Examples of org.eclipse.jface.text.IRewriteTarget

   * @since 2.1
   */
  private void insertProposal(ICompletionProposal p, char trigger, int stateMask, final int offset) {

    fInserting= true;
    IRewriteTarget target= null;
    IEditingSupport helper= new IEditingSupport() {

      public boolean isOriginator(DocumentEvent event, IRegion focus) {
        return focus.getOffset() <= offset && focus.getOffset() + focus.getLength() >= offset;
      }

      public boolean ownsFocusShell() {
        return false;
      }

    };

    try {

      IDocument document= fContentAssistSubjectControlAdapter.getDocument();

      if (fViewer instanceof ITextViewerExtension) {
        ITextViewerExtension extension= (ITextViewerExtension) fViewer;
        target= extension.getRewriteTarget();
      }

      if (target != null)
        target.beginCompoundChange();

      if (fViewer instanceof IEditingSupportRegistry) {
        IEditingSupportRegistry registry= (IEditingSupportRegistry) fViewer;
        registry.register(helper);
      }


      if (p instanceof ICompletionProposalExtension2 && fViewer != null) {
        ICompletionProposalExtension2 e= (ICompletionProposalExtension2) p;
        e.apply(fViewer, trigger, stateMask, offset);
      } else if (p instanceof ICompletionProposalExtension) {
        ICompletionProposalExtension e= (ICompletionProposalExtension) p;
        e.apply(document, trigger, offset);
      } else {
        p.apply(document);
      }

      Point selection= p.getSelection(document);
      if (selection != null) {
        fContentAssistSubjectControlAdapter.setSelectedRange(selection.x, selection.y);
        fContentAssistSubjectControlAdapter.revealRange(selection.x, selection.y);
      }

      IContextInformation info= p.getContextInformation();
      if (info != null) {

        int contextInformationOffset;
        if (p instanceof ICompletionProposalExtension) {
          ICompletionProposalExtension e= (ICompletionProposalExtension) p;
          contextInformationOffset= e.getContextInformationPosition();
        } else {
          if (selection == null)
            selection= fContentAssistSubjectControlAdapter.getSelectedRange();
          contextInformationOffset= selection.x + selection.y;
        }

        fContentAssistant.showContextInformation(info, contextInformationOffset);
      } else
        fContentAssistant.showContextInformation(null, -1);


    } finally {
      if (target != null)
        target.endCompoundChange();

      if (fViewer instanceof IEditingSupportRegistry) {
        IEditingSupportRegistry registry= (IEditingSupportRegistry) fViewer;
        registry.unregister(helper);
      }
View Full Code Here

Examples of org.eclipse.jface.text.IRewriteTarget

   *             Thrown when the invocation of the change failed.
   */
  protected void performChange(IEditorPart activeEditor, IDocument document)
      throws CoreException {
    Change change = null;
    IRewriteTarget rewriteTarget = null;
    try {
      change = getChange();
      if (change != null) {
        if (document != null) {
          LinkedModeModel.closeAllModels(document);
        }
        if (activeEditor != null) {
          rewriteTarget = (IRewriteTarget) activeEditor
              .getAdapter(IRewriteTarget.class);
          if (rewriteTarget != null) {
            rewriteTarget.beginCompoundChange();
          }
        }

        change.initializeValidationData(new NullProgressMonitor());
        RefactoringStatus valid = change
            .isValid(new NullProgressMonitor());
        if (valid.hasFatalError()) {
          IStatus status = new Status(
              IStatus.ERROR,
              PHPUiPlugin.ID,
              IStatus.ERROR,
              valid
                  .getMessageMatchingSeverity(RefactoringStatus.FATAL),
              null);
          throw new CoreException(status);
        } else {
          IUndoManager manager = RefactoringCore.getUndoManager();
          Change undoChange;
          boolean successful = false;
          try {
            manager.aboutToPerformChange(change);
            undoChange = change.perform(new NullProgressMonitor());
            successful = true;
          } finally {
            manager.changePerformed(change, successful);
          }
          if (undoChange != null) {
            undoChange
                .initializeValidationData(new NullProgressMonitor());
            manager.addUndo(getName(), undoChange);
          }
        }
      }
    } finally {
      if (rewriteTarget != null) {
        rewriteTarget.endCompoundChange();
      }

      if (change != null) {
        change.dispose();
      }
View Full Code Here

Examples of org.eclipse.jface.text.IRewriteTarget

          event.detail= DND.DROP_NONE;
          return;
        }

        // Start compound change
        IRewriteTarget target= (IRewriteTarget)editor.getAdapter(IRewriteTarget.class);
        if (target != null)
          target.beginCompoundChange();
      }

      if (!((AbstractTextEditor) editor).validateEditorInputState()) {
        event.detail= DND.DROP_NONE;
        return;
View Full Code Here

Examples of org.eclipse.jface.text.IRewriteTarget

          delta= length;
        textWidget.replaceTextRange(fSelection.x + delta, length, ""); //$NON-NLS-1$

        if (fTextDragAndDropToken == null) {
          // Move in same editor - end compound change
          IRewriteTarget target= (IRewriteTarget)editor.getAdapter(IRewriteTarget.class);
          if (target != null)
            target.endCompoundChange();
        }

      }
    } finally {
      fTextDragAndDropToken= null;
View Full Code Here

Examples of org.eclipse.jface.text.IRewriteTarget

  public void run(IAction action){
    //checks to see if you can edit the document
    try {
      if(editor != null && editor.isEditable()){
        // make the edit atomic so one undo undos
        IRewriteTarget target = (IRewriteTarget) editor.getAdapter(IRewriteTarget.class);
        if (target != null)
          target.beginCompoundChange();
        String openComment = "<!--- ";
        String closeComment = " --->";
        int selectionLength = 0;
        // Get the document
        IDocument doc = editor.getDocumentProvider().getDocument(editor.getEditorInput());
        String lineEnding = doc.getLineDelimiter(0);
       
        // Get the selection
        ISelection sel = editor.getSelectionProvider().getSelection();
        ITextSelection selectioner = (ITextSelection) sel;
        // Get the partition
        ITypedRegion partition = doc.getPartition(((ITextSelection)sel).getOffset());
        String partType = partition.getType();
        if (partType.equals(CFPartitionScanner.CF_SCRIPT) || partType.equals(CFPartitionScanner.CF_SCRIPT_COMMENT_BLOCK)
            || partType.equals(CFPartitionScanner.JAVADOC_COMMENT) || partType.equals(CFPartitionScanner.CF_SCRIPT_COMMENT)) {
          openComment = "/*";
          closeComment = "*/";
        }
       
        // if we already are in a comment partition, remove it, else add it
        if (partType.equals(CFPartitionScanner.CF_COMMENT) || partType.equals(CFPartitionScanner.CF_SCRIPT_COMMENT_BLOCK)
            || partType.equals(CFPartitionScanner.JAVADOC_COMMENT) || partType.equals(CFPartitionScanner.CF_SCRIPT_COMMENT)) {
          // Track the position in the document that the actual comments blocks are
          int openCommentStart = partition.getOffset();
          int closeCommentStart = partition.getOffset();
         
          // Find the full partition selection string
          String selection = doc.get().substring(partition.getOffset(), partition.getOffset() + partition.getLength());
         
          // Find the opening comment information with optional space at the end
          Pattern pattern = Pattern.compile("^(" + openComment.replace("*", "[*]") + "[ ]?[" + lineEnding + "]?)");
          Matcher matcher = pattern.matcher(selection);
         
          if(matcher.find()) {
            openComment = matcher.group();
            openCommentStart += matcher.start();
          }
         
          // Find the closing comment information with optional space at the beginning
          pattern = Pattern.compile("([" + lineEnding + "]?[ ]?" + closeComment.replace("*", "[*]") + ")$");
          matcher = pattern.matcher(selection);
         
          if(matcher.find()) {
            closeComment = matcher.group();
            closeCommentStart += matcher.start();
          }
         
          // Only get rid of the newline characters if the open and close both have them
          // Check to see if the open has a newline but the close doesn't
          if (selectioner.getText().endsWith(lineEnding) && selectioner.getText().startsWith(openComment + lineEnding)) {
            openComment = openComment.substring(lineEnding.length() - 1, openComment.length() - lineEnding.length());
          }
         
          FindReplaceDocumentAdapter finder = new FindReplaceDocumentAdapter(doc);
         
          // Find and replace the closing comment first so that it doesn't get messed up with positions
          finder.find(closeCommentStart, closeComment, true, false, false, false);
          finder.replace("", false);
         
          // Find and replace the opening comment so that it doesn't affect the closing comment replace
          finder.find(openCommentStart, openComment, true, false, false, false);
          finder.replace("", false);
          selectionLength = selection.length() - openComment.length() - closeComment.length() + 1;
        } else {
          if(selectioner.getText().endsWith("\n") && !selectioner.getText().startsWith("\n")){           
            // add newlines if this looks like a newline-to-newline comment, to be pretty
            openComment = openComment.concat("\n");
            closeComment = closeComment.concat("\n");
          }
          selectionLength = this.enclose(doc,(ITextSelection)sel, openComment, closeComment);
         
          // move the caret somewhere
        }
        if (selectioner.getLength() == 0) {
          editor.setHighlightRange(selectioner.getOffset() + openComment.length(), 1, true);
        } else {
          editor.selectAndReveal(selectioner.getOffset(), selectionLength);
        }
        if (target != null)
          target.endCompoundChange();

      }
    } catch (BadLocationException e) {
      e.printStackTrace(System.err);
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.