From b5a90924a7af789247999a2d8bc1353c8e7c78aa Mon Sep 17 00:00:00 2001 From: Xavier Le Vourch Date: Wed, 4 Feb 2009 23:50:51 +0000 Subject: [PATCH] CallSuperFirst android rule now accepts logging before call to super() git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/branches/pmd/4.2.x@6812 51baf565-9d33-0410-a72c-fc3788e3496d --- .../pmd/rules/android/xml/CallSuperFirst.xml | 28 +++++++++++++++++++ pmd/rulesets/android.xml | 26 ++++++++++------- 2 files changed, 44 insertions(+), 10 deletions(-) diff --git a/pmd/regress/test/net/sourceforge/pmd/rules/android/xml/CallSuperFirst.xml b/pmd/regress/test/net/sourceforge/pmd/rules/android/xml/CallSuperFirst.xml index 9ae1745d31..38e490e56c 100644 --- a/pmd/regress/test/net/sourceforge/pmd/rules/android/xml/CallSuperFirst.xml +++ b/pmd/regress/test/net/sourceforge/pmd/rules/android/xml/CallSuperFirst.xml @@ -17,6 +17,34 @@ public class MyActivity extends Activity { + 0 + + + + 1 diff --git a/pmd/rulesets/android.xml b/pmd/rulesets/android.xml index c6c86b96be..f7450f3239 100644 --- a/pmd/rulesets/android.xml +++ b/pmd/rulesets/android.xml @@ -12,10 +12,10 @@ To get better results, make sure that the auxclasspath is defined for type resol - Super must be called at the start of the method + Super should be called at the start of the method 3 @@ -30,8 +30,14 @@ To get better results, make sure that the auxclasspath is defined for type resol @Image='onResume' or @Image='onStart' ]] - /Block/BlockStatement[1] - [not(Statement/StatementExpression/PrimaryExpression/PrimaryPrefix[@Image= ancestor::MethodDeclaration/MethodDeclarator/@Image])] + /Block[not( + (BlockStatement[1]/Statement/StatementExpression/PrimaryExpression/PrimaryPrefix[@Image= ancestor::MethodDeclaration/MethodDeclarator/@Image]) or + ((BlockStatement[1]/Statement/IfStatement/Expression[ + PrimaryExpression/PrimaryPrefix/Name[@Image='Config.LOGD' or @Image='Config.LOGV'] + or + ConditionalAndExpression/PrimaryExpression/PrimaryPrefix/Name[@Image='Config.LOGD' or @Image='Config.LOGV'] + ]) and + (BlockStatement[2]/Statement/StatementExpression/PrimaryExpression/PrimaryPrefix[@Image= ancestor::MethodDeclaration/MethodDeclarator/@Image])))] [ancestor::ClassOrInterfaceDeclaration[//ClassOrInterfaceType[ typeof(@Image, 'android.app.Activity', 'Activity') or typeof(@Image, 'android.app.Application', 'Application') or @@ -54,10 +60,10 @@ To get better results, make sure that the auxclasspath is defined for type resol - Super must be called at the end of the method + Super should be called at the end of the method 3 @@ -94,10 +100,10 @@ To get better results, make sure that the auxclasspath is defined for type resol - Log.d must be protected by checking Config.LOGD + Log.d calls should be protected by checking Config.LOGD first 3 @@ -129,10 +135,10 @@ To get better results, make sure that the auxclasspath is defined for type resol - Log.v must be protected by checking Config.LOGV + Log.v calls should be protected by checking Config.LOGV first 3