Skip to content

Commit

Permalink
Run google-java-format on all Guice code.
Browse files Browse the repository at this point in the history
configure a presubmit to ensure that it stays formatted.

Highlights include:
* simplified import order
* method annotations are now consistently defined on the preceding line
* javadoc reformatted to 100 chars column width

One test that contained line numbers in error messages had to be modified and
the formatter didn't like some of the more complicated preprocessor directives
(MOE and AOP).

To avoid formatting the copyright notices as javadoc i did a preprocessing step to rewrite the initial '/**' to '/*' using perl

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=132704710
  • Loading branch information
lukesandberg authored and sameb committed Sep 13, 2016
1 parent d34d64e commit d66a079
Show file tree
Hide file tree
Showing 22 changed files with 245 additions and 169 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/*
* Copyright (C) 2011 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -42,6 +42,7 @@ public abstract class AbstractInjectorGrapher implements InjectorGrapher {

/**
* Parameters used to override default settings of the grapher.
*
* @since 4.0
*/
public static final class GrapherParameters {
Expand Down Expand Up @@ -98,11 +99,13 @@ public AbstractInjectorGrapher(GrapherParameters options) {
this.edgeCreator = options.getEdgeCreator();
}

@Override public final void graph(Injector injector) throws IOException {
@Override
public final void graph(Injector injector) throws IOException {
graph(injector, rootKeySetCreator.getRootKeys(injector));
}

@Override public final void graph(Injector injector, Set<Key<?>> root) throws IOException {
@Override
public final void graph(Injector injector, Set<Key<?>> root) throws IOException {
reset();

Iterable<Binding<?>> bindings = getBindings(injector, root);
Expand Down Expand Up @@ -154,8 +157,8 @@ private void createNodes(Iterable<Node> nodes, Map<NodeId, NodeId> aliases) thro

private void createEdges(Iterable<Edge> edges, Map<NodeId, NodeId> aliases) throws IOException {
for (Edge edge : edges) {
edge = edge.copy(resolveAlias(aliases, edge.getFromId()),
resolveAlias(aliases, edge.getToId()));
edge =
edge.copy(resolveAlias(aliases, edge.getFromId()), resolveAlias(aliases, edge.getToId()));
if (!edge.getFromId().equals(edge.getToId())) {
if (edge instanceof BindingEdge) {
newBindingEdge((BindingEdge) edge);
Expand All @@ -171,8 +174,8 @@ private NodeId resolveAlias(Map<NodeId, NodeId> aliases, NodeId nodeId) {
}

/**
* Transitively resolves aliases. Given aliases (X to Y) and (Y to Z), it will return mappings
* (X to Z) and (Y to Z).
* Transitively resolves aliases. Given aliases (X to Y) and (Y to Z), it will return mappings (X
* to Z) and (Y to Z).
*/
private Map<NodeId, NodeId> resolveAliases(Iterable<Alias> aliases) {
Map<NodeId, NodeId> resolved = Maps.newHashMap();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/*
* Copyright (C) 2011 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/*
* Copyright (C) 2011 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
18 changes: 10 additions & 8 deletions extensions/grapher/src/com/google/inject/grapher/BindingEdge.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/*
* Copyright (C) 2008 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -25,9 +25,7 @@
* @since 4.0 (since 2.0 as an interface)
*/
public class BindingEdge extends Edge {
/**
* Classification for what kind of binding this edge represents.
*/
/** Classification for what kind of binding this edge represents. */
public enum Type {
/** Binding is to an instance or class of the binding's same type. */
NORMAL,
Expand All @@ -48,23 +46,27 @@ public Type getType() {
return type;
}

@Override public boolean equals(Object obj) {
@Override
public boolean equals(Object obj) {
if (!(obj instanceof BindingEdge)) {
return false;
}
BindingEdge other = (BindingEdge) obj;
return super.equals(other) && Objects.equal(type, other.type);
}

@Override public int hashCode() {
@Override
public int hashCode() {
return 31 * super.hashCode() + Objects.hashCode(type);
}

@Override public String toString() {
@Override
public String toString() {
return "BindingEdge{fromId=" + getFromId() + " toId=" + getToId() + " type=" + type + "}";
}

@Override public Edge copy(NodeId fromId, NodeId toId) {
@Override
public Edge copy(NodeId fromId, NodeId toId) {
return new BindingEdge(fromId, toId, type);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/*
* Copyright (C) 2011 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -39,7 +39,8 @@
*/
final class DefaultEdgeCreator implements EdgeCreator {

@Override public Iterable<Edge> getEdges(Iterable<Binding<?>> bindings) {
@Override
public Iterable<Edge> getEdges(Iterable<Binding<?>> bindings) {
List<Edge> edges = Lists.newArrayList();
EdgeVisitor visitor = new EdgeVisitor();
for (Binding<?> binding : bindings) {
Expand All @@ -58,8 +59,7 @@ private static final class EdgeVisitor
* Returns a dependency edge for each {@link Dependency} in the binding. These will be from the
* given node ID to the {@link Dependency}'s {@link Key}.
*
* @param nodeId ID of the node that should be the tail of the dependency
* edges
* @param nodeId ID of the node that should be the tail of the dependency edges
* @param binding {@link Binding} for the dependencies
*/
private <T extends Binding<?> & HasDependencies> Collection<Edge> newDependencyEdges(
Expand All @@ -76,7 +76,8 @@ private <T extends Binding<?> & HasDependencies> Collection<Edge> newDependencyE
* Visitor for {@link ConstructorBinding}s. These are for classes that Guice will instantiate to
* satisfy injection requests.
*/
@Override public Collection<Edge> visit(ConstructorBinding<?> binding) {
@Override
public Collection<Edge> visit(ConstructorBinding<?> binding) {
return newDependencyEdges(NodeId.newTypeId(binding.getKey()), binding);
}

Expand All @@ -85,10 +86,13 @@ private <T extends Binding<?> & HasDependencies> Collection<Edge> newDependencyE
* annotated primitive type, and the value of {@link ConvertedConstantBinding#getSourceKey()}
* will be of a {@link String} with the same annotation.
*/
@Override public Collection<Edge> visit(ConvertedConstantBinding<?> binding) {
return ImmutableList.<Edge>of(new BindingEdge(NodeId.newTypeId(binding.getKey()),
NodeId.newTypeId(binding.getSourceKey()),
BindingEdge.Type.CONVERTED_CONSTANT));
@Override
public Collection<Edge> visit(ConvertedConstantBinding<?> binding) {
return ImmutableList.<Edge>of(
new BindingEdge(
NodeId.newTypeId(binding.getKey()),
NodeId.newTypeId(binding.getSourceKey()),
BindingEdge.Type.CONVERTED_CONSTANT));
}

/**
Expand All @@ -97,57 +101,76 @@ private <T extends Binding<?> & HasDependencies> Collection<Edge> newDependencyE
* or on {@link Dependency}s the instance declares through the {@link HasDependencies}
* interface.
*/
@Override public Collection<Edge> visit(InstanceBinding<?> binding) {
@Override
public Collection<Edge> visit(InstanceBinding<?> binding) {
return new ImmutableList.Builder<Edge>()
.add(new BindingEdge(NodeId.newTypeId(binding.getKey()),
NodeId.newInstanceId(binding.getKey()),
BindingEdge.Type.NORMAL))
.add(
new BindingEdge(
NodeId.newTypeId(binding.getKey()),
NodeId.newInstanceId(binding.getKey()),
BindingEdge.Type.NORMAL))
.addAll(newDependencyEdges(NodeId.newInstanceId(binding.getKey()), binding))
.build();
}

/**
* Visitor for {@link LinkedKeyBinding}. This is the standard {@link Binding} you get from
* binding an interface class to an implementation class. We draw a {@link BindingEdge} from
* the interface node to the node of the implementing class.
* binding an interface class to an implementation class. We draw a {@link BindingEdge} from the
* interface node to the node of the implementing class.
*/
@Override public Collection<Edge> visit(LinkedKeyBinding<?> binding) {
return ImmutableList.<Edge>of(new BindingEdge(NodeId.newTypeId(binding.getKey()),
NodeId.newTypeId(binding.getLinkedKey()),
BindingEdge.Type.NORMAL));
@Override
public Collection<Edge> visit(LinkedKeyBinding<?> binding) {
return ImmutableList.<Edge>of(
new BindingEdge(
NodeId.newTypeId(binding.getKey()),
NodeId.newTypeId(binding.getLinkedKey()),
BindingEdge.Type.NORMAL));
}

/**
* Visitor for {@link ProviderBinding}. These {@link Binding}s arise from an
* {@link InjectionPoint} for the {@link Provider} interface.
* Visitor for {@link ProviderBinding}. These {@link Binding}s arise from an {@link
* InjectionPoint} for the {@link Provider} interface.
*/
@Override public Collection<Edge> visit(ProviderBinding<?> binding) {
return ImmutableList.<Edge>of(new BindingEdge(NodeId.newTypeId(binding.getKey()),
NodeId.newTypeId(binding.getProvidedKey()), BindingEdge.Type.PROVIDER));
@Override
public Collection<Edge> visit(ProviderBinding<?> binding) {
return ImmutableList.<Edge>of(
new BindingEdge(
NodeId.newTypeId(binding.getKey()),
NodeId.newTypeId(binding.getProvidedKey()),
BindingEdge.Type.PROVIDER));
}

/**
* Same as {@link #visit(InstanceBinding)}, but the binding edge is
* {@link BindingEdge.Type#PROVIDER}.
* Same as {@link #visit(InstanceBinding)}, but the binding edge is {@link
* BindingEdge.Type#PROVIDER}.
*/
@Override public Collection<Edge> visit(ProviderInstanceBinding<?> binding) {
@Override
public Collection<Edge> visit(ProviderInstanceBinding<?> binding) {
return new ImmutableList.Builder<Edge>()
.add(new BindingEdge(NodeId.newTypeId(binding.getKey()),
NodeId.newInstanceId(binding.getKey()), BindingEdge.Type.PROVIDER))
.add(
new BindingEdge(
NodeId.newTypeId(binding.getKey()),
NodeId.newInstanceId(binding.getKey()),
BindingEdge.Type.PROVIDER))
.addAll(newDependencyEdges(NodeId.newInstanceId(binding.getKey()), binding))
.build();
}

/**
* Same as {@link #visit(LinkedKeyBinding)}, but the binding edge is
* {@link BindingEdge.Type#PROVIDER}.
* Same as {@link #visit(LinkedKeyBinding)}, but the binding edge is {@link
* BindingEdge.Type#PROVIDER}.
*/
@Override public Collection<Edge> visit(ProviderKeyBinding<?> binding) {
return ImmutableList.<Edge>of(new BindingEdge(NodeId.newTypeId(binding.getKey()),
NodeId.newTypeId(binding.getProviderKey()), BindingEdge.Type.PROVIDER));
@Override
public Collection<Edge> visit(ProviderKeyBinding<?> binding) {
return ImmutableList.<Edge>of(
new BindingEdge(
NodeId.newTypeId(binding.getKey()),
NodeId.newTypeId(binding.getProviderKey()),
BindingEdge.Type.PROVIDER));
}

@Override public Collection<Edge> visitOther(Binding<?> binding) {
@Override
public Collection<Edge> visitOther(Binding<?> binding) {
return ImmutableList.of();
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/*
* Copyright (C) 2011 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -26,7 +26,6 @@
import com.google.inject.spi.InjectionPoint;
import com.google.inject.spi.InstanceBinding;
import com.google.inject.spi.ProviderInstanceBinding;

import java.lang.reflect.Member;
import java.util.Collection;
import java.util.List;
Expand All @@ -37,7 +36,8 @@
* @author [email protected] (Bojan Djordjevic)
*/
final class DefaultNodeCreator implements NodeCreator {
@Override public Iterable<Node> getNodes(Iterable<Binding<?>> bindings) {
@Override
public Iterable<Node> getNodes(Iterable<Binding<?>> bindings) {
List<Node> nodes = Lists.newArrayList();
NodeVisitor visitor = new NodeVisitor();
for (Binding<?> binding : bindings) {
Expand All @@ -64,10 +64,10 @@ private InterfaceNode newInterfaceNode(Binding<?> binding) {
* @param members members to add to the node
* @return implementation node for the given binding
*/
private ImplementationNode newImplementationNode(Binding<?> binding,
Collection<Member> members) {
return new ImplementationNode(NodeId.newTypeId(binding.getKey()), binding.getSource(),
members);
private ImplementationNode newImplementationNode(
Binding<?> binding, Collection<Member> members) {
return new ImplementationNode(
NodeId.newTypeId(binding.getKey()), binding.getSource(), members);
}

/**
Expand All @@ -77,8 +77,8 @@ private ImplementationNode newImplementationNode(Binding<?> binding,
* @param instance value of the instance
* @return instance node for the given binding
*/
private <T extends Binding<?> & HasDependencies> InstanceNode newInstanceNode(T binding,
Object instance) {
private <T extends Binding<?> & HasDependencies> InstanceNode newInstanceNode(
T binding, Object instance) {
Collection<Member> members = Lists.newArrayList();
for (Dependency<?> dependency : binding.getDependencies()) {
InjectionPoint injectionPoint = dependency.getInjectionPoint();
Expand All @@ -87,15 +87,16 @@ private <T extends Binding<?> & HasDependencies> InstanceNode newInstanceNode(T
members.add(injectionPoint.getMember());
}
}
return new InstanceNode(NodeId.newInstanceId(binding.getKey()), binding.getSource(), instance,
members);
return new InstanceNode(
NodeId.newInstanceId(binding.getKey()), binding.getSource(), instance, members);
}

/**
* Visitor for {@link ConstructorBinding}s. These are for classes that Guice will instantiate to
* satisfy injection requests.
*/
@Override public Collection<Node> visit(ConstructorBinding<?> binding) {
@Override
public Collection<Node> visit(ConstructorBinding<?> binding) {
Collection<Member> members = Lists.newArrayList();
members.add(binding.getConstructor().getMember());
for (InjectionPoint injectionPoint : binding.getInjectableMembers()) {
Expand All @@ -110,21 +111,24 @@ private <T extends Binding<?> & HasDependencies> InstanceNode newInstanceNode(T
* the binding's {@link Key}, and then an implementation node for the instance {@link Object}
* itself.
*/
@Override public Collection<Node> visit(InstanceBinding<?> binding) {
return ImmutableList.<Node>of(newInterfaceNode(binding), newInstanceNode(binding,
binding.getInstance()));
@Override
public Collection<Node> visit(InstanceBinding<?> binding) {
return ImmutableList.<Node>of(
newInterfaceNode(binding), newInstanceNode(binding, binding.getInstance()));
}

/**
* Same as {@link #visit(InstanceBinding)}, but the binding edge is
* {@link BindingEdgeType#PROVIDER}.
* Same as {@link #visit(InstanceBinding)}, but the binding edge is {@link
* BindingEdgeType#PROVIDER}.
*/
@Override public Collection<Node> visit(ProviderInstanceBinding<?> binding) {
return ImmutableList.<Node>of(newInterfaceNode(binding), newInstanceNode(binding,
binding.getUserSuppliedProvider()));
@Override
public Collection<Node> visit(ProviderInstanceBinding<?> binding) {
return ImmutableList.<Node>of(
newInterfaceNode(binding), newInstanceNode(binding, binding.getUserSuppliedProvider()));
}

@Override public Collection<Node> visitOther(Binding<?> binding) {
@Override
public Collection<Node> visitOther(Binding<?> binding) {
return ImmutableList.<Node>of(newInterfaceNode(binding));
}
}
Expand Down
Loading

0 comments on commit d66a079

Please sign in to comment.