[Codenarc-developer] FW: [ codenarc-Bugs-3155974 ] Unused* rules misses references within inner cla
Brought to you by:
chrismair
From: Chris M. <chr...@ea...> - 2011-02-25 01:40:24
|
Hamlet, I think the UnusedVariable rule still has this limitation. That test class even has a testApplyTo_VariableOnlyReferencedWithinInnerClass_Violation_KnownIssue() test method. Thanks a bunch for fixing these inner class issues! Chris -----Original Message----- From: SourceForge.net [mailto:no...@so...] Sent: Thursday, February 24, 2011 10:20 AM To: no...@so... Subject: [ codenarc-Bugs-3155974 ] Unused* rules misses references within inner classes Bugs item #3155974, was opened at 2011-01-11 19:29 Message generated for change (Comment added) made by hamletdrc You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=1126573&aid=3155974&group_id=250145 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: None Group: None >Status: Closed Resolution: None Priority: 5 Private: No Submitted By: Chris Mair (chrismair) Assigned to: Hamlet D'Arcy (hamletdrc) Summary: Unused* rules misses references within inner classes Initial Comment: This code: def buildCallable() { String ssn = 'xxx' return new Callable<Object>(){ public Object call(){ return participantDao.getParticipantPlans(ssn) } } } produces: Violation[rule=UnusedVariableRule[name=UnusedVariable, priority=2], lineNumber=3, sourceLine=String ssn = 'xxx', message=The variable [ssn] is not used] ---------------------------------------------------------------------- >Comment By: Hamlet D'Arcy (hamletdrc) Date: 2011-02-24 09:20 Message: fixed in 0.13 ---------------------------------------------------------------------- Comment By: Hamlet D'Arcy (hamletdrc) Date: 2011-02-23 15:35 Message: i fixed this for private methods and private fields. Have not finished with parameters yet. ---------------------------------------------------------------------- Comment By: Chris Mair (chrismair) Date: 2011-01-21 07:42 Message: Yes, let's leave it open and work towards a solution. ---------------------------------------------------------------------- Comment By: Hamlet D'Arcy (hamletdrc) Date: 2011-01-21 07:14 Message: Can we leave this open? The unused rules should all work with anonymous inner classes, no problems. For inner classes and nested classes, it is a little harder. But, we do have the getSourceUnit() method available to us, and we can actually see all the other classes defined in the SourceUnit. It's a matter of getting the other classes out of the SourceUnit, scanning them once to build up a list of referenced variables/methods/properties, and then walking each class once to see if there are private members not in the list. Need to make sure it works in this threaded environment too. This seems feasible to me. I say leave it open. ---------------------------------------------------------------------- Comment By: Chris Mair (chrismair) Date: 2011-01-20 19:54 Message: I have expanded the scope of this issue to include UnusedVariable, UnusedPrivateMethod, UnusedPrivateMethodParameter and UnusedPrivateField rules. They all suffer the same limitation, for the same reason. ---------------------------------------------------------------------- Comment By: Chris Mair (chrismair) Date: 2011-01-12 20:24 Message: Unfortunately, the AST does not give direct access to ClassNode for the inner class being defined from the point in the AST where it is defined. For example, in the code example above, the ReturnStatement contains a ConstructorCall, but provides no way to get at that inner ClassNode. Furthermore, CodeNarc is designed to analyze at the class-level, so it would take some pretty nasty contortions to get to it. So, for now, I am documenting it as a known limitation that the UnusedVariableRule cannot see references within inner classes. Keep in mind also, that anonymous inner classes can often be rewritten using closures (which work just fine with the UnusedVariable rule). ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=1126573&aid=3155974&group_id=250145 |