From 1f6c51bd849f58ec6f9dca1e9d088a60d86ab150 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jyri-Matti=20La=CC=88hteenma=CC=88ki?= Date: Fri, 28 Jun 2024 11:38:15 +0300 Subject: [PATCH] make fields public --- pom.xml | 4 +-- .../utils/meta/CommonMetadataProcessor.java | 29 ++++++++++++------- .../utils/meta/CommonMetadataProcessor2.java | 1 + .../utils/meta/CommonMetadataProcessor3.java | 1 + .../generators/ConstructorsAsFunctions.java | 1 - .../generators/InstanceFieldsAsFunctions.java | 1 - .../meta/generators/MethodsAsFunctions.java | 1 - 7 files changed, 23 insertions(+), 15 deletions(-) diff --git a/pom.xml b/pom.xml index 58c5d35..3ec75df 100644 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ 4.0.0 fi.solita.utils meta-utils - 0.12.33 + 0.12.35 @@ -36,7 +36,7 @@ fi.solita.utils functional-utils - 0.12.47 + 0.12.52 diff --git a/src/main/java/fi/solita/utils/meta/CommonMetadataProcessor.java b/src/main/java/fi/solita/utils/meta/CommonMetadataProcessor.java index 1406d6f..796a25f 100644 --- a/src/main/java/fi/solita/utils/meta/CommonMetadataProcessor.java +++ b/src/main/java/fi/solita/utils/meta/CommonMetadataProcessor.java @@ -19,7 +19,8 @@ import static fi.solita.utils.meta.Helpers.element2NestedClasses; import static fi.solita.utils.meta.Helpers.getPackageName; import static fi.solita.utils.meta.Helpers.nanosToMillis; -import static fi.solita.utils.meta.Helpers.nonGeneratedElements; +import static fi.solita.utils.meta.Helpers.generatedElements; +import static fi.solita.utils.meta.Helpers.forcedElements; import static fi.solita.utils.meta.Helpers.padding; import static fi.solita.utils.meta.Helpers.privateElement; import static fi.solita.utils.meta.Helpers.publicElement; @@ -71,6 +72,7 @@ "CommonMetadataProcessor." + CommonMetadataProcessor.Options.excludesRegex, "CommonMetadataProcessor." + CommonMetadataProcessor.Options.onlyPublicMembers, "CommonMetadataProcessor." + CommonMetadataProcessor.Options.includePrivateMembers, + "CommonMetadataProcessor." + CommonMetadataProcessor.Options.makeFieldsPublic, "CommonMetadataProcessor." + CommonMetadataProcessor.Options.includesAnnotation, "CommonMetadataProcessor." + CommonMetadataProcessor.Options.excludesAnnotation, "CommonMetadataProcessor." + CommonMetadataProcessor.Options.methodsAsFunctionsEnabled, @@ -90,6 +92,7 @@ public static class Options { public static final String excludesRegex = "excludesRegex"; public static final String onlyPublicMembers = "onlyPublicMembers"; public static final String includePrivateMembers = "includePrivateMembers"; + public static final String makeFieldsPublic = "makeFieldsPublic"; public static final String includesAnnotation = "includesAnnotation"; public static final String excludesAnnotation = "excludesAnnotation"; public static final String methodsAsFunctionsEnabled = "methodsAsFunctionsEnabled"; @@ -110,10 +113,11 @@ protected boolean enabledByDefault() { public Pattern excludesRegex() { return Pattern.compile(findOption(Options.excludesRegex, ".*_")); } public boolean onlyPublicMembers() { return Boolean.parseBoolean(findOption(Options.onlyPublicMembers, "false")); } public boolean includePrivateMembers() { return Boolean.parseBoolean(findOption(Options.includePrivateMembers, "false")); } + public boolean makeFieldsPublic() { return Boolean.parseBoolean(findOption(Options.makeFieldsPublic, "false")); } public String generatedClassNamePattern() { return findOption(Options.generatedClassNamePattern, "{}_"); } public String generatedPackagePattern() { return findOption(Options.generatedPackagePattern, "{}"); } public String includesAnnotation() { return findOption(Options.includesAnnotation, ""); } - public String excludesAnnotation() { return findOption(Options.excludesAnnotation, mkString(",", newList("javax.annotation.processing.Generated", "javax.annotation.Generated", "javax.persistence.Entity", "javax.persistence.MappedSuperclass", "javax.persistence.Embeddable", NoMetadataGeneration.class.getName()))); } + public String excludesAnnotation() { return findOption(Options.excludesAnnotation, mkString(",", newList("javax.persistence.Entity", "javax.persistence.MappedSuperclass", "javax.persistence.Embeddable", NoMetadataGeneration.class.getName()))); } public Pattern extendClassNamePattern() { return Pattern.compile(""); } public boolean methodsAsFunctionsEnabled() { return Boolean.parseBoolean(findOption(Options.methodsAsFunctionsEnabled, "true")); } public boolean constructorsAsFunctionsEnabled() { return Boolean.parseBoolean(findOption(Options.constructorsAsFunctionsEnabled, "true")); } @@ -133,8 +137,8 @@ public boolean accept(Element candidate) { //msg.printMessage(Kind.OTHER, "Skipping due to not TypeElement: " + candidate.getSimpleName()); return false; } - if (!nonGeneratedElements.accept(candidate) ) { - //msg.printMessage(Kind.OTHER, "Skipping due to being generated element: " + candidate.getSimpleName()); + if (generatedElements.accept(candidate) && !forcedElements.accept(candidate)) { + //msg.printMessage(Kind.OTHER, "Skipping due to being generated non-forced element: " + candidate.getSimpleName()); return false; } if (!includeAllByAnnotation.accept(candidate) && !withAnnotations(includesAnnotation(), true).accept(candidate)) { @@ -174,6 +178,7 @@ public boolean accept(Element candidate) { public OPTIONS generatorOptions() { final boolean onlyPublicMembers = CommonMetadataProcessor.this.onlyPublicMembers(); final boolean includePrivateMembers = CommonMetadataProcessor.this.includePrivateMembers(); + final boolean makeFieldsPublic = CommonMetadataProcessor.this.makeFieldsPublic(); final String generatedPackagePattern = CommonMetadataProcessor.this.generatedPackagePattern(); final String generatedClassNamePattern = CommonMetadataProcessor.this.generatedClassNamePattern(); final boolean methodsAsFunctionsEnabled = CommonMetadataProcessor.this.methodsAsFunctionsEnabled(); @@ -189,6 +194,10 @@ public boolean onlyPublicMembers() { public boolean includePrivateMembers() { return includePrivateMembers; } + @Override + public boolean makeFieldsPublic() { + return makeFieldsPublic; + } public String generatedPackagePattern() { return generatedPackagePattern; } @@ -299,9 +308,9 @@ public boolean doProcess(RoundEnvironment roundEnv) { List content = newList(map(padding, concat(flatMap(Helpers.>right(), elemData), flatMap(Helpers.>right(), nestedData)))); String genPackage = genPackagePat.replace("{}", getPackageName(element)); - String genClassName = genClassNamePat.replace("{}", element.getSimpleName().toString()); + String genClassName = generatedClassName(genClassNamePat, element.getSimpleName().toString()); String superclassName = removeGenericPart.apply(element.getSuperclass().toString()); - Option extendedClassName = extendClassNamePattern.matcher(superclassName).matches() ? Some(genClassNamePat.replace("{}", superclassName)) : Option.None(); + Option extendedClassName = extendClassNamePattern.matcher(superclassName).matches() ? Some(generatedClassName(genClassNamePat, superclassName)) : Option.None(); long time4 = System.nanoTime(); if (!content.isEmpty() || Helpers.isAbstract(element)) { // always produce metaclass for abstract classes in case they are inherited @@ -332,6 +341,10 @@ public boolean doProcess(RoundEnvironment roundEnv) { } return false; } + + public static String generatedClassName(String genClassNamePat, String className) { + return genClassNamePat.replace("{}", className); + } public static abstract class CombinedGeneratorOptions implements InstanceFieldsAsFunctions.Options, MethodsAsFunctions.Options, ConstructorsAsFunctions.Options, InstanceFieldsAsEnum.Options, InstanceFieldsAsTuple.Options { @Override @@ -472,10 +485,6 @@ public List getAdditionalBodyLinesForMethods(ExecutableElement element) return emptyList(); } @Override - public boolean makeFieldsPublic() { - return false; - } - @Override public boolean generateMemberInitializerForMethods() { return true; } diff --git a/src/main/java/fi/solita/utils/meta/CommonMetadataProcessor2.java b/src/main/java/fi/solita/utils/meta/CommonMetadataProcessor2.java index 135cf52..f64e100 100644 --- a/src/main/java/fi/solita/utils/meta/CommonMetadataProcessor2.java +++ b/src/main/java/fi/solita/utils/meta/CommonMetadataProcessor2.java @@ -14,6 +14,7 @@ "CommonMetadataProcessor2." + CommonMetadataProcessor.Options.excludesRegex, "CommonMetadataProcessor2." + CommonMetadataProcessor.Options.onlyPublicMembers, "CommonMetadataProcessor2." + CommonMetadataProcessor.Options.includePrivateMembers, + "CommonMetadataProcessor2." + CommonMetadataProcessor.Options.makeFieldsPublic, "CommonMetadataProcessor2." + CommonMetadataProcessor.Options.includesAnnotation, "CommonMetadataProcessor2." + CommonMetadataProcessor.Options.excludesAnnotation, "CommonMetadataProcessor2." + CommonMetadataProcessor.Options.methodsAsFunctionsEnabled, diff --git a/src/main/java/fi/solita/utils/meta/CommonMetadataProcessor3.java b/src/main/java/fi/solita/utils/meta/CommonMetadataProcessor3.java index f3d931a..0b0982b 100644 --- a/src/main/java/fi/solita/utils/meta/CommonMetadataProcessor3.java +++ b/src/main/java/fi/solita/utils/meta/CommonMetadataProcessor3.java @@ -14,6 +14,7 @@ "CommonMetadataProcessor3." + CommonMetadataProcessor.Options.excludesRegex, "CommonMetadataProcessor3." + CommonMetadataProcessor.Options.onlyPublicMembers, "CommonMetadataProcessor3." + CommonMetadataProcessor.Options.includePrivateMembers, + "CommonMetadataProcessor3." + CommonMetadataProcessor.Options.makeFieldsPublic, "CommonMetadataProcessor3." + CommonMetadataProcessor.Options.includesAnnotation, "CommonMetadataProcessor3." + CommonMetadataProcessor.Options.excludesAnnotation, "CommonMetadataProcessor3." + CommonMetadataProcessor.Options.methodsAsFunctionsEnabled, diff --git a/src/main/java/fi/solita/utils/meta/generators/ConstructorsAsFunctions.java b/src/main/java/fi/solita/utils/meta/generators/ConstructorsAsFunctions.java index f930b16..d748ffe 100644 --- a/src/main/java/fi/solita/utils/meta/generators/ConstructorsAsFunctions.java +++ b/src/main/java/fi/solita/utils/meta/generators/ConstructorsAsFunctions.java @@ -137,7 +137,6 @@ public Iterable apply(Helpers.EnvDependent helper, Options options, Map. Some("}") ); - @SuppressWarnings("unchecked") Iterable res = concat( hasRawTypes ? Some("@SuppressWarnings(\"rawtypes\")") diff --git a/src/main/java/fi/solita/utils/meta/generators/InstanceFieldsAsFunctions.java b/src/main/java/fi/solita/utils/meta/generators/InstanceFieldsAsFunctions.java index db4f2c3..7a6c3e0 100644 --- a/src/main/java/fi/solita/utils/meta/generators/InstanceFieldsAsFunctions.java +++ b/src/main/java/fi/solita/utils/meta/generators/InstanceFieldsAsFunctions.java @@ -203,7 +203,6 @@ public String transform(String candidate) { String initParams = "(" + enclosingElementQualifiedNameImported + ".class, \"" + fieldName + "\")"; - @SuppressWarnings("unchecked") Iterable res = concat( needsToBeFunction ? newList(enclosingElementQualifiedNameImported.equals(enclosingElementGenericQualifiedNameImported) ? "" : "@SuppressWarnings(\"rawtypes\")", diff --git a/src/main/java/fi/solita/utils/meta/generators/MethodsAsFunctions.java b/src/main/java/fi/solita/utils/meta/generators/MethodsAsFunctions.java index 9bd231b..f6cab68 100644 --- a/src/main/java/fi/solita/utils/meta/generators/MethodsAsFunctions.java +++ b/src/main/java/fi/solita/utils/meta/generators/MethodsAsFunctions.java @@ -218,7 +218,6 @@ public Iterable apply(Helpers.EnvDependent helper, Options options, Set< isPrivate && (method.getReturnType().getKind() == TypeKind.TYPEVAR || hasNonQmarkGenerics(returnType)) ? Some("\"unchecked\"") : None, hasRawTypes ? Some("\"rawtypes\"") : None); - @SuppressWarnings("unchecked") Iterable res = concat( isEmpty(warnings) ? None