ICompletionContext context = getContext();
if (!(context instanceof ArrayKeyContext)) {
return;
}
ArrayKeyContext arrayContext = (ArrayKeyContext) context;
CompletionRequestor requestor = arrayContext.getCompletionRequestor();
String arrayVarName = arrayContext.getArrayVarName();
String prefix = arrayContext.getPrefix();
int extraObject = ProposalExtraInfo.DEFAULT;
if (!arrayContext.hasQuotes()) {
extraObject |= ProposalExtraInfo.ADD_QUOTES;
}
// report server variables:
if (arrayVarName.equals("$_SERVER") //$NON-NLS-1$
|| arrayVarName.equals("$HTTP_SERVER_VARS")) { // NON-NLS-1 //$NON-NLS-1$
// //NON-NLS-2
reportVariables(reporter, arrayContext, SERVER_VARS, prefix,
extraObject);
}
// report session variables:
else if (arrayVarName.equals("$_SESSION") //$NON-NLS-1$
|| arrayVarName.equals("$HTTP_SESSION_VARS")) { // NON-NLS-1 //$NON-NLS-1$
// //NON-NLS-2
reportVariables(reporter, arrayContext, SESSION_VARS, prefix,
extraObject);
}
// report global variables in special globals array:
else if (arrayVarName.equals("$GLOBALS")) { // NON-NLS-1 //$NON-NLS-1$
MatchRule matchRule = MatchRule.PREFIX;
if (requestor.isContextInformationMode()) {
matchRule = MatchRule.EXACT;
}
IDLTKSearchScope scope = createSearchScope();
IField[] elements = PhpModelAccess.getDefault().findFields(
"$" + prefix, matchRule, Modifiers.AccGlobal, //$NON-NLS-1$
Modifiers.AccConstant, scope, null);
List<IField> list = new ArrayList<IField>();
if (!prefix.startsWith("$")) { //$NON-NLS-1$
elements = PhpModelAccess.getDefault().findFields("$" + prefix, //$NON-NLS-1$
matchRule, Modifiers.AccGlobal, Modifiers.AccConstant,
scope, null);
list.addAll(Arrays.asList(elements));
elements = list.toArray(new IField[list.size()]);
}
SourceRange replaceRange = getReplacementRange(arrayContext);
for (IModelElement element : elements) {
IField field = (IField) element;
try {
ISourceRange sourceRange = field.getSourceRange();
FakeField fakeField = new FakeField(
(ModelElement) field.getParent(), field
.getElementName().substring(1),
sourceRange.getOffset(), sourceRange.getLength());
reporter.reportField(fakeField, "", replaceRange, true, 0, //$NON-NLS-1$
extraObject); // NON-NLS-1
} catch (ModelException e) {
PHPCorePlugin.log(e);
}
}
PHPVersion phpVersion = arrayContext.getPhpVersion();
reportVariables(reporter, arrayContext,
PHPVariables.getVariables(phpVersion), prefix, true,
extraObject);
}
}