< prev index next >

src/jdk.jcmd/share/classes/sun/tools/jstat/Parser.java

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.  Oracle designates this

@@ -58,17 +58,19 @@
     private static final String HEADER = "header";
     private static final String WIDTH = "width";
     private static final String FORMAT = "format";
     private static final String ALIGN = "align";
     private static final String SCALE = "scale";
+    private static final String REQUIRED = "required";
 
     private static final String START = OPTION;
 
     private static final Set<String> scaleKeyWords = Scale.keySet();
     private static final Set<String> alignKeyWords = Alignment.keySet();
+    private static final Set<String> boolKeyWords = Set.of("true", "false");
     private static String[] otherKeyWords = {
-        OPTION, COLUMN, DATA, HEADER, WIDTH, FORMAT, ALIGN, SCALE
+        OPTION, COLUMN, DATA, HEADER, WIDTH, FORMAT, ALIGN, SCALE, REQUIRED
     };
 
     private static char[] infixOps = {
         OPERATOR_PLUS, OPERATOR_MINUS, OPERATOR_MULTIPLY, OPERATOR_DIVIDE
     };

@@ -443,17 +445,28 @@
         cf.setExpression(e);
         log(pdebug, "Parsed: data -> " + e);
     }
 
     /**
+     * requiredstmt -> 'required' expression
+     */
+    private void requiredStmt(ColumnFormat cf) throws ParserException, IOException {
+        match(REQUIRED);
+        Token t = matchOne(boolKeyWords);
+        cf.setRequired(Boolean.parseBoolean(t.sval));
+        log(pdebug, "Parsed: required -> " + cf.isRequired());
+    }
+
+    /**
      * statementlist -> optionalstmt statementlist
      * optionalstmt -> 'data' expression
      *                 'header' quotedstring
      *                 'width' integer
      *                 'format' formatstring
      *                 'align' alignspec
      *                 'scale' scalespec
+     *                 'required' boolean
      */
     private void statementList(ColumnFormat cf)
                  throws ParserException, IOException {
         while (true) {
             if (lookahead.ttype != StreamTokenizer.TT_WORD) {

@@ -470,10 +483,12 @@
                 formatStmt(cf);
             } else if (lookahead.sval.compareTo(ALIGN) == 0) {
                 alignStmt(cf);
             } else if (lookahead.sval.compareTo(SCALE) == 0) {
                 scaleStmt(cf);
+            } else if (lookahead.sval.compareTo(REQUIRED) == 0) {
+                requiredStmt(cf);
             } else {
                 return;
             }
         }
     }
< prev index next >