This repository has been archived by the owner on Mar 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 55
/
Field.java
142 lines (126 loc) · 3.19 KB
/
Field.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
package org.eclipse.ice.dev.annotations.processors;
import lombok.Builder;
import lombok.Data;
import lombok.NonNull;
/**
* Container for Field information, taken from DataField Annotations, in
* simplified form for use by Velocity template.
*
* @author Daniel Bluhm
*/
@Data
@Builder
public class Field {
/**
* Name of the field.
*/
String name;
/**
* String representation of the field's type.
*/
String type;
/**
* The default value of this field.
*/
String defaultValue;
/**
* Comment to add to the field declaration.
*/
String comment;
/**
* Whether or not this field can be null.
*
* This value affects the kind of checks generated in IDataElement.matches().
*/
boolean nullable;
/**
* Whether or not the type of this field is a primitive type.
*
* This value affects the kind of checks generated in IDataElement.matches().
* This is inferred from the Field's type.
*/
boolean primitive;
/**
* Whether or not this field should be included in IDataElement.matches().
*/
@Builder.Default boolean match = true;
/**
* Builder class for Field. This class must be a static inner class of Field in
* order to take advantage of Lombok's @Builder annotation. The methods defined
* here replace the defaults generated by Lombok.
*/
public static class FieldBuilder {
/**
* Format long as String for use as default value initializer.
* @param value the value to be formatted.
* @return FieldBuilder
*/
public FieldBuilder defaultValue(long value) {
this.defaultValue = Long.toString(value) + "L";
return this;
}
/**
* Format String as escaped String for use as default value initializer.
* @param value the value to be formatted.
* @return FieldBuilder
*/
public FieldBuilder defaultValue(String value) {
this.defaultValue = "\"" + value + "\"";
return this;
}
/**
* Format boolean as String for use as default value initializer.
* @param value the value to be formatted.
* @return FieldBuilder
*/
public FieldBuilder defaultValue(boolean value) {
this.defaultValue = Boolean.toString(value);
return this;
}
/**
* Take a Raw string value and pass through without manipulating for use as
* default value initializer.
* @param value the value to be formatted.
* @return FieldBuilder
*/
public FieldBuilder defaultValue(Raw value) {
this.defaultValue = value.getValue();
return this;
}
/**
* Format type as String.
* @param type the type to be formatted.
* @return
*/
public FieldBuilder type(Class<?> type) {
this.type = type.getName().toString();
this.primitive = type.isPrimitive();
return this;
}
/**
* Take a raw string value and pass through without manipulating for use as
* type.
* @param type the type
* @return
*/
public FieldBuilder type(Raw type) {
this.type = type.getValue();
return this;
}
}
/**
* Marker class used to mark a string value as one that should not be
* manipulated when building a field.
*/
@Data public static class Raw {
@NonNull String value;
}
/**
* Convenience method for creating Raw value.
* @param value
* @return
*/
public static Raw raw(String value) {
return new Raw(value);
}
}