'Implement methods' fix was bound to an error
This commit is contained in:
@@ -25,3 +25,4 @@ replace.operation.in.binary.expression=Replace operation in a binary expression
|
|||||||
replace.cast.with.static.assert=Replace a cast with a static assert
|
replace.cast.with.static.assert=Replace a cast with a static assert
|
||||||
replace.with.dot.call=Replace with dot call
|
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) {
|
else if (diagnostic.getSeverity() == Severity.WARNING) {
|
||||||
annotation = holder.createWarningAnnotation(diagnostic.getFactory().getTextRange(diagnostic), getMessage(diagnostic));
|
annotation = holder.createWarningAnnotation(diagnostic.getFactory().getTextRange(diagnostic), getMessage(diagnostic));
|
||||||
}
|
}
|
||||||
if (annotation != null && diagnostic instanceof DiagnosticWithPsiElementImpl) {
|
if (annotation != null) {
|
||||||
DiagnosticWithPsiElement diagnosticWithPsiElement = (DiagnosticWithPsiElement) diagnostic;
|
if (diagnostic instanceof DiagnosticWithPsiElementImpl && diagnostic.getFactory() instanceof PsiElementOnlyDiagnosticFactory) {
|
||||||
if (diagnostic.getFactory() instanceof PsiElementOnlyDiagnosticFactory) {
|
|
||||||
PsiElementOnlyDiagnosticFactory factory = (PsiElementOnlyDiagnosticFactory) diagnostic.getFactory();
|
PsiElementOnlyDiagnosticFactory factory = (PsiElementOnlyDiagnosticFactory) diagnostic.getFactory();
|
||||||
Collection<JetIntentionActionFactory> intentionActionFactories = QuickFixes.get(factory);
|
Collection<JetIntentionActionFactory> intentionActionFactories = QuickFixes.get(factory);
|
||||||
for (JetIntentionActionFactory intentionActionFactory : intentionActionFactories) {
|
for (JetIntentionActionFactory intentionActionFactory : intentionActionFactories) {
|
||||||
IntentionAction action = null;
|
IntentionAction action = null;
|
||||||
if (intentionActionFactory != null) {
|
if (intentionActionFactory != null) {
|
||||||
action = intentionActionFactory.createAction(diagnosticWithPsiElement);
|
action = intentionActionFactory.createAction((DiagnosticWithPsiElement) diagnostic);
|
||||||
}
|
}
|
||||||
if (action != null) {
|
if (action != null) {
|
||||||
annotation.registerFix(action);
|
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;
|
package org.jetbrains.jet.plugin.codeInsight;
|
||||||
|
|
||||||
import com.google.common.collect.Sets;
|
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.descriptors.*;
|
||||||
import org.jetbrains.jet.lang.resolve.OverrideResolver;
|
import org.jetbrains.jet.lang.resolve.OverrideResolver;
|
||||||
|
import org.jetbrains.jet.plugin.JetBundle;
|
||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author yole
|
* @author yole
|
||||||
*/
|
*/
|
||||||
public class ImplementMethodsHandler extends OverrideImplementMethodsHandler {
|
public class ImplementMethodsHandler extends OverrideImplementMethodsHandler implements IntentionAction {
|
||||||
protected Set<CallableMemberDescriptor> collectMethodsToGenerate(MutableClassDescriptor descriptor) {
|
protected Set<CallableMemberDescriptor> collectMethodsToGenerate(MutableClassDescriptor descriptor) {
|
||||||
Set<CallableMemberDescriptor> missingImplementations = Sets.newLinkedHashSet();
|
Set<CallableMemberDescriptor> missingImplementations = Sets.newLinkedHashSet();
|
||||||
OverrideResolver.collectMissingImplementations(descriptor, missingImplementations, missingImplementations);
|
OverrideResolver.collectMissingImplementations(descriptor, missingImplementations, missingImplementations);
|
||||||
@@ -19,4 +26,21 @@ public class ImplementMethodsHandler extends OverrideImplementMethodsHandler {
|
|||||||
protected String getChooserTitle() {
|
protected String getChooserTitle() {
|
||||||
return "Implement Members";
|
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.HashMultimap;
|
||||||
import com.google.common.collect.Multimap;
|
import com.google.common.collect.Multimap;
|
||||||
|
import com.intellij.codeInsight.intention.IntentionAction;
|
||||||
import com.intellij.psi.PsiElement;
|
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.DiagnosticParameters;
|
||||||
import org.jetbrains.jet.lang.diagnostics.Errors;
|
import org.jetbrains.jet.lang.diagnostics.Errors;
|
||||||
import org.jetbrains.jet.lang.diagnostics.PsiElementOnlyDiagnosticFactory;
|
import org.jetbrains.jet.lang.diagnostics.PsiElementOnlyDiagnosticFactory;
|
||||||
import org.jetbrains.jet.lang.psi.*;
|
import org.jetbrains.jet.lang.psi.*;
|
||||||
import org.jetbrains.jet.lexer.JetToken;
|
import org.jetbrains.jet.lexer.JetToken;
|
||||||
import org.jetbrains.jet.lexer.JetTokens;
|
import org.jetbrains.jet.lexer.JetTokens;
|
||||||
|
import org.jetbrains.jet.plugin.codeInsight.ImplementMethodsHandler;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
@@ -16,16 +19,21 @@ import java.util.Collection;
|
|||||||
* @author svtk
|
* @author svtk
|
||||||
*/
|
*/
|
||||||
public class QuickFixes {
|
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) {
|
public static Collection<JetIntentionActionFactory> get(PsiElementOnlyDiagnosticFactory diagnosticFactory) {
|
||||||
|
return jetActionMap.get(diagnosticFactory);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Collection<IntentionAction> get(DiagnosticFactory diagnosticFactory) {
|
||||||
return actionMap.get(diagnosticFactory);
|
return actionMap.get(diagnosticFactory);
|
||||||
}
|
}
|
||||||
|
|
||||||
private QuickFixes() {}
|
private QuickFixes() {}
|
||||||
|
|
||||||
private static <T extends PsiElement> void add(PsiElementOnlyDiagnosticFactory<? extends T> diagnosticFactory, JetIntentionActionFactory<T> actionFactory) {
|
private static <T extends PsiElement> void add(PsiElementOnlyDiagnosticFactory<? extends T> diagnosticFactory, JetIntentionActionFactory<T> actionFactory) {
|
||||||
actionMap.put(diagnosticFactory, actionFactory);
|
jetActionMap.put(diagnosticFactory, actionFactory);
|
||||||
}
|
}
|
||||||
|
|
||||||
static {
|
static {
|
||||||
@@ -108,5 +116,9 @@ public class QuickFixes {
|
|||||||
add(Errors.PUBLIC_MEMBER_SHOULD_SPECIFY_TYPE, AddReturnTypeFix.createFactory());
|
add(Errors.PUBLIC_MEMBER_SHOULD_SPECIFY_TYPE, AddReturnTypeFix.createFactory());
|
||||||
|
|
||||||
add(Errors.INITIALIZATION_USING_BACKING_FIELD, ChangeToBackingFieldFix.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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user