public static PojoClass of(PojoInfo pojoInfo, TypeInfo typeInfo) { Naming naming = pojoInfo.naming(); TypeSpec.Builder type = TypeSpec .classBuilder(naming.pojoSimpleName()) .addModifiers(Modifier.FINAL) .superclass(naming.superClassTypeName()); naming.typeVariableNameListTo(type); List<InvalidateMethod> invalidateMethodList = InvalidateMethod.of(typeInfo); return new PojoClass(pojoInfo, type, invalidateMethodList); }
public static TestableContribution of(PojoInfo pojoInfo) { Naming naming = pojoInfo.naming(); TypeName superClassTypeName = naming.superClassTypeName(); ParameterizedTypeName testerTypeName = ParameterizedTypeName.get(TESTER, naming.superClass()); return superClassTypeName instanceof ParameterizedTypeName ? new Generic(pojoInfo, testerTypeName) : new TestableContribution(pojoInfo, testerTypeName); }
public Artifact toArtifact(TypeSpec.Builder type) { return toArtifact(type.build()); }
public TypeName builderInnerTypeName(MethodInfo method) { String innerSimpleName = builderInnerSimpleName(method); ClassName innerClassName = builderInterface.nestedClass(innerSimpleName); return typeNameUnbounded(innerClassName); }
public static BuilderClass of(StandardBuilderConfiguration builder) { Naming naming = builder.naming(); TypeSpec.Builder type = TypeSpec.classBuilder(naming.builderClassSimpleName()) .addModifiers(Modifier.FINAL) .addSuperinterface(naming.builderInterfaceTypeNameUnbounded()); naming.typeVariableNameListTo(type); return new BuilderClass(builder, type); }
private MethodSpec load1() { return MethodSpec.methodBuilder("load") .addModifiers(Modifier.PUBLIC) .returns(naming.superClassTypeName()) .addParameters(parameterSpecList) .addParameter(pojoInfo.rowParameterSpec()) .addCode("return new $T($L, ", naming.pojo(), inject.name()) .addCode(Joiner.on(", ") .addAll(parameterSpecList.stream().map(spec -> spec.name)) .add("row") .join()) .addStatement(")") .build(); }
private MethodSpec load() { CodeBlock.Builder body = CodeBlock.builder() .addStatement("$1T rs = new $1T($2S, resultSet)", ResultSetWrapper.class, tableSimpleName()) .add("return new $T(", naming.pojo()) .add("\n $L", inject.name()); pojoInfo.constructorContextList() .stream() .flatMap(ConstructorContext::parameterInfoStream) .map(ParameterInfo::name) .forEach(name -> body.add(",\n $L", name)); pojoInfo.propertyList() .stream() .sorted() .map(property -> property.adapt(IsRelationalLoaderLoadMethod.INSTANCE)) .forEach(body::add); body.add(");\n"); return MethodSpec.methodBuilder("load") .addAnnotation(Override.class) .addModifiers(Modifier.PUBLIC) .addParameter(ResultSet.class, "resultSet") .returns(naming.superClass()) .addCode(body.build()) .build(); }
private MethodSpec findByPrimaryKey0() { String paramNames = primaryKeyParameterSpecList.stream() .map(param -> param.name) .collect(Collectors.joining(", ")); return MethodSpec.methodBuilder("find") .addModifiers(Modifier.PUBLIC) .addParameters(primaryKeyParameterSpecList) .returns(naming.superClassTypeName()) .addStatement("return maybe($L).orElseThrow($T::new)", paramNames, NoResultFoundException.class) .build(); }
public static BuilderInterface of(StandardBuilderConfiguration builder) { TypeInfo typeInfo = builder.typeInfo(); Naming naming = builder.naming(); TypeSpec.Builder type = TypeSpec.interfaceBuilder(naming.builderInterfaceSimpleName()) .addModifiers(typeInfo.accessInfo().modifiers()); naming.typeVariableNameListTo(type); return new BuilderInterface(builder, type); }
String nextName = naming.builderInnerSimpleName(methodInfo); TypeSpec.Builder next = TypeSpec.interfaceBuilder(nextName) .addModifiers(Modifier.PUBLIC, Modifier.STATIC); naming.typeVariableNameListTo(next);
private TypeSpec type() { ClassName superClass = naming.superClass(); return TypeSpec.classBuilder("Abstract" + superClass.simpleName() + "Loader") .addAnnotation(GENERATED) .addModifiers(Modifier.ABSTRACT) .addSuperinterface(ParameterizedTypeName.get(ClassName.get(ResultSetLoader.class), superClass)) .addField(inject.fieldSpec()) .addMethods(pojoInfo.constructorContextList() .stream() .map(IsRelationalLoaderConstructor::of) .map(IsRelationalLoaderConstructor::execute) .collect(Collectors.toList())) .addMethod(load()) .addMethods(pojoInfo.propertyList() .stream() .flatMap(property -> property.adapt(this)) .collect(Collectors.toList())) .build(); }
private MethodSpec builderIfaceMethod() { MethodSpec.Builder method = MethodSpec.methodBuilder(name) .addModifiers(Modifier.PUBLIC, Modifier.ABSTRACT) .returns(naming().builderInnerTypeName(methodInfo())) .addParameters(parameterSpecList) .varargs(varargs); return methodBuild(method); }
private static Naming of0(TypeInfo typeInfo) { return new Naming( typeInfo.className(), typeInfo.classNameSuffix("Pojo"), typeInfo.classNameSuffix("Builder"), typeInfo.classNameSuffix("BuilderPojo"), typeInfo.typeVariableNameList(), typeInfo.typeVariableNameRawList(), typeInfo.typeVariableNameUnboundedList()); }
MethodSpec standard() { return constructorInfo.constructorWriter() .accessInfo(AccessInfo.PUBLIC) .addParameterList() .addParameterList(customParameterList) .addParameter(naming.builderClassTypeName(), "builder") .addStandardSuperStatement() .addCode(body.build()) .write(); }
private MethodSpec load0() { return MethodSpec.methodBuilder("load") .addModifiers(Modifier.PUBLIC) .returns(naming.superClassTypeName()) .addParameters(parameterSpecList) .addParameters(pojoInfo.foreignKeyParameterSpecList()) .addParameter(pojoInfo.rowParameterSpecColumns()) .addCode("return new $T($L, ", naming.pojo(), inject.name()) .addCode(Joiner.on(", ") .addAll(parameterSpecList.stream().map(spec -> spec.name)) .addAll(pojoInfo.foreignKeyPropertyList().stream().map(OrmProperty::name)) .add("row") .join()) .addStatement(")") .build(); }
public static BuilderClass of(StandardBuilderConfiguration builder) { Naming naming = builder.naming(); TypeSpec.Builder type = TypeSpec.classBuilder(naming.builderClassSimpleName()) .addModifiers(Modifier.FINAL) .addSuperinterface(naming.builderInterfaceTypeNameUnbounded()); naming.typeVariableNameListTo(type); return new BuilderClass(builder, type); }
private MethodSpec findByPrimaryKey1() { ClassName optionalClassName = ClassName.get(Optional.class); return MethodSpec.methodBuilder("maybe") .addModifiers(Modifier.PUBLIC) .addParameters(primaryKeyParameterSpecList) .returns(ParameterizedTypeName.get(optionalClassName, naming.superClassTypeName())) .addCode(QueryMethodBody.builder(pojoInfo, QueryReturnType.OPTIONAL) .whereExpression(new Where()) .build()) .build(); }
public static BuilderInterface of(StandardBuilderConfiguration builder) { TypeInfo typeInfo = builder.typeInfo(); Naming naming = builder.naming(); TypeSpec.Builder type = TypeSpec.interfaceBuilder(naming.builderInterfaceSimpleName()) .addModifiers(typeInfo.accessInfo().modifiers()); naming.typeVariableNameListTo(type); return new BuilderInterface(builder, type); }
public TypeName builderInnerTypeName(MethodInfo method) { String innerSimpleName = builderInnerSimpleName(method); ClassName innerClassName = builderInterface.nestedClass(innerSimpleName); return typeNameUnbounded(innerClassName); }
String nextName = naming.builderInnerSimpleName(methodInfo); TypeSpec.Builder next = TypeSpec.interfaceBuilder(nextName) .addModifiers(Modifier.PUBLIC, Modifier.STATIC); naming.typeVariableNameListTo(next);