IDEA-120217 same lambda param names highlighting

This commit is contained in:
Anna Kozlova
2014-02-04 17:58:25 +04:00
parent b6cb00a53c
commit ba11e80028
3 changed files with 23 additions and 12 deletions

View File

@@ -600,7 +600,7 @@ public class HighlightUtil extends HighlightUtilBase {
static HighlightInfo checkVariableAlreadyDefined(@NotNull PsiVariable variable) {
if (variable instanceof ExternallyDefinedPsiElement) return null;
boolean isIncorrect = false;
PsiElement declarationScope;
PsiElement declarationScope = null;
if (variable instanceof PsiLocalVariable ||
variable instanceof PsiParameter &&
((declarationScope = ((PsiParameter)variable).getDeclarationScope()) instanceof PsiCatchSection ||
@@ -623,6 +623,8 @@ public class HighlightUtil extends HighlightUtilBase {
}
if (proc.size() > 0) {
isIncorrect = true;
} else if (declarationScope instanceof PsiLambdaExpression) {
isIncorrect = checkSameNames(variable);
}
}
else if (variable instanceof PsiField) {
@@ -635,17 +637,7 @@ public class HighlightUtil extends HighlightUtilBase {
}
}
else {
PsiElement scope = variable.getParent();
PsiElement[] children = scope.getChildren();
for (PsiElement child : children) {
if (child instanceof PsiVariable) {
if (child.equals(variable)) continue;
if (variable.getName().equals(((PsiVariable)child).getName())) {
isIncorrect = true;
break;
}
}
}
isIncorrect = checkSameNames(variable);
}
if (isIncorrect) {
@@ -662,6 +654,20 @@ public class HighlightUtil extends HighlightUtilBase {
return null;
}
private static boolean checkSameNames(PsiVariable variable) {
PsiElement scope = variable.getParent();
PsiElement[] children = scope.getChildren();
for (PsiElement child : children) {
if (child instanceof PsiVariable) {
if (child.equals(variable)) continue;
if (variable.getName().equals(((PsiVariable)child).getName())) {
return true;
}
}
}
return false;
}
@Nullable
public static HighlightInfo checkUnderscore(@NotNull PsiIdentifier identifier, @NotNull PsiVariable variable) {
if ("_".equals(variable.getName()) && PsiUtil.isLanguageLevel8OrHigher(variable)) {

View File

@@ -0,0 +1,4 @@
import java.util.function.BiFunction;
class X {
BiFunction<Object, Object, Object> b = (<error descr="Variable 'o1' is already defined in the scope">o1</error>, <error descr="Variable 'o1' is already defined in the scope">o1</error>) -> null;
}

View File

@@ -97,6 +97,7 @@ public class LambdaHighlightingTest extends LightDaemonAnalyzerTestCase {
public void testWildcardsAndFormalLambdaParams() {doTest();}
public void testFinalInitializer() {doTest();}
public void testBreakContinueInside() {doTest();}
public void testSameLambdaParamNames() {doTest();}
private void doTest() {
doTest(false);