processor/src/main/java/com/hannesdorfmann/parcelableplease/processor/codegenerator/SupportedTypes.java
public static TypeMirror hasGenericsTypeArgumentOf(Element element, String typeToCheck,
                                                     Elements elements, Types types) {

    if (element.asType().getKind() != TypeKind.DECLARED
        || !(element.asType() instanceof DeclaredType)) {
      ProcessorMessage.error(element, "The field %s in %s doesn't have generic type arguments!",
          element.getSimpleName(), element.asType().toString());
    }

    DeclaredType declaredType = (DeclaredType) element.asType();
    List<? extends TypeMirror> typeArguments = declaredType.getTypeArguments();

    if (typeArguments.isEmpty()) {
      ProcessorMessage.error(element, "The field %s in %s doesn't have generic type arguments!",
          element.getSimpleName(), element.asType().toString());
    }

    if (typeArguments.size() > 1) {
      ProcessorMessage.error(element, "The field %s in %s has more than 1 generic type argument!",
          element.getSimpleName(), element.asType().toString());
    }

    // Ok it has a generic argument, check if this extends Parcelable
    TypeMirror argument = typeArguments.get(0);

    if (typeToCheck != null) {
      if (!isOfType(argument, typeToCheck, elements, types)) {
        ProcessorMessage.error(element,
            "The fields %s  generic type argument is not of type  %s! (in %s )",
            element.getSimpleName(), typeToCheck, element.asType().toString());
      }
    }

    // everything is like expected
    return argument;
  }
public static TypeMirror hasGenericsTypeArgumentOf(Element element, String typeToCheck,
                                                     Elements elements, Types types) {

    if (element.asType().getKind() != TypeKind.DECLARED
        || !(element.asType() instanceof DeclaredType)) {
      ProcessorMessage.error(element, "The field %s in %s doesn't have generic type arguments!",
          element.getSimpleName(), element.asType().toString());
    }

    DeclaredType declaredType = (DeclaredType) element.asType();
    List<? extends TypeMirror> typeArguments = declaredType.getTypeArguments();

    if (typeArguments.isEmpty()) {
      ProcessorMessage.error(element, "The field %s in %s doesn't have generic type arguments!",
          element.getSimpleName(), element.asType().toString());
    }

    if (typeArguments.size() > 1) {
      ProcessorMessage.error(element, "The field %s in %s has more than 1 generic type argument!",
          element.getSimpleName(), element.asType().toString());
    }

    // Ok it has a generic argument, check if this extends Parcelable
    TypeMirror argument = typeArguments.get(0);

    if (typeToCheck != null) {
      if (!isOfType(argument, typeToCheck, elements, types)) {
        ProcessorMessage.error(element,
            "The fields %s  generic type argument is not of type  %s! (in %s )",
            element.getSimpleName(), typeToCheck, element.asType().toString());
      }
    }

    // everything is like expected
    return argument;
  }
Checks if the variabel element has generics arguments that matches the expected type