1 /*
   2  * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package jdk.nashorn.api.tree;
  27 
  28 
  29 /**
  30  * Indicates that an unknown kind of Tree was encountered.  This
  31  * can occur if the language evolves and new kinds of Trees are
  32  * added to the {@code Tree} hierarchy.  May be thrown by a
  33  * {@linkplain TreeVisitor tree visitor} to indicate that the
  34  * visitor was created for a prior version of the language.
  35  *
  36  * @since 1.9
  37  */
  38 @jdk.Exported
  39 public class UnknownTreeException extends RuntimeException {
  40 
  41     private static final long serialVersionUID = 1L;
  42 
  43     private transient final Tree tree;
  44     private transient final Object parameter;
  45 
  46     /**
  47      * Creates a new {@code UnknownTreeException}.  The {@code p}
  48      * parameter may be used to pass in an additional argument with
  49      * information about the context in which the unknown element was
  50      * encountered; for example, the visit methods of {@link
  51      * TreeVisitor} may pass in their additional parameter.
  52      *
  53      * @param t the unknown tree, may be {@code null}
  54      * @param p an additional parameter, may be {@code null}
  55      */
  56     public UnknownTreeException(Tree t, Object p) {
  57         super("Unknown tree: " + t);
  58         this.tree = t;
  59         this.parameter = p;
  60     }
  61 
  62     /**
  63      * Returns the unknown tree.
  64      * The value may be unavailable if this exception has been
  65      * serialized and then read back in.
  66      *
  67      * @return the unknown element, or {@code null} if unavailable
  68      */
  69     public Tree getUnknownTree() {
  70         return tree;
  71     }
  72 
  73     /**
  74      * Returns the additional argument.
  75      * The value may be unavailable if this exception has been
  76      * serialized and then read back in.
  77      *
  78      * @return the additional argument
  79      */
  80     public Object getArgument() {
  81         return parameter;
  82     }
  83 }