test/jdk/java/beans/Performance/Test4058433.java
author lancea
Thu, 14 Nov 2019 10:54:32 -0500
changeset 59083 3e4d8b5856f3
parent 47216 71c04702a3d5
permissions -rw-r--r--
8234080: jdk/nio/zipfs/CRCWriteTest.java fails Reviewed-by: clanger, amlu
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
25566
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
     1
/*
32115
e686c75fd10a 8066404: The case is failed automatically and thrown the "java.lang.IllegalStateException" exception
serb
parents: 25566
diff changeset
     2
 * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
25566
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
     4
 *
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
     7
 * published by the Free Software Foundation.
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
     8
 *
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    13
 * accompanied this code).
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    14
 *
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    18
 *
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    21
 * questions.
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    22
 */
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    23
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    24
import java.awt.Image;
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    25
import java.beans.BeanDescriptor;
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    26
import java.beans.BeanInfo;
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    27
import java.beans.EventSetDescriptor;
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    28
import java.beans.FeatureDescriptor;
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    29
import java.beans.IndexedPropertyDescriptor;
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    30
import java.beans.Introspector;
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    31
import java.beans.MethodDescriptor;
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    32
import java.beans.ParameterDescriptor;
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    33
import java.beans.PropertyDescriptor;
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    34
import java.lang.reflect.Array;
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    35
import java.lang.reflect.Method;
32115
e686c75fd10a 8066404: The case is failed automatically and thrown the "java.lang.IllegalStateException" exception
serb
parents: 25566
diff changeset
    36
import java.net.URI;
e686c75fd10a 8066404: The case is failed automatically and thrown the "java.lang.IllegalStateException" exception
serb
parents: 25566
diff changeset
    37
import java.nio.file.FileSystem;
e686c75fd10a 8066404: The case is failed automatically and thrown the "java.lang.IllegalStateException" exception
serb
parents: 25566
diff changeset
    38
import java.nio.file.FileSystems;
e686c75fd10a 8066404: The case is failed automatically and thrown the "java.lang.IllegalStateException" exception
serb
parents: 25566
diff changeset
    39
import java.nio.file.FileVisitResult;
e686c75fd10a 8066404: The case is failed automatically and thrown the "java.lang.IllegalStateException" exception
serb
parents: 25566
diff changeset
    40
import java.nio.file.Files;
e686c75fd10a 8066404: The case is failed automatically and thrown the "java.lang.IllegalStateException" exception
serb
parents: 25566
diff changeset
    41
import java.nio.file.Path;
e686c75fd10a 8066404: The case is failed automatically and thrown the "java.lang.IllegalStateException" exception
serb
parents: 25566
diff changeset
    42
import java.nio.file.SimpleFileVisitor;
e686c75fd10a 8066404: The case is failed automatically and thrown the "java.lang.IllegalStateException" exception
serb
parents: 25566
diff changeset
    43
