use of com.intellij.xml.XmlAttributeDescriptor in project android by JetBrains.
the class PropertyTestCase method createFrom.
@NotNull
protected NlPropertyItem createFrom(@NotNull NlComponent component, @NotNull String attributeName) {
List<NlComponent> components = ImmutableList.of(component);
XmlAttributeDescriptor descriptor = getDescriptor(component, attributeName);
assertThat(descriptor).isNotNull();
AttributeDefinition definition = getDefinition(component, descriptor);
String namespace = getNamespace(component, descriptor);
return NlPropertyItem.create(components, descriptor, namespace, definition);
}
use of com.intellij.xml.XmlAttributeDescriptor in project android by JetBrains.
the class NlPropertyItemTest method testCreateWithoutSpecifyingNamespace.
public void testCreateWithoutSpecifyingNamespace() {
XmlAttributeDescriptor descriptor = getDescriptor(myTextView, ATTR_TEXT);
assertThat(descriptor).isNotNull();
NlPropertyItem item = NlPropertyItem.create(ImmutableList.of(myTextView), descriptor, null, getDefinition(myTextView, descriptor));
assertThat(item).isNotInstanceOf(NlFlagPropertyItem.class);
assertThat(item).isNotInstanceOf(NlIdPropertyItem.class);
assertThat(item.getName()).isEqualTo(ATTR_TEXT);
assertThat(item.getNamespace()).isEqualTo(ANDROID_URI);
}
use of com.intellij.xml.XmlAttributeDescriptor in project android by JetBrains.
the class NlPropertyItemTest method testSameDefinition.
public void testSameDefinition() {
NlPropertyItem text = createFrom(myTextView, ATTR_TEXT);
NlPropertyItem gravity = createFrom(myTextView, ATTR_GRAVITY);
XmlAttributeDescriptor gravityDescriptor = getDescriptor(myTextView, ATTR_GRAVITY);
assertThat(gravityDescriptor).isNotNull();
assertThat(text.sameDefinition(text)).isTrue();
assertThat(text.sameDefinition(new NlPropertyItem(ImmutableList.of(myTextView), ANDROID_URI, text.getDefinition()))).isTrue();
assertThat(text.sameDefinition(new NlPropertyItem(ImmutableList.of(myTextView), TOOLS_URI, text.getDefinition()))).isFalse();
assertThat(text.sameDefinition(new NlPropertyItem(ImmutableList.of(myTextView), ANDROID_URI, gravity.getDefinition()))).isFalse();
assertThat(text.sameDefinition(new NlPropertyItem(ImmutableList.of(myTextView), gravityDescriptor, TOOLS_URI, text.getDefinition()))).isFalse();
}
use of com.intellij.xml.XmlAttributeDescriptor in project intellij-plugins by JetBrains.
the class MxmlTagNameReference method insertNamespaceDeclaration.
public static void insertNamespaceDeclaration(@NotNull final XmlTag tag, @NotNull final String namespace, @NotNull final String prefix) {
final XmlAttribute[] attributes = tag.getAttributes();
XmlAttribute anchor = null;
for (final XmlAttribute attribute : attributes) {
final XmlAttributeDescriptor descriptor = attribute.getDescriptor();
if (attribute.isNamespaceDeclaration() || (descriptor != null && descriptor.isRequired())) {
anchor = attribute;
} else {
break;
}
}
@NonNls final String qname = "xmlns" + (prefix.length() > 0 ? ":" + prefix : "");
final XmlAttribute attribute = XmlElementFactory.getInstance(tag.getProject()).createXmlAttribute(qname, namespace);
if (anchor == null) {
tag.add(attribute);
} else {
tag.addAfter(attribute, anchor);
}
CodeStyleManager.getInstance(tag.getProject()).reformat(tag);
}
use of com.intellij.xml.XmlAttributeDescriptor in project intellij-plugins by JetBrains.
the class AngularJSAttributeDescriptorsProvider method getAttributeDescriptor.
@Nullable
@Override
public XmlAttributeDescriptor getAttributeDescriptor(final String attrName, XmlTag xmlTag) {
if (xmlTag != null) {
final Project project = xmlTag.getProject();
final String attributeName = DirectiveUtil.normalizeAttributeName(attrName);
PsiElement declaration = applicableDirective(project, attributeName, xmlTag, AngularDirectivesDocIndex.KEY);
if (declaration == PsiUtilCore.NULL_PSI_ELEMENT) {
declaration = applicableDirective(project, attributeName, xmlTag, AngularDirectivesIndex.KEY);
}
if (isApplicable(declaration)) {
return createDescriptor(project, attributeName, declaration);
}
if (!AngularIndexUtil.hasAngularJS2(project))
return null;
for (XmlAttribute attribute : xmlTag.getAttributes()) {
String name = attribute.getName();
if (isAngular2Attribute(name, project) || name.equals(attrName))
continue;
declaration = applicableDirective(project, name, xmlTag, AngularDirectivesIndex.KEY);
if (isApplicable(declaration)) {
for (XmlAttributeDescriptor binding : AngularAttributeDescriptor.getFieldBasedDescriptors((JSImplicitElement) declaration)) {
if (binding.getName().equals(attrName)) {
return binding;
}
}
}
}
if (AngularAttributesRegistry.isBindingAttribute(attrName, project)) {
return new AngularBindingDescriptor(xmlTag, attrName);
}
if (AngularAttributesRegistry.isEventAttribute(attrName, project)) {
return new AngularEventHandlerDescriptor(xmlTag, attrName);
}
return getAngular2Descriptor(attrName, project);
}
return null;
}
Aggregations