PostfixTemplateExpressionSelector (Condition<? super PsiElement> additionalFilter) { return new PostfixTemplateExpressionSelectorBase(additionalFilter) { @Override protected List<PsiElement> getNonFilteredExpressions(@NotNull PsiElement context, @NotNull Document document, int offset) { boolean isEnhancedSwitchAvailable = HighlightingFeature.ENHANCED_SWITCH.isAvailable(context); List<PsiElement> result = new ArrayList<>(); for (PsiElement element = PsiTreeUtil.getNonStrictParentOfType(context, PsiExpression.class, PsiStatement.class); element instanceof PsiExpression; element = element.getParent()) { PsiElement parent = element.getParent(); if (parent instanceof PsiExpressionStatement) { result.add(element); } else if (isEnhancedSwitchAvailable && (isVariableInitializer(element, parent) || isRightSideOfAssignment(element, parent) || isReturnValue(element, parent) || isArgumentList(parent))) { result.add(element); } } return result; } @Override protected Condition<PsiElement> getFilters(int offset) { return and(super.getFilters(offset), getPsiErrorFilter()); } @NotNull @Override public Function<PsiElement, String> getRenderer() { return JavaPostfixTemplatesUtils.getRenderer(); } private static boolean isVariableInitializer(PsiElement element, PsiElement parent) { return parent instanceof PsiVariable && ((PsiVariable)parent).getInitializer() == element; } private static boolean isRightSideOfAssignment(PsiElement element, PsiElement parent) { return parent instanceof PsiAssignmentExpression && ((PsiAssignmentExpression)parent).getRExpression() == element; } private static boolean isReturnValue(PsiElement element, PsiElement parent) { return parent instanceof PsiReturnStatement && ((PsiReturnStatement)parent).getReturnValue() == element; } private static boolean isArgumentList(PsiElement parent) { return parent instanceof PsiExpressionList && parent.getParent() instanceof PsiCall; } }; }