1. /*
  2. * @(#)MirroredTypeException.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 com.sun.mirror.declaration.Declaration;
  10. /**
  11. * Thrown when an application attempts to access the {@link Class} object
  12. * corresponding to a {@link TypeMirror}.
  13. *
  14. * @see MirroredTypesException
  15. * @see Declaration#getAnnotation(Class)
  16. */
  17. public class MirroredTypeException extends RuntimeException {
  18. private static final long serialVersionUID = 1;
  19. private transient TypeMirror type; // cannot be serialized
  20. private String name; // type's qualified "name"
  21. /**
  22. * Constructs a new MirroredTypeException for the specified type.
  23. *
  24. * @param type the type being accessed
  25. */
  26. public MirroredTypeException(TypeMirror type) {
  27. super("Attempt to access Class object for TypeMirror " + type);
  28. this.type = type;
  29. name = type.toString();
  30. }
  31. /**
  32. * Returns the type mirror corresponding to the type being accessed.
  33. * The type mirror may be unavailable if this exception has been
  34. * serialized and then read back in.
  35. *
  36. * @return the type mirror, or <tt>null</tt> if unavailable
  37. */
  38. public TypeMirror getTypeMirror() {
  39. return type;
  40. }
  41. /**
  42. * Returns the fully qualified name of the type being accessed.
  43. * More precisely, returns the canonical name of a class,
  44. * interface, array, or primitive, and returns <tt>"void"</tt> for
  45. * the pseudo-type representing the type of <tt>void</tt>.
  46. *
  47. * @return the fully qualified name of the type being accessed
  48. */
  49. public String getQualifiedName() {
  50. return name;
  51. }
  52. }