diff options
author | Rich Hickey <richhickey@gmail.com> | 2008-01-06 21:36:09 +0000 |
---|---|---|
committer | Rich Hickey <richhickey@gmail.com> | 2008-01-06 21:36:09 +0000 |
commit | fa30aeed53960838cdcc5d0437fdccab0e9be828 (patch) | |
tree | f13607b7cfe50531bbad320f3c713b5088761c34 /src | |
parent | 4586ede5f3b1cb09e8c15d9ca2c89e60bfde313b (diff) |
added *warn-on-reflection*
Diffstat (limited to 'src')
-rw-r--r-- | src/boot.clj | 1 | ||||
-rw-r--r-- | src/jvm/clojure/lang/Compiler.java | 22 | ||||
-rw-r--r-- | src/jvm/clojure/lang/RT.java | 1 | ||||
-rw-r--r-- | src/jvm/clojure/lang/Repl.java | 1 |
4 files changed, 23 insertions, 2 deletions
diff --git a/src/boot.clj b/src/boot.clj index 9c0cc335..79e0533d 100644 --- a/src/boot.clj +++ b/src/boot.clj @@ -1012,5 +1012,6 @@ defstruct struct accessor create-struct subvec false? true? + *warn-on-reflection* )) diff --git a/src/jvm/clojure/lang/Compiler.java b/src/jvm/clojure/lang/Compiler.java index dd3fe7e1..cf0b801a 100644 --- a/src/jvm/clojure/lang/Compiler.java +++ b/src/jvm/clojure/lang/Compiler.java @@ -734,6 +734,10 @@ static class InstanceFieldExpr extends FieldExpr implements AssignableExpr{ this.field = targetClass != null ? targetClass.getField(fieldName) : null; this.fieldName = fieldName; this.line = line; + if(field == null && RT.booleanCast(RT.WARN_ON_REFLECTION)) + { + System.err.format("Reflection warning, line: %d - reference to field %s can't be resolved.\n", line, fieldName); + } } public Object eval() throws Exception{ @@ -925,6 +929,11 @@ static class InstanceMethodExpr extends MethodExpr{ } else method = null; + + if(method == null && RT.booleanCast(RT.WARN_ON_REFLECTION)) + { + System.err.format("Reflection warning, line: %d - call to %s can't be resolved.\n", line, methodName); + } } public Object eval() throws Exception{ @@ -1007,6 +1016,10 @@ static class StaticMethodExpr extends MethodExpr{ methodidx = getMatchingParams(params, args); } method = (java.lang.reflect.Method) (methodidx >= 0 ? methods.get(methodidx) : null); + if(method == null && RT.booleanCast(RT.WARN_ON_REFLECTION)) + { + System.err.format("Reflection warning, line: %d - call to %s can't be resolved.\n", line, methodName); + } } public Object eval() throws Exception{ @@ -1661,7 +1674,7 @@ static class NewExpr implements Expr{ final static Method forNameMethod = Method.getMethod("Class forName(String)"); - public NewExpr(String className, IPersistentVector args) throws Exception{ + public NewExpr(String className, IPersistentVector args, int line) throws Exception{ this.args = args; this.className = className; this.c = Class.forName(className); @@ -1687,6 +1700,10 @@ static class NewExpr implements Expr{ } this.ctor = ctoridx >= 0 ? (Constructor) ctors.get(ctoridx) : null; + if(ctor == null && RT.booleanCast(RT.WARN_ON_REFLECTION)) + { + System.err.format("Reflection warning, line: %d - call to %s ctor can't be resolved.\n", line, className); + } } public Object eval() throws Exception{ @@ -1730,6 +1747,7 @@ static class NewExpr implements Expr{ static class Parser implements IParser{ public Expr parse(C context, Object frm) throws Exception{ + int line = (Integer) LINE.get(); ISeq form = (ISeq) frm; //(new Classname args...) if(form.count() < 2) @@ -1740,7 +1758,7 @@ static class NewExpr implements Expr{ PersistentVector args = PersistentVector.EMPTY; for(ISeq s = RT.rest(RT.rest(form)); s != null; s = s.rest()) args = args.cons(analyze(C.EXPRESSION, s.first())); - return new NewExpr(className, args); + return new NewExpr(className, args, line); } } diff --git a/src/jvm/clojure/lang/RT.java b/src/jvm/clojure/lang/RT.java index 3586aab0..14b78de9 100644 --- a/src/jvm/clojure/lang/RT.java +++ b/src/jvm/clojure/lang/RT.java @@ -118,6 +118,7 @@ Symbol.create("Exception"), "java.lang.Exception" final static Var PRINT_META = Var.intern(Symbol.create("clojure", "*print-meta*"), F); final static Var PRINT_READABLY = Var.intern(Symbol.create("clojure", "*print-readably*"), T); +final static Var WARN_ON_REFLECTION = Var.intern(Symbol.create("clojure", "*warn-on-reflection*"), F); final static Var IMPORTS = Var.intern(Symbol.create("clojure", "*imports*"), DEFAULT_IMPORTS); final static IFn inNamespace = new AFn(){ diff --git a/src/jvm/clojure/lang/Repl.java b/src/jvm/clojure/lang/Repl.java index e3de82d5..d5caefdc 100644 --- a/src/jvm/clojure/lang/Repl.java +++ b/src/jvm/clojure/lang/Repl.java @@ -39,6 +39,7 @@ public static void main(String[] args){ RT.map(RT.NS_REFERS, RT.NS_REFERS.get(), RT.NS_IMPORTS, RT.NS_IMPORTS.get(), RT.CURRENT_NS_SYM, RT.CURRENT_NS_SYM.get(), + RT.WARN_ON_REFLECTION, RT.WARN_ON_REFLECTION.get(), Compiler.SOURCE, "REPL" )); w.write("Clojure\n"); |