TemplateDataModifications (@NotNull CharSequence sourceCode, @NotNull Lexer baseLexer) { TemplateDataModifications modifications = new TemplateDataModifications(); baseLexer.start(sourceCode); TextRange currentRange = TextRange.EMPTY_RANGE; int tokenCounter = 0; while (baseLexer.getTokenType() != null) { if (++tokenCounter % CHECK_PROGRESS_AFTER_TOKENS == 0) { ProgressManager.checkCanceled(); } TextRange newRange = TextRange.create(baseLexer.getTokenStart(), baseLexer.getTokenEnd()); assert currentRange.getEndOffset() == newRange.getStartOffset() : "Inconsistent tokens stream from " + baseLexer + ": " + getRangeDump(currentRange, sourceCode) + " followed by " + getRangeDump(newRange, sourceCode); currentRange = newRange; if (baseLexer.getTokenType() == myTemplateElementType) { TemplateDataModifications tokenModifications = appendCurrentTemplateToken(baseLexer.getTokenEnd(), baseLexer.getTokenSequence()); modifications.addAll(tokenModifications); } else { modifications.addOuterRange(currentRange, isInsertionToken(baseLexer.getTokenType(), baseLexer.getTokenSequence())); } baseLexer.advance(); } return modifications; }