Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public CodeModel preTransform(CodeModel codeModel) {

public CodeModel postTransform(CodeModel codeModel) {
codeModel = new OperationGroupFilter(fluentJavaSettings.getJavaNamesForRemoveOperationGroup()).process(codeModel);
codeModel = new OperationGroupRenamer(fluentJavaSettings.getJavaNamesForRenameOperationGroup()).process(codeModel);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be before NamingConflictResolver?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, makes sense. If we have two conflict operation groups and want to rename, we probably want to rename both.

codeModel = new NamingConflictResolver().process(codeModel);
codeModel = new SchemaRenamer(fluentJavaSettings.getJavaNamesForRenameModel()).process(codeModel);
codeModel = new OperationNameNormalization().process(codeModel);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.autorest.fluent.transformer;

import com.azure.autorest.extension.base.model.codemodel.CodeModel;
import com.azure.autorest.extension.base.plugin.PluginLogger;
import com.azure.autorest.fluent.util.Utils;
import com.azure.autorest.fluentnamer.FluentNamer;
import com.azure.autorest.preprocessor.namer.CodeNamer;
import org.slf4j.Logger;

import java.util.Map;

public class OperationGroupRenamer {

private final Logger logger = new PluginLogger(FluentNamer.getPluginInstance(), OperationGroupRenamer.class);

private final Map<String, String> renameOperationGroup;

public OperationGroupRenamer(Map<String, String> renameOperationGroup) {
this.renameOperationGroup = renameOperationGroup;
}

public CodeModel process(CodeModel codeModel) {
// rename operation group
codeModel.getOperationGroups().forEach(og -> {
String methodGroupName = CodeNamer.getPlural(Utils.getJavaName(og));
String rename = renameOperationGroup.get(methodGroupName);
if (rename != null) {
og.getLanguage().getJava().setName(rename);
logger.info("Renamed operation group from '{}' to '{}'.", methodGroupName, rename);
}
});
return codeModel;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ public class FluentJavaSettings {

private final Set<String> javaNamesForPropertyIncludeAlways = new HashSet<>();

private final Map<String, String> renameOperationGroup = new HashMap<>();

private String pomFilename = "pom.xml";

private String artifactVersion;
Expand Down Expand Up @@ -134,6 +136,10 @@ public Set<String> getJavaNamesForPropertyIncludeAlways() {
return javaNamesForPropertyIncludeAlways;
}

public Map<String, String> getJavaNamesForRenameOperationGroup() {
return renameOperationGroup;
}

public String getPomFilename() {
return pomFilename;
}
Expand Down Expand Up @@ -181,6 +187,21 @@ private void loadSettings() {

loadStringSetting("remove-operation-group", s -> splitStringToSet(s, javaNamesForRemoveOperationGroup));

loadStringSetting("rename-operation-group", s -> {
if (!CoreUtils.isNullOrEmpty(s)) {
String[] renamePairs = s.split(Pattern.quote(","));
for (String pair : renamePairs) {
String[] fromAndTo = pair.split(Pattern.quote(":"));
if (fromAndTo.length == 2) {
String from = fromAndTo[0];
String to = fromAndTo[1];
if (!CoreUtils.isNullOrEmpty(from) && !CoreUtils.isNullOrEmpty(to)) {
renameOperationGroup.put(from, to);
}
}
}
}
});
// loadBooleanSetting("track1-naming", b -> track1Naming = b);
// loadBooleanSetting("resource-property-as-subresource", b -> resourcePropertyAsSubResource = b);

Expand Down