private Pair<String, List<Object>> mapCall( Field field, CallFormat call, String target, String parcel) { Object[] formatArgs = new Object[call.getArgs().length]; List<Object> args = new ArrayList<>(call.getArgs().length); for (int j = 0, d = call.getArgs().length; j < d; j++) { CallFormat.Arg arg = call.getArgs()[j]; switch (arg) { case PARCEL: { formatArgs[j] = "$N"; args.add(parcel); break; } case TARGET_GETTER: { if (field.isAccessible()) { formatArgs[j] = "$N.$N"; args.add(target); args.add(field.element.getSimpleName()); } else { formatArgs[j] = "$N.$N()"; args.add(target); args.add(field.getter.getSimpleName()); } break; } case RAW_TYPE: { TypeName rawType = ProcessorUtils.getRawType(field.element.asType()); formatArgs[j] = "$T"; args.add(rawType); break; } case CLASS_LOADER_OR_NULL: { TypeName rawType = ProcessorUtils.getRawType(field.element.asType()); if (rawType != null) { formatArgs[j] = "$T.class.getClassLoader()"; args.add(rawType); } else { formatArgs[j] = "null"; } break; } case TYPE: { formatArgs[j] = "$T"; args.add(field.element.asType()); break; } default: throw new IllegalStateException(); } } String format = String.format(call.getFormat(), formatArgs); return new Pair<>(format, args); }
@Override public void checkClass(TypeElement e) throws ProcessorError { // support any class that implements Parcelable if (!ProcessorUtils.isSubClassOf(e, Parcelable.class)) { throw new ProcessorError(e, ParcelErrorMsg.Invalid_Parcel_class); } // check constructor if (!hasParcelableConstructor(e)) { throw new ProcessorError(e, ParcelErrorMsg.Parcel_class_without_constructor); } }