use of com.intellij.psi.xml.XmlElement in project intellij-community by JetBrains.
the class QNameUtil method createQName.
public static QName createQName(@NotNull String qname, @NotNull PsiElement context) {
final String[] strings = qname.split(":", 2);
if (strings.length == 1) {
return new QName(null, qname);
}
final XmlElement ctx = PsiTreeUtil.getParentOfType(context, XmlElement.class, false);
if (ctx == null)
return UNRESOLVED;
final String uri = XsltNamespaceContext.getNamespaceUriStatic(strings[0], ctx);
if (uri == null)
return UNRESOLVED;
return new QName(uri, strings[1], strings[0]);
}
use of com.intellij.psi.xml.XmlElement in project intellij-community by JetBrains.
the class DtdResolveUtil method getNsDescriptor.
@Nullable
static XmlNSDescriptor getNsDescriptor(XmlElement element) {
final XmlElement parentThatProvidesMetaData = PsiTreeUtil.getParentOfType(CompletionUtilCoreImpl.getOriginalElement(element), XmlDocument.class, XmlMarkupDecl.class);
if (parentThatProvidesMetaData instanceof XmlDocument) {
final XmlDocument document = (XmlDocument) parentThatProvidesMetaData;
XmlNSDescriptor rootTagNSDescriptor = document.getRootTagNSDescriptor();
if (rootTagNSDescriptor == null)
rootTagNSDescriptor = (XmlNSDescriptor) document.getMetaData();
return rootTagNSDescriptor;
} else if (parentThatProvidesMetaData instanceof XmlMarkupDecl) {
final XmlMarkupDecl markupDecl = (XmlMarkupDecl) parentThatProvidesMetaData;
final PsiMetaData psiMetaData = markupDecl.getMetaData();
if (psiMetaData instanceof XmlNSDescriptor) {
return (XmlNSDescriptor) psiMetaData;
}
}
return null;
}
use of com.intellij.psi.xml.XmlElement 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.XmlElement in project intellij-community by JetBrains.
the class RemoveRedundantEscapeAction method replacement.
@NotNull
private String replacement(int codePoint) {
final PsiElement context = myChar.getContainingFile().getContext();
String s = Character.isSupplementaryCodePoint(codePoint) ? Character.toString(Character.highSurrogate(codePoint)) + Character.toString(Character.lowSurrogate(codePoint)) : Character.toString((char) codePoint);
if (RegExpElementImpl.isLiteralExpression(context)) {
return StringUtil.escapeStringCharacters(s);
} else if (context instanceof XmlElement) {
return XmlStringUtil.escapeString(s);
} else {
return s;
}
}
use of com.intellij.psi.xml.XmlElement in project intellij-community by JetBrains.
the class AntDomElement method getContextAntProject.
public final AntDomProject getContextAntProject() {
final AntConfigurationBase antConfig = AntConfigurationBase.getInstance(getManager().getProject());
final XmlElement xmlElement = getXmlElement();
if (xmlElement == null) {
return getAntProject();
}
PsiFile containingFile = xmlElement.getContainingFile();
if (containingFile != null) {
containingFile = containingFile.getOriginalFile();
}
if (!(containingFile instanceof XmlFile)) {
return getAntProject();
}
final XmlFile contextFile = antConfig.getEffectiveContextFile(((XmlFile) containingFile));
if (contextFile == null) {
return getAntProject();
}
return AntSupport.getAntDomProject(contextFile);
}
Aggregations