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
This commit is contained in:
@ -17,6 +17,34 @@ public class MyActivity extends Activity {
|
|||||||
</test-code>
|
</test-code>
|
||||||
<test-code>
|
<test-code>
|
||||||
<description><![CDATA[
|
<description><![CDATA[
|
||||||
|
Success, first statement is enclosed in Config.LOGD or LOGV
|
||||||
|
]]></description>
|
||||||
|
<expected-problems>0</expected-problems>
|
||||||
|
<code><![CDATA[
|
||||||
|
public class MyActivity extends Activity {
|
||||||
|
@Override
|
||||||
|
protected void onCreate(final Bundle state) {
|
||||||
|
if (Config.LOGD) { Log.d("Tag", "msg 1"); }
|
||||||
|
super.onCreate(state);
|
||||||
|
foo();
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
protected void onResume() {
|
||||||
|
if (Config.LOGV) { Log.v("Tag", "msg 1"); }
|
||||||
|
super.onResume();
|
||||||
|
foo();
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
protected void onStart() {
|
||||||
|
if (booleanValue && Config.LOGD) { Log.d("Tag", "msg 1"); }
|
||||||
|
super.onStart();
|
||||||
|
foo();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]]></code>
|
||||||
|
</test-code>
|
||||||
|
<test-code>
|
||||||
|
<description><![CDATA[
|
||||||
Failure
|
Failure
|
||||||
]]></description>
|
]]></description>
|
||||||
<expected-problems>1</expected-problems>
|
<expected-problems>1</expected-problems>
|
||||||
|
@ -12,10 +12,10 @@ To get better results, make sure that the auxclasspath is defined for type resol
|
|||||||
|
|
||||||
<rule name="CallSuperFirst"
|
<rule name="CallSuperFirst"
|
||||||
since="4.2.5"
|
since="4.2.5"
|
||||||
message="super must be called at the start of the method"
|
message="super should be called at the start of the method"
|
||||||
class="net.sourceforge.pmd.rules.XPathRule"
|
class="net.sourceforge.pmd.rules.XPathRule"
|
||||||
externalInfoUrl="http://pmd.sourceforge.net/rules/android.html#CallSuperFirst">
|
externalInfoUrl="http://pmd.sourceforge.net/rules/android.html#CallSuperFirst">
|
||||||
<description>Super must be called at the start of the method</description>
|
<description>Super should be called at the start of the method</description>
|
||||||
<priority>3</priority>
|
<priority>3</priority>
|
||||||
<properties>
|
<properties>
|
||||||
<property name="xpath">
|
<property name="xpath">
|
||||||
@ -30,8 +30,14 @@ To get better results, make sure that the auxclasspath is defined for type resol
|
|||||||
@Image='onResume' or
|
@Image='onResume' or
|
||||||
@Image='onStart'
|
@Image='onStart'
|
||||||
]]
|
]]
|
||||||
/Block/BlockStatement[1]
|
/Block[not(
|
||||||
[not(Statement/StatementExpression/PrimaryExpression/PrimaryPrefix[@Image= ancestor::MethodDeclaration/MethodDeclarator/@Image])]
|
(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[
|
[ancestor::ClassOrInterfaceDeclaration[//ClassOrInterfaceType[
|
||||||
typeof(@Image, 'android.app.Activity', 'Activity') or
|
typeof(@Image, 'android.app.Activity', 'Activity') or
|
||||||
typeof(@Image, 'android.app.Application', 'Application') 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
|
|||||||
|
|
||||||
<rule name="CallSuperLast"
|
<rule name="CallSuperLast"
|
||||||
since="4.2.5"
|
since="4.2.5"
|
||||||
message="super must be called at the end of the method"
|
message="super should be called at the end of the method"
|
||||||
class="net.sourceforge.pmd.rules.XPathRule"
|
class="net.sourceforge.pmd.rules.XPathRule"
|
||||||
externalInfoUrl="http://pmd.sourceforge.net/rules/android.html#CallSuperLast">
|
externalInfoUrl="http://pmd.sourceforge.net/rules/android.html#CallSuperLast">
|
||||||
<description>Super must be called at the end of the method</description>
|
<description>Super should be called at the end of the method</description>
|
||||||
<priority>3</priority>
|
<priority>3</priority>
|
||||||
<properties>
|
<properties>
|
||||||
<property name="xpath">
|
<property name="xpath">
|
||||||
@ -94,10 +100,10 @@ To get better results, make sure that the auxclasspath is defined for type resol
|
|||||||
</rule>
|
</rule>
|
||||||
|
|
||||||
<rule name="ProtectLogD" since="4.2.5"
|
<rule name="ProtectLogD" since="4.2.5"
|
||||||
message="Log.d must be protected by checking Config.LOGD"
|
message="Log.d calls should be protected by checking Config.LOGD first"
|
||||||
class="net.sourceforge.pmd.rules.XPathRule"
|
class="net.sourceforge.pmd.rules.XPathRule"
|
||||||
externalInfoUrl="http://pmd.sourceforge.net/rules/android.html#ProtectLogD">
|
externalInfoUrl="http://pmd.sourceforge.net/rules/android.html#ProtectLogD">
|
||||||
<description>Log.d must be protected by checking Config.LOGD</description>
|
<description>Log.d calls should be protected by checking Config.LOGD first</description>
|
||||||
<priority>3</priority>
|
<priority>3</priority>
|
||||||
<properties>
|
<properties>
|
||||||
<property name="xpath">
|
<property name="xpath">
|
||||||
@ -129,10 +135,10 @@ To get better results, make sure that the auxclasspath is defined for type resol
|
|||||||
</rule>
|
</rule>
|
||||||
|
|
||||||
<rule name="ProtectLogV" since="4.2.5"
|
<rule name="ProtectLogV" since="4.2.5"
|
||||||
message="Log.v must be protected by checking Config.LOGV"
|
message="Log.v calls should be protected by checking Config.LOGV first"
|
||||||
class="net.sourceforge.pmd.rules.XPathRule"
|
class="net.sourceforge.pmd.rules.XPathRule"
|
||||||
externalInfoUrl="http://pmd.sourceforge.net/rules/android.html#ProtectLogV">
|
externalInfoUrl="http://pmd.sourceforge.net/rules/android.html#ProtectLogV">
|
||||||
<description>Log.v must be protected by checking Config.LOGV</description>
|
<description>Log.v calls should be protected by checking Config.LOGV first</description>
|
||||||
<priority>3</priority>
|
<priority>3</priority>
|
||||||
<properties>
|
<properties>
|
||||||
<property name="xpath">
|
<property name="xpath">
|
||||||
|
Reference in New Issue
Block a user