*
* @throws BadLocationException
*/
public String getPreviousWord(int times) throws BadLocationException
{
TextSequence statementText = getStatementText();
int statementLength = statementText.length();
int wordEnd = PHPTextSequenceUtilities.readBackwardSpaces(
statementText, statementLength); // read whitespace
int wordStart = PHPTextSequenceUtilities.readIdentifierStartIndex(
phpVersion, statementText, wordEnd, true);
for (int i = 0; i < times - 1; i++) {
statementLength = wordStart;
wordEnd = PHPTextSequenceUtilities.readBackwardSpaces(
statementText, statementLength); // read whitespace
wordStart = PHPTextSequenceUtilities.readIdentifierStartIndex(
phpVersion, statementText, wordEnd, true);
}
if (wordStart < 0 || wordEnd < 0 || wordStart > wordEnd) {
return "";
}
String previousWord = statementText.subSequence(wordStart, wordEnd)
.toString();
if (hasWhitespaceBeforeCursor()) {
return previousWord;
}
wordEnd = PHPTextSequenceUtilities.readBackwardSpaces(statementText,
wordStart - 1); // read whitespace
wordStart = PHPTextSequenceUtilities.readIdentifierStartIndex(
phpVersion, statementText, wordEnd, true);
if (wordStart < 0 || wordEnd < 0 || wordStart > wordEnd) {
return "";
}
previousWord = statementText.subSequence(wordStart, wordEnd).toString();
return previousWord;
}