com.aptana.ide.editor.js.context
Class JSLexemeUtils

java.lang.Object
  extended by com.aptana.ide.editor.js.context.JSLexemeUtils

public class JSLexemeUtils
extends java.lang.Object

Author:
Robin Debreuil

Constructor Summary
JSLexemeUtils(LexemeList lexemeList)
          Constructs a new File environment.
 
Method Summary
 void calculateCurrentLexeme(int offset)
          Calculates the index and lexeme that the given offset is within and caches it.
 int findDocOffset(int currentIndex)
          findDocOffset
 JSFunctionInfo findIdentifierBeforeEqual(int currentIndex)
          findIdentifierBeforeEqual
 int findNextTokenType(int startIndex, int typeIndex)
          findNextTokenType
 Lexeme getCurrentLexeme()
          Gets the cached current Lexeme based on the current offset of the document.
 int getCurrentLexemeIndex()
          Gets the cached current Lexeme index based on the offset in the current document.
 JSFunctionInfo getFunctionInfo(int currentIndex)
          Looks for the name of the function in the following formats: TYPE 1: function foo() {} TYPE 2: foo = function() {} TYPE 3: bar.foo = function() {} TYPE 4: foo = { "bar" : function() {}, bar2 : function() {}, ...
 int getIndexAfterTypeIdentifier(int index)
          getIndexAfterTypeIdentifier
 int getLexemeCeilingIndex(int offset)
          Gets the lexeme ceiling index from a given offset (lexeme offset, not document offset).
 int getLexemeFloorIndex(int offset)
          Gets the lexeme floor index from a given offset (lexeme offset, not document offset).
 Lexeme getLexemeFromDocumentOffset(int offset)
          Calculates and returns the Lexeme at a document based offset.
 int getLexemeIndexFromDocumentOffset(int offset)
          Calculates and returns the Lexeme index at the current document offset.
 LexemeList getLexemeList()
          Get the current list of lexemes and synchronize the command tree.
 Lexeme getNextIdentifier(int index)
          Returns the next IDENTIFIER Lexeme from the starting 'index' position
 java.lang.String getNextTypeIdentifier(int startIndex)
          getNextTypeIdentifier
 Lexeme getPreviousIdentifier(int index)
          getPreviousIdentifier
 java.lang.String getTypeAfterEqualNew(int index)
          Find 'foo' in a 'var a = new foo();' statement, but also account for comments.
 int isNextTokenType(int startIndex, int typeIndex)
          isNextTokenType
 int isPrevTokenType(int startIndex, int typeIndex)
          isPrevTokenType
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JSLexemeUtils

public JSLexemeUtils(LexemeList lexemeList)
Constructs a new File environment. There is one such object per file, and this takes care of parsing it and keeping its environment up to date.

Parameters:
lexemeList -
Method Detail

getLexemeList

public LexemeList getLexemeList()
Get the current list of lexemes and synchronize the command tree. Performance warning: this method will trigger a full parse if necessary, if you do not need access to the parser's command nodes, then use getLexemeListFast().

Returns:
The lexeme list

getCurrentLexeme

public Lexeme getCurrentLexeme()
Gets the cached current Lexeme based on the current offset of the document.

Returns:
Returns the current lexeme.

getCurrentLexemeIndex

public int getCurrentLexemeIndex()
Gets the cached current Lexeme index based on the offset in the current document.

Returns:
Returns the current lexeme index.

getLexemeIndexFromDocumentOffset

public int getLexemeIndexFromDocumentOffset(int offset)
Calculates and returns the Lexeme index at the current document offset. Note that document offsets are one greater that lexeme offsets. Use getCurrentLexemeInde if querying for the current caret offset.

Parameters:
offset - The offset in the document to check at.
Returns:
Returns the index of the Lexeme at the current offset.

getLexemeFloorIndex

public int getLexemeFloorIndex(int offset)
Gets the lexeme floor index from a given offset (lexeme offset, not document offset). If this hits a whitespace character (which has no lexeme), it will return the previous (lower) lexeme. This is a convenience method that directly calls getLexemeFloorIndex on lexemelist.

Parameters:
offset -
Returns:
Returns the lexeme floor index from a given lexeme offset.

getLexemeCeilingIndex

public int getLexemeCeilingIndex(int offset)
Gets the lexeme ceiling index from a given offset (lexeme offset, not document offset). If this hits a whitespace character (which has no lexeme), it will return the next (higher) lexeme. This is a convenience method that directly calls getLexemeCeilingIndex on lexemelist.

Parameters:
offset -
Returns:
Returns the lexeme floor index from a given lexeme offset.

getLexemeFromDocumentOffset

public Lexeme getLexemeFromDocumentOffset(int offset)
Calculates and returns the Lexeme at a document based offset. Use getCurrentLexeme if querying for the current caret offset.

Parameters:
offset - The offset in the document to check at.
Returns:
Returns the Lexeme at the current offset.

calculateCurrentLexeme

public void calculateCurrentLexeme(int offset)
Calculates the index and lexeme that the given offset is within and caches it. This accounts for whitespace areas by setting the result to the previous lexeme if available.

Parameters:
offset -

getNextIdentifier

public Lexeme getNextIdentifier(int index)
Returns the next IDENTIFIER Lexeme from the starting 'index' position

Parameters:
index -
Returns:
Returns the next Ident lexeme

getPreviousIdentifier

public Lexeme getPreviousIdentifier(int index)
getPreviousIdentifier

Parameters:
index -
Returns:
Lexeme

getNextTypeIdentifier

public java.lang.String getNextTypeIdentifier(int startIndex)
getNextTypeIdentifier

Parameters:
startIndex -
Returns:
String

getTypeAfterEqualNew

public java.lang.String getTypeAfterEqualNew(int index)
Find 'foo' in a 'var a = new foo();' statement, but also account for comments.

Parameters:
index -
Returns:
Returns 'foo' in a 'var a = new foo();' statement, but also account for comments.

getIndexAfterTypeIdentifier

public int getIndexAfterTypeIdentifier(int index)
getIndexAfterTypeIdentifier

Parameters:
index -
Returns:
int

findNextTokenType

public int findNextTokenType(int startIndex,
                             int typeIndex)
findNextTokenType

Parameters:
startIndex -
typeIndex -
Returns:
int

isNextTokenType

public int isNextTokenType(int startIndex,
                           int typeIndex)
isNextTokenType

Parameters:
startIndex -
typeIndex -
Returns:
int

isPrevTokenType

public int isPrevTokenType(int startIndex,
                           int typeIndex)
isPrevTokenType

Parameters:
startIndex -
typeIndex -
Returns:
int

getFunctionInfo

public JSFunctionInfo getFunctionInfo(int currentIndex)
Looks for the name of the function in the following formats: TYPE 1: function foo() {} TYPE 2: foo = function() {} TYPE 3: bar.foo = function() {} TYPE 4: foo = { "bar" : function() {}, bar2 : function() {}, ... } TYPE 5: function foo() { bar=function() {} }

Parameters:
currentIndex - The current index of the lexemes to look at.
Returns:
Returns the name of the function

findDocOffset

public int findDocOffset(int currentIndex)
findDocOffset

Parameters:
currentIndex -
Returns:
int

findIdentifierBeforeEqual

public JSFunctionInfo findIdentifierBeforeEqual(int currentIndex)
findIdentifierBeforeEqual

Parameters:
currentIndex -
Returns:
JSFunctionInfo