X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=binding%2Fmdsal-binding-dom-codec%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fmdsal%2Fbinding%2Fdom%2Fcodec%2Fimpl%2FCodecDataObjectGenerator.java;h=19f31386fa760760d15b3d1af6b8f6dcf7ab37c7;hb=c3613aa89ab5619abc59ac6e0e6890a9041249c7;hp=62776c833c163554762bbc0229b6f8c88d0166c2;hpb=956e0bfdf6ddea00c23e0e57d2b90e83c5cf9b60;p=mdsal.git
diff --git a/binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/CodecDataObjectGenerator.java b/binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/CodecDataObjectGenerator.java
index 62776c833c..19f31386fa 100644
--- a/binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/CodecDataObjectGenerator.java
+++ b/binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/CodecDataObjectGenerator.java
@@ -41,13 +41,12 @@ import net.bytebuddy.implementation.bytecode.member.MethodReturn;
import net.bytebuddy.implementation.bytecode.member.MethodVariableAccess;
import net.bytebuddy.jar.asm.Opcodes;
import org.eclipse.jdt.annotation.Nullable;
+import org.opendaylight.mdsal.binding.dom.codec.impl.ClassGeneratorBridge.CodecContextSupplierProvider;
import org.opendaylight.mdsal.binding.dom.codec.impl.ClassGeneratorBridge.LocalNameProvider;
-import org.opendaylight.mdsal.binding.dom.codec.impl.ClassGeneratorBridge.NodeContextSupplierProvider;
import org.opendaylight.mdsal.binding.loader.BindingClassLoader;
import org.opendaylight.mdsal.binding.loader.BindingClassLoader.ClassGenerator;
import org.opendaylight.mdsal.binding.loader.BindingClassLoader.GeneratorResult;
-import org.opendaylight.mdsal.binding.spec.naming.BindingMapping;
-import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.contract.Naming;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -59,7 +58,7 @@ import org.slf4j.LoggerFactory;
* strong connection between a generated class to the extent possible. In most cases (grouping-generated types) this
* involves one level of indirection, which is a safe approach. If we are dealing with a type generated outside of a
* grouping statement, though, we are guaranteed instantiation-invariance and hence can hard-wire to a runtime-constant
- * {@link NodeContextSupplier} -- which provides significant boost to JITs ability to optimize code -- especially with
+ * {@link CodecContextSupplier} -- which provides significant boost to JITs ability to optimize code -- especially with
* inlining and constant propagation.
*
*
@@ -133,14 +132,14 @@ import org.slf4j.LoggerFactory;
* and class loading (in {@link BindingClassLoader}). The process is performed in four steps:
*
* - During code generation, the context fields are pointed towards
- * {@link ClassGeneratorBridge#resolveNodeContextSupplier(String)} and
+ * {@link ClassGeneratorBridge#resolveCodecContextSupplier(String)} and
* {@link ClassGeneratorBridge#resolveKey(String)} methods, which are public and static, hence perfectly usable
* in the context of a class initializer.
* - During class loading of generated byte code, the original instance of the generator is called to wrap the actual
* class loading operation. At this point the generator installs itself as the current generator for this thread via
* {@link ClassGeneratorBridge#setup(CodecDataObjectGenerator)} and allows the class to be loaded.
*
- After the class has been loaded, but before the call returns, we will force the class to initialize, at which
- * point the static invocations will be redirected to {@link #resolveNodeContextSupplier(String)} and
+ * point the static invocations will be redirected to {@link #resolveCodecContextSupplier(String)} and
* {@link #resolveKey(String)} methods, thus initializing the fields to the intended constants.
* - Before returning from the class loading call, the generator will detach itself via
* {@link ClassGeneratorBridge#tearDown(CodecDataObjectGenerator)}.
@@ -155,10 +154,10 @@ abstract class CodecDataObjectGenerator> implements
// FIXME: MDSAL-443: wire this implementation, which requires that BindingRuntimeTypes provides information about
// types being generated from within a grouping
private static final class Fixed> extends CodecDataObjectGenerator
- implements NodeContextSupplierProvider {
- private final ImmutableMap properties;
+ implements CodecContextSupplierProvider {
+ private final ImmutableMap properties;
- Fixed(final TypeDescription superClass, final ImmutableMap properties,
+ Fixed(final TypeDescription superClass, final ImmutableMap properties,
final @Nullable Method keyMethod) {
super(superClass, keyMethod);
this.properties = requireNonNull(properties);
@@ -170,7 +169,7 @@ abstract class CodecDataObjectGenerator> implements
for (Method method : properties.keySet()) {
LOG.trace("Generating for fixed method {}", method);
final String methodName = method.getName();
- final TypeDescription retType = TypeDescription.ForLoadedType.of(method.getReturnType());
+ final TypeDescription retType = ForLoadedType.of(method.getReturnType());
tmp = tmp.defineMethod(methodName, retType, PUB_FINAL).intercept(
new SupplierGetterMethodImplementation(methodName, retType));
}
@@ -178,8 +177,8 @@ abstract class CodecDataObjectGenerator> implements
}
@Override
- public NodeContextSupplier resolveNodeContextSupplier(final String methodName) {
- final Optional> found = properties.entrySet().stream()
+ public CodecContextSupplier resolveCodecContextSupplier(final String methodName) {
+ final Optional> found = properties.entrySet().stream()
.filter(entry -> methodName.equals(entry.getKey().getName())).findAny();
verify(found.isPresent(), "Failed to find property for %s in %s", methodName, this);
return verifyNotNull(found.orElseThrow().getValue());
@@ -205,7 +204,7 @@ abstract class CodecDataObjectGenerator> implements
for (Method method : simpleProperties.keySet()) {
LOG.trace("Generating for simple method {}", method);
final String methodName = method.getName();
- final TypeDescription retType = TypeDescription.ForLoadedType.of(method.getReturnType());
+ final TypeDescription retType = ForLoadedType.of(method.getReturnType());
tmp = tmp.defineMethod(methodName, retType, PUB_FINAL).intercept(
new SimpleGetterMethodImplementation(methodName, retType));
}
@@ -214,7 +213,7 @@ abstract class CodecDataObjectGenerator> implements
final Method method = info.getterMethod();
LOG.trace("Generating for structured method {}", method);
final String methodName = method.getName();
- final TypeDescription retType = TypeDescription.ForLoadedType.of(method.getReturnType());
+ final TypeDescription retType = ForLoadedType.of(method.getReturnType());
tmp = tmp.defineMethod(methodName, retType, PUB_FINAL).intercept(
new StructuredGetterMethodImplementation(methodName, retType, entry.getKey()));
@@ -260,18 +259,17 @@ abstract class CodecDataObjectGenerator> implements
this.keyMethod = keyMethod;
}
- static > Class generate(final BindingClassLoader loader,
- final Class bindingInterface, final ImmutableMap simpleProperties,
+ static > Class generate(final BindingClassLoader loader,
+ final Class> bindingInterface, final ImmutableMap simpleProperties,
final Map, PropertyInfo> daoProperties, final Method keyMethod) {
- return loader.generateClass(bindingInterface, "codecImpl",
+ return CodecPackage.CODEC.generateClass(loader, bindingInterface,
new Reusable<>(BB_CDO, simpleProperties, daoProperties, keyMethod));
}
- static > Class generateAugmentable(
- final BindingClassLoader loader, final Class bindingInterface,
- final ImmutableMap simpleProperties,
+ static > Class generateAugmentable(final BindingClassLoader loader,
+ final Class> bindingInterface, final ImmutableMap simpleProperties,
final Map, PropertyInfo> daoProperties, final Method keyMethod) {
- return loader.generateClass(bindingInterface, "codecImpl",
+ return CodecPackage.CODEC.generateClass(loader, bindingInterface,
new Reusable<>(BB_ACDO, simpleProperties, daoProperties, keyMethod));
}
@@ -290,7 +288,7 @@ abstract class CodecDataObjectGenerator> implements
if (keyMethod != null) {
LOG.trace("Generating for key {}", keyMethod);
final String methodName = keyMethod.getName();
- final TypeDescription retType = TypeDescription.ForLoadedType.of(keyMethod.getReturnType());
+ final TypeDescription retType = ForLoadedType.of(keyMethod.getReturnType());
builder = builder.defineMethod(methodName, retType, PUB_FINAL).intercept(
new KeyMethodImplementation(methodName, retType));
}
@@ -316,7 +314,7 @@ abstract class CodecDataObjectGenerator> implements
return new Implementation.Simple(
// return Foo.bindingHashCode(this);
loadThis(),
- invokeMethod(bindingInterface, BindingMapping.BINDING_HASHCODE_NAME, bindingInterface),
+ invokeMethod(bindingInterface, Naming.BINDING_HASHCODE_NAME, bindingInterface),
MethodReturn.INTEGER);
}
@@ -325,7 +323,7 @@ abstract class CodecDataObjectGenerator> implements
// return Foo.bindingEquals(this, obj);
loadThis(),
FIRST_ARG_REF,
- invokeMethod(bindingInterface, BindingMapping.BINDING_EQUALS_NAME, bindingInterface, Object.class),
+ invokeMethod(bindingInterface, Naming.BINDING_EQUALS_NAME, bindingInterface, Object.class),
MethodReturn.INTEGER);
}
@@ -333,7 +331,7 @@ abstract class CodecDataObjectGenerator> implements
return new Implementation.Simple(
// return Foo.bindingToString(this);
loadThis(),
- invokeMethod(bindingInterface, BindingMapping.BINDING_TO_STRING_NAME, bindingInterface),
+ invokeMethod(bindingInterface, Naming.BINDING_TO_STRING_NAME, bindingInterface),
MethodReturn.REFERENCE);
}
@@ -351,7 +349,7 @@ abstract class CodecDataObjectGenerator> implements
private abstract static class AbstractCachedMethodImplementation extends AbstractMethodImplementation {
private static final Generic BB_HANDLE = TypeDefinition.Sort.describe(VarHandle.class);
private static final Generic BB_OBJECT = TypeDefinition.Sort.describe(Object.class);
- private static final StackManipulation OBJECT_CLASS = ClassConstant.of(TypeDescription.OBJECT);
+ private static final StackManipulation OBJECT_CLASS = ClassConstant.of(ForLoadedType.of(Object.class));
private static final StackManipulation LOOKUP = invokeMethod(MethodHandles.class, "lookup");
private static final StackManipulation FIND_VAR_HANDLE = invokeMethod(Lookup.class,
"findVarHandle", Class.class, String.class, Class.class);
@@ -518,10 +516,10 @@ abstract class CodecDataObjectGenerator> implements
private static final class SupplierGetterMethodImplementation extends AbstractCachedMethodImplementation {
private static final StackManipulation CODEC_MEMBER = invokeMethod(CodecDataObject.class,
- "codecMember", VarHandle.class, NodeContextSupplier.class);
+ "codecMember", VarHandle.class, CodecContextSupplier.class);
private static final StackManipulation BRIDGE_RESOLVE = invokeMethod(ClassGeneratorBridge.class,
"resolveNodeContextSupplier", String.class);
- private static final Generic BB_NCS = TypeDefinition.Sort.describe(NodeContextSupplier.class);
+ private static final Generic BB_NCS = TypeDefinition.Sort.describe(CodecContextSupplier.class);
// getFoo$$$C
private final String contextName;