fix #123 allow to specify extra annotations on repositories/methods
[yosql.git] / yosql-codegen / src / main / java / wtf / metio / yosql / codegen / blocks / DefaultMethods.java
blobdc952dce71ab76d04a96cec32ea7d6e9d027be54
1 /*
2 * This file is part of yosql. It is subject to the license terms in the LICENSE file found in the top-level
3 * directory of this distribution and at https://creativecommons.org/publicdomain/zero/1.0/. No part of yosql,
4 * including this file, may be copied, modified, propagated, or distributed except according to the terms contained
5 * in the LICENSE file.
6 */
8 package wtf.metio.yosql.codegen.blocks;
10 import com.squareup.javapoet.MethodSpec;
11 import wtf.metio.yosql.models.immutables.JavaConfiguration;
12 import wtf.metio.yosql.models.immutables.SqlConfiguration;
13 import wtf.metio.yosql.models.immutables.SqlStatement;
15 import javax.lang.model.element.Modifier;
16 import java.util.List;
18 public final class DefaultMethods implements Methods {
20 private final Annotations annotations;
21 private final Javadoc javadoc;
22 private final JavaConfiguration java;
24 public DefaultMethods(final Annotations annotations, final Javadoc javadoc, final JavaConfiguration java) {
25 this.annotations = annotations;
26 this.javadoc = javadoc;
27 this.java = java;
30 @Override
31 public MethodSpec.Builder publicMethod(final String name) {
32 final var modifiers = java.useFinalMethods()
33 ? List.of(Modifier.PUBLIC, Modifier.FINAL)
34 : List.of(Modifier.PUBLIC);
35 return MethodSpec.methodBuilder(name)
36 .addModifiers(modifiers)
37 .addAnnotations(annotations.generatedMethod());
40 @Override
41 public MethodSpec.Builder publicMethod(
42 final String name,
43 final List<SqlStatement> statements,
44 final String configuration) {
45 final var modifiers = java.useFinalMethods()
46 ? List.of(Modifier.PUBLIC, Modifier.FINAL)
47 : List.of(Modifier.PUBLIC);
48 return MethodSpec.methodBuilder(name)
49 .addModifiers(modifiers)
50 .addAnnotations(annotations.generatedMethod())
51 .addAnnotations(annotations.generatedMethod(SqlConfiguration.fromStatements(statements)))
52 .addJavadoc(javadoc.methodJavadoc(statements, configuration));
55 @Override
56 public MethodSpec.Builder declaration(
57 final String name,
58 final List<SqlStatement> statements,
59 final String configuration) {
60 return MethodSpec.methodBuilder(name)
61 .addModifiers(Modifier.PUBLIC, Modifier.ABSTRACT)
62 .addAnnotations(annotations.generatedMethod())
63 .addAnnotations(annotations.generatedMethod(SqlConfiguration.fromStatements(statements)))
64 .addJavadoc(javadoc.methodJavadoc(statements, configuration));
67 @Override
68 public MethodSpec.Builder implementation(final String name) {
69 final var modifiers = java.useFinalMethods()
70 ? List.of(Modifier.PUBLIC, Modifier.FINAL)
71 : List.of(Modifier.PUBLIC);
72 return MethodSpec.methodBuilder(name)
73 .addModifiers(modifiers)
74 .addAnnotation(Override.class)
75 .addAnnotations(annotations.generatedMethod());
78 @Override
79 public MethodSpec.Builder constructor() {
80 return MethodSpec.constructorBuilder()
81 .addModifiers(Modifier.PUBLIC)
82 .addAnnotations(annotations.generatedMethod())
83 .addAnnotations(annotations.generatedConstructor());