Package org.eclipse.text.edits

Examples of org.eclipse.text.edits.TextEdit


    // note this doesn't interfer with repository providers as this is a new resource that cannot be under
    // version control yet
    Util.setReadOnly(destFile, false);
    ICompilationUnit destCU = dest.getCompilationUnit(destName);
    IDocument document = getDocument(destCU);
    TextEdit edits = rewrite.rewriteAST(document, null);
    try {
      edits.apply(document);
    } catch (BadLocationException e) {
      throw new JavaModelException(e, IJavaModelStatusConstants.INVALID_CONTENTS);
    }
    destCU.save(getSubProgressMonitor(1), this.force);
  }
View Full Code Here


  public CreateElementInCUOperation(IJavaElement parentElement) {
    super(null, new IJavaElement[]{parentElement});
    initializeDefaultPosition();
  }
  protected void apply(ASTRewrite rewriter, IDocument document, Map options) throws JavaModelException {
    TextEdit edits = rewriter.rewriteAST(document, options);
     try {
       edits.apply(document);
     } catch (BadLocationException e) {
       throw new JavaModelException(e, IJavaModelStatusConstants.INVALID_CONTENTS);
     }
  }
View Full Code Here

                final boolean fileChangeIsNew = (fileChange == null);
                if (fileChange == null) {
                    fileChange = new TextFileChange(proxy.getName(), resource);
                    fileChange.setEdit(new MultiTextEdit());
                }
                TextEdit rootEdit = fileChange.getEdit();

                /* loop over all renames to perform */
                for (Map.Entry<IPackageFragment,RenameArguments> entry : pkgFragments.entrySet()) {
                    IPackageFragment pkgFragment = entry.getKey();
                    RenameArguments arguments = entry.getValue();

                    final String oldName = pkgFragment.getElementName();
                    final String newName = arguments.getNewName();

                    Pattern pattern = Pattern.compile(
                    /* match start boundary */"(^|" + grammarSeparator + ")" +
                    /* match itself / package name */"(" + Pattern.quote(oldName) + ")" +
                    /* match end boundary */"(" + grammarSeparator + "|" + Pattern.quote(".*") + "|" + Pattern.quote("\\") + "|$)");

                    /* find all matches to replace and add them to the root edit */
                    Matcher matcher = pattern.matcher(bndFileText);
                    while (matcher.find()) {
                        rootEdit.addChild(new ReplaceEdit(matcher.start(2), matcher.group(2).length(), newName));
                    }

                    pattern = Pattern.compile(
                    /* match start boundary */"(^|" + grammarSeparator + ")" +
                    /* match bundle activator */"(Bundle-Activator\\s*:\\s*)" +
                    /* match itself / package name */"(" + Pattern.quote(oldName) + ")" +
                    /* match class name */"(\\.[^\\.]+)" +
                    /* match end boundary */"(" + grammarSeparator + "|" + Pattern.quote("\\") + "|$)");

                    /* find all matches to replace and add them to the root edit */
                    matcher = pattern.matcher(bndFileText);
                    while (matcher.find()) {
                        rootEdit.addChild(new ReplaceEdit(matcher.start(3), matcher.group(3).length(), newName));
                    }
                }

                /*
                 * only store the changes when no changes were stored before for this file and when there are actually
                 * changes.
                 */
                if (fileChangeIsNew && rootEdit.hasChildren()) {
                    fileChanges.put(resource, fileChange);
                }

                return false;
            }
View Full Code Here

        public String addStaticImport(String declaringTypeName, String simpleName, boolean isField) {
            return fImportsRewrite.addStaticImport(declaringTypeName, simpleName, isField);
        }

        /* package */void create(boolean needsSave, IProgressMonitor monitor) throws CoreException {
            TextEdit edit = fImportsRewrite.rewriteImports(monitor);
            JavaModelUtil.applyEdit(fImportsRewrite.getCompilationUnit(), edit, needsSave, null);
        }
View Full Code Here

    options.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_6);
    options.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_6);
    options.put(DefaultCodeFormatterConstants.FORMATTER_JOIN_WRAPPED_LINES, DefaultCodeFormatterConstants.FALSE);

    CodeFormatter codeFormatter = ToolFactory.createCodeFormatter(options);
    TextEdit format = codeFormatter.format(CodeFormatter.K_COMPILATION_UNIT, text, 0, text.length(), 0, null);
    IDocument document = new Document(text);
    format.apply(document);
    return document.get();
  }
View Full Code Here

  }

  protected abstract RefactoringStatus updateReferences(IProgressMonitor pm) throws CoreException;

  protected static void addTextEdit(TextChange change, String name, TextEdit edit) throws MalformedTreeException {
    TextEdit root = change.getEdit();
    if (root == null) {
      root = new MultiTextEdit();
      change.setEdit(root);
    }

    root.addChild(edit);
    change.addTextEditGroup(new TextEditGroup(name, edit));
  }
View Full Code Here

    }
   

    classListRewrite.insertAfter(method, fCoveringDeclarationFinder.getCoveringMethodDeclaration(), newMethodEdit);
   
    TextEdit fullDocumentEdit = rewriter.rewriteAST(document, null);

    anotherChange.addEdit(fullDocumentEdit);
   
    return anotherChange;
  }
View Full Code Here

     *
     * @param diff
     * @return
     */
    private static TextEdit createEditFromDiff(final Difference diff) {
        TextEdit result = null;

        // delete
        if (diff.getAddedEnd() == -1 && diff.getDeletedEnd() != -1) {
            result = new DeleteEdit(diff.getDeletedStart(), diff.getDeletedEnd()
                    - diff.getDeletedStart() + 1);
View Full Code Here

     * @param deletedEnd
     * @return
     */
    private static TextEdit createReplaceEdit(final int addedStart, final int addedEnd,
            final int deletedStart, final int deletedEnd) {
        final TextEdit result = new MultiTextEdit();

        final int addedLength = addedEnd - addedStart + 1;
        final int deletedLength = deletedEnd - deletedStart + 1;
        final int minLength = Math.min(addedLength, deletedLength);

        if (deletedLength < addedLength) {
            result.addChild(new InsertEdit(deletedStart + minLength, getString(addedStart
                    + minLength, addedEnd)));
        }

        result.addChild(new ReplaceEdit(deletedStart, minLength, getString(addedStart,
                addedStart + minLength - 1)));

        if (addedLength < deletedLength) {
            result.addChild(new DeleteEdit(deletedStart + minLength, deletedLength
                    - minLength));
        }

        return result;
    }
View Full Code Here

  public TextEdit format(IDocument document, int start, int length) {
    return format(document, start, length, new XMLFormattingPreferences());
  }

  public TextEdit format(IDocument document, int start, int length, XMLFormattingPreferences preferences) {
    TextEdit edit = null;
    if (document instanceof IStructuredDocument) {
      IStructuredModel model = StructuredModelManager.getModelManager().getModelForEdit((IStructuredDocument) document);
      if (model != null) {
        try {
          edit = format(model, start, length, preferences);
View Full Code Here

TOP

Related Classes of org.eclipse.text.edits.TextEdit

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.