mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IG: quickfix for "Method does not call super method" (IDEA-89117)
This commit is contained in:
+62
-1
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
* Copyright 2000-2016 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.
|
||||
@@ -15,9 +15,18 @@
|
||||
*/
|
||||
package com.siyeh.ig.inheritance;
|
||||
|
||||
import com.intellij.codeInspection.ProblemDescriptor;
|
||||
import com.intellij.codeInspection.util.SpecialAnnotationsUtil;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.codeStyle.CodeStyleManager;
|
||||
import com.intellij.util.ui.CheckBox;
|
||||
import com.siyeh.InspectionGadgetsBundle;
|
||||
import com.siyeh.ig.InspectionGadgetsFix;
|
||||
import com.siyeh.ig.psiutils.HighlightUtils;
|
||||
import org.jetbrains.annotations.Nls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
@@ -41,4 +50,56 @@ public class RefusedBequestInspection extends RefusedBequestInspectionBase {
|
||||
|
||||
return panel;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
protected InspectionGadgetsFix buildFix(Object... infos) {
|
||||
return new RefusedBequestFix();
|
||||
}
|
||||
|
||||
private static class RefusedBequestFix extends InspectionGadgetsFix {
|
||||
|
||||
@Nls
|
||||
@NotNull
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Insert call to super method";
|
||||
}
|
||||
|
||||
@Nls
|
||||
@NotNull
|
||||
@Override
|
||||
public String getFamilyName() {
|
||||
return getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doFix(Project project, ProblemDescriptor descriptor) {
|
||||
final PsiElement methodName = descriptor.getPsiElement();
|
||||
final PsiMethod method = (PsiMethod)methodName.getParent();
|
||||
assert method != null;
|
||||
final PsiCodeBlock body = method.getBody();
|
||||
if (body == null) {
|
||||
return;
|
||||
}
|
||||
final PsiElementFactory factory = JavaPsiFacade.getElementFactory(project);
|
||||
final StringBuilder statementText = new StringBuilder("super.");
|
||||
statementText.append(methodName.getText()).append('(');
|
||||
boolean comma = false;
|
||||
for (PsiParameter parameter : method.getParameterList().getParameters()) {
|
||||
if (comma) statementText.append(',');
|
||||
else comma = true;
|
||||
statementText.append(parameter.getName());
|
||||
}
|
||||
statementText.append(");");
|
||||
final PsiStatement newStatement = factory.createStatementFromText(statementText.toString(), null);
|
||||
final CodeStyleManager styleManager = CodeStyleManager.getInstance(project);
|
||||
final PsiJavaToken brace = body.getLBrace();
|
||||
final PsiElement element = body.addAfter(newStatement, brace);
|
||||
final PsiElement element1 = styleManager.reformat(element);
|
||||
if (isOnTheFly()) {
|
||||
HighlightUtils.highlightElement(element1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user