From c7d7b261fd326d02cc243a431022d5b9149fdcc6 Mon Sep 17 00:00:00 2001 From: liach Date: Fri, 22 Jan 2021 16:00:30 -0600 Subject: Fixes open declaration not opening declaration Signed-off-by: liach --- .../cuchaz/enigma/analysis/EntryReference.java | 59 +++++++++++++--------- .../java/cuchaz/enigma/source/SourceIndex.java | 1 + 2 files changed, 35 insertions(+), 25 deletions(-) (limited to 'enigma') diff --git a/enigma/src/main/java/cuchaz/enigma/analysis/EntryReference.java b/enigma/src/main/java/cuchaz/enigma/analysis/EntryReference.java index cccabd0..6dd6526 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; public class EntryReference, C extends Entry> implements Translatable { private static final List CONSTRUCTOR_NON_NAMES = Arrays.asList("this", "super", "static"); - public E entry; - public C context; - public ReferenceTargetType targetType; - - private boolean sourceName; + public final E entry; + public final C context; + public final ReferenceTargetType targetType; + private final boolean declaration; // if the ref goes to the decl of the item. when true context == null + private final boolean sourceName; + + public static , C extends Entry> EntryReference declaration(E entry, String sourceName) { + return new EntryReference<>(entry, sourceName, null, ReferenceTargetType.none(), true); + } public EntryReference(E entry, String sourceName) { this(entry, sourceName, null); @@ -43,6 +47,10 @@ public class EntryReference, C extends Entry> implements T } public EntryReference(E entry, String sourceName, C context, ReferenceTargetType targetType) { + this(entry, sourceName, context, targetType, false); + } + + protected EntryReference(E entry, String sourceName, C context, ReferenceTargetType targetType, boolean declaration) { if (entry == null) { throw new IllegalArgumentException("Entry cannot be null!"); } @@ -50,11 +58,10 @@ public class EntryReference, C extends Entry> implements T this.entry = entry; this.context = context; this.targetType = targetType; + this.declaration = declaration; - this.sourceName = sourceName != null && !sourceName.isEmpty(); - if (entry instanceof MethodEntry && ((MethodEntry) entry).isConstructor() && CONSTRUCTOR_NON_NAMES.contains(sourceName)) { - this.sourceName = false; - } + this.sourceName = sourceName != null && !sourceName.isEmpty() && + !(entry instanceof MethodEntry && ((MethodEntry) entry).isConstructor() && CONSTRUCTOR_NON_NAMES.contains(sourceName)); } public EntryReference(E entry, C context, EntryReference other) { @@ -62,6 +69,7 @@ public class EntryReference, C extends Entry> implements T this.context = context; this.sourceName = other.sourceName; this.targetType = other.targetType; + this.declaration = other.declaration; } public ClassEntry getLocationClassEntry() { @@ -75,6 +83,13 @@ public class EntryReference, C extends Entry> implements T return this.sourceName; } + /** + * Returns whether this refers to the declaration of an entry. + */ + public boolean isDeclaration() { + return this.declaration; + } + public Entry getNameableEntry() { if (entry instanceof MethodEntry && ((MethodEntry) entry).isConstructor()) { // renaming a constructor really means renaming the class @@ -92,7 +107,7 @@ public class EntryReference, C extends Entry> implements T if (context != null) { return Objects.hash(entry.hashCode(), context.hashCode()); } - return entry.hashCode(); + return entry.hashCode() ^ Boolean.hashCode(this.declaration); } @Override @@ -101,21 +116,10 @@ public class EntryReference, C extends Entry> implements T } public boolean equals(EntryReference other) { - if (other == null) return false; - - // check entry first - boolean isEntrySame = entry.equals(other.entry); - if (!isEntrySame) { - return false; - } - - // check caller - if (context == null && other.context == null) { - return true; - } else if (context != null && other.context != null) { - return context.equals(other.context); - } - return false; + return other != null + && Objects.equals(entry, other.entry) + && Objects.equals(context, other.context) + && declaration == other.declaration; } @Override @@ -123,6 +127,11 @@ public class EntryReference, C extends Entry> implements T StringBuilder buf = new StringBuilder(); buf.append(entry); + if (declaration) { + buf.append("'s declaration"); + return buf.toString(); + } + if (context != null) { buf.append(" called from "); 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 178ce20..ed6cfb9 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 { EntryReference, Entry> reference = new EntryReference<>(deobfEntry, token.text); tokenToReference.put(token, reference); referenceToTokens.put(reference, token); + referenceToTokens.put(EntryReference.declaration(deobfEntry, token.text), token); declarationToToken.put(deobfEntry, token); } } -- cgit v1.2.3