|
7 | 7 | import com.microsoft.azure.functions.annotation.*;
|
8 | 8 |
|
9 | 9 | public class CoreTypeResolver {
|
10 |
| - private static boolean isOutputParameter(Type target) { |
11 |
| - if (target instanceof ParameterizedType) { |
12 |
| - target = ((ParameterizedType) target).getRawType(); |
13 |
| - } |
14 |
| - return (target instanceof Class<?>) |
15 |
| - && (OutputBinding.class.isAssignableFrom((Class<?>) target)); |
16 |
| - } |
| 10 | + private static boolean isOutputParameter(Type target) { |
| 11 | + if (target instanceof ParameterizedType) { |
| 12 | + target = ((ParameterizedType) target).getRawType(); |
| 13 | + } |
| 14 | + return (target instanceof Class<?>) && (OutputBinding.class.isAssignableFrom((Class<?>) target)); |
| 15 | + } |
17 | 16 |
|
18 |
| - public static Type getParameterizedActualTypeArgumentsType(Type paramType) { |
19 |
| - if (paramType instanceof ParameterizedType) { |
20 |
| - ParameterizedType generics = (ParameterizedType) paramType; |
21 |
| - Type[] arguments = generics.getActualTypeArguments(); |
22 |
| - if (arguments.length > 0) { |
23 |
| - return arguments[0]; |
24 |
| - } |
25 |
| - } |
26 |
| - return Object.class; |
27 |
| - } |
| 17 | + public static Type getParameterizedActualTypeArgumentsType(Type paramType) { |
| 18 | + if (paramType instanceof ParameterizedType) { |
| 19 | + ParameterizedType generics = (ParameterizedType) paramType; |
| 20 | + Type[] arguments = generics.getActualTypeArguments(); |
| 21 | + if (arguments.length > 0) { |
| 22 | + return arguments[0]; |
| 23 | + } |
| 24 | + } |
| 25 | + return Object.class; |
| 26 | + } |
28 | 27 |
|
29 |
| - public static boolean isValidOutputType(Type target) { |
30 |
| - if (!isOutputParameter(target)) { |
31 |
| - return false; |
32 |
| - } |
33 |
| - target = getParameterizedActualTypeArgumentsType(target); |
34 |
| - return !isOutputParameter(target); |
35 |
| - } |
| 28 | + public static boolean isValidOutputType(Type target) { |
| 29 | + if (!isOutputParameter(target)) { |
| 30 | + return false; |
| 31 | + } |
| 32 | + target = getParameterizedActualTypeArgumentsType(target); |
| 33 | + return !isOutputParameter(target); |
| 34 | + } |
36 | 35 |
|
37 |
| - public static boolean isHttpResponse(Type target) { |
38 |
| - return HttpResponseMessage.class.isAssignableFrom(getRuntimeClass(target)); |
39 |
| - } |
| 36 | + public static boolean isHttpResponse(Type target) { |
| 37 | + return HttpResponseMessage.class.isAssignableFrom(getRuntimeClass(target)); |
| 38 | + } |
40 | 39 |
|
41 |
| - public static Class<?> getRuntimeClass(Type type) { |
42 |
| - if (type instanceof ParameterizedType) { |
43 |
| - type = ((ParameterizedType) type).getRawType(); |
44 |
| - } |
45 |
| - return (Class<?>) type; |
46 |
| - } |
| 40 | + public static Class<?> getRuntimeClass(Type type) { |
| 41 | + if (type instanceof ParameterizedType) { |
| 42 | + type = ((ParameterizedType) type).getRawType(); |
| 43 | + } |
| 44 | + return (Class<?>) type; |
| 45 | + } |
47 | 46 |
|
48 |
| - public static String getAnnotationName(Parameter parameter) { |
49 |
| - Annotation[] annotations = parameter.getAnnotations(); |
50 |
| - for (Annotation annotation : annotations) { |
51 |
| - CustomBinding customBindingAnnotation = annotation.annotationType() |
52 |
| - .getAnnotation(CustomBinding.class); |
53 |
| - if (customBindingAnnotation != null) { |
54 |
| - return getBindingNameFromCustomBindingAnnotation(customBindingAnnotation); |
55 |
| - } else if (annotation.toString().contains("com.microsoft.azure.functions.annotation")) { |
56 |
| - return getBindingNameFromAnnotation(annotation); |
57 |
| - } |
58 |
| - } |
59 |
| - return null; |
60 |
| - } |
| 47 | + public static String getAnnotationName(Parameter parameter) { |
| 48 | + Annotation[] annotations = parameter.getAnnotations(); |
| 49 | + String annotationName = null; |
61 | 50 |
|
62 |
| - private static String getBindingNameFromAnnotation(Annotation annotation) { |
63 |
| - for (Method annotationMethod : annotation.getClass().getMethods()) { |
64 |
| - if (annotationMethod.getName().equals("name")) { |
65 |
| - try { |
66 |
| - return (String) annotationMethod.invoke(annotation); |
67 |
| - } catch (Exception ex) { |
68 |
| - // Ignore |
69 |
| - return null; |
70 |
| - } |
71 |
| - } |
72 |
| - } |
73 |
| - return null; |
74 |
| - } |
| 51 | + for (Annotation annotation : annotations) { |
| 52 | + if (annotation.toString().contains("com.microsoft.azure.functions.annotation")) { |
| 53 | + annotationName = getBindingNameFromAnnotation(annotation); |
| 54 | + } |
| 55 | + if (annotationName == null) { |
| 56 | + CustomBinding customBindingAnnotation = annotation.annotationType().getAnnotation(CustomBinding.class); |
| 57 | + if (customBindingAnnotation != null) { |
| 58 | + annotationName = getBindingNameFromAnnotation(annotation); |
| 59 | + if (annotationName == null) { |
| 60 | + annotationName = getBindingNameFromCustomBindingAnnotation(customBindingAnnotation); |
| 61 | + } |
| 62 | + } |
| 63 | + } |
| 64 | + } |
| 65 | + return annotationName; |
| 66 | + } |
75 | 67 |
|
76 |
| - private static String getBindingNameFromCustomBindingAnnotation( |
77 |
| - CustomBinding customBindingAnnotation) { |
78 |
| - try { |
79 |
| - return customBindingAnnotation.name(); |
80 |
| - } catch (Exception ex) { |
81 |
| - // Ignore |
82 |
| - return null; |
83 |
| - } |
84 |
| - } |
| 68 | + private static String getBindingNameFromAnnotation(Annotation annotation) { |
| 69 | + for (Method annotationMethod : annotation.getClass().getMethods()) { |
| 70 | + if (annotationMethod.getName().equals("name")) { |
| 71 | + try { |
| 72 | + return (String) annotationMethod.invoke(annotation); |
| 73 | + } catch (Exception ex) { |
| 74 | + // Ignore |
| 75 | + return null; |
| 76 | + } |
| 77 | + } |
| 78 | + } |
| 79 | + return null; |
| 80 | + } |
85 | 81 |
|
86 |
| - static String getBindingNameAnnotation(Parameter param) { |
87 |
| - BindingName paramAnnotation = param.getDeclaredAnnotation(BindingName.class); |
88 |
| - if (paramAnnotation != null) { |
89 |
| - return paramAnnotation.value(); |
90 |
| - } |
91 |
| - return new String(""); |
92 |
| - } |
| 82 | + private static String getBindingNameFromCustomBindingAnnotation(CustomBinding customBindingAnnotation) { |
| 83 | + try { |
| 84 | + return customBindingAnnotation.name(); |
| 85 | + } catch (Exception ex) { |
| 86 | + // Ignore |
| 87 | + return null; |
| 88 | + } |
| 89 | + } |
| 90 | + |
| 91 | + static String getBindingNameAnnotation(Parameter param) { |
| 92 | + BindingName paramAnnotation = param.getDeclaredAnnotation(BindingName.class); |
| 93 | + if (paramAnnotation != null) { |
| 94 | + return paramAnnotation.value(); |
| 95 | + } |
| 96 | + return new String(""); |
| 97 | + } |
93 | 98 | }
|
0 commit comments