Example usage for org.eclipse.jdt.core.dom Comment setSourceRange

List of usage examples for org.eclipse.jdt.core.dom Comment setSourceRange

Introduction

In this page you can find the example usage for org.eclipse.jdt.core.dom Comment setSourceRange.

Prototype

public final void setSourceRange(int startPosition, int length) 

Source Link

Document

Sets the source range of the original source file where the source fragment corresponding to this node was found.

Usage

From source file:org.eclipse.jdt.core.dom.ASTConverter.java

License:Open Source License

protected Comment createComment(int[] positions) {
    // Create comment node
    Comment comment = null;
    int start = positions[0];
    int end = positions[1];
    if (positions[1] > 0) { // Javadoc comments have positive end position
        Javadoc docComment = this.docParser.parse(positions);
        if (docComment == null)
            return null;
        comment = docComment;//from  ww w .  j  av  a  2s.  co  m
    } else {
        end = -end;
        if (positions[0] == 0) { // we cannot know without testing chars again
            if (this.docParser.scanner.source[1] == '/') {
                comment = new LineComment(this.ast);
            } else {
                comment = new BlockComment(this.ast);
            }
        } else if (positions[0] > 0) { // Block comment have positive start position
            comment = new BlockComment(this.ast);
        } else { // Line comment have negative start and end position
            start = -start;
            comment = new LineComment(this.ast);
        }
        comment.setSourceRange(start, end - start);
    }
    return comment;
}