mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
'this' reference in static method of anonymous class
This commit is contained in:
+17
-5
@@ -85,12 +85,24 @@ public class GrThisReferenceExpressionImpl extends GrThisSuperReferenceExpressio
|
||||
}
|
||||
|
||||
private PsiType createType(PsiClass context) {
|
||||
PsiElementFactory elementFactory = JavaPsiFacade.getInstance(getProject()).getElementFactory();
|
||||
if (PsiUtil.isInStaticContext(this)) {
|
||||
return elementFactory.createTypeFromText(CommonClassNames.JAVA_LANG_CLASS + "<" + context.getName() + ">", this);
|
||||
//in case of anonymous class this code don't matter because anonymous classes can't have static methods
|
||||
final JavaPsiFacade facade = JavaPsiFacade.getInstance(context.getProject());
|
||||
PsiElementFactory elementFactory = facade.getElementFactory();
|
||||
|
||||
if (!PsiUtil.isInStaticContext(this)) return elementFactory.createType(context);
|
||||
|
||||
//create instance of java.lang.Class<CurrentClass>
|
||||
if (context instanceof PsiAnonymousClass) {
|
||||
final PsiClassType type = ((PsiAnonymousClass)context).getBaseClassType();
|
||||
final PsiClass aClass =
|
||||
facade.findClass(CommonClassNames.JAVA_LANG_CLASS, context.getResolveScope());
|
||||
if (aClass != null) {
|
||||
return elementFactory.createType(aClass, type);
|
||||
}
|
||||
else {
|
||||
return elementFactory.createTypeFromText(CommonClassNames.JAVA_LANG_CLASS + "<" + type.getCanonicalText() + ">", this);
|
||||
}
|
||||
}
|
||||
return elementFactory.createType(context);
|
||||
return elementFactory.createTypeFromText(CommonClassNames.JAVA_LANG_CLASS + "<" + context.getName() + ">", this);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -538,4 +538,21 @@ class Bar {{
|
||||
void testOctalInspection() {
|
||||
doTest(new GroovyOctalIntegerInspection())
|
||||
}
|
||||
|
||||
void testThisInStaticMethodOfAnonymousClass() {
|
||||
myFixture.configureByText('a.groovy', '''\
|
||||
class A {
|
||||
static abc
|
||||
def foo() {
|
||||
new Runnable() {
|
||||
<error descr="Inner classes cannot have static declarations">static</error> void run() {
|
||||
print this.@abc
|
||||
}
|
||||
}.run()
|
||||
}
|
||||
}''')
|
||||
|
||||
myFixture.enableInspections(GroovyAssignabilityCheckInspection)
|
||||
myFixture.checkHighlighting(true, false, false);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user