Skip to content

Commit

Permalink
make fields public
Browse files Browse the repository at this point in the history
  • Loading branch information
jyrimatti committed Jun 28, 2024
1 parent 7fe36a6 commit 1f6c51b
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 15 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>fi.solita.utils</groupId>
<artifactId>meta-utils</artifactId>
<version>0.12.33</version>
<version>0.12.35</version>
<build>
<resources>
<resource>
Expand Down Expand Up @@ -36,7 +36,7 @@
<dependency>
<groupId>fi.solita.utils</groupId>
<artifactId>functional-utils</artifactId>
<version>0.12.47</version>
<version>0.12.52</version>
</dependency>

<dependency>
Expand Down
29 changes: 19 additions & 10 deletions src/main/java/fi/solita/utils/meta/CommonMetadataProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -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";
Expand All @@ -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("<not enabled>"); }
public boolean methodsAsFunctionsEnabled() { return Boolean.parseBoolean(findOption(Options.methodsAsFunctionsEnabled, "true")); }
public boolean constructorsAsFunctionsEnabled() { return Boolean.parseBoolean(findOption(Options.constructorsAsFunctionsEnabled, "true")); }
Expand All @@ -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)) {
Expand Down Expand Up @@ -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();
Expand All @@ -189,6 +194,10 @@ public boolean onlyPublicMembers() {
public boolean includePrivateMembers() {
return includePrivateMembers;
}
@Override
public boolean makeFieldsPublic() {
return makeFieldsPublic;
}
public String generatedPackagePattern() {
return generatedPackagePattern;
}
Expand Down Expand Up @@ -299,9 +308,9 @@ public boolean doProcess(RoundEnvironment roundEnv) {
List<String> content = newList(map(padding, concat(flatMap(Helpers.<List<String>>right(), elemData), flatMap(Helpers.<List<String>>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<String> extendedClassName = extendClassNamePattern.matcher(superclassName).matches() ? Some(genClassNamePat.replace("{}", superclassName)) : Option.<String>None();
Option<String> extendedClassName = extendClassNamePattern.matcher(superclassName).matches() ? Some(generatedClassName(genClassNamePat, superclassName)) : Option.<String>None();
long time4 = System.nanoTime();
if (!content.isEmpty() || Helpers.isAbstract(element)) {
// always produce metaclass for abstract classes in case they are inherited
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -472,10 +485,6 @@ public List<String> getAdditionalBodyLinesForMethods(ExecutableElement element)
return emptyList();
}
@Override
public boolean makeFieldsPublic() {
return false;
}
@Override
public boolean generateMemberInitializerForMethods() {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ public Iterable<String> apply(Helpers.EnvDependent helper, Options options, Map.
Some("}")
);

@SuppressWarnings("unchecked")
Iterable<String> res = concat(
hasRawTypes
? Some("@SuppressWarnings(\"rawtypes\")")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,6 @@ public String transform(String candidate) {

String initParams = "(" + enclosingElementQualifiedNameImported + ".class, \"" + fieldName + "\")";

@SuppressWarnings("unchecked")
Iterable<String> res = concat(
needsToBeFunction
? newList(enclosingElementQualifiedNameImported.equals(enclosingElementGenericQualifiedNameImported) ? "" : "@SuppressWarnings(\"rawtypes\")",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,6 @@ public Iterable<String> 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<String> res = concat(
isEmpty(warnings)
? None
Expand Down

0 comments on commit 1f6c51b

Please sign in to comment.