Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update processor #63

Merged
merged 1 commit into from
Dec 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}

}
Loading