Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[android] Check AppCompatActivity classes with CallSuperFirst and CallSuperLast rules #171

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions pmd-java/src/main/resources/rulesets/java/android.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ To get better results, make sure that the auxclasspath is defined for type resol
(BlockStatement[1]/Statement/StatementExpression/PrimaryExpression[./PrimaryPrefix[@SuperModifier='true']]/PrimarySuffix[@Image= ancestor::MethodDeclaration/MethodDeclarator/@Image]))]
[ancestor::ClassOrInterfaceDeclaration[ExtendsList/ClassOrInterfaceType[
typeof(@Image, 'android.app.Activity', 'Activity') or
typeof(@Image, 'android.support.v7.app.AppCompatActivity', 'AppCompatActivity') or
typeof(@Image, 'android.app.Application', 'Application') or
typeof(@Image, 'android.app.Service', 'Service')
]]]
Expand Down Expand Up @@ -74,6 +75,7 @@ public class DummyActivity extends Activity {
[not(Statement/StatementExpression/PrimaryExpression[./PrimaryPrefix[@SuperModifier='true']]/PrimarySuffix[@Image= ancestor::MethodDeclaration/MethodDeclarator/@Image])]
[ancestor::ClassOrInterfaceDeclaration[ExtendsList/ClassOrInterfaceType[
typeof(@Image, 'android.app.Activity', 'Activity') or
typeof(@Image, 'android.support.v7.app.AppCompatActivity', 'AppCompatActivity') or
typeof(@Image, 'android.app.Application', 'Application') or
typeof(@Image, 'android.app.Service', 'Service')
]]]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,35 @@ public class NotAnActivity {
protected void onResume() {
doSomething();
}
}
]]></code>
</test-code>
<test-code>
<description><![CDATA[
Success
]]></description>
<expected-problems>0</expected-problems>
<code><![CDATA[
public class MyActivity extends AppCompatActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
foo();
}
}
]]></code>
</test-code>
<test-code>
<description><![CDATA[
Failure
]]></description>
<expected-problems>1</expected-problems>
<code><![CDATA[
public class MyActivity extends AppCompatActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
foo();
}
}
]]></code>
</test-code>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,35 @@ public class NotAnActivity {
protected void onPause() {
doSomething();
}
}
]]></code>
</test-code>
<test-code>
<description><![CDATA[
Success
]]></description>
<expected-problems>0</expected-problems>
<code><![CDATA[
public class MyActivity extends AppCompatActivity {
@Override
protected void onDestroy() {
foo();
super.onDestroy();
}
}
]]></code>
</test-code>
<test-code>
<description><![CDATA[
Failure
]]></description>
<expected-problems>1</expected-problems>
<code><![CDATA[
public class MyActivity extends AppCompatActivity {
@Override
protected void onDestroy() {
foo();
}
}
]]></code>
</test-code>
Expand Down