mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
default methods: filter out defaults from anonymous completion (IDEA-98954)
This commit is contained in:
@@ -22,11 +22,13 @@ import com.intellij.psi.codeStyle.CodeStyleManager;
|
||||
import com.intellij.psi.impl.source.PostprocessReformattingAspect;
|
||||
import com.intellij.psi.infos.CandidateInfo;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -221,6 +223,15 @@ public class ConstructorInsertHandler implements InsertHandler<LookupElementDeco
|
||||
if (aClass == null) return;
|
||||
|
||||
final Collection<CandidateInfo> candidatesToImplement = OverrideImplementUtil.getMethodsToOverrideImplement(aClass, true);
|
||||
if (PsiUtil.isLanguageLevel8OrHigher(aClass)) {
|
||||
for (Iterator<CandidateInfo> iterator = candidatesToImplement.iterator(); iterator.hasNext(); ) {
|
||||
final CandidateInfo candidate = iterator.next();
|
||||
final PsiElement element = candidate.getElement();
|
||||
if (element instanceof PsiMethod && ((PsiMethod)element).hasModifierProperty(PsiModifier.DEFAULT)) {
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
boolean invokeOverride = candidatesToImplement.isEmpty();
|
||||
if (invokeOverride){
|
||||
OverrideImplementUtil.chooseAndOverrideOrImplementMethods(project, editor, aClass, false);
|
||||
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
interface Predicate<T> {
|
||||
public boolean test(T t);
|
||||
public default Predicate<T> and(Predicate<? super T> p) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class Test1 {
|
||||
{
|
||||
Predicate p = new Predicate() {
|
||||
@Override
|
||||
public boolean test(Object o) {
|
||||
<selection>return false; //To change body of implemented methods use File | Settings | File Templates.</selection>
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
interface Predicate<T> {
|
||||
public boolean test(T t);
|
||||
public default Predicate<T> and(Predicate<? super T> p) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class Test1 {
|
||||
{
|
||||
Predicate p = new Predic<caret>
|
||||
}
|
||||
}
|
||||
+4
-1
@@ -17,7 +17,6 @@ package com.intellij.codeInsight.completion;
|
||||
|
||||
import com.intellij.JavaTestUtil;
|
||||
import com.intellij.codeInsight.lookup.Lookup;
|
||||
import com.intellij.codeInsight.lookup.LookupElementPresentation;
|
||||
import com.intellij.testFramework.LightProjectDescriptor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -63,6 +62,10 @@ public class SmartType18CompletionTest extends LightFixtureCompletionTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testIgnoreDefaultMethods() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
private void doTest() {
|
||||
configureByFile("/" + getTestName(false) + ".java");
|
||||
assertNotNull(myItems);
|
||||
|
||||
Reference in New Issue
Block a user