mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-19 13:02:30 +07:00
IDEA-120217 same lambda param names highlighting
This commit is contained in:
@@ -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)) {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user