You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by jh...@apache.org on 2022/10/20 19:12:24 UTC
[calcite] 02/02: [CALCITE-5339] Use Method#getParameterCount rather than Method#getParameterTypes to get length
This is an automated email from the ASF dual-hosted git repository.
jhyde pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/calcite.git
commit 21110741ff104cb019b0f9de034845bf47ca8717
Author: Sergey Nuyanzin <sn...@gmail.com>
AuthorDate: Thu Oct 20 01:18:34 2022 +0200
[CALCITE-5339] Use Method#getParameterCount rather than Method#getParameterTypes to get length
The issue with Method#getParameters is that each time it
creates a new array by calling clone. It does not make sense
for the cases when only knowledge about number of parameters
is required.
Close apache/calcite#2943
---
.../org/apache/calcite/rel/metadata/janino/CacheGeneratorUtil.java | 2 +-
.../java/org/apache/calcite/schema/impl/ReflectiveFunctionBase.java | 4 ++--
.../main/java/org/apache/calcite/sql/pretty/SqlPrettyWriter.java | 6 +++---
core/src/test/java/org/apache/calcite/test/SqlTestGen.java | 2 +-
testkit/src/main/java/org/apache/calcite/test/CalciteAssert.java | 2 +-
5 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/core/src/main/java/org/apache/calcite/rel/metadata/janino/CacheGeneratorUtil.java b/core/src/main/java/org/apache/calcite/rel/metadata/janino/CacheGeneratorUtil.java
index 0ea152d323..9a0aa8ca8d 100644
--- a/core/src/main/java/org/apache/calcite/rel/metadata/janino/CacheGeneratorUtil.java
+++ b/core/src/main/java/org/apache/calcite/rel/metadata/janino/CacheGeneratorUtil.java
@@ -197,7 +197,7 @@ class CacheGeneratorUtil {
@Override void cacheKeyBlock(StringBuilder buff, Method method, int methodIndex) {
buff.append(" key = ")
.append(
- (method.getParameterTypes().length < 6
+ (method.getParameterCount() < 6
? org.apache.calcite.runtime.FlatLists.class
: ImmutableList.class).getName())
.append(".of(");
diff --git a/core/src/main/java/org/apache/calcite/schema/impl/ReflectiveFunctionBase.java b/core/src/main/java/org/apache/calcite/schema/impl/ReflectiveFunctionBase.java
index 71573e0cf5..c3a0211342 100644
--- a/core/src/main/java/org/apache/calcite/schema/impl/ReflectiveFunctionBase.java
+++ b/core/src/main/java/org/apache/calcite/schema/impl/ReflectiveFunctionBase.java
@@ -71,7 +71,7 @@ public abstract class ReflectiveFunctionBase implements Function {
*/
static boolean classHasPublicZeroArgsConstructor(Class<?> clazz) {
for (Constructor<?> constructor : clazz.getConstructors()) {
- if (constructor.getParameterTypes().length == 0
+ if (constructor.getParameterCount() == 0
&& Modifier.isPublic(constructor.getModifiers())) {
return true;
}
@@ -89,7 +89,7 @@ public abstract class ReflectiveFunctionBase implements Function {
*/
static boolean classHasPublicFunctionContextConstructor(Class<?> clazz) {
for (Constructor<?> constructor : clazz.getConstructors()) {
- if (constructor.getParameterTypes().length == 1
+ if (constructor.getParameterCount() == 1
&& constructor.getParameterTypes()[0] == FunctionContext.class
&& Modifier.isPublic(constructor.getModifiers())) {
return true;
diff --git a/core/src/main/java/org/apache/calcite/sql/pretty/SqlPrettyWriter.java b/core/src/main/java/org/apache/calcite/sql/pretty/SqlPrettyWriter.java
index 57cbf5f750..13f43e8b50 100644
--- a/core/src/main/java/org/apache/calcite/sql/pretty/SqlPrettyWriter.java
+++ b/core/src/main/java/org/apache/calcite/sql/pretty/SqlPrettyWriter.java
@@ -1388,7 +1388,7 @@ public class SqlPrettyWriter implements SqlWriter {
for (Method method : o.getClass().getMethods()) {
if (method.getName().startsWith("set")
&& (method.getReturnType() == Void.class)
- && (method.getParameterTypes().length == 1)) {
+ && (method.getParameterCount() == 1)) {
String attributeName =
stripPrefix(
method.getName(),
@@ -1397,7 +1397,7 @@ public class SqlPrettyWriter implements SqlWriter {
}
if (method.getName().startsWith("get")
&& (method.getReturnType() != Void.class)
- && (method.getParameterTypes().length == 0)) {
+ && (method.getParameterCount() == 0)) {
String attributeName =
stripPrefix(
method.getName(),
@@ -1406,7 +1406,7 @@ public class SqlPrettyWriter implements SqlWriter {
}
if (method.getName().startsWith("is")
&& (method.getReturnType() == Boolean.class)
- && (method.getParameterTypes().length == 0)) {
+ && (method.getParameterCount() == 0)) {
String attributeName =
stripPrefix(
method.getName(),
diff --git a/core/src/test/java/org/apache/calcite/test/SqlTestGen.java b/core/src/test/java/org/apache/calcite/test/SqlTestGen.java
index 791850fb6a..8e5c29b0df 100644
--- a/core/src/test/java/org/apache/calcite/test/SqlTestGen.java
+++ b/core/src/test/java/org/apache/calcite/test/SqlTestGen.java
@@ -77,7 +77,7 @@ class SqlTestGen {
if (method.getName().startsWith("test")
&& Modifier.isPublic(method.getModifiers())
&& !Modifier.isStatic(method.getModifiers())
- && (method.getParameterTypes().length == 0)
+ && (method.getParameterCount() == 0)
&& (method.getReturnType() == Void.TYPE)) {
list.add(method);
}
diff --git a/testkit/src/main/java/org/apache/calcite/test/CalciteAssert.java b/testkit/src/main/java/org/apache/calcite/test/CalciteAssert.java
index 2aa10f6b2e..82ac88b623 100644
--- a/testkit/src/main/java/org/apache/calcite/test/CalciteAssert.java
+++ b/testkit/src/main/java/org/apache/calcite/test/CalciteAssert.java
@@ -723,7 +723,7 @@ public class CalciteAssert {
loop:
for (Method method1 : aClass.getMethods()) {
if (method1.getName().equals(methodName)
- && method1.getParameterTypes().length == args.length
+ && method1.getParameterCount() == args.length
&& Modifier.isPublic(method1.getDeclaringClass().getModifiers())) {
for (Pair<Object, Class> pair
: Pair.zip(args, (Class[]) method1.getParameterTypes())) {