'Implement methods' fix was bound to an error

This commit is contained in:
svtk
2011-11-22 14:32:49 +04:00
parent 159865d751
commit ed4dc03b16
4 changed files with 48 additions and 8 deletions
@@ -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
change.to.backing.field=Change reference to backing field
implement.members=Implement members
@@ -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<JetIntentionActionFactory> 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<IntentionAction> actions = QuickFixes.get(diagnostic.getFactory());
for (IntentionAction action : actions) {
annotation.registerFix(action);
}
}
}
}
@@ -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<CallableMemberDescriptor> collectMethodsToGenerate(MutableClassDescriptor descriptor) {
Set<CallableMemberDescriptor> 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);
}
}
@@ -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<PsiElementOnlyDiagnosticFactory, JetIntentionActionFactory> actionMap = HashMultimap.create();
private static final Multimap<PsiElementOnlyDiagnosticFactory, JetIntentionActionFactory> jetActionMap = HashMultimap.create();
private static final Multimap<DiagnosticFactory, IntentionAction> actionMap = HashMultimap.create();
public static Collection<JetIntentionActionFactory> get(PsiElementOnlyDiagnosticFactory diagnosticFactory) {
return jetActionMap.get(diagnosticFactory);
}
public static Collection<IntentionAction> get(DiagnosticFactory diagnosticFactory) {
return actionMap.get(diagnosticFactory);
}
private QuickFixes() {}
private static <T extends PsiElement> void add(PsiElementOnlyDiagnosticFactory<? extends T> diagnosticFactory, JetIntentionActionFactory<T> 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);
}
}