01: /*
02: * Copyright 2004-2005 Sun Microsystems, Inc. All Rights Reserved.
03: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
04: *
05: * This code is free software; you can redistribute it and/or modify it
06: * under the terms of the GNU General Public License version 2 only, as
07: * published by the Free Software Foundation. Sun designates this
08: * particular file as subject to the "Classpath" exception as provided
09: * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22: * CA 95054 USA or visit www.sun.com if you need additional information or
23: * have any questions.
24: */
25:
26: package com.sun.mirror.type;
27:
28: import java.lang.annotation.Annotation;
29: import java.util.ArrayList;
30: import java.util.Collection;
31: import java.util.Collections;
32:
33: import com.sun.mirror.declaration.Declaration;
34:
35: /**
36: * Thrown when an application attempts to access a sequence of {@link Class}
37: * objects each corresponding to a {@link TypeMirror}.
38: *
39: * @see MirroredTypeException
40: * @see Declaration#getAnnotation(Class)
41: */
42: public class MirroredTypesException extends RuntimeException {
43:
44: private static final long serialVersionUID = 1;
45:
46: private transient Collection<TypeMirror> types; // cannot be serialized
47: private Collection<String> names; // types' qualified "names"
48:
49: /**
50: * Constructs a new MirroredTypesException for the specified types.
51: *
52: * @param types an ordered collection of the types being accessed
53: */
54: public MirroredTypesException(Collection<TypeMirror> types) {
55: super ("Attempt to access Class objects for TypeMirrors "
56: + types);
57: this .types = types;
58: names = new ArrayList<String>();
59: for (TypeMirror t : types) {
60: names.add(t.toString());
61: }
62: }
63:
64: /**
65: * Returns the type mirrors corresponding to the types being accessed.
66: * The type mirrors may be unavailable if this exception has been
67: * serialized and then read back in.
68: *
69: * @return the type mirrors in order, or <tt>null</tt> if unavailable
70: */
71: public Collection<TypeMirror> getTypeMirrors() {
72: return (types != null) ? Collections
73: .unmodifiableCollection(types) : null;
74: }
75:
76: /**
77: * Returns the fully qualified names of the types being accessed.
78: * More precisely, returns the canonical names of each class,
79: * interface, array, or primitive, and <tt>"void"</tt> for
80: * the pseudo-type representing the type of <tt>void</tt>.
81: *
82: * @return the fully qualified names, in order, of the types being
83: * accessed
84: */
85: public Collection<String> getQualifiedNames() {
86: return Collections.unmodifiableCollection(names);
87: }
88: }
|