Search in sources :

Example 6 with JSMemberInfo

use of com.intellij.lang.javascript.refactoring.util.JSMemberInfo in project intellij-plugins by JetBrains.

the class FlexMoveMembersTest method performAction.

private void performAction(String sourceClassName, final String targetClassName, final String visibility, final String[] memberNames) throws Exception {
    final JSClassResolver resolver = JSDialectSpecificHandlersFactory.forLanguage(JavaScriptSupportLoader.ECMA_SCRIPT_L4).getClassResolver();
    final JSClass sourceClass = (JSClass) resolver.findClassByQName(sourceClassName, ActionScriptMoveMembersDialog.getScope(myProject));
    assertNotNull("Class " + sourceClassName + " not found", sourceClass);
    JSClass targetClass = (JSClass) resolver.findClassByQName(targetClassName, ActionScriptMoveMembersDialog.getScope(myProject));
    assertNotNull("Class " + targetClassName + " not found", targetClass);
    final List<JSMemberInfo> memberInfos = new ArrayList<>();
    JSMemberInfo.extractStaticMembers(sourceClass, memberInfos, new MemberInfoBase.Filter<JSAttributeListOwner>() {

        @Override
        public boolean includeMember(JSAttributeListOwner member) {
            return memberNames.length == 0 || ArrayUtil.contains(member.getName(), memberNames);
        }
    });
    JSMemberInfo.sortByOffset(memberInfos);
    for (JSMemberInfo memberInfo : memberInfos) {
        memberInfo.setChecked(true);
    }
    new JSMoveMembersProcessor(myProject, null, sourceClass, ActionScriptMoveMembersDialog.getScope(myProject), new JSMoveMembersOptions() {

        @Override
        public JSAttributeListOwner[] getSelectedMembers() {
            final JSMemberInfo[] selected = JSMemberInfo.getSelected(memberInfos, sourceClass, Conditions.alwaysTrue());
            JSAttributeListOwner[] result = new JSAttributeListOwner[selected.length];
            for (int i = 0; i < result.length; i++) {
                result[i] = selected[i].getMember();
            }
            return result;
        }

        @Override
        public String getTargetClassName() {
            return targetClassName;
        }

        @Override
        public String getMemberVisibility() {
            return visibility;
        }
    }).run();
    myProject.getComponent(PostprocessReformattingAspect.class).doPostponedFormatting();
    FileDocumentManager.getInstance().saveAllDocuments();
}
Also used : JSClassResolver(com.intellij.lang.javascript.psi.resolve.JSClassResolver) JSMoveMembersProcessor(com.intellij.lang.javascript.refactoring.moveMembers.JSMoveMembersProcessor) ArrayList(java.util.ArrayList) JSMemberInfo(com.intellij.lang.javascript.refactoring.util.JSMemberInfo) MemberInfoBase(com.intellij.refactoring.classMembers.MemberInfoBase) PostprocessReformattingAspect(com.intellij.psi.impl.source.PostprocessReformattingAspect) JSMoveMembersOptions(com.intellij.lang.javascript.refactoring.moveMembers.JSMoveMembersOptions) JSAttributeListOwner(com.intellij.lang.javascript.psi.ecmal4.JSAttributeListOwner) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass)

Example 7 with JSMemberInfo

use of com.intellij.lang.javascript.refactoring.util.JSMemberInfo in project intellij-plugins by JetBrains.

the class FlexPullUpTest method getMemberInfos.

public static List<JSMemberInfo> getMemberInfos(final String[] members, JSClass clazz, boolean makeAbstract) {
    final List<JSMemberInfo> memberInfos = new ArrayList<>();
    JSMemberInfo.extractClassMembers(clazz, memberInfos, new MemberInfoBase.Filter<JSAttributeListOwner>() {

        @Override
        public boolean includeMember(JSAttributeListOwner member) {
            return ArrayUtil.contains(member.getName(), members);
        }
    });
    //assertTrue("Nothing to process", !memberInfos.isEmpty());
    for (JSMemberInfo memberInfo : memberInfos) {
        memberInfo.setChecked(true);
        if (makeAbstract) {
            memberInfo.setToAbstract(true);
        }
    }
    JSMemberInfo.sortByOffset(memberInfos);
    return memberInfos;
}
Also used : ArrayList(java.util.ArrayList) JSAttributeListOwner(com.intellij.lang.javascript.psi.ecmal4.JSAttributeListOwner) JSMemberInfo(com.intellij.lang.javascript.refactoring.util.JSMemberInfo) MemberInfoBase(com.intellij.refactoring.classMembers.MemberInfoBase)

Example 8 with JSMemberInfo

