use of javax.lang.model.element.AnnotationValue in project tiger by google.
the class Tiger3ProcessorForPackaged method collectComponentToParentMapByModule.
/**
* Return mappings by checking (sub)component -> module -> subcomponent.
*/
private Map<TypeElement, TypeElement> collectComponentToParentMapByModule(Set<TypeElement> components) {
Map<TypeElement, TypeElement> result = new HashMap<>();
for (TypeElement c : components) {
for (TypeElement module : utils.findAllModulesOfComponentRecursively(c)) {
AnnotationMirror annotationMirror = utils.getAnnotationMirror(module, Module.class);
AnnotationValue subcomponentsAnnotationValue = Utils.getAnnotationValue(elements, annotationMirror, MODULE_ANNOTATION_ELEMENT_SUBCOMPONENTS);
if (subcomponentsAnnotationValue == null) {
continue;
}
for (AnnotationValue av : (List<AnnotationValue>) subcomponentsAnnotationValue.getValue()) {
TypeElement subcomponent = (TypeElement) ((DeclaredType) av.getValue()).asElement();
Preconditions.checkState(utils.isSubcomponent(subcomponent));
result.put(subcomponent, c);
}
}
}
logger.n("result" + result);
return result;
}
use of javax.lang.model.element.AnnotationValue in project tiger by google.
the class TigerDaggerGeneratorProcessor method getModulesInComponents.
private void getModulesInComponents(Collection<? extends Element> components, SetMultimap<CoreInjectorInfo, TypeElement> scopeModules, Set<TypeElement> unscopedModules) {
Set<TypeElement> modules = new HashSet<>();
for (Element component : components) {
AnnotationMirror componentAnnotationMirror = utils.isComponent(component) ? utils.getAnnotationMirror(component, Component.class) : utils.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());
}
}
}
modules = utils.findAllModulesRecursively(modules, elements);
for (TypeElement module : modules) {
TypeElement scopeType = utils.getModuleScope((DeclaredType) module.asType(), scopeAliasCondenser);
if (scopeType != null) {
scopeModules.put(new CoreInjectorInfo(scopeType), module);
} else {
unscopedModules.add(module);
}
}
}
use of javax.lang.model.element.AnnotationValue in project tiger by google.
the class Tiger2Processor method findDirectModules.
private void findDirectModules(Set<TypeElement> modules, Element component) {
AnnotationMirror componentAnnotationMirror = utils.isComponent(component) ? utils.getAnnotationMirror(component, Component.class) : utils.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 dubbo by alibaba.
the class AnnotationUtils method getAttribute.
static <T> T getAttribute(Map<? extends ExecutableElement, ? extends AnnotationValue> attributesMap, String attributeName) {
T annotationValue = null;
for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : attributesMap.entrySet()) {
ExecutableElement attributeMethod = entry.getKey();
if (Objects.equals(attributeName, attributeMethod.getSimpleName().toString())) {
TypeMirror attributeType = attributeMethod.getReturnType();
AnnotationValue value = entry.getValue();
if (attributeType instanceof ArrayType) {
// array-typed attribute values
ArrayType arrayType = (ArrayType) attributeType;
String componentType = arrayType.getComponentType().toString();
ClassLoader classLoader = AnnotationUtils.class.getClassLoader();
List<AnnotationValue> values = (List<AnnotationValue>) value.getValue();
int size = values.size();
try {
Class componentClass = classLoader.loadClass(componentType);
boolean isEnum = componentClass.isEnum();
Object array = Array.newInstance(componentClass, values.size());
for (int i = 0; i < size; i++) {
Object element = values.get(i).getValue();
if (isEnum) {
element = valueOf(componentClass, element.toString());
}
Array.set(array, i, element);
}
annotationValue = (T) array;
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
} else {
annotationValue = (T) value.getValue();
}
break;
}
}
return annotationValue;
}
use of javax.lang.model.element.AnnotationValue in project androidannotations by androidannotations.
the class AnnotationHelper method extractAnnotationClassParameter.
public DeclaredType extractAnnotationClassParameter(Element element, String annotationName, String methodName) {
AnnotationMirror annotationMirror = findAnnotationMirror(element, annotationName);
Map<? extends ExecutableElement, ? extends AnnotationValue> elementValues = annotationMirror.getElementValues();
for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : elementValues.entrySet()) {
/*
* "methodName" is unset when the default value is used
*/
if (methodName.equals(entry.getKey().getSimpleName().toString())) {
AnnotationValue annotationValue = entry.getValue();
return (DeclaredType) annotationValue.getValue();
}
}
return null;
}
Aggregations