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. package com.sun.mirror.type;
  8. import java.lang.annotation.Annotation;
  9. import java.util.ArrayList;
  10. import java.util.Collection;
  11. import java.util.Collections;
  12. import com.sun.mirror.declaration.Declaration;
  13. /**
  14. * Thrown when an application attempts to access a sequence of {@link Class}
  15. * objects each corresponding to a {@link TypeMirror}.
  16. *
  17. * @see MirroredTypeException
  18. * @see Declaration#getAnnotation(Class)
  19. */
  20. public class MirroredTypesException extends RuntimeException {
  21. private static final long serialVersionUID = 1;
  22. private transient Collection<TypeMirror> types; // cannot be serialized
  23. private Collection<String> names; // types' qualified "names"
  24. /**
  25. * Constructs a new MirroredTypesException for the specified types.
  26. *
  27. * @param types an ordered collection of the types being accessed
  28. */
  29. public MirroredTypesException(Collection<TypeMirror> types) {
  30. super("Attempt to access Class objects for TypeMirrors " + types);
  31. this.types = types;
  32. names = new ArrayList();
  33. for (TypeMirror t : types) {
  34. names.add(t.toString());
  35. }
  36. }
  37. /**
  38. * Returns the type mirrors corresponding to the types being accessed.
  39. * The type mirrors may be unavailable if this exception has been
  40. * serialized and then read back in.
  41. *
  42. * @return the type mirrors in order, or <tt>null</tt> if unavailable
  43. */
  44. public Collection<TypeMirror> getTypeMirrors() {
  45. return (types != null)
  46. ? Collections.unmodifiableCollection(types)
  47. : null;
  48. }
  49. /**
  50. * Returns the fully qualified names of the types being accessed.
  51. * More precisely, returns the canonical names of each class,
  52. * interface, array, or primitive, and <tt>"void"</tt> for
  53. * the pseudo-type representing the type of <tt>void</tt>.
  54. *
  55. * @return the fully qualified names, in order, of the types being
  56. * accessed
  57. */
  58. public Collection<String> getQualifiedNames() {
  59. return Collections.unmodifiableCollection(names);
  60. }
  61. }