示例#1
0
 @Override
 public String toString() {
   StringBuilder b = new StringBuilder();
   for (Class<?> ann : annotations) {
     b.append(ann.getSimpleName()).append(' ');
   }
   b.append((type instanceof Class<?>) ? ((Class<?>) type).getSimpleName() : type.toString());
   return b.toString();
 }
  public DataConverter(Class<T> clazz)
      throws TooManyPrimaryKeys, NotAnnotatedAsTableClassException, PrimaryKeyIsNotColumnException,
          NoPrimaryKeyException {
    if (clazz.getAnnotation(Table.class) == null) {
      throw new NotAnnotatedAsTableClassException();
    } else {
      if (!clazz.getDeclaredAnnotation(Table.class).name().equals("")) {
        tableName = clazz.getDeclaredAnnotation(Table.class).name();
      } else {
        tableName = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, clazz.getSimpleName());
      }
    }
    fields = new ArrayList<FieldConverter>();
    for (Field field : clazz.getDeclaredFields()) {
      Class<?> type = field.getType();
      Annotation primaryKeyAnnotation = field.getDeclaredAnnotation(PrimaryKey.class),
          columnAnnotation = field.getDeclaredAnnotation(Column.class);

      if (primaryKeyAnnotation != null) {
        if (columnAnnotation == null) {
          throw new PrimaryKeyIsNotColumnException();
        }
        if (primaryKeyField != null) {
          throw new TooManyPrimaryKeys();
        }
        primaryKeyField = field;
      }
      if (columnAnnotation != null) {
        String name = null;
        if (!field.getDeclaredAnnotation(Column.class).name().equals("")) {
          name = field.getDeclaredAnnotation(Column.class).name();
        } else {
          name = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, field.getName());
        }
        FieldConverter currentFieldConverter = new FieldConverter(name, field);
        fields.add(currentFieldConverter);
        if (field.equals(primaryKeyField)) {
          primaryKeyFieldConverter = currentFieldConverter;
        }
      }
      Annotation[] annotations = field.getDeclaredAnnotations();
      for (Annotation annotation : annotations) {
        annotation.getClass();
      }
    }
    if (primaryKeyField == null) {
      throw new NoPrimaryKeyException();
    }
  }
示例#3
0
    public boolean matchesDestructor(Class<?> type) {
      if (!symbol.contains(type.getSimpleName())) {
        return false;
      }

      parse();

      try {
        if (ref != null) {
          return ref.matchesDestructor(type);
        }
      } catch (Exception ex) {
        ex.printStackTrace();
      }
      return false;
    }
示例#4
0
 public boolean matches(Type type, Annotations annotations) {
   String thisName = getQualifiedName(new StringBuilder(), false).toString();
   Class typeClass = getTypeClass(type);
   String typeName = typeClass.getSimpleName();
   return thisName.equals(typeName) || thisName.equals(typeClass.getName());
 }