mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-26 19:06:24 +07:00
prefer null and new to the void methods in expression context
This commit is contained in:
@@ -135,23 +135,40 @@ public class JavaCompletionSorting {
|
||||
|
||||
private static ExpectedTypeMatching getExpectedTypeMatching(LookupElement item, ExpectedTypeInfo[] expectedInfos) {
|
||||
PsiType itemType = JavaCompletionUtil.getLookupElementType(item);
|
||||
if (itemType == null) return ExpectedTypeMatching.normal;
|
||||
|
||||
for (final ExpectedTypeInfo expectedInfo : expectedInfos) {
|
||||
final PsiType defaultType = expectedInfo.getDefaultType();
|
||||
final PsiType expectedType = expectedInfo.getType();
|
||||
if (!expectedType.isValid()) {
|
||||
return ExpectedTypeMatching.normal;
|
||||
}
|
||||
if (itemType != null) {
|
||||
for (final ExpectedTypeInfo expectedInfo : expectedInfos) {
|
||||
final PsiType defaultType = expectedInfo.getDefaultType();
|
||||
final PsiType expectedType = expectedInfo.getType();
|
||||
|
||||
if (defaultType != expectedType && defaultType.isAssignableFrom(itemType)) {
|
||||
return ExpectedTypeMatching.ofDefaultType;
|
||||
if (defaultType != expectedType && defaultType.isAssignableFrom(itemType)) {
|
||||
return ExpectedTypeMatching.ofDefaultType;
|
||||
}
|
||||
if (expectedType.isAssignableFrom(itemType)) {
|
||||
return ExpectedTypeMatching.expected;
|
||||
}
|
||||
}
|
||||
if (expectedType.isAssignableFrom(itemType)) {
|
||||
return ExpectedTypeMatching.expected;
|
||||
}
|
||||
|
||||
boolean hasNonVoid = false;
|
||||
for (ExpectedTypeInfo info : expectedInfos) {
|
||||
if (!PsiType.VOID.equals(info.getType())) {
|
||||
hasNonVoid = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (hasNonVoid) {
|
||||
if (item.getObject() instanceof PsiKeyword) {
|
||||
String keyword = ((PsiKeyword)item.getObject()).getText();
|
||||
if (PsiKeyword.NEW.equals(keyword) || PsiKeyword.NULL.equals(keyword)) {
|
||||
return ExpectedTypeMatching.maybeExpected;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (expectedInfos.length > 0) {
|
||||
return ExpectedTypeMatching.unexpected;
|
||||
}
|
||||
|
||||
return ExpectedTypeMatching.normal;
|
||||
}
|
||||
|
||||
@@ -391,7 +408,9 @@ public class JavaCompletionSorting {
|
||||
private enum ExpectedTypeMatching {
|
||||
ofDefaultType,
|
||||
expected,
|
||||
maybeExpected,
|
||||
normal,
|
||||
unexpected,
|
||||
}
|
||||
|
||||
private static class PreferAccessible extends LookupElementWeigher {
|
||||
|
||||
Reference in New Issue
Block a user