Author: grobmeier Date: Sun Oct 16 16:08:24 2011 New Revision: 1184856 URL: http://svn.apache.org/viewvc?rev=1184856&view=rev Log: OGNL-11: fixed checkstyle errors
Modified: commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTCtor.java commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTInstanceof.java commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTList.java commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTMap.java commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTMethod.java commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTOr.java Modified: commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTCtor.java URL: http://svn.apache.org/viewvc/commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTCtor.java?rev=1184856&r1=1184855&r2=1184856&view=diff ============================================================================== --- commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTCtor.java (original) +++ commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTCtor.java Sun Oct 16 16:08:24 2011 @@ -196,8 +196,9 @@ public class ASTCtor } if ( isArray ) + { context.put( "_ctorClass", clazz ); - + } } catch ( Throwable t ) { @@ -264,11 +265,15 @@ public class ASTCtor cast = (String) context.remove( ExpressionCompiler.PRE_CAST ); } if ( cast == null ) + { cast = ""; - + } + if ( !ASTConst.class.isInstance( _children[i] ) ) + { value = cast + value; - + } + values[i] = objValue; expressions[i] = value; types[i] = context.getCurrentType(); @@ -293,16 +298,18 @@ public class ASTCtor } if ( ctor == null ) + { ctor = OgnlRuntime.getConvertedConstructorAndArgs( context, clazz, OgnlRuntime.getConstructors( clazz ), values, new Object[values.length] ); - - if ( ctor == null ) + } + + if ( ctor == null ) + { throw new NoSuchMethodException( - "Unable to find constructor appropriate for arguments in class: " - + clazz ); - + "Unable to find constructor appropriate for arguments in class: " + clazz ); + } ctorParamTypes = ctor.getParameterTypes(); // now loop over child values again and build up the actual source string @@ -321,7 +328,9 @@ public class ASTCtor String literal = OgnlRuntime.getNumericLiteral( types[i] ); if ( literal != null ) + { value += literal; + } } if ( ctorParamTypes[i] != types[i] ) @@ -340,12 +349,17 @@ public class ASTCtor { if ( !types[i].isArray() && types[i].isPrimitive() && !ctorParamTypes[i].isPrimitive() ) + { value = "new " - + ExpressionCompiler.getCastString( OgnlRuntime.getPrimitiveWrapperClass( types[i] ) ) + + ExpressionCompiler.getCastString( + OgnlRuntime.getPrimitiveWrapperClass( types[i] ) ) + "(" + value + ")"; + } else + { value = " ($w) " + value; + } } } Modified: commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTInstanceof.java URL: http://svn.apache.org/viewvc/commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTInstanceof.java?rev=1184856&r1=1184855&r2=1184856&view=diff ============================================================================== --- commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTInstanceof.java (original) +++ commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTInstanceof.java Sun Oct 16 16:08:24 2011 @@ -75,10 +75,13 @@ public class ASTInstanceof String ret = ""; if ( ASTConst.class.isInstance( _children[0] ) ) + { ret = ( (Boolean) getValueBody( context, target ) ).toString(); + } else + { ret = _children[0].toGetSourceString( context, target ) + " instanceof " + targetType; - + } context.setCurrentType( Boolean.TYPE ); return ret; Modified: commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTList.java URL: http://svn.apache.org/viewvc/commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTList.java?rev=1184856&r1=1184855&r2=1184856&view=diff ============================================================================== --- commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTList.java (original) +++ commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTList.java Sun Oct 16 16:08:24 2011 @@ -49,7 +49,9 @@ public class ASTList { List answer = new ArrayList( jjtGetNumChildren() ); for ( int i = 0; i < jjtGetNumChildren(); ++i ) + { answer.add( _children[i].getValue( context, source ) ); + } return answer; } @@ -95,8 +97,9 @@ public class ASTList if ( !array ) { if ( jjtGetNumChildren() < 1 ) + { return "java.util.Arrays.asList( new Object[0])"; - + } result += "java.util.Arrays.asList( new Object[] "; } @@ -133,31 +136,37 @@ public class ASTList cast = (String) context.remove( ExpressionCompiler.PRE_CAST ); } if ( cast == null ) + { cast = ""; - + } + if ( !ASTConst.class.isInstance( _children[i] ) ) + { value = cast + value; - + } Class ctorClass = (Class) context.get( "_ctorClass" ); if ( array && ctorClass != null && !ctorClass.isPrimitive() ) { Class valueClass = value != null ? value.getClass() : null; if ( NodeType.class.isAssignableFrom( _children[i].getClass() ) ) + { valueClass = ( (NodeType) _children[i] ).getGetterClass(); - + } if ( valueClass != null && ctorClass.isArray() ) { value = - OgnlRuntime.getCompiler().createLocalReference( context, - "(" - + ExpressionCompiler.getCastString( ctorClass ) - + ")org.apache.commons.ognl.OgnlOps.toArray(" - + value - + ", " - + ctorClass.getComponentType().getName() - + ".class, true)", ctorClass ); + OgnlRuntime + .getCompiler() + .createLocalReference( context, + "(" + + ExpressionCompiler.getCastString( ctorClass ) + + ")org.apache.commons.ognl.OgnlOps.toArray(" + + value + + ", " + + ctorClass.getComponentType().getName() + + ".class, true)", ctorClass ); } else if ( ctorClass.isPrimitive() ) @@ -166,32 +175,37 @@ public class ASTList Class wrapClass = OgnlRuntime.getPrimitiveWrapperClass( ctorClass ); value = - OgnlRuntime.getCompiler().createLocalReference( context, - "((" - + wrapClass.getName() - + ")org.apache.commons.ognl.OgnlOps.convertValue(" - + value - + "," - + wrapClass.getName() - + ".class, true))." - + OgnlRuntime.getNumericValueGetter( wrapClass ), - ctorClass ); - + OgnlRuntime + .getCompiler() + .createLocalReference( context, + "((" + + wrapClass.getName() + + ")org.apache.commons.ognl.OgnlOps.convertValue(" + + value + + "," + + wrapClass.getName() + + ".class, true))." + + OgnlRuntime.getNumericValueGetter( wrapClass ), + ctorClass ); } else if ( ctorClass != Object.class ) { value = - OgnlRuntime.getCompiler().createLocalReference( context, - "(" - + ctorClass.getName() - + ")org.apache.commons.ognl.OgnlOps.convertValue(" - + value + "," + ctorClass.getName() - + ".class)", ctorClass ); + OgnlRuntime + .getCompiler() + .createLocalReference( + context, + "(" + + ctorClass.getName() + + ")org.apache.commons.ognl.OgnlOps.convertValue(" + + value + "," + ctorClass.getName() + + ".class)", ctorClass ); } else if ( ( NodeType.class.isInstance( _children[i] ) - && ( (NodeType) _children[i] ).getGetterClass() != null && Number.class.isAssignableFrom( ( (NodeType) _children[i] ).getGetterClass() ) ) + && ( (NodeType) _children[i] ).getGetterClass() != null + && Number.class.isAssignableFrom( ( (NodeType) _children[i] ).getGetterClass() ) ) || valueClass.isPrimitive() ) { @@ -210,8 +224,9 @@ public class ASTList } if ( objValue == null || value.length() <= 0 ) + { value = "null"; - + } result += value; } @@ -227,8 +242,9 @@ public class ASTList result += "}"; if ( !array ) + { result += ")"; - + } return result; } Modified: commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTMap.java URL: http://svn.apache.org/viewvc/commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTMap.java?rev=1184856&r1=1184855&r2=1184856&view=diff ============================================================================== --- commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTMap.java (original) +++ commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTMap.java Sun Oct 16 16:08:24 2011 @@ -33,7 +33,7 @@ class ASTMap extends SimpleNode { - private static Class DEFAULT_MAP_CLASS; + private static Class defaultMapClass; private String className; @@ -42,11 +42,11 @@ class ASTMap /* Try to get LinkedHashMap; if older JDK than 1.4 use HashMap */ try { - DEFAULT_MAP_CLASS = Class.forName( "java.util.LinkedHashMap" ); + defaultMapClass = Class.forName( "java.util.LinkedHashMap" ); } catch ( ClassNotFoundException ex ) { - DEFAULT_MAP_CLASS = HashMap.class; + defaultMapClass = HashMap.class; } } @@ -74,12 +74,12 @@ class ASTMap { try { - answer = (Map) DEFAULT_MAP_CLASS.newInstance(); + answer = (Map) defaultMapClass.newInstance(); } catch ( Exception ex ) { /* This should never happen */ - throw new OgnlException( "Default Map class '" + DEFAULT_MAP_CLASS.getName() + "' instantiation error", + throw new OgnlException( "Default Map class '" + defaultMapClass.getName() + "' instantiation error", ex ); } } Modified: commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTMethod.java URL: http://svn.apache.org/viewvc/commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTMethod.java?rev=1184856&r1=1184855&r2=1184856&view=diff ============================================================================== --- commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTMethod.java (original) +++ commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTMethod.java Sun Oct 16 16:08:24 2011 @@ -66,13 +66,13 @@ public class ASTMethod implements OrderedReturn, NodeType { - private String _methodName; + private String methodName; - private String _lastExpression; + private String lastExpression; - private String _coreExpression; + private String coreExpression; - private Class _getterClass; + private Class getterClass; public ASTMethod( int id ) { @@ -84,18 +84,22 @@ public class ASTMethod super( p, id ); } - /** Called from parser action. */ + /** + * Called from parser action. + * @param methodName sets the name of the method + */ public void setMethodName( String methodName ) { - _methodName = methodName; + this.methodName = methodName; } /** * Returns the method name that this node will call. + * @return the method name */ public String getMethodName() { - return _methodName; + return methodName; } protected Object getValueBody( OgnlContext context, Object source ) @@ -112,12 +116,12 @@ public class ASTMethod args[i] = _children[i].getValue( context, root ); } - result = OgnlRuntime.callMethod( context, source, _methodName, args ); + result = OgnlRuntime.callMethod( context, source, methodName, args ); if ( result == null ) { NullHandler nh = OgnlRuntime.getNullHandler( OgnlRuntime.getTargetClass( source ) ); - result = nh.nullMethodResult( context, source, _methodName, args ); + result = nh.nullMethodResult( context, source, methodName, args ); } return result; @@ -131,27 +135,27 @@ public class ASTMethod public String getLastExpression() { - return _lastExpression; + return lastExpression; } public String getCoreExpression() { - return _coreExpression; + return coreExpression; } public Class getGetterClass() { - return _getterClass; + return getterClass; } public Class getSetterClass() { - return _getterClass; + return getterClass; } public String toString() { - StringBuilder result = new StringBuilder( _methodName ); + StringBuilder result = new StringBuilder( methodName ); result.append( "(" ); if ( ( _children != null ) && ( _children.length > 0 ) ) @@ -175,12 +179,14 @@ public class ASTMethod public String toGetSourceString( OgnlContext context, Object target ) { /* - * System.out.println("methodName is " + _methodName + " for target " + target + " target class: " + (target != + * System.out.println("methodName is " + methodName + " for target " + target + " target class: " + (target != * null ? target.getClass() : null) + " current type: " + context.getCurrentType()); */ - if ( target == null ) + if ( target == null ) + { throw new UnsupportedCompilationException( "Target object is null." ); - + } + String post = ""; String result = null; Method m = null; @@ -191,33 +197,36 @@ public class ASTMethod m = OgnlRuntime.getMethod( context, context.getCurrentType() != null ? context.getCurrentType() : target.getClass(), - _methodName, _children, false ); - if ( m == null ) - m = - OgnlRuntime.getReadMethod( target.getClass(), _methodName, _children != null ? _children.length - : -1 ); - + methodName, _children, false ); + if ( m == null ) + { + m = OgnlRuntime + .getReadMethod( target.getClass(), methodName, _children != null ? _children.length : -1 ); + } + if ( m == null ) { m = - OgnlRuntime.getWriteMethod( target.getClass(), _methodName, _children != null ? _children.length + OgnlRuntime.getWriteMethod( target.getClass(), methodName, _children != null ? _children.length : -1 ); if ( m != null ) { context.setCurrentType( m.getReturnType() ); - context.setCurrentAccessor( OgnlRuntime.getCompiler().getSuperOrInterfaceClass( m, - m.getDeclaringClass() ) ); + context.setCurrentAccessor( + OgnlRuntime.getCompiler().getSuperOrInterfaceClass( m, m.getDeclaringClass() ) ); - _coreExpression = toSetSourceString( context, target ); - if ( _coreExpression == null || _coreExpression.length() < 1 ) + coreExpression = toSetSourceString( context, target ); + if ( coreExpression == null || coreExpression.length() < 1 ) + { throw new UnsupportedCompilationException( "can't find suitable getter method" ); + } + + coreExpression += ";"; + lastExpression = "null"; - _coreExpression += ";"; - _lastExpression = "null"; - - return _coreExpression; + return coreExpression; } return ""; @@ -225,7 +234,7 @@ public class ASTMethod else { - _getterClass = m.getReturnType(); + getterClass = m.getReturnType(); } // TODO: This is a hacky workaround until javassist supports varargs method invocations @@ -234,7 +243,8 @@ public class ASTMethod if ( varArgs ) { - throw new UnsupportedCompilationException( "Javassist does not currently support varargs method calls" ); + throw new UnsupportedCompilationException( + "Javassist does not currently support varargs method calls" ); } result = "." + m.getName() + "("; @@ -244,7 +254,7 @@ public class ASTMethod Class[] parms = m.getParameterTypes(); String prevCast = (String) context.remove( ExpressionCompiler.PRE_CAST ); /* - * System.out.println("before children methodName is " + _methodName + " for target " + target + + * System.out.println("before children methodName is " + methodName + " for target " + target + * " target class: " + (target != null ? target.getClass() : null) + " current type: " + * context.getCurrentType() + " and previous type: " + context.getPreviousType()); */ @@ -267,8 +277,9 @@ public class ASTMethod String parmString = _children[i].toGetSourceString( context, context.getRoot() ); if ( parmString == null || parmString.trim().length() < 1 ) + { parmString = "null"; - + } // to undo type setting of constants when used as method parameters if ( ASTConst.class.isInstance( _children[i] ) ) { @@ -284,29 +295,37 @@ public class ASTMethod cast = (String) context.remove( ExpressionCompiler.PRE_CAST ); } if ( cast == null ) + { cast = ""; - + } + if ( !ASTConst.class.isInstance( _children[i] ) ) + { parmString = cast + parmString; - + } + Class valueClass = value != null ? value.getClass() : null; if ( NodeType.class.isAssignableFrom( _children[i].getClass() ) ) + { valueClass = ( (NodeType) _children[i] ).getGetterClass(); - + } + if ( ( !varArgs || varArgs && ( i + 1 ) < parms.length ) && valueClass != parms[i] ) { if ( parms[i].isArray() ) { parmString = - OgnlRuntime.getCompiler().createLocalReference( context, - "(" - + ExpressionCompiler.getCastString( parms[i] ) - + ")org.apache.commons.ognl.OgnlOps#toArray(" - + parmString - + ", " - + parms[i].getComponentType().getName() - + ".class, true)", parms[i] ); + OgnlRuntime + .getCompiler() + .createLocalReference( context, + "(" + + ExpressionCompiler.getCastString( parms[i] ) + + ")org.apache.commons.ognl.OgnlOps#toArray(" + + parmString + + ", " + + parms[i].getComponentType().getName() + + ".class, true)", parms[i] ); } else if ( parms[i].isPrimitive() ) @@ -315,31 +334,36 @@ public class ASTMethod Class wrapClass = OgnlRuntime.getPrimitiveWrapperClass( parms[i] ); parmString = - OgnlRuntime.getCompiler().createLocalReference( context, - "((" - + wrapClass.getName() - + ")org.apache.commons.ognl.OgnlOps#convertValue(" - + parmString - + "," - + wrapClass.getName() - + ".class, true))." - + OgnlRuntime.getNumericValueGetter( wrapClass ), - parms[i] ); + OgnlRuntime + .getCompiler() + .createLocalReference( context, + "((" + + wrapClass.getName() + + ")org.apache.commons.ognl.OgnlOps#convertValue(" + + parmString + + "," + + wrapClass.getName() + + ".class, true))." + + OgnlRuntime.getNumericValueGetter( wrapClass ), + parms[i] ); } else if ( parms[i] != Object.class ) { parmString = - OgnlRuntime.getCompiler().createLocalReference( context, - "(" - + parms[i].getName() - + ")org.apache.commons.ognl.OgnlOps#convertValue(" - + parmString + "," - + parms[i].getName() + ".class)", - parms[i] ); + OgnlRuntime + .getCompiler() + .createLocalReference( context, + "(" + + parms[i].getName() + + ")org.apache.commons.ognl.OgnlOps#convertValue(" + + parmString + "," + + parms[i].getName() + ".class)", + parms[i] ); } else if ( ( NodeType.class.isInstance( _children[i] ) - && ( (NodeType) _children[i] ).getGetterClass() != null && Number.class.isAssignableFrom( ( (NodeType) _children[i] ).getGetterClass() ) ) + && ( (NodeType) _children[i] ).getGetterClass() != null + && Number.class.isAssignableFrom( ( (NodeType) _children[i] ).getGetterClass() ) ) || ( valueClass != null && valueClass.isPrimitive() ) ) { parmString = " ($w) " + parmString; @@ -379,8 +403,8 @@ public class ASTMethod if ( m.getReturnType() == void.class ) { - _coreExpression = result + ";"; - _lastExpression = "null"; + coreExpression = result + ";"; + lastExpression = "null"; } context.setCurrentType( m.getReturnType() ); @@ -397,11 +421,11 @@ public class ASTMethod */ Method m = OgnlRuntime.getWriteMethod( context.getCurrentType() != null ? context.getCurrentType() : target.getClass(), - _methodName, _children != null ? _children.length : -1 ); + methodName, _children != null ? _children.length : -1 ); if ( m == null ) { throw new UnsupportedCompilationException( "Unable to determine setter method generation for " - + _methodName ); + + methodName ); } String post = ""; @@ -414,7 +438,7 @@ public class ASTMethod ExpressionCompiler.addCastString( context, "new " + wrapper.getName() + "(" ); post = ")"; - _getterClass = wrapper; + getterClass = wrapper; } boolean varArgs = OgnlRuntime.isJdk15() && m.isVarArgs(); @@ -454,16 +478,19 @@ public class ASTMethod String parmString = _children[i].toSetSourceString( context, context.getRoot() ); if ( context.getCurrentType() == Void.TYPE || context.getCurrentType() == void.class ) + { throw new UnsupportedCompilationException( "Method argument can't be a void type." ); - + } + if ( parmString == null || parmString.trim().length() < 1 ) { if ( ASTProperty.class.isInstance( _children[i] ) || ASTMethod.class.isInstance( _children[i] ) || ASTStaticMethod.class.isInstance( _children[i] ) || ASTChain.class.isInstance( _children[i] ) ) + { throw new UnsupportedCompilationException( - "ASTMethod setter child returned null from a sub property expression." ); - + "ASTMethod setter child returned null from a sub property expression." ); + } parmString = "null"; } @@ -483,27 +510,33 @@ public class ASTMethod } if ( cast == null ) + { cast = ""; - + } + parmString = cast + parmString; Class valueClass = value != null ? value.getClass() : null; if ( NodeType.class.isAssignableFrom( _children[i].getClass() ) ) + { valueClass = ( (NodeType) _children[i] ).getGetterClass(); - + } + if ( valueClass != parms[i] ) { if ( parms[i].isArray() ) { parmString = - OgnlRuntime.getCompiler().createLocalReference( context, - "(" - + ExpressionCompiler.getCastString( parms[i] ) - + ")org.apache.commons.ognl.OgnlOps#toArray(" - + parmString - + ", " - + parms[i].getComponentType().getName() - + ".class)", parms[i] ); + OgnlRuntime + .getCompiler() + .createLocalReference( context, + "(" + + ExpressionCompiler.getCastString( parms[i] ) + + ")org.apache.commons.ognl.OgnlOps#toArray(" + + parmString + + ", " + + parms[i].getComponentType().getName() + + ".class)", parms[i] ); } else if ( parms[i].isPrimitive() ) @@ -511,32 +544,37 @@ public class ASTMethod Class wrapClass = OgnlRuntime.getPrimitiveWrapperClass( parms[i] ); parmString = - OgnlRuntime.getCompiler().createLocalReference( context, - "((" - + wrapClass.getName() - + ")org.apache.commons.ognl.OgnlOps#convertValue(" - + parmString - + "," - + wrapClass.getName() - + ".class, true))." - + OgnlRuntime.getNumericValueGetter( wrapClass ), - parms[i] ); + OgnlRuntime + .getCompiler() + .createLocalReference( context, + "((" + + wrapClass.getName() + + ")org.apache.commons.ognl.OgnlOps#convertValue(" + + parmString + + "," + + wrapClass.getName() + + ".class, true))." + + OgnlRuntime.getNumericValueGetter( wrapClass ), + parms[i] ); } else if ( parms[i] != Object.class ) { parmString = - OgnlRuntime.getCompiler().createLocalReference( context, - "(" - + parms[i].getName() - + ")org.apache.commons.ognl.OgnlOps#convertValue(" - + parmString + "," - + parms[i].getName() + ".class)", - parms[i] ); + OgnlRuntime + .getCompiler() + .createLocalReference( context, + "(" + + parms[i].getName() + + ")org.apache.commons.ognl.OgnlOps#convertValue(" + + parmString + "," + + parms[i].getName() + ".class)", + parms[i] ); } else if ( ( NodeType.class.isInstance( _children[i] ) - && ( (NodeType) _children[i] ).getGetterClass() != null && Number.class.isAssignableFrom( ( (NodeType) _children[i] ).getGetterClass() ) ) + && ( (NodeType) _children[i] ).getGetterClass() != null + && Number.class.isAssignableFrom( ( (NodeType) _children[i] ).getGetterClass() ) ) || ( valueClass != null && valueClass.isPrimitive() ) ) { parmString = " ($w) " + parmString; Modified: commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTOr.java URL: http://svn.apache.org/viewvc/commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTOr.java?rev=1184856&r1=1184855&r2=1184856&view=diff ============================================================================== --- commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTOr.java (original) +++ commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ASTOr.java Sun Oct 16 16:08:24 2011 @@ -54,7 +54,9 @@ public class ASTOr { result = _children[i].getValue( context, source ); if ( i != last && OgnlOps.booleanValue( result ) ) + { break; + } } return result; } @@ -67,7 +69,9 @@ public class ASTOr { Object v = _children[i].getValue( context, target ); if ( OgnlOps.booleanValue( v ) ) + { return; + } } _children[last].setValue( context, target, value ); } @@ -85,8 +89,10 @@ public class ASTOr public String toGetSourceString( OgnlContext context, Object target ) { if ( _children.length != 2 ) + { throw new UnsupportedCompilationException( "Can only compile boolean expressions with two children." ); - + } + String result = "("; try @@ -94,14 +100,18 @@ public class ASTOr String first = OgnlRuntime.getChildSource( context, target, _children[0] ); if ( !OgnlRuntime.isBoolean( first ) ) + { first = OgnlRuntime.getCompiler().createLocalReference( context, first, context.getCurrentType() ); - + } + Class firstType = context.getCurrentType(); String second = OgnlRuntime.getChildSource( context, target, _children[1] ); if ( !OgnlRuntime.isBoolean( second ) ) + { second = OgnlRuntime.getCompiler().createLocalReference( context, second, context.getCurrentType() ); - + } + Class secondType = context.getCurrentType(); boolean mismatched = @@ -135,12 +145,16 @@ public class ASTOr public String toSetSourceString( OgnlContext context, Object target ) { if ( _children.length != 2 ) + { throw new UnsupportedCompilationException( "Can only compile boolean expressions with two children." ); - + } + String pre = (String) context.get( "_currentChain" ); if ( pre == null ) + { pre = ""; - + } + String result = ""; try @@ -152,16 +166,18 @@ public class ASTOr ExpressionCompiler.getRootExpression( _children[0], context.getRoot(), context ) + pre + _children[0].toGetSourceString( context, target ); if ( !OgnlRuntime.isBoolean( first ) ) + { first = OgnlRuntime.getCompiler().createLocalReference( context, first, Object.class ); - + } _children[1].getValue( context, target ); String second = ExpressionCompiler.getRootExpression( _children[1], context.getRoot(), context ) + pre + _children[1].toSetSourceString( context, target ); if ( !OgnlRuntime.isBoolean( second ) ) + { second = OgnlRuntime.getCompiler().createLocalReference( context, second, context.getCurrentType() ); - + } result += "org.apache.commons.ognl.OgnlOps.booleanValue(" + first + ")"; result += " ? ";