Skip to content

Commit

Permalink
chore(java): Upgrade java IR to v53 (#5379)
Browse files Browse the repository at this point in the history
* chore(java): Upgrade java IR to v53

* Fix upgrade breaks

* Add changelog entries

* chore: update changelog

* Add versions to migrator

* Bump cli version

* chore: update changelog

---------

Co-authored-by: Alberto <[email protected]>
Co-authored-by: ajgateno <[email protected]>
  • Loading branch information
3 people authored Dec 10, 2024
1 parent a5e0009 commit ddcbb96
Show file tree
Hide file tree
Showing 18 changed files with 288 additions and 119 deletions.
4 changes: 4 additions & 0 deletions fern/pages/changelogs/cli/2024-12-10.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## 0.45.4-rc1
**`(chore):`** Bumped Java IR to latest (v53)


4 changes: 4 additions & 0 deletions fern/pages/changelogs/java-model/2024-12-10.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## 1.3.0
**`(chore):`** Bump IR version to latest (v53)


4 changes: 4 additions & 0 deletions fern/pages/changelogs/java-spring/2024-12-10.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## 1.3.0
**`(chore):`** Bump IR version to latest (v53)


2 changes: 1 addition & 1 deletion generators/java/generator-utils/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
dependencies {
api 'com.squareup:javapoet'
api 'com.fern.fern:irV46'
api 'com.fern.fern:irV53'
api 'com.fern.fern:generator-exec-client'
api 'com.fasterxml.jackson.core:jackson-annotations'
api 'com.fasterxml.jackson.core:jackson-databind'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,7 @@

import com.fasterxml.jackson.databind.JsonNode;
import com.fern.ir.model.commons.TypeId;
import com.fern.ir.model.types.AliasTypeDeclaration;
import com.fern.ir.model.types.ContainerType;
import com.fern.ir.model.types.DeclaredTypeName;
import com.fern.ir.model.types.Literal;
import com.fern.ir.model.types.MapType;
import com.fern.ir.model.types.PrimitiveType;
import com.fern.ir.model.types.PrimitiveTypeV1;
import com.fern.ir.model.types.ResolvedNamedType;
import com.fern.ir.model.types.ResolvedTypeReference;
import com.fern.ir.model.types.TypeDeclaration;
import com.fern.ir.model.types.TypeReference;
import com.fern.ir.model.types.*;
import com.squareup.javapoet.ArrayTypeName;
import com.squareup.javapoet.ClassName;
import com.squareup.javapoet.ParameterizedTypeName;
Expand Down Expand Up @@ -57,17 +47,21 @@ private TypeReferenceToTypeNameConverter(boolean primitiveAllowed) {
}

@Override
public TypeName visitNamed(DeclaredTypeName declaredTypeName) {
public TypeName visitNamed(NamedType named) {
if (!customConfig.wrappedAliases()) {
TypeDeclaration typeDeclaration = typeDefinitionsByName.get(declaredTypeName.getTypeId());
TypeDeclaration typeDeclaration = typeDefinitionsByName.get(named.getTypeId());
boolean isAlias = typeDeclaration.getShape().isAlias();
if (isAlias) {
AliasTypeDeclaration aliasTypeDeclaration =
typeDeclaration.getShape().getAlias().get();
return aliasTypeDeclaration.getResolvedType().visit(this);
}
}
return poetClassNameFactory.getTypeClassName(declaredTypeName);
return poetClassNameFactory.getTypeClassName(DeclaredTypeName.builder()
.typeId(named.getTypeId())
.fernFilepath(named.getFernFilepath())
.name(named.getName())
.build());
}

@Override
Expand Down Expand Up @@ -139,6 +133,30 @@ public TypeName visitLong() {
return ClassName.get(Long.class);
}

@Override
public TypeName visitUint() {
if (primitiveAllowed) {
return TypeName.LONG;
}
return ClassName.get(Long.class);
}

@Override
public TypeName visitUint64() {
if (primitiveAllowed) {
return TypeName.LONG;
}
return ClassName.get(Long.class);
}

@Override
public TypeName visitFloat() {
if (primitiveAllowed) {
return TypeName.FLOAT;
}
return ClassName.get(Float.class);
}

@Override
public TypeName visitDateTime() {
return ClassName.get(OffsetDateTime.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,21 @@ public CodeBlock visitLong() {
return CodeBlock.of("return $T.$L($L)", Long.class, "toString", VALUE_FIELD_NAME);
}

@Override
public CodeBlock visitUint() {
return CodeBlock.of("return $T.$L($L)", Long.class, "toString", VALUE_FIELD_NAME);
}

@Override
public CodeBlock visitUint64() {
return CodeBlock.of("return $T.$L($L)", Long.class, "toString", VALUE_FIELD_NAME);
}

@Override
public CodeBlock visitFloat() {
return CodeBlock.of("return $T.$L($L)", Float.class, "toString", VALUE_FIELD_NAME);
}

@Override
public CodeBlock visitDateTime() {
return CodeBlock.of("return $L.$L()", VALUE_FIELD_NAME, "toString");
Expand Down Expand Up @@ -273,6 +288,21 @@ public CodeBlock visitLong() {
return CodeBlock.of("return $L.hashCode()", VALUE_FIELD_NAME);
}

@Override
public CodeBlock visitUint() {
return CodeBlock.of("return $L.hashCode()", VALUE_FIELD_NAME);
}

@Override
public CodeBlock visitUint64() {
return CodeBlock.of("return $L.hashCode()", VALUE_FIELD_NAME);
}

@Override
public CodeBlock visitFloat() {
return CodeBlock.of("return $T.hashCode($L)", Float.class, VALUE_FIELD_NAME);
}

@Override
public CodeBlock visitDateTime() {
return CodeBlock.of("return $L.hashCode()", VALUE_FIELD_NAME);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,7 @@
import com.fasterxml.jackson.annotation.JsonValue;
import com.fern.ir.model.commons.NameAndWireValue;
import com.fern.ir.model.constants.Constants;
import com.fern.ir.model.types.DeclaredTypeName;
import com.fern.ir.model.types.SingleUnionType;
import com.fern.ir.model.types.SingleUnionTypeProperties;
import com.fern.ir.model.types.SingleUnionTypeProperty;
import com.fern.ir.model.types.TypeReference;
import com.fern.ir.model.types.UnionTypeDeclaration;
import com.fern.ir.model.types.*;
import com.fern.java.AbstractGeneratorContext;
import com.fern.java.FernJavaAnnotations;
import com.fern.java.generators.union.UnionSubType;
Expand Down Expand Up @@ -192,7 +187,13 @@ public Void visitSamePropertiesAsObject(DeclaredTypeName samePropertiesAsObject)
generatorContext
.getPoetTypeNameMapper()
.convertToTypeName(
true, TypeReference.named(samePropertiesAsObject)),
true,
TypeReference.named(NamedType.builder()
.typeId(samePropertiesAsObject.getTypeId())
.fernFilepath(
samePropertiesAsObject.getFernFilepath())
.name(samePropertiesAsObject.getName())
.build())),
"value")
.build())
.addStatement("this.$L = $L", "value", "value")
Expand Down Expand Up @@ -275,7 +276,13 @@ public Optional<FieldSpec> visitSamePropertiesAsObject(DeclaredTypeName sameProp
return Optional.of(FieldSpec.builder(
generatorContext
.getPoetTypeNameMapper()
.convertToTypeName(true, TypeReference.named(samePropertiesAsObject)),
.convertToTypeName(
true,
TypeReference.named(NamedType.builder()
.typeId(samePropertiesAsObject.getTypeId())
.fernFilepath(samePropertiesAsObject.getFernFilepath())
.name(samePropertiesAsObject.getName())
.build())),
"value",
Modifier.PRIVATE)
.addAnnotation(JsonUnwrapped.class)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
package com.fern.java.utils;

import com.fern.ir.model.types.ContainerType;
import com.fern.ir.model.types.DeclaredTypeName;
import com.fern.ir.model.types.Literal;
import com.fern.ir.model.types.MapType;
import com.fern.ir.model.types.PrimitiveType;
import com.fern.ir.model.types.PrimitiveTypeV1;
import com.fern.ir.model.types.TypeReference;
import com.fern.ir.model.types.*;
import java.util.Optional;

public class TypeReferenceUtils {
Expand Down Expand Up @@ -56,7 +50,7 @@ public String visitContainer(ContainerType container) {
}

@Override
public String visitNamed(DeclaredTypeName named) {
public String visitNamed(NamedType named) {
return named.getName().getPascalCase().getUnsafeName();
}

Expand Down Expand Up @@ -171,6 +165,21 @@ public String visitLong() {
return "Long";
}

@Override
public String visitUint() {
return "Long";
}

@Override
public String visitUint64() {
return "Long";
}

@Override
public String visitFloat() {
return "Float";
}

@Override
public String visitDateTime() {
return "DateTime";
Expand Down
7 changes: 7 additions & 0 deletions generators/java/model/versions.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
- changelogEntry:
- summary: |
Bump IR version to latest (v53)
type: chore
createdAt: '2024-12-10'
irVersion: 53
version: 1.3.0
- changelogEntry:
- summary: |
Bump Jackson version to latest (2.17.2)
Expand Down
Loading

0 comments on commit ddcbb96

Please sign in to comment.