Skip to content

Commit 64bdb55

Browse files
committed
Add support primitive types for return method
1 parent bd2c82b commit 64bdb55

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

moxy-compiler/src/main/java/com/omegar/mvp/compiler/viewstate/ViewInterfaceInfoToViewStateJavaFileProcessor.java

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,14 +221,32 @@ private MethodSpec generateVoidMethod(DeclaredType enclosingType, CommandViewMet
221221

222222
private MethodSpec generateReturnMethod(DeclaredType enclosingType, ReturnViewMethod method, CommandViewMethod commandViewMethod) {
223223
String commandClassName = commandViewMethod.getCommandClassName();
224-
return MethodSpec.overriding(method.getElement(), enclosingType, mTypes)
224+
MethodSpec.Builder builder = MethodSpec.overriding(method.getElement(), enclosingType, mTypes)
225225
.beginControlFlow("for ($L viewCommand : mViewCommands.getCurrentState())", VIEW_COMMAND_CLASS_NAME)
226226
.beginControlFlow("if (viewCommand instanceof $L)", commandClassName)
227227
.addStatement("return (($L) viewCommand).$L", commandClassName, commandViewMethod.getArgumentsString())
228228
.endControlFlow()
229-
.endControlFlow()
230-
.addStatement("return null")
231-
.build();
229+
.endControlFlow();
230+
231+
switch (method.getReturnType().getKind()) {
232+
case BOOLEAN:
233+
builder.addStatement("return false");
234+
break;
235+
case BYTE:
236+
case SHORT:
237+
case INT:
238+
case LONG:
239+
case FLOAT:
240+
case CHAR:
241+
case DOUBLE:
242+
builder.addStatement("return 0");
243+
break;
244+
default:
245+
builder.addStatement("return null");
246+
break;
247+
}
248+
249+
return builder.build();
232250
}
233251

234252
private MethodSpec generateCommandConstructor(CommandViewMethod method) {

0 commit comments

Comments
 (0)