Skip to content
Permalink
Browse files
Raise embedded if into parent if.
  • Loading branch information
garydgregory committed Feb 28, 2021
1 parent 694464f commit b33a4a6ce5ad48964d0e7a7fb9cb013b1062e97d
Showing 2 changed files with 114 additions and 133 deletions.
@@ -75,71 +75,68 @@ protected Object getValueBody( OgnlContext context, Object source )
{
boolean handled = false;

if ( i < ilast )
if ( (i < ilast) && (children[i] instanceof ASTProperty) )
{
if ( children[i] instanceof ASTProperty )
ASTProperty propertyNode = (ASTProperty) children[i];
int indexType = propertyNode.getIndexedPropertyType( context, result );

if ( ( indexType != OgnlRuntime.INDEXED_PROPERTY_NONE )
&& ( children[i + 1] instanceof ASTProperty ) )
{
ASTProperty propertyNode = (ASTProperty) children[i];
int indexType = propertyNode.getIndexedPropertyType( context, result );
ASTProperty indexNode = (ASTProperty) children[i + 1];

if ( ( indexType != OgnlRuntime.INDEXED_PROPERTY_NONE )
&& ( children[i + 1] instanceof ASTProperty ) )
if ( indexNode.isIndexedAccess() )
{
ASTProperty indexNode = (ASTProperty) children[i + 1];
Object index = indexNode.getProperty( context, result );

if ( indexNode.isIndexedAccess() )
if ( index instanceof DynamicSubscript )
{
Object index = indexNode.getProperty( context, result );

if ( index instanceof DynamicSubscript )
if ( indexType == OgnlRuntime.INDEXED_PROPERTY_INT )
{
if ( indexType == OgnlRuntime.INDEXED_PROPERTY_INT )
{
Object array = propertyNode.getValue( context, result );
int len = Array.getLength( array );

switch ( ( (DynamicSubscript) index ).getFlag() )
{
case DynamicSubscript.ALL:
result = Array.newInstance( array.getClass().getComponentType(), len );
System.arraycopy( array, 0, result, 0, len );
handled = true;
i++;
break;
case DynamicSubscript.FIRST:
index = ( len > 0 ) ? 0 : -1;
break;
case DynamicSubscript.MID:
index = ( len > 0 ) ? ( len / 2 ) : -1;
break;
case DynamicSubscript.LAST:
index = ( len > 0 ) ? ( len - 1 ) : -1;
break;
default:
break;
}
}
else
Object array = propertyNode.getValue( context, result );
int len = Array.getLength( array );

switch ( ( (DynamicSubscript) index ).getFlag() )
{
if ( indexType == OgnlRuntime.INDEXED_PROPERTY_OBJECT )
{
throw new OgnlException( "DynamicSubscript '" + indexNode
+ "' not allowed for object indexed property '" + propertyNode + "'" );
}
case DynamicSubscript.ALL:
result = Array.newInstance( array.getClass().getComponentType(), len );
System.arraycopy( array, 0, result, 0, len );
handled = true;
i++;
break;
case DynamicSubscript.FIRST:
index = ( len > 0 ) ? 0 : -1;
break;
case DynamicSubscript.MID:
index = ( len > 0 ) ? ( len / 2 ) : -1;
break;
case DynamicSubscript.LAST:
index = ( len > 0 ) ? ( len - 1 ) : -1;
break;
default:
break;
}
}
if ( !handled )
else
{
result =
OgnlRuntime.getIndexedProperty(
context,
result,
propertyNode.getProperty( context, result ).toString(),
index );
handled = true;
i++;
if ( indexType == OgnlRuntime.INDEXED_PROPERTY_OBJECT )
{
throw new OgnlException( "DynamicSubscript '" + indexNode
+ "' not allowed for object indexed property '" + propertyNode + "'" );
}
}
}
if ( !handled )
{
result =
OgnlRuntime.getIndexedProperty(
context,
result,
propertyNode.getProperty( context, result ).toString(),
index );
handled = true;
i++;
}
}
}
}
@@ -158,78 +155,75 @@ protected void setValueBody( OgnlContext context, Object target, Object value )

for ( int i = 0, ilast = children.length - 2; i <= ilast; ++i )
{
if ( i <= ilast )
if ( (i <= ilast) && (children[i] instanceof ASTProperty) )
{
if ( children[i] instanceof ASTProperty )
ASTProperty propertyNode = (ASTProperty) children[i];
int indexType = propertyNode.getIndexedPropertyType( context, target );

if ( ( indexType != OgnlRuntime.INDEXED_PROPERTY_NONE )
&& ( children[i + 1] instanceof ASTProperty ) )
{
ASTProperty propertyNode = (ASTProperty) children[i];
int indexType = propertyNode.getIndexedPropertyType( context, target );
ASTProperty indexNode = (ASTProperty) children[i + 1];

if ( ( indexType != OgnlRuntime.INDEXED_PROPERTY_NONE )
&& ( children[i + 1] instanceof ASTProperty ) )
if ( indexNode.isIndexedAccess() )
{
ASTProperty indexNode = (ASTProperty) children[i + 1];
Object index = indexNode.getProperty( context, target );

if ( indexNode.isIndexedAccess() )
if ( index instanceof DynamicSubscript )
{
Object index = indexNode.getProperty( context, target );

if ( index instanceof DynamicSubscript )
if ( indexType == OgnlRuntime.INDEXED_PROPERTY_INT )
{
if ( indexType == OgnlRuntime.INDEXED_PROPERTY_INT )
{
Object array = propertyNode.getValue( context, target );
int len = Array.getLength( array );

switch ( ( (DynamicSubscript) index ).getFlag() )
{
case DynamicSubscript.ALL:
System.arraycopy( target, 0, value, 0, len );
handled = true;
i++;
break;
case DynamicSubscript.FIRST:
index = ( len > 0 ) ? 0 : -1;
break;
case DynamicSubscript.MID:
index = ( len > 0 ) ? ( len / 2 ) : -1;
break;
case DynamicSubscript.LAST:
index = ( len > 0 ) ? ( len - 1 ) : -1;
break;
default:
break;
}
}
else
Object array = propertyNode.getValue( context, target );
int len = Array.getLength( array );

switch ( ( (DynamicSubscript) index ).getFlag() )
{
if ( indexType == OgnlRuntime.INDEXED_PROPERTY_OBJECT )
{
throw new OgnlException( "DynamicSubscript '" + indexNode
+ "' not allowed for object indexed property '" + propertyNode + "'" );
}
case DynamicSubscript.ALL:
System.arraycopy( target, 0, value, 0, len );
handled = true;
i++;
break;
case DynamicSubscript.FIRST:
index = ( len > 0 ) ? 0 : -1;
break;
case DynamicSubscript.MID:
index = ( len > 0 ) ? ( len / 2 ) : -1;
break;
case DynamicSubscript.LAST:
index = ( len > 0 ) ? ( len - 1 ) : -1;
break;
default:
break;
}
}
if ( !handled && i == ilast )
else
{
OgnlRuntime.setIndexedProperty( context, target,
propertyNode.getProperty( context, target ).toString(),
index, value );
handled = true;
i++;
}
else if ( !handled )
{
target =
OgnlRuntime.getIndexedProperty(
context,
target,
propertyNode.getProperty( context, target ).toString(),
index );
i++;
continue;
if ( indexType == OgnlRuntime.INDEXED_PROPERTY_OBJECT )
{
throw new OgnlException( "DynamicSubscript '" + indexNode
+ "' not allowed for object indexed property '" + propertyNode + "'" );
}
}
}
if ( !handled && i == ilast )
{
OgnlRuntime.setIndexedProperty( context, target,
propertyNode.getProperty( context, target ).toString(),
index, value );
handled = true;
i++;
}
else if ( !handled )
{
target =
OgnlRuntime.getIndexedProperty(
context,
target,
propertyNode.getProperty( context, target ).toString(),
index );
i++;
continue;
}
}
}
}
@@ -1065,12 +1065,9 @@ public static Object getMethodValue( OgnlContext context, Object target, String
method = getReadMethod( targetClass, propertyName, 0 );
}

if ( checkAccessAndExistence )
if ( checkAccessAndExistence && (( method == null ) || !context.getMemberAccess().isAccessible( context, target, method, propertyName )) )
{
if ( ( method == null ) || !context.getMemberAccess().isAccessible( context, target, method, propertyName ) )
{
methodValue = NotFound;
}
methodValue = NotFound;
}
if ( methodValue == null )
{
@@ -1106,12 +1103,9 @@ public static boolean setMethodValue( OgnlContext context, Object target, String
boolean result = true;
Method method = getSetMethod( context, ( target == null ) ? null : target.getClass(), propertyName );

if ( checkAccessAndExistence )
if ( checkAccessAndExistence && (( method == null ) || !context.getMemberAccess().isAccessible( context, target, method, propertyName )) )
{
if ( ( method == null ) || !context.getMemberAccess().isAccessible( context, target, method, propertyName ) )
{
result = false;
}
result = false;
}

if ( result )
@@ -1195,12 +1189,9 @@ public static Object getFieldValue( OgnlContext context, Object target, String p
Class<?> targetClass = target == null ? null : target.getClass();
Field field = getField( targetClass, propertyName );

if ( checkAccessAndExistence )
if ( checkAccessAndExistence && (( field == null ) || !context.getMemberAccess().isAccessible( context, target, field, propertyName )) )
{
if ( ( field == null ) || !context.getMemberAccess().isAccessible( context, target, field, propertyName ) )
{
result = NotFound;
}
result = NotFound;
}
if ( result == null )
{
@@ -1908,14 +1899,10 @@ else if ( method == null || ( method.getParameterTypes().length > methodParamLen
if ( numParms > 0 && methodDescriptor.getMethod().getParameterTypes().length == numParms )
{
return methodDescriptor.getMethod();
}
else if ( numParms < 0 )
} else if ( (numParms < 0) && (method == null || ( method.getParameterTypes().length
> methodDescriptor.getMethod().getParameterTypes().length )) )
{
if ( method == null || ( method.getParameterTypes().length
> methodDescriptor.getMethod().getParameterTypes().length ) )
{
method = methodDescriptor.getMethod();
}
method = methodDescriptor.getMethod();
}
}
}

0 comments on commit b33a4a6

Please sign in to comment.