Skip to content

Commit 8e29257

Browse files
committed
AnonymousClass -> AnonymousFunction, use ClassType.Function
1 parent 2fb450e commit 8e29257

File tree

4 files changed

+11
-25
lines changed

4 files changed

+11
-25
lines changed

src/JavaBlock.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ public void ReturnAnonymousClass(string anonymousClassDeclaration, Action<JavaCl
7171
contents.ReturnAnonymousClass(anonymousClassDeclaration, anonymousClassBlock);
7272
}
7373

74-
public void AnonymousClass(string anonymousClassDeclaration, Action<JavaClass> anonymousClassBlock)
74+
public void AnonymousFunction(string parameterType, string parameterName, string returnType, Action<JavaBlock> methodBlock)
7575
{
76-
contents.AnonymousClass(anonymousClassDeclaration, anonymousClassBlock);
76+
contents.AnonymousFunction(parameterType, parameterName, returnType, methodBlock);
7777
}
7878

7979
public JavaIfBlock If(string condition, Action<JavaBlock> ifAction)

src/JavaCodeGenerator.cs

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4289,10 +4289,7 @@ restAPIMethodReturnBodyClientType is ListType restAPIMethodReturnBodyClientListT
42894289
function.Indent(() =>
42904290
{
42914291
function.Text(".map(");
4292-
function.AnonymousClass($"new Function<{returnValueTypeArgumentType}, {mapperReturnType}>()", anonymousClass =>
4293-
{
4294-
anonymousClass.PublicMethod($"{mapperReturnType} apply(RestResponse<?, ?> res)", method => method.Return("res.body()"));
4295-
});
4292+
function.AnonymousFunction(returnValueTypeArgumentType.ToString(), "res", mapperReturnType.ToString(), method => method.Return("res.body()"));
42964293
function.Line(");");
42974294
});
42984295
});
@@ -4355,10 +4352,7 @@ restAPIMethodReturnBodyClientType is ListType restAPIMethodReturnBodyClientListT
43554352
{
43564353
function.Text(".map(");
43574354

4358-
function.AnonymousClass($"new Function<{returnValueTypeArgumentType}, {mapperReturnType}>()", anonymousClass =>
4359-
{
4360-
anonymousClass.PublicMethod($"{mapperReturnType} apply(RestResponse<?, {mapperReturnType}> res)", method => method.Return("res.body()"));
4361-
});
4355+
function.AnonymousFunction(returnValueTypeArgumentType.ToString(), "res", mapperReturnType.ToString(), method => method.Return("res.body()"));
43624356
function.Line(")");
43634357
function.Line(".toObservable();");
43644358
});
@@ -4566,23 +4560,15 @@ restAPIMethodReturnBodyClientType is ListType restAPIMethodReturnBodyClientListT
45664560
if (restAPIMethodReturnBodyClientType != PrimitiveType.Void)
45674561
{
45684562
function.Text($".flatMapMaybe(");
4569-
function.AnonymousClass($"new Function<{returnValueTypeArgumentClientType}, {mapperReturnType}>()", anonymousClassBlock =>
4570-
{
4571-
anonymousClassBlock.PublicMethod(
4572-
$"{mapperReturnType} apply({returnValueTypeArgumentClientType} res)",
4563+
function.AnonymousFunction(returnValueTypeArgumentClientType.ToString(), "res", mapperReturnType.ToString(),
45734564
method => method.Return($"res.body() == null ? Maybe.<{restAPIMethodReturnBodyClientType.AsNullable()}>empty() : Maybe.just(res.body())"));
4574-
});
45754565
function.Line(");");
45764566
}
45774567
else if (isFluentDelete)
45784568
{
45794569
function.Text($".flatMapMaybe(");
4580-
function.AnonymousClass($"new Function<{returnValueTypeArgumentClientType}, {GenericType.Maybe(ClassType.Void)}>()", anonymousClassBlock =>
4581-
{
4582-
anonymousClassBlock.PublicMethod(
4583-
$"{GenericType.Maybe(ClassType.Void)} apply({returnValueTypeArgumentClientType} res)",
4570+
function.AnonymousFunction(returnValueTypeArgumentClientType.ToString(), "res", GenericType.Maybe(ClassType.Void).ToString(),
45844571
method => method.Return("Maybe.empty()"));
4585-
});
45864572
function.Line(");");
45874573
}
45884574
else

src/JavaFileContents.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -324,15 +324,15 @@ public void ReturnAnonymousClass(string anonymousClassDeclaration, Action<JavaCl
324324
Line("};");
325325
}
326326

327-
public void AnonymousClass(string anonymousClassDeclaration, Action<JavaClass> anonymousClassBlock)
327+
public void AnonymousFunction(string parameterType, string parameterName, string returnType, Action<JavaBlock> methodBlock)
328328
{
329-
Line($"{anonymousClassDeclaration} {{");
329+
Line($"new Function<{parameterType}, {returnType}>() {{");
330330
Indent(() =>
331331
{
332332
JavaClass javaClass = new JavaClass(this);
333-
anonymousClassBlock(javaClass);
333+
javaClass.PublicMethod($"{returnType} apply({parameterType} {parameterName})", methodBlock);
334334
});
335-
Line("}");
335+
Text("}");
336336
}
337337

338338
public void Annotation(params string[] annotations)

src/Model/RestAPIMethod.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ public void AddImportsTo(ISet<string> imports, bool includeImplementationImports
154154

155155
if (includeImplementationImports)
156156
{
157-
imports.Add("io.reactivex.functions.Function");
157+
ClassType.Function.AddImportsTo(imports, includeImplementationImports);
158158

159159
if (IsResumable)
160160
{

0 commit comments

Comments
 (0)