Search in sources :

Example 1 with MemberInfo

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;
}
Also used : MemberInfo(com.intellij.refactoring.util.classMembers.MemberInfo) MemberSelectionPanel(com.intellij.refactoring.ui.MemberSelectionPanel)

Example 2 with MemberInfo

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);
    }
}
Also used : FileTemplate(com.intellij.ide.fileTemplates.FileTemplate) TestFramework(com.intellij.testIntegration.TestFramework) Computable(com.intellij.openapi.util.Computable) ContainerUtil(com.intellij.util.containers.ContainerUtil) CodeInsightUtil(com.intellij.codeInsight.CodeInsightUtil) HashSet(java.util.HashSet) CodeInsightBundle(com.intellij.codeInsight.CodeInsightBundle) Comparing(com.intellij.openapi.util.Comparing) Project(com.intellij.openapi.project.Project) Messages(com.intellij.openapi.ui.Messages) MemberInfo(com.intellij.refactoring.util.classMembers.MemberInfo) FileModificationService(com.intellij.codeInsight.FileModificationService) Properties(java.util.Properties) IncorrectOperationException(com.intellij.util.IncorrectOperationException) FileTemplateManager(com.intellij.ide.fileTemplates.FileTemplateManager) StringUtil(com.intellij.openapi.util.text.StringUtil) Collection(java.util.Collection) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) Set(java.util.Set) Template(com.intellij.codeInsight.template.Template) IdeDocumentHistory(com.intellij.openapi.fileEditor.ex.IdeDocumentHistory) Editor(com.intellij.openapi.editor.Editor) TestIntegrationUtils(com.intellij.testIntegration.TestIntegrationUtils) Nullable(org.jetbrains.annotations.Nullable) GlobalSearchScopesCore(com.intellij.psi.search.GlobalSearchScopesCore) FileTemplateDescriptor(com.intellij.ide.fileTemplates.FileTemplateDescriptor) FileTemplateUtil(com.intellij.ide.fileTemplates.FileTemplateUtil) ApplicationManager(com.intellij.openapi.application.ApplicationManager) com.intellij.psi(com.intellij.psi) NotNull(org.jetbrains.annotations.NotNull) PostprocessReformattingAspect(com.intellij.psi.impl.source.PostprocessReformattingAspect) MemberInfo(com.intellij.refactoring.util.classMembers.MemberInfo) HashSet(java.util.HashSet) FileTemplate(com.intellij.ide.fileTemplates.FileTemplate) Template(com.intellij.codeInsight.template.Template)

Example 3 with MemberInfo

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);
}
Also used : MemberInfo(com.intellij.refactoring.util.classMembers.MemberInfo) HashSet(java.util.HashSet) PsiMember(com.intellij.psi.PsiMember)

Example 4 with MemberInfo

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);
}
Also used : MemberInfo(com.intellij.refactoring.util.classMembers.MemberInfo) PsiMethod(com.intellij.psi.PsiMethod)

Example 5 with MemberInfo

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");
}
Also used : PullUpConflictsUtil(com.intellij.refactoring.memberPullUp.PullUpConflictsUtil) UIUtil(com.intellij.util.ui.UIUtil) LanguageLevel(com.intellij.pom.java.LanguageLevel) MemberInfo(com.intellij.refactoring.util.classMembers.MemberInfo) Arrays(java.util.Arrays) JavaTestUtil(com.intellij.JavaTestUtil) DocCommentPolicy(com.intellij.refactoring.util.DocCommentPolicy) PullUpProcessor(com.intellij.refactoring.memberPullUp.PullUpProcessor) TreeSet(java.util.TreeSet) PsiTreeUtil(com.intellij.psi.util.PsiTreeUtil) MoveMemberListener(com.intellij.refactoring.listeners.MoveMemberListener) JavaRefactoringListenerManager(com.intellij.refactoring.listeners.JavaRefactoringListenerManager) com.intellij.psi(com.intellij.psi) NotNull(org.jetbrains.annotations.NotNull) MultiMap(com.intellij.util.containers.MultiMap) MoveMemberListener(com.intellij.refactoring.listeners.MoveMemberListener) MultiMap(com.intellij.util.containers.MultiMap) MemberInfo(com.intellij.refactoring.util.classMembers.MemberInfo) TreeSet(java.util.TreeSet) PullUpProcessor(com.intellij.refactoring.memberPullUp.PullUpProcessor) DocCommentPolicy(com.intellij.refactoring.util.DocCommentPolicy)

Aggregations

MemberInfo (com.intellij.refactoring.util.classMembers.MemberInfo)45 DocCommentPolicy (com.intellij.refactoring.util.DocCommentPolicy)12 PsiMethod (com.intellij.psi.PsiMethod)6 MultiMap (com.intellij.util.containers.MultiMap)6 ArrayList (java.util.ArrayList)6 Project (com.intellij.openapi.project.Project)5 com.intellij.psi (com.intellij.psi)5 MemberSelectionPanel (com.intellij.refactoring.ui.MemberSelectionPanel)5 IncorrectOperationException (com.intellij.util.IncorrectOperationException)5 HashSet (java.util.HashSet)5 Editor (com.intellij.openapi.editor.Editor)4 PsiClass (com.intellij.psi.PsiClass)4 PullUpProcessor (com.intellij.refactoring.memberPullUp.PullUpProcessor)4 DialogWrapper (com.intellij.openapi.ui.DialogWrapper)3 PsiMember (com.intellij.psi.PsiMember)3 MemberSelectionTable (com.intellij.refactoring.ui.MemberSelectionTable)3 MemberInfoStorage (com.intellij.refactoring.util.classMembers.MemberInfoStorage)3 UsageInfo (com.intellij.usageView.UsageInfo)3 NotNull (org.jetbrains.annotations.NotNull)3 Nullable (org.jetbrains.annotations.Nullable)3