-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMethodDefinition.java
117 lines (101 loc) · 3.08 KB
/
MethodDefinition.java
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
package nl.rug.jbi.jsm.bcel;
import com.google.common.base.Function;
import com.google.common.collect.Lists;
import org.apache.bcel.generic.MethodGen;
import org.apache.bcel.generic.Type;
import java.util.Arrays;
import java.util.List;
import static nl.rug.jbi.jsm.bcel.BCELTools.type2className;
/**
* Represents a method of the class inspected in the current scope, will be emitted for each method found by
* the {@link nl.rug.jbi.jsm.bcel.ClassVisitor}.
*
* @author David van Leusen
* @since 2014-05-28
*/
public class MethodDefinition {
private final MethodGen mg;
public MethodDefinition(MethodGen mg) {
this.mg = mg;
}
/**
* @return The name of the method, not guaranteed to be unique because of overloading.
*/
public String getMethodName() {
return mg.getName();
}
/**
* @return A string representing the type of object this method returns.
*/
public String getReturnType() {
return type2className(mg.getReturnType());
}
/**
* @return An array of strings representing the types of exceptions thrown by this method.
*/
public String[] getExceptions() {
return mg.getExceptions();
}
/**
* Notice: use {@link #getExactArgumentTypes()} if difference between polymorphic methods is important.
*
* @return A list of strings representing the base types of the arguments of this method.
*/
public List<String> getArgumentTypes() {
return Lists.transform(Arrays.asList(this.mg.getArgumentTypes()), new Function<Type, String>() {
@Override
public String apply(final Type type) {
return type2className(type);
}
});
}
/**
* Use {@link #getArgumentTypes()} if only the actual base types are important.
*
* @return A list of strings representing the types of the arguments EXACTLY as BCEL reports them.
*/
public List<String> getExactArgumentTypes() {
return Lists.transform(Arrays.asList(this.mg.getArgumentTypes()), new Function<Type, String>() {
@Override
public String apply(final Type type) {
return type.toString();
}
});
}
/**
* @return Whether this method has the 'public' modifier.
*/
public boolean isPublic() {
return mg.isPublic();
}
/**
* @return Whether this method has the 'protected' modifier.
*/
public boolean isProtected() {
return mg.isProtected();
}
/**
* @return Whether this method has the 'abstract' modifier.
*/
public boolean isAbstract() {
return mg.isAbstract();
}
/**
* @return Whether this method has the 'private' modifier.
*/
public boolean isPrivate() {
return mg.isPrivate();
}
/**
* @return Whether this method has the 'native' modifier.
*/
public boolean isNative() {
return mg.isNative();
}
/**
* @return Whether this method has the 'static' modifier.
*/
public boolean isStatic() {
return mg.isStatic();
}
}