Search in sources :

Example 41 with MemberInfo

use of com.intellij.refactoring.util.classMembers.MemberInfo in project intellij-community by JetBrains.

the class JavaPushDownDelegate method findInheritors.

@Override
public List<PsiElement> findInheritors(PushDownData<MemberInfo, PsiMember> pushDownData) {
    final List<PsiElement> result = new ArrayList<>();
    final PsiClass aClass = (PsiClass) pushDownData.getSourceClass();
    ClassInheritorsSearch.search(aClass, false).forEach((iClass) -> {
        result.add(iClass);
        return true;
    });
    final PsiMethod interfaceMethod = LambdaUtil.getFunctionalInterfaceMethod(aClass);
    if (interfaceMethod != null) {
        for (MemberInfo info : pushDownData.getMembersToMove()) {
            if (interfaceMethod == info.getMember()) {
                FunctionalExpressionSearch.search(aClass).forEach(expression -> {
                    result.add(expression);
                    return true;
                });
                break;
            }
        }
    }
    return result;
}
Also used : MemberInfo(com.intellij.refactoring.util.classMembers.MemberInfo)

Example 42 with MemberInfo

use of com.intellij.refactoring.util.classMembers.MemberInfo in project intellij-community by JetBrains.

the class ExtractSuperClassTest method testAnonymClass.

public void testAnonymClass() throws Exception {
    String rootBefore = getRoot() + "/before";
    PsiTestUtil.removeAllRoots(myModule, IdeaTestUtil.getMockJdk14());
    final VirtualFile rootDir = PsiTestUtil.createTestProjectStructure(myProject, myModule, rootBefore, myFilesToDelete);
    PsiClass psiClass = myJavaFacade.findClass("Test", ProjectScope.getAllScope(myProject));
    assertNotNull(psiClass);
    final PsiField[] fields = psiClass.getFields();
    assertTrue(fields.length == 1);
    final PsiExpression initializer = fields[0].getInitializer();
    assertNotNull(initializer);
    assertInstanceOf(initializer, PsiNewExpression.class);
    final PsiAnonymousClass anonymousClass = ((PsiNewExpression) initializer).getAnonymousClass();
    assertNotNull(anonymousClass);
    final ArrayList<MemberInfo> infos = new ArrayList<>();
    MemberInfo.extractClassMembers(anonymousClass, infos, member -> true, false);
    for (MemberInfo info : infos) {
        info.setChecked(true);
    }
    new WriteCommandAction.Simple(myProject) {

        @Override
        protected void run() throws Throwable {
            ExtractSuperClassUtil.extractSuperClass(myProject, psiClass.getContainingFile().getContainingDirectory(), "TestSubclass", anonymousClass, infos.toArray(new MemberInfo[infos.size()]), new DocCommentPolicy(DocCommentPolicy.ASIS));
        }
    }.execute();
    String rootAfter = getRoot() + "/after";
    VirtualFile rootDir2 = LocalFileSystem.getInstance().findFileByPath(rootAfter.replace(File.separatorChar, '/'));
    myProject.getComponent(PostprocessReformattingAspect.class).doPostponedFormatting();
    IdeaTestUtil.assertDirectoriesEqual(rootDir2, rootDir);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) ArrayList(java.util.ArrayList) PostprocessReformattingAspect(com.intellij.psi.impl.source.PostprocessReformattingAspect) MemberInfo(com.intellij.refactoring.util.classMembers.MemberInfo) DocCommentPolicy(com.intellij.refactoring.util.DocCommentPolicy)

Example 43 with MemberInfo

use of com.intellij.refactoring.util.classMembers.MemberInfo in project intellij-community by JetBrains.

the class CreateTestDialog method updateMethodsTable.

