use of com.intellij.javascript.flex.mxml.schema.CodeContextHolder in project intellij-plugins by JetBrains.
the class NewFlexComponentAction method getPrefixAndNamespace.
public static Pair<String, String> getPrefixAndNamespace(XmlTag tag, String qName) {
Module module = ModuleUtilCore.findModuleForPsiElement(tag);
boolean isFlex4Template = ArrayUtil.contains(JavaScriptSupportLoader.MXML_URI3, tag.knownNamespaces());
CodeContextHolder holder = CodeContextHolder.getInstance(module.getProject());
// ensure namespace is loaded into code context (including all the namespaces from all the libraries)
CodeContext.getContext(MxmlJSClass.MXML_URI4, module);
Collection<String> namespaces = holder.getNamespaces(module);
String[] illegalNamespaces = isFlex4Template ? new String[] { JavaScriptSupportLoader.MXML_URI } : MxmlJSClass.FLEX_4_NAMESPACES;
for (String namespace : namespaces) {
if (ArrayUtil.contains(namespace, illegalNamespaces) || CodeContext.isPackageBackedNamespace(namespace)) {
continue;
}
CodeContext codeContext = CodeContext.isStdNamespace(namespace) ? holder.getStandardContext(namespace, module) : holder.getCodeContext(namespace, module);
if (codeContext == null) {
continue;
}
if (codeContext.getElementDescriptor(StringUtil.getShortName(qName), qName) != null) {
return Pair.create(FlexSchemaHandler.getDefaultPrefix(namespace), namespace);
}
}
String packageName = StringUtil.getPackageName(qName);
String namespace = StringUtil.isEmpty(packageName) ? "*" : packageName + ".*";
return Pair.create(FlexSchemaHandler.getDefaultPrefix(namespace), namespace);
}
Aggregations