code: private void addGetParcelClass(TypeSpec.Builder classBuilder) {
          MethodSpec.Builder methodBuilder = MethodSpec.methodBuilder("getParcelerClass")
                  .addModifiers(Modifier.PRIVATE)
                  .returns(Class.class)
                  .addParameter(Object.class, "object")
                  .beginControlFlow("if (object != null)")
                  .addStatement("Class objClass = object.getClass()")
                  .addStatement("boolean found = false")
                  .beginControlFlow("while (!found && objClass != null)")
                  .beginControlFlow("try")
                  .addStatement("Class.forName(objClass.getName() + \"$$$$Parcelable\")")
                  .addStatement("found = true")
                  .endControlFlow()
                  .beginControlFlow("catch (ClassNotFoundException ignored)")
                  .addStatement("objClass = objClass.getSuperclass()")
                  .endControlFlow()
                  .endControlFlow()
                  .addStatement("return objClass")
                  .endControlFlow()
                  .addStatement("return null");
  
          classBuilder.addMethod(methodBuilder.build());
      }
docs: getParcelClass method