mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-03-22 15:19:59 +07:00
PY-77490 Infer nullability annotations in PyDefUseUtil
(cherry picked from commit f993806b3d199160b8a18117fc6b473e52db13bb) IJ-CR-149696 GitOrigin-RevId: 773c097981921257681a67c58fd6ba2190a3a9c2
This commit is contained in:
committed by
intellij-monorepo-bot
parent
535af53f05
commit
bb5e98a07d
@@ -51,15 +51,23 @@ public final class PyDefUseUtil {
|
||||
private static final int MAX_CONTROL_FLOW_SIZE = 200;
|
||||
|
||||
@NotNull
|
||||
public static List<Instruction> getLatestDefs(ScopeOwner block, String varName, PsiElement anchor, boolean acceptTypeAssertions,
|
||||
boolean acceptImplicitImports, @NotNull TypeEvalContext context) {
|
||||
public static List<Instruction> getLatestDefs(@NotNull ScopeOwner block,
|
||||
@NotNull String varName,
|
||||
PsiElement anchor,
|
||||
boolean acceptTypeAssertions,
|
||||
boolean acceptImplicitImports,
|
||||
@NotNull TypeEvalContext context) {
|
||||
return getLatestDefs(ControlFlowCache.getControlFlow(block), varName, anchor, acceptTypeAssertions, acceptImplicitImports, context);
|
||||
}
|
||||
|
||||
|
||||
@NotNull
|
||||
public static List<Instruction> getLatestDefs(ControlFlow controlFlow, String varName, PsiElement anchor, boolean acceptTypeAssertions,
|
||||
boolean acceptImplicitImports, @NotNull TypeEvalContext context) {
|
||||
public static List<Instruction> getLatestDefs(@NotNull ControlFlow controlFlow,
|
||||
@NotNull String varName,
|
||||
PsiElement anchor,
|
||||
boolean acceptTypeAssertions,
|
||||
boolean acceptImplicitImports,
|
||||
@NotNull TypeEvalContext context) {
|
||||
final Instruction[] instructions = controlFlow.getInstructions();
|
||||
final PyAugAssignmentStatement augAssignment = PyAugAssignmentStatementNavigator.getStatementByTarget(anchor);
|
||||
if (augAssignment != null) {
|
||||
@@ -79,9 +87,12 @@ public final class PyDefUseUtil {
|
||||
return new ArrayList<>(result);
|
||||
}
|
||||
|
||||
private static Collection<Instruction> getLatestDefs(final String varName, final Instruction[] instructions, final int startNum,
|
||||
final boolean acceptTypeAssertions, final boolean acceptImplicitImports,
|
||||
@NotNull final TypeEvalContext context) {
|
||||
private static @NotNull Collection<Instruction> getLatestDefs(final @NotNull String varName,
|
||||
final Instruction @NotNull [] instructions,
|
||||
final int startNum,
|
||||
final boolean acceptTypeAssertions,
|
||||
final boolean acceptImplicitImports,
|
||||
@NotNull final TypeEvalContext context) {
|
||||
final Collection<Instruction> result = new LinkedHashSet<>();
|
||||
final HashMap<PyCallSiteExpression, ConditionalInstruction> pendingTypeGuard = new HashMap<>();
|
||||
ControlFlowUtil.iteratePrev(startNum, instructions,
|
||||
@@ -162,7 +173,7 @@ public final class PyDefUseUtil {
|
||||
return element instanceof PyElement ? ((PyElement)element).getName() : null;
|
||||
}
|
||||
|
||||
public static PsiElement @NotNull [] getPostRefs(ScopeOwner block, PyTargetExpression var, PyExpression anchor) {
|
||||
public static PsiElement @NotNull [] getPostRefs(@NotNull ScopeOwner block, @NotNull PyTargetExpression var, PyExpression anchor) {
|
||||
final ControlFlow controlFlow = ControlFlowCache.getControlFlow(block);
|
||||
final Instruction[] instructions = controlFlow.getInstructions();
|
||||
final int instr = ControlFlowUtil.findInstructionNumberByElement(instructions, anchor);
|
||||
@@ -177,11 +188,11 @@ public final class PyDefUseUtil {
|
||||
return result.toArray(PyElement.EMPTY_ARRAY);
|
||||
}
|
||||
|
||||
private static void getPostRefs(PyTargetExpression var,
|
||||
private static void getPostRefs(@NotNull PyTargetExpression var,
|
||||
Instruction[] instructions,
|
||||
int instr,
|
||||
boolean[] visited,
|
||||
Collection<PyElement> result) {
|
||||
boolean @NotNull [] visited,
|
||||
@NotNull Collection<PyElement> result) {
|
||||
// TODO: Use ControlFlowUtil.process() for forwards CFG traversal
|
||||
if (visited[instr]) return;
|
||||
visited[instr] = true;
|
||||
|
||||
Reference in New Issue
Block a user