Search in sources :

Example 6 with TextRange

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

the class GroovyTypeDefinitionBodySelectioner method select.

@Override
public List<TextRange> select(PsiElement e, CharSequence editorText, int cursorOffset, Editor editor) {
    List<TextRange> result = super.select(e, editorText, cursorOffset, editor);
    if (e instanceof GrTypeDefinitionBody) {
        GrTypeDefinitionBody block = ((GrTypeDefinitionBody) e);
        int startOffset = findOpeningBrace(block);
        int endOffset = findClosingBrace(block, startOffset);
        TextRange range = new TextRange(startOffset, endOffset);
        result.addAll(expandToWholeLine(editorText, range));
    }
    return result;
}
Also used : GrTypeDefinitionBody(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinitionBody) TextRange(com.intellij.openapi.util.TextRange)

Example 7 with TextRange

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

the class GroovyWordSelectionHandler method select.

@Override
public List<TextRange> select(PsiElement e, CharSequence editorText, int cursorOffset, Editor editor) {
    final TextRange originalRange = e.getTextRange();
    LOG.assertTrue(originalRange.getEndOffset() <= editorText.length(), getClass() + "; " + e);
    List<TextRange> ranges;
    if (isSeparateStatement(e)) {
        ranges = ExtendWordSelectionHandlerBase.expandToWholeLine(editorText, originalRange, true);
        if (ranges.size() == 1 && ranges.contains(originalRange)) {
            ranges = ExtendWordSelectionHandlerBase.expandToWholeLine(editorText, originalRange, false);
        }
    } else {
        ranges = new ArrayList<>();
        ranges.add(e.getTextRange());
    }
    SelectWordUtil.addWordOrLexemeSelection(editor.getSettings().isCamelWords(), editor, cursorOffset, ranges);
    return ranges;
}
Also used : TextRange(com.intellij.openapi.util.TextRange)

Example 8 with TextRange

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

the class GrHighlightExitPointHandler method computeUsages.

@Override
public void computeUsages(List<PsiElement> targets) {
    PsiElement parent = myTarget.getParent();
    if (!(parent instanceof GrReturnStatement) && !(parent instanceof GrThrowStatement))
        return;
    final GrControlFlowOwner flowOwner = ControlFlowUtils.findControlFlowOwner(parent);
    ControlFlowUtils.visitAllExitPoints(flowOwner, new ControlFlowUtils.ExitPointVisitor() {

        @Override
        public boolean visitExitPoint(Instruction instruction, @Nullable GrExpression returnValue) {
            final PsiElement returnElement = instruction.getElement();
            if (returnElement != null && isCorrectReturn(returnElement)) {
                final TextRange range = returnElement.getTextRange();
                myReadUsages.add(range);
            }
            return true;
        }
    });
}
Also used : GrControlFlowOwner(org.jetbrains.plugins.groovy.lang.psi.GrControlFlowOwner) GrThrowStatement(org.jetbrains.plugins.groovy.lang.psi.api.statements.branch.GrThrowStatement) GrExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression) TextRange(com.intellij.openapi.util.TextRange) GrReturnStatement(org.jetbrains.plugins.groovy.lang.psi.api.statements.branch.GrReturnStatement) ControlFlowUtils(org.jetbrains.plugins.groovy.codeInspection.utils.ControlFlowUtils) Instruction(org.jetbrains.plugins.groovy.lang.psi.controlFlow.Instruction) PsiElement(com.intellij.psi.PsiElement)

Example 9 with TextRange

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

the class GroovySpacingProcessor method processParentheses.

private boolean processParentheses(@NotNull IElementType left, @NotNull IElementType right, @NotNull Boolean spaceWithin, @Nullable Boolean spaceWithinEmpty, @Nullable Boolean leftLF, @Nullable Boolean rightLF) {
    if (myType1 == left && myType2 == right && spaceWithinEmpty != null) {
        createSpaceInCode(spaceWithinEmpty);
        return true;
    } else if (myType1 == left) {
        final ASTNode rparenth = findFrom(myChild1, right, true);
        if (rparenth == null || leftLF == null) {
            createSpaceInCode(spaceWithin);
        } else {
            final TextRange range = new TextRange(myChild1.getStartOffset(), rparenth.getTextRange().getEndOffset());
            createDependentLFSpacing(leftLF, spaceWithin, range);
        }
        return true;
    } else if (myType2 == right) {
        final ASTNode lparenth = findFrom(myChild1, left, false);
        if (lparenth == null || rightLF == null) {
            createSpaceInCode(spaceWithin);
        } else {
            final TextRange range = new TextRange(lparenth.getStartOffset(), myChild2.getTextRange().getEndOffset());
            createDependentLFSpacing(rightLF, spaceWithin, range);
        }
        return true;
    } else {
        return false;
    }
}
Also used : ASTNode(com.intellij.lang.ASTNode) TextRange(com.intellij.openapi.util.TextRange)

Example 10 with TextRange

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

the class MavenFixedValueReferenceProvider method getReferencesByElement.

@Override
public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull MavenDomConfiguration domCfg, @NotNull ProcessingContext context) {
    ElementManipulator<PsiElement> manipulator = ElementManipulators.getManipulator(element);
    TextRange range = manipulator.getRangeInElement(element);
    String text = range.substring(element.getText());
    Matcher matcher = MavenPropertyResolver.PATTERN.matcher(text);
    if (matcher.find()) {
        return PsiReference.EMPTY_ARRAY;
    }
    return new PsiReference[] { new PsiReferenceBase<PsiElement>(element, mySoft) {

        @Nullable
        @Override
        public PsiElement resolve() {
            if (mySoft) {
                return null;
            }
            if (Arrays.asList(myValues).contains(getValue())) {
                return getElement();
            }
            return null;
        }

        @NotNull
        @Override
        public Object[] getVariants() {
            return myValues;
        }
    } };
}
Also used : Matcher(java.util.regex.Matcher) TextRange(com.intellij.openapi.util.TextRange)

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