ThreeState (String keyword) { PsiStatement parentStatement = PsiTreeUtil.getParentOfType(myPosition, PsiStatement.class); if (PsiKeyword.RETURN.equals(keyword)) { if (isLastStatement(parentStatement) && !isOnTopLevelInVoidMethod(parentStatement) && !(parentStatement.getParent() instanceof PsiLoopStatement)) { return ThreeState.YES; } } if ((PsiKeyword.BREAK.equals(keyword) || PsiKeyword.CONTINUE.equals(keyword)) && PsiTreeUtil.getParentOfType(myPosition, PsiLoopStatement.class) != null && isLastStatement(parentStatement)) { return ThreeState.YES; } if (PsiKeyword.ELSE.equals(keyword) || PsiKeyword.FINALLY.equals(keyword) || PsiKeyword.CATCH.equals(keyword)) { return ThreeState.YES; } if (PsiKeyword.TRUE.equals(keyword) || PsiKeyword.FALSE.equals(keyword)) { if (myCompletionType == CompletionType.SMART) { boolean inReturn = psiElement().withParents(PsiReferenceExpression.class, PsiReturnStatement.class).accepts(myPosition); return inReturn ? ThreeState.YES : ThreeState.UNSURE; } else if (ContainerUtil.exists(myExpectedTypes, info -> PsiTypes.booleanType().isAssignableFrom(info.getDefaultType())) && !(myPosition.getParent() instanceof PsiIfStatement)) { return ThreeState.YES; } } if (PsiKeyword.INTERFACE.equals(keyword) && psiElement().afterLeaf("@").accepts(myPosition)) { return ThreeState.NO; } if (PsiKeyword.NULL.equals(keyword) && isComparisonRhs(myPosition)) { boolean expectsNotNull = ContainerUtil.exists(myExpectedTypes, PreferByKindWeigher::isEnumClass); return expectsNotNull ? ThreeState.NO : ThreeState.YES; } if (JavaKeywordCompletion.PRIMITIVE_TYPES.contains(keyword) || PsiKeyword.VOID.equals(keyword)) { boolean inCallArg = psiElement().withParents(PsiReferenceExpression.class, PsiExpressionList.class).accepts(myPosition); return inCallArg || isInMethodTypeArg(myPosition) ? ThreeState.NO : ThreeState.UNSURE; } if (PsiKeyword.FINAL.equals(keyword) && isBeforeVariableOnSameLine(parentStatement)) { return ThreeState.YES; } return ThreeState.UNSURE; }