blob: 07e75ceed857867bef0095002c4025a02198ed8d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
package org.testng.internal;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
/**
* Encapsulation of either a method or a constructor.
*
* @author Cedric Beust <cedric@beust.com>
*/
public class ConstructorOrMethod {
private Method m_method;
private Constructor m_constructor;
private boolean m_enabled = true;
public ConstructorOrMethod(Method m) {
m_method = m;
}
public ConstructorOrMethod(Constructor c) {
m_constructor = c;
}
public Class<?> getDeclaringClass() {
return getMethod() != null ? getMethod().getDeclaringClass() : getConstructor().getDeclaringClass();
}
public String getName() {
return getMethod() != null ? getMethod().getName() : getConstructor().getName();
}
public Class[] getParameterTypes() {
return getMethod() != null ? getMethod().getParameterTypes() : getConstructor().getParameterTypes();
}
public Method getMethod() {
return m_method;
}
public Constructor getConstructor() {
return m_constructor;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((getConstructor() == null) ? 0 : getConstructor().hashCode());
result = prime * result + ((getMethod() == null) ? 0 : getMethod().hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
ConstructorOrMethod other = (ConstructorOrMethod) obj;
if (getConstructor() == null) {
if (other.getConstructor() != null)
return false;
} else if (!getConstructor().equals(other.getConstructor()))
return false;
if (getMethod() == null) {
if (other.getMethod() != null)
return false;
} else if (!getMethod().equals(other.getMethod()))
return false;
return true;
}
public void setEnabled(boolean enabled) {
m_enabled = enabled;
}
public boolean getEnabled() {
return m_enabled;
}
@Override
public String toString() {
if (m_method != null) return m_method.toString();
else return m_constructor.toString();
}
}
|