This is an automated email from the ASF dual-hosted git repository. paulk pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/groovy.git
commit 716fea15295e7c0649380b4b2a5e5cc364816a44 Author: Paul King <pa...@asert.com.au> AuthorDate: Sat Apr 6 11:57:40 2024 +1000 fix deprecated method usage --- src/main/java/groovy/util/GroovyCollections.java | 7 +++-- ...StaticTypesMethodReferenceExpressionWriter.java | 2 +- .../groovy/control/CompilerConfiguration.java | 1 + .../groovy/runtime/ArrayGroovyMethods.java | 34 +++++++++++----------- .../typehandling/DefaultTypeTransformation.java | 13 ++------- .../transform/stc/StaticTypeCheckingSupport.java | 3 +- src/test/groovy/ClosureJavaIntegrationTest.java | 2 +- src/test/groovy/lang/ScriptTest.java | 4 +-- .../groovy/runtime/JdkDynamicProxyTest.java | 8 ++--- .../groovy/swing/extensions/SwingExtensions.java | 11 +++---- 10 files changed, 40 insertions(+), 45 deletions(-) diff --git a/src/main/java/groovy/util/GroovyCollections.java b/src/main/java/groovy/util/GroovyCollections.java index 4eba93638f..8d35754080 100644 --- a/src/main/java/groovy/util/GroovyCollections.java +++ b/src/main/java/groovy/util/GroovyCollections.java @@ -21,6 +21,7 @@ package groovy.util; import groovy.lang.Closure; import groovy.transform.stc.ClosureParams; import groovy.transform.stc.FromString; +import org.codehaus.groovy.runtime.ArrayGroovyMethods; import org.codehaus.groovy.runtime.DefaultGroovyMethods; import org.codehaus.groovy.runtime.NumberAwareComparator; import org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation; @@ -192,7 +193,7 @@ public class GroovyCollections { * @return the minimum value */ public static <T> T min(T[] items) { - return DefaultGroovyMethods.min(items); + return ArrayGroovyMethods.min(items); } /** @@ -214,7 +215,7 @@ public class GroovyCollections { * @return the maximum value */ public static <T> T max(T[] items) { - return DefaultGroovyMethods.max(items); + return ArrayGroovyMethods.max(items); } /** @@ -235,7 +236,7 @@ public class GroovyCollections { * @return the sum of the items */ public static Object sum(Object[] items) { - return DefaultGroovyMethods.sum(items); + return ArrayGroovyMethods.sum(items); } /** diff --git a/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesMethodReferenceExpressionWriter.java b/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesMethodReferenceExpressionWriter.java index d28cfdef70..9a98919956 100644 --- a/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesMethodReferenceExpressionWriter.java +++ b/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesMethodReferenceExpressionWriter.java @@ -59,7 +59,7 @@ import static org.codehaus.groovy.ast.tools.GeneralUtils.varX; import static org.codehaus.groovy.ast.tools.GenericsUtils.extractPlaceholders; import static org.codehaus.groovy.ast.tools.ParameterUtils.isVargs; import static org.codehaus.groovy.ast.tools.ParameterUtils.parametersCompatible; -import static org.codehaus.groovy.runtime.DefaultGroovyMethods.last; +import static org.codehaus.groovy.runtime.ArrayGroovyMethods.last; import static org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.allParametersAndArgumentsMatch; import static org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.filterMethodsByVisibility; import static org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.findDGMMethodsForClassNode; diff --git a/src/main/java/org/codehaus/groovy/control/CompilerConfiguration.java b/src/main/java/org/codehaus/groovy/control/CompilerConfiguration.java index 7eedc75250..b17c1846c7 100644 --- a/src/main/java/org/codehaus/groovy/control/CompilerConfiguration.java +++ b/src/main/java/org/codehaus/groovy/control/CompilerConfiguration.java @@ -230,6 +230,7 @@ public class CompilerConfiguration { } @Override + @Deprecated public void setOutput(final PrintWriter output) { throw new UnsupportedOperationException(); } diff --git a/src/main/java/org/codehaus/groovy/runtime/ArrayGroovyMethods.java b/src/main/java/org/codehaus/groovy/runtime/ArrayGroovyMethods.java index a3d742f891..ebd06072c9 100644 --- a/src/main/java/org/codehaus/groovy/runtime/ArrayGroovyMethods.java +++ b/src/main/java/org/codehaus/groovy/runtime/ArrayGroovyMethods.java @@ -655,7 +655,7 @@ public class ArrayGroovyMethods extends DefaultGroovyMethodsSupport { * @param self a boolean Array to be chopped * @param chopSizes the sizes for the returned pieces * @return a list of lists chopping the original array elements into pieces determined by chopSizes - * @see DefaultGroovyMethods#collate(Object[], int) to chop a list into pieces of a fixed size + * @see ArrayGroovyMethods#collate(Object[], int) to chop a list into pieces of a fixed size * @since 5.0.0 */ public static List<List<Boolean>> chop(boolean[] self, int... chopSizes) { @@ -674,7 +674,7 @@ public class ArrayGroovyMethods extends DefaultGroovyMethodsSupport { * @param self a byte Array to be chopped * @param chopSizes the sizes for the returned pieces * @return a list of lists chopping the original array elements into pieces determined by chopSizes - * @see DefaultGroovyMethods#collate(Object[], int) to chop a list into pieces of a fixed size + * @see ArrayGroovyMethods#collate(Object[], int) to chop a list into pieces of a fixed size * @since 5.0.0 */ public static List<List<Byte>> chop(byte[] self, int... chopSizes) { @@ -693,7 +693,7 @@ public class ArrayGroovyMethods extends DefaultGroovyMethodsSupport { * @param self a char Array to be chopped * @param chopSizes the sizes for the returned pieces * @return a list of lists chopping the original array elements into pieces determined by chopSizes - * @see DefaultGroovyMethods#collate(Object[], int) to chop a list into pieces of a fixed size + * @see ArrayGroovyMethods#collate(Object[], int) to chop a list into pieces of a fixed size * @since 5.0.0 */ public static List<List<Character>> chop(char[] self, int... chopSizes) { @@ -712,7 +712,7 @@ public class ArrayGroovyMethods extends DefaultGroovyMethodsSupport { * @param self a short Array to be chopped * @param chopSizes the sizes for the returned pieces * @return a list of lists chopping the original array elements into pieces determined by chopSizes - * @see DefaultGroovyMethods#collate(Object[], int) to chop a list into pieces of a fixed size + * @see ArrayGroovyMethods#collate(Object[], int) to chop a list into pieces of a fixed size * @since 5.0.0 */ public static List<List<Short>> chop(short[] self, int... chopSizes) { @@ -731,7 +731,7 @@ public class ArrayGroovyMethods extends DefaultGroovyMethodsSupport { * @param self an int Array to be chopped * @param chopSizes the sizes for the returned pieces * @return a list of lists chopping the original array elements into pieces determined by chopSizes - * @see DefaultGroovyMethods#collate(Object[], int) to chop a list into pieces of a fixed size + * @see ArrayGroovyMethods#collate(Object[], int) to chop a list into pieces of a fixed size * @since 5.0.0 */ public static List<List<Integer>> chop(int[] self, int... chopSizes) { @@ -750,7 +750,7 @@ public class ArrayGroovyMethods extends DefaultGroovyMethodsSupport { * @param self a long Array to be chopped * @param chopSizes the sizes for the returned pieces * @return a list of lists chopping the original array elements into pieces determined by chopSizes - * @see DefaultGroovyMethods#collate(Object[], int) to chop a list into pieces of a fixed size + * @see ArrayGroovyMethods#collate(Object[], int) to chop a list into pieces of a fixed size * @since 5.0.0 */ public static List<List<Long>> chop(long[] self, int... chopSizes) { @@ -769,7 +769,7 @@ public class ArrayGroovyMethods extends DefaultGroovyMethodsSupport { * @param self a float Array to be chopped * @param chopSizes the sizes for the returned pieces * @return a list of lists chopping the original array elements into pieces determined by chopSizes - * @see DefaultGroovyMethods#collate(Object[], int) to chop a list into pieces of a fixed size + * @see ArrayGroovyMethods#collate(Object[], int) to chop a list into pieces of a fixed size * @since 5.0.0 */ public static List<List<Float>> chop(float[] self, int... chopSizes) { @@ -788,7 +788,7 @@ public class ArrayGroovyMethods extends DefaultGroovyMethodsSupport { * @param self a double Array to be chopped * @param chopSizes the sizes for the returned pieces * @return a list of lists chopping the original array elements into pieces determined by chopSizes - * @see DefaultGroovyMethods#collate(Object[], int) to chop a list into pieces of a fixed size + * @see ArrayGroovyMethods#collate(Object[], int) to chop a list into pieces of a fixed size * @since 5.0.0 */ public static List<List<Double>> chop(double[] self, int... chopSizes) { @@ -4001,7 +4001,7 @@ public class ArrayGroovyMethods extends DefaultGroovyMethodsSupport { * assert array.indices == 0..1 * </pre> * - * @see DefaultGroovyMethods#getIndices(Object[]) + * @see ArrayGroovyMethods#getIndices(Object[]) * @since 3.0.8 */ public static IntRange getIndices(boolean[] self) { @@ -4016,7 +4016,7 @@ public class ArrayGroovyMethods extends DefaultGroovyMethodsSupport { * assert array.indices == 0..1 * </pre> * - * @see DefaultGroovyMethods#getIndices(Object[]) + * @see ArrayGroovyMethods#getIndices(Object[]) * @since 3.0.8 */ public static IntRange getIndices(byte[] self) { @@ -4031,7 +4031,7 @@ public class ArrayGroovyMethods extends DefaultGroovyMethodsSupport { * assert array.indices == 0..1 * </pre> * - * @see DefaultGroovyMethods#getIndices(Object[]) + * @see ArrayGroovyMethods#getIndices(Object[]) * @since 3.0.8 */ public static IntRange getIndices(char[] self) { @@ -4046,7 +4046,7 @@ public class ArrayGroovyMethods extends DefaultGroovyMethodsSupport { * assert array.indices == 0..1 * </pre> * - * @see DefaultGroovyMethods#getIndices(Object[]) + * @see ArrayGroovyMethods#getIndices(Object[]) * @since 3.0.8 */ public static IntRange getIndices(short[] self) { @@ -4061,7 +4061,7 @@ public class ArrayGroovyMethods extends DefaultGroovyMethodsSupport { * assert array.indices == 0..1 * </pre> * - * @see DefaultGroovyMethods#getIndices(Object[]) + * @see ArrayGroovyMethods#getIndices(Object[]) * @since 3.0.8 */ public static IntRange getIndices(int[] self) { @@ -4076,7 +4076,7 @@ public class ArrayGroovyMethods extends DefaultGroovyMethodsSupport { * assert array.indices == 0..1 * </pre> * - * @see DefaultGroovyMethods#getIndices(Object[]) + * @see ArrayGroovyMethods#getIndices(Object[]) * @since 3.0.8 */ public static IntRange getIndices(long[] self) { @@ -4091,7 +4091,7 @@ public class ArrayGroovyMethods extends DefaultGroovyMethodsSupport { * assert array.indices == 0..1 * </pre> * - * @see DefaultGroovyMethods#getIndices(Object[]) + * @see ArrayGroovyMethods#getIndices(Object[]) * @since 3.0.8 */ public static IntRange getIndices(float[] self) { @@ -4106,7 +4106,7 @@ public class ArrayGroovyMethods extends DefaultGroovyMethodsSupport { * assert array.indices == 0..1 * </pre> * - * @see DefaultGroovyMethods#getIndices(Object[]) + * @see ArrayGroovyMethods#getIndices(Object[]) * @since 3.0.8 */ public static IntRange getIndices(double[] self) { @@ -6076,7 +6076,7 @@ public class ArrayGroovyMethods extends DefaultGroovyMethodsSupport { case 0: return self.clone(); case 1: - return DefaultGroovyMethods.minus(self, removeMe[0]); + return ArrayGroovyMethods.minus(self, removeMe[0]); default: Collection<T> temp = DefaultGroovyMethods.minus((Collection<T>) toList(self), Arrays.asList(removeMe)); return temp.toArray(createSimilarArray(self, temp.size())); diff --git a/src/main/java/org/codehaus/groovy/runtime/typehandling/DefaultTypeTransformation.java b/src/main/java/org/codehaus/groovy/runtime/typehandling/DefaultTypeTransformation.java index f48d1143ef..a44bd80d3b 100644 --- a/src/main/java/org/codehaus/groovy/runtime/typehandling/DefaultTypeTransformation.java +++ b/src/main/java/org/codehaus/groovy/runtime/typehandling/DefaultTypeTransformation.java @@ -23,16 +23,7 @@ import groovy.lang.GString; import groovy.lang.GroovyRuntimeException; import org.codehaus.groovy.classgen.asm.util.TypeUtil; import org.codehaus.groovy.reflection.stdclasses.CachedSAMClass; -import org.codehaus.groovy.runtime.DefaultGroovyMethods; -import org.codehaus.groovy.runtime.FormatHelper; -import org.codehaus.groovy.runtime.InvokerHelper; -import org.codehaus.groovy.runtime.InvokerInvocationException; -import org.codehaus.groovy.runtime.IteratorClosureAdapter; -import org.codehaus.groovy.runtime.MethodClosure; -import org.codehaus.groovy.runtime.NullObject; -import org.codehaus.groovy.runtime.ResourceGroovyMethods; -import org.codehaus.groovy.runtime.StreamGroovyMethods; -import org.codehaus.groovy.runtime.StringGroovyMethods; +import org.codehaus.groovy.runtime.*; import java.io.File; import java.io.IOException; @@ -843,7 +834,7 @@ public class DefaultTypeTransformation { right = primitiveArrayToUnmodifiableList(right); } if (left instanceof Object[] && right instanceof List) { - return DefaultGroovyMethods.equals((Object[]) left, (List) right); + return ArrayGroovyMethods.equals((Object[]) left, (List) right); } if (left instanceof List && right instanceof Object[]) { return DefaultGroovyMethods.equals((List) left, (Object[]) right); diff --git a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java index daf7b32818..54dbcbffec 100644 --- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java +++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java @@ -47,6 +47,7 @@ import org.codehaus.groovy.ast.tools.WideningCategories; import org.codehaus.groovy.control.CompilationUnit; import org.codehaus.groovy.control.CompilerConfiguration; import org.codehaus.groovy.control.Phases; +import org.codehaus.groovy.runtime.ArrayGroovyMethods; import org.codehaus.groovy.runtime.BytecodeInterface8; import org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl; import org.codehaus.groovy.syntax.Types; @@ -1378,7 +1379,7 @@ public abstract class StaticTypeCheckingSupport { } GenericsType[] gts = type.getGenericsTypes(); - if (asBoolean(gts)) { + if (ArrayGroovyMethods.asBoolean(gts)) { gts = gts.clone(); for (int i = 0, n = gts.length; i < n; i += 1) { GenericsType gt = gts[i]; diff --git a/src/test/groovy/ClosureJavaIntegrationTest.java b/src/test/groovy/ClosureJavaIntegrationTest.java index a855ff0229..a9886bae9d 100644 --- a/src/test/groovy/ClosureJavaIntegrationTest.java +++ b/src/test/groovy/ClosureJavaIntegrationTest.java @@ -202,6 +202,6 @@ public class ClosureJavaIntegrationTest extends TestCase { return total.add(BigDecimal.ONE.divide(new BigDecimal(next))); } }; - assertTrue(DefaultTypeTransformation.compareEqual(BigDecimal.ONE, inject(c, initial, closure))); + assertTrue(DefaultTypeTransformation.compareEqual(BigDecimal.ONE, inject((Iterable<Integer>)c, initial, closure))); } } diff --git a/src/test/groovy/lang/ScriptTest.java b/src/test/groovy/lang/ScriptTest.java index ce9b497de4..9b39682b49 100644 --- a/src/test/groovy/lang/ScriptTest.java +++ b/src/test/groovy/lang/ScriptTest.java @@ -36,13 +36,13 @@ public class ScriptTest extends TestSupport { * @throws IllegalAccessException * @throws InstantiationException */ - public void testInvokeMethodFallsThroughToMethodClosureInBinding() throws IOException, CompilationFailedException, IllegalAccessException, InstantiationException { + public void testInvokeMethodFallsThroughToMethodClosureInBinding() throws IOException, CompilationFailedException, IllegalAccessException, InstantiationException, NoSuchMethodException { String text = "if (method() == 3) { println 'succeeded' }"; GroovyCodeSource codeSource = new GroovyCodeSource(text, "groovy.script", "groovy.script"); GroovyClassLoader loader = new GroovyClassLoader(Thread.currentThread().getContextClassLoader()); Class clazz = loader.parseClass(codeSource); - Script script = ((Script) clazz.newInstance()); + Script script = ((Script) clazz.getDeclaredConstructor().newInstance()); Binding binding = new Binding(); binding.setVariable("method", new MethodClosure(new Dummy(), "method")); diff --git a/src/test/org/codehaus/groovy/runtime/JdkDynamicProxyTest.java b/src/test/org/codehaus/groovy/runtime/JdkDynamicProxyTest.java index 65b4565062..8720db1fa5 100644 --- a/src/test/org/codehaus/groovy/runtime/JdkDynamicProxyTest.java +++ b/src/test/org/codehaus/groovy/runtime/JdkDynamicProxyTest.java @@ -27,8 +27,8 @@ public class JdkDynamicProxyTest extends GroovyTestCase { // Instantiate all beans. final GroovyClassLoader loader = new GroovyClassLoader(); - JdkDynamicProxyServiceBean sb1 = (JdkDynamicProxyServiceBean) JdkDynamicProxyInvocationHandler.getProxiedObject(loader.loadClass("org.codehaus.groovy.runtime.JdkDynamicProxyServiceBeanImpl1").newInstance()); - JdkDynamicProxyServiceBean sb2 = (JdkDynamicProxyServiceBean) JdkDynamicProxyInvocationHandler.getProxiedObject(loader.loadClass("org.codehaus.groovy.runtime.JdkDynamicProxyServiceBeanImpl2").newInstance()); + JdkDynamicProxyServiceBean sb1 = (JdkDynamicProxyServiceBean) JdkDynamicProxyInvocationHandler.getProxiedObject(loader.loadClass("org.codehaus.groovy.runtime.JdkDynamicProxyServiceBeanImpl1").getDeclaredConstructor().newInstance()); + JdkDynamicProxyServiceBean sb2 = (JdkDynamicProxyServiceBean) JdkDynamicProxyInvocationHandler.getProxiedObject(loader.loadClass("org.codehaus.groovy.runtime.JdkDynamicProxyServiceBeanImpl2").getDeclaredConstructor().newInstance()); // Manually wire beans together. sb1.setJdkDynamicProxyServiceBean(sb2); @@ -38,8 +38,8 @@ public class JdkDynamicProxyTest extends GroovyTestCase { public void testJdkDynamicProxyDifferentLoaders() throws Exception { // Instantiate all beans. - JdkDynamicProxyServiceBean sb1 = (JdkDynamicProxyServiceBean) JdkDynamicProxyInvocationHandler.getProxiedObject(new GroovyClassLoader().loadClass("org.codehaus.groovy.runtime.JdkDynamicProxyServiceBeanImpl1").newInstance()); - JdkDynamicProxyServiceBean sb2 = (JdkDynamicProxyServiceBean) JdkDynamicProxyInvocationHandler.getProxiedObject(new GroovyClassLoader().loadClass("org.codehaus.groovy.runtime.JdkDynamicProxyServiceBeanImpl2").newInstance()); + JdkDynamicProxyServiceBean sb1 = (JdkDynamicProxyServiceBean) JdkDynamicProxyInvocationHandler.getProxiedObject(new GroovyClassLoader().loadClass("org.codehaus.groovy.runtime.JdkDynamicProxyServiceBeanImpl1").getDeclaredConstructor().newInstance()); + JdkDynamicProxyServiceBean sb2 = (JdkDynamicProxyServiceBean) JdkDynamicProxyInvocationHandler.getProxiedObject(new GroovyClassLoader().loadClass("org.codehaus.groovy.runtime.JdkDynamicProxyServiceBeanImpl2").getDeclaredConstructor().newInstance()); // Manually wire beans together. sb1.setJdkDynamicProxyServiceBean(sb2); diff --git a/subprojects/groovy-swing/src/main/java/org/apache/groovy/swing/extensions/SwingExtensions.java b/subprojects/groovy-swing/src/main/java/org/apache/groovy/swing/extensions/SwingExtensions.java index 756f0b6c57..17e21e095c 100644 --- a/subprojects/groovy-swing/src/main/java/org/apache/groovy/swing/extensions/SwingExtensions.java +++ b/subprojects/groovy-swing/src/main/java/org/apache/groovy/swing/extensions/SwingExtensions.java @@ -19,6 +19,7 @@ package org.apache.groovy.swing.extensions; import groovy.lang.GString; +import org.codehaus.groovy.runtime.ArrayGroovyMethods; import org.codehaus.groovy.runtime.DefaultGroovyMethods; import org.codehaus.groovy.runtime.typehandling.ShortTypeHandling; @@ -87,7 +88,7 @@ public class SwingExtensions { * @since 1.6.4 */ public static Iterator<Component> iterator(Container self) { - return DefaultGroovyMethods.iterator(self.getComponents()); + return ArrayGroovyMethods.iterator(self.getComponents()); } /** @@ -659,7 +660,7 @@ public class SwingExtensions { * @since 1.6.4 */ public static Iterator<?> iterator(TreePath self) { - return DefaultGroovyMethods.iterator(self.getPath()); + return ArrayGroovyMethods.iterator(self.getPath()); } /** @@ -852,7 +853,7 @@ public class SwingExtensions { * @since 1.6.4 */ public static Iterator<Component> iterator(JMenu self) { - return DefaultGroovyMethods.iterator(self.getMenuComponents()); + return ArrayGroovyMethods.iterator(self.getMenuComponents()); } /** @@ -900,7 +901,7 @@ public class SwingExtensions { * @since 1.6.4 */ public static Iterator<MenuElement> iterator(JMenuBar self) { - return DefaultGroovyMethods.iterator(self.getSubElements()); + return ArrayGroovyMethods.iterator(self.getSubElements()); } /** @@ -981,7 +982,7 @@ public class SwingExtensions { * @since 1.6.4 */ public static Iterator<MenuElement> iterator(JPopupMenu self) { - return DefaultGroovyMethods.iterator(self.getSubElements()); + return ArrayGroovyMethods.iterator(self.getSubElements()); } /**