Author: mcucchiara
Date: Fri Nov  4 09:01:49 2011
New Revision: 1197437

URL: http://svn.apache.org/viewvc?rev=1197437&view=rev
Log:
OGNL-35 - CPD fix, extracted getIndexString() from getSourceAccessor() and 
getSourceSetter().

Modified:
    
commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ArrayPropertyAccessor.java

Modified: 
commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ArrayPropertyAccessor.java
URL: 
http://svn.apache.org/viewvc/commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ArrayPropertyAccessor.java?rev=1197437&r1=1197436&r2=1197437&view=diff
==============================================================================
--- 
commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ArrayPropertyAccessor.java
 (original)
+++ 
commons/proper/ognl/trunk/src/main/java/org/apache/commons/ognl/ArrayPropertyAccessor.java
 Fri Nov  4 09:01:49 2011
@@ -145,29 +145,7 @@ public class ArrayPropertyAccessor
     @Override
     public String getSourceAccessor( OgnlContext context, Object target, 
Object index )
     {
-        String indexStr = index.toString();
-
-        // need to convert to primitive for list index access
-
-        // System.out.println("index class " + index.getClass() + " current 
type " + context.getCurrentType() +
-        // " current object class " + context.getCurrentObject().getClass());
-
-        if ( context.getCurrentType() != null && 
!context.getCurrentType().isPrimitive()
-            && Number.class.isAssignableFrom( context.getCurrentType() ) )
-        {
-            indexStr += "." + OgnlRuntime.getNumericValueGetter( 
context.getCurrentType() );
-        }
-        else if ( context.getCurrentObject() != null
-            && Number.class.isAssignableFrom( 
context.getCurrentObject().getClass() )
-            && !context.getCurrentType().isPrimitive() )
-        {
-            // means it needs to be cast first as well
-
-            String toString =
-                String.class.isInstance( index ) && context.getCurrentType() 
!= Object.class ? "" : ".toString()";
-
-            indexStr = "org.apache.commons.ognl.OgnlOps#getIntValue(" + 
indexStr + toString + ")";
-        }
+        String indexStr = getIndexString(context, index);
 
         context.setCurrentAccessor( target.getClass() );
         context.setCurrentType( target.getClass().getComponentType() );
@@ -178,10 +156,31 @@ public class ArrayPropertyAccessor
     @Override
     public String getSourceSetter( OgnlContext context, Object target, Object 
index )
     {
+        String indexStr = getIndexString(context, index);
+
+        Class<?> type = target.getClass().isArray() ? 
target.getClass().getComponentType() : target.getClass();
+
+        context.setCurrentAccessor( target.getClass() );
+        context.setCurrentType( target.getClass().getComponentType() );
+
+        if ( type.isPrimitive() )
+        {
+            Class<?> wrapClass = OgnlRuntime.getPrimitiveWrapperClass( type );
+
+            return "[" + indexStr + "]=((" + wrapClass.getName() + 
")org.apache.commons.ognl.OgnlOps.convertValue($3,"
+                + wrapClass.getName() + ".class, true))." + 
OgnlRuntime.getNumericValueGetter( wrapClass );
+        }
+        return "[" + indexStr + 
"]=org.apache.commons.ognl.OgnlOps.convertValue($3," + type.getName() + 
".class)";
+    }
+
+    private static String getIndexString( OgnlContext context, Object index ) {
         String indexStr = index.toString();
 
         // need to convert to primitive for list index access
 
+        // System.out.println("index class " + index.getClass() + " current 
type " + context.getCurrentType() +
+        // " current object class " + context.getCurrentObject().getClass());
+
         if ( context.getCurrentType() != null && 
!context.getCurrentType().isPrimitive()
             && Number.class.isAssignableFrom( context.getCurrentType() ) )
         {
@@ -198,19 +197,6 @@ public class ArrayPropertyAccessor
 
             indexStr = "org.apache.commons.ognl.OgnlOps#getIntValue(" + 
indexStr + toString + ")";
         }
-
-        Class<?> type = target.getClass().isArray() ? 
target.getClass().getComponentType() : target.getClass();
-
-        context.setCurrentAccessor( target.getClass() );
-        context.setCurrentType( target.getClass().getComponentType() );
-
-        if ( type.isPrimitive() )
-        {
-            Class<?> wrapClass = OgnlRuntime.getPrimitiveWrapperClass( type );
-
-            return "[" + indexStr + "]=((" + wrapClass.getName() + 
")org.apache.commons.ognl.OgnlOps.convertValue($3,"
-                + wrapClass.getName() + ".class, true))." + 
OgnlRuntime.getNumericValueGetter( wrapClass );
-        }
-        return "[" + indexStr + 
"]=org.apache.commons.ognl.OgnlOps.convertValue($3," + type.getName() + 
".class)";
+        return indexStr;
     }
 }


Reply via email to