Search in sources :

Example 6 with ProperTextRange

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

the class InjectedCaret method setSelection.

@Override
public void setSelection(int startOffset, @Nullable VisualPosition endPosition, int endOffset) {
    TextRange hostRange = myEditorWindow.getDocument().injectedToHost(new ProperTextRange(startOffset, endOffset));
    myDelegate.setSelection(hostRange.getStartOffset(), endPosition, hostRange.getEndOffset());
}
Also used : ProperTextRange(com.intellij.openapi.util.ProperTextRange) ProperTextRange(com.intellij.openapi.util.ProperTextRange) TextRange(com.intellij.openapi.util.TextRange)

Example 7 with ProperTextRange

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

the class SelectionModelWindow method setSelection.

@Override
public void setSelection(final int startOffset, final int endOffset) {
    TextRange hostRange = myDocument.injectedToHost(new ProperTextRange(startOffset, endOffset));
    myHostModel.setSelection(hostRange.getStartOffset(), hostRange.getEndOffset());
}
Also used : ProperTextRange(com.intellij.openapi.util.ProperTextRange) ProperTextRange(com.intellij.openapi.util.ProperTextRange) TextRange(com.intellij.openapi.util.TextRange)

Example 8 with ProperTextRange

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

the class InjectedCaret method setSelection.

@Override
public void setSelection(int startOffset, int endOffset) {
    TextRange hostRange = myEditorWindow.getDocument().injectedToHost(new ProperTextRange(startOffset, endOffset));
    myDelegate.setSelection(hostRange.getStartOffset(), hostRange.getEndOffset());
}
Also used : ProperTextRange(com.intellij.openapi.util.ProperTextRange) ProperTextRange(com.intellij.openapi.util.ProperTextRange) TextRange(com.intellij.openapi.util.TextRange)

Example 9 with ProperTextRange

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

the class CommonMoveUtil method retargetUsages.

public static NonCodeUsageInfo[] retargetUsages(final UsageInfo[] usages, final Map<PsiElement, PsiElement> oldToNewElementsMapping) throws IncorrectOperationException {
    Arrays.sort(usages, (o1, o2) -> {
        final VirtualFile file1 = o1.getVirtualFile();
        final VirtualFile file2 = o2.getVirtualFile();
        if (Comparing.equal(file1, file2)) {
            final ProperTextRange rangeInElement1 = o1.getRangeInElement();
            final ProperTextRange rangeInElement2 = o2.getRangeInElement();
            if (rangeInElement1 != null && rangeInElement2 != null) {
                return rangeInElement2.getStartOffset() - rangeInElement1.getStartOffset();
            }
            return 0;
        }
        if (file1 == null)
            return -1;
        if (file2 == null)
            return 1;
        return Comparing.compare(file1.getPath(), file2.getPath());
    });
    List<NonCodeUsageInfo> nonCodeUsages = new ArrayList<>();
    for (UsageInfo usage : usages) {
        if (usage instanceof NonCodeUsageInfo) {
            nonCodeUsages.add((NonCodeUsageInfo) usage);
        } else if (usage instanceof MoveRenameUsageInfo) {
            final MoveRenameUsageInfo moveRenameUsage = (MoveRenameUsageInfo) usage;
            final PsiElement oldElement = moveRenameUsage.getReferencedElement();
            final PsiElement newElement = oldToNewElementsMapping.get(oldElement);
            LOG.assertTrue(newElement != null, oldElement);
            final PsiReference reference = moveRenameUsage.getReference();
            if (reference != null) {
                try {
                    reference.bindToElement(newElement);
                } catch (IncorrectOperationException e) {
                //
                }
            }
        }
    }
    return nonCodeUsages.toArray(new NonCodeUsageInfo[nonCodeUsages.size()]);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ProperTextRange(com.intellij.openapi.util.ProperTextRange) NonCodeUsageInfo(com.intellij.refactoring.util.NonCodeUsageInfo) MoveRenameUsageInfo(com.intellij.refactoring.util.MoveRenameUsageInfo) PsiReference(com.intellij.psi.PsiReference) IncorrectOperationException(com.intellij.util.IncorrectOperationException) NonCodeUsageInfo(com.intellij.refactoring.util.NonCodeUsageInfo) MoveRenameUsageInfo(com.intellij.refactoring.util.MoveRenameUsageInfo) UsageInfo(com.intellij.usageView.UsageInfo) PsiElement(com.intellij.psi.PsiElement)

Example 10 with ProperTextRange

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

the class FindManagerTest method getParentFromUsage.

private static PsiElement getParentFromUsage(UsageInfo usage) {
    ProperTextRange range = usage.getRangeInElement();
    assertNotNull(range);
    PsiElement element = usage.getElement();
    assertNotNull(element);
    PsiElement elementAt = element.findElementAt(range.getStartOffset());
    assertNotNull(elementAt);
    return elementAt.getParent();
}
Also used : ProperTextRange(com.intellij.openapi.util.ProperTextRange)

Aggregations

ProperTextRange (com.intellij.openapi.util.ProperTextRange)31 TextRange (com.intellij.openapi.util.TextRange)14 com.intellij.codeInsight.hint (com.intellij.codeInsight.hint)4 PsiElement (com.intellij.psi.PsiElement)4 RelativePoint (com.intellij.ui.awt.RelativePoint)4 NotNull (org.jetbrains.annotations.NotNull)4 Nullable (org.jetbrains.annotations.Nullable)4 Document (com.intellij.openapi.editor.Document)2 Segment (com.intellij.openapi.util.Segment)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 List (java.util.List)2 BackgroundEditorHighlighter (com.intellij.codeHighlighting.BackgroundEditorHighlighter)1 HighlightingPass (com.intellij.codeHighlighting.HighlightingPass)1 EditorInfo (com.intellij.codeInsight.EditorInfo)1 DefaultHighlightInfoProcessor (com.intellij.codeInsight.daemon.impl.DefaultHighlightInfoProcessor)1 GeneralHighlightingPass (com.intellij.codeInsight.daemon.impl.GeneralHighlightingPass)1 LocalInspectionsPass (com.intellij.codeInsight.daemon.impl.LocalInspectionsPass)1 EmptyPass (com.intellij.codeInsight.daemon.impl.ProgressableTextEditorHighlightingPass.EmptyPass)1 GenericElementSignatureProvider (com.intellij.codeInsight.folding.impl.GenericElementSignatureProvider)1 InspectionManager (com.intellij.codeInspection.InspectionManager)1