use of com.intellij.openapi.util.TextRange in project intellij-community by JetBrains.
the class XmlAttributeLiteralEscaper method getOffsetInHost.
@Override
public int getOffsetInHost(final int offsetInDecoded, @NotNull final TextRange rangeInsideHost) {
TextRange valueTextRange = myXmlAttribute.getValueTextRange();
int displayStart = myXmlAttribute.physicalToDisplay(rangeInsideHost.getStartOffset());
int dp = myXmlAttribute.displayToPhysical(offsetInDecoded + displayStart - valueTextRange.getStartOffset());
if (dp == -1)
return -1;
return dp + valueTextRange.getStartOffset();
}
use of com.intellij.openapi.util.TextRange in project intellij-community by JetBrains.
the class TagNameReference method getRangeInElement.
@Override
public TextRange getRangeInElement() {
final ASTNode nameElement = getNameElement();
if (nameElement == null) {
return TextRange.EMPTY_RANGE;
}
int colon = nameElement.getText().indexOf(':') + 1;
if (myStartTagFlag) {
final int parentOffset = ((TreeElement) nameElement).getStartOffsetInParent();
return new TextRange(parentOffset + colon, parentOffset + nameElement.getTextLength());
} else {
final PsiElement element = getElement();
if (element == myNameElement)
return new TextRange(colon, myNameElement.getTextLength());
final int elementLength = element.getTextLength();
int diffFromEnd = 0;
for (ASTNode node = element.getNode().getLastChildNode(); node != nameElement && node != null; node = node.getTreePrev()) {
diffFromEnd += node.getTextLength();
}
final int nameEnd = elementLength - diffFromEnd;
return new TextRange(nameEnd - nameElement.getTextLength() + colon, nameEnd);
}
}
use of com.intellij.openapi.util.TextRange in project intellij-community by JetBrains.
the class DefaultXmlExtension method getPrefixDeclaration.
@Override
public SchemaPrefix getPrefixDeclaration(final XmlTag context, String namespacePrefix) {
@NonNls String nsDeclarationAttrName = null;
for (XmlTag t = context; t != null; t = t.getParentTag()) {
if (t.hasNamespaceDeclarations()) {
if (nsDeclarationAttrName == null)
nsDeclarationAttrName = namespacePrefix.length() > 0 ? "xmlns:" + namespacePrefix : "xmlns";
XmlAttribute attribute = t.getAttribute(nsDeclarationAttrName);
if (attribute != null) {
final String attrPrefix = attribute.getNamespacePrefix();
final TextRange textRange = TextRange.from(attrPrefix.length() + 1, namespacePrefix.length());
return new SchemaPrefix(attribute, textRange, namespacePrefix);
}
}
}
return null;
}
use of com.intellij.openapi.util.TextRange in project intellij-community by JetBrains.
the class XmlAttributeValueImpl method getValueTextRange.
@Override
public TextRange getValueTextRange() {
final TextRange range = getTextRange();
final String value = getValue();
if (value.isEmpty()) {
return range;
}
final int start = range.getStartOffset() + getText().indexOf(value);
final int end = start + value.length();
return new TextRange(start, end);
}
use of com.intellij.openapi.util.TextRange in project intellij-community by JetBrains.
the class GroovySpacingProcessor method visitTypeDefinition.
@Override
public void visitTypeDefinition(@NotNull GrTypeDefinition typeDefinition) {
if (myType2 == GroovyElementTypes.CLASS_BODY) {
if (typeDefinition instanceof GrAnonymousClassDefinition) {
//don't manually remove line feeds because this line is ambiguous
createSpaceProperty(mySettings.SPACE_BEFORE_CLASS_LBRACE, true, 100);
} else {
PsiElement nameIdentifier = typeDefinition.getNameIdentifierGroovy();
int dependenceStart = nameIdentifier.getTextRange().getStartOffset();
final TextRange range = new TextRange(dependenceStart, myChild1.getTextRange().getEndOffset());
createSpaceBeforeLBrace(mySettings.SPACE_BEFORE_CLASS_LBRACE, mySettings.CLASS_BRACE_STYLE, range, false);
}
} else if (myType2 == GroovyElementTypes.TYPE_PARAMETER_LIST) {
createSpaceInCode(false);
} else if (myType2 == GroovyElementTypes.ARGUMENTS) {
manageSpaceBeforeCallLParenth();
}
}
Aggregations