use of com.intellij.psi.xml.XmlAttribute in project intellij-community by JetBrains.
the class AddSchemaPrefixIntention method getXmlnsDeclaration.
@Nullable
private static XmlAttribute getXmlnsDeclaration(PsiElement element) {
final PsiElement parent = element.getParent();
if (parent instanceof XmlTag) {
XmlTag tag = (XmlTag) parent;
if (tag.getNamespacePrefix().isEmpty()) {
while (tag != null) {
final XmlAttribute attr = tag.getAttribute("xmlns");
if (attr != null)
return attr;
tag = tag.getParentTag();
}
}
} else if (parent instanceof XmlAttribute && ((XmlAttribute) parent).getName().equals("xmlns")) {
return (XmlAttribute) parent;
}
return null;
}
use of com.intellij.psi.xml.XmlAttribute in project intellij-community by JetBrains.
the class SchemaReferencesProvider method getReferencesByElement.
@Override
@NotNull
public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull final ProcessingContext context) {
final PsiElement parent = element.getParent();
if (!(parent instanceof XmlAttribute))
return PsiReference.EMPTY_ARRAY;
final String attrName = ((XmlAttribute) parent).getName();
if (VALUE_ATTR_NAME.equals(attrName)) {
return PsiReference.EMPTY_ARRAY;
} else if (NAME_ATTR_NAME.equals(attrName)) {
return new PsiReference[] { new NameReference(element) };
} else if (MEMBER_TYPES_ATTR_NAME.equals(attrName)) {
final List<PsiReference> result = new ArrayList<>(1);
final String text = element.getText();
int lastIndex = 1;
final int testLength = text.length();
for (int i = 1; i < testLength; ++i) {
if (Character.isWhitespace(text.charAt(i))) {
if (lastIndex != i)
result.add(new TypeOrElementOrAttributeReference(element, new TextRange(lastIndex, i)));
lastIndex = i + 1;
}
}
if (lastIndex != testLength - 1)
result.add(new TypeOrElementOrAttributeReference(element, new TextRange(lastIndex, testLength - 1)));
return result.toArray(new PsiReference[result.size()]);
} else {
final PsiReference prefix = createSchemaPrefixReference(element);
final PsiReference ref = createTypeOrElementOrAttributeReference(element, prefix == null ? null : prefix.getCanonicalText());
return prefix == null ? new PsiReference[] { ref } : new PsiReference[] { ref, prefix };
}
}
use of com.intellij.psi.xml.XmlAttribute in project intellij-community by JetBrains.
the class TypeOrElementOrAttributeReference method determineReferenceType.
@Nullable
private static ReferenceType determineReferenceType(PsiElement element) {
final XmlAttribute attribute = PsiTreeUtil.getParentOfType(element, XmlAttribute.class);
if (attribute == null) {
return null;
}
final XmlTag tag = attribute.getParent();
final String localName = tag.getLocalName();
final String attributeLocalName = attribute.getLocalName();
if (SchemaReferencesProvider.REF_ATTR_NAME.equals(attributeLocalName) || SchemaReferencesProvider.SUBSTITUTION_GROUP_ATTR_NAME.equals(attributeLocalName)) {
if (localName.equals(SchemaReferencesProvider.GROUP_TAG_NAME)) {
return ReferenceType.GroupReference;
} else if (localName.equals(SchemaReferencesProvider.ATTRIBUTE_GROUP_TAG_NAME)) {
return ReferenceType.AttributeGroupReference;
} else if (SchemaReferencesProvider.ELEMENT_TAG_NAME.equals(localName)) {
return ReferenceType.ElementReference;
} else if (SchemaReferencesProvider.ATTRIBUTE_TAG_NAME.equals(localName)) {
return ReferenceType.AttributeReference;
}
} else if (SchemaReferencesProvider.TYPE_ATTR_NAME.equals(attributeLocalName) || SchemaReferencesProvider.BASE_ATTR_NAME.equals(attributeLocalName) || SchemaReferencesProvider.MEMBER_TYPES_ATTR_NAME.equals(attributeLocalName) || SchemaReferencesProvider.ITEM_TYPE_ATTR_NAME.equals(attributeLocalName)) {
return ReferenceType.TypeReference;
}
return null;
}
use of com.intellij.psi.xml.XmlAttribute in project intellij-community by JetBrains.
the class XmlDuplicatedIdInspection method buildVisitor.
@NotNull
@Override
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, final boolean isOnTheFly) {
return new XmlElementVisitor() {
@Override
public void visitXmlAttributeValue(final XmlAttributeValue value) {
if (value.getTextRange().isEmpty()) {
return;
}
final PsiFile file = value.getContainingFile();
if (!(file instanceof XmlFile)) {
return;
}
PsiFile baseFile = PsiUtilCore.getTemplateLanguageFile(file);
if (baseFile != file && !(baseFile instanceof XmlFile)) {
return;
}
final XmlRefCountHolder refHolder = XmlRefCountHolder.getRefCountHolder((XmlFile) file);
if (refHolder == null)
return;
final PsiElement parent = value.getParent();
if (!(parent instanceof XmlAttribute))
return;
final XmlTag tag = (XmlTag) parent.getParent();
if (tag == null)
return;
checkValue(value, (XmlFile) file, refHolder, tag, holder);
}
};
}
use of com.intellij.psi.xml.XmlAttribute in project intellij-community by JetBrains.
the class MicrodataUtil method findScopesWithItemRef.
private static Map<String, XmlTag> findScopesWithItemRef(@Nullable final PsiFile file) {
if (!(file instanceof XmlFile))
return Collections.emptyMap();
return CachedValuesManager.getCachedValue(file, new CachedValueProvider<Map<String, XmlTag>>() {
@Nullable
@Override
public Result<Map<String, XmlTag>> compute() {
final Map<String, XmlTag> result = new THashMap<>();
file.accept(new XmlRecursiveElementVisitor() {
@Override
public void visitXmlTag(final XmlTag tag) {
super.visitXmlTag(tag);
XmlAttribute refAttr = tag.getAttribute(ITEM_REF);
if (refAttr != null && tag.getAttribute(ITEM_SCOPE) != null) {
getReferencesForAttributeValue(refAttr.getValueElement(), (t, v) -> {
result.put(t, tag);
return null;
});
}
}
});
return Result.create(result, file);
}
});
}
Aggregations