From 8658b30dde888d6fd9cedffeb391d184ad1aa955 Mon Sep 17 00:00:00 2001 From: peter Date: Wed, 14 Jan 2015 20:59:37 +0100 Subject: [PATCH] dfa: support outer class fields access with qualified this --- .../dataFlow/value/DfaExpressionFactory.java | 8 ++++++++ .../inspection/dataFlow/fixture/OptionalThis.java | 15 +++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/value/DfaExpressionFactory.java b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/value/DfaExpressionFactory.java index 92df8c858229..10332afeaed1 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/value/DfaExpressionFactory.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/value/DfaExpressionFactory.java @@ -107,6 +107,14 @@ public class DfaExpressionFactory { return myFactory.getConstFactory().createFromValue(value, type, null); } + if (expression instanceof PsiThisExpression) { + PsiJavaCodeReferenceElement qualifier = ((PsiThisExpression)expression).getQualifier(); + PsiElement target = qualifier == null ? null : qualifier.resolve(); + if (target instanceof PsiClass) { + return myFactory.getVarFactory().createVariableValue((PsiModifierListOwner)target, null, false, null); + } + } + return null; } diff --git a/java/java-tests/testData/inspection/dataFlow/fixture/OptionalThis.java b/java/java-tests/testData/inspection/dataFlow/fixture/OptionalThis.java index a7cbd4789e89..7e70f258dc44 100644 --- a/java/java-tests/testData/inspection/dataFlow/fixture/OptionalThis.java +++ b/java/java-tests/testData/inspection/dataFlow/fixture/OptionalThis.java @@ -43,4 +43,19 @@ class TestInspection { private void doSomething(@NotNull String s) { //... } +} + +class WithInner { + @Nullable Object o; + + { + new Runnable() { + @Override + public void run() { + if (WithInner.this.o != null) { + System.out.println(WithInner.this.o.toString()); + } + } + }; + } } \ No newline at end of file