use of java.lang.annotation.Annotation in project elasticsearch by elastic.
the class InjectionPoint method forMember.
private List<Dependency<?>> forMember(Member member, TypeLiteral<?> type, Annotation[][] parameterAnnotations) {
Errors errors = new Errors(member);
Iterator<Annotation[]> annotationsIterator = Arrays.asList(parameterAnnotations).iterator();
List<Dependency<?>> dependencies = new ArrayList<>();
int index = 0;
for (TypeLiteral<?> parameterType : type.getParameterTypes(member)) {
try {
Annotation[] paramAnnotations = annotationsIterator.next();
Key<?> key = Annotations.getKey(parameterType, member, paramAnnotations, errors);
dependencies.add(newDependency(key, Nullability.allowsNull(paramAnnotations), index));
index++;
} catch (ErrorsException e) {
errors.merge(e.getErrors());
}
}
errors.throwConfigurationExceptionIfErrorsExist();
return Collections.unmodifiableList(dependencies);
}
use of java.lang.annotation.Annotation in project cucumber-jvm by cucumber.
the class ParameterInfo method fromMethod.
public static List<ParameterInfo> fromMethod(Method method) {
List<ParameterInfo> result = new ArrayList<ParameterInfo>();
Type[] genericParameterTypes = method.getGenericParameterTypes();
Annotation[][] annotations = method.getParameterAnnotations();
for (int i = 0; i < genericParameterTypes.length; i++) {
String format = null;
String delimiter = DEFAULT_DELIMITER;
boolean transposed = false;
Transformer<?> transformer = null;
for (Annotation annotation : annotations[i]) {
if (annotation instanceof Format) {
format = ((Format) annotation).value();
} else if (isAnnotatedWith(annotation, Format.class)) {
format = getAnnotationForAnnotation(annotation, Format.class).value();
}
if (annotation instanceof Delimiter) {
delimiter = ((Delimiter) annotation).value();
} else if (isAnnotatedWith(annotation, Delimiter.class)) {
delimiter = getAnnotationForAnnotation(annotation, Delimiter.class).value();
}
if (annotation instanceof Transpose) {
transposed = ((Transpose) annotation).value();
}
if (annotation instanceof Transform) {
transformer = getTransformer(annotation);
} else if (isAnnotatedWith(annotation, Transform.class)) {
transformer = getTransformer(getAnnotationForAnnotation(annotation, Transform.class));
}
}
result.add(new ParameterInfo(genericParameterTypes[i], format, delimiter, transposed, transformer));
}
return result;
}
use of java.lang.annotation.Annotation in project pinot by linkedin.
the class PinotRestletApplication method attachRoutesForClass.
protected void attachRoutesForClass(Router router, Class<? extends ServerResource> clazz) {
TreeSet<String> pathsOrderedByLength = new TreeSet<String>(ComparatorUtils.chainedComparator(new Comparator<String>() {
@Override
public int compare(String left, String right) {
int leftLength = left.length();
int rightLength = right.length();
return leftLength < rightLength ? -1 : (leftLength == rightLength ? 0 : 1);
}
}, ComparatorUtils.NATURAL_COMPARATOR));
for (Method method : clazz.getDeclaredMethods()) {
Annotation annotationInstance = method.getAnnotation(Paths.class);
if (annotationInstance != null) {
pathsOrderedByLength.addAll(Arrays.asList(((Paths) annotationInstance).value()));
}
}
for (String routePath : pathsOrderedByLength) {
LOGGER.info("Attaching route {} -> {}", routePath, clazz.getSimpleName());
attachRoute(router, routePath, clazz);
}
}
use of java.lang.annotation.Annotation in project pinot by linkedin.
the class SwaggerResource method schemaForType.
private JSONObject schemaForType(Class<?> type) {
try {
JSONObject schema = new JSONObject();
schema.put("type", "object");
schema.put("title", type.getSimpleName());
Example example = type.getAnnotation(Example.class);
if (example != null) {
schema.put("example", new JSONObject(example.value()));
}
for (Constructor<?> constructor : type.getConstructors()) {
if (constructor.isAnnotationPresent(JsonCreator.class)) {
JSONObject properties = new JSONObject();
JSONArray required = new JSONArray();
Annotation[][] parameterAnnotations = constructor.getParameterAnnotations();
Class<?>[] parameterTypes = constructor.getParameterTypes();
for (int i = 0; i < parameterTypes.length; i++) {
Class<?> parameterType = parameterTypes[i];
Annotation[] annotations = parameterAnnotations[i];
if (annotations.length != 0) {
for (Annotation annotation : annotations) {
if (annotation instanceof JsonProperty) {
JsonProperty jsonPropertyAnnotation = (JsonProperty) annotation;
JSONObject parameter = new JSONObject();
properties.put(jsonPropertyAnnotation.value(), parameter);
if (parameterType.equals(String.class)) {
parameter.put("type", "string");
} else if (parameterType.equals(Boolean.class) || parameterType.equals(Boolean.TYPE)) {
parameter.put("type", "boolean");
} else if (parameterType.equals(Integer.class) || parameterType.equals(Integer.TYPE)) {
parameter.put("type", "integer");
} else if (parameterType.equals(Long.class) || parameterType.equals(Long.TYPE)) {
// Long maps to integer type in http://swagger.io/specification/#dataTypeFormat
parameter.put("type", "integer");
} else if (parameterType.equals(Float.class) || parameterType.equals(Float.TYPE)) {
parameter.put("type", "boolean");
} else if (parameterType.equals(Double.class) || parameterType.equals(Double.TYPE)) {
parameter.put("type", "double");
} else if (parameterType.equals(Byte.class) || parameterType.equals(Byte.TYPE)) {
// Byte maps to string type in http://swagger.io/specification/#dataTypeFormat
parameter.put("type", "string");
} else {
parameter.put("type", "string");
}
if (jsonPropertyAnnotation.required()) {
required.put(jsonPropertyAnnotation.value());
}
}
}
}
}
if (required.length() != 0) {
schema.put("required", required);
}
schema.put("properties", properties);
break;
}
}
return schema;
} catch (Exception e) {
return new JSONObject();
}
}
use of java.lang.annotation.Annotation in project morphia by mongodb.
the class MappedClass method callLifecycleMethods.
/**
* Call the lifecycle methods
*
* @param event the lifecycle annotation
* @param entity the entity to process
* @param dbObj the dbObject to use
* @param mapper the Mapper to use
* @return dbObj
*/
@SuppressWarnings({ "WMI", "unchecked" })
public DBObject callLifecycleMethods(final Class<? extends Annotation> event, final Object entity, final DBObject dbObj, final Mapper mapper) {
final List<ClassMethodPair> methodPairs = getLifecycleMethods((Class<Annotation>) event);
DBObject retDbObj = dbObj;
try {
Object tempObj;
if (methodPairs != null) {
final HashMap<Class<?>, Object> toCall = new HashMap<Class<?>, Object>((int) (methodPairs.size() * 1.3));
for (final ClassMethodPair cm : methodPairs) {
toCall.put(cm.clazz, null);
}
for (final Class<?> c : toCall.keySet()) {
if (c != null) {
toCall.put(c, getOrCreateInstance(c, mapper));
}
}
for (final ClassMethodPair cm : methodPairs) {
final Method method = cm.method;
final Object inst = toCall.get(cm.clazz);
method.setAccessible(true);
if (LOG.isDebugEnabled()) {
LOG.debug(format("Calling lifecycle method(@%s %s) on %s", event.getSimpleName(), method, inst));
}
if (inst == null) {
if (method.getParameterTypes().length == 0) {
tempObj = method.invoke(entity);
} else {
tempObj = method.invoke(entity, retDbObj);
}
} else if (method.getParameterTypes().length == 0) {
tempObj = method.invoke(inst);
} else if (method.getParameterTypes().length == 1) {
tempObj = method.invoke(inst, entity);
} else {
tempObj = method.invoke(inst, entity, retDbObj);
}
if (tempObj != null) {
retDbObj = (DBObject) tempObj;
}
}
}
callGlobalInterceptors(event, entity, dbObj, mapper);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
} catch (InvocationTargetException e) {
throw new RuntimeException(e);
}
return retDbObj;
}
Aggregations