1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085
|
/*
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import java.beans.BeanInfo;
import java.beans.BeanProperty;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyChangeListener;
import java.beans.PropertyDescriptor;
import java.util.Arrays;
/**
* @test
* @bug 8132703 8132163 8132732 8132973 8154756 8132888 8155103
* @summary Some check for BeanProperty annotation
* @author a.stepanov
* @run main BeanPropertyTest
*/
public class BeanPropertyTest {
private final static String DESCRIPTION = "TEST";
private final static boolean BOUND = true;
private final static boolean EXPERT = false;
private final static boolean HIDDEN = true;
private final static boolean PREFERRED = false;
private final static boolean REQUIRED = true;
private final static boolean UPDATE = false;
private final static String
V_NAME = "javax.swing.SwingConstants.TOP",
V_SHORT = "TOP",
V = Integer.toString(javax.swing.SwingConstants.TOP);
private final static int X = javax.swing.SwingConstants.TOP;
private final static String DESCRIPTION_2 = "XYZ";
// ---------- test cases ----------
public static class G01 {
private final static String TESTCASE = "arbitrary getter name";
private final int x = X;
@BeanProperty(
description = DESCRIPTION,
bound = BOUND,
expert = EXPERT,
hidden = HIDDEN,
preferred = PREFERRED,
required = REQUIRED,
visualUpdate = UPDATE,
enumerationValues = {V_NAME})
public int get1() { return x; }
public void addPropertyChangeListener(PropertyChangeListener l) {}
public void removePropertyChangeListener(PropertyChangeListener l) {}
}
public static class S01 {
private final static String TESTCASE = "arbitrary setter name";
private int x;
@BeanProperty(
description = DESCRIPTION,
bound = BOUND,
expert = EXPERT,
hidden = HIDDEN,
preferred = PREFERRED,
required = REQUIRED,
visualUpdate = UPDATE,
enumerationValues = {V_NAME})
public void setXXXXX(int v) { x = v; }
public void addPropertyChangeListener(PropertyChangeListener l) {}
public void removePropertyChangeListener(PropertyChangeListener l) {}
}
// JDK-8132703
public static class G02 {
private final static String TESTCASE = "arbitrary getter name";
private final int x = X;
@BeanProperty(
description = DESCRIPTION,
bound = BOUND,
expert = EXPERT,
hidden = HIDDEN,
preferred = PREFERRED,
required = REQUIRED,
visualUpdate = UPDATE,
enumerationValues = {V_NAME})
public int get() { return x; }
public void addPropertyChangeListener(PropertyChangeListener l) {}
public void removePropertyChangeListener(PropertyChangeListener l) {}
}
// JDK-8132703
public static class S02 {
private final static String TESTCASE = "arbitrary setter name";
private int x;
@BeanProperty(
description = DESCRIPTION,
bound = BOUND,
expert = EXPERT,
hidden = HIDDEN,
preferred = PREFERRED,
required = REQUIRED,
visualUpdate = UPDATE,
enumerationValues = {V_NAME})
public void set(int v) { x = v; }
public void addPropertyChangeListener(PropertyChangeListener l) {}
public void removePropertyChangeListener(PropertyChangeListener l) {}
}
// JDK-8132703
public static class G03 {
private final static String TESTCASE = "arbitrary getter name";
private final int x = X;
@BeanProperty(
description = DESCRIPTION,
bound = BOUND,
expert = EXPERT,
hidden = HIDDEN,
preferred = PREFERRED,
required = REQUIRED,
visualUpdate = UPDATE,
enumerationValues = {V_NAME})
public int GetX() { return x; }
public void addPropertyChangeListener(PropertyChangeListener l) {}
public void removePropertyChangeListener(PropertyChangeListener l) {}
}
// JDK-8132703
public static class S03 {
private final static String TESTCASE = "arbitrary setter name";
private int x;
@BeanProperty(
description = DESCRIPTION,
bound = BOUND,
expert = EXPERT,
hidden = HIDDEN,
preferred = PREFERRED,
required = REQUIRED,
visualUpdate = UPDATE,
enumerationValues = {V_NAME})
public void SetX(int v) { x = v; }
public void addPropertyChangeListener(PropertyChangeListener l) {}
public void removePropertyChangeListener(PropertyChangeListener l) {}
}
// JDK-8132163
public static class G04 {
private final static String TESTCASE = "arbitrary getter return type";
private final int x = X;
@BeanProperty(
description = DESCRIPTION,
bound = BOUND,
expert = EXPERT,
hidden = HIDDEN,
preferred = PREFERRED,
required = REQUIRED,
visualUpdate = UPDATE,
enumerationValues = {V_NAME})
public Object getX() { return x; }
public void addPropertyChangeListener(PropertyChangeListener l) {}
public void removePropertyChangeListener(PropertyChangeListener l) {}
}
// JDK-8132163
public static class S04 {
private final static String TESTCASE = "arbitrary setter argument type";
private int x;
@BeanProperty(
description = DESCRIPTION,
bound = BOUND,
expert = EXPERT,
hidden = HIDDEN,
preferred = PREFERRED,
required = REQUIRED,
visualUpdate = UPDATE,
enumerationValues = {V_NAME})
public void setX(short v) { x = v; }
public void addPropertyChangeListener(PropertyChangeListener l) {}
public void removePropertyChangeListener(PropertyChangeListener l) {}
}
public static class G05 {
private final static String TESTCASE =
"annotated getter + arbitrary setter argument type";
private int x;
@BeanProperty(
description = DESCRIPTION,
bound = BOUND,
expert = EXPERT,
hidden = HIDDEN,
preferred = PREFERRED,
required = REQUIRED,
visualUpdate = UPDATE,
enumerationValues = {V_NAME})
public int getX() { return x; }
public void setX(short v) { x = v; }
public void addPropertyChangeListener(PropertyChangeListener l) {}
public void removePropertyChangeListener(PropertyChangeListener l) {}
}
// JDK-8132163
public static class S05 {
private final static String TESTCASE =
"annotated setter + arbitrary getter return type";
private int x;
@BeanProperty(
description = DESCRIPTION,
bound = BOUND,
expert = EXPERT,
hidden = HIDDEN,
preferred = PREFERRED,
required = REQUIRED,
visualUpdate = UPDATE,
enumerationValues = {V_NAME})
public void setX(int v) { x = v; }
public Object getX() { return x; }
public void addPropertyChangeListener(PropertyChangeListener l) {}
public void removePropertyChangeListener(PropertyChangeListener l) {}
}
public static class G06 {
private final static String TESTCASE = "indexed getter";
private final int x[] = {X, X, X};
@BeanProperty(
description = DESCRIPTION,
bound = BOUND,
expert = EXPERT,
hidden = HIDDEN,
preferred = PREFERRED,
required = REQUIRED,
visualUpdate = UPDATE,
enumerationValues = {V_NAME})
public int getX(int i) { return x[i]; }
public void addPropertyChangeListener(PropertyChangeListener l) {}
public void removePropertyChangeListener(PropertyChangeListener l) {}
}
public static class S06 {
private final static String TESTCASE = "indexed setter";
private final int x[] = {X, X, X};
@BeanProperty(
description = DESCRIPTION,
bound = BOUND,
expert = EXPERT,
hidden = HIDDEN,
preferred = PREFERRED,
required = REQUIRED,
visualUpdate = UPDATE,
enumerationValues = {V_NAME})
public void setX(int i, int v) { x[i] = v; }
public void addPropertyChangeListener(PropertyChangeListener l) {}
public void removePropertyChangeListener(PropertyChangeListener l) {}
}
public static class G07 {
private final static String TESTCASE =
"indexed (annotated) + non-indexed getters";
private final int x[] = {X, X, X};
@BeanProperty(
description = DESCRIPTION,
bound = BOUND,
expert = EXPERT,
hidden = HIDDEN,
preferred = PREFERRED,
required = REQUIRED,
visualUpdate = UPDATE,
enumerationValues = {V_NAME})
public int getX(int i) { return x[i]; }
public int[] getX() { return x; }
public void addPropertyChangeListener(PropertyChangeListener l) {}
public void removePropertyChangeListener(PropertyChangeListener l) {}
}
public static class S07 {
private final static String TESTCASE =
"indexed (annotated) + non-indexed setters";
private int x[] = new int[3];
@BeanProperty(
description = DESCRIPTION,
bound = BOUND,
expert = EXPERT,
hidden = HIDDEN,
preferred = PREFERRED,
required = REQUIRED,
visualUpdate = UPDATE,
enumerationValues = {V_NAME})
public void setX(int i, int v) { x[i] = v; }
public void setX(int a[]) { x = Arrays.copyOf(a, a.length); }
public void addPropertyChangeListener(PropertyChangeListener l) {}
public void removePropertyChangeListener(PropertyChangeListener l) {}
}
// JDK-8132732
public static class G08 {
private final static String TESTCASE =
"non-indexed (annotated) + indexed getters";
private final int x[] = {X, X, X};
@BeanProperty(
description = DESCRIPTION,
bound = BOUND,
expert = EXPERT,
hidden = HIDDEN,
preferred = PREFERRED,
required = REQUIRED,
visualUpdate = UPDATE,
enumerationValues = {V_NAME})
public int[] getX() { return x; }
public int getX(int i) { return x[i]; }
public void addPropertyChangeListener(PropertyChangeListener l) {}
public void removePropertyChangeListener(PropertyChangeListener l) {}
}
// JDK-8132732
public static class S08 {
private final static String TESTCASE =
"non-indexed (annotated) + indexed setters";
private int x[] = new int[3];
@BeanProperty(
description = DESCRIPTION,
bound = BOUND,
expert = EXPERT,
hidden = HIDDEN,
preferred = PREFERRED,
required = REQUIRED,
visualUpdate = UPDATE,
enumerationValues = {V_NAME})
public void setX(int a[]) { x = Arrays.copyOf(a, a.length); }
public void setX(int i, int v) { x[i] = v; }
public void addPropertyChangeListener(PropertyChangeListener l) {}
public void removePropertyChangeListener(PropertyChangeListener l) {}
}
// JDK-8132732
public static class G09 {
private final static String TESTCASE = "two annotated getters";
private final int x[] = {X, X, X};
@BeanProperty(
description = DESCRIPTION,
bound = BOUND,
expert = EXPERT,
hidden = HIDDEN,
preferred = PREFERRED,
required = REQUIRED,
visualUpdate = UPDATE,
enumerationValues = {V_NAME})
public int[] getX() { return x; }
@BeanProperty(
description = DESCRIPTION_2,
bound = !BOUND,
expert = !EXPERT,
hidden = !HIDDEN,
preferred = !PREFERRED,
required = !REQUIRED,
visualUpdate = !UPDATE)
public int getX(int i) { return x[i]; }
public void addPropertyChangeListener(PropertyChangeListener l) {}
public void removePropertyChangeListener(PropertyChangeListener l) {}
}
// JDK-8132732
public static class S09 {
private final static String TESTCASE = "two annotated setters";
private int x[] = new int[3];
@BeanProperty(
description = DESCRIPTION,
bound = BOUND,
expert = EXPERT,
hidden = HIDDEN,
preferred = PREFERRED,
required = REQUIRED,
visualUpdate = UPDATE,
enumerationValues = {V_NAME})
public void setX(int a[]) { x = Arrays.copyOf(a, a.length); }
@BeanProperty(
description = DESCRIPTION_2,
bound = !BOUND,
expert = !EXPERT,
hidden = !HIDDEN,
preferred = !PREFERRED,
required = !REQUIRED,
visualUpdate = !UPDATE)
public void setX(int i, int v) { x[i] = v; }
public void addPropertyChangeListener(PropertyChangeListener l) {}
public void removePropertyChangeListener(PropertyChangeListener l) {}
}
public static class G10 {
private final static String TESTCASE =
"getter + similarly named field";
public int prop, Prop, setProp, getProp;
@BeanProperty(
description = DESCRIPTION,
bound = BOUND,
expert = EXPERT,
hidden = HIDDEN,
preferred = PREFERRED,
required = REQUIRED,
visualUpdate = UPDATE,
enumerationValues = {V_NAME})
public int getProp() { return X; }
public void setProp(int v) { prop = Prop = setProp = getProp = v; }
public void addPropertyChangeListener(PropertyChangeListener l) {}
public void removePropertyChangeListener(PropertyChangeListener l) {}
}
public static class S10 {
private final static String TESTCASE =
"setter + similarly named field";
public int prop, Prop, setProp, getProp;
private int x;
@BeanProperty(
description = DESCRIPTION,
bound = BOUND,
expert = EXPERT,
hidden = HIDDEN,
preferred = PREFERRED,
required = REQUIRED,
visualUpdate = UPDATE,
enumerationValues = {V_NAME})
public int getProp() { return x; }
public void setProp(int v) { x = v; }
public void addPropertyChangeListener(PropertyChangeListener l) {}
public void removePropertyChangeListener(PropertyChangeListener l) {}
}
public static class G11 {
private final static String TESTCASE =
"getter + similarly named field of other type";
public Object prop, Prop, setProp, getProp;
@BeanProperty(
description = DESCRIPTION,
bound = BOUND,
expert = EXPERT,
hidden = HIDDEN,
preferred = PREFERRED,
required = REQUIRED,
visualUpdate = UPDATE,
enumerationValues = {V_NAME})
public int getProp() { return X; }
public void setProp(int v) { prop = Prop = setProp = getProp = v; }
public void addPropertyChangeListener(PropertyChangeListener l) {}
public void removePropertyChangeListener(PropertyChangeListener l) {}
}
public static class S11 {
private final static String TESTCASE =
"setter + similarly named field of other type";
public String prop, Prop, setProp, getProp;
private int x;
@BeanProperty(
description = DESCRIPTION,
bound = BOUND,
expert = EXPERT,
hidden = HIDDEN,
preferred = PREFERRED,
required = REQUIRED,
visualUpdate = UPDATE,
enumerationValues = {V_NAME})
public int getProp() { return x; }
public void setProp(int v) { x = v; }
public void addPropertyChangeListener(PropertyChangeListener l) {}
public void removePropertyChangeListener(PropertyChangeListener l) {}
}
// JDK-8132163
public static class G12 {
private final static String TESTCASE =
"getter having wrapper class return type";
private final int x = X;
@BeanProperty(
description = DESCRIPTION,
bound = BOUND,
expert = EXPERT,
hidden = HIDDEN,
preferred = PREFERRED,
required = REQUIRED,
visualUpdate = UPDATE,
enumerationValues = {V_NAME})
public Integer getProp() { return x; }
public void addPropertyChangeListener(PropertyChangeListener l) {}
public void removePropertyChangeListener(PropertyChangeListener l) {}
}
// JDK-8132163
public static class S12 {
private final static String TESTCASE =
"setter with wrapper class argument type";
private int x;
@BeanProperty(
description = DESCRIPTION,
bound = BOUND,
expert = EXPERT,
hidden = HIDDEN,
preferred = PREFERRED,
required = REQUIRED,
visualUpdate = UPDATE,
enumerationValues = {V_NAME})
public void setX(Integer v) { x = v; }
public void addPropertyChangeListener(PropertyChangeListener l) {}
public void removePropertyChangeListener(PropertyChangeListener l) {}
}
public static class G13 {
private final static String TESTCASE =
"getter + overloading methods";
private final int x = X;
@BeanProperty(
description = DESCRIPTION,
bound = BOUND,
expert = EXPERT,
hidden = HIDDEN,
preferred = PREFERRED,
required = REQUIRED,
visualUpdate = UPDATE,
enumerationValues = {V_NAME})
public int getX() { return x; }
public int getX(boolean arg) { return (arg ? x : 0); }
public int getX(int ... dummy) { return 0; }
public void addPropertyChangeListener(PropertyChangeListener l) {}
public void removePropertyChangeListener(PropertyChangeListener l) {}
}
// JDK-8154756
public static class S13 {
private final static String TESTCASE =
"setter + overloading methods";
private int x;
@BeanProperty(
description = DESCRIPTION,
bound = BOUND,
expert = EXPERT,
hidden = HIDDEN,
preferred = PREFERRED,
required = REQUIRED,
visualUpdate = UPDATE,
enumerationValues = {V_NAME})
public void setX(int v) { x = v; }
public int setX() { return (x = X); }
public void setX(int ... dummy) {}
private void setX(Object ... dummy) {}
public void addPropertyChangeListener(PropertyChangeListener l) {}
public void removePropertyChangeListener(PropertyChangeListener l) {}
}
// JDK-8132888
public static class G14 {
private final static String TESTCASE = "non-public getter";
private final int x = X;
@BeanProperty(
description = DESCRIPTION,
bound = BOUND,
expert = EXPERT,
hidden = HIDDEN,
preferred = PREFERRED,
required = REQUIRED,
visualUpdate = UPDATE,
enumerationValues = {V_NAME})
int getX() { return x; } // getter is not public
public void addPropertyChangeListener(PropertyChangeListener l) {}
public void removePropertyChangeListener(PropertyChangeListener l) {}
}
// JDK-8132888
public static class S14 {
private final static String TESTCASE = "non-public setter";
private int x;
@BeanProperty(
description = DESCRIPTION,
bound = BOUND,
expert = EXPERT,
hidden = HIDDEN,
preferred = PREFERRED,
required = REQUIRED,
visualUpdate = UPDATE,
enumerationValues = {V_NAME})
void setX(int v) { x = v; } // setter is not public
public void addPropertyChangeListener(PropertyChangeListener l) {}
public void removePropertyChangeListener(PropertyChangeListener l) {}
}
public static class getX {
private final static String TESTCASE =
"class name coincides with getter name";
private int x;
@BeanProperty(
description = DESCRIPTION,
bound = BOUND,
expert = EXPERT,
hidden = HIDDEN,
preferred = PREFERRED,
required = REQUIRED,
visualUpdate = UPDATE,
enumerationValues = {V_NAME})
public int getX() { return x; }
public void setX(int v) { x = v; }
public void addPropertyChangeListener(PropertyChangeListener l) {}
public void removePropertyChangeListener(PropertyChangeListener l) {}
}
public static class setX {
private final static String TESTCASE =
"class name coincides with setter name";
private int x;
@BeanProperty(
description = DESCRIPTION,
bound = BOUND,
expert = EXPERT,
hidden = HIDDEN,
preferred = PREFERRED,
required = REQUIRED,
visualUpdate = UPDATE,
enumerationValues = {V_NAME})
public void setX(int v) { x = v; }
public int getX() { return x; }
public void addPropertyChangeListener(PropertyChangeListener l) {}
public void removePropertyChangeListener(PropertyChangeListener l) {}
}
// JDK-8132973
public static class GS {
private final static String TESTCASE =
"both getter and setter are annotated";
private int x;
@BeanProperty(
description = DESCRIPTION,
bound = BOUND,
expert = EXPERT,
hidden = HIDDEN,
preferred = PREFERRED,
required = REQUIRED,
visualUpdate = UPDATE,
enumerationValues = {V_NAME})
public int getX() { return x; }
@BeanProperty(
description = DESCRIPTION_2,
bound = !BOUND,
expert = !EXPERT,
hidden = !HIDDEN,
preferred = !PREFERRED,
required = !REQUIRED,
visualUpdate = !UPDATE)
public void setX(int v) { x = v; }
public void addPropertyChangeListener(PropertyChangeListener l) {}
public void removePropertyChangeListener(PropertyChangeListener l) {}
}
public static class Self {
private final static String TESTCASE = "trivial singleton";
private static Self instance = null;
private Self() {}
@BeanProperty(
description = DESCRIPTION,
bound = BOUND,
expert = EXPERT,
hidden = HIDDEN,
preferred = PREFERRED,
required = REQUIRED,
visualUpdate = UPDATE)
public Self getSelf() {
if (instance == null) { instance = new Self(); }
return instance;
}
public void addPropertyChangeListener(PropertyChangeListener l) {}
public void removePropertyChangeListener(PropertyChangeListener l) {}
}
public static class SelfArr {
private final static String TESTCASE = "trivial singleton + array";
private static SelfArr arr[] = null;
private SelfArr() {}
@BeanProperty(
description = DESCRIPTION,
bound = BOUND,
expert = EXPERT,
hidden = HIDDEN,
preferred = PREFERRED,
required = REQUIRED,
visualUpdate = UPDATE)
public SelfArr[] getSelfArr() {
if (arr == null) { arr = new SelfArr[]{new SelfArr(), new SelfArr()}; }
return arr;
}
public void addPropertyChangeListener(PropertyChangeListener l) {}
public void removePropertyChangeListener(PropertyChangeListener l) {}
}
public enum E {
ONE,
TWO {
@BeanProperty(
description = DESCRIPTION,
bound = BOUND,
expert = EXPERT,
hidden = HIDDEN,
preferred = PREFERRED,
required = REQUIRED,
visualUpdate = UPDATE,
enumerationValues = {V_NAME})
public void setX(int v) {}
public void addPropertyChangeListener(PropertyChangeListener l) {}
public void removePropertyChangeListener(PropertyChangeListener l) {}
};
@BeanProperty(
description = DESCRIPTION,
bound = BOUND,
expert = EXPERT,
hidden = HIDDEN,
preferred = PREFERRED,
required = REQUIRED,
visualUpdate = UPDATE,
enumerationValues = {V_NAME})
public void setX(int v) {}
public void addPropertyChangeListener(PropertyChangeListener l) {}
public void removePropertyChangeListener(PropertyChangeListener l) {}
}
private enum EB {
TRUE(true), FALSE(false);
private boolean b;
private EB(boolean v) { b = v; }
@BeanProperty(
description = DESCRIPTION,
bound = BOUND,
expert = EXPERT,
hidden = HIDDEN,
preferred = PREFERRED,
required = REQUIRED,
visualUpdate = UPDATE)
public boolean isTrue() { return true; }
public void addPropertyChangeListener(PropertyChangeListener l) {}
public void removePropertyChangeListener(PropertyChangeListener l) {}
}
// ---------- checks ----------
private static boolean check(String what, boolean v, boolean ref) {
boolean ok = (v == ref);
if (!ok) { System.out.println(
"invalid " + what + ": " + v + ", expected: " + ref); }
return ok;
}
private static boolean checkInfo(BeanInfo i, boolean checkVals) {
System.out.println("checking info...");
PropertyDescriptor descriptors[] = i.getPropertyDescriptors();
int nd = descriptors.length;
if (nd != 1) {
System.out.println("invalid number of descriptors: " + nd);
return false;
}
PropertyDescriptor d = descriptors[0];
String descr = d.getShortDescription();
boolean ok = descr.equals(DESCRIPTION);
if (!ok) { System.out.println("invalid description: " + descr +
", expected: " + DESCRIPTION); }
ok &= check("isBound", d.isBound(), BOUND);
ok &= check("isExpert", d.isExpert(), EXPERT);
ok &= check("isHidden", d.isHidden(), HIDDEN);
ok &= check("isPreferred", d.isPreferred(), PREFERRED);
ok &= check("required", (boolean) d.getValue("required"), REQUIRED);
ok &= check("visualUpdate",
(boolean) d.getValue("visualUpdate"), UPDATE);
if (!checkVals) { return ok; }
Object vals[] = (Object[]) d.getValue("enumerationValues");
if (vals == null) {
System.out.println("null enumerationValues");
return false;
}
boolean okVals = (
(vals.length == 3) &&
vals[0].toString().equals(V_SHORT) &&
vals[1].toString().equals(V) &&
vals[2].toString().equals(V_NAME));
if (!okVals) { System.out.println("invalid enumerationValues"); }
return (ok && okVals);
}
private static boolean checkAlternativeInfo(BeanInfo i) {
System.out.println("checking alternative info...");
PropertyDescriptor descriptors[] = i.getPropertyDescriptors();
int nd = descriptors.length;
if (nd != 1) {
System.out.println("invalid number of descriptors: " + nd);
return false;
}
PropertyDescriptor d = descriptors[0];
String descr = d.getShortDescription();
boolean ok = descr.equals(DESCRIPTION_2);
if (!ok) { System.out.println("invalid alternative description: " +
descr + ", expected: " + DESCRIPTION_2); }
ok &= check("isBound", d.isBound(), !BOUND);
ok &= check("isExpert", d.isExpert(), !EXPERT);
ok &= check("isHidden", d.isHidden(), !HIDDEN);
ok &= check("isPreferred", d.isPreferred(), !PREFERRED);
ok &= check("required", (boolean) d.getValue("required"), !REQUIRED);
ok &= check("visualUpdate",
(boolean) d.getValue("visualUpdate"), !UPDATE);
Object vals[] = (Object[]) d.getValue("enumerationValues");
if (vals != null || vals.length > 0) {
System.out.println("non-null enumerationValues");
return false;
}
return ok;
}
private static boolean checkAlternative(Class<?> c) {
return (
c.equals(G09.class) ||
c.equals(S09.class) ||
c.equals(GS.class));
}
private static boolean ignoreVals(Class<?> c) {
return (c.equals(Self.class) || c.equals(SelfArr.class)) || c.equals(EB.class);
}
// ---------- run test ----------
public static void main(String[] args) throws Exception {
Class<?> cases[] = {
G01.class, S01.class,
// G02.class, S02.class, // TODO: please update after 8132703 fix
// G03.class, S03.class, // TODO: please update after 8132703 fix
// G04.class, S04.class, // TODO: please update after 8132163 fix
G05.class, // S05.class, // TODO: please update after 8132163 fix
G06.class, S06.class,
G07.class, S07.class,
// G08.class, S08.class, // TODO: please update after 8132732 fix
// G09.class, S09.class, // TODO: please update after 8132732 fix
G10.class, S10.class,
G11.class, S11.class,
// G12.class, S12.class, // TODO: please update after 8132163 fix
G13.class, // S13.class, // TODO: please update after 8154756 fix
// G14.class, S14.class, // TODO: please update after 8132888 fix or
// remove these cases if it is not an issue
GS.class,
getX.class, setX.class,
Self.class, SelfArr.class
};
boolean passed = true;
for (Class<?> c: cases) {
java.lang.reflect.Field f = c.getDeclaredField("TESTCASE");
f.setAccessible(true);
String descr = f.get(c).toString();
System.out.println("\n" + c.getSimpleName() + " (" + descr + "):");
BeanInfo i;
try { i = Introspector.getBeanInfo(c, Object.class); }
catch (IntrospectionException e) { throw new RuntimeException(e); }
boolean ok = checkInfo(i, !ignoreVals(c));
if (checkAlternative(c)) {
ok |= checkAlternativeInfo(i);
}
System.out.println(ok ? "OK" : "NOK");
passed = passed && ok;
}
// enums
Class<?> enumCases[] = {
E.class, E.TWO.getClass(), EB.class
};
int ne = 1;
for (Class<?> c: enumCases) {
System.out.println("\nEnum-" + ne + ":");
ne++;
BeanInfo i;
try { i = Introspector.getBeanInfo(c, Enum.class); }
catch (IntrospectionException e) { throw new RuntimeException(e); }
boolean ok = checkInfo(i, !ignoreVals(c));
System.out.println(ok ? "OK" : "NOK");
passed = passed && ok;
}
if (!passed) { throw new RuntimeException("test failed"); }
System.out.println("\ntest passed");
}
}
|