Skip to content

Commit

Permalink
add annotation to force generation for a class
Browse files Browse the repository at this point in the history
  • Loading branch information
jyrimatti committed Jan 4, 2024
1 parent 05ce714 commit a9197d4
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 3 deletions.
20 changes: 20 additions & 0 deletions .project
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,24 @@
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
<filteredResources>
<filter>
<id>1683121120929</id>
<name></name>
<type>10</type>
<matcher>
<id>org.eclipse.ui.ide.multiFilter</id>
<arguments>1.0-name-matches-false-false-bin</arguments>
</matcher>
</filter>
<filter>
<id>1683121120939</id>
<name></name>
<type>10</type>
<matcher>
<id>org.eclipse.ui.ide.multiFilter</id>
<arguments>1.0-name-matches-false-false-out</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>
2 changes: 1 addition & 1 deletion 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.26</version>
<version>0.12.27</version>
<build>
<resources>
<resource>
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/fi/solita/utils/meta/ForceMetadataGeneration.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package fi.solita.utils.meta;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* Force specified metadata generation even if it is configured disabled globally
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface ForceMetadataGeneration {
boolean constructorsAsFunctions() default false;
boolean methodsAsFunctions() default false;
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
import fi.solita.utils.functional.Apply;
import fi.solita.utils.functional.Function1;
import fi.solita.utils.functional.Function3;
import fi.solita.utils.functional.Option;
import fi.solita.utils.meta.ForceMetadataGeneration;
import fi.solita.utils.meta.Helpers;

public class ConstructorsAsFunctions extends Generator<ConstructorsAsFunctions.Options> {
Expand All @@ -68,7 +70,7 @@ public static interface Options extends GeneratorOptions {

@Override
public Iterable<String> apply(ProcessingEnvironment processingEnv, Options options, TypeElement source) {
if (!options.constructorsAsFunctionsEnabled()) {
if (!options.constructorsAsFunctionsEnabled() && (source.getAnnotation(ForceMetadataGeneration.class) == null || !source.getAnnotation(ForceMetadataGeneration.class).constructorsAsFunctions())) {
return emptyList();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
import fi.solita.utils.functional.Pair;
import fi.solita.utils.functional.Predicate;
import fi.solita.utils.functional.Transformer;
import fi.solita.utils.meta.ForceMetadataGeneration;
import fi.solita.utils.meta.Helpers;

public class MethodsAsFunctions extends Generator<MethodsAsFunctions.Options> {
Expand All @@ -90,7 +91,7 @@ public static interface Options extends GeneratorOptions {

@Override
public Iterable<String> apply(ProcessingEnvironment processingEnv, Options options, TypeElement source) {
if (!options.methodsAsFunctionsEnabled()) {
if (!options.methodsAsFunctionsEnabled() && (source.getAnnotation(ForceMetadataGeneration.class) == null || !source.getAnnotation(ForceMetadataGeneration.class).methodsAsFunctions())) {
return emptyList();
}

Expand Down

0 comments on commit a9197d4

Please sign in to comment.