1 package jdiff; 2 3 import java.util.*; 4 import com.sun.javadoc.*; 5 6 12 class ClassDiff { 13 14 15 public String name_; 16 17 18 public boolean isInterface_; 19 20 23 public String inheritanceChange_ = null; 24 25 28 public String documentationChange_ = null; 29 30 35 public String modifiersChange_ = null; 36 37 38 public List ctorsAdded = null; 39 40 public List ctorsRemoved = null; 41 42 public List ctorsChanged = null; 43 44 45 public List methodsAdded = null; 46 47 public List methodsRemoved = null; 48 49 public List methodsChanged = null; 50 51 52 public List fieldsAdded = null; 53 54 public List fieldsRemoved = null; 55 56 public List fieldsChanged = null; 57 58 59 public double pdiff = 0.0; 60 61 62 public ClassDiff(String name) { 63 name_ = name; 64 isInterface_ = false; 65 66 ctorsAdded = new ArrayList(); ctorsRemoved = new ArrayList(); ctorsChanged = new ArrayList(); 70 methodsAdded = new ArrayList(); methodsRemoved = new ArrayList(); methodsChanged = new ArrayList(); 74 fieldsAdded = new ArrayList(); fieldsRemoved = new ArrayList(); fieldsChanged = new ArrayList(); } 78 79 84 public static String diff(ClassAPI oldClass, ClassAPI newClass) { 85 Collections.sort(oldClass.implements_); 86 Collections.sort(newClass.implements_); 87 String res = ""; 88 boolean hasContent = false; 89 if (oldClass.extends_ != null && newClass.extends_ != null && 90 oldClass.extends_.compareTo(newClass.extends_) != 0) { 91 res += "The superclass changed from <code>" + oldClass.extends_ + "</code> to <code>" + newClass.extends_ + "</code>.<br>"; 92 hasContent = true; 93 } 94 String removedInterfaces = ""; 96 int numRemoved = 0; 97 Iterator iter = oldClass.implements_.iterator(); 98 while (iter.hasNext()) { 99 String oldInterface = (String )(iter.next()); 100 int idx = Collections.binarySearch(newClass.implements_, oldInterface); 101 if (idx < 0) { 102 if (numRemoved != 0) 103 removedInterfaces += ", "; 104 removedInterfaces += oldInterface; 105 numRemoved++; 106 } 107 } 108 String addedInterfaces = ""; 109 int numAdded = 0; 110 iter = newClass.implements_.iterator(); 111 while (iter.hasNext()) { 112 String newInterface = (String )(iter.next()); 113 int idx = Collections.binarySearch(oldClass.implements_, newInterface); 114 if (idx < 0) { 115 if (numAdded != 0) 116 addedInterfaces += ", "; 117 addedInterfaces += newInterface; 118 numAdded++; 119 } 120 } 121 if (numRemoved != 0) { 122 if (hasContent) 123 res += " "; 124 if (numRemoved == 1) 125 res += "Removed interface <code>" + removedInterfaces + "</code>.<br>"; 126 else 127 res += "Removed interfaces <code>" + removedInterfaces + "</code>.<br>"; 128 hasContent = true; 129 } 130 if (numAdded != 0) { 131 if (hasContent) 132 res += " "; 133 if (numAdded == 1) 134 res += "Added interface <code>" + addedInterfaces + "</code>.<br>"; 135 else 136 res += "Added interfaces <code>" + addedInterfaces + "</code>.<br>"; 137 hasContent = true; 138 } 139 if (res.compareTo("") == 0) 140 return null; 141 return res; 142 } 143 144 145 public void addModifiersChange(String commonModifierChanges) { 146 if (commonModifierChanges != null) { 147 if (modifiersChange_ == null) 148 modifiersChange_ = commonModifierChanges; 149 else 150 modifiersChange_ += " " + commonModifierChanges; 151 } 152 } 153 } 154 155 | Popular Tags |