}
// This text region must be of type PhpScriptRegion:
if (tRegion != null
&& TwigTextSequenceUtilities.isTwigRegion(tRegion.getType())) {
ITwigScriptRegion twigScriptRegion = (ITwigScriptRegion) tRegion;
try {
// Set default starting position to the beginning of the
// PhpScriptRegion:
int startOffset = container.getStartOffset()
+ twigScriptRegion.getStart();
// Now, search backwards for the statement start (in this
// PhpScriptRegion):
ITextRegion startTokenRegion;
if (documentOffset == startOffset) {
startTokenRegion = twigScriptRegion.getTwigToken(0);
} else {
startTokenRegion = twigScriptRegion.getTwigToken(offset
- startOffset - 1);
}
while (true) {
// If statement start is at the beginning of the PHP script
// region:
if (startTokenRegion.getStart() == 0) {
break;
}
if (startTokenRegion.getType() == PHPRegionTypes.PHP_CURLY_CLOSE
|| startTokenRegion.getType() == PHPRegionTypes.PHP_CURLY_OPEN
|| startTokenRegion.getType() == PHPRegionTypes.PHP_SEMICOLON) {
// Calculate starting position of the statement (it
// should go right after this startTokenRegion):
startOffset += startTokenRegion.getEnd();
break;
}
startTokenRegion = twigScriptRegion
.getTwigToken(startTokenRegion.getStart() - 1);
}
TextSequence textSequence = TextSequenceUtilities
.createTextSequence(sdRegion, startOffset, offset