public Strategy strategyFor(Object toBeCloned, Field field) { if (toBeCloned == null) return Strategy.IGNORE; if (field.getDeclaredAnnotation(annotationClass) != null) return strategy; return Strategy.IGNORE; } };
public Strategy strategyFor(Object toBeCloned, Field field) { if (toBeCloned == null) return Strategy.IGNORE; if (field.getDeclaredAnnotation(annotationClass) != null) return strategy; return Strategy.IGNORE; } };
private boolean reviewSupportedRelations(Field field) { JoinTable joinTable = field.getDeclaredAnnotation(JoinTable.class); if (joinTable != null) { logger.warn("JoinTable mapping unsupported, has no effect on join table persistence if needed"); return false; } JoinColumns joinColumns = field.getDeclaredAnnotation(JoinColumns.class); if (joinColumns != null) { throw new UnsupportedOperationException("@JoinColumns annotation not supported"); } return true; }
private Field findIdField(Class<?> clazz) { Field[] fields = clazz.getDeclaredFields(); if (fields == null) { return null; } for (Field field : fields) { if (field.getDeclaredAnnotation(Id.class) != null) { return field; } } return null; }
public List<Field> localFiles() { Class<?> clazz = getClass(); List<Field> res = new ArrayList<>(); while (clazz != null) { res.addAll(Arrays.stream(clazz.getDeclaredFields()) .filter(f -> f.getDeclaredAnnotation(LocalFile.class) != null) .collect(Collectors.toList())); clazz = clazz.getSuperclass(); } return res; }
public static <T> List<String> getKeyProperties(T p) { Field[] ss = p.getClass().getDeclaredFields(); return Arrays .asList(ss) .stream() .filter(propertyElement -> propertyElement .getDeclaredAnnotation(Key.class) != null) .map(propertyElement -> propertyElement.getName()) .collect(Collectors.toList()); }
public List<Field> localFiles() { Class<?> clazz = getClass(); List<Field> res = new ArrayList<>(); while (clazz != null) { res.addAll(Arrays.stream(clazz.getDeclaredFields()) .filter(f -> f.getDeclaredAnnotation(LocalFile.class) != null) .collect(Collectors.toList())); clazz = clazz.getSuperclass(); } return res; }
/** * Поиск по аннотации "Name" */ private void checkNamedAnnotations() { List<String> list = Arrays.stream(getClass().getDeclaredFields()) .filter(f -> f.getDeclaredAnnotation(Name.class) != null) .map(f -> f.getDeclaredAnnotation(Name.class).value()) .collect(toList()); if (list.size() != new HashSet<>(list).size()) { throw new IllegalStateException("Найдено несколько аннотаций @Name с одинаковым значением в классе " + this.getClass().getName()); } }
/** * Поиск и инициализации элементов страницы без аннотации Optional */ private List<SelenideElement> readWithWrappedElements() { return Arrays.stream(getClass().getDeclaredFields()) .filter(f -> f.getDeclaredAnnotation(Optional.class) == null) .map(this::extractFieldValueViaReflection) .flatMap(v -> v instanceof List ? ((List<?>) v).stream() : Stream.of(v)) .map(AkitaPage::castToSelenideElement) .filter(Objects::nonNull) .collect(toList()); }
/** * Get {@link Real} annotation. * * @return optional with real annotation, empty optional otherwise */ default Optional<Real> getReal() { return ofNullable(getMember().getDeclaredAnnotation(Real.class)); }
/** * Get {@link Sut} annotation. * * @return sut annotation */ default Sut getSut() { return getMember().getDeclaredAnnotation(Sut.class); }
/** * Get {@link Fake} annotation. * * @return optional with fake annotation, empty optional otherwise */ default Optional<Fake> getFake() { return ofNullable(getMember().getDeclaredAnnotation(Fake.class)); }
/** * Get {@link Fixture} annotation. * * @return optional with fixture annotation, empty optional otherwise */ default Optional<Fixture> getFixture() { return ofNullable(getMember().getDeclaredAnnotation(Fixture.class)); }
/** * Get {@link Property} annotation. * * @return optional with property annotation, empty optional otherwise */ default Optional<Property> getProperty() { return ofNullable(getMember().getDeclaredAnnotation(Property.class)); }
/** * Get {@link Virtual} annotation. * * @return optional with virtual annotation, empty optional otherwise */ default Optional<Virtual> getVirtual() { return ofNullable(getMember().getDeclaredAnnotation(Virtual.class)); }
private void eachForm(Consumer<AkitaPage> func) { Arrays.stream(getClass().getDeclaredFields()) .filter(f -> f.getDeclaredAnnotation(Optional.class) == null) .forEach(f -> { if (AkitaPage.class.isAssignableFrom(f.getType())){ AkitaPage akitaPage = AkitaScenario.getInstance().getPage((Class<? extends AkitaPage>)f.getType()).initialize(); func.accept(akitaPage); } }); }
public static void mapDataType(XContentBuilder mappingBuilder, Field field) throws IOException { if (!isValidBinaryType(field)) { throw new IllegalArgumentException( String.format("field type[%s] is invalid type of binary.", field.getType())); } BinaryField binaryField = field.getDeclaredAnnotation(BinaryField.class); mapDataType(mappingBuilder, binaryField); } }
public static void mapDataType(XContentBuilder mappingBuilder, Field field) throws IOException { if (!isValidIPFieldType(field)) { throw new IllegalArgumentException( String.format("field type[%s] is invalid type of ip.", field.getType())); } IPField ipField = field.getDeclaredAnnotation(IPField.class); mapDataType(mappingBuilder, ipField); } }
public static void mapDataType(XContentBuilder mappingBuilder, Field field) throws IOException { if (!isValidCompletionFieldType(field)) { throw new IllegalArgumentException( String.format("field type[%s] is invalid type of string.", field.getType())); } CompletionField completionField = field.getDeclaredAnnotation(CompletionField.class); mapDataType(mappingBuilder, completionField); } }
public static <A extends java.lang.annotation.Annotation> Array<Field> findFieldsByAnnotation(Object instance, Class<A> annotationClass) { Array<Field> fields = new Array<>(); for (java.lang.reflect.Field field : instance.getClass().getDeclaredFields()) { if (field.getDeclaredAnnotation(annotationClass) != null) { fields.add(field); } } return fields; }