8081604: rename ScriptingFunctions.tokenizeCommandLine

Tue, 02 Jun 2015 10:40:19 +0200

author
mhaupt
date
Tue, 02 Jun 2015 10:40:19 +0200
changeset 1388
d03088193a17
parent 1387
4632d53923d4
child 1389
24cb54d0bfa2

8081604: rename ScriptingFunctions.tokenizeCommandLine
Summary: This used to be a single-purpose private helper; it is now used by external clients, and for new purposes. Consequently, it deserves a less specific name.
Reviewed-by: attila, lagergren, sundar

src/jdk/nashorn/internal/runtime/ScriptingFunctions.java file | annotate | diff | comparison | revisions
test/src/jdk/nashorn/internal/test/framework/TestFinder.java file | annotate | diff | comparison | revisions
     1.1 --- a/src/jdk/nashorn/internal/runtime/ScriptingFunctions.java	Tue Jun 02 10:40:10 2015 +0200
     1.2 +++ b/src/jdk/nashorn/internal/runtime/ScriptingFunctions.java	Tue Jun 02 10:40:19 2015 +0200
     1.3 @@ -137,7 +137,7 @@
     1.4          final ScriptObject global = Context.getGlobal();
     1.5  
     1.6          // Set up initial process.
     1.7 -        final ProcessBuilder processBuilder = new ProcessBuilder(tokenizeCommandLine(JSType.toString(string)));
     1.8 +        final ProcessBuilder processBuilder = new ProcessBuilder(tokenizeString(JSType.toString(string)));
     1.9  
    1.10          // Current ENV property state.
    1.11          final Object env = global.get(ENV_NAME);
    1.12 @@ -237,23 +237,22 @@
    1.13      }
    1.14  
    1.15      /**
    1.16 -     * Break an exec string into tokens, honoring quoted arguments and escaped
    1.17 -     * spaces.
    1.18 +     * Break a string into tokens, honoring quoted arguments and escaped spaces.
    1.19       *
    1.20 -     * @param execString a {@link String} with the command line to execute.
    1.21 +     * @param str a {@link String} to tokenize.
    1.22       * @return a {@link List} of {@link String}s representing the tokens that
    1.23 -     * constitute the command line.
    1.24 +     * constitute the string.
    1.25       * @throws IOException in case {@link StreamTokenizer#nextToken()} raises it.
    1.26       */
    1.27 -    public static List<String> tokenizeCommandLine(final String execString) throws IOException {
    1.28 -        final StreamTokenizer tokenizer = new StreamTokenizer(new StringReader(execString));
    1.29 +    public static List<String> tokenizeString(final String str) throws IOException {
    1.30 +        final StreamTokenizer tokenizer = new StreamTokenizer(new StringReader(str));
    1.31          tokenizer.resetSyntax();
    1.32          tokenizer.wordChars(0, 255);
    1.33          tokenizer.whitespaceChars(0, ' ');
    1.34          tokenizer.commentChar('#');
    1.35          tokenizer.quoteChar('"');
    1.36          tokenizer.quoteChar('\'');
    1.37 -        final List<String> cmdList = new ArrayList<>();
    1.38 +        final List<String> tokenList = new ArrayList<>();
    1.39          final StringBuilder toAppend = new StringBuilder();
    1.40          while (tokenizer.nextToken() != StreamTokenizer.TT_EOF) {
    1.41              final String s = tokenizer.sval;
    1.42 @@ -265,13 +264,13 @@
    1.43                  // omit trailing \, append space instead
    1.44                  toAppend.append(s.substring(0, s.length() - 1)).append(' ');
    1.45              } else {
    1.46 -                cmdList.add(toAppend.append(s).toString());
    1.47 +                tokenList.add(toAppend.append(s).toString());
    1.48                  toAppend.setLength(0);
    1.49              }
    1.50          }
    1.51          if (toAppend.length() != 0) {
    1.52 -            cmdList.add(toAppend.toString());
    1.53 +            tokenList.add(toAppend.toString());
    1.54          }
    1.55 -        return cmdList;
    1.56 +        return tokenList;
    1.57      }
    1.58  }
     2.1 --- a/test/src/jdk/nashorn/internal/test/framework/TestFinder.java	Tue Jun 02 10:40:10 2015 +0200
     2.2 +++ b/test/src/jdk/nashorn/internal/test/framework/TestFinder.java	Tue Jun 02 10:40:19 2015 +0200
     2.3 @@ -225,7 +225,7 @@
     2.4          boolean explicitOptimistic = false;
     2.5  
     2.6          String allContent = new String(Files.readAllBytes(testFile));
     2.7 -        Iterator<String> scanner = ScriptingFunctions.tokenizeCommandLine(allContent).iterator();
     2.8 +        Iterator<String> scanner = ScriptingFunctions.tokenizeString(allContent).iterator();
     2.9          while (scanner.hasNext()) {
    2.10              // TODO: Scan for /ref=file qualifiers, etc, to determine run
    2.11              // behavior

mercurial