Search in sources :

Example 66 with HashSet

use of com.intellij.util.containers.HashSet in project intellij-community by JetBrains.

the class JavaTestFinder method collectTests.

private boolean collectTests(PsiClass klass, Processor<Pair<? extends PsiNamedElement, Integer>> processor) {
    GlobalSearchScope scope = getSearchScope(klass, false);
    PsiShortNamesCache cache = PsiShortNamesCache.getInstance(klass.getProject());
    String klassName = klass.getName();
    Pattern pattern = Pattern.compile(".*" + StringUtil.escapeToRegexp(klassName) + ".*", Pattern.CASE_INSENSITIVE);
    HashSet<String> names = new HashSet<>();
    cache.getAllClassNames(names);
    for (String eachName : names) {
        if (pattern.matcher(eachName).matches()) {
            for (PsiClass eachClass : cache.getClassesByName(eachName, scope)) {
                if (isTestClass(eachClass, klass)) {
                    if (!processor.process(Pair.create(eachClass, TestFinderHelper.calcTestNameProximity(klassName, eachName)))) {
                        return true;
                    }
                }
            }
        }
    }
    return false;
}
Also used : Pattern(java.util.regex.Pattern) PsiShortNamesCache(com.intellij.psi.search.PsiShortNamesCache) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) PsiClass(com.intellij.psi.PsiClass) HashSet(com.intellij.util.containers.HashSet)

Example 67 with HashSet

use of com.intellij.util.containers.HashSet in project intellij-community by JetBrains.

the class JspContextManager method getRootContextFile.

@NotNull
public BaseJspFile getRootContextFile(@NotNull BaseJspFile file) {
    BaseJspFile rootContext = file;
    HashSet<BaseJspFile> recursionPreventer = new HashSet<>();
    do {
        recursionPreventer.add(rootContext);
        BaseJspFile context = getContextFile(rootContext);
        if (context == null || recursionPreventer.contains(context))
            break;
        rootContext = context;
    } while (true);
    return rootContext;
}
Also used : BaseJspFile(com.intellij.psi.jsp.BaseJspFile) HashSet(com.intellij.util.containers.HashSet) NotNull(org.jetbrains.annotations.NotNull)

Example 68 with HashSet

use of com.intellij.util.containers.HashSet in project intellij-plugins by JetBrains.

the class Struts2TilesModelProvider method computeModels.

