Coverage Report - org.apache.commons.ognl.BooleanExpression
 
Classes in this File Line Coverage Branch Coverage Complexity
BooleanExpression
47%
11/23
50%
5/10
3.4
 
 1  
 package org.apache.commons.ognl;
 2  
 
 3  
 /*
 4  
  * Licensed to the Apache Software Foundation (ASF) under one
 5  
  * or more contributor license agreements.  See the NOTICE file
 6  
  * distributed with this work for additional information
 7  
  * regarding copyright ownership.  The ASF licenses this file
 8  
  * to you under the Apache License, Version 2.0 (the
 9  
  * "License"); you may not use this file except in compliance
 10  
  * with the License.  You may obtain a copy of the License at
 11  
  *
 12  
  *   http://www.apache.org/licenses/LICENSE-2.0
 13  
  *
 14  
  * Unless required by applicable law or agreed to in writing,
 15  
  * software distributed under the License is distributed on an
 16  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 17  
  * KIND, either express or implied.  See the License for the
 18  
  * specific language governing permissions and limitations
 19  
  * under the License.
 20  
  */
 21  
 
 22  
 import org.apache.commons.ognl.enhance.UnsupportedCompilationException;
 23  
 
 24  
 /**
 25  
  * Base class for boolean expressions.
 26  
  * 
 27  
  * @author jkuhnert
 28  
  */
 29  
 public abstract class BooleanExpression
 30  
     extends ExpressionNode
 31  
     implements NodeType
 32  
 {
 33  
 
 34  
     private static final long serialVersionUID = 8630306635724834872L;
 35  
 
 36  
     protected Class<?> getterClass;
 37  
 
 38  
     public BooleanExpression( int id )
 39  
     {
 40  265
         super( id );
 41  265
     }
 42  
 
 43  
     public BooleanExpression( OgnlParser p, int id )
 44  
     {
 45  0
         super( p, id );
 46  0
     }
 47  
 
 48  
     /**
 49  
      * {@inheritDoc}
 50  
      */
 51  
     public Class<?> getGetterClass()
 52  
     {
 53  3
         return getterClass;
 54  
     }
 55  
 
 56  
     /**
 57  
      * {@inheritDoc}
 58  
      */
 59  
     public Class<?> getSetterClass()
 60  
     {
 61  0
         return null;
 62  
     }
 63  
 
 64  
     /**
 65  
      * {@inheritDoc}
 66  
      */
 67  
     @Override
 68  
     public String toGetSourceString( OgnlContext context, Object target )
 69  
     {
 70  
         try
 71  
         {
 72  
 
 73  18
             Object value = getValueBody( context, target );
 74  
 
 75  18
             if ( value != null && Boolean.class.isAssignableFrom( value.getClass() ) )
 76  
             {
 77  18
                 getterClass = Boolean.TYPE;
 78  
             }
 79  0
             else if ( value != null )
 80  
             {
 81  0
                 getterClass = value.getClass();
 82  
             }
 83  
             else
 84  
             {
 85  0
                 getterClass = Boolean.TYPE;
 86  
             }
 87  
 
 88  18
             String ret = super.toGetSourceString( context, target );
 89  
 
 90  18
             if ( "(false)".equals( ret ) )
 91  
             {
 92  6
                 return "false";
 93  
             }
 94  12
             else if ( "(true)".equals( ret ) )
 95  
             {
 96  0
                 return "true";
 97  
             }
 98  12
             return ret;
 99  
 
 100  
         }
 101  0
         catch ( NullPointerException e )
 102  
         {
 103  
 
 104  
             // expected to happen in some instances
 105  0
             e.printStackTrace();
 106  
 
 107  0
             throw new UnsupportedCompilationException( "evaluation resulted in null expression." );
 108  
         }
 109  0
         catch ( Throwable t )
 110  
         {
 111  0
             throw OgnlOps.castToRuntime( t );
 112  
         }
 113  
     }
 114  
 }