mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-19 13:02:30 +07:00
GuessManagerImpl: minimal assignment handling
This commit is contained in:
@@ -17,10 +17,7 @@ package com.intellij.codeInsight.guess.impl;
|
||||
|
||||
import com.intellij.codeInsight.guess.GuessManager;
|
||||
import com.intellij.codeInspection.dataFlow.*;
|
||||
import com.intellij.codeInspection.dataFlow.instructions.InstanceofInstruction;
|
||||
import com.intellij.codeInspection.dataFlow.instructions.MethodCallInstruction;
|
||||
import com.intellij.codeInspection.dataFlow.instructions.PushInstruction;
|
||||
import com.intellij.codeInspection.dataFlow.instructions.TypeCastInstruction;
|
||||
import com.intellij.codeInspection.dataFlow.instructions.*;
|
||||
import com.intellij.codeInspection.dataFlow.value.DfaInstanceofValue;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
@@ -422,6 +419,21 @@ public class GuessManagerImpl extends GuessManager {
|
||||
return super.visitTypeCast(instruction, runner, memState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DfaInstructionState[] visitAssign(AssignInstruction instruction, DataFlowRunner runner, DfaMemoryState memState) {
|
||||
PsiExpression left = instruction.getLExpression();
|
||||
PsiExpression right = instruction.getRExpression();
|
||||
if (left != null && right != null) {
|
||||
MultiMap<PsiExpression, PsiType> states = ((ExpressionTypeMemoryState)memState).getStates();
|
||||
states.remove(left);
|
||||
PsiType rightType = right.getType();
|
||||
if (rightType != null) {
|
||||
((ExpressionTypeMemoryState) memState).setExpressionType(left, runner.getFactory().createDfaType(rightType).getPsiType());
|
||||
}
|
||||
}
|
||||
return super.visitAssign(instruction, runner, memState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DfaInstructionState[] visitMethodCall(MethodCallInstruction instruction, DataFlowRunner runner, DfaMemoryState memState) {
|
||||
if (myForPlace == instruction.getCallExpression()) {
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
class Foo {
|
||||
void test(Object obj) {
|
||||
if(!(obj instanceof String)) {
|
||||
obj = "foo";
|
||||
}
|
||||
obj.subst<caret>
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
class Foo {
|
||||
void test(Object obj) {
|
||||
if(!(obj instanceof String)) {
|
||||
obj = "foo";
|
||||
}
|
||||
((String) obj).substring()
|
||||
}
|
||||
}
|
||||
@@ -42,6 +42,7 @@ class NormalCompletionDfaTest extends LightFixtureCompletionTestCase {
|
||||
void testQualifierCastingBeforeLt() { doTest() }
|
||||
void testCastQualifierForPrivateFieldReference() { doTest() }
|
||||
void testOrAssignmentDfa() { doTest() }
|
||||
void testInstanceOfAssignmentDfa() { doTest() }
|
||||
void testFieldWithCastingCaret() { doTest() }
|
||||
|
||||
void testCastTwice() {
|
||||
|
||||
Reference in New Issue
Block a user