Java 类org.eclipse.jdt.core.dom.rewrite.TargetSourceRangeComputer 实例源码

项目:che    文件:TightSourceRangeComputer.java   
@Override
public SourceRange computeSourceRange(ASTNode node) {
  if (fTightSourceRangeNodes.contains(node)) {
    return new TargetSourceRangeComputer.SourceRange(node.getStartPosition(), node.getLength());
  } else {
    return super.computeSourceRange(node); // see bug 85850
  }
}
项目:Eclipse-Postfix-Code-Completion    文件:TightSourceRangeComputer.java   
@Override
public SourceRange computeSourceRange(ASTNode node) {
    if (fTightSourceRangeNodes.contains(node)) {
        return new TargetSourceRangeComputer.SourceRange(node.getStartPosition(), node.getLength());
    } else {
        return super.computeSourceRange(node); // see bug 85850
    }
}
项目:Eclipse-Postfix-Code-Completion    文件:RewriteEventStore.java   
public void updatePlaceholderSourceRanges(TargetSourceRangeComputer sourceRangeComputer) {
    TargetSourceRangeComputer.SourceRange startRange= sourceRangeComputer.computeSourceRange(getStartNode());
    TargetSourceRangeComputer.SourceRange endRange= sourceRangeComputer.computeSourceRange(getEndNode());
    int startPos= startRange.getStartPosition();
    int endPos= endRange.getStartPosition() + endRange.getLength();

    Block internalPlaceholder= getInternalPlaceholder();
    internalPlaceholder.setSourceRange(startPos, endPos - startPos);
}
项目:Eclipse-Postfix-Code-Completion    文件:RewriteEventStore.java   
public void prepareMovedNodes(TargetSourceRangeComputer sourceRangeComputer) {
    if (this.nodeCopySources != null) {
        prepareSingleNodeCopies();
    }

    if (this.nodeRangeInfos != null) {
        prepareNodeRangeCopies(sourceRangeComputer);
    }
}
项目:Eclipse-Postfix-Code-Completion    文件:RewriteEventStore.java   
private void prepareNodeRangeCopies(TargetSourceRangeComputer sourceRangeComputer) {
    for (Iterator iter= this.nodeRangeInfos.entrySet().iterator(); iter.hasNext();) {
        Map.Entry entry= (Map.Entry) iter.next();
        List rangeInfos= (List) entry.getValue(); // list of CopySourceRange
        Collections.sort(rangeInfos); // sort by start index, length, move or copy

        PropertyLocation loc= (PropertyLocation) entry.getKey();
        RewriteEvent[] children= getListEvent(loc.getParent(), loc.getProperty(), true).getChildren();

        RewriteEvent[] newChildren= processListWithRanges(rangeInfos, children, sourceRangeComputer);
        addEvent(loc.getParent(), loc.getProperty(), new ListRewriteEvent(newChildren)); // replace the current edits
    }
}
项目:Eclipse-Postfix-Code-Completion    文件:ASTRewriteAnalyzer.java   
/**
 * Constructor for ASTRewriteAnalyzer.
 * <p>The given options cannot be null.</p>
 * 
 * @param content the content of the compilation unit to rewrite.
 * @param lineInfo line information for the content of the compilation unit to rewrite.
 * @param rootEdit the edit to add all generated edits to
 * @param eventStore the event store containing the description of changes
 * @param nodeInfos annotations to nodes, such as if a node is a string placeholder or a copy target
 * @param comments list of comments of the compilation unit to rewrite (elements of type <code>Comment</code>) or <code>null</code>.
 * @param options the current jdt.core options (formatting/compliance)
 * @param extendedSourceRangeComputer the source range computer to use
 * @param recoveryScannerData internal data used by {@link RecoveryScanner}
 */
