Java Code Examples for javax.xml.bind.annotation.XmlAccessType#PROPERTY

The following examples show how to use javax.xml.bind.annotation.XmlAccessType#PROPERTY . 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 vote down vote up
/**
 * 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: JAXBContextInitializer.java    From cxf with Apache License 2.0 6 votes vote down vote up
/**
 * 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 3
Source File: ClassInfoImpl.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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 4
Source File: ClassInfoImpl.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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 5
Source File: ClassInfoImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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 6
Source File: ClassInfoImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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 7
Source File: ClassInfoImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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 8
Source File: ClassInfoImpl.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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 9
Source File: ClassInfoImpl.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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 10
Source File: ClassInfoImpl.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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.
}