use of java.lang.reflect.AnnotatedElement in project openj9 by eclipse.
the class TypeAnnotatedTestClassTest method checkAnnotations.
private void checkAnnotations(AnnotatedElement[] annotatees, String annotationName, String argumentName, String[] expectedAnnotations) {
HashSet<String> actualAnnotations = new HashSet<>(annotatees.length);
for (AnnotatedElement at : annotatees) {
for (Annotation an : at.getAnnotations()) {
actualAnnotations.add(an.toString());
}
}
if (verbose) {
logger.debug("=================================");
for (String s : actualAnnotations) {
logger.debug("Annotation: " + s);
}
}
if (null != expectedAnnotations) {
AssertJUnit.assertEquals("wrong number of annotations", expectedAnnotations.length, actualAnnotations.size());
for (String s : expectedAnnotations) {
String comparandJava8 = "@" + annotationName + "(" + argumentName + "=" + s + ")";
String comparandJava9 = "@" + annotationName + "(" + argumentName + "=\"" + s + "\")";
AssertJUnit.assertTrue(comparandJava8 + " and " + comparandJava9 + " missing", actualAnnotations.contains(comparandJava8) || actualAnnotations.contains(comparandJava9));
}
} else {
AssertJUnit.assertTrue("unexpected annotations", actualAnnotations.size() == 0);
}
}
use of java.lang.reflect.AnnotatedElement in project java-client by appium.
the class WidgetByBuilder method getByFromDeclaredClass.
@SuppressWarnings("unchecked")
private By getByFromDeclaredClass(WhatIsNeeded whatIsNeeded) {
AnnotatedElement annotatedElement = annotatedElementContainer.getAnnotated();
Field field = Field.class.cast(annotatedElement);
Class<?> declaredClass;
By result = null;
try {
if (List.class.isAssignableFrom(field.getType())) {
declaredClass = getClassFromAListField(field);
} else {
declaredClass = field.getType();
}
Class<?> convenientClass;
if (whatIsNeeded.equals(WhatIsNeeded.DEFAULT_OR_HTML)) {
convenientClass = getDefaultOrHTMLWidgetClass((Class<? extends Widget>) declaredClass, field);
} else {
convenientClass = getMobileNativeWidgetClass((Class<? extends Widget>) declaredClass, field, platform, automation);
}
while (result == null && !convenientClass.equals(Object.class)) {
setAnnotated(convenientClass);
if (whatIsNeeded.equals(WhatIsNeeded.DEFAULT_OR_HTML)) {
result = super.buildDefaultBy();
} else {
result = super.buildMobileNativeBy();
}
convenientClass = convenientClass.getSuperclass();
}
return result;
} finally {
if (field != null) {
setAnnotated(field);
}
}
}
use of java.lang.reflect.AnnotatedElement in project java-client by appium.
the class DefaultElementByBuilder method buildMobileNativeBy.
@Override
protected By buildMobileNativeBy() {
AnnotatedElement annotatedElement = annotatedElementContainer.getAnnotated();
HowToUseLocators howToUseLocators = annotatedElement.getAnnotation(HowToUseLocators.class);
Optional<HowToUseLocators> howToUseLocatorsOptional = ofNullable(howToUseLocators);
By result = null;
if (isSelendroidAutomation()) {
result = buildMobileBy(howToUseLocatorsOptional.map(HowToUseLocators::selendroidAutomation).orElse(null), getBys(SelendroidFindBy.class, SelendroidFindBys.class, SelendroidFindAll.class));
}
if (isAndroid() && result == null) {
return buildMobileBy(howToUseLocatorsOptional.map(HowToUseLocators::androidAutomation).orElse(null), getBys(AndroidFindBy.class, AndroidFindBys.class, AndroidFindAll.class));
}
if (isIOSXcuit()) {
result = buildMobileBy(howToUseLocatorsOptional.map(HowToUseLocators::iOSXCUITAutomation).orElse(null), getBys(iOSXCUITFindBy.class, iOSXCUITFindBys.class, iOSXCUITFindAll.class));
}
if (isIOS() && result == null) {
return buildMobileBy(howToUseLocatorsOptional.map(HowToUseLocators::iOSAutomation).orElse(null), getBys(iOSFindBy.class, iOSFindBys.class, iOSFindAll.class));
}
if (isWindows()) {
return buildMobileBy(howToUseLocatorsOptional.map(HowToUseLocators::windowsAutomation).orElse(null), getBys(WindowsFindBy.class, WindowsFindBys.class, WindowsFindAll.class));
}
return ofNullable(result).orElse(null);
}
use of java.lang.reflect.AnnotatedElement in project java-client by appium.
the class DefaultElementByBuilder method getBys.
private By[] getBys(Class<? extends Annotation> singleLocator, Class<? extends Annotation> chainedLocator, Class<? extends Annotation> allLocator) {
AnnotationComparator comparator = new AnnotationComparator();
AnnotatedElement annotatedElement = annotatedElementContainer.getAnnotated();
List<Annotation> annotations = new ArrayList<>(asList(annotatedElement.getAnnotationsByType(singleLocator)));
annotations.addAll(asList(annotatedElement.getAnnotationsByType(chainedLocator)));
annotations.addAll(asList(annotatedElement.getAnnotationsByType(allLocator)));
annotations.sort(comparator);
List<By> result = new ArrayList<>();
for (Annotation a : annotations) {
Class<?> annotationClass = a.annotationType();
if (singleLocator.equals(annotationClass)) {
result.add(createBy(new Annotation[] { a }, HowToUseSelectors.USE_ONE));
continue;
}
Method value;
Annotation[] subLocators;
try {
value = annotationClass.getMethod(VALUE, ANNOTATION_ARGUMENTS);
subLocators = (Annotation[]) value.invoke(a, ANNOTATION_PARAMETERS);
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
throw new ClassCastException(String.format("The annotation '%s' has no convenient '%s' method which " + "returns array of annotations", annotationClass.getName(), VALUE));
}
Arrays.sort(subLocators, comparator);
if (chainedLocator.equals(annotationClass)) {
result.add(createBy(subLocators, HowToUseSelectors.BUILD_CHAINED));
continue;
}
if (allLocator.equals(annotationClass)) {
result.add(createBy(subLocators, HowToUseSelectors.USE_ANY));
}
}
return result.toArray(new By[result.size()]);
}
use of java.lang.reflect.AnnotatedElement in project candlepin by candlepin.
the class HibernateValidationAnnotationTest method runMap.
private void runMap(Map<Field, Matcher<AnnotatedElement>> fm) {
for (Map.Entry<Field, Matcher<AnnotatedElement>> entry : fm.entrySet()) {
Matcher<AnnotatedElement> matcher = entry.getValue();
Field field = entry.getKey();
assertTrue(matcher.matches(field));
}
}
Aggregations