KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > mirror > type > MirroredTypesException


1 /*
2  * @(#)MirroredTypesException.java 1.1 04/04/20
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package com.sun.mirror.type;
9
10
11 import java.lang.annotation.Annotation JavaDoc;
12 import java.util.ArrayList JavaDoc;
13 import java.util.Collection JavaDoc;
14 import java.util.Collections JavaDoc;
15
16 import com.sun.mirror.declaration.Declaration;
17
18
19 /**
20  * Thrown when an application attempts to access a sequence of {@link Class}
21  * objects each corresponding to a {@link TypeMirror}.
22  *
23  * @see MirroredTypeException
24  * @see Declaration#getAnnotation(Class)
25  */

26 public class MirroredTypesException extends RuntimeException JavaDoc {
27
28     private static final long serialVersionUID = 1;
29
30     private transient Collection JavaDoc<TypeMirror> types; // cannot be serialized
31
private Collection JavaDoc<String JavaDoc> names; // types' qualified "names"
32

33     /**
34      * Constructs a new MirroredTypesException for the specified types.
35      *
36      * @param types an ordered collection of the types being accessed
37      */

38     public MirroredTypesException(Collection JavaDoc<TypeMirror> types) {
39     super("Attempt to access Class objects for TypeMirrors " + types);
40     this.types = types;
41     names = new ArrayList JavaDoc();
42     for (TypeMirror t : types) {
43         names.add(t.toString());
44     }
45     }
46
47     /**
48      * Returns the type mirrors corresponding to the types being accessed.
49      * The type mirrors may be unavailable if this exception has been
50      * serialized and then read back in.
51      *
52      * @return the type mirrors in order, or <tt>null</tt> if unavailable
53      */

54     public Collection JavaDoc<TypeMirror> getTypeMirrors() {
55     return (types != null)
56         ? Collections.unmodifiableCollection(types)
57         : null;
58     }
59
60     /**
61      * Returns the fully qualified names of the types being accessed.
62      * More precisely, returns the canonical names of each class,
63      * interface, array, or primitive, and <tt>"void"</tt> for
64      * the pseudo-type representing the type of <tt>void</tt>.
65      *
66      * @return the fully qualified names, in order, of the types being
67      * accessed
68      */

69     public Collection JavaDoc<String JavaDoc> getQualifiedNames() {
70     return Collections.unmodifiableCollection(names);
71     }
72 }
73
Popular Tags