コード例 #1
0
 private static void callOn(Modal modal, String method) {
   try {
     // try with bootstrap 2.0.4.0 signature
     GwtReflectionUtils.callPrivateMethod(modal, method);
   } catch (ReflectionException e) {
     // try with bootstrap 2.1.1.0 signature
     GwtReflectionUtils.callPrivateMethod(modal, method, new Object[] {null});
   }
 }
コード例 #2
0
  private Class<?> getResourceType(String alias, String localName, Map<String, Object> attributes) {
    String type = (String) attributes.get("type");

    if (type == null && "image".equals(localName)) {
      // special code for <ui:image> with no 'type' attribute
      return ImageResource.class;
    } else if (type == null && "style".equals(localName)) {
      // special code for <ui:style> with no 'type' attribute
      return CssResource.class;
    } else if (type == null && "data".equals(localName)) {
      // special code for <ui:data> with no 'type' attribute
      return DataResource.class;
    } else if (type == null) {
      throw new GwtTestUiBinderException(
          "<"
              + localName
              + "> element declared in "
              + owner.getClass().getSimpleName()
              + ".ui.xml must specify a 'type' attribute");
    }

    try {
      return GwtReflectionUtils.getClass(type);
    } catch (ClassNotFoundException e2) {
      throw new GwtTestUiBinderException(
          "Cannot find class '"
              + type
              + "' for resource '"
              + alias
              + "' declared in file '"
              + owner.getClass().getSimpleName()
              + ".ui.xml'");
    }
  }
コード例 #3
0
    private Field getUniqueUiField(String alias) {
      Set<Field> resourceFields = GwtReflectionUtils.getFields(owner.getClass());
      if (resourceFields.size() == 0) {
        return null;
      }

      Field result = null;

      for (Field f : resourceFields) {
        if (alias.equals(f.getName()) && f.isAnnotationPresent(UiField.class)) {
          if (result != null) {
            throw new GwtTestUiBinderException(
                "There are more than one '"
                    + f.getName()
                    + "' @UiField in class '"
                    + owner.getClass().getName()
                    + "' or its superclass");
          }

          result = f;
        }
      }

      return result;
    }
コード例 #4
0
    private void collectSingleImport(
        String importValue, Map<String, Object> resources, Object owner) {
      try {
        int token = importValue.lastIndexOf('.');
        String className = importValue.substring(0, token);
        Class<?> clazz = GwtReflectionUtils.getClass(className);
        String fieldName = importValue.substring(token + 1);

        Object objectToImport = GwtReflectionUtils.getStaticFieldValue(clazz, fieldName);

        // register static field value in UiResourcesManager inner map
        resources.put(fieldName, objectToImport);

      } catch (Exception e) {
        throw new GwtTestUiBinderException(
            "Error while trying to import ui field '" + importValue + "'", e);
      }
    }
コード例 #5
0
    private void collectMultipleImports(
        String importValue, Map<String, Object> resources, Object owner) {

      try {
        String className = importValue.substring(0, importValue.lastIndexOf('.'));

        Class<?> clazz = GwtReflectionUtils.getClass(className);

        // this code handles classes and enums fine
        for (Field field : GwtReflectionUtils.getFields(clazz)) {
          if (Modifier.isStatic(field.getModifiers())
              && !Modifier.isPrivate(field.getModifiers())
              && !Modifier.isProtected(field.getModifiers())) {
            // register static field value in UiResourcesManager inner map
            Object value = GwtReflectionUtils.getStaticFieldValue(clazz, field.getName());
            resources.put(field.getName(), value);
          }
        }

      } catch (Exception e) {
        throw new GwtTestUiBinderException(
            "Error while trying to import multiple ui fields '" + importValue + "'", e);
      }
    }
コード例 #6
0
 protected Set<Field> getMockFields() {
   Set<Field> set = new HashSet<Field>();
   set.addAll(GwtReflectionUtils.getAnnotatedField(this.getClass(), Mock.class).keySet());
   return set;
 }