use of com.intellij.psi.xml.XmlAttribute 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.psi.xml.XmlAttribute in project android by JetBrains.
the class DeletionHandler method transfer.
private void transfer(NlComponent deleted, NlComponent target, ConstraintType targetType, int depth) {
if (depth == 20) {
// the cycle detection code
return;
}
assert myDeleted.contains(deleted);
for (XmlAttribute attribute : deleted.getTag().getAttributes()) {
String name = attribute.getLocalName();
ConstraintType type = ConstraintType.fromAttribute(name);
if (type == null) {
continue;
}
ConstraintType transfer = getCompatibleConstraint(type, targetType);
if (transfer != null) {
String id = getId(attribute);
if (id != null) {
if (myDeletedIds.contains(id)) {
NlComponent nextDeleted = myNodeMap.get(id);
if (nextDeleted != null) {
// Points to another deleted node: recurse
transfer(nextDeleted, target, targetType, depth + 1);
}
} else {
// Found an undeleted node destination: point to it directly.
// Note that we're using the
target.setAttribute(ANDROID_URI, transfer.name, attribute.getValue());
}
} else {
// Pointing to parent or center etc (non-id ref): replicate this on the target
target.setAttribute(ANDROID_URI, name, attribute.getValue());
}
}
}
}
use of com.intellij.psi.xml.XmlAttribute in project android by JetBrains.
the class DeletionHandler method updateConstraints.
/**
* Updates the constraints in the layout to handle deletion of a set of
* nodes. This ensures that any constraints pointing to one of the deleted
* nodes are changed properly to point to a non-deleted node with similar
* constraints.
*/
public void updateConstraints() {
if (myChildren.size() == myDeleted.size()) {
// Deleting everything: Nothing to be done
return;
}
for (NlComponent child : myChildren) {
if (myDeleted.contains(child)) {
continue;
}
for (XmlAttribute attribute : child.getTag().getAttributes()) {
String id = getId(attribute);
if (id != null) {
if (myDeletedIds.contains(id)) {
// Unset this reference to a deleted widget. It might be
// replaced if the pointed to node points to some other node
// on the same side, but it may use a different constraint name,
// or have none at all (e.g. parent).
String name = attribute.getLocalName();
attribute.delete();
NlComponent deleted = myNodeMap.get(id);
if (deleted != null) {
ConstraintType type = ConstraintType.fromAttribute(name);
if (type != null) {
transfer(deleted, child, type, 0);
}
}
}
}
}
}
}
use of com.intellij.psi.xml.XmlAttribute 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;
}
use of com.intellij.psi.xml.XmlAttribute in project intellij-plugins by JetBrains.
the class ActionScriptCustomIndexer method processXmlTag.
@Override
protected JSQualifiedName processXmlTag(XmlTag element) {
final XmlAttribute idAttribute = element.getAttribute("id");
final String id = idAttribute == null ? null : idAttribute.getValue();
if (idAttribute != null && id != null) {
final JSImplicitElementImpl.Builder builder = new JSImplicitElementImpl.Builder(id, null).setType(JSImplicitElement.Type.Tag);
addImplicitElement(idAttribute, builder);
}
return myNamespaces.peek();
}
Aggregations