mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-08 15:09:39 +07:00
create factory for "Configure annotations" button/action listener to reduce code duplication
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
* Copyright 2000-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -22,16 +22,13 @@ import com.intellij.compiler.CompilerWorkspaceConfiguration;
|
||||
import com.intellij.compiler.MalformedPatternException;
|
||||
import com.intellij.compiler.impl.javaCompiler.javac.JavacConfiguration;
|
||||
import com.intellij.compiler.server.BuildManager;
|
||||
import com.intellij.ide.DataManager;
|
||||
import com.intellij.ide.PowerSaveMode;
|
||||
import com.intellij.openapi.actionSystem.CommonDataKeys;
|
||||
import com.intellij.openapi.compiler.CompilerBundle;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.options.Configurable;
|
||||
import com.intellij.openapi.options.ConfigurationException;
|
||||
import com.intellij.openapi.options.SearchableConfigurable;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.project.ProjectManager;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.ui.DocumentAdapter;
|
||||
import com.intellij.ui.Gray;
|
||||
@@ -47,8 +44,6 @@ import org.jetbrains.annotations.NotNull;
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.DocumentEvent;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
|
||||
@@ -112,16 +107,7 @@ public class CompilerUIConfigurable implements SearchableConfigurable, Configura
|
||||
s -> StringUtil.startsWithIgnoreCase(s, "-Xmx")) == null);
|
||||
}
|
||||
});
|
||||
myConfigureAnnotations.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Project project = CommonDataKeys.PROJECT.getData(DataManager.getInstance().getDataContext(myPanel));
|
||||
if (project == null) {
|
||||
project = ProjectManager.getInstance().getDefaultProject();
|
||||
}
|
||||
new NullableNotNullDialog(project).show();
|
||||
}
|
||||
});
|
||||
myConfigureAnnotations.addActionListener(NullableNotNullDialog.createActionListener(myPanel));
|
||||
}
|
||||
|
||||
private void tweakControls(@NotNull Project project) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
* Copyright 2000-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -18,10 +18,6 @@ package com.intellij.codeInspection.dataFlow;
|
||||
import com.intellij.codeInsight.NullableNotNullDialog;
|
||||
import com.intellij.codeInspection.*;
|
||||
import com.intellij.codeInspection.nullable.NullableStuffInspection;
|
||||
import com.intellij.ide.DataManager;
|
||||
import com.intellij.openapi.actionSystem.CommonDataKeys;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.project.ProjectManager;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.refactoring.util.RefactoringUtil;
|
||||
@@ -32,8 +28,6 @@ import javax.swing.*;
|
||||
import javax.swing.event.ChangeEvent;
|
||||
import javax.swing.event.ChangeListener;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.List;
|
||||
|
||||
public class DataFlowInspection extends DataFlowInspectionBase {
|
||||
@@ -151,16 +145,7 @@ public class DataFlowInspection extends DataFlowInspectionBase {
|
||||
gc.gridy = 0;
|
||||
add(mySuggestNullables, gc);
|
||||
|
||||
final JButton configureAnnotations = new JButton(InspectionsBundle.message("configure.annotations.option"));
|
||||
configureAnnotations.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Project project = CommonDataKeys.PROJECT.getData(DataManager.getInstance().getDataContext(OptionsPanel.this));
|
||||
if (project == null) project = ProjectManager.getInstance().getDefaultProject();
|
||||
final NullableNotNullDialog dialog = new NullableNotNullDialog(project);
|
||||
dialog.show();
|
||||
}
|
||||
});
|
||||
final JButton configureAnnotations = NullableNotNullDialog.createConfigureAnnotationsButton(this);
|
||||
gc.gridy++;
|
||||
gc.fill = GridBagConstraints.NONE;
|
||||
gc.insets.left = 20;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2011 JetBrains s.r.o.
|
||||
* Copyright 2000-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -20,11 +20,8 @@ import com.intellij.codeInspection.InspectionsBundle;
|
||||
import com.intellij.codeInspection.LocalQuickFix;
|
||||
import com.intellij.codeInspection.LocalQuickFixOnPsiElement;
|
||||
import com.intellij.find.findUsages.PsiElement2UsageTargetAdapter;
|
||||
import com.intellij.ide.DataManager;
|
||||
import com.intellij.openapi.actionSystem.CommonDataKeys;
|
||||
import com.intellij.openapi.application.ReadAction;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.project.ProjectManager;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
@@ -83,15 +80,7 @@ public class NullableStuffInspection extends NullableStuffInspectionBase {
|
||||
myIgnoreExternalSuperNotNull.addActionListener(actionListener);
|
||||
myRequireNNFieldsInitialized.addActionListener(actionListener);
|
||||
myReportNullLiteralsPassedNotNullParameter.addActionListener(actionListener);
|
||||
myConfigureAnnotationsButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Project project = CommonDataKeys.PROJECT.getData(DataManager.getInstance().getDataContext(OptionsPanel.this));
|
||||
if (project == null) project = ProjectManager.getInstance().getDefaultProject();
|
||||
final NullableNotNullDialog dialog = new NullableNotNullDialog(project);
|
||||
dialog.show();
|
||||
}
|
||||
});
|
||||
myConfigureAnnotationsButton.addActionListener(NullableNotNullDialog.createActionListener(this));
|
||||
reset();
|
||||
}
|
||||
|
||||
|
||||
@@ -15,12 +15,16 @@
|
||||
*/
|
||||
package com.intellij.codeInsight;
|
||||
|
||||
import com.intellij.codeInspection.InspectionsBundle;
|
||||
import com.intellij.icons.AllIcons;
|
||||
import com.intellij.ide.DataManager;
|
||||
import com.intellij.ide.util.ClassFilter;
|
||||
import com.intellij.ide.util.TreeClassChooser;
|
||||
import com.intellij.ide.util.TreeClassChooserFactory;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.CommonDataKeys;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.project.ProjectManager;
|
||||
import com.intellij.openapi.ui.DialogWrapper;
|
||||
import com.intellij.openapi.ui.Splitter;
|
||||
import com.intellij.psi.PsiClass;
|
||||
@@ -36,6 +40,8 @@ import javax.swing.*;
|
||||
import javax.swing.event.ListSelectionEvent;
|
||||
import javax.swing.event.ListSelectionListener;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
@@ -57,6 +63,28 @@ public class NullableNotNullDialog extends DialogWrapper {
|
||||
setTitle("Nullable/NotNull configuration");
|
||||
}
|
||||
|
||||
public static JButton createConfigureAnnotationsButton(Component context) {
|
||||
final JButton button = new JButton(InspectionsBundle.message("configure.annotations.option"));
|
||||
button.addActionListener(createActionListener(context));
|
||||
return button;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an action listener showing this dialog.
|
||||
* @param context component where project context will be retrieved from
|
||||
* @return the action listener
|
||||
*/
|
||||
public static ActionListener createActionListener(Component context) {
|
||||
return new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Project project = CommonDataKeys.PROJECT.getData(DataManager.getInstance().getDataContext(context));
|
||||
if (project == null) project = ProjectManager.getInstance().getDefaultProject();
|
||||
new NullableNotNullDialog(project).show();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JComponent createCenterPanel() {
|
||||
final NullableNotNullManager manager = NullableNotNullManager.getInstance(myProject);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
* Copyright 2000-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,19 +16,12 @@
|
||||
package com.siyeh.ig.bugs;
|
||||
|
||||
import com.intellij.codeInsight.NullableNotNullDialog;
|
||||
import com.intellij.codeInspection.InspectionsBundle;
|
||||
import com.intellij.codeInspection.ui.MultipleCheckboxOptionsPanel;
|
||||
import com.intellij.ide.DataManager;
|
||||
import com.intellij.ide.util.SuperMethodWarningUtil;
|
||||
import com.intellij.openapi.actionSystem.CommonDataKeys;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.project.ProjectManager;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import com.siyeh.InspectionGadgetsBundle;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
public class ReturnNullInspection extends ReturnNullInspectionBase {
|
||||
|
||||
@@ -39,16 +32,7 @@ public class ReturnNullInspection extends ReturnNullInspectionBase {
|
||||
optionsPanel.addCheckbox(InspectionGadgetsBundle.message("return.of.null.arrays.option"), "m_reportArrayMethods");
|
||||
optionsPanel.addCheckbox(InspectionGadgetsBundle.message("return.of.null.collections.option"), "m_reportCollectionMethods");
|
||||
optionsPanel.addCheckbox(InspectionGadgetsBundle.message("return.of.null.objects.option"), "m_reportObjectMethods");
|
||||
final JButton configureAnnotations = new JButton(InspectionsBundle.message("configure.annotations.option"));
|
||||
configureAnnotations.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Project project = CommonDataKeys.PROJECT.getData(DataManager.getInstance().getDataContext(optionsPanel));
|
||||
if (project == null) project = ProjectManager.getInstance().getDefaultProject();
|
||||
new NullableNotNullDialog(project).show();
|
||||
}
|
||||
});
|
||||
optionsPanel.addComponent(configureAnnotations);
|
||||
optionsPanel.addComponent(NullableNotNullDialog.createConfigureAnnotationsButton(optionsPanel));
|
||||
return optionsPanel;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user