TextRange (TextRange textRange, PsiLanguageInjectionHost host) { ElementManipulator<PsiLanguageInjectionHost> manipulator = ElementManipulators.getManipulator(host); if (manipulator == null) return null; final TextRange injectionRangeInHost = manipulator.getRangeInElement(host); final int hostStartOffset = host.getTextRange().getStartOffset(); final @NotNull TextRange injectedDocument = injectionRangeInHost.shiftRight(hostStartOffset); TextRange intersection = textRange.intersection(injectedDocument); return intersection == null ? null : intersection.shiftLeft(injectedDocument.getStartOffset()); }