MCPcopy Index your code
hub / github.com/clojure/clojure / invokeConstructor

Method invokeConstructor

src/jvm/clojure/lang/Reflector.java:304–345  ·  view source on GitHub ↗
(Class c, Object[] args)

Source from the content-addressed store, hash-verified

302}
303
304public static Object invokeConstructor(Class c, Object[] args) {
305 try
306 {
307 Constructor[] allctors = c.getConstructors();
308 ArrayList ctors = new ArrayList();
309 for(int i = 0; i < allctors.length; i++)
310 {
311 Constructor ctor = allctors[i];
312 if(ctor.getParameterTypes().length == args.length)
313 ctors.add(ctor);
314 }
315 if(ctors.isEmpty())
316 {
317 throw new IllegalArgumentException("No matching ctor found"
318 + " for " + c);
319 }
320 else if(ctors.size() == 1)
321 {
322 Constructor ctor = (Constructor) ctors.get(0);
323 return ctor.newInstance(boxArgs(ctor.getParameterTypes(), args));
324 }
325 else //overloaded w/same arity
326 {
327 for(Iterator iterator = ctors.iterator(); iterator.hasNext();)
328 {
329 Constructor ctor = (Constructor) iterator.next();
330 Class[] params = ctor.getParameterTypes();
331 if(isCongruent(params, args))
332 {
333 Object[] boxedArgs = boxArgs(params, args);
334 return ctor.newInstance(boxedArgs);
335 }
336 }
337 throw new IllegalArgumentException("No matching ctor found"
338 + " for " + c);
339 }
340 }
341 catch(Exception e)
342 {
343 throw Util.sneakyThrow(getCauseOrElse(e));
344 }
345}
346
347public static Object invokeStaticMethodVariadic(String className, String methodName, Object... args) {
348 return invokeStaticMethod(className, methodName, args);

Callers 8

evalMethod · 0.95
invokeStaticMethodMethod · 0.95
invokeMethod · 0.95
readRecordMethod · 0.95
emitMethod · 0.45
emitKeywordCallsitesMethod · 0.45
emitValueMethod · 0.45
emitMethod · 0.45

Calls 12

boxArgsMethod · 0.95
isCongruentMethod · 0.95
sneakyThrowMethod · 0.95
getCauseOrElseMethod · 0.95
newInstanceMethod · 0.80
addMethod · 0.65
isEmptyMethod · 0.65
getMethod · 0.65
iteratorMethod · 0.65
nextMethod · 0.65
sizeMethod · 0.45
hasNextMethod · 0.45

Tested by

no test coverage detected