mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
can be final: accept field initialized with this qualifier
This commit is contained in:
@@ -60,8 +60,9 @@ public class RefFieldImpl extends RefJavaElementImpl implements RefField {
|
||||
|
||||
if (forWriting && expressionFrom != null) {
|
||||
PsiClassInitializer initializer = PsiTreeUtil.getParentOfType(expressionFrom, PsiClassInitializer.class);
|
||||
if (initializer != null) {
|
||||
if (initializer.getParent() instanceof PsiClass && psiFrom == initializer.getParent() && !expressionFrom.isQualified()) {
|
||||
if (initializer != null && initializer.getParent() instanceof PsiClass && psiFrom == initializer.getParent()) {
|
||||
PsiExpression qualifierExpression = expressionFrom.getQualifierExpression();
|
||||
if (qualifierExpression == null || qualifierExpression instanceof PsiThisExpression && ((PsiThisExpression)qualifierExpression).getQualifier() == null) {
|
||||
referencedFromClassInitializer = true;
|
||||
}
|
||||
}
|
||||
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<problems>
|
||||
<problem>
|
||||
<file>Test.java</file>
|
||||
<line>2</line>
|
||||
<description>Declaration can have final modifier</description>
|
||||
</problem>
|
||||
</problems>
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
final class G {
|
||||
private Object foo;
|
||||
{
|
||||
this.foo = "";
|
||||
}
|
||||
|
||||
void fooBar() {
|
||||
System.out.println(foo);
|
||||
}
|
||||
}
|
||||
@@ -162,4 +162,8 @@ public class CanBeFinalTest extends InspectionTestCase {
|
||||
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testfieldInitializedInClassInitializer() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user