void (@NotNull PsiElement element) { if (!(element instanceof PsiStatement statement)) { return; } final Project project = element.getProject(); if (ExpandBooleanPredicate.isBooleanAssignment(statement)) { final PsiExpressionStatement assignmentStatement = (PsiExpressionStatement)statement; final PsiAssignmentExpression assignmentExpression = (PsiAssignmentExpression)assignmentStatement.getExpression(); final PsiExpression rhs = assignmentExpression.getRExpression(); if (rhs == null) { return; } final CommentTracker tracker = new CommentTracker(); tracker.markUnchanged(rhs); final String lhsText = assignmentExpression.getLExpression().getText(); final String signText = assignmentExpression.getOperationSign().getText(); @NonNls final String newStatementText = "if(" + ((signText.length() == 2) ? lhsText + signText.charAt(0) : "") + "true)" + lhsText + "=true; else " + lhsText + "=false;"; final PsiIfStatement newIfStatement = (PsiIfStatement)JavaPsiFacade.getElementFactory(project).createStatementFromText(newStatementText, element); final PsiExpression condition = newIfStatement.getCondition(); assert condition != null; if (condition instanceof PsiBinaryExpression binaryExpression) { final PsiExpression operand = binaryExpression.getROperand(); if (operand != null) { operand.replace(rhs); } } else { condition.replace(rhs); } final PsiElement newElement = tracker.replaceAndRestoreComments(statement, newIfStatement); CodeStyleManager.getInstance(project).reformat(newElement); } else if (ExpandBooleanPredicate.isBooleanReturn(statement)) { final PsiReturnStatement returnStatement = (PsiReturnStatement)statement; final PsiExpression returnValue = returnStatement.getReturnValue(); if (returnValue == null) { return; } @NonNls final String newStatementText = "if(true) return true; else return false;"; final PsiIfStatement newIfStatement = (PsiIfStatement)JavaPsiFacade.getElementFactory(project).createStatementFromText(newStatementText, element); final PsiExpression condition = newIfStatement.getCondition(); assert condition != null; final CommentTracker tracker = new CommentTracker(); tracker.markUnchanged(returnValue); condition.replace(returnValue); final PsiElement newElement = tracker.replaceAndRestoreComments(statement, newIfStatement); CodeStyleManager.getInstance(project).reformat(newElement); } else if (ExpandBooleanPredicate.isBooleanDeclaration(statement)) { final PsiDeclarationStatement declarationStatement = (PsiDeclarationStatement)statement; final PsiElement declaredElement = declarationStatement.getDeclaredElements()[0]; if (!(declaredElement instanceof PsiLocalVariable variable)) { return; } final PsiExpression initializer = variable.getInitializer(); if (initializer == null) { return; } final String name = variable.getName(); @NonNls final String newStatementText = "if(true) " + name +"=true; else " + name + "=false;"; final PsiIfStatement newIfStatement = (PsiIfStatement)JavaPsiFacade.getElementFactory(project).createStatementFromText(newStatementText, statement); final PsiExpression condition = newIfStatement.getCondition(); assert condition != null; condition.replace(initializer); CodeStyleManager.getInstance(project).reformat(declarationStatement.getParent().addAfter(newIfStatement, declarationStatement)); final PsiTypeElement typeElement = variable.getTypeElement(); if (typeElement.isInferredType() && PsiTypesUtil.replaceWithExplicitType(typeElement) == null) { return; } initializer.delete(); } }