Search in sources :

Example 1 with INJECTION

use of dagger.spi.model.BindingKind.INJECTION in project dapper by jbock-java.

the class IncompatiblyScopedBindingsValidator method visitGraph.

@Override
public void visitGraph(BindingGraph bindingGraph, DiagnosticReporter diagnosticReporter) {
    DiagnosticMessageGenerator diagnosticMessageGenerator = diagnosticMessageGeneratorFactory.create(bindingGraph);
    ImmutableSetMultimap.Builder<ComponentNode, dagger.spi.model.Binding> incompatibleBindings = ImmutableSetMultimap.builder();
    for (dagger.spi.model.Binding binding : bindingGraph.bindings()) {
        binding.scope().filter(scope -> !scope.isReusable()).ifPresent(scope -> {
            ComponentNode componentNode = bindingGraph.componentNode(binding.componentPath()).get();
            if (!componentNode.scopes().contains(scope)) {
                // properly scoped ancestor component, so ignore them here.
                if (binding.kind().equals(INJECTION) && (bindingGraph.rootComponentNode().isSubcomponent() || !bindingGraph.rootComponentNode().isRealComponent())) {
                    return;
                }
                incompatibleBindings.put(componentNode, binding);
            }
        });
    }
    Multimaps.asMap(incompatibleBindings.build()).forEach((componentNode, bindings) -> report(componentNode, bindings, diagnosticReporter, diagnosticMessageGenerator));
}
Also used : Binding(dagger.spi.model.Binding) Scopes.getReadableSource(dagger.internal.codegen.base.Scopes.getReadableSource) BindingGraphPlugin(dagger.spi.model.BindingGraphPlugin) BindingGraph(dagger.spi.model.BindingGraph) DiagnosticMessageGenerator(dagger.internal.codegen.validation.DiagnosticMessageGenerator) DiagnosticReporter(dagger.spi.model.DiagnosticReporter) XElements.closestEnclosingTypeElement(dagger.internal.codegen.xprocessing.XElements.closestEnclosingTypeElement) Scopes(dagger.internal.codegen.base.Scopes) MethodSignatureFormatter(dagger.internal.codegen.binding.MethodSignatureFormatter) Set(java.util.Set) Multimaps(dagger.internal.codegen.collect.Multimaps) ERROR(javax.tools.Diagnostic.Kind.ERROR) Collectors.joining(java.util.stream.Collectors.joining) INDENT(dagger.internal.codegen.base.Formatter.INDENT) XElements.asExecutable(dagger.internal.codegen.xprocessing.XElements.asExecutable) INJECTION(dagger.spi.model.BindingKind.INJECTION) Diagnostic(javax.tools.Diagnostic) Binding(dagger.spi.model.Binding) Optional(java.util.Optional) CompilerOptions(dagger.internal.codegen.compileroption.CompilerOptions) ComponentNode(dagger.spi.model.BindingGraph.ComponentNode) Inject(jakarta.inject.Inject) ImmutableSetMultimap(dagger.internal.codegen.collect.ImmutableSetMultimap) ImmutableSetMultimap(dagger.internal.codegen.collect.ImmutableSetMultimap) DiagnosticMessageGenerator(dagger.internal.codegen.validation.DiagnosticMessageGenerator) Binding(dagger.spi.model.Binding) ComponentNode(dagger.spi.model.BindingGraph.ComponentNode)

Example 2 with INJECTION

use of dagger.spi.model.BindingKind.INJECTION in project DaggerCodeParse-2.38.1base by hellogaod.

the class IncompatiblyScopedBindingsValidator method visitGraph.

@Override
public void visitGraph(BindingGraph bindingGraph, DiagnosticReporter diagnosticReporter) {
    ImmutableSetMultimap.Builder<BindingGraph.ComponentNode, dagger.spi.model.Binding> incompatibleBindings = ImmutableSetMultimap.builder();
    for (dagger.spi.model.Binding binding : bindingGraph.bindings()) {
        binding.scope().filter(scope -> !scope.isReusable()).ifPresent(scope -> {
            BindingGraph.ComponentNode componentNode = bindingGraph.componentNode(binding.componentPath()).get();
            if (!componentNode.scopes().contains(scope)) {
                // properly scoped ancestor component, so ignore them here.
                if (binding.kind().equals(INJECTION) && (bindingGraph.rootComponentNode().isSubcomponent() || !bindingGraph.rootComponentNode().isRealComponent())) {
                    return;
                }
                incompatibleBindings.put(componentNode, binding);
            }
        });
    }
    Multimaps.asMap(incompatibleBindings.build()).forEach((componentNode, bindings) -> report(componentNode, bindings, diagnosticReporter));
}
Also used : Binding(dagger.spi.model.Binding) Scopes.getReadableSource(dagger.internal.codegen.base.Scopes.getReadableSource) MoreElements(com.google.auto.common.MoreElements) BindingGraphPlugin(dagger.spi.model.BindingGraphPlugin) BindingGraph(dagger.spi.model.BindingGraph) DaggerElements.closestEnclosingTypeElement(dagger.internal.codegen.langmodel.DaggerElements.closestEnclosingTypeElement) DiagnosticReporter(dagger.spi.model.DiagnosticReporter) Set(java.util.Set) Scopes(dagger.internal.codegen.base.Scopes) MethodSignatureFormatter(dagger.internal.codegen.binding.MethodSignatureFormatter) ERROR(javax.tools.Diagnostic.Kind.ERROR) Collectors.joining(java.util.stream.Collectors.joining) Multimaps(com.google.common.collect.Multimaps) Inject(javax.inject.Inject) INDENT(dagger.internal.codegen.base.Formatter.INDENT) Diagnostic(javax.tools.Diagnostic) INJECTION(dagger.spi.model.BindingKind.INJECTION) Binding(dagger.spi.model.Binding) Optional(java.util.Optional) CompilerOptions(dagger.internal.codegen.compileroption.CompilerOptions) ImmutableSetMultimap(com.google.common.collect.ImmutableSetMultimap) BindingGraph(dagger.spi.model.BindingGraph) ImmutableSetMultimap(com.google.common.collect.ImmutableSetMultimap) Binding(dagger.spi.model.Binding)

Aggregations

INDENT (dagger.internal.codegen.base.Formatter.INDENT)2 Scopes (dagger.internal.codegen.base.Scopes)2 Scopes.getReadableSource (dagger.internal.codegen.base.Scopes.getReadableSource)2 MethodSignatureFormatter (dagger.internal.codegen.binding.MethodSignatureFormatter)2 CompilerOptions (dagger.internal.codegen.compileroption.CompilerOptions)2 Binding (dagger.spi.model.Binding)2 BindingGraph (dagger.spi.model.BindingGraph)2 BindingGraphPlugin (dagger.spi.model.BindingGraphPlugin)2 INJECTION (dagger.spi.model.BindingKind.INJECTION)2 DiagnosticReporter (dagger.spi.model.DiagnosticReporter)2 Optional (java.util.Optional)2 Set (java.util.Set)2 Collectors.joining (java.util.stream.Collectors.joining)2 Diagnostic (javax.tools.Diagnostic)2 ERROR (javax.tools.Diagnostic.Kind.ERROR)2 MoreElements (com.google.auto.common.MoreElements)1 ImmutableSetMultimap (com.google.common.collect.ImmutableSetMultimap)1 Multimaps (com.google.common.collect.Multimaps)1 ImmutableSetMultimap (dagger.internal.codegen.collect.ImmutableSetMultimap)1 Multimaps (dagger.internal.codegen.collect.Multimaps)1