Search in sources :

Example 1 with XmlTagValue

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

the class DomTarget method getTarget.

@Nullable
public static DomTarget getTarget(DomElement element, GenericDomValue nameElement) {
    if (nameElement instanceof GenericAttributeValue) {
        final GenericAttributeValue genericAttributeValue = (GenericAttributeValue) nameElement;
        final XmlAttributeValue attributeValue = genericAttributeValue.getXmlAttributeValue();
        if (attributeValue == null) {
            return null;
        }
        final int length = attributeValue.getTextLength();
        if (length >= 2) {
            return new DomTarget(element, attributeValue, new TextRange(1, length - 1), nameElement);
        }
    }
    final XmlTag tag = nameElement.getXmlTag();
    if (tag == null) {
        return null;
    }
    XmlTagValue tagValue = tag.getValue();
    if (StringUtil.isEmpty(tagValue.getTrimmedText())) {
        return null;
    }
    return new DomTarget(element, tag, XmlTagUtil.getTrimmedValueRange(tag), nameElement);
}
Also used : XmlTagValue(com.intellij.psi.xml.XmlTagValue) TextRange(com.intellij.openapi.util.TextRange) XmlAttributeValue(com.intellij.psi.xml.XmlAttributeValue) XmlTag(com.intellij.psi.xml.XmlTag) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with XmlTagValue

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

the class DomHardCoreTestCase method assertReference.

protected PsiReference assertReference(final GenericDomValue value, PsiElement resolveTo) {
    final XmlTagValue tagValue = value.getXmlTag().getValue();
    final TextRange textRange = tagValue.getTextRange();
    final String s = value.getStringValue();
    assertNotNull(s);
    final int i = tagValue.getText().indexOf(s);
    return assertReference(value, resolveTo, textRange.getStartOffset() + i + s.length());
}
Also used : XmlTagValue(com.intellij.psi.xml.XmlTagValue) TextRange(com.intellij.openapi.util.TextRange)

Example 3 with XmlTagValue

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

the class DomReferencesTest method testPsiPrimitiveTypeArray.

public void testPsiPrimitiveTypeArray() throws Throwable {
    final MyElement element = createElement("<a><psi-type>int[]</psi-type></a>");
    final GenericDomValue value = element.getPsiType();
    final XmlTagValue tagValue = value.getXmlTag().getValue();
    final int i = tagValue.getText().indexOf(value.getStringValue());
    assertReference(value, value.getXmlTag(), tagValue.getTextRange().getStartOffset() + i + "int".length());
}
Also used : XmlTagValue(com.intellij.psi.xml.XmlTagValue)

Example 4 with XmlTagValue

use of com.intellij.psi.xml.XmlTagValue 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 5 with XmlTagValue

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

the class XmlTagUtil method getTrimmedValueRange.

@NotNull
public static TextRange getTrimmedValueRange(@NotNull final XmlTag tag) {
    XmlTagValue tagValue = tag.getValue();
    final String text = tagValue.getText();
    final String trimmed = text.trim();
    final int index = text.indexOf(trimmed);
    final int startOffset = tagValue.getTextRange().getStartOffset() - tag.getTextRange().getStartOffset() + index;
    return new TextRange(startOffset, startOffset + trimmed.length());
}
Also used : XmlTagValue(com.intellij.psi.xml.XmlTagValue) TextRange(com.intellij.openapi.util.TextRange) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

XmlTagValue (com.intellij.psi.xml.XmlTagValue)11 TextRange (com.intellij.openapi.util.TextRange)5 XmlTag (com.intellij.psi.xml.XmlTag)5 NotNull (org.jetbrains.annotations.NotNull)4 XmlAttributeValue (com.intellij.psi.xml.XmlAttributeValue)3 PsiFile (com.intellij.psi.PsiFile)2 XmlText (com.intellij.psi.xml.XmlText)2 ResourceRepository (com.android.ide.common.resources.ResourceRepository)1 ResourceResolver (com.android.ide.common.resources.ResourceResolver)1 Density (com.android.resources.Density)1 ResourceType (com.android.resources.ResourceType)1 ResourceReferenceType (com.android.tools.idea.AndroidPsiUtils.ResourceReferenceType)1 LocalResourceRepository (com.android.tools.idea.res.LocalResourceRepository)1 XmlLikeFileType (com.intellij.ide.highlighter.XmlLikeFileType)1 XmlLexer (com.intellij.lexer.XmlLexer)1 FileType (com.intellij.openapi.fileTypes.FileType)1 Project (com.intellij.openapi.project.Project)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiElement (com.intellij.psi.PsiElement)1 PsiReferenceExpression (com.intellij.psi.PsiReferenceExpression)1