use of com.intellij.xml.XmlAttributeDescriptor in project intellij-community by JetBrains.
the class Html5CustomAttributeDescriptorsProvider method getAttributeDescriptors.
@Override
public XmlAttributeDescriptor[] getAttributeDescriptors(XmlTag tag) {
if (tag == null || !HtmlUtil.isHtml5Context(tag)) {
return XmlAttributeDescriptor.EMPTY;
}
final List<String> currentAttrs = new ArrayList<>();
for (XmlAttribute attribute : tag.getAttributes()) {
currentAttrs.add(attribute.getName());
}
final Project project = tag.getProject();
final Collection<String> keys = CachedValuesManager.getManager(project).getCachedValue(project, () -> {
final Collection<String> keys1 = FileBasedIndex.getInstance().getAllKeys(Html5CustomAttributesIndex.INDEX_ID, project);
final GlobalSearchScope scope = GlobalSearchScope.allScope(project);
return CachedValueProvider.Result.<Collection<String>>create(ContainerUtil.filter(keys1, key -> !FileBasedIndex.getInstance().processValues(Html5CustomAttributesIndex.INDEX_ID, key, null, (file, value) -> false, scope)), PsiModificationTracker.MODIFICATION_COUNT);
});
if (keys.isEmpty())
return XmlAttributeDescriptor.EMPTY;
final List<XmlAttributeDescriptor> result = new ArrayList<>();
for (String key : keys) {
boolean add = true;
for (String attr : currentAttrs) {
if (attr.startsWith(key)) {
add = false;
}
}
if (add) {
result.add(new AnyXmlAttributeDescriptor(key));
}
}
return result.toArray(new XmlAttributeDescriptor[result.size()]);
}
use of com.intellij.xml.XmlAttributeDescriptor in project intellij-community by JetBrains.
the class MicrodataAttributeDescriptorsProvider method getAttributeDescriptors.
@Override
public XmlAttributeDescriptor[] getAttributeDescriptors(XmlTag context) {
if (!HtmlUtil.isHtml5Context(context)) {
return XmlAttributeDescriptor.EMPTY;
}
final String tagName = context.getName();
List<XmlAttributeDescriptor> result = new ArrayList<>();
final boolean goodContextForProps = "div".equalsIgnoreCase(tagName) || "span".equalsIgnoreCase(tagName) || "a".equalsIgnoreCase(tagName);
if (goodContextForProps && hasScopeTag(context)) {
result.add(new MicrodataPropertyAttributeDescriptor(context));
}
if (context.getAttribute(ITEM_SCOPE) == null) {
result.add(new AnyXmlAttributeDescriptor(ITEM_SCOPE));
} else {
result.add(new XmlAttributeDescriptorWithEmptyDefaultValue(ITEM_ID));
result.add(new XmlAttributeDescriptorWithEmptyDefaultValue(ITEM_TYPE));
result.add(new XmlAttributeDescriptorWithEmptyDefaultValue(ITEM_REF));
}
return result.toArray(new XmlAttributeDescriptor[result.size()]);
}
use of com.intellij.xml.XmlAttributeDescriptor in project intellij-community by JetBrains.
the class XmlHighlightingTest method testAnyAttributeNavigation.
public void testAnyAttributeNavigation() throws Exception {
configureByFiles(null, getVirtualFile(BASE_PATH + "AnyAttributeNavigation/test.xml"), getVirtualFile(BASE_PATH + "AnyAttributeNavigation/test.xsd"), getVirtualFile(BASE_PATH + "AnyAttributeNavigation/library.xsd"));
PsiReference at = getFile().findReferenceAt(getEditor().getCaretModel().getOffset());
XmlTag tag = PsiTreeUtil.getParentOfType(at.getElement(), XmlTag.class);
XmlElementDescriptorImpl descriptor = (XmlElementDescriptorImpl) tag.getDescriptor();
XmlAttributeDescriptor[] descriptors = descriptor.getAttributesDescriptors(tag);
System.out.println(Arrays.asList(descriptors));
doDoTest(true, false);
PsiElement resolve = at.resolve();
assertTrue(resolve instanceof XmlTag);
}
use of com.intellij.xml.XmlAttributeDescriptor in project intellij-community by JetBrains.
the class PsiDocumentNavigator method getElementById.
public Object getElementById(Object object, final String elementId) {
final XmlTag rootTag = ((XmlFile) ((XmlElement) object).getContainingFile()).getRootTag();
if (rootTag == null) {
return null;
}
final Ref<XmlTag> ref = new Ref<>();
rootTag.accept(new XmlRecursiveElementVisitor() {
@Override
public void visitElement(PsiElement element) {
if (ref.get() == null) {
super.visitElement(element);
}
}
@Override
public void visitXmlAttribute(XmlAttribute attribute) {
final XmlAttributeDescriptor descriptor = attribute.getDescriptor();
final String value = attribute.getValue();
if ((value != null && (descriptor != null && descriptor.hasIdType()))) {
if (elementId.equals(value)) {
ref.set(attribute.getParent());
}
}
}
});
return ref.get();
}
use of com.intellij.xml.XmlAttributeDescriptor in project intellij-community by JetBrains.
the class XmlAttributeReferenceCompletionProvider method addAttributeReferenceCompletionVariants.
public static void addAttributeReferenceCompletionVariants(XmlAttributeReference reference, CompletionResultSet result, @Nullable InsertHandler<LookupElement> replacementInsertHandler) {
final XmlTag declarationTag = reference.getElement().getParent();
LOG.assertTrue(declarationTag.isValid());
final XmlElementDescriptor parentDescriptor = declarationTag.getDescriptor();
if (parentDescriptor != null) {
final XmlAttribute[] attributes = declarationTag.getAttributes();
XmlAttributeDescriptor[] descriptors = parentDescriptor.getAttributesDescriptors(declarationTag);
descriptors = HtmlUtil.appendHtmlSpecificAttributeCompletions(declarationTag, descriptors, reference.getElement());
addVariants(result, attributes, descriptors, reference.getElement(), replacementInsertHandler);
}
}
Aggregations