Exemplo n.º 1
0
 private static Method getBaselineMethod(JComponent component) {
   if (COMPONENT_BASELINE_METHOD != null) {
     return COMPONENT_BASELINE_METHOD;
   }
   Class klass = component.getClass();
   while (klass != null) {
     if (BASELINE_MAP.containsKey(klass)) {
       Method method = (Method) BASELINE_MAP.get(klass);
       return method;
     }
     klass = klass.getSuperclass();
   }
   klass = component.getClass();
   Method[] methods = klass.getMethods();
   for (int i = methods.length - 1; i >= 0; i--) {
     Method method = methods[i];
     if ("getBaseline".equals(method.getName())) {
       Class[] params = method.getParameterTypes();
       if (params.length == 2 && params[0] == int.class && params[1] == int.class) {
         BASELINE_MAP.put(klass, method);
         return method;
       }
     }
   }
   BASELINE_MAP.put(klass, null);
   return null;
 }
Exemplo n.º 2
0
 private boolean isSynthIcon(Icon icon) {
   if (_synthIconMap == null) {
     _synthIconMap = new HashMap<String, Boolean>();
   }
   Class<?> aClass = icon.getClass();
   java.util.List<String> classNamesToPut = new ArrayList<String>();
   boolean isSynthIcon = false;
   while (aClass != null) {
     String name = aClass.getCanonicalName();
     if (name != null) {
       Boolean value = _synthIconMap.get(name);
       if (value != null) {
         return value;
       }
       classNamesToPut.add(name);
       if (isSynthIconClassName(name)) {
         isSynthIcon = true;
         break;
       }
     }
     aClass = aClass.getSuperclass();
   }
   for (String name : classNamesToPut) {
     _synthIconMap.put(name, isSynthIcon);
   }
   return isSynthIcon;
 }
Exemplo n.º 3
0
  /**
   * @param methodName getter method
   * @param clazz value object class
   * @return attribute name related to the specified getter method
   */
  private String getAttributeName(String methodName, Class classType) {
    String attributeName = null;
    if (methodName.startsWith("is"))
      attributeName =
          methodName.substring(2, 3).toLowerCase()
              + (methodName.length() > 3 ? methodName.substring(3) : "");
    else
      attributeName =
          methodName.substring(3, 4).toLowerCase()
              + (methodName.length() > 4 ? methodName.substring(4) : "");

    // an attribute name "Xxxx" becomes "xxxx" and this is not correct!
    try {
      Class c = classType;
      boolean attributeFound = false;
      while (!c.equals(Object.class)) {
        try {
          c.getDeclaredField(attributeName);
          attributeFound = true;
          break;
        } catch (Throwable ex2) {
          c = c.getSuperclass();
        }
      }
      if (!attributeFound) {
        // now trying to find an attribute having the first character in upper case (e.g. "Xxxx")
        String name = attributeName.substring(0, 1).toUpperCase() + attributeName.substring(1);
        c = classType;
        while (!c.equals(Object.class)) {
          try {
            c.getDeclaredField(name);
            attributeFound = true;
            break;
          } catch (Throwable ex2) {
            c = c.getSuperclass();
          }
        }
        if (attributeFound) attributeName = name;
      }
    } catch (Throwable ex1) {
    }

    return attributeName;
  }
