import static com.google.common.base.Verify.verify;
import static com.google.common.base.Verify.verifyNotNull;
import static java.util.Objects.requireNonNull;
-import static org.opendaylight.mdsal.binding.dom.codec.impl.ByteBuddyUtils.THIS;
+import static org.opendaylight.mdsal.binding.dom.codec.impl.ByteBuddyUtils.computeFrames;
import static org.opendaylight.mdsal.binding.dom.codec.impl.ByteBuddyUtils.getField;
import static org.opendaylight.mdsal.binding.dom.codec.impl.ByteBuddyUtils.invokeMethod;
+import static org.opendaylight.mdsal.binding.dom.codec.impl.ByteBuddyUtils.loadThis;
import static org.opendaylight.mdsal.binding.dom.codec.impl.ByteBuddyUtils.putField;
import com.google.common.collect.ImmutableMap;
final Generic bindingDef = TypeDefinition.Sort.describe(bindingInterface);
@SuppressWarnings("unchecked")
Builder<T> builder = (Builder<T>) BB.subclass(Generic.Builder.parameterizedType(superClass, bindingDef).build())
- .visit(ByteBuddyUtils.computeFrames()).name(fqcn).implement(bindingDef);
+ .visit(computeFrames()).name(fqcn).implement(bindingDef);
builder = generateGetters(builder);
private static Implementation codecHashCode(final Class<?> bindingInterface) {
return new Implementation.Simple(
// return Foo.bindingHashCode(this);
- THIS,
+ loadThis(),
invokeMethod(bindingInterface, BindingMapping.BINDING_HASHCODE_NAME, bindingInterface),
MethodReturn.INTEGER);
}
private static Implementation codecEquals(final Class<?> bindingInterface) {
return new Implementation.Simple(
// return Foo.bindingEquals(this, obj);
- THIS,
+ loadThis(),
FIRST_ARG_REF,
invokeMethod(bindingInterface, BindingMapping.BINDING_EQUALS_NAME, bindingInterface, Object.class),
MethodReturn.INTEGER);
private static Implementation toString(final Class<?> bindingInterface) {
return new Implementation.Simple(
// return Foo.bindingToString(this);
- THIS,
+ loadThis(),
invokeMethod(bindingInterface, BindingMapping.BINDING_TO_STRING_NAME, bindingInterface),
MethodReturn.REFERENCE);
}
public ByteCodeAppender appender(final Target implementationTarget) {
return new ByteCodeAppender.Simple(
// return (FooType) codecKey(getFoo$$$V);
- THIS,
+ loadThis(),
getField(implementationTarget.getInstrumentedType(), handleName),
CODEC_KEY,
TypeCasting.to(retType),
final TypeDescription instrumentedType = implementationTarget.getInstrumentedType();
return new ByteCodeAppender.Simple(
// return (FooType) codecMember(getFoo$$$V, getFoo$$$S);
- THIS,
+ loadThis(),
getField(instrumentedType, handleName),
getField(instrumentedType, stringName),
CODEC_MEMBER,
public ByteCodeAppender appender(final Target implementationTarget) {
return new ByteCodeAppender.Simple(
// return (FooType) codecMember(getFoo$$$V, FooType.class);
- THIS,
+ loadThis(),
getField(implementationTarget.getInstrumentedType(), handleName),
ClassConstant.of(TypeDefinition.Sort.describe(bindingClass).asErasure()),
CODEC_MEMBER,
final TypeDescription instrumentedType = implementationTarget.getInstrumentedType();
return new ByteCodeAppender.Simple(
// return (FooType) codecMember(getFoo$$$V, getFoo$$$C);
- THIS,
+ loadThis(),
getField(instrumentedType, handleName),
getField(instrumentedType, contextName),
CODEC_MEMBER,
import net.bytebuddy.implementation.bytecode.member.MethodVariableAccess;
import net.bytebuddy.jar.asm.MethodVisitor;
import net.bytebuddy.jar.asm.Opcodes;
+import net.bytebuddy.matcher.ElementMatcher;
import net.bytebuddy.matcher.ElementMatchers;
import org.eclipse.jdt.annotation.Nullable;
import org.opendaylight.mdsal.binding.dom.codec.api.BindingStreamEventWriter;
private enum InitializeInstanceField implements ByteCodeAppender {
INSTANCE;
+ // TODO: eliminate this constant when ElementMatchers.isDefaultConstructor() returns a singleton
+ private static final ElementMatcher<MethodDescription> IS_DEFAULT_CONSTRUCTOR =
+ ElementMatchers.isDefaultConstructor();
+
@Override
public Size apply(final MethodVisitor methodVisitor, final Context implementationContext,
final MethodDescription instrumentedMethod) {
TypeCreation.of(instrumentedType),
Duplication.SINGLE,
MethodInvocation.invoke(instrumentedType.getDeclaredMethods()
- .filter(ElementMatchers.isDefaultConstructor()).getOnly().asDefined()),
+ .filter(IS_DEFAULT_CONSTRUCTOR).getOnly().asDefined()),
putField(instrumentedType, INSTANCE_FIELD))
.apply(methodVisitor, implementationContext);
return new Size(operandStackSize.getMaximalSize(), instrumentedMethod.getStackSize());
package org.opendaylight.mdsal.binding.dom.codec.impl;
import static com.google.common.base.Preconditions.checkState;
+import static org.opendaylight.mdsal.binding.dom.codec.impl.ByteBuddyUtils.getField;
+import static org.opendaylight.mdsal.binding.dom.codec.impl.ByteBuddyUtils.loadThis;
+import static org.opendaylight.mdsal.binding.dom.codec.impl.ByteBuddyUtils.putField;
import com.google.common.base.Throwables;
import java.lang.invoke.MethodHandle;
private enum ConstructorImplementation implements Implementation {
INSTANCE;
- private static final StackManipulation INSTANT_ARG = MethodVariableAccess.REFERENCE.loadFrom(3);
+ private static final StackManipulation LOAD_INSTANT_ARG = MethodVariableAccess.REFERENCE.loadFrom(3);
private static final StackManipulation LOAD_CTOR_ARGS;
static {
.filter(ElementMatchers.isConstructor()).getOnly();
return new ByteCodeAppender.Simple(
- ByteBuddyUtils.THIS,
+ loadThis(),
LOAD_CTOR_ARGS,
MethodInvocation.invoke(superCtor),
- ByteBuddyUtils.THIS,
- INSTANT_ARG,
- ByteBuddyUtils.putField(instrumentedType, INSTANT_FIELD),
+ loadThis(),
+ LOAD_INSTANT_ARG,
+ putField(instrumentedType, INSTANT_FIELD),
MethodReturn.VOID);
}
}
@Override
public ByteCodeAppender appender(final Target implementationTarget) {
return new ByteCodeAppender.Simple(
- ByteBuddyUtils.THIS,
- ByteBuddyUtils.getField(implementationTarget.getInstrumentedType(), INSTANT_FIELD),
+ loadThis(),
+ getField(implementationTarget.getInstrumentedType(), INSTANT_FIELD),
MethodReturn.REFERENCE);
}
}