Java Code Examples for javax.xml.bind.annotation.XmlAccessType#PUBLIC_MEMBER
The following examples show how to use
javax.xml.bind.annotation.XmlAccessType#PUBLIC_MEMBER .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JavaTypeAnalyzer.java From jaxrs-analyzer with Apache License 2.0 | 6 votes |
/** * Checks if the method is public and non-static and that the method is a Getter. * Does not allow methods with ignored names. * Does also not take methods annotated with {@link XmlTransient}. * * @param method The method * @return {@code true} if the method should be analyzed further */ private static boolean isRelevant(final Method method, final XmlAccessType accessType) { if (method.isSynthetic() || !isGetter(method)) return false; final boolean propertyIgnored = ignoredFieldNames.contains(extractPropertyName(method.getName())); if (propertyIgnored || hasIgnoreAnnotation(method) || isTypeIgnored(method.getReturnType())) { return false; } if (isAnnotationPresent(method, XmlElement.class)) return true; if (accessType == XmlAccessType.PROPERTY) return !isAnnotationPresent(method, XmlTransient.class); else if (accessType == XmlAccessType.PUBLIC_MEMBER) return Modifier.isPublic(method.getModifiers()) && !isAnnotationPresent(method, XmlTransient.class); return false; }
Example 2
Source File: JavaTypeAnalyzer.java From jaxrs-analyzer with Apache License 2.0 | 6 votes |
private static boolean isRelevant(final Field field, final XmlAccessType accessType) { if (field.isSynthetic()) return false; if (hasIgnoreAnnotation(field) || isTypeIgnored(field.getType())) { ignoredFieldNames.add(field.getName()); return false; } if (isAnnotationPresent(field, XmlElement.class)) return true; final int modifiers = field.getModifiers(); if (accessType == XmlAccessType.FIELD) // always take, unless static or transient return !Modifier.isTransient(modifiers) && !Modifier.isStatic(modifiers) && !isAnnotationPresent(field, XmlTransient.class); else if (accessType == XmlAccessType.PUBLIC_MEMBER) // only for public, non-static return Modifier.isPublic(modifiers) && !Modifier.isStatic(modifiers) && !isAnnotationPresent(field, XmlTransient.class); return false; }
Example 3
Source File: JAXBContextInitializer.java From cxf with Apache License 2.0 | 6 votes |
/** * Checks if the field is accepted as a JAXB property. */ static boolean isFieldAccepted(Field field, XmlAccessType accessType) { // We only accept non static fields which are not marked @XmlTransient or has transient modifier if (field.isAnnotationPresent(XmlTransient.class) || Modifier.isTransient(field.getModifiers())) { return false; } if (Modifier.isStatic(field.getModifiers())) { return field.isAnnotationPresent(XmlAttribute.class); } if (accessType == XmlAccessType.PUBLIC_MEMBER && !Modifier.isPublic(field.getModifiers())) { return false; } if (accessType == XmlAccessType.NONE || accessType == XmlAccessType.PROPERTY) { return checkJaxbAnnotation(field.getAnnotations()); } return true; }
Example 4
Source File: ClassInfoImpl.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
/** * Computes the {@link XmlAccessType} on this class by looking at {@link XmlAccessorType} * annotations. */ private XmlAccessType getAccessType() { XmlAccessorType xat = getClassOrPackageAnnotation(XmlAccessorType.class); if(xat!=null) return xat.value(); else return XmlAccessType.PUBLIC_MEMBER; }
Example 5
Source File: Utils.java From cxf with Apache License 2.0 | 5 votes |
static boolean isMethodAccepted(Method method, XmlAccessType accessType, boolean acceptSetters) { // ignore bridge, static, @XmlTransient methods plus methods declared in Throwable if (method.isBridge() || Modifier.isStatic(method.getModifiers()) || method.isAnnotationPresent(XmlTransient.class) || method.getDeclaringClass().equals(Throwable.class) || "getClass".equals(method.getName())) { return false; } // Allow only public methods if PUBLIC_MEMBER access is requested if (accessType == XmlAccessType.PUBLIC_MEMBER && !Modifier.isPublic(method.getModifiers())) { return false; } if (isGetter(method)) { // does nothing } else if (isSetter(method)) { if (!acceptSetters) { return false; } } else { // we accept only getters and setters return false; } // let JAXB annotations decide if NONE or FIELD access is requested if (accessType == XmlAccessType.NONE || accessType == XmlAccessType.FIELD) { return JAXBContextInitializer.checkJaxbAnnotation(method.getAnnotations()); } // method accepted return true; }
Example 6
Source File: ClassInfoImpl.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
/** * Computes the {@link XmlAccessType} on this class by looking at {@link XmlAccessorType} * annotations. */ private XmlAccessType getAccessType() { XmlAccessorType xat = getClassOrPackageAnnotation(XmlAccessorType.class); if(xat!=null) return xat.value(); else return XmlAccessType.PUBLIC_MEMBER; }
Example 7
Source File: JavaTypeAnalyzer.java From jaxrs-analyzer with Apache License 2.0 | 5 votes |
private XmlAccessType getXmlAccessType(final Class<?> clazz) { Class<?> current = clazz; while (current != null) { if (isAnnotationPresent(current, XmlAccessorType.class)) return getAnnotation(current, XmlAccessorType.class).value(); current = current.getSuperclass(); } return XmlAccessType.PUBLIC_MEMBER; }
Example 8
Source File: ClassInfoImpl.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
/** * Computes the {@link XmlAccessType} on this class by looking at {@link XmlAccessorType} * annotations. */ private XmlAccessType getAccessType() { XmlAccessorType xat = getClassOrPackageAnnotation(XmlAccessorType.class); if(xat!=null) return xat.value(); else return XmlAccessType.PUBLIC_MEMBER; }
Example 9
Source File: ClassInfoImpl.java From hottub with GNU General Public License v2.0 | 5 votes |
/** * Computes the {@link XmlAccessType} on this class by looking at {@link XmlAccessorType} * annotations. */ private XmlAccessType getAccessType() { XmlAccessorType xat = getClassOrPackageAnnotation(XmlAccessorType.class); if(xat!=null) return xat.value(); else return XmlAccessType.PUBLIC_MEMBER; }
Example 10
Source File: ClassInfoImpl.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * Computes the {@link XmlAccessType} on this class by looking at {@link XmlAccessorType} * annotations. */ private XmlAccessType getAccessType() { XmlAccessorType xat = getClassOrPackageAnnotation(XmlAccessorType.class); if(xat!=null) return xat.value(); else return XmlAccessType.PUBLIC_MEMBER; }
Example 11
Source File: ClassInfoImpl.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
private void findFieldProperties(C c, XmlAccessType at) { // always find properties from the super class first C sc = nav().getSuperClass(c); if (shouldRecurseSuperClass(sc)) { findFieldProperties(sc,at); } for( F f : nav().getDeclaredFields(c) ) { Annotation[] annotations = reader().getAllFieldAnnotations(f,this); boolean isDummy = reader().hasFieldAnnotation(OverrideAnnotationOf.class, f); if( nav().isTransient(f) ) { // it's an error for transient field to have any binding annotation if(hasJAXBAnnotation(annotations)) builder.reportError(new IllegalAnnotationException( Messages.TRANSIENT_FIELD_NOT_BINDABLE.format(nav().getFieldName(f)), getSomeJAXBAnnotation(annotations))); } else if( nav().isStaticField(f) ) { // static fields are bound only when there's explicit annotation. if(hasJAXBAnnotation(annotations)) addProperty(createFieldSeed(f),annotations, false); } else { if(at==XmlAccessType.FIELD ||(at==XmlAccessType.PUBLIC_MEMBER && nav().isPublicField(f)) || hasJAXBAnnotation(annotations)) { if (isDummy) { ClassInfo<T, C> top = getBaseClass(); while ((top != null) && (top.getProperty("content") == null)) { top = top.getBaseClass(); } DummyPropertyInfo prop = (DummyPropertyInfo) top.getProperty("content"); PropertySeed seed = createFieldSeed(f); ((DummyPropertyInfo)prop).addType(createReferenceProperty(seed)); } else { addProperty(createFieldSeed(f), annotations, false); } } checkFieldXmlLocation(f); } } }
Example 12
Source File: ClassInfoImpl.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
private void findFieldProperties(C c, XmlAccessType at) { // always find properties from the super class first C sc = nav().getSuperClass(c); if (shouldRecurseSuperClass(sc)) { findFieldProperties(sc,at); } for( F f : nav().getDeclaredFields(c) ) { Annotation[] annotations = reader().getAllFieldAnnotations(f,this); boolean isDummy = reader().hasFieldAnnotation(OverrideAnnotationOf.class, f); if( nav().isTransient(f) ) { // it's an error for transient field to have any binding annotation if(hasJAXBAnnotation(annotations)) builder.reportError(new IllegalAnnotationException( Messages.TRANSIENT_FIELD_NOT_BINDABLE.format(nav().getFieldName(f)), getSomeJAXBAnnotation(annotations))); } else if( nav().isStaticField(f) ) { // static fields are bound only when there's explicit annotation. if(hasJAXBAnnotation(annotations)) addProperty(createFieldSeed(f),annotations, false); } else { if(at==XmlAccessType.FIELD ||(at==XmlAccessType.PUBLIC_MEMBER && nav().isPublicField(f)) || hasJAXBAnnotation(annotations)) { if (isDummy) { ClassInfo<T, C> top = getBaseClass(); while ((top != null) && (top.getProperty("content") == null)) { top = top.getBaseClass(); } DummyPropertyInfo prop = (DummyPropertyInfo) top.getProperty("content"); PropertySeed seed = createFieldSeed(f); ((DummyPropertyInfo)prop).addType(createReferenceProperty(seed)); } else { addProperty(createFieldSeed(f), annotations, false); } } checkFieldXmlLocation(f); } } }
Example 13
Source File: ClassInfoImpl.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
private void findFieldProperties(C c, XmlAccessType at) { // always find properties from the super class first C sc = nav().getSuperClass(c); if (shouldRecurseSuperClass(sc)) { findFieldProperties(sc,at); } for( F f : nav().getDeclaredFields(c) ) { Annotation[] annotations = reader().getAllFieldAnnotations(f,this); boolean isDummy = reader().hasFieldAnnotation(OverrideAnnotationOf.class, f); if( nav().isTransient(f) ) { // it's an error for transient field to have any binding annotation if(hasJAXBAnnotation(annotations)) builder.reportError(new IllegalAnnotationException( Messages.TRANSIENT_FIELD_NOT_BINDABLE.format(nav().getFieldName(f)), getSomeJAXBAnnotation(annotations))); } else if( nav().isStaticField(f) ) { // static fields are bound only when there's explicit annotation. if(hasJAXBAnnotation(annotations)) addProperty(createFieldSeed(f),annotations, false); } else { if(at==XmlAccessType.FIELD ||(at==XmlAccessType.PUBLIC_MEMBER && nav().isPublicField(f)) || hasJAXBAnnotation(annotations)) { if (isDummy) { ClassInfo<T, C> top = getBaseClass(); while ((top != null) && (top.getProperty("content") == null)) { top = top.getBaseClass(); } DummyPropertyInfo prop = (DummyPropertyInfo) top.getProperty("content"); PropertySeed seed = createFieldSeed(f); ((DummyPropertyInfo)prop).addType(createReferenceProperty(seed)); } else { addProperty(createFieldSeed(f), annotations, false); } } checkFieldXmlLocation(f); } } }
Example 14
Source File: ClassInfoImpl.java From hottub with GNU General Public License v2.0 | 4 votes |
/** * Adds properties that consists of accessors. */ private void findGetterSetterProperties(XmlAccessType at) { // in the first step we accumulate getters and setters // into this map keyed by the property name. Map<String,M> getters = new LinkedHashMap<String,M>(); Map<String,M> setters = new LinkedHashMap<String,M>(); C c = clazz; do { collectGetterSetters(clazz, getters, setters); // take super classes into account if they have @XmlTransient c = nav().getSuperClass(c); } while(shouldRecurseSuperClass(c)); // compute the intersection Set<String> complete = new TreeSet<String>(getters.keySet()); complete.retainAll(setters.keySet()); resurrect(getters, complete); resurrect(setters, complete); // then look for read/write properties. for (String name : complete) { M getter = getters.get(name); M setter = setters.get(name); Annotation[] ga = getter!=null ? reader().getAllMethodAnnotations(getter,new MethodLocatable<M>(this,getter,nav())) : EMPTY_ANNOTATIONS; Annotation[] sa = setter!=null ? reader().getAllMethodAnnotations(setter,new MethodLocatable<M>(this,setter,nav())) : EMPTY_ANNOTATIONS; boolean hasAnnotation = hasJAXBAnnotation(ga) || hasJAXBAnnotation(sa); boolean isOverriding = false; if(!hasAnnotation) { // checking if the method is overriding others isn't free, // so we don't compute it if it's not necessary. isOverriding = (getter!=null && nav().isOverriding(getter,c)) && (setter!=null && nav().isOverriding(setter,c)); } if((at==XmlAccessType.PROPERTY && !isOverriding) || (at==XmlAccessType.PUBLIC_MEMBER && isConsideredPublic(getter) && isConsideredPublic(setter) && !isOverriding) || hasAnnotation) { // make sure that the type is consistent if(getter!=null && setter!=null && !nav().isSameType(nav().getReturnType(getter), nav().getMethodParameters(setter)[0])) { // inconsistent builder.reportError(new IllegalAnnotationException( Messages.GETTER_SETTER_INCOMPATIBLE_TYPE.format( nav().getTypeName(nav().getReturnType(getter)), nav().getTypeName(nav().getMethodParameters(setter)[0]) ), new MethodLocatable<M>( this, getter, nav()), new MethodLocatable<M>( this, setter, nav()))); continue; } // merge annotations from two list Annotation[] r; if(ga.length==0) { r = sa; } else if(sa.length==0) { r = ga; } else { r = new Annotation[ga.length+sa.length]; System.arraycopy(ga,0,r,0,ga.length); System.arraycopy(sa,0,r,ga.length,sa.length); } addProperty(createAccessorSeed(getter, setter), r, false); } } // done with complete pairs getters.keySet().removeAll(complete); setters.keySet().removeAll(complete); // TODO: think about // class Foo { // int getFoo(); // } // class Bar extends Foo { // void setFoo(int x); // } // and how it will be XML-ized. }
Example 15
Source File: ClassInfoImpl.java From hottub with GNU General Public License v2.0 | 4 votes |
private void findFieldProperties(C c, XmlAccessType at) { // always find properties from the super class first C sc = nav().getSuperClass(c); if (shouldRecurseSuperClass(sc)) { findFieldProperties(sc,at); } for( F f : nav().getDeclaredFields(c) ) { Annotation[] annotations = reader().getAllFieldAnnotations(f,this); boolean isDummy = reader().hasFieldAnnotation(OverrideAnnotationOf.class, f); if( nav().isTransient(f) ) { // it's an error for transient field to have any binding annotation if(hasJAXBAnnotation(annotations)) builder.reportError(new IllegalAnnotationException( Messages.TRANSIENT_FIELD_NOT_BINDABLE.format(nav().getFieldName(f)), getSomeJAXBAnnotation(annotations))); } else if( nav().isStaticField(f) ) { // static fields are bound only when there's explicit annotation. if(hasJAXBAnnotation(annotations)) addProperty(createFieldSeed(f),annotations, false); } else { if(at==XmlAccessType.FIELD ||(at==XmlAccessType.PUBLIC_MEMBER && nav().isPublicField(f)) || hasJAXBAnnotation(annotations)) { if (isDummy) { ClassInfo<T, C> top = getBaseClass(); while ((top != null) && (top.getProperty("content") == null)) { top = top.getBaseClass(); } DummyPropertyInfo prop = (DummyPropertyInfo) top.getProperty("content"); PropertySeed seed = createFieldSeed(f); ((DummyPropertyInfo)prop).addType(createReferenceProperty(seed)); } else { addProperty(createFieldSeed(f), annotations, false); } } checkFieldXmlLocation(f); } } }
Example 16
Source File: ClassInfoImpl.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
/** * Adds properties that consists of accessors. */ private void findGetterSetterProperties(XmlAccessType at) { // in the first step we accumulate getters and setters // into this map keyed by the property name. Map<String,M> getters = new LinkedHashMap<String,M>(); Map<String,M> setters = new LinkedHashMap<String,M>(); C c = clazz; do { collectGetterSetters(clazz, getters, setters); // take super classes into account if they have @XmlTransient c = nav().getSuperClass(c); } while(shouldRecurseSuperClass(c)); // compute the intersection Set<String> complete = new TreeSet<String>(getters.keySet()); complete.retainAll(setters.keySet()); resurrect(getters, complete); resurrect(setters, complete); // then look for read/write properties. for (String name : complete) { M getter = getters.get(name); M setter = setters.get(name); Annotation[] ga = getter!=null ? reader().getAllMethodAnnotations(getter,new MethodLocatable<M>(this,getter,nav())) : EMPTY_ANNOTATIONS; Annotation[] sa = setter!=null ? reader().getAllMethodAnnotations(setter,new MethodLocatable<M>(this,setter,nav())) : EMPTY_ANNOTATIONS; boolean hasAnnotation = hasJAXBAnnotation(ga) || hasJAXBAnnotation(sa); boolean isOverriding = false; if(!hasAnnotation) { // checking if the method is overriding others isn't free, // so we don't compute it if it's not necessary. isOverriding = (getter!=null && nav().isOverriding(getter,c)) && (setter!=null && nav().isOverriding(setter,c)); } if((at==XmlAccessType.PROPERTY && !isOverriding) || (at==XmlAccessType.PUBLIC_MEMBER && isConsideredPublic(getter) && isConsideredPublic(setter) && !isOverriding) || hasAnnotation) { // make sure that the type is consistent if(getter!=null && setter!=null && !nav().isSameType(nav().getReturnType(getter), nav().getMethodParameters(setter)[0])) { // inconsistent builder.reportError(new IllegalAnnotationException( Messages.GETTER_SETTER_INCOMPATIBLE_TYPE.format( nav().getTypeName(nav().getReturnType(getter)), nav().getTypeName(nav().getMethodParameters(setter)[0]) ), new MethodLocatable<M>( this, getter, nav()), new MethodLocatable<M>( this, setter, nav()))); continue; } // merge annotations from two list Annotation[] r; if(ga.length==0) { r = sa; } else if(sa.length==0) { r = ga; } else { r = new Annotation[ga.length+sa.length]; System.arraycopy(ga,0,r,0,ga.length); System.arraycopy(sa,0,r,ga.length,sa.length); } addProperty(createAccessorSeed(getter, setter), r, false); } } // done with complete pairs getters.keySet().removeAll(complete); setters.keySet().removeAll(complete); // TODO: think about // class Foo { // int getFoo(); // } // class Bar extends Foo { // void setFoo(int x); // } // and how it will be XML-ized. }
Example 17
Source File: ClassInfoImpl.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
private void findFieldProperties(C c, XmlAccessType at) { // always find properties from the super class first C sc = nav().getSuperClass(c); if (shouldRecurseSuperClass(sc)) { findFieldProperties(sc,at); } for( F f : nav().getDeclaredFields(c) ) { Annotation[] annotations = reader().getAllFieldAnnotations(f,this); boolean isDummy = reader().hasFieldAnnotation(OverrideAnnotationOf.class, f); if( nav().isTransient(f) ) { // it's an error for transient field to have any binding annotation if(hasJAXBAnnotation(annotations)) builder.reportError(new IllegalAnnotationException( Messages.TRANSIENT_FIELD_NOT_BINDABLE.format(nav().getFieldName(f)), getSomeJAXBAnnotation(annotations))); } else if( nav().isStaticField(f) ) { // static fields are bound only when there's explicit annotation. if(hasJAXBAnnotation(annotations)) addProperty(createFieldSeed(f),annotations, false); } else { if(at==XmlAccessType.FIELD ||(at==XmlAccessType.PUBLIC_MEMBER && nav().isPublicField(f)) || hasJAXBAnnotation(annotations)) { if (isDummy) { ClassInfo<T, C> top = getBaseClass(); while ((top != null) && (top.getProperty("content") == null)) { top = top.getBaseClass(); } DummyPropertyInfo prop = (DummyPropertyInfo) top.getProperty("content"); PropertySeed seed = createFieldSeed(f); ((DummyPropertyInfo)prop).addType(createReferenceProperty(seed)); } else { addProperty(createFieldSeed(f), annotations, false); } } checkFieldXmlLocation(f); } } }
Example 18
Source File: ClassInfoImpl.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
/** * Adds properties that consists of accessors. */ private void findGetterSetterProperties(XmlAccessType at) { // in the first step we accumulate getters and setters // into this map keyed by the property name. Map<String,M> getters = new LinkedHashMap<String,M>(); Map<String,M> setters = new LinkedHashMap<String,M>(); C c = clazz; do { collectGetterSetters(clazz, getters, setters); // take super classes into account if they have @XmlTransient c = nav().getSuperClass(c); } while(shouldRecurseSuperClass(c)); // compute the intersection Set<String> complete = new TreeSet<String>(getters.keySet()); complete.retainAll(setters.keySet()); resurrect(getters, complete); resurrect(setters, complete); // then look for read/write properties. for (String name : complete) { M getter = getters.get(name); M setter = setters.get(name); Annotation[] ga = getter!=null ? reader().getAllMethodAnnotations(getter,new MethodLocatable<M>(this,getter,nav())) : EMPTY_ANNOTATIONS; Annotation[] sa = setter!=null ? reader().getAllMethodAnnotations(setter,new MethodLocatable<M>(this,setter,nav())) : EMPTY_ANNOTATIONS; boolean hasAnnotation = hasJAXBAnnotation(ga) || hasJAXBAnnotation(sa); boolean isOverriding = false; if(!hasAnnotation) { // checking if the method is overriding others isn't free, // so we don't compute it if it's not necessary. isOverriding = (getter!=null && nav().isOverriding(getter,c)) && (setter!=null && nav().isOverriding(setter,c)); } if((at==XmlAccessType.PROPERTY && !isOverriding) || (at==XmlAccessType.PUBLIC_MEMBER && isConsideredPublic(getter) && isConsideredPublic(setter) && !isOverriding) || hasAnnotation) { // make sure that the type is consistent if(getter!=null && setter!=null && !nav().isSameType(nav().getReturnType(getter), nav().getMethodParameters(setter)[0])) { // inconsistent builder.reportError(new IllegalAnnotationException( Messages.GETTER_SETTER_INCOMPATIBLE_TYPE.format( nav().getTypeName(nav().getReturnType(getter)), nav().getTypeName(nav().getMethodParameters(setter)[0]) ), new MethodLocatable<M>( this, getter, nav()), new MethodLocatable<M>( this, setter, nav()))); continue; } // merge annotations from two list Annotation[] r; if(ga.length==0) { r = sa; } else if(sa.length==0) { r = ga; } else { r = new Annotation[ga.length+sa.length]; System.arraycopy(ga,0,r,0,ga.length); System.arraycopy(sa,0,r,ga.length,sa.length); } addProperty(createAccessorSeed(getter, setter), r, false); } } // done with complete pairs getters.keySet().removeAll(complete); setters.keySet().removeAll(complete); // TODO: think about // class Foo { // int getFoo(); // } // class Bar extends Foo { // void setFoo(int x); // } // and how it will be XML-ized. }
Example 19
Source File: ClassInfoImpl.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
/** * Adds properties that consists of accessors. */ private void findGetterSetterProperties(XmlAccessType at) { // in the first step we accumulate getters and setters // into this map keyed by the property name. Map<String,M> getters = new LinkedHashMap<String,M>(); Map<String,M> setters = new LinkedHashMap<String,M>(); C c = clazz; do { collectGetterSetters(clazz, getters, setters); // take super classes into account if they have @XmlTransient c = nav().getSuperClass(c); } while(shouldRecurseSuperClass(c)); // compute the intersection Set<String> complete = new TreeSet<String>(getters.keySet()); complete.retainAll(setters.keySet()); resurrect(getters, complete); resurrect(setters, complete); // then look for read/write properties. for (String name : complete) { M getter = getters.get(name); M setter = setters.get(name); Annotation[] ga = getter!=null ? reader().getAllMethodAnnotations(getter,new MethodLocatable<M>(this,getter,nav())) : EMPTY_ANNOTATIONS; Annotation[] sa = setter!=null ? reader().getAllMethodAnnotations(setter,new MethodLocatable<M>(this,setter,nav())) : EMPTY_ANNOTATIONS; boolean hasAnnotation = hasJAXBAnnotation(ga) || hasJAXBAnnotation(sa); boolean isOverriding = false; if(!hasAnnotation) { // checking if the method is overriding others isn't free, // so we don't compute it if it's not necessary. isOverriding = (getter!=null && nav().isOverriding(getter,c)) && (setter!=null && nav().isOverriding(setter,c)); } if((at==XmlAccessType.PROPERTY && !isOverriding) || (at==XmlAccessType.PUBLIC_MEMBER && isConsideredPublic(getter) && isConsideredPublic(setter) && !isOverriding) || hasAnnotation) { // make sure that the type is consistent if(getter!=null && setter!=null && !nav().isSameType(nav().getReturnType(getter), nav().getMethodParameters(setter)[0])) { // inconsistent builder.reportError(new IllegalAnnotationException( Messages.GETTER_SETTER_INCOMPATIBLE_TYPE.format( nav().getTypeName(nav().getReturnType(getter)), nav().getTypeName(nav().getMethodParameters(setter)[0]) ), new MethodLocatable<M>( this, getter, nav()), new MethodLocatable<M>( this, setter, nav()))); continue; } // merge annotations from two list Annotation[] r; if(ga.length==0) { r = sa; } else if(sa.length==0) { r = ga; } else { r = new Annotation[ga.length+sa.length]; System.arraycopy(ga,0,r,0,ga.length); System.arraycopy(sa,0,r,ga.length,sa.length); } addProperty(createAccessorSeed(getter, setter), r, false); } } // done with complete pairs getters.keySet().removeAll(complete); setters.keySet().removeAll(complete); // TODO: think about // class Foo { // int getFoo(); // } // class Bar extends Foo { // void setFoo(int x); // } // and how it will be XML-ized. }
Example 20
Source File: ClassInfoImpl.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
private void findFieldProperties(C c, XmlAccessType at) { // always find properties from the super class first C sc = nav().getSuperClass(c); if (shouldRecurseSuperClass(sc)) { findFieldProperties(sc,at); } for( F f : nav().getDeclaredFields(c) ) { Annotation[] annotations = reader().getAllFieldAnnotations(f,this); boolean isDummy = reader().hasFieldAnnotation(OverrideAnnotationOf.class, f); if( nav().isTransient(f) ) { // it's an error for transient field to have any binding annotation if(hasJAXBAnnotation(annotations)) builder.reportError(new IllegalAnnotationException( Messages.TRANSIENT_FIELD_NOT_BINDABLE.format(nav().getFieldName(f)), getSomeJAXBAnnotation(annotations))); } else if( nav().isStaticField(f) ) { // static fields are bound only when there's explicit annotation. if(hasJAXBAnnotation(annotations)) addProperty(createFieldSeed(f),annotations, false); } else { if(at==XmlAccessType.FIELD ||(at==XmlAccessType.PUBLIC_MEMBER && nav().isPublicField(f)) || hasJAXBAnnotation(annotations)) { if (isDummy) { ClassInfo<T, C> top = getBaseClass(); while ((top != null) && (top.getProperty("content") == null)) { top = top.getBaseClass(); } DummyPropertyInfo prop = (DummyPropertyInfo) top.getProperty("content"); PropertySeed seed = createFieldSeed(f); ((DummyPropertyInfo)prop).addType(createReferenceProperty(seed)); } else { addProperty(createFieldSeed(f), annotations, false); } } checkFieldXmlLocation(f); } } }