コード例 #1
0
  /**
   * Checks if specified field requires recursive inspection to find resource annotations.
   *
   * @param f Field.
   * @return {@code true} if requires, {@code false} if doesn't.
   */
  static boolean mayRequireResources(Field f) {
    assert f != null;

    // Need to inspect anonymous classes, callable and runnable instances.
    return f.getName().startsWith("this$")
        || f.getName().startsWith("val$")
        || Callable.class.isAssignableFrom(f.getType())
        || Runnable.class.isAssignableFrom(f.getType());
  }
コード例 #2
0
ファイル: JiraIssues.java プロジェクト: darkowl91/hotfix
 private String field(Issue issue, TicketFields filed) {
   Field field = issue.getFieldByName(filed.getName());
   if (field != null) {
     Object fieldValue = field.getValue();
     if (fieldValue != null) {
       return fieldValue.toString();
     }
   }
   return "";
 }
コード例 #3
0
  /**
   * Copy from the copy method in StructUtil. Did not want to drag that code in. maybe this actually
   * should go to struct.
   *
   * @param from
   * @param to
   * @param excludes
   * @return
   * @throws Exception
   */
  public static <T extends struct> T xcopy(struct from, T to, String... excludes) throws Exception {
    Arrays.sort(excludes);
    for (Field f : from.fields()) {
      if (Arrays.binarySearch(excludes, f.getName()) >= 0) continue;

      Object o = f.get(from);
      if (o == null) continue;

      Field tof = to.getField(f.getName());
      if (tof != null)
        try {
          tof.set(to, Converter.cnv(tof.getGenericType(), o));
        } catch (Exception e) {
          System.out.println(
              "Failed to convert "
                  + f.getName()
                  + " from "
                  + from.getClass()
                  + " to "
                  + to.getClass()
                  + " value "
                  + o
                  + " exception "
                  + e);
        }
    }

    return to;
  }
コード例 #4
0
  /**
   * Sets the field represented by this {@code field} object on the specified object argument {@code
   * target} to the specified new value {@code rsrc}.
   *
   * @param field Field where resource should be injected.
   * @param target Target object.
   * @param rsrc Resource object which should be injected in target object field.
   * @throws GridException Thrown if unable to inject resource.
   */
  @SuppressWarnings({"ErrorNotRethrown"})
  static void inject(Field field, Object target, Object rsrc) throws GridException {
    if (rsrc != null && !field.getType().isAssignableFrom(rsrc.getClass()))
      throw new GridException(
          "Resource field is not assignable from the resource: " + rsrc.getClass());

    try {
      // Override default Java access check.
      field.setAccessible(true);

      field.set(target, rsrc);
    } catch (SecurityException | ExceptionInInitializerError | IllegalAccessException e) {
      throw new GridException(
          "Failed to inject resource [field="
              + field.getName()
              + ", target="
              + target
              + ", rsrc="
              + rsrc
              + ']',
          e);
    }
  }