From 48ecf04d9d1240dec9eb9801d1f80e66e8f281de Mon Sep 17 00:00:00 2001 From: jbock Date: Mon, 25 Dec 2023 21:13:35 +0100 Subject: [PATCH] update processor --- compiler/build.gradle | 2 +- .../simple/processor/ContextComponent.java | 17 ----------------- .../jbock/simple/processor/writing/Context.java | 2 +- .../simple/processor/writing/ContextModule.java | 16 +++++++++++++--- 4 files changed, 15 insertions(+), 22 deletions(-) diff --git a/compiler/build.gradle b/compiler/build.gradle index 98417bd..436c7a5 100644 --- a/compiler/build.gradle +++ b/compiler/build.gradle @@ -55,7 +55,7 @@ dependencies { implementation('io.github.jbock-java:javapoet:1.15') implementation('io.github.jbock-java:auto-common:1.2.3') shadow(simple_component) - annotationProcessor('io.github.jbock-java:simple-component-compiler:1.023') + annotationProcessor('io.github.jbock-java:simple-component-compiler:1.024') testImplementation('io.github.jbock-java:compile-testing:0.19.12') testImplementation('org.junit.jupiter:junit-jupiter:5.10.1') testImplementation(simple_component) diff --git a/compiler/src/main/java/io/jbock/simple/processor/ContextComponent.java b/compiler/src/main/java/io/jbock/simple/processor/ContextComponent.java index 898768c..2083c28 100644 --- a/compiler/src/main/java/io/jbock/simple/processor/ContextComponent.java +++ b/compiler/src/main/java/io/jbock/simple/processor/ContextComponent.java @@ -2,21 +2,13 @@ import io.jbock.simple.Component; import io.jbock.simple.Inject; -import io.jbock.simple.Provides; -import io.jbock.simple.processor.binding.Binding; import io.jbock.simple.processor.binding.ComponentElement; -import io.jbock.simple.processor.binding.Key; import io.jbock.simple.processor.binding.KeyFactory; -import io.jbock.simple.processor.graph.TopologicalSorter; import io.jbock.simple.processor.util.TypeTool; import io.jbock.simple.processor.writing.ComponentImpl; -import io.jbock.simple.processor.writing.Context; import io.jbock.simple.processor.writing.ContextModule; -import io.jbock.simple.processor.writing.NamedBinding; import javax.lang.model.element.TypeElement; -import java.util.List; -import java.util.Map; @Component(modules = ContextModule.class) public interface ContextComponent { @@ -36,15 +28,6 @@ interface Builder { ComponentImpl componentImpl(); - @Provides - static Context createContext( - TopologicalSorter topologicalSorter, - KeyFactory keyFactory) { - List bindings = topologicalSorter.sortedBindings(); - Map sorted = ContextModule.addNames(keyFactory, bindings); - return new Context(sorted, ContextModule.createNames(sorted)); - } - final class Factory { private final TypeTool tool; diff --git a/compiler/src/main/java/io/jbock/simple/processor/writing/Context.java b/compiler/src/main/java/io/jbock/simple/processor/writing/Context.java index 447e73b..3e393b9 100644 --- a/compiler/src/main/java/io/jbock/simple/processor/writing/Context.java +++ b/compiler/src/main/java/io/jbock/simple/processor/writing/Context.java @@ -11,7 +11,7 @@ public final class Context { private final Map sorted; private final Function names; - public Context(Map sorted, Function names) { + Context(Map sorted, Function names) { this.sorted = sorted; this.names = names; } diff --git a/compiler/src/main/java/io/jbock/simple/processor/writing/ContextModule.java b/compiler/src/main/java/io/jbock/simple/processor/writing/ContextModule.java index e41004a..c84c549 100644 --- a/compiler/src/main/java/io/jbock/simple/processor/writing/ContextModule.java +++ b/compiler/src/main/java/io/jbock/simple/processor/writing/ContextModule.java @@ -1,10 +1,12 @@ package io.jbock.simple.processor.writing; import io.jbock.javapoet.ParameterSpec; +import io.jbock.simple.Inject; import io.jbock.simple.Modulus; import io.jbock.simple.processor.binding.Binding; import io.jbock.simple.processor.binding.Key; import io.jbock.simple.processor.binding.KeyFactory; +import io.jbock.simple.processor.graph.TopologicalSorter; import io.jbock.simple.processor.util.UniqueNameSet; import javax.lang.model.SourceVersion; @@ -17,7 +19,16 @@ @Modulus public interface ContextModule { - static Map addNames( + @Inject + static Context createContext( + TopologicalSorter topologicalSorter, + KeyFactory keyFactory) { + List bindings = topologicalSorter.sortedBindings(); + Map sorted = ContextModule.addNames(keyFactory, bindings); + return new Context(sorted, ContextModule.createNames(sorted)); + } + + private static Map addNames( KeyFactory keyFactory, List bindings) { UniqueNameSet uniqueNameSet = new UniqueNameSet(); @@ -33,7 +44,7 @@ static Map addNames( return result; } - static Function createNames( + private static Function createNames( Map sorted) { Map cache = new HashMap<>(); return key -> { @@ -84,5 +95,4 @@ private static String protectAgainstKeywords(String candidateName) { return SourceVersion.isKeyword(candidateName) ? candidateName + '_' : candidateName; } } - }