public ASTRewriteAnalyzer(
        char[] content,
        LineInformation lineInfo,
        String lineDelim,
        TextEdit rootEdit,
        RewriteEventStore eventStore,
        NodeInfoStore nodeInfos,
        List comments,
        Map options,
        TargetSourceRangeComputer extendedSourceRangeComputer,
        RecoveryScannerData recoveryScannerData) {
    this.eventStore= eventStore;
    this.content= content;
    this.lineInfo= lineInfo;
    this.nodeInfos= nodeInfos;
    this.tokenScanner= null;
    this.currentEdit= rootEdit;
    this.sourceCopyInfoToEdit= new IdentityHashMap();
    this.sourceCopyEndNodes= new Stack();

    this.formatter= new ASTRewriteFormatter(nodeInfos, eventStore, options, lineDelim);

    this.extendedSourceRangeComputer = extendedSourceRangeComputer;
    this.lineCommentEndOffsets= new LineCommentEndOffsets(comments);

    this.options = options;

    this.recoveryScannerData = recoveryScannerData;
}
项目:Eclipse-Postfix-Code-Completion    文件:InternalASTRewrite.java   
/**
 * Performs the rewrite: The rewrite events are translated to the corresponding in text changes.
 * The given options can be null in which case the global options {@link JavaCore#getOptions() JavaCore.getOptions()}
 * will be used.
 *
 * @param document Document which describes the code of the AST that is passed in in the
 * constructor. This document is accessed read-only.
 * @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() {
            /**
             * This implementation of
             * {@link TargetSourceRangeComputer#computeSourceRange(ASTNode)}
             * is specialized to work in the case of internal AST rewriting, where the
             * original AST has been modified from its original form. This means that
             * one cannot trust that the root of the given node is the compilation unit.
             */
            public SourceRange computeSourceRange(ASTNode node) {
                int extendedStartPosition = rootNode.getExtendedStartPosition(node);
                int extendedLength = rootNode.getExtendedLength(node);
                return new SourceRange(extendedStartPosition, extendedLength);
            }
        };
        char[] content= document.get().toCharArray();
        LineInformation lineInfo= LineInformation.create(document);
        String lineDelim= TextUtilities.getDefaultLineDelimiter(document);
        List comments= rootNode.getCommentList();

        Map currentOptions = options == null ? JavaCore.getOptions() : options;
        ASTRewriteAnalyzer visitor = new ASTRewriteAnalyzer(content, lineInfo, lineDelim, result, this.eventStore, this.nodeStore, comments, currentOptions, xsrComputer, (RecoveryScannerData)rootNode.getStatementsRecoveryData());
        rootNode.accept(visitor);
    }
    return result;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:TightSourceRangeComputer.java   
