Try to generate and cast object to field type or string if possible

@param generator generator
@param fieldType actual field type
@return generated and casted object
16920
@SuppressWarnings("unchecked")
    public static <T> T generateObject(final IGenerator generator,
                                       final Class<T> fieldType) {
        if(generator == null)
            return null;

        final Object object = generator.generate();
        return castObject(object, fieldType);
    }
1161044
private static FieldType getPlaceholder(final Class<?> type, final int fieldID)
   {
      return new FieldType()
      {
         @Override public FieldTypeClass getFieldTypeClass()
         {
            return FieldTypeClass.UNKNOWN;
         }

         @Override public String name()
         {
            return "UNKNOWN";
         }

         @Override public int getValue()
         {
            return fieldID;
         }

         @Override public String getName()
         {
            return "Unknown " + (type == null ? "" : type.getSimpleName() + "(" + fieldID + ")");
         }

         @Override public String getName(Locale locale)
         {
            return getName();
         }

         @Override public DataType getDataType()
         {
            return null;
         }

         @Override public FieldType getUnitsType()
         {
            return null;
         }

         @Override public String toString()
         {
            return getName();
         }
      };
   }
1218384
public static AnnotationTypeFieldBuilder getInstance(
            Context context, ClassDoc classDoc,
            AnnotationTypeFieldWriter writer) {
        return new AnnotationTypeFieldBuilder(context, classDoc,
                    writer, VisibleMemberMap.ANNOTATION_TYPE_FIELDS);
    }
1032192
def get_generator_type(genr):
    
    if genr in _checked_generator_types:
        return _checked_generator_types[genr]
    if not genr.gi_frame is None and 'gen_type' in genr.gi_frame.f_locals:
        return genr.gi_frame.f_locals['gen_type']
    else:
        cllble, nesting, slf = util.get_callable_fq_for_code(genr.gi_code)
        if cllble is None:
            return Generator
        return _funcsigtypes(cllble, slf, nesting[-1] if slf else None,
                genr.gi_frame.f_globals if not genr.gi_frame is None else None)[1]
193142
public AbstractBuilder getFieldBuilder(ClassWriter classWriter) {
        return FieldBuilder.getInstance(context, classWriter.getTypeElement(),
            writerFactory.getFieldWriter(classWriter));
    }
923470
@Nullable
  public SoyType getFieldType(String fieldName) {
    FieldWithType field = fields.get(fieldName);
    return field != null ? field.getType() : null;
  }
536385
@Override
    public Object generate(TableGeneratorDiscriptor discriptor, ClientBase client, String dataType)
    {
        Cassandra.Client conn = ((CassandraClientBase) client).getRawClient(discriptor.getSchema());
        long latestCount = 0l;
        try
        {
            conn.set_keyspace(discriptor.getSchema());

            if (((CassandraClientBase) client).isCql3Enabled())
            {
                CQLTranslator translator = new CQLTranslator();
                ((CassandraClientBase) client).execute(translator.buildUpdateQuery(discriptor).toString(), conn);

                CqlResult result = ((CassandraClientBase) client).execute(translator.buildSelectQuery(discriptor)
                        .toString(), conn);

                for (CqlRow row : result.getRows())
                {
                    latestCount = ByteBufferUtil.toLong(ByteBuffer.wrap(row.getColumns().get(0).getValue()));
                }
            }
            else
            {

                ColumnPath columnPath = new ColumnPath(discriptor.getTable());
                columnPath.setColumn(discriptor.getValueColumnName().getBytes());

                try
                {
                    latestCount = conn.get(ByteBuffer.wrap(discriptor.getPkColumnValue().getBytes()), columnPath,
                            ((CassandraClientBase) client).getConsistencyLevel()).counter_column.value;
                }
                catch (NotFoundException e)
                {
                    log.warn("Counter value not found for {}, resetting it to zero.", discriptor.getPkColumnName());
                    latestCount = 0;
                }
                ColumnParent columnParent = new ColumnParent(discriptor.getTable());

                CounterColumn counterColumn = new CounterColumn(ByteBuffer.wrap(discriptor.getValueColumnName()
                        .getBytes()), 1);

                conn.add(ByteBuffer.wrap(discriptor.getPkColumnValue().getBytes()), columnParent, counterColumn,
                        ((CassandraClientBase) client).getConsistencyLevel());
            }
            if (latestCount == 0)
            {
                return (long) discriptor.getInitialValue();
            }
            else
            {
                return (latestCount + 1) * discriptor.getAllocationSize();
            }
        }
        catch (UnavailableException e)
        {
            log.error("Error while reading counter value from table{}, Caused by: .", discriptor.getTable(), e);
            throw new KunderaException(e);
        }
        catch (TimedOutException e)
        {
            log.error("Error while reading counter value from table{}, Caused by: .", discriptor.getTable(), e);
            throw new KunderaException(e);
        }
        catch (Exception e)
        {
            log.error("Error while using keyspace. Caused by: .", e);
            throw new KunderaException(e);
        }
    }
