/**
  * Computes the display string for any value, for a specific type.
  *
  * @param desc the field descriptor - custom formatters are extracted from this descriptor.
  * @param t the value to print
  * @return the formatted string
  */
 public static <T> String print(TypeDescriptor desc, T t) {
   if (t == null) {
     return "";
   }
   if (desc != null && conversion.canConvert(desc, TypeDescriptor.valueOf(String.class))) {
     return (String) conversion.convert(t, desc, TypeDescriptor.valueOf(String.class));
   } else if (conversion.canConvert(t.getClass(), String.class)) {
     return conversion.convert(t, String.class);
   } else {
     return t.toString();
   }
 }
Exemple #2
0
  /**
   * Initializes the expression
   *
   * @param tp the type prefix
   * @param td the type descriptor. The element type of the enclosed initializer will be
   *     automatically and recursively set.
   * @exception IllegalArgumentException if tp is null or td is null
   */
  public ArrayAllocation(TypeName tp, TypeDescriptor td, SourceInfo si) {
    super(si);

    if (tp == null) throw new IllegalArgumentException("tp == null");
    if (td == null) throw new IllegalArgumentException("td == null");
    elementType = tp;
    typeDescriptor = td;
    td.initialize(tp);
  }
 /**
  * Parses this string as instance of a specific field in the given class
  *
  * @param field the related field (custom formatters are extracted from this field annotation)
  * @param text the text to parse
  * @param clazz class representing the required type
  * @return the parsed value
  */
 @SuppressWarnings("unchecked")
 public static <T> T parse(Field field, String text, Class<T> clazz) {
   return (T) conversion.convert(text, new TypeDescriptor(field), TypeDescriptor.valueOf(clazz));
 }
 public Access type() {
   TypeDescriptor d = new TypeDescriptor(p, typeDescriptor);
   return d.type();
 }
 public List parameterListSkipFirst() {
   TypeDescriptor d = new TypeDescriptor(p, parameterDescriptors);
   return d.parameterListSkipFirst();
 }
Exemple #6
0
 /**
  * Note: This method <em>doesn't</em> follow the usual convention of firing a property change. If
  * that functionality is needed, the code should be fixed.
  *
  * @param init An initializer, assumed to already be set up with a valid element type. (The
  *     ArrayInitializer constructor will set up the element type automatically, but this method
  *     does not.)
  */
 public void setInitialization(ArrayInitializer init) {
   typeDescriptor.initialization = init;
 }
Exemple #7
0
 /**
  * Note: This method <em>doesn't</em> follow the usual convention of firing a property change. If
  * that functionality is needed, the code should be fixed.
  */
 public void setSizes(List<? extends Expression> sz) {
   typeDescriptor.sizes = (sz == null) ? null : new ArrayList<Expression>(sz);
 }
Exemple #8
0
 /**
  * Note: This method <em>doesn't</em> follow the usual convention of firing a property change. If
  * that functionality is needed, the code should be fixed.
  */
 public void setDimension(int dim) {
   typeDescriptor.dimension = dim;
 }