Package org.eclipse.text.edits

Examples of org.eclipse.text.edits.TextEditGroup


  public boolean visit(PrimitiveType node) {
    if (!hasChildrenChanges(node)) {
      return doVisitUnchangedChildren(node);
    }
    PrimitiveType.Code newCode= (PrimitiveType.Code) getNewValue(node, PrimitiveType.PRIMITIVE_TYPE_CODE_PROPERTY);
    TextEditGroup group = getEditGroup(node, PrimitiveType.PRIMITIVE_TYPE_CODE_PROPERTY);
    doTextReplace(node.getStartPosition(), node.getLength(), newCode.toString(), group);
    return false;
  }
View Full Code Here


  public boolean visit(SimpleName node) {
    if (!hasChildrenChanges(node)) {
      return doVisitUnchangedChildren(node);
    }
    String newString= (String) getNewValue(node, SimpleName.IDENTIFIER_PROPERTY);
    TextEditGroup group = getEditGroup(node, SimpleName.IDENTIFIER_PROPERTY);
    doTextReplace(node.getStartPosition(), node.getLength(), newString, group);
    return false;
  }
View Full Code Here

  public boolean visit(StringLiteral node) {
    if (!hasChildrenChanges(node)) {
      return doVisitUnchangedChildren(node);
    }
    String escapedSeq= (String) getNewValue(node, StringLiteral.ESCAPED_VALUE_PROPERTY);
    TextEditGroup group = getEditGroup(node, StringLiteral.ESCAPED_VALUE_PROPERTY);
    doTextReplace(node.getStartPosition(), node.getLength(), escapedSeq, group);

    return false;
  }
View Full Code Here

  public boolean visit(TextElement node) {
    if (!hasChildrenChanges(node)) {
      return doVisitUnchangedChildren(node);
    }
    String newText= (String) getNewValue(node, TextElement.TEXT_PROPERTY);
    TextEditGroup group = getEditGroup(node, TextElement.TEXT_PROPERTY);
    doTextReplace(node.getStartPosition(), node.getLength(), newText, group);
    return false;
  }
View Full Code Here

  public boolean visit(Modifier node) {
    if (!hasChildrenChanges(node)) {
      return doVisitUnchangedChildren(node);
    }
    String newText= getNewValue(node, Modifier.KEYWORD_PROPERTY).toString(); // type Modifier.ModifierKeyword
    TextEditGroup group = getEditGroup(node, Modifier.KEYWORD_PROPERTY);
    doTextReplace(node.getStartPosition(), node.getLength(), newText, group);
    return false;
  }
