PsiElementVisitor (@NotNull ProblemsHolder holder, boolean isOnTheFly) { return new JavaElementVisitor() { @Override public void visitLiteralExpression(@NotNull PsiLiteralExpression literal) { if (!isNegativeHexLiteral(literal)) return; checkLongContext(literal); } @Override public void visitReferenceExpression(@NotNull PsiReferenceExpression ref) { PsiVariable variable = tryCast(ref.resolve(), PsiVariable.class); if (variable == null || !variable.hasModifierProperty(PsiModifier.FINAL)) return; PsiLiteralExpression initializer = tryCast(PsiUtil.skipParenthesizedExprDown(PsiFieldImpl.getDetachedInitializer(variable)), PsiLiteralExpression.class); if (initializer == null || !isNegativeHexLiteral(initializer)) return; checkLongContext(ref); } private void checkLongContext(@NotNull PsiExpression expression) { if (!PsiTypes.longType().equals(ExpectedTypeUtils.findExpectedType(expression, true))) return; if (isInAssertEqualsLong(expression)) return; LocalQuickFix[] fixes = null; if (expression instanceof PsiLiteralExpression) { fixes = new LocalQuickFix[]{ new AddLongSuffixFix(), new ConvertToLongFix() }; } holder.registerProblem(expression, InspectionGadgetsBundle.message("negative.int.constant.in.long.context.display.name"), fixes); } }; }