use of com.intellij.javascript.flex.mxml.MxmlJSClass 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.javascript.flex.mxml.MxmlJSClass in project intellij-plugins by JetBrains.
the class NodeClassInfo method fillMapsForClass.
private static void fillMapsForClass(final JSClass jsClass, final Map<String, Icon> staticFields, final Map<String, Icon> staticProperties, final Map<String, Icon> fields, final Map<String, Icon> properties) {
for (final JSField variable : jsClass.getFields()) {
final JSAttributeList varAttributes = variable.getAttributeList();
if (varAttributes != null && varAttributes.hasModifier(JSAttributeList.ModifierType.STATIC)) {
staticFields.put(variable.getName(), variable.getIcon(Iconable.ICON_FLAG_VISIBILITY));
} else {
fields.put(variable.getName(), variable.getIcon(Iconable.ICON_FLAG_VISIBILITY));
}
}
for (final JSFunction function : jsClass.getFunctions()) {
if (function.getKind() == JSFunction.FunctionKind.GETTER && function.getName() != null) {
final JSAttributeList functionAttributes = function.getAttributeList();
if (functionAttributes != null && functionAttributes.hasModifier(JSAttributeList.ModifierType.STATIC)) {
staticProperties.put(function.getName(), function.getIcon(Iconable.ICON_FLAG_VISIBILITY));
} else {
properties.put(function.getName(), function.getIcon(Iconable.ICON_FLAG_VISIBILITY));
}
}
}
if (jsClass instanceof MxmlJSClass) {
final PsiFile file = jsClass.getContainingFile();
final XmlFile xmlFile = file instanceof XmlFile ? (XmlFile) file : null;
final XmlTag rootTag = xmlFile == null ? null : xmlFile.getRootTag();
if (rootTag != null) {
processSubtagsRecursively(rootTag, tag -> {
final String id = tag.getAttributeValue("id");
if (id != null) {
fields.put(id, tag.getIcon(Iconable.ICON_FLAG_VISIBILITY));
}
return !MxmlJSClass.isTagThatAllowsAnyXmlContent(tag);
});
}
}
}
use of com.intellij.javascript.flex.mxml.MxmlJSClass in project intellij-plugins by JetBrains.
the class FlexValue method computeSourcePosition.
@Override
public void computeSourcePosition(@NotNull final XNavigatable navigatable) {
if (mySourcePosition == null) {
navigatable.setSourcePosition(null);
return;
}
XSourcePosition result = null;
final Project project = myDebugProcess.getSession().getProject();
if (myValueType == ValueType.Variable) {
final PsiElement contextElement = XDebuggerUtil.getInstance().findContextElement(mySourcePosition.getFile(), mySourcePosition.getOffset(), project, true);
final JSFunction jsFunction = PsiTreeUtil.getParentOfType(contextElement, JSFunction.class);
if (jsFunction != null) {
final Ref<JSVariable> varRef = new Ref<>();
jsFunction.accept(new JSElementVisitor() {
@Override
public void visitJSElement(final JSElement node) {
if (varRef.isNull()) {
node.acceptChildren(this);
}
}
@Override
public void visitJSVariable(final JSVariable node) {
if (myName.equals(node.getName())) {
varRef.set(node);
}
super.visitJSVariable(node);
}
});
if (!varRef.isNull()) {
result = DebuggerSupportUtils.calcSourcePosition(varRef.get());
}
}
} else if (myValueType == ValueType.Parameter) {
final PsiElement contextElement = XDebuggerUtil.getInstance().findContextElement(mySourcePosition.getFile(), mySourcePosition.getOffset(), project, true);
final JSFunction jsFunction = PsiTreeUtil.getParentOfType(contextElement, JSFunction.class);
final JSParameter[] parameters = jsFunction == null ? JSParameter.EMPTY_ARRAY : jsFunction.getParameterVariables();
for (final JSParameter parameter : parameters) {
if (myName.equals(parameter.getName())) {
result = DebuggerSupportUtils.calcSourcePosition(parameter);
break;
}
}
} else if (myValueType == ValueType.Field && myParentResult != null) {
final String typeFromFlexValueResult = getTypeAndAdditionalInfo(myParentResult).first;
final JSClass jsClass = findJSClass(project, ModuleUtilCore.findModuleForFile(mySourcePosition.getFile(), project), typeFromFlexValueResult);
if (jsClass != null) {
final Ref<PsiElement> fieldRef = new Ref<>();
fieldRef.set(JSInheritanceUtil.findMember(myName, jsClass, JSInheritanceUtil.SearchedMemberType.FieldsAndMethods, JSFunction.FunctionKind.GETTER, true));
if (fieldRef.isNull() && jsClass instanceof MxmlJSClass) {
final PsiFile file = jsClass.getContainingFile();
final XmlFile xmlFile = file instanceof XmlFile ? (XmlFile) file : null;
final XmlTag rootTag = xmlFile == null ? null : xmlFile.getRootTag();
if (rootTag != null) {
NodeClassInfo.processSubtagsRecursively(rootTag, tag -> {
final XmlAttribute idAttr = tag.getAttribute("id");
final String id = idAttr == null ? null : idAttr.getValue();
if (id != null && id.equals(myName)) {
fieldRef.set(idAttr);
}
return !MxmlJSClass.isTagThatAllowsAnyXmlContent(tag);
});
}
}
result = DebuggerSupportUtils.calcSourcePosition(fieldRef.get());
}
}
navigatable.setSourcePosition(result);
}
Aggregations