11
11
import com .intellij .openapi .fileTypes .FileTypes ;
12
12
import com .intellij .openapi .project .Project ;
13
13
import com .intellij .openapi .ui .ComboBox ;
14
- import com .intellij .psi .PsiDirectory ;
15
14
import com .intellij .psi .PsiFile ;
16
15
import com .intellij .ui .EditorTextField ;
17
16
import com .jetbrains .php .PhpIndex ;
34
33
import com .magento .idea .magento2plugin .magento .packages .Areas ;
35
34
import com .magento .idea .magento2plugin .magento .packages .DiArgumentType ;
36
35
import com .magento .idea .magento2plugin .ui .FilteredComboBox ;
37
- import com .magento .idea .magento2plugin .util .magento .GetModuleNameByDirectoryUtil ;
38
36
import java .awt .event .ActionListener ;
39
37
import java .awt .event .KeyEvent ;
40
38
import java .awt .event .WindowAdapter ;
54
52
import org .jetbrains .annotations .NonNls ;
55
53
import org .jetbrains .annotations .NotNull ;
56
54
55
+ @ SuppressWarnings ({
56
+ "PMD.TooManyFields" ,
57
+ "PMD.UnusedPrivateField" ,
58
+ "PMD.ExcessiveImports" ,
59
+ "PMD.AvoidInstantiatingObjectsInLoops"
60
+ })
57
61
public class NewArgumentInjectionDialog extends AbstractDialog {
58
62
59
63
private static final String TARGET_AREA = "Target Area" ;
@@ -64,9 +68,7 @@ public class NewArgumentInjectionDialog extends AbstractDialog {
64
68
private static final String CONST_VALUE = "Target Constant" ;
65
69
66
70
private final @ NotNull Project project ;
67
- private final String moduleName ;
68
71
private final PhpClass targetClass ;
69
- private final Parameter targetParameter ;
70
72
71
73
private JPanel contentPane ;
72
74
private JButton buttonCancel ;
@@ -130,7 +132,7 @@ public class NewArgumentInjectionDialog extends AbstractDialog {
130
132
private JButton addArrayValueBtn ;
131
133
private JTextArea arrayView ;
132
134
133
- final DiArrayValueData arrayValues ;
135
+ private final DiArrayValueData arrayValues ;
134
136
135
137
// labels
136
138
private JLabel argumentTypeLabel ;//NOPMD
@@ -152,22 +154,24 @@ public class NewArgumentInjectionDialog extends AbstractDialog {
152
154
* New argument injection dialog constructor.
153
155
*
154
156
* @param project Project
155
- * @param directory PsiDirectory
156
157
* @param targetClass PhpClass
157
158
* @param parameter Parameter
158
159
*/
160
+ @ SuppressWarnings ({
161
+ "PMD.AccessorMethodGeneration" ,
162
+ "PMD.ExcessiveMethodLength" ,
163
+ "PMD.CognitiveComplexity" ,
164
+ "PMD.CyclomaticComplexity" ,
165
+ })
159
166
public NewArgumentInjectionDialog (
160
167
final @ NotNull Project project ,
161
- final @ NotNull PsiDirectory directory ,
162
168
final @ NotNull PhpClass targetClass ,
163
169
final @ NotNull Parameter parameter
164
170
) {
165
171
super ();
166
172
167
173
this .project = project ;
168
174
this .targetClass = targetClass ;
169
- this .targetParameter = parameter ;
170
- this .moduleName = GetModuleNameByDirectoryUtil .execute (directory , project );
171
175
arrayValues = new DiArrayValueData ();
172
176
173
177
setContentPane (contentPane );
@@ -197,7 +201,7 @@ public void windowClosing(final WindowEvent event) {
197
201
addComponentListener (new FocusOnAFieldListener (() -> targetModule .requestFocusInWindow ()));
198
202
199
203
targetClassField .setText (targetClass .getPresentableFQN ());
200
- targetArgument .setText (targetParameter .getName ());
204
+ targetArgument .setText (parameter .getName ());
201
205
202
206
// make all value panes invisible
203
207
objectValuePane .setVisible (false );
@@ -335,18 +339,16 @@ public void documentChanged(final @NotNull DocumentEvent event) {
335
339
* Open a new argument injection dialog.
336
340
*
337
341
* @param project Project
338
- * @param directory PsiDirectory
339
342
* @param targetClass PhpClass
340
343
* @param parameter Parameter
341
344
*/
342
345
public static void open (
343
346
final @ NotNull Project project ,
344
- final @ NotNull PsiDirectory directory ,
345
347
final @ NotNull PhpClass targetClass ,
346
348
final @ NotNull Parameter parameter
347
349
) {
348
350
final NewArgumentInjectionDialog dialog =
349
- new NewArgumentInjectionDialog (project , directory , targetClass , parameter );
351
+ new NewArgumentInjectionDialog (project , targetClass , parameter );
350
352
dialog .pack ();
351
353
dialog .centerDialog (dialog );
352
354
dialog .setVisible (true );
@@ -397,7 +399,7 @@ private void onOK() {
397
399
/**
398
400
* Create custom components and fill their entries.
399
401
*/
400
- @ SuppressWarnings ({"PMD.UnusedPrivateMethod" , "PMD.AvoidInstantiatingObjectsInLoops" })
402
+ @ SuppressWarnings ({"PMD.UnusedPrivateMethod" })
401
403
private void createUIComponents () {
402
404
targetModule = new FilteredComboBox (new ModuleIndex (project ).getEditableModuleNames ());
403
405
targetArea = new ComboBox <>();
@@ -425,9 +427,10 @@ private void createUIComponents() {
425
427
booleanValue .addItem (new ComboBoxItemData ("" , " --- Select Value --- " ));
426
428
booleanValue .addItem (new ComboBoxItemData ("false" , "False" ));
427
429
booleanValue .addItem (new ComboBoxItemData ("true" , "True" ));
430
+ final String selectConstantText = " --- Select Constant --- " ;
428
431
429
- initParameterConstValue .addItem (new ComboBoxItemData ("" , " --- Select Constant --- " ));
430
- constantValue .addItem (new ComboBoxItemData ("" , " --- Select Constant --- " ));
432
+ initParameterConstValue .addItem (new ComboBoxItemData ("" , selectConstantText ));
433
+ constantValue .addItem (new ComboBoxItemData ("" , selectConstantText ));
431
434
432
435
initParameterTypeValue = new EditorTextField ("" , project , FileTypes .PLAIN_TEXT );
433
436
constantTypeValue = new EditorTextField ("" , project , FileTypes .PLAIN_TEXT );
@@ -479,7 +482,7 @@ private List<String> getConstantsNames(final @NotNull String fqn) {
479
482
final Collection <PhpClass > classes = phpIndex .getClassesByFQN (fqn );
480
483
PhpClass clazz = null ;
481
484
482
- if (!interfaces .isEmpty ()) {
485
+ if (!interfaces .isEmpty ()) { // NOPMD
483
486
clazz = interfaces .iterator ().next ();
484
487
} else if (!classes .isEmpty ()) {
485
488
clazz = classes .iterator ().next ();
@@ -509,7 +512,7 @@ private void populateSubArrayKeyCombobox() {
509
512
subArrayKey .addItem (new ComboBoxItemData ("" , " --- Top Array --- " ));
510
513
populateSubArrayKeyCombobox (arrayValues , "" );
511
514
512
- if (subArrayKey .getItemCount () > 1 ) {
515
+ if (subArrayKey .getItemCount () > 1 ) { // NOPMD
513
516
subArrayKeyLabel .setVisible (true );
514
517
subArrayKey .setVisible (true );
515
518
}
@@ -564,6 +567,7 @@ private void changeViewBySelectedArgumentType(final String itemValue) {
564
567
}
565
568
}
566
569
570
+ @ SuppressWarnings ({"PMD.CognitiveComplexity" , "PMD.CyclomaticComplexity" })
567
571
private @ NotNull String getArgumentValue () {
568
572
final ComboBoxItemData item = (ComboBoxItemData ) argumentType .getSelectedItem ();
569
573
0 commit comments