use of com.intellij.lang.javascript.psi.ecmal4.JSClass in project intellij-plugins by JetBrains.
the class FlashUmlDataModel method expandPackage.
public void expandPackage(final String psiPackage) {
packages.remove(psiPackage);
packagesRemovedByUser.add(psiPackage);
final GlobalSearchScope searchScope = GlobalSearchScope.allScope(getProject());
for (JSClass psiClass : getClasses(psiPackage, searchScope)) {
addElement(psiClass);
}
for (String aPackage : getSubPackages(psiPackage, searchScope)) {
addElement(aPackage);
}
}
use of com.intellij.lang.javascript.psi.ecmal4.JSClass in project intellij-plugins by JetBrains.
the class FlashUmlDataModel method createEdge.
@Override
@Nullable
public DiagramEdge<Object> createEdge(@NotNull final DiagramNode<Object> from, @NotNull final DiagramNode<Object> to) {
final JSClass fromClass = (JSClass) from.getIdentifyingElement();
final JSClass toClass = (JSClass) to.getIdentifyingElement();
if (fromClass.isEquivalentTo(toClass)) {
return null;
}
if (toClass.isInterface()) {
if (JSPsiImplUtils.containsEquivalent(fromClass.isInterface() ? fromClass.getSuperClasses() : fromClass.getImplementedInterfaces(), toClass)) {
return null;
}
Callable<DiagramEdge<Object>> callable = () -> {
String targetQName = toClass.getQualifiedName();
JSRefactoringUtil.addToSupersList(fromClass, targetQName, true);
if (targetQName.contains(".") && !(fromClass instanceof XmlBackedJSClassImpl)) {
List<FormatFixer> formatters = new ArrayList<>();
formatters.add(ImportUtils.insertImportStatements(fromClass, Collections.singletonList(targetQName)));
formatters.addAll(ECMAScriptImportOptimizer.executeNoFormat(fromClass.getContainingFile()));
FormatFixer.fixAll(formatters);
}
return addEdgeAndRefresh(from, to, fromClass.isInterface() ? FlashUmlRelationship.GENERALIZATION : FlashUmlRelationship.INTERFACE_GENERALIZATION);
};
String commandName = FlexBundle.message(fromClass.isInterface() ? "create.extends.relationship.command.name" : "create.implements.relationship.command.name", fromClass.getQualifiedName(), toClass.getQualifiedName());
return DiagramAction.performCommand(getBuilder(), callable, commandName, null, fromClass.getContainingFile());
} else {
if (fromClass.isInterface()) {
return null;
} else if (fromClass instanceof XmlBackedJSClassImpl) {
JSClass[] superClasses = fromClass.getSuperClasses();
if (JSPsiImplUtils.containsEquivalent(superClasses, toClass)) {
return null;
}
if (superClasses.length > 0) {
// if base component is not resolved, replace it silently
final JSClass currentParent = superClasses[0];
if (Messages.showYesNoDialog(FlexBundle.message("replace.base.component.prompt", currentParent.getQualifiedName(), toClass.getQualifiedName()), FlexBundle.message("create.edge.title"), Messages.getQuestionIcon()) == Messages.NO) {
return null;
}
}
Callable<DiagramEdge<Object>> callable = () -> {
NewFlexComponentAction.setParentComponent((MxmlJSClass) fromClass, toClass.getQualifiedName());
return addEdgeAndRefresh(from, to, DiagramRelationships.GENERALIZATION);
};
String commandName = FlexBundle.message("create.extends.relationship.command.name", fromClass.getQualifiedName(), toClass.getQualifiedName());
return DiagramAction.performCommand(getBuilder(), callable, commandName, null, fromClass.getContainingFile());
} else {
final JSClass[] superClasses = fromClass.getSuperClasses();
if (JSPsiImplUtils.containsEquivalent(superClasses, toClass)) {
return null;
}
if (superClasses.length > 0 && !JSResolveUtil.isObjectClass(superClasses[0])) {
// if base class is not resolved, replace it silently
final JSClass currentParent = superClasses[0];
if (Messages.showYesNoDialog(FlexBundle.message("replace.base.class.prompt", currentParent.getQualifiedName(), toClass.getQualifiedName()), FlexBundle.message("create.edge.title"), Messages.getQuestionIcon()) == Messages.NO) {
return null;
}
}
Callable<DiagramEdge<Object>> callable = () -> {
List<FormatFixer> formatters = new ArrayList<>();
boolean optimize = false;
if (superClasses.length > 0 && !JSResolveUtil.isObjectClass(superClasses[0])) {
JSRefactoringUtil.removeFromReferenceList(fromClass.getExtendsList(), superClasses[0], formatters);
optimize = needsImport(fromClass, superClasses[0]);
}
JSRefactoringUtil.addToSupersList(fromClass, toClass.getQualifiedName(), false);
if (needsImport(fromClass, toClass)) {
formatters.add(ImportUtils.insertImportStatements(fromClass, Collections.singletonList(toClass.getQualifiedName())));
optimize = true;
}
if (optimize) {
formatters.addAll(ECMAScriptImportOptimizer.executeNoFormat(fromClass.getContainingFile()));
}
FormatFixer.fixAll(formatters);
return addEdgeAndRefresh(from, to, DiagramRelationships.GENERALIZATION);
};
String commandName = FlexBundle.message("create.extends.relationship.command.name", fromClass.getQualifiedName(), toClass.getQualifiedName());
return DiagramAction.performCommand(getBuilder(), callable, commandName, null, fromClass.getContainingFile());
}
}
}
use of com.intellij.lang.javascript.psi.ecmal4.JSClass in project intellij-plugins by JetBrains.
the class FlashUmlDataModel method findNearestInterfaces.
private static void findNearestInterfaces(final JSClass psiClass, final Set<JSClass> result) {
for (JSClass anInterface : psiClass.getSuperClasses()) {
if (result.contains(anInterface)) {
// don't check isEquivalent, equality check is enough for interfaces
continue;
}
result.add(anInterface);
findNearestInterfaces(anInterface, result);
}
}
use of com.intellij.lang.javascript.psi.ecmal4.JSClass in project intellij-plugins by JetBrains.
the class FlashUmlDataModel method addElement.
@Nullable
public DiagramNode<Object> addElement(Object element) {
if (findNode(element) != null)
return null;
if (element instanceof JSClass) {
if (!isAllowedToShow((JSClass) element)) {
return null;
}
JSClass psiClass = (JSClass) element;
if (psiClass.getQualifiedName() == null)
return null;
final SmartPsiElementPointer<JSClass> pointer = spManager.createSmartPsiElementPointer(psiClass);
final String fqn = psiClass.getQualifiedName();
classesAddedByUser.put(fqn, pointer);
classesRemovedByUser.remove(fqn);
setupScopeManager(psiClass, true);
return new FlashUmlClassNode((JSClass) element, getProvider());
} else if (element instanceof String) {
String aPackage = (String) element;
packages.add(aPackage);
packagesRemovedByUser.remove(aPackage);
return new FlashUmlPackageNode(aPackage, getProvider());
}
return null;
}
use of com.intellij.lang.javascript.psi.ecmal4.JSClass in project intellij-plugins by JetBrains.
the class JSCreateMethodDialog method createFakeMethod.
static JSFunction createFakeMethod(JSClass clazz, String text, boolean inClass) {
if (inClass) {
JSFile file = JSElementFactory.createExpressionCodeFragment(clazz.getProject(), (clazz.isInterface() ? "interface" : "class") + " Dummy {" + text + "}", clazz, JavaScriptSupportLoader.ECMA_SCRIPT_L4, null, JSElementFactory.TopLevelCompletion.NO, null);
JSClass aClass = PsiTreeUtil.findChildOfType(file, JSClass.class);
return aClass.getFunctions()[0];
} else {
JSFile file = JSElementFactory.createExpressionCodeFragment(clazz.getProject(), text, clazz, JavaScriptSupportLoader.ECMA_SCRIPT_L4, null, JSElementFactory.TopLevelCompletion.NO, null);
return PsiTreeUtil.findChildOfType(file, JSFunction.class);
}
}
Aggregations