Search in sources :

Example 6 with XmlText

use of com.intellij.psi.xml.XmlText in project intellij-community by JetBrains.

the class HtmlTextCompletionConfidence method shouldSkipAutopopupInHtml.

public static boolean shouldSkipAutopopupInHtml(@NotNull PsiElement contextElement, int offset) {
    ASTNode node = contextElement.getNode();
    if (node != null && node.getElementType() == XmlTokenType.XML_DATA_CHARACTERS) {
        PsiElement parent = contextElement.getParent();
        if (parent instanceof XmlText || parent instanceof XmlDocument) {
            String contextElementText = contextElement.getText();
            int endOffset = offset - contextElement.getTextRange().getStartOffset();
            String prefix = contextElementText.substring(0, Math.min(contextElementText.length(), endOffset));
            return !StringUtil.startsWithChar(prefix, '<') && !StringUtil.startsWithChar(prefix, '&');
        }
    }
    return false;
}
Also used : ASTNode(com.intellij.lang.ASTNode) XmlText(com.intellij.psi.xml.XmlText) XmlDocument(com.intellij.psi.xml.XmlDocument) PsiElement(com.intellij.psi.PsiElement)

Example 7 with XmlText

use of com.intellij.psi.xml.XmlText in project intellij-community by JetBrains.

the class XmlCharFilter method isWithinTag.

public static boolean isWithinTag(Lookup lookup) {
    if (isInXmlContext(lookup)) {
        PsiElement psiElement = lookup.getPsiElement();
        final PsiElement parentElement = psiElement != null ? psiElement.getParent() : null;
        if (parentElement instanceof XmlTag)
            return true;
        if (parentElement instanceof PsiErrorElement && parentElement.getParent() instanceof XmlDocument)
            return true;
        return (parentElement instanceof XmlDocument || parentElement instanceof XmlText) && (psiElement.textMatches("<") || psiElement.textMatches("\""));
    }
    return false;
}
Also used : PsiErrorElement(com.intellij.psi.PsiErrorElement) XmlDocument(com.intellij.psi.xml.XmlDocument) XmlText(com.intellij.psi.xml.XmlText) PsiElement(com.intellij.psi.PsiElement) XmlTag(com.intellij.psi.xml.XmlTag)

Example 8 with XmlText

use of com.intellij.psi.xml.XmlText in project intellij-community by JetBrains.

the class XmlTagManipulator method getValueRanges.

public static TextRange[] getValueRanges(@NotNull final XmlTag tag) {
    final XmlTagValue value = tag.getValue();
    final XmlText[] texts = value.getTextElements();
    if (texts.length == 0) {
        return new TextRange[] { value.getTextRange().shiftRight(-tag.getTextOffset()) };
    } else {
        final TextRange[] ranges = new TextRange[texts.length];
        for (int i = 0; i < texts.length; i++) {
            ranges[i] = getValueRange(texts[i]);
        }
        return ranges;
    }
}
Also used : XmlTagValue(com.intellij.psi.xml.XmlTagValue) XmlText(com.intellij.psi.xml.XmlText) TextRange(com.intellij.openapi.util.TextRange)

Example 9 with XmlText

use of com.intellij.psi.xml.XmlText in project intellij-community by JetBrains.

the class CreatePatternFix method doFix.

private void doFix() throws IncorrectOperationException {
    final XmlTag tag = PsiTreeUtil.getParentOfType(myReference.getElement(), XmlTag.class);
    assert tag != null;
    final XmlTag defineTag = tag.createChildTag("define", ApplicationLoader.RNG_NAMESPACE, "\n \n", false);
    defineTag.setAttribute("name", myReference.getCanonicalText());
    final RngGrammar grammar = ((DefinitionReference) myReference).getScope();
    if (grammar == null)
        return;
    final XmlTag root = grammar.getXmlTag();
    if (root == null)
        return;
    final XmlTag[] tags = root.getSubTags();
    for (XmlTag xmlTag : tags) {
        if (PsiTreeUtil.isAncestor(xmlTag, tag, false)) {
            final XmlElementFactory ef = XmlElementFactory.getInstance(tag.getProject());
            final XmlText text = ef.createDisplayText(" ");
            final PsiElement e = root.addAfter(text, xmlTag);
            root.addAfter(defineTag, e);
            return;
        }
    }
    root.add(defineTag);
}
Also used : XmlElementFactory(com.intellij.psi.XmlElementFactory) XmlText(com.intellij.psi.xml.XmlText) PsiElement(com.intellij.psi.PsiElement) XmlTag(com.intellij.psi.xml.XmlTag) RngGrammar(org.intellij.plugins.relaxNG.xml.dom.RngGrammar)

Example 10 with XmlText

use of com.intellij.psi.xml.XmlText in project intellij-community by JetBrains.

the class XmlTextTest method testDisplayToPhysical.

public void testDisplayToPhysical() throws Exception {
    String xml = "<div>&amp;abc</div>";
    XmlFile file = (XmlFile) PsiFileFactory.getInstance(getProject()).createFileFromText("foo.xml", xml);
    XmlTag root = file.getDocument().getRootTag();
    final XmlText text = root.getValue().getTextElements()[0];
    assertEquals("&abc", text.getValue());
    assertEquals(0, text.displayToPhysical(0));
    assertEquals(5, text.displayToPhysical(1));
    assertEquals(6, text.displayToPhysical(2));
    assertEquals(7, text.displayToPhysical(3));
    assertEquals(8, text.displayToPhysical(4));
}
Also used : XmlFile(com.intellij.psi.xml.XmlFile) XmlText(com.intellij.psi.xml.XmlText) XmlTag(com.intellij.psi.xml.XmlTag)

Aggregations

XmlText (com.intellij.psi.xml.XmlText)24 XmlTag (com.intellij.psi.xml.XmlTag)16 PsiElement (com.intellij.psi.PsiElement)12 ASTNode (com.intellij.lang.ASTNode)5 TextRange (com.intellij.openapi.util.TextRange)3 XmlAttributeValue (com.intellij.psi.xml.XmlAttributeValue)3 XmlFile (com.intellij.psi.xml.XmlFile)3 Nullable (org.jetbrains.annotations.Nullable)3 LookupElement (com.intellij.codeInsight.lookup.LookupElement)2 Language (com.intellij.lang.Language)2 Project (com.intellij.openapi.project.Project)2 PsiWhiteSpace (com.intellij.psi.PsiWhiteSpace)2 XmlDocument (com.intellij.psi.xml.XmlDocument)2 XmlTagValue (com.intellij.psi.xml.XmlTagValue)2 DomElement (com.intellij.util.xml.DomElement)2 NotNull (org.jetbrains.annotations.NotNull)2 MavenProjectIndicesManager (org.jetbrains.idea.maven.indices.MavenProjectIndicesManager)2 TypographyDetector (com.android.tools.lint.checks.TypographyDetector)1 NegatingComparable (com.intellij.codeInsight.completion.impl.NegatingComparable)1 LookupElementWeigher (com.intellij.codeInsight.lookup.LookupElementWeigher)1