Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java Jakarta Annotations #3094

Merged
merged 10 commits into from
Aug 11, 2023
2 changes: 1 addition & 1 deletion it/java/basic/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

<kiota-java.version>0.5.0</kiota-java.version>
<kiota-java.version>0.6.0</kiota-java.version>
</properties>

<dependencies>
Expand Down
6 changes: 3 additions & 3 deletions src/Kiota.Builder/Writers/Java/CodeEnumWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ public override void WriteCodeElement(CodeEnum codeElement, LanguageWriter write
writer.WriteLine("this.value = value;");
writer.DecreaseIndent();
writer.WriteLines("}",
"@javax.annotation.Nonnull",
"@jakarta.annotation.Nonnull",
"public String getValue() { return this.value; }",
"@javax.annotation.Nullable",
$"public static {enumName} forValue(@javax.annotation.Nonnull final String searchValue) {{");
"@jakarta.annotation.Nullable",
$"public static {enumName} forValue(@jakarta.annotation.Nonnull final String searchValue) {{");
writer.IncreaseIndent();
writer.WriteLines("Objects.requireNonNull(searchValue);",
"switch(searchValue) {");
Expand Down
2 changes: 1 addition & 1 deletion src/Kiota.Builder/Writers/Java/CodeMethodWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public override void WriteCodeElement(CodeMethod codeElement, LanguageWriter wri
codeElement.IsOfKind(CodeMethodKind.RequestExecutor) &&
returnType.Equals("void", StringComparison.OrdinalIgnoreCase))
returnType = "Void"; //generic type for the future
writer.WriteLine(codeElement.ReturnType.IsNullable && !codeElement.IsAsync ? "@javax.annotation.Nullable" : "@javax.annotation.Nonnull");
writer.WriteLine(codeElement.ReturnType.IsNullable && !codeElement.IsAsync ? "@jakarta.annotation.Nullable" : "@jakarta.annotation.Nonnull");
var signatureReturnType = WriteMethodPrototype(codeElement, writer, returnType);
writer.IncreaseIndent();
var inherits = parentClass.StartBlock.Inherits != null && !parentClass.IsErrorDefinition;
Expand Down
4 changes: 2 additions & 2 deletions src/Kiota.Builder/Writers/Java/CodePropertyWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public override void WriteCodeElement(CodeProperty codeElement, LanguageWriter w
switch (codeElement.Kind)
{
case CodePropertyKind.RequestBuilder:
writer.WriteLine("@javax.annotation.Nonnull");
writer.WriteLine("@jakarta.annotation.Nonnull");
writer.StartBlock($"{conventions.GetAccessModifier(codeElement.Access)} {returnType} {codeElement.Name.ToFirstCharacterLowerCase()}() {{");
conventions.AddRequestBuilderBody(parentClass, returnType, writer);
writer.CloseBlock();
Expand All @@ -38,7 +38,7 @@ public override void WriteCodeElement(CodeProperty codeElement, LanguageWriter w
if (codeElement.Type is CodeType currentType && currentType.TypeDefinition is CodeEnum enumType && enumType.Flags)
returnType = $"EnumSet<{returnType}>";
if (codeElement.Access != AccessModifier.Private)
writer.WriteLine(codeElement.Type.IsNullable ? "@javax.annotation.Nullable" : "@javax.annotation.Nonnull");
writer.WriteLine(codeElement.Type.IsNullable ? "@jakarta.annotation.Nullable" : "@jakarta.annotation.Nonnull");
writer.WriteLine($"{conventions.GetAccessModifier(codeElement.Access)} {returnType} {codeElement.NamePrefix}{codeElement.Name.ToFirstCharacterLowerCase()}{defaultValue};");
break;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Kiota.Builder/Writers/Java/JavaConventionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public override string GetParameterSignature(CodeParameter parameter, CodeElemen
{
ArgumentNullException.ThrowIfNull(parameter);
var nullKeyword = parameter.Optional ? "Nullable" : "Nonnull";
var nullAnnotation = parameter.Type.IsNullable ? $"@javax.annotation.{nullKeyword} " : string.Empty;
var nullAnnotation = parameter.Type.IsNullable ? $"@jakarta.annotation.{nullKeyword} " : string.Empty;
return $"{nullAnnotation}final {GetTypeString(parameter.Type, targetElement)} {parameter.Name.ToFirstCharacterLowerCase()}";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ public void WritesEnum()
Assert.Contains("this.value = value", result);
Assert.Contains("public String getValue()", result);
Assert.Contains("return this.value", result);
Assert.Contains("@javax.annotation.Nonnull", result);
Assert.Contains("@javax.annotation.Nullable", result);
Assert.Contains("forValue(@javax.annotation.Nonnull final String searchValue)", result);
Assert.Contains("@jakarta.annotation.Nonnull", result);
Assert.Contains("@jakarta.annotation.Nullable", result);
Assert.Contains("forValue(@jakarta.annotation.Nonnull final String searchValue)", result);
Assert.Contains("default: return null;", result);
AssertExtensions.CurlyBracesAreClosed(result);
Assert.Contains(optionName, result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public void WritesCustomProperty()
writer.Write(property);
var result = tw.ToString();
Assert.Contains($"{TypeName} {PropertyName}", result);
Assert.Contains("@javax.annotation.Nullable", result);
Assert.Contains("@jakarta.annotation.Nullable", result);
}
[Fact]
public void WritesFlagEnums()
Expand All @@ -102,7 +102,7 @@ public void WritesNonNull()
(property.Type as CodeType).IsNullable = false;
writer.Write(property);
var result = tw.ToString();
Assert.Contains("@javax.annotation.Nonnull", result);
Assert.Contains("@jakarta.annotation.Nonnull", result);
}
[Fact]
public void WritesSerializationAnnotation()
Expand Down
Loading