suggest to extend class from Throwable when it participates in throw statement (IDEA-118215)

This commit is contained in:
Anna Kozlova
2013-12-16 19:49:08 +04:00
parent 05d3b27d0f
commit 27a4b1890d
4 changed files with 47 additions and 0 deletions

View File

@@ -2421,6 +2421,11 @@ public class HighlightUtil extends HighlightUtilBase {
QuickFixAction.registerQuickFixAction(highlightInfo, QUICK_FIX_FACTORY.createAddTypeCastFix(throwable, (PsiExpression)context));
}
}
final PsiClass aClass = PsiUtil.resolveClassInClassTypeOnly(type);
if (aClass != null) {
QuickFixAction.registerQuickFixAction(highlightInfo, QUICK_FIX_FACTORY.createExtendsListFix(aClass, throwable, true));
}
return highlightInfo;
}
return null;

View File

@@ -0,0 +1,8 @@
// "Make 'C' extend 'java.lang.Throwable'" "true"
class C extends Throwable {}
class Main {
public static void main(String[] args) {
throw new <caret>C();
}
}

View File

@@ -0,0 +1,8 @@
// "Make 'C' extend 'java.lang.Throwable'" "true"
class C {}
class Main {
public static void main(String[] args) {
throw new <caret>C();
}
}

View File

@@ -0,0 +1,26 @@
/*
* Copyright 2000-2013 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.codeInsight.daemon.quickFix;
public class MakeExtendsThrowableTest extends LightQuickFix15TestCase {
public void test() throws Exception { doAllTests(); }
@Override
protected String getBasePath() {
return "/codeInsight/daemonCodeAnalyzer/quickFix/makeExtendsThrowable";
}
}