mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-152289 Code completion suggests "return" as the first result in the empty constructor
This commit is contained in:
@@ -168,7 +168,9 @@ public class PreferByKindWeigher extends LookupElementWeigher {
|
||||
|
||||
if (object instanceof PsiKeyword) {
|
||||
String keyword = ((PsiKeyword)object).getText();
|
||||
if (PsiKeyword.RETURN.equals(keyword) && isLastStatement(PsiTreeUtil.getParentOfType(myPosition, PsiStatement.class))) {
|
||||
if (PsiKeyword.RETURN.equals(keyword) &&
|
||||
isLastStatement(PsiTreeUtil.getParentOfType(myPosition, PsiStatement.class)) &&
|
||||
!isOnTopLevelInVoidMethod(myPosition)) {
|
||||
return MyResult.probableKeyword;
|
||||
}
|
||||
if (PsiKeyword.ELSE.equals(keyword) || PsiKeyword.FINALLY.equals(keyword)) {
|
||||
@@ -262,6 +264,17 @@ public class PreferByKindWeigher extends LookupElementWeigher {
|
||||
return MyResult.normal;
|
||||
}
|
||||
|
||||
private static boolean isOnTopLevelInVoidMethod(PsiElement position) {
|
||||
PsiCodeBlock block = PsiTreeUtil.getParentOfType(position, PsiCodeBlock.class);
|
||||
if (block != null) {
|
||||
PsiElement parent = block.getParent();
|
||||
if (parent instanceof PsiMethod) {
|
||||
return ((PsiMethod)parent).isConstructor() || PsiType.VOID.equals(((PsiMethod)parent).getReturnType());
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean isGetter(Object object) {
|
||||
if (!(object instanceof PsiMethod)) return false;
|
||||
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
class Util {
|
||||
void foo(int reaction, boolean rezet) {
|
||||
int foo(int reaction, boolean rezet) {
|
||||
re<caret>
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
class Util {
|
||||
Util(int reaction, boolean rezet) {
|
||||
re<caret>
|
||||
}
|
||||
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
class Util {
|
||||
void foo(int reaction, boolean rezet) {
|
||||
re<caret>
|
||||
}
|
||||
|
||||
}
|
||||
+8
@@ -435,6 +435,14 @@ interface TxANotAnno {}
|
||||
checkPreferredItems 0, 'reaction', 'rezet', 'return'
|
||||
}
|
||||
|
||||
public void testDispreferReturnInConstructor() {
|
||||
checkPreferredItems 0, 'reaction', 'rezet', 'return'
|
||||
}
|
||||
|
||||
public void testDispreferReturnInVoidMethodTopLevel() {
|
||||
checkPreferredItems 0, 'reaction', 'rezet', 'return'
|
||||
}
|
||||
|
||||
public void testDoNotPreferGetClass() {
|
||||
checkPreferredItems 0, 'get', 'getClass'
|
||||
incUseCount(lookup, 1)
|
||||
|
||||
Reference in New Issue
Block a user