Package org.eclipse.text.edits

Examples of org.eclipse.text.edits.TextEditGroup


   */
  public final ITrackedNodePosition track(ASTNode node) {
    if (node == null) {
      throw new IllegalArgumentException();
    }
    TextEditGroup group= this.eventStore.getTrackedNodeData(node);
    if (group == null) {
      group= new TextEditGroup("internal"); //$NON-NLS-1$
      this.eventStore.setTrackedNodeData(node, group);
    }
    return new TrackedNodePosition(group, node);
 
View Full Code Here


          change.setEdit(new MultiTextEdit());
          changes.put(file, change);
        }
        ReplaceEdit edit= new ReplaceEdit(matchAccess.getMatchOffset(), matchAccess.getMatchLength(), newName);
        change.addEdit(edit);
        change.addTextEditGroup(new TextEditGroup("Update type reference", edit)); //$NON-NLS-1$
        return true;
      }
    };
    TextSearchEngine.create().search(scope, collector, pattern, pm);
   
View Full Code Here

      root = new MultiTextEdit();
      change.setEdit(root);
    }

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

   
    MultiTextEdit rootEdit = new MultiTextEdit();
   
    anotherChange.setEdit(rootEdit);
   
    TextEditGroup newMethodEdit = new TextEditGroup(Messages.format(RefactoringMessages.ExtractMethodPreviewPage_TextChangeNewMethod, fMethodName));
    TextEditGroup inlineReplacementEdit = new TextEditGroup(Messages.format(RefactoringMessages.ExtractMethodPreviewPage_TextChangeSubstituteStatements, fMethodName));
    TextEditGroup additionalInlineReplacementEdit = new TextEditGroup(Messages.format(RefactoringMessages.ExtractMethodPreviewPage_TextChangeSubsituteDuplicateStatements, fMethodName));
    anotherChange.addTextEditGroup(newMethodEdit);
    anotherChange.addTextEditGroup(inlineReplacementEdit);
    anotherChange.addTextEditGroup(additionalInlineReplacementEdit);
   
    AST ast = fProgram.getAST();
    MethodDeclaration method = ast.newMethodDeclaration();
    Block extractedMethodBody = ast.newBlock();
       
    FunctionDeclaration functionDec = ast.newFunctionDeclaration(ast.newIdentifier(fMethodName), computeArguments(ast), extractedMethodBody, false);
    method.setModifier(fModifierAccessFlag);
    method.setFunction(functionDec);
   
    ASTRewrite rewriter = ASTRewrite.create(ast);
   
    ListRewrite classListRewrite = rewriter.getListRewrite( fCoveringDeclarationFinder.getCoveringClassDeclaration().getBody(), Block.STATEMENTS_PROPERTY);
    VariableBase dispatcher = ast.newVariable(THIS_VARIABLE_NAME);
    FunctionInvocation calledExtractedMethod = ast.newFunctionInvocation(ast.newFunctionName(ast.newIdentifier(fMethodName)), computeParameters(ast));
    MethodInvocation inlineMethodCall = ast.newMethodInvocation(dispatcher, calledExtractedMethod);

    List<List<ASTNode>> Occurences = new ArrayList<List<ASTNode>>();
   
    if(fReplaceDuplicates) {
      for(Match replace : fDuplicates) {
        Occurences.add(Arrays.asList(replace.getNodes()));
      }
    } else {
      Occurences.add(fSelectedNodesFinder.getNodes());
    }
   
    boolean createdMethodBody = false;
   
    TextEditGroup inlineReplacementEditGroup = inlineReplacementEdit;
   
    for(List<ASTNode> selectedNodeOccurence : Occurences) {
   
      // this is also an indicator, whether this loop was already gone through
      if(createdMethodBody) {
View Full Code Here

 
 
  @Override
  protected ASTRewrite getRewrite() throws CoreException {
    LinkedProposalModel linkedModel = getLinkedProposalModel();
    TextEditGroup editGroup = new TextEditGroup(ASSIGN_TO_LOCAL_ID);
 
    ExpressionStatement statement = getStatement(context);
    Expression expression = statement.getExpression();
   
    AST ast = statement.getAST();
View Full Code Here

  private int rewriteRequiredNode(ASTNode parent, StructuralPropertyDescriptor property) {
    RewriteEvent event= getEvent(parent, property);
    if (event != null && event.getChangeKind() == RewriteEvent.REPLACED) {
      ASTNode node= (ASTNode) event.getOriginalValue();
      TextEditGroup editGroup= getEditGroup(event);
      SourceRange range= getExtendedRange(node);
      int offset= range.getStartPosition();
      int length= range.getLength();
      doTextRemoveAndVisit(offset, length, node, editGroup);
      doTextInsert(offset, (ASTNode) event.getNewValue(), getIndent(offset), true, editGroup);
View Full Code Here

    RewriteEvent event= getEvent(parent, property);
    if (event != null) {
      switch (event.getChangeKind()) {
        case RewriteEvent.INSERTED: {
          ASTNode node= (ASTNode) event.getNewValue();
          TextEditGroup editGroup= getEditGroup(event);
          int indent= getIndent(offset);
          doTextInsert(offset, prefix.getPrefix(indent), editGroup);
          doTextInsert(offset, node, indent, true, editGroup);
          return offset;
        }
        case RewriteEvent.REMOVED: {
          ASTNode node= (ASTNode) event.getOriginalValue();
          TextEditGroup editGroup= getEditGroup(event);
         
          // if there is a prefix, remove the prefix as well
          int nodeEnd;
          int len;
          if (offset == 0) {
            SourceRange range= getExtendedRange(node);
            offset= range.getStartPosition();
            len= range.getLength();
            nodeEnd= offset+len;
          } else {
            nodeEnd= getExtendedEnd(node);
            len= nodeEnd-offset;
          }
          doTextRemoveAndVisit(offset, len, node, editGroup);
          return nodeEnd;
        }
        case RewriteEvent.REPLACED: {
          ASTNode node= (ASTNode) event.getOriginalValue();
          TextEditGroup editGroup= getEditGroup(event);
          SourceRange range= getExtendedRange(node);
          int nodeOffset= range.getStartPosition();
          int nodeLen= range.getLength();
          doTextRemoveAndVisit(nodeOffset, nodeLen, node, editGroup);
          doTextInsert(nodeOffset, (ASTNode) event.getNewValue(), getIndent(offset), true, editGroup);
View Full Code Here

    RewriteEvent event= getEvent(parent, property);
    if (event != null) {
      switch (event.getChangeKind()) {
        case RewriteEvent.INSERTED: {
          ASTNode node= (ASTNode) event.getNewValue();
          TextEditGroup editGroup= getEditGroup(event);

          String[] strings= context.getPrefixAndSuffix(indent, node, this.eventStore);

          doTextInsert(offset, strings[0], editGroup);
          doTextInsert(offset, node, indent, true, editGroup);
          doTextInsert(offset, strings[1], editGroup);
          return offset;
        }
        case RewriteEvent.REMOVED: {
          ASTNode node= (ASTNode) event.getOriginalValue();
          if (endPos == -1) {
            endPos= getExtendedEnd(node);
          }

          TextEditGroup editGroup= getEditGroup(event);
          // if there is a prefix, remove the prefix as well
          int len= endPos - offset;
          doTextRemoveAndVisit(offset, len, node, editGroup);
          return endPos;
        }
        case RewriteEvent.REPLACED: {
          ASTNode node= (ASTNode) event.getOriginalValue();
          boolean insertNewLine = false;
          if (endPos == -1) {
            int previousEnd = node.getStartPosition() + node.getLength();
            endPos= getExtendedEnd(node);
            if (endPos != previousEnd) {
              // check if the end is a comment
              int token = TokenScanner.END_OF_FILE;
              try {
                token = getScanner().readNext(previousEnd, false);
              } catch(CoreException e) {
                // ignore
              }
              if (token == TerminalTokens.TokenNameCOMMENT_LINE) {
                insertNewLine = true;
              }
            }
          }
          TextEditGroup editGroup= getEditGroup(event);
          int nodeLen= endPos - offset;

          ASTNode replacingNode= (ASTNode) event.getNewValue();
          String[] strings= context.getPrefixAndSuffix(indent, replacingNode, this.eventStore);
          doTextRemoveAndVisit(offset, nodeLen, node, editGroup);
View Full Code Here

    RewriteEvent event= getEvent(parent, property);
    if (event != null) {
      switch (event.getChangeKind()) {
        case RewriteEvent.INSERTED: {
          ASTNode node= (ASTNode) event.getNewValue();
          TextEditGroup editGroup= getEditGroup(event);
          doTextInsert(startPos, node, getIndent(startPos), true, editGroup);
          doTextInsert(startPos, ".", editGroup); //$NON-NLS-1$
          return startPos;
        }
        case RewriteEvent.REMOVED: {
          try {
            ASTNode node= (ASTNode) event.getOriginalValue();
            TextEditGroup editGroup= getEditGroup(event);
            int dotEnd= getScanner().getTokenEndOffset(TerminalTokens.TokenNameDOT, node.getStartPosition() + node.getLength());
            doTextRemoveAndVisit(startPos, dotEnd - startPos, node, editGroup);
            return dotEnd;
          } catch (CoreException e) {
            handleException(e);
          }
          break;
        }
        case RewriteEvent.REPLACED: {
          ASTNode node= (ASTNode) event.getOriginalValue();
          TextEditGroup editGroup= getEditGroup(event);
          SourceRange range= getExtendedRange(node);
          int offset= range.getStartPosition();
          int length= range.getLength();

          doTextRemoveAndVisit(offset, length, node, editGroup);
View Full Code Here

    RewriteEvent event= getEvent(parent, MethodDeclaration.BODY_PROPERTY);
    if (event != null) {
      switch (event.getChangeKind()) {
        case RewriteEvent.INSERTED: {
          int endPos= parent.getStartPosition() + parent.getLength();
          TextEditGroup editGroup= getEditGroup(event);
          ASTNode body= (ASTNode) event.getNewValue();
          doTextRemove(startPos, endPos - startPos, editGroup);
          int indent= getIndent(parent.getStartPosition());
          String prefix= this.formatter.METHOD_BODY.getPrefix(indent);
          doTextInsert(startPos, prefix, editGroup);
          doTextInsert(startPos, body, indent, true, editGroup);
          return;
        }
        case RewriteEvent.REMOVED: {
          TextEditGroup editGroup= getEditGroup(event);
          ASTNode body= (ASTNode) event.getOriginalValue();
          int endPos= parent.getStartPosition() + parent.getLength();
          doTextRemoveAndVisit(startPos, endPos - startPos, body, editGroup);
          doTextInsert(startPos, ";", editGroup); //$NON-NLS-1$
          return;
        }
        case RewriteEvent.REPLACED: {
          TextEditGroup editGroup= getEditGroup(event);
          ASTNode body= (ASTNode) event.getOriginalValue();
          doTextRemoveAndVisit(body.getStartPosition(), body.getLength(), body, editGroup);
          doTextInsert(body.getStartPosition(), (ASTNode) event.getNewValue(), getIndent(body.getStartPosition()), true, editGroup);
          return;
        }
View Full Code Here

TOP

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

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.