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

Method readRecord

src/jvm/clojure/lang/LispReader.java:1454–1504  ·  view source on GitHub ↗
(Object form, Symbol recordName, Object opts, Object pendingForms)

Source from the content-addressed store, hash-verified

1452 }
1453
1454 private Object readRecord(Object form, Symbol recordName, Object opts, Object pendingForms){
1455 boolean readeval = RT.booleanCast(RT.READEVAL.deref());
1456
1457 if(!readeval)
1458 {
1459 throw Util.runtimeException("Record construction syntax can only be used when *read-eval* == true");
1460 }
1461
1462 Class recordClass = RT.classForNameNonLoading(recordName.toString());
1463
1464
1465 boolean shortForm = true;
1466
1467 if(form instanceof IPersistentMap) {
1468 shortForm = false;
1469 } else if (form instanceof IPersistentVector) {
1470 shortForm = true;
1471 } else {
1472 throw Util.runtimeException("Unreadable constructor form starting with \"#" + recordName + "\"");
1473 }
1474
1475 Object ret = null;
1476 Constructor[] allctors = ((Class)recordClass).getConstructors();
1477
1478 if(shortForm)
1479 {
1480 IPersistentVector recordEntries = (IPersistentVector)form;
1481 boolean ctorFound = false;
1482 for (Constructor ctor : allctors)
1483 if(ctor.getParameterTypes().length == recordEntries.count())
1484 ctorFound = true;
1485
1486 if(!ctorFound)
1487 throw Util.runtimeException("Unexpected number of constructor arguments to " + recordClass.toString() + ": got " + recordEntries.count());
1488
1489 ret = Reflector.invokeConstructor(recordClass, RT.toArray(recordEntries));
1490 }
1491 else
1492 {
1493
1494 IPersistentMap vals = (IPersistentMap)form;
1495 for(ISeq s = RT.keys(vals); s != null; s = s.next())
1496 {
1497 if(!(s.first() instanceof Keyword))
1498 throw Util.runtimeException("Unreadable defrecord form: key must be of type clojure.lang.Keyword, got " + s.first().toString());
1499 }
1500 ret = Reflector.invokeStaticMethod(recordClass, "create", new Object[]{vals});
1501 }
1502
1503 return ret;
1504 }
1505}
1506
1507static boolean isPreserveReadCond(Object opts) {

Callers 1

invokeMethod · 0.95

Calls 12

booleanCastMethod · 0.95
runtimeExceptionMethod · 0.95
invokeConstructorMethod · 0.95
toArrayMethod · 0.95
keysMethod · 0.95
nextMethod · 0.95
firstMethod · 0.95
invokeStaticMethodMethod · 0.95
derefMethod · 0.65
countMethod · 0.65
toStringMethod · 0.45

Tested by

no test coverage detected