boolean (@NotNull PsiElement variableNode) { final PsiElement parent = variableNode.getParent(); if (parent instanceof PsiContinueStatement) return true; if (parent instanceof PsiBreakStatement) return true; final PsiElement grandParent = parent.getParent(); if (parent instanceof PsiPatternVariable && grandParent instanceof PsiTypeTestPattern) { return !(grandParent.getParent() instanceof PsiParenthesizedPattern); } if (grandParent instanceof PsiReferenceList) return true; if (grandParent instanceof PsiPolyadicExpression) { return ((PsiPolyadicExpression)grandParent).getOperands().length > 2; } if (parent instanceof PsiReferenceExpression) { if (grandParent instanceof PsiReferenceExpression) return true; if (grandParent instanceof PsiReturnStatement) return true; if (grandParent instanceof PsiAssertStatement) return ((PsiAssertStatement)grandParent).getAssertDescription() == parent; if (grandParent instanceof PsiNameValuePair) return ((PsiNameValuePair)grandParent).getValue() == parent; if (grandParent instanceof PsiForStatement) return true; } if (grandParent instanceof PsiVariable) { return ((PsiVariable)grandParent).getInitializer() == parent; } if (grandParent instanceof PsiNewExpression) { return ((PsiNewExpression)grandParent).getArrayInitializer() != null; } if (grandParent instanceof PsiTypeElement) { final PsiElement greatGrandParent = grandParent.getParent(); if (greatGrandParent instanceof PsiTypeElement) { final PsiType type = ((PsiTypeElement)greatGrandParent).getType(); return type instanceof PsiWildcardType && ((PsiWildcardType)type).isExtends(); } if (greatGrandParent instanceof PsiMethod || greatGrandParent instanceof PsiVariable) { return true; } } if (grandParent instanceof PsiExpressionStatement) { final PsiElement greatGrandParent = grandParent.getParent(); if (greatGrandParent instanceof PsiForStatement && !PsiTreeUtil.isAncestor(((PsiForStatement)greatGrandParent).getBody(), variableNode, true)) { return true; } if (isCompleteStatement((PsiExpressionStatement)grandParent)) { if (greatGrandParent instanceof PsiLoopStatement || (greatGrandParent instanceof PsiIfStatement && ((PsiIfStatement)greatGrandParent).getElseBranch() != grandParent)) return false; return !(greatGrandParent instanceof PsiCodeBlock) || !(greatGrandParent.getParent() instanceof JavaDummyHolder) || PsiTreeUtil.getChildrenOfAnyType(greatGrandParent, PsiStatement.class, PsiComment.class).size() > 1; } } return false; }