Forbid static method call

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Forbid static method call

Leif Bladt (Inxmail GmbH)
Hi,

I wonder if I can forbid the call of some specific static methods, like the JOptionPane.show... methods. I tried it with the IllegalToken check, but I couldn't manage to get it filtered on the needed method names. In fact it warned me about every single method call in the project :)

<module name="IllegalToken">
        <property name="tokens" value="METHOD_CALL"/>
</module>

The DescendantToken check also didn't work. So is there as possibility I've overseen to get it done?


Tahnks for your help,
Leif


--
Software Developer

------------------------------------------------------

Inxmail GmbH
Wentzingerstr. 21, 79106 Freiburg, Germany
Tel: +49 761 296979-0, Fax: -9
[hidden email], www.inxmail.de


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Checkstyle-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/checkstyle-user
Reply | Threaded
Open this post in threaded view
|

Re: Forbid static method call

Romain PELISSE-3
Hi,

I think you can do this more easily using PMD (and writing an XPath rule) (http://pmd.sourceforge.net).

On Thu, Nov 26, 2009 at 04:44:39PM +0100, Leif Bladt (Inxmail GmbH) wrote:

> Hi,
>
> I wonder if I can forbid the call of some specific static methods, like the JOptionPane.show... methods. I tried it with the IllegalToken check, but I couldn't manage to get it filtered on the needed method names. In fact it warned me about every single method call in the project :)
>
> <module name="IllegalToken">
> <property name="tokens" value="METHOD_CALL"/>
> </module>
>
> The DescendantToken check also didn't work. So is there as possibility I've overseen to get it done?
>
>
> Tahnks for your help,
> Leif
>
>
> --
> Software Developer
>
> ------------------------------------------------------
>
> Inxmail GmbH
> Wentzingerstr. 21, 79106 Freiburg, Germany
> Tel: +49 761 296979-0, Fax: -9
> [hidden email], www.inxmail.de
>
>
> ------------------------------------------------------------------------------
> Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
> trial. Simplify your report design, integration and deployment - and focus on
> what you do best, core application coding. Discover what's new with
> Crystal Reports now.  http://p.sf.net/sfu/bobj-july
> _______________________________________________
> Checkstyle-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/checkstyle-user
>

--
Cordialement,
06.20.55.46.25
Romain PELISSE - Architecte Open Source chez Atos Origin

   Développement durable, anticipons pour notre avenir / Sustainibility,
   advance our future
   Préservons l'environnement, n'imprimez ce mail que si nécessaire /
   please consider your environmental responsibility before printing this
   e-mail.
   Ce message et les pièces jointes sont confidentiels et réservés à
   l'usage exclusif de ses destinataires. Il peut également être protégé
   par le secret professionnel. Si vous recevez ce message par erreur, merci
   d'en avertir immédiatement l'expéditeur et de le détruire.
   L'intégrité du message ne pouvant être assurée sur Internet, la
   responsabilité du groupe Atos Origin ne pourra être recherchée quant au
   contenu de ce message. Bien que les meilleurs efforts soient faits pour
   maintenir cette transmission exempte de tout virus, l'expéditeur ne donne
   aucune garantie à cet égard et sa responsabilité ne saurait être
   recherchée pour tout dommage résultant d'un virus transmis.

   This e-mail and the documents attached are confidential and intended
   solely for the addressee; it may also be privileged. If you receive this
   e-mail in error, please notify the sender immediately and destroy it. As
   its integrity cannot be secured on the Internet, the Atos Origin group
   liability cannot be triggered for the message content. Although the sender
   endeavours to maintain a computer virus-free network, the sender does not
   warrant that this transmission is virus-free and will not be liable for
   any damages resulting from any virus transmitted.

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Checkstyle-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/checkstyle-user
Reply | Threaded
Open this post in threaded view
|

Re: Forbid static method call

Niels Stargardt-2
In reply to this post by Leif Bladt (Inxmail GmbH)
Hi
Am 26.11.2009 16:44, Leif Bladt (Inxmail GmbH) schrieb:

> Hi,
>
> I wonder if I can forbid the call of some specific static methods, like the JOptionPane.show... methods. I tried it with the IllegalToken check, but I couldn't manage to get it filtered on the needed method names. In fact it warned me about every single method call in the project :)
>
> <module name="IllegalToken">
> <property name="tokens" value="METHOD_CALL"/>
> </module>
>
> The DescendantToken check also didn't work. So is there as possibility I've overseen to get it done?
>
>
> Tahnks for your help,
> Leif
why you don't use the regexp-check?

Regards
Niels

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Checkstyle-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/checkstyle-user
Reply | Threaded
Open this post in threaded view
|

Re: Forbid static method call

Leif Bladt (Inxmail GmbH)
Hi,

Am 26.11.2009 um 19:39 schrieb Niels Stargardt:
> Hi
> Am 26.11.2009 16:44, Leif Bladt (Inxmail GmbH) schrieb:
>> Hi,
>>
>> I wonder if I can forbid the call of some specific static methods, like the JOptionPane.show... methods. I tried it with the IllegalToken check, but I couldn't manage to get it filtered on the needed method names. In fact it warned me about every single method call in the project :)
> why you don't use the regexp-check?
Good idea, but these calls can span across several lines, so at least the RegexpMultiline is needed. And to operate so low-level on a text-file makes it hard to ignore comments (all different flavors) in java files. So I think it's very hard to make this check robust with "pure" regular expressions.

--
Software Developer

------------------------------------------------------

Inxmail GmbH
Wentzingerstr. 21, 79106 Freiburg, Germany
Tel: +49 761 296979-0, Fax: -9
[hidden email], www.inxmail.de


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Checkstyle-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/checkstyle-user
Reply | Threaded
Open this post in threaded view
|

Re: Forbid static method call

Niels Stargardt-2
In reply to this post by Leif Bladt (Inxmail GmbH)
Am 26.11.2009 16:44, Leif Bladt (Inxmail GmbH) schrieb:

> Hi,
>
> I wonder if I can forbid the call of some specific static methods, like the JOptionPane.show... methods. I tried it with the IllegalToken check, but I couldn't manage to get it filtered on the needed method names. In fact it warned me about every single method call in the project :)
>
> <module name="IllegalToken">
> <property name="tokens" value="METHOD_CALL"/>
> </module>
>
> The DescendantToken check also didn't work. So is there as possibility I've overseen to get it done?
>
>
> Tahnks for your help,
> Leif
>
>
Hi at least I would assert that you must set the format option, but I'm
not familiar with the check.

Regards
Niels

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Checkstyle-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/checkstyle-user
Reply | Threaded
Open this post in threaded view
|

Re: Forbid static method call

Leif Bladt (Inxmail GmbH)
Hi Niels,

Am 27.11.2009 um 09:20 schrieb Niels Stargardt:
> Hi at least I would assert that you must set the format option, but I'm
> not familiar with the check.

The IllegalToken has no format property, though the IllegalTokenText has it. I also tried it with the IllegalTokenText check, but with no success. I couldn't figure out, how the format string has to be defined to filter METHOD_CALL tokens.


Leif

--
Software Developer

------------------------------------------------------

Inxmail GmbH
Wentzingerstr. 21, 79106 Freiburg, Germany
Tel: +49 761 296979-0, Fax: -9
[hidden email], www.inxmail.de
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Checkstyle-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/checkstyle-user
Reply | Threaded
Open this post in threaded view
|

Re: Forbid static method call

Oliver Burn
Your best bet if you want a 100% reliable way of preventing calls to certain static methods is to use PMD as this tool provides access to the type information that is required.

On Fri, Nov 27, 2009 at 19:39, Leif Bladt (Inxmail GmbH) <[hidden email]> wrote:
Hi Niels,

Am 27.11.2009 um 09:20 schrieb Niels Stargardt:
> Hi at least I would assert that you must set the format option, but I'm
> not familiar with the check.

The IllegalToken has no format property, though the IllegalTokenText has it. I also tried it with the IllegalTokenText check, but with no success. I couldn't figure out, how the format string has to be defined to filter METHOD_CALL tokens.


Leif

--
Software Developer

------------------------------------------------------

Inxmail GmbH
Wentzingerstr. 21, 79106 Freiburg, Germany
Tel: +49 761 296979-0, Fax: -9
[hidden email], www.inxmail.de
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Checkstyle-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/checkstyle-user


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Checkstyle-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/checkstyle-user
Reply | Threaded
Open this post in threaded view
|

Re: Forbid static method call

Leif Bladt (Inxmail GmbH)
Hi Oliver and Romain,

> Your best bet if you want a 100% reliable way of preventing calls to certain static methods is to use PMD as this tool provides access to the type information that is required.
Works like a charm. Thanks a lot!


Leif

--
Software Developer

------------------------------------------------------

Inxmail GmbH
Wentzingerstr. 21, 79106 Freiburg, Germany
Tel: +49 761 296979-0, Fax: -9
[hidden email], www.inxmail.de


------------------------------------------------------------------------------
Join us December 9, 2009 for the Red Hat Virtual Experience,
a free event focused on virtualization and cloud computing.
Attend in-depth sessions from your desk. Your couch. Anywhere.
http://p.sf.net/sfu/redhat-sfdev2dev
_______________________________________________
Checkstyle-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/checkstyle-user