71848
public static Object serializeField(ObjectMapper objectMapper, Object value) {
        if (value == null || BASIC_TYPES.contains(value.getClass())) {
            // Return as is
            return value;
        } else if (value instanceof DBObject) {
            return serializeFields(objectMapper, (DBObject) value);
        } else if (value instanceof Collection) {
            Collection<?> coll = (Collection<?>) value;
            List<Object> copy = null;
            int position = 0;
            for (Object item : coll) {
                Object returned = serializeField(objectMapper, item);
                if (returned != item) {
                    if (copy == null) {
                        copy = new ArrayList<Object>(coll);
                    }
                    copy.set(position, returned);
                }
                position++;
            }
            if (copy != null) {
                return copy;
            } else {
                return coll;
            }
        } else if (value.getClass().isArray()) {
            if (BASIC_TYPES.contains(value.getClass().getComponentType())) {
                return value;
            }
            Object[] array = (Object[]) value;
            Object[] copy = null;
            for (int i = 0; i < array.length; i++) {
                Object returned = serializeField(objectMapper, array[i]);
                if (returned != array[i]) {
                    if (copy == null) {
                        copy = new Object[array.length];
                        System.arraycopy(array, 0, copy, 0, array.length);
                    }
                    copy[i] = returned;
                }
            }
            if (copy != null) {
                return copy;
            } else {
                return array;
            }
        } else {
            // We don't know what it is, serialise it
            BsonObjectGenerator generator = new BsonObjectGenerator();
            try {
                objectMapper.writeValue(generator, value);
            } catch (JsonMappingException e) {
                throw new MongoJsonMappingException(e);
            } catch (IOException e) {
                throw new RuntimeException("Somehow got an IOException writing to memory", e);
            }
            return generator.getValue();
        }
    }
178635
public AbstractBuilder getAnnotationTypeFieldsBuilder(
            AnnotationTypeWriter annotationTypeWriter)
    throws Exception {
        return AnnotationTypeFieldBuilder.getInstance(context,
            annotationTypeWriter.getAnnotationTypeDoc(),
            writerFactory.getAnnotationTypeFieldWriter(
                annotationTypeWriter));
    }
818328
public static FieldBuilder getInstance(Context context,
            TypeElement typeElement,
            FieldWriter writer) {
        return new FieldBuilder(context, typeElement, writer);
    }
613848
public static Class<?> getParameterTypeOfRepeatedField(Field field) {
    Class<?> componentType = null;
    if (isCollection(field.getType())) {
      validateCollection(field);
      Type parameterType = getParameterType((ParameterizedType) field.getGenericType());
      validateNestedParameterizedType(parameterType);
      componentType = (Class<?>) parameterType;
    } else if (field.getType().isArray()) {
      componentType = field.getType().getComponentType();
      return componentType;
    } else {
      throw new IllegalArgumentException("Unsupported repeated type " + field.getType()
          + " Allowed repeated fields are Collection<T> and arrays");
    }
    validateNestedRepeatedType(componentType, field);
    return componentType;
  }
95020
public static final FieldType getInstance(int fieldID)
   {
      FieldType result;
      int prefix = fieldID & 0xFFFF0000;
      int index = fieldID & 0x0000FFFF;

      switch (prefix)
      {
         case MPPTaskField.TASK_FIELD_BASE:
         {
            result = MPPTaskField.getInstance(index);
            if (result == null)
            {
               result = getPlaceholder(TaskField.class, index);
            }
            break;
         }

         case MPPResourceField.RESOURCE_FIELD_BASE:
         {
            result = MPPResourceField.getInstance(index);
            if (result == null)
            {
               result = getPlaceholder(ResourceField.class, index);
            }
            break;
         }

         case MPPAssignmentField.ASSIGNMENT_FIELD_BASE:
         {
            result = MPPAssignmentField.getInstance(index);
            if (result == null)
            {
               result = getPlaceholder(AssignmentField.class, index);
            }
            break;
         }

         case MPPConstraintField.CONSTRAINT_FIELD_BASE:
         {
            result = MPPConstraintField.getInstance(index);
            if (result == null)
            {
               result = getPlaceholder(ConstraintField.class, index);
            }
            break;
         }

         default:
         {
            result = getPlaceholder(null, index);
            break;
         }
      }

      return result;
   }
416886
public static FieldBuilder getInstance(Context context,
            ClassDoc classDoc,
            FieldWriter writer) {
        return new FieldBuilder(context, classDoc, writer);
    }
536569
function getPossibleTypeNames(generator, property) {
  return generator.context.schema.getPossibleTypes(getNamedType(property.fieldType || property.type)).map(type => type.name);
}
550479
public static Method getSetter(String fieldName, Class<?> clazz, Class<?> fieldType) {
    String setterName = buildSetterName(fieldName);
    try {
      // Using getMathods(), getMathod(...) expects exact parameter type
      // matching and ignores inheritance-tree.
      Method[] methods = clazz.getMethods();
      for(Method method : methods) {
        if(method.getName().equals(setterName)) {
          Class<?>[] paramTypes = method.getParameterTypes();
          if(paramTypes != null && paramTypes.length == 1 && paramTypes[0].isAssignableFrom(fieldType)) {
            return method;
          }
        }
      }
      return null;
    }
    catch (SecurityException e) {
      throw LOG.unableToAccessMethod(setterName, clazz.getName());
    }
  }
617231
public static Class<?> getGenericTypeOfCollectionField(Field field) {
        Type genericType = field.getGenericType();

        if (!(genericType instanceof ParameterizedType)) {
            throw new IllegalArgumentException("Field is not a ParameterizedType.");
        }

        Type[] genericTypes = ((ParameterizedType) genericType).getActualTypeArguments();


        if (genericTypes.length != 1) {
            throw new IllegalArgumentException("Field does not have a single generic type.");
        }

        if (!(genericTypes[0] instanceof Class)) {
            throw new IllegalArgumentException("Field's generic type is not a class?");
        }

        return (Class<?>) genericTypes[0];
    }
3106
public DateTimeFormatterBuilder appendText(DateTimeFieldType fieldType) {
        if (fieldType == null) {
            throw new IllegalArgumentException("Field type must not be null");
        }
        return append0(new TextField(fieldType, false));
    }