Exemplo n.º 4
0
  private void resetClassFields(final Class<?> aClass) {
    try {
      UsefulTestCase.clearDeclaredFields(this, aClass);
    } catch (IllegalAccessException e) {
      throw new RuntimeException(e);
    }

    if (aClass == LightPlatformTestCase.class) return;
    resetClassFields(aClass.getSuperclass());
  }
  private void resetClassFields(final Class<?> aClass) {
    try {
      clearDeclaredFields(this, aClass);
    } catch (IllegalAccessException e) {
      LOG.error(e);
    }

    if (aClass == PlatformTestCase.class) return;
    resetClassFields(aClass.getSuperclass());
  }
  /**
   * Helper method to lookup a cell renderer based on type.
   *
   * @param type the type for which a renderer should be found
   * @return a renderer for the given object type
   */
  private TableCellRenderer getCellRenderer(Class type) {
    // try to create one from the factory
    TableCellRenderer renderer = getRendererFactory().createTableCellRenderer(type);

    // if that fails, recursively try again with the superclass
    if (renderer == null && type != null) renderer = getCellRenderer(type.getSuperclass());

    // if that fails, just use the default Object renderer
    if (renderer == null) renderer = super.getDefaultRenderer(Object.class);

    return renderer;
  }
 private static Method findMethod(
     Class<? extends Object> aClass, String methodName, Class[] params) {
   try {
     final Method method = aClass.getDeclaredMethod(methodName, params);
     method.setAccessible(true);
     return method;
   } catch (NoSuchMethodException ignored) {
   }
   final Class<?> parent = aClass.getSuperclass();
   if (parent == null) {
     return null;
   }
   return findMethod(parent, methodName, params);
 }
 public static boolean canRunTest(@NotNull Class testCaseClass) {
   if (GraphicsEnvironment.isHeadless()) {
     for (Class<?> clazz = testCaseClass; clazz != null; clazz = clazz.getSuperclass()) {
       if (clazz.getAnnotation(SkipInHeadlessEnvironment.class) != null) {
         System.out.println(
             "Class '"
                 + testCaseClass.getName()
                 + "' is skipped because it requires working UI environment");
         return false;
       }
     }
   }
   return true;
 }
Exemplo n.º 9
0
    private static void fixPopupSize(final Popup popup, final Component contents) {
      if (!UIUtil.isUnderGTKLookAndFeel() || !(contents instanceof JPopupMenu)) return;

      for (Class<?> aClass = popup.getClass();
          aClass != null && Popup.class.isAssignableFrom(aClass);
          aClass = aClass.getSuperclass()) {
        try {
          final Method getComponent = aClass.getDeclaredMethod("getComponent");
          getComponent.setAccessible(true);
          final Object component = getComponent.invoke(popup);
          if (component instanceof JWindow) {
            ((JWindow) component).setSize(new Dimension(0, 0));
          }
          break;
        } catch (Exception ignored) {
        }
      }
    }
Exemplo n.º 10
0
  public static void get(Class clazz) {
    //
    // Gets array of direct interface of clazz object
    //
    Class[] interfaces = clazz.getInterfaces();

    System.out.format("Direct Interfaces of %s:%n", clazz.getName());
    for (Class clz : interfaces) {
      System.out.println(clz.getName());
    }

    //
    // Gets direct superclass of clazz object
    //
    Class superclz = clazz.getSuperclass();
    System.out.format("Direct Superclass of %s: is %s %n", clazz.getName(), superclz.getName());
    System.out.println("====================================");
  }
  /**
   * Construct a variable
   *
   * @param aType the type
   * @param aName the name
   * @param aValue the value
   */
  public Variable(Class<?> aType, String aName, Object aValue) {
    type = aType;
    name = aName;
    value = aValue;
    fields = new ArrayList<Field>();

    // find all fields if we have a class type except we don't expand strings and null values

    if (!type.isPrimitive() && !type.isArray() && !type.equals(String.class) && value != null) {
      // get fields from the class and all superclasses
      for (Class<?> c = value.getClass(); c != null; c = c.getSuperclass()) {
        Field[] fs = c.getDeclaredFields();
        AccessibleObject.setAccessible(fs, true);

        // get all nonstatic fields
        for (Field f : fs) if ((f.getModifiers() & Modifier.STATIC) == 0) fields.add(f);
      }
    }
  }
Exemplo n.º 12
0
 private static Method getBRBIMethod(Component component) {
   Class klass = component.getClass();
   while (klass != null) {
     if (BRB_I_MAP.containsKey(klass)) {
       Method method = (Method) BRB_I_MAP.get(klass);
       return method;
     }
     klass = klass.getSuperclass();
   }
   klass = component.getClass();
   Method[] methods = klass.getMethods();
   for (int i = methods.length - 1; i >= 0; i--) {
     Method method = methods[i];
     if ("getBaselineResizeBehaviorInt".equals(method.getName())) {
       Class[] params = method.getParameterTypes();
       if (params.length == 0) {
         BRB_I_MAP.put(klass, method);
         return method;
       }
     }
   }
   BRB_I_MAP.put(klass, null);
   return null;
 }