Search in sources :

Example 46 with TextRange

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();
}
Also used : TextRange(com.intellij.openapi.util.TextRange)

Example 47 with TextRange

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);
    }
}
Also used : ASTNode(com.intellij.lang.ASTNode) TextRange(com.intellij.openapi.util.TextRange) PsiElement(com.intellij.psi.PsiElement) TreeElement(com.intellij.psi.impl.source.tree.TreeElement)

Example 48 with TextRange

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;
}
Also used : NonNls(org.jetbrains.annotations.NonNls) XmlAttribute(com.intellij.psi.xml.XmlAttribute) SchemaPrefix(com.intellij.psi.impl.source.xml.SchemaPrefix) TextRange(com.intellij.openapi.util.TextRange) XmlTag(com.intellij.psi.xml.XmlTag)

Example 49 with TextRange

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);
}
Also used : TextRange(com.intellij.openapi.util.TextRange)

Example 50 with TextRange

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();
    }
}
Also used : GrAnonymousClassDefinition(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrAnonymousClassDefinition) TextRange(com.intellij.openapi.util.TextRange) GroovyPsiElement(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement) PsiElement(com.intellij.psi.PsiElement)

Aggregations

TextRange (com.intellij.openapi.util.TextRange)1314 PsiElement (com.intellij.psi.PsiElement)261 NotNull (org.jetbrains.annotations.NotNull)237 Nullable (org.jetbrains.annotations.Nullable)167 Document (com.intellij.openapi.editor.Document)132 ArrayList (java.util.ArrayList)117 Project (com.intellij.openapi.project.Project)96 PsiFile (com.intellij.psi.PsiFile)96 ASTNode (com.intellij.lang.ASTNode)95 Editor (com.intellij.openapi.editor.Editor)75 PsiReference (com.intellij.psi.PsiReference)54 VirtualFile (com.intellij.openapi.vfs.VirtualFile)51 IElementType (com.intellij.psi.tree.IElementType)48 IncorrectOperationException (com.intellij.util.IncorrectOperationException)48 Pair (com.intellij.openapi.util.Pair)47 HighlightInfo (com.intellij.codeInsight.daemon.impl.HighlightInfo)33 ProperTextRange (com.intellij.openapi.util.ProperTextRange)32 FoldingDescriptor (com.intellij.lang.folding.FoldingDescriptor)31 XmlTag (com.intellij.psi.xml.XmlTag)31 List (java.util.List)31