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;
}
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;
}
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;
}
}
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);
}
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>&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));
}
Aggregations