use of com.intellij.lang.javascript.psi.ecmal4.JSClass in project intellij-plugins by JetBrains.
the class FlashUmlTest method doTestImpl.
private DiagramBuilder doTestImpl(@Nullable File projectRoot, String[] files, String[] additionalClasses, Computable<GlobalSearchScope> scopeProvider, @Nullable EnumSet<FlashUmlDependenciesSettingsOption> dependencies, @Nullable String expectedFileNamePrefix) throws Exception {
List<VirtualFile> vFiles = new ArrayList<>(files.length);
for (String file : files) {
vFiles.add(getVirtualFile(BASE_PATH + file));
}
ApplicationManager.getApplication().runWriteAction(() -> {
final ModuleRootManager rootManager = ModuleRootManager.getInstance(myModule);
final ModifiableRootModel rootModel = rootManager.getModifiableModel();
ContentEntry[] contentEntries = rootModel.getContentEntries();
for (ContentEntry contentEntry : contentEntries) {
rootModel.removeContentEntry(contentEntry);
}
rootModel.commit();
});
configureByFiles(projectRoot, VfsUtilCore.toVirtualFileArray(vFiles));
final LinkedHashMap<Integer, String> markers = JSTestUtils.extractPositionMarkers(getProject(), getEditor().getDocument());
assertFalse(markers.isEmpty());
DiagramBuilder builder = null;
int i = 1;
for (Map.Entry<Integer, String> marker : markers.entrySet()) {
getEditor().getCaretModel().moveToOffset(marker.getKey());
i++;
String expectedPrefix = StringUtil.isNotEmpty(marker.getValue()) ? marker.getValue() : expectedFileNamePrefix;
final DataContext dataContext = DataManager.getInstance().getDataContext();
final DiagramProvider[] providers = DiagramProvider.findProviders(dataContext, "unknown");
final FlashUmlProvider provider = ContainerUtil.findInstance(providers, FlashUmlProvider.class);
assertNotNull("Flash UML provider not found", provider);
final String actualOriginFqn = provider.getVfsResolver().getQualifiedName(provider.getElementManager().findInDataContext(dataContext));
final Object actualOrigin = provider.getVfsResolver().resolveElementByFQN(actualOriginFqn, getProject());
builder = UmlGraphBuilderFactory.create(myProject, provider, actualOrigin, null);
Disposer.register(getTestRootDisposable(), builder);
final DiagramDataModel<Object> model = builder.getDataModel();
DiagramConfiguration configuration = DiagramConfiguration.getConfiguration();
String originalCategories = configuration.categories.get(provider.getID());
if (dependencies != null) {
model.setShowDependencies(true);
EnumSet<FlashUmlDependenciesSettingsOption> disabledOptions = EnumSet.complementOf(dependencies);
configuration.categories.put(provider.getID(), StringUtil.join(disabledOptions, option -> option.getDisplayName(), ";"));
} else {
model.setShowDependencies(false);
}
try {
model.refreshDataModel();
// first limit elements by scope
Collection<DiagramNode<Object>> nodesToRemove = new ArrayList<>();
for (DiagramNode<Object> node : model.getNodes()) {
if (node.getIdentifyingElement() instanceof JSClass && !scopeProvider.compute().contains(((JSClass) node.getIdentifyingElement()).getContainingFile().getVirtualFile())) {
nodesToRemove.add(node);
}
}
for (DiagramNode<Object> node : nodesToRemove) {
model.removeNode(node);
}
builder.updateGraph();
// then add explicitly required classes
for (String aClass : additionalClasses) {
JSClass c = JSTestUtils.findClassByQName(aClass, GlobalSearchScope.allScope(myProject));
final DiagramNode node = model.addElement(c);
if (node != null) {
builder.createDraggedNode(node, node.getTooltip(), DiagramUtils.getBestPositionForNode(builder));
builder.updateGraph();
}
}
assertModel(expectedPrefix, provider, actualOriginFqn, model);
} finally {
configuration.categories.put(provider.getID(), originalCategories);
}
}
assert builder != null;
return builder;
}
use of com.intellij.lang.javascript.psi.ecmal4.JSClass 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();
}
use of com.intellij.lang.javascript.psi.ecmal4.JSClass 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();
}
use of com.intellij.lang.javascript.psi.ecmal4.JSClass 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;
}
use of com.intellij.lang.javascript.psi.ecmal4.JSClass 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();
}
}
Aggregations