private boolean rangeAdded(TextEdit edit) {
   unchangedUntil(edit.getOffset());
   buf.append("<b>"); // $NON-NLS-1$
   appendContent(previewContent, edit.getOffset(), edit.getExclusiveEnd(), buf, false);
   buf.append("</b>"); // $NON-NLS-1$
   fWrittenToPos = edit.getExclusiveEnd();
   return false;
 }
예제 #2
0
  private void handleReplace(IASTNode node) {
    List<ASTModification> modifications = getModifications(node, ModificationKind.REPLACE);
    String source = node.getTranslationUnit().getRawSignature();
    TextEdit edit;
    ChangeGeneratorWriterVisitor writer =
        new ChangeGeneratorWriterVisitor(modificationStore, commentMap);
    IASTFileLocation fileLocation = node.getFileLocation();
    Integer val = sourceOffsets.get(fileLocation.getFileName());
    int processedOffset = val != null ? val.intValue() : 0;
    if (modifications.size() == 1 && modifications.get(0).getNewNode() == null) {
      int offset = getOffsetIncludingComments(node);
      int endOffset = getEndOffsetIncludingComments(node);
      offset = Math.max(skipPrecedingBlankLines(source, offset), processedOffset);
      endOffset = skipTrailingBlankLines(source, endOffset);
      IASTNode[] siblingsList = getContainingNodeList(node);
      if (siblingsList != null) {
        if (siblingsList.length > 1) {
          if (node == siblingsList[0]) {
            endOffset = skipToTrailingDelimiter(source, ',', endOffset);
          } else {
            offset = skipToPrecedingDelimiter(source, ',', offset);
          }
        } else if (node.getPropertyInParent() == ICPPASTFunctionDefinition.MEMBER_INITIALIZER) {
          offset = skipToPrecedingDelimiter(source, ':', offset);
        }
      }
      IASTNode prevNode = getPreviousSiblingOrPreprocessorNode(node);
      IASTNode nextNode = getNextSiblingOrPreprocessorNode(node);
      if (prevNode != null && nextNode != null) {
        if (ASTWriter.requireBlankLineInBetween(prevNode, nextNode)) {
          writer.newLine();
        }
      } else if (node.getParent() instanceof ICPPASTNamespaceDefinition) {
        writer.newLine();
      }
      String code = writer.toString();
      edit = new ReplaceEdit(offset, endOffset - offset, code);
    } else {
      node.accept(writer);
      String code = writer.toString();
      int offset = fileLocation.getNodeOffset();
      int endOffset = offset + fileLocation.getNodeLength();
      if (node instanceof IASTStatement || node instanceof IASTDeclaration) {
        // Include trailing comments in the area to be replaced.
        endOffset = Math.max(endOffset, getEndOffsetIncludingTrailingComments(node));
      }
      String lineSeparator = writer.getScribe().getLineSeparator();
      if (code.endsWith(lineSeparator)) {
        code = code.substring(0, code.length() - lineSeparator.length());
      }
      edit = new ReplaceEdit(offset, endOffset - offset, code);
    }
    IFile file = FileHelper.getFileFromNode(node);
    MultiTextEdit parentEdit = getEdit(node, file);
    parentEdit.addChild(edit);

    sourceOffsets.put(fileLocation.getFileName(), edit.getExclusiveEnd());
  }