@Override
public SourceRange computeSourceRange(ASTNode node) {
    if (fTightSourceRangeNodes.contains(node)) {
        return new TargetSourceRangeComputer.SourceRange(node.getStartPosition(), node.getLength());
    } else {
        return super.computeSourceRange(node); // see bug 85850
    }
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:RewriteEventStore.java   
public void updatePlaceholderSourceRanges(TargetSourceRangeComputer sourceRangeComputer) {
    TargetSourceRangeComputer.SourceRange startRange= sourceRangeComputer.computeSourceRange(getStartNode());
    TargetSourceRangeComputer.SourceRange endRange= sourceRangeComputer.computeSourceRange(getEndNode());
    int startPos= startRange.getStartPosition();
    int endPos= endRange.getStartPosition() + endRange.getLength();

    Block internalPlaceholder= getInternalPlaceholder();
    internalPlaceholder.setSourceRange(startPos, endPos - startPos);
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:RewriteEventStore.java   
public void prepareMovedNodes(TargetSourceRangeComputer sourceRangeComputer) {
    if (this.nodeCopySources != null) {
        prepareSingleNodeCopies();
    }

    if (this.nodeRangeInfos != null) {
        prepareNodeRangeCopies(sourceRangeComputer);
    }
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:RewriteEventStore.java   
private void prepareNodeRangeCopies(TargetSourceRangeComputer sourceRangeComputer) {
    for (Iterator iter= this.nodeRangeInfos.entrySet().iterator(); iter.hasNext();) {
        Map.Entry entry= (Map.Entry) iter.next();
        List rangeInfos= (List) entry.getValue(); // list of CopySourceRange
        Collections.sort(rangeInfos); // sort by start index, length, move or copy

        PropertyLocation loc= (PropertyLocation) entry.getKey();
        RewriteEvent[] children= getListEvent(loc.getParent(), loc.getProperty(), true).getChildren();

        RewriteEvent[] newChildren= processListWithRanges(rangeInfos, children, sourceRangeComputer);
        addEvent(loc.getParent(), loc.getProperty(), new ListRewriteEvent(newChildren)); // replace the current edits
    }
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:ASTRewriteAnalyzer.java   
/**
 * Constructor for ASTRewriteAnalyzer.
 * <p>The given options cannot be null.</p>
 * 
 * @param content the content of the compilation unit to rewrite.
 * @param lineInfo line information for the content of the compilation unit to rewrite.
 * @param rootEdit the edit to add all generated edits to
 * @param eventStore the event store containing the description of changes
 * @param nodeInfos annotations to nodes, such as if a node is a string placeholder or a copy target
 * @param comments list of comments of the compilation unit to rewrite (elements of type <code>Comment</code>) or <code>null</code>.
 * @param options the current jdt.core options (formatting/compliance)
 * @param extendedSourceRangeComputer the source range computer to use
 * @param recoveryScannerData internal data used by {@link RecoveryScanner}
 */
public ASTRewriteAnalyzer(
        char[] content,
        LineInformation lineInfo,
        String lineDelim,
        TextEdit rootEdit,
        RewriteEventStore eventStore,
        NodeInfoStore nodeInfos,
        List comments,
        Map options,
        TargetSourceRangeComputer extendedSourceRangeComputer,
        RecoveryScannerData recoveryScannerData) {
    this.eventStore= eventStore;
    this.content= content;
    this.lineInfo= lineInfo;
    this.nodeInfos= nodeInfos;
    this.tokenScanner= null;
    this.currentEdit= rootEdit;
    this.sourceCopyInfoToEdit= new IdentityHashMap();
    this.sourceCopyEndNodes= new Stack();

    this.formatter= new ASTRewriteFormatter(nodeInfos, eventStore, options, lineDelim);

    this.extendedSourceRangeComputer = extendedSourceRangeComputer;
    this.lineCommentEndOffsets= new LineCommentEndOffsets(comments);

    this.options = options;

    this.recoveryScannerData = recoveryScannerData;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:InternalASTRewrite.java   
/**
 * Performs the rewrite: The rewrite events are translated to the corresponding in text changes.
 * The given options can be null in which case the global options {@link JavaCore#getOptions() JavaCore.getOptions()}
 * will be used.
 *
 * @param document Document which describes the code of the AST that is passed in in the
 * constructor. This document is accessed read-only.
 * @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() {
            /**
             * This implementation of
             * {@link TargetSourceRangeComputer#computeSourceRange(ASTNode)}
             * is specialized to work in the case of internal AST rewriting, where the
             * original AST has been modified from its original form. This means that
             * one cannot trust that the root of the given node is the compilation unit.
             */
            public SourceRange computeSourceRange(ASTNode node) {
                int extendedStartPosition = rootNode.getExtendedStartPosition(node);
                int extendedLength = rootNode.getExtendedLength(node);
                return new SourceRange(extendedStartPosition, extendedLength);
            }
        };
        char[] content= document.get().toCharArray();
        LineInformation lineInfo= LineInformation.create(document);
        String lineDelim= TextUtilities.getDefaultLineDelimiter(document);
        List comments= rootNode.getCommentList();

        Map currentOptions = options == null ? JavaCore.getOptions() : options;
        ASTRewriteAnalyzer visitor = new ASTRewriteAnalyzer(content, lineInfo, lineDelim, result, this.eventStore, this.nodeStore, comments, currentOptions, xsrComputer, (RecoveryScannerData)rootNode.getStatementsRecoveryData());
        rootNode.accept(visitor);
    }
    return result;
}
项目:Eclipse-Postfix-Code-Completion    文件:ASTRewriteAnalyzer.java   
final int getExtendedEnd(ASTNode node) {
    TargetSourceRangeComputer.SourceRange range= getExtendedRange(node);
    return range.getStartPosition() + range.getLength();
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:ASTRewriteAnalyzer.java   
final int getExtendedEnd(ASTNode node) {
    TargetSourceRangeComputer.SourceRange range= getExtendedRange(node);
    return range.getStartPosition() + range.getLength();
}