org.jruby.lexer.yacc
Class SourcePosition

java.lang.Object
  extended byorg.jruby.lexer.yacc.SourcePosition
All Implemented Interfaces:
ISourcePosition, java.io.Serializable

public class SourcePosition
extends java.lang.Object
implements ISourcePosition, java.io.Serializable

Position within a source. This could have column as well, but it currently does not. A normal ruby intrepretter does not use this information in error/warning information. An IDE using this may need it though. This is trivially added if need be.

See Also:
ISourcePosition, Serialized Form

Constructor Summary
SourcePosition()
          Creates a default source position - required for serialization.
SourcePosition(java.lang.String file, int startLine, int endLine)
          Creates a new source position.
SourcePosition(java.lang.String file, int startLine, int endLine, int startOffset, int endOffset)
          Creates a new source position.
 
Method Summary
 void adjustStartOffset(int relativeValue)
          Modify startOffset by a relativeValue.
static SourcePosition combinePosition(ISourcePosition firstPos, ISourcePosition secondPos)
          Not used in interpreter Creates a new position the encloses both parameter positions.
 boolean equals(java.lang.Object object)
           
 int getEndLine()
          Which is the last(end) line that this source position occurs on (zero-based)
 int getEndOffset()
          Not used in interpreter
 java.lang.String getFile()
          Which file does this source position live in?
 int getStartLine()
          Not used in interpreter
 int getStartOffset()
          Not used in interpreter
 int hashCode()
          Something we can use for identity in hashing, etc...
 java.lang.String toString()
           
 ISourcePosition union(ISourcePosition other)
          Calculates the logical union of the two positions and creates a new resulting position
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SourcePosition

public SourcePosition()
Creates a default source position - required for serialization.


SourcePosition

public SourcePosition(java.lang.String file,
                      int startLine,
                      int endLine)
Creates a new source position.

Parameters:
file - location of the source (must not be null)
endLine - what line within the source

SourcePosition

public SourcePosition(java.lang.String file,
                      int startLine,
                      int endLine,
                      int startOffset,
                      int endOffset)
Creates a new source position.

Parameters:
file - location of the source (must not be null)
Method Detail

getFile

public java.lang.String getFile()
Description copied from interface: ISourcePosition
Which file does this source position live in?

Specified by:
getFile in interface ISourcePosition
Returns:
name of the source file.
See Also:
ISourcePosition.getFile()

getStartLine

public int getStartLine()
Not used in interpreter

Specified by:
getStartLine in interface ISourcePosition
Returns:
See Also:
ISourcePosition.getStartLine()

getEndLine

public int getEndLine()
Description copied from interface: ISourcePosition
Which is the last(end) line that this source position occurs on (zero-based)

Specified by:
getEndLine in interface ISourcePosition
Returns:
the line
See Also:
ISourcePosition.getEndLine()

equals

public boolean equals(java.lang.Object object)
Parameters:
object - the object which should be compared
Returns:
simple Object.equals() implementation

hashCode

public int hashCode()
Something we can use for identity in hashing, etc...

See Also:
Object.hashCode()

toString

public java.lang.String toString()
See Also:
Object.toString()

adjustStartOffset

public void adjustStartOffset(int relativeValue)
Description copied from interface: ISourcePosition
Modify startOffset by a relativeValue. At times our grammar and lexer do not give us the exact positions we need so we need to manually tweak position. The bummer of this is this requires ISourcePosition implementations are mutable.

Specified by:
adjustStartOffset in interface ISourcePosition
Parameters:
relativeValue - to nudge startOffset up or down
See Also:
ISourcePosition.adjustStartOffset(int)

getStartOffset

public int getStartOffset()
Not used in interpreter

Specified by:
getStartOffset in interface ISourcePosition
Returns:
the offset
See Also:
ISourcePosition.getStartOffset()

getEndOffset

public int getEndOffset()
Not used in interpreter

Specified by:
getEndOffset in interface ISourcePosition
Returns:
the offset
See Also:
ISourcePosition.getEndOffset()

union

public ISourcePosition union(ISourcePosition other)
Description copied from interface: ISourcePosition
Calculates the logical union of the two positions and creates a new resulting position

Specified by:
union in interface ISourcePosition
Parameters:
other - to be unioned against this position
Returns:
a new position
See Also:
ISourcePosition.union(ISourcePosition)

combinePosition

public static SourcePosition combinePosition(ISourcePosition firstPos,
                                             ISourcePosition secondPos)
Not used in interpreter Creates a new position the encloses both parameter positions.



Copyright © 2002-2007 JRuby Team. All Rights Reserved.