mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-13 09:19:13 +07:00
[java-inspections] MagicConstantInspection: test to ensure that parameters and fields do not propagate automatically
GitOrigin-RevId: 7053c2c950894e6694353e90d77cb1f2ff772fb3
This commit is contained in:
committed by
intellij-monorepo-bot
parent
624b012c49
commit
7e2050cf72
@@ -0,0 +1,36 @@
|
||||
import org.intellij.lang.annotations.MagicConstant;
|
||||
|
||||
class Main {
|
||||
static final int V1 = 10;
|
||||
static final int V2 = 20;
|
||||
|
||||
void consume(@MagicConstant(intValues = {V1, V2}) int x) {
|
||||
|
||||
}
|
||||
}
|
||||
class Use {
|
||||
int field;
|
||||
int fieldOk;
|
||||
@MagicConstant(intValues = {Main.V1, Main.V2})
|
||||
int fieldOkAnnotated;
|
||||
|
||||
Use() {
|
||||
this.field = 123;
|
||||
this.fieldOk = Main.V1;
|
||||
this.fieldOkAnnotated = Main.V2;
|
||||
test(123, Main.V1, Main.V2);
|
||||
}
|
||||
|
||||
void test(int parameter, int parameterOk, @MagicConstant(intValues = {Main.V1, Main.V2}) int parameterOkAnnotated) {
|
||||
int local = 123;
|
||||
int localOk = Main.V1;
|
||||
new Main().consume(<warning descr="Should be one of: Main.V1, Main.V2">field</warning>);
|
||||
new Main().consume(<warning descr="Should be one of: Main.V1, Main.V2">fieldOk</warning>);
|
||||
new Main().consume(fieldOkAnnotated);
|
||||
new Main().consume(<warning descr="Should be one of: Main.V1, Main.V2">local</warning>);
|
||||
new Main().consume(localOk);
|
||||
new Main().consume(<warning descr="Should be one of: Main.V1, Main.V2">parameter</warning>);
|
||||
new Main().consume(<warning descr="Should be one of: Main.V1, Main.V2">parameterOk</warning>);
|
||||
new Main().consume(parameterOkAnnotated);
|
||||
}
|
||||
}
|
||||
+1
@@ -37,6 +37,7 @@ public class MagicConstantInspectionTest extends LightJavaCodeInsightFixtureTest
|
||||
public void testEnumConstructor() { doTest(); }
|
||||
public void testFieldInitializer() { doTest(); }
|
||||
public void testSwitchBlock() { doTest(); }
|
||||
public void testPropagate() { doTest(); }
|
||||
public void testSwitchExpression1() { IdeaTestUtil.withLevel(getModule(), LanguageLevel.JDK_14, () -> doTest()); }
|
||||
public void testSwitchExpression2() { IdeaTestUtil.withLevel(getModule(), LanguageLevel.JDK_14, () -> doTest()); }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user