diff options
| author | 2019-05-15 22:03:13 -0700 | |
|---|---|---|
| committer | 2019-05-16 07:03:13 +0200 | |
| commit | cb8823eb0b446d5c1b9b580e5578866e691771d8 (patch) | |
| tree | 1e8c1a5b981f3ad42c393f5d7cb75754f25f51ba /src/main/java/cuchaz/enigma/analysis | |
| parent | checkmappings command (#137) (diff) | |
| download | enigma-fork-cb8823eb0b446d5c1b9b580e5578866e691771d8.tar.gz enigma-fork-cb8823eb0b446d5c1b9b580e5578866e691771d8.tar.xz enigma-fork-cb8823eb0b446d5c1b9b580e5578866e691771d8.zip | |
Feature/weave (#138)
* Add weave/stitch style command system to enigma
Also fixed divide by zero stupidity
Signed-off-by: liach <liach@users.noreply.github.com>
* Add tests for package access index and command
Signed-off-by: liach <liach@users.noreply.github.com>
* Minor tweaks
Signed-off-by: liach <liach@users.noreply.github.com>
Diffstat (limited to 'src/main/java/cuchaz/enigma/analysis')
| -rw-r--r-- | src/main/java/cuchaz/enigma/analysis/index/PackageVisibilityIndex.java | 10 | ||||
| -rw-r--r-- | src/main/java/cuchaz/enigma/analysis/index/ReferenceIndex.java | 3 |
2 files changed, 7 insertions, 6 deletions
diff --git a/src/main/java/cuchaz/enigma/analysis/index/PackageVisibilityIndex.java b/src/main/java/cuchaz/enigma/analysis/index/PackageVisibilityIndex.java index 9e9115f..da28ac4 100644 --- a/src/main/java/cuchaz/enigma/analysis/index/PackageVisibilityIndex.java +++ b/src/main/java/cuchaz/enigma/analysis/index/PackageVisibilityIndex.java | |||
| @@ -11,7 +11,7 @@ import cuchaz.enigma.translation.representation.entry.*; | |||
| 11 | import java.util.*; | 11 | import java.util.*; |
| 12 | 12 | ||
| 13 | public class PackageVisibilityIndex implements JarIndexer { | 13 | public class PackageVisibilityIndex implements JarIndexer { |
| 14 | private static boolean isPackageVisibleOnlyRef(AccessFlags entryAcc, EntryReference ref, InheritanceIndex inheritanceIndex) { | 14 | private static boolean requiresSamePackage(AccessFlags entryAcc, EntryReference ref, InheritanceIndex inheritanceIndex) { |
| 15 | if (entryAcc.isPublic()) return false; | 15 | if (entryAcc.isPublic()) return false; |
| 16 | if (entryAcc.isProtected()) { | 16 | if (entryAcc.isProtected()) { |
| 17 | Set<ClassEntry> callerAncestors = inheritanceIndex.getAncestors(ref.context.getContainingClass()); | 17 | Set<ClassEntry> callerAncestors = inheritanceIndex.getAncestors(ref.context.getContainingClass()); |
| @@ -43,7 +43,7 @@ public class PackageVisibilityIndex implements JarIndexer { | |||
| 43 | AccessFlags entryAcc = entryIndex.getFieldAccess(entry); | 43 | AccessFlags entryAcc = entryIndex.getFieldAccess(entry); |
| 44 | if (!entryAcc.isPublic() && !entryAcc.isPrivate()) { | 44 | if (!entryAcc.isPublic() && !entryAcc.isPrivate()) { |
| 45 | for (EntryReference<FieldEntry, MethodDefEntry> ref : referenceIndex.getReferencesToField(entry)) { | 45 | for (EntryReference<FieldEntry, MethodDefEntry> ref : referenceIndex.getReferencesToField(entry)) { |
| 46 | if (isPackageVisibleOnlyRef(entryAcc, ref, inheritanceIndex)) { | 46 | if (requiresSamePackage(entryAcc, ref, inheritanceIndex)) { |
| 47 | addConnection(ref.entry.getContainingClass(), ref.context.getContainingClass()); | 47 | addConnection(ref.entry.getContainingClass(), ref.context.getContainingClass()); |
| 48 | } | 48 | } |
| 49 | } | 49 | } |
| @@ -54,7 +54,7 @@ public class PackageVisibilityIndex implements JarIndexer { | |||
| 54 | AccessFlags entryAcc = entryIndex.getMethodAccess(entry); | 54 | AccessFlags entryAcc = entryIndex.getMethodAccess(entry); |
| 55 | if (!entryAcc.isPublic() && !entryAcc.isPrivate()) { | 55 | if (!entryAcc.isPublic() && !entryAcc.isPrivate()) { |
| 56 | for (EntryReference<MethodEntry, MethodDefEntry> ref : referenceIndex.getReferencesToMethod(entry)) { | 56 | for (EntryReference<MethodEntry, MethodDefEntry> ref : referenceIndex.getReferencesToMethod(entry)) { |
| 57 | if (isPackageVisibleOnlyRef(entryAcc, ref, inheritanceIndex)) { | 57 | if (requiresSamePackage(entryAcc, ref, inheritanceIndex)) { |
| 58 | addConnection(ref.entry.getContainingClass(), ref.context.getContainingClass()); | 58 | addConnection(ref.entry.getContainingClass(), ref.context.getContainingClass()); |
| 59 | } | 59 | } |
| 60 | } | 60 | } |
| @@ -65,13 +65,13 @@ public class PackageVisibilityIndex implements JarIndexer { | |||
| 65 | AccessFlags entryAcc = entryIndex.getClassAccess(entry); | 65 | AccessFlags entryAcc = entryIndex.getClassAccess(entry); |
| 66 | if (!entryAcc.isPublic() && !entryAcc.isPrivate()) { | 66 | if (!entryAcc.isPublic() && !entryAcc.isPrivate()) { |
| 67 | for (EntryReference<ClassEntry, FieldDefEntry> ref : referenceIndex.getFieldTypeReferencesToClass(entry)) { | 67 | for (EntryReference<ClassEntry, FieldDefEntry> ref : referenceIndex.getFieldTypeReferencesToClass(entry)) { |
| 68 | if (isPackageVisibleOnlyRef(entryAcc, ref, inheritanceIndex)) { | 68 | if (requiresSamePackage(entryAcc, ref, inheritanceIndex)) { |
| 69 | addConnection(ref.entry.getContainingClass(), ref.context.getContainingClass()); | 69 | addConnection(ref.entry.getContainingClass(), ref.context.getContainingClass()); |
| 70 | } | 70 | } |
| 71 | } | 71 | } |
| 72 | 72 | ||
| 73 | for (EntryReference<ClassEntry, MethodDefEntry> ref : referenceIndex.getMethodTypeReferencesToClass(entry)) { | 73 | for (EntryReference<ClassEntry, MethodDefEntry> ref : referenceIndex.getMethodTypeReferencesToClass(entry)) { |
| 74 | if (isPackageVisibleOnlyRef(entryAcc, ref, inheritanceIndex)) { | 74 | if (requiresSamePackage(entryAcc, ref, inheritanceIndex)) { |
| 75 | addConnection(ref.entry.getContainingClass(), ref.context.getContainingClass()); | 75 | addConnection(ref.entry.getContainingClass(), ref.context.getContainingClass()); |
| 76 | } | 76 | } |
| 77 | } | 77 | } |
diff --git a/src/main/java/cuchaz/enigma/analysis/index/ReferenceIndex.java b/src/main/java/cuchaz/enigma/analysis/index/ReferenceIndex.java index 6764ac0..04306bd 100644 --- a/src/main/java/cuchaz/enigma/analysis/index/ReferenceIndex.java +++ b/src/main/java/cuchaz/enigma/analysis/index/ReferenceIndex.java | |||
| @@ -92,7 +92,8 @@ public class ReferenceIndex implements JarIndexer { | |||
| 92 | } | 92 | } |
| 93 | 93 | ||
| 94 | private <E extends Entry<?>, C extends Entry<?>> Multimap<E, EntryReference<E, C>> remapReferencesTo(JarIndex index, Multimap<E, EntryReference<E, C>> multimap) { | 94 | private <E extends Entry<?>, C extends Entry<?>> Multimap<E, EntryReference<E, C>> remapReferencesTo(JarIndex index, Multimap<E, EntryReference<E, C>> multimap) { |
| 95 | Multimap<E, EntryReference<E, C>> resolved = HashMultimap.create(multimap.keySet().size(), multimap.size() / multimap.keySet().size()); | 95 | final int keySetSize = multimap.keySet().size(); |
| 96 | Multimap<E, EntryReference<E, C>> resolved = HashMultimap.create(keySetSize, keySetSize == 0 ? 0 : multimap.size() / keySetSize); | ||
| 96 | for (Map.Entry<E, EntryReference<E, C>> entry : multimap.entries()) { | 97 | for (Map.Entry<E, EntryReference<E, C>> entry : multimap.entries()) { |
| 97 | resolved.put(remap(index, entry.getKey()), remap(index, entry.getValue())); | 98 | resolved.put(remap(index, entry.getKey()), remap(index, entry.getValue())); |
| 98 | } | 99 | } |