Skip to contentMethod: PropertiesParametersResolver(Field)
1: /**
2: * Copyright (C) 2016 Czech Technical University in Prague
3: *
4: * This program is free software: you can redistribute it and/or modify it under
5: * the terms of the GNU General Public License as published by the Free Software
6: * Foundation, either version 3 of the License, or (at your option) any
7: * later version.
8: *
9: * This program is distributed in the hope that it will be useful, but WITHOUT
10: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12: * details. You should have received a copy of the GNU General Public License
13: * along with this program. If not, see <http://www.gnu.org/licenses/>.
14: */
15: package cz.cvut.kbss.jopa.model.metamodel;
16:
17: import java.lang.reflect.*;
18:
19: class PropertiesParametersResolver {
20:
21: private final java.lang.reflect.Type keyType;
22: private final java.lang.reflect.Type valueType;
23:
24: PropertiesParametersResolver(Field propertiesField) {
25: final ParameterizedType typeSpec = (ParameterizedType) propertiesField.getGenericType();
26:• assert typeSpec.getActualTypeArguments().length == 2;
27: this.keyType = typeSpec.getActualTypeArguments()[0];
28: this.valueType = typeSpec.getActualTypeArguments()[1];
29: }
30:
31: java.lang.reflect.Type getKeyType() {
32: return keyType;
33: }
34:
35: java.lang.reflect.Type getValueType() {
36: return valueType;
37: }
38:
39: Class<?> getPropertyIdentifierType() {
40: assert keyType instanceof Class;
41: return (Class<?>) keyType;
42: }
43:
44: Class<?> getPropertyValueType() {
45: assert valueType instanceof ParameterizedType;
46: final ParameterizedType type = (ParameterizedType) valueType;
47: assert type.getActualTypeArguments().length == 1;
48: assert type.getActualTypeArguments()[0] instanceof Class;
49: return (Class<?>) type.getActualTypeArguments()[0];
50: }
51: }