use of com.intellij.xml.XmlElementDescriptor in project intellij-plugins by JetBrains.
the class CreateFlexSkinIntention method getHostComponentClass.
@Nullable
private JSClass getHostComponentClass() {
final XmlTag tag = myElement instanceof XmlTag ? ((XmlTag) myElement).getParentTag() : myElement instanceof XmlAttributeValue ? (XmlTag) myElement.getParent().getParent() : null;
final XmlElementDescriptor descriptor = tag == null ? null : tag.getDescriptor();
if (descriptor instanceof ClassBackedElementDescriptor) {
final PsiElement declaration = descriptor.getDeclaration();
if (declaration instanceof JSClass) {
return (JSClass) declaration;
}
}
return null;
}
use of com.intellij.xml.XmlElementDescriptor in project intellij-plugins by JetBrains.
the class AngularJSErrorFilter method shouldHighlightErrorElement.
@Override
public boolean shouldHighlightErrorElement(@NotNull PsiErrorElement error) {
final Project project = error.getProject();
final Language language = error.getLanguage();
if ("CSS".equals(language.getID()) && PsiTreeUtil.getParentOfType(error, XmlAttribute.class) != null && AngularIndexUtil.hasAngularJS(project)) {
final PsiFile file = error.getContainingFile();
PsiErrorElement nextError = error;
while (nextError != null) {
if (hasAngularInjectionAt(project, file, nextError.getTextOffset()))
return false;
nextError = PsiTreeUtil.getNextSiblingOfType(nextError, PsiErrorElement.class);
}
}
if (HTMLLanguage.INSTANCE.is(language) && error.getErrorDescription().endsWith("not closed")) {
final PsiElement parent = error.getParent();
final XmlElementDescriptor descriptor = parent instanceof XmlTag ? ((XmlTag) parent).getDescriptor() : null;
return !(descriptor instanceof AngularJSTagDescriptor);
}
if (XMLLanguage.INSTANCE.is(language) && error.getErrorDescription().equals(XmlErrorMessages.message("xml.parsing.unexpected.tokens"))) {
return !error.getParent().getLanguage().is(Angular2HTMLLanguage.INSTANCE);
}
return true;
}
use of com.intellij.xml.XmlElementDescriptor in project android by JetBrains.
the class AndroidXmlTagDescriptor method getElementsDescriptors.
@Override
public XmlElementDescriptor[] getElementsDescriptors(XmlTag context) {
final XmlElementDescriptor[] descriptors = myParentDescriptor.getElementsDescriptors(context);
if (myBaseClassName == null || context == null) {
return descriptors;
}
final AndroidFacet facet = AndroidFacet.getInstance(context);
if (facet == null) {
return descriptors;
}
final XmlElementDescriptor[] androidDescriptors = new XmlElementDescriptor[descriptors.length];
final DomElement domElement = DomManager.getDomManager(context.getProject()).getDomElement(context);
final PsiClass baseClass = JavaPsiFacade.getInstance(context.getProject()).findClass(myBaseClassName, facet.getModule().getModuleWithLibrariesScope());
for (int i = 0; i < descriptors.length; i++) {
final XmlElementDescriptor descriptor = descriptors[i];
final String tagName = descriptor.getName();
final PsiClass aClass = tagName != null && baseClass != null ? LayoutViewClassUtils.findClassByTagName(facet, tagName, baseClass) : null;
final Icon icon = AndroidDomElementDescriptorProvider.getIconForTag(tagName, domElement);
androidDescriptors[i] = new AndroidXmlTagDescriptor(aClass, descriptor, myBaseClassName, icon);
}
return androidDescriptors;
}
use of com.intellij.xml.XmlElementDescriptor in project android by JetBrains.
the class AndroidDomElementDescriptorProvider method getDescriptor.
@Nullable
private static XmlElementDescriptor getDescriptor(DomElement domElement, XmlTag tag, @Nullable String baseClassName) {
AndroidFacet facet = AndroidFacet.getInstance(domElement);
if (facet == null)
return null;
final String name = domElement.getXmlTag().getName();
final PsiClass aClass = baseClassName != null ? LayoutViewClassUtils.findClassByTagName(facet, name, baseClassName) : null;
final Icon icon = getIconForTag(name, domElement);
final DefinesXml definesXml = domElement.getAnnotation(DefinesXml.class);
if (definesXml != null) {
return new AndroidXmlTagDescriptor(aClass, new DomElementXmlDescriptor(domElement), baseClassName, icon);
}
final PsiElement parent = tag.getParent();
if (parent instanceof XmlTag) {
final XmlElementDescriptor parentDescriptor = ((XmlTag) parent).getDescriptor();
if (parentDescriptor != null && parentDescriptor instanceof AndroidXmlTagDescriptor) {
XmlElementDescriptor domDescriptor = parentDescriptor.getElementDescriptor(tag, (XmlTag) parent);
if (domDescriptor != null) {
return new AndroidXmlTagDescriptor(aClass, domDescriptor, baseClassName, icon);
}
}
}
return null;
}
use of com.intellij.xml.XmlElementDescriptor in project intellij-plugins by JetBrains.
the class FlexSchemaHandler method getAvailableNamespaces.
@NotNull
@Override
public Set<String> getAvailableNamespaces(@NotNull XmlFile _file, @Nullable @NonNls final String tagName) {
// tagName == null => tag name completion
// tagName != null => guess namespace of unresolved tag
PsiFile originalFile = _file.getOriginalFile();
if (originalFile instanceof XmlFile)
_file = (XmlFile) originalFile;
final XmlFile file = _file;
final Project project = file.getProject();
final Module module = ProjectRootManager.getInstance(project).getFileIndex().getModuleForFile(file.getVirtualFile());
final Collection<String> illegalNamespaces = getIllegalNamespaces(file);
final Set<String> result = new THashSet<>();
final Set<String> componentsThatHaveNotPackageBackedNamespace = new THashSet<>();
for (final String namespace : CodeContextHolder.getInstance(project).getNamespaces(module)) {
if (!CodeContext.isPackageBackedNamespace(namespace) && !illegalNamespaces.contains(namespace)) {
// package backed namespaces will be added later from JSPackageIndex
if (tagName == null) {
result.add(namespace);
} else {
final XmlElementDescriptor descriptor = CodeContext.getContext(namespace, module).getElementDescriptor(tagName, (XmlTag) null);
if (descriptor != null) {
result.add(namespace);
componentsThatHaveNotPackageBackedNamespace.add(descriptor.getQualifiedName());
}
}
}
}
if (tagName == null && !illegalNamespaces.contains(JavaScriptSupportLoader.MXML_URI)) {
result.add(JavaScriptSupportLoader.MXML_URI);
}
if (XmlBackedJSClassImpl.SCRIPT_TAG_NAME.equals(tagName) || "Style".equals(tagName))
return result;
if (DumbService.isDumb(project))
return result;
if (tagName == null) {
FileBasedIndex.getInstance().processAllKeys(JSPackageIndex.INDEX_ID, packageName -> {
result.add(StringUtil.isEmpty(packageName) ? "*" : packageName + ".*");
return true;
}, project);
} else {
final GlobalSearchScope scopeWithLibs = module != null ? GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module) : GlobalSearchScope.allScope(project);
for (JSQualifiedNamedElement element : JSResolveUtil.findElementsByName(tagName, project, scopeWithLibs, false)) {
if (element instanceof JSClass && CodeContext.hasDefaultConstructor((JSClass) element)) {
final String packageName = StringUtil.getPackageName(element.getQualifiedName());
if (!componentsThatHaveNotPackageBackedNamespace.contains(StringUtil.getQualifiedName(packageName, tagName))) {
result.add(StringUtil.isEmpty(packageName) ? "*" : packageName + ".*");
}
}
}
}
final GlobalSearchScope scopeWithoutLibs = module != null ? GlobalSearchScope.moduleWithDependenciesScope(module) : GlobalSearchScope.allScope(project);
// packages that contain *.mxml files and do not contain *.as are not retrieved from JSPackageIndex
FlexResolveHelper.processAllMxmlAndFxgFiles(scopeWithoutLibs, project, new FlexResolveHelper.MxmlAndFxgFilesProcessor() {
public void addDependency(final PsiDirectory directory) {
}
public boolean processFile(final VirtualFile file, final VirtualFile root) {
if (tagName == null || tagName.equals(file.getNameWithoutExtension())) {
final String packageName = VfsUtilCore.getRelativePath(file.getParent(), root, '.');
if (packageName != null && (tagName == null || !componentsThatHaveNotPackageBackedNamespace.contains(StringUtil.getQualifiedName(packageName, tagName)))) {
result.add(StringUtil.isEmpty(packageName) ? "*" : packageName + ".*");
}
}
return true;
}
}, tagName);
return result;
}
Aggregations