Skip to content

Commit

Permalink
Refactor Field/MethodSignature constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
stephan-gh committed Aug 29, 2018
1 parent 01be654 commit b147c6b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

/**
Expand All @@ -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;
}

/**
Expand All @@ -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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down

0 comments on commit b147c6b

Please sign in to comment.