Skip to content

Commit 7ef1bd7

Browse files
author
Vitaliy Boyko
committed
Static fixes
1 parent 7c85cbf commit 7ef1bd7

38 files changed

+2250
-1201
lines changed

gradle-tasks/pmd/ruleset.xml

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
</description>
1616
<rule ref="category/java/bestpractices.xml">
1717
<exclude name="JUnit4TestShouldUseTestAnnotation"/>
18+
<exclude name="JUnit4TestShouldUseBeforeAnnotation"/>
1819
</rule>
1920
<rule ref="category/java/codestyle.xml">
2021
<exclude name="AtLeastOneConstructor" />
@@ -26,6 +27,7 @@
2627
</rule>
2728
<rule ref="category/java/documentation.xml">
2829
<exclude name="CommentRequired" />
30+
<exclude name="CommentSize" />
2931
</rule>
3032
<rule ref="category/java/errorprone.xml">
3133
<exclude name="BeanMembersShouldSerialize"/>

src/com/magento/idea/magento2plugin/actions/generation/NewModuleAction.java

+44-39
Original file line numberDiff line numberDiff line change
@@ -2,88 +2,93 @@
22
* Copyright © Magento, Inc. All rights reserved.
33
* See COPYING.txt for license details.
44
*/
5+
56
package com.magento.idea.magento2plugin.actions.generation;
67

78
import com.intellij.ide.IdeView;
8-
import com.intellij.openapi.actionSystem.*;
9-
import com.intellij.openapi.editor.Editor;
9+
import com.intellij.openapi.actionSystem.AnActionEvent;
10+
import com.intellij.openapi.actionSystem.CommonDataKeys;
11+
import com.intellij.openapi.actionSystem.DataContext;
12+
import com.intellij.openapi.actionSystem.LangDataKeys;
13+
import com.intellij.openapi.actionSystem.PlatformDataKeys;
1014
import com.intellij.openapi.project.Project;
11-
import com.intellij.openapi.util.Pair;
1215
import com.intellij.psi.PsiDirectory;
1316
import com.intellij.psi.PsiElement;
14-
import com.intellij.psi.PsiFile;
15-
import com.jetbrains.php.lang.psi.PhpFile;
16-
import com.jetbrains.php.lang.psi.elements.PhpClass;
1717
import com.magento.idea.magento2plugin.MagentoIcons;
1818
import com.magento.idea.magento2plugin.actions.generation.dialog.NewModuleDialog;
1919
import com.magento.idea.magento2plugin.actions.generation.util.IsClickedDirectoryInsideProject;
2020
import com.magento.idea.magento2plugin.project.Settings;
2121
import com.magento.idea.magento2plugin.util.magento.GetModuleNameByDirectory;
2222
import org.jetbrains.annotations.NotNull;
23-
import org.jetbrains.annotations.Nullable;
2423

