From 4be005617b3b8c3578cca07c5d085d12916f0d1d Mon Sep 17 00:00:00 2001
From: lclc98
Date: Thu, 30 Jun 2016 00:49:21 +1000
Subject: Json format (#2)
* Added new format
* Fixed bug
* Updated Version
---
src/main/java/cuchaz/enigma/mapping/Signature.java | 117 +++++++++++++++++++++
1 file changed, 117 insertions(+)
create mode 100644 src/main/java/cuchaz/enigma/mapping/Signature.java
(limited to 'src/main/java/cuchaz/enigma/mapping/Signature.java')
diff --git a/src/main/java/cuchaz/enigma/mapping/Signature.java b/src/main/java/cuchaz/enigma/mapping/Signature.java
new file mode 100644
index 0000000..117018a
--- /dev/null
+++ b/src/main/java/cuchaz/enigma/mapping/Signature.java
@@ -0,0 +1,117 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Jeff Martin.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the GNU Lesser General Public
+ * License v3.0 which accompanies this distribution, and is available at
+ * http://www.gnu.org/licenses/lgpl.html
+ *
+ * Contributors:
+ * Jeff Martin - initial API and implementation
+ ******************************************************************************/
+package cuchaz.enigma.mapping;
+
+import com.google.common.collect.Lists;
+
+import java.io.Serializable;
+import java.util.List;
+
+import cuchaz.enigma.Util;
+
+public class Signature implements Serializable {
+
+ private static final long serialVersionUID = -5843719505729497539L;
+
+ private List m_argumentTypes;
+ private Type m_returnType;
+
+ public Signature(String signature) {
+ try {
+ m_argumentTypes = Lists.newArrayList();
+ int i = 0;
+ while (i < signature.length()) {
+ char c = signature.charAt(i);
+ if (c == '(') {
+ assert (m_argumentTypes.isEmpty());
+ assert (m_returnType == null);
+ i++;
+ } else if (c == ')') {
+ i++;
+ break;
+ } else {
+ String type = Type.parseFirst(signature.substring(i));
+ m_argumentTypes.add(new Type(type));
+ i += type.length();
+ }
+ }
+ m_returnType = new Type(Type.parseFirst(signature.substring(i)));
+ } catch (Exception ex) {
+ throw new IllegalArgumentException("Unable to parse signature: " + signature, ex);
+ }
+ }
+
+ public Signature(Signature other) {
+ m_argumentTypes = Lists.newArrayList(other.m_argumentTypes);
+ m_returnType = new Type(other.m_returnType);
+ }
+
+ public Signature(Signature other, ClassNameReplacer replacer) {
+ m_argumentTypes = Lists.newArrayList(other.m_argumentTypes);
+ for (int i = 0; i < m_argumentTypes.size(); i++) {
+ m_argumentTypes.set(i, new Type(m_argumentTypes.get(i), replacer));
+ }
+ m_returnType = new Type(other.m_returnType, replacer);
+ }
+
+ public List getArgumentTypes() {
+ return m_argumentTypes;
+ }
+
+ public Type getReturnType() {
+ return m_returnType;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder buf = new StringBuilder();
+ buf.append("(");
+ for (Type type : m_argumentTypes) {
+ buf.append(type.toString());
+ }
+ buf.append(")");
+ buf.append(m_returnType.toString());
+ return buf.toString();
+ }
+
+ public Iterable types() {
+ List types = Lists.newArrayList();
+ types.addAll(m_argumentTypes);
+ types.add(m_returnType);
+ return types;
+ }
+
+ @Override
+ public boolean equals(Object other) {
+ if (other instanceof Signature) {
+ return equals((Signature) other);
+ }
+ return false;
+ }
+
+ public boolean equals(Signature other) {
+ return m_argumentTypes.equals(other.m_argumentTypes) && m_returnType.equals(other.m_returnType);
+ }
+
+ @Override
+ public int hashCode() {
+ return Util.combineHashesOrdered(m_argumentTypes.hashCode(), m_returnType.hashCode());
+ }
+
+ public boolean hasClass(ClassEntry classEntry) {
+ for (Type type : types()) {
+ if (type.hasClass() && type.getClassEntry().equals(classEntry)) {
+ return true;
+ }
+ }
+ return false;
+ }
+}
--
cgit v1.2.3