@NotNull
public Collection<TilesModel> computeModels(@NotNull final Module module) {
    final Project project = module.getProject();
    final JavaPsiFacade facade = JavaPsiFacade.getInstance(project);
    final GlobalSearchScope moduleScope = GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module, false);
    // struts2-tiles plugin must be available
    final PsiClass strutsTilesListenerClass = facade.findClass(STRUTS_TILES_LISTENER_CLASS, moduleScope);
    if (strutsTilesListenerClass == null) {
        return Collections.emptyList();
    }
    final PsiClass tilesListenerClass = facade.findClass(TilesConstants.TILES_LISTENER, moduleScope);
    final StrutsPluginDomFactory<TilesDefinitions, TilesModel> factory = StrutsProjectComponent.getInstance(project).getTilesFactory();
    final Set<TilesModel> struts2TilesModels = new HashSet<>();
    final Consumer<Set<XmlFile>> consumer = definitions -> {
        final DomFileElement<TilesDefinitions> domFileElement = factory.createMergedModelRoot(definitions);
        if (domFileElement != null) {
            struts2TilesModels.add(new TilesModelImpl(definitions, domFileElement, STRUTS2_TILES_MODEL));
        }
    };
    final WebDirectoryUtil webDirectoryUtil = WebDirectoryUtil.getWebDirectoryUtil(project);
    final Collection<WebFacet> webFacets = WebFacet.getInstances(module);
    for (final WebFacet webFacet : webFacets) {
        final WebApp webApp = webFacet.getRoot();
        if (webApp == null) {
            continue;
        }
        // determine configured tiles config files
        @NonNls final Set<String> tilesConfigNames = findConfiguredTilesPaths(webApp);
        // no configured paths? use default
        if (tilesConfigNames.isEmpty()) {
            tilesConfigNames.add(DEFAULT_TILES_XML);
        }
        // resolve to XmlFile
        final Set<XmlFile> tilesFileSet = new HashSet<>();
        for (final String tilesPath : tilesConfigNames) {
            final PsiElement tilesXmlFile = webDirectoryUtil.findFileByPath(tilesPath, webFacet);
            if (tilesXmlFile instanceof XmlFile) {
                tilesFileSet.add((XmlFile) tilesXmlFile);
            }
        }
        final List<Listener> listenerList = webApp.getListeners();
        for (final Listener listener : listenerList) {
            final PsiClass listenerClass = listener.getListenerClass().getValue();
            if (strutsTilesListenerClass.equals(listenerClass) || Comparing.equal(tilesListenerClass, listenerClass)) {
                consumer.consume(tilesFileSet);
            }
        }
    }
    return struts2TilesModels;
}
Also used : JavaPsiFacade(com.intellij.psi.JavaPsiFacade) WebFacet(com.intellij.javaee.web.facet.WebFacet) XmlFile(com.intellij.psi.xml.XmlFile) JavaPsiFacade(com.intellij.psi.JavaPsiFacade) HashSet(com.intellij.util.containers.HashSet) NonNls(org.jetbrains.annotations.NonNls) THashSet(gnu.trove.THashSet) ContainerUtil(com.intellij.util.containers.ContainerUtil) StrutsProjectComponent(com.intellij.struts.StrutsProjectComponent) PsiClass(com.intellij.psi.PsiClass) Comparing(com.intellij.openapi.util.Comparing) PsiElement(com.intellij.psi.PsiElement) Project(com.intellij.openapi.project.Project) Module(com.intellij.openapi.module.Module) TilesModelProvider(com.intellij.struts.TilesModelProvider) WebDirectoryUtil(com.intellij.psi.impl.source.jsp.WebDirectoryUtil) TilesDefinitions(com.intellij.struts.dom.tiles.TilesDefinitions) TilesModel(com.intellij.struts.TilesModel) TilesConstants(com.intellij.tiles.TilesConstants) StringUtil(com.intellij.openapi.util.text.StringUtil) TilesModelImpl(com.intellij.struts.psi.TilesModelImpl) Collection(java.util.Collection) DomFileElement(com.intellij.util.xml.DomFileElement) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) Set(java.util.Set) List(java.util.List) WebApp(com.intellij.javaee.model.xml.web.WebApp) ParamValue(com.intellij.javaee.model.xml.ParamValue) Listener(com.intellij.javaee.model.xml.Listener) NotNull(org.jetbrains.annotations.NotNull) StrutsPluginDomFactory(com.intellij.struts.StrutsPluginDomFactory) Collections(java.util.Collections) Consumer(com.intellij.util.Consumer) Condition(com.intellij.openapi.util.Condition) HashSet(com.intellij.util.containers.HashSet) THashSet(gnu.trove.THashSet) Set(java.util.Set) Listener(com.intellij.javaee.model.xml.Listener) TilesModelImpl(com.intellij.struts.psi.TilesModelImpl) DomFileElement(com.intellij.util.xml.DomFileElement) WebDirectoryUtil(com.intellij.psi.impl.source.jsp.WebDirectoryUtil) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) PsiElement(com.intellij.psi.PsiElement) HashSet(com.intellij.util.containers.HashSet) THashSet(gnu.trove.THashSet) NonNls(org.jetbrains.annotations.NonNls) XmlFile(com.intellij.psi.xml.XmlFile) PsiClass(com.intellij.psi.PsiClass) TilesDefinitions(com.intellij.struts.dom.tiles.TilesDefinitions) TilesModel(com.intellij.struts.TilesModel) Project(com.intellij.openapi.project.Project) WebFacet(com.intellij.javaee.web.facet.WebFacet) WebApp(com.intellij.javaee.model.xml.web.WebApp) NotNull(org.jetbrains.annotations.NotNull)

Example 69 with HashSet

use of com.intellij.util.containers.HashSet in project intellij-plugins by JetBrains.

the class DartVmServiceDebugProcess method getUrisForFile.

