use of com.intellij.psi.xml.XmlAttribute in project intellij-community by JetBrains.
the class XmlSchemaTest method testAny3.
public void testAny3() throws Exception {
XmlNSDescriptor NSDescriptor = createDescriptor("<xsd:schema targetNamespace=\"http://foo\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" >" + " <xsd:element name=\"root\">" + " <xsd:complexType>" + " <xsd:anyAttribute namespace=\"##other\" processContents=\"skip\"/>" + " </xsd:complexType>" + " </xsd:element>" + "</xsd:schema>");
XmlFile xmlFile = (XmlFile) createFile("file.xml", "<root xmlns=\"http://foo\" y:a=\"1\">" + "</root>");
final XmlTag rootTag = xmlFile.getDocument().getRootTag();
XmlElementDescriptor rootDescriptor = NSDescriptor.getElementDescriptor(rootTag);
assertNotNull(rootDescriptor);
XmlAttribute attribute = rootTag.getAttribute("y:a", XmlUtil.EMPTY_URI);
assertNotNull(attribute);
XmlAttributeDescriptor aDescriptor = rootDescriptor.getAttributeDescriptor("y:a", rootTag);
assertNotNull(aDescriptor);
}
use of com.intellij.psi.xml.XmlAttribute in project intellij-community by JetBrains.
the class MvcFramework method getInstalledPluginNameByPath.
@Nullable
public String getInstalledPluginNameByPath(Project project, @NotNull VirtualFile pluginPath) {
VirtualFile pluginXml = pluginPath.findChild("plugin.xml");
if (pluginXml == null)
return null;
PsiFile pluginXmlPsi = PsiManager.getInstance(project).findFile(pluginXml);
if (!(pluginXmlPsi instanceof XmlFile))
return null;
XmlTag rootTag = ((XmlFile) pluginXmlPsi).getRootTag();
if (rootTag == null || !"plugin".equals(rootTag.getName()))
return null;
XmlAttribute attrName = rootTag.getAttribute("name");
if (attrName == null)
return null;
String res = attrName.getValue();
if (res == null)
return null;
res = res.trim();
if (res.isEmpty())
return null;
return res;
}
use of com.intellij.psi.xml.XmlAttribute in project intellij-community by JetBrains.
the class MavenFilteredPropertiesCompletionAndResolutionTest method testReferencesInXml.
public void testReferencesInXml() throws Exception {
createProjectSubDir("res");
importProject("<groupId>test</groupId>" + "<artifactId>project</artifactId>" + "<version>1</version>" + "<build>" + " <resources>" + " <resource>" + " <directory>res</directory>" + " <filtering>true</filtering>" + " </resource>" + " </resources>" + "</build>");
VirtualFile f = createProjectSubFile("res/foo.xml", "<root attr='${based<caret>ir}'>" + "</root>");
myFixture.configureFromExistingVirtualFile(f);
XmlAttribute attribute = PsiTreeUtil.getParentOfType(myFixture.getFile().findElementAt(myFixture.getCaretOffset()), XmlAttribute.class);
PsiReference[] references = attribute.getReferences();
for (PsiReference ref : references) {
if (ref.resolve() instanceof PsiDirectory) {
// Maven references was added.
return;
}
}
assertTrue("Maven filter reference was not added", false);
}
use of com.intellij.psi.xml.XmlAttribute in project intellij-community by JetBrains.
the class RngDocumentationProvider method generateDoc.
@Override
@Nullable
public String generateDoc(PsiElement element, @Nullable PsiElement originalElement) {
final XmlElement c = PsiTreeUtil.getParentOfType(originalElement, XmlTag.class, XmlAttribute.class);
if (c != null && c.getManager() == null) {
LOG.warn("Invalid context element passed to generateDoc()", new Throwable("<stack trace>"));
return null;
}
if (c instanceof XmlTag) {
final XmlTag xmlElement = (XmlTag) c;
final XmlElementDescriptor descriptor = xmlElement.getDescriptor();
if (descriptor instanceof CompositeDescriptor) {
final StringBuilder sb = new StringBuilder();
final CompositeDescriptor d = (CompositeDescriptor) descriptor;
final DElementPattern[] patterns = d.getElementPatterns();
final THashSet<PsiElement> elements = ContainerUtil.newIdentityTroveSet();
for (DElementPattern pattern : patterns) {
final PsiElement psiElement = d.getDeclaration(pattern.getLocation());
if (psiElement instanceof XmlTag && elements.add(psiElement)) {
if (sb.length() > 0) {
sb.append("<hr>");
}
sb.append(getDocumentationFromTag((XmlTag) psiElement, xmlElement.getLocalName(), "Element"));
}
}
return makeDocumentation(sb);
} else if (descriptor instanceof RngElementDescriptor) {
final RngElementDescriptor d = (RngElementDescriptor) descriptor;
final PsiElement declaration = d.getDeclaration();
if (declaration instanceof XmlTag) {
return makeDocumentation(getDocumentationFromTag((XmlTag) declaration, xmlElement.getLocalName(), "Element"));
}
}
} else if (c instanceof XmlAttribute) {
final XmlAttribute attribute = (XmlAttribute) c;
final XmlAttributeDescriptor descriptor = attribute.getDescriptor();
if (descriptor instanceof RngXmlAttributeDescriptor) {
final RngXmlAttributeDescriptor d = (RngXmlAttributeDescriptor) descriptor;
final StringBuilder sb = new StringBuilder();
final Collection<PsiElement> declaration = ContainerUtil.newIdentityTroveSet(d.getDeclarations());
for (PsiElement psiElement : declaration) {
if (psiElement instanceof XmlTag) {
if (sb.length() > 0) {
sb.append("<hr>");
}
sb.append(getDocumentationFromTag((XmlTag) psiElement, d.getName(), "Attribute"));
}
}
return makeDocumentation(sb);
}
} else if (element instanceof XmlTag) {
return makeDocumentation(getDocumentationFromTag((XmlTag) element, ((XmlTag) element).getLocalName(), "Element"));
}
return null;
}
use of com.intellij.psi.xml.XmlAttribute in project intellij-community by JetBrains.
the class AntDomExtender method defineAttributes.
private static void defineAttributes(XmlTag xmlTag, DomExtensionsRegistrar registrar, DomGenericInfo genericInfo, AbstractIntrospector parentIntrospector) {
final Map<String, Pair<Type, Class>> registeredAttribs = getStaticallyRegisteredAttributes(genericInfo);
// define attributes discovered by introspector and not yet defined statically
final Iterator<String> introspectedAttributes = parentIntrospector.getAttributesIterator();
while (introspectedAttributes.hasNext()) {
final String attribName = introspectedAttributes.next();
if (genericInfo.getAttributeChildDescription(attribName) == null) {
// if not defined yet
final String _attribName = attribName.toLowerCase(Locale.US);
final Pair<Type, Class> types = registeredAttribs.get(_attribName);
Type type = types != null ? types.getFirst() : null;
Class converterClass = types != null ? types.getSecond() : null;
if (type == null) {
// use String by default
type = String.class;
final Class attributeType = parentIntrospector.getAttributeType(attribName);
if (attributeType != null) {
// handle well-known types
if (File.class.isAssignableFrom(attributeType)) {
type = PsiFileSystemItem.class;
converterClass = AntPathConverter.class;
} else if (Boolean.class.isAssignableFrom(attributeType)) {
type = Boolean.class;
converterClass = AntBooleanConverter.class;
} else if (isAssignableFrom(Reference.class.getName(), attributeType)) {
converterClass = AntDomRefIdConverter.class;
}
}
}
LOG.assertTrue(type != null);
registerAttribute(registrar, attribName, type, converterClass);
if (types == null) {
// augment the map if this was a newly added attribute
registeredAttribs.put(_attribName, Pair.create(type, converterClass));
}
}
}
// additionaly register all attributes that exist in XML but differ from the registered ones only in case
for (XmlAttribute xmlAttribute : xmlTag.getAttributes()) {
final String existingAttribName = xmlAttribute.getName();
if (genericInfo.getAttributeChildDescription(existingAttribName) == null) {
final Pair<Type, Class> pair = registeredAttribs.get(existingAttribName.toLowerCase(Locale.US));
if (pair != null) {
// if such attribute should actually be here
registerAttribute(registrar, existingAttribName, pair.getFirst(), pair.getSecond());
}
}
}
}
Aggregations