From 669e7abee8e8bafa05d11b77dd02d02533ffba26 Mon Sep 17 00:00:00 2001 From: Jan Ouwens Date: Wed, 19 Jan 2022 09:13:58 +0100 Subject: [PATCH] Adds multi-release logic --- .../internal/reflection/RecordsHelper.java | 10 ++++++++++ .../reflection/SealedClassesHelper.java | 10 ++++++++++ equalsverifier-aggregator/pom.xml | 8 ++++---- .../internal/reflection/ClassAccessor.java | 20 ++----------------- .../internal/reflection/RecordsHelper.java | 10 ++++++++++ .../reflection/SealedClassesHelper.java | 10 ++++++++++ pom.xml | 2 +- 7 files changed, 47 insertions(+), 23 deletions(-) create mode 100644 equalsverifier-16/src/main/java/nl/jqno/equalsverifier/internal/reflection/RecordsHelper.java create mode 100644 equalsverifier-17/src/main/java/nl/jqno/equalsverifier/internal/reflection/SealedClassesHelper.java create mode 100644 equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/RecordsHelper.java create mode 100644 equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/SealedClassesHelper.java diff --git a/equalsverifier-16/src/main/java/nl/jqno/equalsverifier/internal/reflection/RecordsHelper.java b/equalsverifier-16/src/main/java/nl/jqno/equalsverifier/internal/reflection/RecordsHelper.java new file mode 100644 index 000000000..404560797 --- /dev/null +++ b/equalsverifier-16/src/main/java/nl/jqno/equalsverifier/internal/reflection/RecordsHelper.java @@ -0,0 +1,10 @@ +package nl.jqno.equalsverifier.internal.reflection; + +public final class RecordsHelper { + + private RecordsHelper() {} + + public static boolean isRecord(Class type) { + return type.isRecord(); + } +} diff --git a/equalsverifier-17/src/main/java/nl/jqno/equalsverifier/internal/reflection/SealedClassesHelper.java b/equalsverifier-17/src/main/java/nl/jqno/equalsverifier/internal/reflection/SealedClassesHelper.java new file mode 100644 index 000000000..bf573e9d2 --- /dev/null +++ b/equalsverifier-17/src/main/java/nl/jqno/equalsverifier/internal/reflection/SealedClassesHelper.java @@ -0,0 +1,10 @@ +package nl.jqno.equalsverifier.internal.reflection; + +public final class SealedClassesHelper { + + private SealedClassesHelper() {} + + public static boolean isSealed(Class type) { + return type.isSealed(); + } +} diff --git a/equalsverifier-aggregator/pom.xml b/equalsverifier-aggregator/pom.xml index 44e973ac1..e48d47e34 100644 --- a/equalsverifier-aggregator/pom.xml +++ b/equalsverifier-aggregator/pom.xml @@ -59,8 +59,8 @@ - - + + @@ -82,8 +82,8 @@ - - + + diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/ClassAccessor.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/ClassAccessor.java index 942ae8d5f..70b677362 100644 --- a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/ClassAccessor.java +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/ClassAccessor.java @@ -3,7 +3,6 @@ import static nl.jqno.equalsverifier.internal.util.Rethrow.rethrow; import java.lang.reflect.Field; -import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.util.Set; import java.util.function.Predicate; @@ -53,11 +52,7 @@ public Class getType() { * @return true if T is a Java Record. */ public boolean isRecord() { - Class record = Util.classForName("java.lang.Record"); - if (record == null) { - return false; - } - return record.isAssignableFrom(type); + return RecordsHelper.isRecord(type); } /** @@ -66,18 +61,7 @@ public boolean isRecord() { * @return true if T is a sealed class */ public boolean isSealed() { - int version = Integer.parseInt(System.getProperty("java.version").replaceAll("[.-].*", "")); - if (version >= 17) { - try { - Class clazz = Util.classForName("java.lang.Class"); - Method isSealed = clazz.getDeclaredMethod("isSealed"); - Object result = isSealed.invoke(type); - return result == null ? false : (Boolean) result; - } catch (ReflectiveOperationException | SecurityException e) { - return false; - } - } - return false; + return SealedClassesHelper.isSealed(type); } /** diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/RecordsHelper.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/RecordsHelper.java new file mode 100644 index 000000000..e32661185 --- /dev/null +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/RecordsHelper.java @@ -0,0 +1,10 @@ +package nl.jqno.equalsverifier.internal.reflection; + +public final class RecordsHelper { + + private RecordsHelper() {} + + public static boolean isRecord(Class type) { + return false; + } +} diff --git a/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/SealedClassesHelper.java b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/SealedClassesHelper.java new file mode 100644 index 000000000..9548e3628 --- /dev/null +++ b/equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/SealedClassesHelper.java @@ -0,0 +1,10 @@ +package nl.jqno.equalsverifier.internal.reflection; + +public final class SealedClassesHelper { + + private SealedClassesHelper() {} + + public static boolean isSealed(Class type) { + return false; + } +} diff --git a/pom.xml b/pom.xml index 3ddf95ff0..d8f3d4f07 100644 --- a/pom.xml +++ b/pom.xml @@ -70,7 +70,7 @@ ${argline.module} ${argline.preview} ${argline.experimental} - 0.94 + 0.97 9.2.1 3.1.2