mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-184127 Field reference is highlighted with red in Evaluate window in debugger
This commit is contained in:
+8
-16
@@ -1,17 +1,5 @@
|
||||
/*
|
||||
* 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.
|
||||
* Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
*/
|
||||
package com.intellij.psi.impl.source.resolve;
|
||||
|
||||
@@ -66,9 +54,13 @@ public class VariableResolverProcessor extends ConflictFilterProcessor implement
|
||||
|
||||
@Override
|
||||
public final void handleEvent(@NotNull PsiScopeProcessor.Event event, Object associated) {
|
||||
// do not resolve conflicts on CHANGE_LEVEL if VisibilityChecker is present
|
||||
if (event == JavaScopeProcessorEvent.CHANGE_LEVEL &&
|
||||
(!(myPlaceFile instanceof JavaCodeFragment) || ((JavaCodeFragment)myPlaceFile).getVisibilityChecker() == null)) {
|
||||
// Special handling when VisibilityChecker is present
|
||||
if (myPlaceFile instanceof JavaCodeFragment && ((JavaCodeFragment)myPlaceFile).getVisibilityChecker() != null) {
|
||||
if (event == JavaScopeProcessorEvent.SET_CURRENT_FILE_CONTEXT && myName != null) {
|
||||
getResult();
|
||||
}
|
||||
}
|
||||
else {
|
||||
super.handleEvent(event, associated);
|
||||
}
|
||||
if(event == JavaScopeProcessorEvent.START_STATIC){
|
||||
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
public class FieldVsOuter2 {
|
||||
public final String field = "xxx";
|
||||
|
||||
private class Inner {
|
||||
public final String field = "yyy";
|
||||
|
||||
public void foo() {
|
||||
System.out.println(<ref>field);
|
||||
}
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
public class FieldVsOuter {
|
||||
public final String field = "xxx";
|
||||
|
||||
private static class Inner {
|
||||
public final String field = "yyy";
|
||||
|
||||
public void foo() {
|
||||
System.out.println(<ref>field);
|
||||
}
|
||||
}
|
||||
}
|
||||
+29
-18
@@ -1,4 +1,6 @@
|
||||
// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
/*
|
||||
* Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
*/
|
||||
package com.intellij.java.psi.resolve;
|
||||
|
||||
import com.intellij.codeInsight.AnnotationUtil;
|
||||
@@ -10,6 +12,8 @@ import com.intellij.psi.impl.source.tree.java.PsiReferenceExpressionImpl;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.testFramework.ResolveTestCase;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* @author max
|
||||
*/
|
||||
@@ -49,35 +53,42 @@ public class ResolveInCodeFragmentTest extends ResolveTestCase {
|
||||
}
|
||||
|
||||
public void testResolveFieldVsLocalWithVisiblityChecker() throws Exception {
|
||||
PsiReference iRef = configure();
|
||||
|
||||
JavaCodeFragment codeFragment = JavaCodeFragmentFactory.getInstance(myProject).createExpressionCodeFragment(
|
||||
"xxx", iRef.getElement(), null, true);
|
||||
codeFragment.setVisibilityChecker(JavaCodeFragment.VisibilityChecker.EVERYTHING_VISIBLE);
|
||||
|
||||
PsiElement[] fileContent = codeFragment.getChildren();
|
||||
assertEquals(1, fileContent.length);
|
||||
assertTrue(fileContent[0] instanceof PsiExpression);
|
||||
|
||||
PsiExpression expr = (PsiExpression) fileContent[0];
|
||||
PsiElement resolve = ((PsiReferenceExpressionImpl)expr).resolve();
|
||||
assertInstanceOf(resolve, PsiLocalVariable.class);
|
||||
doTestResolveWithVisibilityChecker("xxx", e -> assertInstanceOf(e, PsiLocalVariable.class));
|
||||
}
|
||||
|
||||
public void testResolveFieldVsParamWithVisiblityChecker() throws Exception {
|
||||
doTestResolveWithVisibilityChecker("field", e -> assertInstanceOf(e, PsiParameter.class));
|
||||
}
|
||||
|
||||
public void testResolveFieldInStaticInnerWithVisiblityChecker() throws Exception {
|
||||
doTestResolveWithVisibilityChecker("field", e -> {
|
||||
assertInstanceOf(e, PsiField.class);
|
||||
assertEquals("Inner", ((PsiField)e).getContainingClass().getName());
|
||||
});
|
||||
}
|
||||
|
||||
public void testResolveFieldInInnerWithVisiblityChecker() throws Exception {
|
||||
doTestResolveWithVisibilityChecker("field", e -> {
|
||||
assertInstanceOf(e, PsiField.class);
|
||||
assertEquals("Inner", ((PsiField)e).getContainingClass().getName());
|
||||
});
|
||||
}
|
||||
|
||||
private void doTestResolveWithVisibilityChecker(String field, Consumer<PsiElement> checker) throws Exception {
|
||||
PsiReference iRef = configure();
|
||||
|
||||
JavaCodeFragment codeFragment = JavaCodeFragmentFactory.getInstance(myProject).createExpressionCodeFragment(
|
||||
"field", iRef.getElement(), null, true);
|
||||
field, iRef.getElement(), null, true);
|
||||
codeFragment.setVisibilityChecker(JavaCodeFragment.VisibilityChecker.EVERYTHING_VISIBLE);
|
||||
|
||||
PsiElement[] fileContent = codeFragment.getChildren();
|
||||
assertEquals(1, fileContent.length);
|
||||
assertTrue(fileContent[0] instanceof PsiExpression);
|
||||
|
||||
PsiExpression expr = (PsiExpression) fileContent[0];
|
||||
PsiElement resolve = ((PsiReferenceExpressionImpl)expr).resolve();
|
||||
assertInstanceOf(resolve, PsiParameter.class);
|
||||
PsiExpression expr = (PsiExpression)fileContent[0];
|
||||
JavaResolveResult[] results = ((PsiReferenceExpressionImpl)expr).multiResolve(false);
|
||||
assertSize(1, results);
|
||||
checker.accept(results[0].getElement());
|
||||
}
|
||||
|
||||
private PsiReference configure() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user