diff options
| author | 2016-06-30 00:49:21 +1000 | |
|---|---|---|
| committer | 2016-06-30 00:49:21 +1000 | |
| commit | 4be005617b3b8c3578cca07c5d085d12916f0d1d (patch) | |
| tree | db163431f38703e26da417ef05eaea2b27a498b9 /src/cuchaz/enigma/analysis/EntryReference.java | |
| parent | Some small changes to fix idea importing (diff) | |
| download | enigma-fork-4be005617b3b8c3578cca07c5d085d12916f0d1d.tar.gz enigma-fork-4be005617b3b8c3578cca07c5d085d12916f0d1d.tar.xz enigma-fork-4be005617b3b8c3578cca07c5d085d12916f0d1d.zip | |
Json format (#2)
* Added new format
* Fixed bug
* Updated Version
Diffstat (limited to 'src/cuchaz/enigma/analysis/EntryReference.java')
| -rw-r--r-- | src/cuchaz/enigma/analysis/EntryReference.java | 126 |
1 files changed, 0 insertions, 126 deletions
diff --git a/src/cuchaz/enigma/analysis/EntryReference.java b/src/cuchaz/enigma/analysis/EntryReference.java deleted file mode 100644 index 8512723..0000000 --- a/src/cuchaz/enigma/analysis/EntryReference.java +++ /dev/null | |||
| @@ -1,126 +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 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | package cuchaz.enigma.analysis; | ||
| 12 | |||
| 13 | import java.util.Arrays; | ||
| 14 | import java.util.List; | ||
| 15 | |||
| 16 | import cuchaz.enigma.Util; | ||
| 17 | import cuchaz.enigma.mapping.ClassEntry; | ||
| 18 | import cuchaz.enigma.mapping.ConstructorEntry; | ||
| 19 | import cuchaz.enigma.mapping.Entry; | ||
| 20 | |||
| 21 | public class EntryReference<E extends Entry,C extends Entry> { | ||
| 22 | |||
| 23 | private static final List<String> ConstructorNonNames = Arrays.asList("this", "super", "static"); | ||
| 24 | public E entry; | ||
| 25 | public C context; | ||
| 26 | |||
| 27 | private boolean m_isNamed; | ||
| 28 | |||
| 29 | public EntryReference(E entry, String sourceName) { | ||
| 30 | this(entry, sourceName, null); | ||
| 31 | } | ||
| 32 | |||
| 33 | public EntryReference(E entry, String sourceName, C context) { | ||
| 34 | if (entry == null) { | ||
| 35 | throw new IllegalArgumentException("Entry cannot be null!"); | ||
| 36 | } | ||
| 37 | |||
| 38 | this.entry = entry; | ||
| 39 | this.context = context; | ||
| 40 | |||
| 41 | m_isNamed = sourceName != null && sourceName.length() > 0; | ||
| 42 | if (entry instanceof ConstructorEntry && ConstructorNonNames.contains(sourceName)) { | ||
| 43 | m_isNamed = false; | ||
| 44 | } | ||
| 45 | } | ||
| 46 | |||
| 47 | public EntryReference(E entry, C context, EntryReference<E,C> other) { | ||
| 48 | this.entry = entry; | ||
| 49 | this.context = context; | ||
| 50 | m_isNamed = other.m_isNamed; | ||
| 51 | } | ||
| 52 | |||
| 53 | public ClassEntry getLocationClassEntry() { | ||
| 54 | if (context != null) { | ||
| 55 | return context.getClassEntry(); | ||
| 56 | } | ||
| 57 | return entry.getClassEntry(); | ||
| 58 | } | ||
| 59 | |||
| 60 | public boolean isNamed() { | ||
| 61 | return m_isNamed; | ||
| 62 | } | ||
| 63 | |||
| 64 | public Entry getNameableEntry() { | ||
| 65 | if (entry instanceof ConstructorEntry) { | ||
| 66 | // renaming a constructor really means renaming the class | ||
| 67 | return entry.getClassEntry(); | ||
| 68 | } | ||
| 69 | return entry; | ||
| 70 | } | ||
| 71 | |||
| 72 | public String getNamableName() { | ||
| 73 | if (getNameableEntry() instanceof ClassEntry) { | ||
| 74 | ClassEntry classEntry = (ClassEntry)getNameableEntry(); | ||
| 75 | if (classEntry.isInnerClass()) { | ||
| 76 | // make sure we only rename the inner class name | ||
| 77 | return classEntry.getInnermostClassName(); | ||
| 78 | } | ||
| 79 | } | ||
| 80 | |||
| 81 | return getNameableEntry().getName(); | ||
| 82 | } | ||
| 83 | |||
| 84 | @Override | ||
| 85 | public int hashCode() { | ||
| 86 | if (context != null) { | ||
| 87 | return Util.combineHashesOrdered(entry.hashCode(), context.hashCode()); | ||
| 88 | } | ||
| 89 | return entry.hashCode(); | ||
| 90 | } | ||
| 91 | |||
| 92 | @Override | ||
| 93 | public boolean equals(Object other) { | ||
| 94 | if (other instanceof EntryReference) { | ||
| 95 | return equals((EntryReference<?,?>)other); | ||
| 96 | } | ||
| 97 | return false; | ||
| 98 | } | ||
| 99 | |||
| 100 | public boolean equals(EntryReference<?,?> other) { | ||
| 101 | // check entry first | ||
| 102 | boolean isEntrySame = entry.equals(other.entry); | ||
| 103 | if (!isEntrySame) { | ||
| 104 | return false; | ||
| 105 | } | ||
| 106 | |||
| 107 | // check caller | ||
| 108 | if (context == null && other.context == null) { | ||
| 109 | return true; | ||
| 110 | } else if (context != null && other.context != null) { | ||
| 111 | return context.equals(other.context); | ||
| 112 | } | ||
| 113 | return false; | ||
| 114 | } | ||
| 115 | |||
| 116 | @Override | ||
| 117 | public String toString() { | ||
| 118 | StringBuilder buf = new StringBuilder(); | ||
| 119 | buf.append(entry); | ||
| 120 | if (context != null) { | ||
| 121 | buf.append(" called from "); | ||
| 122 | buf.append(context); | ||
| 123 | } | ||
| 124 | return buf.toString(); | ||
| 125 | } | ||
| 126 | } | ||