Newer
Older
MagnetRON / src / org / ntlab / deltaExtractor / Alias.java
  1. package org.ntlab.deltaExtractor;
  2. import org.ntlab.trace.MethodExecution;
  3. import org.ntlab.trace.MethodInvocation;
  4. import org.ntlab.trace.Statement;
  5. import org.ntlab.trace.TracePoint;
  6. /**
  7. * オブジェクトの参照情報(エイリアス)を表すクラス
  8. * @author Isitani
  9. *
  10. */
  11. public class Alias {
  12. private String objectId;
  13. private TracePoint occurrencePoint; // 当該オブジェクトの参照が行われている実行箇所に対応するTracePoint
  14. private AliasType aliasType;
  15. private int index;
  16. public enum AliasType {
  17. // メソッドへの入口
  18. FORMAL_PARAMETER,
  19. THIS,
  20. METHOD_INVOCATION,
  21. CONSTRACTOR_INVOCATION,
  22. // 追跡オブジェクトの切り替え
  23. FIELD,
  24. CONTAINER,
  25. ARRAY_ELEMENT,
  26. ARRAY,
  27. ARRAY_CREATE,
  28.  
  29. // メソッドからの出口
  30. ACTUAL_ARGUMENT,
  31. RECEIVER,
  32. RETURN_VALUE
  33. }
  34. public Alias(AliasType aliasType, int index, String objectId, TracePoint occurrencePoint) {
  35. this.aliasType = aliasType;
  36. this.index = index;
  37. this.objectId = objectId;
  38. this.occurrencePoint = occurrencePoint;
  39. }
  40. public AliasType getAliasType() {
  41. return aliasType;
  42. }
  43. public int getIndex() {
  44. return index;
  45. }
  46. public String getObjectId() {
  47. return objectId;
  48. }
  49. public TracePoint getOccurrencePoint() {
  50. return occurrencePoint;
  51. }
  52. public MethodExecution getMethodExecution() {
  53. return occurrencePoint.getMethodExecution();
  54. }
  55. public String getMethodSignature() {
  56. return occurrencePoint.getMethodExecution().getSignature();
  57. }
  58.  
  59. /**
  60. * Get time stamp of statement.
  61. * @return
  62. */
  63. public long getTimeStamp() {
  64. if (!occurrencePoint.isValid()) {
  65. return occurrencePoint.getMethodExecution().getEntryTime();
  66. }
  67. long stTimeStamp = occurrencePoint.getStatement().getTimeStamp();
  68. Statement st = occurrencePoint.getStatement();
  69. if (aliasType == AliasType.RETURN_VALUE) {
  70. stTimeStamp = occurrencePoint.getMethodExecution().getExitTime();
  71. } else if (aliasType == AliasType.METHOD_INVOCATION && st instanceof MethodInvocation) {
  72. stTimeStamp = ((MethodInvocation) st).getCalledMethodExecution().getExitTime();
  73. } else if (aliasType == AliasType.FORMAL_PARAMETER) {
  74. stTimeStamp = occurrencePoint.getMethodExecution().getEntryTime();
  75. }
  76. return stTimeStamp;
  77. }
  78.  
  79. public int getLineNo() {
  80. try {
  81. Statement statement = occurrencePoint.getStatement();
  82. return statement.getLineNo();
  83. } catch (Exception e) {
  84. return -1;
  85. }
  86. }
  87. public void setObjectId(String objectId) {
  88. this.objectId = objectId;
  89. }
  90. @Override
  91. public int hashCode() {
  92. final int prime = 31;
  93. int result = 1;
  94. result = prime * result + ((aliasType == null) ? 0 : aliasType.hashCode());
  95. result = prime * result + index;
  96. result = prime * result + ((objectId == null) ? 0 : objectId.hashCode());
  97. result = prime * result + ((occurrencePoint == null) ? 0 : occurrencePoint.hashCode());
  98. return result;
  99. }
  100.  
  101. @Override
  102. public boolean equals(Object obj) {
  103. if (this == obj)
  104. return true;
  105. if (obj == null)
  106. return false;
  107. if (getClass() != obj.getClass())
  108. return false;
  109. Alias other = (Alias) obj;
  110. if (aliasType != other.aliasType)
  111. return false;
  112. if (index != other.index)
  113. return false;
  114. if (objectId == null) {
  115. if (other.objectId != null)
  116. return false;
  117. } else if (!objectId.equals(other.objectId))
  118. return false;
  119. if (occurrencePoint == null) {
  120. if (other.occurrencePoint != null)
  121. return false;
  122. } else if (!occurrencePoint.equals(other.occurrencePoint))
  123. return false;
  124. return true;
  125. }
  126. }