Re: [Codenarc-user] Incomplete AST nodes?
Brought to you by:
chrismair
From: Klaus B. <kla...@go...> - 2011-04-14 07:45:58
|
Hi Hamlet, the class hierarchy problem is because the AST generation takes a class at a time and fills the superClass property just for the next level up. If the superClass itself has not yet been inspected, it gets Object as superClass. The way I (kind of) solved this problem was by using a 2-phase approach. I modified the Codenarc script to run it two times and at the same time build my own class-superClass map. Not perfect, I know. But I got a complete hierarchy. Now to the actual problem I want to solve: I'm writing a rule, that finds non-declared properties (or you might say dynamic properties). That is all variable accesses that are not declared in the class/superClass, the closure or whatever context the access is. I'm pretty close to a working solution but I it will remain an approximation to a strict parser with holes in it. The background is to give the developers in my organisation a tool to check for typos and 'forgotten' variables due to incomplete refactoring. I continued, where GroovyLint stopped. I tried enhancing GroovyLint on this topic, but at some point I got non-debuggable ClassNotFound-exceptions and went over to CodeNarc. At this point I also discovered the differences in completeness of the AST tree between GroovyLint and CodeNarc (mainly because of the different compile stage). I also though about using Groovy++ for that task, but at this point G++ has a different semantic than original Groovy wrt. scope in closures and maybe elsewhere too. Anyway, that is my goal for giving Java programmers a smooth transition to Groovy. You might argue, that CodeNarc is not the right tool. IntelliJ would be an alternative, since it identifies these variables as well, but I miss the reporting capability over a code base. Btw. a topic for a side-discussion at GR-8 in Copenhagen?! Best regards, klaus. On Wed, Apr 13, 2011 at 9:15 PM, Hamlet DArcy <ham...@ca...> wrote: > CodeNarc runs in a fairly early compiler phase. We do this so that you don't need to have the project's compiled class files on the classpath... you can still run CodeNarc even if your build/code is broken! On the negative side, that means a lot of type information is missing. Be careful when referencing types because any non-JDK types may not exist at the time you run CodeNarc. > > Do you have a simple example of the source the shows Object as the parent class with the missing inheritence problem? SOmething like > {code} > class A {} > class B extends A {} > class C extends B {} > {code} > Or something simple like that? > > ALso, I'd love to hear the specifics of the rule. Perhaps I can quickly write it for you, that way we can include it in the base product rather than leave it to something for you to maintain. (just a thought) > > > ----- Original Message ----- >> I'm trying to build a rather complex rule based on information also >> kept in the super class of a classnode. I made several observations: >> 1. The class hierarchy seems broken with some classes. That is, >> walking up along the superClass members I see java.lang.Object too >> soon >> 2. Not all fields of a class are visible in the classNode. >> >> I've built a rule based on the AbstractAstVisitor and overloaded >> multiple visit* methods, such as visitClassEx and >> visitConstructorOrMethodEx. >> >> For the incomplete fields information I suspect the threaded >> execution >> of the rules against the fileset. But why some superClass info is >> missing I cannot explain. >> >> Any idea, what goes wrong here? >> >> Regards, >> klaus. >> >> ------------------------------------------------------------------------------ >> Forrester Wave Report - Recovery time is now measured in hours and >> minutes >> not days. Key insights are discussed in the 2010 Forrester Wave >> Report as >> part of an in-depth evaluation of disaster recovery service >> providers. >> Forrester found the best-in-class provider in terms of services and >> vision. >> Read this report now! http://p.sf.net/sfu/ibm-webcastpromo >> _______________________________________________ >> Codenarc-user mailing list >> Cod...@li... >> https://lists.sourceforge.net/lists/listinfo/codenarc-user >> > |