<commit_before>/*
 * Copyright 2000-2006 JetBrains s.r.o.
 *
 * 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 com.intellij.gwt.module;

import com.intellij.gwt.module.index.GwtHtmlFileIndex;
import com.intellij.gwt.module.model.GwtEntryPoint;
import com.intellij.gwt.module.model.GwtModule;
import com.intellij.ide.highlighter.HtmlFileType;
import com.intellij.ide.highlighter.XmlFileType;
import com.intellij.lang.html.HTMLLanguage;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleUtil;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.ContentIterator;
import com.intellij.openapi.roots.ProjectFileIndex;
import com.intellij.openapi.roots.ProjectRootManager;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.vfs.VfsUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.*;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.search.GlobalSearchScopesCore;
import com.intellij.psi.util.CachedValue;
import com.intellij.psi.util.CachedValueProvider;
import com.intellij.psi.util.CachedValuesManager;
import com.intellij.psi.xml.XmlFile;
import com.intellij.psi.xml.XmlTag;
import com.intellij.util.ArrayUtil;
import com.intellij.util.xml.DomFileElement;
import com.intellij.util.xml.DomManager;
import com.intellij.util.xml.DomService;
import consulo.psi.PsiPackage;
import consulo.util.dataholder.Key;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.*;

/**
 * @author nik
 */
public class GwtModulesManagerImpl extends GwtModulesManager
{
	private static final Key<CachedValue<Set<GwtModule>>> CACHED_GWT_INHERITED_MODULES = Key.create("CACHED_GWT_INHERITED_MODULES");
	private Project myProject;
	private ProjectFileIndex myProjectFileIndex;

	public GwtModulesManagerImpl(final Project project)
	{
		myProject = project;
		myProjectFileIndex = ProjectRootManager.getInstance(myProject).getFileIndex();
	}

	@Override
	@Nonnull
	public GwtModule[] getAllGwtModules()
	{
		return getGwtModules(GlobalSearchScope.allScope(myProject));
	}

	private GwtModule[] getGwtModules(@Nonnull GlobalSearchScope scope)
	{
		final GwtModulesFinder finder = new GwtModulesFinder(myProject);
		final Collection<VirtualFile> candidates = DomService.getInstance().getDomFileCandidates(GwtModule.class, myProject, scope);
		for(VirtualFile file : candidates)
		{
			if(myProjectFileIndex.isInSource(file) || myProjectFileIndex.isInResource(file) || myProjectFileIndex.isInLibraryClasses(file))
			{
				finder.processFile(file);
			}
		}

		final List<GwtModule> list = finder.getResults();
		return list.toArray(new GwtModule[list.size()]);
	}

	@Override
	@Nonnull
	public GwtModule[] getGwtModules(@Nonnull final Module module)
	{
		return getGwtModules(GlobalSearchScope.moduleScope(module));
	}
<commit_msg>do not allow in dumb mode<commit_after>/*
 * Copyright 2000-2006 JetBrains s.r.o.
 *
 * 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 com.intellij.gwt.module;

import com.intellij.gwt.module.index.GwtHtmlFileIndex;
import com.intellij.gwt.module.model.GwtEntryPoint;
import com.intellij.gwt.module.model.GwtModule;
import com.intellij.ide.highlighter.HtmlFileType;
import com.intellij.ide.highlighter.XmlFileType;
import com.intellij.lang.html.HTMLLanguage;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleUtil;
import com.intellij.openapi.project.DumbService;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.ContentIterator;
import com.intellij.openapi.roots.ProjectFileIndex;
import com.intellij.openapi.roots.ProjectRootManager;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.vfs.VfsUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.*;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.search.GlobalSearchScopesCore;
import com.intellij.psi.util.CachedValue;
import com.intellij.psi.util.CachedValueProvider;
import com.intellij.psi.util.CachedValuesManager;
import com.intellij.psi.xml.XmlFile;
import com.intellij.psi.xml.XmlTag;
import com.intellij.util.ArrayUtil;
import com.intellij.util.xml.DomFileElement;
import com.intellij.util.xml.DomManager;
import com.intellij.util.xml.DomService;
import consulo.psi.PsiPackage;
import consulo.util.dataholder.Key;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.*;

/**
 * @author nik
 */
public class GwtModulesManagerImpl extends GwtModulesManager
{
	private static final Key<CachedValue<Set<GwtModule>>> CACHED_GWT_INHERITED_MODULES = Key.create("CACHED_GWT_INHERITED_MODULES");
	private Project myProject;
	private ProjectFileIndex myProjectFileIndex;

	public GwtModulesManagerImpl(final Project project)
	{
		myProject = project;
		myProjectFileIndex = ProjectRootManager.getInstance(myProject).getFileIndex();
	}

	@Override
	@Nonnull
	public GwtModule[] getAllGwtModules()
	{
		return getGwtModules(GlobalSearchScope.allScope(myProject));
	}

	private GwtModule[] getGwtModules(@Nonnull GlobalSearchScope scope)
	{
		if(!DumbService.isDumb(myProject))
		{
			return new GwtModule[0];
		}

		final GwtModulesFinder finder = new GwtModulesFinder(myProject);
		final Collection<VirtualFile> candidates = DomService.getInstance().getDomFileCandidates(GwtModule.class, myProject, scope);
		for(VirtualFile file : candidates)
		{
			if(myProjectFileIndex.isInSource(file) || myProjectFileIndex.isInResource(file) || myProjectFileIndex.isInLibraryClasses(file))
			{
				finder.processFile(file);
			}
		}

		final List<GwtModule> list = finder.getResults();
		return list.toArray(new GwtModule[list.size()]);
	}

	@Override
	@Nonnull
	public GwtModule[] getGwtModules(@Nonnull final Module module)
	{
		return getGwtModules(GlobalSearchScope.moduleScope(module));
	}

{'fraction_non_alphanumeric': 0.10056677808458073, 'fraction_numerical': 0.0036331928498764716, 'mean_word_length': 5.701071080817917, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 10}, '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': '6648957', 'n_tokens_mistral': 2286, 'n_tokens_neox': 2227, 'n_words': 457}