001    /*
002     * Copyright 2005-2006 Sun Microsystems, Inc.  All Rights Reserved.
003     * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004     *
005     * This code is free software; you can redistribute it and/or modify it
006     * under the terms of the GNU General Public License version 2 only, as
007     * published by the Free Software Foundation.  Sun designates this
008     * particular file as subject to the "Classpath" exception as provided
009     * by Sun in the LICENSE file that accompanied this code.
010     *
011     * This code is distributed in the hope that it will be useful, but WITHOUT
012     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013     * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
014     * version 2 for more details (a copy is included in the LICENSE file that
015     * accompanied this code).
016     *
017     * You should have received a copy of the GNU General Public License version
018     * 2 along with this work; if not, write to the Free Software Foundation,
019     * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020     *
021     * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022     * CA 95054 USA or visit www.sun.com if you need additional information or
023     * have any questions.
024     */
025    
026    package javax.lang.model.element;
027    
028    /**
029     * Indicates that an unknown kind of element was encountered.  This
030     * can occur if the language evolves and new kinds of elements are
031     * added to the {@code Element} hierarchy.  May be thrown by an
032     * {@linkplain ElementVisitor element visitor} to indicate that the
033     * visitor was created for a prior version of the language.
034     *
035     * @author Joseph D. Darcy
036     * @author Scott Seligman
037     * @author Peter von der Ahé
038     * @see ElementVisitor#visitUnknown
039     * @since 1.6
040     */
041    public class UnknownElementException extends RuntimeException {
042    
043        private static final long serialVersionUID = 269L;
044    
045        private transient Element element;
046        private transient Object parameter;
047    
048        /**
049         * Creates a new {@code UnknownElementException}.  The {@code p}
050         * parameter may be used to pass in an additional argument with
051         * information about the context in which the unknown element was
052         * encountered; for example, the visit methods of {@link
053         * ElementVisitor} may pass in their additional parameter.
054         *
055         * @param e the unknown element, may be {@code null}
056         * @param p an additional parameter, may be {@code null}
057         */
058        public UnknownElementException(Element e, Object p) {
059            super("Unknown element: " + e);
060            element = e;
061            this.parameter = p;
062        }
063    
064        /**
065         * Returns the unknown element.
066         * The value may be unavailable if this exception has been
067         * serialized and then read back in.
068         *
069         * @return the unknown element, or {@code null} if unavailable
070         */
071        public Element getUnknownElement() {
072            return element;
073        }
074    
075        /**
076         * Returns the additional argument.
077         *
078         * @return the additional argument
079         */
080        public Object getArgument() {
081            return parameter;
082        }
083    }