mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-19 04:51:24 +07:00
method refs: check access problems
This commit is contained in:
@@ -977,6 +977,10 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh
|
||||
if (myRefCountHolder != null) {
|
||||
myRefCountHolder.registerReference(expression, result);
|
||||
}
|
||||
if (result.getElement() != null && !result.isAccessible()) {
|
||||
final String accessProblem = HighlightUtil.buildProblemWithAccessDescription(expression, result);
|
||||
myHolder.add(HighlightInfo.createHighlightInfo(HighlightInfoType.ERROR, expression, accessProblem));
|
||||
}
|
||||
if (!myHolder.hasErrorResults()) {
|
||||
final PsiType functionalInterfaceType = expression.getFunctionalInterfaceType();
|
||||
if (LambdaUtil.dependsOnTypeParams(functionalInterfaceType, functionalInterfaceType, expression, null)) {
|
||||
|
||||
@@ -302,6 +302,7 @@ public class PsiMethodReferenceExpressionImpl extends PsiReferenceExpressionBase
|
||||
};
|
||||
processor.setIsConstructor(isConstructor);
|
||||
processor.setName(isConstructor ? containingClass.getName() : element.getText());
|
||||
processor.setAccessClass(containingClass);
|
||||
|
||||
if (beginsWithReferenceType) {
|
||||
if (containingClass.getContainingClass() == null || !containingClass.hasModifierProperty(PsiModifier.STATIC)) {
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
class MyTest {
|
||||
|
||||
private static class Foo {
|
||||
static int foo(int i) { return i; }
|
||||
}
|
||||
|
||||
static Foo foo = new Foo();
|
||||
|
||||
static void foo(String s) {}
|
||||
|
||||
static void bar(Integer i, Number n) {}
|
||||
static void bar(Number n, Integer i) {}
|
||||
|
||||
void baz(int i) {}
|
||||
}
|
||||
|
||||
class AlienTest {
|
||||
|
||||
interface IInt {
|
||||
int _(int i);
|
||||
}
|
||||
|
||||
interface IIntInt {
|
||||
int _(Integer i1, Integer i2);
|
||||
}
|
||||
|
||||
static {
|
||||
<error descr="Incompatible types. Found: '<method reference>', required: 'AlienTest.IInt'">IInt i1 = MyTest::abracadabra;</error>
|
||||
<error descr="Incompatible types. Found: '<method reference>', required: 'AlienTest.IInt'">IInt i2 = MyTest::foo;</error>
|
||||
<error descr="Incompatible types. Found: '<method reference>', required: 'AlienTest.IInt'">IInt i3 = MyTest::bar;</error>
|
||||
<error descr="Incompatible types. Found: '<method reference>', required: 'AlienTest.IIntInt'">IIntInt i4 = MyTest::bar;</error>
|
||||
<error descr="Incompatible types. Found: '<method reference>', required: 'AlienTest.IInt'">IInt i5 = MyTest::baz;</error>
|
||||
IInt i6 = <error descr="'foo(int)' is not public in 'MyTest.Foo'. Cannot be accessed from outside package">MyTest.foo::foo</error>;
|
||||
IInt i7 = MyTest.<error descr="'MyTest.Foo' has private access in 'MyTest'">Foo</error>::foo;
|
||||
}
|
||||
}
|
||||
@@ -97,6 +97,10 @@ public class MethodRefHighlightingTest extends LightDaemonAnalyzerTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testAccessModifiers() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testReturnTypeSpecific() throws Exception {
|
||||
doTest(true);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user