From 42e815aeaee8bd5ec4a70a282208a3689f9828c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jyri-Matti=20La=CC=88hteenma=CC=88ki?= Date: Tue, 2 Apr 2024 15:14:18 +0300 Subject: [PATCH] some helpers --- pom.xml | 2 +- src/main/java/fi/solita/utils/meta/Helpers.java | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index d4d7f9d..58c5d35 100644 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ 4.0.0 fi.solita.utils meta-utils - 0.12.32 + 0.12.33 diff --git a/src/main/java/fi/solita/utils/meta/Helpers.java b/src/main/java/fi/solita/utils/meta/Helpers.java index fcfd56b..5005e61 100644 --- a/src/main/java/fi/solita/utils/meta/Helpers.java +++ b/src/main/java/fi/solita/utils/meta/Helpers.java @@ -7,9 +7,9 @@ import static fi.solita.utils.functional.Functional.concat; import static fi.solita.utils.functional.Functional.exists; import static fi.solita.utils.functional.Functional.filter; +import static fi.solita.utils.functional.Functional.flatMap; import static fi.solita.utils.functional.Functional.head; import static fi.solita.utils.functional.Functional.map; -import static fi.solita.utils.functional.Functional.flatMap; import static fi.solita.utils.functional.Functional.reduce; import static fi.solita.utils.functional.Functional.zip; import static fi.solita.utils.functional.FunctionalC.reverse; @@ -97,6 +97,10 @@ public static final String containedType(Element e) { return containedType(type); } + public static final String containedType(TypeMirror t) { + return containedType(typeMirror2GenericQualifiedName.apply(t)); + } + public static final String containedType(String type) { // FIXME: fancier way to do this? return type.substring(type.indexOf('<')+1, type.lastIndexOf('>')); @@ -483,7 +487,7 @@ public boolean accept(Element candidate) { return candidate.getModifiers().contains(Modifier.STATIC); } }; - + public static final boolean isPrivate(Element e) { return e.getModifiers().contains(Modifier.PRIVATE); } @@ -545,6 +549,15 @@ public final boolean isSameType(TypeMirror type, Class other) { public final boolean throwsCheckedExceptions(ExecutableElement e) { return exists(not(uncheckedExceptions), e.getThrownTypes()); } + + public final Iterable ancestorsInheriting(TypeMirror type, final Class clazz) { + return filter(new Predicate() { + @Override + public boolean accept(TypeMirror candidate) { + return isSubtype(candidate, clazz); + } + }, typeUtils.directSupertypes(type)); + } } public static final Transformer nanosToMillis = new Transformer() {