Skip to content

Package: ManagedClassProcessor

ManagedClassProcessor

nameinstructionbranchcomplexitylinemethod
checkForNoArgConstructor(Class)
M: 0 C: 22
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
getManagedSupertype(Class)
M: 0 C: 12
100%
M: 1 C: 3
75%
M: 1 C: 2
67%
M: 0 C: 3
100%
M: 0 C: 1
100%
isEntityType(Class)
M: 0 C: 8
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
isManagedType(Class)
M: 0 C: 10
100%
M: 0 C: 4
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
isMappedSuperclassType(Class)
M: 0 C: 8
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
processEntityType(Class)
M: 0 C: 33
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
processManagedType(Class)
M: 18 C: 16
47%
M: 2 C: 4
67%
M: 2 C: 2
50%
M: 1 C: 5
83%
M: 0 C: 1
100%
processMappedSuperclassType(Class)
M: 4 C: 10
71%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 0 C: 2
100%
M: 0 C: 1
100%
static {...}
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%

Coverage

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 cz.cvut.kbss.jopa.exception.MetamodelInitializationException;
18: import cz.cvut.kbss.jopa.model.IRI;
19: import cz.cvut.kbss.jopa.model.annotations.MappedSuperclass;
20: import cz.cvut.kbss.jopa.model.annotations.OWLClass;
21:
22: /**
23: * Utility methods for processing managed types for metamodel construction.
24: */
25: class ManagedClassProcessor {
26:
27: private ManagedClassProcessor() {
28: }
29:
30: static <T> AbstractIdentifiableType<T> processManagedType(Class<T> cls) {
31:• assert isManagedType(cls);
32:• if (isEntityType(cls)) {
33: return processEntityType(cls);
34:• } else if (isMappedSuperclassType(cls)) {
35: return processMappedSuperclassType(cls);
36: }
37: throw new IllegalArgumentException("Type " + cls + " is not a managed type.");
38: }
39:
40: static <T> EntityTypeImpl<T> processEntityType(Class<T> cls) {
41: final OWLClass c = cls.getDeclaredAnnotation(OWLClass.class);
42:
43:• if (c == null) {
44: throw new MetamodelInitializationException("The class " + cls + " is not an OWLPersistence entity!");
45: }
46:
47: checkForNoArgConstructor(cls);
48:
49: return new EntityTypeImpl<>(cls.getSimpleName(), cls, IRI.create(c.iri()));
50: }
51:
52: private static <T> void checkForNoArgConstructor(Class<T> cls) {
53: try {
54: cls.getDeclaredConstructor();
55: } catch (NoSuchMethodException e) {
56: throw new MetamodelInitializationException("Class " + cls + " is missing required no-arg constructor.");
57: }
58: }
59:
60: private static <T> MappedSuperclassTypeImpl<T> processMappedSuperclassType(Class<T> cls) {
61:• assert cls.getDeclaredAnnotation(MappedSuperclass.class) != null;
62:
63: return new MappedSuperclassTypeImpl<>(cls);
64: }
65:
66: static <T> Class<? super T> getManagedSupertype(Class<T> cls) {
67:• if (cls.getSuperclass() != null && isManagedType(cls.getSuperclass())) {
68: return cls.getSuperclass();
69: }
70: return null;
71: }
72:
73: private static boolean isManagedType(Class<?> cls) {
74:• return isEntityType(cls) || isMappedSuperclassType(cls);
75: }
76:
77: private static boolean isEntityType(Class<?> cls) {
78:• return cls.getDeclaredAnnotation(OWLClass.class) != null;
79: }
80:
81: private static boolean isMappedSuperclassType(Class<?> cls) {
82:• return cls.getDeclaredAnnotation(MappedSuperclass.class) != null;
83: }
84: }