package icepick.annotation;

import javax.lang.model.element.Element;
import javax.lang.model.type.TypeMirror;
import javax.lang.model.util.Elements;
import javax.lang.model.util.Types;

class IcicleField {

    public final String name;
    public final String typeCast;
    public final String command;

    IcicleField(String name, String typeCast, String command) {
        this.name = name;
        this.command = command;
        this.typeCast = typeCast;
    }

    static class Factory {

        private final Types typeUtils;
        private final IcicleConversionMap conversionMap;

        Factory(Elements elementUtils, Types typeUtils) {
            this.typeUtils = typeUtils;
            this.conversionMap = new IcicleConversionMap(elementUtils, typeUtils);
        }

        public IcicleField from(Element element) {
            TypeMirror typeMirror = element.asType();
            String command = convert(typeMirror);
            String typeCast = IcicleConversionMap.TYPE_CAST_COMMANDS.contains(command) ? "(" + typeMirror.toString() + ")" : "";
            String name = element.getSimpleName().toString();
            return new IcicleField(name, typeCast, command);
        }

        public String convert(TypeMirror typeMirror) {
            for (TypeMirror other : conversionMap.keySet()) {
                if (typeUtils.isAssignable(typeMirror, other)) {
                    return conversionMap.get(other);
                }
            }
            throw new AssertionError("Cannot insert a " + typeMirror + " into a Bundle");
        }
    }
}

@@ -1206,21 +1206,22 @@
        p
-ublic
+rivate
  String 
@@ -1491,54 +1491,258 @@
 new 
-AssertionError(%22Cannot insert a %22 + typeMirror
+UnableToSerializeException(typeMirror);%0A        %7D%0A    %7D%0A%0A    public static class UnableToSerializeException extends RuntimeException %7B%0A        UnableToSerializeException(TypeMirror fieldType) %7B%0A            super(%22Don't know how to put a %22 + fieldType
  + %22

Add a proper exception type for failed conversion