Skip to content

Commit 45f72d9

Browse files
committed
Adjust naming and add tests.
1 parent 8b1a2c5 commit 45f72d9

File tree

11 files changed

+110
-18
lines changed

11 files changed

+110
-18
lines changed
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,24 @@
55

66
import java.lang.invoke.MethodHandles;
77

8-
public class DynamicConstantAdvice {
8+
public class AdviceDynamicConstant {
99

10-
public DynamicConstantAdvice foo() {
10+
public AdviceDynamicConstant foo() {
1111
return null;
1212
}
1313

1414
@Advice.OnMethodExit
1515
public static void exit(@Advice.DynamicConstant(
1616
bootstrapType = JavaConstant.MethodHandle.HandleType.INVOKE_STATIC,
1717
bootstrapName = "constantdynamic",
18-
bootstrapOwner = DynamicConstantAdvice.class,
19-
bootstrapReturnType = DynamicConstantAdvice.class,
20-
bootstrapParameterTypes = {MethodHandles.Lookup.class, String.class, Object[].class}) DynamicConstantAdvice constant,
21-
@Advice.Return(readOnly = false) DynamicConstantAdvice returned) throws Throwable {
18+
bootstrapOwner = AdviceDynamicConstant.class,
19+
bootstrapReturnType = AdviceDynamicConstant.class,
20+
bootstrapParameterTypes = {MethodHandles.Lookup.class, String.class, Object[].class}) AdviceDynamicConstant constant,
21+
@Advice.Return(readOnly = false) AdviceDynamicConstant returned) throws Throwable {
2222
returned = constant;
2323
}
2424

25-
public static DynamicConstantAdvice constantdynamic(MethodHandles.Lookup lookup, String name, Object... args) {
26-
return new DynamicConstantAdvice();
25+
public static AdviceDynamicConstant constantdynamic(MethodHandles.Lookup lookup, String name, Object... args) {
26+
return new AdviceDynamicConstant();
2727
}
2828
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package net.bytebuddy.test.precompiled.v11;
2+
3+
import net.bytebuddy.asm.MemberSubstitution;
4+
import net.bytebuddy.utility.JavaConstant;
5+
6+
import java.lang.invoke.MethodHandles;
7+
8+
public class MemberSubstitutionDynamicConstant {
9+
10+
public MemberSubstitutionDynamicConstant foo;
11+
12+
public MemberSubstitutionDynamicConstant foo() {
13+
return foo;
14+
}
15+
16+
public static MemberSubstitutionDynamicConstant intercept(@MemberSubstitution.DynamicConstant(
17+
bootstrapType = JavaConstant.MethodHandle.HandleType.INVOKE_STATIC,
18+
bootstrapName = "constantdynamic",
19+
bootstrapOwner = MemberSubstitutionDynamicConstant.class,
20+
bootstrapReturnType = MemberSubstitutionDynamicConstant.class,
21+
bootstrapParameterTypes = {MethodHandles.Lookup.class, String.class, Object[].class}) MemberSubstitutionDynamicConstant constant) throws Throwable {
22+
return constant;
23+
}
24+
25+
public static MemberSubstitutionDynamicConstant constantdynamic(MethodHandles.Lookup lookup, String name, Object... args) {
26+
return new MemberSubstitutionDynamicConstant();
27+
}
28+
}
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,25 @@
77
import java.lang.invoke.ConstantCallSite;
88
import java.lang.invoke.MethodHandles;
99

10-
public class DynamicConstantAdvice {
10+
public class AdviceDynamicConstant {
1111

12-
public DynamicConstantAdvice foo() {
12+
public AdviceDynamicConstant foo() {
1313
return null;
1414
}
1515

1616
@Advice.OnMethodExit
1717
public static void exit(@Advice.DynamicConstant(
1818
bootstrapType = JavaConstant.MethodHandle.HandleType.INVOKE_STATIC,
1919
bootstrapName = "invokedynamic",
20-
bootstrapOwner = DynamicConstantAdvice.class,
20+
bootstrapOwner = AdviceDynamicConstant.class,
2121
bootstrapReturnType = CallSite.class,
2222
bootstrapParameterTypes = Object[].class,
23-
invokedynamic = true) DynamicConstantAdvice constant,
24-
@Advice.Return(readOnly = false) DynamicConstantAdvice returned) throws Throwable {
23+
invokedynamic = true) AdviceDynamicConstant constant,
24+
@Advice.Return(readOnly = false) AdviceDynamicConstant returned) throws Throwable {
2525
returned = constant;
2626
}
2727

2828
public static CallSite invokedynamic(Object... args) {
29-
return new ConstantCallSite(MethodHandles.constant(DynamicConstantAdvice.class, new DynamicConstantAdvice()));
29+
return new ConstantCallSite(MethodHandles.constant(AdviceDynamicConstant.class, new AdviceDynamicConstant()));
3030
}
3131
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package net.bytebuddy.test.precompiled.v7;
2+
3+
import net.bytebuddy.asm.MemberSubstitution;
4+
import net.bytebuddy.utility.JavaConstant;
5+
6+
import java.lang.invoke.CallSite;
7+
import java.lang.invoke.ConstantCallSite;
8+
import java.lang.invoke.MethodHandles;
9+
10+
public class MemberSubstitutionDynamicConstant {
11+
12+
public MemberSubstitutionDynamicConstant foo;
13+
14+
public MemberSubstitutionDynamicConstant foo() {
15+
return foo;
16+
}
17+
18+
public static MemberSubstitutionDynamicConstant intercept(@MemberSubstitution.DynamicConstant(
19+
bootstrapType = JavaConstant.MethodHandle.HandleType.INVOKE_STATIC,
20+
bootstrapName = "invokedynamic",
21+
bootstrapOwner = MemberSubstitutionDynamicConstant.class,
22+
bootstrapReturnType = CallSite.class,
23+
bootstrapParameterTypes = Object[].class) MemberSubstitutionDynamicConstant constant) throws Throwable {
24+
return constant;
25+
}
26+
27+
public static CallSite invokedynamic(Object... args) {
28+
return new ConstantCallSite(MethodHandles.constant(MemberSubstitutionDynamicConstant.class, new MemberSubstitutionDynamicConstant()));
29+
}
30+
}

byte-buddy-dep/src/test/java/net/bytebuddy/asm/AdviceTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import net.bytebuddy.matcher.ElementMatchers;
2222
import net.bytebuddy.pool.TypePool;
2323
import net.bytebuddy.test.packaging.AdviceTestHelper;
24-
import net.bytebuddy.test.utility.DebuggingWrapper;
2524
import net.bytebuddy.test.utility.JavaVersionRule;
2625
import net.bytebuddy.utility.JavaConstant;
2726
import net.bytebuddy.utility.JavaType;
@@ -1609,7 +1608,7 @@ public void testHandle() throws Exception {
16091608
@Test
16101609
@JavaVersionRule.Enforce(value = 11, target = HandleSample.class)
16111610
public void testDynamicConstant() throws Exception {
1612-
Class<?> bootstrap = Class.forName("net.bytebuddy.test.precompiled.v11.DynamicConstantAdvice");
1611+
Class<?> bootstrap = Class.forName("net.bytebuddy.test.precompiled.v11.AdviceDynamicConstant");
16131612
Class<?> type = new ByteBuddy()
16141613
.redefine(bootstrap)
16151614
.visit(Advice.to(bootstrap).on(named(FOO)))
@@ -1625,7 +1624,7 @@ public void testDynamicConstant() throws Exception {
16251624
@Test
16261625
@JavaVersionRule.Enforce(value = 7, target = HandleSample.class)
16271626
public void testDynamicConstantInvokedynamic() throws Exception {
1628-
Class<?> bootstrap = Class.forName("net.bytebuddy.test.precompiled.v7.DynamicConstantAdvice");
1627+
Class<?> bootstrap = Class.forName("net.bytebuddy.test.precompiled.v7.AdviceDynamicConstant");
16291628
Class<?> type = new ByteBuddy()
16301629
.redefine(bootstrap)
16311630
.visit(Advice.to(bootstrap).on(named(FOO)))

byte-buddy-dep/src/test/java/net/bytebuddy/asm/MemberSubstitutionChainWithAnnotationTest.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,40 @@ public void testHandle() throws Exception {
312312
assertThat(type.getDeclaredMethod(RUN).invoke(instance), is((Object) FOO));
313313
}
314314

315+
@Test
316+
@JavaVersionRule.Enforce(value = 7)
317+
public void testDynamicConstantInvokedynamic() throws Exception {
318+
Class<?> bootstrap = Class.forName("net.bytebuddy.test.precompiled.v7.MemberSubstitutionDynamicConstant");
319+
Class<?> type = new ByteBuddy()
320+
.redefine(bootstrap)
321+
.visit(MemberSubstitution.strict()
322+
.field(named(FOO))
323+
.replaceWithChain(MemberSubstitution.Substitution.Chain.Step.ForDelegation.to(bootstrap.getMethod("intercept", bootstrap)))
324+
.on(named(RUN)))
325+
.make()
326+
.load(ClassLoadingStrategy.BOOTSTRAP_LOADER, ClassLoadingStrategy.Default.WRAPPER)
327+
.getLoaded();
328+
Object instance = type.getDeclaredConstructor().newInstance();
329+
assertThat(type.getDeclaredMethod(RUN).invoke(instance), instanceOf(bootstrap));
330+
}
331+
332+
@Test
333+
@JavaVersionRule.Enforce(value = 11)
334+
public void testDynamicConstant() throws Exception {
335+
Class<?> bootstrap = Class.forName("net.bytebuddy.test.precompiled.v11.MemberSubstitutionDynamicConstant");
336+
Class<?> type = new ByteBuddy()
337+
.redefine(bootstrap)
338+
.visit(MemberSubstitution.strict()
339+
.field(named(FOO))
340+
.replaceWithChain(MemberSubstitution.Substitution.Chain.Step.ForDelegation.to(bootstrap.getMethod("intercept", bootstrap)))
341+
.on(named(RUN)))
342+
.make()
343+
.load(ClassLoadingStrategy.BOOTSTRAP_LOADER, ClassLoadingStrategy.Default.WRAPPER)
344+
.getLoaded();
345+
Object instance = type.getDeclaredConstructor().newInstance();
346+
assertThat(type.getDeclaredMethod(RUN).invoke(instance), instanceOf(bootstrap));
347+
}
348+
315349
@Test
316350
@JavaVersionRule.Enforce(value = 7, target = SelfCallHandleSample.class)
317351
public void testSelfCallHandleHierarchy() throws Exception {

byte-buddy-dep/src/test/java/net/bytebuddy/implementation/bytecode/member/MethodInvocationGenericTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package net.bytebuddy.implementation.bytecode.member;
22

33
import net.bytebuddy.description.method.MethodDescription;
4+
import net.bytebuddy.description.method.ParameterDescription;
45
import net.bytebuddy.description.method.ParameterList;
56
import net.bytebuddy.description.type.TypeDefinition;
67
import net.bytebuddy.description.type.TypeDescription;
@@ -60,7 +61,7 @@ public void setUp() throws Exception {
6061
when(declaredMethod.asSignatureToken()).thenReturn(token);
6162
when(declaredMethod.isSpecializableFor(targetType)).thenReturn(true);
6263
when(declaredMethod.asDefined()).thenReturn(declaredMethod);
63-
when(declaredMethod.getParameters()).thenReturn(new ParameterList.Empty<>());
64+
when(declaredMethod.getParameters()).thenReturn(new ParameterList.Empty<ParameterDescription.InDefinedShape>());
6465
when(declaredMethod.getInternalName()).thenReturn(FOO);
6566
}
6667

0 commit comments

Comments
 (0)