public static boolean fieldHasAnnotation(Field field, Class annotationClass, Class interfaceClass) { return isInterface(field, interfaceClass) && field.isAnnotationPresent(annotationClass); } }
public static boolean fieldHasAnnotation(Field field, Class annotationClass, Class interfaceClass) { return isInterface(field, interfaceClass) && field.isAnnotationPresent(annotationClass); } }
public static boolean isInterface(Field field, Class<?> expected) { return isInterface(field.getType(), expected); }
public static boolean isInterface(Field field, Class<?> expected) { return isInterface(field.getType(), expected); }
public static boolean isInterface(Class<?> type, Class<?> expected) { if (type == null || expected == null || type == Object.class) return false; if (type == expected) return true; List<Class> interfaces = asList(type.getInterfaces()); return any(interfaces, i -> isInterface(i, expected)) || isInterface(type.getSuperclass(), expected); }
private boolean isObjEmpty(Object obj) { if (obj == null) return true; if (obj instanceof String) return obj.toString().equals(""); if (isInterface(obj.getClass(), Collection.class)) return ((Collection) obj).isEmpty(); return obj.getClass().isArray() && getLength(obj) == 0; }
public static boolean isInterface(Class<?> type, Class<?> expected) { if (type == null || expected == null || type == Object.class) return false; if (type == expected) return true; List<Class> interfaces = asList(type.getInterfaces()); return any(interfaces, i -> isInterface(i, expected)) || isInterface(type.getSuperclass(), expected); }
private static void setUpTableFromAnnotation(BaseElement instance, Field field) { JTable jTable = field.getAnnotation(JTable.class); if (jTable == null || !isInterface(field, ITable.class)) return; setUpTable((Table) instance, jTable); } private static void setUpDropdownFromAnnotation(BaseElement instance, Field field) {
private static boolean isExpectedClass(Field field, Class<?>... types) { if (types == null || types.length == 0) return true; for (Class<?> type : types) if (isClass(field, type) || isInterface(field, type)) return true; return false; }
private static void setUpMenuFromAnnotation(BaseElement instance, Field field) { JMenu jMenu = field.getAnnotation(JMenu.class); if (jMenu == null || !isInterface(field, IMenu.class)) return; setUpMenu((Menu) instance, jMenu); }
private static boolean isExpectedClass(Field field, Class<?>... types) { if (types == null || types.length == 0) return true; for (Class<?> type : types) if (isClass(field, type) || isInterface(field, type)) return true; return false; }
private static void setUpDropdownFromAnnotation(BaseElement instance, Field field) { JDropdown jDropdown = field.getAnnotation(JDropdown.class); if (jDropdown == null || !isInterface(field, IDropDown.class)) return; setUpDropdown((Dropdown) instance, jDropdown); } private static void setUpMenuFromAnnotation(BaseElement instance, Field field) {
@Override public WebElement getWebElement() { if (avatar.hasWebElement()) return avatar.getElement(); Object parent = getParent(); return parent != null && isInterface(parent.getClass(), IHasElement.class) ? ((IHasElement)parent).getWebElement() : null; } public void setWebElement(WebElement webElement) {
public WebElement getWebElement() { if (avatar.hasWebElement()) return avatar.getElement(); Object parent = getParent(); return parent != null && isInterface(parent.getClass(), IHasElement.class) ? ((IHasElement)parent).getWebElement() : null; } public void setWebElement(WebElement webElement) {
@Override public WebElement getWebElement() { if (avatar.hasWebElement()) return avatar.getElement(); Object parent = getParent(); return parent != null && isInterface(parent.getClass(), IHasElement.class) ? ((IHasElement)parent).getWebElement() : null; } public void setWebElement(WebElement webElement) {
private void setElement(Object parent, Class<?> parentType, Field field, String driverName) { try { Class<?> type = field.getType(); IBaseElement instance = isInterface(type, IPage.class) ? getInstancePage(parent, field, type, parentType) : getInstanceElement(parent, type, parentType, field, driverName); instance.setName(field); if (parent != null) { instance.getAvatar().setDriverName(driverName); } instance.setTypeName(type.getSimpleName()); field.set(parent, instance); setImage(parent, instance, field); if (isInterface(field, IComposite.class)) { initElements(instance, driverName); } } catch (Exception ex) { throw exception("Error in setElement for field '%s' with parent '%s'", field.getName(), parentType == null ? "NULL Class" : parentType.getSimpleName() + LINE_BREAK + ex.getMessage()); } }
private void setElement(Object parent, Class<?> parentType, Field field, String driverName) { try { Class<?> type = field.getType(); IBaseElement instance = isInterface(type, IPage.class) ? getInstancePage(parent, field, type, parentType) : getInstanceElement(parent, type, parentType, field, driverName); instance.setName(field); if (parent != null) { instance.getAvatar().setDriverName(driverName); } instance.setTypeName(type.getSimpleName()); field.set(parent, instance); setImage(parent, instance, field); if (isInterface(field, IComposite.class)) { initElements(instance, driverName); } } catch (Exception ex) { throw exception("Error in setElement for field '%s' with parent '%s'", field.getName(), parentType == null ? "NULL Class" : parentType.getSimpleName() + LINE_BREAK + ex.getMessage()); } }
protected IBaseElement getElementsRules(Field field, String driverName, Class<?> type, String fieldName) throws IllegalAccessException, InstantiationException { By newLocator = getNewLocator(field); BaseElement instance = null; if (isInterface(type, List.class)) { Class<?> elementClass = (Class<?>) ((ParameterizedType) field.getGenericType()).getActualTypeArguments()[0]; if (elementClass.isInterface()) elementClass = getClassFromInterface(type); if (elementClass != null) instance = new Elements(newLocator, elementClass); } else { if (type.isInterface()) type = getClassFromInterface(type); if (type != null) { instance = (BaseElement) type.newInstance(); if (instance.getAvatar() != null && newLocator == null) instance.setAvatar(new GetElementModule(instance)); else instance.setAvatar(new GetElementModule(newLocator, instance)); } } if (instance == null) throw exception("Unknown interface: %s (%s). Add relation interface -> class in VIElement.InterfaceTypeMap", type, fieldName); instance.avatar.setDriverName(driverName); return instance; }
instance = new EntityTable((Class<?>) types[0], (Class<?>) types[1]); if (instance == null && isInterface(type, List.class)) { Class<?> elementClass = (Class<?>) ((ParameterizedType) field.getGenericType()) .getActualTypeArguments()[0];
instance = new EntityTable((Class<?>) types[0], (Class<?>) types[1]); if (instance == null && isInterface(type, List.class)) { Class<?> elementClass = (Class<?>) ((ParameterizedType) field.getGenericType()) .getActualTypeArguments()[0];