Skip to content

Commit

Permalink
Remove codegen bridge as the functionality is now in azure-core (#2628)
Browse files Browse the repository at this point in the history
Remove codegen bridge as the functionality is now in azure-core
  • Loading branch information
alzimmermsft authored Mar 18, 2024
1 parent ec6c18e commit 90517f2
Show file tree
Hide file tree
Showing 43 changed files with 57 additions and 4,059 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
package fixtures.bodycomplex.implementation.models;

import com.azure.core.annotation.Fluent;
import com.azure.core.util.CoreUtils;
import com.azure.json.JsonReader;
import com.azure.json.JsonSerializable;
import com.azure.json.JsonToken;
import com.azure.json.JsonWriter;
import fixtures.bodycomplex.implementation.CoreToCodegenBridgeUtils;
import java.io.IOException;
import java.time.Duration;

Expand Down Expand Up @@ -55,7 +55,7 @@ public DurationWrapper setField(Duration field) {
@Override
public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
jsonWriter.writeStartObject();
jsonWriter.writeStringField("field", CoreToCodegenBridgeUtils.durationToStringWithDays(this.field));
jsonWriter.writeStringField("field", CoreUtils.durationToStringWithDays(this.field));
return jsonWriter.writeEndObject();
}

Expand Down
14 changes: 0 additions & 14 deletions javagen/src/main/java/com/azure/autorest/Javagen.java
Original file line number Diff line number Diff line change
Expand Up @@ -341,20 +341,6 @@ protected void writeClientModels(Client client, JavaPackage javaPackage, JavaSet
}

protected void writeHelperClasses(Client client, JavaPackage javaPackage, JavaSettings settings) {
// While azure-core's ResponseError hasn't shipped implementing JsonSerializable add a utility method that
// will serialize and deserialize ResponseError.
if (settings.isStreamStyleSerialization()) {
boolean generateCoreToCodegenBridgeUtils = false;
for (ClientModel model : client.getModels()) {
if (ClientModelUtil.generateCoreToCodegenBridgeUtils(model, settings)) {
generateCoreToCodegenBridgeUtils = true;
break;
}
}
if (generateCoreToCodegenBridgeUtils) {
javaPackage.addJavaFromResources(settings.getPackage(settings.getImplementationSubpackage()), ClientModelUtil.CORE_TO_CODEGEN_BRIDGE_UTILS_CLASS_NAME);
}
}
}

private void clear() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import com.azure.autorest.extension.base.model.extensionmodel.XmsExtensions;
import com.azure.autorest.extension.base.plugin.JavaSettings;
import com.azure.autorest.util.ClientModelUtil;
import com.azure.autorest.util.TemplateUtil;
import com.azure.core.client.traits.ConfigurationTrait;
import com.azure.core.client.traits.EndpointTrait;
Expand Down Expand Up @@ -149,6 +148,24 @@ private static ClassType.Builder getClassTypeBuilder(Class<?> classKey) {
}
}

public static final ClassType REQUEST_CONDITIONS = new Builder().knownClass(RequestConditions.class).build();
public static final ClassType MATCH_CONDITIONS = new Builder().knownClass(MatchConditions.class).build();
public static final ClassType CORE_UTILS = getClassTypeBuilder(CoreUtils.class).build();
public static final ClassType RESPONSE = getClassTypeBuilder(Response.class).build();
public static final ClassType SIMPLE_RESPONSE = getClassTypeBuilder(SimpleResponse.class).build();
public static final ClassType EXPANDABLE_STRING_ENUM = getClassTypeBuilder(ExpandableStringEnum.class).build();
public static final ClassType HTTP_PIPELINE_BUILDER = getClassTypeBuilder(HttpPipelineBuilder.class).build();
public static final ClassType KEY_CREDENTIAL_POLICY = getClassTypeBuilder(KeyCredentialPolicy.class).build();
public static final ClassType KEY_CREDENTIAL_TRAIT = getClassTypeBuilder(KeyCredentialTrait.class).build();
public static final ClassType ENDPOINT_TRAIT = getClassTypeBuilder(EndpointTrait.class).build();
public static final ClassType HTTP_TRAIT = getClassTypeBuilder(HttpTrait.class).build();
public static final ClassType CONFIGURATION_TRAIT = getClassTypeBuilder(ConfigurationTrait.class).build();
public static final ClassType POLL_OPERATION_DETAILS = getClassTypeBuilder(PollOperationDetails.class).build();
public static final ClassType JSON_SERIALIZABLE = getClassTypeBuilder(JsonSerializable.class).build();
public static final ClassType JSON_WRITER = getClassTypeBuilder(JsonWriter.class).build();
public static final ClassType JSON_READER = getClassTypeBuilder(JsonReader.class).build();
public static final ClassType JSON_TOKEN = getClassTypeBuilder(JsonToken.class).build();
public static final ClassType TYPE_REFERENCE = getClassTypeBuilder(TypeReference.class).build();

