@Nonnull @Override public LeafElement createLeaf(@Nonnull IElementType type, @Nonnull LanguageVersion languageVersion, @Nonnull CharSequence text) { final ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(type.getLanguage()); if(parserDefinition != null) { if(parserDefinition.getCommentTokens(languageVersion).contains(type)) { return new PsiCoreCommentImpl(type, text); } } // this is special case, then type is WHITE_SPACE, but no parser definition if(type == TokenType.WHITE_SPACE) { return new PsiWhiteSpaceImpl(text); } if (type instanceof ILeafElementType) { return (LeafElement)((ILeafElementType)type).createLeafNode(text); } return new LeafPsiElement(type, text); }
@NotNull public static LeafElement leaf(@NotNull final IElementType type, @NotNull CharSequence text) { if (type == TokenType.WHITE_SPACE) { return new PsiWhiteSpaceImpl(text); } if (type instanceof ILeafElementType) { return (LeafElement)((ILeafElementType)type).createLeafNode(text); } final LeafElement customLeaf = factory(type).createLeaf(type, text); return customLeaf != null ? customLeaf : DefaultFactoryHolder.DEFAULT.createLeaf(type, text); }