mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-13 09:19:13 +07:00
unchecked warning inside lambda return statements
This commit is contained in:
+32
-11
@@ -401,24 +401,45 @@ public class UncheckedWarningLocalInspectionBase extends BaseJavaBatchLocalInspe
|
||||
public void visitReturnStatement(PsiReturnStatement statement) {
|
||||
super.visitReturnStatement(statement);
|
||||
if (IGNORE_UNCHECKED_ASSIGNMENT) return;
|
||||
PsiType returnType = null;
|
||||
final PsiElement psiElement = PsiTreeUtil.getParentOfType(statement, PsiMethod.class, PsiLambdaExpression.class);
|
||||
if (psiElement instanceof PsiMethod) {
|
||||
final PsiMethod method = (PsiMethod)psiElement;
|
||||
final PsiType returnType = method.getReturnType();
|
||||
if (returnType != null && !PsiType.VOID.equals(returnType)) {
|
||||
final PsiExpression returnValue = statement.getReturnValue();
|
||||
if (returnValue != null) {
|
||||
final PsiType valueType = returnValue.getType();
|
||||
if (valueType != null) {
|
||||
checkRawToGenericsAssignment(returnValue, returnValue, returnType, valueType,
|
||||
false,
|
||||
new LocalQuickFix[]{QuickFixFactory.getInstance().createMethodReturnFix(method, valueType, true)});
|
||||
}
|
||||
returnType = ((PsiMethod)psiElement).getReturnType();
|
||||
}
|
||||
else if (psiElement instanceof PsiLambdaExpression) {
|
||||
returnType = LambdaUtil.getFunctionalInterfaceReturnType((PsiLambdaExpression)psiElement);
|
||||
}
|
||||
|
||||
if (returnType != null && !PsiType.VOID.equals(returnType)) {
|
||||
final PsiExpression returnValue = statement.getReturnValue();
|
||||
if (returnValue != null) {
|
||||
final PsiType valueType = returnValue.getType();
|
||||
if (valueType != null) {
|
||||
LocalQuickFix[] fixes = psiElement instanceof PsiMethod
|
||||
? new LocalQuickFix[]{QuickFixFactory.getInstance().createMethodReturnFix((PsiMethod)psiElement, valueType, true)}
|
||||
: LocalQuickFix.EMPTY_ARRAY;
|
||||
checkRawToGenericsAssignment(returnValue, returnValue, returnType, valueType, false, fixes);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitLambdaExpression(PsiLambdaExpression expression) {
|
||||
super.visitLambdaExpression(expression);
|
||||
|
||||
if (IGNORE_UNCHECKED_ASSIGNMENT) return;
|
||||
PsiElement body = expression.getBody();
|
||||
if (body instanceof PsiExpression) {
|
||||
PsiType interfaceReturnType = LambdaUtil.getFunctionalInterfaceReturnType(expression);
|
||||
if (interfaceReturnType != null && !PsiType.VOID.equals(interfaceReturnType)) {
|
||||
PsiType type = ((PsiExpression)body).getType();
|
||||
if (type != null) {
|
||||
checkRawToGenericsAssignment(body, (PsiExpression)body, interfaceReturnType, type, false, LocalQuickFix.EMPTY_ARRAY);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private String getUncheckedCallDescription(PsiElement place, JavaResolveResult resolveResult) {
|
||||
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
import java.util.function.IntFunction;
|
||||
|
||||
class Test {
|
||||
{
|
||||
IntFunction<Class<? extends String>[]> var1 = value -> {
|
||||
return <warning descr="Unchecked assignment: 'java.lang.Class[]' to 'java.lang.Class<? extends java.lang.String>[]'">new Class[value]</warning>;
|
||||
};
|
||||
System.out.println(var1);
|
||||
|
||||
IntFunction<Class<? extends String>[]> var2 = value -> <warning descr="Unchecked assignment: 'java.lang.Class[]' to 'java.lang.Class<? extends java.lang.String>[]'">new Class[value]</warning>;
|
||||
System.out.println(var2);
|
||||
}
|
||||
}
|
||||
+4
@@ -1001,6 +1001,10 @@ public class GenericsHighlighting8Test extends LightDaemonAnalyzerTestCase {
|
||||
doTest(true);
|
||||
}
|
||||
|
||||
public void testUncheckedWarningsInsideLambda() throws Exception {
|
||||
doTest(true);
|
||||
}
|
||||
|
||||
public void testMembersContainedInCapturedWildcardType() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user