|
15 | 15 | import com.intellij.ui.EditorTextField; |
16 | 16 | import com.jetbrains.php.PhpIndex; |
17 | 17 | import com.jetbrains.php.completion.PhpCompletionUtil; |
| 18 | +import com.jetbrains.php.lang.PhpLangUtil; |
18 | 19 | import com.jetbrains.php.lang.psi.elements.Field; |
19 | 20 | import com.jetbrains.php.lang.psi.elements.Parameter; |
20 | 21 | import com.jetbrains.php.lang.psi.elements.PhpClass; |
|
33 | 34 | import com.magento.idea.magento2plugin.magento.packages.Areas; |
34 | 35 | import com.magento.idea.magento2plugin.magento.packages.DiArgumentType; |
35 | 36 | import com.magento.idea.magento2plugin.ui.FilteredComboBox; |
| 37 | +import com.magento.idea.magento2plugin.util.php.PhpTypeMetadataParserUtil; |
36 | 38 | import java.awt.event.ActionListener; |
37 | 39 | import java.awt.event.KeyEvent; |
38 | 40 | import java.awt.event.WindowAdapter; |
39 | 41 | import java.awt.event.WindowEvent; |
40 | 42 | import java.util.ArrayList; |
| 43 | +import java.util.Arrays; |
41 | 44 | import java.util.Collection; |
42 | 45 | import java.util.List; |
43 | 46 | import javax.swing.JButton; |
@@ -69,6 +72,7 @@ public class NewArgumentInjectionDialog extends AbstractDialog { |
69 | 72 |
|
70 | 73 | private final @NotNull Project project; |
71 | 74 | private final PhpClass targetClass; |
| 75 | + private final Parameter targetParameter; |
72 | 76 |
|
73 | 77 | private JPanel contentPane; |
74 | 78 | private JButton buttonCancel; |
@@ -172,6 +176,7 @@ public NewArgumentInjectionDialog( |
172 | 176 |
|
173 | 177 | this.project = project; |
174 | 178 | this.targetClass = targetClass; |
| 179 | + targetParameter = parameter; |
175 | 180 | arrayValues = new DiArrayValueData(); |
176 | 181 |
|
177 | 182 | setContentPane(contentPane); |
@@ -333,6 +338,7 @@ public void documentChanged(final @NotNull DocumentEvent event) { |
333 | 338 | } |
334 | 339 | } |
335 | 340 | }); |
| 341 | + guessTargetType(); |
336 | 342 | } |
337 | 343 |
|
338 | 344 | /** |
@@ -618,6 +624,39 @@ private void changeViewBySelectedArgumentType(final String itemValue) { |
618 | 624 | return ""; |
619 | 625 | } |
620 | 626 |
|
| 627 | + @SuppressWarnings("PMD.CyclomaticComplexity") |
| 628 | + private void guessTargetType() { |
| 629 | + final String mainType = PhpTypeMetadataParserUtil.getMainType(targetParameter); |
| 630 | + |
| 631 | + if (mainType == null) { |
| 632 | + return; |
| 633 | + } |
| 634 | + String targetDiType = ""; |
| 635 | + |
| 636 | + if (Arrays.asList("int", "float").contains(mainType)) { |
| 637 | + targetDiType = DiArgumentType.NUMBER.getArgumentType(); |
| 638 | + } else if (DiArgumentType.STRING.getArgumentType().equals(mainType)) { |
| 639 | + targetDiType = DiArgumentType.STRING.getArgumentType(); |
| 640 | + } else if ("bool".equals(mainType)) { |
| 641 | + targetDiType = DiArgumentType.BOOLEAN.getArgumentType(); |
| 642 | + } else if (PhpLangUtil.isFqn(mainType)) { |
| 643 | + targetDiType = DiArgumentType.OBJECT.getArgumentType(); |
| 644 | + } else if ("array".equals(mainType)) { |
| 645 | + targetDiType = DiArgumentType.ARRAY.getArgumentType(); |
| 646 | + } |
| 647 | + |
| 648 | + if (targetDiType.isEmpty()) { |
| 649 | + return; |
| 650 | + } |
| 651 | + |
| 652 | + for (int i = 0; i < argumentType.getItemCount(); i++) { |
| 653 | + if (targetDiType.equals(argumentType.getItemAt(i).getKey())) { |
| 654 | + argumentType.setSelectedIndex(i); |
| 655 | + break; |
| 656 | + } |
| 657 | + } |
| 658 | + } |
| 659 | + |
621 | 660 | private DiArgumentData getDialogDataObject() { |
622 | 661 | if (targetArea.getSelectedItem() == null) { |
623 | 662 | showErrorMessage(new ValidatorBundle().message(NotEmptyRule.MESSAGE, TARGET_AREA)); |
|
0 commit comments