# HG changeset patch # User Doug Simon # Date 1376942467 -7200 # Node ID 5a7644d5fe207e5b65da7de4b75cf264c0363957 # Parent 70e8575d526437cc96622e2698f996356dd9ea28 added capability for embedding new lines in lengthy option help messages diff -r 70e8575d5264 -r 5a7644d5fe20 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotOptions.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotOptions.java Mon Aug 19 21:58:03 2013 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotOptions.java Mon Aug 19 22:01:07 2013 +0200 @@ -173,6 +173,48 @@ return true; } + /** + * Wraps some given text to one or more lines of a given maximum width. + * + * @param text text to wrap + * @param width maximum width of an output line, exception for words in {@code text} longer than + * this value + * @return {@code text} broken into lines + */ + private static List wrap(String text, int width) { + List lines = Collections.singletonList(text); + if (text.length() > width) { + String[] chunks = text.split("\\s+"); + lines = new ArrayList<>(); + StringBuilder line = new StringBuilder(); + for (String chunk : chunks) { + if (line.length() + chunk.length() > width) { + lines.add(line.toString()); + line.setLength(0); + } + if (line.length() != 0) { + line.append(' '); + } + String[] embeddedLines = chunk.split("%n"); + if (embeddedLines.length == 1) { + line.append(chunk); + } else { + for (int i = 0; i < embeddedLines.length; i++) { + line.append(embeddedLines[i]); + if (i < embeddedLines.length - 1) { + lines.add(line.toString()); + line.setLength(0); + } + } + } + } + if (line.length() != 0) { + lines.add(line.toString()); + } + } + return lines; + } + private static void printFlags() { Logger.info("[Graal flags]"); SortedMap sortedOptions = new TreeMap<>(options); @@ -180,7 +222,11 @@ e.getKey(); OptionDescriptor desc = e.getValue(); Object value = desc.getOptionValue().getValue(); - Logger.info(String.format("%9s %-40s = %-14s %s", desc.getType().getSimpleName(), e.getKey(), value, desc.getHelp())); + List helpLines = wrap(desc.getHelp(), 70); + Logger.info(String.format("%9s %-40s = %-14s %s", desc.getType().getSimpleName(), e.getKey(), value, helpLines.get(0))); + for (int i = 1; i < helpLines.size(); i++) { + Logger.info(String.format("%67s %s", " ", helpLines.get(i))); + } } System.exit(0); diff -r 70e8575d5264 -r 5a7644d5fe20 graal/com.oracle.graal.options/src/com/oracle/graal/options/Option.java --- a/graal/com.oracle.graal.options/src/com/oracle/graal/options/Option.java Mon Aug 19 21:58:03 2013 +0200 +++ b/graal/com.oracle.graal.options/src/com/oracle/graal/options/Option.java Mon Aug 19 22:01:07 2013 +0200 @@ -36,7 +36,8 @@ public @interface Option { /** - * Gets a help message for the option. + * Gets a help message for the option. New lines can be embedded in the message with + * {@code "%n"}. */ String help();