Search in sources :

Example 1 with JSPullUpHelper

use of com.intellij.lang.javascript.refactoring.memberPullUp.JSPullUpHelper 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

JSFunction (com.intellij.lang.javascript.psi.JSFunction)1 JSClass (com.intellij.lang.javascript.psi.ecmal4.JSClass)1 JSClassResolver (com.intellij.lang.javascript.psi.resolve.JSClassResolver)1 JSPullUpHelper (com.intellij.lang.javascript.refactoring.memberPullUp.JSPullUpHelper)1 JSInterfaceContainmentVerifier (com.intellij.lang.javascript.refactoring.util.JSInterfaceContainmentVerifier)1 JSMemberInfo (com.intellij.lang.javascript.refactoring.util.JSMemberInfo)1 PsiElement (com.intellij.psi.PsiElement)1 PostprocessReformattingAspect (com.intellij.psi.impl.source.PostprocessReformattingAspect)1 ArrayList (java.util.ArrayList)1