Reporting unused parameters
This commit is contained in:
@@ -34,6 +34,7 @@ public class Dependencies {
|
|||||||
|
|
||||||
private final Set<Field> allFields = Sets.newLinkedHashSet();
|
private final Set<Field> allFields = Sets.newLinkedHashSet();
|
||||||
private final Set<Field> satisfied = Sets.newHashSet();
|
private final Set<Field> satisfied = Sets.newHashSet();
|
||||||
|
private final Set<Field> used = Sets.newHashSet();
|
||||||
private final Multimap<DiType, Field> typeToFields = HashMultimap.create();
|
private final Multimap<DiType, Field> typeToFields = HashMultimap.create();
|
||||||
|
|
||||||
private final Set<Field> newFields = Sets.newLinkedHashSet();
|
private final Set<Field> newFields = Sets.newLinkedHashSet();
|
||||||
@@ -85,6 +86,7 @@ public class Dependencies {
|
|||||||
field + ": " + method + ": " + allFields,
|
field + ": " + method + ": " + allFields,
|
||||||
neededFor.prepend(field)
|
neededFor.prepend(field)
|
||||||
);
|
);
|
||||||
|
used.add(dependency);
|
||||||
|
|
||||||
field.getDependencies().add(new SetterDependency(field, method.getName(), dependency));
|
field.getDependencies().add(new SetterDependency(field, method.getName(), dependency));
|
||||||
}
|
}
|
||||||
@@ -152,6 +154,7 @@ public class Dependencies {
|
|||||||
"constructor: " + constructor + ", parameter: " + parameterType,
|
"constructor: " + constructor + ", parameter: " + parameterType,
|
||||||
neededFor.prepend(field)
|
neededFor.prepend(field)
|
||||||
);
|
);
|
||||||
|
used.add(fieldForParameter);
|
||||||
dependency.getConstructorArguments().add(fieldForParameter);
|
dependency.getConstructorArguments().add(fieldForParameter);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -165,6 +168,11 @@ public class Dependencies {
|
|||||||
return newFields;
|
return newFields;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public Set<Field> getUsedFields() {
|
||||||
|
return used;
|
||||||
|
}
|
||||||
|
|
||||||
private interface ImmutableStack<T> {
|
private interface ImmutableStack<T> {
|
||||||
@NotNull
|
@NotNull
|
||||||
ImmutableStack<T> prepend(T t);
|
ImmutableStack<T> prepend(T t);
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ public class DependencyInjectorGenerator {
|
|||||||
File file = new File(outputFileName);
|
File file = new File(outputFileName);
|
||||||
|
|
||||||
fields.addAll(dependencies.satisfyDependencies());
|
fields.addAll(dependencies.satisfyDependencies());
|
||||||
|
reportUnusedParameters(injectorPackageName, injectorClassName);
|
||||||
|
|
||||||
StringBuilder preamble = new StringBuilder();
|
StringBuilder preamble = new StringBuilder();
|
||||||
generatePreamble(injectorPackageName, new Printer(preamble));
|
generatePreamble(injectorPackageName, new Printer(preamble));
|
||||||
@@ -92,6 +92,15 @@ public class DependencyInjectorGenerator {
|
|||||||
GeneratorsFileUtil.writeFileIfContentChanged(file, text.toString());
|
GeneratorsFileUtil.writeFileIfContentChanged(file, text.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void reportUnusedParameters(String injectorPackageName, String injectorClassName) {
|
||||||
|
Sets.SetView<Field> unusedParameters = Sets.difference(backsParameter, dependencies.getUsedFields());
|
||||||
|
for (Field parameter : unusedParameters) {
|
||||||
|
if (!parameter.isPublic()) {
|
||||||
|
System.err.println("Unused parameter: " + parameter + " for " + injectorPackageName + "." + injectorClassName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void generatePreamble(String injectorPackageName, Printer p) throws IOException {
|
private void generatePreamble(String injectorPackageName, Printer p) throws IOException {
|
||||||
String copyright = "injector-generator/copyright.txt";
|
String copyright = "injector-generator/copyright.txt";
|
||||||
p.println(FileUtil.loadFile(new File(copyright)));
|
p.println(FileUtil.loadFile(new File(copyright)));
|
||||||
|
|||||||
Reference in New Issue
Block a user