Package org.eclipse.text.edits

Examples of org.eclipse.text.edits.MultiTextEdit


    }

    private IDocument applyGenerateProperties(MockupGeneratePropertiesRequestProcessor requestProcessor)
            throws BadLocationException, MalformedTreeException, MisconfigurationException {
        IDocument refactoringDoc = new Document(data.source);
        MultiTextEdit multi = new MultiTextEdit();
        for (GeneratePropertiesRequest req : requestProcessor.getRefactoringRequests()) {
            SelectionState state = req.getSelectionState();

            if (state.isGetter()) {
                multi.addChild(new GetterMethodEdit(req).getEdit());
            }
            if (state.isSetter()) {
                multi.addChild(new SetterMethodEdit(req).getEdit());
            }
            if (state.isDelete()) {
                multi.addChild(new DeleteMethodEdit(req).getEdit());
            }
            multi.addChild(new PropertyEdit(req).getEdit());
        }
        multi.apply(refactoringDoc);
        return refactoringDoc;
    }
View Full Code Here


        ExtractMethodRequest req = requestProcessor.getRefactoringRequests().get(0);

        ExtractMethodEdit extractedMethodEdit = new ExtractMethodEdit(req);
        ExtractCallEdit callExtractedMethodEdit = new ExtractCallEdit(req);

        MultiTextEdit edit = new MultiTextEdit();
        edit.addChild(extractedMethodEdit.getEdit());
        edit.addChild(callExtractedMethodEdit.getEdit());

        IDocument refactoringDoc = new Document(data.source);
        edit.apply(refactoringDoc);
        return refactoringDoc;
    }
View Full Code Here

    {
      try{
        ICompilationUnit src = (ICompilationUnit)cu.getJavaElement();
        IJavaProject javaProject = src.getJavaProject();

        MultiTextEdit edit = new MultiTextEdit();
        ImportRewrite imports = StubUtility.createImportRewrite(cu, true);
        imports.addStaticImport("org.junit.Assert", "*", false);
        imports.addImport(JUnitCorePlugin.JUNIT4_ANNOTATION_NAME);
        edit.addChild(imports.rewriteImports(null));

        AST ast = cu.getAST();
        ASTRewrite astRewrite = ASTRewrite.create(ast);
        ASTNode node = cu.findDeclaringNode(typeBinding);
        ChildListPropertyDescriptor property = ((AbstractTypeDeclaration)node)
          .getBodyDeclarationsProperty();
        ListRewrite memberRewriter = astRewrite.getListRewrite(node, property);
        HashSet<String> added = new HashSet<String>();
        for (IMethodBinding binding : methodBindings){
          String name = binding.getName();
          if (added.contains(name)){
            continue;
          }
          added.add(name);

          MethodDeclaration stub = ast.newMethodDeclaration();
          stub.setConstructor(false);
          stub.modifiers().addAll(ast.newModifiers(Modifier.PUBLIC));

          Annotation marker = ast.newMarkerAnnotation();
          marker.setTypeName(ast.newSimpleName("Test"));
          astRewrite
            .getListRewrite(stub, MethodDeclaration.MODIFIERS2_PROPERTY)
            .insertFirst(marker, null);

          stub.setName(ast.newSimpleName(name));

          Block body = ast.newBlock();
          stub.setBody(body);

          String todoTask = "";
          String todoTaskTag = JUnitStubUtility.getTodoTaskTag(javaProject);
          if (todoTaskTag != null) {
            todoTask = " // " + todoTaskTag;
          }
          String message = WizardMessages
            .NewTestCaseWizardPageOne_not_yet_implemented_string;
          body.statements().add(astRewrite.createStringPlaceholder(
                todoTask,
                ASTNode.RETURN_STATEMENT));
          body.statements().add(astRewrite.createStringPlaceholder(
                Messages.format("fail(\"{0}\");", message),
                ASTNode.RETURN_STATEMENT));

          memberRewriter.insertLast(stub, null);
        }
        edit.addChild(astRewrite.rewriteAST());

        JavaModelUtil.applyEdit(src, edit, true, null);
      }catch(Exception e){
        throw new RuntimeException(e);
      }
View Full Code Here

      .getAST(src, SharedASTProvider.WAIT_YES, null);

    @SuppressWarnings("unchecked")
    List<ImportDeclaration> imports = astRoot.imports();
    String lineDelim = src.findRecommendedLineSeparator();
    MultiTextEdit edit = new MultiTextEdit();
    ImportDeclaration next = null;
    for (int i = imports.size() - 1; i >= 0; i--){
      ImportDeclaration imprt = imports.get(i);
      int end = imprt.getStartPosition() + imprt.getLength() + lineDelim.length();
      if (next != null &&
          end == next.getStartPosition() &&
          !ImportUtils.importsInSameGroup(separationLevel, imprt, next))
      {
        edit.addChild(new InsertEdit(end, lineDelim));
      }
      next = imprt;
    }

    return edit.getChildrenSize() > 0 ? edit : null;
  }
