Newer
Older
MagnetRON / src / org / ntlab / traceanalyzer / MarkedMethodExecution.java
Aki Hongo on 3 Mar 2020 2 KB first commit
  1. package org.ntlab.traceanalyzer;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.HashSet;
  5.  
  6. import org.ntlab.trace.MethodExecution;
  7.  
  8. public class MarkedMethodExecution {
  9. private MethodExecution methodExecution;
  10. private ArrayList<MarkedMethodExecution> children = null;
  11. private int uniqueMethodInvokedFrom = 0;
  12. public MarkedMethodExecution(MethodExecution methodExecution) {
  13. this.methodExecution = methodExecution;
  14. }
  15.  
  16. public void addChild(MarkedMethodExecution child) {
  17. if (children == null) {
  18. children = new ArrayList<MarkedMethodExecution>();
  19. }
  20. children.add(child);
  21. }
  22. public ArrayList<MarkedMethodExecution> getChildren() {
  23. if (children == null) {
  24. ArrayList<MethodExecution> rawChildren = methodExecution.getChildren();
  25. children = new ArrayList<MarkedMethodExecution>();
  26. for (int i = 0; i < rawChildren.size(); i++) {
  27. children.add(0, new MarkedMethodExecution(rawChildren.get(i)));
  28. }
  29. }
  30. return children;
  31. }
  32.  
  33. public Object getParent() {
  34. return methodExecution.getParent();
  35. }
  36.  
  37. public String getSignature() {
  38. return methodExecution.getSignature();
  39. }
  40. public String getDeclaringClassName() {
  41. return methodExecution.getDeclaringClassName();
  42. }
  43. public String getReceiverClassName() {
  44. return methodExecution.getThisClassName();
  45. }
  46.  
  47. /**
  48. * マーク固有のメソッドが呼び出されたかどうかを調べる
  49. * @param commonMethodSignatures マーク外で呼び出された全メソッドのシグニチャ
  50. */
  51. public int searchUniqueMethodInvocation(HashSet<String> commonMethodSignatures) {
  52. if (uniqueMethodInvokedFrom > 0) return uniqueMethodInvokedFrom;
  53. if (isUniqueMethod(commonMethodSignatures)) uniqueMethodInvokedFrom = 2;
  54. ArrayList<MarkedMethodExecution> children = getChildren();
  55. for (int i = 0; i < children.size(); i++) {
  56. int u = children.get(i).searchUniqueMethodInvocation(commonMethodSignatures);
  57. if (uniqueMethodInvokedFrom == 0 && u > 0) uniqueMethodInvokedFrom = 1;
  58. }
  59. return uniqueMethodInvokedFrom;
  60. }
  61.  
  62. /**
  63. * マーク固有のメソッド実行をすべて取得する
  64. * @param commonMethodSignatures マーク外で実行された全メソッドのシグニチャ
  65. * @return このメソッド実行以下のマーク固有の全メソッド実行
  66. */
  67. public void getUniqueMethodExecutions(HashSet<String> commonMethodSignatures, ArrayList<MarkedMethodExecution> uniqueMethodExecutions) {
  68. if (isUniqueMethod(commonMethodSignatures)) {
  69. uniqueMethodExecutions.add(this);
  70. }
  71. for (int n = 0; n < children.size(); n++) {
  72. children.get(n).getUniqueMethodExecutions(commonMethodSignatures, uniqueMethodExecutions);
  73. }
  74. }
  75. /**
  76. * このメソッド実行からマーク固有のメソッドが呼び出されたか?
  77. * @return 0: 呼び出されていない, 1: 呼び出された, 2: 自分自身がマーク固有メソッド
  78. */
  79. public int isUniqueMethodInvokedFrom() {
  80. return uniqueMethodInvokedFrom;
  81. }
  82.  
  83. private boolean isUniqueMethod(HashSet<String> commonMethodSignatures) {
  84. return !commonMethodSignatures.contains(getSignature());
  85. }
  86. }