Search in sources :

Example 51 with TextRange

use of com.intellij.openapi.util.TextRange in project intellij-community by JetBrains.

the class GroovySpacingProcessorBasic method createDependentSpacingForClosure.

@NotNull
static Spacing createDependentSpacingForClosure(@NotNull CommonCodeStyleSettings settings, @NotNull GroovyCodeStyleSettings groovySettings, @NotNull GrClosableBlock closure, final boolean forArrow) {
    boolean spaceWithinBraces = closure.getParent() instanceof GrStringInjection ? groovySettings.SPACE_WITHIN_GSTRING_INJECTION_BRACES : settings.SPACE_WITHIN_BRACES;
    GrStatement[] statements = closure.getStatements();
    if (statements.length > 0) {
        final PsiElement startElem = forArrow ? statements[0] : closure;
        int start = startElem.getTextRange().getStartOffset();
        int end = statements[statements.length - 1].getTextRange().getEndOffset();
        TextRange range = new TextRange(start, end);
        int minSpaces = spaceWithinBraces || forArrow ? 1 : 0;
        int maxSpaces = spaceWithinBraces || forArrow ? 1 : 0;
        return Spacing.createDependentLFSpacing(minSpaces, maxSpaces, range, settings.KEEP_LINE_BREAKS, settings.KEEP_BLANK_LINES_IN_CODE);
    }
    return spaceWithinBraces || forArrow ? COMMON_SPACING : NO_SPACING_WITH_NEWLINE;
}
Also used : TextRange(com.intellij.openapi.util.TextRange) GrStringInjection(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrStringInjection) PsiElement(com.intellij.psi.PsiElement) GrStatement(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement) NotNull(org.jetbrains.annotations.NotNull)

Example 52 with TextRange

use of com.intellij.openapi.util.TextRange in project intellij-community by JetBrains.

the class ClosureBodyBlock method init.

private void init() {
    if (mySubBlocks == null) {
        GroovyBlockGenerator generator = new GroovyBlockGenerator(this);
        List<ASTNode> children = GroovyBlockGenerator.getClosureBodyVisibleChildren(myNode.getTreeParent());
        mySubBlocks = generator.generateSubBlockForCodeBlocks(false, children, myContext.getGroovySettings().INDENT_LABEL_BLOCKS);
        //at least -> exists
        assert !mySubBlocks.isEmpty();
        TextRange firstRange = mySubBlocks.get(0).getTextRange();
        TextRange lastRange = mySubBlocks.get(mySubBlocks.size() - 1).getTextRange();
        myTextRange = new TextRange(firstRange.getStartOffset(), lastRange.getEndOffset());
    }
}
Also used : ASTNode(com.intellij.lang.ASTNode) TextRange(com.intellij.openapi.util.TextRange)

Example 53 with TextRange

use of com.intellij.openapi.util.TextRange in project intellij-community by JetBrains.

the class GrLabelBlock method createTextRange.

private static TextRange createTextRange(List<ASTNode> subStatements) {
    ASTNode first = subStatements.get(0);
    ASTNode last = subStatements.get(subStatements.size() - 1);
    return new TextRange(first.getTextRange().getStartOffset(), last.getTextRange().getEndOffset());
}
Also used : ASTNode(com.intellij.lang.ASTNode) TextRange(com.intellij.openapi.util.TextRange)

Example 54 with TextRange

use of com.intellij.openapi.util.TextRange in project intellij-community by JetBrains.

the class ConvertToGeeseBracesIntention method findRange.

private static TextRange findRange(PsiElement element) {
    PsiElement first = null;
    PsiElement last = null;
    for (PsiElement cur = element; GeeseUtil.isClosureRBrace(cur) && GeeseUtil.isClosureContainLF(cur); cur = getNext(cur)) {
        last = cur;
    }
    for (PsiElement cur = element; GeeseUtil.isClosureRBrace(cur) && GeeseUtil.isClosureContainLF(cur); cur = getPrev(cur)) {
        first = cur;
    }
    LOG.assertTrue(first != null);
    LOG.assertTrue(last != null);
    return new TextRange(first.getTextRange().getStartOffset(), last.getTextRange().getEndOffset());
}
Also used : TextRange(com.intellij.openapi.util.TextRange) PsiElement(com.intellij.psi.PsiElement)

Example 55 with TextRange

use of com.intellij.openapi.util.TextRange in project intellij-community by JetBrains.

the class JavaFxTagNameReference method getRangeInElement.

@Override
public TextRange getRangeInElement() {
    final TextRange rangeInElement = super.getRangeInElement();
    final XmlTag tagElement = getTagElement();
    if (tagElement != null) {
        final String tagElementName = tagElement.getName();
        final int dotIdx = tagElementName.indexOf(".");
        final int startOffset = rangeInElement.getStartOffset();
        if (dotIdx > -1 && startOffset + dotIdx + 2 < rangeInElement.getEndOffset()) {
            return new TextRange(startOffset + dotIdx + 1, rangeInElement.getEndOffset());
        }
    }
    return rangeInElement;
}
Also used : TextRange(com.intellij.openapi.util.TextRange) XmlTag(com.intellij.psi.xml.XmlTag)

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