From b147c6b9ab700131a08218d50896c3255954270e Mon Sep 17 00:00:00 2001 From: Minecrell Date: Wed, 29 Aug 2018 09:32:26 +0200 Subject: [PATCH] Refactor Field/MethodSignature constructors --- .../asm/analysis/ClassNodeClassInfo.java | 4 +-- .../bombe/type/signature/FieldSignature.java | 18 ++++++----- .../bombe/type/signature/MethodSignature.java | 31 +++++++++++++------ 3 files changed, 34 insertions(+), 19 deletions(-) diff --git a/bombe-asm/src/main/java/me/jamiemansfield/bombe/asm/analysis/ClassNodeClassInfo.java b/bombe-asm/src/main/java/me/jamiemansfield/bombe/asm/analysis/ClassNodeClassInfo.java index 8338d91..ab31f69 100644 --- a/bombe-asm/src/main/java/me/jamiemansfield/bombe/asm/analysis/ClassNodeClassInfo.java +++ b/bombe-asm/src/main/java/me/jamiemansfield/bombe/asm/analysis/ClassNodeClassInfo.java @@ -51,10 +51,10 @@ class ClassNodeClassInfo extends InheritanceProvider.ClassInfo.Impl { ); this.interfaces.addAll(klass.interfaces); klass.fields.stream() - .map(fieldNode -> new FieldSignature(fieldNode.name, fieldNode.desc)) + .map(fieldNode -> FieldSignature.of(fieldNode.name, fieldNode.desc)) .forEach(this.fields::add); klass.methods.stream() - .map(methodNode -> new MethodSignature(methodNode.name, methodNode.desc)) + .map(methodNode -> MethodSignature.of(methodNode.name, methodNode.desc)) .forEach(this.methods::add); } diff --git a/bombe-core/src/main/java/me/jamiemansfield/bombe/type/signature/FieldSignature.java b/bombe-core/src/main/java/me/jamiemansfield/bombe/type/signature/FieldSignature.java index 30e6cff..e0ed3e5 100644 --- a/bombe-core/src/main/java/me/jamiemansfield/bombe/type/signature/FieldSignature.java +++ b/bombe-core/src/main/java/me/jamiemansfield/bombe/type/signature/FieldSignature.java @@ -47,14 +47,15 @@ public class FieldSignature extends MemberSignature { private final FieldType type; /** - * Creates a field signature, with the given name and type. + * Creates a new field signature with the given name and + * decoded type descriptor. * * @param name The name of the field - * @param type The type of the field + * @param type The raw type of the field + * @return The new field signature */ - public FieldSignature(final String name, final FieldType type) { - super(name); - this.type = type; + public static FieldSignature of(String name, String type) { + return new FieldSignature(name, FieldType.of(type)); } /** @@ -63,8 +64,9 @@ public FieldSignature(final String name, final FieldType type) { * @param name The name of the field * @param type The type of the field */ - public FieldSignature(final String name, final String type) { - this(name, FieldType.of(type)); + public FieldSignature(final String name, final FieldType type) { + super(name); + this.type = type; } /** @@ -74,7 +76,7 @@ public FieldSignature(final String name, final String type) { * @since 0.1.1 */ public FieldSignature(final String name) { - this(name, (FieldType) null); + this(name, null); } /** diff --git a/bombe-core/src/main/java/me/jamiemansfield/bombe/type/signature/MethodSignature.java b/bombe-core/src/main/java/me/jamiemansfield/bombe/type/signature/MethodSignature.java index c3e2a63..f5172ac 100644 --- a/bombe-core/src/main/java/me/jamiemansfield/bombe/type/signature/MethodSignature.java +++ b/bombe-core/src/main/java/me/jamiemansfield/bombe/type/signature/MethodSignature.java @@ -46,24 +46,37 @@ public class MethodSignature extends MemberSignature { private final MethodDescriptor descriptor; /** - * Creates a method signature, with the given name and {@link MethodDescriptor}. + * Creates a method signature, with the given method name and raw descriptor. * * @param name The method name - * @param descriptor The method descriptor + * @param descriptor The method's raw descriptor + * @return The new method signature */ - public MethodSignature(final String name, final MethodDescriptor descriptor) { - super(name); - this.descriptor = descriptor; + public static MethodSignature of(final String name, final String descriptor) { + return new MethodSignature(name, MethodDescriptor.of(descriptor)); } /** - * Creates a method descriptor, with the given method name and raw descriptor. + * Creates a method signature, with the given raw string that contains the + * method name and descriptor concatenated. + * + * @param nameAndDescriptor The method name and descriptor + * @return The new method signature + */ + public static MethodSignature of(final String nameAndDescriptor) { + int methodIndex = nameAndDescriptor.indexOf('('); + return of(nameAndDescriptor.substring(0, methodIndex), nameAndDescriptor.substring(methodIndex)); + } + + /** + * Creates a method signature, with the given name and {@link MethodDescriptor}. * * @param name The method name - * @param descriptor The method's raw descriptor + * @param descriptor The method descriptor */ - public MethodSignature(final String name, final String descriptor) { - this(name, MethodDescriptor.of(descriptor)); + public MethodSignature(final String name, final MethodDescriptor descriptor) { + super(name); + this.descriptor = descriptor; } /**