Search in sources :

Example 1 with Facet

use of com.intellij.facet.Facet in project intellij-community by JetBrains.

the class PythonSdkType method findPythonSdk.

@Nullable
public static Sdk findPythonSdk(@Nullable Module module) {
    if (module == null)
        return null;
    final Sdk sdk = ModuleRootManager.getInstance(module).getSdk();
    if (sdk != null && sdk.getSdkType() instanceof PythonSdkType)
        return sdk;
    final Facet[] facets = FacetManager.getInstance(module).getAllFacets();
    for (Facet facet : facets) {
        final FacetConfiguration configuration = facet.getConfiguration();
        if (configuration instanceof PythonFacetSettings) {
            return ((PythonFacetSettings) configuration).getSdk();
        }
    }
    return null;
}
Also used : FacetConfiguration(com.intellij.facet.FacetConfiguration) PythonFacetSettings(com.jetbrains.python.facet.PythonFacetSettings) Facet(com.intellij.facet.Facet) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with Facet

use of com.intellij.facet.Facet in project intellij-community by JetBrains.

the class PythonCommandLineState method addRootsFromModule.

private static void addRootsFromModule(Module module, Collection<String> pythonPathList) {
    // for Jython
    final CompilerModuleExtension extension = CompilerModuleExtension.getInstance(module);
    if (extension != null) {
        final VirtualFile path = extension.getCompilerOutputPath();
        if (path != null) {
            pythonPathList.add(path.getPath());
        }
        final VirtualFile pathForTests = extension.getCompilerOutputPathForTests();
        if (pathForTests != null) {
            pythonPathList.add(pathForTests.getPath());
        }
    }
    //additional paths from facets (f.e. buildout)
    final Facet[] facets = FacetManager.getInstance(module).getAllFacets();
    for (Facet facet : facets) {
        if (facet instanceof PythonPathContributingFacet) {
            List<String> more_paths = ((PythonPathContributingFacet) facet).getAdditionalPythonPath();
            if (more_paths != null)
                pythonPathList.addAll(more_paths);
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PythonPathContributingFacet(com.jetbrains.python.facet.PythonPathContributingFacet) LibraryContributingFacet(com.jetbrains.python.facet.LibraryContributingFacet) PythonPathContributingFacet(com.jetbrains.python.facet.PythonPathContributingFacet) Facet(com.intellij.facet.Facet)

Example 3 with Facet

use of com.intellij.facet.Facet in project intellij-community by JetBrains.

the class PythonLanguageLevelPusher method isPythonModule.

private static boolean isPythonModule(@NotNull final Module module) {
    final ModuleType moduleType = ModuleType.get(module);
    if (moduleType instanceof PythonModuleTypeBase)
        return true;
    final Facet[] allFacets = FacetManager.getInstance(module).getAllFacets();
    for (Facet facet : allFacets) {
        if (facet.getConfiguration() instanceof PythonFacetSettings) {
            return true;
        }
    }
    return false;
}
Also used : ModuleType(com.intellij.openapi.module.ModuleType) PythonFacetSettings(com.jetbrains.python.facet.PythonFacetSettings) PythonModuleTypeBase(com.jetbrains.python.PythonModuleTypeBase) Facet(com.intellij.facet.Facet)

Example 4 with Facet

use of com.intellij.facet.Facet in project intellij-community by JetBrains.

the class FacetModelBase method getFacetsByType.

@Override
@NotNull
public <F extends Facet> Collection<F> getFacetsByType(FacetTypeId<F> typeId) {
    if (myType2Facets == null) {
        MultiValuesMap<FacetTypeId, Facet> typeToFacets = new MultiValuesMap<>();
        for (Facet facet : getAllFacets()) {
            typeToFacets.put(facet.getTypeId(), facet);
        }
        Map<FacetTypeId, Collection<Facet>> typeToFacetsCollection = new HashMap<>();
        for (FacetTypeId id : typeToFacets.keySet()) {
            final Collection<Facet> facets = typeToFacets.get(id);
            typeToFacetsCollection.put(id, Collections.unmodifiableCollection(facets));
        }
        myType2Facets = typeToFacetsCollection;
    }
    final Collection<F> facets = (Collection<F>) myType2Facets.get(typeId);
    return facets != null ? facets : Collections.<F>emptyList();
}
Also used : MultiValuesMap(com.intellij.openapi.util.MultiValuesMap) FacetTypeId(com.intellij.facet.FacetTypeId) Facet(com.intellij.facet.Facet) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with Facet

use of com.intellij.facet.Facet in project intellij-community by JetBrains.

the class FacetModelBase method getSortedFacets.

@Override
@NotNull
public Facet[] getSortedFacets() {
    if (mySortedFacets == null) {
        final Facet[] allFacets = getAllFacets();
        if (allFacets.length == 0) {
            mySortedFacets = Facet.EMPTY_ARRAY;
        } else {
            LinkedHashSet<Facet> facets = new LinkedHashSet<>();
            for (Facet facet : allFacets) {
                addUnderlyingFacets(facets, facet);
            }
            mySortedFacets = facets.toArray(new Facet[facets.size()]);
        }
    }
    return mySortedFacets;
}
Also used : Facet(com.intellij.facet.Facet) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

Facet (com.intellij.facet.Facet)17 Module (com.intellij.openapi.module.Module)8 Project (com.intellij.openapi.project.Project)4 ArrayList (java.util.ArrayList)4 NotNull (org.jetbrains.annotations.NotNull)4 FacetManagerAdapter (com.intellij.facet.FacetManagerAdapter)3 ProjectFacetsConfigurator (com.intellij.facet.impl.ProjectFacetsConfigurator)3 MessageBusConnection (com.intellij.util.messages.MessageBusConnection)3 Nullable (org.jetbrains.annotations.Nullable)3 FacetTypeId (com.intellij.facet.FacetTypeId)2 MultiValuesMap (com.intellij.openapi.util.MultiValuesMap)2 Pair (com.intellij.openapi.util.Pair)2 PythonFacetSettings (com.jetbrains.python.facet.PythonFacetSettings)2 FacetConfiguration (com.intellij.facet.FacetConfiguration)1 ModifiableFacetModel (com.intellij.facet.ModifiableFacetModel)1 FacetPointerListener (com.intellij.facet.pointers.FacetPointerListener)1 FacetEditor (com.intellij.facet.ui.FacetEditor)1 CompilerManager (com.intellij.openapi.compiler.CompilerManager)1 ModuleType (com.intellij.openapi.module.ModuleType)1 ModuleListener (com.intellij.openapi.project.ModuleListener)1