use of com.intellij.xml.XmlElementDescriptor in project intellij-plugins by JetBrains.
the class AngularJSTagDescriptorsProvider method getDescriptor.
@Nullable
@Override
public XmlElementDescriptor getDescriptor(XmlTag xmlTag) {
final Project project = xmlTag.getProject();
if (!(xmlTag instanceof HtmlTag && AngularIndexUtil.hasAngularJS(project)))
return null;
final String tagName = xmlTag.getName();
final String directiveName = DirectiveUtil.normalizeAttributeName(tagName);
final XmlNSDescriptor nsDescriptor = xmlTag.getNSDescriptor(xmlTag.getNamespace(), false);
final XmlElementDescriptor descriptor = nsDescriptor != null ? nsDescriptor.getElementDescriptor(xmlTag) : null;
if (descriptor != null && !(descriptor instanceof AnyXmlElementDescriptor)) {
return null;
}
if ((NG_CONTAINER.equals(directiveName) || NG_CONTENT.equals(directiveName) || NG_TEMPLATE.equals(directiveName)) && AngularIndexUtil.hasAngularJS2(project)) {
return new AngularJSTagDescriptor(directiveName, createDirective(xmlTag, directiveName));
}
JSImplicitElement directive = DirectiveUtil.getTagDirective(directiveName, project);
if (DirectiveUtil.isAngular2Directive(directive) && !directive.getName().equals(tagName)) {
// we've found directive via normalized name for Angular, it should not work
directive = null;
}
if (directive == null && !tagName.equals(directiveName) && AngularIndexUtil.hasAngularJS2(project)) {
directive = DirectiveUtil.getTagDirective(tagName, project);
if (!DirectiveUtil.isAngular2Directive(directive))
directive = null;
}
return directive != null ? new AngularJSTagDescriptor(directiveName, directive) : null;
}
use of com.intellij.xml.XmlElementDescriptor in project intellij-plugins by JetBrains.
the class FlexCssElementDescriptorProvider method getClassFromMxmlDescriptor.
@Nullable
private static JSClass getClassFromMxmlDescriptor(@NotNull CssSimpleSelector selector, @NotNull Module module) {
final XmlElementDescriptor xmlElementDescriptor = getTypeSelectorDescriptor(selector, module);
if (xmlElementDescriptor == null) {
return null;
}
final PsiElement declaration = xmlElementDescriptor.getDeclaration();
return declaration instanceof JSClass ? (JSClass) declaration : null;
}
use of com.intellij.xml.XmlElementDescriptor in project intellij-plugins by JetBrains.
the class ResolveExternalInlineStyleSourceAction method find.
private Navigatable find(XmlTag parent, boolean firstLevel) {
for (XmlTag xmlTag : parent.getSubTags()) {
String localName = xmlTag.getLocalName();
if (firstLevel && ignoredRootTags.contains(localName)) {
continue;
}
XmlElementDescriptor xmlTagDescriptor = xmlTag.getDescriptor();
if (xmlTagDescriptor instanceof ClassBackedElementDescriptor) {
Navigatable result;
if (xmlTagDescriptor.getQualifiedName().equals(elementFqn)) {
result = findTargetIfStyleDeclarationOwner(xmlTag);
if (result != null) {
return result;
}
}
result = find(xmlTag, false);
if (result != null) {
return result;
}
}
}
return null;
}
use of com.intellij.xml.XmlElementDescriptor in project intellij-plugins by JetBrains.
the class ResolveExternalInlineStyleSourceAction method findTargetIfStyleDeclarationOwner.
private Navigatable findTargetIfStyleDeclarationOwner(XmlTag parent) {
int foundCount = 0;
Navigatable target = null;
for (XmlAttribute attribute : parent.getAttributes()) {
XmlAttributeDescriptor descriptor = attribute.getDescriptor();
// 8
if (descriptor instanceof AnnotationBackedDescriptor) {
String ourValue = properties.get(descriptor.getName());
if (ourValue != null) {
if (attribute.getDisplayValue().equals(ourValue)) {
foundCount++;
if (descriptor.getName().equals(targetStyleName)) {
target = (Navigatable) attribute;
}
if (foundCount == properties.size()) {
return target;
}
}
}
}
}
for (XmlTag tag : parent.getSubTags()) {
XmlElementDescriptor descriptor = tag.getDescriptor();
if (descriptor instanceof AnnotationBackedDescriptor && ((PsiPresentableMetaData) descriptor).getTypeName().equals(FlexAnnotationNames.STYLE)) {
String ourValue = properties.get(descriptor.getName());
if (ourValue != null) {
if (tag.getSubTags().length == 0 && tag.getValue().getTrimmedText().equals(ourValue)) {
foundCount++;
if (descriptor.getName().equals(targetStyleName)) {
target = (Navigatable) tag;
}
if (foundCount == properties.size()) {
return target;
}
}
}
}
}
return null;
}
use of com.intellij.xml.XmlElementDescriptor in project intellij-plugins by JetBrains.
the class AngularJSAttributeDescriptorsProvider method getAttributeDescriptors.
@Override
public XmlAttributeDescriptor[] getAttributeDescriptors(XmlTag xmlTag) {
if (xmlTag != null) {
final Map<String, XmlAttributeDescriptor> result = new LinkedHashMap<>();
final Project project = xmlTag.getProject();
final XmlElementDescriptor descriptor = xmlTag.getDescriptor();
final Collection<String> directives = AngularIndexUtil.getAllKeys(AngularDirectivesIndex.KEY, project);
if (AngularIndexUtil.hasAngularJS2(project)) {
if (descriptor instanceof HtmlElementDescriptorImpl) {
final XmlAttributeDescriptor[] descriptors = ((HtmlElementDescriptorImpl) descriptor).getDefaultAttributeDescriptors(xmlTag);
for (XmlAttributeDescriptor attributeDescriptor : descriptors) {
final String name = attributeDescriptor.getName();
if (name.startsWith("on")) {
addAttributes(project, result, "(" + name.substring(2) + ")", null);
}
}
}
for (XmlAttribute attribute : xmlTag.getAttributes()) {
final String name = attribute.getName();
if (isAngular2Attribute(name, project) || !directives.contains(name))
continue;
final PsiElement declaration = applicableDirective(project, name, xmlTag, AngularDirectivesIndex.KEY);
if (isApplicable(declaration)) {
for (XmlAttributeDescriptor binding : AngularAttributeDescriptor.getFieldBasedDescriptors((JSImplicitElement) declaration)) {
result.put(binding.getName(), binding);
}
}
}
}
final Collection<String> docDirectives = AngularIndexUtil.getAllKeys(AngularDirectivesDocIndex.KEY, project);
for (String directiveName : docDirectives) {
PsiElement declaration = applicableDirective(project, directiveName, xmlTag, AngularDirectivesDocIndex.KEY);
if (isApplicable(declaration)) {
addAttributes(project, result, directiveName, declaration);
}
}
for (String directiveName : directives) {
if (!docDirectives.contains(directiveName)) {
PsiElement declaration = applicableDirective(project, directiveName, xmlTag, AngularDirectivesIndex.KEY);
if (isApplicable(declaration)) {
addAttributes(project, result, directiveName, declaration);
}
}
}
return result.values().toArray(new XmlAttributeDescriptor[result.size()]);
}
return XmlAttributeDescriptor.EMPTY;
}
Aggregations