package consulo.xml.html.lexer;

import com.intellij.lang.HtmlInlineScriptTokenTypesProvider;
import com.intellij.lang.LanguageHtmlInlineScriptTokenTypesProvider;
import com.intellij.lexer.BaseHtmlLexer;
import com.intellij.lexer.EmbeddedTokenTypesProvider;
import com.intellij.lexer.HtmlLexer;
import com.intellij.psi.tree.IElementType;
import consulo.application.internal.PerApplicationInstance;

import javax.annotation.Nonnull;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.util.List;

/**
 * @author VISTALL
 * @since 2020-08-07
 */
@Singleton
public class InlineElementTypeHolder
{
	private static PerApplicationInstance<InlineElementTypeHolder> ourInstance = PerApplicationInstance.of(InlineElementTypeHolder.class);

	@Nonnull
	public static InlineElementTypeHolder getInstance()
	{
		return ourInstance.get();
	}

	private final IElementType myInlineStyleElementType;
	private final IElementType myInlineScriptElementType;

	@Inject
	private InlineElementTypeHolder()
	{
		List<EmbeddedTokenTypesProvider> extensions = EmbeddedTokenTypesProvider.EXTENSION_POINT_NAME.getExtensionList();
		IElementType inlineStyleElementType = null;
		for(EmbeddedTokenTypesProvider extension : extensions)
		{
			if(HtmlLexer.INLINE_STYLE_NAME.equals(extension.getName()))
			{
				inlineStyleElementType = extension.getElementType();
				break;
			}
		}
		myInlineStyleElementType = inlineStyleElementType;
		// At the moment only JS.
		HtmlInlineScriptTokenTypesProvider provider = LanguageHtmlInlineScriptTokenTypesProvider.getInlineScriptProvider(BaseHtmlLexer.ourDefaultLanguage);
		myInlineScriptElementType = provider != null ? provider.getElementType() : null;
	}

	@Nonnull
	public IElementType getInlineScriptElementType()
	{
		return myInlineScriptElementType;
	}

	@Nonnull
	public IElementType getInlineStyleElementType()
	{
		return myInlineStyleElementType;
	}
}

@@ -425,16 +425,50 @@
 onnull;%0A
+import javax.annotation.Nullable;%0A
 import j
@@ -1713,38 +1713,39 @@
  : null;%0A%09%7D%0A%0A%09@N
-onn
 ull
+able
 %0A%09public IElemen
@@ -1821,30 +1821,31 @@
 ype;%0A%09%7D%0A%0A%09@N
-onn
 ull
+able
 %0A%09public IEl

fix nullable