jdk/make/src/classes/build/tools/swingbeaninfo/GenDocletBeanInfo.java
author ihse
Thu, 14 Nov 2013 11:19:32 +0100
changeset 21805 c7d7946239de
parent 5506 jdk/make/tools/swing-beans/GenDocletBeanInfo.java@202f599c92aa
child 23010 6dadb192ad81
permissions -rw-r--r--
8027566: Remove the old build system Reviewed-by: erikj, tbell
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 1998, 2001, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
21805
c7d7946239de 8027566: Remove the old build system
ihse
parents: 5506
diff changeset
    26
package build.tools.swingbeaninfo;
c7d7946239de 8027566: Remove the old build system
ihse
parents: 5506
diff changeset
    27
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import com.sun.javadoc.ClassDoc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import com.sun.javadoc.MethodDoc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import com.sun.javadoc.RootDoc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import com.sun.javadoc.Tag;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.beans.Introspector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.util.Enumeration;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.util.Hashtable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.util.HashMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.util.StringTokenizer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * Properties supported and tag syntax:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 *      bound: flag
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *      constrained: flag
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *      expert: flag
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *      hidden: flag
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *      preferred: flag
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *      description: string
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *      displayname: string
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *      propertyeditorclass: string (with dots: foo.bar.MyPropertyEditor
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 *      customizerclass: string (w/dots: foo.bar.MyCustomizer)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 *      attribute: key1 value1
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 *      attribute: key2 value2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * TODO: getValue and genDocletInfo needs some cleaning.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * @author Hans Muller
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * @author Rich Schiavi
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * @author Mark Davidson
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
public class GenDocletBeanInfo {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    static String[] ATTRIBUTE_NAMES = { "bound",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
                                     "constrained",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
                                     "expert",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
                                     "hidden",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
                                     "preferred",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
                                     "displayname",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
                                     "propertyeditorclass",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
                                     "customizerclass",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
                                     "displayname",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
                                     "description",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
                                     "enum",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
                                     "attribute" };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    private static boolean DEBUG = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    private static String fileDir = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    private static String templateDir = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    public static final String TRUE = "true";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    public static final String FALSE = "false";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * Method called from the javadoc environment to determint the options length.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * Doclet options:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     *      -t template location
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     *      -d outputdir
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     *      -x true Enable debug output.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    public static int optionLength(String option) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        // remind: this needs to be cleaned up
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        if (option.equals("-t"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
            return 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        if (option.equals("-d"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            return 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        if (option.equals("-x"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
            return 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    /** @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * bound:true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * constrained:false
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * expert:true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * hidden:true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * preferred:false
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * description: the description of this method can
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     *              do all sorts of funky things. if it \n
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     *              is indented like this, we have to remove
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     *              all char spaces greater than 2 and also any hard-coded \n
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     *              newline characters and all newlines
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * displayname: theString
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * propertyeditorclass: foo.bar.MyPropertyEditorClass
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * customizerclass: foo.bar.MyCustomizerClass
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * attribute:key1 value1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * attribute: key2  value2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    public static boolean start(RootDoc doc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        readOptions(doc.options());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        if (templateDir.length() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            System.err.println("-t option not specified");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        if (fileDir.length() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            System.err.println("-d option not specified");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        GenSwingBeanInfo generator = new GenSwingBeanInfo(fileDir, templateDir, DEBUG);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        Hashtable dochash = new Hashtable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        DocBeanInfo dbi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        /* "javadoc Foo.java Bar.java" will return:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        *         "Foo Foo.I1 Foo.I2 Bar Bar.I1 Bar.I2"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        * i.e., with all the innerclasses of classes specified in the command
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        * line.  We don't want to generate BeanInfo for any of these inner
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        * classes, so we ignore these by remembering what the last outer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        * class was.  A hack, I admit, but makes the build faster.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        String previousClass = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        ClassDoc[] classes = doc.classes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        for (int cnt = 0; cnt < classes.length; cnt++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            String className = classes[cnt].qualifiedName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            if (previousClass != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                className.startsWith(previousClass) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                className.charAt(previousClass.length()) == '.') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            previousClass = className;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            // XXX - debug
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            System.out.println("\n>>> Generating beaninfo for " + className + "...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            // Examine the javadoc tags and look for the the @beaninfo tag
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            // This first block looks at the javadoc for the class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            Tag[] tags = classes[cnt].tags();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            for (int i = 0; i < tags.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                if (tags[i].kind().equalsIgnoreCase("@beaninfo")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                    if (DEBUG)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                       System.out.println("GenDocletBeanInfo: found @beaninfo tagged Class: " + tags[i].text());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                    dbi = genDocletInfo(tags[i].text(), classes[cnt].name());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                    dochash.put(dbi.name, dbi);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            // This block looks at the javadoc for the class methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            int startPos = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            MethodDoc[] methods = classes[cnt].methods();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            for (int j = 0; j < methods.length; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                // actually don't "introspect" - look for all
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                // methods with a @beaninfo tag
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                tags = methods[j].tags();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                for (int x = 0; x < tags.length; x++){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                    if (tags[x].kind().equalsIgnoreCase("@beaninfo")){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                        if ((methods[j].name().startsWith("get")) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                            (methods[j].name().startsWith("set")))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                            startPos = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                        else if (methods[j].name().startsWith("is"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                            startPos = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                            startPos = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                        String propDesc =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                            Introspector.decapitalize((methods[j].name()).substring(startPos));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                        if (DEBUG)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                            System.out.println("GenDocletBeanInfo: found @beaninfo tagged Method: " + tags[x].text());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                        dbi = genDocletInfo(tags[x].text(), propDesc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                        dochash.put(dbi.name, dbi);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            if (DEBUG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                // dump our classes doc beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                System.out.println(">>>>DocletBeanInfo for class: " + classes[cnt].name());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                Enumeration e = dochash.elements();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                while (e.hasMoreElements()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                    DocBeanInfo db = (DocBeanInfo)e.nextElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                    System.out.println(db.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            // Use the generator to create the beaninfo code for the class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            generator.genBeanInfo(classes[cnt].containingPackage().name(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                                        classes[cnt].name(), dochash);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            // reset the values!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            dochash.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        } // end for loop
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * Reads the command line options.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * Side Effect, sets class variables templateDir, fileDir and DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    private static void readOptions(String[][] options)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        // Parse the command line args
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        for (int i = 0; i < options.length; i++){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            if (options[i][0].equals("-t")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                templateDir = options[i][1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            } else if (options[i][0].equals("-d")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                fileDir = options[i][1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            } else if (options[i][0].equals("-x")){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                if (options[i][1].equals("true"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                    DEBUG=true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                    DEBUG=false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * Create a "BeanInfo" data structure from the tag. This is a data structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * which contains all beaninfo data for a method or a class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * @param text All the text after the @beaninfo tag.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * @param name Name of the property i.e., mnemonic for setMnemonic
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    private static DocBeanInfo genDocletInfo(String text, String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        int beanflags = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        String desc = "null";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        String displayname = "null";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        String propertyeditorclass = "null";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        String customizerclass = "null";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        String value = "null";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        HashMap attribs = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        HashMap enums = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        int index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        for (int j = 0; j < ATTRIBUTE_NAMES.length; j++){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            index = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
            if ((index = text.indexOf(ATTRIBUTE_NAMES[j])) != -1){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                value = getValue((text).substring(index),ATTRIBUTE_NAMES[j]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                if (ATTRIBUTE_NAMES[j].equalsIgnoreCase("attribute")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                    attribs = getAttributeMap(value, " ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                if (ATTRIBUTE_NAMES[j].equalsIgnoreCase("enum")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                    enums = getAttributeMap(value, " \n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                else if (ATTRIBUTE_NAMES[j].equals("displayname")){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                    displayname = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                else if (ATTRIBUTE_NAMES[j].equalsIgnoreCase("propertyeditorclass")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                    propertyeditorclass = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                else if (ATTRIBUTE_NAMES[j].equalsIgnoreCase("customizerclass")){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                    customizerclass = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                else if ((ATTRIBUTE_NAMES[j].equalsIgnoreCase("bound"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                         && (value.equalsIgnoreCase(TRUE)))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                    beanflags = beanflags | DocBeanInfo.BOUND;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                else if ((ATTRIBUTE_NAMES[j].equalsIgnoreCase("expert"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                         && (value.equalsIgnoreCase(TRUE)))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                    beanflags = beanflags | DocBeanInfo.EXPERT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                else if ((ATTRIBUTE_NAMES[j].equalsIgnoreCase("constrained"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                         && (value.equalsIgnoreCase(TRUE)))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                    beanflags = beanflags | DocBeanInfo.CONSTRAINED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
                else if ((ATTRIBUTE_NAMES[j].equalsIgnoreCase("hidden"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
                         && (value.equalsIgnoreCase(TRUE)))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
                    beanflags = beanflags | DocBeanInfo.HIDDEN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                else if ((ATTRIBUTE_NAMES[j].equalsIgnoreCase("preferred"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                         && (value.equalsIgnoreCase(TRUE)))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
                    beanflags = beanflags | DocBeanInfo.PREFERRED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
                else if (ATTRIBUTE_NAMES[j].equalsIgnoreCase("description")){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                    desc = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        /** here we create our doclet-beaninfo data structure, which we read in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
         *  later if it has anything worthwhile
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        // Construct a new Descriptor class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        return new DocBeanInfo(name, beanflags, desc,displayname,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                                         propertyeditorclass, customizerclass,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                                         attribs, enums);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * Parses the substring and returns the cleaned up value for the attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * @param substring Full String of the attrib tag.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     *       i.e., "attribute: visualUpdate true" will return "visualUpdate true";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    private static String getValue(String substring, String prop) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        StringTokenizer t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        String value = "null";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
            /** if the ATTRIBUTE_NAMES is NOT the description, then we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
             *  parse until newline
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
             *  if it is the description we read until the next token
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
             *  and then look for a match in the last MAXMATCH index
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
             *  and truncate the description
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
             *  if it is the attribute we wead until no more
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
            if (prop.equalsIgnoreCase("attribute")){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
                StringBuffer tmp = new StringBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
                    t = new StringTokenizer(substring, " :\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
                    t.nextToken().trim();//the prop
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
                    // we want to return : key1 value1 key2 value2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
                    while (t.hasMoreTokens()){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
                        tmp.append(t.nextToken().trim()).append(" ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
                        tmp.append(t.nextToken().trim()).append(" ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
                        String test = t.nextToken().trim();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
                        if (!(test.equalsIgnoreCase("attribute")))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
                            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
                } catch (Exception e){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
                value = tmp.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
            else if (prop.equalsIgnoreCase("enum")){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                t = new StringTokenizer(substring, ":");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                t.nextToken().trim(); // the prop we already know
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
                StringBuffer tmp = new StringBuffer(t.nextToken().trim());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
                for (int i = 0; i < ATTRIBUTE_NAMES.length; i++){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
                    if (tmp.toString().endsWith(ATTRIBUTE_NAMES[i])){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
                        int len = ATTRIBUTE_NAMES[i].length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
                        // trim off that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
                        tmp.setLength(tmp.length() - len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
                value = tmp.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
            else if (prop.equalsIgnoreCase("description")){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
                t = new StringTokenizer(substring, ":");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
                t.nextToken().trim(); // the prop we already know
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
                StringBuffer tmp = new StringBuffer(t.nextToken().trim());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
                for (int i = 0; i < ATTRIBUTE_NAMES.length; i++){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
                    if (tmp.toString().endsWith(ATTRIBUTE_NAMES[i])){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                        int len = ATTRIBUTE_NAMES[i].length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
                        // trim off that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
                        tmp.setLength(tmp.length() - len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
                value = hansalizeIt(tmp.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
                // Single value properties like bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                t = new StringTokenizer(substring, ":\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
                t.nextToken().trim(); // the prop we already know
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                value = t.nextToken().trim();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
            // now we need to look for a match of any of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
            // property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
            return value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        catch (Exception e){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
            return "invalidValue";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     * Creates a HashMap containing the key value pair for the parsed values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     * of the "attributes" and "enum" tags.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     * ie. For attribute value: visualUpdate true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     *     The HashMap will have key: visualUpdate, value: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
    private static HashMap getAttributeMap(String str, String delim)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        StringTokenizer t = new StringTokenizer(str, delim);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        HashMap map = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        String key;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        String value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        int num = t.countTokens()/2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        if (num > 0)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
            map = new HashMap();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
            for (int i = 0; i < num; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
                key = t.nextToken().trim();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
                value = t.nextToken().trim();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
                map.put(key, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        return map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
    // looks for extra spaces, \n hard-coded and invisible,etc
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
    private static String hansalizeIt(String from){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        char [] chars = from.toCharArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        int len = chars.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        int toss = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        // remove double spaces
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        for (int i = 0; i < len; i++){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
            if ((chars[i] == ' ')) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
                if (i+1 < len) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
                    if ((chars[i+1] == ' ' ) || (chars[i+1] == '\n'))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
                        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
                            --len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
                            System.arraycopy(chars,i+1,chars,i,len-i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
                            --i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
            if (chars[i] == '\n'){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
                chars[i] = ' ';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
                i -= 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
            if (chars[i] == '\\') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
                if (i+1 < len) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
                    if (chars[i+1] == 'n'){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
                        chars[i+1] = ' ';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
                        --len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
                        System.arraycopy(chars,i+1, chars,i, len-i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
                        --i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        return new String(chars,0,len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
}