+ private <T extends DataNodeContainer & ActionNodeContainer> void actionsToGenType(final ModuleContext context,
+ final Type parent, final T parentSchema, final Type keyType, final boolean inGrouping) {
+ for (final ActionDefinition action : parentSchema.getActions()) {
+ if (action.isAugmenting()) {
+ continue;
+ }
+
+ final GeneratedType input;
+ final GeneratedType output;
+ if (action.isAddedByUses()) {
+ final ActionDefinition orig = findOrigAction(parentSchema, action).get();
+ // Original definition may live in a different module, make sure we account for that
+ final ModuleContext origContext = moduleContext(
+ orig.getPath().getPathFromRoot().iterator().next().getModule());
+ input = context.addAliasType(origContext, orig.getInput(), action.getInput());
+ output = context.addAliasType(origContext, orig.getOutput(), action.getOutput());
+ } else {
+ input = actionContainer(context, RPC_INPUT, action.getInput(), inGrouping);
+ output = actionContainer(context, RPC_OUTPUT, action.getOutput(), inGrouping);
+ }
+
+ if (!(parentSchema instanceof GroupingDefinition)) {
+ // Parent is a non-grouping, hence we need to establish an Action instance, which can be completely
+ // identified by an InstanceIdentifier. We do not generate Actions for groupings as they are inexact,
+ // and do not capture an actual instantiation.
+ final QName qname = action.getQName();
+ final GeneratedTypeBuilder builder = typeProvider.newGeneratedTypeBuilder(JavaTypeName.create(
+ packageNameForGeneratedType(context.modulePackageName(), action.getPath()),
+ BindingMapping.getClassName(qname)));
+ qnameConstant(builder, JavaTypeName.create(context.modulePackageName(),
+ BindingMapping.MODULE_INFO_CLASS_NAME), qname.getLocalName());
+
+ annotateDeprecatedIfNecessary(action, builder);
+ builder.addImplementsType(keyType != null ? keyedListAction(parent, keyType, input, output)
+ : action(parent, input, output));
+
+ addCodegenInformation(builder, context.module(), action);
+ context.addChildNodeType(action, builder);
+ }
+ }
+ }
+
+ private Optional<ActionDefinition> findOrigAction(final DataNodeContainer parent, final ActionDefinition action) {
+ final QName qname = action.getQName();
+ for (UsesNode uses : parent.getUses()) {
+ final GroupingDefinition grp = findUsedGrouping(uses);
+ // Target grouping may reside in a different module, hence we need to rebind the QName to match grouping's
+ // namespace
+ final Optional<ActionDefinition> found = grp.findAction(qname.withModule(grp.getQName().getModule()));
+ if (found.isPresent()) {
+ final ActionDefinition result = found.get();
+ return result.isAddedByUses() ? findOrigAction(grp, result) : found;
+ }
+ }
+
+ return Optional.empty();
+ }
+
+ private GeneratedType actionContainer(final ModuleContext context, final Type baseInterface,
+ final ContainerSchemaNode schema, final boolean inGrouping) {
+ final GeneratedTypeBuilder genType = processDataSchemaNode(context, baseInterface, schema, inGrouping);
+ resolveDataSchemaNodes(context, genType, genType, schema.getChildNodes(), inGrouping);
+ return genType.build();
+ }
+