LazyType.java 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // Copyright (c) 2011 Per M.A. Bothner.
  2. // This is free software; for terms and warranty disclaimer see ./COPYING.
  3. package gnu.kawa.reflect;
  4. import gnu.bytecode.*;
  5. /** The type of lazy values - i.e. ones that eventually produce values.
  6. * This includes futures and promises.
  7. */
  8. public class LazyType extends ObjectType
  9. {
  10. ClassType rawType;
  11. Type valueType;
  12. public Type getValueType() {
  13. return valueType;
  14. }
  15. public Type getRawType() {
  16. return rawType;
  17. }
  18. public LazyType(ClassType rawType, Type valueType) {
  19. this.rawType = rawType;
  20. this.valueType = valueType;
  21. }
  22. ParameterizedType implementationType;
  23. public Type getImplementationType() {
  24. if (implementationType == null) {
  25. implementationType = new ParameterizedType(rawType, valueType);
  26. implementationType.setTypeArgumentBound(0, '+');
  27. }
  28. return implementationType;
  29. }
  30. public static LazyType getInstance(ClassType rawType, Type valueType) {
  31. return new LazyType(rawType, valueType);
  32. }
  33. public static final ClassType lazyType = ClassType.make("gnu.mapping.Lazy");
  34. public static final ClassType promiseType = ClassType.make("gnu.mapping.Promise");
  35. public int compare(Type other) {
  36. return valueType.compare(other);
  37. }
  38. public static LazyType getLazyType(Type valueType) {
  39. return getInstance(lazyType, valueType);
  40. }
  41. public static LazyType getPromiseType(Type valueType) {
  42. return getInstance(promiseType, valueType);
  43. }
  44. public String toString() {
  45. return rawType.toString()+'['+valueType.toString()+']'; // FIXME
  46. }
  47. public static boolean maybeLazy (Type type) {
  48. type = type.getRawType();
  49. if (type instanceof ClassType
  50. && ((ClassType) type).implementsInterface(lazyType))
  51. return true;
  52. if (type == Type.objectType)
  53. return true;
  54. return false;
  55. }
  56. }