PsiElementVisitor (@NotNull ProblemsHolder holder, boolean isOnTheFly) { if (!HighlightingFeature.STRING_TEMPLATES.isAvailable(holder.getFile())) return PsiElementVisitor.EMPTY_VISITOR; return new JavaElementVisitor() { @Override public void visitTemplateExpression(@NotNull PsiTemplateExpression expression) { PsiTemplate template = expression.getTemplate(); if (template == null) return; if (!JavaPsiStringTemplateUtil.isStrTemplate(expression.getProcessor())) return; for (PsiExpression embeddedExpression : template.getEmbeddedExpressions()) { if (isEmbeddedLiteralRedundant(embeddedExpression)) { holder.problem(embeddedExpression, InspectionGadgetsBundle.message("inspection.redundant.embedded.expression.message.literal")) .fix(new RemoveEmbeddedExpressionFix(embeddedExpression)).register(); } else if (embeddedExpression instanceof PsiEmptyExpressionImpl) { String text = template.getText(); TextRange rangeInParent = embeddedExpression.getTextRangeInParent(); int startIndex = text.lastIndexOf("\\{", rangeInParent.getStartOffset()); int endIndex = text.indexOf("}", rangeInParent.getEndOffset()); if (startIndex != -1 && endIndex != -1) { holder.problem(template, InspectionGadgetsBundle.message("inspection.redundant.embedded.expression.message.empty")) .range(TextRange.create(startIndex, endIndex + 1)) .fix(new RemoveEmbeddedExpressionFix(embeddedExpression)) .register(); } } } } }; }