public static boolean isInInjectedLanguagePrefixSuffix(@NotNull final PsiElement element) { PsiFile injectedFile = element.getContainingFile(); if (injectedFile == null) return false; Project project = injectedFile.getProject(); InjectedLanguageManager languageManager = InjectedLanguageManager.getInstance(project); if (!languageManager.isInjectedFragment(injectedFile)) return false; TextRange elementRange = element.getTextRange(); List<TextRange> editables = languageManager.intersectWithAllEditableFragments(injectedFile, elementRange); int combinedEdiablesLength = 0; for (TextRange editable : editables) { combinedEdiablesLength += editable.getLength(); } return combinedEdiablesLength != elementRange.getLength(); }
private SchemaPrefixReference createPrefixReference( ASTNode startTagName, String prefix, TagNameReference tagRef) { return new SchemaPrefixReference( this, TextRange.from(startTagName.getStartOffset() - getStartOffset(), prefix.length()), prefix, tagRef); }
@NotNull static PsiElement loadTree(@NotNull PsiElement host, @NotNull PsiFile containingFile) { if (containingFile instanceof DummyHolder) { PsiElement context = containingFile.getContext(); if (context != null) { PsiFile topFile = context.getContainingFile(); topFile.getNode(); // load tree TextRange textRange = host.getTextRange().shiftRight(context.getTextRange().getStartOffset()); PsiElement inLoadedTree = PsiTreeUtil.findElementOfClassAtRange( topFile, textRange.getStartOffset(), textRange.getEndOffset(), host.getClass()); if (inLoadedTree != null) { host = inLoadedTree; } } } return host; }