use of com.intellij.codeInspection.LocalQuickFix in project intellij-community by JetBrains.
the class DefinitionReference method getQuickFixes.
@Override
public LocalQuickFix[] getQuickFixes() {
final XmlTag tag = PsiTreeUtil.getParentOfType(getElement(), XmlTag.class);
assert tag != null;
final RngGrammar scope = myValue.getParentOfType(RngGrammar.class, true);
if (scope != null) {
return new LocalQuickFix[] { new CreatePatternFix(this) };
}
return LocalQuickFix.EMPTY_ARRAY;
}
use of com.intellij.codeInspection.LocalQuickFix in project intellij-community by JetBrains.
the class AbstractFix method createQuickFix.
@Nullable
public LocalQuickFix createQuickFix(boolean isOnTheFly) {
final boolean requiresEditor = requiresEditor();
if (requiresEditor && !isOnTheFly)
return null;
return new LocalQuickFix() {
@NotNull
public String getName() {
return AbstractFix.this.getText();
}
@NotNull
public String getFamilyName() {
return AbstractFix.this.getFamilyName();
}
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
Editor editor;
if (requiresEditor) {
final DataContext dataContext = DataManager.getInstance().getDataContext();
editor = CommonDataKeys.EDITOR.getData(dataContext);
if (editor == null) {
if ((editor = FileEditorManager.getInstance(project).getSelectedTextEditor()) == null) {
return;
}
}
} else {
editor = null;
}
final PsiFile psiFile = descriptor.getPsiElement().getContainingFile();
if (!isAvailable(project, editor, psiFile)) {
return;
}
invoke(project, editor, psiFile);
}
};
}
use of com.intellij.codeInspection.LocalQuickFix in project intellij-community by JetBrains.
the class IntentionListStep method getWeight.
private int getWeight(IntentionActionWithTextCaching action) {
IntentionAction a = action.getAction();
int group = getGroup(action);
if (a instanceof IntentionActionWrapper) {
a = ((IntentionActionWrapper) a).getDelegate();
}
if (a instanceof IntentionWrapper) {
a = ((IntentionWrapper) a).getAction();
}
if (a instanceof HighPriorityAction) {
return group + 3;
}
if (a instanceof LowPriorityAction) {
return group - 3;
}
if (a instanceof SuppressIntentionActionFromFix) {
if (((SuppressIntentionActionFromFix) a).isShouldBeAppliedToInjectionHost() == ThreeState.NO) {
return group - 1;
}
}
if (a instanceof QuickFixWrapper) {
final LocalQuickFix quickFix = ((QuickFixWrapper) a).getFix();
if (quickFix instanceof HighPriorityAction) {
return group + 3;
}
if (quickFix instanceof LowPriorityAction) {
return group - 3;
}
}
return group;
}
use of com.intellij.codeInspection.LocalQuickFix in project intellij-community by JetBrains.
the class QuickFixWrapper method invoke.
@Override
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
//if (!CodeInsightUtil.prepareFileForWrite(file)) return;
// consider all local quick fixes do it themselves
final PsiElement element = myDescriptor.getPsiElement();
final PsiFile fileForUndo = element == null ? null : element.getContainingFile();
LocalQuickFix fix = getFix();
fix.applyFix(project, myDescriptor);
DaemonCodeAnalyzer.getInstance(project).restart();
if (fileForUndo != null && !fileForUndo.equals(file)) {
UndoUtil.markPsiFileForUndo(fileForUndo);
}
}
use of com.intellij.codeInspection.LocalQuickFix in project intellij-community by JetBrains.
the class QuickFixWrapper method isAvailable.
@Override
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
PsiElement psiElement = myDescriptor.getPsiElement();
if (psiElement == null || !psiElement.isValid())
return false;
final LocalQuickFix fix = getFix();
return !(fix instanceof IntentionAction) || ((IntentionAction) fix).isAvailable(project, editor, file);
}
Aggregations