ExpectedTypeMatching (LookupElement item, ExpectedTypeInfo[] expectedInfos, @Nullable String expectedMemberName, @NotNull PsiElement position) { PsiType itemType = JavaCompletionUtil.getLookupElementType(item); if (itemType != null) { PsiUtil.ensureValidType(itemType); for (final ExpectedTypeInfo expectedInfo : expectedInfos) { PsiType expectedType = expectedInfo.getType(); if (expectedInfo.getKind() == ExpectedTypeInfo.TYPE_OR_SUPERTYPE) { if (itemType.isAssignableFrom(expectedType)) { return ExpectedTypeMatching.expected; } } else { PsiType defaultType = expectedInfo.getDefaultType(); if (defaultType != expectedType && defaultType.isAssignableFrom(itemType)) { return ExpectedTypeMatching.ofDefaultType; } if (expectedType.isAssignableFrom(itemType)) { return ExpectedTypeMatching.expected; } } } } if (hasNonVoid(expectedInfos)) { if (item.getObject() instanceof PsiKeyword) { String keyword = ((PsiKeyword)item.getObject()).getText(); if (PsiKeyword.NEW.equals(keyword) && !(position.getParent() instanceof PsiMethodReferenceExpression) || PsiKeyword.NULL.equals(keyword)) { return ExpectedTypeMatching.maybeExpected; } } } else if (expectedInfos.length > 0) { return ExpectedTypeMatching.unexpected; } return preferByMemberName(expectedMemberName, itemType); }