Skip to content

Commit c03fc71

Browse files
committed
Release 0.0.11
1 parent 5d6313b commit c03fc71

1 file changed

Lines changed: 59 additions & 64 deletions

File tree

src/main/java/com/remondis/resample/InvocationSensor.java

Lines changed: 59 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -24,78 +24,73 @@
2424
*/
2525
class InvocationSensor<T> {
2626

27-
private T proxyObject;
27+
private T proxyObject;
2828

29-
private List<String> propertyNames = new LinkedList<>();
29+
private List<String> propertyNames = new LinkedList<>();
3030

31-
InvocationSensor(Class<T> superType) {
32-
Class<? extends T> proxyClass = new ByteBuddy().subclass(superType)
33-
.method(isGetter())
34-
.intercept(of((proxy, method, args) -> markPropertyAsCalled(
35-
method)))
36-
.method(isDeclaredBy(Object.class))
37-
.intercept(of((proxy, method, args) -> invokeMethodProxySafe(
38-
method,
39-
this,
40-
args)))
41-
.method(not(isGetter()).and(not(isDeclaredBy(Object.class))))
42-
.intercept(of((proxy, method, args) -> {
43-
throw ReflectionException.notAGetter(method);
44-
}))
45-
.make()
46-
.load(getClass().getClassLoader(),
47-
ClassLoadingStrategy.Default.INJECTION)
48-
.getLoaded();
31+
InvocationSensor(Class<T> superType) {
32+
Class<? extends T> proxyClass = new ByteBuddy().subclass(superType)
33+
.method(isGetter())
34+
.intercept(of((proxy, method, args) -> markPropertyAsCalled(method)))
35+
.method(isDeclaredBy(Object.class))
36+
.intercept(of((proxy, method, args) -> invokeMethodProxySafe(method, this, args)))
37+
.method(not(isGetter()).and(not(isDeclaredBy(Object.class))))
38+
.intercept(of((proxy, method, args) -> {
39+
throw ReflectionException.notAGetter(method);
40+
}))
41+
.make()
42+
.load(getClass().getClassLoader(), ClassLoadingStrategy.Default.INJECTION)
43+
.getLoaded();
4944

50-
proxyObject = superType.cast(ReflectionUtil.newInstance(proxyClass));
51-
}
45+
proxyObject = superType.cast(ReflectionUtil.newInstance(proxyClass));
46+
}
5247

53-
private Object markPropertyAsCalled(Method method) {
54-
String propertyName = toPropertyName(method);
55-
propertyNames.add(propertyName);
56-
return nullOrDefaultValue(method.getReturnType());
57-
}
48+
private Object markPropertyAsCalled(Method method) {
49+
String propertyName = toPropertyName(method);
50+
propertyNames.add(propertyName);
51+
return nullOrDefaultValue(method.getReturnType());
52+
}
5853

59-
/**
60-
* Returns the proxy object get-method calls can be performed on.
61-
*
62-
* @return The proxy.
63-
*/
64-
T getSensor() {
65-
return proxyObject;
66-
}
54+
/**
55+
* Returns the proxy object get-method calls can be performed on.
56+
*
57+
* @return The proxy.
58+
*/
59+
T getSensor() {
60+
return proxyObject;
61+
}
6762

68-
/**
69-
* Returns the list of property names that were tracked by get calls.
70-
*
71-
* @return Returns the tracked property names.
72-
*/
73-
List<String> getTrackedPropertyNames() {
74-
return Collections.unmodifiableList(propertyNames);
75-
}
63+
/**
64+
* Returns the list of property names that were tracked by get calls.
65+
*
66+
* @return Returns the tracked property names.
67+
*/
68+
List<String> getTrackedPropertyNames() {
69+
return Collections.unmodifiableList(propertyNames);
70+
}
7671

77-
/**
78-
* Checks if there were any properties accessed by get calls.
79-
*
80-
* @return Returns <code>true</code> if there were at least one interaction with
81-
* a property. Otherwise <code>false</code> is returned.
82-
*/
83-
boolean hasTrackedProperties() {
84-
return !propertyNames.isEmpty();
85-
}
72+
/**
73+
* Checks if there were any properties accessed by get calls.
74+
*
75+
* @return Returns <code>true</code> if there were at least one interaction with
76+
* a property. Otherwise <code>false</code> is returned.
77+
*/
78+
boolean hasTrackedProperties() {
79+
return !propertyNames.isEmpty();
80+
}
8681

87-
/**
88-
* Resets all tracked information.
89-
*/
90-
void reset() {
91-
propertyNames.clear();
92-
}
82+
/**
83+
* Resets all tracked information.
84+
*/
85+
void reset() {
86+
propertyNames.clear();
87+
}
9388

94-
private static Object nullOrDefaultValue(Class<?> returnType) {
95-
if (returnType.isPrimitive()) {
96-
return defaultValue(returnType);
97-
} else {
98-
return null;
99-
}
89+
private static Object nullOrDefaultValue(Class<?> returnType) {
90+
if (returnType.isPrimitive()) {
91+
return defaultValue(returnType);
92+
} else {
93+
return null;
10094
}
95+
}
10196
}

0 commit comments

Comments
 (0)