Skip to content

Commit 700fc08

Browse files
committed
house keeping
1 parent 0c3720f commit 700fc08

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

jmolecules-bytebuddy-tests/jmolecules-bytebuddy-tests-vaadoo/src/test/java/org/jmolecules/bytebuddy/JMoleculesVaadooPluginTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class JMoleculesVaadooPluginTests {
2626

2727
@Test
2828
void defaultsForSampleValueObject() throws Exception {
29-
assertThat(SampleValueObject.class.getDeclaredMethod("__vaadoo$validate")).isNotNull();
29+
assertThat(SampleValueObject.class.getDeclaredMethod("validate")).isNotNull();
3030
}
3131

3232
@Test

jmolecules-bytebuddy/src/main/java/org/jmolecules/bytebuddy/VaadooImplementor.java

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,26 @@
1212
import net.bytebuddy.dynamic.DynamicType.Builder;
1313
import net.bytebuddy.implementation.ExceptionMethod;
1414
import net.bytebuddy.implementation.MethodCall;
15-
import net.bytebuddy.implementation.StubMethod;
1615
import net.bytebuddy.implementation.SuperMethodCall;
1716

1817
class VaadooImplementor {
1918

20-
private static final String VALIDATE_METHOD_NAME = "__vaadoo$validate";
19+
private static final String VALIDATE_METHOD_NAME_1 = "validate";
20+
private static final String VALIDATE_METHOD_NAME_2 = "__vaadoo$__validate";
2121

2222
JMoleculesTypeBuilder implementVaadoo(JMoleculesTypeBuilder type, Log log) {
23-
String methodName = nonExistingMethodName(type, VALIDATE_METHOD_NAME);
23+
String methodName = nonExistingMethodName(type);
2424
return type //
2525
.mapBuilder(t -> addValidationMethod(t, methodName))
2626
.mapBuilder(t -> injectValidationIntoConstructors(t, methodName));
2727
}
2828

29-
private static String nonExistingMethodName(JMoleculesTypeBuilder type, String baseMethodName) {
29+
private static String nonExistingMethodName(JMoleculesTypeBuilder type) {
30+
if (type.tryFindMethod(target -> isValidateMethod(target, VALIDATE_METHOD_NAME_1)) == null) {
31+
return VALIDATE_METHOD_NAME_1;
32+
}
33+
34+
String baseMethodName = VALIDATE_METHOD_NAME_2;
3035
String methodName = baseMethodName;
3136
for (int i = 0;; i++) {
3237
final String currentName = methodName;
@@ -43,14 +48,8 @@ private static boolean isValidateMethod(InDefinedShape target, String methodName
4348
}
4449

4550
private Builder<?> addValidationMethod(Builder<?> builder, String methodName) {
46-
return builder
47-
.defineMethod(methodName, void.class)
48-
.intercept(
49-
ExceptionMethod.throwing(
50-
IllegalStateException.class,
51-
"Vaadoo validation failed: override or disable this method"
52-
)
53-
);
51+
return builder.defineMethod(methodName, void.class).intercept(ExceptionMethod
52+
.throwing(IllegalStateException.class, "Vaadoo validation failed: override or disable this method"));
5453
}
5554

5655
private Builder<?> injectValidationIntoConstructors(Builder<?> builder, String methodName) {

0 commit comments

Comments
 (0)