Skip to content

Package: PropertyInfo$MethodInfo

PropertyInfo$MethodInfo

nameinstructionbranchcomplexitylinemethod
PropertyInfo.MethodInfo(Method, Field)
M: 0 C: 9
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
getAnnotation(Class)
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getField()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getMember()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getName()
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getType()
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
toString()
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*
2: * JOPA
3: * Copyright (C) 2023 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.model.metamodel;
19:
20: import java.lang.annotation.Annotation;
21: import java.lang.reflect.Field;
22: import java.lang.reflect.Member;
23: import java.lang.reflect.Method;
24:
25: /**
26: * A simple wrapper that enables using annotations from methods while processing fields during metamodel creation.
27: * @see AnnotatedAccessor
28: */
29: public interface PropertyInfo {
30: <T extends Annotation> T getAnnotation(Class<T> annotationClass);
31:
32: Class<?> getType();
33:
34: String getName();
35:
36: Member getMember();
37:
38: Field getField();
39:
40: static PropertyInfo from(Field field) {
41: return new FieldInfo(field);
42: }
43:
44: static PropertyInfo from(Method method,Field field) {
45: return new MethodInfo(method,field);
46: }
47:
48: class FieldInfo implements PropertyInfo {
49: private final Field field;
50:
51: public FieldInfo(Field field) {
52: this.field = field;
53: }
54:
55: @Override
56: public Class<?> getType() {
57: return field.getType();
58: }
59:
60: @Override
61: public String getName() {
62: return field.getName();
63: }
64:
65: @Override
66: public Member getMember() {
67: return field;
68: }
69:
70: @Override
71: public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
72: return field.getAnnotation(annotationClass);
73: }
74:
75: @Override
76: public Field getField() {
77: return field;
78: }
79:
80: @Override
81: public String toString() {
82: return "FieldInfo{" +
83: "class =" + field.getDeclaringClass().getName() +
84: ", field=" + field.getName() +
85: '}';
86: }
87: }
88:
89: class MethodInfo implements PropertyInfo {
90: private final Method method;
91:
92: private final Field rawField;
93:
94: public MethodInfo(Method method, Field rawField) {
95: this.method = method;
96: this.rawField = rawField;
97: }
98:
99: @Override
100: public Class<?> getType() {
101: return rawField.getType();
102: }
103:
104: @Override
105: public String getName() {
106: return rawField.getName();
107: }
108: @Override
109: public Member getMember() {
110: return method;
111: }
112:
113: @Override
114: public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
115: return method.getAnnotation(annotationClass);
116: }
117:
118: @Override
119: public Field getField() {
120: return rawField;
121: }
122:
123: @Override
124: public String toString() {
125: return "MethodInfo{" +
126: "method=" + method +
127: ", rawField=" + rawField +
128: '}';
129: }
130: }
131: }
132: