diff options
3 files changed, 37 insertions, 27 deletions
diff --git a/enigma-swing/src/main/java/cuchaz/enigma/gui/GuiController.java b/enigma-swing/src/main/java/cuchaz/enigma/gui/GuiController.java index a2346f1c..f990f98c 100644 --- a/enigma-swing/src/main/java/cuchaz/enigma/gui/GuiController.java +++ b/enigma-swing/src/main/java/cuchaz/enigma/gui/GuiController.java | |||
| @@ -273,7 +273,7 @@ public class GuiController implements ClientPacketHandler { | |||
| 273 | if (entry == null) { | 273 | if (entry == null) { |
| 274 | throw new IllegalArgumentException("Entry cannot be null!"); | 274 | throw new IllegalArgumentException("Entry cannot be null!"); |
| 275 | } | 275 | } |
| 276 | openReference(new EntryReference<>(entry, entry.getName())); | 276 | openReference(EntryReference.declaration(entry, entry.getName())); |
| 277 | } | 277 | } |
| 278 | 278 | ||
| 279 | /** | 279 | /** |
| @@ -301,7 +301,7 @@ public class GuiController implements ClientPacketHandler { | |||
| 301 | * @param reference the reference | 301 | * @param reference the reference |
| 302 | */ | 302 | */ |
| 303 | private void setReference(EntryReference<Entry<?>, Entry<?>> reference) { | 303 | private void setReference(EntryReference<Entry<?>, Entry<?>> reference) { |
| 304 | gui.openClass(reference.getLocationClassEntry()).showReference(reference); | 304 | gui.openClass(reference.getLocationClassEntry().getOutermostClass()).showReference(reference); |
| 305 | } | 305 | } |
| 306 | 306 | ||
| 307 | public Collection<Token> getTokensForReference(DecompiledClassSource source, EntryReference<Entry<?>, Entry<?>> reference) { | 307 | public Collection<Token> getTokensForReference(DecompiledClassSource source, EntryReference<Entry<?>, Entry<?>> reference) { |
diff --git a/enigma/src/main/java/cuchaz/enigma/analysis/EntryReference.java b/enigma/src/main/java/cuchaz/enigma/analysis/EntryReference.java index cccabd01..6dd65260 100644 --- a/enigma/src/main/java/cuchaz/enigma/analysis/EntryReference.java +++ b/enigma/src/main/java/cuchaz/enigma/analysis/EntryReference.java | |||
| @@ -28,11 +28,15 @@ import cuchaz.enigma.translation.representation.entry.MethodEntry; | |||
| 28 | public class EntryReference<E extends Entry<?>, C extends Entry<?>> implements Translatable { | 28 | public class EntryReference<E extends Entry<?>, C extends Entry<?>> implements Translatable { |
| 29 | 29 | ||
| 30 | private static final List<String> CONSTRUCTOR_NON_NAMES = Arrays.asList("this", "super", "static"); | 30 | private static final List<String> CONSTRUCTOR_NON_NAMES = Arrays.asList("this", "super", "static"); |
| 31 | public E entry; | 31 | public final E entry; |
| 32 | public C context; | 32 | public final C context; |
| 33 | public ReferenceTargetType targetType; | 33 | public final ReferenceTargetType targetType; |
| 34 | 34 | private final boolean declaration; // if the ref goes to the decl of the item. when true context == null | |
| 35 | private boolean sourceName; | 35 | private final boolean sourceName; |
| 36 | |||
| 37 | public static <E extends Entry<?>, C extends Entry<?>> EntryReference<E, C> declaration(E entry, String sourceName) { | ||
| 38 | return new EntryReference<>(entry, sourceName, null, ReferenceTargetType.none(), true); | ||
| 39 | } | ||
| 36 | 40 | ||
| 37 | public EntryReference(E entry, String sourceName) { | 41 | public EntryReference(E entry, String sourceName) { |
| 38 | this(entry, sourceName, null); | 42 | this(entry, sourceName, null); |
| @@ -43,6 +47,10 @@ public class EntryReference<E extends Entry<?>, C extends Entry<?>> implements T | |||
| 43 | } | 47 | } |
| 44 | 48 | ||
| 45 | public EntryReference(E entry, String sourceName, C context, ReferenceTargetType targetType) { | 49 | public EntryReference(E entry, String sourceName, C context, ReferenceTargetType targetType) { |
| 50 | this(entry, sourceName, context, targetType, false); | ||
| 51 | } | ||
| 52 | |||
| 53 | protected EntryReference(E entry, String sourceName, C context, ReferenceTargetType targetType, boolean declaration) { | ||
| 46 | if (entry == null) { | 54 | if (entry == null) { |
| 47 | throw new IllegalArgumentException("Entry cannot be null!"); | 55 | throw new IllegalArgumentException("Entry cannot be null!"); |
| 48 | } | 56 | } |
| @@ -50,11 +58,10 @@ public class EntryReference<E extends Entry<?>, C extends Entry<?>> implements T | |||
| 50 | this.entry = entry; | 58 | this.entry = entry; |
| 51 | this.context = context; | 59 | this.context = context; |
| 52 | this.targetType = targetType; | 60 | this.targetType = targetType; |
| 61 | this.declaration = declaration; | ||
| 53 | 62 | ||
| 54 | this.sourceName = sourceName != null && !sourceName.isEmpty(); | 63 | this.sourceName = sourceName != null && !sourceName.isEmpty() && |
| 55 | if (entry instanceof MethodEntry && ((MethodEntry) entry).isConstructor() && CONSTRUCTOR_NON_NAMES.contains(sourceName)) { | 64 | !(entry instanceof MethodEntry && ((MethodEntry) entry).isConstructor() && CONSTRUCTOR_NON_NAMES.contains(sourceName)); |
| 56 | this.sourceName = false; | ||
| 57 | } | ||
| 58 | } | 65 | } |
| 59 | 66 | ||
| 60 | public EntryReference(E entry, C context, EntryReference<E, C> other) { | 67 | public EntryReference(E entry, C context, EntryReference<E, C> other) { |
| @@ -62,6 +69,7 @@ public class EntryReference<E extends Entry<?>, C extends Entry<?>> implements T | |||
| 62 | this.context = context; | 69 | this.context = context; |
| 63 | this.sourceName = other.sourceName; | 70 | this.sourceName = other.sourceName; |
| 64 | this.targetType = other.targetType; | 71 | this.targetType = other.targetType; |
| 72 | this.declaration = other.declaration; | ||
| 65 | } | 73 | } |
| 66 | 74 | ||
| 67 | public ClassEntry getLocationClassEntry() { | 75 | public ClassEntry getLocationClassEntry() { |
| @@ -75,6 +83,13 @@ public class EntryReference<E extends Entry<?>, C extends Entry<?>> implements T | |||
| 75 | return this.sourceName; | 83 | return this.sourceName; |
| 76 | } | 84 | } |
| 77 | 85 | ||
| 86 | /** | ||
| 87 | * Returns whether this refers to the declaration of an entry. | ||
| 88 | */ | ||
| 89 | public boolean isDeclaration() { | ||
| 90 | return this.declaration; | ||
| 91 | } | ||
| 92 | |||
| 78 | public Entry<?> getNameableEntry() { | 93 | public Entry<?> getNameableEntry() { |
| 79 | if (entry instanceof MethodEntry && ((MethodEntry) entry).isConstructor()) { | 94 | if (entry instanceof MethodEntry && ((MethodEntry) entry).isConstructor()) { |
| 80 | // renaming a constructor really means renaming the class | 95 | // renaming a constructor really means renaming the class |
| @@ -92,7 +107,7 @@ public class EntryReference<E extends Entry<?>, C extends Entry<?>> implements T | |||
| 92 | if (context != null) { | 107 | if (context != null) { |
| 93 | return Objects.hash(entry.hashCode(), context.hashCode()); | 108 | return Objects.hash(entry.hashCode(), context.hashCode()); |
| 94 | } | 109 | } |
| 95 | return entry.hashCode(); | 110 | return entry.hashCode() ^ Boolean.hashCode(this.declaration); |
| 96 | } | 111 | } |
| 97 | 112 | ||
| 98 | @Override | 113 | @Override |
| @@ -101,21 +116,10 @@ public class EntryReference<E extends Entry<?>, C extends Entry<?>> implements T | |||
| 101 | } | 116 | } |
| 102 | 117 | ||
| 103 | public boolean equals(EntryReference<?, ?> other) { | 118 | public boolean equals(EntryReference<?, ?> other) { |
| 104 | if (other == null) return false; | 119 | return other != null |
| 105 | 120 | && Objects.equals(entry, other.entry) | |
| 106 | // check entry first | 121 | && Objects.equals(context, other.context) |
| 107 | boolean isEntrySame = entry.equals(other.entry); | 122 | && declaration == other.declaration; |
| 108 | if (!isEntrySame) { | ||
| 109 | return false; | ||
| 110 | } | ||
| 111 | |||
| 112 | // check caller | ||
| 113 | if (context == null && other.context == null) { | ||
| 114 | return true; | ||
| 115 | } else if (context != null && other.context != null) { | ||
| 116 | return context.equals(other.context); | ||
| 117 | } | ||
| 118 | return false; | ||
| 119 | } | 123 | } |
| 120 | 124 | ||
| 121 | @Override | 125 | @Override |
| @@ -123,6 +127,11 @@ public class EntryReference<E extends Entry<?>, C extends Entry<?>> implements T | |||
| 123 | StringBuilder buf = new StringBuilder(); | 127 | StringBuilder buf = new StringBuilder(); |
| 124 | buf.append(entry); | 128 | buf.append(entry); |
| 125 | 129 | ||
| 130 | if (declaration) { | ||
| 131 | buf.append("'s declaration"); | ||
| 132 | return buf.toString(); | ||
| 133 | } | ||
| 134 | |||
| 126 | if (context != null) { | 135 | if (context != null) { |
| 127 | buf.append(" called from "); | 136 | buf.append(" called from "); |
| 128 | buf.append(context); | 137 | buf.append(context); |
diff --git a/enigma/src/main/java/cuchaz/enigma/source/SourceIndex.java b/enigma/src/main/java/cuchaz/enigma/source/SourceIndex.java index 178ce20e..ed6cfb94 100644 --- a/enigma/src/main/java/cuchaz/enigma/source/SourceIndex.java +++ b/enigma/src/main/java/cuchaz/enigma/source/SourceIndex.java | |||
| @@ -88,6 +88,7 @@ public class SourceIndex { | |||
| 88 | EntryReference<Entry<?>, Entry<?>> reference = new EntryReference<>(deobfEntry, token.text); | 88 | EntryReference<Entry<?>, Entry<?>> reference = new EntryReference<>(deobfEntry, token.text); |
| 89 | tokenToReference.put(token, reference); | 89 | tokenToReference.put(token, reference); |
| 90 | referenceToTokens.put(reference, token); | 90 | referenceToTokens.put(reference, token); |
| 91 | referenceToTokens.put(EntryReference.declaration(deobfEntry, token.text), token); | ||
| 91 | declarationToToken.put(deobfEntry, token); | 92 | declarationToToken.put(deobfEntry, token); |
| 92 | } | 93 | } |
| 93 | } | 94 | } |