mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
highlight incorrect throw statements
This commit is contained in:
+11
@@ -46,6 +46,7 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArg
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrOpenBlock;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.branch.GrReturnStatement;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.branch.GrThrowStatement;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.*;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrString;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrIndexProperty;
|
||||
@@ -349,6 +350,16 @@ public class GroovyAssignabilityCheckInspection extends BaseInspection {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitThrowStatement(GrThrowStatement throwStatement) {
|
||||
super.visitThrowStatement(throwStatement);
|
||||
|
||||
final GrExpression exception = throwStatement.getException();
|
||||
if (exception != null) {
|
||||
checkAssignability(PsiType.getJavaLangThrowable(throwStatement.getManager(), throwStatement.getResolveScope()), exception, exception);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean checkLiteralConstructorApplicability(GroovyResolveResult result, GrListOrMap listOrMap, boolean checkUnknownArgs) {
|
||||
final PsiElement element = result.getElement();
|
||||
LOG.assertTrue(element instanceof PsiMethod && ((PsiMethod)element).isConstructor());
|
||||
|
||||
+22
-10
@@ -867,7 +867,7 @@ C<error descr="Wrong number of type arguments: 2; required: 1"><String, Double><
|
||||
}
|
||||
|
||||
public void testRawClosureReturnType() {
|
||||
myFixture.configureByText('_.groovy', '''\
|
||||
testHighlighting('''\
|
||||
class A<T> {
|
||||
A(T t) {this.t = t}
|
||||
|
||||
@@ -880,17 +880,17 @@ class A<T> {
|
||||
|
||||
def a = new A(new Date())
|
||||
Date d = <warning descr="Cannot assign 'Object' to 'Date'">a.cl()</warning>
|
||||
''')
|
||||
testHighlighting(GroovyUncheckedAssignmentOfMemberOfRawTypeInspection)
|
||||
''', GroovyUncheckedAssignmentOfMemberOfRawTypeInspection)
|
||||
}
|
||||
|
||||
private void testHighlighting(Class<? extends LocalInspectionTool>... inspections) {
|
||||
private void testHighlighting(String text, Class<? extends LocalInspectionTool>... inspections) {
|
||||
myFixture.configureByText('_.groovy', text)
|
||||
myFixture.enableInspections(inspections)
|
||||
myFixture.testHighlighting(true, false, true)
|
||||
}
|
||||
|
||||
void testMethodRefs1() {
|
||||
myFixture.configureByText('_.groovy', '''\
|
||||
testHighlighting('''\
|
||||
class A {
|
||||
int foo(){2}
|
||||
|
||||
@@ -903,12 +903,11 @@ int i = foo()
|
||||
int i2 = <warning descr="Cannot assign 'Date' to 'int'">foo(2)</warning>
|
||||
Date d = foo(2)
|
||||
Date d2 = <warning descr="Cannot assign 'Integer' to 'Date'">foo()</warning>
|
||||
''')
|
||||
testHighlighting(GroovyAssignabilityCheckInspection)
|
||||
''', GroovyAssignabilityCheckInspection)
|
||||
}
|
||||
|
||||
void testMethodRefs2() {
|
||||
myFixture.configureByText('_.groovy', '''\
|
||||
testHighlighting('''\
|
||||
class Bar {
|
||||
def foo(int i, String s2) {s2}
|
||||
def foo(int i, int i2) {i2}
|
||||
@@ -920,8 +919,21 @@ String s = cl("2")
|
||||
int s2 = <warning descr="Cannot assign 'String' to 'int'">cl("2")</warning>
|
||||
int i = cl(3)
|
||||
String i2 = cl(3)
|
||||
''')
|
||||
testHighlighting(GroovyAssignabilityCheckInspection)
|
||||
''', GroovyAssignabilityCheckInspection)
|
||||
}
|
||||
|
||||
void testThrowObject() {
|
||||
testHighlighting('''\
|
||||
def foo() {
|
||||
throw new RuntimeException()
|
||||
}
|
||||
def bar () {
|
||||
throw <warning descr="Cannot assign 'Object' to 'Throwable'">new Object()</warning>
|
||||
}
|
||||
|
||||
def test() {
|
||||
throw new Throwable()
|
||||
}
|
||||
''', GroovyAssignabilityCheckInspection)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user