@Nullable private static XmlTag getAnchor(@NotNull XmlTag contextTag, Editor editor, XmlElementDescriptor selected) { XmlContentDFA contentDFA = XmlContentDFA.getContentDFA(contextTag); int offset = editor.getCaretModel().getOffset(); if (contentDFA == null) { return null; } XmlTag anchor = null; boolean previousPositionIsPossible = true; for (XmlTag subTag : contextTag.getSubTags()) { if (contentDFA.getPossibleElements().contains(selected)) { if (subTag.getTextOffset() > offset) { break; } anchor = subTag; previousPositionIsPossible = true; } else { previousPositionIsPossible = false; } contentDFA.transition(subTag); } return previousPositionIsPossible ? null : anchor; }
public void complete(CompletionParameters parameters, final CompletionResultSet result, PsiElement element) { if (!XmlCompletionContributor.isXmlNameCompletion(parameters)) { return; } result.stopHere(); if (!(element.getParent() instanceof XmlTag)) { return; } final XmlTag tag = (XmlTag)element.getParent(); final XmlTag parentTag = tag.getParentTag(); if (parentTag == null) return; final XmlContentDFA dfa = XmlContentDFA.getContentDFA(parentTag); if (dfa == null) return; ApplicationManager.getApplication().runReadAction(new Runnable() { @Override public void run() { for (XmlTag subTag : parentTag.getSubTags()) { if (subTag == tag) { break; } dfa.transition(subTag); } List<XmlElementDescriptor> elements = dfa.getPossibleElements(); for (XmlElementDescriptor elementDescriptor: elements) { addElementToResult(elementDescriptor, result); } } }); }