|
| 1 | +// Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | +// Licensed under the MIT License. |
| 3 | + |
| 4 | +import com.azure.autorest.customization.ClassCustomization; |
| 5 | +import com.azure.autorest.customization.Customization; |
| 6 | +import com.azure.autorest.customization.LibraryCustomization; |
| 7 | +import com.azure.autorest.customization.PackageCustomization; |
| 8 | +import com.github.javaparser.ast.type.ClassOrInterfaceType; |
| 9 | +import org.slf4j.Logger; |
| 10 | + |
| 11 | +/** |
| 12 | + * Code customization after code generation. |
| 13 | + */ |
| 14 | +public class EventHubsCustomization extends Customization { |
| 15 | + @Override |
| 16 | + public void customize(LibraryCustomization customization, Logger logger) { |
| 17 | + PackageCustomization fluentModelsPackage = customization.getPackage("com.azure.resourcemanager.eventhubs.fluent.models"); |
| 18 | + // change base class from `ProxyResource` to `Resource`, to avoid breaking changes and compilation errors |
| 19 | + customizeResourceBaseClass(fluentModelsPackage.getClass("EHNamespaceInner")); |
| 20 | + customizeResourceBaseClass(fluentModelsPackage.getClass("ClusterInner")); |
| 21 | + } |
| 22 | + |
| 23 | + /** |
| 24 | + * Customize the base class to be "com.azure.core.management.Resource". |
| 25 | + * |
| 26 | + * @param customization the customization for class |
| 27 | + */ |
| 28 | + private static void customizeResourceBaseClass(ClassCustomization customization) { |
| 29 | + customization.customizeAst(ast -> { |
| 30 | + ast.getClassByName(customization.getClassName()).ifPresent(clazz -> { |
| 31 | + String resourceClassName = "com.azure.core.management.Resource"; |
| 32 | + ast.addImport(resourceClassName); |
| 33 | + clazz.getExtendedTypes().clear(); |
| 34 | + clazz.addExtendedType(new ClassOrInterfaceType(null, "Resource")); |
| 35 | + }); |
| 36 | + }); |
| 37 | + } |
| 38 | +} |
0 commit comments