1 package com.fasterxml.jackson.databind.ext;
2
3 import java.beans.ConstructorProperties;
4 import java.beans.Transient;
5
6 import com.fasterxml.jackson.databind.PropertyName;
7 import com.fasterxml.jackson.databind.introspect.Annotated;
8 import com.fasterxml.jackson.databind.introspect.AnnotatedParameter;
9 import com.fasterxml.jackson.databind.introspect.AnnotatedWithParams;
10
11 /**
12  * @since 2.8
13  */

14 public class Java7SupportImpl extends Java7Support
15 {
16     @SuppressWarnings("unused"// compiler warns, just needed side-effects
17     private final Class<?> _bogus;
18
19     public Java7SupportImpl() {
20         // Trigger loading of annotations that only JDK 7 has, to trigger
21         // early fail (see [databind#2466])
22         Class<?> cls = Transient.class;
23         cls = ConstructorProperties.class;
24         _bogus = cls;
25     }
26
27     @Override
28     public Boolean findTransient(Annotated a) {
29         Transient t = a.getAnnotation(Transient.class);
30         if (t != null) {
31             return t.value();
32         }
33         return null;
34     }
35
36     @Override
37     public Boolean hasCreatorAnnotation(Annotated a) {
38         ConstructorProperties props = a.getAnnotation(ConstructorProperties.class);
39         // 08-Nov-2015, tatu: One possible check would be to ensure there is at least
40         //    one name iff constructor has arguments. But seems unnecessary for now.
41         if (props != null) {
42             return Boolean.TRUE;
43         }
44         return null;
45     }
46
47     @Override
48     public PropertyName findConstructorName(AnnotatedParameter p)
49     {
50         AnnotatedWithParams ctor = p.getOwner();
51         if (ctor != null) {
52             ConstructorProperties props = ctor.getAnnotation(ConstructorProperties.class);
53             if (props != null) {
54                 String[] names = props.value();
55                 int ix = p.getIndex();
56                 if (ix < names.length) {
57                     return PropertyName.construct(names[ix]);
58                 }
59             }
60         }
61         return null;
62     }
63 }
64