<commit_before>/*
 * Copyright 2013-2014 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 org.mustbe.consulo.csharp.lang.psi.impl.source.resolve.type;

import gnu.trove.TIntObjectHashMap;

import org.jetbrains.annotations.Nullable;
import org.mustbe.consulo.csharp.lang.psi.CSharpFileFactory;
import org.mustbe.consulo.dotnet.DotNetTypes;
import org.mustbe.consulo.dotnet.psi.DotNetTypeDeclaration;
import org.mustbe.consulo.dotnet.resolve.DotNetPsiSearcher;
import com.intellij.ProjectTopics;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.roots.ModuleRootAdapter;
import com.intellij.openapi.roots.ModuleRootEvent;
import com.intellij.psi.search.GlobalSearchScope;

/**
 * @author VISTALL
 * @since 18.01.14
 */
public class CSharpModuleTypeHelperImpl extends CSharpModuleTypeHelper
{
	private Module myModule;

	private final TIntObjectHashMap<DotNetTypeDeclaration> myArrayTypes = new TIntObjectHashMap<DotNetTypeDeclaration>();

	public CSharpModuleTypeHelperImpl(Module module)
	{
		myModule = module;
		myModule.getProject().getMessageBus().connect().subscribe(ProjectTopics.PROJECT_ROOTS, new ModuleRootAdapter()
		{
			@Override
			public void rootsChanged(ModuleRootEvent event)
			{
				myArrayTypes.clear();
			}
		});
	}

	@Nullable
	@Override
	public DotNetTypeDeclaration getArrayType(int dimensions)
	{
		DotNetTypeDeclaration declaration = myArrayTypes.get(dimensions);
		if(declaration == null)
		{
			GlobalSearchScope searchScope = GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(myModule);
			DotNetTypeDeclaration type = DotNetPsiSearcher.getInstance(myModule.getProject()).findType(DotNetTypes.System.Array, searchScope);
			if(type == null)
			{
				return null;
			}

			StringBuilder builder = new StringBuilder();
			builder.append("public class ArrayImpl<T> : System.Array, System.Collections.Generic.IEnumerable<T>");
			builder.append("{");
			builder.append("private ArrayImpl() {}");
			builder.append("public T this[int index");
			for(int i = 0; i < dimensions; i++)
			{
				builder.append(", int index").append(i);
			}
			builder.append("] { get; set; }");
			builder.append("public System.Collections.Generic.IEnumerator<T> System.Collections.Generic.IEnumerator<T>.GetEnumerator() {}");
			builder.append("}");

			DotNetTypeDeclaration typeDeclaration = CSharpFileFactory.createTypeDeclaration(myModule.getProject(), builder.toString());
			myArrayTypes.put(dimensions, typeDeclaration);
			return typeDeclaration;
		}
		else
		{
			return declaration;
		}
	}
}<commit_msg>fixed #222<commit_after>/*
 * Copyright 2013-2014 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 org.mustbe.consulo.csharp.lang.psi.impl.source.resolve.type;

import gnu.trove.TIntObjectHashMap;

import org.jetbrains.annotations.Nullable;
import org.mustbe.consulo.csharp.lang.psi.CSharpFileFactory;
import org.mustbe.consulo.dotnet.DotNetTypes;
import org.mustbe.consulo.dotnet.psi.DotNetTypeDeclaration;
import org.mustbe.consulo.dotnet.resolve.DotNetPsiSearcher;
import com.intellij.ProjectTopics;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.roots.ModuleRootAdapter;
import com.intellij.openapi.roots.ModuleRootEvent;
import com.intellij.psi.search.GlobalSearchScope;

/**
 * @author VISTALL
 * @since 18.01.14
 */
public class CSharpModuleTypeHelperImpl extends CSharpModuleTypeHelper
{
	private Module myModule;

	private final TIntObjectHashMap<DotNetTypeDeclaration> myArrayTypes = new TIntObjectHashMap<DotNetTypeDeclaration>();

	public CSharpModuleTypeHelperImpl(Module module)
	{
		myModule = module;
		myModule.getProject().getMessageBus().connect().subscribe(ProjectTopics.PROJECT_ROOTS, new ModuleRootAdapter()
		{
			@Override
			public void rootsChanged(ModuleRootEvent event)
			{
				myArrayTypes.clear();
			}
		});
	}

	@Nullable
	@Override
	public DotNetTypeDeclaration getArrayType(int dimensions)
	{
		DotNetTypeDeclaration declaration = myArrayTypes.get(dimensions);
		if(declaration == null)
		{
			GlobalSearchScope searchScope = GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(myModule);
			DotNetTypeDeclaration type = DotNetPsiSearcher.getInstance(myModule.getProject()).findType(DotNetTypes.System.Array, searchScope);
			if(type == null)
			{
				return null;
			}

			StringBuilder builder = new StringBuilder();
			builder.append("public class ArrayImpl<T> : System.Array, System.Collections.Generic.IEnumerable<T>");
			builder.append("{");
			builder.append("private ArrayImpl() {}");
			builder.append("public T this[long index");
			for(int i = 0; i < dimensions; i++)
			{
				builder.append(", int index").append(i);
			}
			builder.append("] { get; set; }");
			builder.append("public T this[int index");
			for(int i = 0; i < dimensions; i++)
			{
				builder.append(", int index").append(i);
			}
			builder.append("] { get; set; }");
			builder.append("public T this[uint index");
			for(int i = 0; i < dimensions; i++)
			{
				builder.append(", int index").append(i);
			}
			builder.append("] { get; set; }");
			builder.append("public System.Collections.Generic.IEnumerator<T> System.Collections.Generic.IEnumerator<T>.GetEnumerator() {}");
			builder.append("}");

			DotNetTypeDeclaration typeDeclaration = CSharpFileFactory.createTypeDeclaration(myModule.getProject(), builder.toString());
			myArrayTypes.put(dimensions, typeDeclaration);
			return typeDeclaration;
		}
		else
		{
			return declaration;
		}
	}
}
{'fraction_non_alphanumeric': 0.11445690582270703, 'fraction_numerical': 0.006606237517283761, 'mean_word_length': 4.896739130434782, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5457612', 'n_tokens_mistral': 2143, 'n_tokens_neox': 1933, 'n_words': 439}