private static boolean statementCanBePlacedAlong(final PsiElement element) { if (element instanceof JspTemplateStatement) { PsiElement neighbour = element.getPrevSibling(); // we can place statement inside scriptlet only return neighbour != null && !(neighbour instanceof JspTemplateStatement); } if (element instanceof PsiBlockStatement) return false; final PsiElement parent = element.getParent(); if (parent instanceof JspClassLevelDeclarationStatement) return false; if (parent instanceof PsiCodeBlock) return true; if (parent instanceof PsiIfStatement && (element == ((PsiIfStatement)parent).getThenBranch() || element == ((PsiIfStatement)parent).getElseBranch())) { return true; } if (parent instanceof PsiWhileStatement && element == ((PsiWhileStatement)parent).getBody()) { return true; } if (parent instanceof PsiDoWhileStatement && element == ((PsiDoWhileStatement)parent).getBody()) { return true; } // know nothing about that return false; }