PsiElementVisitor (@NotNull final ProblemsHolder holder, boolean isOnTheFly) { return new PsiElementVisitor() { @SuppressWarnings("unchecked") private static final Class<? extends UExpression>[] uExpressionClasses = new Class[] {UInjectionHost.class, UCallExpression.class, UReferenceExpression.class}; @Override public void visitElement(@NotNull PsiElement element) { super.visitElement(element); UExpression uElement = UastContextKt.toUElementOfExpectedTypes(element, uExpressionClasses); if (uElement == null) return; Value titleValue = getTitleValue(uElement, null); if (titleValue == null) return; List<UExpression> usages = I18nInspection.findIndirectUsages(uElement, false); if (usages.isEmpty()) { usages = Collections.singletonList(uElement); } EnumSet<Nls.Capitalization> capitalizationContexts = EnumSet.noneOf(Nls.Capitalization.class); for (UExpression usage : usages) { capitalizationContexts.add(getCapitalization(usage)); } capitalizationContexts.remove(Nls.Capitalization.NotSpecified); for (Nls.Capitalization capitalization : capitalizationContexts) { if (!titleValue.isSatisfied(capitalization)) { String message; LocalQuickFix fix = null; if (capitalizationContexts.size() > 1) { message = JavaI18nBundle.message("inspection.title.capitalization.mix.description"); } else if (titleValue instanceof DeclaredValue) { message = JavaI18nBundle.message("inspection.title.capitalization.mismatch.description", titleValue, getCapitalizationName(capitalization)); } else { fix = titleValue.canFix() && (element instanceof PsiExpression || uElement instanceof UCallExpression call && getPropertyArgument(call) != null) ? new TitleCapitalizationFix(titleValue, capitalization) : null; message = JavaI18nBundle.message("inspection.title.capitalization.description", titleValue, getCapitalizationName(capitalization)); } holder.registerProblem(element, message, ProblemHighlightType.GENERIC_ERROR_OR_WARNING, LocalQuickFix.notNullElements(fix)); } } } private static Nls.Capitalization getCapitalization(UExpression usage) { Nls.Capitalization capitalization = Nls.Capitalization.NotSpecified; NlsInfo info = NlsInfo.forExpression(usage, false); if (info instanceof NlsInfo.Localized) { capitalization = ((NlsInfo.Localized)info).getCapitalization(); } else if (info.getNlsStatus() == ThreeState.UNSURE) { UElement parent = usage.getUastParent(); if (usage instanceof UCallExpression && parent instanceof UQualifiedReferenceExpression) { parent = parent.getUastParent(); } UCallExpression call = ObjectUtils.tryCast(parent, UCallExpression.class); if (call != null) { PsiMethod method = call.resolve(); if (method != null) { PsiParameter parameter = AnnotationContext.getParameter(method, call, usage); if (parameter != null) { capitalization = getSupplierCapitalization(parameter); } } } } return capitalization; } }; }