List<VariableInfo> (GrStatement @NotNull [] statements, VariableInfo @NotNull [] vars) { Map<String, VariableInfo> names = new HashMap<>(); for (VariableInfo var : vars) { names.put(var.getName(), var); } List<VariableInfo> result = new ArrayList<>(); for (GrStatement statement : statements) { if (statement instanceof GrVariableDeclaration declaration) { for (GrVariable variable : declaration.getVariables()) { final VariableInfo removed = names.remove(variable.getName()); if (removed != null) { result.add(removed); } } } } for (String varName : names.keySet()) { if (ResolveUtil.resolveProperty(statements[statements.length - 1], varName) == null) { result.add(names.get(varName)); } } return result; }