use of com.intellij.xml.XmlAttributeDescriptor in project intellij-community by JetBrains.
the class AbstractDomChildrenDescriptor method getAttributesDescriptors.
@Override
public XmlAttributeDescriptor[] getAttributesDescriptors(@Nullable final XmlTag context) {
if (context == null)
return XmlAttributeDescriptor.EMPTY;
DomElement domElement = myManager.getDomElement(context);
if (domElement == null)
return XmlAttributeDescriptor.EMPTY;
final List<? extends DomAttributeChildDescription> descriptions = domElement.getGenericInfo().getAttributeChildrenDescriptions();
List<XmlAttributeDescriptor> descriptors = new ArrayList<>();
for (DomAttributeChildDescription description : descriptions) {
descriptors.add(new DomAttributeXmlDescriptor(description, myManager.getProject()));
}
List<? extends CustomDomChildrenDescription> customs = domElement.getGenericInfo().getCustomNameChildrenDescription();
for (CustomDomChildrenDescription custom : customs) {
CustomDomChildrenDescription.AttributeDescriptor descriptor = custom.getCustomAttributeDescriptor();
if (descriptor != null) {
for (EvaluatedXmlName variant : descriptor.getCompletionVariants(domElement)) {
AttributeChildDescriptionImpl childDescription = new AttributeChildDescriptionImpl(variant.getXmlName(), String.class);
descriptors.add(new DomAttributeXmlDescriptor(childDescription, myManager.getProject()));
}
}
}
return descriptors.toArray(new XmlAttributeDescriptor[descriptors.size()]);
}
use of com.intellij.xml.XmlAttributeDescriptor in project intellij-community by JetBrains.
the class XmlNSDescriptorImpl method getAttributeImpl.
@Nullable
private XmlAttributeDescriptor getAttributeImpl(String localName, String namespace, @Nullable Set<XmlTag> visited) {
if (myTag == null)
return null;
XmlNSDescriptor nsDescriptor = myTag.getNSDescriptor(namespace, true);
if (nsDescriptor != this && nsDescriptor instanceof XmlNSDescriptorImpl) {
return ((XmlNSDescriptorImpl) nsDescriptor).getAttributeImpl(localName, namespace, visited);
}
if (visited == null)
visited = new HashSet<>(1);
else if (visited.contains(myTag))
return null;
visited.add(myTag);
XmlTag[] tags = myTag.getSubTags();
for (XmlTag tag : tags) {
if (equalsToSchemaName(tag, ATTRIBUTE_TAG_NAME)) {
String name = tag.getAttributeValue("name");
if (name != null) {
if (checkElementNameEquivalence(localName, namespace, name, tag)) {
return createAttributeDescriptor(tag);
}
}
} else if (equalsToSchemaName(tag, INCLUDE_TAG_NAME) || (equalsToSchemaName(tag, IMPORT_TAG_NAME) && namespace.equals(tag.getAttributeValue("namespace")))) {
final String schemaLocation = tag.getAttributeValue("schemaLocation");
if (schemaLocation != null) {
final XmlFile xmlFile = XmlUtil.findNamespace(myTag.getContainingFile(), schemaLocation);
if (xmlFile != null) {
final XmlDocument includedDocument = xmlFile.getDocument();
if (includedDocument != null) {
final PsiMetaData data = includedDocument.getMetaData();
if (data instanceof XmlNSDescriptorImpl) {
final XmlAttributeDescriptor attributeDescriptor = ((XmlNSDescriptorImpl) data).getAttributeImpl(localName, namespace, visited);
if (attributeDescriptor != null) {
final CachedValue<XmlAttributeDescriptor> value = CachedValuesManager.getManager(includedDocument.getProject()).createCachedValue(() -> {
Object[] deps = attributeDescriptor.getDependences();
if (deps.length == 0) {
LOG.error(attributeDescriptor + " (" + attributeDescriptor.getClass() + ") returned no dependencies");
}
return new CachedValueProvider.Result<>(attributeDescriptor, deps);
}, false);
return value.getValue();
}
}
}
}
}
}
}
return null;
}
use of com.intellij.xml.XmlAttributeDescriptor in project intellij-community by JetBrains.
the class XmlElementDescriptorImpl method collectAttributeDescriptorsMap.
// Read-only calculation
@Override
protected HashMap<String, XmlAttributeDescriptor> collectAttributeDescriptorsMap(final XmlTag context) {
final HashMap<String, XmlAttributeDescriptor> localADM;
final XmlAttributeDescriptor[] xmlAttributeDescriptors = getAttributesDescriptors(context);
localADM = new HashMap<>(xmlAttributeDescriptors.length);
for (final XmlAttributeDescriptor xmlAttributeDescriptor : xmlAttributeDescriptors) {
localADM.put(xmlAttributeDescriptor.getName(), xmlAttributeDescriptor);
}
return localADM;
}
use of com.intellij.xml.XmlAttributeDescriptor in project intellij-community by JetBrains.
the class XsltContextProviderBase method processElementDescriptors.
private static void processElementDescriptors(XmlElementDescriptor descriptor, XmlTag tag, ElementNames names, Set<XmlElementDescriptor> history, int depth) throws StopProcessingException {
if (!history.add(descriptor) || ++depth == 200) {
if (depth == 200) {
throw new StopProcessingException();
}
return;
}
final String namespace = descriptor instanceof XmlElementDescriptorImpl ? ((XmlElementDescriptorImpl) descriptor).getNamespace() : tag.getNamespace();
names.elementNames.add(new QName(namespace, descriptor.getName()));
final XmlAttributeDescriptor[] attributesDescriptors = descriptor.getAttributesDescriptors(null);
for (XmlAttributeDescriptor attributesDescriptor : attributesDescriptors) {
final String localPart = attributesDescriptor.getName();
if (!"xmlns".equals(localPart))
names.attributeNames.add(new QName(localPart));
}
final XmlElementDescriptor[] descriptors = descriptor.getElementsDescriptors(tag);
for (XmlElementDescriptor elem : descriptors) {
processElementDescriptors(elem, tag, names, history, depth);
}
}
use of com.intellij.xml.XmlAttributeDescriptor in project intellij-community by JetBrains.
the class XmlParameterInfoHandler method updateElementDescriptor.
public static void updateElementDescriptor(XmlElementDescriptor descriptor, ParameterInfoUIContext context, Function<String, Boolean> attributePresentFun) {
final XmlAttributeDescriptor[] attributes = descriptor != null ? getSortedDescriptors(descriptor) : XmlAttributeDescriptor.EMPTY;
StringBuilder buffer = new StringBuilder();
int highlightStartOffset = -1;
int highlightEndOffset = -1;
if (attributes.length == 0) {
buffer.append(CodeInsightBundle.message("xml.tag.info.no.attributes"));
} else {
StringBuilder text1 = new StringBuilder(" ");
StringBuilder text2 = new StringBuilder(" ");
StringBuilder text3 = new StringBuilder(" ");
for (XmlAttributeDescriptor attribute : attributes) {
if (Boolean.TRUE.equals(attributePresentFun.fun(attribute.getName()))) {
if (!(text1.toString().equals(" "))) {
text1.append(", ");
}
text1.append(attribute.getName());
} else if (attribute.isRequired()) {
if (!(text2.toString().equals(" "))) {
text2.append(", ");
}
text2.append(attribute.getName());
} else {
if (!(text3.toString().equals(" "))) {
text3.append(", ");
}
text3.append(attribute.getName());
}
}
if (!text1.toString().equals(" ") && !text2.toString().equals(" ")) {
text1.append(", ");
}
if (!text2.toString().equals(" ") && !text3.toString().equals(" ")) {
text2.append(", ");
}
if (!text1.toString().equals(" ") && !text3.toString().equals(" ") && text2.toString().equals(" ")) {
text1.append(", ");
}
buffer.append(text1);
highlightStartOffset = buffer.length();
buffer.append(text2);
highlightEndOffset = buffer.length();
buffer.append(text3);
}
context.setupUIComponentPresentation(buffer.toString(), highlightStartOffset, highlightEndOffset, false, false, true, context.getDefaultParameterColor());
}
Aggregations