Skip to content

Commit

Permalink
minor refactor: remove deprecated code usage
Browse files Browse the repository at this point in the history
  • Loading branch information
paulk-asert committed Dec 4, 2024
1 parent e9cdfbf commit 457ca9b
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import org.codehaus.groovy.reflection.ReflectionCache;
import org.codehaus.groovy.runtime.callsite.CallSite;
import org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite;
import org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation;
import org.codehaus.groovy.runtime.typehandling.ShortTypeHandling;

public class CharacterArrayPutAtMetaMethod extends ArrayPutAtMetaMethod {
private static final CachedClass ARRAY_CLASS = ReflectionCache.getCachedClass(char[].class);
Expand All @@ -38,7 +38,7 @@ public final CachedClass getDeclaringClass() {
public Object invoke(Object object, Object[] args) {
final char[] objects = (char[]) object;
final int index = normaliseIndex((Integer) args[0], objects.length);
objects[index] = DefaultTypeTransformation.getCharFromSizeOneString(args[1]);
objects[index] = ShortTypeHandling.castToChar(args[1]);
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.codehaus.groovy.runtime.callsite.CallSite;
import org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite;
import org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation;
import org.codehaus.groovy.runtime.typehandling.ShortTypeHandling;

public class DoubleArrayPutAtMetaMethod extends ArrayPutAtMetaMethod {
private static final CachedClass ARRAY_CLASS = ReflectionCache.getCachedClass(double[].class);
Expand All @@ -42,7 +43,7 @@ public Object invoke(Object object, Object[] args) {
Object newValue = args[1];
if (!(newValue instanceof Double)) {
if (newValue instanceof Character || newValue instanceof String || newValue instanceof GString) {
Character ch = DefaultTypeTransformation.getCharFromSizeOneString(newValue);
Character ch = ShortTypeHandling.castToChar(newValue);
objects[index] = (Double) DefaultTypeTransformation.castToType(ch, Double.class);
} else {
objects[index] = ((Number) newValue).doubleValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.codehaus.groovy.runtime.callsite.CallSite;
import org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite;
import org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation;
import org.codehaus.groovy.runtime.typehandling.ShortTypeHandling;

public class FloatArrayPutAtMetaMethod extends ArrayPutAtMetaMethod {
private static final CachedClass ARRAY_CLASS = ReflectionCache.getCachedClass(float[].class);
Expand All @@ -42,7 +43,7 @@ public Object invoke(Object object, Object[] args) {
Object newValue = args[1];
if (!(newValue instanceof Float)) {
if (newValue instanceof Character || newValue instanceof String || newValue instanceof GString) {
Character ch = DefaultTypeTransformation.getCharFromSizeOneString(newValue);
Character ch = ShortTypeHandling.castToChar(newValue);
objects[index] = (Float) DefaultTypeTransformation.castToType(ch, Float.class);
} else {
objects[index] = ((Number) newValue).floatValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.codehaus.groovy.runtime.callsite.CallSite;
import org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite;
import org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation;
import org.codehaus.groovy.runtime.typehandling.ShortTypeHandling;

public class IntegerArrayPutAtMetaMethod extends ArrayPutAtMetaMethod {
private static final CachedClass ARRAY_CLASS = ReflectionCache.getCachedClass(int[].class);
Expand All @@ -42,7 +43,7 @@ public Object invoke(Object object, Object[] args) {
Object newValue = args[1];
if (!(newValue instanceof Integer)) {
if (newValue instanceof Character || newValue instanceof String || newValue instanceof GString) {
Character ch = DefaultTypeTransformation.getCharFromSizeOneString(newValue);
Character ch = ShortTypeHandling.castToChar(newValue);
objects[index] = (Integer) DefaultTypeTransformation.castToType(ch, Integer.class);
} else {
objects[index] = ((Number) newValue).intValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.codehaus.groovy.runtime.callsite.CallSite;
import org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite;
import org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation;
import org.codehaus.groovy.runtime.typehandling.ShortTypeHandling;

public class LongArrayPutAtMetaMethod extends ArrayPutAtMetaMethod {
private static final CachedClass ARRAY_CLASS = ReflectionCache.getCachedClass(long[].class);
Expand All @@ -42,7 +43,7 @@ public Object invoke(Object object, Object[] args) {
Object newValue = args[1];
if (!(newValue instanceof Long)) {
if (newValue instanceof Character || newValue instanceof String || newValue instanceof GString) {
Character ch = DefaultTypeTransformation.getCharFromSizeOneString(newValue);
Character ch = ShortTypeHandling.castToChar(newValue);
objects[index] = (Long) DefaultTypeTransformation.castToType(ch, Long.class);
} else {
objects[index] = ((Number) newValue).longValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.codehaus.groovy.runtime.callsite.CallSite;
import org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite;
import org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation;
import org.codehaus.groovy.runtime.typehandling.ShortTypeHandling;

import static org.codehaus.groovy.reflection.ReflectionCache.OBJECT_ARRAY_CLASS;

Expand All @@ -51,12 +52,12 @@ private static Object adjustNewValue(final Object[] objects, final Object newVal
adjustedNewVal = DefaultTypeTransformation.castToType(newValue, arrayComponentClass);
}
} else if (Character.class.isAssignableFrom(arrayComponentClass)) {
adjustedNewVal = DefaultTypeTransformation.getCharFromSizeOneString(newValue);
adjustedNewVal = ShortTypeHandling.castToChar(newValue);
} else if (String.class.equals(arrayComponentClass) && newValue instanceof GString) {
adjustedNewVal = DefaultTypeTransformation.castToType(newValue, arrayComponentClass);
} else if (Number.class.isAssignableFrom(arrayComponentClass)) {
if (newValue instanceof Character || newValue instanceof String || newValue instanceof GString) {
Character ch = DefaultTypeTransformation.getCharFromSizeOneString(newValue);
Character ch = ShortTypeHandling.castToChar(newValue);
adjustedNewVal = DefaultTypeTransformation.castToType(ch, arrayComponentClass);
}
} else if (arrayComponentClass.isArray()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.codehaus.groovy.runtime.callsite.CallSite;
import org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite;
import org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation;
import org.codehaus.groovy.runtime.typehandling.ShortTypeHandling;

public class ShortArrayPutAtMetaMethod extends ArrayPutAtMetaMethod {
private static final CachedClass ARRAY_CLASS = ReflectionCache.getCachedClass(short[].class);
Expand All @@ -42,7 +43,7 @@ public Object invoke(Object object, Object[] args) {
Object newValue = args[1];
if (!(newValue instanceof Short)) {
if (newValue instanceof Character || newValue instanceof String || newValue instanceof GString) {
Character ch = DefaultTypeTransformation.getCharFromSizeOneString(newValue);
Character ch = ShortTypeHandling.castToChar(newValue);
objects[index] = (Short) DefaultTypeTransformation.castToType(ch, Short.class);
} else {
objects[index] = ((Number) newValue).shortValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1668,7 +1668,7 @@ private static ClassNode extractType(GenericsType gt) {

if (gt.getLowerBound() != null) {
cn = gt.getLowerBound();
} else if (asBoolean(gt.getUpperBounds())) {
} else if (ArrayGroovyMethods.asBoolean(gt.getUpperBounds())) {
cn = gt.getUpperBounds()[0];
}
}
Expand Down

0 comments on commit 457ca9b

Please sign in to comment.