UnknownTreeException.java revision 1604:6f34826bbfdc
1234285Sdim/*
2234285Sdim * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
3234285Sdim * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4234285Sdim *
5234285Sdim * This code is free software; you can redistribute it and/or modify it
6234285Sdim * under the terms of the GNU General Public License version 2 only, as
7234285Sdim * published by the Free Software Foundation.  Oracle designates this
8234285Sdim * particular file as subject to the "Classpath" exception as provided
9234285Sdim * by Oracle in the LICENSE file that accompanied this code.
10234285Sdim *
11234285Sdim * This code is distributed in the hope that it will be useful, but WITHOUT
12234285Sdim * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13234285Sdim * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14234285Sdim * version 2 for more details (a copy is included in the LICENSE file that
15249423Sdim * accompanied this code).
16249423Sdim *
17234285Sdim * You should have received a copy of the GNU General Public License version
18234285Sdim * 2 along with this work; if not, write to the Free Software Foundation,
19234285Sdim * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20234285Sdim *
21234285Sdim * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22234285Sdim * or visit www.oracle.com if you need additional information or have any
23234285Sdim * questions.
24234285Sdim */
25234285Sdim
26234285Sdimpackage jdk.nashorn.api.tree;
27234285Sdim
28234285Sdim
29234285Sdim/**
30234285Sdim * Indicates that an unknown kind of Tree was encountered.  This
31234285Sdim * can occur if the language evolves and new kinds of Trees are
32234285Sdim * added to the {@code Tree} hierarchy.  May be thrown by a
33234285Sdim * {@linkplain TreeVisitor tree visitor} to indicate that the
34234285Sdim * visitor was created for a prior version of the language.
35234285Sdim *
36234285Sdim * @since 9
37234285Sdim */
38234285Sdimpublic class UnknownTreeException extends RuntimeException {
39234285Sdim
40234285Sdim    private static final long serialVersionUID = 1L;
41234285Sdim
42234285Sdim    private transient final Tree tree;
43234285Sdim    private transient final Object parameter;
44234285Sdim
45234285Sdim    /**
46234285Sdim     * Creates a new {@code UnknownTreeException}.  The {@code p}
47234285Sdim     * parameter may be used to pass in an additional argument with
48     * information about the context in which the unknown element was
49     * encountered; for example, the visit methods of {@link
50     * TreeVisitor} may pass in their additional parameter.
51     *
52     * @param t the unknown tree, may be {@code null}
53     * @param p an additional parameter, may be {@code null}
54     */
55    public UnknownTreeException(Tree t, Object p) {
56        super("Unknown tree: " + t);
57        this.tree = t;
58        this.parameter = p;
59    }
60
61    /**
62     * Returns the unknown tree.
63     * The value may be unavailable if this exception has been
64     * serialized and then read back in.
65     *
66     * @return the unknown element, or {@code null} if unavailable
67     */
68    public Tree getUnknownTree() {
69        return tree;
70    }
71
72    /**
73     * Returns the additional argument.
74     * The value may be unavailable if this exception has been
75     * serialized and then read back in.
76     *
77     * @return the additional argument
78     */
79    public Object getArgument() {
80        return parameter;
81    }
82}
83