View Full Code Here

      }

      boolean insertNew = currPos == -1;
      if (insertNew) { // only inserts
        if (keyword.length() > 0) {  // creating a new list -> insert keyword first (e.g. " throws ")
          TextEditGroup editGroup= getEditGroup(this.list[0]); // first node is insert
          doTextInsert(offset, keyword, editGroup);
        }
        currPos= offset;
      }
      if (lastNonDelete == -1) { // all removed, set back to start so the keyword is removed as well
        currPos= offset;
      }

      int prevEnd= currPos;
      int prevMark= RewriteEvent.UNCHANGED;

      final int NONE= 0, NEW= 1, EXISTING= 2;
      int separatorState= NEW;

      for (int i= 0; i < total; i++) {
        RewriteEvent currEvent= this.list[i];
        int currMark= currEvent.getChangeKind();
        int nextIndex= i + 1;

        if (currMark == RewriteEvent.INSERTED) {
          TextEditGroup editGroup= getEditGroup(currEvent);
          ASTNode node= (ASTNode) currEvent.getNewValue();

          if (separatorState == NONE) { // element after last existing element (but not first)
            doTextInsert(currPos, getSeparatorString(i - 1), editGroup); // insert separator
            separatorState= NEW;
          }
          if (separatorState == NEW || insertAfterSeparator(node)) {
            if (separatorState == EXISTING) {
              updateIndent(prevMark, currPos, i, editGroup);
            }
           
            doTextInsert(currPos, node, getNodeIndent(i), true, editGroup); // insert node

            separatorState= NEW;
            if (i != lastNonDelete) {
              if (this.list[nextIndex].getChangeKind() != RewriteEvent.INSERTED) {
                doTextInsert(currPos, getSeparatorString(i), editGroup); // insert separator
              } else {
                separatorState= NONE;
              }
            }
          } else { // EXISTING && insert before separator
            doTextInsert(prevEnd, getSeparatorString(i - 1), editGroup);
            doTextInsert(prevEnd, node, getNodeIndent(i), true, editGroup);
          }
          if (insertNew) {
            if (endKeyword != null && endKeyword.length() > 0) {
              doTextInsert(currPos, endKeyword, editGroup);
            }
          }
        } else if (currMark == RewriteEvent.REMOVED) {
          ASTNode node= (ASTNode) currEvent.getOriginalValue();
          TextEditGroup editGroup= getEditGroup(currEvent);
          int currEnd= getEndOfNode(node);
          // https://bugs.eclipse.org/bugs/show_bug.cgi?id=306524
          // Check for leading comments that are not part of extended range, and prevent them
          // from getting removed.
          try {
            TokenScanner scanner = getScanner();
            int newOffset = prevEnd;
            int extendedOffset = getExtendedOffset(node);
            // Try to find the end of the last comment which is not part of extended source
            // range of the node.
            while (TokenScanner.isComment(scanner.readNext(newOffset, false))) {
              int tempOffset = scanner.getNextEndOffset(newOffset, false);
              // check whether the comment is part of extended source range of the node.
              // If it is then we need to stop.
              if (tempOffset < extendedOffset) {
                newOffset = tempOffset;
              } else {
                break;
              }
            }
            if (currPos < newOffset) {
              currPos = extendedOffset;
            }
            prevEnd = newOffset;   
          } catch (CoreException e) {
            // ignore
          }
          if (i > lastNonDelete && separatorState == EXISTING) {
            // is last, remove previous separator: split delete to allow range copies
            doTextRemove(prevEnd, currPos - prevEnd, editGroup); // remove separator
            doTextRemoveAndVisit(currPos, currEnd - currPos, node, editGroup); // remove node
            currPos= currEnd;
            prevEnd= currEnd;
          } else {
            if (i < lastNonDelete) {
              updateIndent(prevMark, currPos, i, editGroup);
            }
           
            // remove element and next separator
            int end= getStartOfNextNode(nextIndex, currEnd); // start of next
            // https://bugs.eclipse.org/bugs/show_bug.cgi?id=306524
            // Check for trailing comments that are not part of extended range, and prevent them
            // from getting removed.
            try {
              TokenScanner scanner = getScanner();
              int nextToken= scanner.readNext(currEnd, false);
              if (TokenScanner.isComment(nextToken)) {
                // the separator also has comments that are not part of extended
                // source range of this node or the next node. So dont remove the separator
                if (end != scanner.getNextStartOffset(currEnd, false)) {
                  // If this condition were true, comments just found as part of the separator would've basically been
                  // part of the extended source range of the next node. So 'end' wud've safely been set to the correct position
                  // and no change is needed.
                  end = currEnd;
                }
              }
            } catch (CoreException e) {
              // ignore
            }
            doTextRemoveAndVisit(currPos, currEnd - currPos, node, getEditGroup(currEvent)); // remove node
            if (mustRemoveSeparator(currPos, i)) {
              doTextRemove(currEnd, end - currEnd, editGroup); // remove separator
            }
            currPos= end;
            prevEnd= currEnd;
            separatorState= NEW;
          }
        } else { // replaced or unchanged
          if (currMark == RewriteEvent.REPLACED) {
            ASTNode node= (ASTNode) currEvent.getOriginalValue();
            int currEnd= getEndOfNode(node);

            TextEditGroup editGroup= getEditGroup(currEvent);
            ASTNode changed= (ASTNode) currEvent.getNewValue();
           
            updateIndent(prevMark, currPos, i, editGroup);
            // make sure that comments between last modified source position and extended starting position of
            // node to be replaced are not touched
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

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.