package-info.java revision 1204:9597425b6b38
1279377Simp/*
2279377Simp * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
3279377Simp * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4279377Simp *
5279377Simp * This code is free software; you can redistribute it and/or modify it
6279377Simp * under the terms of the GNU General Public License version 2 only, as
7279377Simp * published by the Free Software Foundation.  Oracle designates this
8279377Simp * particular file as subject to the "Classpath" exception as provided
9279377Simp * by Oracle in the LICENSE file that accompanied this code.
10279377Simp *
11279377Simp * This code is distributed in the hope that it will be useful, but WITHOUT
12279377Simp * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13279377Simp * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14279377Simp * version 2 for more details (a copy is included in the LICENSE file that
15279377Simp * accompanied this code).
16279377Simp *
17279377Simp * You should have received a copy of the GNU General Public License version
18279377Simp * 2 along with this work; if not, write to the Free Software Foundation,
19279377Simp * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20279377Simp *
21279377Simp * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22279377Simp * or visit www.oracle.com if you need additional information or have any
23279377Simp * questions.
24279377Simp */
25279377Simp
26279377Simp/**
27279377Simp * <p>
28279377Simp * Nashorn parser API provides interfaces to represent ECMAScript source code
29279377Simp * as abstract syntax trees (AST) and Parser to parse ECMAScript source scripts.
30279377Simp * </p>
31279377Simp * <p>
32279377Simp * Using parser API user can write Java code to access parse tree
33279377Simp * representation of ECMAScript source. Script source may be a file,
34279377Simp * a URL or a String. Unless stated otherwise null argument in methods of this
35279377Simp * package result in NullPointerException being thrown.
36279377Simp * </p>
37279377Simp *
38279377Simp * <pre>
39279377Simp * <code>
40279377Simp * import jdk.nashorn.api.tree.*;
41279377Simp * import java.io.File;
42279377Simp *
43279377Simp * // Simple example that prints warning on 'with' statements
44279377Simp * public class Main {
45279377Simp *     public static void main(String[] args) throws Exception {
46279377Simp *         // Create a new parser instance
47279377Simp *         Parser parser = Parser.create();
48279377Simp *         File sourceFile = new File(args[0]);
49279377Simp *
50279377Simp *         // Parse given source File using parse method.
51279377Simp *         // Pass a diagnostic listener to print error messages.
52279377Simp *         CompilationUnitTree cut = parser.parse(sourceFile,
53279377Simp *             (d) -&gt; { System.out.println(d); });
54279377Simp *
55279377Simp *         if (cut != null) {
56279377Simp *             // call Tree.accept method passing a SimpleTreeVisitor
57279377Simp *             cut.accept(new SimpleTreeVisitor&lt;Void, Void&gt;() {
58279377Simp *                 // visit method for 'with' statement
59279377Simp *                 public Void visitWith(WithTree wt, Void v) {
60279377Simp *                     // print warning on 'with' statement
61279377Simp *                     System.out.println("Warning: using 'with' statement!");
62279377Simp *                     return null;
63279377Simp *                 }
64279377Simp *             }, null);
65279377Simp *         }
66279377Simp *     }
67279377Simp * }
68279377Simp * </code>
69279377Simp * </pre>
70279377Simp *
71279377Simp * @since 1.9
72279377Simp */
73279377Simp@jdk.Exported
74279377Simppackage jdk.nashorn.api.tree;
75279377Simp
76279377Simp