Repository navigation
Expand file tree
/
Copy pathExecutableReaderImpl.java
More file actions
127 lines (109 loc) · 3.2 KB
/
Copy pathExecutableReaderImpl.java
File metadata and controls
127 lines (109 loc) · 3.2 KB
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package javakit.resolver;
import snap.util.ArrayUtils;
import java.lang.reflect.*;
/**
* This class is an ExecutableReader implementation for java.lang.Executable.
*/
public class ExecutableReaderImpl implements ExecutableReader {
// The executable
private Executable _executable;
// The JavaExecutable
private JavaExecutable _javaExecutable;
// The Resolver
private Resolver _resolver;
/**
* Constructor.
*/
public ExecutableReaderImpl(Executable anExec)
{
_executable = anExec;
}
/**
* Sets the JavaExecutable.
*/
@Override
public void setJavaExecutable(JavaExecutable anExec)
{
_javaExecutable = anExec;
_resolver = _javaExecutable._resolver;
}
/**
* Returns the name.
*/
@Override
public String getName() { return _executable.getName(); }
/**
* Returns the simple name.
*/
@Override
public String getSimpleName()
{
if (_executable instanceof Constructor)
return _javaExecutable._declaringClass.getSimpleName();
return _executable.getName();
}
/**
* Returns the modifiers.
*/
@Override
public int getModifiers() { return _executable.getModifiers(); }
/**
* Returns whether Method/Constructor is VarArgs type.
*/
@Override
public boolean isVarArgs() { return _executable.isVarArgs(); }
/**
* Returns whether Method is default type.
*/
@Override
public boolean isDefault() { return _executable instanceof Method && ((Method) _executable).isDefault(); }
/**
* Returns the TypeVars.
*/
@Override
public JavaTypeVariable[] getTypeParameters()
{
TypeVariable<?>[] typeVars = _executable.getTypeParameters();
return ArrayUtils.map(typeVars, tvar -> new JavaTypeVariable(_resolver, _javaExecutable, tvar), JavaTypeVariable.class);
}
/**
* Returns the parameter types.
*/
@Override
public JavaType[] getGenericParameterTypes()
{
// Get GenericParameterTypes (this can fail https://bugs.openjdk.java.net/browse/JDK-8075483))
Type[] paramTypesReal = _executable.getGenericParameterTypes();
if (paramTypesReal.length < _executable.getParameterCount())
paramTypesReal = _executable.getParameterTypes();
// Return JavaTypes
return _resolver.getJavaTypesForTypes(paramTypesReal);
}
/**
* Returns the parameter classes.
*/
@Override
public JavaClass[] getParameterClasses()
{
Class<?>[] paramClasses = _executable.getParameterTypes();
return ArrayUtils.map(paramClasses, _resolver::getJavaClassForClass, JavaClass.class);
}
/**
* Returns the return type.
*/
@Override
public JavaType getGenericReturnType()
{
Type returnTypeReal = ((Method) _executable).getGenericReturnType();
return _resolver.getJavaTypeForType(returnTypeReal);
}
/**
* Returns the parameter names.
*/
@Override
public String[] getParameterNames()
{
Parameter[] parameters = _executable.getParameters();
return ArrayUtils.map(parameters, param -> param.getName(), String.class);
}
}