Skip to content

Commit

Permalink
Polish #29
Browse files Browse the repository at this point in the history
  • Loading branch information
mercyblitz committed Dec 6, 2024
1 parent 1cfe8d4 commit b31af7d
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ public final boolean isPresent() {
@Override
public String toString() {
return "ClassDefinition{" +
"since=" + since +
", deprecation=" + deprecation +
"since=" + super.since +
", deprecation=" + super.deprecation +
", className='" + this.getClassName() + '\'' +
", resolvedClass=" + getResolvedClass() +
", resolvedClass=" + super.getResolvedClass() +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public ConstructorDefinition(Version since, Deprecation deprecation, String decl

@Override
protected Constructor resolveMember() {
return findConstructor(getDeclaredClass(), getParameterTypes());
return findConstructor(super.getDeclaredClass(), super.getParameterTypes());
}

/**
Expand All @@ -88,12 +88,12 @@ public Constructor<?> getConstructor() {
@Override
public String toString() {
return "ConstructorDefinition{" +
"since=" + this.since +
", deprecation=" + this.deprecation +
", declaredClassName='" + this.getDeclaredClassName() + '\'' +
", declaredClass=" + this.getDeclaredClass() +
", parameterClassName=" + Arrays.toString(this.parameterClassNames) +
", parameterTypes=" + Arrays.toString(this.parameterTypes) +
"since=" + super.since +
", deprecation=" + super.deprecation +
", declaredClassName='" + super.getDeclaredClassName() + '\'' +
", declaredClass=" + super.getDeclaredClass() +
", parameterClassName=" + Arrays.toString(super.parameterClassNames) +
", parameterTypes=" + Arrays.toString(super.getParameterTypes()) +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@ public abstract class ExecutableDefinition<E extends Executable> extends MemberD
@Nonnull
protected final String[] parameterClassNames;

private transient boolean resolvedParameterTypes;

@Nonnull
protected final transient Class<?>[] parameterTypes;
private transient Class<?>[] parameterTypes;

/**
* @param since the 'since' version
Expand Down Expand Up @@ -92,16 +94,6 @@ public ExecutableDefinition(Version since, Deprecation deprecation, String decla
assertNotNull(parameterClassNames, () -> "the class names of parameters of method must not be null.");
assertNoNullElements(parameterClassNames, () -> "The parameter class names must not contain any null element.");
this.parameterClassNames = parameterClassNames;
this.parameterTypes = resolveParameterTypes(parameterClassNames);
}

protected Class<?>[] resolveParameterTypes(String[] parameterClassNames) {
int length = parameterClassNames.length;
Class<?>[] parameterTypes = new Class<?>[length];
for (int i = 0; i < length; i++) {
parameterTypes[i] = resolveClass(parameterClassNames[i], this.classLoader);
}
return parameterTypes;
}

/**
Expand All @@ -121,7 +113,11 @@ public final String[] getParameterClassNames() {
*/
@Nonnull
public final Class<?>[] getParameterTypes() {
return parameterTypes.clone();
if (!this.resolvedParameterTypes && this.parameterTypes == null) {
this.parameterTypes = resolveParameterTypes(this.parameterClassNames);
this.resolvedParameterTypes = true;
}
return this.parameterTypes.clone();
}

@Override
Expand Down Expand Up @@ -153,4 +149,13 @@ public String toString() {
", parameterTypes=" + Arrays.toString(this.parameterTypes) +
'}';
}

protected Class<?>[] resolveParameterTypes(String[] parameterClassNames) {
int length = parameterClassNames.length;
Class<?>[] parameterTypes = new Class<?>[length];
for (int i = 0; i < length; i++) {
parameterTypes[i] = resolveClass(parameterClassNames[i], this.classLoader);
}
return parameterTypes;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public abstract class MemberDefinition<M extends Member> extends ReflectiveDefin
protected final String name;

@Nullable
private M member;
private transient M member;

private boolean resolvedMember;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,14 @@ public <R> R invoke(Object instance, Object... args) throws IllegalStateExceptio
@Override
public String toString() {
return "MethodDefinition{" +
"since=" + this.since +
", deprecation=" + this.deprecation +
", declaredClassName='" + this.getDeclaredClassName() + '\'' +
", declaredClass=" + this.getDeclaredClass() +
"since=" + super.since +
", deprecation=" + super.deprecation +
", declaredClassName='" + super.getDeclaredClassName() + '\'' +
", declaredClass=" + super.getDeclaredClass() +
", methodName='" + getMethodName() + '\'' +
", method=" + getMethod() +
", parameterClassName=" + Arrays.toString(this.parameterClassNames) +
", parameterTypes=" + Arrays.toString(this.parameterTypes) +
", parameterClassName=" + Arrays.toString(super.parameterClassNames) +
", parameterTypes=" + Arrays.toString(super.getParameterTypes()) +
'}';
}
}

0 comments on commit b31af7d

Please sign in to comment.