Re: Checkstyle Custom rule fails to instantiate

"Mark Tymieniecki" <[email protected]> Wed, 1 Feb 2012 09:18:33 -0000
Newsgroups gmane.comp.java.audit.checkstyle.user
Message-ID <[email protected]>
Hi Lars,

Yes I had a thought about this as well so the extension jar is in the same
folder as checkstyle-5.5-all.jar and this is declared on CLASSPATH

Regards

-----Original Message-----
From: Lars K=F6dderitzsch [mailto:[email protected]] =

Sent: 31 January 2012 18:03
To: [email protected]
Subject: Re: [Checkstyle-user] Checkstyle Custom rule fails to instantiate

Hi again,

packaging the dtd is not necessary, and there are also no other xml files to
take care of.

Only thing that would come to mind to re-check, is whether your extension
jar is on Checkstyle's execution classpath.
Depending on your means of invoking Checkstyle (command line, ant, maven,
eclipse-cs plugin...) this may vary...

BR,
Lars

Am 31.01.2012 10:57, schrieb Mark Tymieniecki:
> Hi Lars,
>
> I have indeed packaged my check as described even trying both dtd1.0 =

> and
> dtd1.3 so as to match the main rules xml file.
> Is there any other XML file that may need 'modifying' ?
>
> REgards
>
> -----Original Message-----
> From: Mark Tymieniecki [mailto:[email protected]]
> Sent: 30 January 2012 20:30
> To: [email protected]
> Subject: Re: [Checkstyle-user] Checkstyle Custom rule fails to =

> instantiate
>
> Hi Lars,
>
> Sadly yes, but I will double check to ensure it is in the root path
>
> -----Original Message-----
> From: Lars K=F6dderitzsch [mailto:[email protected]]
> Sent: 30 January 2012 19:04
> To: [email protected]
> Subject: Re: [Checkstyle-user] Checkstyle Custom rule fails to =

> instantiate
>
> Have you tried packaging your package.xml within your extension jar as =

> described here:
> http://checkstyle.sourceforge.net/config.html#Packages
> ?
>
> HTH, Lars
>
>
> Am 29.01.2012 17:42, schrieb tymieniecki:
>> package softquatrachecks;
>>
>> import com.puppycrawl.tools.checkstyle.api.Check;
>> import com.puppycrawl.tools.checkstyle.api.DetailAST;
>> import com.puppycrawl.tools.checkstyle.api.FullIdent;
>> import com.puppycrawl.tools.checkstyle.api.TokenTypes;
>> import com.puppycrawl.tools.checkstyle.checks.CheckUtils;
>>
>> /**
>>    *
>>    *
>>    * This package provides the custom checks that were required outside
>>    * of the standard checks provided
>>    *
>>    */
>> public class LoggerAttrCheck extends Check {
>> 	 /**
>>        *
>>        * Indicator 7: Logging Mechanisms
>>        *
>>        * The Logger must be declared as a static final class attribute
>>        *
>>        */
>>       @Override
>>       public int[] getDefaultTokens()
>>       {
>>           return new int[] {
>>               TokenTypes.VARIABLE_DEF
>>           };
>>       }
>>
>>       @Override
>>       public void visitToken(DetailAST aAST)
>>       {
>> 		=

>>       	if(aAST.getType()=3D=3DTokenTypes.VARIABLE_DEF)
>>       	     visitVariableDef(aAST);
>>
>>       }
>>       /**
>>        * Checks type of given variable.
>>        * @param aAST variable to check.
>>        */
>>       private void visitVariableDef(DetailAST aAST)
>>       {
>>           checkVariableDefn(aAST);
>>       }
>>
>>       /**
>>        *
>>        * Checks variable to see if its a Logger and static final
>>        *      * @param aAST node to check.
>>        */
>>       private void checkVariableDefn(DetailAST aAST)
>>       {
>>           final DetailAST type =3D aAST.findFirstToken(TokenTypes.TYPE);
>>           final FullIdent ident =3D CheckUtils.createFullType(type);
>>           if ((ident.getText().equals("Logger"))) {
>>
>>
> if((!aAST.branchContains(TokenTypes.FINAL))||(!aAST.branchContains(Tok
> enType
> s.LITERAL_STATIC)))
>> 			{
>>      			 log(type.getLineNo(), type.getColumnNo(),
>>        		        "Logger not defined as static final class
> attribute",
>> type.getText());
>> 			}
>>           }
>>       }
>>
>> }
>> When the rule is processed I get the message:
>> "Unable to create Checker: cannot initialize module TreeWalker - =

>> Unable to instantiate LoggerAttr"
>>
>> Now my checkstyle_packages.xml file in che checkstyle-5.5 folder is  :
>> <?xml version=3D"1.0" encoding=3D"UTF-8"?>
>>
>>       <!DOCTYPE checkstyle-packages PUBLIC
>>       &quot;-//Puppy Crawl//DTD Package Names 1.0//EN&quot;
>>       &quot;http://www.puppycrawl.com/dtds/packages_1_0.dtd&quot;>
>>
>> <checkstyle-packages>
>>     <package name=3D"softquatrachecks"/> </checkstyle-packages>
>>
>> Any Ideas folks
>>
>>
>> --
>> View this message in context:
>> http://checkstyle.2069334.n4.nabble.com/Checkstyle-Custom-rule-fails-
>> t
>> o-instantiate-tp4338632p4338632.html
>> Sent from the CheckStyle - User mailing list archive at Nabble.com.
>>
>> ---------------------------------------------------------------------
>> -
>> -------- Try before you buy =3D See our experts in action!
>> The most comprehensive online learning library for Microsoft =

>> developers is just $99.99! Visual Studio, SharePoint, SQL - plus =

>> HTML5, CSS3, MVC3, Metro Style Apps, more. Free future releases when =

>> you
> subscribe now!
>> http://p.sf.net/sfu/learndevnow-dev2
>> _______________________________________________
>> Checkstyle-user mailing list
>> [email protected]
>> https://lists.sourceforge.net/lists/listinfo/checkstyle-user
>>
>
> ----------------------------------------------------------------------
> ------
> --
> Try before you buy =3D See our experts in action!
> The most comprehensive online learning library for Microsoft =

> developers is just $99.99! Visual Studio, SharePoint, SQL - plus =

> HTML5, CSS3, MVC3, Metro Style Apps, more. Free future releases when you
subscribe now!
> http://p.sf.net/sfu/learndevnow-dev2
> _______________________________________________
> Checkstyle-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/checkstyle-user
>
>
> ----------------------------------------------------------------------
> ------
> --
> Try before you buy =3D See our experts in action!
> The most comprehensive online learning library for Microsoft =

> developers is just $99.99! Visual Studio, SharePoint, SQL - plus =

> HTML5, CSS3, MVC3, Metro Style Apps, more. Free future releases when you
subscribe now!
> http://p.sf.net/sfu/learndevnow-dev2
> _______________________________________________
> Checkstyle-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/checkstyle-user
>
>
> ----------------------------------------------------------------------
> -------- Keep Your Developer Skills Current with LearnDevNow!
> The most comprehensive online learning library for Microsoft =

> developers is just $99.99! Visual Studio, SharePoint, SQL - plus =

> HTML5, CSS3, MVC3, Metro Style Apps, more. Free future releases when you
subscribe now!
> http://p.sf.net/sfu/learndevnow-d2d
> _______________________________________________
> Checkstyle-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/checkstyle-user
>


----------------------------------------------------------------------------
--
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers is
just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3, Metro
Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
Checkstyle-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/checkstyle-user


---------------------------------------------------------------------------=
---
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d