Skip to content

Commit 5953334

Browse files
committed
add @OverRide and some try-with-resource
s
1 parent 6ec1085 commit 5953334

File tree

18 files changed

+91
-25
lines changed

18 files changed

+91
-25
lines changed

benchmarks/org/mozilla/javascript/benchmarks/BuiltinBenchmark.java

+3
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public void close() {
5959
@State(Scope.Thread)
6060
public static class AnnotatedClassState extends AbstractClassState {
6161

62+
@Override
6263
@Setup(Level.Trial)
6364
public void init()
6465
throws IllegalAccessException, InvocationTargetException, InstantiationException {
@@ -122,6 +123,7 @@ public int getValue() {
122123
@State(Scope.Thread)
123124
public static class IdClassState extends AbstractClassState {
124125

126+
@Override
125127
@Setup(Level.Trial)
126128
public void init()
127129
throws IllegalAccessException, InvocationTargetException, InstantiationException {
@@ -314,6 +316,7 @@ protected int findPrototypeId(String s) {
314316
@State(Scope.Thread)
315317
public static class DumbLambdaState extends AbstractClassState {
316318

319+
@Override
317320
@Setup(Level.Trial)
318321
public void init()
319322
throws IllegalAccessException, InvocationTargetException, InstantiationException {

examples/DynamicScopes.java

+1
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ static class PerThread implements Runnable {
139139
this.x = x;
140140
}
141141

142+
@Override
142143
public void run() {
143144
// We need a new Context for this thread.
144145
Context cx = Context.enter();

src/org/mozilla/javascript/Hashtable.java

+1
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ public void clear() {
273273
map.clear();
274274
}
275275

276+
@Override
276277
public Iterator<Entry> iterator() {
277278
return new Iter(first);
278279
}

src/org/mozilla/javascript/NativeJavaList.java

+1
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ public boolean has(int index, Scriptable start) {
7777
return super.has(index, start);
7878
}
7979

80+
@Override
8081
public void delete(int index) {
8182
if (isWithValidIndex(index)) {
8283
list.set(index, null);

testsrc/org/mozilla/javascript/tests/scriptengine/BuiltinsTest.java

+18-16
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,24 @@ public void printStdout() throws ScriptException {
3737

3838
@Test
3939
public void printStdoutAndCheckItPrints() throws Exception {
40-
ByteArrayOutputStream bos = new ByteArrayOutputStream();
41-
PrintStream original = System.out;
42-
PrintStream modified = new PrintStream(bos, false);
43-
System.setOut(modified);
44-
// Now Get A SimpleContext
45-
ScriptContext sc = new SimpleScriptContext();
46-
try {
47-
// this was a broken test
48-
engine.eval("print('Hello, World!');", sc);
49-
// this has been hard work https://github.com/mozilla/rhino/issues/1356
50-
Assert.assertEquals("Hello, World!\n", bos.toString());
51-
} finally {
52-
// revert the sys out
53-
System.setOut(original);
54-
modified.close();
55-
bos.close();
40+
try (ByteArrayOutputStream bos = new ByteArrayOutputStream()) {
41+
PrintStream original = System.out;
42+
try (PrintStream modified = new PrintStream(bos, false)) {
43+
System.setOut(modified);
44+
try {
45+
// Now Get A SimpleContext
46+
ScriptContext sc = new SimpleScriptContext();
47+
48+
// this was a broken test
49+
engine.eval("print('Hello, World!');", sc);
50+
51+
// this has been hard work https://github.com/mozilla/rhino/issues/1356
52+
Assert.assertEquals("Hello, World!\n", bos.toString());
53+
} finally {
54+
// revert the sys out
55+
System.setOut(original);
56+
}
57+
}
5658
}
5759
}
5860

toolsrc/org/mozilla/javascript/tools/ToolErrorReporter.java

+3
Original file line numberDiff line numberDiff line change
@@ -92,18 +92,21 @@ private static String getExceptionMessage(RhinoException ex) {
9292
return msg;
9393
}
9494

95+
@Override
9596
public void warning(
9697
String message, String sourceName, int line, String lineSource, int lineOffset) {
9798
if (!reportWarnings) return;
9899
reportErrorMessage(message, sourceName, line, lineSource, lineOffset, true);
99100
}
100101

102+
@Override
101103
public void error(
102104
String message, String sourceName, int line, String lineSource, int lineOffset) {
103105
hasReportedErrorFlag = true;
104106
reportErrorMessage(message, sourceName, line, lineSource, lineOffset, false);
105107
}
106108

109+
@Override
107110
public EvaluatorException runtimeError(
108111
String message, String sourceName, int line, String lineSource, int lineOffset) {
109112
return new EvaluatorException(message, sourceName, line, lineSource, lineOffset);

toolsrc/org/mozilla/javascript/tools/debugger/Dim.java

+10
Original file line numberDiff line numberDiff line change
@@ -805,6 +805,7 @@ private DimIProxy(Dim dim, int type) {
805805
// ContextAction
806806

807807
/** Performs the action given by {@link #type}. */
808+
@Override
808809
public Object run(Context cx) {
809810
switch (type) {
810811
case IPROXY_COMPILE_SCRIPT:
@@ -863,6 +864,7 @@ private void withContext() {
863864
// ContextFactory.Listener
864865

865866
/** Called when a Context is created. */
867+
@Override
866868
public void contextCreated(Context cx) {
867869
if (type != IPROXY_LISTEN) Kit.codeBug();
868870
ContextData contextData = new ContextData();
@@ -873,13 +875,15 @@ public void contextCreated(Context cx) {
873875
}
874876

875877
/** Called when a Context is destroyed. */
878+
@Override
876879
public void contextReleased(Context cx) {
877880
if (type != IPROXY_LISTEN) Kit.codeBug();
878881
}
879882

880883
// Debugger
881884

882885
/** Returns a StackFrame for the given function or script. */
886+
@Override
883887
public DebugFrame getFrame(Context cx, DebuggableScript fnOrScript) {
884888
if (type != IPROXY_DEBUG) Kit.codeBug();
885889

@@ -892,6 +896,7 @@ public DebugFrame getFrame(Context cx, DebuggableScript fnOrScript) {
892896
}
893897

894898
/** Called when compilation is finished. */
899+
@Override
895900
public void handleCompilationDone(Context cx, DebuggableScript fnOrScript, String source) {
896901
if (type != IPROXY_DEBUG) Kit.codeBug();
897902

@@ -984,6 +989,7 @@ private StackFrame(Context cx, Dim dim, FunctionSource fsource) {
984989
}
985990

986991
/** Called when the stack frame is entered. */
992+
@Override
987993
public void onEnter(Context cx, Scriptable scope, Scriptable thisObj, Object[] args) {
988994
contextData.pushFrame(this);
989995
this.scope = scope;
@@ -994,6 +1000,7 @@ public void onEnter(Context cx, Scriptable scope, Scriptable thisObj, Object[] a
9941000
}
9951001

9961002
/** Called when the current position has changed. */
1003+
@Override
9971004
public void onLineChange(Context cx, int lineno) {
9981005
this.lineNumber = lineno;
9991006

@@ -1013,11 +1020,13 @@ public void onLineChange(Context cx, int lineno) {
10131020
}
10141021

10151022
/** Called when an exception has been thrown. */
1023+
@Override
10161024
public void onExceptionThrown(Context cx, Throwable exception) {
10171025
dim.handleExceptionThrown(cx, exception, this);
10181026
}
10191027

10201028
/** Called when the stack frame has been left. */
1029+
@Override
10211030
public void onExit(Context cx, boolean byThrow, Object resultOrException) {
10221031
if (dim.breakOnReturn && !byThrow) {
10231032
dim.handleBreakpointHit(this, cx);
@@ -1026,6 +1035,7 @@ public void onExit(Context cx, boolean byThrow, Object resultOrException) {
10261035
}
10271036

10281037
/** Called when a 'debugger' statement is executed. */
1038+
@Override
10291039
public void onDebuggerStatement(Context cx) {
10301040
dim.handleBreakpointHit(this, cx);
10311041
}

toolsrc/org/mozilla/javascript/tools/debugger/Main.java

+2
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ public static ScopeProvider newScopeProvider(Scriptable scope) {
307307
// ContextAction
308308

309309
/** Exit action. */
310+
@Override
310311
public void run() {
311312
if (type != EXIT_ACTION) Kit.codeBug();
312313
System.exit(0);
@@ -315,6 +316,7 @@ public void run() {
315316
// ScopeProvider
316317

317318
/** Returns the scope for script evaluations. */
319+
@Override
318320
public Scriptable getScope() {
319321
if (type != SCOPE_PROVIDER) Kit.codeBug();
320322
if (scope == null) Kit.codeBug();

toolsrc/org/mozilla/javascript/tools/debugger/treetable/AbstractCellEditor.java

+7
Original file line numberDiff line numberDiff line change
@@ -41,28 +41,35 @@ public class AbstractCellEditor implements CellEditor {
4141

4242
protected EventListenerList listenerList = new EventListenerList();
4343

44+
@Override
4445
public Object getCellEditorValue() {
4546
return null;
4647
}
4748

49+
@Override
4850
public boolean isCellEditable(EventObject e) {
4951
return true;
5052
}
5153

54+
@Override
5255
public boolean shouldSelectCell(EventObject anEvent) {
5356
return false;
5457
}
5558

59+
@Override
5660
public boolean stopCellEditing() {
5761
return true;
5862
}
5963

64+
@Override
6065
public void cancelCellEditing() {}
6166

67+
@Override
6268
public void addCellEditorListener(CellEditorListener l) {
6369
listenerList.add(CellEditorListener.class, l);
6470
}
6571

72+
@Override
6673
public void removeCellEditorListener(CellEditorListener l) {
6774
listenerList.remove(CellEditorListener.class, l);
6875
}

toolsrc/org/mozilla/javascript/tools/debugger/treetable/JTreeTable.java

+3
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ public void paint(Graphics g) {
201201
}
202202

203203
/** TreeCellRenderer method. Overridden to update the visible row. */
204+
@Override
204205
public Component getTableCellRendererComponent(
205206
JTable table,
206207
Object value,
@@ -218,6 +219,7 @@ public Component getTableCellRendererComponent(
218219

219220
/** TreeTableCellEditor implementation. Component returned is the JTree. */
220221
public class TreeTableCellEditor extends AbstractCellEditor implements TableCellEditor {
222+
@Override
221223
public Component getTableCellEditorComponent(
222224
JTable table, Object value, boolean isSelected, int r, int c) {
223225
return tree;
@@ -351,6 +353,7 @@ protected void updateSelectedPathsFromSelectedRows() {
351353
* the list changse.
352354
*/
353355
class ListSelectionHandler implements ListSelectionListener {
356+
@Override
354357
public void valueChanged(ListSelectionEvent e) {
355358
updateSelectedPathsFromSelectedRows();
356359
}

toolsrc/org/mozilla/javascript/tools/debugger/treetable/TreeTableModelAdapter.java

+10
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,12 @@ public TreeTableModelAdapter(TreeTableModel treeTableModel, JTree tree) {
6464
new TreeExpansionListener() {
6565
// Don't use fireTableRowsInserted() here; the selection model
6666
// would get updated twice.
67+
@Override
6768
public void treeExpanded(TreeExpansionEvent event) {
6869
fireTableDataChanged();
6970
}
7071

72+
@Override
7173
public void treeCollapsed(TreeExpansionEvent event) {
7274
fireTableDataChanged();
7375
}
@@ -79,18 +81,22 @@ public void treeCollapsed(TreeExpansionEvent event) {
7981
// the event before us.
8082
treeTableModel.addTreeModelListener(
8183
new TreeModelListener() {
84+
@Override
8285
public void treeNodesChanged(TreeModelEvent e) {
8386
delayedFireTableDataChanged();
8487
}
8588

89+
@Override
8690
public void treeNodesInserted(TreeModelEvent e) {
8791
delayedFireTableDataChanged();
8892
}
8993

94+
@Override
9095
public void treeNodesRemoved(TreeModelEvent e) {
9196
delayedFireTableDataChanged();
9297
}
9398

99+
@Override
94100
public void treeStructureChanged(TreeModelEvent e) {
95101
delayedFireTableDataChanged();
96102
}
@@ -99,6 +105,7 @@ public void treeStructureChanged(TreeModelEvent e) {
99105

100106
// Wrappers, implementing TableModel interface.
101107

108+
@Override
102109
public int getColumnCount() {
103110
return treeTableModel.getColumnCount();
104111
}
@@ -113,6 +120,7 @@ public Class<?> getColumnClass(int column) {
113120
return treeTableModel.getColumnClass(column);
114121
}
115122

123+
@Override
116124
public int getRowCount() {
117125
return tree.getRowCount();
118126
}
@@ -122,6 +130,7 @@ protected Object nodeForRow(int row) {
122130
return treePath.getLastPathComponent();
123131
}
124132

133+
@Override
125134
public Object getValueAt(int row, int column) {
126135
return treeTableModel.getValueAt(nodeForRow(row), column);
127136
}
@@ -143,6 +152,7 @@ public void setValueAt(Object value, int row, int column) {
143152
protected void delayedFireTableDataChanged() {
144153
SwingUtilities.invokeLater(
145154
new Runnable() {
155+
@Override
146156
public void run() {
147157
fireTableDataChanged();
148158
}

toolsrc/org/mozilla/javascript/tools/shell/ConsoleTextArea.java

+7
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public ConsoleWrite(ConsoleTextArea textArea, String str) {
3030
this.str = str;
3131
}
3232

33+
@Override
3334
public void run() {
3435
textArea.write(str);
3536
}
@@ -149,6 +150,7 @@ public void eval(String str) {
149150
console1.flush();
150151
}
151152

153+
@Override
152154
public void keyPressed(KeyEvent e) {
153155
int code = e.getKeyCode();
154156
if (code == KeyEvent.VK_BACK_SPACE || code == KeyEvent.VK_LEFT) {
@@ -213,6 +215,7 @@ public void keyPressed(KeyEvent e) {
213215
}
214216
}
215217

218+
@Override
216219
public void keyTyped(KeyEvent e) {
217220
int keyChar = e.getKeyChar();
218221
if (keyChar == 0x8 /* KeyEvent.VK_BACK_SPACE */) {
@@ -224,6 +227,7 @@ public void keyTyped(KeyEvent e) {
224227
}
225228
}
226229

230+
@Override
227231
public synchronized void keyReleased(KeyEvent e) {}
228232

229233
public synchronized void write(String str) {
@@ -233,6 +237,7 @@ public synchronized void write(String str) {
233237
select(outputMark, outputMark);
234238
}
235239

240+
@Override
236241
public synchronized void insertUpdate(DocumentEvent e) {
237242
int len = e.getLength();
238243
int off = e.getOffset();
@@ -241,6 +246,7 @@ public synchronized void insertUpdate(DocumentEvent e) {
241246
}
242247
}
243248

249+
@Override
244250
public synchronized void removeUpdate(DocumentEvent e) {
245251
int len = e.getLength();
246252
int off = e.getOffset();
@@ -260,6 +266,7 @@ public synchronized void postUpdateUI() {
260266
select(outputMark, outputMark);
261267
}
262268

269+
@Override
263270
public synchronized void changedUpdate(DocumentEvent e) {}
264271

265272
public InputStream getIn() {

0 commit comments

Comments
 (0)