mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
lambda: initial is assignable check; effectively final; acceptable context
This commit is contained in:
+21
@@ -692,6 +692,27 @@ public class HighlightControlFlowUtil {
|
||||
final HighlightInfo highlightInfo = HighlightInfo.createHighlightInfo(HighlightInfoType.ERROR, context, description);
|
||||
QuickFixAction.registerQuickFixAction(highlightInfo, new VariableAccessFromInnerClassFix(variable, innerClass));
|
||||
return highlightInfo;
|
||||
} else {
|
||||
final PsiLambdaExpression lambdaExpression = PsiTreeUtil.getParentOfType(context, PsiLambdaExpression.class);
|
||||
if (lambdaExpression != null) {
|
||||
if (variable instanceof PsiParameter) {
|
||||
final PsiElement parent = variable.getParent();
|
||||
if (parent instanceof PsiParameterList && parent.getParent() == lambdaExpression) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
boolean effectivelyFinal = true;
|
||||
for (PsiReference reference : ReferencesSearch.search(variable)) {
|
||||
final PsiElement element = reference.getElement();
|
||||
if (element instanceof PsiExpression && PsiUtil.isOnAssignmentLeftHand((PsiExpression)element)) {
|
||||
effectivelyFinal = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!effectivelyFinal ) {
|
||||
return HighlightInfo.createHighlightInfo(HighlightInfoType.ERROR, context, "Variable used in lambda expression should be effectively final");
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -331,6 +331,9 @@ public class HighlightUtil {
|
||||
PsiType checkType = typeElement.getType();
|
||||
PsiType operandType = operand.getType();
|
||||
if (operandType == null) return null;
|
||||
if (operandType instanceof PsiLambdaExpressionType) {
|
||||
return HighlightInfo.createHighlightInfo(HighlightInfoType.ERROR, expression, "Lambda expression is not expected here");
|
||||
}
|
||||
if (TypeConversionUtil.isPrimitiveAndNotNull(operandType)
|
||||
|| TypeConversionUtil.isPrimitiveAndNotNull(checkType)
|
||||
|| !TypeConversionUtil.areTypesConvertible(operandType, checkType)) {
|
||||
|
||||
Reference in New Issue
Block a user