Search in sources :

Example 96 with Sdk

use of com.intellij.openapi.projectRoots.Sdk in project intellij-community by JetBrains.

the class ClasspathPanelImpl method navigate.

@Override
public void navigate(boolean openLibraryEditor) {
    final OrderEntry entry = getSelectedEntry();
    final ProjectStructureConfigurable rootConfigurable = ProjectStructureConfigurable.getInstance(myState.getProject());
    if (entry instanceof ModuleOrderEntry) {
        Module module = ((ModuleOrderEntry) entry).getModule();
        if (module != null) {
            rootConfigurable.select(module.getName(), null, true);
        }
    } else if (entry instanceof LibraryOrderEntry) {
        if (!openLibraryEditor && !((LibraryOrderEntry) entry).getLibraryLevel().equals(LibraryTableImplUtil.MODULE_LEVEL)) {
            rootConfigurable.select((LibraryOrderEntry) entry, true);
        } else {
            doEdit();
        }
    } else if (entry instanceof JdkOrderEntry) {
        Sdk jdk = ((JdkOrderEntry) entry).getJdk();
        if (jdk != null) {
            rootConfigurable.select(jdk, true);
        }
    }
}
Also used : Sdk(com.intellij.openapi.projectRoots.Sdk) Module(com.intellij.openapi.module.Module) ProjectStructureConfigurable(com.intellij.openapi.roots.ui.configuration.ProjectStructureConfigurable)

Example 97 with Sdk

use of com.intellij.openapi.projectRoots.Sdk in project intellij-community by JetBrains.

the class ReplaceAddAllArrayToCollectionFix method isAvailable.

@Override
public boolean isAvailable(@NotNull final Project project, final Editor editor, final PsiFile file) {
    if (!myMethodCall.isValid())
        return false;
    final Module module = ModuleUtilCore.findModuleForPsiElement(file);
    if (module == null)
        return false;
    final Sdk jdk = ModuleRootManager.getInstance(module).getSdk();
    if (jdk == null || !JavaSdk.getInstance().isOfVersionOrHigher(jdk, JavaSdkVersion.JDK_1_5))
        return false;
    final PsiReferenceExpression expression = myMethodCall.getMethodExpression();
    final PsiElement element = expression.resolve();
    if (element instanceof PsiMethod) {
        final PsiMethod method = (PsiMethod) element;
        final JavaPsiFacade psiFacade = JavaPsiFacade.getInstance(project);
        final PsiClass collectionsClass = psiFacade.findClass("java.util.Collection", GlobalSearchScope.allScope(project));
        if (collectionsClass != null && InheritanceUtil.isInheritorOrSelf(method.getContainingClass(), collectionsClass, true)) {
            if (Comparing.strEqual(method.getName(), "addAll") && PsiType.BOOLEAN.equals(method.getReturnType())) {
                final PsiParameter[] psiParameters = method.getParameterList().getParameters();
                if (psiParameters.length == 1 && psiParameters[0].getType() instanceof PsiClassType && InheritanceUtil.isInheritorOrSelf(((PsiClassType) psiParameters[0].getType()).resolve(), collectionsClass, true)) {
                    final PsiExpressionList list = myMethodCall.getArgumentList();
                    final PsiExpression[] expressions = list.getExpressions();
                    if (expressions.length == 1) {
                        if (expressions[0].getType() instanceof PsiArrayType) {
                            return true;
                        }
                    }
                }
            }
        }
    }
    return false;
}
Also used : JavaSdk(com.intellij.openapi.projectRoots.JavaSdk) Sdk(com.intellij.openapi.projectRoots.Sdk) Module(com.intellij.openapi.module.Module)

Example 98 with Sdk

use of com.intellij.openapi.projectRoots.Sdk in project intellij-community by JetBrains.

the class SdkSetupNotificationTestBase method tearDown.

@Override
protected void tearDown() throws Exception {
    FileEditorManagerEx.getInstanceEx(getProject()).closeAllFiles();
    final Sdk[] jdks = ReadAction.compute(() -> ProjectJdkTable.getInstance().getAllJdks());
    try {
        for (Sdk jdk : jdks) {
            WriteAction.run(() -> ProjectJdkTable.getInstance().removeJdk(jdk));
        }
    } finally {
        super.tearDown();
    }
}
Also used : Sdk(com.intellij.openapi.projectRoots.Sdk)

