PageRenderTime 50ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/src/sys/java/fan/sys/ListType.java

https://bitbucket.org/bedlaczech/fan-1.0
Java | 105 lines | 65 code | 18 blank | 22 comment | 8 complexity | ef42acef4907f10195d447b63bfc9e1a MD5 | raw file
Possible License(s): CC-BY-SA-3.0
  1. //
  2. // Copyright (c) 2006, Brian Frank and Andy Frank
  3. // Licensed under the Academic Free License version 3.0
  4. //
  5. // History:
  6. // 13 Jan 06 (Fri 13th) Brian Frank Creation
  7. //
  8. package fan.sys;
  9. import java.io.*;
  10. import java.lang.reflect.*;
  11. import java.util.ArrayList;
  12. import java.util.HashMap;
  13. import fanx.fcode.*;
  14. import fanx.emit.*;
  15. /**
  16. * ListType is the GenericType for Lists: Foo[] -> V = Foo
  17. */
  18. public class ListType
  19. extends GenericType
  20. {
  21. //////////////////////////////////////////////////////////////////////////
  22. // Constructor
  23. //////////////////////////////////////////////////////////////////////////
  24. ListType(Type v)
  25. {
  26. super(Sys.ListType);
  27. this.v = v;
  28. }
  29. //////////////////////////////////////////////////////////////////////////
  30. // Type
  31. //////////////////////////////////////////////////////////////////////////
  32. public final long hash()
  33. {
  34. return FanStr.hash(signature());
  35. }
  36. public final boolean equals(Object obj)
  37. {
  38. if (obj instanceof ListType)
  39. {
  40. return v.equals(((ListType)obj).v);
  41. }
  42. return false;
  43. }
  44. public final String signature()
  45. {
  46. if (sig == null) sig = v.signature() + "[]";
  47. return sig;
  48. }
  49. public boolean is(Type type)
  50. {
  51. if (type instanceof ListType)
  52. {
  53. ListType t = (ListType)type;
  54. return v.is(t.v);
  55. }
  56. return super.is(type);
  57. }
  58. Map makeParams()
  59. {
  60. return new Map(Sys.StrType, Sys.TypeType)
  61. .set("V", v)
  62. .set("L", this).ro();
  63. }
  64. public Class toClass() { return List.class; }
  65. //////////////////////////////////////////////////////////////////////////
  66. // GenericType
  67. //////////////////////////////////////////////////////////////////////////
  68. public Type getRawType()
  69. {
  70. return Sys.ListType;
  71. }
  72. public boolean isGenericParameter()
  73. {
  74. return v.isGenericParameter();
  75. }
  76. protected Type doParameterize(Type t)
  77. {
  78. if (t == Sys.VType) return v;
  79. if (t == Sys.LType) return this;
  80. throw new IllegalStateException(t.toString());
  81. }
  82. //////////////////////////////////////////////////////////////////////////
  83. // Fields
  84. //////////////////////////////////////////////////////////////////////////
  85. public final Type v;
  86. private String sig;
  87. }