import java.nio.file.attribute.BasicFileAttributes;
25566
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    44
import java.util.Arrays;
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    45
import java.util.Comparator;
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    46
import java.util.Enumeration;
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    47
import java.util.Map.Entry;
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    48
import java.util.Objects;
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    49
import java.util.TreeMap;
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    50
import java.util.TreeSet;
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    51
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    52
/*
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    53
 * @test
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    54
 * @bug 4058433
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    55
 * @summary Generates BeanInfo for public classes in AWT, Accessibility, and Swing
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    56
 * @author Sergey Malenkov
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    57
 */
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    58
public class Test4058433 implements Comparator<Object> {
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    59
    @Override
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    60
    public int compare(Object one, Object two) {
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    61
        if (one instanceof Method && two instanceof Method) {
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    62
            Method oneMethod = (Method) one;
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    63
            Method twoMethod = (Method) two;
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    64
            int result = oneMethod.getName().compareTo(twoMethod.getName());
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    65
            if (result != 0) {
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    66
                return result;
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    67
            }
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    68
        }
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    69
        if (one instanceof FeatureDescriptor && two instanceof FeatureDescriptor) {
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    70
            FeatureDescriptor oneFD = (FeatureDescriptor) one;
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    71
            FeatureDescriptor twoFD = (FeatureDescriptor) two;
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    72
            int result = oneFD.getName().compareTo(twoFD.getName());
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    73
            if (result != 0) {
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    74
                return result;
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    75
            }
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    76
        }
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    77
        return one.toString().compareTo(two.toString());
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    78
    }
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    79
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    80
    public static void main(String[] args) throws Exception {
32115
e686c75fd10a 8066404: The case is failed automatically and thrown the "java.lang.IllegalStateException" exception
serb
parents: 25566
diff changeset
    81
        FileSystem fs = FileSystems.getFileSystem(URI.create("jrt:/"));
e686c75fd10a 8066404: The case is failed automatically and thrown the "java.lang.IllegalStateException" exception
serb
parents: 25566
diff changeset
    82
        fs.getFileStores();
25566
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    83
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    84
        TreeSet<Class<?>> types = new TreeSet<>(new Test4058433());
32115
e686c75fd10a 8066404: The case is failed automatically and thrown the "java.lang.IllegalStateException" exception
serb
parents: 25566
diff changeset
    85
        Files.walkFileTree(fs.getPath("/modules/java.desktop"), new SimpleFileVisitor<Path>() {
e686c75fd10a 8066404: The case is failed automatically and thrown the "java.lang.IllegalStateException" exception
serb
parents: 25566
diff changeset
    86
            @Override
e686c75fd10a 8066404: The case is failed automatically and thrown the "java.lang.IllegalStateException" exception
serb
parents: 25566
diff changeset
    87
            public FileVisitResult visitFile(Path file,
e686c75fd10a 8066404: The case is failed automatically and thrown the "java.lang.IllegalStateException" exception
serb
parents: 25566
diff changeset
    88
                                             BasicFileAttributes attrs) {
e686c75fd10a 8066404: The case is failed automatically and thrown the "java.lang.IllegalStateException" exception
serb
parents: 25566
diff changeset
    89
                file = file.subpath(2, file.getNameCount());
e686c75fd10a 8066404: The case is failed automatically and thrown the "java.lang.IllegalStateException" exception
serb
parents: 25566
diff changeset
    90
                if (file.startsWith("java/awt/")
e686c75fd10a 8066404: The case is failed automatically and thrown the "java.lang.IllegalStateException" exception
serb
parents: 25566
diff changeset
    91
                        || file.startsWith("javax/accessibility/")
e686c75fd10a 8066404: The case is failed automatically and thrown the "java.lang.IllegalStateException" exception
serb
parents: 25566
diff changeset
    92
                        || file.startsWith("javax/swing/")) {
e686c75fd10a 8066404: The case is failed automatically and thrown the "java.lang.IllegalStateException" exception
serb
parents: 25566
diff changeset
    93
                    String name =file.toString();
25566
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    94
                    if (name.endsWith(".class")) {
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
    95
                        name = name.substring(0, name.indexOf(".")).replace('/', '.');
32115
e686c75fd10a 8066404: The case is failed automatically and thrown the "java.lang.IllegalStateException" exception
serb
parents: 25566
diff changeset
    96
e686c75fd10a 8066404: The case is failed automatically and thrown the "java.lang.IllegalStateException" exception
serb
parents: 25566
diff changeset
    97
                        final Class<?> type;
e686c75fd10a 8066404: The case is failed automatically and thrown the "java.lang.IllegalStateException" exception
serb
parents: 25566
diff changeset
    98
                        try {
e686c75fd10a 8066404: The case is failed automatically and thrown the "java.lang.IllegalStateException" exception
serb
parents: 25566
diff changeset
    99
                            type = Class.forName(name);
e686c75fd10a 8066404: The case is failed automatically and thrown the "java.lang.IllegalStateException" exception
serb
parents: 25566
diff changeset
   100
                        } catch (ClassNotFoundException e) {
e686c75fd10a 8066404: The case is failed automatically and thrown the "java.lang.IllegalStateException" exception
serb
parents: 25566
diff changeset
   101
                            throw new RuntimeException(e);
e686c75fd10a 8066404: The case is failed automatically and thrown the "java.lang.IllegalStateException" exception
serb
parents: 25566
diff changeset
   102
                        }
e686c75fd10a 8066404: The case is failed automatically and thrown the "java.lang.IllegalStateException" exception
serb
parents: 25566
diff changeset
   103
                        if (!BeanInfo.class.isAssignableFrom(type) && !type.isInterface()
e686c75fd10a 8066404: The case is failed automatically and thrown the "java.lang.IllegalStateException" exception
serb
parents: 25566
diff changeset
   104
                            && !type.isEnum() && !type.isAnnotation()
e686c75fd10a 8066404: The case is failed automatically and thrown the "java.lang.IllegalStateException" exception
serb
parents: 25566
diff changeset
   105
                            && !type.isAnonymousClass()) {
25566
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   106
                            if (null == type.getDeclaringClass()) {
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   107
                                types.add(type);
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   108
                            }
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   109
                        }
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   110
                    }
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   111
                }
32115
e686c75fd10a 8066404: The case is failed automatically and thrown the "java.lang.IllegalStateException" exception
serb
parents: 25566
diff changeset
   112
                return FileVisitResult.CONTINUE;
25566
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   113
            }
32115
e686c75fd10a 8066404: The case is failed automatically and thrown the "java.lang.IllegalStateException" exception
serb
parents: 25566
diff changeset
   114
        });
e686c75fd10a 8066404: The case is failed automatically and thrown the "java.lang.IllegalStateException" exception
serb
parents: 25566
diff changeset
   115
25566
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   116
        System.out.println("found " + types.size() + " classes");
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   117
        long time = -System.currentTimeMillis();
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   118
        for (Class<?> type : types) {
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   119
            System.out.println("========================================");
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   120
            BeanInfo info = Introspector.getBeanInfo(type);
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   121
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   122
            BeanDescriptor bd = info.getBeanDescriptor();
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   123
            System.out.println(bd.getBeanClass());
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   124
            print("customizer", bd.getCustomizerClass());
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   125
            print(bd);
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   126
            print("mono 16x16", info.getIcon(BeanInfo.ICON_MONO_16x16));
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   127
            print("mono 32x32", info.getIcon(BeanInfo.ICON_MONO_32x32));
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   128
            print("color 16x16", info.getIcon(BeanInfo.ICON_COLOR_16x16));
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   129
            print("color 32x32", info.getIcon(BeanInfo.ICON_COLOR_32x32));
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   130
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   131
            PropertyDescriptor[] pds = info.getPropertyDescriptors();
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   132
            PropertyDescriptor dpd = getDefault(pds, info.getDefaultPropertyIndex());
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   133
            System.out.println(pds.length + " property descriptors");
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   134
            Arrays.sort(pds, new Test4058433());
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   135
            for (PropertyDescriptor pd : pds) {
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   136
                print(pd);
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   137
                if (dpd == pd) {
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   138
                    System.out.println("default property");
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   139
                }
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   140
                print("bound", pd.isBound());
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   141
                print("constrained", pd.isConstrained());
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   142
                print("property editor", pd.getPropertyEditorClass());
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   143
                print("property type", pd.getPropertyType());
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   144
                print("read method", pd.getReadMethod());
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   145
                print("write method", pd.getWriteMethod());
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   146
                if (pd instanceof IndexedPropertyDescriptor) {
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   147
                    IndexedPropertyDescriptor ipd = (IndexedPropertyDescriptor) pd;
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   148
                    print("indexed property type", ipd.getIndexedPropertyType());
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   149
                    print("indexed read method", ipd.getIndexedReadMethod());
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   150
                    print("indexed write method", ipd.getIndexedWriteMethod());
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   151
                }
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   152
            }
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   153
            EventSetDescriptor[] esds = info.getEventSetDescriptors();
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   154
            EventSetDescriptor desd = getDefault(esds, info.getDefaultEventIndex());
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   155
            System.out.println(esds.length + " event set descriptors");
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   156
            Arrays.sort(esds, new Test4058433());
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   157
            for (EventSetDescriptor esd : esds) {
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   158
                print(esd);
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   159
                if (desd == esd) {
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   160
                    System.out.println("default event set");
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   161
                }
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   162
                print("in default", esd.isInDefaultEventSet());
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   163
                print("unicast", esd.isUnicast());
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   164
                print("listener type", esd.getListenerType());
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   165
                print("get listener method", esd.getGetListenerMethod());
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   166
                print("add listener method", esd.getAddListenerMethod());
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   167
                print("remove listener method", esd.getRemoveListenerMethod());
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   168
                Method[] methods = esd.getListenerMethods();
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   169
                Arrays.sort(methods, new Test4058433());
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   170
                for (Method method : methods) {
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   171
                    print("listener method", method);
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   172
                }
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   173
                print(esd.getListenerMethodDescriptors());
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   174
            }
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   175
            print(info.getMethodDescriptors());
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   176
        }
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   177
        time += System.currentTimeMillis();
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   178
        System.out.println("DONE IN " + time + " MS");
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   179
    }
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   180
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   181
    private static <T> T getDefault(T[] array, int index) {
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   182
        return (index == -1) ? null : array[index];
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   183
    }
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   184
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   185
    private static void print(MethodDescriptor[] mds) {
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   186
        System.out.println(mds.length + " method descriptors");
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   187
        Arrays.sort(mds, new Test4058433());
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   188
        for (MethodDescriptor md : mds) {
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   189
            print(md);
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   190
            print("method", md.getMethod());
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   191
            ParameterDescriptor[] pds = md.getParameterDescriptors();
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   192
            if (pds != null) {
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   193
                System.out.println(pds.length + " parameter descriptors");
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   194
                for (ParameterDescriptor pd : pds) {
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   195
                    print(pd);
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   196
                }
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   197
            }
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   198
        }
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   199
    }
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   200
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   201
    private static void print(FeatureDescriptor descriptor) {
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   202
        String name = descriptor.getName();
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   203
        String display = descriptor.getDisplayName();
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   204
        String description = descriptor.getShortDescription();
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   205
        System.out.println("name: " + name);
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   206
        if (!Objects.equals(name, display)) {
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   207
            System.out.println("display name: " + display);
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   208
        }
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   209
        if (!Objects.equals(display, description)) {
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   210
            System.out.println("description: " + description.trim());
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   211
        }
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   212
        print("expert", descriptor.isExpert());
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   213
        print("hidden", descriptor.isHidden());
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   214
        print("preferred", descriptor.isPreferred());
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   215
        TreeMap<String,Object> map = new TreeMap<>();
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   216
        Enumeration<String> enumeration = descriptor.attributeNames();
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   217
        while (enumeration.hasMoreElements()) {
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   218
            String id = enumeration.nextElement();
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   219
            Object value = descriptor.getValue(id);
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   220
            if (value.getClass().isArray()) {
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   221
                TreeSet<String> set = new TreeSet<>();
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   222
                int index = 0;
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   223
                int length = Array.getLength(value);
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   224
                while (index < length) {
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   225
                    set.add(Array.get(value, index++) + ", " +
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   226
                            Array.get(value, index++) + ", " +
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   227
                            Array.get(value, index++));
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   228
                }
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   229
                value = set.toString();
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   230
            }
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   231
            map.put(id, value);
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   232
        }
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   233
        for (Entry<String,Object> entry : map.entrySet()) {
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   234
            System.out.println(entry.getKey() + ": " + entry.getValue());
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   235
        }
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   236
    }
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   237
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   238
    private static void print(String id, boolean flag) {
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   239
        if (flag) {
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   240
            System.out.println(id + " is set");
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   241
        }
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   242
    }
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   243
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   244
    private static void print(String id, Class<?> type) {
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   245
        if (type != null) {
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   246
            System.out.println(id + ": " + type.getName());
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   247
        }
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   248
    }
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   249
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   250
    private static void print(String id, Method method) {
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   251
        if (method != null) {
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   252
            System.out.println(id + ": " + method);
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   253
        }
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   254
    }
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   255
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   256
    private static void print(String name, Image image) {
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   257
        if (image != null) {
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   258
            System.out.println(name + " icon is exist");
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   259
        }
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   260
    }
ba387c302edd 4058433: RFE: tool for creating BeanInfo template
malenkov
parents:
diff changeset
   261
}