public static final ClassType VOID = new ClassType.Builder(false).knownClass(Void.class).build();

Expand Down Expand Up @@ -254,7 +271,7 @@ private static ClassType.Builder getClassTypeBuilder(Class<?> classKey) {
public static final ClassType DURATION = new Builder(false).knownClass(Duration.class)
.defaultValueExpressionConverter(defaultValueExpression -> "Duration.parse(\"" + defaultValueExpression + "\")")
.jsonToken("JsonToken.STRING")
.serializationValueGetterModifier(valueGetter -> ClientModelUtil.CORE_TO_CODEGEN_BRIDGE_UTILS_CLASS_NAME + ".durationToStringWithDays(" + valueGetter + ")")
.serializationValueGetterModifier(valueGetter -> CORE_UTILS.getName() + ".durationToStringWithDays(" + valueGetter + ")")
.jsonDeserializationMethod("getNullable(nonNullReader -> Duration.parse(nonNullReader.getString()))")
.serializationMethodBase("writeString")
.xmlElementDeserializationMethod("getNullableElement(Duration::parse)")
Expand Down Expand Up @@ -471,25 +488,6 @@ private static ClassType.Builder getClassTypeBuilder(Class<?> classKey) {
.jsonToken("JsonToken.START_OBJECT")
.build();

public static final ClassType REQUEST_CONDITIONS = new Builder().knownClass(RequestConditions.class).build();
public static final ClassType MATCH_CONDITIONS = new Builder().knownClass(MatchConditions.class).build();
public static final ClassType CORE_UTILS = getClassTypeBuilder(CoreUtils.class).build();
public static final ClassType RESPONSE = getClassTypeBuilder(Response.class).build();
public static final ClassType SIMPLE_RESPONSE = getClassTypeBuilder(SimpleResponse.class).build();
public static final ClassType EXPANDABLE_STRING_ENUM = getClassTypeBuilder(ExpandableStringEnum.class).build();
public static final ClassType HTTP_PIPELINE_BUILDER = getClassTypeBuilder(HttpPipelineBuilder.class).build();
public static final ClassType KEY_CREDENTIAL_POLICY = getClassTypeBuilder(KeyCredentialPolicy.class).build();
public static final ClassType KEY_CREDENTIAL_TRAIT = getClassTypeBuilder(KeyCredentialTrait.class).build();
public static final ClassType ENDPOINT_TRAIT = getClassTypeBuilder(EndpointTrait.class).build();
public static final ClassType HTTP_TRAIT = getClassTypeBuilder(HttpTrait.class).build();
public static final ClassType CONFIGURATION_TRAIT = getClassTypeBuilder(ConfigurationTrait.class).build();
public static final ClassType POLL_OPERATION_DETAILS = getClassTypeBuilder(PollOperationDetails.class).build();
public static final ClassType JSON_SERIALIZABLE = getClassTypeBuilder(JsonSerializable.class).build();
public static final ClassType JSON_WRITER = getClassTypeBuilder(JsonWriter.class).build();
public static final ClassType JSON_READER = getClassTypeBuilder(JsonReader.class).build();
public static final ClassType JSON_TOKEN = getClassTypeBuilder(JsonToken.class).build();
public static final ClassType TYPE_REFERENCE = getClassTypeBuilder(TypeReference.class).build();

private final String fullName;
private final String packageName;
private final String name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,6 @@ protected void addSerializationImports(Set<String> imports, ClientModel model, J
imports.add(List.class.getName());
imports.add(Map.class.getName());
imports.add(Objects.class.getName());
imports.add(settings.getPackage(settings.getImplementationSubpackage()) + "."
+ ClientModelUtil.CORE_TO_CODEGEN_BRIDGE_UTILS_CLASS_NAME);
}

@Override
Expand Down Expand Up @@ -377,11 +375,7 @@ private static void serializeJsonProperty(JavaBlock methodBlock, ClientModelProp
// This is primitives, boxed primitives, a small set of string based models, and other ClientModels.
String fieldSerializationMethod = wireType.jsonSerializationMethodCall("jsonWriter", serializedName,
propertyValueGetter);
if (wireType == ClassType.RESPONSE_ERROR) {
// While azure-core hasn't shipped ResponseError implementing JsonSerializable it has special handling.
methodBlock.line("jsonWriter.writeFieldName(\"" + serializedName + "\");");
methodBlock.line(ClientModelUtil.CORE_TO_CODEGEN_BRIDGE_UTILS_CLASS_NAME + ".responseErrorToJson(jsonWriter, " + propertyValueGetter + ");");
} else if (fieldSerializationMethod != null) {
if (fieldSerializationMethod != null) {
if (isJsonMergePatch && wireType instanceof ClassType && ((ClassType) wireType).isSwaggerType()) {
methodBlock.line(propertyValueGetter + ".serializeAsJsonMergePatch(true);");
}
Expand Down Expand Up @@ -475,11 +469,7 @@ private static void serializeJsonContainerProperty(JavaBlock methodBlock, String
}

methodBlock.indent(() -> {
if (elementType == ClassType.RESPONSE_ERROR) {
// While azure-core hasn't shipped ResponseError implementing JsonSerializable it has special handling.
methodBlock.line(lambdaWriterName + ".writeFieldName(\"" + serializedName + "\");");
methodBlock.line(ClientModelUtil.CORE_TO_CODEGEN_BRIDGE_UTILS_CLASS_NAME + ".responseErrorToJson(" + lambdaWriterName + ", " + propertyValueGetter + ");");
} else if (valueSerializationMethod != null) {
if (valueSerializationMethod != null) {
if (isJsonMergePatch && containerType instanceof MapType) {
methodBlock.block("", codeBlock -> {
codeBlock.ifBlock(elementName + "!=null", ifBlock -> {
Expand Down Expand Up @@ -1038,15 +1028,7 @@ private static void generateJsonDeserializationLogic(JavaBlock deserializationBl
// Attempt to determine whether the wire type is simple deserialization.
// This is primitives, boxed primitives, a small set of string based models, and other ClientModels.
String simpleDeserialization = getSimpleJsonDeserialization(wireType, "reader");
if (wireType == ClassType.RESPONSE_ERROR) {
// While azure-core hasn't shipped ResponseError implementing JsonSerializable it has special handling.
if (!hasConstructorArguments) {
handleSettingDeserializedValue(deserializationBlock, modelVariableName, property,
ClientModelUtil.CORE_TO_CODEGEN_BRIDGE_UTILS_CLASS_NAME + ".responseErrorFromJson(reader)", fromSuper);
} else {
deserializationBlock.line(property.getName() + " = " + ClientModelUtil.CORE_TO_CODEGEN_BRIDGE_UTILS_CLASS_NAME + ".responseErrorFromJson(reader);");
}
} else if (simpleDeserialization != null) {
if (simpleDeserialization != null) {
// Need to convert the wire type to the client type for constructors.
// Need to convert the wire type to the client type for public setters.
boolean convertToClientType = (clientType != wireType)
Expand Down Expand Up @@ -1153,10 +1135,7 @@ private static void deserializeJsonContainerProperty(JavaBlock methodBlock, Stri
methodBlock.line(callingReaderName + "." + utilityMethod + "(" + lambdaReaderName + " ->");
}
methodBlock.indent(() -> {
if (elementWireType == ClassType.RESPONSE_ERROR) {
// While azure-core hasn't shipped ResponseError implementing JsonSerializable it has special handling.
methodBlock.line(ClientModelUtil.CORE_TO_CODEGEN_BRIDGE_UTILS_CLASS_NAME + ".responseErrorFromJson(" + lambdaReaderName + ")");
} else if (valueDeserializationMethod != null) {
if (valueDeserializationMethod != null) {
if (convertToClientType) {
// If the wire type is nullable don't attempt to call the convert to client type until it's known that
// a value was deserialized. This protects against cases such as UnixTimeLong where the wire type is
Expand Down
Loading

0 comments on commit 90517f2

Please sign in to comment.