String (@NotNull Field field) { final List<String> escaped = new ArrayList<>(); for (String part : field.getAttributesAndLookups()) { if (part.startsWith(".")) { escaped.add(part); } else if (part.startsWith("[")) { if (part.contains("\\")) { return null; } final String indexText = part.substring(1, part.length() - 1); if (indexText.matches("\\d+")) { escaped.add(part); continue; } final char originalQuote = myNodeInfo.getSingleQuote(); char targetQuote = PyStringLiteralUtil.flipQuote(originalQuote); // there are no escapes inside the fragment, so the lookup key cannot contain // the host string quote unless it's a multiline string literal if (indexText.indexOf(targetQuote) >= 0) { if (!myNodeInfo.isTripleQuoted() || indexText.indexOf(originalQuote) >= 0) { return null; } targetQuote = originalQuote; } escaped.add("[" + targetQuote + indexText + targetQuote + "]"); } } return StringUtil.join(escaped, ""); }