Highlight implicit parameters in lambdas as in anonymous classes (IDEA-152652)

This commit is contained in:
Yaroslav Lepenkin
2016-03-24 16:09:23 +03:00
parent 7efdf29c50
commit d3657bc657
4 changed files with 60 additions and 5 deletions
@@ -1079,11 +1079,11 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh
if (resolved instanceof PsiVariable) {
PsiVariable variable = (PsiVariable)resolved;
final PsiClass containingClass = PsiTreeUtil.getParentOfType(ref, PsiClass.class);
if (containingClass instanceof PsiAnonymousClass &&
final PsiElement containingClass = PsiTreeUtil.getNonStrictParentOfType(ref, PsiClass.class, PsiLambdaExpression.class);
if ((containingClass instanceof PsiAnonymousClass || containingClass instanceof PsiLambdaExpression) &&
!PsiTreeUtil.isAncestor(containingClass, variable, false) &&
!(variable instanceof PsiField)) {
if (!PsiTreeUtil.isAncestor(((PsiAnonymousClass) containingClass).getArgumentList(), ref, false)) {
if (containingClass instanceof PsiLambdaExpression || !PsiTreeUtil.isAncestor(((PsiAnonymousClass) containingClass).getArgumentList(), ref, false)) {
myHolder.add(HighlightInfo.newHighlightInfo(JavaHighlightInfoTypes.IMPLICIT_ANONYMOUS_CLASS_PARAMETER).range(ref).create());
}
}
@@ -0,0 +1,43 @@
/*
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.codeInsight.daemon;
import com.intellij.testFramework.ExpectedHighlightingData;
public class JavaSymbolHighlightingTest extends LightDaemonAnalyzerTestCase {
public void testImplicitAnonymousClassParameterHighlighting_InsideLambda() throws Exception {
configureFromFileText("Test.java",
"class T {\n" +
" public void test() {\n" +
" int xxx = 12;\n" +
" Runnable r = () -> {\n" +
" check(<symbolName type=\"IMPLICIT_ANONYMOUS_CLASS_PARAMETER\">xxx</symbolName>);\n" +
" };" +
" }\n" +
" public void check(int a) {}\n" +
"}");
doTestConfiguredFile(true, true, true, null);
}
@Override
protected ExpectedHighlightingData getExpectedHighlightingData(boolean checkWarnings, boolean checkWeakWarnings, boolean checkInfos) {
JavaExpectedHighlightingData data = new JavaExpectedHighlightingData(getEditor().getDocument(), false, false, false, true, getFile());
data.checkSymbolNames();
return data;
}
}
@@ -32,6 +32,15 @@ public class JavaExpectedHighlightingData extends ExpectedHighlightingData {
boolean checkInfos, @Nullable PsiFile file) {
super(document, checkWarnings, checkWeakWarnings, checkInfos, file);
}
public JavaExpectedHighlightingData(@NotNull Document document,
boolean checkWarnings,
boolean checkWeakWarnings,
boolean checkInfos,
boolean ignoreExtraHighlighting,
@Nullable PsiFile file) {
super(document, checkWarnings, checkWeakWarnings, checkInfos, ignoreExtraHighlighting, file);
}
@Override
protected HighlightInfoType getTypeByName(String typeString) throws Exception {
@@ -18,7 +18,6 @@ package com.intellij.codeInsight.daemon;
import com.intellij.codeHighlighting.Pass;
import com.intellij.codeInsight.daemon.impl.DaemonCodeAnalyzerImpl;
import com.intellij.codeInsight.daemon.impl.HighlightInfo;
import com.intellij.codeInsight.daemon.impl.HighlightInfoType;
import com.intellij.injected.editor.EditorWindow;
import com.intellij.lang.annotation.HighlightSeverity;
import com.intellij.lang.injection.InjectedLanguageManager;
@@ -94,9 +93,13 @@ public abstract class LightDaemonAnalyzerTestCase extends LightCodeInsightTestCa
protected void doTestConfiguredFile(boolean checkWarnings, boolean checkWeakWarnings, boolean checkInfos, @Nullable String filePath) {
getJavaFacade().setAssertOnFileLoadingFilter(VirtualFileFilter.NONE, myTestRootDisposable);
ExpectedHighlightingData data = new ExpectedHighlightingData(getEditor().getDocument(), checkWarnings, checkWeakWarnings, checkInfos);
ExpectedHighlightingData data = getExpectedHighlightingData(checkWarnings, checkWeakWarnings, checkInfos);
checkHighlighting(data, composeLocalPath(filePath));
}
protected ExpectedHighlightingData getExpectedHighlightingData(boolean checkWarnings, boolean checkWeakWarnings, boolean checkInfos) {
return new ExpectedHighlightingData(getEditor().getDocument(), checkWarnings, checkWeakWarnings, checkInfos);
}
@Nullable
private String composeLocalPath(@Nullable String filePath) {