Package org.eclipse.jdt.core.dom.rewrite.TargetSourceRangeComputer

Examples of org.eclipse.jdt.core.dom.rewrite.TargetSourceRangeComputer.SourceRange


  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);
      return offset + length;
    }
    return doVisit(parent, property, 0);
View Full Code Here


         
          // 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);
          return nodeOffset + nodeLen;
        }
      }
View Full Code Here

          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);
          doTextInsert(offset, (ASTNode) event.getNewValue(), getIndent(startPos), true, editGroup);
          try {
            return getScanner().getTokenEndOffset(TerminalTokens.TokenNameDOT, offset + length);
View Full Code Here

    CopySourceInfo[] infos= this.eventStore.getNodeCopySources(node);
    doCopySourcePreVisit(infos, this.sourceCopyEndNodes);

    TextEditGroup editGroup= this.eventStore.getTrackedNodeData(node);
    if (editGroup != null) {
      SourceRange range= getExtendedRange(node);
      int offset= range.getStartPosition();
      int length= range.getLength();
      TextEdit edit= new RangeMarker(offset, length);
      addEditGroup(editGroup, edit);
      addEdit(edit);
      this.currentEdit= edit;
    }
View Full Code Here

          pos= endPos;
          break;
        }
        case RewriteEvent.REPLACED: {
          ASTNode superClass= (ASTNode) superClassEvent.getOriginalValue();
          SourceRange range= getExtendedRange(superClass);
          int offset= range.getStartPosition();
          int length= range.getLength();
          doTextRemoveAndVisit(offset, length, superClass, getEditGroup(superClassEvent));
          doTextInsert(offset, (ASTNode) superClassEvent.getNewValue(), 0, false, getEditGroup(superClassEvent));
          pos= offset + length;
          break;
        }
