From e94a9686f8ecec065f1bedf8b6301bbaf543f82e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Kypta?= Date: Fri, 17 Jul 2015 08:44:55 +0200 Subject: [PATCH] Fix #60 --- META-INF/plugin.xml | 5 +++-- src/com/avast/android/butterknifezelezny/InjectAction.java | 3 +++ src/com/avast/android/butterknifezelezny/common/Utils.java | 7 ++++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/META-INF/plugin.xml b/META-INF/plugin.xml index 86b2e5d..eee548d 100644 --- a/META-INF/plugin.xml +++ b/META-INF/plugin.xml @@ -1,7 +1,7 @@ eu.inmite.android.plugin.butterknifezelezny Android ButterKnife Zelezny - 1.4-SNAPSHOT + 1.3.2 Avast - 1.4-SNAPSHOT + 1.3.2 (7/17/2015)
    +
  • Fixed plugin crash (#60)
1.3.1 (7/16/2015) diff --git a/src/com/avast/android/butterknifezelezny/InjectAction.java b/src/com/avast/android/butterknifezelezny/InjectAction.java index 75e50b3..b741220 100644 --- a/src/com/avast/android/butterknifezelezny/InjectAction.java +++ b/src/com/avast/android/butterknifezelezny/InjectAction.java @@ -110,6 +110,9 @@ protected void showDialog(Project project, Editor editor, ArrayList ele PsiClass clazz = getTargetClass(editor, file); final IButterKnife butterKnife = ButterKnifeFactory.findButterKnifeForPsiElement(project, file); + if (butterKnife == null) { + return; + } // get parent classes and check if it's an adapter boolean createHolder = false; diff --git a/src/com/avast/android/butterknifezelezny/common/Utils.java b/src/com/avast/android/butterknifezelezny/common/Utils.java index 1693a30..b7a8d31 100644 --- a/src/com/avast/android/butterknifezelezny/common/Utils.java +++ b/src/com/avast/android/butterknifezelezny/common/Utils.java @@ -5,6 +5,7 @@ import com.avast.android.butterknifezelezny.model.Element; import com.intellij.ide.util.PropertiesComponent; import com.intellij.openapi.editor.Editor; +import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleUtil; import com.intellij.openapi.project.Project; import com.intellij.openapi.projectRoots.ProjectJdkTable; @@ -311,7 +312,11 @@ public static boolean isEmptyString(String text) { * @since 1.3 */ public static boolean isClassAvailableForPsiFile(@NotNull Project project, @NotNull PsiElement psiElement, @NotNull String className) { - GlobalSearchScope moduleScope = ModuleUtil.findModuleForPsiElement(psiElement).getModuleWithDependenciesAndLibrariesScope(false); + Module module = ModuleUtil.findModuleForPsiElement(psiElement); + if (module == null) { + return false; + } + GlobalSearchScope moduleScope = module.getModuleWithDependenciesAndLibrariesScope(false); PsiClass classInModule = JavaPsiFacade.getInstance(project).findClass(className, moduleScope); return classInModule != null; }