001    package javafe;
002    
003    import javafe.util.UsageError;
004    
005    /**
006     * This class holds the command-line options specific to the SrcTool class.
007     */
008     
009    public class SrcToolOptions extends Options
010    {
011      /**
012       * Do we allow the <code>-avoidSpec</code> option?  Defaults to
013       * yes.
014       */
015      public static boolean allowAvoidSpec = true;
016    
017      /**
018       * Do we allow the -depend option?  Defaults to yes.
019       */
020      public static boolean allowDepend = true;
021    
022      /**
023       * Should we avoid specs for all types loaded after the initial
024       * set of source files?
025       *
026       * <p> Defaults to false.  Set by using the <tt>-avoidSpec</tt>
027       * option.
028       *
029       * <p> Note: if <code>processRecursively</code> is set, then we
030       * always avoid specs.
031       */
032      public boolean avoidSpec = false;
033    
034      /**
035       * Should we process files recursively?  Defaults to no, can be set
036       * by a sub-class, or the <tt>-depend</tt> option.
037       *
038       * <p> Warning: this needs to be set before option processing is
039       * finished!
040       */
041      public boolean processRecursively = false;
042    
043      /**
044       * The list of filenames on the command line; this {@link java.util.Vector} is
045       * aliased with a variable in {@link SrcTool}.
046       */
047        
048      // @overrides Options.processOption(String, String[], int)
049    
050      public int processOption(String option, String[] args, int offset) 
051        throws UsageError {
052        if (option.equals("-depend") && allowDepend) {
053          processRecursively = true;
054          return offset;
055        } else if (option.equals("-avoidSpec") && allowAvoidSpec) {
056          avoidSpec = true;
057          return offset;
058        } else
059          // Pass on unrecognized options:
060          return super.processOption(option, args, offset);
061      }
062            
063      /**
064       * Print non-option usage info to <code>System.err</code>.  Output
065       * must include at least one newline.
066       */
067      public String showNonOptions() {
068        return ("<source files>");
069      }
070    
071      /**
072       * Print option information to <code>System.err</code>.  Each
073       * printed line should be preceeded by two blank spaces.
074       *
075       * <p> Each overriding method should first call
076       * <code>super.showOptions()</code>.
077       */
078      public String showOptions(boolean all) {
079        String[][] data1 = {{"-AvoidSpec",
080                             "Avoid specification files if possible and read type and spec information\n" +
081                             "\tfrom source and class files instead"}};
082        String[][] data2 = {{"-Depend",
083                             "Recursively process all specification, source, and binary files on which\n" +
084                             "\tthe input files depend"}};
085    
086        StringBuffer sb = new StringBuffer(super.showOptions(all));
087            
088        if (allowAvoidSpec) sb.append(showOptionArray(data1));
089            
090        if (allowDepend) sb.append(showOptionArray(data2));
091                    
092        return sb.toString();
093      }
094    
095    }