public static String getCompilableText(String backText) {
        String trimed = backText.trim();
        if ( trimed.endsWith( ";" ) ) {
            // RHS expression should compile if it ends with ; but to get the last object,
            // we do no want it, to simulate a return statement
            return backText.substring( 0,
                                       backText.length() - 1 );
        } else if ( trimed.endsWith( "." ) || trimed.endsWith( "," ) ) {
            // RHS expression should compile if it ends with no dot or comma
            return backText.substring( 0,
                                       backText.length() - 1 );
        } else if ( CompletionUtil.COMPLETED_MVEL_EXPRESSION.matcher( backText ).matches() ) {
            // RHS expression should compile if closed. just need to close the
            // statement
            return backText + ";";
            //        } else if ( INCOMPLETED_MVEL_EXPRESSION.matcher( backText ).matches() ) {
            //            // remove the last char and close the statement
            //            return backText.substring( 0,
            //                                       backText.length() - 1 );
        } else {
            //TODO: support completion within with {} blocks
            //TODO: support completion within nested expression.

            return backText;
        }
    }
public static String getCompilableText(String backText) {
        String trimed = backText.trim();
        if ( trimed.endsWith( ";" ) ) {
            
            
            return backText.substring( 0,
                                       backText.length() - 1 );
        } else if ( trimed.endsWith( "." ) || trimed.endsWith( "," ) ) {
            
            return backText.substring( 0,
                                       backText.length() - 1 );
        } else if ( CompletionUtil.COMPLETED_MVEL_EXPRESSION.matcher( backText ).matches() ) {
            
            
            return backText + ";";
            
            
            
            
        } else {
            
            

            return backText;
        }
    }
public static String getCompilableText ( String backText ) { String trimed = backText . trim ( ) ; if ( trimed . endsWith ( ";" ) ) { // RHS expression should compile if it ends with ; but to get the last object, // we do no want it, to simulate a return statement return backText . substring ( 0 , backText . length ( ) - 1 ) ; } else if ( trimed . endsWith ( "." ) || trimed . endsWith ( "," ) ) { // RHS expression should compile if it ends with no dot or comma return backText . substring ( 0 , backText . length ( ) - 1 ) ; } else if ( CompletionUtil . COMPLETED_MVEL_EXPRESSION . matcher ( backText ) . matches ( ) ) { // RHS expression should compile if closed. just need to close the // statement return backText + ";" ; //        } else if ( INCOMPLETED_MVEL_EXPRESSION.matcher( backText ).matches() ) { //            // remove the last char and close the statement //            return backText.substring( 0, //                                       backText.length() - 1 ); } else { //TODO: support completion within with {} blocks //TODO: support completion within nested expression. return backText ; } }
Attempt to enhance a consequence backtext such that it should compile in MVEL
@param backText
@return a substring of the back text, that should be compilable without
syntax errors by the mvel compiler

TODO: add tests and more use
cases
Attempt to enhance a consequence backtext such that it should compile in MVEL @param backText @return a substring of the back text that should be compilable without syntax errors by the mvel compiler