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

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

Introduction

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

Prototype

public int lineNumber(int position) 

Source Link

Document

Returns the line number corresponding to the given source character position in the original source string.

Usage

From source file:net.sourceforge.metrics.core.sources.AbstractMetricSource.java

License:Open Source License

private void configureOutOfRangeMarker(Metric value, MetricDescriptor md, IResource resource)
        throws CoreException {
    IMarker marker = resource.createMarker("net.sourceforge.metrics.outofrangemarker");
    if ((marker != null) && (marker.exists())) {
        JavaCore.getJavaCore().configureJavaElementMarker(marker, getJavaElement());
        marker.setAttribute("metric", value.getName());
        marker.setAttribute("value", "" + value.doubleValue());
        String message = createMessage(value, md);
        marker.setAttribute(IMarker.MESSAGE, message);
        marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_WARNING);
        if (getJavaElement() instanceof IMember) {
            IMember m = (IMember) getJavaElement();
            int offset = m.getNameRange().getOffset();
            int length = m.getNameRange().getLength();
            marker.setAttribute(IMarker.CHAR_START, offset);
            marker.setAttribute(IMarker.CHAR_END, offset + length);
            CompilationUnit cu = getParsedCompilationUnit();
            if (cu != null) {
                marker.setAttribute(IMarker.LINE_NUMBER, cu.lineNumber(offset));
            }// w  w w  . j a v a  2s . c o m
        }
    }
}

From source file:sharpen.core.framework.ASTUtility.java

License:Open Source License

@SuppressWarnings("deprecation")
public static int lineNumber(CompilationUnit ast, ASTNode node) {
    return ast.lineNumber(node.getStartPosition());
}