Example 99 with Sdk

use of com.intellij.openapi.projectRoots.Sdk in project intellij-community by JetBrains.

the class JavaParameters method getJdkToRunModule.

@Nullable
public static Sdk getJdkToRunModule(Module module, boolean productionOnly) {
    final Sdk moduleSdk = ModuleRootManager.getInstance(module).getSdk();
    if (moduleSdk == null) {
        return null;
    }
    final Set<Sdk> sdksFromDependencies = new LinkedHashSet<>();
    OrderEnumerator enumerator = OrderEnumerator.orderEntries(module).runtimeOnly().recursively();
    if (productionOnly) {
        enumerator = enumerator.productionOnly();
    }
    enumerator.forEachModule(module1 -> {
        Sdk sdk = ModuleRootManager.getInstance(module1).getSdk();
        if (sdk != null && sdk.getSdkType().equals(moduleSdk.getSdkType())) {
            sdksFromDependencies.add(sdk);
        }
        return true;
    });
    return findLatestVersion(moduleSdk, sdksFromDependencies);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Sdk(com.intellij.openapi.projectRoots.Sdk) Nullable(org.jetbrains.annotations.Nullable)

Example 100 with Sdk

use of com.intellij.openapi.projectRoots.Sdk in project intellij-community by JetBrains.

the class JavaParametersUtil method createAlternativeJdk.

private static Sdk createAlternativeJdk(@NotNull String jreHome) throws CantRunException {
    final Sdk configuredJdk = ProjectJdkTable.getInstance().findJdk(jreHome);
    if (configuredJdk != null) {
        return configuredJdk;
    }
    if (!JdkUtil.checkForJre(jreHome) && !JdkUtil.checkForJdk(jreHome)) {
        throw new CantRunException(ExecutionBundle.message("jre.path.is.not.valid.jre.home.error.message", jreHome));
    }
    final JavaSdk javaSdk = JavaSdk.getInstance();
    final String versionString = javaSdk.getVersionString(jreHome);
    final Sdk jdk = javaSdk.createJdk(versionString != null ? versionString : "", jreHome);
    if (jdk == null)
        throw CantRunException.noJdkConfigured();
    return jdk;
}
Also used : CantRunException(com.intellij.execution.CantRunException) JavaSdk(com.intellij.openapi.projectRoots.JavaSdk) JavaSdk(com.intellij.openapi.projectRoots.JavaSdk) Sdk(com.intellij.openapi.projectRoots.Sdk)

Aggregations

Sdk (com.intellij.openapi.projectRoots.Sdk)437 VirtualFile (com.intellij.openapi.vfs.VirtualFile)105 Module (com.intellij.openapi.module.Module)85 Nullable (org.jetbrains.annotations.Nullable)63 File (java.io.File)56 Project (com.intellij.openapi.project.Project)49 NotNull (org.jetbrains.annotations.NotNull)43 JavaSdk (com.intellij.openapi.projectRoots.JavaSdk)37 SdkModificator (com.intellij.openapi.projectRoots.SdkModificator)34 ExecutionException (com.intellij.execution.ExecutionException)20 ModifiableFlexBuildConfiguration (com.intellij.lang.javascript.flex.projectStructure.model.ModifiableFlexBuildConfiguration)19 ArrayList (java.util.ArrayList)18 ProjectJdkTable (com.intellij.openapi.projectRoots.ProjectJdkTable)17 IOException (java.io.IOException)16 AndroidSdkAdditionalData (org.jetbrains.android.sdk.AndroidSdkAdditionalData)16 IAndroidTarget (com.android.sdklib.IAndroidTarget)14 JavaSdkType (com.intellij.openapi.projectRoots.JavaSdkType)14 Library (com.intellij.openapi.roots.libraries.Library)14 JavaSdkVersion (com.intellij.openapi.projectRoots.JavaSdkVersion)13 BuildConfigurationNature (com.intellij.flex.model.bc.BuildConfigurationNature)11