diff --git a/build.gradle b/build.gradle index e22e3deb1..9e276ea0f 100644 --- a/build.gradle +++ b/build.gradle @@ -127,7 +127,7 @@ subprojects { destinationFile = file("${buildDir}/jacoco/test.exec") } - reports.html.required = false + reports.html.required = true } tasks.withType(JavaCompile).each { diff --git a/processor/build.gradle b/processor/build.gradle index 5262fc300..e1dca11e4 100644 --- a/processor/build.gradle +++ b/processor/build.gradle @@ -6,6 +6,8 @@ dependencies { test { useJUnitPlatform() + reports.html.required = true + jvmArgs([ '--add-opens=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED', '--add-opens=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED', diff --git a/processor/src/main/java/com/github/tonivade/purefun/HigherKindProcessor.java b/processor/src/main/java/com/github/tonivade/purefun/processor/HigherKindProcessor.java similarity index 98% rename from processor/src/main/java/com/github/tonivade/purefun/HigherKindProcessor.java rename to processor/src/main/java/com/github/tonivade/purefun/processor/HigherKindProcessor.java index 0b45beac4..c09c7ab08 100644 --- a/processor/src/main/java/com/github/tonivade/purefun/HigherKindProcessor.java +++ b/processor/src/main/java/com/github/tonivade/purefun/processor/HigherKindProcessor.java @@ -2,7 +2,7 @@ * Copyright (c) 2018-2023, Antonio Gabriel Muñoz Conejo * Distributed under the terms of the MIT License */ -package com.github.tonivade.purefun; +package com.github.tonivade.purefun.processor; import static java.lang.String.format; import static java.util.stream.Collectors.joining; @@ -20,10 +20,12 @@ import javax.tools.Diagnostic; import javax.tools.JavaFileObject; +import com.github.tonivade.purefun.HigherKind; + @SupportedAnnotationTypes("com.github.tonivade.purefun.HigherKind") public class HigherKindProcessor extends AbstractProcessor { - private static final String GENERATED = "@Generated(\"com.github.tonivade.purefun.HigherKindProcessor\")"; + private static final String GENERATED = "@Generated(\"com.github.tonivade.purefun.processor.HigherKindProcessor\")"; private static final String JAVAX_ANNOTATION_GENERATED = "javax.annotation.Generated"; private static final String JAVAX_ANNOTATION_PROCESSING_GENERATED = "javax.annotation.processing.Generated"; @@ -59,9 +61,9 @@ private void generate(TypeElement element) throws IOException { int lastIndexOf = qualifiedName.lastIndexOf('.'); String packageName; String className; - + HigherKind annotation = element.getAnnotation(HigherKind.class); - + if (lastIndexOf > 0) { packageName = qualifiedName.substring(0, lastIndexOf); className = qualifiedName.substring(lastIndexOf + 1); @@ -215,7 +217,7 @@ private static void narrowK2(PrintWriter writer, String className, String aType, private static void narrowK3(PrintWriter writer, String className, String aType, String bType, String cType, String hkt) { narrowK(writer, "<" + aType + ", " + bType + ", " + cType + ">", className + "", hkt); } - + private static void narrowK(PrintWriter writer, String types, String returnType, String param) { writer.println(" @SuppressWarnings(\"unchecked\")"); writer.println(" static " + types + " " + returnType + " narrowK(" + param + " hkt) {"); @@ -223,15 +225,15 @@ private static void narrowK(PrintWriter writer, String types, String returnType, writer.println(" }"); writer.println(); } - + private static void toTypeOf1(PrintWriter writer, String className, String aType, String hkt, String typeOf) { toTypeOf(writer, "<" + aType + ">", className + "", hkt, typeOf, className); } - + private static void toTypeOf2(PrintWriter writer, String className, String aType, String bType, String hkt, String typeOf) { toTypeOf(writer, "<" + aType + ", " + bType + ">", className + "", hkt, typeOf, className); } - + private static void toTypeOf3(PrintWriter writer, String className, String aType, String bType, String cType, String hkt, String typeOf) { toTypeOf(writer, "<" + aType + ", " + bType + ", " + cType + ">", className + "", hkt, typeOf, className); } diff --git a/processor/src/main/resources/META-INF/services/javax.annotation.processing.Processor b/processor/src/main/resources/META-INF/services/javax.annotation.processing.Processor index 16bbbf73e..4b1d0e788 100644 --- a/processor/src/main/resources/META-INF/services/javax.annotation.processing.Processor +++ b/processor/src/main/resources/META-INF/services/javax.annotation.processing.Processor @@ -1 +1 @@ -com.github.tonivade.purefun.HigherKindProcessor +com.github.tonivade.purefun.processor.HigherKindProcessor diff --git a/processor/src/test/java/com/github/tonivade/purefun/HigherKindProcessorTest.java b/processor/src/test/java/com/github/tonivade/purefun/processor/HigherKindProcessorTest.java similarity index 91% rename from processor/src/test/java/com/github/tonivade/purefun/HigherKindProcessorTest.java rename to processor/src/test/java/com/github/tonivade/purefun/processor/HigherKindProcessorTest.java index 3c026b2f5..99cb9db49 100644 --- a/processor/src/test/java/com/github/tonivade/purefun/HigherKindProcessorTest.java +++ b/processor/src/test/java/com/github/tonivade/purefun/processor/HigherKindProcessorTest.java @@ -2,7 +2,7 @@ * Copyright (c) 2018-2023, Antonio Gabriel Muñoz Conejo * Distributed under the terms of the MIT License */ -package com.github.tonivade.purefun; +package com.github.tonivade.purefun.processor; import static com.google.common.truth.Truth.assert_; import static com.google.testing.compile.JavaFileObjects.forSourceLines; @@ -18,7 +18,7 @@ public class HigherKindProcessorTest { "import com.github.tonivade.purefun.Witness;", "import javax.annotation.processing.Generated;", - "@Generated(\"com.github.tonivade.purefun.HigherKindProcessor\")", + "@Generated(\"com.github.tonivade.purefun.processor.HigherKindProcessor\")", "public final class Foo_ implements Witness {", "private Foo_() {}", "}"); @@ -41,7 +41,7 @@ public void compilesKind1() { "import com.github.tonivade.purefun.Fixer;", "import javax.annotation.processing.Generated;", - "@Generated(\"com.github.tonivade.purefun.HigherKindProcessor\")", + "@Generated(\"com.github.tonivade.purefun.processor.HigherKindProcessor\")", "public sealed interface FooOf extends Kind permits Foo {", "@SuppressWarnings(\"unchecked\")", @@ -74,7 +74,7 @@ public void compilesKind1NoPackage() { "import com.github.tonivade.purefun.Fixer;", "import javax.annotation.processing.Generated;", - "@Generated(\"com.github.tonivade.purefun.HigherKindProcessor\")", + "@Generated(\"com.github.tonivade.purefun.processor.HigherKindProcessor\")", "public sealed interface FooOf extends Kind permits Foo {", "@SuppressWarnings(\"unchecked\")", @@ -92,7 +92,7 @@ public void compilesKind1NoPackage() { "import com.github.tonivade.purefun.Witness;", "import javax.annotation.processing.Generated;", - "@Generated(\"com.github.tonivade.purefun.HigherKindProcessor\")", + "@Generated(\"com.github.tonivade.purefun.processor.HigherKindProcessor\")", "public final class Foo_ implements Witness {", "private Foo_() {}", "}"); @@ -119,7 +119,7 @@ public void compilesKind1Bounds() { "import com.github.tonivade.purefun.Fixer;", "import javax.annotation.processing.Generated;", - "@Generated(\"com.github.tonivade.purefun.HigherKindProcessor\")", + "@Generated(\"com.github.tonivade.purefun.processor.HigherKindProcessor\")", "public sealed interface FooOf extends Kind permits Foo {", "@SuppressWarnings(\"unchecked\")", @@ -188,14 +188,14 @@ public void compilesKind2() { "import com.github.tonivade.purefun.Fixer;", "import javax.annotation.processing.Generated;", - "@Generated(\"com.github.tonivade.purefun.HigherKindProcessor\")", + "@Generated(\"com.github.tonivade.purefun.processor.HigherKindProcessor\")", "public sealed interface FooOf extends Kind, B> permits Foo {", "@SuppressWarnings(\"unchecked\")", "static Foo narrowK(Kind, ? extends B> hkt) {", "return (Foo) hkt;", "}", - + "static Fixer, B>, Foo> toFoo() {", "return FooOf::narrowK;", "}", @@ -225,14 +225,14 @@ public void compilesKind3() { "import com.github.tonivade.purefun.Fixer;", "import javax.annotation.processing.Generated;", - "@Generated(\"com.github.tonivade.purefun.HigherKindProcessor\")", + "@Generated(\"com.github.tonivade.purefun.processor.HigherKindProcessor\")", "public sealed interface FooOf extends Kind, B>, C> permits Foo {", "@SuppressWarnings(\"unchecked\")", "static Foo narrowK(Kind, B>, ? extends C> hkt) {", "return (Foo) hkt;", "}", - + "static Fixer, B>, C>, Foo> toFoo() {", "return FooOf::narrowK;", "}",