PatternVariableCandidate (@NotNull Statement ifBranch, @NotNull VarExprent operand, @NotNull ConstExprent checkType, @NotNull VarTracker varTracker, @NotNull Statement topLevelStatement) { if (ifBranch instanceof BasicBlockStatement) { //check that cast correct and get the last assignment PatternVariableCandidate candidate = findSimpleCandidateFromIfStat(ifBranch, operand, checkType, topLevelStatement); //check what if it is record patterns VarTracker newVarTracker = varTracker.copy(); if (newVarTracker == null) { return candidate; } RecordVarExprent previousRecord = newVarTracker.getRecord(operand); if (previousRecord == null) { return candidate; } previousRecord.setVarType(checkType.getConstType()); if (!(ifBranch.getParent() instanceof IfStatement)) { //prevent infinite recursion PatternVariableCandidate recordCandidate = findRecordPatternCandidate(ifBranch.getParent(), newVarTracker); if (recordCandidate != null) { varTracker.putAll(newVarTracker); return recordCandidate; } } return candidate; } if (ifBranch instanceof SequenceStatement || ifBranch instanceof IfStatement) { return findNextPatternVarCandidate(ifBranch.getFirst(), operand, checkType, varTracker, topLevelStatement); } return null; }