boolean (@NotNull PsiElement element) { PsiElement parent = element.getParent(); if (element instanceof PsiExpressionListStatement) { // statement list allowed in for() init or update only if (!(parent instanceof PsiForStatement)) return false; PsiForStatement forStatement = (PsiForStatement)parent; if (!(element == forStatement.getInitialization() || element == forStatement.getUpdate())) return false; PsiExpressionList expressionList = ((PsiExpressionListStatement)element).getExpressionList(); for (PsiExpression expression : expressionList.getExpressions()) { if (!isStatement(expression)) return false; } return true; } if (element instanceof PsiExpressionStatement) { return parent instanceof PsiSwitchLabeledRuleStatement && ((PsiSwitchLabeledRuleStatement)parent).getEnclosingSwitchBlock() instanceof PsiSwitchExpression || isStatement(((PsiExpressionStatement)element).getExpression()); } if (element instanceof PsiDeclarationStatement) { if (parent instanceof PsiCodeBlock) return true; if (parent instanceof PsiCodeFragment) return true; if (!(parent instanceof PsiForStatement) || ((PsiForStatement)parent).getBody() == element) { return false; } } if (element instanceof PsiStatement) return true; if (element instanceof PsiAssignmentExpression) return true; if (isIncrementDecrementOperation(element)) return true; if (element instanceof PsiMethodCallExpression) return true; if (element instanceof PsiNewExpression) { return !(((PsiNewExpression)element).getType() instanceof PsiArrayType); } return element instanceof PsiCodeBlock; }