check context for functional expressions once (IDEA-159362)

This commit is contained in:
Anna Kozlova
2016-08-08 08:35:27 +02:00
parent ccf3beba42
commit 8ac15c13de
3 changed files with 18 additions and 10 deletions
@@ -278,14 +278,6 @@ public class HighlightUtil extends HighlightUtilBase {
PsiType checkType = typeElement.getType();
PsiType operandType = operand.getType();
if (operandType == null) return null;
if (operandType instanceof PsiLambdaExpressionType) {
return HighlightInfo
.newHighlightInfo(HighlightInfoType.ERROR).range(expression).descriptionAndTooltip("Lambda expression is not expected here").create();
}
if (operandType instanceof PsiMethodReferenceType) {
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(expression).descriptionAndTooltip(
"Method reference expression is not expected here").create();
}
if (TypeConversionUtil.isPrimitiveAndNotNull(operandType)
|| TypeConversionUtil.isPrimitiveAndNotNull(checkType)
|| !TypeConversionUtil.areTypesConvertible(operandType, checkType)) {
@@ -1285,6 +1285,12 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh
}
myHolder.add(HighlightNamesUtil.highlightClassNameInQualifier(expression, colorsScheme));
}
if (!LambdaUtil.isValidLambdaContext(expression.getParent())) {
myHolder.add(HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(expression)
.descriptionAndTooltip("Method reference expression is not expected here").create());
}
if (!myHolder.hasErrorResults()) {
final PsiType functionalInterfaceType = expression.getFunctionalInterfaceType();
if (functionalInterfaceType != null) {
@@ -1,6 +1,10 @@
public class Test {
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
class Test {
{
if (<error descr="Method reference expression is not expected here">Test::length instanceof String</error>) {
if (<error descr="Method reference expression is not expected here">Test::length</error> instanceof String) {
}
bar(Test::length);
}
@@ -14,4 +18,10 @@ public class Test {
interface Bar {
Integer _(String s);
}
void f() throws IOException {
try (BufferedReader reader = new BufferedReader(new FileReader(""))) {
for (String line : <error descr="Method reference expression is not expected here">reader::lines</error>) {}
}
}
}