summaryrefslogtreecommitdiff
path: root/enigma
diff options
context:
space:
mode:
authorGravatar 2xsaiko2021-01-24 13:19:13 +0100
committerGravatar GitHub2021-01-24 13:19:13 +0100
commit38b46e1e2e7d60f55ee3f661560c692fe680d149 (patch)
treee64f9bd1b8b2767a05f66b35ed20185bd4ae6748 /enigma
parentMerge pull request #341 from Juuxel/structure-panel-prs/fix-switching (diff)
parentFixes open declaration not opening declaration (diff)
downloadenigma-fork-38b46e1e2e7d60f55ee3f661560c692fe680d149.tar.gz
enigma-fork-38b46e1e2e7d60f55ee3f661560c692fe680d149.tar.xz
enigma-fork-38b46e1e2e7d60f55ee3f661560c692fe680d149.zip
Merge pull request #338 from liachmodded/fix/def-browse
Fixes open declaration not opening declaration
Diffstat (limited to 'enigma')
-rw-r--r--enigma/src/main/java/cuchaz/enigma/analysis/EntryReference.java59
-rw-r--r--enigma/src/main/java/cuchaz/enigma/source/SourceIndex.java1
2 files changed, 35 insertions, 25 deletions
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;
28public class EntryReference<E extends Entry<?>, C extends Entry<?>> implements Translatable { 28public 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 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 {
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 }