From ced2abb8602aa820eb50a8115b6653e3a04ac3a3 Mon Sep 17 00:00:00 2001 From: Valentin Kipyatkov Date: Wed, 13 Aug 2014 13:48:37 +0400 Subject: [PATCH] Converted AutoImportFix to Kotlin --- .../codeInsight/daemon/impl/annotations.xml | 5 + .../com/intellij/psi/search/annotations.xml | 6 + .../quickfix/JetIntentionActionsFactory.java | 2 +- .../plugin/quickfix/AddWhenElseBranchFix.java | 2 +- .../jet/plugin/quickfix/AutoImportFix.java | 320 ------------------ .../jet/plugin/quickfix/AutoImportFix.kt | 189 +++++++++++ .../quickfix/ChangeFunctionReturnTypeFix.java | 2 +- .../quickfix/ChangeFunctionSignatureFix.java | 4 +- .../quickfix/ChangeVariableTypeFix.java | 2 +- .../quickfix/CreateFunctionFromUsageFix.kt | 20 +- .../JetSingleIntentionActionFactory.java | 4 +- .../quickfix/MakeOverriddenMemberOpenFix.java | 2 +- .../QuickFixFactoryForTypeMismatchError.java | 2 +- .../plugin/quickfix/QuickFixRegistrar.java | 2 +- .../plugin/quickfix/RemoveModifierFix.java | 2 +- 15 files changed, 222 insertions(+), 342 deletions(-) create mode 100644 annotations/com/intellij/codeInsight/daemon/impl/annotations.xml create mode 100644 annotations/com/intellij/psi/search/annotations.xml delete mode 100644 idea/src/org/jetbrains/jet/plugin/quickfix/AutoImportFix.java create mode 100644 idea/src/org/jetbrains/jet/plugin/quickfix/AutoImportFix.kt diff --git a/annotations/com/intellij/codeInsight/daemon/impl/annotations.xml b/annotations/com/intellij/codeInsight/daemon/impl/annotations.xml new file mode 100644 index 00000000000..7fad54a6f0a --- /dev/null +++ b/annotations/com/intellij/codeInsight/daemon/impl/annotations.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/annotations/com/intellij/psi/search/annotations.xml b/annotations/com/intellij/psi/search/annotations.xml new file mode 100644 index 00000000000..7aa0d5245cf --- /dev/null +++ b/annotations/com/intellij/psi/search/annotations.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/idea/idea-analysis/src/org/jetbrains/jet/plugin/quickfix/JetIntentionActionsFactory.java b/idea/idea-analysis/src/org/jetbrains/jet/plugin/quickfix/JetIntentionActionsFactory.java index 953acf3469b..e6baa65717e 100644 --- a/idea/idea-analysis/src/org/jetbrains/jet/plugin/quickfix/JetIntentionActionsFactory.java +++ b/idea/idea-analysis/src/org/jetbrains/jet/plugin/quickfix/JetIntentionActionsFactory.java @@ -25,5 +25,5 @@ import java.util.List; public interface JetIntentionActionsFactory { @NotNull - List createActions(Diagnostic diagnostic); + List createActions(@NotNull Diagnostic diagnostic); } diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/AddWhenElseBranchFix.java b/idea/src/org/jetbrains/jet/plugin/quickfix/AddWhenElseBranchFix.java index e9ff0c01031..498db49b6b5 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/AddWhenElseBranchFix.java +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/AddWhenElseBranchFix.java @@ -82,7 +82,7 @@ public class AddWhenElseBranchFix extends JetIntentionAction return new JetSingleIntentionActionFactory() { @Nullable @Override - public JetIntentionAction createAction(Diagnostic diagnostic) { + public JetIntentionAction createAction(@NotNull Diagnostic diagnostic) { PsiElement element = diagnostic.getPsiElement(); JetWhenExpression whenExpression = PsiTreeUtil.getParentOfType(element, JetWhenExpression.class, false); if (whenExpression == null) return null; diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/AutoImportFix.java b/idea/src/org/jetbrains/jet/plugin/quickfix/AutoImportFix.java deleted file mode 100644 index 92e641dbec8..00000000000 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/AutoImportFix.java +++ /dev/null @@ -1,320 +0,0 @@ -/* - * Copyright 2010-2013 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.jet.plugin.quickfix; - -import com.google.common.base.Function; -import com.google.common.base.Predicate; -import com.google.common.collect.Collections2; -import com.google.common.collect.Lists; -import com.google.common.collect.Sets; -import com.intellij.codeInsight.daemon.impl.ShowAutoImportPass; -import com.intellij.codeInsight.hint.HintManager; -import com.intellij.codeInsight.intention.HighPriorityAction; -import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.command.CommandProcessor; -import com.intellij.openapi.editor.Editor; -import com.intellij.openapi.module.Module; -import com.intellij.openapi.module.ModuleUtilCore; -import com.intellij.openapi.project.Project; -import com.intellij.psi.PsiClass; -import com.intellij.psi.PsiFile; -import com.intellij.psi.search.GlobalSearchScope; -import com.intellij.psi.search.PsiShortNamesCache; -import com.intellij.util.IncorrectOperationException; -import kotlin.Function1; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import org.jetbrains.jet.lang.descriptors.ClassDescriptor; -import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor; -import org.jetbrains.jet.lang.descriptors.FunctionDescriptor; -import org.jetbrains.jet.lang.diagnostics.Diagnostic; -import org.jetbrains.jet.lang.psi.JetExpression; -import org.jetbrains.jet.lang.psi.JetFile; -import org.jetbrains.jet.lang.psi.JetPsiUtil; -import org.jetbrains.jet.lang.psi.JetSimpleNameExpression; -import org.jetbrains.jet.lang.psi.psiUtil.PsiUtilPackage; -import org.jetbrains.jet.lang.resolve.DescriptorUtils; -import org.jetbrains.jet.lang.resolve.ImportPath; -import org.jetbrains.jet.lang.resolve.lazy.KotlinCodeAnalyzer; -import org.jetbrains.jet.lang.resolve.name.FqName; -import org.jetbrains.jet.lang.resolve.name.Name; -import org.jetbrains.jet.plugin.JetBundle; -import org.jetbrains.jet.plugin.actions.JetAddImportAction; -import org.jetbrains.jet.plugin.caches.JetShortNamesCache; -import org.jetbrains.jet.plugin.caches.KotlinIndicesHelper; -import org.jetbrains.jet.plugin.caches.resolve.ResolvePackage; -import org.jetbrains.jet.plugin.project.ProjectStructureUtil; -import org.jetbrains.jet.plugin.project.ResolveSessionForBodies; -import org.jetbrains.jet.plugin.util.JetPsiHeuristicsUtil; - -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.Set; - -/** - * Check possibility and perform fix for unresolved references. - */ -public class AutoImportFix extends JetHintAction implements HighPriorityAction { - - @NotNull - private final Collection suggestions; - - public AutoImportFix(@NotNull JetSimpleNameExpression element) { - super(element); - suggestions = computeSuggestions(element); - } - - private static Collection computeSuggestions(@NotNull JetSimpleNameExpression element) { - final PsiFile file = element.getContainingFile(); - if (!(file instanceof JetFile)) { - return Collections.emptyList(); - } - - String referenceName = element.getReferencedName(); - if (element.getIdentifier() == null) { - Name conventionName = JetPsiUtil.getConventionName(element); - if (conventionName != null) { - referenceName = conventionName.asString(); - } - } - - if (referenceName.isEmpty()) { - return Collections.emptyList(); - } - - ResolveSessionForBodies resolveSessionForBodies = ResolvePackage.getLazyResolveSession(element); - - Module module = ModuleUtilCore.findModuleForPsiElement(file); - if (module == null) return Collections.emptyList(); - GlobalSearchScope searchScope = GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module); - - List result = Lists.newArrayList(); - if (!isSuppressedTopLevelImportInPosition(element)) { - result.addAll(getClassNames(referenceName, (JetFile) file, searchScope, resolveSessionForBodies)); - result.addAll(getJetTopLevelFunctions(referenceName, element, searchScope, resolveSessionForBodies, file.getProject())); - } - - result.addAll(getJetExtensionFunctions(referenceName, element, searchScope, resolveSessionForBodies, file.getProject())); - - return Collections2.filter(result, new Predicate() { - @Override - public boolean apply(@Nullable FqName fqName) { - assert fqName != null; - return ImportInsertHelper.needImport(new ImportPath(fqName, false), (JetFile) file); - } - }); - } - - private static boolean isSuppressedTopLevelImportInPosition(@NotNull JetSimpleNameExpression element) { - return PsiUtilPackage.isImportDirectiveExpression(element) || JetPsiUtil.isSelectorInQualified(element); - } - - private static Collection getJetTopLevelFunctions( - @NotNull String referenceName, - @NotNull JetExpression context, - @NotNull GlobalSearchScope searchScope, - @NotNull ResolveSessionForBodies resolveSession, - @NotNull Project project - ) { - Collection topLevelFunctions = new KotlinIndicesHelper(project).getTopLevelFunctionDescriptorsByName( - referenceName, context, resolveSession, searchScope); - - return Sets.newHashSet(Collections2.transform(topLevelFunctions, new Function() { - @Override - public FqName apply(@Nullable DeclarationDescriptor declarationDescriptor) { - assert declarationDescriptor != null; - return DescriptorUtils.getFqNameSafe(declarationDescriptor); - } - })); - } - - private static Collection getJetExtensionFunctions( - @NotNull final String referenceName, - @NotNull JetSimpleNameExpression expression, - @NotNull GlobalSearchScope searchScope, - @NotNull ResolveSessionForBodies resolveSession, - @NotNull Project project - ) { - Collection jetCallableExtensions = new KotlinIndicesHelper(project).getCallableExtensions( - new Function1() { - @Override - public Boolean invoke(String callableExtensionName) { - return callableExtensionName.equals(referenceName); - } - }, - expression, - resolveSession, - searchScope); - - return Sets.newHashSet(Collections2.transform(jetCallableExtensions, new Function() { - @Override - public FqName apply(@Nullable DeclarationDescriptor declarationDescriptor) { - assert declarationDescriptor != null; - return DescriptorUtils.getFqNameSafe(declarationDescriptor); - } - })); - } - - /* - * Searches for possible class names in kotlin context and java facade. - */ - public static Collection getClassNames(@NotNull String referenceName, @NotNull JetFile file, @NotNull GlobalSearchScope searchScope, @NotNull KotlinCodeAnalyzer analyzer) { - Set possibleResolveNames = Sets.newHashSet(); - - if (!ProjectStructureUtil.isJsKotlinModule(file)) { - possibleResolveNames.addAll(getClassesFromCache(referenceName, searchScope, file)); - } - else { - possibleResolveNames.addAll(getJetClasses(referenceName, searchScope, file.getProject(), analyzer)); - } - - // TODO: Do appropriate sorting - return Lists.newArrayList(possibleResolveNames); - } - - private static Collection getClassesFromCache(@NotNull String typeName, @NotNull GlobalSearchScope searchScope, @NotNull final JetFile file) { - PsiShortNamesCache cache = getShortNamesCache(file); - - PsiClass[] classes = cache.getClassesByName(typeName, searchScope); - - Collection accessibleClasses = Collections2.filter(Lists.newArrayList(classes), new Predicate() { - @Override - public boolean apply(PsiClass psiClass) { - assert psiClass != null; - return JetPsiHeuristicsUtil.isAccessible(psiClass, file); - } - }); - - return Collections2.transform(accessibleClasses, new Function() { - @Nullable - @Override - public FqName apply(@Nullable PsiClass javaClass) { - assert javaClass != null; - String qualifiedName = javaClass.getQualifiedName(); - assert qualifiedName != null; - return new FqName(qualifiedName); - } - }); - } - - private static PsiShortNamesCache getShortNamesCache(@NotNull JetFile jetFile) { - if (ProjectStructureUtil.isJsKotlinModule(jetFile)) { - return JetShortNamesCache.OBJECT$.getKotlinInstance(jetFile.getProject()); - } - - return PsiShortNamesCache.getInstance(jetFile.getProject()); - } - - private static Collection getJetClasses(@NotNull final String typeName, @NotNull GlobalSearchScope searchScope, @NotNull Project project, @NotNull KotlinCodeAnalyzer resolveSession) { - Collection descriptors = new KotlinIndicesHelper(project).getClassDescriptorsByName(typeName, resolveSession, searchScope); - - return Collections2.transform(descriptors, new Function() { - @Override - public FqName apply(ClassDescriptor descriptor) { - return DescriptorUtils.getFqNameSafe(descriptor); - } - }); - } - - @Override - public boolean showHint(@NotNull Editor editor) { - if (suggestions.isEmpty()) { - return false; - } - - Project project = editor.getProject(); - if (project == null) { - return false; - } - - if (HintManager.getInstance().hasShownHintsThatWillHideByOtherHint(true)) { - return false; - } - - if (!ApplicationManager.getApplication().isUnitTestMode()) { - String hintText = ShowAutoImportPass.getMessage(suggestions.size() > 1, suggestions.iterator().next().asString()); - - HintManager.getInstance().showQuestionHint( - editor, hintText, - element.getTextOffset(), element.getTextRange().getEndOffset(), - createAction(project, editor)); - } - - return true; - } - - @Override - @NotNull - public String getText() { - return JetBundle.message("import.fix"); - } - - @Override - @NotNull - public String getFamilyName() { - return JetBundle.message("import.fix"); - } - - @Override - public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) { - return super.isAvailable(project, editor, file) && !suggestions.isEmpty(); - } - - @Override - public void invoke(@NotNull final Project project, @NotNull final Editor editor, JetFile file) - throws IncorrectOperationException { - CommandProcessor.getInstance().runUndoTransparentAction(new Runnable() { - @Override - public void run() { - createAction(project, editor).execute(); - } - }); - } - - @Override - public boolean startInWriteAction() { - return true; - } - - @NotNull - private JetAddImportAction createAction(@NotNull Project project, @NotNull Editor editor) { - return new JetAddImportAction(project, editor, element, suggestions); - } - - @Nullable - public static JetSingleIntentionActionFactory createFactory() { - return new JetSingleIntentionActionFactory() { - @Nullable - @Override - public JetIntentionAction createAction(@NotNull Diagnostic diagnostic) { - // There could be different psi elements (i.e. JetArrayAccessExpression), but we can fix only JetSimpleNameExpression case - if (diagnostic.getPsiElement() instanceof JetSimpleNameExpression) { - JetSimpleNameExpression psiElement = (JetSimpleNameExpression) diagnostic.getPsiElement(); - return new AutoImportFix(psiElement); - } - - return null; - } - - @Override - public boolean isApplicableForCodeFragment() { - return true; - } - }; - } -} diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/AutoImportFix.kt b/idea/src/org/jetbrains/jet/plugin/quickfix/AutoImportFix.kt new file mode 100644 index 00000000000..096a5d04326 --- /dev/null +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/AutoImportFix.kt @@ -0,0 +1,189 @@ +/* + * Copyright 2010-2014 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.jet.plugin.quickfix + +import com.google.common.collect.Lists +import com.intellij.codeInsight.daemon.impl.ShowAutoImportPass +import com.intellij.codeInsight.hint.HintManager +import com.intellij.codeInsight.intention.HighPriorityAction +import com.intellij.openapi.application.ApplicationManager +import com.intellij.openapi.command.CommandProcessor +import com.intellij.openapi.editor.Editor +import com.intellij.openapi.module.ModuleUtilCore +import com.intellij.openapi.project.Project +import com.intellij.psi.PsiFile +import com.intellij.psi.search.GlobalSearchScope +import com.intellij.psi.search.PsiShortNamesCache +import org.jetbrains.jet.lang.diagnostics.Diagnostic +import org.jetbrains.jet.lang.psi.JetExpression +import org.jetbrains.jet.lang.psi.JetFile +import org.jetbrains.jet.lang.psi.JetPsiUtil +import org.jetbrains.jet.lang.psi.JetSimpleNameExpression +import org.jetbrains.jet.lang.psi.psiUtil.* +import org.jetbrains.jet.lang.resolve.DescriptorUtils +import org.jetbrains.jet.lang.resolve.ImportPath +import org.jetbrains.jet.lang.resolve.lazy.KotlinCodeAnalyzer +import org.jetbrains.jet.lang.resolve.name.FqName +import org.jetbrains.jet.plugin.JetBundle +import org.jetbrains.jet.plugin.actions.JetAddImportAction +import org.jetbrains.jet.plugin.caches.JetShortNamesCache +import org.jetbrains.jet.plugin.caches.KotlinIndicesHelper +import org.jetbrains.jet.plugin.caches.resolve.* +import org.jetbrains.jet.plugin.project.ProjectStructureUtil +import org.jetbrains.jet.plugin.project.ResolveSessionForBodies +import org.jetbrains.jet.plugin.util.JetPsiHeuristicsUtil +import java.util.ArrayList +import com.intellij.codeInsight.intention.IntentionAction + +/** + * Check possibility and perform fix for unresolved references. + */ +public class AutoImportFix(element: JetSimpleNameExpression) : JetHintAction(element), HighPriorityAction { + + private val suggestions: Collection = computeSuggestions(element) + + override fun showHint(editor: Editor): Boolean { + if (suggestions.isEmpty()) return false + val project = editor.getProject() ?: return false + + if (HintManager.getInstance().hasShownHintsThatWillHideByOtherHint(true)) return false + + if (!ApplicationManager.getApplication()!!.isUnitTestMode()) { + val hintText = ShowAutoImportPass.getMessage(suggestions.size() > 1, suggestions.first().asString()) + + HintManager.getInstance().showQuestionHint(editor, hintText, element.getTextOffset(), element.getTextRange()!!.getEndOffset(), createAction(project, editor)) + } + + return true + } + + override fun getText() + = JetBundle.message("import.fix") + + override fun getFamilyName() + = JetBundle.message("import.fix") + + override fun isAvailable(project: Project, editor: Editor, file: PsiFile) + = super< JetHintAction>.isAvailable(project, editor, file) && !suggestions.isEmpty() + + override fun invoke(project: Project, editor: Editor?, file: JetFile?) { + CommandProcessor.getInstance().runUndoTransparentAction { + createAction(project, editor!!).execute() + } + } + + override fun startInWriteAction() + = true + + private fun createAction(project: Project, editor: Editor) + = JetAddImportAction(project, editor, element, suggestions) + + private fun computeSuggestions(element: JetSimpleNameExpression): Collection { + val file = element.getContainingFile() as? JetFile ?: return listOf() + + var referenceName = element.getReferencedName() + if (element.getIdentifier() == null) { + val conventionName = JetPsiUtil.getConventionName(element) + if (conventionName != null) { + referenceName = conventionName.asString() + } + } + + if (referenceName.isEmpty()) return listOf() + + val resolveSessionForBodies = element.getLazyResolveSession() + + val module = ModuleUtilCore.findModuleForPsiElement(file) ?: return listOf() + val searchScope = GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module) + + val result = ArrayList() + if (!isSuppressedTopLevelImportInPosition(element)) { + result.addAll(getClassNames(referenceName, file, searchScope, resolveSessionForBodies)) + result.addAll(getJetTopLevelFunctions(referenceName, element, searchScope, resolveSessionForBodies, file.getProject())) + } + + result.addAll(getJetExtensionFunctions(referenceName, element, searchScope, resolveSessionForBodies, file.getProject())) + + return result.filter { ImportInsertHelper.needImport(ImportPath(it, false), file) } + } + + private fun isSuppressedTopLevelImportInPosition(element: JetSimpleNameExpression) + = element.isImportDirectiveExpression() || JetPsiUtil.isSelectorInQualified(element) + + private fun getJetTopLevelFunctions(referenceName: String, context: JetExpression, searchScope: GlobalSearchScope, resolveSession: ResolveSessionForBodies, project: Project): Collection + = KotlinIndicesHelper(project).getTopLevelFunctionDescriptorsByName(referenceName, context, resolveSession, searchScope) + .map { DescriptorUtils.getFqNameSafe(it) } + .toSet() + + private fun getJetExtensionFunctions(referenceName: String, expression: JetSimpleNameExpression, searchScope: GlobalSearchScope, resolveSession: ResolveSessionForBodies, project: Project): Collection + = KotlinIndicesHelper(project).getCallableExtensions({ it == referenceName}, expression, resolveSession, searchScope) + .map { DescriptorUtils.getFqNameSafe(it) } + .toSet() + + /* + * Searches for possible class names in kotlin context and java facade. + */ + private fun getClassNames(referenceName: String, file: JetFile, searchScope: GlobalSearchScope, analyzer: KotlinCodeAnalyzer): Collection { + val possibleResolveNames = if (!ProjectStructureUtil.isJsKotlinModule(file)) { + getClassesFromCache(referenceName, searchScope, file) + } + else { + getJetClasses(referenceName, searchScope, file.getProject(), analyzer) + } + + // TODO: Do appropriate sorting + return Lists.newArrayList(possibleResolveNames) + } + + private fun getClassesFromCache(typeName: String, searchScope: GlobalSearchScope, file: JetFile): Collection + = getShortNamesCache(file).getClassesByName(typeName, searchScope) + .filter { JetPsiHeuristicsUtil.isAccessible(it, file) } + .map { FqName(it.getQualifiedName()!!) } + .toSet() + + private fun getShortNamesCache(jetFile: JetFile): PsiShortNamesCache { + if (ProjectStructureUtil.isJsKotlinModule(jetFile)) { + return JetShortNamesCache.getKotlinInstance(jetFile.getProject()) + } + + return PsiShortNamesCache.getInstance(jetFile.getProject()) + } + + private fun getJetClasses(typeName: String, searchScope: GlobalSearchScope, project: Project, resolveSession: KotlinCodeAnalyzer): Collection + = KotlinIndicesHelper(project).getClassDescriptorsByName(typeName, resolveSession, searchScope) + .map { DescriptorUtils.getFqNameSafe(it) } + .toSet() + + class object { + public fun createFactory(): JetSingleIntentionActionFactory { + return object : JetSingleIntentionActionFactory() { + override fun createAction(diagnostic: Diagnostic): JetIntentionAction? { + // There could be different psi elements (i.e. JetArrayAccessExpression), but we can fix only JetSimpleNameExpression case + val psiElement = diagnostic.getPsiElement() + if (psiElement is JetSimpleNameExpression) { + return AutoImportFix(psiElement) + } + + return null + } + + override fun isApplicableForCodeFragment() + = true + } + } + } +} diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/ChangeFunctionReturnTypeFix.java b/idea/src/org/jetbrains/jet/plugin/quickfix/ChangeFunctionReturnTypeFix.java index 13913233f8f..9bd064d6514 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/ChangeFunctionReturnTypeFix.java +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/ChangeFunctionReturnTypeFix.java @@ -202,7 +202,7 @@ public class ChangeFunctionReturnTypeFix extends JetIntentionAction return new JetIntentionActionsFactory() { @NotNull @Override - public List createActions(Diagnostic diagnostic) { + public List createActions(@NotNull Diagnostic diagnostic) { List actions = new LinkedList(); JetFunction function = QuickFixUtil.getParentElementOfType(diagnostic, JetFunction.class); diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/ChangeFunctionSignatureFix.java b/idea/src/org/jetbrains/jet/plugin/quickfix/ChangeFunctionSignatureFix.java index 47995fb3609..0abc68f433c 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/ChangeFunctionSignatureFix.java +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/ChangeFunctionSignatureFix.java @@ -142,7 +142,7 @@ public abstract class ChangeFunctionSignatureFix extends JetIntentionAction createActions(Diagnostic diagnostic) { + public List createActions(@NotNull Diagnostic diagnostic) { List actions = new LinkedList(); JetProperty property = QuickFixUtil.getParentElementOfType(diagnostic, JetProperty.class); diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/CreateFunctionFromUsageFix.kt b/idea/src/org/jetbrains/jet/plugin/quickfix/CreateFunctionFromUsageFix.kt index df9e186e1b1..e299503ca40 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/CreateFunctionFromUsageFix.kt +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/CreateFunctionFromUsageFix.kt @@ -872,7 +872,7 @@ public class CreateFunctionFromUsageFix internal ( class object { public fun createCreateGetFunctionFromUsageFactory(): JetSingleIntentionActionFactory { return object : JetSingleIntentionActionFactory() { - override fun createAction(diagnostic: Diagnostic?): IntentionAction? { + override fun createAction(diagnostic: Diagnostic): IntentionAction? { val accessExpr = QuickFixUtil.getParentElementOfType(diagnostic, javaClass()) ?: return null val arrayExpr = accessExpr.getArrayExpression() ?: return null val arrayType = TypeOrExpressionThereof(arrayExpr, Variance.IN_VARIANCE) @@ -889,7 +889,7 @@ public class CreateFunctionFromUsageFix internal ( public fun createCreateSetFunctionFromUsageFactory(): JetSingleIntentionActionFactory { return object : JetSingleIntentionActionFactory() { - override fun createAction(diagnostic: Diagnostic?): IntentionAction? { + override fun createAction(diagnostic: Diagnostic): IntentionAction? { val accessExpr = QuickFixUtil.getParentElementOfType(diagnostic, javaClass()) ?: return null val arrayExpr = accessExpr.getArrayExpression() ?: return null val arrayType = TypeOrExpressionThereof(arrayExpr, Variance.IN_VARIANCE) @@ -911,8 +911,8 @@ public class CreateFunctionFromUsageFix internal ( public fun createCreateHasNextFunctionFromUsageFactory(): JetSingleIntentionActionFactory { return object : JetSingleIntentionActionFactory() { - override fun createAction(diagnostic: Diagnostic?): IntentionAction? { - val diagnosticWithParameters = DiagnosticFactory.cast(diagnostic!!, Errors.HAS_NEXT_MISSING, Errors.HAS_NEXT_FUNCTION_NONE_APPLICABLE) + override fun createAction(diagnostic: Diagnostic): IntentionAction? { + val diagnosticWithParameters = DiagnosticFactory.cast(diagnostic, Errors.HAS_NEXT_MISSING, Errors.HAS_NEXT_FUNCTION_NONE_APPLICABLE) val ownerType = TypeOrExpressionThereof(diagnosticWithParameters.getA(), Variance.IN_VARIANCE) val forExpr = QuickFixUtil.getParentElementOfType(diagnostic, javaClass()) ?: return null @@ -924,8 +924,8 @@ public class CreateFunctionFromUsageFix internal ( public fun createCreateNextFunctionFromUsageFactory(): JetSingleIntentionActionFactory { return object : JetSingleIntentionActionFactory() { - override fun createAction(diagnostic: Diagnostic?): IntentionAction? { - val diagnosticWithParameters = DiagnosticFactory.cast(diagnostic!!, Errors.NEXT_MISSING, Errors.NEXT_NONE_APPLICABLE) + override fun createAction(diagnostic: Diagnostic): IntentionAction? { + val diagnosticWithParameters = DiagnosticFactory.cast(diagnostic, Errors.NEXT_MISSING, Errors.NEXT_NONE_APPLICABLE) val ownerType = TypeOrExpressionThereof(diagnosticWithParameters.getA(), Variance.IN_VARIANCE) val forExpr = QuickFixUtil.getParentElementOfType(diagnostic, javaClass()) ?: return null @@ -938,8 +938,8 @@ public class CreateFunctionFromUsageFix internal ( public fun createCreateIteratorFunctionFromUsageFactory(): JetSingleIntentionActionFactory { return object : JetSingleIntentionActionFactory() { - override fun createAction(diagnostic: Diagnostic?): IntentionAction? { - val file = diagnostic!!.getPsiFile() as? JetFile ?: return null + override fun createAction(diagnostic: Diagnostic): IntentionAction? { + val file = diagnostic.getPsiFile() as? JetFile ?: return null val forExpr = QuickFixUtil.getParentElementOfType(diagnostic, javaClass()) ?: return null val iterableExpr = forExpr.getLoopRange() ?: return null val variableExpr: JetExpression = ((forExpr.getLoopParameter() ?: forExpr.getMultiParameter()) ?: return null) as JetExpression @@ -961,8 +961,8 @@ public class CreateFunctionFromUsageFix internal ( public fun createCreateComponentFunctionFromUsageFactory(): JetSingleIntentionActionFactory { return object : JetSingleIntentionActionFactory() { - override fun createAction(diagnostic: Diagnostic?): IntentionAction? { - val diagnosticWithParameters = Errors.COMPONENT_FUNCTION_MISSING.cast(diagnostic!!) + override fun createAction(diagnostic: Diagnostic): IntentionAction? { + val diagnosticWithParameters = Errors.COMPONENT_FUNCTION_MISSING.cast(diagnostic) val name = diagnosticWithParameters.getA() val componentNumberMatcher = COMPONENT_FUNCTION_PATTERN.matcher(name.getIdentifier()) if (!componentNumberMatcher.matches()) return null diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/JetSingleIntentionActionFactory.java b/idea/src/org/jetbrains/jet/plugin/quickfix/JetSingleIntentionActionFactory.java index 5d8b7f7e74d..de9ccdd58d9 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/JetSingleIntentionActionFactory.java +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/JetSingleIntentionActionFactory.java @@ -28,11 +28,11 @@ import java.util.List; public abstract class JetSingleIntentionActionFactory implements JetIntentionActionsFactory { @Nullable - public abstract IntentionAction createAction(Diagnostic diagnostic); + public abstract IntentionAction createAction(@NotNull Diagnostic diagnostic); @NotNull @Override - public final List createActions(Diagnostic diagnostic) { + public final List createActions(@NotNull Diagnostic diagnostic) { List intentionActionList = new LinkedList(); if (diagnostic.getPsiElement().getContainingFile() instanceof JetCodeFragment && !isApplicableForCodeFragment()) { diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/MakeOverriddenMemberOpenFix.java b/idea/src/org/jetbrains/jet/plugin/quickfix/MakeOverriddenMemberOpenFix.java index 748186ae208..3c10f4557d7 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/MakeOverriddenMemberOpenFix.java +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/MakeOverriddenMemberOpenFix.java @@ -152,7 +152,7 @@ public class MakeOverriddenMemberOpenFix extends JetIntentionAction createActions(Diagnostic diagnostic) { + public List createActions(@NotNull Diagnostic diagnostic) { List actions = new LinkedList(); DiagnosticWithParameters2 diagnosticWithParameters = Errors.TYPE_MISMATCH.cast(diagnostic); diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/QuickFixRegistrar.java b/idea/src/org/jetbrains/jet/plugin/quickfix/QuickFixRegistrar.java index 1de3f9757d4..d9838299f5d 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/QuickFixRegistrar.java +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/QuickFixRegistrar.java @@ -111,7 +111,7 @@ public class QuickFixRegistrar { QuickFixes.factories.put(NO_BACKING_FIELD_CUSTOM_ACCESSORS, changeToPropertyNameFactory); QuickFixes.factories.put(INACCESSIBLE_BACKING_FIELD, changeToPropertyNameFactory); - JetSingleIntentionActionFactory unresolvedReferenceFactory = AutoImportFix.createFactory(); + JetSingleIntentionActionFactory unresolvedReferenceFactory = AutoImportFix.OBJECT$.createFactory(); QuickFixes.factories.put(UNRESOLVED_REFERENCE, unresolvedReferenceFactory); QuickFixes.factories.put(UNRESOLVED_REFERENCE_WRONG_RECEIVER, unresolvedReferenceFactory); diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/RemoveModifierFix.java b/idea/src/org/jetbrains/jet/plugin/quickfix/RemoveModifierFix.java index 1a3858f18e5..68c91d2b1e9 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/RemoveModifierFix.java +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/RemoveModifierFix.java @@ -123,7 +123,7 @@ public class RemoveModifierFix extends JetIntentionAction return new JetSingleIntentionActionFactory() { @Nullable @Override - public JetIntentionAction createAction(Diagnostic diagnostic) { + public JetIntentionAction createAction(@NotNull Diagnostic diagnostic) { JetModifierListOwner modifierListOwner = QuickFixUtil.getParentElementOfType(diagnostic, JetModifierListOwner.class); if (modifierListOwner == null) return null; PsiElement psiElement = diagnostic.getPsiElement();