*
* @return The Context that this expression occurs in
*/
public Context getContext()
{
IASNode p = getParent();
Context c = null;
while (p != null && c == null)
{
if (p instanceof VariableNode)
{
VariableNode vn = (VariableNode)p;
IVariableDefinition varDef = (IVariableDefinition)vn.getDefinition();
switch (varDef.getVariableClassification())
{
case CLASS_MEMBER:
{
if (varDef.hasModifier(ASModifier.STATIC))
c = Context.STATIC_CONTEXT;
else
c = Context.INSTANCE_CONTEXT;
break;
}
case PACKAGE_MEMBER:
{
c = Context.PACKAGE_CONTEXT;
break;
}
case FILE_MEMBER:
{
c = Context.GLOBAL_CONTEXT;
break;
}
// Otherwise, Keep looking, context will be based on the enclosing definition of the
// Variable Decl
//case LOCAL:
//case PARAMETER:
//break;
}
}
else if (p instanceof FunctionNode)
{
FunctionNode fn = (FunctionNode)p;
FunctionDefinition funcDef = fn.getDefinition();
switch (funcDef.getFunctionClassification())
{
case CLASS_MEMBER:
case INTERFACE_MEMBER:
{
if (funcDef.hasModifier(ASModifier.STATIC))
c = Context.STATIC_CONTEXT;
else
c = Context.INSTANCE_CONTEXT;
break;
}
case PACKAGE_MEMBER:
case FILE_MEMBER:
{
c = Context.GLOBAL_CONTEXT;
break;
}
}
}
if (p instanceof FunctionObjectNode)
{
// 'this' could be anything in a function expression - callers can use whatever 'this' they like
c = Context.GLOBAL_CONTEXT;
}
else if (p instanceof ClassNode)
{
// If we get here then this expression must be loose code in a class def,
// so we are running in a static context
c = Context.STATIC_CONTEXT;
}
else if (p instanceof PackageNode)
{
// If we get here, then this expression must be loose code in a package def,
// so we're running in a package context
c = Context.PACKAGE_CONTEXT;
}
else if (p instanceof IMXMLScriptNode)
{
// If we get here then this expression must be loose code in a <fx:Script> tag,
// which is compiled as if it was loose code in a class, so we are a static context
c = Context.STATIC_CONTEXT;
}
else if (p instanceof IMXMLDocumentNode)
{
// If we get here, the this expression must be loose code in a MXML document, such
// as in a databinding expression, so we're in Instance context
c = Context.INSTANCE_CONTEXT;
}
p = p.getParent();
}
// If we run out of parents, then we must be in a global context
if (c == null)
c = Context.GLOBAL_CONTEXT;