mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
functional expressions: pull up conflicts
This commit is contained in:
@@ -26,7 +26,6 @@ package com.intellij.refactoring.memberPullUp;
|
||||
|
||||
import com.intellij.openapi.actionSystem.CommonDataKeys;
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.actionSystem.PlatformDataKeys;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.ScrollType;
|
||||
|
||||
@@ -28,6 +28,7 @@ import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.search.searches.ClassInheritorsSearch;
|
||||
import com.intellij.psi.search.searches.FunctionalExpressionSearch;
|
||||
import com.intellij.psi.util.*;
|
||||
import com.intellij.refactoring.RefactoringBundle;
|
||||
import com.intellij.refactoring.classMembers.MemberInfoBase;
|
||||
@@ -104,6 +105,10 @@ public class PullUpConflictsUtil {
|
||||
}
|
||||
}
|
||||
}
|
||||
final PsiFunctionalExpression functionalExpression = FunctionalExpressionSearch.search(superClass).findFirst();
|
||||
if (functionalExpression != null) {
|
||||
conflicts.putValue(functionalExpression, RefactoringBundle.message("functional.interface.broken"));
|
||||
}
|
||||
}
|
||||
RefactoringConflictsUtil.analyzeAccessibilityConflicts(movedMembers, superClass, conflicts, VisibilityUtil.ESCALATE_VISIBILITY, targetRepresentativeElement, abstrMethods);
|
||||
if (superClass != null) {
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
interface I {
|
||||
void foo();
|
||||
}
|
||||
|
||||
class IImpl implements I {
|
||||
public void foo(){}
|
||||
public void g<caret>et() {}
|
||||
|
||||
{
|
||||
I i = () -> {};
|
||||
}
|
||||
}
|
||||
@@ -16,17 +16,24 @@
|
||||
package com.intellij.refactoring;
|
||||
|
||||
import com.intellij.JavaTestUtil;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.refactoring.listeners.JavaRefactoringListenerManager;
|
||||
import com.intellij.refactoring.listeners.MoveMemberListener;
|
||||
import com.intellij.refactoring.memberPullUp.PullUpConflictsUtil;
|
||||
import com.intellij.refactoring.memberPullUp.PullUpProcessor;
|
||||
import com.intellij.refactoring.util.DocCommentPolicy;
|
||||
import com.intellij.refactoring.util.classMembers.InterfaceContainmentVerifier;
|
||||
import com.intellij.refactoring.util.classMembers.MemberInfo;
|
||||
import com.intellij.testFramework.IdeaTestUtil;
|
||||
import com.intellij.util.containers.MultiMap;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* @author ven
|
||||
*/
|
||||
@@ -86,6 +93,11 @@ public class PullUpTest extends LightRefactoringTestCase {
|
||||
doTest(new RefactoringTestUtil.MemberDescriptor("get", PsiMethod.class));
|
||||
}
|
||||
|
||||
public void testNotFunctionalAnymore() {
|
||||
setLanguageLevel(LanguageLevel.JDK_1_8);
|
||||
doTest(true, "Functional expression demands functional interface to have exact one method", new RefactoringTestUtil.MemberDescriptor("get", PsiMethod.class));
|
||||
}
|
||||
|
||||
public void testAsDefault() {
|
||||
final RefactoringTestUtil.MemberDescriptor descriptor = new RefactoringTestUtil.MemberDescriptor("get", PsiMethod.class);
|
||||
doTest(descriptor);
|
||||
@@ -156,6 +168,13 @@ public class PullUpTest extends LightRefactoringTestCase {
|
||||
}
|
||||
|
||||
private void doTest(final boolean checkMembersMovedCount, RefactoringTestUtil.MemberDescriptor... membersToFind) {
|
||||
doTest(checkMembersMovedCount, null, membersToFind);
|
||||
}
|
||||
|
||||
private void doTest(final boolean checkMembersMovedCount,
|
||||
String conflictMessage,
|
||||
RefactoringTestUtil.MemberDescriptor... membersToFind) {
|
||||
final MultiMap<PsiElement, String> conflictsMap = new MultiMap<PsiElement, String>();
|
||||
configureByFile(BASE_PATH + getTestName(false) + ".java");
|
||||
PsiElement elementAt = getFile().findElementAt(getEditor().getCaretModel().getOffset());
|
||||
final PsiClass sourceClass = PsiTreeUtil.getParentOfType(elementAt, PsiClass.class);
|
||||
@@ -180,10 +199,35 @@ public class PullUpTest extends LightRefactoringTestCase {
|
||||
}
|
||||
};
|
||||
JavaRefactoringListenerManager.getInstance(getProject()).addMoveMembersListener(listener);
|
||||
final PsiDirectory targetDirectory = targetClass.getContainingFile().getContainingDirectory();
|
||||
final PsiPackage targetPackage = targetDirectory != null ? JavaDirectoryService.getInstance().getPackage(targetDirectory) : null;
|
||||
conflictsMap.putAllValues(
|
||||
PullUpConflictsUtil
|
||||
.checkConflicts(infos, sourceClass, targetClass, targetPackage, targetDirectory, new InterfaceContainmentVerifier() {
|
||||
@Override
|
||||
public boolean checkedInterfacesContain(PsiMethod psiMethod) {
|
||||
return PullUpProcessor.checkedInterfacesContain(Arrays.asList(infos), psiMethod);
|
||||
}
|
||||
})
|
||||
);
|
||||
final PullUpProcessor helper = new PullUpProcessor(sourceClass, targetClass, infos, new DocCommentPolicy(DocCommentPolicy.ASIS));
|
||||
helper.run();
|
||||
UIUtil.dispatchAllInvocationEvents();
|
||||
JavaRefactoringListenerManager.getInstance(getProject()).removeMoveMembersListener(listener);
|
||||
|
||||
if (conflictMessage != null && conflictsMap.isEmpty()) {
|
||||
fail("Conflict was not detected");
|
||||
}
|
||||
|
||||
if (conflictMessage == null && !conflictsMap.isEmpty()) {
|
||||
fail(conflictsMap.values().iterator().next());
|
||||
}
|
||||
|
||||
if (conflictMessage != null) {
|
||||
assertEquals(conflictMessage, conflictsMap.values().iterator().next());
|
||||
return;
|
||||
}
|
||||
|
||||
if (checkMembersMovedCount) {
|
||||
assertEquals(countMoved[0], membersToFind.length);
|
||||
}
|
||||
@@ -195,4 +239,9 @@ public class PullUpTest extends LightRefactoringTestCase {
|
||||
protected String getTestDataPath() {
|
||||
return JavaTestUtil.getJavaTestDataPath();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Sdk getProjectJDK() {
|
||||
return IdeaTestUtil.getMockJdk18();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user