From acd8b326dbde3912e3a102b514bf451350452c7e Mon Sep 17 00:00:00 2001 From: Yanis48 Date: Wed, 7 Apr 2021 12:01:04 +0200 Subject: Reorganize entry names --- .../representation/entry/ClassEntry.java | 28 ++++++---- .../translation/representation/entry/Entry.java | 60 ++++++++++++++++++++++ .../representation/entry/ParentedEntry.java | 17 +++++- 3 files changed, 95 insertions(+), 10 deletions(-) (limited to 'enigma/src/main/java') diff --git a/enigma/src/main/java/cuchaz/enigma/translation/representation/entry/ClassEntry.java b/enigma/src/main/java/cuchaz/enigma/translation/representation/entry/ClassEntry.java index 47319e0..fe56611 100644 --- a/enigma/src/main/java/cuchaz/enigma/translation/representation/entry/ClassEntry.java +++ b/enigma/src/main/java/cuchaz/enigma/translation/representation/entry/ClassEntry.java @@ -59,8 +59,26 @@ public class ClassEntry extends ParentedEntry implements Comparable< return this.name; } + @Override + public String getSimpleName() { + int packagePos = name.lastIndexOf('/'); + if (packagePos > 0) { + return name.substring(packagePos + 1); + } + return name; + } + + @Override public String getFullName() { - return fullName; + return this.fullName; + } + + @Override + public String getContextualName() { + if (this.isInnerClass()) { + return this.parent.getSimpleName() + "$" + this.name; + } + return this.getSimpleName(); } @Override @@ -126,14 +144,6 @@ public class ClassEntry extends ParentedEntry implements Comparable< return getPackageName(fullName); } - public String getSimpleName() { - int packagePos = name.lastIndexOf('/'); - if (packagePos > 0) { - return name.substring(packagePos + 1); - } - return name; - } - /** * Returns whether this class entry has a parent, and therefore is an inner class. */ diff --git a/enigma/src/main/java/cuchaz/enigma/translation/representation/entry/Entry.java b/enigma/src/main/java/cuchaz/enigma/translation/representation/entry/Entry.java index 6fd412a..8a81c54 100644 --- a/enigma/src/main/java/cuchaz/enigma/translation/representation/entry/Entry.java +++ b/enigma/src/main/java/cuchaz/enigma/translation/representation/entry/Entry.java @@ -21,8 +21,68 @@ import cuchaz.enigma.translation.mapping.IdentifierValidation; import cuchaz.enigma.utils.validation.ValidationContext; public interface Entry

