mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-21 22:11:40 +07:00
ExpressionTypeMemoryState:isSuperStateOf to check additional field
Fixes IDEA-183267 Completion based on instanceof is gone
This commit is contained in:
@@ -27,6 +27,9 @@ import com.intellij.util.containers.MultiMap;
|
||||
import gnu.trove.TObjectHashingStrategy;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author peter
|
||||
*/
|
||||
@@ -68,6 +71,22 @@ public class ExpressionTypeMemoryState extends DfaMemoryStateImpl {
|
||||
return copy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSuperStateOf(DfaMemoryStateImpl that) {
|
||||
if (!super.isSuperStateOf(that)) {
|
||||
return false;
|
||||
}
|
||||
MultiMap<PsiExpression, PsiType> thatStates = ((ExpressionTypeMemoryState)that).myStates;
|
||||
for (Map.Entry<PsiExpression, Collection<PsiType>> entry : myStates.entrySet()) {
|
||||
Collection<PsiType> thisTypes = entry.getValue();
|
||||
Collection<PsiType> thatTypes = thatStates.get(entry.getKey());
|
||||
if (!thatTypes.containsAll(thisTypes)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean applyCondition(DfaValue dfaCond) {
|
||||
if (dfaCond instanceof DfaInstanceofValue) {
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
import java.math.BigInteger;
|
||||
import java.util.function.Function;
|
||||
|
||||
class Test {
|
||||
private static boolean instanceOfAfterFunction(Integer lambda,
|
||||
Function<Integer, Number> replacer, Object type) {
|
||||
Number function = replacer.apply(lambda);
|
||||
if (function instanceof BigInteger && ((BigInteger)function).bitCount() > 0) {
|
||||
return false;
|
||||
}
|
||||
if (type instanceof String && type.subst<caret>) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import java.math.BigInteger;
|
||||
import java.util.function.Function;
|
||||
|
||||
class Test {
|
||||
private static boolean instanceOfAfterFunction(Integer lambda,
|
||||
Function<Integer, Number> replacer, Object type) {
|
||||
Number function = replacer.apply(lambda);
|
||||
if (function instanceof BigInteger && ((BigInteger)function).bitCount() > 0) {
|
||||
return false;
|
||||
}
|
||||
if (type instanceof String && ((String) type).substring()) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -50,6 +50,7 @@ class NormalCompletionDfaTest extends NormalCompletionTestCase {
|
||||
void testCastWhenMethodComesFromDfaSuperType() { doTest() }
|
||||
void testGenericTypeDfa() { doTest() }
|
||||
void testNoUnnecessaryCastDfa() { doTest() }
|
||||
void testInstanceOfAfterFunction() { doTest() }
|
||||
|
||||
void testCastTwice() {
|
||||
configureByTestName()
|
||||
|
||||
Reference in New Issue
Block a user