/*
 * Copyright 2013-2016 must-be.org
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package consulo.msil.lang.psi.impl;

import com.intellij.lang.ASTNode;
import com.intellij.psi.stubs.IStubElementType;
import com.intellij.psi.stubs.StubElement;
import com.intellij.util.NotNullFunction;
import consulo.annotation.access.RequiredReadAction;
import consulo.dotnet.lang.psi.impl.DotNetTypeRefCacheUtil;
import consulo.dotnet.psi.DotNetType;
import consulo.dotnet.resolve.DotNetTypeRef;

import javax.annotation.Nonnull;

/**
 * @author VISTALL
 * @since 12-May-16
 */
public abstract class MsilTypeImpl<T extends StubElement> extends MsilStubElementImpl<T> implements DotNetType
{
	protected MsilTypeImpl(@Nonnull ASTNode node)
	{
		super(node);
	}

	protected MsilTypeImpl(@Nonnull T stub, @Nonnull IStubElementType nodeType)
	{
		super(stub, nodeType);
	}

	@RequiredReadAction
	@Nonnull
	@Override
	public final DotNetTypeRef toTypeRef()
	{
		return DotNetTypeRefCacheUtil.cacheTypeRef(this, MsilTypeImpl::toTypeRefImpl);
	}

	@RequiredReadAction
	@Nonnull
	protected abstract DotNetTypeRef toTypeRefImpl();

	@Override
	public void accept(MsilVisitor visitor)
	{
		visitor.visitElement(this);
	}
}

@@ -1185,16 +1185,315 @@
 tType%0A%7B%0A
+%09private static class Resolver implements NotNullFunction%3CMsilTypeImpl%3C?%3E, DotNetTypeRef%3E%0A%09%7B%0A%09%09private static final Resolver INSTANCE = new Resolver();%0A%0A%09%09@Override%0A%09%09@Nonnull%0A%09%09@RequiredReadAction%0A%09%09public DotNetTypeRef fun(MsilTypeImpl%3C?%3E msilType)%0A%09%09%7B%0A%09%09%09return msilType.toTypeRefImpl();%0A%09%09%7D%0A%09%7D%0A%0A
 %09protect
@@ -1531,16 +1531,16 @@
 e node)%0A
-
 %09%7B%0A%09%09sup
@@ -1802,35 +1802,25 @@
 is, 
-MsilTypeImpl::toTypeRefImpl
+Resolver.INSTANCE
 );%0A%09

revert change due check inside consulo.dotnet.lang.psi.impl.DotNetTypeRefCacheUtil#getResultCacheResultImpl