| 1 | /* |
|---|
| 2 | * This program is free software; you can redistribute it and/or modify |
|---|
| 3 | * it under the terms of the GNU General Public License as published by |
|---|
| 4 | * the Free Software Foundation; either version 2 of the License, or |
|---|
| 5 | * (at your option) any later version. |
|---|
| 6 | * |
|---|
| 7 | * This program is distributed in the hope that it will be useful, |
|---|
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 10 | * GNU General Public License for more details. |
|---|
| 11 | * |
|---|
| 12 | * You should have received a copy of the GNU General Public License |
|---|
| 13 | * along with this program; if not, write to the Free Software |
|---|
| 14 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
|---|
| 15 | */ |
|---|
| 16 | |
|---|
| 17 | /* |
|---|
| 18 | * GlobalInfoJavadoc.java |
|---|
| 19 | * Copyright (C) 2006 University of Waikato, Hamilton, New Zealand |
|---|
| 20 | */ |
|---|
| 21 | |
|---|
| 22 | package weka.core; |
|---|
| 23 | |
|---|
| 24 | import java.lang.reflect.Method; |
|---|
| 25 | |
|---|
| 26 | /** |
|---|
| 27 | * Generates Javadoc comments from the class's globalInfo method. Can |
|---|
| 28 | * automatically update the comments if they're surrounded by |
|---|
| 29 | * the GLOBALINFO_STARTTAG and GLOBALINFO_ENDTAG (the indention is determined via |
|---|
| 30 | * the GLOBALINFO_STARTTAG). <p/> |
|---|
| 31 | * |
|---|
| 32 | <!-- options-start --> |
|---|
| 33 | * Valid options are: <p/> |
|---|
| 34 | * |
|---|
| 35 | * <pre> -W <classname> |
|---|
| 36 | * The class to load.</pre> |
|---|
| 37 | * |
|---|
| 38 | * <pre> -nostars |
|---|
| 39 | * Suppresses the '*' in the Javadoc.</pre> |
|---|
| 40 | * |
|---|
| 41 | * <pre> -dir <dir> |
|---|
| 42 | * The directory above the package hierarchy of the class.</pre> |
|---|
| 43 | * |
|---|
| 44 | * <pre> -silent |
|---|
| 45 | * Suppresses printing in the console.</pre> |
|---|
| 46 | * |
|---|
| 47 | <!-- options-end --> |
|---|
| 48 | * |
|---|
| 49 | * @author fracpete (fracpete at waikato dot ac dot nz) |
|---|
| 50 | * @version $Revision: 5953 $ |
|---|
| 51 | * @see #GLOBALINFO_METHOD |
|---|
| 52 | * @see #GLOBALINFO_STARTTAG |
|---|
| 53 | * @see #GLOBALINFO_ENDTAG |
|---|
| 54 | */ |
|---|
| 55 | public class GlobalInfoJavadoc |
|---|
| 56 | extends Javadoc { |
|---|
| 57 | |
|---|
| 58 | /** the globalInfo method name */ |
|---|
| 59 | public final static String GLOBALINFO_METHOD = "globalInfo"; |
|---|
| 60 | |
|---|
| 61 | /** the start comment tag for inserting the generated Javadoc */ |
|---|
| 62 | public final static String GLOBALINFO_STARTTAG = "<!-- globalinfo-start -->"; |
|---|
| 63 | |
|---|
| 64 | /** the end comment tag for inserting the generated Javadoc */ |
|---|
| 65 | public final static String GLOBALINFO_ENDTAG = "<!-- globalinfo-end -->"; |
|---|
| 66 | |
|---|
| 67 | /** |
|---|
| 68 | * default constructor |
|---|
| 69 | */ |
|---|
| 70 | public GlobalInfoJavadoc() { |
|---|
| 71 | super(); |
|---|
| 72 | |
|---|
| 73 | m_StartTag = new String[1]; |
|---|
| 74 | m_EndTag = new String[1]; |
|---|
| 75 | m_StartTag[0] = GLOBALINFO_STARTTAG; |
|---|
| 76 | m_EndTag[0] = GLOBALINFO_ENDTAG; |
|---|
| 77 | } |
|---|
| 78 | |
|---|
| 79 | /** |
|---|
| 80 | * generates and returns the Javadoc for the specified start/end tag pair. |
|---|
| 81 | * |
|---|
| 82 | * @param index the index in the start/end tag array |
|---|
| 83 | * @return the generated Javadoc |
|---|
| 84 | * @throws Exception in case the generation fails |
|---|
| 85 | */ |
|---|
| 86 | protected String generateJavadoc(int index) throws Exception { |
|---|
| 87 | String result; |
|---|
| 88 | Method method; |
|---|
| 89 | |
|---|
| 90 | result = ""; |
|---|
| 91 | |
|---|
| 92 | if (index == 0) { |
|---|
| 93 | if (!canInstantiateClass()) |
|---|
| 94 | return result; |
|---|
| 95 | |
|---|
| 96 | try { |
|---|
| 97 | method = getInstance().getClass().getMethod(GLOBALINFO_METHOD, (Class[]) null); |
|---|
| 98 | } |
|---|
| 99 | catch (Exception e) { |
|---|
| 100 | // no method "globalInfo" |
|---|
| 101 | return result; |
|---|
| 102 | } |
|---|
| 103 | |
|---|
| 104 | // retrieve global info |
|---|
| 105 | result = toHTML((String) method.invoke(getInstance(), (Object[]) null)); |
|---|
| 106 | result = result.trim() + "\n<p/>\n"; |
|---|
| 107 | |
|---|
| 108 | // stars? |
|---|
| 109 | if (getUseStars()) |
|---|
| 110 | result = indent(result, 1, "* "); |
|---|
| 111 | } |
|---|
| 112 | |
|---|
| 113 | return result; |
|---|
| 114 | } |
|---|
| 115 | |
|---|
| 116 | /** |
|---|
| 117 | * Returns the revision string. |
|---|
| 118 | * |
|---|
| 119 | * @return the revision |
|---|
| 120 | */ |
|---|
| 121 | public String getRevision() { |
|---|
| 122 | return RevisionUtils.extract("$Revision: 5953 $"); |
|---|
| 123 | } |
|---|
| 124 | |
|---|
| 125 | /** |
|---|
| 126 | * Parses the given commandline parameters and generates the Javadoc. |
|---|
| 127 | * |
|---|
| 128 | * @param args the commandline parameters for the object |
|---|
| 129 | */ |
|---|
| 130 | public static void main(String[] args) { |
|---|
| 131 | runJavadoc(new GlobalInfoJavadoc(), args); |
|---|
| 132 | } |
|---|
| 133 | } |
|---|