See: Description
Interface | Description |
---|---|
ArrayAccessTree |
A tree node for an array access expression.
|
ArrayLiteralTree |
Represents ECMAScript array literal expression.
|
AssignmentTree |
A tree node for an assignment expression.
|
BinaryTree |
A tree node for a binary expression.
|
BlockTree |
A tree node for a statement block.
|
BreakTree |
A tree node for a 'break' statement.
|
CaseTree |
A tree node for a 'case' in a 'switch' statement.
|
CatchTree |
A tree node for a 'catch' block in a 'try' statement.
|
CompilationUnitTree |
Represents the abstract syntax tree for compilation units (source
files)
|
CompoundAssignmentTree |
A tree node for compound assignment operator.
|
ConditionalExpressionTree |
A tree node for the conditional operator ? :.
|
ConditionalLoopTree |
A mixin for conditional "loop" statements.
|
ContinueTree |
A tree node for a 'continue' statement.
|
DebuggerTree |
A tree node for a 'debugger' statement.
|
Diagnostic |
Interface for diagnostics from tools.
|
DiagnosticListener |
Interface for receiving diagnostics from Nashorn parser.
|
DoWhileLoopTree |
A tree node for a 'do' statement.
|
EmptyStatementTree |
A tree node for an empty (skip) statement.
|
ErroneousTree |
A tree node to stand in for a malformed expression.
|
ExpressionStatementTree |
A tree node for an expression statement.
|
ExpressionTree |
A tree node used as the base class for the different types of
expressions.
|
ForInLoopTree |
A tree node for for..in statement
For example:
|
ForLoopTree |
A tree node for a basic 'for' loop statement.
|
FunctionCallTree |
A tree node for a function call expression.
|
FunctionDeclarationTree |
A tree node for a function declaration.
|
FunctionExpressionTree |
A tree node for a function expression.
|
GotoTree |
A tree node for a statement that jumps to a target.
|
IdentifierTree |
A tree node for an identifier expression.
|
IfTree |
A tree node for an 'if' statement.
|
InstanceOfTree |
A tree node for an 'instanceof' expression.
|
LabeledStatementTree |
A tree node for a labeled statement.
|
LineMap |
Provides methods to convert between character positions and line numbers
for a compilation unit.
|
LiteralTree |
A tree node for a literal expression.
|
LoopTree |
A mixin for "loop" statements.
|
MemberSelectTree |
A tree node for a member access expression.
|
NewTree |
A tree node to declare a new instance of a class.
|
ObjectLiteralTree |
Represents ECMAScript object literal expression.
|
ParenthesizedTree |
A tree node for a parenthesized expression.
|
Parser |
Represents nashorn ECMAScript parser instance.
|
PropertyTree |
To represent property setting in an object literal tree.
|
RegExpLiteralTree |
Represents regular expression literal in the source code.
|
ReturnTree |
A tree node for a 'return' statement.
|
StatementTree |
A tree node used as the base class for the different kinds of
statements.
|
SwitchTree |
A tree node for a 'switch' statement.
|
ThrowTree |
A tree node for a 'throw' statement.
|
Tree |
Common interface for all nodes in an abstract syntax tree.
|
TreeVisitor<R,P> |
A visitor of trees, in the style of the visitor design pattern.
|
TryTree |
A tree node for a 'try' statement.
|
UnaryTree |
A tree node for postfix and unary expressions.
|
VariableTree |
A tree node for a variable declaration.
|
WhileLoopTree |
A tree node for a 'while' loop statement.
|
WithTree |
A tree node for a 'with' statement.
|
Class | Description |
---|---|
SimpleTreeVisitorES5_1<R,P> |
A simple implementation of the TreeVisitor for ECMAScript edition 5.1.
|
Enum | Description |
---|---|
Diagnostic.Kind |
Kinds of diagnostics, for example, error or warning.
|
Tree.Kind |
Enumerates all kinds of trees.
|
Exception | Description |
---|---|
UnknownTreeException |
Indicates that an unknown kind of Tree was encountered.
|
Nashorn parser API provides interfaces to represent ECMAScript source code as abstract syntax trees (AST) and Parser to parse ECMAScript source scripts.
Using parser API user can write Java code to access parse tree representation of ECMAScript source. Script source may be a file, a URL or a String. Unless stated otherwise null argument in methods of this package result in NullPointerException being thrown.
import jdk.nashorn.api.tree.*;
import java.io.File;
// Simple example that prints warning on 'with' statements
public class Main {
public static void main(String[] args) throws Exception {
// Create a new parser instance
Parser parser = Parser.create();
File sourceFile = new File(args[0]);
// Parse given source File using parse method.
// Pass a diagnostic listener to print error messages.
CompilationUnitTree cut = parser.parse(sourceFile,
(d) -> { System.out.println(d); });
if (cut != null) {
// call Tree.accept method passing a SimpleTreeVisitor
cut.accept(new SimpleTreeVisitor<Void, Void>() {
// visit method for 'with' statement
public Void visitWith(WithTree wt, Void v) {
// print warning on 'with' statement
System.out.println("Warning: using 'with' statement!");
return null;
}
}, null);
}
}
}
Copyright © 2014, 2016, Oracle and/or its affiliates. All rights reserved.
DRAFT 9-internal+0-2016-03-31-172659.buildd.src