@Override
public boolean process(Set<? extends TypeElement> type, RoundEnvironment env) {
Elements elementUtils = processingEnv.getElementUtils();
Types typeUtils = processingEnv.getTypeUtils();
Filer filer = processingEnv.getFiler();
TypeElement fragmentType = elementUtils.getTypeElement("android.app.Fragment");
TypeElement supportFragmentType =
elementUtils.getTypeElement("android.support.v4.app.Fragment");
Map<TypeElement, Set<Element>> fieldsByType = new HashMap<TypeElement, Set<Element>>(100);
Element[] origHelper = null;
for (Element element : env.getElementsAnnotatedWith(Arg.class)) {
TypeElement enclosingElement = (TypeElement) element.getEnclosingElement();
// Check if its a fragment
if (!((fragmentType != null && typeUtils.isSubtype(enclosingElement.asType(),
fragmentType.asType())) || (supportFragmentType != null && typeUtils.isSubtype(
enclosingElement.asType(), supportFragmentType.asType())))) {
error(element, "@Arg can only be used on fragment fields (%s.%s)",
enclosingElement.getQualifiedName(), element);
continue;
}
if (element.getModifiers().contains(Modifier.FINAL) || element.getModifiers()
.contains(Modifier.STATIC) || element.getModifiers().contains(Modifier.PRIVATE) || element
.getModifiers()
.contains(Modifier.PROTECTED)) {
error(element, "@Arg fields must not be private, protected, final or static (%s.%s)",
enclosingElement.getQualifiedName(), element);
continue;
}
Set<Element> fields = fieldsByType.get(enclosingElement);
if (fields == null) {
fields = new LinkedHashSet<Element>(10);
fieldsByType.put(enclosingElement, fields);
}
fields.add(element);
}
// Store the key - value for the generated FragmentArtMap class
Map<String, String> autoMapping = new HashMap<String, String>();
for (Map.Entry<TypeElement, Set<Element>> entry : fieldsByType.entrySet()) {
try {
// Skip abstract classes
if (entry.getKey().getModifiers().contains(Modifier.ABSTRACT)) {
continue;
}
String builder = entry.getKey().getSimpleName() + "Builder";
List<Element> originating = new ArrayList<Element>(10);
originating.add(entry.getKey());
TypeMirror superClass = entry.getKey().getSuperclass();
while (superClass.getKind() != TypeKind.NONE) {
TypeElement element = (TypeElement) typeUtils.asElement(superClass);
if (element.getQualifiedName().toString().startsWith("android.")) {
break;
}
originating.add(element);
superClass = element.getSuperclass();