Skip to content

Commit

Permalink
update processor
Browse files Browse the repository at this point in the history
  • Loading branch information
h908714124 committed Dec 25, 2023
1 parent 52dfef8 commit 48ecf04
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 22 deletions.
2 changes: 1 addition & 1 deletion compiler/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -36,15 +28,6 @@ interface Builder {

ComponentImpl componentImpl();

@Provides
static Context createContext(
TopologicalSorter topologicalSorter,
KeyFactory keyFactory) {
List<Binding> bindings = topologicalSorter.sortedBindings();
Map<Key, NamedBinding> sorted = ContextModule.addNames(keyFactory, bindings);
return new Context(sorted, ContextModule.createNames(sorted));
}

final class Factory {
private final TypeTool tool;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public final class Context {
private final Map<Key, NamedBinding> sorted;
private final Function<Key, ParameterSpec> names;

public Context(Map<Key, NamedBinding> sorted, Function<Key, ParameterSpec> names) {
Context(Map<Key, NamedBinding> sorted, Function<Key, ParameterSpec> names) {
this.sorted = sorted;
this.names = names;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -17,7 +19,16 @@
@Modulus
public interface ContextModule {

static Map<Key, NamedBinding> addNames(
@Inject
static Context createContext(
TopologicalSorter topologicalSorter,
KeyFactory keyFactory) {
List<Binding> bindings = topologicalSorter.sortedBindings();
Map<Key, NamedBinding> sorted = ContextModule.addNames(keyFactory, bindings);
return new Context(sorted, ContextModule.createNames(sorted));
}

private static Map<Key, NamedBinding> addNames(
KeyFactory keyFactory,
List<Binding> bindings) {
UniqueNameSet uniqueNameSet = new UniqueNameSet();
Expand All @@ -33,7 +44,7 @@ static Map<Key, NamedBinding> addNames(
return result;
}

static Function<Key, ParameterSpec> createNames(
private static Function<Key, ParameterSpec> createNames(
Map<Key, NamedBinding> sorted) {
Map<Key, ParameterSpec> cache = new HashMap<>();
return key -> {
Expand Down Expand Up @@ -84,5 +95,4 @@ private static String protectAgainstKeywords(String candidateName) {
return SourceVersion.isKeyword(candidateName) ? candidateName + '_' : candidateName;
}
}

}

0 comments on commit 48ecf04

Please sign in to comment.