use of com.intellij.lang.javascript.refactoring.util.JSMemberInfo in project intellij-plugins by JetBrains.

the class FlexPullUpTest method performAction.

private void performAction(String from, String to, final int docCommentPolicy, String[] expectedConflicts, final String[] toPullUp) {
    final JSClassResolver resolver = JSDialectSpecificHandlersFactory.forLanguage(JavaScriptSupportLoader.ECMA_SCRIPT_L4).getClassResolver();
    final JSClass sourceClass = (JSClass) resolver.findClassByQName(from, GlobalSearchScope.projectScope(getProject()));
    assertNotNull("source class not found: " + sourceClass, sourceClass);
    final JSClass targetClass = (JSClass) resolver.findClassByQName(to, GlobalSearchScope.projectScope(getProject()));
    assertNotNull("target class not found: " + targetClass, targetClass);
    assertTrue("Source should be a subclass of target", JSInheritanceUtil.isParentClass(sourceClass, targetClass));
    final List<JSMemberInfo> memberInfos = getMemberInfos(toPullUp, sourceClass, false);
    final JSMemberInfo[] infosArray = JSMemberInfo.getSelected(memberInfos, sourceClass, Conditions.alwaysTrue());
    MultiMap<PsiElement, String> conflicts = JSPullUpConflictsUtil.checkConflicts(infosArray, sourceClass, targetClass, new JSInterfaceContainmentVerifier() {

        @Override
        public boolean checkedInterfacesContain(JSFunction psiMethod) {
            return JSPullUpHelper.checkedInterfacesContain(memberInfos, psiMethod);
        }
    }, JSVisibilityUtil.DEFAULT_OPTIONS);
    ArrayList<String> messages = new ArrayList<>(conflicts.values());
    for (int i = 0; i < messages.size(); i++) {
        messages.set(i, messages.get(i).replaceAll("<[^>]+>", ""));
    }
    assertSameElements(messages, expectedConflicts);
    if (conflicts.isEmpty()) {
        WriteCommandAction.runWriteCommandAction(null, () -> {
            new JSPullUpHelper(sourceClass, targetClass, infosArray, docCommentPolicy).moveMembersToBase();
            myProject.getComponent(PostprocessReformattingAspect.class).doPostponedFormatting();
        });
        FileDocumentManager.getInstance().saveAllDocuments();
    }
}
Also used : JSClassResolver(com.intellij.lang.javascript.psi.resolve.JSClassResolver) ArrayList(java.util.ArrayList) JSMemberInfo(com.intellij.lang.javascript.refactoring.util.JSMemberInfo) JSPullUpHelper(com.intellij.lang.javascript.refactoring.memberPullUp.JSPullUpHelper) JSInterfaceContainmentVerifier(com.intellij.lang.javascript.refactoring.util.JSInterfaceContainmentVerifier) PostprocessReformattingAspect(com.intellij.psi.impl.source.PostprocessReformattingAspect) JSFunction(com.intellij.lang.javascript.psi.JSFunction) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) PsiElement(com.intellij.psi.PsiElement)

Aggregations

JSMemberInfo (com.intellij.lang.javascript.refactoring.util.JSMemberInfo)8 JSClass (com.intellij.lang.javascript.psi.ecmal4.JSClass)6 PsiElement (com.intellij.psi.PsiElement)4 JSFunction (com.intellij.lang.javascript.psi.JSFunction)3 JSAttributeListOwner (com.intellij.lang.javascript.psi.ecmal4.JSAttributeListOwner)3 StringUtil (com.intellij.openapi.util.text.StringUtil)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 PsiDirectory (com.intellij.psi.PsiDirectory)3 PostprocessReformattingAspect (com.intellij.psi.impl.source.PostprocessReformattingAspect)3 ArrayList (java.util.ArrayList)3 CodeInsightBundle (com.intellij.codeInsight.CodeInsightBundle)2 JavaScriptSupportLoader (com.intellij.lang.javascript.JavaScriptSupportLoader)2 JSClassResolver (com.intellij.lang.javascript.psi.resolve.JSClassResolver)2 JSInheritanceUtil (com.intellij.lang.javascript.psi.resolve.JSInheritanceUtil)2 ApplicationManager (com.intellij.openapi.application.ApplicationManager)2 DialogWrapper (com.intellij.openapi.ui.DialogWrapper)2 Conditions (com.intellij.openapi.util.Conditions)2 MemberInfoBase (com.intellij.refactoring.classMembers.MemberInfoBase)2 THashSet (gnu.trove.THashSet)2 FlexTestUtils (com.intellij.flex.util.FlexTestUtils)1