corrected false MagicNumberCheck errors for interfaces (bug 745941)
MagicNumberCheck now checks array initializers. (request 745949)
This commit is contained in:
parent
4628bc229d
commit
e8ad93aea6
|
|
@ -61,6 +61,10 @@
|
|||
<li class="body">Added check for trailing comma in array
|
||||
initialization. (module ArrayTrailingComma, request
|
||||
696301)</li>
|
||||
|
||||
<li class="body">MagicNumberCheck now checks array initializers. (request
|
||||
745949)</li>
|
||||
|
||||
</ul>
|
||||
|
||||
<p class="body">
|
||||
|
|
@ -75,6 +79,9 @@
|
|||
<li class="body">Typo in HideUtilityClassConstructor description (bug
|
||||
743973)</li>
|
||||
|
||||
<li class="body">False MagicNumberCheck errors for interfaces (bug
|
||||
745941)</li>
|
||||
|
||||
</ul>
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ package com.puppycrawl.tools.checkstyle.checks;
|
|||
|
||||
import com.puppycrawl.tools.checkstyle.api.Check;
|
||||
import com.puppycrawl.tools.checkstyle.api.DetailAST;
|
||||
import com.puppycrawl.tools.checkstyle.api.ScopeUtils;
|
||||
import com.puppycrawl.tools.checkstyle.api.TokenTypes;
|
||||
import java.util.Arrays;
|
||||
|
||||
|
|
@ -141,6 +142,9 @@ public class MagicNumberCheck extends Check
|
|||
*/
|
||||
private boolean isConstantDefinition(DetailAST aAST)
|
||||
{
|
||||
if (ScopeUtils.inInterfaceBlock(aAST)) {
|
||||
return true;
|
||||
}
|
||||
DetailAST parent = aAST.getParent();
|
||||
|
||||
//expression?
|
||||
|
|
@ -148,8 +152,13 @@ public class MagicNumberCheck extends Check
|
|||
return false;
|
||||
}
|
||||
|
||||
//assignment?
|
||||
//array init?
|
||||
parent = parent.getParent();
|
||||
if ((parent != null) && (parent.getType() == TokenTypes.ARRAY_INIT)) {
|
||||
parent = parent.getParent();
|
||||
}
|
||||
|
||||
//assignment?
|
||||
if ((parent == null) || (parent.getType() != TokenTypes.ASSIGN)) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -72,3 +72,16 @@ public class InputMagicNumber {
|
|||
long longHexVar17 = 0X11l;
|
||||
}
|
||||
}
|
||||
|
||||
interface Blah
|
||||
{
|
||||
int LOW = 5;
|
||||
int HIGH = 78;
|
||||
}
|
||||
|
||||
class ArrayMagicTest
|
||||
{
|
||||
private static final int[] NONMAGIC = {3};
|
||||
private int[] magic = {3};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ public class MagicNumberCheckTest
|
|||
"69:24: '0X011' is a magic number.",
|
||||
"71:29: '0x10L' is a magic number.",
|
||||
"72:29: '0X11l' is a magic number.",
|
||||
"85:28: '3' is a magic number.",
|
||||
};
|
||||
verify(checkConfig, getPath("InputMagicNumber.java"), expected);
|
||||
}
|
||||
|
|
@ -110,6 +111,7 @@ public class MagicNumberCheckTest
|
|||
"70:28: '0x0L' is a magic number.",
|
||||
"71:29: '0x10L' is a magic number.",
|
||||
"72:29: '0X11l' is a magic number.",
|
||||
"85:28: '3' is a magic number.",
|
||||
};
|
||||
verify(checkConfig, getPath("InputMagicNumber.java"), expected);
|
||||
}
|
||||
|
|
@ -139,6 +141,7 @@ public class MagicNumberCheckTest
|
|||
"69:24: '0X011' is a magic number.",
|
||||
"71:29: '0x10L' is a magic number.",
|
||||
"72:29: '0X11l' is a magic number.",
|
||||
"85:28: '3' is a magic number.",
|
||||
};
|
||||
verify(checkConfig, getPath("InputMagicNumber.java"), expected);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue