/tutorial/external/Java/example2.e

http://github.com/tybor/Liberty · Specman e · 77 lines · 50 code · 11 blank · 16 comment · 0 complexity · 67e5dc4599fa843d5e0a09b3def18263 MD5 · raw file

  1. class EXAMPLE2
  2. -- Compilation:
  3. -- compile_to_jvm example2
  4. -- javac ISimple.java
  5. -- javac ASimple.java
  6. -- Execution:
  7. -- java example2
  8. -- This example demonstrates how to read and write Java object class and instance
  9. -- fields from Eiffel.
  10. creation {ANY}
  11. make
  12. feature {ANY}
  13. make is
  14. local
  15. a1: POINTER; b: BOOLEAN; i: INTEGER; d: DOUBLE
  16. do
  17. -- create new ASimple instance
  18. a1 := new_ASimple -- verify that it is an instance of ASimple
  19. b := instanceof_ASimple(a1)
  20. io.put_string("is a1 an instance of ASimple? " + b.to_string + "%N")
  21. -- get the instance variable theInteger
  22. i := get_theInteger(checkcast_ASimple(a1))
  23. io.put_string("value of theInteger: " + i.to_string + "%N")
  24. -- set the instance variable theInteger to 13
  25. set_theInteger(checkcast_ASimple(a1), 13)
  26. -- get the instance variable theInteger
  27. i := get_theInteger(checkcast_ASimple(a1))
  28. io.put_string("value of theInteger after setting to 13: " + i.to_string + "%N")
  29. -- get the class variable theStaticInteger
  30. i := get_theStaticInteger
  31. io.put_string("value of theStaticInteger: " + i.to_string + "%N")
  32. -- set the class variable theStaticInteger to -11
  33. set_theStaticInteger(-11)
  34. -- get the class variable theStaticInteger
  35. i := get_theStaticInteger
  36. io.put_string("value of theStaticInteger after setting to -11: " + i.to_string + "%N")
  37. -- get the class constant dConstant from ISimple
  38. d := get_dConstant
  39. io.put_string("value of dConstant: " + d.to_string + "%N")
  40. end
  41. feature {ANY} -- externals
  42. new_ASimple: POINTER is
  43. external "Java class ASimple new ()"
  44. end
  45. checkcast_ASimple (p: POINTER): POINTER is
  46. external "Java class ASimple checkcast"
  47. end
  48. instanceof_ASimple (p: POINTER): BOOLEAN is
  49. external "Java class ASimple instanceof"
  50. end
  51. get_theStaticInteger: INTEGER is
  52. external "Java class ASimple get field static int theStaticInteger"
  53. end
  54. set_theStaticInteger (a: INTEGER) is
  55. external "Java class ASimple set field static int theStaticInteger"
  56. end
  57. get_theInteger (p: POINTER): INTEGER is
  58. external "Java class ASimple get field int theInteger"
  59. end
  60. set_theInteger (p: POINTER; a: INTEGER) is
  61. external "Java class ASimple set field int theInteger"
  62. end
  63. get_dConstant: DOUBLE is
  64. external "Java class ISimple get field static double dConstant"
  65. end
  66. end -- class EXAMPLE2