Package org.eclipse.text.edits

Examples of org.eclipse.text.edits.TextEdit


      FindReplaceDocumentAdapter find = new FindReplaceDocumentAdapter(doc);
      IRegion resultStart = find.find(0, "location\\s*=\\s*\"", true, true, false, true);
      IRegion resultStop = find.find(resultStart.getOffset() + resultStart.getLength(), "\"", true, true, false, false);
 
      String linkTarget = WGADesignStructureHelper.computeDirLinkTarget(info.getFile().getParent(), computeNewLinkTarget(info));
      TextEdit edit = new ReplaceEdit(resultStart.getLength() + resultStart.getOffset(), resultStop.getOffset() - (resultStart.getLength() + resultStart.getOffset()), linkTarget);
     
      change.setEdit(edit);
      return change;
      }else if (info.getArguments() instanceof DeleteArguments) {
        // check if resource to delete will still exists after parent deletion is performed - otherwise we can skip any change here
View Full Code Here


        options.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_5);
        options.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_5);
        Document doc = new Document(m_compilationUnit.toString());
        CodeFormatter fmtr = ToolFactory.createCodeFormatter(options);
        String text = doc.get();
        TextEdit edits = fmtr.format(CodeFormatter.K_COMPILATION_UNIT, text, 0, text.length(), 0, null);
        File gendir = m_package.getGenerateDirectory();
        if (gendir != null) {
            try {
                File file = new File(gendir, m_name + ".java");
                FileWriter fwrit = new FileWriter(file);
                WriterVisitor visitor = new WriterVisitor(text, fwrit);
                edits.accept(visitor);
                visitor.finish();
                fwrit.flush();
                fwrit.close();
                s_logger.info("Generated class file " + file.getCanonicalPath() + " (writing AST took " + (System.currentTimeMillis()-start) + " ms.)");
            } catch (IOException e) {
View Full Code Here

    }
    this.preferences.initial_indentation_level = indentationLevel;

    this.newCodeFormatter = new CodeFormatterVisitor(this.preferences, this.options, offset, length, this.codeSnippetParsingUtil);
   
    TextEdit textEdit = this.newCodeFormatter.format(source, expression);
    return textEdit;
  }
View Full Code Here

    for (int i= 0; i < markers.length; i++) {
      resultingMarkers.add(markers[i]); // add to result
    }   
   
    String unformatted= flattener.getResult();
    TextEdit edit= formatNode(node, unformatted, initialIndentationLevel);
    if (edit == null) {
        if (initialIndentationLevel > 0) {
            // at least correct the indent
            String indentString = createIndentString(initialIndentationLevel);
        ReplaceEdit[] edits = IndentManipulation.getChangeIndentEdits(unformatted, 0, this.tabWidth, this.indentWidth, indentString);
        edit= new MultiTextEdit();
        edit.addChild(new InsertEdit(0, indentString));
        edit.addChildren(edits);
        } else {
           return unformatted;
        }
    }
    return evaluateFormatterEdit(unformatted, edit, markers);
View Full Code Here

          return null;
      }
    }
   
    String concatStr= prefix + str + suffix;
    TextEdit edit= formatString(code, concatStr, prefix.length(), str.length(), indentationLevel);
   
    if (prefix.length() > 0) {
      edit= shifEdit(edit, prefix.length());
    }   
    return edit;
View Full Code Here

    }   
    return edit;
 
     
  private static TextEdit shifEdit(TextEdit oldEdit, int diff) {
    TextEdit newEdit;
    if (oldEdit instanceof ReplaceEdit) {
      ReplaceEdit edit= (ReplaceEdit) oldEdit;
      newEdit= new ReplaceEdit(edit.getOffset() - diff, edit.getLength(), edit.getText());
    } else if (oldEdit instanceof InsertEdit) {
      InsertEdit edit= (InsertEdit) oldEdit;
      newEdit= new InsertEdit(edit.getOffset() - diff,  edit.getText());
    } else if (oldEdit instanceof DeleteEdit) {
      DeleteEdit edit= (DeleteEdit) oldEdit;
      newEdit= new DeleteEdit(edit.getOffset() - diff,  edit.getLength());
    } else if (oldEdit instanceof MultiTextEdit) {
      newEdit= new MultiTextEdit();     
    } else {
      return null; // not supported
    }
    TextEdit[] children= oldEdit.getChildren();
    for (int i= 0; i < children.length; i++) {
      TextEdit shifted= shifEdit(children[i], diff);
      if (shifted != null) {
        newEdit.addChild(shifted);
      }
    }
    return newEdit;
View Full Code Here

    }
   
    public String getPrefix(int indent) {
      Position pos= new Position(this.start, this.length);
      String str= this.string;
      TextEdit res= formatString(this.kind, str, 0, str.length(), indent);
      if (res != null) {
        str= evaluateFormatterEdit(str, res, new Position[] { pos });
      }
      return str.substring(pos.offset + 1, pos.offset + pos.length - 1);
    }
View Full Code Here

    public String[] getPrefixAndSuffix(int indent, ASTNode node, RewriteEventStore events) {
      String nodeString= ASTRewriteFlattener.asString(node, events);
      String str= this.prefix + nodeString;
      Position pos= new Position(this.start, this.prefix.length() + 1 - this.start);

      TextEdit res= formatString(CodeFormatter.K_STATEMENTS, str, 0, str.length(), indent);
      if (res != null) {
        str= evaluateFormatterEdit(str, res, new Position[] { pos });
      }
      return new String[] { str.substring(pos.offset + 1, pos.offset + pos.length - 1), ""}; //$NON-NLS-1$
    }
View Full Code Here

      String str= this.prefix + nodeString + this.suffix;
     
      Position pos1= new Position(this.start, nodeStart + 1 - this.start);
      Position pos2= new Position(nodeEnd, 2);

      TextEdit res= formatString(CodeFormatter.K_STATEMENTS, str, 0, str.length(), indent);
      if (res != null) {
        str= evaluateFormatterEdit(str, res, new Position[] { pos1, pos2 });
      }
      return new String[] {
        str.substring(pos1.offset + 1, pos1.offset + pos1.length - 1),
View Full Code Here

   * @param snippet the code snippet
   * @return the formatted code snippet
   */
  private String formatCodeSnippet(String snippet) {
    String lineDelimiter= TextUtilities.getDefaultLineDelimiter(getDocument());
    TextEdit edit= CommentFormatterUtil.format2(CodeFormatter.K_UNKNOWN, snippet, 0, lineDelimiter, this.preferences.getMap());
    if (edit != null)
      snippet= CommentFormatterUtil.evaluateFormatterEdit(snippet, edit, null);
    return snippet;
  }
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.