Improve MagicConstantInspection in case of two constants sources

This commit is contained in:
Vladislav Rassokhin
2017-02-14 18:38:48 +03:00
parent 8badcc8f56
commit 07b27a76a9
3 changed files with 77 additions and 64 deletions
@@ -14,7 +14,7 @@
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">magic constant</problem_class>
<description>Should be one of: Const.X, Const.Y, Const.Z</description>
<description>Should be one of: Const2.I, Const.X, Const.Y, Const.Z</description>
</problem>
@@ -26,7 +26,7 @@
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">magic constant</problem_class>
<description>Should be one of: Const.X, Const.Y, Const.Z</description>
<description>Should be one of: Const2.I, Const.X, Const.Y, Const.Z</description>
</problem>
@@ -38,7 +38,7 @@
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">magic constant</problem_class>
<description>Should be one of: Const.X, Const.Y, Const.Z</description>
<description>Should be one of: Const2.I, Const.X, Const.Y, Const.Z</description>
</problem>
@@ -50,7 +50,7 @@
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">magic constant</problem_class>
<description>Should be one of: Const.X, Const.Y, Const.Z</description>
<description>Should be one of: Const2.I, Const.X, Const.Y, Const.Z</description>
</problem>
@@ -62,7 +62,7 @@
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">magic constant</problem_class>
<description>Should be one of: Const.X, Const.Y, Const.Z</description>
<description>Should be one of: Const2.I, Const.X, Const.Y, Const.Z</description>
</problem>
@@ -74,7 +74,7 @@
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">magic constant</problem_class>
<description>Should be one of: Const.X, Const.Y, Const.Z</description>
<description>Should be one of: Const2.I, Const.X, Const.Y, Const.Z</description>
</problem>
@@ -86,7 +86,7 @@
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">magic constant</problem_class>
<description>Should be one of: Const.X, Const.Y, Const.Z</description>
<description>Should be one of: Const2.I, Const.X, Const.Y, Const.Z</description>
</problem>
@@ -98,7 +98,7 @@
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">magic constant</problem_class>
<description>Should be one of: Const.X, Const.Y, Const.Z</description>
<description>Should be one of: Const2.I, Const.X, Const.Y, Const.Z</description>
</problem>
@@ -110,7 +110,7 @@
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">magic constant</problem_class>
<description>Should be one of: Const.X, Const.Y, Const.Z</description>
<description>Should be one of: Const2.I, Const.X, Const.Y, Const.Z</description>
</problem>
@@ -122,7 +122,7 @@
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">magic constant</problem_class>
<description>Should be one of: Const.X, Const.Y, Const.Z</description>
<description>Should be one of: Const2.I, Const.X, Const.Y, Const.Z</description>
</problem>
@@ -134,7 +134,7 @@
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">magic constant</problem_class>
<description>Should be one of: Const.X, Const.Y, Const.Z</description>
<description>Should be one of: Const2.I, Const.X, Const.Y, Const.Z</description>
</problem>
@@ -146,7 +146,7 @@
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">magic constant</problem_class>
<description>Should be one of: Const.X, Const.Y, Const.Z</description>
<description>Should be one of: Const2.I, Const.X, Const.Y, Const.Z</description>
</problem>
@@ -158,7 +158,7 @@
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">magic constant</problem_class>
<description>Should be one of: Const.X, Const.Y, Const.Z</description>
<description>Should be one of: Const2.I, Const.X, Const.Y, Const.Z</description>
</problem>
@@ -170,7 +170,7 @@
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">magic constant</problem_class>
<description>Should be one of: Const.X, Const.Y, Const.Z</description>
<description>Should be one of: Const2.I, Const.X, Const.Y, Const.Z</description>
</problem>
@@ -178,7 +178,7 @@
<file>X.java</file>
<line>81</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">magic constant</problem_class>
<description>Should be one of: Const.X, Const.Y, Const.Z or their combination</description>
<description>Should be one of: Const2.I, Const.X, Const.Y, Const.Z or their combination</description>
</problem>
@@ -189,7 +189,7 @@
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">magic constant</problem_class>
<description>Should be one of: Const.X, Const.Y, Const.Z or their combination</description>
<description>Should be one of: Const2.I, Const.X, Const.Y, Const.Z or their combination</description>
</problem>
@@ -201,7 +201,7 @@
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">magic constant</problem_class>
<description>Should be one of: Const.X, Const.Y, Const.Z</description>
<description>Should be one of: Const2.I, Const.X, Const.Y, Const.Z</description>
</problem>
@@ -213,7 +213,7 @@
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">magic constant</problem_class>
<description>Should be one of: Const.X, Const.Y, Const.Z or their combination</description>
<description>Should be one of: Const2.I, Const.X, Const.Y, Const.Z or their combination</description>
</problem>
@@ -225,7 +225,7 @@
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">magic constant</problem_class>
<description>Should be one of: Const.X, Const.Y, Const.Z or their combination</description>
<description>Should be one of: Const2.I, Const.X, Const.Y, Const.Z or their combination</description>
</problem>
@@ -237,7 +237,7 @@
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">magic constant</problem_class>
<description>Should be one of: Const.X, Const.Y, Const.Z or their combination</description>
<description>Should be one of: Const2.I, Const.X, Const.Y, Const.Z or their combination</description>
</problem>
@@ -249,7 +249,7 @@
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">magic constant</problem_class>
<description>Should be one of: Const.X, Const.Y, Const.Z or their combination</description>
<description>Should be one of: Const2.I, Const.X, Const.Y, Const.Z or their combination</description>
</problem>
@@ -257,14 +257,14 @@
<file>X.java</file>
<line>118</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">magic constant</problem_class>
<description>Should be one of: Const.X, Const.Y, Const.Z or their combination</description>
<description>Should be one of: Const2.I, Const.X, Const.Y, Const.Z or their combination</description>
</problem>
<problem>
<file>X.java</file>
<line>119</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">magic constant</problem_class>
<description>Should be one of: Const.X, Const.Y, Const.Z or their combination</description>
<description>Should be one of: Const2.I, Const.X, Const.Y, Const.Z or their combination</description>
</problem>
@@ -276,7 +276,7 @@
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">magic constant</problem_class>
<description>Should be one of: Const.X, Const.Y, Const.Z or their combination</description>
<description>Should be one of: Const2.I, Const.X, Const.Y, Const.Z or their combination</description>
</problem>
@@ -288,7 +288,7 @@
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">magic constant</problem_class>
<description>Should be one of: Const.X, Const.Y, Const.Z or their combination</description>
<description>Should be one of: Const2.I, Const.X, Const.Y, Const.Z or their combination</description>
</problem>
@@ -300,7 +300,7 @@
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">magic constant</problem_class>
<description>Should be one of: Const.X, Const.Y, Const.Z or their combination</description>
<description>Should be one of: Const2.I, Const.X, Const.Y, Const.Z or their combination</description>
</problem>
@@ -312,7 +312,7 @@
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">magic constant</problem_class>
<description>Should be one of: Const.X, Const.Y, Const.Z or their combination</description>
<description>Should be one of: Const2.I, Const.X, Const.Y, Const.Z or their combination</description>
</problem>
@@ -322,7 +322,7 @@
<file>X.java</file>
<line>173</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">magic constant</problem_class>
<description>Should be one of: Const.X, Const.Y, Const.Z</description>
<description>Should be one of: Const2.I, Const.X, Const.Y, Const.Z</description>
</problem>
@@ -331,7 +331,7 @@
<file>X.java</file>
<line>174</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">magic constant</problem_class>
<description>Should be one of: Const.X, Const.Y, Const.Z</description>
<description>Should be one of: Const2.I, Const.X, Const.Y, Const.Z</description>
</problem>
@@ -340,7 +340,7 @@
<file>X.java</file>
<line>175</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">magic constant</problem_class>
<description>Should be one of: Const.X, Const.Y, Const.Z</description>
<description>Should be one of: Const2.I, Const.X, Const.Y, Const.Z</description>
</problem>
@@ -349,7 +349,7 @@
<file>X.java</file>
<line>177</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">magic constant</problem_class>
<description>Should be one of: Const.X, Const.Y, Const.Z</description>
<description>Should be one of: Const2.I, Const.X, Const.Y, Const.Z</description>
</problem>
@@ -357,7 +357,7 @@
<file>X.java</file>
<line>178</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">magic constant</problem_class>
<description>Should be one of: Const.X, Const.Y, Const.Z</description>
<description>Should be one of: Const2.I, Const.X, Const.Y, Const.Z</description>
</problem>
@@ -366,7 +366,7 @@
<file>X.java</file>
<line>179</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">magic constant</problem_class>
<description>Should be one of: Const.X, Const.Y, Const.Z</description>
<description>Should be one of: Const2.I, Const.X, Const.Y, Const.Z</description>
</problem>
@@ -375,7 +375,7 @@
<file>X.java</file>
<line>180</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">magic constant</problem_class>
<description>Should be one of: Const.X, Const.Y, Const.Z</description>
<description>Should be one of: Const2.I, Const.X, Const.Y, Const.Z</description>
</problem>
@@ -24,7 +24,7 @@ class Const {
}
public class X {
void f(@MagicConstant(intValues={Const.X, Const.Y, Const.Z}) int x) {
void f(@MagicConstant(intValues={Const.X, Const.Y, Const.Z, Const2.I}) int x) {
/////////// BAD
f(0);
f(1);
@@ -50,7 +50,7 @@ public class X {
f2(x);
}
void f2(@MagicConstant(valuesFromClass =Const.class) int x) {
void f2(@MagicConstant(valuesFromClass =Const.class, intValues={Const2.I}) int x) {
/////////// BAD
f2(0);
f2(1);
@@ -61,11 +61,11 @@ public class X {
x = 2;
assert x != 1;
}
////////////// GOOD
f2(Const.X);
f2(Const.Y);
f2(Const.Z);
f2(Const.Z);
f2(Const2.I);
int i2 = this == null ? Const.X : Const.Y;
f2(i2);
if (x == Const.X) {
@@ -76,7 +76,7 @@ public class X {
f(x);
}
void f3(@MagicConstant(flags ={Const.X, Const.Y, Const.Z}) int x) {
void f3(@MagicConstant(flags ={Const.X, Const.Y, Const.Z, Const2.I}) int x) {
/////////// BAD
f3(2);
f3(1);
@@ -113,7 +113,7 @@ public class X {
f4(x);
}
void f4(@MagicConstant(flagsFromClass =Const.class) int x) {
void f4(@MagicConstant(flagsFromClass =Const.class, flags={Const2.I}) int x) {
/////////// BAD
f4(-3);
f4(1);
@@ -128,8 +128,8 @@ public class X {
////////////// GOOD
f4(Const.X);
f4(Const.Y);
f4(Const.Z);
f4(Const.Z);
f4(Const2.I);
int i2 = this == null ? Const.X : Const.Y;
f4(i2);
int ix = Const.X | Const.Y;
@@ -152,7 +152,7 @@ public class X {
class Alias {
@MagicConstant(intValues={Const.X, Const.Y, Const.Z})
@MagicConstant(intValues={Const.X, Const.Y, Const.Z, Const2.I})
@interface IntEnum{}
void f(@IntEnum int x) {
@@ -268,3 +268,6 @@ public class X {
font(0);
}
}
class Const2 {
public static final int I = 0x10;
}