Menu

Avoid System.out.println

Anonymous
2004-03-31
2012-10-07
  • Anonymous

    Anonymous - 2004-03-31

    Hello!
    I am trying to write a rule that will make the programmers avoid using System.out.print
    This is what I have so far:

       <rule name="DontUseSyste.out.print" message="Do not use System.out.println, nobody likes those, specially Josh. Use the logger instead" class="net.sourceforge.pmd.rules.XPathRule" include="true">
            <description>  Do not use System.out.println      </description>
            <example><![CDATA[

    System.out.println // don't do this!

        ]]></example>
            <priority>1</priority>
            <properties>
                <property name="xpath">
                    <value><![CDATA[
                //AllocationExpression[Name/@Image='System.out.println'][not(ArrayDimsAndInits)]>
            ]]></value>
                </property>
            </properties>
        </rule>

    I am using eclipse 3.0. And theres is something wrong
    with that code.
    Anybody?
    Thanks.

     
    • Anonymous

      Anonymous - 2004-03-31

      Nevermind, I got it.

       
      • Tom Copeland

        Tom Copeland - 2004-04-01

        Hi Jorge -

        Sorry about the delay in replying - I was on vacation for a few days and we had an off-site yesterday, so I'm going through my email catching up with things now. 

        Glad you sorted it out, FWIW, I've been using a Java rule to catch these:

        =============
        public class SystemOutRule extends AbstractRule implements Rule {

            public Object visit(ASTName node, Object data){
                RuleContext ctx = (RuleContext)data;
                if (node.getImage() != null && (node.getImage().startsWith("System.out") || node.getImage().startsWith("System.err") || node.getImage().startsWith("System.in"))) {
                    ctx.getReport().addRuleViolation(createRuleViolation(ctx, node.getBeginLine()));
                }
                return super.visit(node,data);
            }
        }
        =============

        but if you got an XPath rule to work that's definitely an easier way to go...

        Yours,

        Tom

         
    • rg@work

      rg@work - 2004-07-26

      Hi Jorge

      I am also trying to write the same rule with XPath.

      Do you see anything wrong with the following rule?

      //Statement/StatementExpression/PrimaryExpression/PrimaryPrefix/Name[@Image='System.out.println']

      Could it be possible for you to post your rule.

      Thanks !!!

       
    • PravinD

      PravinD - 2005-03-02

      Could someone post the correct version of the XPath rule that throws a warning when it comes across a System.out.println statement?

      Thanks in advance!!!!

      Pravin. D

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.