use of com.intellij.lang.javascript.refactoring.util.JSMemberInfo in project intellij-plugins by JetBrains.
the class FlexExtractSuperTest method performAction.
private void performAction(boolean classNotInterface, String from, final String extractedSuperName, int docCommentPolicy, JSExtractSuperProcessor.Mode mode, String[] members, String[] conflicts) {
JSClass sourceClass = JSTestUtils.findClassByQName(from, GlobalSearchScope.moduleScope(myModule));
final List<JSMemberInfo> memberInfos = FlexPullUpTest.getMemberInfos(members, sourceClass, false);
JSMemberInfo.sortByOffset(memberInfos);
JSMemberInfo[] infosArray = JSMemberInfo.getSelected(memberInfos, sourceClass, Conditions.alwaysTrue());
try {
final PsiElement finalSourceClass = sourceClass;
PsiDirectory dir = WriteCommandAction.runWriteCommandAction(null, (Computable<PsiDirectory>) () -> ActionScriptCreateClassOrInterfaceFix.findOrCreateDirectory(StringUtil.getPackageName(extractedSuperName), finalSourceClass));
new JSExtractSuperProcessor(sourceClass, infosArray, StringUtil.getShortName(extractedSuperName), StringUtil.getPackageName(extractedSuperName), docCommentPolicy, mode, classNotInterface, dir).run();
assertEquals("Conflicts expected:\n" + StringUtil.join(conflicts, "\n"), 0, conflicts.length);
myProject.getComponent(PostprocessReformattingAspect.class).doPostponedFormatting();
FileDocumentManager.getInstance().saveAllDocuments();
} catch (BaseRefactoringProcessor.ConflictsInTestsException e) {
assertNotNull("Conflicts not expected but found:" + e.getMessage(), conflicts);
assertSameElements(e.getMessages(), conflicts);
myDoCompare = false;
}
}
use of com.intellij.lang.javascript.refactoring.util.JSMemberInfo in project intellij-plugins by JetBrains.
the class FlexUnitTestCreator method getMethodsText.
private static String getMethodsText(final JSClass createdClass, final boolean generateSetUp, final boolean generateTearDown, final JSMemberInfo[] selectedMemberInfos) {
final StringBuilder builder = new StringBuilder();
builder.append(generateSetUp ? JSInheritanceUtil.findMember("setUp", createdClass, JSInheritanceUtil.SearchedMemberType.Methods, FunctionKind.SIMPLE, true) == null ? "[Before]\npublic function setUp():void{\n\n}" : "[Before]\npublic override function setUp():void{\nsuper.setUp();\n}" : "");
builder.append(generateTearDown ? JSInheritanceUtil.findMember("tearDown", createdClass, JSInheritanceUtil.SearchedMemberType.Methods, FunctionKind.SIMPLE, true) == null ? "[After]\npublic function tearDown():void{\n\n}" : "[After]\npublic override function tearDown():void{\nsuper.tearDown();\n}" : "");
// because getters and setters have same name
final Set<String> processedNames = new THashSet<>();
for (final JSMemberInfo info : selectedMemberInfos) {
final String name = info.getMember().getName();
if (!processedNames.contains(name)) {
processedNames.add(name);
final String testName = "test" + capitalizeFirstCharacter(name);
builder.append("[Test]\npublic function ").append(testName).append("():void{\n\n}");
}
}
return builder.toString();
}
use of com.intellij.lang.javascript.refactoring.util.JSMemberInfo in project intellij-plugins by JetBrains.
the class FlexUnitTestCreator method createTest.
public void createTest(final Project project, final Editor editor, final PsiFile file) {
final JSClass jsClass = FlexUnitTestFinder.findContextClass(file);
if (jsClass == null)
return;
final String testClassName;
final String packageName;
final JSClass superClass;
final PsiDirectory targetDirectory;
final boolean generateSetUp;
final boolean generateTearDown;
final JSMemberInfo[] selectedMemberInfos;
if (ApplicationManager.getApplication().isUnitTestMode()) {
testClassName = jsClass.getName() + "Test";
packageName = StringUtil.getPackageName(jsClass.getQualifiedName());
superClass = null;
targetDirectory = jsClass.getContainingFile().getContainingDirectory();
generateSetUp = true;
generateTearDown = true;
selectedMemberInfos = new JSMemberInfo[0];
} else {
final CreateFlexUnitTestDialog dialog = new CreateFlexUnitTestDialog(ModuleUtilCore.findModuleForPsiElement(jsClass), jsClass);
dialog.show();
if (dialog.getExitCode() != DialogWrapper.OK_EXIT_CODE) {
return;
}
testClassName = dialog.getTestClassName();
packageName = dialog.getPackageName();
superClass = dialog.getSuperClass();
targetDirectory = dialog.getTargetDirectory();
generateSetUp = dialog.isGenerateSetUp();
generateTearDown = dialog.isGenerateTearDown();
selectedMemberInfos = dialog.getSelectedMemberInfos();
}
final Consumer<JSClass> postProcessRunnable = createdClass -> {
final String methodsText = getMethodsText(createdClass, generateSetUp, generateTearDown, selectedMemberInfos);
if (!methodsText.isEmpty()) {
final PsiElement methods = JSChangeUtil.createJSTreeFromText(project, "{" + methodsText + "}", JavaScriptSupportLoader.ECMA_SCRIPT_L4).getPsi();
if (methods != null) {
for (final PsiElement psiElement : PsiTreeUtil.getChildrenOfTypeAsList(methods, JSFunction.class)) {
createdClass.add(psiElement);
}
}
}
CodeStyleManager.getInstance(project).reformat(createdClass);
createdClass.navigate(true);
};
CommandProcessor.getInstance().executeCommand(project, () -> ActionScriptCreateClassOrInterfaceFix.createClass(ActionScriptCreateClassOrInterfaceFix.ACTION_SCRIPT_CLASS_WITH_SUPERS_TEMPLATE_NAME, testClassName, packageName, superClass, Collections.emptyList(), targetDirectory, CodeInsightBundle.message("intention.create.test"), true, Collections.emptyMap(), postProcessRunnable), CodeInsightBundle.message("intention.create.test"), null);
}
use of com.intellij.lang.javascript.refactoring.util.JSMemberInfo in project intellij-plugins by JetBrains.
the class CreateFlexUnitTestDialog method createUIComponents.
private void createUIComponents() {
final Module module = ModuleUtil.findModuleForPsiElement(myContextClass);
assert module != null;
myPackageCombo = JSReferenceEditor.forPackageName(StringUtil.getPackageName(myContextClass.getQualifiedName()), module.getProject(), null, getTestClassPackageScope(module), RefactoringBundle.message("choose.destination.package"));
final Condition<JSClass> filter = jsClass -> {
final JSAttributeList attributeList = jsClass.getAttributeList();
return !jsClass.isInterface() && attributeList != null && !attributeList.hasModifier(JSAttributeList.ModifierType.FINAL);
};
mySuperClassField = JSReferenceEditor.forClassName("", module.getProject(), null, getSuperClassScope(module), null, filter, JSBundle.message("choose.super.class.title"));
final List<JSMemberInfo> memberInfos = new ArrayList<>();
JSMemberInfo.extractClassMembers(myContextClass, memberInfos, new MemberInfoBase.Filter<JSAttributeListOwner>() {
public boolean includeMember(final JSAttributeListOwner member) {
final JSAttributeList attributeList = member.getAttributeList();
return member instanceof JSFunction && ((JSFunction) member).getKind() != JSFunction.FunctionKind.CONSTRUCTOR && attributeList != null && attributeList.getAccessType() == JSAttributeList.AccessType.PUBLIC;
}
});
myMemberSelectionPanel = new JSMemberSelectionPanel("Generate test methods for:", memberInfos, null);
}
use of com.intellij.lang.javascript.refactoring.util.JSMemberInfo in project intellij-plugins by JetBrains.
the class FlexPushDownTest method performAction.
private void performAction(String from, int docCommentPolicy, boolean makeAbstract, final String[] toPushDown) {
final JSClass sourceClass = (JSClass) JSDialectSpecificHandlersFactory.forLanguage(JavaScriptSupportLoader.ECMA_SCRIPT_L4).getClassResolver().findClassByQName(from, GlobalSearchScope.projectScope(getProject()));
assertNotNull("source class not found: " + from, sourceClass);
assertTrue(sourceClass.getQualifiedName() + " has no inheritors", !JSInheritanceUtil.findDirectSubClasses(sourceClass, false).isEmpty());
final List<JSMemberInfo> memberInfos = FlexPullUpTest.getMemberInfos(toPushDown, sourceClass, makeAbstract);
JSMemberInfo[] infosArray = JSMemberInfo.getSelected(memberInfos, sourceClass, Conditions.alwaysTrue());
new JSPushDownProcessor(myProject, infosArray, sourceClass, docCommentPolicy) {
@Override
@NotNull
protected UsageInfo[] findUsages() {
// ensure stable order
final UsageInfo[] usages = super.findUsages();
Arrays.sort(usages, (o1, o2) -> ((JSClass) o1.getElement()).getQualifiedName().compareTo(((JSClass) o2.getElement()).getQualifiedName()));
return usages;
}
}.run();
myProject.getComponent(PostprocessReformattingAspect.class).doPostponedFormatting();
FileDocumentManager.getInstance().saveAllDocuments();
}
Aggregations