From 51c78ef47bc8fbe5dd1fd5927aba32b0646a1e4b Mon Sep 17 00:00:00 2001 From: Vitaliy Boyko Date: Mon, 26 Apr 2021 15:16:29 +0300 Subject: [PATCH] Fixed `Java.lang.IllegalArgumentException` During adding a new method into an existing plugin Adjusted plugin logo --- CHANGELOG.md | 4 ++++ resources/META-INF/pluginIcon.svg | 8 ++++++- .../PluginGenerateMethodHandlerBase.java | 22 +++++++++++++------ 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7e489060b..507100690 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0). ## 3.2.2 +### Fixed + +- `Java.lang.IllegalArgumentException` During adding a new method into an existing plugin + ## 3.2.1 ### Fixed diff --git a/resources/META-INF/pluginIcon.svg b/resources/META-INF/pluginIcon.svg index a79977df8..564f534c2 100644 --- a/resources/META-INF/pluginIcon.svg +++ b/resources/META-INF/pluginIcon.svg @@ -1 +1,7 @@ -Magento-colorAlexis Doreau \ No newline at end of file + + + + + + \ No newline at end of file diff --git a/src/com/magento/idea/magento2plugin/actions/generation/PluginGenerateMethodHandlerBase.java b/src/com/magento/idea/magento2plugin/actions/generation/PluginGenerateMethodHandlerBase.java index 2cb3b262d..c2fdb8ce8 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/PluginGenerateMethodHandlerBase.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/PluginGenerateMethodHandlerBase.java @@ -44,7 +44,6 @@ import gnu.trove.THashSet; import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; import java.util.Iterator; import java.util.List; import java.util.Locale; @@ -318,18 +317,27 @@ public static Collection fixOrderToBeAsOriginalFiles( final PhpNamedElementNode... selected ) { final List newSelected = ContainerUtil.newArrayList(selected); - Collections.sort(newSelected, (o1, o2) -> { + newSelected.sort((o1, o2) -> { final PsiElement psiElement = o1.getPsiElement(); final PsiElement psiElement2 = o2.getPsiElement(); final PsiFile containingFile = psiElement.getContainingFile(); final PsiFile containingFile2 = psiElement2.getContainingFile(); return containingFile.equals(containingFile2) - ? psiElement.getTextOffset() - psiElement2.getTextOffset() - : containingFile.getName().compareTo(containingFile2.getName()); + ? psiElement.getTextOffset() - psiElement2.getTextOffset() + : getDocumentPosition(containingFile, containingFile2); }); return newSelected; } + private static int getDocumentPosition( + final PsiFile containingFile, + final PsiFile containingFile2 + ) { + return containingFile.getVirtualFile().getPresentableUrl().compareTo( + containingFile2.getVirtualFile().getPresentableUrl() + ); + } + private static int getSuitableEditorPosition(final Editor editor, final PhpFile phpFile) { final PsiElement currElement = phpFile.findElementAt(editor.getCaretModel().getOffset()); if (currElement != null) { @@ -371,9 +379,9 @@ private static boolean isClassMember(final PsiElement element) { return false; } final IElementType elementType = element.getNode().getElementType(); - return elementType == PhpElementTypes.CLASS_FIELDS - || elementType == PhpElementTypes.CLASS_CONSTANTS - || elementType == PhpStubElementTypes.CLASS_METHOD; + return elementType.equals(PhpElementTypes.CLASS_FIELDS) + || elementType.equals(PhpElementTypes.CLASS_CONSTANTS) + || elementType.equals(PhpStubElementTypes.CLASS_METHOD); } private static int getNextPos(final PsiElement element) {