diff options
Diffstat (limited to 'src/cuchaz/enigma/convert/ClassIdentity.java')
| -rw-r--r-- | src/cuchaz/enigma/convert/ClassIdentity.java | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/src/cuchaz/enigma/convert/ClassIdentity.java b/src/cuchaz/enigma/convert/ClassIdentity.java index d07e0a4..35667b0 100644 --- a/src/cuchaz/enigma/convert/ClassIdentity.java +++ b/src/cuchaz/enigma/convert/ClassIdentity.java | |||
| @@ -16,6 +16,7 @@ import java.security.NoSuchAlgorithmException; | |||
| 16 | import java.util.Enumeration; | 16 | import java.util.Enumeration; |
| 17 | import java.util.List; | 17 | import java.util.List; |
| 18 | import java.util.Map; | 18 | import java.util.Map; |
| 19 | import java.util.Set; | ||
| 19 | 20 | ||
| 20 | import javassist.CannotCompileException; | 21 | import javassist.CannotCompileException; |
| 21 | import javassist.CtBehavior; | 22 | import javassist.CtBehavior; |
| @@ -38,6 +39,7 @@ import com.google.common.collect.HashMultiset; | |||
| 38 | import com.google.common.collect.Lists; | 39 | import com.google.common.collect.Lists; |
| 39 | import com.google.common.collect.Maps; | 40 | import com.google.common.collect.Maps; |
| 40 | import com.google.common.collect.Multiset; | 41 | import com.google.common.collect.Multiset; |
| 42 | import com.google.common.collect.Sets; | ||
| 41 | 43 | ||
| 42 | import cuchaz.enigma.Constants; | 44 | import cuchaz.enigma.Constants; |
| 43 | import cuchaz.enigma.Util; | 45 | import cuchaz.enigma.Util; |
| @@ -67,6 +69,7 @@ public class ClassIdentity { | |||
| 67 | private String m_staticInitializer; | 69 | private String m_staticInitializer; |
| 68 | private String m_extends; | 70 | private String m_extends; |
| 69 | private Multiset<String> m_implements; | 71 | private Multiset<String> m_implements; |
| 72 | private Set<String> m_stringLiterals; | ||
| 70 | private Multiset<String> m_implementations; | 73 | private Multiset<String> m_implementations; |
| 71 | private Multiset<String> m_references; | 74 | private Multiset<String> m_references; |
| 72 | private String m_outer; | 75 | private String m_outer; |
| @@ -140,6 +143,14 @@ public class ClassIdentity { | |||
| 140 | m_implements.add(scrubClassName(Descriptor.toJvmName(interfaceName))); | 143 | m_implements.add(scrubClassName(Descriptor.toJvmName(interfaceName))); |
| 141 | } | 144 | } |
| 142 | 145 | ||
| 146 | m_stringLiterals = Sets.newHashSet(); | ||
| 147 | ConstPool constants = c.getClassFile().getConstPool(); | ||
| 148 | for (int i=1; i<constants.getSize(); i++) { | ||
| 149 | if (constants.getTag(i) == ConstPool.CONST_String) { | ||
| 150 | m_stringLiterals.add(constants.getStringInfo(i)); | ||
| 151 | } | ||
| 152 | } | ||
| 153 | |||
| 143 | // stuff from the jar index | 154 | // stuff from the jar index |
| 144 | 155 | ||
| 145 | m_implementations = HashMultiset.create(); | 156 | m_implementations = HashMultiset.create(); |
| @@ -410,13 +421,15 @@ public class ClassIdentity { | |||
| 410 | public int getMatchScore(ClassIdentity other) { | 421 | public int getMatchScore(ClassIdentity other) { |
| 411 | return 2*getNumMatches(m_extends, other.m_extends) | 422 | return 2*getNumMatches(m_extends, other.m_extends) |
| 412 | + 2*getNumMatches(m_outer, other.m_outer) | 423 | + 2*getNumMatches(m_outer, other.m_outer) |
| 424 | + 2*getNumMatches(m_implements, other.m_implements) | ||
| 425 | + getNumMatches(m_stringLiterals, other.m_stringLiterals) | ||
| 413 | + getNumMatches(m_fields, other.m_fields) | 426 | + getNumMatches(m_fields, other.m_fields) |
| 414 | + getNumMatches(m_methods, other.m_methods) | 427 | + getNumMatches(m_methods, other.m_methods) |
| 415 | + getNumMatches(m_constructors, other.m_constructors); | 428 | + getNumMatches(m_constructors, other.m_constructors); |
| 416 | } | 429 | } |
| 417 | 430 | ||
| 418 | public int getMaxMatchScore() { | 431 | public int getMaxMatchScore() { |
| 419 | return 2 + 2 + m_fields.size() + m_methods.size() + m_constructors.size(); | 432 | return 2 + 2 + 2*m_implements.size() + m_stringLiterals.size() + m_fields.size() + m_methods.size() + m_constructors.size(); |
| 420 | } | 433 | } |
| 421 | 434 | ||
| 422 | public boolean matches(CtClass c) { | 435 | public boolean matches(CtClass c) { |
| @@ -426,6 +439,16 @@ public class ClassIdentity { | |||
| 426 | && m_constructors.size() == c.getDeclaredConstructors().length; | 439 | && m_constructors.size() == c.getDeclaredConstructors().length; |
| 427 | } | 440 | } |
| 428 | 441 | ||
| 442 | private int getNumMatches(Set<String> a, Set<String> b) { | ||
| 443 | int numMatches = 0; | ||
| 444 | for (String val : a) { | ||
| 445 | if (b.contains(val)) { | ||
| 446 | numMatches++; | ||
| 447 | } | ||
| 448 | } | ||
| 449 | return numMatches; | ||
| 450 | } | ||
| 451 | |||
| 429 | private int getNumMatches(Multiset<String> a, Multiset<String> b) { | 452 | private int getNumMatches(Multiset<String> a, Multiset<String> b) { |
| 430 | int numMatches = 0; | 453 | int numMatches = 0; |
| 431 | for (String val : a) { | 454 | for (String val : a) { |