Search in sources :

Example 1 with JSMoveMembersProcessor

use of com.intellij.lang.javascript.refactoring.moveMembers.JSMoveMembersProcessor 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)

Aggregations

JSAttributeListOwner (com.intellij.lang.javascript.psi.ecmal4.JSAttributeListOwner)1 JSClass (com.intellij.lang.javascript.psi.ecmal4.JSClass)1 JSClassResolver (com.intellij.lang.javascript.psi.resolve.JSClassResolver)1 JSMoveMembersOptions (com.intellij.lang.javascript.refactoring.moveMembers.JSMoveMembersOptions)1 JSMoveMembersProcessor (com.intellij.lang.javascript.refactoring.moveMembers.JSMoveMembersProcessor)1 JSMemberInfo (com.intellij.lang.javascript.refactoring.util.JSMemberInfo)1 PostprocessReformattingAspect (com.intellij.psi.impl.source.PostprocessReformattingAspect)1 MemberInfoBase (com.intellij.refactoring.classMembers.MemberInfoBase)1 ArrayList (java.util.ArrayList)1