Debian Codegraph @

rhino/examples/Counter.java

raw symbols SCIP
1 /* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 *
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7 import org.mozilla.javascript.*;
8 import org.mozilla.javascript.annotations.JSFunction;
9 import org.mozilla.javascript.annotations.JSConstructor;
10 import org.mozilla.javascript.annotations.JSGetter;
11
12 public class Counter extends ScriptableObject {
13 private static final long serialVersionUID = 438270592527335642L;
14
15 // The zero-argument constructor used by Rhino runtime to create instances
16 public Counter() { }
17
18 // @JSConstructor annotation defines the JavaScript constructor
19 @JSConstructor
20 public Counter(int a) { count = a; }
21
22 // The class name is defined by the getClassName method
23 @Override
24 public String getClassName() { return "Counter"; }
25
26 // The method getCount defines the count property.
27 @JSGetter
28 public int getCount() { return count++; }
29
30 // Methods can be defined the @JSFunction annotation.
31 // Here we define resetCount for JavaScript.
32 @JSFunction
33 public void resetCount() { count = 0; }
34
35 private int count;
36 }