diff options
Diffstat (limited to 'src/main/java/cuchaz/enigma/analysis/EntryReference.java')
| -rw-r--r-- | src/main/java/cuchaz/enigma/analysis/EntryReference.java | 140 |
1 files changed, 0 insertions, 140 deletions
diff --git a/src/main/java/cuchaz/enigma/analysis/EntryReference.java b/src/main/java/cuchaz/enigma/analysis/EntryReference.java deleted file mode 100644 index 2e738c0..0000000 --- a/src/main/java/cuchaz/enigma/analysis/EntryReference.java +++ /dev/null | |||
| @@ -1,140 +0,0 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * <p> | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | |||
| 12 | package cuchaz.enigma.analysis; | ||
| 13 | |||
| 14 | import cuchaz.enigma.translation.Translatable; | ||
| 15 | import cuchaz.enigma.translation.Translator; | ||
| 16 | import cuchaz.enigma.translation.mapping.EntryMapping; | ||
| 17 | import cuchaz.enigma.translation.mapping.EntryResolver; | ||
| 18 | import cuchaz.enigma.translation.mapping.EntryMap; | ||
| 19 | import cuchaz.enigma.translation.representation.entry.ClassEntry; | ||
| 20 | import cuchaz.enigma.translation.representation.entry.Entry; | ||
| 21 | import cuchaz.enigma.translation.representation.entry.MethodEntry; | ||
| 22 | import cuchaz.enigma.utils.Utils; | ||
| 23 | |||
| 24 | import java.util.Arrays; | ||
| 25 | import java.util.List; | ||
| 26 | |||
| 27 | public class EntryReference<E extends Entry<?>, C extends Entry<?>> implements Translatable { | ||
| 28 | |||
| 29 | private static final List<String> CONSTRUCTOR_NON_NAMES = Arrays.asList("this", "super", "static"); | ||
| 30 | public E entry; | ||
| 31 | public C context; | ||
| 32 | public ReferenceTargetType targetType; | ||
| 33 | |||
| 34 | private boolean sourceName; | ||
| 35 | |||
| 36 | public EntryReference(E entry, String sourceName) { | ||
| 37 | this(entry, sourceName, null); | ||
| 38 | } | ||
| 39 | |||
| 40 | public EntryReference(E entry, String sourceName, C context) { | ||
| 41 | this(entry, sourceName, context, ReferenceTargetType.none()); | ||
| 42 | } | ||
| 43 | |||
| 44 | public EntryReference(E entry, String sourceName, C context, ReferenceTargetType targetType) { | ||
| 45 | if (entry == null) { | ||
| 46 | throw new IllegalArgumentException("Entry cannot be null!"); | ||
| 47 | } | ||
| 48 | |||
| 49 | this.entry = entry; | ||
| 50 | this.context = context; | ||
| 51 | this.targetType = targetType; | ||
| 52 | |||
| 53 | this.sourceName = sourceName != null && !sourceName.isEmpty(); | ||
| 54 | if (entry instanceof MethodEntry && ((MethodEntry) entry).isConstructor() && CONSTRUCTOR_NON_NAMES.contains(sourceName)) { | ||
| 55 | this.sourceName = false; | ||
| 56 | } | ||
| 57 | } | ||
| 58 | |||
| 59 | public EntryReference(E entry, C context, EntryReference<E, C> other) { | ||
| 60 | this.entry = entry; | ||
| 61 | this.context = context; | ||
| 62 | this.sourceName = other.sourceName; | ||
| 63 | this.targetType = other.targetType; | ||
| 64 | } | ||
| 65 | |||
| 66 | public ClassEntry getLocationClassEntry() { | ||
| 67 | if (context != null) { | ||
| 68 | return context.getContainingClass(); | ||
| 69 | } | ||
| 70 | return entry.getContainingClass(); | ||
| 71 | } | ||
| 72 | |||
| 73 | public boolean isNamed() { | ||
| 74 | return this.sourceName; | ||
| 75 | } | ||
| 76 | |||
| 77 | public Entry<?> getNameableEntry() { | ||
| 78 | if (entry instanceof MethodEntry && ((MethodEntry) entry).isConstructor()) { | ||
| 79 | // renaming a constructor really means renaming the class | ||
| 80 | return entry.getContainingClass(); | ||
| 81 | } | ||
| 82 | return entry; | ||
| 83 | } | ||
| 84 | |||
| 85 | public String getNameableName() { | ||
| 86 | return getNameableEntry().getName(); | ||
| 87 | } | ||
| 88 | |||
| 89 | @Override | ||
| 90 | public int hashCode() { | ||
| 91 | if (context != null) { | ||
| 92 | return Utils.combineHashesOrdered(entry.hashCode(), context.hashCode()); | ||
| 93 | } | ||
| 94 | return entry.hashCode(); | ||
| 95 | } | ||
| 96 | |||
| 97 | @Override | ||
| 98 | public boolean equals(Object other) { | ||
| 99 | return other instanceof EntryReference && equals((EntryReference<?, ?>) other); | ||
| 100 | } | ||
| 101 | |||
| 102 | public boolean equals(EntryReference<?, ?> other) { | ||
| 103 | // check entry first | ||
| 104 | boolean isEntrySame = entry.equals(other.entry); | ||
| 105 | if (!isEntrySame) { | ||
| 106 | return false; | ||
| 107 | } | ||
| 108 | |||
| 109 | // check caller | ||
| 110 | if (context == null && other.context == null) { | ||
| 111 | return true; | ||
| 112 | } else if (context != null && other.context != null) { | ||
| 113 | return context.equals(other.context); | ||
| 114 | } | ||
| 115 | return false; | ||
| 116 | } | ||
| 117 | |||
| 118 | @Override | ||
| 119 | public String toString() { | ||
| 120 | StringBuilder buf = new StringBuilder(); | ||
| 121 | buf.append(entry); | ||
| 122 | |||
| 123 | if (context != null) { | ||
| 124 | buf.append(" called from "); | ||
| 125 | buf.append(context); | ||
| 126 | } | ||
| 127 | |||
| 128 | if (targetType != null && targetType.getKind() != ReferenceTargetType.Kind.NONE) { | ||
| 129 | buf.append(" on target of type "); | ||
| 130 | buf.append(targetType); | ||
| 131 | } | ||
| 132 | |||
| 133 | return buf.toString(); | ||
| 134 | } | ||
| 135 | |||
| 136 | @Override | ||
| 137 | public Translatable translate(Translator translator, EntryResolver resolver, EntryMap<EntryMapping> mappings) { | ||
| 138 | return new EntryReference<>(translator.translate(entry), translator.translate(context), this); | ||
| 139 | } | ||
| 140 | } | ||