src/main/java/ognl/enhance/ExpressionCompiler.java
public static String getRootExpression(Node expression, Object root, OgnlContext context)
    {
        String rootExpr = "";

        if (!shouldCast(expression))
            return rootExpr;

        if ((!ASTList.class.isInstance(expression)
             && !ASTVarRef.class.isInstance(expression)
             && !ASTStaticMethod.class.isInstance(expression)
             && !ASTStaticField.class.isInstance(expression)
             && !ASTConst.class.isInstance(expression)
             && !ExpressionNode.class.isInstance(expression)
             && !ASTCtor.class.isInstance(expression)
             && !ASTStaticMethod.class.isInstance(expression)
             && root != null) || (root != null && ASTRootVarRef.class.isInstance(expression))) {

            Class castClass = OgnlRuntime.getCompiler().getRootExpressionClass(expression, context);
            
            if (castClass.isArray() || ASTRootVarRef.class.isInstance(expression)
                || ASTThisVarRef.class.isInstance(expression))
            {
                rootExpr = "((" + getCastString(castClass) + ")$2)";

                if (ASTProperty.class.isInstance(expression) && !((ASTProperty) expression).isIndexedAccess())
                    rootExpr += ".";
            } else if ((ASTProperty.class.isInstance(expression)
                        && ((ASTProperty) expression).isIndexedAccess())
                       || ASTChain.class.isInstance(expression))
            {
                rootExpr = "((" + getCastString(castClass) + ")$2)";
            } else
            {
                rootExpr = "((" + getCastString(castClass) + ")$2).";
            }
        }

        return rootExpr;
    }
public static String getRootExpression(Node expression, Object root, OgnlContext context)
    {
        String rootExpr = "";

        if (!shouldCast(expression))
            return rootExpr;

        if ((!ASTList.class.isInstance(expression)
             && !ASTVarRef.class.isInstance(expression)
             && !ASTStaticMethod.class.isInstance(expression)
             && !ASTStaticField.class.isInstance(expression)
             && !ASTConst.class.isInstance(expression)
             && !ExpressionNode.class.isInstance(expression)
             && !ASTCtor.class.isInstance(expression)
             && !ASTStaticMethod.class.isInstance(expression)
             && root != null) || (root != null && ASTRootVarRef.class.isInstance(expression))) {

            Class castClass = OgnlRuntime.getCompiler().getRootExpressionClass(expression, context);
            
            if (castClass.isArray() || ASTRootVarRef.class.isInstance(expression)
                || ASTThisVarRef.class.isInstance(expression))
            {
                rootExpr = "((" + getCastString(castClass) + ")$2)";

                if (ASTProperty.class.isInstance(expression) && !((ASTProperty) expression).isIndexedAccess())
                    rootExpr += ".";
            } else if ((ASTProperty.class.isInstance(expression)
                        && ((ASTProperty) expression).isIndexedAccess())
                       || ASTChain.class.isInstance(expression))
            {
                rootExpr = "((" + getCastString(castClass) + ")$2)";
            } else
            {
                rootExpr = "((" + getCastString(castClass) + ")$2).";
            }
        }

        return rootExpr;
    }
public static String getRootExpression ( Node expression , Object root , OgnlContext context ) { String rootExpr = "" ; if ( ! shouldCast ( expression ) ) return rootExpr ; if ( ( ! ASTList . class . isInstance ( expression ) && ! ASTVarRef . class . isInstance ( expression ) && ! ASTStaticMethod . class . isInstance ( expression ) && ! ASTStaticField . class . isInstance ( expression ) && ! ASTConst . class . isInstance ( expression ) && ! ExpressionNode . class . isInstance ( expression ) && ! ASTCtor . class . isInstance ( expression ) && ! ASTStaticMethod . class . isInstance ( expression ) && root != null ) || ( root != null && ASTRootVarRef . class . isInstance ( expression ) ) ) { Class castClass = OgnlRuntime . getCompiler ( ) . getRootExpressionClass ( expression , context ) ; if ( castClass . isArray ( ) || ASTRootVarRef . class . isInstance ( expression ) || ASTThisVarRef . class . isInstance ( expression ) ) { rootExpr = "((" + getCastString ( castClass ) + ")$2)" ; if ( ASTProperty . class . isInstance ( expression ) && ! ( ( ASTProperty ) expression ) . isIndexedAccess ( ) ) rootExpr += "." ; } else if ( ( ASTProperty . class . isInstance ( expression ) && ( ( ASTProperty ) expression ) . isIndexedAccess ( ) ) || ASTChain . class . isInstance ( expression ) ) { rootExpr = "((" + getCastString ( castClass ) + ")$2)" ; } else { rootExpr = "((" + getCastString ( castClass ) + ")$2)." ; } } return rootExpr ; }
Convenience method called by many different property/method resolving AST types to get a root expression
resolving string for the given node.  The callers are mostly ignorant and rely on this method to properly
determine if the expression should be cast at all and take the appropriate actions if it should.

@param expression
The node to check and generate a root expression to if necessary.
@param root
The root object for this execution.
@param context
The current execution context.
@return Either an empty string or a root path java source string compatible with javassist compilations
from the root object up to the specified {@link Node}.
Convenience method called by many different property / method resolving AST types to get a root expression resolving string for the given node . The callers are mostly ignorant and rely on this method to properly determine if the expression should be cast at all and take the appropriate actions if it should .