View Full Code Here

    int oldLength = src.getBuffer().getLength();
    if (type != null){
      CompilationUnit astRoot = SharedASTProvider
        .getAST(src, SharedASTProvider.WAIT_YES, null);

      edits = new MultiTextEdit();
      ImportRewrite importRewrite = StubUtility.createImportRewrite(astRoot, true);
      ImportRewriteContext context = new ContextSensitiveImportRewriteContext(
          astRoot, offset, importRewrite);
      String res = importRewrite.addImport(type, context);
      if (type.equals(res)){
View Full Code Here

          "org.eclim.java.import.package_separation_level");
    String lineDelim = src.findRecommendedLineSeparator();
    CompilationUnit astRoot = SharedASTProvider
      .getAST(src, SharedASTProvider.WAIT_YES, null);
    ASTNode node = NodeFinder.perform(astRoot, offset, 1);
    MultiTextEdit edit = new MultiTextEdit();
    if (node != null && node.getNodeType() == ASTNode.IMPORT_DECLARATION){
      ImportDeclaration imprt = (ImportDeclaration)node;

      ASTNode next = getNext(astRoot, node, lineDelim);
      while (next != null && next.getNodeType() == ASTNode.IMPORT_DECLARATION){
        ImportDeclaration nextImprt = (ImportDeclaration)next;
        if (!ImportUtils.importsInSameGroup(separationLevel, imprt, nextImprt)){
          int end =
            imprt.getStartPosition() +
            imprt.getLength() +
            lineDelim.length();
          addLineDelim(astRoot, edit, end, lineDelim);
        }
        next = getNext(astRoot, next, lineDelim);
        imprt = nextImprt;
      }

      // reset imprt ref back to the one we are importing.
      imprt = (ImportDeclaration)node;
      ASTNode prev = getPrev(astRoot, node, lineDelim);
      if (prev != null && prev.getNodeType() == ASTNode.IMPORT_DECLARATION){
        ImportDeclaration prevImprt = (ImportDeclaration)prev;
        if (!ImportUtils.importsInSameGroup(separationLevel, imprt, prevImprt)){
          int end = prev.getStartPosition() + prev.getLength() + lineDelim.length();
          addLineDelim(astRoot, edit, end, lineDelim);
        }
      }
    }
    return edit.getChildrenSize() > 0 ? edit : null;
  }
View Full Code Here

    try {
      monitor.beginTask(Messages.bind(Messages.importRewrite_processDescription), 2);
      if (!hasRecordedChanges()) {
        this.createdImports= CharOperation.NO_STRINGS;
        this.createdStaticImports= CharOperation.NO_STRINGS;
        return new MultiTextEdit();
      }

      CompilationUnit usedAstRoot= this.astRoot;
      if (usedAstRoot == null) {
        ASTParser parser= ASTParser.newParser(AST.JLS4);
View Full Code Here

   * @param options the given options
   * @throws IllegalArgumentException if the rewrite fails
   * @return Returns the edit describing the text changes.
   */
  public TextEdit rewriteAST(IDocument document, Map options) {
    TextEdit result = new MultiTextEdit();

    final CompilationUnit rootNode = getRootNode();
    if (rootNode != null) {
      TargetSourceRangeComputer xsrComputer = new TargetSourceRangeComputer() {
        /**
 
View Full Code Here

    // https://bugs.eclipse.org/bugs/show_bug.cgi?id=208541
    adaptRegions();
    // https://bugs.eclipse.org/bugs/show_bug.cgi?id=234583
    adaptEdits();

    MultiTextEdit edit = null;
    int regionsLength = this.adaptedRegions.length;
    int textRegionStart;
    int textRegionEnd;
    if (regionsLength == 1) {
      IRegion lastRegion = this.adaptedRegions[0];
      textRegionStart = lastRegion.getOffset();
      textRegionEnd = textRegionStart + lastRegion.getLength();
    } else {
      textRegionStart = this.adaptedRegions[0].getOffset();
      IRegion lastRegion = this.adaptedRegions[regionsLength - 1];
      textRegionEnd = lastRegion.getOffset() + lastRegion.getLength();
    }

    int length = textRegionEnd - textRegionStart + 1;
    if (textRegionStart <= 0) {
      if (length <= 0) {
        edit = new MultiTextEdit(0, 0);
      } else {
        edit = new MultiTextEdit(0, textRegionEnd);
      }
    } else {
      edit = new MultiTextEdit(textRegionStart, length - 1);
    }
    for (int i= 0, max = this.editsIndex; i < max; i++) {
      OptimizedReplaceEdit currentEdit = this.edits[i];
      if (currentEdit.offset >= 0 && currentEdit.offset <= this.scannerEndPosition) {
        if (currentEdit.length == 0 || (currentEdit.offset != this.scannerEndPosition && isMeaningfulEdit(currentEdit))) {
          try {
            edit.addChild(new ReplaceEdit(currentEdit.offset, currentEdit.length, currentEdit.replacement));
          }
          catch (MalformedTreeException ex) {
            // log exception in case of error
            CommentFormatterUtil.log(ex);
             throw ex;
View Full Code Here

      throw new IllegalArgumentException();
    }

    ASTNode rootNode= getRootNode();
    if (rootNode == null) {
      return new MultiTextEdit(); // no changes
    }

    char[] content= document.get().toCharArray();
    LineInformation lineInfo= LineInformation.create(document);
    String lineDelim= TextUtilities.getDefaultLineDelimiter(document);
View Full Code Here

TOP

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

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.