add quickfix for non-disjoint multi-catch

This commit is contained in:
Bas Leijdekkers
2016-02-12 21:30:28 +01:00
parent 5fb3774b58
commit 6e43997abd
3 changed files with 30 additions and 3 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2015 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.
@@ -2373,8 +2373,11 @@ public class HighlightUtil extends HighlightUtilBase {
final String name1 = PsiFormatUtil.formatClass(class1, PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_FQ_NAME);
final String name2 = PsiFormatUtil.formatClass(class2, PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_FQ_NAME);
final String message = JavaErrorMessages.message("exception.must.be.disjoint", sub ? name1 : name2, sub ? name2 : name1);
PsiElement element = typeElements.get(sub ? i : j);
result.add(HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(element).descriptionAndTooltip(message).create());
final PsiTypeElement element = typeElements.get(sub ? i : j);
final HighlightInfo highlight =
HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(element).descriptionAndTooltip(message).create();
QuickFixAction.registerQuickFixAction(highlight, QUICK_FIX_FACTORY.createDeleteMultiCatchFix(element));
result.add(highlight);
break;
}
}
@@ -0,0 +1,12 @@
// "Delete catch for 'java.lang.RuntimeException'" "true"
import java.io.*;
class C {
void m() {
try {
int p = 0;
}
catch (Exception e) {
}
}
}
@@ -0,0 +1,12 @@
// "Delete catch for 'java.lang.RuntimeException'" "true"
import java.io.*;
class C {
void m() {
try {
int p = 0;
}
catch (<caret>RuntimeException | Exception e) {
}
}
}