use of dagger.internal.codegen.Util.CodeGenerationIncompleteException in project dagger by square.
the class ValidationProcessor method process.
@Override
public boolean process(Set<? extends TypeElement> types, RoundEnvironment env) {
List<Element> allElements = new ArrayList<Element>();
Map<Element, Element> parametersToTheirMethods = new LinkedHashMap<Element, Element>();
getAllElements(env, allElements, parametersToTheirMethods);
for (Element element : allElements) {
try {
validateProvides(element);
} catch (CodeGenerationIncompleteException e) {
// Upstream compiler issue in play. Ignore this element.
continue;
}
validateScoping(element);
validateQualifiers(element, parametersToTheirMethods);
}
return false;
}
use of dagger.internal.codegen.Util.CodeGenerationIncompleteException in project dagger by square.
the class ModuleAdapterProcessor method process.
@Override
public boolean process(Set<? extends TypeElement> types, RoundEnvironment env) {
remainingTypes.putAll(providerMethodsByClass(env));
for (Iterator<String> i = remainingTypes.keySet().iterator(); i.hasNext(); ) {
String typeName = i.next();
TypeElement type = processingEnv.getElementUtils().getTypeElement(typeName);
List<ExecutableElement> providesTypes = remainingTypes.get(typeName);
try {
// Attempt to get the annotation. If types are missing, this will throw
// CodeGenerationIncompleteException.
Map<String, Object> parsedAnnotation = getAnnotation(Module.class, type);
if (parsedAnnotation == null) {
error(type + " has @Provides methods but no @Module annotation", type);
continue;
}
JavaFile javaFile = generateModuleAdapter(type, parsedAnnotation, providesTypes);
javaFile.writeTo(processingEnv.getFiler());
} catch (CodeGenerationIncompleteException e) {
// A dependent type was not defined, we'll try to catch it on another pass.
continue;
} catch (IOException e) {
error("Code gen failed: " + e, type);
}
i.remove();
}
if (env.processingOver() && remainingTypes.size() > 0) {
processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "Could not find types required by provides methods for " + remainingTypes.keySet());
}
// FullGraphProcessor needs an opportunity to process.
return false;
}
use of dagger.internal.codegen.Util.CodeGenerationIncompleteException in project dagger by square.
the class GraphAnalysisProcessor method process.
/**
* Perform full-graph analysis on complete modules. This checks that all of
* the module's dependencies are satisfied.
*/
@Override
public boolean process(Set<? extends TypeElement> types, RoundEnvironment env) {
if (!env.processingOver()) {
// passes.
for (Element e : env.getElementsAnnotatedWith(Module.class)) {
if (!(e instanceof TypeElement)) {
error("@Module applies to a type, " + e.getSimpleName() + " is a " + e.getKind(), e);
continue;
}
delayedModuleNames.add(((TypeElement) e).getQualifiedName().toString());
}
return false;
}
Set<Element> modules = new LinkedHashSet<Element>();
for (String moduleName : delayedModuleNames) {
modules.add(elements().getTypeElement(moduleName));
}
for (Element element : modules) {
Map<String, Object> annotation = null;
try {
annotation = getAnnotation(Module.class, element);
} catch (CodeGenerationIncompleteException e) {
// skip this element. An up-stream compiler error is in play.
continue;
}
TypeElement moduleType = (TypeElement) element;
if (annotation == null) {
error("Missing @Module annotation.", moduleType);
continue;
}
if (annotation.get("complete").equals(Boolean.TRUE)) {
Map<String, Binding<?>> bindings;
try {
bindings = processCompleteModule(moduleType, false);
new ProblemDetector().detectCircularDependencies(bindings.values());
} catch (ModuleValidationException e) {
error("Graph validation failed: " + e.getMessage(), e.source);
continue;
} catch (InvalidBindingException e) {
error("Graph validation failed: " + e.getMessage(), elements().getTypeElement(e.type));
continue;
} catch (RuntimeException e) {
if (ERROR_NAMES_TO_PROPAGATE.contains(e.getClass().getName())) {
throw e;
}
error("Unknown error " + e.getClass().getName() + " thrown by javac in graph validation: " + e.getMessage(), moduleType);
continue;
}
try {
writeDotFile(moduleType, bindings);
} catch (IOException e) {
StringWriter sw = new StringWriter();
e.printStackTrace(new PrintWriter(sw));
processingEnv.getMessager().printMessage(Diagnostic.Kind.WARNING, "Graph visualization failed. Please report this as a bug.\n\n" + sw, moduleType);
}
}
if (annotation.get("library").equals(Boolean.FALSE)) {
Map<String, Binding<?>> bindings = processCompleteModule(moduleType, true);
try {
new ProblemDetector().detectUnusedBinding(bindings.values());
} catch (IllegalStateException e) {
error("Graph validation failed: " + e.getMessage(), moduleType);
}
}
}
return false;
}
Aggregations