use of javax.lang.model.element.AnnotationValue in project tiger by google.
the class Utils method findDirectModules.
public void findDirectModules(Set<TypeElement> modules, Element component) {
AnnotationMirror componentAnnotationMirror = isComponent(component) ? getAnnotationMirror(component, Component.class) : getAnnotationMirror(component, Subcomponent.class);
AnnotationValue moduleAnnotationValue = Utils.getAnnotationValue(elements, componentAnnotationMirror, "modules");
if (moduleAnnotationValue != null) {
for (AnnotationValue annotationValue : (List<AnnotationValue>) moduleAnnotationValue.getValue()) {
modules.add((TypeElement) ((DeclaredType) annotationValue.getValue()).asElement());
}
}
}
use of javax.lang.model.element.AnnotationValue in project tiger by google.
the class Utils method findAllModulesRecursively.
/**
* Returns modules included and created by {@link ContributesAndroidInjector}.
*/
@SuppressWarnings("unchecked")
public Set<TypeElement> findAllModulesRecursively(Elements elements, TypeElement module) {
Set<TypeElement> result = new HashSet<>();
result.add(module);
// included
for (AnnotationMirror annotationMirror : module.getAnnotationMirrors()) {
// TODO: only handle @Module
for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : annotationMirror.getElementValues().entrySet()) {
ExecutableElement key = entry.getKey();
/**
* Checks for {@link Module.includes}.
*/
if (key.getSimpleName().contentEquals("includes")) {
for (AnnotationValue annotationValue : (List<AnnotationValue>) entry.getValue().getValue()) {
TypeElement childModule = (TypeElement) ((DeclaredType) annotationValue.getValue()).asElement();
result.addAll(findAllModulesRecursively(elements, childModule));
}
// messager.printMessage(Kind.NOTE, TAG + ".findAllModulesRecursively, result " + result);
}
}
}
/**
* by {@link ContributesAndroidInjector}
*/
Set<TypeElement> modulesGenerated = collectModulesByContributesAndroidInjectorInModule(elements, messager, module);
if (modulesGenerated != null) {
// trimModules(modulesGenerated);
result.addAll(modulesGenerated);
}
return result;
}
use of javax.lang.model.element.AnnotationValue in project tiger by google.
the class Utils method getComponentDependencies.
/**
* Returns dependencies of the give component, empty set if none.
*/
public Set<TypeElement> getComponentDependencies(TypeElement component) {
Set<TypeElement> result = new HashSet<>();
AnnotationMirror componentAnnotationMirror = Preconditions.checkNotNull(getAnnotationMirror(component, Component.class), String.format("@Component not found for %s", component));
AnnotationValue dependenciesAnnotationValue = getAnnotationValue(elements, componentAnnotationMirror, COMPONANT_ANNOTATION_ELEMENT_DEPENDENCIES);
if (dependenciesAnnotationValue == null) {
return result;
}
List<? extends AnnotationValue> dependencies = (List<? extends AnnotationValue>) dependenciesAnnotationValue.getValue();
for (AnnotationValue dependency : dependencies) {
result.add((TypeElement) ((DeclaredType) dependency.getValue()).asElement());
}
return result;
}
use of javax.lang.model.element.AnnotationValue in project tiger by google.
the class Tiger2Processor method getComponentDependencies.
/**
* Returns dependencies of the give component, empty set if none.
*/
private Set<TypeElement> getComponentDependencies(TypeElement component) {
Set<TypeElement> result = new HashSet<>();
AnnotationMirror componentAnnotationMirror = Preconditions.checkNotNull(utils.getAnnotationMirror(component, Component.class), String.format("@Component not found for %s", component));
AnnotationValue dependenciesAnnotationValue = utils.getAnnotationValue(elements, componentAnnotationMirror, COMPONANT_ANNOTATION_ELEMENT_DEPENDENCIES);
if (dependenciesAnnotationValue == null) {
return result;
}
List<? extends AnnotationValue> dependencies = (List<? extends AnnotationValue>) dependenciesAnnotationValue.getValue();
for (AnnotationValue dependency : dependencies) {
result.add((TypeElement) ((DeclaredType) dependency.getValue()).asElement());
}
return result;
}
use of javax.lang.model.element.AnnotationValue in project tiger by google.
the class Tiger2Processor method verifyComponents.
/**
* Not all combination of eitherComponents are allowed. Here are the limitation.
*
* <pre>
* 1. All eitherComponents must be scoped.
* </pre>
*
* <pre>
* 2. There is at most one dependencies component. This is automatically fulfilled for subcomponents.
* </pre>
*
* <pre>
* 3. Only one root. Forest not supported.
* </pre>
*
* All exceptions are easy to fix, if any. This map to the core injectors very well. Modules
* needed by a core injector but not needed by related component(s) can just be passed in as null
* because it will never be used.
*/
private void verifyComponents(Set<TypeElement> components) {
TypeElement root = null;
for (TypeElement component : components) {
Preconditions.checkNotNull(utils.getScopeType(component, scopeAliasCondenser), String.format("Unscoped component supported : %s", component));
AnnotationMirror annotationMirror = utils.getAnnotationMirror(component, Component.class);
List<AnnotationValue> dependencies = null;
AnnotationValue annotationValue = utils.getAnnotationValue(elements, annotationMirror, COMPONANT_ANNOTATION_ELEMENT_DEPENDENCIES);
if (annotationValue != null) {
dependencies = (List<AnnotationValue>) annotationValue.getValue();
}
if (dependencies == null || dependencies.isEmpty()) {
Preconditions.checkState(root == null, String.format("More than one root eitherComponents found: %s and %s", root, component));
root = component;
} else {
Preconditions.checkState(dependencies.size() == 1, String.format("More than one dependencies found for component: %s", component));
}
}
}
Aggregations