This is an automated email from the ASF dual-hosted git repository.
lukaszlenart pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-ognl.git
The following commit(s) were added to refs/heads/master by this push:
new c901ba5 Remove redundant calls of java.lang.Class methods. Replaced
with object instanceof.
new f2a63d6 Merge pull request #45 from arturobernalg/feature/instance
c901ba5 is described below
commit c901ba54b752e471f67e66fc5c2867473d4932eb
Author: Arturo Bernal <[email protected]>
AuthorDate: Mon Jun 21 07:27:32 2021 +0200
Remove redundant calls of java.lang.Class methods. Replaced with object
instanceof.
---
src/main/java/org/apache/commons/ognl/ASTAdd.java | 40 ++++++++++----------
.../java/org/apache/commons/ognl/ASTAssign.java | 10 ++---
.../java/org/apache/commons/ognl/ASTBitNegate.java | 2 +-
.../java/org/apache/commons/ognl/ASTChain.java | 32 ++++++++--------
.../java/org/apache/commons/ognl/ASTConst.java | 6 +--
src/main/java/org/apache/commons/ognl/ASTCtor.java | 14 +++----
.../org/apache/commons/ognl/ASTInstanceof.java | 2 +-
src/main/java/org/apache/commons/ognl/ASTList.java | 8 ++--
.../java/org/apache/commons/ognl/ASTMethod.java | 8 ++--
.../org/apache/commons/ognl/ASTMethodUtil.java | 6 +--
.../java/org/apache/commons/ognl/ASTNegate.java | 2 +-
.../java/org/apache/commons/ognl/ASTProperty.java | 18 ++++-----
.../java/org/apache/commons/ognl/ASTSequence.java | 6 +--
.../org/apache/commons/ognl/ASTStaticMethod.java | 2 +-
src/main/java/org/apache/commons/ognl/ASTTest.java | 6 +--
.../java/org/apache/commons/ognl/ASTVarRef.java | 2 +-
.../apache/commons/ognl/ArrayPropertyAccessor.java | 2 +-
.../org/apache/commons/ognl/ExpressionNode.java | 6 +--
.../apache/commons/ognl/ListPropertyAccessor.java | 6 +--
.../apache/commons/ognl/MapPropertyAccessor.java | 4 +-
.../org/apache/commons/ognl/NumericExpression.java | 8 ++--
src/main/java/org/apache/commons/ognl/OgnlOps.java | 8 ++--
.../java/org/apache/commons/ognl/OgnlRuntime.java | 9 ++---
.../commons/ognl/enhance/ExpressionCompiler.java | 43 +++++++++++-----------
.../entry/GenericMethodParameterTypeFactory.java | 12 +++---
25 files changed, 129 insertions(+), 133 deletions(-)
diff --git a/src/main/java/org/apache/commons/ognl/ASTAdd.java
b/src/main/java/org/apache/commons/ognl/ASTAdd.java
index 950c9de..04a4427 100644
--- a/src/main/java/org/apache/commons/ognl/ASTAdd.java
+++ b/src/main/java/org/apache/commons/ognl/ASTAdd.java
@@ -159,7 +159,7 @@ class ASTAdd
{
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 @@ class ASTAdd
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 @@ class ASTAdd
// 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 @@ class ASTAdd
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 @@ class ASTAdd
// 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 @@ class ASTAdd
{
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 @@ class ASTAdd
{
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(".");
}
diff --git a/src/main/java/org/apache/commons/ognl/ASTAssign.java
b/src/main/java/org/apache/commons/ognl/ASTAssign.java
index b394435..7a6d3aa 100644
--- a/src/main/java/org/apache/commons/ognl/ASTAssign.java
+++ b/src/main/java/org/apache/commons/ognl/ASTAssign.java
@@ -53,7 +53,7 @@ class ASTAssign
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 @@ class ASTAssign
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 @@ class ASTAssign
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 @@ class ASTAssign
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 )
{
diff --git a/src/main/java/org/apache/commons/ognl/ASTBitNegate.java
b/src/main/java/org/apache/commons/ognl/ASTBitNegate.java
index 316fd92..f612e45 100644
--- a/src/main/java/org/apache/commons/ognl/ASTBitNegate.java
+++ b/src/main/java/org/apache/commons/ognl/ASTBitNegate.java
@@ -45,7 +45,7 @@ class ASTBitNegate
{
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]
) + ")";
}
diff --git a/src/main/java/org/apache/commons/ognl/ASTChain.java
b/src/main/java/org/apache/commons/ognl/ASTChain.java
index 8ca6e3c..8344376 100644
--- a/src/main/java/org/apache/commons/ognl/ASTChain.java
+++ b/src/main/java/org/apache/commons/ognl/ASTChain.java
@@ -295,22 +295,22 @@ public class ASTChain
// 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 class ASTChain
* 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 class ASTChain
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 class ASTChain
{
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 class ASTChain
// 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 class ASTChain
* 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;
diff --git a/src/main/java/org/apache/commons/ognl/ASTConst.java
b/src/main/java/org/apache/commons/ognl/ASTConst.java
index 8139863..9813f3a 100644
--- a/src/main/java/org/apache/commons/ognl/ASTConst.java
+++ b/src/main/java/org/apache/commons/ognl/ASTConst.java
@@ -81,7 +81,7 @@ public class ASTConst
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 class ASTConst
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 class ASTConst
return retval.toString();
}
- if ( Character.class.isInstance( value ) )
+ if (value instanceof Character)
{
Character val = (Character) value;
diff --git a/src/main/java/org/apache/commons/ognl/ASTCtor.java
b/src/main/java/org/apache/commons/ognl/ASTCtor.java
index 37603d3..5ac44a6 100644
--- a/src/main/java/org/apache/commons/ognl/ASTCtor.java
+++ b/src/main/java/org/apache/commons/ognl/ASTCtor.java
@@ -181,12 +181,12 @@ public class ASTCtor
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 @@ public class ASTCtor
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 @@ public class ASTCtor
cast = "";
}
- if ( !ASTConst.class.isInstance( children[i] ) )
+ if ( !(children[i] instanceof ASTConst))
{
value = cast + value;
}
@@ -301,15 +301,15 @@ public class ASTCtor
{
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() )
diff --git a/src/main/java/org/apache/commons/ognl/ASTInstanceof.java
b/src/main/java/org/apache/commons/ognl/ASTInstanceof.java
index 3b6b5d9..9eb4b5d 100644
--- a/src/main/java/org/apache/commons/ognl/ASTInstanceof.java
+++ b/src/main/java/org/apache/commons/ognl/ASTInstanceof.java
@@ -72,7 +72,7 @@ public class ASTInstanceof
String ret = "";
- if ( ASTConst.class.isInstance( children[0] ) )
+ if (children[0] instanceof ASTConst)
{
ret = ( (Boolean) getValueBody( context, target ) ).toString();
}
diff --git a/src/main/java/org/apache/commons/ognl/ASTList.java
b/src/main/java/org/apache/commons/ognl/ASTList.java
index f481c6c..eb019a7 100644
--- a/src/main/java/org/apache/commons/ognl/ASTList.java
+++ b/src/main/java/org/apache/commons/ognl/ASTList.java
@@ -67,7 +67,7 @@ public class ASTList
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 class ASTList
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 class ASTList
cast = "";
}
- if ( !ASTConst.class.isInstance( children[i] ) )
+ if ( !(children[i] instanceof ASTConst))
{
value = cast + value;
}
@@ -164,7 +164,7 @@ public class ASTList
+ 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() )
diff --git a/src/main/java/org/apache/commons/ognl/ASTMethod.java
b/src/main/java/org/apache/commons/ognl/ASTMethod.java
index 80d33b3..0a52322 100644
--- a/src/main/java/org/apache/commons/ognl/ASTMethod.java
+++ b/src/main/java/org/apache/commons/ognl/ASTMethod.java
@@ -277,7 +277,7 @@ public class ASTMethod
StringBuilder result = new StringBuilder("." + method.getName() + "(");
if ( method.getReturnType() != void.class &&
method.getReturnType().isPrimitive() && ( parent == null
- || !ASTTest.class.isInstance( parent ) ) )
+ || !(parent instanceof ASTTest)) )
{
Class wrapper = OgnlRuntime.getPrimitiveWrapperClass(
method.getReturnType() );
@@ -331,8 +331,8 @@ public class ASTMethod
if ( parmString == null || parmString.trim().length() < 1 )
{
- if ( ASTProperty.class.isInstance( child ) ||
ASTMethod.class.isInstance( child )
- || ASTStaticMethod.class.isInstance( child ) ||
ASTChain.class.isInstance( child ) )
+ if ( child instanceof ASTProperty || child instanceof
ASTMethod
+ || child instanceof ASTStaticMethod || child
instanceof ASTChain)
{
throw new UnsupportedCompilationException(
"ASTMethod setter child returned null from a
sub property expression." );
@@ -341,7 +341,7 @@ public class ASTMethod
}
// to undo type setting of constants when used as method
parameters
- if ( ASTConst.class.isInstance( child ) )
+ if (child instanceof ASTConst)
{
context.setCurrentType( prevType );
}
diff --git a/src/main/java/org/apache/commons/ognl/ASTMethodUtil.java
b/src/main/java/org/apache/commons/ognl/ASTMethodUtil.java
index b702e8a..55e9eab 100644
--- a/src/main/java/org/apache/commons/ognl/ASTMethodUtil.java
+++ b/src/main/java/org/apache/commons/ognl/ASTMethodUtil.java
@@ -44,7 +44,7 @@ class ASTMethodUtil
}
// to undo type setting of constants when used as method parameters
- if ( ASTConst.class.isInstance( child ) )
+ if (child instanceof ASTConst)
{
context.setCurrentType( prevType );
}
@@ -62,7 +62,7 @@ class ASTMethodUtil
cast = "";
}
- if ( !ASTConst.class.isInstance( child ) )
+ if ( !(child instanceof ASTConst))
{
parmString = cast + parmString;
}
@@ -108,7 +108,7 @@ class ASTMethodUtil
parm );
}
- else if ( ( NodeType.class.isInstance( child ) && ( (NodeType) child
).getGetterClass() != null
+ else if ( ( child instanceof NodeType && ( (NodeType) child
).getGetterClass() != null
&& Number.class.isAssignableFrom( ( (NodeType) child
).getGetterClass() ) ) || ( valueClass != null
&& valueClass.isPrimitive() ) )
{
diff --git a/src/main/java/org/apache/commons/ognl/ASTNegate.java
b/src/main/java/org/apache/commons/ognl/ASTNegate.java
index dd6f2fe..d40322c 100644
--- a/src/main/java/org/apache/commons/ognl/ASTNegate.java
+++ b/src/main/java/org/apache/commons/ognl/ASTNegate.java
@@ -45,7 +45,7 @@ class ASTNegate
{
String source = children[0].toGetSourceString( context, target );
- if ( !ASTNegate.class.isInstance( children[0] ) )
+ if ( !(children[0] instanceof ASTNegate))
{
return "-" + source;
}
diff --git a/src/main/java/org/apache/commons/ognl/ASTProperty.java
b/src/main/java/org/apache/commons/ognl/ASTProperty.java
index 9825d80..8a5caf3 100644
--- a/src/main/java/org/apache/commons/ognl/ASTProperty.java
+++ b/src/main/java/org/apache/commons/ognl/ASTProperty.java
@@ -196,7 +196,7 @@ public class ASTProperty
// + " and srcString " + srcString + " on target: " + target);
Object currentObject = context.getCurrentObject();
- if ( ASTConst.class.isInstance( child ) &&
Number.class.isInstance( currentObject ) )
+ if ( child instanceof ASTConst && currentObject instanceof
Number)
{
context.setCurrentType(
OgnlRuntime.getPrimitiveWrapperClass( currentObject.getClass() ) );
}
@@ -300,8 +300,7 @@ public class ASTProperty
String srcString = child.toGetSourceString( context,
context.getRoot() );
- if ( ASTConst.class.isInstance( child ) &&
String.class.isInstance(
- context.getCurrentObject() ) )
+ if ( child instanceof ASTConst &&
context.getCurrentObject() instanceof String)
{
srcString = "\"" + srcString + "\"";
}
@@ -372,11 +371,11 @@ public class ASTProperty
Method getIndexedWriteMethod( PropertyDescriptor pd )
{
- if ( IndexedPropertyDescriptor.class.isInstance( pd ) )
+ if (pd instanceof IndexedPropertyDescriptor)
{
return ( (IndexedPropertyDescriptor) pd ).getIndexedWriteMethod();
}
- if ( ObjectIndexedPropertyDescriptor.class.isInstance( pd ) )
+ if (pd instanceof ObjectIndexedPropertyDescriptor)
{
return ( (ObjectIndexedPropertyDescriptor) pd
).getIndexedWriteMethod();
}
@@ -422,7 +421,7 @@ public class ASTProperty
PropertyAccessor propertyAccessor =
OgnlRuntime.getPropertyAccessor( target.getClass() );
Object currentObject = context.getCurrentObject();
- if ( ASTConst.class.isInstance( child ) &&
Number.class.isInstance( currentObject ) )
+ if ( child instanceof ASTConst && currentObject instanceof
Number)
{
context.setCurrentType(
OgnlRuntime.getPrimitiveWrapperClass( currentObject.getClass() ) );
}
@@ -577,8 +576,7 @@ public class ASTProperty
String srcString = child.toGetSourceString( context,
context.getRoot() );
- if ( ASTConst.class.isInstance( child ) &&
String.class.isInstance(
- context.getCurrentObject() ) )
+ if ( child instanceof ASTConst &&
context.getCurrentObject() instanceof String)
{
srcString = "\"" + srcString + "\"";
}
@@ -630,7 +628,7 @@ public class ASTProperty
String srcString = child.toGetSourceString( context, context.getRoot()
);
srcString = ExpressionCompiler.getRootExpression( child,
context.getRoot(), context ) + srcString;
- if ( ASTChain.class.isInstance( child ) )
+ if (child instanceof ASTChain)
{
String cast = (String) context.remove( ExpressionCompiler.PRE_CAST
);
if ( cast != null )
@@ -639,7 +637,7 @@ public class ASTProperty
}
}
- if ( ASTConst.class.isInstance( child ) && String.class.isInstance(
context.getCurrentObject() ) )
+ if ( child instanceof ASTConst && context.getCurrentObject()
instanceof String)
{
srcString = "\"" + srcString + "\"";
}
diff --git a/src/main/java/org/apache/commons/ognl/ASTSequence.java
b/src/main/java/org/apache/commons/ognl/ASTSequence.java
index 4f4d4f6..0142420 100644
--- a/src/main/java/org/apache/commons/ognl/ASTSequence.java
+++ b/src/main/java/org/apache/commons/ognl/ASTSequence.java
@@ -109,12 +109,12 @@ public class ASTSequence
// System.out.println("astsequence child : " +
_children[i].getClass().getName());
String seqValue = children[i].toGetSourceString( context, target );
- if ( ( i + 1 ) < children.length && ASTOr.class.isInstance(
children[i] ) )
+ if ( ( i + 1 ) < children.length && children[i] instanceof ASTOr)
{
seqValue = "(" + seqValue + ")";
}
- if ( i > 0 && ASTProperty.class.isInstance( children[i] ) &&
seqValue != null
+ if ( i > 0 && children[i] instanceof ASTProperty && seqValue !=
null
&& !seqValue.trim().isEmpty() )
{
String pre = (String) context.get( "_currentChain" );
@@ -144,7 +144,7 @@ public class ASTSequence
}
// set last known type from last child with a type
- if ( NodeType.class.isInstance( children[i] ) && ( (NodeType)
children[i] ).getGetterClass() != null )
+ if ( children[i] instanceof NodeType && ( (NodeType) children[i]
).getGetterClass() != null )
{
lastType = (NodeType) children[i];
}
diff --git a/src/main/java/org/apache/commons/ognl/ASTStaticMethod.java
b/src/main/java/org/apache/commons/ognl/ASTStaticMethod.java
index 586bc33..7134dfc 100644
--- a/src/main/java/org/apache/commons/ognl/ASTStaticMethod.java
+++ b/src/main/java/org/apache/commons/ognl/ASTStaticMethod.java
@@ -150,7 +150,7 @@ public class ASTStaticMethod
+
")org.apache.commons.ognl.OgnlOps.convertValue(" + parmString + ","
+ parms[i].getName() + ".class)", parms[i] );
}
- else if ( ( NodeType.class.isInstance( child ) && (
(NodeType) child ).getGetterClass() != null
+ else if ( ( child instanceof NodeType && ( (NodeType)
child ).getGetterClass() != null
&& Number.class.isAssignableFrom( ( (NodeType)
child ).getGetterClass() ) )
|| valueClass.isPrimitive() )
{
diff --git a/src/main/java/org/apache/commons/ognl/ASTTest.java
b/src/main/java/org/apache/commons/ognl/ASTTest.java
index 0d9ead9..62bb200 100644
--- a/src/main/java/org/apache/commons/ognl/ASTTest.java
+++ b/src/main/java/org/apache/commons/ognl/ASTTest.java
@@ -82,7 +82,7 @@ class ASTTest
first = OgnlRuntime.getCompiler( context
).createLocalReference( context, first, context.getCurrentType() );
}
- if ( ExpressionNode.class.isInstance( children[0] ) )
+ if (children[0] instanceof ExpressionNode)
{
first = "(" + first + ")";
}
@@ -95,7 +95,7 @@ class ASTTest
second = OgnlRuntime.getCompiler( context
).createLocalReference( context, second, context.getCurrentType() );
}
- if ( ExpressionNode.class.isInstance( children[1] ) )
+ if (children[1] instanceof ExpressionNode)
{
second = "(" + second + ")";
}
@@ -109,7 +109,7 @@ class ASTTest
}
- if ( ExpressionNode.class.isInstance( children[2] ) )
+ if (children[2] instanceof ExpressionNode)
{
third = "(" + third + ")";
}
diff --git a/src/main/java/org/apache/commons/ognl/ASTVarRef.java
b/src/main/java/org/apache/commons/ognl/ASTVarRef.java
index 28f8c2d..53d5fef 100644
--- a/src/main/java/org/apache/commons/ognl/ASTVarRef.java
+++ b/src/main/java/org/apache/commons/ognl/ASTVarRef.java
@@ -124,7 +124,7 @@ public class ASTVarRef
post = ")";
}
- if ( parent != null && ASTAssign.class.isInstance( parent ) )
+ if ( parent != null && parent instanceof ASTAssign)
{
core = "$1.put(\"" + name + "\",";
last = pre + "$1.get(\"" + name + "\")" + post;
diff --git a/src/main/java/org/apache/commons/ognl/ArrayPropertyAccessor.java
b/src/main/java/org/apache/commons/ognl/ArrayPropertyAccessor.java
index ca6094f..5c32cf0 100644
--- a/src/main/java/org/apache/commons/ognl/ArrayPropertyAccessor.java
+++ b/src/main/java/org/apache/commons/ognl/ArrayPropertyAccessor.java
@@ -184,7 +184,7 @@ public class ArrayPropertyAccessor
// means it needs to be cast first as well
String toString =
- String.class.isInstance( index ) && context.getCurrentType()
!= Object.class ? "" : ".toString()";
+ index instanceof String && context.getCurrentType() !=
Object.class ? "" : ".toString()";
indexStr = format(
"org.apache.commons.ognl.OgnlOps#getIntValue(%s%s)", indexStr, toString );
}
diff --git a/src/main/java/org/apache/commons/ognl/ExpressionNode.java
b/src/main/java/org/apache/commons/ognl/ExpressionNode.java
index 76e4a7b..4fdf017 100644
--- a/src/main/java/org/apache/commons/ognl/ExpressionNode.java
+++ b/src/main/java/org/apache/commons/ognl/ExpressionNode.java
@@ -94,13 +94,13 @@ public abstract class ExpressionNode
String value = children[i].toGetSourceString( context, target
);
- if ( ( ASTProperty.class.isInstance( children[i] ) ||
ASTMethod.class.isInstance( children[i] )
- || ASTSequence.class.isInstance( children[i] ) ||
ASTChain.class.isInstance( children[i] ) )
+ if ( ( children[i] instanceof ASTProperty || children[i]
instanceof ASTMethod
+ || children[i] instanceof ASTSequence || children[i]
instanceof ASTChain)
&& value != null && !value.trim().isEmpty() )
{
String pre = null;
- if ( ASTMethod.class.isInstance( children[i] ) )
+ if (children[i] instanceof ASTMethod)
{
pre = (String) context.get( "_currentChain" );
}
diff --git a/src/main/java/org/apache/commons/ognl/ListPropertyAccessor.java
b/src/main/java/org/apache/commons/ognl/ListPropertyAccessor.java
index cfc955d..bafd9cc 100644
--- a/src/main/java/org/apache/commons/ognl/ListPropertyAccessor.java
+++ b/src/main/java/org/apache/commons/ognl/ListPropertyAccessor.java
@@ -183,7 +183,7 @@ public class ListPropertyAccessor
{
String indexStr = index.toString().replace( "\"", "" );
- if ( String.class.isInstance( index ) )
+ if (index instanceof String)
{
if ( "size".equals( indexStr ) )
{
@@ -231,7 +231,7 @@ public class ListPropertyAccessor
{
Object currentObject = context.getCurrentObject();
Class<?> currentType = context.getCurrentType();
- if ( currentObject != null && !Number.class.isInstance( currentObject
) )
+ if ( currentObject != null && !(currentObject instanceof Number))
{
try
{
@@ -274,7 +274,7 @@ public class ListPropertyAccessor
{
// means it needs to be cast first as well
- String toString = String.class.isInstance( index ) && currentType
!= Object.class ? "" : ".toString()";
+ String toString = index instanceof String && currentType !=
Object.class ? "" : ".toString()";
indexStr = "org.apache.commons.ognl.OgnlOps#getIntValue(" +
indexStr + toString + ")";
}
diff --git a/src/main/java/org/apache/commons/ognl/MapPropertyAccessor.java
b/src/main/java/org/apache/commons/ognl/MapPropertyAccessor.java
index 833ab5e..df526d4 100644
--- a/src/main/java/org/apache/commons/ognl/MapPropertyAccessor.java
+++ b/src/main/java/org/apache/commons/ognl/MapPropertyAccessor.java
@@ -118,7 +118,7 @@ public class MapPropertyAccessor
context.setCurrentAccessor( Map.class );
context.setCurrentType( Object.class );
- if ( String.class.isInstance( index ) && !indexedAccess )
+ if ( index instanceof String && !indexedAccess )
{
String key = indexStr.replace( "\"", "" );
@@ -154,7 +154,7 @@ public class MapPropertyAccessor
String indexStr = index.toString();
- if ( String.class.isInstance( index ) )
+ if (index instanceof String)
{
String key = indexStr.replace( "\"", "" );
diff --git a/src/main/java/org/apache/commons/ognl/NumericExpression.java
b/src/main/java/org/apache/commons/ognl/NumericExpression.java
index 06dc46a..266ba46 100644
--- a/src/main/java/org/apache/commons/ognl/NumericExpression.java
+++ b/src/main/java/org/apache/commons/ognl/NumericExpression.java
@@ -108,13 +108,13 @@ public abstract class NumericExpression
StringBuilder ret = new StringBuilder( source );
Object value = context.getCurrentObject();
- if ( ASTConst.class.isInstance( child ) && value != null )
+ if ( child instanceof ASTConst && value != null )
{
return value.toString();
}
if ( context.getCurrentType() != null &&
!context.getCurrentType().isPrimitive()
- && context.getCurrentObject() != null && Number.class.isInstance(
context.getCurrentObject() ) )
+ && context.getCurrentObject() != null &&
context.getCurrentObject() instanceof Number)
{
ret = new StringBuilder( "((" ).append(
ExpressionCompiler.getCastString(
context.getCurrentObject().getClass() ) ).append( ")" ).append(
@@ -122,7 +122,7 @@ public abstract class NumericExpression
OgnlRuntime.getNumericValueGetter(
context.getCurrentObject().getClass() ) );
}
else if ( context.getCurrentType() != null &&
context.getCurrentType().isPrimitive()
- && ( ASTConst.class.isInstance( child ) ||
NumericExpression.class.isInstance( child ) ) )
+ && ( child instanceof ASTConst || child instanceof
NumericExpression) )
{
@SuppressWarnings( "unchecked" ) // checked by the condition in
the if clause
Class<? extends Number> numberClass = (Class<? extends Number>)
context.getCurrentType();
@@ -136,7 +136,7 @@ public abstract class NumericExpression
context.setCurrentType( Double.TYPE );
}
- if ( NumericExpression.class.isInstance( child ) )
+ if (child instanceof NumericExpression)
{
ret = new StringBuilder( "(" ).append( ret ).append( ")" );
}
diff --git a/src/main/java/org/apache/commons/ognl/OgnlOps.java
b/src/main/java/org/apache/commons/ognl/OgnlOps.java
index a6b9eec..58fd1c7 100644
--- a/src/main/java/org/apache/commons/ognl/OgnlOps.java
+++ b/src/main/java/org/apache/commons/ognl/OgnlOps.java
@@ -798,13 +798,13 @@ public abstract class OgnlOps
return -1;
}
- if ( Number.class.isInstance( value ) )
+ if (value instanceof Number)
{
return ( (Number) value ).intValue();
}
- String str = String.class.isInstance( value ) ? (String) value :
value.toString();
+ String str = value instanceof String ? (String) value :
value.toString();
return Integer.parseInt( str );
}
@@ -1292,12 +1292,12 @@ public abstract class OgnlOps
*/
public static RuntimeException castToRuntime( Throwable t )
{
- if ( RuntimeException.class.isInstance( t ) )
+ if (t instanceof RuntimeException)
{
return (RuntimeException) t;
}
- if ( OgnlException.class.isInstance( t ) )
+ if (t instanceof OgnlException)
{
throw new UnsupportedCompilationException( "Error evluating
expression: " + t.getMessage(), t );
}
diff --git a/src/main/java/org/apache/commons/ognl/OgnlRuntime.java
b/src/main/java/org/apache/commons/ognl/OgnlRuntime.java
index 54a7a5f..e0a9ed7 100644
--- a/src/main/java/org/apache/commons/ognl/OgnlRuntime.java
+++ b/src/main/java/org/apache/commons/ognl/OgnlRuntime.java
@@ -395,8 +395,7 @@ public class OgnlRuntime
public static Class<?>[] findParameterTypes( Class<?> type, Method method )
throws CacheException
{
- if ( type == null || type.getGenericSuperclass() == null ||
!ParameterizedType.class.isInstance(
- type.getGenericSuperclass() ) ||
method.getDeclaringClass().getTypeParameters() == null )
+ if ( type == null || type.getGenericSuperclass() == null ||
!(type.getGenericSuperclass() instanceof ParameterizedType) ||
method.getDeclaringClass().getTypeParameters() == null )
{
return getParameterTypes( method );
}
@@ -809,7 +808,7 @@ public class OgnlRuntime
for ( Method method : methods )
{
Class<?> typeClass = target != null ? target.getClass() : null;
- if ( typeClass == null && source != null &&
Class.class.isInstance( source ) )
+ if ( typeClass == null && source != null && source instanceof
Class)
{
typeClass = (Class<?>) source;
}
@@ -2086,7 +2085,7 @@ public class OgnlRuntime
// handle root / method expressions that may not have proper root java
source access
- if ( !ASTConst.class.isInstance( child ) && ( target == null ||
context.getRoot() != target ) )
+ if ( !(child instanceof ASTConst) && ( target == null ||
context.getRoot() != target ) )
{
source = pre + source;
}
@@ -2097,7 +2096,7 @@ public class OgnlRuntime
context.setCurrentAccessor( context.getRoot().getClass() );
}
- if ( ASTChain.class.isInstance( child ) )
+ if (child instanceof ASTChain)
{
String cast = (String) context.remove( ExpressionCompiler.PRE_CAST
);
if ( cast == null )
diff --git
a/src/main/java/org/apache/commons/ognl/enhance/ExpressionCompiler.java
b/src/main/java/org/apache/commons/ognl/enhance/ExpressionCompiler.java
index 3eed6a8..628af40 100644
--- a/src/main/java/org/apache/commons/ognl/enhance/ExpressionCompiler.java
+++ b/src/main/java/org/apache/commons/ognl/enhance/ExpressionCompiler.java
@@ -148,27 +148,26 @@ public class ExpressionCompiler
return rootExpr;
}
- if ( ( !ASTList.class.isInstance( expression ) &&
!ASTVarRef.class.isInstance( expression )
- && !ASTStaticMethod.class.isInstance( expression ) &&
!ASTStaticField.class.isInstance( expression )
- && !ASTConst.class.isInstance( expression ) &&
!ExpressionNode.class.isInstance( expression )
- && !ASTCtor.class.isInstance( expression ) &&
!ASTStaticMethod.class.isInstance( expression )
- && root != null ) || ( root != null &&
ASTRootVarRef.class.isInstance( expression ) ) )
+ if ( ( !(expression instanceof ASTList) && !(expression instanceof
ASTVarRef)
+ && !(expression instanceof ASTStaticMethod) && !(expression
instanceof ASTStaticField)
+ && !(expression instanceof ASTConst) && !(expression instanceof
ExpressionNode)
+ && !(expression instanceof ASTCtor) && !(expression instanceof
ASTStaticMethod)
+ && root != null ) || ( root != null && expression instanceof
ASTRootVarRef) )
{
Class<?> castClass = OgnlRuntime.getCompiler( context
).getRootExpressionClass( expression, context );
- if ( castClass.isArray() || ASTRootVarRef.class.isInstance(
expression ) || ASTThisVarRef.class.isInstance(
- expression ) )
+ if ( castClass.isArray() || expression instanceof ASTRootVarRef ||
expression instanceof ASTThisVarRef)
{
rootExpr = "((" + getCastString( castClass ) + ")$2)";
- if ( ASTProperty.class.isInstance( expression ) && !(
(ASTProperty) expression ).isIndexedAccess() )
+ if ( expression instanceof ASTProperty && !( (ASTProperty)
expression ).isIndexedAccess() )
{
rootExpr += ".";
}
}
- else if ( ( ASTProperty.class.isInstance( expression ) && (
(ASTProperty) expression ).isIndexedAccess() )
- || ASTChain.class.isInstance( expression ) )
+ else if ( ( expression instanceof ASTProperty && ( (ASTProperty)
expression ).isIndexedAccess() )
+ || expression instanceof ASTChain)
{
rootExpr = "((" + getCastString( castClass ) + ")$2)";
}
@@ -190,18 +189,18 @@ public class ExpressionCompiler
*/
public static boolean shouldCast( Node expression )
{
- if ( ASTChain.class.isInstance( expression ) )
+ if (expression instanceof ASTChain)
{
Node child = expression.jjtGetChild( 0 );
- if ( ASTConst.class.isInstance( child ) ||
ASTStaticMethod.class.isInstance( child )
- || ASTStaticField.class.isInstance( child ) || (
ASTVarRef.class.isInstance( child )
- && !ASTRootVarRef.class.isInstance( child ) ) )
+ if ( child instanceof ASTConst || child instanceof ASTStaticMethod
+ || child instanceof ASTStaticField || ( child instanceof
ASTVarRef
+ && !(child instanceof ASTRootVarRef)) )
{
return false;
}
}
- return !ASTConst.class.isInstance( expression );
+ return !(expression instanceof ASTConst);
}
/**
@@ -218,11 +217,11 @@ public class ExpressionCompiler
&& context.getCurrentAccessor().isAssignableFrom(
context.getPreviousType() ) ) || body == null
|| body.trim().length() < 1 || ( context.getCurrentType() != null
&& context.getCurrentType().isArray() && (
context.getPreviousType() == null || context.getPreviousType() !=
Object.class ) )
- || ASTOr.class.isInstance( expression ) ||
ASTAnd.class.isInstance( expression )
- || ASTRootVarRef.class.isInstance( expression ) ||
context.getCurrentAccessor() == Class.class || (
+ || expression instanceof ASTOr || expression instanceof ASTAnd
+ || expression instanceof ASTRootVarRef ||
context.getCurrentAccessor() == Class.class || (
context.get( ExpressionCompiler.PRE_CAST ) != null && ( (String)
context.get(
- ExpressionCompiler.PRE_CAST ) ).startsWith( "new" ) ) ||
ASTStaticField.class.isInstance( expression )
- || ASTStaticMethod.class.isInstance( expression ) || (
OrderedReturn.class.isInstance( expression )
+ ExpressionCompiler.PRE_CAST ) ).startsWith( "new" ) ) ||
expression instanceof ASTStaticField
+ || expression instanceof ASTStaticMethod || ( expression
instanceof OrderedReturn
&& ( (OrderedReturn) expression ).getLastExpression() != null ) )
{
return body;
@@ -619,10 +618,10 @@ public class ExpressionCompiler
createLocalReferences( context, classPool, newClass, objClass,
valueGetter.getParameterTypes() );
- if ( OrderedReturn.class.isInstance( expression )
+ if ( expression instanceof OrderedReturn
&& ( (OrderedReturn) expression ).getLastExpression() != null )
{
- body = "{ " + ( ASTMethod.class.isInstance( expression ) ||
ASTChain.class.isInstance( expression )
+ body = "{ " + ( expression instanceof ASTMethod || expression
instanceof ASTChain
? rootExpr
: "" ) + ( castExpression != null ? castExpression : "" )
+ ( (OrderedReturn) expression ).getCoreExpression() + "
return " + pre
@@ -697,7 +696,7 @@ public class ExpressionCompiler
CtMethod valueSetter, Node expression,
Object root )
throws Exception
{
- if ( ExpressionNode.class.isInstance( expression ) ||
ASTConst.class.isInstance( expression ) )
+ if ( expression instanceof ExpressionNode || expression instanceof
ASTConst)
{
throw new UnsupportedCompilationException( "Can't compile
expression/constant setters." );
}
diff --git
a/src/main/java/org/apache/commons/ognl/internal/entry/GenericMethodParameterTypeFactory.java
b/src/main/java/org/apache/commons/ognl/internal/entry/GenericMethodParameterTypeFactory.java
index 2e6e5d8..55af62b 100644
---
a/src/main/java/org/apache/commons/ognl/internal/entry/GenericMethodParameterTypeFactory.java
+++
b/src/main/java/org/apache/commons/ognl/internal/entry/GenericMethodParameterTypeFactory.java
@@ -49,20 +49,20 @@ public class GenericMethodParameterTypeFactory
{
TypeVariable<?> paramType = null;
- if ( TypeVariable.class.isInstance( genTypes[i] ) )
+ if (genTypes[i] instanceof TypeVariable)
{
paramType = (TypeVariable<?>) genTypes[i];
}
- else if ( GenericArrayType.class.isInstance( genTypes[i] ) )
+ else if (genTypes[i] instanceof GenericArrayType)
{
paramType = (TypeVariable<?>) ( (GenericArrayType) genTypes[i]
).getGenericComponentType();
}
- else if ( ParameterizedType.class.isInstance( genTypes[i] ) )
+ else if (genTypes[i] instanceof ParameterizedType)
{
types[i] = (Class<?>) ( (ParameterizedType) genTypes[i]
).getRawType();
continue;
}
- else if ( Class.class.isInstance( genTypes[i] ) )
+ else if (genTypes[i] instanceof Class)
{
types[i] = (Class<?>) genTypes[i];
continue;
@@ -72,7 +72,7 @@ public class GenericMethodParameterTypeFactory
if ( resolved != null )
{
- if ( GenericArrayType.class.isInstance( genTypes[i] ) )
+ if (genTypes[i] instanceof GenericArrayType)
{
resolved = Array.newInstance( resolved, 0 ).getClass();
}
@@ -95,7 +95,7 @@ public class GenericMethodParameterTypeFactory
for ( int i = 0; i < declaredTypes.length; i++ )
{
- if ( !TypeVariable.class.isInstance(
param.getActualTypeArguments()[i] )
+ if ( !(param.getActualTypeArguments()[i] instanceof TypeVariable)
&& declaredTypes[i].getName().equals( var.getName() ) )
{
return (Class<?>) param.getActualTypeArguments()[i];