return EMPTY;
}
// Determine element name:
int elementStart = container.getStartOffset()
+ phpScriptRegion.getStart() + tRegion.getStart();
TextSequence statement = PHPTextSequenceUtilities
.getStatement(elementStart + tRegion.getLength(),
sRegion, true);
if (statement == null) {
return EMPTY;
}
int endPosition = PHPTextSequenceUtilities
.readBackwardSpaces(statement, statement.length());
int startPosition = PHPTextSequenceUtilities
.readIdentifierStartIndex(phpVersion, statement,
endPosition, true);
String elementName = statement.subSequence(startPosition,
endPosition).toString();
// Determine previous word:
int prevWordEnd = PHPTextSequenceUtilities
.readBackwardSpaces(statement, startPosition);
int prevWordStart = PHPTextSequenceUtilities
.readIdentifierStartIndex(phpVersion, statement,
prevWordEnd, false);
String prevWord = statement.subSequence(prevWordStart,
prevWordEnd).toString();
// Determine next word:
ITextRegion nextRegion = tRegion;
do {
nextRegion = phpScriptRegion.getPhpToken(nextRegion
.getEnd());
if (!PHPPartitionTypes.isPHPCommentState(nextRegion
.getType())
&& nextRegion.getType() != PHPRegionTypes.WHITESPACE) {
break;
}
} while (nextRegion.getEnd() < phpScriptRegion.getLength());
String nextWord = sDoc.get(
container.getStartOffset()
+ phpScriptRegion.getStart()
+ nextRegion.getStart(),
nextRegion.getTextLength());
if (elementName.length() > 0) {
IType containerType = PHPModelUtils.getCurrentType(
sourceModule, offset);
if (containerType == null) {
containerType = PHPModelUtils.getCurrentNamespace(
sourceModule, offset);
}
// If we are in function declaration:
if (FUNCTION.equalsIgnoreCase(prevWord)) { //$NON-NLS-1$
if (containerType != null) {
return PHPModelUtils.getTypeMethod(
containerType, elementName, true);
}
return getFunction(sourceModule, elementName);
}
// If we are in class declaration:
if (CLASS.equalsIgnoreCase(prevWord)
|| INTERFACE.equalsIgnoreCase(prevWord)) { //$NON-NLS-1$ //$NON-NLS-2$
if (containerType != null) {
if (containerType.getElementName()
.equalsIgnoreCase(elementName)) {
containerType = PHPModelUtils
.getCurrentNamespace(sourceModule,
offset);
}
if (containerType != null) {
return PHPModelUtils.getTypeType(
containerType, elementName, true);
}
}
return getClass(sourceModule, elementName);
}
// Class instantiation:
if (NEW.equalsIgnoreCase(prevWord)) { //$NON-NLS-1$
return getConstructorsIfAny(extractClasses(PHPModelUtils
.getTypes(elementName, sourceModule,
offset, cache, null)));
}
// Handle extends and implements:
// Check that the statement suites the condition. If
// class or interface keywords don't appear in the
// beginning of the statement or they are alone there.
boolean isClassDeclaration = false;
if (statement.length() > 6
&& (CLASS.equals(statement.subSequence(0, 5)
.toString())
&& (isClassDeclaration = true) || statement
.length() > 10
&& INTERFACE.equals(statement
.subSequence(0, 9).toString()))) { //$NON-NLS-1$ //$NON-NLS-2$
IModelElement[] generalizationTypes = getGeneralizationTypes(
sourceModule, isClassDeclaration, prevWord,
elementName, offset);
if (generalizationTypes != null) {
return generalizationTypes;
}
// Multiple extensions and implementations:
int listStartPosition = PHPTextSequenceUtilities
.readIdentifierListStartIndex(statement,
endPosition);
// Determine pre-list word:
int preListWordEnd = PHPTextSequenceUtilities
.readBackwardSpaces(statement,
listStartPosition);
int preListWordStart = PHPTextSequenceUtilities
.readIdentifierStartIndex(statement,
preListWordEnd, false);
String preListWord = statement.subSequence(
preListWordStart, preListWordEnd)
.toString();
generalizationTypes = getGeneralizationTypes(
sourceModule, isClassDeclaration,
preListWord, elementName, offset);
if (generalizationTypes != null) {
return generalizationTypes;
}
}
// Previous trigger:
String trigger = null;
if (startPosition > 2) {
trigger = statement.subSequence(startPosition - 2,
startPosition).toString();
}
// If this is variable:
if (elementName.charAt(0) == '$'