Newer
Older
MagnetRON / src / org / ntlab / trace / MethodExecutionJPDA.java
Aki Hongo on 3 Mar 2020 2 KB first commit
  1. package org.ntlab.trace;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.HashMap;
  5. import java.util.HashSet;
  6.  
  7. public class MethodExecutionJPDA {
  8. private String signature;
  9. private MethodExecutionJPDA callerMethodExecution = null;
  10. private ArrayList<MethodExecutionJPDA> children = new ArrayList<MethodExecutionJPDA>();
  11. private long entryTime = 0L;
  12. public MethodExecutionJPDA(String signature, long enterTime) {
  13. this.signature = signature;
  14. this.entryTime = enterTime;
  15. }
  16. public String getSignature() {
  17. return signature;
  18. }
  19.  
  20. public long getEntryTime() {
  21. return entryTime;
  22. }
  23. public void addChild(MethodExecutionJPDA child) {
  24. children.add(child);
  25. }
  26.  
  27. public ArrayList<MethodExecutionJPDA> getChildren() {
  28. return children;
  29. }
  30.  
  31. public void setCaller(MethodExecutionJPDA callerMethodExecution) {
  32. this.callerMethodExecution = callerMethodExecution;
  33. }
  34.  
  35. public MethodExecutionJPDA getParent() {
  36. return callerMethodExecution;
  37. }
  38.  
  39. public MethodExecutionJPDA getCallerMethodExecution() {
  40. return callerMethodExecution;
  41. }
  42. /**
  43. * このメソッド実行およびその全呼び出し先を呼び出し木の中で逆向きに探索する(ただし、visitor が true を返すまで)
  44. * @param visitor ビジター
  45. * @return true -- 探索を中断した, false -- 最後まで探索した
  46. */
  47. public boolean traverseMethodExecutionsBackward(IMethodExecutionVisitorJPDA visitor) {
  48. if (visitor.preVisitMethodExecution(this)) return true;
  49. ArrayList<MethodExecutionJPDA> calledMethodExecutions = getChildren();
  50. for (int i = calledMethodExecutions.size() - 1; i >= 0; i--) {
  51. MethodExecutionJPDA child = calledMethodExecutions.get(i);
  52. if (child.traverseMethodExecutionsBackward(visitor)) return true;
  53. }
  54. if (visitor.postVisitMethodExecution(this, null)) return true;
  55. return false;
  56. }
  57. public interface IMethodExecutionVisitorJPDA {
  58. abstract public boolean preVisitThread(ThreadInstanceJPDA thread);
  59. abstract public boolean postVisitThread(ThreadInstanceJPDA thread);
  60. abstract public boolean preVisitMethodExecution(MethodExecutionJPDA methodExecution);
  61. abstract public boolean postVisitMethodExecution(MethodExecutionJPDA methodExecution, ArrayList<MethodExecutionJPDA> children);
  62. }
  63. }