From 0f47403d0220757fed189b76e2071e25b1025cb8 Mon Sep 17 00:00:00 2001 From: Runemoro Date: Wed, 3 Jun 2020 13:39:42 -0400 Subject: Split GUI code to separate module (#242) * Split into modules * Post merge compile fixes Co-authored-by: modmuss50 --- .../translation/representation/AccessFlags.java | 116 --------- .../enigma/translation/representation/Lambda.java | 105 -------- .../representation/MethodDescriptor.java | 132 ---------- .../translation/representation/Signature.java | 98 -------- .../translation/representation/TypeDescriptor.java | 268 --------------------- .../representation/entry/ClassDefEntry.java | 93 ------- .../representation/entry/ClassEntry.java | 214 ---------------- .../translation/representation/entry/DefEntry.java | 7 - .../translation/representation/entry/Entry.java | 107 -------- .../representation/entry/FieldDefEntry.java | 71 ------ .../representation/entry/FieldEntry.java | 96 -------- .../entry/LocalVariableDefEntry.java | 51 ---- .../representation/entry/LocalVariableEntry.java | 93 ------- .../representation/entry/MethodDefEntry.java | 71 ------ .../representation/entry/MethodEntry.java | 105 -------- .../representation/entry/ParentedEntry.java | 82 ------- 16 files changed, 1709 deletions(-) delete mode 100644 src/main/java/cuchaz/enigma/translation/representation/AccessFlags.java delete mode 100644 src/main/java/cuchaz/enigma/translation/representation/Lambda.java delete mode 100644 src/main/java/cuchaz/enigma/translation/representation/MethodDescriptor.java delete mode 100644 src/main/java/cuchaz/enigma/translation/representation/Signature.java delete mode 100644 src/main/java/cuchaz/enigma/translation/representation/TypeDescriptor.java delete mode 100644 src/main/java/cuchaz/enigma/translation/representation/entry/ClassDefEntry.java delete mode 100644 src/main/java/cuchaz/enigma/translation/representation/entry/ClassEntry.java delete mode 100644 src/main/java/cuchaz/enigma/translation/representation/entry/DefEntry.java delete mode 100644 src/main/java/cuchaz/enigma/translation/representation/entry/Entry.java delete mode 100644 src/main/java/cuchaz/enigma/translation/representation/entry/FieldDefEntry.java delete mode 100644 src/main/java/cuchaz/enigma/translation/representation/entry/FieldEntry.java delete mode 100644 src/main/java/cuchaz/enigma/translation/representation/entry/LocalVariableDefEntry.java delete mode 100644 src/main/java/cuchaz/enigma/translation/representation/entry/LocalVariableEntry.java delete mode 100644 src/main/java/cuchaz/enigma/translation/representation/entry/MethodDefEntry.java delete mode 100644 src/main/java/cuchaz/enigma/translation/representation/entry/MethodEntry.java delete mode 100644 src/main/java/cuchaz/enigma/translation/representation/entry/ParentedEntry.java (limited to 'src/main/java/cuchaz/enigma/translation/representation') diff --git a/src/main/java/cuchaz/enigma/translation/representation/AccessFlags.java b/src/main/java/cuchaz/enigma/translation/representation/AccessFlags.java deleted file mode 100644 index b280eef..0000000 --- a/src/main/java/cuchaz/enigma/translation/representation/AccessFlags.java +++ /dev/null @@ -1,116 +0,0 @@ -package cuchaz.enigma.translation.representation; - -import cuchaz.enigma.analysis.Access; -import org.objectweb.asm.Opcodes; - -import java.lang.reflect.Modifier; - -public class AccessFlags { - public static final AccessFlags PRIVATE = new AccessFlags(Opcodes.ACC_PRIVATE); - public static final AccessFlags PUBLIC = new AccessFlags(Opcodes.ACC_PUBLIC); - - private int flags; - - public AccessFlags(int flags) { - this.flags = flags; - } - - public boolean isPrivate() { - return Modifier.isPrivate(this.flags); - } - - public boolean isProtected() { - return Modifier.isProtected(this.flags); - } - - public boolean isPublic() { - return Modifier.isPublic(this.flags); - } - - public boolean isSynthetic() { - return (this.flags & Opcodes.ACC_SYNTHETIC) != 0; - } - - public boolean isStatic() { - return Modifier.isStatic(this.flags); - } - - public boolean isEnum() { - return (flags & Opcodes.ACC_ENUM) != 0; - } - - public boolean isBridge() { - return (flags & Opcodes.ACC_BRIDGE) != 0; - } - - public boolean isFinal() { - return (flags & Opcodes.ACC_FINAL) != 0; - } - - public boolean isInterface() { - return (flags & Opcodes.ACC_INTERFACE) != 0; - } - - public AccessFlags setPrivate() { - this.setVisibility(Opcodes.ACC_PRIVATE); - return this; - } - - public AccessFlags setProtected() { - this.setVisibility(Opcodes.ACC_PROTECTED); - return this; - } - - public AccessFlags setPublic() { - this.setVisibility(Opcodes.ACC_PUBLIC); - return this; - } - - public AccessFlags setBridge() { - flags |= Opcodes.ACC_BRIDGE; - return this; - } - - @Deprecated - public AccessFlags setBridged() { - return setBridge(); - } - - public void setVisibility(int visibility) { - this.resetVisibility(); - this.flags |= visibility; - } - - private void resetVisibility() { - this.flags &= ~(Opcodes.ACC_PRIVATE | Opcodes.ACC_PROTECTED | Opcodes.ACC_PUBLIC); - } - - public int getFlags() { - return this.flags; - } - - @Override - public boolean equals(Object obj) { - return obj instanceof AccessFlags && ((AccessFlags) obj).flags == flags; - } - - @Override - public int hashCode() { - return flags; - } - - @Override - public String toString() { - StringBuilder builder = new StringBuilder(Access.get(this).toString().toLowerCase()); - if (isStatic()) { - builder.append(" static"); - } - if (isSynthetic()) { - builder.append(" synthetic"); - } - if (isBridge()) { - builder.append(" bridge"); - } - return builder.toString(); - } -} diff --git a/src/main/java/cuchaz/enigma/translation/representation/Lambda.java b/src/main/java/cuchaz/enigma/translation/representation/Lambda.java deleted file mode 100644 index 63eb563..0000000 --- a/src/main/java/cuchaz/enigma/translation/representation/Lambda.java +++ /dev/null @@ -1,105 +0,0 @@ -package cuchaz.enigma.translation.representation; - -import cuchaz.enigma.translation.Translatable; -import cuchaz.enigma.translation.Translator; -import cuchaz.enigma.translation.mapping.EntryMap; -import cuchaz.enigma.translation.mapping.EntryMapping; -import cuchaz.enigma.translation.mapping.EntryResolver; -import cuchaz.enigma.translation.mapping.ResolutionStrategy; -import cuchaz.enigma.translation.representation.entry.ClassEntry; -import cuchaz.enigma.translation.representation.entry.MethodEntry; -import cuchaz.enigma.translation.representation.entry.ParentedEntry; - -import java.util.Objects; - -public class Lambda implements Translatable { - private final String invokedName; - private final MethodDescriptor invokedType; - private final MethodDescriptor samMethodType; - private final ParentedEntry implMethod; - private final MethodDescriptor instantiatedMethodType; - - public Lambda(String invokedName, MethodDescriptor invokedType, MethodDescriptor samMethodType, ParentedEntry implMethod, MethodDescriptor instantiatedMethodType) { - this.invokedName = invokedName; - this.invokedType = invokedType; - this.samMethodType = samMethodType; - this.implMethod = implMethod; - this.instantiatedMethodType = instantiatedMethodType; - } - - @Override - public Lambda translate(Translator translator, EntryResolver resolver, EntryMap mappings) { - MethodEntry samMethod = new MethodEntry(getInterface(), invokedName, samMethodType); - EntryMapping samMethodMapping = resolveMapping(resolver, mappings, samMethod); - - return new Lambda( - samMethodMapping != null ? samMethodMapping.getTargetName() : invokedName, - invokedType.translate(translator, resolver, mappings), - samMethodType.translate(translator, resolver, mappings), - implMethod.translate(translator, resolver, mappings), - instantiatedMethodType.translate(translator, resolver, mappings) - ); - } - - private EntryMapping resolveMapping(EntryResolver resolver, EntryMap mappings, MethodEntry methodEntry) { - for (MethodEntry entry : resolver.resolveEntry(methodEntry, ResolutionStrategy.RESOLVE_ROOT)) { - EntryMapping mapping = mappings.get(entry); - if (mapping != null) { - return mapping; - } - } - return null; - } - - public ClassEntry getInterface() { - return invokedType.getReturnDesc().getTypeEntry(); - } - - public String getInvokedName() { - return invokedName; - } - - public MethodDescriptor getInvokedType() { - return invokedType; - } - - public MethodDescriptor getSamMethodType() { - return samMethodType; - } - - public ParentedEntry getImplMethod() { - return implMethod; - } - - public MethodDescriptor getInstantiatedMethodType() { - return instantiatedMethodType; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - Lambda lambda = (Lambda) o; - return Objects.equals(invokedName, lambda.invokedName) && - Objects.equals(invokedType, lambda.invokedType) && - Objects.equals(samMethodType, lambda.samMethodType) && - Objects.equals(implMethod, lambda.implMethod) && - Objects.equals(instantiatedMethodType, lambda.instantiatedMethodType); - } - - @Override - public int hashCode() { - return Objects.hash(invokedName, invokedType, samMethodType, implMethod, instantiatedMethodType); - } - - @Override - public String toString() { - return "Lambda{" + - "invokedName='" + invokedName + '\'' + - ", invokedType=" + invokedType + - ", samMethodType=" + samMethodType + - ", implMethod=" + implMethod + - ", instantiatedMethodType=" + instantiatedMethodType + - '}'; - } -} diff --git a/src/main/java/cuchaz/enigma/translation/representation/MethodDescriptor.java b/src/main/java/cuchaz/enigma/translation/representation/MethodDescriptor.java deleted file mode 100644 index 37a7014..0000000 --- a/src/main/java/cuchaz/enigma/translation/representation/MethodDescriptor.java +++ /dev/null @@ -1,132 +0,0 @@ -/******************************************************************************* - * 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.translation.representation; - -import com.google.common.collect.Lists; -import cuchaz.enigma.translation.Translatable; -import cuchaz.enigma.translation.Translator; -import cuchaz.enigma.translation.mapping.EntryMapping; -import cuchaz.enigma.translation.mapping.EntryResolver; -import cuchaz.enigma.translation.mapping.EntryMap; -import cuchaz.enigma.translation.representation.entry.ClassEntry; -import cuchaz.enigma.utils.Utils; - -import java.util.ArrayList; -import java.util.List; -import java.util.function.Function; - -public class MethodDescriptor implements Translatable { - - private List argumentDescs; - private TypeDescriptor returnDesc; - - public MethodDescriptor(String desc) { - try { - this.argumentDescs = Lists.newArrayList(); - int i = 0; - while (i < desc.length()) { - char c = desc.charAt(i); - if (c == '(') { - assert (this.argumentDescs.isEmpty()); - assert (this.returnDesc == null); - i++; - } else if (c == ')') { - i++; - break; - } else { - String type = TypeDescriptor.parseFirst(desc.substring(i)); - this.argumentDescs.add(new TypeDescriptor(type)); - i += type.length(); - } - } - this.returnDesc = new TypeDescriptor(TypeDescriptor.parseFirst(desc.substring(i))); - } catch (Exception ex) { - throw new IllegalArgumentException("Unable to parse method descriptor: " + desc, ex); - } - } - - public MethodDescriptor(List argumentDescs, TypeDescriptor returnDesc) { - this.argumentDescs = argumentDescs; - this.returnDesc = returnDesc; - } - - public List getArgumentDescs() { - return this.argumentDescs; - } - - public TypeDescriptor getReturnDesc() { - return this.returnDesc; - } - - @Override - public String toString() { - StringBuilder buf = new StringBuilder(); - buf.append("("); - for (TypeDescriptor desc : this.argumentDescs) { - buf.append(desc); - } - buf.append(")"); - buf.append(this.returnDesc); - return buf.toString(); - } - - public Iterable types() { - List descs = Lists.newArrayList(); - descs.addAll(this.argumentDescs); - descs.add(this.returnDesc); - return descs; - } - - @Override - public boolean equals(Object other) { - return other instanceof MethodDescriptor && equals((MethodDescriptor) other); - } - - public boolean equals(MethodDescriptor other) { - return this.argumentDescs.equals(other.argumentDescs) && this.returnDesc.equals(other.returnDesc); - } - - @Override - public int hashCode() { - return Utils.combineHashesOrdered(this.argumentDescs.hashCode(), this.returnDesc.hashCode()); - } - - public boolean hasClass(ClassEntry classEntry) { - for (TypeDescriptor desc : types()) { - if (desc.containsType() && desc.getTypeEntry().equals(classEntry)) { - return true; - } - } - return false; - } - - public MethodDescriptor remap(Function remapper) { - List argumentDescs = new ArrayList<>(this.argumentDescs.size()); - for (TypeDescriptor desc : this.argumentDescs) { - argumentDescs.add(desc.remap(remapper)); - } - return new MethodDescriptor(argumentDescs, returnDesc.remap(remapper)); - } - - @Override - public MethodDescriptor translate(Translator translator, EntryResolver resolver, EntryMap mappings) { - List translatedArguments = new ArrayList<>(argumentDescs.size()); - for (TypeDescriptor argument : argumentDescs) { - translatedArguments.add(translator.translate(argument)); - } - return new MethodDescriptor(translatedArguments, translator.translate(returnDesc)); - } - - public boolean canConflictWith(MethodDescriptor descriptor) { - return descriptor.argumentDescs.equals(argumentDescs); - } -} diff --git a/src/main/java/cuchaz/enigma/translation/representation/Signature.java b/src/main/java/cuchaz/enigma/translation/representation/Signature.java deleted file mode 100644 index 424088a..0000000 --- a/src/main/java/cuchaz/enigma/translation/representation/Signature.java +++ /dev/null @@ -1,98 +0,0 @@ -package cuchaz.enigma.translation.representation; - -import cuchaz.enigma.bytecode.translators.TranslationSignatureVisitor; -import cuchaz.enigma.translation.Translatable; -import cuchaz.enigma.translation.Translator; -import cuchaz.enigma.translation.mapping.EntryMap; -import cuchaz.enigma.translation.mapping.EntryMapping; -import cuchaz.enigma.translation.mapping.EntryResolver; -import cuchaz.enigma.translation.representation.entry.ClassEntry; -import org.objectweb.asm.signature.SignatureReader; -import org.objectweb.asm.signature.SignatureVisitor; -import org.objectweb.asm.signature.SignatureWriter; - -import java.util.function.Function; -import java.util.regex.Pattern; - -public class Signature implements Translatable { - private static final Pattern OBJECT_PATTERN = Pattern.compile(".*:Ljava/lang/Object;:.*"); - - private final String signature; - private final boolean isType; - - private Signature(String signature, boolean isType) { - if (signature != null && OBJECT_PATTERN.matcher(signature).matches()) { - signature = signature.replaceAll(":Ljava/lang/Object;:", "::"); - } - - this.signature = signature; - this.isType = isType; - } - - public static Signature createTypedSignature(String signature) { - if (signature != null && !signature.isEmpty()) { - return new Signature(signature, true); - } - return new Signature(null, true); - } - - public static Signature createSignature(String signature) { - if (signature != null && !signature.isEmpty()) { - return new Signature(signature, false); - } - return new Signature(null, false); - } - - public String getSignature() { - return signature; - } - - public boolean isType() { - return isType; - } - - public Signature remap(Function remapper) { - if (signature == null) { - return this; - } - SignatureWriter writer = new SignatureWriter(); - SignatureVisitor visitor = new TranslationSignatureVisitor(remapper, writer); - if (isType) { - new SignatureReader(signature).acceptType(visitor); - } else { - new SignatureReader(signature).accept(visitor); - } - return new Signature(writer.toString(), isType); - } - - @Override - public boolean equals(Object obj) { - if (obj instanceof Signature) { - Signature other = (Signature) obj; - return (other.signature == null && signature == null || other.signature != null - && signature != null && other.signature.equals(signature)) - && other.isType == this.isType; - } - return false; - } - - @Override - public int hashCode() { - int hash = (isType ? 1 : 0) << 16; - if (signature != null) { - hash |= signature.hashCode(); - } - - return hash; - } - - @Override - public String toString() { - return signature; - } - - @Override - public Translatable translate(Translator translator, EntryResolver resolver, EntryMap mappings) { - return remap(name -> translator.translate(new ClassEntry(name)).getFullName()); - } -} diff --git a/src/main/java/cuchaz/enigma/translation/representation/TypeDescriptor.java b/src/main/java/cuchaz/enigma/translation/representation/TypeDescriptor.java deleted file mode 100644 index f7ba849..0000000 --- a/src/main/java/cuchaz/enigma/translation/representation/TypeDescriptor.java +++ /dev/null @@ -1,268 +0,0 @@ -/******************************************************************************* - * 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.translation.representation; - -import com.google.common.base.Preconditions; -import com.google.common.collect.Maps; -import cuchaz.enigma.translation.Translatable; -import cuchaz.enigma.translation.Translator; -import cuchaz.enigma.translation.mapping.EntryMapping; -import cuchaz.enigma.translation.mapping.EntryResolver; -import cuchaz.enigma.translation.mapping.EntryMap; -import cuchaz.enigma.translation.representation.entry.ClassEntry; - -import java.util.Map; -import java.util.function.Function; - -public class TypeDescriptor implements Translatable { - - protected final String desc; - - public TypeDescriptor(String desc) { - Preconditions.checkNotNull(desc, "Desc cannot be null"); - - // don't deal with generics - // this is just for raw jvm types - if (desc.charAt(0) == 'T' || desc.indexOf('<') >= 0 || desc.indexOf('>') >= 0) { - throw new IllegalArgumentException("don't use with generic types or templates: " + desc); - } - - this.desc = desc; - } - - public static String parseFirst(String in) { - - if (in == null || in.length() <= 0) { - throw new IllegalArgumentException("No desc to parse, input is empty!"); - } - - // read one desc from the input - - char c = in.charAt(0); - - // first check for void - if (c == 'V') { - return "V"; - } - - // then check for primitives - Primitive primitive = Primitive.get(c); - if (primitive != null) { - return in.substring(0, 1); - } - - // then check for classes - if (c == 'L') { - return readClass(in); - } - - // then check for templates - if (c == 'T') { - return readClass(in); - } - - // then check for arrays - int dim = countArrayDimension(in); - if (dim > 0) { - String arrayType = TypeDescriptor.parseFirst(in.substring(dim)); - return in.substring(0, dim + arrayType.length()); - } - - throw new IllegalArgumentException("don't know how to parse: " + in); - } - - private static int countArrayDimension(String in) { - int i = 0; - while (i < in.length() && in.charAt(i) == '[') - i++; - return i; - } - - private static String readClass(String in) { - // read all the characters in the buffer until we hit a ';' - // include the parameters too - StringBuilder buf = new StringBuilder(); - int depth = 0; - for (int i = 0; i < in.length(); i++) { - char c = in.charAt(i); - buf.append(c); - - if (c == '<') { - depth++; - } else if (c == '>') { - depth--; - } else if (depth == 0 && c == ';') { - return buf.toString(); - } - } - return null; - } - - public static TypeDescriptor of(String name) { - return new TypeDescriptor("L" + name + ";"); - } - - @Override - public String toString() { - return this.desc; - } - - public boolean isVoid() { - return this.desc.length() == 1 && this.desc.charAt(0) == 'V'; - } - - public boolean isPrimitive() { - return this.desc.length() == 1 && Primitive.get(this.desc.charAt(0)) != null; - } - - public Primitive getPrimitive() { - if (!isPrimitive()) { - throw new IllegalStateException("not a primitive"); - } - return Primitive.get(this.desc.charAt(0)); - } - - public boolean isType() { - return this.desc.charAt(0) == 'L' && this.desc.charAt(this.desc.length() - 1) == ';'; - } - - public ClassEntry getTypeEntry() { - if (isType()) { - String name = this.desc.substring(1, this.desc.length() - 1); - - int pos = name.indexOf('<'); - if (pos >= 0) { - // remove the parameters from the class name - name = name.substring(0, pos); - } - - return new ClassEntry(name); - - } else if (isArray() && getArrayType().isType()) { - return getArrayType().getTypeEntry(); - } else { - throw new IllegalStateException("desc doesn't have a class"); - } - } - - public boolean isArray() { - return this.desc.charAt(0) == '['; - } - - public int getArrayDimension() { - if (!isArray()) { - throw new IllegalStateException("not an array"); - } - return countArrayDimension(this.desc); - } - - public TypeDescriptor getArrayType() { - if (!isArray()) { - throw new IllegalStateException("not an array"); - } - return new TypeDescriptor(this.desc.substring(getArrayDimension())); - } - - public boolean containsType() { - return isType() || (isArray() && getArrayType().containsType()); - } - - @Override - public boolean equals(Object other) { - return other instanceof TypeDescriptor && equals((TypeDescriptor) other); - } - - public boolean equals(TypeDescriptor other) { - return this.desc.equals(other.desc); - } - - @Override - public int hashCode() { - return this.desc.hashCode(); - } - - public TypeDescriptor remap(Function remapper) { - String desc = this.desc; - if (isType() || (isArray() && containsType())) { - String replacedName = remapper.apply(this.getTypeEntry().getFullName()); - if (replacedName != null) { - if (this.isType()) { - desc = "L" + replacedName + ";"; - } else { - desc = getArrayPrefix(this.getArrayDimension()) + "L" + replacedName + ";"; - } - } - } - return new TypeDescriptor(desc); - } - - private static String getArrayPrefix(int dimension) { - StringBuilder buf = new StringBuilder(); - for (int i = 0; i < dimension; i++) { - buf.append("["); - } - return buf.toString(); - } - - public int getSize() { - switch (desc.charAt(0)) { - case 'J': - case 'D': - if (desc.length() == 1) { - return 2; - } else { - return 1; - } - default: - return 1; - } - } - - @Override - public Translatable translate(Translator translator, EntryResolver resolver, EntryMap mappings) { - return remap(name -> translator.translate(new ClassEntry(name)).getFullName()); - } - - public enum Primitive { - BYTE('B'), - CHARACTER('C'), - SHORT('S'), - INTEGER('I'), - LONG('J'), - FLOAT('F'), - DOUBLE('D'), - BOOLEAN('Z'); - - private static final Map lookup; - - static { - lookup = Maps.newTreeMap(); - for (Primitive val : values()) { - lookup.put(val.getCode(), val); - } - } - - private char code; - - Primitive(char code) { - this.code = code; - } - - public static Primitive get(char code) { - return lookup.get(code); - } - - public char getCode() { - return this.code; - } - } -} diff --git a/src/main/java/cuchaz/enigma/translation/representation/entry/ClassDefEntry.java b/src/main/java/cuchaz/enigma/translation/representation/entry/ClassDefEntry.java deleted file mode 100644 index 6930765..0000000 --- a/src/main/java/cuchaz/enigma/translation/representation/entry/ClassDefEntry.java +++ /dev/null @@ -1,93 +0,0 @@ -/******************************************************************************* - * 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.translation.representation.entry; - -import com.google.common.base.Preconditions; -import cuchaz.enigma.translation.Translator; -import cuchaz.enigma.translation.mapping.EntryMapping; -import cuchaz.enigma.translation.representation.AccessFlags; -import cuchaz.enigma.translation.representation.Signature; - -import javax.annotation.Nullable; -import java.util.Arrays; - -public class ClassDefEntry extends ClassEntry implements DefEntry { - private final AccessFlags access; - private final Signature signature; - private final ClassEntry superClass; - private final ClassEntry[] interfaces; - - public ClassDefEntry(String className, Signature signature, AccessFlags access, @Nullable ClassEntry superClass, ClassEntry[] interfaces) { - this(getOuterClass(className), getInnerName(className), signature, access, superClass, interfaces, null); - } - - public ClassDefEntry(ClassEntry parent, String className, Signature signature, AccessFlags access, @Nullable ClassEntry superClass, ClassEntry[] interfaces) { - this(parent, className, signature, access, superClass, interfaces, null); - } - - public ClassDefEntry(ClassEntry parent, String className, Signature signature, AccessFlags access, @Nullable ClassEntry superClass, - ClassEntry[] interfaces, String javadocs) { - super(parent, className, javadocs); - Preconditions.checkNotNull(signature, "Class signature cannot be null"); - Preconditions.checkNotNull(access, "Class access cannot be null"); - - this.signature = signature; - this.access = access; - this.superClass = superClass; - this.interfaces = interfaces != null ? interfaces : new ClassEntry[0]; - } - - public static ClassDefEntry parse(int access, String name, String signature, String superName, String[] interfaces) { - ClassEntry superClass = superName != null ? new ClassEntry(superName) : null; - ClassEntry[] interfaceClasses = Arrays.stream(interfaces).map(ClassEntry::new).toArray(ClassEntry[]::new); - return new ClassDefEntry(name, Signature.createSignature(signature), new AccessFlags(access), superClass, interfaceClasses); - } - - public Signature getSignature() { - return signature; - } - - @Override - public AccessFlags getAccess() { - return access; - } - - @Nullable - public ClassEntry getSuperClass() { - return superClass; - } - - public ClassEntry[] getInterfaces() { - return interfaces; - } - - @Override - public ClassDefEntry translate(Translator translator, @Nullable EntryMapping mapping) { - Signature translatedSignature = translator.translate(signature); - String translatedName = mapping != null ? mapping.getTargetName() : name; - AccessFlags translatedAccess = mapping != null ? mapping.getAccessModifier().transform(access) : access; - ClassEntry translatedSuper = translator.translate(superClass); - ClassEntry[] translatedInterfaces = Arrays.stream(interfaces).map(translator::translate).toArray(ClassEntry[]::new); - String docs = mapping != null ? mapping.getJavadoc() : null; - return new ClassDefEntry(parent, translatedName, translatedSignature, translatedAccess, translatedSuper, translatedInterfaces, docs); - } - - @Override - public ClassDefEntry withName(String name) { - return new ClassDefEntry(parent, name, signature, access, superClass, interfaces, javadocs); - } - - @Override - public ClassDefEntry withParent(ClassEntry parent) { - return new ClassDefEntry(parent, name, signature, access, superClass, interfaces, javadocs); - } -} diff --git a/src/main/java/cuchaz/enigma/translation/representation/entry/ClassEntry.java b/src/main/java/cuchaz/enigma/translation/representation/entry/ClassEntry.java deleted file mode 100644 index d6171f1..0000000 --- a/src/main/java/cuchaz/enigma/translation/representation/entry/ClassEntry.java +++ /dev/null @@ -1,214 +0,0 @@ -/******************************************************************************* - * 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.translation.representation.entry; - -import cuchaz.enigma.throwables.IllegalNameException; -import cuchaz.enigma.translation.Translator; -import cuchaz.enigma.translation.mapping.EntryMapping; -import cuchaz.enigma.translation.mapping.NameValidator; -import cuchaz.enigma.translation.representation.TypeDescriptor; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; -import java.util.List; -import java.util.Objects; - -public class ClassEntry extends ParentedEntry implements Comparable { - private final String fullName; - - public ClassEntry(String className) { - this(getOuterClass(className), getInnerName(className), null); - } - - public ClassEntry(@Nullable ClassEntry parent, String className) { - this(parent, className, null); - } - - public ClassEntry(@Nullable ClassEntry parent, String className, @Nullable String javadocs) { - super(parent, className, javadocs); - if (parent != null) { - fullName = parent.getFullName() + "$" + name; - } else { - fullName = name; - } - - if (parent == null && className.indexOf('.') >= 0) { - throw new IllegalArgumentException("Class name must be in JVM format. ie, path/to/package/class$inner : " + className); - } - } - - @Override - public Class getParentType() { - return ClassEntry.class; - } - - @Override - public String getName() { - return this.name; - } - - public String getFullName() { - return fullName; - } - - @Override - public ClassEntry translate(Translator translator, @Nullable EntryMapping mapping) { - if (name.charAt(0) == '[') { - String translatedName = translator.translate(new TypeDescriptor(name)).toString(); - return new ClassEntry(parent, translatedName); - } - - String translatedName = mapping != null ? mapping.getTargetName() : name; - String docs = mapping != null ? mapping.getJavadoc() : null; - return new ClassEntry(parent, translatedName, docs); - } - - @Override - public ClassEntry getContainingClass() { - return this; - } - - @Override - public int hashCode() { - return fullName.hashCode(); - } - - @Override - public boolean equals(Object other) { - return other instanceof ClassEntry && equals((ClassEntry) other); - } - - public boolean equals(ClassEntry other) { - return other != null && Objects.equals(parent, other.parent) && this.name.equals(other.name); - } - - @Override - public boolean canConflictWith(Entry entry) { - return true; - } - - @Override - public void validateName(String name) throws IllegalNameException { - NameValidator.validateClassName(name); - } - - @Override - public ClassEntry withName(String name) { - return new ClassEntry(parent, name, javadocs); - } - - @Override - public ClassEntry withParent(ClassEntry parent) { - return new ClassEntry(parent, name, javadocs); - } - - @Override - public String toString() { - return getFullName(); - } - - public String getPackageName() { - return getPackageName(fullName); - } - - public String getSimpleName() { - int packagePos = name.lastIndexOf('/'); - if (packagePos > 0) { - return name.substring(packagePos + 1); - } - return name; - } - - public boolean isInnerClass() { - return parent != null; - } - - @Nullable - public ClassEntry getOuterClass() { - return parent; - } - - @Nonnull - public ClassEntry getOutermostClass() { - if (parent == null) { - return this; - } - return parent.getOutermostClass(); - } - - public ClassEntry buildClassEntry(List classChain) { - assert (classChain.contains(this)); - StringBuilder buf = new StringBuilder(); - for (ClassEntry chainEntry : classChain) { - if (buf.length() == 0) { - buf.append(chainEntry.getFullName()); - } else { - buf.append("$"); - buf.append(chainEntry.getSimpleName()); - } - - if (chainEntry == this) { - break; - } - } - return new ClassEntry(buf.toString()); - } - - public boolean isJre() { - String packageName = getPackageName(); - return packageName != null && (packageName.startsWith("java") || packageName.startsWith("javax")); - } - - public static String getPackageName(String name) { - int pos = name.lastIndexOf('/'); - if (pos > 0) { - return name.substring(0, pos); - } - return null; - } - - @Nullable - public static ClassEntry getOuterClass(String name) { - int index = name.lastIndexOf('$'); - if (index >= 0) { - return new ClassEntry(name.substring(0, index)); - } - return null; - } - - public static String getInnerName(String name) { - int innerClassPos = name.lastIndexOf('$'); - if (innerClassPos > 0) { - return name.substring(innerClassPos + 1); - } - return name; - } - - @Override - public String getSourceRemapName() { - ClassEntry outerClass = getOuterClass(); - if (outerClass != null) { - return outerClass.getSourceRemapName() + "." + name; - } - return getSimpleName(); - } - - @Override - public int compareTo(ClassEntry entry) { - String fullName = getFullName(); - String otherFullName = entry.getFullName(); - if (fullName.length() != otherFullName.length()) { - return fullName.length() - otherFullName.length(); - } - return fullName.compareTo(otherFullName); - } -} diff --git a/src/main/java/cuchaz/enigma/translation/representation/entry/DefEntry.java b/src/main/java/cuchaz/enigma/translation/representation/entry/DefEntry.java deleted file mode 100644 index 82536c7..0000000 --- a/src/main/java/cuchaz/enigma/translation/representation/entry/DefEntry.java +++ /dev/null @@ -1,7 +0,0 @@ -package cuchaz.enigma.translation.representation.entry; - -import cuchaz.enigma.translation.representation.AccessFlags; - -public interface DefEntry

> extends Entry

{ - AccessFlags getAccess(); -} diff --git a/src/main/java/cuchaz/enigma/translation/representation/entry/Entry.java b/src/main/java/cuchaz/enigma/translation/representation/entry/Entry.java deleted file mode 100644 index 72b0391..0000000 --- a/src/main/java/cuchaz/enigma/translation/representation/entry/Entry.java +++ /dev/null @@ -1,107 +0,0 @@ -/******************************************************************************* - * 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.translation.representation.entry; - -import cuchaz.enigma.throwables.IllegalNameException; -import cuchaz.enigma.translation.Translatable; -import cuchaz.enigma.translation.mapping.NameValidator; - -import javax.annotation.Nullable; -import java.util.ArrayList; -import java.util.List; - -public interface Entry

> extends Translatable { - String getName(); - - String getJavadocs(); - - default String getSourceRemapName() { - return getName(); - } - - @Nullable - P getParent(); - - Class

getParentType(); - - Entry

withName(String name); - - Entry

withParent(P parent); - - boolean canConflictWith(Entry entry); - - @Nullable - default ClassEntry getContainingClass() { - P parent = getParent(); - if (parent == null) { - return null; - } - if (parent instanceof ClassEntry) { - return (ClassEntry) parent; - } - return parent.getContainingClass(); - } - - default List> getAncestry() { - P parent = getParent(); - List> entries = new ArrayList<>(); - if (parent != null) { - entries.addAll(parent.getAncestry()); - } - entries.add(this); - return entries; - } - - @Nullable - @SuppressWarnings("unchecked") - default > E findAncestor(Class type) { - List> ancestry = getAncestry(); - for (int i = ancestry.size() - 1; i >= 0; i--) { - Entry ancestor = ancestry.get(i); - if (type.isAssignableFrom(ancestor.getClass())) { - return (E) ancestor; - } - } - return null; - } - - @SuppressWarnings("unchecked") - default > Entry

replaceAncestor(E target, E replacement) { - if (replacement.equals(target)) { - return this; - } - - if (equals(target)) { - return (Entry

) replacement; - } - - P parent = getParent(); - if (parent == null) { - return this; - } - - return withParent((P) parent.replaceAncestor(target, replacement)); - } - - default void validateName(String name) throws IllegalNameException { - NameValidator.validateIdentifier(name); - } - - @SuppressWarnings("unchecked") - @Nullable - default > Entry castParent(Class parentType) { - if (parentType.equals(getParentType())) { - return (Entry) this; - } - return null; - } -} diff --git a/src/main/java/cuchaz/enigma/translation/representation/entry/FieldDefEntry.java b/src/main/java/cuchaz/enigma/translation/representation/entry/FieldDefEntry.java deleted file mode 100644 index f9282b2..0000000 --- a/src/main/java/cuchaz/enigma/translation/representation/entry/FieldDefEntry.java +++ /dev/null @@ -1,71 +0,0 @@ -/******************************************************************************* - * 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.translation.representation.entry; - -import com.google.common.base.Preconditions; -import cuchaz.enigma.translation.Translator; -import cuchaz.enigma.translation.mapping.EntryMapping; -import cuchaz.enigma.translation.representation.AccessFlags; -import cuchaz.enigma.translation.representation.Signature; -import cuchaz.enigma.translation.representation.TypeDescriptor; - -import javax.annotation.Nullable; - -public class FieldDefEntry extends FieldEntry implements DefEntry { - private final AccessFlags access; - private final Signature signature; - - public FieldDefEntry(ClassEntry owner, String name, TypeDescriptor desc, Signature signature, AccessFlags access) { - this(owner, name, desc, signature, access, null); - } - - public FieldDefEntry(ClassEntry owner, String name, TypeDescriptor desc, Signature signature, AccessFlags access, String javadocs) { - super(owner, name, desc, javadocs); - Preconditions.checkNotNull(access, "Field access cannot be null"); - Preconditions.checkNotNull(signature, "Field signature cannot be null"); - this.access = access; - this.signature = signature; - } - - public static FieldDefEntry parse(ClassEntry owner, int access, String name, String desc, String signature) { - return new FieldDefEntry(owner, name, new TypeDescriptor(desc), Signature.createTypedSignature(signature), new AccessFlags(access), null); - } - - @Override - public AccessFlags getAccess() { - return access; - } - - public Signature getSignature() { - return signature; - } - - @Override - public FieldDefEntry translate(Translator translator, @Nullable EntryMapping mapping) { - TypeDescriptor translatedDesc = translator.translate(desc); - Signature translatedSignature = translator.translate(signature); - String translatedName = mapping != null ? mapping.getTargetName() : name; - AccessFlags translatedAccess = mapping != null ? mapping.getAccessModifier().transform(access) : access; - String docs = mapping != null ? mapping.getJavadoc() : null; - return new FieldDefEntry(parent, translatedName, translatedDesc, translatedSignature, translatedAccess, docs); - } - - @Override - public FieldDefEntry withName(String name) { - return new FieldDefEntry(parent, name, desc, signature, access, javadocs); - } - - @Override - public FieldDefEntry withParent(ClassEntry owner) { - return new FieldDefEntry(owner, this.name, this.desc, signature, access, javadocs); - } -} diff --git a/src/main/java/cuchaz/enigma/translation/representation/entry/FieldEntry.java b/src/main/java/cuchaz/enigma/translation/representation/entry/FieldEntry.java deleted file mode 100644 index bef0edf..0000000 --- a/src/main/java/cuchaz/enigma/translation/representation/entry/FieldEntry.java +++ /dev/null @@ -1,96 +0,0 @@ -/******************************************************************************* - * 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.translation.representation.entry; - -import com.google.common.base.Preconditions; -import cuchaz.enigma.translation.Translator; -import cuchaz.enigma.translation.mapping.EntryMapping; -import cuchaz.enigma.translation.representation.TypeDescriptor; -import cuchaz.enigma.utils.Utils; - -import javax.annotation.Nullable; - -public class FieldEntry extends ParentedEntry implements Comparable { - protected final TypeDescriptor desc; - - public FieldEntry(ClassEntry parent, String name, TypeDescriptor desc) { - this(parent, name, desc, null); - } - - public FieldEntry(ClassEntry parent, String name, TypeDescriptor desc, String javadocs) { - super(parent, name, javadocs); - - Preconditions.checkNotNull(parent, "Owner cannot be null"); - Preconditions.checkNotNull(desc, "Field descriptor cannot be null"); - - this.desc = desc; - } - - public static FieldEntry parse(String owner, String name, String desc) { - return new FieldEntry(new ClassEntry(owner), name, new TypeDescriptor(desc), null); - } - - @Override - public Class getParentType() { - return ClassEntry.class; - } - - public TypeDescriptor getDesc() { - return this.desc; - } - - @Override - public FieldEntry withName(String name) { - return new FieldEntry(parent, name, desc, null); - } - - @Override - public FieldEntry withParent(ClassEntry parent) { - return new FieldEntry(parent, this.name, this.desc, null); - } - - @Override - protected FieldEntry translate(Translator translator, @Nullable EntryMapping mapping) { - String translatedName = mapping != null ? mapping.getTargetName() : name; - String docs = mapping != null ? mapping.getJavadoc() : null; - return new FieldEntry(parent, translatedName, translator.translate(desc), docs); - } - - @Override - public int hashCode() { - return Utils.combineHashesOrdered(this.parent, this.name, this.desc); - } - - @Override - public boolean equals(Object other) { - return other instanceof FieldEntry && equals((FieldEntry) other); - } - - public boolean equals(FieldEntry other) { - return this.parent.equals(other.parent) && name.equals(other.name) && desc.equals(other.desc); - } - - @Override - public boolean canConflictWith(Entry entry) { - return entry instanceof FieldEntry && ((FieldEntry) entry).parent.equals(parent); - } - - @Override - public String toString() { - return this.parent.getFullName() + "." + this.name + ":" + this.desc; - } - - @Override - public int compareTo(FieldEntry entry) { - return (name + desc.toString()).compareTo(entry.name + entry.desc.toString()); - } -} diff --git a/src/main/java/cuchaz/enigma/translation/representation/entry/LocalVariableDefEntry.java b/src/main/java/cuchaz/enigma/translation/representation/entry/LocalVariableDefEntry.java deleted file mode 100644 index aad4236..0000000 --- a/src/main/java/cuchaz/enigma/translation/representation/entry/LocalVariableDefEntry.java +++ /dev/null @@ -1,51 +0,0 @@ -package cuchaz.enigma.translation.representation.entry; - -import com.google.common.base.Preconditions; -import cuchaz.enigma.translation.Translator; -import cuchaz.enigma.translation.mapping.EntryMapping; -import cuchaz.enigma.translation.representation.TypeDescriptor; - -import javax.annotation.Nullable; - -/** - * TypeDescriptor... - * Created by Thog - * 19/10/2016 - */ -public class LocalVariableDefEntry extends LocalVariableEntry { - protected final TypeDescriptor desc; - - public LocalVariableDefEntry(MethodEntry ownerEntry, int index, String name, boolean parameter, TypeDescriptor desc, String javadoc) { - super(ownerEntry, index, name, parameter, javadoc); - Preconditions.checkNotNull(desc, "Variable desc cannot be null"); - - this.desc = desc; - } - - public TypeDescriptor getDesc() { - return desc; - } - - @Override - public LocalVariableDefEntry translate(Translator translator, @Nullable EntryMapping mapping) { - TypeDescriptor translatedDesc = translator.translate(desc); - String translatedName = mapping != null ? mapping.getTargetName() : name; - String javadoc = mapping != null ? mapping.getJavadoc() : javadocs; - return new LocalVariableDefEntry(parent, index, translatedName, parameter, translatedDesc, javadoc); - } - - @Override - public LocalVariableDefEntry withName(String name) { - return new LocalVariableDefEntry(parent, index, name, parameter, desc, javadocs); - } - - @Override - public LocalVariableDefEntry withParent(MethodEntry entry) { - return new LocalVariableDefEntry(entry, index, name, parameter, desc, javadocs); - } - - @Override - public String toString() { - return this.parent + "(" + this.index + ":" + this.name + ":" + this.desc + ")"; - } -} diff --git a/src/main/java/cuchaz/enigma/translation/representation/entry/LocalVariableEntry.java b/src/main/java/cuchaz/enigma/translation/representation/entry/LocalVariableEntry.java deleted file mode 100644 index 3ccb1fa..0000000 --- a/src/main/java/cuchaz/enigma/translation/representation/entry/LocalVariableEntry.java +++ /dev/null @@ -1,93 +0,0 @@ -package cuchaz.enigma.translation.representation.entry; - -import com.google.common.base.Preconditions; -import cuchaz.enigma.translation.Translator; -import cuchaz.enigma.translation.mapping.EntryMapping; -import cuchaz.enigma.utils.Utils; - -import javax.annotation.Nullable; - -/** - * TypeDescriptor... - * Created by Thog - * 19/10/2016 - */ -public class LocalVariableEntry extends ParentedEntry implements Comparable { - - protected final int index; - protected final boolean parameter; - - public LocalVariableEntry(MethodEntry parent, int index, String name, boolean parameter, String javadoc) { - super(parent, name, javadoc); - - Preconditions.checkNotNull(parent, "Variable owner cannot be null"); - Preconditions.checkArgument(index >= 0, "Index must be positive"); - - this.index = index; - this.parameter = parameter; - } - - @Override - public Class getParentType() { - return MethodEntry.class; - } - - public boolean isArgument() { - return this.parameter; - } - - public int getIndex() { - return index; - } - - @Override - public String getName() { - return this.name; - } - - @Override - public LocalVariableEntry translate(Translator translator, @Nullable EntryMapping mapping) { - String translatedName = mapping != null ? mapping.getTargetName() : name; - String javadoc = mapping != null ? mapping.getJavadoc() : null; - return new LocalVariableEntry(parent, index, translatedName, parameter, javadoc); - } - - @Override - public LocalVariableEntry withName(String name) { - return new LocalVariableEntry(parent, index, name, parameter, javadocs); - } - - @Override - public LocalVariableEntry withParent(MethodEntry parent) { - return new LocalVariableEntry(parent, index, name, parameter, javadocs); - } - - @Override - public int hashCode() { - return Utils.combineHashesOrdered(this.parent, this.index); - } - - @Override - public boolean equals(Object other) { - return other instanceof LocalVariableEntry && equals((LocalVariableEntry) other); - } - - public boolean equals(LocalVariableEntry other) { - return this.parent.equals(other.parent) && this.index == other.index; - } - - @Override - public boolean canConflictWith(Entry entry) { - return entry instanceof LocalVariableEntry && ((LocalVariableEntry) entry).parent.equals(parent); - } - - @Override - public String toString() { - return this.parent + "(" + this.index + ":" + this.name + ")"; - } - - @Override - public int compareTo(LocalVariableEntry entry) { - return Integer.compare(index, entry.index); - } -} diff --git a/src/main/java/cuchaz/enigma/translation/representation/entry/MethodDefEntry.java b/src/main/java/cuchaz/enigma/translation/representation/entry/MethodDefEntry.java deleted file mode 100644 index 4e75a5c..0000000 --- a/src/main/java/cuchaz/enigma/translation/representation/entry/MethodDefEntry.java +++ /dev/null @@ -1,71 +0,0 @@ -/******************************************************************************* - * 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.translation.representation.entry; - -import com.google.common.base.Preconditions; -import cuchaz.enigma.translation.Translator; -import cuchaz.enigma.translation.mapping.EntryMapping; -import cuchaz.enigma.translation.representation.AccessFlags; -import cuchaz.enigma.translation.representation.MethodDescriptor; -import cuchaz.enigma.translation.representation.Signature; - -import javax.annotation.Nullable; - -public class MethodDefEntry extends MethodEntry implements DefEntry { - private final AccessFlags access; - private final Signature signature; - - public MethodDefEntry(ClassEntry owner, String name, MethodDescriptor descriptor, Signature signature, AccessFlags access) { - this(owner, name, descriptor, signature, access, null); - } - - public MethodDefEntry(ClassEntry owner, String name, MethodDescriptor descriptor, Signature signature, AccessFlags access, String docs) { - super(owner, name, descriptor, docs); - Preconditions.checkNotNull(access, "Method access cannot be null"); - Preconditions.checkNotNull(signature, "Method signature cannot be null"); - this.access = access; - this.signature = signature; - } - - public static MethodDefEntry parse(ClassEntry owner, int access, String name, String desc, String signature) { - return new MethodDefEntry(owner, name, new MethodDescriptor(desc), Signature.createSignature(signature), new AccessFlags(access), null); - } - - @Override - public AccessFlags getAccess() { - return access; - } - - public Signature getSignature() { - return signature; - } - - @Override - public MethodDefEntry translate(Translator translator, @Nullable EntryMapping mapping) { - MethodDescriptor translatedDesc = translator.translate(descriptor); - Signature translatedSignature = translator.translate(signature); - String translatedName = mapping != null ? mapping.getTargetName() : name; - AccessFlags translatedAccess = mapping != null ? mapping.getAccessModifier().transform(access) : access; - String docs = mapping != null ? mapping.getJavadoc() : null; - return new MethodDefEntry(parent, translatedName, translatedDesc, translatedSignature, translatedAccess, docs); - } - - @Override - public MethodDefEntry withName(String name) { - return new MethodDefEntry(parent, name, descriptor, signature, access, javadocs); - } - - @Override - public MethodDefEntry withParent(ClassEntry parent) { - return new MethodDefEntry(new ClassEntry(parent.getFullName()), name, descriptor, signature, access, javadocs); - } -} diff --git a/src/main/java/cuchaz/enigma/translation/representation/entry/MethodEntry.java b/src/main/java/cuchaz/enigma/translation/representation/entry/MethodEntry.java deleted file mode 100644 index e1ffad3..0000000 --- a/src/main/java/cuchaz/enigma/translation/representation/entry/MethodEntry.java +++ /dev/null @@ -1,105 +0,0 @@ -/******************************************************************************* - * 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.translation.representation.entry; - -import com.google.common.base.Preconditions; -import cuchaz.enigma.translation.Translator; -import cuchaz.enigma.translation.mapping.EntryMapping; -import cuchaz.enigma.translation.representation.MethodDescriptor; -import cuchaz.enigma.utils.Utils; - -import javax.annotation.Nullable; - -public class MethodEntry extends ParentedEntry implements Comparable { - - protected final MethodDescriptor descriptor; - - public MethodEntry(ClassEntry parent, String name, MethodDescriptor descriptor) { - this(parent, name, descriptor, null); - } - - public MethodEntry(ClassEntry parent, String name, MethodDescriptor descriptor, String javadocs) { - super(parent, name, javadocs); - - Preconditions.checkNotNull(parent, "Parent cannot be null"); - Preconditions.checkNotNull(descriptor, "Method descriptor cannot be null"); - - this.descriptor = descriptor; - } - - public static MethodEntry parse(String owner, String name, String desc) { - return new MethodEntry(new ClassEntry(owner), name, new MethodDescriptor(desc), null); - } - - @Override - public Class getParentType() { - return ClassEntry.class; - } - - public MethodDescriptor getDesc() { - return this.descriptor; - } - - public boolean isConstructor() { - return name.equals("") || name.equals(""); - } - - @Override - public MethodEntry translate(Translator translator, @Nullable EntryMapping mapping) { - String translatedName = mapping != null ? mapping.getTargetName() : name; - String docs = mapping != null ? mapping.getJavadoc() : null; - return new MethodEntry(parent, translatedName, translator.translate(descriptor), docs); - } - - @Override - public MethodEntry withName(String name) { - return new MethodEntry(parent, name, descriptor, javadocs); - } - - @Override - public MethodEntry withParent(ClassEntry parent) { - return new MethodEntry(new ClassEntry(parent.getFullName()), name, descriptor, javadocs); - } - - @Override - public int hashCode() { - return Utils.combineHashesOrdered(this.parent, this.name, this.descriptor); - } - - @Override - public boolean equals(Object other) { - return other instanceof MethodEntry && equals((MethodEntry) other); - } - - public boolean equals(MethodEntry other) { - return this.parent.equals(other.getParent()) && this.name.equals(other.getName()) && this.descriptor.equals(other.getDesc()); - } - - @Override - public boolean canConflictWith(Entry entry) { - if (entry instanceof MethodEntry) { - MethodEntry methodEntry = (MethodEntry) entry; - return methodEntry.parent.equals(parent) && methodEntry.descriptor.canConflictWith(descriptor); - } - return false; - } - - @Override - public String toString() { - return this.parent.getFullName() + "." + this.name + this.descriptor; - } - - @Override - public int compareTo(MethodEntry entry) { - return (name + descriptor.toString()).compareTo(entry.name + entry.descriptor.toString()); - } -} diff --git a/src/main/java/cuchaz/enigma/translation/representation/entry/ParentedEntry.java b/src/main/java/cuchaz/enigma/translation/representation/entry/ParentedEntry.java deleted file mode 100644 index cbc5faf..0000000 --- a/src/main/java/cuchaz/enigma/translation/representation/entry/ParentedEntry.java +++ /dev/null @@ -1,82 +0,0 @@ -/******************************************************************************* - * 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.translation.representation.entry; - -import com.google.common.base.Preconditions; -import cuchaz.enigma.translation.Translatable; -import cuchaz.enigma.translation.Translator; -import cuchaz.enigma.translation.mapping.EntryMap; -import cuchaz.enigma.translation.mapping.EntryMapping; -import cuchaz.enigma.translation.mapping.EntryResolver; -import cuchaz.enigma.translation.mapping.ResolutionStrategy; - -import javax.annotation.Nullable; - -public abstract class ParentedEntry

> implements Entry

{ - protected final P parent; - protected final String name; - protected final @Nullable String javadocs; - - protected ParentedEntry(P parent, String name, String javadocs) { - this.parent = parent; - this.name = name; - this.javadocs = javadocs; - - Preconditions.checkNotNull(name, "Name cannot be null"); - } - - @Override - public abstract ParentedEntry

withParent(P parent); - - @Override - public abstract ParentedEntry

withName(String name); - - protected abstract ParentedEntry

translate(Translator translator, @Nullable EntryMapping mapping); - - @Override - public String getName() { - return name; - } - - @Override - @Nullable - public P getParent() { - return parent; - } - - @Nullable - @Override - public String getJavadocs() { - return javadocs; - } - - @Override - public ParentedEntry

translate(Translator translator, EntryResolver resolver, EntryMap mappings) { - P parent = getParent(); - EntryMapping mapping = resolveMapping(resolver, mappings); - if (parent == null) { - return translate(translator, mapping); - } - P translatedParent = translator.translate(parent); - return withParent(translatedParent).translate(translator, mapping); - } - - private EntryMapping resolveMapping(EntryResolver resolver, EntryMap mappings) { - for (ParentedEntry

entry : resolver.resolveEntry(this, ResolutionStrategy.RESOLVE_ROOT)) { - EntryMapping mapping = mappings.get(entry); - if (mapping != null) { - return mapping; - } - } - return null; - } -} -- cgit v1.2.3