Package org.eclipse.ltk.core.refactoring

Examples of org.eclipse.ltk.core.refactoring.TextChange


    if (asyncType != null) {
      String asyncTypeName = asyncType.getFullyQualifiedName();
      // when we move service, Eclipse adds import for Async type,
      // but we don't need it, so remove this import from text change
      {
        TextChange textChange = getTextChange(m_type.getUnderlyingResource());
        if (textChange != null) {
          removeInsertEdits_forSubString(textChange.getEdit(), "import " + asyncTypeName);
          removeInsertEdits_forNewLine(textChange.getEdit());
        }
      }
      // remove Async type, our builder will regenerate it near to moved service type
      compositeChange.add(RefactoringUtils.createDeleteTypeChange(asyncType));
    }
View Full Code Here


  /**
   * Adds {@link TextEdit}s into existing Java file {@link Change}.
   */
  private void addHandlerMethodChanges(CompositeChange compositeChange, IProgressMonitor pm)
      throws Exception {
    TextChange change = new CompilationUnitChange("(No matter)", m_field.getCompilationUnit());
    change.setEdit(new MultiTextEdit());
    // update handler methods
    String oldMethodPrefix = "on" + StringUtils.capitalize(m_oldName);
    String newMethodPrefix = "on" + StringUtils.capitalize(m_newName);
    IType type = (IType) m_field.getParent();
    for (IMethod method : type.getMethods()) {
      // prepare @UiHandler annotation
      IAnnotation annotation = getHandlerAnnotation(method);
      if (annotation == null) {
        continue;
      }
      // update @UiHandler name
      {
        ISourceRange annoRange = annotation.getSourceRange();
        ISourceRange nameRange = annotation.getNameRange();
        int nameEnd = nameRange.getOffset() + nameRange.getLength();
        int annoEnd = annoRange.getOffset() + annoRange.getLength();
        change.addEdit(new ReplaceEdit(nameEnd, annoEnd - nameEnd, "(\"" + m_newName + "\")"));
      }
      // rename method
      String methodName = method.getElementName();
      if (methodName.startsWith(oldMethodPrefix)) {
        String newName = newMethodPrefix + StringUtils.removeStart(methodName, oldMethodPrefix);
View Full Code Here

  public Object getAdditionalProposalInfo(IProgressMonitor monitor) {

    final StringBuffer buf = new StringBuffer();

    try {
      final TextChange change = getTextChange();

      change.setKeepPreviewEdits(true);
      final IDocument previewContent = change.getPreviewDocument(monitor);
      final TextEdit rootEdit = change.getPreviewEdit(change.getEdit());

      class EditAnnotator extends TextEditVisitor {
        private int fWrittenToPos = 0;

        public void unchangedUntil(int pos) {
View Full Code Here

   *             thrown if the creation of the text change failed.
   */
  protected TextChange createTextChange() throws CoreException {
    ISourceModule cu = getCompilationUnit();
    String name = getName();
    TextChange change;
    if (!cu.getResource().exists()) {
      String source;
      try {
        source = cu.getSource();
      } catch (ModelException e) {
        PHPUiPlugin.log(e);
        source = new String(); // empty
      }
      Document document = new Document(source);
      document.setInitialLineDelimiter(StubUtility
          .getLineDelimiterUsed(cu.getScriptProject()));
      change = new DocumentChange(name, document);
    } else {
      SourceModuleChange cuChange = new SourceModuleChange(name, cu);
      cuChange.setSaveMode(TextFileChange.LEAVE_DIRTY);
      change = cuChange;
    }
    TextEdit rootEdit = new MultiTextEdit();
    change.setEdit(rootEdit);

    // initialize text change
    IDocument document = change
        .getCurrentDocument(new NullProgressMonitor());
    addEdits(document, rootEdit);
    return change;
  }
View Full Code Here

     * @param status the status for the change.
     * @param fChange tho 'root' change.
     * @param editsAlreadyCreated
     */
    private void createCurrModuleChange() {
        TextChange docChange;
        if (this.currentFile != null) {
            docChange = new PyTextFileChange("Current module: " + moduleName, this.currentFile);
        } else {
            //used for tests
            docChange = PyDocumentChange.create("Current module: " + moduleName, this.currentDoc);
        }
        if (docOccurrences.size() == 0) {
            status.addFatalError("No occurrences found.");
            return;
        }

        MultiTextEdit rootEdit = new MultiTextEdit();
        docChange.setEdit(rootEdit);
        docChange.setKeepPreviewEdits(true);

        List<Tuple<TextEdit, String>> renameEdits = getAllRenameEdits(currentDoc, docOccurrences);
        fillEditsInDocChange(docChange, rootEdit, renameEdits);
    }
View Full Code Here

                Map.Entry entry = (Map.Entry) iterator.next();
                IFile file = (IFile) entry.getKey();
                Collection bucket = (Collection) entry.getValue();
                if (!bucket.isEmpty()) {
                    try {
                        TextChange change = createFileChange(file, pattern, bucket, resultingStatus, matchGroups);
                        if (change != null) {
                            compositeChange.add(change);
                            hasChanges = true;
                        }
                    } catch (CoreException e) {
View Full Code Here

  }

  protected TextChange createTextChange() throws CoreException {
    ICompilationUnit cu = m_cu;
    String name = "TestNG";
    TextChange change = null;
//    if (!cu.getResource().exists()) {
//      String source;
//      try {
//        source= cu.getSource();
//      } catch (JavaModelException e) {
//        JavaPlugin.log(e);
//        source= new String(); // empty
//      }
//    }
    Document document= new Document(cu.getSource());
    document.setInitialLineDelimiter(StubUtility.getLineDelimiterUsed(cu));
    change= new DocumentChange(name, document);
//    } else {
//      Document doc = new Document(m_cu.getSource());
//      CompilationUnitChange cuChange = new CompilationUnitChange(name, cu);
//      cuChange.setSaveMode(TextFileChange.LEAVE_DIRTY);
//      change= cuChange;
//    }
    TextEdit rootEdit= new MultiTextEdit();
    change.setEdit(rootEdit);

    // initialize text change
//    IDocument document= change.getCurrentDocument(new NullProgressMonitor());
    addEdits(change.getCurrentDocument(new NullProgressMonitor()), rootEdit);
    return change;
  }
View Full Code Here

   */
  private String getHtml() {
    final StringBuffer buf= new StringBuffer();

    try {
      final TextChange change= getTextChange();

      change.setKeepPreviewEdits(true);
      final IDocument previewContent= change.getPreviewDocument(new NullProgressMonitor());
      final TextEdit rootEdit= change.getPreviewEdit(change.getEdit());

      class EditAnnotator extends TextEditVisitor {
        private int m_writtenToPos = 0;

        public void unchangedUntil(int pos) {
View Full Code Here

    // need to look at already refactored positions to make sure offsets are
    // correct
    List<Integer> refactoredPositions = new ArrayList<Integer>();
    ProcessorBasedRefactoring refactoring = getProcessor().getRefactoring();
    if (refactoring != null) {
      TextChange textChange = refactoring.getTextChange(file);
      if (textChange != null) {
        TextEdit edit = textChange.getEdit();
        getPositions(edit, refactoredPositions);
      }
    }

    int changeCount = 0;
View Full Code Here

        @Override
        public boolean acceptPatternMatch( final TextSearchMatchAccess matchAccess ) throws CoreException {
          IFile file = matchAccess.getFile();
          TextFileChange change = (TextFileChange) changes.get( file );
          if ( change == null ) {
            TextChange textChange = getTextChange( file ); // an other participant already modified that file?
            if ( textChange != null ) {
              return false; // don't try to merge changes
            }
            change = new TextFileChange( file.getName(), file );
            change.setEdit( new MultiTextEdit() );
View Full Code Here

TOP

Related Classes of org.eclipse.ltk.core.refactoring.TextChange

Copyright © 2018 www.massapicom. 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.