use of com.intellij.codeInsight.unwrap.UnwrapDescriptor in project intellij-community by JetBrains.
the class XmlUnwrapDescriptor method collectUnwrappers.
@Override
public List<Pair<PsiElement, Unwrapper>> collectUnwrappers(Project project, Editor editor, PsiFile file) {
int offset = editor.getCaretModel().getOffset();
PsiElement e1 = file.findElementAt(offset);
if (e1 != null) {
Language language = e1.getParent().getLanguage();
if (language != file.getLanguage()) {
UnwrapDescriptor unwrapDescriptor = LanguageUnwrappers.INSTANCE.forLanguage(language);
if (unwrapDescriptor != null && !(unwrapDescriptor instanceof XmlUnwrapDescriptor)) {
return unwrapDescriptor.collectUnwrappers(project, editor, file);
}
}
}
List<Pair<PsiElement, Unwrapper>> result = new ArrayList<>();
FileViewProvider viewProvider = file.getViewProvider();
for (Language language : viewProvider.getLanguages()) {
UnwrapDescriptor unwrapDescriptor = LanguageUnwrappers.INSTANCE.forLanguage(language);
if (unwrapDescriptor instanceof XmlUnwrapDescriptor) {
PsiElement e = viewProvider.findElementAt(offset, language);
PsiElement tag = PsiTreeUtil.getParentOfType(e, XmlTag.class);
while (tag != null) {
if (XmlChildRole.START_TAG_NAME_FINDER.findChild(tag.getNode()) != null) {
// Exclude implicit tags suck as 'jsp:root'
result.add(new Pair<>(tag, new XmlEnclosingTagUnwrapper()));
}
tag = PsiTreeUtil.getParentOfType(tag, XmlTag.class);
}
}
}
Collections.sort(result, (o1, o2) -> o2.first.getTextOffset() - o1.first.getTextOffset());
return result;
}
Aggregations