Skip to content

Commit

Permalink
[Refactor] Move CompositeBindingGraphValidator into bindinggraphvalid…
Browse files Browse the repository at this point in the history
…ation package.

This class is a BindingGraphPlugin, so it should go into the bindinggraphvalidation package with the rest of our BindingGraphPlugins. Additionally, this allows us to make this class package-private.

This CL also converts a hand-written factory to use Dagger's new AssistedFactory.

RELNOTES=N/A
PiperOrigin-RevId: 444983117
  • Loading branch information
bcorso authored and Dagger Team committed Apr 27, 2022
1 parent 1a01575 commit 0dfbcaa
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 62 deletions.
1 change: 1 addition & 0 deletions java/dagger/internal/codegen/bindinggraphvalidation/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ java_library(
"//java/dagger/spi",
"//third_party/java/auto:common",
"//third_party/java/auto:value",
"//third_party/java/error_prone:annotations",
"//third_party/java/guava/base",
"//third_party/java/guava/collect",
"//third_party/java/guava/graph",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import dagger.Module;
import dagger.Provides;
import dagger.internal.codegen.compileroption.CompilerOptions;
import dagger.internal.codegen.validation.CompositeBindingGraphPlugin;
import dagger.internal.codegen.validation.Validation;
import dagger.spi.model.BindingGraphPlugin;

Expand Down Expand Up @@ -57,7 +56,7 @@ static ImmutableSet<BindingGraphPlugin> providePlugins(
validation10,
validation11);
if (compilerOptions.experimentalDaggerErrorMessages()) {
return ImmutableSet.of(factory.create(plugins, "Dagger/Validation"));
return ImmutableSet.of(factory.create(plugins));
} else {
return plugins;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package dagger.internal.codegen.validation;
package dagger.internal.codegen.bindinggraphvalidation;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
Expand All @@ -26,6 +26,10 @@

import com.google.common.collect.ImmutableSet;
import com.google.errorprone.annotations.FormatMethod;
import dagger.assisted.Assisted;
import dagger.assisted.AssistedFactory;
import dagger.assisted.AssistedInject;
import dagger.internal.codegen.validation.DiagnosticMessageGenerator;
import dagger.spi.model.BindingGraph;
import dagger.spi.model.BindingGraph.ChildFactoryMethodEdge;
import dagger.spi.model.BindingGraph.ComponentNode;
Expand All @@ -37,7 +41,6 @@
import java.util.Optional;
import java.util.Set;
import javax.annotation.processing.Filer;
import javax.inject.Inject;
import javax.lang.model.util.Elements; // ALLOW_TYPES_ELEMENTS because of interface dependencies
import javax.lang.model.util.Types; // ALLOW_TYPES_ELEMENTS because of interface dependencies
import javax.tools.Diagnostic;
Expand All @@ -46,32 +49,20 @@
* Combines many {@link BindingGraphPlugin} implementations. This helps reduce spam by combining
* all of the messages that are reported on the root component.
*/
public final class CompositeBindingGraphPlugin implements BindingGraphPlugin {
final class CompositeBindingGraphPlugin implements BindingGraphPlugin {
@AssistedFactory
interface Factory {
CompositeBindingGraphPlugin create(ImmutableSet<BindingGraphPlugin> plugins);
}

private final ImmutableSet<BindingGraphPlugin> plugins;
private final String pluginName;
private final DiagnosticMessageGenerator.Factory messageGeneratorFactory;

/** Factory class for {@link CompositeBindingGraphPlugin}. */
public static final class Factory {
private final DiagnosticMessageGenerator.Factory messageGeneratorFactory;

@Inject Factory(DiagnosticMessageGenerator.Factory messageGeneratorFactory) {
this.messageGeneratorFactory = messageGeneratorFactory;
}

public CompositeBindingGraphPlugin create(
ImmutableSet<BindingGraphPlugin> plugins, String pluginName) {
return new CompositeBindingGraphPlugin(plugins, pluginName, messageGeneratorFactory);
}
}

private CompositeBindingGraphPlugin(
ImmutableSet<BindingGraphPlugin> plugins,
String pluginName,
@AssistedInject
CompositeBindingGraphPlugin(
@Assisted ImmutableSet<BindingGraphPlugin> plugins,
DiagnosticMessageGenerator.Factory messageGeneratorFactory) {
this.plugins = plugins;
this.pluginName = pluginName;
this.messageGeneratorFactory = messageGeneratorFactory;
}

Expand Down Expand Up @@ -114,7 +105,7 @@ public Set<String> supportedOptions() {

@Override
public String pluginName() {
return pluginName;
return "Dagger/Validation";
}

// TODO(erichang): This kind of breaks some of the encapsulation by relying on or repeating
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package dagger.internal.codegen.validation;
package dagger.internal.codegen.bindinggraphvalidation;

import static java.util.Comparator.comparing;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
* limitations under the License.
*/

package dagger.internal.codegen.validation;
package dagger.internal.codegen.bindinggraphvalidation;

import static com.google.common.truth.Truth.assertThat;
import static dagger.internal.codegen.validation.PackageNameCompressor.LEGEND_FOOTER;
import static dagger.internal.codegen.validation.PackageNameCompressor.LEGEND_HEADER;
import static dagger.internal.codegen.bindinggraphvalidation.PackageNameCompressor.LEGEND_FOOTER;
import static dagger.internal.codegen.bindinggraphvalidation.PackageNameCompressor.LEGEND_HEADER;

import org.junit.Test;
import org.junit.runner.RunWith;
Expand Down
33 changes: 0 additions & 33 deletions javatests/dagger/internal/codegen/validation/BUILD

This file was deleted.

0 comments on commit 0dfbcaa

Please sign in to comment.