mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-89017 (Add "disable for annotations" checkbox for "Magic Number" inspection)
This commit is contained in:
@@ -354,6 +354,7 @@ string.concatenation.ignore.assert.option=Ignore for assert statement arguments
|
||||
string.concatenation.ignore.exceptions.option=Ignore for throwable arguments
|
||||
string.concatenation.ignore.constant.initializers.option=Ignore for initializers of constants
|
||||
ignore.in.test.code=Ignore in test code
|
||||
ignore.in.annotations=Ignore in annotations
|
||||
string.equalsignorecase.call.display.name=Call to 'String.equalsIgnoreCase()'
|
||||
string.equalsignorecase.call.problem.descriptor=<code>String.#ref()</code> using internationalized strings #loc
|
||||
string.equals.call.display.name=Call to 'String.equals()'
|
||||
|
||||
@@ -39,6 +39,9 @@ public class MagicNumberInspection extends BaseInspection {
|
||||
@SuppressWarnings("PublicField")
|
||||
public boolean ignoreInTestCode = false;
|
||||
|
||||
@SuppressWarnings("PublicField")
|
||||
public boolean ignoreInAnnotations = true;
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getDisplayName() {
|
||||
@@ -56,6 +59,7 @@ public class MagicNumberInspection extends BaseInspection {
|
||||
final MultipleCheckboxOptionsPanel panel = new MultipleCheckboxOptionsPanel(this);
|
||||
panel.addCheckbox(InspectionGadgetsBundle.message("magic.number.ignore.option"), "ignoreInHashCode");
|
||||
panel.addCheckbox(InspectionGadgetsBundle.message("ignore.in.test.code"), "ignoreInTestCode");
|
||||
panel.addCheckbox(InspectionGadgetsBundle.message("ignore.in.annotations"),"ignoreInAnnotations");
|
||||
return panel;
|
||||
}
|
||||
|
||||
@@ -102,6 +106,9 @@ public class MagicNumberInspection extends BaseInspection {
|
||||
return;
|
||||
}
|
||||
final PsiElement parent = expression.getParent();
|
||||
if (ignoreInAnnotations && parent instanceof PsiNameValuePair) {
|
||||
return;
|
||||
}
|
||||
if (parent instanceof PsiPrefixExpression) {
|
||||
registerError(parent);
|
||||
}
|
||||
|
||||
@@ -10,6 +10,8 @@ Use the first checkbox below to disable this inspection within <b>hashCode()</b>
|
||||
<p>
|
||||
Use the second checkbox below to ignore magic numbers in test code.
|
||||
<p>
|
||||
Use the third checkbox below to ignore magic numbers in annotations.
|
||||
<p>
|
||||
<small>Powered by InspectionGadgets</small>
|
||||
</body>
|
||||
</html>
|
||||
+9
-5
@@ -1,9 +1,10 @@
|
||||
package com.siyeh.igtest.abstraction;
|
||||
package com.siyeh.igtest.abstraction.magic_number;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.HashSet;
|
||||
|
||||
public class MagicNumberInspection
|
||||
@Size(max = 15)
|
||||
public class MagicNumber
|
||||
{
|
||||
private static final int s_foo = 400;
|
||||
private int m_foo = 400;
|
||||
@@ -21,10 +22,10 @@ public class MagicNumberInspection
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
final MagicNumberInspection magicNumberInspection = (MagicNumberInspection) o;
|
||||
final MagicNumber magicNumber = (MagicNumber) o;
|
||||
|
||||
if (m_foo != magicNumberInspection.m_foo) return false;
|
||||
if (m_foo2 != magicNumberInspection.m_foo2) return false;
|
||||
if (m_foo != magicNumber.m_foo) return false;
|
||||
if (m_foo2 != magicNumber.m_foo2) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -35,4 +36,7 @@ public class MagicNumberInspection
|
||||
result = 29 * result + m_foo2;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@interface Size {
|
||||
int max();
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<problems>
|
||||
<problem>
|
||||
<file>MagicNumber.java</file>
|
||||
<line>10</line>
|
||||
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">"Magic number"</problem_class>
|
||||
<description>Magic number <code>400</code> #loc</description>
|
||||
</problem>
|
||||
|
||||
<problem>
|
||||
<file>MagicNumber.java</file>
|
||||
<line>17</line>
|
||||
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">"Magic number"</problem_class>
|
||||
<description>Magic number <code>400</code> #loc</description>
|
||||
</problem>
|
||||
|
||||
<problem>
|
||||
<file>MagicNumber.java</file>
|
||||
<line>12</line>
|
||||
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">"Magic number"</problem_class>
|
||||
<description>Magic number <code>400</code> #loc</description>
|
||||
</problem>
|
||||
|
||||
<problem>
|
||||
<file>MagicNumber.java</file>
|
||||
<line>11</line>
|
||||
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">"Magic number"</problem_class>
|
||||
<description>Magic number <code>400</code> #loc</description>
|
||||
</problem>
|
||||
</problems>
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package com.siyeh.ig.abstraction;
|
||||
|
||||
import com.siyeh.ig.IGInspectionTestCase;
|
||||
|
||||
public class MagicNumberInspectionTest extends IGInspectionTestCase {
|
||||
|
||||
public void test() throws Exception {
|
||||
final MagicNumberInspection tool = new MagicNumberInspection();
|
||||
tool.ignoreInHashCode = true;
|
||||
tool.ignoreInAnnotations = true;
|
||||
doTest("com/siyeh/igtest/abstraction/magic_number", tool);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user