IDEA-180061 Debugger evaluates private field instead of captured local

This commit is contained in:
Egor Ushakov
2017-10-10 10:04:15 +03:00
parent f18d0f8415
commit fb3a605637
3 changed files with 40 additions and 35 deletions
@@ -1,24 +1,7 @@
/*
* 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.scope.conflictResolvers;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiField;
import com.intellij.psi.PsiLocalVariable;
import com.intellij.psi.*;
import com.intellij.psi.infos.CandidateInfo;
import com.intellij.psi.scope.PsiConflictResolver;
import org.jetbrains.annotations.NotNull;
@@ -45,7 +28,7 @@ public class JavaVariableConflictResolver implements PsiConflictResolver{
final PsiElement otherElement = candidate.getElement();
if (!(otherElement instanceof PsiField)) {
if (otherElement instanceof PsiLocalVariable) {
if (otherElement instanceof PsiLocalVariable || otherElement instanceof PsiParameter) {
return candidate;
}
else {
@@ -0,0 +1,20 @@
public class PrivateFieldVsParam {
public static void main(String[] args) {
start(5);
}
static void start(int field) {
new Cls() {
@Override
void foo() {
System.out.println(<ref>field);
}
}.foo();
}
private static abstract class Cls {
private String field = "xxx";
abstract void foo();
}
}
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2017 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.java.psi.resolve;
import com.intellij.codeInsight.AnnotationUtil;
@@ -78,6 +64,22 @@ public class ResolveInCodeFragmentTest extends ResolveTestCase {
assertInstanceOf(resolve, PsiLocalVariable.class);
}
public void testResolveFieldVsParamWithVisiblityChecker() throws Exception {
PsiReference iRef = configure();
JavaCodeFragment codeFragment = JavaCodeFragmentFactory.getInstance(myProject).createExpressionCodeFragment(
"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);
}
private PsiReference configure() throws Exception {
return configureByFile("codeFragment/" + getTestName(false) + ".java");
}