private void updateMethodsTable() {
    List<MemberInfo> methods = TestIntegrationUtils.extractClassMethods(myTargetClass, myShowInheritedMethodsBox.isSelected());
    Set<PsiMember> selectedMethods = new HashSet<>();
    for (MemberInfo each : myMethodsTable.getSelectedMemberInfos()) {
        selectedMethods.add(each.getMember());
    }
    for (MemberInfo each : methods) {
        each.setChecked(selectedMethods.contains(each.getMember()));
    }
    myMethodsTable.setMemberInfos(methods);
}
Also used : MemberInfo(com.intellij.refactoring.util.classMembers.MemberInfo)

Example 44 with MemberInfo

use of com.intellij.refactoring.util.classMembers.MemberInfo in project intellij-community by JetBrains.

the class MissedTestsDialog method disableMethodsWithTests.

private void disableMethodsWithTests(List<MemberInfo> info) {
    final Set<String> existingNames = new HashSet<>();
    final String prefix = getTestPrefix(existingNames);
    existingNames.addAll(ContainerUtil.map(myTestClass.getMethods(), method -> StringUtil.decapitalize(StringUtil.trimStart(method.getName(), prefix))));
    for (MemberInfo memberInfo : info) {
        final PsiMember member = memberInfo.getMember();
        memberInfo.setChecked(!(member instanceof PsiMethod && existingNames.contains(member.getName())));
    }
}
Also used : ActionListener(java.awt.event.ActionListener) TestFramework(com.intellij.testIntegration.TestFramework) JavaPsiFacade(com.intellij.psi.JavaPsiFacade) MemberSelectionTable(com.intellij.refactoring.ui.MemberSelectionTable) ContainerUtil(com.intellij.util.containers.ContainerUtil) HashSet(java.util.HashSet) CodeInsightBundle(com.intellij.codeInsight.CodeInsightBundle) PsiClass(com.intellij.psi.PsiClass) DialogWrapper(com.intellij.openapi.ui.DialogWrapper) Project(com.intellij.openapi.project.Project) MemberInfo(com.intellij.refactoring.util.classMembers.MemberInfo) PsiMember(com.intellij.psi.PsiMember) JBCheckBox(com.intellij.ui.components.JBCheckBox) IncorrectOperationException(com.intellij.util.IncorrectOperationException) PsiMethod(com.intellij.psi.PsiMethod) StringUtil(com.intellij.openapi.util.text.StringUtil) Collection(java.util.Collection) Set(java.util.Set) Template(com.intellij.codeInsight.template.Template) ActionEvent(java.awt.event.ActionEvent) TestIntegrationUtils(com.intellij.testIntegration.TestIntegrationUtils) java.awt(java.awt) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) Function(com.intellij.util.Function) ScrollPaneFactory(com.intellij.ui.ScrollPaneFactory) javax.swing(javax.swing) MemberInfo(com.intellij.refactoring.util.classMembers.MemberInfo) PsiMethod(com.intellij.psi.PsiMethod) HashSet(java.util.HashSet) PsiMember(com.intellij.psi.PsiMember)

Example 45 with MemberInfo

use of com.intellij.refactoring.util.classMembers.MemberInfo in project intellij-community by JetBrains.

the class MissedTestsDialog method createCenterPanel.

@Nullable
@Override
protected JComponent createCenterPanel() {
    final List<MemberInfo> info = TestIntegrationUtils.extractClassMethods(mySourceClass, false);
    disableMethodsWithTests(info);
    final JPanel panel = new JPanel(new BorderLayout());
    myTable = new MemberSelectionTable(info, null);
    panel.add(ScrollPaneFactory.createScrollPane(myTable), BorderLayout.CENTER);
    panel.add(myIncludeInheritedCb, BorderLayout.NORTH);
    myIncludeInheritedCb.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            updateMethodsTable();
        }
    });
    return panel;
}
Also used : MemberSelectionTable(com.intellij.refactoring.ui.MemberSelectionTable) MemberInfo(com.intellij.refactoring.util.classMembers.MemberInfo) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) Nullable(org.jetbrains.annotations.Nullable)

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