1 package com
.intellij
.codeInspection
.dataFlow
.instructions
;
3 import com
.intellij
.codeInspection
.dataFlow
.DataFlowRunner
;
4 import com
.intellij
.codeInspection
.dataFlow
.DfaInstructionState
;
5 import com
.intellij
.codeInspection
.dataFlow
.DfaMemoryState
;
6 import com
.intellij
.codeInspection
.dataFlow
.InstructionVisitor
;
7 import com
.intellij
.codeInspection
.dataFlow
.value
.DfaValue
;
8 import com
.intellij
.psi
.PsiArrayAccessExpression
;
9 import com
.intellij
.psi
.PsiExpression
;
10 import com
.intellij
.psi
.PsiReferenceExpression
;
11 import org
.jetbrains
.annotations
.NonNls
;
12 import org
.jetbrains
.annotations
.Nullable
;
17 public class FieldReferenceInstruction
extends Instruction
{
18 private final PsiExpression myExpression
;
19 private final boolean myIsPhysical
;
20 @Nullable private final String mySyntheticFieldName
;
22 public FieldReferenceInstruction(PsiExpression expression
, @Nullable @NonNls String syntheticFieldName
) {
23 myExpression
= expression
;
24 myIsPhysical
= expression
.isPhysical();
25 mySyntheticFieldName
= syntheticFieldName
;
29 public DfaInstructionState
[] accept(DataFlowRunner runner
, DfaMemoryState stateBefore
, InstructionVisitor visitor
) {
30 return visitor
.visitFieldReference(this, runner
, stateBefore
);
33 public DfaInstructionState
[] apply(DataFlowRunner runner
, DfaMemoryState memState
) {
34 final DfaValue qualifier
= memState
.pop();
35 if (myIsPhysical
&& !memState
.applyNotNull(qualifier
)) {
36 onInstructionProducesNPE(runner
);
37 return DfaInstructionState
.EMPTY_ARRAY
;
40 return new DfaInstructionState
[]{new DfaInstructionState(runner
.getInstruction(getIndex() + 1), memState
)};
43 protected void onInstructionProducesNPE(final DataFlowRunner runner
) {
47 public String
toString() {
48 return "FIELD_REFERENCE: " + myExpression
.getText();
51 public PsiExpression
getExpression() { return myExpression
; }
53 public PsiExpression
getElementToAssert() {
54 if (mySyntheticFieldName
!= null) return myExpression
;
55 return myExpression
instanceof PsiArrayAccessExpression
56 ?
((PsiArrayAccessExpression
)myExpression
).getArrayExpression()
57 : ((PsiReferenceExpression
)myExpression
).getQualifierExpression();