Examples of TextEdit


Examples of org.eclipse.text.edits.TextEdit

    newOptions.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_OPENING_BRACE_IN_ARRAY_INITIALIZER, JavaCore.INSERT);
    newOptions.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_OPENING_BRACE_IN_ARRAY_INITIALIZER, JavaCore.INSERT);
    newOptions.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_CLOSING_BRACE_IN_ARRAY_INITIALIZER, JavaCore.INSERT);
   
    DefaultCodeFormatter defaultCodeFormatter = new DefaultCodeFormatter(newOptions);
    TextEdit textEdit = defaultCodeFormatter.format(org.aspectj.org.eclipse.jdt.core.formatter.CodeFormatter.K_UNKNOWN, string, 0, string.length(), indentLevel, lineSeparator);
    if (positions != null && textEdit != null) {
      // update positions
      TextEdit[] edits = textEdit.getChildren();
      int textEditSize = edits.length;
      int editsIndex = 0;
      int delta = 0;
      int originalSourceLength = string.length() - 1;
      if (textEditSize != 0) {
View Full Code Here

Examples of org.eclipse.text.edits.TextEdit

            CompilationUnit astCU = (CompilationUnit) this.parser.createAST(this.progressMonitor);
            AST ast = astCU.getAST();
            ASTRewrite rewrite = ASTRewrite.create(ast);
            updatePackageStatement(astCU, newFragName, rewrite);
            IDocument document = getDocument(cu);
            TextEdit edits = rewrite.rewriteAST(document, null);
            try {
              edits.apply(document);
            } catch (BadLocationException e) {
              throw new JavaModelException(e, IJavaModelStatusConstants.INVALID_CONTENTS);
            }     
            cu.save(null, false);
          }
View Full Code Here

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

Examples of org.eclipse.text.edits.TextEdit

  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

Examples of org.eclipse.text.edits.TextEdit

                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

Examples of org.eclipse.text.edits.TextEdit

        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

Examples of org.eclipse.text.edits.TextEdit

    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

Examples of org.eclipse.text.edits.TextEdit

  }

  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

Examples of org.eclipse.text.edits.TextEdit

    }
   

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

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

Examples of org.eclipse.text.edits.TextEdit

     *
     * @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
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.