Example usage for org.eclipse.jdt.core.dom CompilationUnit getLength

List of usage examples for org.eclipse.jdt.core.dom CompilationUnit getLength

Introduction

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

Prototype

public final int getLength() 

Source Link

Document

Returns the length in characters of the original source file indicating where the source fragment corresponding to this node ends.

Usage

From source file:com.dnw.plugin.ast.VisitContext.java

License:Open Source License

/**
 * Constructor of VisitContext./*  w w w .j  ava2 s  . c om*/
 * 
 * @author manbaum
 * @since Oct 17, 2014
 * @param file
 * @param parser
 * @param unit
 * @param root
 * @param monitor
 */
public VisitContext(IFile file, ASTParser parser, ICompilationUnit unit, CompilationUnit root,
        IProgressMonitor monitor) {
    this.file = file;
    this.parser = parser;
    this.unit = unit;
    this.root = root;
    this.monitor = SubMonitor.convert(monitor, root.getLength());
    this.monitor.setTaskName(file.getFullPath().toString());
    currentPosition = 0;
}

From source file:org.eclipse.umlgen.reverse.java.JavaReverseCUVisitor.java

License:Open Source License

/**
 * Extract code ranges inside "user code" tags.
 *
 * @param node/*  w w w  . j  av a  2 s.c  o  m*/
 * @return ranges list
 */
private List<int[]> getRanges(CompilationUnit node) {

    ArrayList<int[]> userCodeRange = new ArrayList<int[]>();
    int range1 = -1;
    int range2 = -1;

    List<Comment> listc = node.getCommentList();

    for (Comment com : listc) {
        if (com instanceof LineComment) {
            LineComment linecom = (LineComment) com;
            int startpos = linecom.getStartPosition();
            int linepos = node.getLineNumber(startpos) - 1;
            String text = sources[linepos];
            if (text.indexOf(userCodeStartTag) > 0) {
                if (range1 < 0) {
                    range1 = linecom.getStartPosition();
                }
            }
            if (text.indexOf(userCodeStopTag) > 0) {
                range2 = linecom.getStartPosition();
                int[] range = { range1, range2 };
                userCodeRange.add(range);
                range1 = -1;
            }
        }
    }
    if (range1 > range2) {
        range2 = node.getLength() + 1;
        int[] range = { range1, range2 };
        userCodeRange.add(range);
    }
    return userCodeRange;

}