void (@NotNull Environment env) { PsiDocumentManager.getInstance(getProject()).commitDocument(getDocument()); int randomOffset = generatePsiOffset(env, null); PsiElement leaf = getFile().findElementAt(randomOffset); if (leaf != null) { List<PsiElement> elementsToWrap = new JavaParenthesesPolicy().getElementsToWrap(leaf); if (elementsToWrap.isEmpty()) return; PsiElement expr = env.generateValue(Generator.sampledFrom(elementsToWrap).noShrink(), null); if (!(expr instanceof PsiExpression)) return; PsiType type = ((PsiExpression)expr).getType(); if (type == null || type instanceof PsiDisjunctionType || !PsiTypesUtil.isDenotableType(type, expr)) return; //accept cast in expression statement env.logMessage("Inserting cast '" + StringUtil.escapeStringCharacters("(" + type.getCanonicalText() + ")") + "' at " + MadTestingUtil.getPositionDescription(expr.getTextOffset(), getDocument())); WriteCommandAction.runWriteCommandAction(getProject(), () -> AddTypeCastFix.addTypeCast(getProject(), (PsiExpression)expr, type)); } }