mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
access for private members through type parameter bound is forbidden in jdk7 (IDEA-88895)
This commit is contained in:
@@ -15,6 +15,8 @@
|
||||
*/
|
||||
package com.intellij.psi.infos;
|
||||
|
||||
import com.intellij.openapi.projectRoots.JavaSdkVersion;
|
||||
import com.intellij.openapi.projectRoots.JavaVersionService;
|
||||
import com.intellij.psi.*;
|
||||
|
||||
/**
|
||||
@@ -99,12 +101,31 @@ public class CandidateInfo implements JavaResolveResult {
|
||||
final PsiMember member = (PsiMember)myCandidate;
|
||||
accessProblem = !JavaPsiFacade.getInstance(myPlace.getProject()).getResolveHelper()
|
||||
.isAccessible(member, member.getModifierList(), myPlace, myAccessClass, myCurrentFileResolveContext);
|
||||
if (!accessProblem && member.hasModifierProperty(PsiModifier.PRIVATE) && myPlace instanceof PsiReferenceExpression && JavaVersionService.getInstance().isAtLeast(myPlace, JavaSdkVersion.JDK_1_7)) {
|
||||
accessProblem = isAccessedThroughTypeParameterBound();
|
||||
}
|
||||
}
|
||||
myAccessProblem = accessProblem ? Boolean.TRUE : Boolean.FALSE;
|
||||
}
|
||||
return !myAccessProblem.booleanValue();
|
||||
}
|
||||
|
||||
private boolean isAccessedThroughTypeParameterBound() {
|
||||
final PsiExpression qualifierExpression = ((PsiReferenceExpression)myPlace).getQualifierExpression();
|
||||
if (qualifierExpression instanceof PsiMethodCallExpression) {
|
||||
final JavaResolveResult resolveResult = ((PsiMethodCallExpression)qualifierExpression).resolveMethodGenerics();
|
||||
final PsiElement element = resolveResult.getElement();
|
||||
if (element instanceof PsiMethod) {
|
||||
final PsiType returnType = ((PsiMethod)element).getReturnType();
|
||||
final PsiType substitutedReturnType = resolveResult.getSubstitutor().substitute(returnType);
|
||||
if (substitutedReturnType instanceof PsiCapturedWildcardType) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isStaticsScopeCorrect(){
|
||||
return !myStaticsProblem;
|
||||
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
import java.util.Iterator;
|
||||
|
||||
public class WildcardGenericAndPrivateField {
|
||||
|
||||
private Object field;
|
||||
|
||||
public Iterator<? extends WildcardGenericAndPrivateField> iterator() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void methodDoesNotCompile() {
|
||||
Iterator<? extends WildcardGenericAndPrivateField> iterator = iterator();
|
||||
while ( iterator.hasNext() ) {
|
||||
Object o = iterator.next().<error descr="'field' has private access in 'WildcardGenericAndPrivateField'">field</error>;
|
||||
}
|
||||
}
|
||||
|
||||
public void methodCompiles() {
|
||||
Iterator<? extends WildcardGenericAndPrivateField> iterator = iterator();
|
||||
while ( iterator.hasNext() ) {
|
||||
WildcardGenericAndPrivateField next = iterator.next();
|
||||
Object o = next.field;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -127,6 +127,7 @@ public class GenericsHighlightingTest extends LightDaemonAnalyzerTestCase {
|
||||
public void testIDEA80386() throws Exception { doTest(false);}
|
||||
|
||||
public void testIDEA66311() throws Exception { doTest17Incompatibility();}
|
||||
public void testIDEA88895() throws Exception { doTest17Incompatibility();}
|
||||
public void testIDEA66311_16() throws Exception { doTest(false);}
|
||||
public void testIDEA76283() throws Exception {doTest(false);}
|
||||
public void testIDEA74899() throws Exception {doTest(false);}
|
||||
|
||||
Reference in New Issue
Block a user