Skip to content

Commit 29dcb68

Browse files
committed
support parameter annotations in deftype/record
1 parent 7879383 commit 29dcb68

File tree

2 files changed

+34
-11
lines changed

2 files changed

+34
-11
lines changed

src/clj/clojure/core.clj

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3843,16 +3843,21 @@
38433843
(add-annotation av (name k) v))
38443844
(add-annotation av "value" v)))
38453845

3846-
(defn- add-annotations [visitor m]
3847-
(doseq [[k v] m]
3848-
(when (symbol? k)
3849-
(when-let [c (resolve k)]
3850-
(when (is-annotation? c)
3851-
;this is known duck/reflective as no common base of ASM Visitors
3852-
(let [av (.visitAnnotation visitor (descriptor c)
3853-
(is-runtime-annotation? c))]
3854-
(process-annotation av v)
3855-
(.visitEnd av)))))))
3846+
(defn- add-annotations
3847+
([visitor m] (add-annotations visitor m nil))
3848+
([visitor m i]
3849+
(doseq [[k v] m]
3850+
(when (symbol? k)
3851+
(when-let [c (resolve k)]
3852+
(when (is-annotation? c)
3853+
;this is known duck/reflective as no common base of ASM Visitors
3854+
(let [av (if i
3855+
(.visitParameterAnnotation visitor i (descriptor c)
3856+
(is-runtime-annotation? c))
3857+
(.visitAnnotation visitor (descriptor c)
3858+
(is-runtime-annotation? c)))]
3859+
(process-annotation av v)
3860+
(.visitEnd av))))))))
38563861

38573862
(defn alter-var-root
38583863
"Atomically alters the root binding of var v by applying f to its

src/jvm/clojure/lang/Compiler.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5441,7 +5441,7 @@ static PathNode commonPath(PathNode n1, PathNode n2){
54415441

54425442
static void addAnnotation(Object visitor, IPersistentMap meta){
54435443
try{
5444-
if(ADD_ANNOTATIONS.isBound())
5444+
if(meta != null && ADD_ANNOTATIONS.isBound())
54455445
ADD_ANNOTATIONS.invoke(visitor, meta);
54465446
}
54475447
catch (Exception e)
@@ -5450,6 +5450,17 @@ static void addAnnotation(Object visitor, IPersistentMap meta){
54505450
}
54515451
}
54525452

5453+
static void addParameterAnnotation(Object visitor, IPersistentMap meta, int i){
5454+
try{
5455+
if(meta != null && ADD_ANNOTATIONS.isBound())
5456+
ADD_ANNOTATIONS.invoke(visitor, meta, i);
5457+
}
5458+
catch (Exception e)
5459+
{
5460+
throw new RuntimeException(e);
5461+
}
5462+
}
5463+
54535464
private static Expr analyzeSymbol(Symbol sym) throws Exception{
54545465
Symbol tag = tagOf(sym);
54555466
if(sym.ns == null) //ns-qualified syms are always Vars
@@ -6322,6 +6333,7 @@ public static class NewInstanceMethod extends ObjMethod{
63226333
Class[] exclasses;
63236334

63246335
static Symbol dummyThis = Symbol.intern(null,"dummy_this_dlskjsdfower");
6336+
private IPersistentVector parms;
63256337

63266338
public NewInstanceMethod(ObjExpr objx, ObjMethod parent){
63276339
super(objx, parent);
@@ -6471,6 +6483,7 @@ static NewInstanceMethod parse(ObjExpr objx, ISeq form, Symbol thistag,
64716483
LOOP_LOCALS.set(argLocals);
64726484
method.name = name.name;
64736485
method.methodMeta = RT.meta(name);
6486+
method.parms = parms;
64746487
method.argLocals = argLocals;
64756488
method.body = (new BodyExpr.Parser()).parse(C.RETURN, body);
64766489
return method;
@@ -6521,6 +6534,11 @@ public void emit(ObjExpr obj, ClassVisitor cv){
65216534
extypes,
65226535
cv);
65236536
addAnnotation(gen,methodMeta);
6537+
for(int i = 0; i < parms.count(); i++)
6538+
{
6539+
IPersistentMap meta = RT.meta(parms.nth(i));
6540+
addParameterAnnotation(gen, meta, i);
6541+
}
65246542
gen.visitCode();
65256543
Label loopLabel = gen.mark();
65266544
gen.visitLineNumber(line, loopLabel);

0 commit comments

Comments
 (0)