• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pmd / pmd / 403

22 Feb 2026 04:05PM UTC coverage: 78.975% (+0.02%) from 78.958%
403

push

github

web-flow
chore: Small release process fixes (#6447)

18539 of 24360 branches covered (76.1%)

Branch coverage included in aggregate %.

40429 of 50307 relevant lines covered (80.36%)

0.81 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

98.11
/pmd-visualforce/src/main/java/net/sourceforge/pmd/lang/visualforce/DataType.java
1
/*
2
 * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3
 */
4

5
package net.sourceforge.pmd.lang.visualforce;
6

7
import java.lang.reflect.Field;
8
import java.util.Arrays;
9
import java.util.HashMap;
10
import java.util.HashSet;
11
import java.util.Locale;
12
import java.util.Map;
13
import java.util.Set;
14

15
import org.slf4j.Logger;
16
import org.slf4j.LoggerFactory;
17

18
/**
19
 * Represents all data types that can be referenced from a Visualforce page. This enum consolidates the data types
20
 * available to CustomFields and Apex. It uses the naming convention of CustomFields.
21
 *
22
 * See https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/meta_field_types.htm#meta_type_fieldtype
23
 */
24
public enum DataType {
1✔
25
    /**
26
     * @deprecated Since 7.22.0. Use {@link #AUTO_NUMBER} instead.
27
     */
28
    @Deprecated
1✔
29
    @SuppressWarnings("PMD.FieldNamingConventions")
30
    AutoNumber("AutoNumber", false),
31
    AUTO_NUMBER("AutoNumber", false),
1✔
32
    /**
33
     * @deprecated Since 7.22.0. Use {@link #CHECKBOX} instead.
34
     */
35
    @Deprecated
1✔
36
    @SuppressWarnings("PMD.FieldNamingConventions")
37
    Checkbox("Checkbox", false, "Boolean"),
38
    CHECKBOX("Checkbox", false, "Boolean"),
1✔
39
    /**
40
     * @deprecated Since 7.22.0. Use {@link #CURRENCY} instead.
41
     */
42
    @Deprecated
1✔
43
    @SuppressWarnings("PMD.FieldNamingConventions")
44
    Currency("Currency", false, "Currency"),
45
    CURRENCY("Currency", false, "Currency"),
1✔
46
    /**
47
     * @deprecated Since 7.22.0. Use {@link #DATE} instead.
48
     */
49
    @Deprecated
1✔
50
    @SuppressWarnings("PMD.FieldNamingConventions")
51
    Date("Date", false, "Date"),
52
    DATE("Date", false, "Date"),
1✔
53
    /**
54
     * @deprecated Since 7.22.0. Use {@link #DATE_TIME} instead.
55
     */
56
    @Deprecated
1✔
57
    @SuppressWarnings("PMD.FieldNamingConventions")
58
    DateTime("DateTime", false, "Datetime"),
59
    DATE_TIME("DateTime", false, "Datetime"),
1✔
60
    /**
61
     * @deprecated Since 7.22.0. Use {@link #EMAIL} instead.
62
     */
63
    @Deprecated
1✔
64
    @SuppressWarnings("PMD.FieldNamingConventions")
65
    Email("Email", false),
66
    EMAIL("Email", false),
1✔
67
    /**
68
     * @deprecated Since 7.22.0. Use {@link #ENCRYPTED_TEXT} instead.
69
     */
70
    @Deprecated
1✔
71
    @SuppressWarnings("PMD.FieldNamingConventions")
72
    EncryptedText("EncryptedText", true),
73
    ENCRYPTED_TEXT("EncryptedText", true),
1✔
74
    /**
75
     * @deprecated Since 7.22.0. Use {@link #EXTERNAL_LOOKUP} instead.
76
     */
77
    @Deprecated
1✔
78
    @SuppressWarnings("PMD.FieldNamingConventions")
79
    ExternalLookup("ExternalLookup", true),
80
    EXTERNAL_LOOKUP("ExternalLookup", true),
1✔
81
    /**
82
     * @deprecated Since 7.22.0. Use {@link #FILE} instead.
83
     */
84
    @Deprecated
1✔
85
    @SuppressWarnings("PMD.FieldNamingConventions")
86
    File("File", false),
87
    FILE("File", false),
1✔
88
    /**
89
     * @deprecated Since 7.22.0. Use {@link #HIERARCHY} instead.
90
     */
91
    @Deprecated
1✔
92
    @SuppressWarnings("PMD.FieldNamingConventions")
93
    Hierarchy("Hierarchy", false),
94
    HIERARCHY("Hierarchy", false),
1✔
95
    /**
96
     * @deprecated Since 7.22.0. Use {@link #HTML} instead.
97
     */
98
    @Deprecated
1✔
99
    @SuppressWarnings("PMD.FieldNamingConventions")
100
    Html("Html", false),
101
    HTML("Html", false),
1✔
102
    /**
103
     * @deprecated Since 7.22.0. Use {@link #INDIRECT_LOOKUP} instead.
104
     */
105
    @Deprecated
1✔
106
    @SuppressWarnings("PMD.FieldNamingConventions")
107
    IndirectLookup("IndirectLookup", false),
108
    INDIRECT_LOOKUP("IndirectLookup", false),
1✔
109
    /**
110
     * @deprecated Since 7.22.0. Use {@link #LOCATION} instead.
111
     */
112
    @Deprecated
1✔
113
    @SuppressWarnings("PMD.FieldNamingConventions")
114
    Location("Location", false),
115
    LOCATION("Location", false),
1✔
116
    /**
117
     * @deprecated Since 7.22.0. Use {@link #LONG_TEXT_AREA} instead.
118
     */
119
    @Deprecated
1✔
120
    @SuppressWarnings("PMD.FieldNamingConventions")
121
    LongTextArea("LongTextArea", true),
122
    LONG_TEXT_AREA("LongTextArea", true),
1✔
123
    /**
124
     * @deprecated Since 7.22.0. Use {@link #LOOKUP} instead.
125
     */
126
    @Deprecated
1✔
127
    @SuppressWarnings("PMD.FieldNamingConventions")
128
    Lookup("Lookup", false, "Id"),
129
    LOOKUP("Lookup", false, "Id"),
1✔
130
    /**
131
     * @deprecated Since 7.22.0. Use {@link #MASTER_DETAIL} instead.
132
     */
133
    @Deprecated
1✔
134
    @SuppressWarnings("PMD.FieldNamingConventions")
135
    MasterDetail("MasterDetail", false),
136
    MASTER_DETAIL("MasterDetail", false),
1✔
137
    /**
138
     * @deprecated Since 7.22.0. Use {@link #METADATA_RELATIONSHIP} instead.
139
     */
140
    @Deprecated
1✔
141
    @SuppressWarnings("PMD.FieldNamingConventions")
142
    MetadataRelationship("MetadataRelationship", false),
143
    METADATA_RELATIONSHIP("MetadataRelationship", false),
1✔
144
    /**
145
     * @deprecated Since 7.22.0. Use {@link #MULTISELECT_PICKLIST} instead.
146
     */
147
    @Deprecated
1✔
148
    @SuppressWarnings("PMD.FieldNamingConventions")
149
    MultiselectPicklist("MultiselectPicklist", true),
150
    MULTISELECT_PICKLIST("MultiselectPicklist", true),
1✔
151
    /**
152
     * @deprecated Since 7.22.0. Use {@link #NOTE} instead.
153
     */
154
    @Deprecated
1✔
155
    @SuppressWarnings("PMD.FieldNamingConventions")
156
    Note("Note", true),
157
    NOTE("Note", true),
1✔
158
    /**
159
     * @deprecated Since 7.22.0. Use {@link #NUMBER} instead.
160
     */
161
    @Deprecated
1✔
162
    @SuppressWarnings("PMD.FieldNamingConventions")
163
    Number("Number", false, "Decimal", "Double", "Integer", "Long"),
164
    NUMBER("Number", false, "Decimal", "Double", "Integer", "Long"),
1✔
165
    /**
166
     * @deprecated Since 7.22.0. Use {@link #PERCENT} instead.
167
     */
168
    @Deprecated
1✔
169
    @SuppressWarnings("PMD.FieldNamingConventions")
170
    Percent("Percent", false),
171
    PERCENT("Percent", false),
1✔
172
    /**
173
     * @deprecated Since 7.22.0. Use {@link #PHONE} instead.
174
     */
175
    @Deprecated
1✔
176
    @SuppressWarnings("PMD.FieldNamingConventions")
177
    Phone("Phone", false),
178
    PHONE("Phone", false),
1✔
179
    /**
180
     * @deprecated Since 7.22.0. Use {@link #PICKLIST} instead.
181
     */
182
    @Deprecated
1✔
183
    @SuppressWarnings("PMD.FieldNamingConventions")
184
    Picklist("Picklist", true),
185
    PICKLIST("Picklist", true),
1✔
186
    /**
187
     * @deprecated Since 7.22.0. Use {@link #SUMMARY} instead.
188
     */
189
    @Deprecated
1✔
190
    @SuppressWarnings("PMD.FieldNamingConventions")
191
    Summary("Summary", false),
192
    SUMMARY("Summary", false),
1✔
193
    /**
194
     * @deprecated Since 7.22.0. Use {@link #TEXT} instead.
195
     */
196
    @Deprecated
1✔
197
    @SuppressWarnings("PMD.FieldNamingConventions")
198
    Text("Text", true, "String"),
199
    TEXT("Text", true, "String"),
1✔
200
    /**
201
     * @deprecated Since 7.22.0. Use {@link #TEXT_AREA} instead.
202
     */
203
    @Deprecated
1✔
204
    @SuppressWarnings("PMD.FieldNamingConventions")
205
    TextArea("TextArea", true),
206
    TEXT_AREA("TextArea", true),
1✔
207
    /**
208
     * @deprecated Since 7.22.0. Use {@link #TIME} instead.
209
     */
210
    @Deprecated
1✔
211
    @SuppressWarnings("PMD.FieldNamingConventions")
212
    Time("Time", false, "Time"),
213
    TIME("Time", false, "Time"),
1✔
214
    /**
215
     * @deprecated Since 7.22.0. Use {@link #URL} instead.
216
     */
217
    @Deprecated
1✔
218
    @SuppressWarnings("PMD.FieldNamingConventions")
219
    Url("Url", false),
220
    URL("Url", false),
1✔
221
    /**
222
     * Indicates that Metadata was found, but its type was not mappable. This could because it is a type which isn't
223
     * mapped, or it was an edge case where the type was ambiguously defined in the Metadata.
224
     *
225
     * @deprecated Since 7.22.0. Use {@link #UNKNOWN} instead.
226
     */
227
    @Deprecated
1✔
228
    @SuppressWarnings("PMD.FieldNamingConventions")
229
    Unknown("Unknown", true),
230
    /**
231
     * Indicates that Metadata was found, but its type was not mappable. This could because it is a type which isn't
232
     * mapped, or it was an edge case where the type was ambiguously defined in the Metadata.
233
     */
234
    UNKNOWN("Unknown", true);
1✔
235

236
    private static final Logger LOG = LoggerFactory.getLogger(DataType.class);
1✔
237

238

239
    private final String fieldTypeName;
240

241
    /**
242
     * @since 7.22.0
243
     */
244
    public String fieldTypeName() {
245
        return fieldTypeName;
1✔
246
    }
247

248
    /**
249
     * True if this field is an XSS risk
250
     */
251
    public final boolean requiresEscaping;
252

253
    /**
254
     * The set of primitive type names that map to this type. Multiple types can map to a single instance of this enum.
255
     * Note: these strings are not case-normalized.
256
     */
257
    private final Set<String> basicTypeNames;
258

259
    /**
260
     * A map of the lower-case-normalized field type name to its instance. The case metadata is not guaranteed to have the correct
261
     * case.
262
     */
263
    private static final Map<String, DataType> CASE_NORMALIZED_MAP = new HashMap<>();
1✔
264

265
    /**
266
     * A map of the lower-case-normalized primitive type names to DataType. Multiple types may map to one DataType.
267
     */
268
    private static final Map<String, DataType> BASIC_TYPE_MAP = new HashMap<>();
1✔
269

270
    static {
271
        for (DataType dataType : DataType.values()) {
1✔
272
            try {
273
                Field field = DataType.class.getField(dataType.name());
1✔
274
                if (field.isAnnotationPresent(Deprecated.class)) {
1✔
275
                    continue;
1✔
276
                }
277
            } catch (NoSuchFieldException e) {
×
278
                throw new IllegalStateException(e);
×
279
            }
1✔
280

281
            CASE_NORMALIZED_MAP.put(dataType.fieldTypeName().toLowerCase(Locale.ROOT), dataType);
1✔
282
            for (String typeName : dataType.basicTypeNames) {
1✔
283
                BASIC_TYPE_MAP.put(typeName.toLowerCase(Locale.ROOT), dataType);
1✔
284
            }
1✔
285
        }
286
    }
1✔
287

288
    /**
289
     * Map to correct instance, returns {@code UNKNOWN} if the value can't be mapped.
290
     */
291
    public static DataType fromString(String value) {
292
        value = value != null ? value : "";
1✔
293
        DataType dataType = CASE_NORMALIZED_MAP.get(value.toLowerCase(Locale.ROOT));
1✔
294

295
        if (dataType == null) {
1✔
296
            dataType = DataType.UNKNOWN;
1✔
297
            LOG.debug("Unable to determine DataType of {}", value);
1✔
298
        }
299

300
        return dataType;
1✔
301
    }
302

303
    /**
304
     * Map to correct instance, returns {@code UNKNOWN} if the value can't be mapped.
305
     */
306
    public static DataType fromTypeName(String value) {
307
        value = value != null ? value : "";
1✔
308
        DataType dataType = BASIC_TYPE_MAP.get(value.toLowerCase(Locale.ROOT));
1✔
309

310
        if (dataType == null) {
1✔
311
            dataType = DataType.UNKNOWN;
1✔
312
            LOG.debug("Unable to determine DataType of {}", value);
1✔
313
        }
314

315
        return dataType;
1✔
316
    }
317

318
    DataType(String fieldTypeName, boolean requiresEscaping, String... basicTypeNames) {
1✔
319
        this.fieldTypeName = fieldTypeName;
1✔
320
        this.requiresEscaping = requiresEscaping;
1✔
321
        this.basicTypeNames = new HashSet<>(Arrays.asList(basicTypeNames));
1✔
322
    }
1✔
323
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc