|
1 |
| -package org.babyfish.jimmer.apt.tuple; |
2 |
| - |
3 |
| -import com.squareup.javapoet.ClassName; |
4 |
| -import com.squareup.javapoet.ParameterizedTypeName; |
5 |
| -import com.squareup.javapoet.TypeName; |
6 |
| -import com.squareup.javapoet.TypeSpec; |
7 |
| -import org.babyfish.jimmer.apt.Context; |
8 |
| -import org.babyfish.jimmer.apt.MetaException; |
9 |
| -import org.babyfish.jimmer.apt.immutable.generator.Constants; |
10 |
| -import org.babyfish.jimmer.sql.TypedTuple; |
11 |
| - |
12 |
| -import javax.lang.model.element.*; |
13 |
| -import javax.lang.model.type.PrimitiveType; |
14 |
| -import javax.lang.model.type.TypeMirror; |
15 |
| -import java.util.ArrayList; |
16 |
| -import java.util.Collections; |
17 |
| -import java.util.List; |
18 |
| - |
19 |
| -public abstract class AbstractMemberGenerator { |
20 |
| - |
21 |
| - protected final Context context; |
22 |
| - |
23 |
| - protected final TypeElement typeElement; |
24 |
| - |
25 |
| - protected final ClassName className; |
26 |
| - |
27 |
| - protected final TypeSpec.Builder typeBuilder; |
28 |
| - |
29 |
| - protected final List<VariableElement> fieldElements; |
30 |
| - |
31 |
| - AbstractMemberGenerator( |
32 |
| - Context context, |
33 |
| - TypeElement typeElement, |
34 |
| - ClassName className, |
35 |
| - TypeSpec.Builder typeBuilder |
36 |
| - ) { |
37 |
| - this.context = context; |
38 |
| - this.typeElement = typeElement; |
39 |
| - this.className = className; |
40 |
| - this.typeBuilder = typeBuilder; |
41 |
| - List<VariableElement> fieldElements = new ArrayList<>(); |
42 |
| - for (Element element : typeElement.getEnclosedElements()) { |
43 |
| - if (element instanceof VariableElement) { |
44 |
| - if (!element.getModifiers().contains(Modifier.STATIC)) { |
45 |
| - validateFieldElement((VariableElement) element); |
46 |
| - fieldElements.add((VariableElement) element); |
47 |
| - } |
48 |
| - } |
49 |
| - } |
50 |
| - if (fieldElements.isEmpty()) { |
51 |
| - throw new MetaException( |
52 |
| - typeElement, |
53 |
| - "There is no non-state field" |
54 |
| - ); |
55 |
| - } |
56 |
| - this.fieldElements = Collections.unmodifiableList(fieldElements); |
57 |
| - } |
58 |
| - |
59 |
| - private void validateFieldElement(VariableElement fieldElement) { |
60 |
| - if (context.isDto(fieldElement.asType())) { |
61 |
| - throw new MetaException( |
62 |
| - fieldElement, |
63 |
| - "The field of type decorated by \"@" + |
64 |
| - TypedTuple.class.getName() + |
65 |
| - "\" cannot be dto" |
66 |
| - ); |
67 |
| - } |
68 |
| - } |
69 |
| - |
70 |
| - protected final TypeName expressionTypeName(VariableElement fieldElement, boolean typeBootstrap) { |
71 |
| - TypeMirror type = fieldElement.asType(); |
72 |
| - if (context.isEntity(type)) { |
73 |
| - return context.getImmutableType(type).getTableClassName(); |
74 |
| - } |
75 |
| - if (typeBootstrap) { |
76 |
| - if (context.isEmbeddable(type)) { |
77 |
| - return context.getImmutableType(type).getPropExpressionClassName(); |
78 |
| - } |
79 |
| - if (context.isDate(type)) { |
80 |
| - return ParameterizedTypeName.get( |
81 |
| - Constants.DATE_EXPRESSION_CLASS_NAME, |
82 |
| - ClassName.get(type).box() |
83 |
| - ); |
84 |
| - } |
85 |
| - if (context.isTemporal(type)) { |
86 |
| - return ParameterizedTypeName.get( |
87 |
| - Constants.TEMPORAL_EXPRESSION_CLASS_NAME, |
88 |
| - ClassName.get(type).box() |
89 |
| - ); |
90 |
| - } |
91 |
| - if (context.isNumber(type) || type instanceof PrimitiveType) { |
92 |
| - return ParameterizedTypeName.get( |
93 |
| - Constants.NUMERIC_EXPRESSION_CLASS_NAME, |
94 |
| - ClassName.get(type).box() |
95 |
| - ); |
96 |
| - } |
97 |
| - if (context.isComparable(type)) { |
98 |
| - return ParameterizedTypeName.get( |
99 |
| - Constants.COMPARABLE_EXPRESSION_CLASS_NAME, |
100 |
| - ClassName.get(type).box() |
101 |
| - ); |
102 |
| - } |
103 |
| - } |
104 |
| - return ParameterizedTypeName.get( |
105 |
| - Constants.EXPRESSION_CLASS_NAME, |
106 |
| - ClassName.get(type).box() |
107 |
| - ); |
108 |
| - } |
109 |
| -} |
| 1 | +//package org.babyfish.jimmer.apt.tuple; |
| 2 | +// |
| 3 | +//import com.squareup.javapoet.ClassName; |
| 4 | +//import com.squareup.javapoet.ParameterizedTypeName; |
| 5 | +//import com.squareup.javapoet.TypeName; |
| 6 | +//import com.squareup.javapoet.TypeSpec; |
| 7 | +//import org.babyfish.jimmer.apt.Context; |
| 8 | +//import org.babyfish.jimmer.apt.MetaException; |
| 9 | +//import org.babyfish.jimmer.apt.immutable.generator.Constants; |
| 10 | +//import org.babyfish.jimmer.sql.TypedTuple; |
| 11 | +// |
| 12 | +//import javax.lang.model.element.*; |
| 13 | +//import javax.lang.model.type.PrimitiveType; |
| 14 | +//import javax.lang.model.type.TypeMirror; |
| 15 | +//import java.util.ArrayList; |
| 16 | +//import java.util.Collections; |
| 17 | +//import java.util.List; |
| 18 | +// |
| 19 | +//public abstract class AbstractMemberGenerator { |
| 20 | +// |
| 21 | +// protected final Context context; |
| 22 | +// |
| 23 | +// protected final TypeElement typeElement; |
| 24 | +// |
| 25 | +// protected final ClassName className; |
| 26 | +// |
| 27 | +// protected final TypeSpec.Builder typeBuilder; |
| 28 | +// |
| 29 | +// protected final List<VariableElement> fieldElements; |
| 30 | +// |
| 31 | +// AbstractMemberGenerator( |
| 32 | +// Context context, |
| 33 | +// TypeElement typeElement, |
| 34 | +// ClassName className, |
| 35 | +// TypeSpec.Builder typeBuilder |
| 36 | +// ) { |
| 37 | +// this.context = context; |
| 38 | +// this.typeElement = typeElement; |
| 39 | +// this.className = className; |
| 40 | +// this.typeBuilder = typeBuilder; |
| 41 | +// List<VariableElement> fieldElements = new ArrayList<>(); |
| 42 | +// for (Element element : typeElement.getEnclosedElements()) { |
| 43 | +// if (element instanceof VariableElement) { |
| 44 | +// if (!element.getModifiers().contains(Modifier.STATIC)) { |
| 45 | +// validateFieldElement((VariableElement) element); |
| 46 | +// fieldElements.add((VariableElement) element); |
| 47 | +// } |
| 48 | +// } |
| 49 | +// } |
| 50 | +// if (fieldElements.isEmpty()) { |
| 51 | +// throw new MetaException( |
| 52 | +// typeElement, |
| 53 | +// "There is no non-state field" |
| 54 | +// ); |
| 55 | +// } |
| 56 | +// this.fieldElements = Collections.unmodifiableList(fieldElements); |
| 57 | +// } |
| 58 | +// |
| 59 | +// private void validateFieldElement(VariableElement fieldElement) { |
| 60 | +// if (context.isDto(fieldElement.asType())) { |
| 61 | +// throw new MetaException( |
| 62 | +// fieldElement, |
| 63 | +// "The field of type decorated by \"@" + |
| 64 | +// TypedTuple.class.getName() + |
| 65 | +// "\" cannot be dto" |
| 66 | +// ); |
| 67 | +// } |
| 68 | +// } |
| 69 | +// |
| 70 | +// protected final TypeName expressionTypeName(VariableElement fieldElement, boolean typeBootstrap) { |
| 71 | +// TypeMirror type = fieldElement.asType(); |
| 72 | +// if (context.isEntity(type)) { |
| 73 | +// return context.getImmutableType(type).getTableClassName(); |
| 74 | +// } |
| 75 | +// if (typeBootstrap) { |
| 76 | +// if (context.isEmbeddable(type)) { |
| 77 | +// return context.getImmutableType(type).getPropExpressionClassName(); |
| 78 | +// } |
| 79 | +// if (context.isDate(type)) { |
| 80 | +// return ParameterizedTypeName.get( |
| 81 | +// Constants.DATE_EXPRESSION_CLASS_NAME, |
| 82 | +// ClassName.get(type).box() |
| 83 | +// ); |
| 84 | +// } |
| 85 | +// if (context.isTemporal(type)) { |
| 86 | +// return ParameterizedTypeName.get( |
| 87 | +// Constants.TEMPORAL_EXPRESSION_CLASS_NAME, |
| 88 | +// ClassName.get(type).box() |
| 89 | +// ); |
| 90 | +// } |
| 91 | +// if (context.isNumber(type) || type instanceof PrimitiveType) { |
| 92 | +// return ParameterizedTypeName.get( |
| 93 | +// Constants.NUMERIC_EXPRESSION_CLASS_NAME, |
| 94 | +// ClassName.get(type).box() |
| 95 | +// ); |
| 96 | +// } |
| 97 | +// if (context.isComparable(type)) { |
| 98 | +// return ParameterizedTypeName.get( |
| 99 | +// Constants.COMPARABLE_EXPRESSION_CLASS_NAME, |
| 100 | +// ClassName.get(type).box() |
| 101 | +// ); |
| 102 | +// } |
| 103 | +// } |
| 104 | +// return ParameterizedTypeName.get( |
| 105 | +// Constants.EXPRESSION_CLASS_NAME, |
| 106 | +// ClassName.get(type).box() |
| 107 | +// ); |
| 108 | +// } |
| 109 | +//} |
0 commit comments