Skip to contentMethod: getName()
1: /*
2: * JOPA
3: * Copyright (C) 2024 Czech Technical University in Prague
4: *
5: * This library is free software; you can redistribute it and/or
6: * modify it under the terms of the GNU Lesser General Public
7: * License as published by the Free Software Foundation; either
8: * version 3.0 of the License, or (at your option) any later version.
9: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public
16: * License along with this library.
17: */
18: package cz.cvut.kbss.jopa.modelgen.classmodel;
19:
20: import javax.lang.model.element.Element;
21: import java.util.ArrayList;
22: import java.util.Arrays;
23: import java.util.List;
24: import java.util.stream.Collectors;
25:
26: public class Field {
27: private final List<String> imports = new ArrayList<>();
28: private String name;
29: private Type type;
30: private String parentName;
31: private List<MappingAnnotations> annotatedWith;
32:
33: public Field() {
34: name = "";
35: type = null;
36: parentName = "";
37: annotatedWith = new ArrayList<>();
38: }
39:
40: public Field(Element elProperty, Element elParent) {
41: this.name = elProperty.toString();
42: this.type = new Type(elProperty.asType());
43: this.parentName = elParent.toString();
44: this.annotatedWith = Arrays.stream(MappingAnnotations.values())
45: .filter(annotationEnum -> elProperty.getAnnotationMirrors().stream()
46: .anyMatch(annotationMirror ->
47: annotationMirror.getAnnotationType().toString()
48: .contains(annotationEnum.getAnnotation())))
49: .collect(Collectors.toList());
50: if (type.getIsSimple()) {
51: imports.add(type.getTypeName());
52: } else {
53: for (Type type : type.getTypes()) {
54: imports.add(type.getTypeName());
55: imports.add(this.type.getTypeName());
56: }
57: }
58: }
59:
60: public String getName() {
61: return name;
62: }
63:
64: public void setName(String name) {
65: this.name = name;
66: }
67:
68: public Type getType() {
69: return type;
70: }
71:
72: public void setType(Type type) {
73: this.type = type;
74: }
75:
76: public String getParentName() {
77: return parentName;
78: }
79:
80: public void setParentName(String parentName) {
81: this.parentName = parentName;
82: }
83:
84: public List<MappingAnnotations> getAnnotatedWith() {
85: return annotatedWith;
86: }
87:
88: public void setAnnotatedWith(List<MappingAnnotations> annotatedWith) {
89: this.annotatedWith = annotatedWith;
90: }
91:
92: public List<String> getImports() {
93: return imports;
94: }
95: }