IDEA-186767 Magic constant: false positive for JFrame.EXIT_ON_CLOSE

This commit is contained in:
Alexey Kudravtsev
2018-03-01 14:09:00 +03:00
parent d5239ecb84
commit f6002904a7
3 changed files with 12 additions and 1 deletions
@@ -21,6 +21,9 @@ import javax.swing.*;
public class X {
void f(JFrame frame) {
frame.setDefaultCloseOperation(2); // there is beanInfo in in JFrame.java, have to parse (but added to exceptions, so ok)
// despite JFrame.EXIT_ON_CLOSE (incorrectly) not mentioned in beaninfo, we override it in our annotations.xml, see IDEA-186767
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
void f(Frame frame) {
@@ -38,7 +38,6 @@ import org.jetbrains.annotations.NotNull;
import java.io.File;
public class MagicConstantInspectionTest extends InspectionTestCase {
private FileTreeAccessFilter myFilter;
@Override
@@ -66,6 +65,10 @@ public class MagicConstantInspectionTest extends InspectionTestCase {
@Override
protected void setupRootModel(@NotNull String testDir, @NotNull VirtualFile[] sourceDir, String sdkName) {
super.setupRootModel(testDir, sourceDir, sdkName);
PsiClass jframe = getJavaFacade().findClass("javax.swing.JFrame", GlobalSearchScope.allScope(getProject()));
assertNotNull("configure decent JDK for testsake", jframe);
VirtualFile projectDir = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(new File(testDir));
// allow to load AST for all files to highlight
VfsUtilCore.visitChildrenRecursively(projectDir, new VirtualFileVisitor() {
@@ -69,6 +69,11 @@
<item name="javax.swing.JEditorPane JEditorPane(java.lang.String, java.lang.String) 0">
<annotation name="org.jetbrains.annotations.NonNls" />
</item>
<item name='javax.swing.JFrame void setDefaultCloseOperation(int) 0'>
<annotation name="org.intellij.lang.annotations.MagicConstant">
<val name="intValues" val="{javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE, javax.swing.WindowConstants.HIDE_ON_CLOSE, javax.swing.WindowConstants.DISPOSE_ON_CLOSE, javax.swing.WindowConstants.EXIT_ON_CLOSE, javax.swing.JFrame.EXIT_ON_CLOSE}" />
</annotation>
</item>
<item name="javax.swing.JLabel JLabel(java.lang.String, int) 1">
<annotation name="org.intellij.lang.annotations.MagicConstant">
<val name="intValues" val="{javax.swing.SwingConstants.LEFT, javax.swing.SwingConstants.CENTER, javax.swing.SwingConstants.RIGHT, javax.swing.SwingConstants.LEADING, javax.swing.SwingConstants.TRAILING}" />