Coverage Report - com.sun.tools.javafx.main.JavafxOption
 
Classes in this File Line Coverage Branch Coverage Complexity
JavafxOption
N/A
N/A
0
JavafxOption$FXOption
25%
2/8
0%
0/6
0
JavafxOption$HiddenOption
29%
2/7
N/A
0
JavafxOption$Option
63%
17/27
55%
11/20
0
JavafxOption$OptionKind
0%
0/4
N/A
0
JavafxOption$XOption
57%
4/7
N/A
0
 
 1  
 /*
 2  
  * Copyright 1999-2007 Sun Microsystems, Inc.  All Rights Reserved.
 3  
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 4  
  *
 5  
  * This code is free software; you can redistribute it and/or modify it
 6  
  * under the terms of the GNU General Public License version 2 only, as
 7  
  * published by the Free Software Foundation.  Sun designates this
 8  
  * particular file as subject to the "Classpath" exception as provided
 9  
  * by Sun in the LICENSE file that accompanied this code.
 10  
  *
 11  
  * This code is distributed in the hope that it will be useful, but WITHOUT
 12  
  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 13  
  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 14  
  * version 2 for more details (a copy is included in the LICENSE file that
 15  
  * accompanied this code).
 16  
  *
 17  
  * You should have received a copy of the GNU General Public License version
 18  
  * 2 along with this work; if not, write to the Free Software Foundation,
 19  
  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 20  
  *
 21  
  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
 22  
  * CA 95054 USA or visit www.sun.com if you need additional information or
 23  
  * have any questions.
 24  
  */
 25  
 
 26  
 package com.sun.tools.javafx.main;
 27  
 
 28  
 import com.sun.tools.javac.util.Log;
 29  
 import com.sun.tools.javac.util.Options;
 30  
 import java.io.PrintWriter;
 31  
 
 32  
 /**
 33  
  * TODO: describe com.sun.tools.javac.main.JavacOption
 34  
  *
 35  
  * <p><b>This is NOT part of any API supported by Sun Microsystems.
 36  
  * If you write code that depends on this, you do so at your own
 37  
  * risk.  This code and its internal interfaces are subject to change
 38  
  * or deletion without notice.</b></p>
 39  
  */
 40  
 public interface JavafxOption {
 41  
 
 42  
     OptionKind getKind();
 43  
 
 44  
     /** Does this option take a (separate) operand? */
 45  
     boolean hasArg();
 46  
 
 47  
     /** Does argument string match option pattern?
 48  
      *  @param arg        The command line argument string.
 49  
      */
 50  
     boolean matches(String arg);
 51  
 
 52  
     /** Process the option (with arg). Return true if error detected.
 53  
      */
 54  
     boolean process(Options options, String option, String arg);
 55  
 
 56  
     /** Process the option (without arg). Return true if error detected.
 57  
      */
 58  
     boolean process(Options options, String option);
 59  
     
 60  
     OptionName getName();
 61  
 
 62  0
     enum OptionKind {
 63  0
         NORMAL,
 64  0
         EXTENDED,
 65  0
         HIDDEN,
 66  
     }
 67  
     
 68  
     /** This class represents an option recognized by the main program
 69  
      */
 70  
     static class Option implements JavafxOption {
 71  
 
 72  
         /** Option string.
 73  
          */
 74  
         OptionName name;
 75  
 
 76  
         /** Documentation key for arguments.
 77  
          */
 78  
         String argsNameKey;
 79  
 
 80  
         /** Documentation key for description.
 81  
          */
 82  
         String descrKey;
 83  
 
 84  
         /** Suffix option (-foo=bar or -foo:bar)
 85  
          */
 86  
         boolean hasSuffix;
 87  
 
 88  26568
         Option(OptionName name, String argsNameKey, String descrKey) {
 89  26568
             this.name = name;
 90  26568
             this.argsNameKey = argsNameKey;
 91  26568
             this.descrKey = descrKey;
 92  26568
             char lastChar = name.optionName.charAt(name.optionName.length()-1);
 93  26568
             hasSuffix = lastChar == ':' || lastChar == '=';
 94  26568
         }
 95  
         Option(OptionName name, String descrKey) {
 96  4920
             this(name, null, descrKey);
 97  4920
         }
 98  
 
 99  
     @Override
 100  
         public String toString() {
 101  0
             return name.optionName;
 102  
         }
 103  
 
 104  
         /** Does this option take a (separate) operand?
 105  
          */
 106  
         public boolean hasArg() {
 107  1737
             return argsNameKey != null && !hasSuffix;
 108  
         }
 109  
 
 110  
         /** Does argument string match option pattern?
 111  
          *  @param arg        The command line argument string.
 112  
          */
 113  
     public boolean matches(String arg) {
 114  22568
             return hasSuffix ? arg.startsWith(name.optionName) : arg.equals(name.optionName);
 115  
         }
 116  
 
 117  
         /** Print a line of documentation describing this option, if standard.
 118  
          */
 119  
         void help(PrintWriter out) {
 120  0
             String s = "  " + helpSynopsis();
 121  0
             out.print(s);
 122  0
             for (int j = s.length(); j < 29; j++) out.print(" ");
 123  0
             Log.printLines(out, Main.getLocalizedString(descrKey));
 124  0
         }
 125  
         String helpSynopsis() {
 126  0
             return name +
 127  
                 (argsNameKey == null ? "" :
 128  
                  ((hasSuffix ? "" : " ") +
 129  
                   Main.getLocalizedString(argsNameKey)));
 130  
         }
 131  
 
 132  
         /** Print a line of documentation describing this option, if non-standard.
 133  
          */
 134  0
         void xhelp(PrintWriter out) {}
 135  
 
 136  
         /** Process the option (with arg). Return true if error detected.
 137  
          */
 138  
         public boolean process(Options options, String option, String arg) {
 139  1196
         if (options != null)
 140  1196
                 options.put(option, arg);
 141  1196
             return false;
 142  
         }
 143  
 
 144  
         /** Process the option (without arg). Return true if error detected.
 145  
          */
 146  
         public boolean process(Options options, String option) {
 147  58
             if (hasSuffix)
 148  0
                 return process(options, name.optionName, option.substring(name.optionName.length()));
 149  
             else
 150  58
                 return process(options, option, option);
 151  
         }
 152  
         
 153  0
         public OptionKind getKind() { return OptionKind.NORMAL; }
 154  
         
 155  26568
         public OptionName getName() { return name; }
 156  
     };
 157  
 
 158  
     /** A nonstandard or extended (-X) option
 159  
      */
 160  
     static class XOption extends Option {
 161  
         XOption(OptionName name, String argsNameKey, String descrKey) {
 162  6888
             super(name, argsNameKey, descrKey);
 163  6888
         }
 164  
         XOption(OptionName name, String descrKey) {
 165  2952
             this(name, null, descrKey);
 166  2952
         }
 167  
         @Override
 168  0
         void help(PrintWriter out) {}
 169  
         @Override
 170  0
         void xhelp(PrintWriter out) { super.help(out); }
 171  
         @Override
 172  0
             public OptionKind getKind() { return OptionKind.EXTENDED; }
 173  
     };
 174  
 
 175  
     /** A hidden (implementor) option
 176  
      */
 177  
     static class HiddenOption extends Option {
 178  
         HiddenOption(OptionName name) {
 179  7380
             super(name, null, null);
 180  7380
         }
 181  
         HiddenOption(OptionName name, String argsNameKey) {
 182  0
             super(name, argsNameKey, null);
 183  0
         }
 184  
         @Override
 185  0
         void help(PrintWriter out) {}
 186  
         @Override
 187  0
         void xhelp(PrintWriter out) {}
 188  
         @Override
 189  0
         public OptionKind getKind() { return OptionKind.HIDDEN; }
 190  
     };
 191  
 
 192  
     /** A javafxc-specific option
 193  
      */
 194  
     static class FXOption extends Option {
 195  
          FXOption(OptionName name, String argsNameKey, String descrKey) {
 196  492
             super(name, argsNameKey, descrKey);
 197  492
         }
 198  
         
 199  
         @Override
 200  
         void help(PrintWriter out) {
 201  0
             String s = "  " + helpSynopsis();
 202  0
             out.print(s);
 203  0
             for (int j = s.length(); j < 29; j++) out.print(" ");
 204  0
             Log.printLines(out, Main.getJavafxLocalizedString(descrKey));
 205  0
         }
 206  
         
 207  
         @Override
 208  
         String helpSynopsis() {
 209  0
             return name +
 210  
                 (argsNameKey == null ? "" :
 211  
                  ((hasSuffix ? "" : " ") +
 212  
                   Main.getJavafxLocalizedString(argsNameKey)));
 213  
         }       
 214  
     }
 215  
 }