Enhanced unnecessary/UselessParentheses with tests from controversial/UnnecessaryParentheses
This commit is contained in:
@ -226,9 +226,14 @@ public class Test {
|
|||||||
<property name="xpath">
|
<property name="xpath">
|
||||||
<value>
|
<value>
|
||||||
<![CDATA[
|
<![CDATA[
|
||||||
//Expression/PrimaryExpression/PrimaryPrefix/Expression
|
//Expression[not(parent::PrimaryPrefix)]/PrimaryExpression[count(*)>1]
|
||||||
[count(*)=1][count(./CastExpression)=0][count(./ConditionalExpression[@Ternary='true'])=0]
|
/PrimaryPrefix/Expression
|
||||||
[not(./AdditiveExpression[//Literal[@StringLiteral='true']])]
|
[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[
|
//Expression/ConditionalAndExpression/PrimaryExpression/PrimaryPrefix/Expression[
|
||||||
count(*)=1 and
|
count(*)=1 and
|
||||||
@ -239,16 +244,17 @@ public class Test {
|
|||||||
|
|
|
|
||||||
//Expression/ConditionalOrExpression/PrimaryExpression/PrimaryPrefix/Expression[
|
//Expression/ConditionalOrExpression/PrimaryExpression/PrimaryPrefix/Expression[
|
||||||
count(*)=1 and
|
count(*)=1 and
|
||||||
count(./CastExpression)=0 and
|
not(./CastExpression) and
|
||||||
count(./ConditionalExpression[@Ternary='true'])=0 and
|
not(./ConditionalExpression[@Ternary='true']) and
|
||||||
count(./EqualityExpression/MultiplicativeExpression)=0]
|
not(./EqualityExpression/MultiplicativeExpression)]
|
||||||
|
|
|
|
||||||
//Expression/ConditionalExpression/PrimaryExpression/PrimaryPrefix/Expression[
|
//Expression/ConditionalExpression/PrimaryExpression/PrimaryPrefix/Expression[
|
||||||
count(*)=1 and
|
count(*)=1 and
|
||||||
count(./CastExpression)=0 and
|
not(./CastExpression) and
|
||||||
count(./EqualityExpression)=0]
|
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
|
count(*)=1 and
|
||||||
not(./CastExpression) and
|
not(./CastExpression) and
|
||||||
not(./AdditiveExpression[@Image = '-']) and
|
not(./AdditiveExpression[@Image = '-']) and
|
||||||
@ -265,14 +271,14 @@ public class Test {
|
|||||||
|
|
|
|
||||||
//Expression/EqualityExpression/PrimaryExpression/PrimaryPrefix/Expression[
|
//Expression/EqualityExpression/PrimaryExpression/PrimaryPrefix/Expression[
|
||||||
count(*)=1 and
|
count(*)=1 and
|
||||||
count(./CastExpression)=0 and
|
not(./CastExpression) and
|
||||||
count(./AndExpression)=0 and
|
not(./AndExpression) and
|
||||||
count(./InclusiveOrExpression)=0 and
|
not(./InclusiveOrExpression) and
|
||||||
count(./ExclusiveOrExpression)=0 and
|
not(./ExclusiveOrExpression) and
|
||||||
count(./ConditionalExpression)=0 and
|
not(./ConditionalExpression) and
|
||||||
count(./ConditionalAndExpression)=0 and
|
not(./ConditionalAndExpression) and
|
||||||
count(./ConditionalOrExpression)=0 and
|
not(./ConditionalOrExpression) and
|
||||||
count(./EqualityExpression)=0]
|
not(./EqualityExpression)]
|
||||||
]]>
|
]]>
|
||||||
</value>
|
</value>
|
||||||
</property>
|
</property>
|
||||||
|
@ -370,4 +370,81 @@ public class Useless {
|
|||||||
}
|
}
|
||||||
]]></code>
|
]]></code>
|
||||||
</test-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>
|
</test-data>
|
||||||
|
Reference in New Issue
Block a user