private Stream<SimpleMethod> convert(Stream<MethodInfo> meths) { return meths.map(meth -> { List<SimpleParam> simpleParams = new ArrayList<>(); for (ParamInfo param: meth.getParams()) { TypeInfo type = param.getType(); simpleParams.add(new SimpleParam(param.getName(), type.getKind(), param.isNullable(), type.getName())); } return new SimpleMethod(meth.getName(), simpleParams); }); }
break; case ENUM: if (param.isNullable()) { writer.format("%s == null ? null : ", unwrappedName); writer.format("utils.convParam%sObject(%s)", container, unwrappedName); } else { if (param.isNullable()) { writer.format("%s == null ? null : ", unwrappedName); if (param.isNullable()) { writer.format("%s == null ? null : ", unwrappedName);
@Test public void testInterfaceWithNullableParamOverride() throws Exception { Consumer<ClassModel> test = model -> { List<MethodInfo> methods = model.getMethods(); assertEquals(1, methods.size()); MethodInfo mi1 = methods.get(0); assertTrue(mi1.getParams().get(0).isNullable()); }; // generateClass(test, MethodWithNullableParamOverride.class, MethodWithNullableParam.class); generateClass(test, MethodWithNullableParamOverride.class); }
@Test public void testMethodWithNullableNonAnnotatedObjectParam() throws Exception { generateClass(model -> { List<MethodInfo> methods = model.getMethods(); assertEquals(1, methods.size()); MethodInfo mi1 = methods.get(0); checkMethod(mi1, "method", 1, "void", MethodKind.OTHER); assertTrue(mi1.getParams().get(0).isNullable()); }, MethodWithNullableNonAnnotatedObjectParam.class); }
@Test public void testMethodWithNullableNonAnnotatedTypeVariableParam() throws Exception { generateClass(model -> { List<MethodInfo> methods = model.getMethods(); assertEquals(1, methods.size()); MethodInfo mi1 = methods.get(0); checkMethod(mi1, "method", 1, "void", MethodKind.OTHER); assertTrue(mi1.getParams().get(0).isNullable()); }, MethodWithNullableNonAnnotatedTypeVariableParam.class); }
@Test public void testMethodWithNullableTypeVariableParam() throws Exception { generateClass(model -> { List<MethodInfo> methods = model.getMethods(); assertEquals(1, methods.size()); MethodInfo mi1 = methods.get(0); checkMethod(mi1, "method", 1, "void", MethodKind.OTHER); assertTrue(mi1.getParams().get(0).isNullable()); }, MethodWithNullableTypeVariableParam.class); }
@Test public void testMethodWithNullableHandler() throws Exception { generateClass(model -> { List<MethodInfo> methods = model.getMethods(); assertEquals(1, methods.size()); MethodInfo mi1 = methods.get(0); checkMethod(mi1, "method", 1, "void", MethodKind.HANDLER); assertTrue(mi1.getParams().get(0).isNullable()); }, MethodWithNullableHandler.class); }
@Test public void testMethodWithNullableParam() throws Exception { generateClass(model -> { List<MethodInfo> methods = model.getMethods(); assertEquals(1, methods.size()); MethodInfo mi1 = methods.get(0); checkMethod(mi1, "method", 1, "void", MethodKind.OTHER); assertTrue(mi1.getParams().get(0).isNullable()); }, MethodWithNullableParam.class); }
@Test public void testMethodWithNullableHandlerAsyncResult() throws Exception { generateClass(model -> { List<MethodInfo> methods = model.getMethods(); assertEquals(1, methods.size()); MethodInfo mi1 = methods.get(0); checkMethod(mi1, "method", 1, "void", MethodKind.FUTURE); assertTrue(mi1.getParams().get(0).isNullable()); }, MethodWithNullableHandlerAsyncResult.class); }
@Test public void testMethodWithOverloadedNullableParam() throws Exception { generateClass(model -> { List<MethodInfo> methods = model.getMethods(); assertEquals(2, methods.size()); MethodInfo mi1 = methods.get(0); checkMethod(mi1, "method", 2, "void", MethodKind.OTHER); assertEquals(ClassKind.STRING, mi1.getParams().get(0).getType().getKind()); checkParam(mi1.getParams().get(0), "s", String.class); assertTrue(mi1.getParams().get(0).isNullable()); checkParam(mi1.getParams().get(1), "i", Integer.class); assertFalse(mi1.getParams().get(1).isNullable()); MethodInfo mi2 = methods.get(1); checkMethod(mi2, "method", 2, "void", MethodKind.OTHER); checkParam(mi2.getParams().get(0), "i", Integer.class); assertFalse(mi2.getParams().get(0).isNullable()); checkParam(mi2.getParams().get(1), "s", String.class); assertTrue(mi2.getParams().get(1).isNullable()); }, MethodWithOverloadedNullableParam.class); }
case PRIMITIVE: case BOXED_PRIMITIVE: if (param.isNullable()) { writer.print("("); if (param.isNullable()) { writer.format(" || __args[%s] == null)", cnt); case STRING: case ENUM: if (param.isNullable()) { writer.print("("); if (param.isNullable()) { writer.format(" || __args[%s] == null)", cnt); case API: writer.format("typeof __args[%s] === 'object' && ", cnt); if (param.isNullable()) { writer.format("(__args[%s] == null || ", cnt); if (param.isNullable()) { writer.print(")"); case SET: writer.format("typeof __args[%s] === 'object' && ", cnt); if (param.isNullable()) { writer.print("(");
if (type.getArg(0).getKind() == ASYNC_RESULT) { ParameterizedTypeInfo asyncType = (ParameterizedTypeInfo) type.getArg(0); if (param.isNullable()) { writer.format("%s == null ? null : ", paramName); writer.print(paramName); } else { if (param.isNullable()) { writer.print(paramName); writer.print(" == null ? null : ");