Expression key = element.getKey();
Expression value = element.getValue();
if (key.getClass() == Scalar.class) {
Scalar varName = (Scalar) key;
// something in the form: return array ('foo' => $bar);
// check the type of $bar:
if (value.getClass() == VariableReference.class) {
VariableReference ref = (VariableReference) value;
for (TemplateVariable variable : deferredVariables) {
// we got the variable, add it the the templateVariables
if (ref.getName().equals(variable.getName())) {
// alter the variable name
variable.setName(varName.getValue());
templateVariables.put(variable, viewPath);
break;
}
}
// this is more complicated, something like:
// return array('form' => $form->createView());
// we need to infer $form and then check the returntype of createView()
} else if(value.getClass() == PHPCallExpression.class) {
PHPCallExpression callExp = (PHPCallExpression) value;
VariableReference varRef = null;
try {
varRef = (VariableReference) callExp.getReceiver();
} catch (ClassCastException e) {
Logger.log(Logger.WARNING, callExp.getReceiver().getClass().toString()
+ " could not be cast to VariableReference in " + currentMethod.getName() );
}
if (varRef == null) {
continue;
}
SimpleReference callName = callExp.getCallName();
// we got the variable name (in this case $form)
// now search for the defferedVariable:
for (TemplateVariable deferred : deferredVariables) {
// we got it, find the returntype of the
// callExpression
if (deferred.getName().equals(varRef.getName())) {
TemplateVariable tempVar = SymfonyModelAccess.getDefault()
.createTemplateVariableByReturnType(source, currentMethod,
callName, deferred.getClassName(), deferred.getNamespace(),
varRef.getName(), cache);
templateVariables.put(tempVar, viewPath);
break;
}
}
// this is a direct ClassInstanceCreation, ie:
// return array('user' => new User());
} else if (value.getClass() == ClassInstanceCreation.class) {
ClassInstanceCreation instance = (ClassInstanceCreation) value;
if (instance.getClassName().getClass() == FullyQualifiedReference.class) {
FullyQualifiedReference fqcn = (FullyQualifiedReference) instance.getClassName();
NamespaceReference nsRef = createFromFQCN(fqcn);
if (nsRef != null) {
TemplateVariable variable = new TemplateVariable(currentMethod, varName.getValue(),
varName.sourceStart(), varName.sourceEnd(), nsRef.getNamespace(), nsRef.getClassName());
templateVariables.put(variable, viewPath);
}
}
} else {