Maps the correlations between target and clean classes. @param targetClass @param cleanClass @param targetMap @param cleanMap @return
(MappedClass targetClass, MappedClass cleanClass, Map<String, MappedClass> targetMap, Map<String, MappedClass> cleanMap)
| 29 | * @return |
| 30 | */ |
| 31 | public static Map<String, MappedClass> correlate(MappedClass targetClass, MappedClass cleanClass, Map<String, MappedClass> targetMap, |
| 32 | Map<String, MappedClass> cleanMap) { |
| 33 | if (targetClass.isRenamed()) { |
| 34 | return targetMap; |
| 35 | } |
| 36 | // Verify classes are similiar |
| 37 | if (!areSimiliar(targetClass, cleanClass)) { |
| 38 | return targetMap; |
| 39 | } |
| 40 | // Hop to all parents. |
| 41 | if (targetClass.hasParent() && cleanClass.hasParent()) { |
| 42 | targetMap = correlate(targetClass.getParent(), cleanClass.getParent(), targetMap, cleanMap); |
| 43 | } |
| 44 | // Hop to all interfaces. |
| 45 | int inters = targetClass.getInterfaces().size(); |
| 46 | if (inters > 0) |
| 47 | for (int key = 0; key < inters; key++) { |
| 48 | MappedClass interfaceClassTarget = targetClass.getInterfaces().get(key); |
| 49 | MappedClass interfaceClassClean = cleanClass.getInterfaces().get(key); |
| 50 | targetMap = correlate(interfaceClassTarget, interfaceClassClean, targetMap, cleanMap); |
| 51 | } |
| 52 | // Begin renaming |
| 53 | targetClass.setNewName(cleanClass.getOriginalName()); |
| 54 | if (!targetClass.isTruelyRenamed()){ |
| 55 | targetClass.setRenamedOverride(true); |
| 56 | } |
| 57 | //targetClass.setRenamedOverride(true); |
| 58 | // Fields |
| 59 | List<MappedMember> targetFields = targetClass.getFields(); |
| 60 | List<MappedMember> cleanFields = cleanClass.getFields(); |
| 61 | int offsetField = 0; |
| 62 | for (int key = 0; key < targetFields.size(); key++) { |
| 63 | if (key >= cleanFields.size()) { |
| 64 | continue; |
| 65 | } |
| 66 | MappedMember targetField = targetFields.get(key); |
| 67 | MappedMember cleanField = cleanFields.get(key + offsetField); |
| 68 | // Extra field? |
| 69 | if (cleanField == null) { |
| 70 | continue; |
| 71 | } |
| 72 | // Signatures do not match. |
| 73 | if (!fix(targetField.getDesc()).equals(fix(cleanField.getDesc()))) { |
| 74 | // Field insertion? Make next pass for the clean field (key - x) |
| 75 | // x++ |
| 76 | offsetField -= 1; |
| 77 | continue; |
| 78 | } else { |
| 79 | if (targetField.getDesc().length() > 4 && cleanField.getDesc().length() > 4) { |
| 80 | String n1 = RegexUtils.matchDescriptionClasses(targetField.getDesc()).get(0); |
| 81 | String n2 = RegexUtils.matchDescriptionClasses(cleanField.getDesc()).get(0); |
| 82 | MappedClass c1 = targetMap.get(n1); |
| 83 | MappedClass c2 = targetMap.get(n2); |
| 84 | if (c1 != null && c2 != null) { |
| 85 | boolean flag = areSimiliar(c1, c2); |
| 86 | if (!flag) { |
| 87 | offsetField -= 1; |
| 88 | continue; |
nothing calls this directly
no test coverage detected