2524
public class NewModuleAction extends com.intellij.openapi.actionSystem.AnAction {
26-
public static String ACTION_NAME = "Magento 2 Module";
27-
public static String ACTION_DESCRIPTION = "Create a new Magento 2 module";
25+
public static String actionName = "Magento 2 Module";
26+
public static String actionDescription = "Create a new Magento 2 module";
2827

29-
NewModuleAction() {
30-
super(ACTION_NAME, ACTION_DESCRIPTION, MagentoIcons.MODULE);
28+
/**
29+
* Constructor.
30+
*/
31+
public NewModuleAction() {
32+
super(actionName, actionDescription, MagentoIcons.MODULE);
3133
}
34+
3235
@Override
33-
public void actionPerformed(@NotNull AnActionEvent e) {
34-
DataContext dataContext = e.getDataContext();
35-
IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext);
36-
if (view != null) {
37-
Project project = CommonDataKeys.PROJECT.getData(dataContext);
38-
if (project != null) {
39-
PsiDirectory initialBaseDir = view.getOrChooseDirectory();
40-
if (initialBaseDir != null) {
41-
this.invoke(project, initialBaseDir, this.getFile(dataContext), view, CommonDataKeys.EDITOR.getData(dataContext));
42-
}
36+
public void actionPerformed(final @NotNull AnActionEvent event) {
37+
final DataContext dataContext = event.getDataContext();
38+
final IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext);
39+
if (view == null) {
40+
return;
41+
}
42+
final Project project = CommonDataKeys.PROJECT.getData(dataContext);
43+
if (project != null) {
44+
final PsiDirectory initialBaseDir = view.getOrChooseDirectory();
45+
if (initialBaseDir != null) {
46+
this.invoke(project, initialBaseDir);
4347
}
4448
}
4549
}
4650

47-
public void invoke(@NotNull Project project, @NotNull PsiDirectory initialBaseDir, @Nullable PsiFile file, @Nullable IdeView view, @Nullable Editor editor) {
48-
NewModuleDialog.open(project, initialBaseDir, file, view, editor);
51+
public void invoke(final @NotNull Project project, final @NotNull PsiDirectory initialBaseDir) {
52+
NewModuleDialog.open(project, initialBaseDir);
4953
}
5054

5155
@Override
5256
public boolean isDumbAware() {
5357
return false;
5458
}
5559

56-
@NotNull
57-
private String getActionName() {
58-
return this.getTemplatePresentation().getText();
59-
}
60-
61-
public PsiFile getFile(DataContext dataContext) {
62-
return CommonDataKeys.PSI_FILE.getData(dataContext);
63-
}
64-
65-
public void update(AnActionEvent event) {
66-
Project project = event.getData(PlatformDataKeys.PROJECT);
60+
/**
61+
* Inherit doc.
62+
*
63+
* @param event AnActionEvent
64+
*/
65+
@Override
66+
public void update(final AnActionEvent event) {
67+
final Project project = event.getData(PlatformDataKeys.PROJECT);
6768

6869
if (Settings.isEnabled(project)) {
69-
String magentoPath = Settings.getMagentoPath(project);
70+
final String magentoPath = Settings.getMagentoPath(project);
7071
if (magentoPath == null) {
7172
event.getPresentation().setVisible(false);
7273
return;
7374
}
74-
PsiElement psiElement = event.getData(PlatformDataKeys.PSI_ELEMENT);
75+
final PsiElement psiElement = event.getData(PlatformDataKeys.PSI_ELEMENT);
7576
if (!(psiElement instanceof PsiDirectory)) {
7677
event.getPresentation().setVisible(false);
7778
return;
7879
}
7980

80-
if(!IsClickedDirectoryInsideProject.getInstance().execute(project, (PsiDirectory) psiElement)) {
81+
if (!IsClickedDirectoryInsideProject.getInstance().execute(
82+
project,
83+
(PsiDirectory) psiElement)
84+
) {
8185
event.getPresentation().setVisible(false);
8286
return;
8387
}
8488

85-
GetModuleNameByDirectory getModuleName = GetModuleNameByDirectory.getInstance(project);
86-
String moduleName = getModuleName.execute((PsiDirectory) psiElement);
89+
final GetModuleNameByDirectory getModuleName = GetModuleNameByDirectory
90+
.getInstance(project);
91+
final String moduleName = getModuleName.execute((PsiDirectory) psiElement);
8792
if (moduleName == null) {
8893
event.getPresentation().setVisible(true);
8994
return;

src/com/magento/idea/magento2plugin/actions/generation/dialog/CreateAPluginDialog.java

+74-29
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* Copyright © Magento, Inc. All rights reserved.
33
* See COPYING.txt for license details.
44
*/
5+
56
package com.magento.idea.magento2plugin.actions.generation.dialog;
67

78
import com.intellij.openapi.project.Project;
@@ -16,40 +17,63 @@
1617
import com.magento.idea.magento2plugin.indexes.ModuleIndex;
1718
import com.magento.idea.magento2plugin.magento.files.Plugin;
1819
import com.magento.idea.magento2plugin.magento.packages.Areas;
20+
import com.magento.idea.magento2plugin.magento.packages.File;
1921
import com.magento.idea.magento2plugin.magento.packages.Package;
2022
import com.magento.idea.magento2plugin.ui.FilteredComboBox;
21-
import org.jetbrains.annotations.NotNull;
22-
import javax.swing.*;
23-
import java.awt.event.*;
24-
import com.magento.idea.magento2plugin.magento.packages.File;
23+
import java.awt.event.ActionEvent;
24+
import java.awt.event.ActionListener;
25+
import java.awt.event.KeyEvent;
26+
import java.awt.event.WindowAdapter;
27+
import java.awt.event.WindowEvent;
2528
import java.util.List;
29+
import javax.swing.JButton;
30+
import javax.swing.JComboBox;
31+
import javax.swing.JComponent;
32+
import javax.swing.JLabel;
33+
import javax.swing.JPanel;
34+
import javax.swing.JTextField;
35+
import javax.swing.KeyStroke;
36+
import org.jetbrains.annotations.NotNull;
2637

38+
@SuppressWarnings({"PMD.TooManyFields", "PMD.DataClass", "PMD.UnusedPrivateMethod"})
2739
public class CreateAPluginDialog extends AbstractDialog {
2840
@NotNull
2941
private final Project project;
30-
private Method targetMethod;
31-
private PhpClass targetClass;
42+
private final Method targetMethod;
43+
private final PhpClass targetClass;
3244
@NotNull
3345
private final CreateAPluginDialogValidator validator;
3446
private JPanel contentPane;
3547
private JButton buttonOK;
3648
private JButton buttonCancel;
3749
private JTextField pluginClassName;
38-
private JLabel pluginClassNameLabel;
3950
private JTextField pluginDirectory;
40-
private JLabel pluginDirectoryName;
41-
private JLabel selectPluginModule;
4251
private JComboBox pluginType;
43-
private JLabel pluginTypeLabel;
4452
private FilteredComboBox pluginModule;
4553
private JComboBox pluginArea;
46-
private JLabel pluginAreaLabel;
47-
private JTextField pluginName;
48-
private JLabel pluginNameLabel;
4954
private JTextField pluginSortOrder;
50-
private JLabel pluginSortOrderLabel;
51-
52-
public CreateAPluginDialog(@NotNull Project project, Method targetMethod, PhpClass targetClass) {
55+
private JTextField pluginName;
56+
private JLabel pluginDirectoryName;//NOPMD
57+
private JLabel selectPluginModule;//NOPMD
58+
private JLabel pluginTypeLabel;//NOPMD
59+
private JLabel pluginAreaLabel;//NOPMD
60+
private JLabel pluginNameLabel;//NOPMD
61+
private JLabel pluginClassNameLabel;//NOPMD
62+
private JLabel pluginSortOrderLabel;//NOPMD
63+
64+
/**
65+
* Constructor.
66+
*
67+
* @param project Project
68+
* @param targetMethod Method
69+
* @param targetClass PhpClass
70+
*/
71+
public CreateAPluginDialog(
72+
final @NotNull Project project,
73+
final Method targetMethod,
74+
final PhpClass targetClass
75+
) {
76+
super();
5377
this.project = project;
5478
this.targetMethod = targetMethod;
5579
this.targetClass = targetClass;
@@ -62,44 +86,46 @@ public CreateAPluginDialog(@NotNull Project project, Method targetMethod, PhpCla
6286
fillTargetAreaOptions();
6387

6488
buttonOK.addActionListener(new ActionListener() {
65-
public void actionPerformed(ActionEvent e) {
89+
public void actionPerformed(final ActionEvent event) {
6690
onOK();
6791
}
6892
});
6993

7094
buttonCancel.addActionListener(new ActionListener() {
71-
public void actionPerformed(ActionEvent e) {
95+
public void actionPerformed(final ActionEvent event) {
7296
onCancel();
7397
}
7498
});
7599

76100
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
77101
addWindowListener(new WindowAdapter() {
78-
public void windowClosing(WindowEvent e) {
102+
public void windowClosing(final WindowEvent event) {
79103
onCancel();
80104
}
81105
});
82106

83107
contentPane.registerKeyboardAction(new ActionListener() {
84-
public void actionPerformed(ActionEvent e) {
108+
public void actionPerformed(final ActionEvent event) {
85109
onCancel();
86110
}
87-
}, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
111+
}, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
112+
JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
113+
);
88114
}
89115

90116
private void fillPluginTypeOptions() {
91-
for (Plugin.PluginType pluginPrefixType: Plugin.PluginType.values()) {
117+
for (final Plugin.PluginType pluginPrefixType: Plugin.PluginType.values()) {
92118
pluginType.addItem(pluginPrefixType.toString());
93119
}
94120
}
95121

96122
private void fillTargetAreaOptions() {
97-
for(Areas area: Areas.values()) {
123+
for (final Areas area : Areas.values()) {
98124
pluginArea.addItem(area.toString());
99125
}
100126
}
101127

102-
private void onOK() {
128+
protected void onOK() {
103129
if (!validator.validate(project)) {
104130
return;
105131
}
@@ -154,22 +180,41 @@ public String getPluginModule() {
154180
return this.pluginModule.getSelectedItem().toString();
155181
}
156182

157-
public static void open(@NotNull Project project, Method targetMethod, PhpClass targetClass) {
158-
CreateAPluginDialog dialog = new CreateAPluginDialog(project, targetMethod, targetClass);
183+
/**
184+
* Open an action dialog.
185+
*
186+
* @param project Project
187+
* @param targetMethod Method
188+
* @param targetClass PhpClass
189+
*/
190+
public static void open(
191+
final @NotNull Project project,
192+
final Method targetMethod,
193+
final PhpClass targetClass
194+
) {
195+
final CreateAPluginDialog dialog = new CreateAPluginDialog(
196+
project,
197+
targetMethod,
198+
targetClass
199+
);
159200
dialog.pack();
160201
dialog.centerDialog(dialog);
161202
dialog.setVisible(true);
162203
}
163204

164205
private void createUIComponents() {
165-
List<String> allModulesList = ModuleIndex.getInstance(project).getEditableModuleNames();
206+
final List<String> allModulesList = ModuleIndex.getInstance(project)
207+
.getEditableModuleNames();
166208

167209
this.pluginModule = new FilteredComboBox(allModulesList);
168210
}
169211

170212
private String getNamespace() {
171-
String targetModule = getPluginModule();
172-
String namespace = targetModule.replace(Package.vendorModuleNameSeparator, Package.fqnSeparator);
213+
final String targetModule = getPluginModule();
214+
String namespace = targetModule.replace(
215+
Package.vendorModuleNameSeparator,
216+
Package.fqnSeparator
217+
);
173218
namespace = namespace.concat(Package.fqnSeparator);
174219
return namespace.concat(getPluginDirectory().replace(File.separator, Package.fqnSeparator));
175220
}

0 commit comments

Comments
 (0)