use of com.intellij.refactoring.util.classMembers.MemberInfo in project intellij-community by JetBrains.
the class PushDownTest method doTestImplements.
private void doTestImplements(boolean toAbstract, boolean failure) {
configureByFile(BASE_PATH + getTestName(false) + ".java");
PsiClass currentClass = JavaPsiFacade.getInstance(getProject()).findClass("Test", GlobalSearchScope.projectScope(getProject()));
MemberInfoStorage memberInfoStorage = new MemberInfoStorage(currentClass, element -> true);
List<MemberInfo> members = memberInfoStorage.getClassMemberInfos(currentClass);
for (MemberInfo member : members) {
member.setChecked(true);
if (toAbstract) {
member.setToAbstract(toAbstract);
}
}
new PushDownProcessor<MemberInfo, PsiMember, PsiClass>(currentClass, members, new DocCommentPolicy(DocCommentPolicy.ASIS)) {
@Override
protected boolean showConflicts(@NotNull MultiMap<PsiElement, String> conflicts, UsageInfo[] usages) {
if (failure == conflicts.isEmpty()) {
fail(failure ? "Conflict was not detected" : "False conflict was detected");
}
return true;
}
}.run();
checkResultByFile(BASE_PATH + getTestName(false) + "_after.java");
}
use of com.intellij.refactoring.util.classMembers.MemberInfo in project intellij-community by JetBrains.
the class PushDownTest method doTest.
private void doTest(final boolean failure) {
configureByFile(BASE_PATH + getTestName(false) + ".java");
final PsiElement targetElement = TargetElementUtil.findTargetElement(getEditor(), TargetElementUtil.ELEMENT_NAME_ACCEPTED);
assertTrue("<caret> is not on member name", targetElement instanceof PsiMember);
final PsiMember psiMember = (PsiMember) targetElement;
final PsiClass currentClass = psiMember.getContainingClass();
assert currentClass != null;
final List<MemberInfo> membersToMove = new ArrayList<>();
final PsiField fieldByName = currentClass.findFieldByName("fieldToMove", false);
if (fieldByName != null) {
final MemberInfo memberInfo = new MemberInfo(fieldByName);
memberInfo.setChecked(true);
membersToMove.add(memberInfo);
}
final PsiClass classByName = currentClass.findInnerClassByName("ClassToMove", false);
if (classByName != null) {
final MemberInfo memberInfo = new MemberInfo(classByName);
memberInfo.setChecked(true);
membersToMove.add(memberInfo);
}
final MemberInfo memberInfo = new MemberInfo(psiMember);
memberInfo.setChecked(true);
membersToMove.add(memberInfo);
new PushDownProcessor<MemberInfo, PsiMember, PsiClass>(currentClass, membersToMove, new DocCommentPolicy(DocCommentPolicy.ASIS)) {
@Override
protected boolean showConflicts(@NotNull MultiMap<PsiElement, String> conflicts, UsageInfo[] usages) {
if (failure == conflicts.isEmpty()) {
fail(failure ? "Conflict was not detected" : "False conflict was detected");
}
return true;
}
}.run();
checkResultByFile(BASE_PATH + getTestName(false) + "_after.java");
}
use of com.intellij.refactoring.util.classMembers.MemberInfo in project intellij-community by JetBrains.
the class RemoveMiddleManTest method doTest.
private void doTest(final String conflict) throws Exception {
doTest((rootDir, rootAfter) -> {
PsiClass aClass = myJavaFacade.findClass("Test", GlobalSearchScope.allScope(getProject()));
if (aClass == null)
aClass = myJavaFacade.findClass("p.Test", GlobalSearchScope.allScope(getProject()));
assertNotNull("Class Test not found", aClass);
final PsiField field = aClass.findFieldByName("myField", false);
final Set<PsiMethod> methods = DelegationUtils.getDelegatingMethodsForField(field);
List<MemberInfo> infos = new ArrayList<>();
for (PsiMethod method : methods) {
final MemberInfo info = new MemberInfo(method);
info.setChecked(true);
info.setToAbstract(true);
infos.add(info);
}
try {
RemoveMiddlemanProcessor processor = new RemoveMiddlemanProcessor(field, infos);
processor.run();
LocalFileSystem.getInstance().refresh(false);
FileDocumentManager.getInstance().saveAllDocuments();
if (conflict != null)
fail("Conflict expected");
} catch (BaseRefactoringProcessor.ConflictsInTestsException e) {
if (conflict == null)
throw e;
assertEquals(conflict, e.getMessage());
}
});
}
use of com.intellij.refactoring.util.classMembers.MemberInfo in project intellij-community by JetBrains.
the class RemoveMiddlemanDialog method createCenterPanel.
protected JComponent createCenterPanel() {
final JPanel panel = new JPanel(new BorderLayout());
panel.setBorder(BorderFactory.createEmptyBorder(10, 0, 5, 0));
final MemberSelectionPanel selectionPanel = new MemberSelectionPanel("&Methods to inline", delegateMethods, "Delete");
final MemberSelectionTable table = selectionPanel.getTable();
table.setMemberInfoModel(new DelegatingMemberInfoModel<PsiMember, MemberInfo>(table.getMemberInfoModel()) {
@Override
public int checkForProblems(@NotNull final MemberInfo member) {
return hasSuperMethods(member) ? ERROR : OK;
}
@Override
public String getTooltipText(final MemberInfo member) {
if (hasSuperMethods(member))
return "Deletion will break type hierarchy";
return super.getTooltipText(member);
}
private boolean hasSuperMethods(final MemberInfo member) {
if (member.isChecked() && member.isToAbstract()) {
final PsiMember psiMember = member.getMember();
if (psiMember instanceof PsiMethod && ((PsiMethod) psiMember).findDeepestSuperMethods().length > 0) {
return true;
}
}
return false;
}
});
panel.add(selectionPanel, BorderLayout.CENTER);
return panel;
}
use of com.intellij.refactoring.util.classMembers.MemberInfo in project intellij-community by JetBrains.
the class RemoveMiddlemanHandler method invoke.
private static void invoke(final PsiField field, Editor editor) {
final Project project = field.getProject();
final Set<PsiMethod> delegating = DelegationUtils.getDelegatingMethodsForField(field);
if (delegating.isEmpty()) {
final String message = RefactorJBundle.message("cannot.perform.the.refactoring") + RefactorJBundle.message("field.selected.is.not.used.as.a.delegate");
CommonRefactoringUtil.showErrorHint(project, editor, message, REFACTORING_NAME, getHelpID());
return;
}
MemberInfo[] infos = new MemberInfo[delegating.size()];
int i = 0;
for (PsiMethod method : delegating) {
final MemberInfo memberInfo = new MemberInfo(method);
memberInfo.setChecked(true);
memberInfo.setToAbstract(method.findDeepestSuperMethods().length == 0);
infos[i++] = memberInfo;
}
new RemoveMiddlemanDialog(field, infos).show();
}
Aggregations