View Full Code Here

        if (newParamCount > 0) {
          doTextInsert(offset, ", ", editGroup); //$NON-NLS-1$
        }
      } else {
        ASTNode elem= (ASTNode) event.getOriginalValue();
        SourceRange range= getExtendedRange(elem);
        int elemOffset= range.getStartPosition();
        int elemLength= range.getLength();
        int elemEnd= elemOffset + elemLength;
        if (changeKind == RewriteEvent.REMOVED) {
          editGroup= getEditGroup(event);
          int endPos;
          if (oldParamCount == 0) {
            endPos= getScanner().getTokenStartOffset(TerminalTokens.TokenNameRPAREN, elemEnd);
          } else {
            endPos= getScanner().getTokenEndOffset(TerminalTokens.TokenNameCOMMA, elemEnd);
          }
          doTextRemoveAndVisit(offset, endPos - offset, elem, editGroup);
          return endPos;
        } else if (changeKind == RewriteEvent.REPLACED) {
          editGroup= getEditGroup(event);
          doTextRemoveAndVisit(elemOffset, elemLength, elem, editGroup);
          doTextInsert(elemOffset, (ASTNode) event.getNewValue(), 0, false, editGroup);
          rewriteQualifier = true;
        }
      }
    } else {
      rewriteRequiredNode(method, MethodDeclaration.RECEIVER_TYPE_PROPERTY);
      if (method.getReceiverType() != null) {
        rewriteQualifier = true;
      }
    }
    if (rewriteQualifier) {
      if (qualEvent != null) {
        int qualChangeKind = qualEvent.getChangeKind();
        TextEditGroup qualGroup = getEditGroup(qualEvent);
        if (qualChangeKind == RewriteEvent.INSERTED) {
          int pos= getScanner().getTokenStartOffset(TerminalTokens.TokenNamethis, offset);
          doTextInsert(pos, (ASTNode) qualEvent.getNewValue(), 0, false, qualGroup);
          doTextInsert(pos, ".", qualGroup); //$NON-NLS-1$
        } else if (qualChangeKind == RewriteEvent.REMOVED) {
          int qualOffset = oldQual.getStartPosition();
          int endPos= getScanner().getTokenEndOffset(TerminalTokens.TokenNameDOT, qualOffset);
          doTextRemove(qualOffset, endPos - qualOffset, qualGroup);
        } else if (qualChangeKind == RewriteEvent.REPLACED) {
          SourceRange range= getExtendedRange(oldQual);
          int elemOffset= range.getStartPosition();
          int elemLength= range.getLength();
          doTextRemoveAndVisit(elemOffset, elemLength, oldQual, qualGroup);
          doTextInsert(elemOffset, newQual, 0, false, qualGroup);
        }
      }
      offset=  getScanner().getTokenEndOffset(TerminalTokens.TokenNamethis, offset);
View Full Code Here

      replacingType= (ArrayType) typeEvent.getNewValue();
      editGroup= getEditGroup(typeEvent);
      Type newType= replacingType.getElementType();
      Type oldType= getElementType(arrayType);
      if (!newType.equals(oldType)) {
        SourceRange range= getExtendedRange(oldType);
        int offset= range.getStartPosition();
        int length= range.getLength();
        doTextRemove(offset, length, editGroup);
        doTextInsert(offset, newType, 0, false, editGroup);
      }
    }

    try {
      // dimension node with expressions and/or annotations
      RewriteEvent dimEvent= getEvent(node, ArrayCreation.DIMENSIONS_PROPERTY);
      boolean hasDimensionChanges= (dimEvent != null && dimEvent.getChangeKind() != RewriteEvent.UNCHANGED);
      RewriteEvent[] events= hasDimensionChanges ? dimEvent.getChildren() : null;
      ArrayType currentLevel = astLevelGTE8 ? null : (ArrayType) replacingType.getElementType().getParent();
      int replacingTypeDimensions = replacingType.getDimensions();
      int i=0, dimSize= (events == null) ? 0 : events.length;
      Type elementType= arrayType.getElementType();
      int offset= elementType.getStartPosition() + elementType.getLength();
      editGroup = null;
      while(currentLevel != null || astLevelGTE8) {
        if (i < dimSize) {
          if (astLevelGTE8)
            rewriteAnnotationsOnDimension(arrayType, replacingType, i, offset, typeReplaced, editGroup);
          offset= getScanner().getTokenEndOffset(TerminalTokens.TokenNameLBRACKET, offset);
          if (hasDimensionChanges) {
            RewriteEvent event= events[i];
            int changeKind= event.getChangeKind();
            if (changeKind == RewriteEvent.INSERTED) { // insert new dimension
              editGroup= getEditGroup(event);
              int endPos= getScanner().getTokenStartOffset(TerminalTokens.TokenNameRBRACKET, offset);
              doTextRemove(offset, endPos - offset, editGroup);
              doTextInsert(offset, (ASTNode) event.getNewValue(), 0, false, editGroup);
            } else {
              ASTNode elem= (ASTNode) event.getOriginalValue();
              int elemEnd= elem.getStartPosition() + elem.getLength();
              int endPos= getScanner().getTokenStartOffset(TerminalTokens.TokenNameRBRACKET, elemEnd);
              if (changeKind == RewriteEvent.REMOVED) {
                editGroup= getEditGroup(event);
                doTextRemoveAndVisit(offset, endPos - offset, elem, editGroup);
              } else if (changeKind == RewriteEvent.REPLACED) {
                editGroup= getEditGroup(event);
                SourceRange range= getExtendedRange(elem);
                int elemOffset= range.getStartPosition();
                int elemLength= range.getLength();
                doTextRemoveAndVisit(elemOffset, elemLength, elem, editGroup);
                doTextInsert(elemOffset, (ASTNode) event.getNewValue(), 0, false, editGroup);
              } else {
                voidVisit(elem);
              }
View Full Code Here

   * @return an extended source range (never null)
   * @since 3.1
   */
  final SourceRange getExtendedRange(ASTNode node) {
    if (this.eventStore.isRangeCopyPlaceholder(node)) {
      return new SourceRange(node.getStartPosition(), node.getLength());
    }
    return this.extendedSourceRangeComputer.computeSourceRange(node);
  }
View Full Code Here

  }

  final TextEdit getCopySourceEdit(CopySourceInfo info) {
    TextEdit edit= (TextEdit) this.sourceCopyInfoToEdit.get(info);
    if (edit == null) {
      SourceRange range= getExtendedRange(info.getNode());
      int start= range.getStartPosition();
      int end= start + range.getLength();
      if (info.isMove) {
        MoveSourceEdit moveSourceEdit= new MoveSourceEdit(start, end - start);
        moveSourceEdit.setTargetEdit(new MoveTargetEdit(0));
        edit= moveSourceEdit;
      } else {
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);
      return offset + length;
    }
    return doVisit(parent, property, 0);
View Full Code Here

TOP

Related Classes of org.eclipse.jdt.core.dom.rewrite.TargetSourceRangeComputer.SourceRange

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.