### Question:
EnterAfterJavadocTagHandler implements EnterHandlerDelegate { @NotNull static Context parse(@NotNull CharSequence text, int startOffset, int endOffset, int offset) { int asteriskOffset = StringUtil.indexOf(text, '*', startOffset, endOffset); if (asteriskOffset < 0) { return NOT_MATCHED_CONTEXT; } startOffset = asteriskOffset + 1; int startTagStartOffset = -1; int startTagEndOffset = -1; Set<CharSequence> closedTags = new HashSet<CharSequence>(); CharSequence startTag = null; for (int i = offset - 1; i >= startOffset; i--) { char c = text.charAt(i); if (c == ' ' || c == '\t') { continue; } if (c == '>') { if (startTagEndOffset < 0) { startTagEndOffset = i; continue; } } if (c == '<') { if (startTagEndOffset < 0 || i >= endOffset) { break; } if (text.charAt(i + 1) == '/') { CharSequence tag = text.subSequence(i + 2, startTagEndOffset); closedTags.add(tag); startTagEndOffset = -1; } else { CharSequence tag = text.subSequence(i + 1, startTagEndOffset); if (closedTags.remove(tag)) { startTagEndOffset = -1; continue; } startTagStartOffset = i; startTag = text.subSequence(i + 1, startTagEndOffset + 1); break; } } } if (startTagStartOffset < 0 || startTagEndOffset < 0) { return NOT_MATCHED_CONTEXT; } int endTagStartOffset = -1; for (int i = offset; i < endOffset; i++) { char c = text.charAt(i); if (c == '<' && i < endOffset && text.charAt(i + 1) == '/' && startTag != null && CharArrayUtil.regionMatches(text, i + 2, endOffset, startTag)) { endTagStartOffset = i; break; } } return new Context(text, startTagEndOffset, endTagStartOffset, offset); }  @Override Result preprocessEnter(PsiFile file,
                                Editor editor,
                                Ref<Integer> caretOffset,
                                Ref<Integer> caretAdvance,
                                DataContext dataContext,
                                EditorActionHandler originalHandler);  }### Answer:
@Test public void textWithoutAsterisk() { String text = " <start>"; EnterAfterJavadocTagHandler.Context context = parse(text); assertEmpty(context); }
@Test public void startTagOnly() { String text = " * <start>"; EnterAfterJavadocTagHandler.Context context = parse(text); assertEquals(text.indexOf(">"), context.startTagEndOffset); assertTrue(context.endTagStartOffset < 0); context = parse(text, text.length() - 1); assertEmpty(context); }
@Test public void nestedTags() { String text = " * <outer><inner> sdf </inner></outer>"; EnterAfterJavadocTagHandler.Context context = parse(text, 0); assertEmpty(context); int offset = text.indexOf("<outer>") + 2; context = parse(text, offset); assertEmpty(context); offset = text.indexOf("<inner>"); context = parse(text, offset); assertEquals(offset - 1, context.startTagEndOffset); assertEquals(text.indexOf("</outer>"), context.endTagStartOffset); offset += 2; context = parse(text, offset); assertEmpty(context); offset = text.indexOf("sdf"); context = parse(text, offset); assertEquals(text.indexOf("<inner>") + "<inner>".length() - 1, context.startTagEndOffset); assertEquals(text.indexOf("</inner>"), context.endTagStartOffset); offset = text.indexOf("</inner>") + 2; context = parse(text, offset); assertEmpty(context); offset = text.indexOf("</outer>"); context = parse(text, offset); assertEquals(text.indexOf("<inner>") - 1, context.startTagEndOffset); assertEquals(offset, context.endTagStartOffset); offset += 2; context = parse(text, offset); assertEmpty(context); context = parse(text); assertEmpty(context); }