@NotNull
public Collection<String> getUrisForFile(@NotNull final VirtualFile file) {
    final Set<String> result = new HashSet<>();
    String uriByIde = myDartUrlResolver.getDartUrlForFile(file);
    // If dart:, short circuit the results.
    if (uriByIde.startsWith(DartUrlResolver.DART_PREFIX)) {
        result.add(uriByIde);
        return result;
    }
    // file:
    if (uriByIde.startsWith(DartUrlResolver.FILE_PREFIX)) {
        result.add(threeSlashize(uriByIde));
    } else {
        result.add(uriByIde);
        result.add(threeSlashize(new File(file.getPath()).toURI().toString()));
    }
    // straight path - used by some VM embedders
    result.add(file.getPath());
    // package: (if applicable)
    if (myDASExecutionContextId != null) {
        final String uriByServer = DartAnalysisServerService.getInstance(getSession().getProject()).execution_mapUri(myDASExecutionContextId, file.getPath(), null);
        if (uriByServer != null) {
            result.add(uriByServer);
        }
    }
    // remote prefix (if applicable)
    if (myRemoteProjectRootUri != null) {
        final VirtualFile pubspec = myDartUrlResolver.getPubspecYamlFile();
        if (pubspec != null) {
            final String projectPath = pubspec.getParent().getPath();
            final String filePath = file.getPath();
            if (filePath.startsWith(projectPath)) {
                result.add(myRemoteProjectRootUri + filePath.substring(projectPath.length()));
            }
        } else if (myCurrentWorkingDirectory != null) {
            // Handle projects with no pubspecs.
            final String projectPath = myCurrentWorkingDirectory.getPath();
            final String filePath = file.getPath();
            if (filePath.startsWith(projectPath)) {
                result.add(myRemoteProjectRootUri + filePath.substring(projectPath.length()));
            }
        }
    }
    return result;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LightVirtualFile(com.intellij.testFramework.LightVirtualFile) VirtualFile(com.intellij.openapi.vfs.VirtualFile) LightVirtualFile(com.intellij.testFramework.LightVirtualFile) PsiFile(com.intellij.psi.PsiFile) File(java.io.File) HashSet(com.intellij.util.containers.HashSet) THashSet(gnu.trove.THashSet) NotNull(org.jetbrains.annotations.NotNull)

Example 70 with HashSet

use of com.intellij.util.containers.HashSet in project android by JetBrains.

the class DeviceArtDescriptor method getDescriptorFiles.

private static List<File> getDescriptorFiles(@Nullable File[] additionalRoots) {
    Set<File> roots = new HashSet<File>();
    File base = getBundledDescriptorsFolder();
    if (base != null) {
        roots.add(base);
    }
    if (additionalRoots != null) {
        Collections.addAll(roots, additionalRoots);
    }
    List<File> files = new ArrayList<File>(roots.size());
    for (File root : roots) {
        File file = getDescriptorFile(root);
        if (file != null) {
            files.add(file);
        }
    }
    return files;
}
Also used : ArrayList(java.util.ArrayList) File(java.io.File) HashSet(com.intellij.util.containers.HashSet)

Aggregations

HashSet (com.intellij.util.containers.HashSet)162 NotNull (org.jetbrains.annotations.NotNull)50 VirtualFile (com.intellij.openapi.vfs.VirtualFile)31 File (java.io.File)22 PsiElement (com.intellij.psi.PsiElement)20 Module (com.intellij.openapi.module.Module)19 ArrayList (java.util.ArrayList)18 Project (com.intellij.openapi.project.Project)17 THashSet (gnu.trove.THashSet)15 Nullable (org.jetbrains.annotations.Nullable)14 HashMap (com.intellij.util.containers.HashMap)13 IOException (java.io.IOException)13 PsiFile (com.intellij.psi.PsiFile)12 UsageInfo (com.intellij.usageView.UsageInfo)12 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)11 MultiMap (com.intellij.util.containers.MultiMap)11 Pair (com.intellij.openapi.util.Pair)7 GrExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression)7 ConflictsDialog (com.intellij.refactoring.ui.ConflictsDialog)6 Document (com.intellij.openapi.editor.Document)5