1 /*
   2  * Copyright (c) 2004, 2005, 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 com.sun.mirror.type;
  27 
  28 
  29 import java.lang.annotation.Annotation;
  30 import java.util.ArrayList;
  31 import java.util.Collection;
  32 import java.util.Collections;
  33 
  34 import com.sun.mirror.declaration.Declaration;
  35 
  36 
  37 /**
  38  * Thrown when an application attempts to access a sequence of {@link Class}
  39  * objects each corresponding to a {@link TypeMirror}.
  40  *
  41  * @deprecated All components of this API have been superseded by the
  42  * standardized annotation processing API.  The replacement for the
  43  * functionality of this exception is {@link
  44  * javax.lang.model.type.MirroredTypesException}.
  45  *
  46  * @see MirroredTypeException
  47  * @see Declaration#getAnnotation(Class)
  48  */
  49 @Deprecated
  50 @SuppressWarnings("deprecation")
  51 public class MirroredTypesException extends RuntimeException {
  52 
  53     private static final long serialVersionUID = 1;
  54 
  55     private transient Collection<TypeMirror> types;     // cannot be serialized
  56     private Collection<String> names;           // types' qualified "names"
  57 
  58     /**
  59      * Constructs a new MirroredTypesException for the specified types.
  60      *
  61      * @param types  an ordered collection of the types being accessed
  62      */
  63     public MirroredTypesException(Collection<TypeMirror> types) {
  64         super("Attempt to access Class objects for TypeMirrors " + types);
  65         this.types = types;
  66         names = new ArrayList<String>();
  67         for (TypeMirror t : types) {
  68             names.add(t.toString());
  69         }
  70     }
  71 
  72     /**
  73      * Returns the type mirrors corresponding to the types being accessed.
  74      * The type mirrors may be unavailable if this exception has been
  75      * serialized and then read back in.
  76      *
  77      * @return the type mirrors in order, or <tt>null</tt> if unavailable
  78      */
  79     public Collection<TypeMirror> getTypeMirrors() {
  80         return (types != null)
  81                 ? Collections.unmodifiableCollection(types)
  82                 : null;
  83     }
  84 
  85     /**
  86      * Returns the fully qualified names of the types being accessed.
  87      * More precisely, returns the canonical names of each class,
  88      * interface, array, or primitive, and <tt>"void"</tt> for
  89      * the pseudo-type representing the type of <tt>void</tt>.
  90      *
  91      * @return the fully qualified names, in order, of the types being
  92      *          accessed
  93      */
  94     public Collection<String> getQualifiedNames() {
  95         return Collections.unmodifiableCollection(names);
  96     }
  97 }