MCPcopy Index your code
hub / github.com/apache/tomcat / toClass

Method toClass

java/org/apache/jasper/compiler/JspUtil.java:263–300  ·  view source on GitHub ↗

Returns the Class object associated with the class or interface with the given string name. The Class object is determined by passing the given string name to the Class.forName() method, unless the given string name represents a primitive type, in which cas

(String type, ClassLoader loader)

Source from the content-addressed store, hash-verified

261 * @throws ClassNotFoundException Loading class failed
262 */
263 public static Class<?> toClass(String type, ClassLoader loader) throws ClassNotFoundException {
264
265 int i0 = type.indexOf('[');
266 int dims = 0;
267 if (i0 > 0) {
268 // This is an array. Count the dimensions
269 for (int i = 0; i < type.length(); i++) {
270 if (type.charAt(i) == '[') {
271 dims++;
272 }
273 }
274 type = type.substring(0, i0);
275 }
276
277 Class<?> c = switch (type) {
278 case "boolean" -> boolean.class;
279 case "char" -> char.class;
280 case "byte" -> byte.class;
281 case "short" -> short.class;
282 case "int" -> int.class;
283 case "long" -> long.class;
284 case "float" -> float.class;
285 case "double" -> double.class;
286 case "void" -> void.class;
287 default -> loader.loadClass(type);
288 };
289
290 if (dims == 0) {
291 return c;
292 }
293
294 if (dims == 1) {
295 return java.lang.reflect.Array.newInstance(c, 1).getClass();
296 }
297
298 // Array of more than i dimension
299 return java.lang.reflect.Array.newInstance(c, new int[dims]).getClass();
300 }
301
302 /**
303 * Produces a String representing a call to the EL interpreter.

Callers 2

checkXmlAttributesMethod · 0.95
visitMethod · 0.95

Calls 5

lengthMethod · 0.80
charAtMethod · 0.80
newInstanceMethod · 0.65
indexOfMethod · 0.45
loadClassMethod · 0.45

Tested by

no test coverage detected