Skip to content

Commit 3990e64

Browse files
authored
8348033: Tidy Nashorn code (#23)
1 parent ddbe28f commit 3990e64

File tree

96 files changed

+145
-354
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+145
-354
lines changed

src/org.openjdk.nashorn.shell/share/classes/org/openjdk/nashorn/tools/jjs/Console.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public void close() {
123123

124124
private void saveHistory() {
125125
try (Writer out = Files.newBufferedWriter(historyFile.toPath())) {
126-
String lineSeparator = System.getProperty("line.separator");
126+
String lineSeparator = System.lineSeparator();
127127

128128
out.write(StreamSupport.stream(getHistory().spliterator(), false)
129129
.map(e -> e.line())

src/org.openjdk.nashorn.shell/share/classes/org/openjdk/nashorn/tools/jjs/EditObject.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,7 @@
4242
final class EditObject extends AbstractJSObject {
4343
private static final Set<String> props;
4444
static {
45-
final HashSet<String> s = new HashSet<>();
46-
s.add("editor");
47-
props = Collections.unmodifiableSet(s);
45+
props = Set.of("editor");
4846
}
4947

5048
private final Console console;

src/org.openjdk.nashorn.shell/share/classes/org/openjdk/nashorn/tools/jjs/ExternalEditor.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
package org.openjdk.nashorn.tools.jjs;
2727

2828
import java.io.IOException;
29-
import java.nio.charset.Charset;
3029
import java.nio.file.ClosedWatchServiceException;
3130
import java.nio.file.FileSystems;
3231
import java.nio.file.Files;
@@ -46,7 +45,6 @@ final class ExternalEditor {
4645

4746
private WatchService watcher;
4847
private Thread watchedThread;
49-
private Path dir;
5048
private Path tmpfile;
5149

5250
ExternalEditor(final Consumer<String> errorHandler, final Consumer<String> saveHandler, final Console input) {
@@ -69,9 +67,9 @@ private void edit(final String cmd, final String initialText) {
6967
*/
7068
private void setupWatch(final String initialText) throws IOException {
7169
this.watcher = FileSystems.getDefault().newWatchService();
72-
this.dir = Files.createTempDirectory("REPL");
70+
Path dir = Files.createTempDirectory("REPL");
7371
this.tmpfile = Files.createTempFile(dir, null, ".js");
74-
Files.write(tmpfile, initialText.getBytes(Charset.forName("UTF-8")));
72+
Files.writeString(tmpfile, initialText);
7573
dir.register(watcher,
7674
ENTRY_CREATE,
7775
ENTRY_DELETE,
@@ -104,8 +102,7 @@ private void setupWatch(final String initialText) throws IOException {
104102
}
105103

106104
private void launch(final String cmd) throws IOException {
107-
ProcessBuilder pb = new ProcessBuilder(cmd, tmpfile.toString());
108-
pb = pb.inheritIO();
105+
ProcessBuilder pb = new ProcessBuilder(cmd, tmpfile.toString()).inheritIO();
109106

110107
try {
111108
input.suspend();

src/org.openjdk.nashorn.shell/share/classes/org/openjdk/nashorn/tools/jjs/HistoryObject.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,7 @@
5151
final class HistoryObject extends AbstractJSObject {
5252
private static final Set<String> props;
5353
static {
54-
final HashSet<String> s = new HashSet<>();
55-
s.add("clear");
56-
s.add("forEach");
57-
s.add("load");
58-
s.add("print");
59-
s.add("save");
60-
s.add("size");
61-
s.add("toString");
62-
props = Collections.unmodifiableSet(s);
54+
props = Set.of("clear", "forEach", "load", "print", "save", "size", "toString");
6355
}
6456

6557
private final History hist;

src/org.openjdk.nashorn.shell/share/classes/org/openjdk/nashorn/tools/jjs/Main.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ protected int readEvalPrint(final Context context, final Global global) {
205205
try {
206206
source = in.readLine(prompt, prompt2);
207207
} catch (final IOException ioe) {
208-
err.println(ioe.toString());
208+
err.println(ioe);
209209
if (env._dump_on_error) {
210210
ioe.printStackTrace(err);
211211
}

src/org.openjdk.nashorn.shell/share/classes/org/openjdk/nashorn/tools/jjs/NashornCompleter.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,9 @@
2929
import java.io.PrintWriter;
3030
import java.util.ArrayList;
3131
import java.util.List;
32-
import java.util.Objects;
3332
import java.util.regex.Pattern;
3433

3534
import jdk.internal.org.jline.reader.Candidate;
36-
import jdk.internal.org.jline.reader.Completer;
37-
import jdk.internal.org.jline.reader.LineReader;
38-
import jdk.internal.org.jline.reader.ParsedLine;
3935
import jdk.internal.org.jline.reader.UserInterruptException;
4036
import org.openjdk.nashorn.api.tree.AssignmentTree;
4137
import org.openjdk.nashorn.api.tree.BinaryTree;
@@ -155,15 +151,14 @@ String readMoreLines(final String firstLine, final Exception exp, final Console
155151
} catch (final Throwable th) {
156152
if (th instanceof UserInterruptException) {
157153
// Ctrl-C from user - discard the whole thing silently!
158-
return null;
159154
} else {
160155
// print anything else -- but still discard the code
161156
err.println(th);
162157
if (env._dump_on_error) {
163158
th.printStackTrace(err);
164159
}
165-
return null;
166160
}
161+
return null;
167162
}
168163

169164
final String allLines = buf.toString();

src/org.openjdk.nashorn.shell/share/classes/org/openjdk/nashorn/tools/jjs/PropertiesHelper.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
package org.openjdk.nashorn.tools.jjs;
2727

2828
import java.io.IOException;
29-
import java.util.ArrayList;
3029
import java.util.Arrays;
3130
import java.util.Collections;
3231
import java.util.List;

src/org.openjdk.nashorn/share/classes/org/openjdk/nashorn/api/scripting/Formatter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ static String format(final String format, final Object[] args) {
104104
// convert double to long
105105
args[index - 1] = ((Double) arg).longValue();
106106
} else if (arg instanceof String
107-
&& ((String) arg).length() > 0) {
107+
&& !((String) arg).isEmpty()) {
108108
// convert string (first character) to int
109109
args[index - 1] = (int) ((String) arg).charAt(0);
110110
}
@@ -126,7 +126,7 @@ static String format(final String format, final Object[] args) {
126126
// convert double to integer
127127
args[index - 1] = ((Double) arg).intValue();
128128
} else if (arg instanceof String
129-
&& ((String) arg).length() > 0) {
129+
&& !((String) arg).isEmpty()) {
130130
// get the first character from string
131131
args[index - 1] = (int) ((String) arg).charAt(0);
132132
}

src/org.openjdk.nashorn/share/classes/org/openjdk/nashorn/api/scripting/ScriptObjectMirror.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,7 @@ private static void checkKey(final Object key) {
740740

741741
if (!(key instanceof String)) {
742742
throw new ClassCastException("key should be a String. It is " + key.getClass().getName() + " instead.");
743-
} else if (((String)key).length() == 0) {
743+
} else if (((String) key).isEmpty()) {
744744
throw new IllegalArgumentException("key can not be empty");
745745
}
746746
}

src/org.openjdk.nashorn/share/classes/org/openjdk/nashorn/api/tree/ExportEntryTree.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
*/
2525
package org.openjdk.nashorn.api.tree;
2626

27-
import java.util.List;
28-
2927
/**
3028
* A Tree node for export entry in <a href="http://www.ecma-international.org/ecma-262/6.0/#sec-modules">Module information</a>.
3129
*/

0 commit comments

Comments
 (0)