12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 package compiler.compilercontrol.share.method;
25
26 import jdk.test.lib.Utils;
27
28 import java.lang.reflect.Constructor;
29 import java.lang.reflect.Executable;
30 import java.lang.reflect.Method;
31 import java.util.Arrays;
32
33 /**
34 * This class represents a signature of the method
35 */
36 public class SignatureType extends MethodElementType {
37 public SignatureType(Executable method) {
38 super(MethodDescriptor.Separator.NONE);
39 // Get parameters
40 Class<?>[] types = method.getParameterTypes();
41 String[] parameterTypes = new String[types.length];
42 for (int i = 0; i < types.length; i++) {
43 parameterTypes[i] = Utils.toJVMTypeSignature(types[i]);
44 }
45 // Get return value
46 String returnType;
47 if (method instanceof Method) {
48 returnType = Utils.toJVMTypeSignature(((Method) method)
49 .getReturnType());
50 } else if (method instanceof Constructor) {
51 // Constructor returns void in VM
52 returnType = Utils.toJVMTypeSignature(void.class);
53 } else {
54 throw new Error(String.format("TESTBUG: wrong type of executable "
55 + "%s of class %s", method, method.getClass()));
56 }
57 // Create signature
58 setElement("(" + String.join("", parameterTypes)+ ")" + returnType);
59 regexp = element;
60 setPattern(MethodDescriptor.PatternType.EXACT);
61 separator = MethodDescriptor.Separator.NONE;
62 }
63
64 @Override
65 public void setElement(String element) {
66 if (element.isEmpty()) {
67 setPattern(MethodDescriptor.PatternType.ANY);
68 } else {
69 super.setElement(element);
70 }
71 }
72
73 @Override
74 public boolean isValid() {
75 if (element.isEmpty()) {
76 return true;
77 }
78 // Allowed primitive types
79 char[] baseTypes = {'B', 'C', 'D', 'F', 'I', 'J', 'S', 'Z'}; // sorted
80 // Parsing states
81 boolean isArray = false;
82 boolean isInsideSig = false;
83 boolean isClass = false;
84
85 for (char ch : element.toCharArray()) {
86 if (ch == '(') {
87 if (isInsideSig) {
88 // Met another ( inside
89 return false;
130 }
131
132 @Override
133 public void setPattern(MethodDescriptor.PatternType patternType) {
134 switch (patternType) {
135 case PREFIX:
136 case SUFFIX:
137 case SUBSTRING:
138 // These patterns are not supported in Compiler Control
139 // Just use ANY pattern instead
140 case ANY:
141 regexp = "\\(.*\\).*";
142 element = "";
143 break;
144 case EXACT:
145 break;
146 default:
147 throw new IllegalArgumentException("ERROR: wrong pattern type "
148 + patternType);
149 }
150 }
151 }
|
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 package compiler.compilercontrol.share.method;
25
26 import jdk.test.lib.Utils;
27
28 import java.lang.reflect.Constructor;
29 import java.lang.reflect.Executable;
30 import java.lang.reflect.Method;
31 import java.util.Arrays;
32 import java.util.regex.Pattern;
33
34 /**
35 * This class represents a signature of the method
36 */
37 public class SignatureType extends MethodElementType {
38 public SignatureType(Executable method) {
39 super(MethodDescriptor.Separator.NONE);
40 // Get parameters
41 Class<?>[] types = method.getParameterTypes();
42 String[] parameterTypes = new String[types.length];
43 for (int i = 0; i < types.length; i++) {
44 parameterTypes[i] = Utils.toJVMTypeSignature(types[i]);
45 }
46 // Get return value
47 String returnType;
48 if (method instanceof Method) {
49 returnType = Utils.toJVMTypeSignature(((Method) method)
50 .getReturnType());
51 } else if (method instanceof Constructor) {
52 // Constructor returns void in VM
53 returnType = Utils.toJVMTypeSignature(void.class);
54 } else {
55 throw new Error(String.format("TESTBUG: wrong type of executable "
56 + "%s of class %s", method, method.getClass()));
57 }
58 // Create signature
59 setElement("(" + String.join("", parameterTypes)+ ")" + returnType);
60 regexp = element;
61 setPattern(MethodDescriptor.PatternType.EXACT);
62 separator = MethodDescriptor.Separator.NONE;
63 }
64
65 @Override
66 public void setElement(String element) {
67 if (element.isEmpty()) {
68 setPattern(MethodDescriptor.PatternType.ANY);
69 } else {
70 this.element = element;
71 this.regexp = element;
72 }
73 }
74
75 @Override
76 public boolean isValid() {
77 if (element.isEmpty()) {
78 return true;
79 }
80 // Allowed primitive types
81 char[] baseTypes = {'B', 'C', 'D', 'F', 'I', 'J', 'S', 'Z'}; // sorted
82 // Parsing states
83 boolean isArray = false;
84 boolean isInsideSig = false;
85 boolean isClass = false;
86
87 for (char ch : element.toCharArray()) {
88 if (ch == '(') {
89 if (isInsideSig) {
90 // Met another ( inside
91 return false;
132 }
133
134 @Override
135 public void setPattern(MethodDescriptor.PatternType patternType) {
136 switch (patternType) {
137 case PREFIX:
138 case SUFFIX:
139 case SUBSTRING:
140 // These patterns are not supported in Compiler Control
141 // Just use ANY pattern instead
142 case ANY:
143 regexp = "\\(.*\\).*";
144 element = "";
145 break;
146 case EXACT:
147 break;
148 default:
149 throw new IllegalArgumentException("ERROR: wrong pattern type "
150 + patternType);
151 }
152 }
153
154 @Override
155 public String getRegexp() {
156 if ("\\(.*\\).*".equals(regexp)) {
157 return regexp;
158 }
159 return Pattern.quote(regexp);
160 }
161 }
|