Top Description Fields Constructors Methods
org.codehaus.groovy.runtime.powerassert

public Class SourceText

extends Object
Class Inheritance
Imports
org.codehaus.groovy.ast.ASTNode, org.codehaus.groovy.ast.stmt.AssertStatement, org.codehaus.groovy.control.Janitor, .SourceUnit, java.util.ArrayList, .List

Provides the source text for an assertion statement and translates coordinates in the original source text to coordinates relative to the assertion's (normalized) source text.

Field Summary

Modifier and TypeField and Description
private final int
private final List<Integer>
private String
private final List<Integer>

Constructor Summary

AccessConstructor and Description
public
SourceText(AssertStatement
an assertion statement
stat
,
SourceUnit
the source unit containing the assertion statement
sourceUnit
,
Janitor
a Janitor for cleaning up reader sources
janitor
)

Constructs a SourceText by reading the given assertion's source text from the given source unit.

Method Summary

Modifier and TypeMethod and Description
private static int
public int

Returns:

the column in getNormalizedText() corresponding to the given line and column in the original source text
getNormalizedColumn
(int
a line number
line
,
int
a column number
column
)

Returns the column in getNormalizedText() corresponding to the given line and column in the original source text.

public String

Returns:

the assertion's source text after removing line breaks.
getNormalizedText
()

Returns the assertion's source text after removing line breaks.

private static boolean
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

firstLineback to summary
private final int firstLine
lineOffsetsback to summary
private final List<Integer> lineOffsets
normalizedTextback to summary
private String normalizedText
textOffsetsback to summary
private final List<Integer> textOffsets

Constructor Detail

SourceTextback to summary
public SourceText(AssertStatement stat, SourceUnit sourceUnit, Janitor janitor)

Constructs a SourceText by reading the given assertion's source text from the given source unit.

Parameters
stat:AssertStatement

an assertion statement

sourceUnit:SourceUnit

the source unit containing the assertion statement

janitor:Janitor

a Janitor for cleaning up reader sources

Method Detail

countLeadingWhitespaceback to summary
private static int countLeadingWhitespace(String lineText)
getNormalizedColumnback to summary
public int getNormalizedColumn(int line, int column)

Returns the column in getNormalizedText() corresponding to the given line and column in the original source text. The first character in the normalized text has column 1.

Parameters
line:int

a line number

column:int

a column number

Returns:int

the column in getNormalizedText() corresponding to the given line and column in the original source text

getNormalizedTextback to summary
public String getNormalizedText()

Returns the assertion's source text after removing line breaks.

Limitation: Line comments within the assertion's source text are not handled.

Returns:String

the assertion's source text after removing line breaks.

hasPlausibleSourcePositionback to summary
private static boolean hasPlausibleSourcePosition(ASTNode node)