1
1
/*
2
- * Copyright (c) 2024 GeyserMC <https://geysermc.org>
3
- *
4
- * Permission is hereby granted, free of charge, to any person obtaining a copy
5
- * of this software and associated documentation files (the "Software"), to deal
6
- * in the Software without restriction, including without limitation the rights
7
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- * copies of the Software, and to permit persons to whom the Software is
9
- * furnished to do so, subject to the following conditions:
10
- *
11
- * The above copyright notice and this permission notice shall be included in
12
- * all copies or substantial portions of the Software.
13
- *
14
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
- * THE SOFTWARE.
21
- *
22
- * @author GeyserMC
2
+ * Copyright (c) 2024 GeyserMC
3
+ * Licensed under the MIT license
23
4
* @link https://github.com/GeyserMC/DatabaseUtils
24
5
*/
25
6
package org .geysermc .databaseutils .processor ;
26
7
27
8
import static org .geysermc .databaseutils .processor .util .AnnotationUtils .hasAnnotation ;
28
9
10
+ import com .google .auto .common .MoreTypes ;
29
11
import java .util .ArrayList ;
30
12
import java .util .Arrays ;
31
13
import java .util .Collection ;
38
20
import javax .lang .model .element .Modifier ;
39
21
import javax .lang .model .element .TypeElement ;
40
22
import javax .lang .model .element .VariableElement ;
23
+ import javax .lang .model .type .TypeMirror ;
41
24
import org .geysermc .databaseutils .meta .Entity ;
25
+ import org .geysermc .databaseutils .meta .Index ;
42
26
import org .geysermc .databaseutils .meta .Key ;
43
27
import org .geysermc .databaseutils .processor .info .ColumnInfo ;
44
28
import org .geysermc .databaseutils .processor .info .EntityInfo ;
@@ -57,7 +41,9 @@ Collection<EntityInfo> processedEntities() {
57
41
return entityInfoByClassName .values ();
58
42
}
59
43
60
- EntityInfo processEntity (TypeElement type ) {
44
+ EntityInfo processEntity (TypeMirror typeMirror ) {
45
+ var type = MoreTypes .asTypeElement (typeMirror );
46
+
61
47
var cached = entityInfoByClassName .get (type .getQualifiedName ());
62
48
if (cached != null ) {
63
49
return cached ;
@@ -78,7 +64,7 @@ EntityInfo processEntity(TypeElement type) {
78
64
var indexes = new ArrayList <IndexInfo >();
79
65
var columns = new ArrayList <ColumnInfo >();
80
66
81
- Arrays .stream (type .getAnnotationsByType (org . geysermc . databaseutils . meta . Index .class ))
67
+ Arrays .stream (type .getAnnotationsByType (Index .class ))
82
68
.map (index -> new IndexInfo (index .name (), index .columns (), index .unique ()))
83
69
.forEach (indexes ::add );
84
70
@@ -100,14 +86,14 @@ EntityInfo processEntity(TypeElement type) {
100
86
}
101
87
102
88
TypeElement typeElement = typeUtils .toBoxedTypeElement (field .asType ());
103
- columns .add (new ColumnInfo (field .getSimpleName (), typeElement .getQualifiedName ()));
89
+ columns .add (new ColumnInfo (field .getSimpleName (), typeElement , typeElement .getQualifiedName ()));
104
90
105
91
if (hasAnnotation (field , Key .class )) {
106
92
keys .add (field .getSimpleName ());
107
93
}
108
- var index = field .getAnnotation (org . geysermc . databaseutils . meta . Index .class );
94
+ var index = field .getAnnotation (Index .class );
109
95
if (index != null ) {
110
- indexes .add (new IndexInfo (index .name (), index .columns (), index .unique ()));
96
+ indexes .add (new IndexInfo (index .name (), index .columns (), index .unique (), index . direction () ));
111
97
}
112
98
}
113
99
0 commit comments