Search in sources :

Example 1 with FacetsProvider

use of com.intellij.openapi.roots.ui.configuration.FacetsProvider in project intellij-community by JetBrains.

the class FrameworkDetectionContextImpl method createDetectedFacetDescriptions.

@NotNull
@Override
public <F extends Facet, C extends FacetConfiguration> List<? extends DetectedFrameworkDescription> createDetectedFacetDescriptions(@NotNull FacetBasedFrameworkDetector<F, C> detector, @NotNull Collection<VirtualFile> files) {
    MultiMap<Module, VirtualFile> filesByModule = MultiMap.createSet();
    for (VirtualFile file : files) {
        final Module module = ModuleUtilCore.findModuleForFile(file, myProject);
        if (module != null) {
            filesByModule.putValue(module, file);
        }
    }
    final List<DetectedFrameworkDescription> result = new ArrayList<>();
    final FacetType<F, C> facetType = detector.getFacetType();
    final FacetsProvider provider = DefaultFacetsProvider.INSTANCE;
    for (Module module : filesByModule.keySet()) {
        final Collection<F> facets = provider.getFacetsByType(module, facetType.getId());
        if (!facetType.isSuitableModuleType(ModuleType.get(module)) || facetType.isOnlyOneFacetAllowed() && !facets.isEmpty()) {
            continue;
        }
        List<C> existentConfigurations = new ArrayList<>();
        for (F facet : facets) {
            //noinspection unchecked
            existentConfigurations.add((C) facet.getConfiguration());
        }
        final Collection<VirtualFile> moduleFiles = filesByModule.get(module);
        final List<Pair<C, Collection<VirtualFile>>> pairs = detector.createConfigurations(moduleFiles, existentConfigurations);
        for (Pair<C, Collection<VirtualFile>> pair : pairs) {
            result.add(new FacetBasedDetectedFrameworkDescriptionImpl<>(module, detector, pair.getFirst(), new HashSet<>(pair.getSecond())));
        }
    }
    return result;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) DetectedFrameworkDescription(com.intellij.framework.detection.DetectedFrameworkDescription) ArrayList(java.util.ArrayList) DefaultFacetsProvider(com.intellij.facet.impl.DefaultFacetsProvider) FacetsProvider(com.intellij.openapi.roots.ui.configuration.FacetsProvider) Collection(java.util.Collection) Module(com.intellij.openapi.module.Module) Pair(com.intellij.openapi.util.Pair) HashSet(java.util.HashSet) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

DefaultFacetsProvider (com.intellij.facet.impl.DefaultFacetsProvider)1 DetectedFrameworkDescription (com.intellij.framework.detection.DetectedFrameworkDescription)1 Module (com.intellij.openapi.module.Module)1 FacetsProvider (com.intellij.openapi.roots.ui.configuration.FacetsProvider)1 Pair (com.intellij.openapi.util.Pair)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 NotNull (org.jetbrains.annotations.NotNull)1