use of com.intellij.openapi.util.TextRange 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());
}
use of com.intellij.openapi.util.TextRange in project intellij-community by JetBrains.
the class XmlAttributeImpl method getReferences.
@NotNull
@Override
public PsiReference[] getReferences(@NotNull PsiReferenceService.Hints hints) {
if (hints.offsetInElement != null) {
XmlElement nameElement = getNameElement();
if (nameElement == null || hints.offsetInElement > nameElement.getStartOffsetInParent() + nameElement.getTextLength()) {
return PsiReference.EMPTY_ARRAY;
}
}
final PsiReference[] referencesFromProviders = ReferenceProvidersRegistry.getReferencesFromProviders(this);
PsiReference[] refs;
if (isNamespaceDeclaration()) {
refs = new PsiReference[referencesFromProviders.length + 1];
final String localName = getLocalName();
final String prefix = XmlUtil.findPrefixByQualifiedName(getName());
final TextRange range = prefix.isEmpty() ? TextRange.from(getName().length(), 0) : TextRange.from(prefix.length() + 1, localName.length());
refs[0] = new SchemaPrefixReference(this, range, localName, null);
} else {
final String prefix = getNamespacePrefix();
if (!prefix.isEmpty() && !getLocalName().isEmpty()) {
refs = new PsiReference[referencesFromProviders.length + 2];
refs[0] = new SchemaPrefixReference(this, TextRange.from(0, prefix.length()), prefix, null);
refs[1] = new XmlAttributeReference(this);
} else {
refs = new PsiReference[referencesFromProviders.length + 1];
refs[0] = new XmlAttributeReference(this);
}
}
System.arraycopy(referencesFromProviders, 0, refs, refs.length - referencesFromProviders.length, referencesFromProviders.length);
return refs;
}
use of com.intellij.openapi.util.TextRange in project intellij-community by JetBrains.
the class XmlAttributeImpl method getDisplayValue.
@Override
public String getDisplayValue() {
String displayText = myDisplayText;
if (displayText != null)
return displayText;
XmlAttributeValue value = getValueElement();
if (value == null)
return null;
PsiElement firstChild = value.getFirstChild();
if (firstChild == null)
return null;
ASTNode child = firstChild.getNode();
TextRange valueTextRange = new TextRange(0, value.getTextLength());
if (child != null && child.getElementType() == XmlTokenType.XML_ATTRIBUTE_VALUE_START_DELIMITER) {
valueTextRange = new TextRange(child.getTextLength(), valueTextRange.getEndOffset());
child = child.getTreeNext();
}
final TIntArrayList gapsStarts = new TIntArrayList();
final TIntArrayList gapsShifts = new TIntArrayList();
StringBuilder buffer = new StringBuilder(getTextLength());
while (child != null) {
final int start = buffer.length();
IElementType elementType = child.getElementType();
if (elementType == XmlTokenType.XML_ATTRIBUTE_VALUE_END_DELIMITER) {
valueTextRange = new TextRange(valueTextRange.getStartOffset(), child.getTextRange().getStartOffset() - value.getTextRange().getStartOffset());
break;
}
if (elementType == XmlTokenType.XML_CHAR_ENTITY_REF) {
buffer.append(XmlUtil.getCharFromEntityRef(child.getText()));
} else if (elementType == XmlElementType.XML_ENTITY_REF) {
buffer.append(XmlUtil.getEntityValue((XmlEntityRef) child));
} else {
appendChildToDisplayValue(buffer, child);
}
int end = buffer.length();
int originalLength = child.getTextLength();
if (end - start != originalLength) {
gapsStarts.add(start);
gapsShifts.add(originalLength - (end - start));
}
child = child.getTreeNext();
}
int[] gapDisplayStarts = ArrayUtil.newIntArray(gapsShifts.size());
int[] gapPhysicalStarts = ArrayUtil.newIntArray(gapsShifts.size());
int currentGapsSum = 0;
for (int i = 0; i < gapDisplayStarts.length; i++) {
currentGapsSum += gapsShifts.get(i);
gapDisplayStarts[i] = gapsStarts.get(i);
gapPhysicalStarts[i] = gapDisplayStarts[i] + currentGapsSum;
}
myGapDisplayStarts = gapDisplayStarts;
myGapPhysicalStarts = gapPhysicalStarts;
myValueTextRange = valueTextRange;
return myDisplayText = buffer.toString();
}
use of com.intellij.openapi.util.TextRange in project intellij-community by JetBrains.
the class URLReference method handleElementRename.
@Override
public PsiElement handleElementRename(String newElementName) throws IncorrectOperationException {
final TextRange textRangeInElement = getRangeInElement();
final PsiElement elementToChange = myElement.findElementAt(textRangeInElement.getStartOffset());
assert elementToChange != null;
final ElementManipulator<PsiElement> manipulator = ElementManipulators.getManipulator(elementToChange);
assert manipulator != null;
final int offsetFromStart = myElement.getTextRange().getStartOffset() + textRangeInElement.getStartOffset() - elementToChange.getTextOffset();
manipulator.handleContentChange(elementToChange, new TextRange(offsetFromStart, offsetFromStart + textRangeInElement.getLength()), newElementName);
return myElement;
}
use of com.intellij.openapi.util.TextRange in project intellij-community by JetBrains.
the class XmlAttributeLiteralEscaper method decode.
@Override
public boolean decode(@NotNull final TextRange rangeInsideHost, @NotNull StringBuilder outChars) {
TextRange valueTextRange = myXmlAttribute.getValueTextRange();
int startInDecoded = myXmlAttribute.physicalToDisplay(rangeInsideHost.getStartOffset() - valueTextRange.getStartOffset());
int endInDecoded = myXmlAttribute.physicalToDisplay(rangeInsideHost.getEndOffset() - valueTextRange.getStartOffset());
String displayValue = myXmlAttribute.getDisplayValue();
//todo investigate IIOB http://www.jetbrains.net/jira/browse/IDEADEV-16796
startInDecoded = startInDecoded < 0 ? 0 : startInDecoded > displayValue.length() ? displayValue.length() : startInDecoded;
endInDecoded = endInDecoded < 0 ? 0 : endInDecoded > displayValue.length() ? displayValue.length() : endInDecoded;
if (startInDecoded > endInDecoded)
endInDecoded = startInDecoded;
outChars.append(displayValue, startInDecoded, endInDecoded);
return true;
}
Aggregations