From ed4dc03b167623954d24936c951d80e77e0330a5 Mon Sep 17 00:00:00 2001 From: svtk Date: Tue, 22 Nov 2011 14:32:49 +0400 Subject: [PATCH] 'Implement methods' fix was bound to an error --- .../jetbrains/jet/plugin/JetBundle.properties | 3 ++- .../jet/plugin/annotations/JetPsiChecker.java | 11 +++++--- .../codeInsight/ImplementMethodsHandler.java | 26 ++++++++++++++++++- .../jet/plugin/quickfix/QuickFixes.java | 16 ++++++++++-- 4 files changed, 48 insertions(+), 8 deletions(-) diff --git a/idea/src/org/jetbrains/jet/plugin/JetBundle.properties b/idea/src/org/jetbrains/jet/plugin/JetBundle.properties index ef9ad9587b6..117e0088faa 100644 --- a/idea/src/org/jetbrains/jet/plugin/JetBundle.properties +++ b/idea/src/org/jetbrains/jet/plugin/JetBundle.properties @@ -24,4 +24,5 @@ remove.elvis.operator=Remove elvis operator replace.operation.in.binary.expression=Replace operation in a binary expression replace.cast.with.static.assert=Replace a cast with a static assert replace.with.dot.call=Replace with dot call -change.to.backing.field=Change reference to backing field \ No newline at end of file +change.to.backing.field=Change reference to backing field +implement.members=Implement members \ No newline at end of file diff --git a/idea/src/org/jetbrains/jet/plugin/annotations/JetPsiChecker.java b/idea/src/org/jetbrains/jet/plugin/annotations/JetPsiChecker.java index 59e3586d793..17353d877d8 100644 --- a/idea/src/org/jetbrains/jet/plugin/annotations/JetPsiChecker.java +++ b/idea/src/org/jetbrains/jet/plugin/annotations/JetPsiChecker.java @@ -89,21 +89,24 @@ public class JetPsiChecker implements Annotator { else if (diagnostic.getSeverity() == Severity.WARNING) { annotation = holder.createWarningAnnotation(diagnostic.getFactory().getTextRange(diagnostic), getMessage(diagnostic)); } - if (annotation != null && diagnostic instanceof DiagnosticWithPsiElementImpl) { - DiagnosticWithPsiElement diagnosticWithPsiElement = (DiagnosticWithPsiElement) diagnostic; - if (diagnostic.getFactory() instanceof PsiElementOnlyDiagnosticFactory) { + if (annotation != null) { + if (diagnostic instanceof DiagnosticWithPsiElementImpl && diagnostic.getFactory() instanceof PsiElementOnlyDiagnosticFactory) { PsiElementOnlyDiagnosticFactory factory = (PsiElementOnlyDiagnosticFactory) diagnostic.getFactory(); Collection intentionActionFactories = QuickFixes.get(factory); for (JetIntentionActionFactory intentionActionFactory : intentionActionFactories) { IntentionAction action = null; if (intentionActionFactory != null) { - action = intentionActionFactory.createAction(diagnosticWithPsiElement); + action = intentionActionFactory.createAction((DiagnosticWithPsiElement) diagnostic); } if (action != null) { annotation.registerFix(action); } } } + Collection actions = QuickFixes.get(diagnostic.getFactory()); + for (IntentionAction action : actions) { + annotation.registerFix(action); + } } } } diff --git a/idea/src/org/jetbrains/jet/plugin/codeInsight/ImplementMethodsHandler.java b/idea/src/org/jetbrains/jet/plugin/codeInsight/ImplementMethodsHandler.java index abf648878ea..4917fd2642e 100644 --- a/idea/src/org/jetbrains/jet/plugin/codeInsight/ImplementMethodsHandler.java +++ b/idea/src/org/jetbrains/jet/plugin/codeInsight/ImplementMethodsHandler.java @@ -1,15 +1,22 @@ package org.jetbrains.jet.plugin.codeInsight; import com.google.common.collect.Sets; +import com.intellij.codeInsight.daemon.QuickFixBundle; +import com.intellij.codeInsight.intention.IntentionAction; +import com.intellij.openapi.editor.Editor; +import com.intellij.openapi.project.Project; +import com.intellij.psi.PsiFile; +import org.jetbrains.annotations.NotNull; import org.jetbrains.jet.lang.descriptors.*; import org.jetbrains.jet.lang.resolve.OverrideResolver; +import org.jetbrains.jet.plugin.JetBundle; import java.util.Set; /** * @author yole */ -public class ImplementMethodsHandler extends OverrideImplementMethodsHandler { +public class ImplementMethodsHandler extends OverrideImplementMethodsHandler implements IntentionAction { protected Set collectMethodsToGenerate(MutableClassDescriptor descriptor) { Set missingImplementations = Sets.newLinkedHashSet(); OverrideResolver.collectMissingImplementations(descriptor, missingImplementations, missingImplementations); @@ -19,4 +26,21 @@ public class ImplementMethodsHandler extends OverrideImplementMethodsHandler { protected String getChooserTitle() { return "Implement Members"; } + + @NotNull + @Override + public String getText() { + return JetBundle.message("implement.members"); + } + + @NotNull + @Override + public String getFamilyName() { + return JetBundle.message("implement.members"); + } + + @Override + public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) { + return isValidFor(editor, file); + } } diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/QuickFixes.java b/idea/src/org/jetbrains/jet/plugin/quickfix/QuickFixes.java index 356bc3237df..8c816241a4c 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/QuickFixes.java +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/QuickFixes.java @@ -2,13 +2,16 @@ package org.jetbrains.jet.plugin.quickfix; import com.google.common.collect.HashMultimap; import com.google.common.collect.Multimap; +import com.intellij.codeInsight.intention.IntentionAction; import com.intellij.psi.PsiElement; +import org.jetbrains.jet.lang.diagnostics.DiagnosticFactory; import org.jetbrains.jet.lang.diagnostics.DiagnosticParameters; import org.jetbrains.jet.lang.diagnostics.Errors; import org.jetbrains.jet.lang.diagnostics.PsiElementOnlyDiagnosticFactory; import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lexer.JetToken; import org.jetbrains.jet.lexer.JetTokens; +import org.jetbrains.jet.plugin.codeInsight.ImplementMethodsHandler; import java.util.Collection; @@ -16,16 +19,21 @@ import java.util.Collection; * @author svtk */ public class QuickFixes { - private static final Multimap actionMap = HashMultimap.create(); + private static final Multimap jetActionMap = HashMultimap.create(); + private static final Multimap actionMap = HashMultimap.create(); public static Collection get(PsiElementOnlyDiagnosticFactory diagnosticFactory) { + return jetActionMap.get(diagnosticFactory); + } + + public static Collection get(DiagnosticFactory diagnosticFactory) { return actionMap.get(diagnosticFactory); } private QuickFixes() {} private static void add(PsiElementOnlyDiagnosticFactory diagnosticFactory, JetIntentionActionFactory actionFactory) { - actionMap.put(diagnosticFactory, actionFactory); + jetActionMap.put(diagnosticFactory, actionFactory); } static { @@ -108,5 +116,9 @@ public class QuickFixes { add(Errors.PUBLIC_MEMBER_SHOULD_SPECIFY_TYPE, AddReturnTypeFix.createFactory()); add(Errors.INITIALIZATION_USING_BACKING_FIELD, ChangeToBackingFieldFix.createFactory()); + + ImplementMethodsHandler implementMethodsHandler = new ImplementMethodsHandler(); + actionMap.put(Errors.ABSTRACT_MEMBER_NOT_IMPLEMENTED, implementMethodsHandler); + actionMap.put(Errors.MANY_IMPL_MEMBER_NOT_IMPLEMENTED, implementMethodsHandler); } } \ No newline at end of file