Re: [Codenarc-developer] (no subject)
Brought to you by:
chrismair
From: Brian S. <bri...@ta...> - 2014-01-29 23:27:02
|
Hi Artur, Changing the phase worked with my test case to detect the interface once I started using AstUtil.classNodeImplementsType for the check. The outstanding question I had was whether I could skip doing the grails import of org.codehaus.groovy.grails.commons.GrailsDomainClass by declaring a simple GrailsDomainClass interface in the rule and checking for that. It looks like some of the checks done by AstUtil.classNodeImplementsType may match on simple class name while omitting the package name, which presumably would work. The other problem I ran into was how to run my custom CodeNarc rules in the grails codenarc plugin. Any ideas here? I see comments saying it's not trivially done. Thanks -Brian Soby On Wed, Jan 29, 2014 at 2:06 PM, Artur Gajowy <art...@gm...>wrote: > Did you change your rule's compilerPhase to SEMANTIC_ANALYSIS or greater? > It should detect the GrailsDomainClass interface in your test, however I'm > not sure if it would detect the implicit interface implementation done by > Grails. > > Be aware of the limitations: > http://codenarc.sourceforge.net/codenarc-enhanced-classpath-rules.html > https://github.com/CodeNarc/CodeNarc/pull/27 > https://github.com/CodeNarc/CodeNarc/issues/29 > > If, however, you're ok with running CodeNarc as a test in your project, > the classpath problems won't affect you. On the other hand - CodeNarc users > running it without Grails classes on classpath won't be able to benefit > from the rule. > > If you decide to implement the rule - make sure you get the > GrailsDomainClass interface's package right and test it on a real project :) > > Best regards, > Artur Gajowy > > > On 29 January 2014 19:21, Brian Soby <bri...@ta...> wrote: > >> Hi all, >> >> I'm working on a mass assignment rule ( >> http://sourceforge.net/p/codenarc/feature-requests/392/) and I can't >> seem to get type or interface based detection to work. Here's my test code: >> >> public interface GrailsDomainClass {} >> class Person implements GrailsDomainClass { >> String name >> Boolean isAdmin >> } >> params = [name: 'John', isAdmin: true] >> def person = new Person(params) >> >> Ideally, I'd 1) visit the Person constructor 2) Check that it implements >> GrailsDomainClass 3) and check that the parameter implements java.util.Map. >> Unfortunately, getInterfaces()/getAllInterfaces() seems to always return an >> empty set. I've resorted to checking for a variable named "params" but that >> seems too fragile. Is there anything I can do to have more robust type and >> interface information available? >> >> Thanks >> -Brian Soby >> >> >> >> >> ------------------------------------------------------------------------------ >> WatchGuard Dimension instantly turns raw network data into actionable >> security intelligence. It gives you real-time visual feedback on key >> security issues and trends. Skip the complicated setup - simply import >> a virtual appliance and go from zero to informed in seconds. >> >> http://pubads.g.doubleclick.net/gampad/clk?id=123612991&iu=/4140/ostg.clktrk >> _______________________________________________ >> Codenarc-developer mailing list >> Cod...@li... >> https://lists.sourceforge.net/lists/listinfo/codenarc-developer >> >> > |