> extends Translatable { + /** + * Returns the default name of this entry. + * + *

For methods, fields and inner classes, it's the same as {@link #getSimpleName()}.

+ *

For other classes, it's the same as {@link #getFullName()}.

+ * + *

Examples:

+ * + */ String getName(); + /** + * Returns the simple name of this entry. + * + *

For methods, fields and inner classes, it's the same as {@link #getName()}.

+ *

For other classes, it's their name without the package name.

+ * + *

Examples:

+ * + */ + String getSimpleName(); + + /** + * Returns the full name of this entry. + * + *

For methods, fields and inner classes, it's their name prefixed with the full name + * of their parent entry.

+ *

For other classes, it's their name prefixed with their package name.

+ * + *

Examples:

+ * + */ + String getFullName(); + + /** + * Returns the contextual name of this entry. + * + *

For methods, fields and inner classes, it's their name prefixed with the contextual + * name of their parent entry.

+ *

For other classes, it's only their simple name.

+ * + *

Examples:

+ * + */ + String getContextualName(); + String getJavadocs(); default String getSourceRemapName() { diff --git a/enigma/src/main/java/cuchaz/enigma/translation/representation/entry/ParentedEntry.java b/enigma/src/main/java/cuchaz/enigma/translation/representation/entry/ParentedEntry.java index b12f9d0..5634891 100644 --- a/enigma/src/main/java/cuchaz/enigma/translation/representation/entry/ParentedEntry.java +++ b/enigma/src/main/java/cuchaz/enigma/translation/representation/entry/ParentedEntry.java @@ -45,7 +45,22 @@ public abstract class ParentedEntry

> implements Entry

{ @Override public String getName() { - return name; + return this.name; + } + + @Override + public String getSimpleName() { + return this.name; + } + + @Override + public String getFullName() { + return this.parent.getFullName() + "." + this.name; + } + + @Override + public String getContextualName() { + return this.parent.getContextualName() + "." + this.name; } @Override -- cgit v1.2.3 From a32d580f656ff5231222d600e146fdd7cd009e74 Mon Sep 17 00:00:00 2001 From: Yanis48 Date: Wed, 7 Apr 2021 12:23:29 +0200 Subject: Simplify toString() implementations --- .../java/cuchaz/enigma/analysis/MethodImplementationsTreeNode.java | 4 +--- .../main/java/cuchaz/enigma/analysis/MethodInheritanceTreeNode.java | 6 ++---- .../cuchaz/enigma/translation/representation/entry/FieldEntry.java | 2 +- .../cuchaz/enigma/translation/representation/entry/MethodEntry.java | 2 +- 4 files changed, 5 insertions(+), 9 deletions(-) (limited to 'enigma/src/main/java') diff --git a/enigma/src/main/java/cuchaz/enigma/analysis/MethodImplementationsTreeNode.java b/enigma/src/main/java/cuchaz/enigma/analysis/MethodImplementationsTreeNode.java index b09f7ac..4633ace 100644 --- a/enigma/src/main/java/cuchaz/enigma/analysis/MethodImplementationsTreeNode.java +++ b/enigma/src/main/java/cuchaz/enigma/analysis/MethodImplementationsTreeNode.java @@ -60,9 +60,7 @@ public class MethodImplementationsTreeNode extends DefaultMutableTreeNode { @Override public String toString() { MethodEntry translatedEntry = translator.translate(entry); - String className = translatedEntry.getParent().getFullName(); - String methodName = translatedEntry.getName(); - return className + "." + methodName + "()"; + return translatedEntry.getFullName() + "()"; } public void load(JarIndex index) { diff --git a/enigma/src/main/java/cuchaz/enigma/analysis/MethodInheritanceTreeNode.java b/enigma/src/main/java/cuchaz/enigma/analysis/MethodInheritanceTreeNode.java index 7bee4dc..455456f 100644 --- a/enigma/src/main/java/cuchaz/enigma/analysis/MethodInheritanceTreeNode.java +++ b/enigma/src/main/java/cuchaz/enigma/analysis/MethodInheritanceTreeNode.java @@ -62,13 +62,11 @@ public class MethodInheritanceTreeNode extends DefaultMutableTreeNode { @Override public String toString() { MethodEntry translatedEntry = translator.translate(entry); - String className = translatedEntry.getContainingClass().getFullName(); if (!this.implemented) { - return className; + return translatedEntry.getParent().getFullName(); } else { - String methodName = translatedEntry.getName(); - return className + "." + methodName + "()"; + return translatedEntry.getFullName() + "()"; } } diff --git a/enigma/src/main/java/cuchaz/enigma/translation/representation/entry/FieldEntry.java b/enigma/src/main/java/cuchaz/enigma/translation/representation/entry/FieldEntry.java index 3c54468..5ddd33d 100644 --- a/enigma/src/main/java/cuchaz/enigma/translation/representation/entry/FieldEntry.java +++ b/enigma/src/main/java/cuchaz/enigma/translation/representation/entry/FieldEntry.java @@ -93,7 +93,7 @@ public class FieldEntry extends ParentedEntry implements Comparable< @Override public String toString() { - return this.parent.getFullName() + "." + this.name + ":" + this.desc; + return this.getFullName() + ":" + this.desc; } @Override diff --git a/enigma/src/main/java/cuchaz/enigma/translation/representation/entry/MethodEntry.java b/enigma/src/main/java/cuchaz/enigma/translation/representation/entry/MethodEntry.java index 4698aa4..864a580 100644 --- a/enigma/src/main/java/cuchaz/enigma/translation/representation/entry/MethodEntry.java +++ b/enigma/src/main/java/cuchaz/enigma/translation/representation/entry/MethodEntry.java @@ -102,7 +102,7 @@ public class MethodEntry extends ParentedEntry implements Comparable @Override public String toString() { - return this.parent.getFullName() + "." + this.name + this.descriptor; + return this.getFullName() + this.descriptor; } @Override -- cgit v1.2.3