Skip to content
Permalink
Browse files
Remove redundant calls of java.lang.Class methods. Replaced with obje…
…ct instanceof.
  • Loading branch information
arturobernalg committed Jun 21, 2021
1 parent 4bc4802 commit c901ba54b752e471f67e66fc5c2867473d4932eb
Showing 25 changed files with 129 additions and 133 deletions.
@@ -159,7 +159,7 @@ public String toGetSourceString( OgnlContext context, Object target )
{
aChildren.toGetSourceString( context, target );

if ( NodeType.class.isInstance( aChildren ) && ( (NodeType) aChildren ).getGetterClass() != null
if ( aChildren instanceof NodeType && ( (NodeType) aChildren ).getGetterClass() != null
&& isWider( (NodeType) aChildren, lastType ) )
{
lastType = (NodeType) aChildren;
@@ -189,7 +189,7 @@ && isWider( (NodeType) aChildren, lastType ) )
String expr = children[i].toGetSourceString( context, target );

if ( ( "null".equals( expr ) )
|| ( !ASTConst.class.isInstance( children[i] )
|| ( !(children[i] instanceof ASTConst)
&& ( expr == null || expr.trim().isEmpty() ) ) )
{
expr = "null";
@@ -198,12 +198,12 @@ && isWider( (NodeType) aChildren, lastType ) )
// System.out.println("astadd child class: " + _children[i].getClass().getName() +
// " and return expr: " + expr);

if ( ASTProperty.class.isInstance( children[i] ) )
if (children[i] instanceof ASTProperty)
{
expr = ExpressionCompiler.getRootExpression( children[i], context.getRoot(), context ) + expr;
context.setCurrentAccessor( context.getRoot().getClass() );
}
else if ( ASTMethod.class.isInstance( children[i] ) )
else if (children[i] instanceof ASTMethod)
{
String chain = (String) context.get( "_currentChain" );
String rootExpr =
@@ -222,17 +222,17 @@ else if ( ASTMethod.class.isInstance( children[i] ) )
context.setCurrentAccessor( context.getRoot().getClass() );

}
else if ( ExpressionNode.class.isInstance( children[i] ) )
else if (children[i] instanceof ExpressionNode)
{
expr = "(" + expr + ")";
}
else if ( ( parent == null || !ASTChain.class.isInstance( parent ) )
&& ASTChain.class.isInstance( children[i] ) )
else if ( ( parent == null || !(parent instanceof ASTChain))
&& children[i] instanceof ASTChain)
{
String rootExpr =
ExpressionCompiler.getRootExpression( children[i], context.getRoot(), context );

if ( !ASTProperty.class.isInstance( children[i].jjtGetChild( 0 ) ) && rootExpr.endsWith( ")" )
if ( !(children[i].jjtGetChild(0) instanceof ASTProperty) && rootExpr.endsWith( ")" )
&& expr.startsWith( ")" ) )
{
expr = expr.substring( 1 );
@@ -253,7 +253,7 @@ else if ( ( parent == null || !ASTChain.class.isInstance( parent ) )
// turn quoted characters into quoted strings

if ( context.getCurrentType() != null && context.getCurrentType() == Character.class
&& ASTConst.class.isInstance( children[i] ) )
&& children[i] instanceof ASTConst)
{
expr = expr.replace( "'", "\"" );
context.setCurrentType( String.class );
@@ -262,14 +262,14 @@ else if ( ( parent == null || !ASTChain.class.isInstance( parent ) )
{

if ( !ASTVarRef.class.isAssignableFrom( children[i].getClass() )
&& !ASTProperty.class.isInstance( children[i] )
&& !ASTMethod.class.isInstance( children[i] )
&& !ASTSequence.class.isInstance( children[i] )
&& !ASTChain.class.isInstance( children[i] )
&& !(children[i] instanceof ASTProperty)
&& !(children[i] instanceof ASTMethod)
&& !(children[i] instanceof ASTSequence)
&& !(children[i] instanceof ASTChain)
&& !NumericExpression.class.isAssignableFrom( children[i].getClass() )
&& !ASTStaticField.class.isInstance( children[i] )
&& !ASTStaticMethod.class.isInstance( children[i] )
&& !ASTTest.class.isInstance( children[i] ) )
&& !(children[i] instanceof ASTStaticField)
&& !(children[i] instanceof ASTStaticMethod)
&& !(children[i] instanceof ASTTest))
{
if ( lastType != null && String.class.isAssignableFrom( lastType.getGetterClass() ) )
{
@@ -292,11 +292,11 @@ else if ( ( parent == null || !ASTChain.class.isInstance( parent ) )
{
if ( context.getCurrentType() != null
&& Number.class.isAssignableFrom( context.getCurrentType() )
&& !ASTMethod.class.isInstance( children[i] ) )
&& !(children[i] instanceof ASTMethod))
{
if ( ASTVarRef.class.isInstance( children[i] )
|| ASTProperty.class.isInstance( children[i] )
|| ASTChain.class.isInstance( children[i] ) )
if ( children[i] instanceof ASTVarRef
|| children[i] instanceof ASTProperty
|| children[i] instanceof ASTChain)
{
result.append(".");
}
@@ -53,7 +53,7 @@ public String toGetSourceString( OgnlContext context, Object target )
String first = children[0].toGetSourceString( context, target );
String second = "";

if ( ASTProperty.class.isInstance( children[1] ) )
if (children[1] instanceof ASTProperty)
{
second += "((" + OgnlRuntime.getCompiler( context ).getClassName( target.getClass() ) + ")$2).";
}
@@ -79,8 +79,8 @@ public String toGetSourceString( OgnlContext context, Object target )
Object.class );
}

if ( NodeType.class.isInstance( children[1] ) && !ASTProperty.class.isInstance( children[1] )
&& ( (NodeType) children[1] ).getGetterClass() != null && !OrderedReturn.class.isInstance( children[1] ) )
if ( children[1] instanceof NodeType && !(children[1] instanceof ASTProperty)
&& ( (NodeType) children[1] ).getGetterClass() != null && !(children[1] instanceof OrderedReturn))
{

second = "new " + ( (NodeType) children[1] ).getGetterClass().getName() + "(" + second + ")";
@@ -113,7 +113,7 @@ public String toSetSourceString( OgnlContext context, Object target )

result += children[0].toSetSourceString( context, target );

if ( ASTProperty.class.isInstance( children[1] ) )
if (children[1] instanceof ASTProperty)
{
result += "((" + OgnlRuntime.getCompiler( context ).getClassName( target.getClass() ) + ")$2).";
}
@@ -133,7 +133,7 @@ public String toSetSourceString( OgnlContext context, Object target )
value = seq.getLastExpression();
}

if ( NodeType.class.isInstance( children[1] ) && !ASTProperty.class.isInstance( children[1] )
if ( children[1] instanceof NodeType && !(children[1] instanceof ASTProperty)
&& ( (NodeType) children[1] ).getGetterClass() != null )
{

@@ -45,7 +45,7 @@ public String toGetSourceString( OgnlContext context, Object target )
{
String source = children[0].toGetSourceString( context, target );

if ( !ASTBitNegate.class.isInstance( children[0] ) )
if ( !(children[0] instanceof ASTBitNegate))
{
return "~(" + super.coerceToNumeric( source, context, children[0] ) + ")";
}
@@ -295,22 +295,22 @@ public String toGetSourceString( OgnlContext context, Object target )

// System.out.println("astchain child returned >> " + value + " <<");

if ( ASTCtor.class.isInstance( child ) )
if (child instanceof ASTCtor)
{
constructor = true;
}

if ( NodeType.class.isInstance( child ) && ( (NodeType) child ).getGetterClass() != null )
if ( child instanceof NodeType && ( (NodeType) child ).getGetterClass() != null )
{
lastType = (NodeType) child;
}

// System.out.println("Astchain i: " + i + " currentobj : " + context.getCurrentObject() +
// " and root: " + context.getRoot());
if ( !ASTVarRef.class.isInstance( child ) && !constructor && !(
OrderedReturn.class.isInstance( child )
if ( !(child instanceof ASTVarRef) && !constructor && !(
child instanceof OrderedReturn
&& ( (OrderedReturn) child ).getLastExpression() != null ) && ( parent == null
|| !ASTSequence.class.isInstance( parent ) ) )
|| !(parent instanceof ASTSequence)) )
{
value = OgnlRuntime.getCompiler( context ).castExpression( context, child, value );
}
@@ -321,7 +321,7 @@ public String toGetSourceString( OgnlContext context, Object target )
* context.getPreviousType() + " prev accessor " + context.getPreviousAccessor());
*/

if ( OrderedReturn.class.isInstance( child )
if ( child instanceof OrderedReturn
&& ( (OrderedReturn) child ).getLastExpression() != null )
{
ordered = true;
@@ -343,8 +343,8 @@ public String toGetSourceString( OgnlContext context, Object target )
lastExpression = context.remove( ExpressionCompiler.PRE_CAST ) + lastExpression;
}
}
else if ( ASTOr.class.isInstance( child ) || ASTAnd.class.isInstance( child )
|| ASTCtor.class.isInstance( child ) || ( ASTStaticField.class.isInstance( child )
else if ( child instanceof ASTOr || child instanceof ASTAnd
|| child instanceof ASTCtor || ( child instanceof ASTStaticField
&& parent == null ) )
{
context.put( "_noRoot", "true" );
@@ -403,7 +403,7 @@ public String toSetSourceString( OgnlContext context, Object target )
{
if ( ( children != null ) && ( children.length > 0 ) )
{
if ( ASTConst.class.isInstance( children[0] ) )
if (children[0] instanceof ASTConst)
{
throw new UnsupportedCompilationException( "Can't modify constant values." );
}
@@ -423,22 +423,22 @@ public String toSetSourceString( OgnlContext context, Object target )

// System.out.println("astchain setter child returned >> " + value + " <<");

if ( ASTCtor.class.isInstance( children[i] ) )
if (children[i] instanceof ASTCtor)
{
constructor = true;
}

if ( NodeType.class.isInstance( children[i] )
if ( children[i] instanceof NodeType
&& ( (NodeType) children[i] ).getGetterClass() != null )
{
lastType = (NodeType) children[i];
}

if ( !ASTVarRef.class.isInstance( children[i] )
if ( !(children[i] instanceof ASTVarRef)
&& !constructor
&& !( OrderedReturn.class.isInstance( children[i] )
&& !( children[i] instanceof OrderedReturn
&& ( (OrderedReturn) children[i] ).getLastExpression() != null )
&& ( parent == null || !ASTSequence.class.isInstance( parent ) ) )
&& ( parent == null || !(parent instanceof ASTSequence)) )
{
value = OgnlRuntime.getCompiler( context ).castExpression( context, children[i], value );
}
@@ -451,8 +451,8 @@ public String toSetSourceString( OgnlContext context, Object target )
* OgnlRuntime.getCompiler().castExpression(context, _children[i], value); }
*/

if ( ASTOr.class.isInstance( children[i] ) || ASTAnd.class.isInstance( children[i] )
|| ASTCtor.class.isInstance( children[i] ) || ASTStaticField.class.isInstance( children[i] ) )
if ( children[i] instanceof ASTOr || children[i] instanceof ASTAnd
|| children[i] instanceof ASTCtor || children[i] instanceof ASTStaticField)
{
context.put( "_noRoot", "true" );
result = value;
@@ -81,7 +81,7 @@ public Class getSetterClass()

public String toGetSourceString( OgnlContext context, Object target )
{
if ( value == null && parent != null && ExpressionNode.class.isInstance( parent ) )
if ( value == null && parent != null && parent instanceof ExpressionNode)
{
context.setCurrentType( null );
return "null";
@@ -95,7 +95,7 @@ public String toGetSourceString( OgnlContext context, Object target )
getterClass = value.getClass();

Object retval = value;
if ( parent != null && ASTProperty.class.isInstance( parent ) )
if ( parent != null && parent instanceof ASTProperty)
{
context.setCurrentObject( value );

@@ -121,7 +121,7 @@ public String toGetSourceString( OgnlContext context, Object target )

return retval.toString();
}
if ( Character.class.isInstance( value ) )
if (value instanceof Character)
{
Character val = (Character) value;

@@ -181,12 +181,12 @@ public String toGetSourceString( OgnlContext context, Object target )

result.append("[").append(children[0].toGetSourceString(context, target)).append("]");
}
else if ( ASTProperty.class.isInstance( children[0] ) )
else if (children[0] instanceof ASTProperty)
{

result.append("[").append(ExpressionCompiler.getRootExpression(children[0], target, context)).append(children[0].toGetSourceString(context, target)).append("]");
}
else if ( ASTChain.class.isInstance( children[0] ) )
else if (children[0] instanceof ASTChain)
{

result.append("[").append(children[0].toGetSourceString(context, target)).append("]");
@@ -217,7 +217,7 @@ else if ( ASTChain.class.isInstance( children[0] ) )
Object objValue = children[i].getValue( context, context.getRoot() );
String value = children[i].toGetSourceString( context, target );

if ( !ASTRootVarRef.class.isInstance( children[i] ) )
if ( !(children[i] instanceof ASTRootVarRef))
{
value = ExpressionCompiler.getRootExpression( children[i], target, context ) + value;
}
@@ -233,7 +233,7 @@ else if ( ASTChain.class.isInstance( children[0] ) )
cast = "";
}

if ( !ASTConst.class.isInstance( children[i] ) )
if ( !(children[i] instanceof ASTConst))
{
value = cast + value;
}
@@ -301,15 +301,15 @@ else if ( ASTChain.class.isInstance( children[0] ) )
{

if ( values[i] != null && !types[i].isPrimitive() && !values[i].getClass().isArray()
&& !ASTConst.class.isInstance( children[i] ) )
&& !(children[i] instanceof ASTConst))
{

value =
"(" + OgnlRuntime.getCompiler( context ).getInterfaceClass( values[i].getClass() ).getName()
+ ")" + value;
}
else if ( !ASTConst.class.isInstance( children[i] )
|| ( ASTConst.class.isInstance( children[i] ) && !types[i].isPrimitive() ) )
else if ( !(children[i] instanceof ASTConst)
|| ( children[i] instanceof ASTConst && !types[i].isPrimitive() ) )
{

if ( !types[i].isArray() && types[i].isPrimitive() && !ctorParamTypes[i].isPrimitive() )
@@ -72,7 +72,7 @@ public String toGetSourceString( OgnlContext context, Object target )

String ret = "";

if ( ASTConst.class.isInstance( children[0] ) )
if (children[0] instanceof ASTConst)
{
ret = ( (Boolean) getValueBody( context, target ) ).toString();
}
@@ -67,7 +67,7 @@ public Class getSetterClass()
public String toGetSourceString( OgnlContext context, Object target )
{
StringBuilder result = new StringBuilder();
boolean array = ASTCtor.class.isInstance(parent) && ((ASTCtor) parent).isArray();
boolean array = parent instanceof ASTCtor && ((ASTCtor) parent).isArray();

context.setCurrentType( List.class );
context.setCurrentAccessor( List.class );
@@ -99,7 +99,7 @@ public String toGetSourceString( OgnlContext context, Object target )
String value = children[i].toGetSourceString( context, target );

// to undo type setting of constants when used as method parameters
if ( ASTConst.class.isInstance( children[i] ) )
if (children[i] instanceof ASTConst)
{

context.setCurrentType( prevType );
@@ -118,7 +118,7 @@ public String toGetSourceString( OgnlContext context, Object target )
cast = "";
}

if ( !ASTConst.class.isInstance( children[i] ) )
if ( !(children[i] instanceof ASTConst))
{
value = cast + value;
}
@@ -164,7 +164,7 @@ else if ( ctorClass != Object.class )
+ ctorClass.getName() + ".class)", ctorClass );

}
else if ( ( NodeType.class.isInstance( children[i] )
else if ( ( children[i] instanceof NodeType
&& ( (NodeType) children[i] ).getGetterClass() != null
&& Number.class.isAssignableFrom( ( (NodeType) children[i] ).getGetterClass() ) )
|| valueClass.isPrimitive() )

0 comments on commit c901ba5

Please sign in to comment.