Enhanced unnecessary/UselessParentheses with tests from controversial/UnnecessaryParentheses

This commit is contained in:
oowekyala
2017-08-16 14:31:52 +02:00
parent 69b32d4c00
commit a4dc70610b
2 changed files with 100 additions and 17 deletions

View File

@ -226,9 +226,14 @@ public class Test {
<property name="xpath">
<value>
<![CDATA[
//Expression/PrimaryExpression/PrimaryPrefix/Expression
[count(*)=1][count(./CastExpression)=0][count(./ConditionalExpression[@Ternary='true'])=0]
[not(./AdditiveExpression[//Literal[@StringLiteral='true']])]
//Expression[not(parent::PrimaryPrefix)]/PrimaryExpression[count(*)>1]
/PrimaryPrefix/Expression
[not(./CastExpression)]
[not(./ConditionalExpression[@Ternary='true'])]
[not(./AdditiveExpression[//Literal[@StringLiteral='true']])]
|
//Expression[not(parent::PrimaryPrefix)]/PrimaryExpression[count(*)=1]
/PrimaryPrefix/Expression
|
//Expression/ConditionalAndExpression/PrimaryExpression/PrimaryPrefix/Expression[
count(*)=1 and
@ -239,16 +244,17 @@ public class Test {
|
//Expression/ConditionalOrExpression/PrimaryExpression/PrimaryPrefix/Expression[
count(*)=1 and
count(./CastExpression)=0 and
count(./ConditionalExpression[@Ternary='true'])=0 and
count(./EqualityExpression/MultiplicativeExpression)=0]
not(./CastExpression) and
not(./ConditionalExpression[@Ternary='true']) and
not(./EqualityExpression/MultiplicativeExpression)]
|
//Expression/ConditionalExpression/PrimaryExpression/PrimaryPrefix/Expression[
count(*)=1 and
count(./CastExpression)=0 and
count(./EqualityExpression)=0]
not(./CastExpression) and
not(./EqualityExpression)]
|
//Expression/AdditiveExpression[not(./PrimaryExpression/PrimaryPrefix/Literal[@StringLiteral='true'])]/PrimaryExpression[1]/PrimaryPrefix/Expression[
//Expression/AdditiveExpression[not(./PrimaryExpression/PrimaryPrefix/Literal[@StringLiteral='true'])]
/PrimaryExpression[1]/PrimaryPrefix/Expression[
count(*)=1 and
not(./CastExpression) and
not(./AdditiveExpression[@Image = '-']) and
@ -265,14 +271,14 @@ public class Test {
|
//Expression/EqualityExpression/PrimaryExpression/PrimaryPrefix/Expression[
count(*)=1 and
count(./CastExpression)=0 and
count(./AndExpression)=0 and
count(./InclusiveOrExpression)=0 and
count(./ExclusiveOrExpression)=0 and
count(./ConditionalExpression)=0 and
count(./ConditionalAndExpression)=0 and
count(./ConditionalOrExpression)=0 and
count(./EqualityExpression)=0]
not(./CastExpression) and
not(./AndExpression) and
not(./InclusiveOrExpression) and
not(./ExclusiveOrExpression) and
not(./ConditionalExpression) and
not(./ConditionalAndExpression) and
not(./ConditionalOrExpression) and
not(./EqualityExpression)]
]]>
</value>
</property>

View File

@ -370,4 +370,81 @@ public class Useless {
}
]]></code>
</test-code>
<test-code>
<description>From controversial/UnnecessaryParentheses: Typecast</description>
<expected-problems>0</expected-problems>
<code><![CDATA[
public class Foo {
public void bar(Object o) {
return ((Exception) o).getMessage();
}
}
]]></code>
</test-code>
<test-code>
<description>From controversial/UnnecessaryParentheses: #537 Trivial case with additive expression</description>
<expected-problems>1</expected-problems>
<code><![CDATA[
public class Foo {
private String getData(final String header) {
String result = ("[" + header + ":" + Utils.decode(header) + "]");
return result;
}
}
]]></code>
</test-code>
<test-code>
<description>From controversial/UnnecessaryParentheses: #537 Trivial case with additive expression modified</description>
<expected-problems>0</expected-problems>
<code><![CDATA[
public class Foo {
private String getData(final String header) {
String result = ("[" + header + ":" + Utils.decode(header) + "]").foo();
return result;
}
}
]]></code>
</test-code>
<test-code>
<description>From controversial/UnnecessaryParentheses: Parentheses around cast</description>
<expected-problems>1</expected-problems>
<code><![CDATA[
public class Foo {
public void bar(Object o) {
return ((String) "doo");
}
}
]]></code>
</test-code>
<test-code>
<description>From controversial/UnnecessaryParentheses: Parentheses around call chain</description>
<expected-problems>1</expected-problems>
<code><![CDATA[
public class Foo {
public void bar(Object o) {
return (a.bar()).foo();
}
}
]]></code>
</test-code>
<test-code>
<description>From controversial/UnnecessaryParentheses: Unreported call chain</description>
<expected-problems>0</expected-problems>
<code><![CDATA[
public class Foo {
public void bar(Object o) {
return a.bar().foo();
}
}
]]></code>
</test-code>
</test-data>