
import java.beans.*;


public class StaticPropTest {

    public static class C {
        public static int getX() { return 42; }
    }

    public static class CBeanInfo extends SimpleBeanInfo {

        @Override
        public BeanDescriptor getBeanDescriptor() {
            BeanDescriptor d = new BeanDescriptor(C.class);
            d.setShortDescription("test");
            return d;
        }

        @Override
        public PropertyDescriptor[] getPropertyDescriptors() {
            PropertyDescriptor[] p = new PropertyDescriptor[1];

            try {
                p[0] = new PropertyDescriptor ("x", C.class, "getX", null);
                p[0].setShortDescription("C property");
                p[0].setPreferred(true);
                p[0].setExpert(true);
            } catch(IntrospectionException e) { throw new RuntimeException(e); }

            return p;
        }

        @Override
        public EventSetDescriptor[] getEventSetDescriptors() { return new EventSetDescriptor[0]; }
        @Override
        public MethodDescriptor[] getMethodDescriptors() { return new MethodDescriptor[]{}; }

        @Override
        public int getDefaultPropertyIndex() { return -1; }
        @Override
        public int getDefaultEventIndex() { return -1; }
        @Override
        public java.awt.Image getIcon(int iconKind) { return null; }
    }

    public static class D {
        @BeanProperty(
            description = "D property",
            preferred   = true,
            expert      = true)
        public static int getX() { return 42; }
    }

    public static void Test(Class<?> c) throws Exception {

        System.out.println("\n" + c.getSimpleName());
        BeanInfo i = Introspector.getBeanInfo(c, Object.class);
        PropertyDescriptor d[] = i.getPropertyDescriptors();
        if (d.length < 1) { System.out.println("no descriptors"); }
        else {
            PropertyDescriptor p = d[0];
            System.out.println(p.getShortDescription() + ", " +
                p.isPreferred() + ", " + p.isExpert());
        }
    }

    public static void main(String[] args) throws Exception {

        Test(C.class);
        Test(D.class);
    }
}
