use of com.intellij.refactoring.util.classMembers.MemberInfo in project intellij-community by JetBrains.
the class ExtractInterfaceDialog method createCenterPanel.
protected JComponent createCenterPanel() {
JPanel panel = new JPanel(new BorderLayout());
final MemberSelectionPanel memberSelectionPanel = new MemberSelectionPanel(RefactoringBundle.message("members.to.form.interface"), myMemberInfos, RefactoringBundle.message("make.abstract"));
memberSelectionPanel.getTable().setMemberInfoModel(new DelegatingMemberInfoModel<PsiMember, MemberInfo>(memberSelectionPanel.getTable().getMemberInfoModel()) {
public Boolean isFixedAbstract(MemberInfo member) {
return Boolean.TRUE;
}
});
panel.add(memberSelectionPanel, BorderLayout.CENTER);
panel.add(myDocCommentPanel, BorderLayout.EAST);
return panel;
}
use of com.intellij.refactoring.util.classMembers.MemberInfo in project intellij-community by JetBrains.
the class JavaTestGenerator method addTestMethods.
public static void addTestMethods(Editor editor, PsiClass targetClass, @Nullable PsiClass sourceClass, final TestFramework descriptor, Collection<MemberInfo> methods, boolean generateBefore, boolean generateAfter) throws IncorrectOperationException {
final Set<String> existingNames = new HashSet<>();
PsiMethod anchor = null;
if (generateBefore && descriptor.findSetUpMethod(targetClass) == null) {
anchor = generateMethod(TestIntegrationUtils.MethodKind.SET_UP, descriptor, targetClass, sourceClass, editor, null, existingNames, null);
}
if (generateAfter && descriptor.findTearDownMethod(targetClass) == null) {
anchor = generateMethod(TestIntegrationUtils.MethodKind.TEAR_DOWN, descriptor, targetClass, sourceClass, editor, null, existingNames, anchor);
}
final Template template = TestIntegrationUtils.createTestMethodTemplate(TestIntegrationUtils.MethodKind.TEST, descriptor, targetClass, sourceClass, null, true, existingNames);
JVMElementFactory elementFactory = JVMElementFactories.getFactory(targetClass.getLanguage(), targetClass.getProject());
final String prefix = elementFactory != null ? elementFactory.createMethodFromText(template.getTemplateText(), targetClass).getName() : "";
existingNames.addAll(ContainerUtil.map(targetClass.getMethods(), method -> StringUtil.decapitalize(StringUtil.trimStart(method.getName(), prefix))));
for (MemberInfo m : methods) {
anchor = generateMethod(TestIntegrationUtils.MethodKind.TEST, descriptor, targetClass, sourceClass, editor, m.getMember().getName(), existingNames, anchor);
}
}
use of com.intellij.refactoring.util.classMembers.MemberInfo in project intellij-community by JetBrains.
the class MissedTestsDialog method updateMethodsTable.
private void updateMethodsTable() {
List<MemberInfo> infos = TestIntegrationUtils.extractClassMethods(mySourceClass, myIncludeInheritedCb.isSelected());
Set<PsiMember> selectedMethods = new HashSet<>();
for (MemberInfo each : myTable.getSelectedMemberInfos()) {
selectedMethods.add(each.getMember());
}
for (MemberInfo each : infos) {
each.setChecked(selectedMethods.contains(each.getMember()));
}
myTable.setMemberInfos(infos);
}
use of com.intellij.refactoring.util.classMembers.MemberInfo in project intellij-community by JetBrains.
the class MemberSelectionTable method isAbstractColumnEditable.
@Override
protected boolean isAbstractColumnEditable(int rowIndex) {
MemberInfo info = myMemberInfos.get(rowIndex);
if (!(info.getMember() instanceof PsiMethod))
return false;
if (info.isStatic())
return false;
PsiMethod method = (PsiMethod) info.getMember();
if (method.hasModifierProperty(PsiModifier.ABSTRACT)) {
if (myMemberInfoModel.isFixedAbstract(info) != null) {
return false;
}
}
return info.isChecked() && myMemberInfoModel.isAbstractEnabled(info);
}
use of com.intellij.refactoring.util.classMembers.MemberInfo in project intellij-community by JetBrains.
the class PullUpTest method doTest.
private void doTest(final boolean checkMembersMovedCount, String conflictMessage, RefactoringTestUtil.MemberDescriptor... membersToFind) {
final MultiMap<PsiElement, String> conflictsMap = new MultiMap<>();
configureByFile(BASE_PATH + getTestName(false) + ".java");
PsiElement elementAt = getFile().findElementAt(getEditor().getCaretModel().getOffset());
final PsiClass sourceClass = PsiTreeUtil.getParentOfType(elementAt, PsiClass.class);
assertNotNull(sourceClass);
PsiClass targetClass = sourceClass.getSuperClass();
assertNotNull(targetClass);
if (!targetClass.isWritable()) {
final PsiClass[] interfaces = sourceClass.getInterfaces();
assertEquals(1, interfaces.length);
assertTrue(interfaces[0].isWritable());
targetClass = interfaces[0];
}
final MemberInfo[] infos = RefactoringTestUtil.findMembers(sourceClass, membersToFind);
final int[] countMoved = { 0 };
final MoveMemberListener listener = (aClass, member) -> {
assertEquals(sourceClass, aClass);
countMoved[0]++;
};
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, psiMethod -> 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 && !IGNORE_CONFLICTS.equals(conflictMessage)) {
TreeSet<String> conflicts = new TreeSet<>(conflictsMap.values());
assertEquals(conflictMessage, conflicts.iterator().next());
return;
}
if (checkMembersMovedCount) {
assertEquals(countMoved[0], membersToFind.length);
}
checkResultByFile(BASE_PATH + getTestName(false) + "_after.java");
}
Aggregations