Search in sources :

Example 86 with LanguageLevel

use of com.intellij.pom.java.LanguageLevel in project intellij-community by JetBrains.

the class GradleProjectImportBuilder method beforeCommit.

@Override
protected void beforeCommit(@NotNull DataNode<ProjectData> dataNode, @NotNull Project project) {
    DataNode<JavaProjectData> javaProjectNode = ExternalSystemApiUtil.find(dataNode, JavaProjectData.KEY);
    if (javaProjectNode == null) {
        return;
    }
    final LanguageLevel externalLanguageLevel = javaProjectNode.getData().getLanguageLevel();
    final LanguageLevelProjectExtension languageLevelExtension = LanguageLevelProjectExtension.getInstance(project);
    if (externalLanguageLevel != languageLevelExtension.getLanguageLevel()) {
        languageLevelExtension.setLanguageLevel(externalLanguageLevel);
    }
}
Also used : LanguageLevel(com.intellij.pom.java.LanguageLevel) JavaProjectData(com.intellij.externalSystem.JavaProjectData) LanguageLevelProjectExtension(com.intellij.openapi.roots.LanguageLevelProjectExtension)

Example 87 with LanguageLevel

use of com.intellij.pom.java.LanguageLevel in project android by JetBrains.

the class PostProjectBuildTasksExecutor method getMaxJavaLangLevel.

@VisibleForTesting
@Nullable
LanguageLevel getMaxJavaLangLevel() {
    LanguageLevel maxLangLevel = null;
    Module[] modules = ModuleManager.getInstance(myProject).getModules();
    for (Module module : modules) {
        AndroidFacet facet = AndroidFacet.getInstance(module);
        if (facet == null) {
            continue;
        }
        AndroidModuleModel androidModel = AndroidModuleModel.get(facet);
        if (androidModel != null) {
            LanguageLevel langLevel = androidModel.getJavaLanguageLevel();
            if (langLevel != null && (maxLangLevel == null || maxLangLevel.compareTo(langLevel) < 0)) {
                maxLangLevel = langLevel;
            }
        }
    }
    return maxLangLevel;
}
Also used : LanguageLevel(com.intellij.pom.java.LanguageLevel) AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) Module(com.intellij.openapi.module.Module) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Nullable(org.jetbrains.annotations.Nullable)

Example 88 with LanguageLevel

use of com.intellij.pom.java.LanguageLevel in project android by JetBrains.

the class SdkModuleSetupStep method doSetUpModule.

@Override
protected void doSetUpModule(@NotNull Module module, @NotNull IdeModifiableModelsProvider ideModelsProvider, @NotNull AndroidModuleModel androidModel, @Nullable SyncAction.ModuleModels gradleModels, @Nullable ProgressIndicator indicator) {
    File androidSdkHomePath = IdeSdks.getInstance().getAndroidSdkPath();
    // Android SDK may be not configured in IntelliJ
    if (androidSdkHomePath == null) {
        assert !IdeInfo.getInstance().isAndroidStudio();
        logAndroidSdkHomeNotFound();
        return;
    }
    ModifiableRootModel moduleModel = ideModelsProvider.getModifiableRootModel(module);
    LanguageLevel languageLevel = androidModel.getJavaLanguageLevel();
    if (languageLevel != null) {
        moduleModel.getModuleExtension(LanguageLevelModuleExtensionImpl.class).setLanguageLevel(languageLevel);
    }
    AndroidProject androidProject = androidModel.getAndroidProject();
    String compileTarget = androidProject.getCompileTarget();
    Sdk sdk = myAndroidSdks.findSuitableAndroidSdk(compileTarget);
    if (sdk == null) {
        sdk = myAndroidSdks.tryToCreate(androidSdkHomePath, compileTarget);
        if (sdk == null) {
            // If SDK was not created, this might be an add-on.
            sdk = findMatchingSdkForAddon(androidProject);
        }
    }
    if (sdk == null) {
        showPlatformNotFoundError(module, compileTarget);
        return;
    }
    moduleModel.setSdk(sdk);
    String sdkPath = sdk.getHomePath();
    if (sdkPath == null) {
        sdkPath = "<path not set>";
    }
    getLog().info(String.format("Set Android SDK '%1$s' (%2$s) to module '%3$s'", sdk.getName(), sdkPath, module.getName()));
}
Also used : ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) LanguageLevelModuleExtensionImpl(com.intellij.openapi.roots.LanguageLevelModuleExtensionImpl) LanguageLevel(com.intellij.pom.java.LanguageLevel) AndroidProject(com.android.builder.model.AndroidProject) Sdk(com.intellij.openapi.projectRoots.Sdk) VirtualFile(com.intellij.openapi.vfs.VirtualFile) VfsUtilCore.virtualToIoFile(com.intellij.openapi.vfs.VfsUtilCore.virtualToIoFile) File(java.io.File)

Example 89 with LanguageLevel

use of com.intellij.pom.java.LanguageLevel in project android by JetBrains.

the class JavaLanguageLevelModuleSetupStep method getMinimumLanguageLevelForAndroidModules.

@Nullable
private static LanguageLevel getMinimumLanguageLevelForAndroidModules(@NotNull IdeModifiableModelsProvider modelsProvider) {
    Module[] modules = modelsProvider.getModules();
    if (modules.length == 0) {
        return null;
    }
    LanguageLevel result = null;
    List<LanguageLevel> languageLevels = new ArrayList<>();
    for (Module dependency : modules) {
        LanguageLevel dependencyLanguageLevel = getLanguageLevelForAndroidModule(dependency, modelsProvider);
        if (dependencyLanguageLevel != null) {
            languageLevels.add(dependencyLanguageLevel);
        }
    }
    for (LanguageLevel dependencyLanguageLevel : languageLevels) {
        if (result == null || result.compareTo(dependencyLanguageLevel) > 0) {
            result = dependencyLanguageLevel;
        }
    }
    return result;
}
Also used : LanguageLevel(com.intellij.pom.java.LanguageLevel) ArrayList(java.util.ArrayList) Module(com.intellij.openapi.module.Module) Nullable(org.jetbrains.annotations.Nullable)

Example 90 with LanguageLevel

use of com.intellij.pom.java.LanguageLevel in project android by JetBrains.

the class AndroidTestCase method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    TestFixtureBuilder<IdeaProjectTestFixture> projectBuilder = IdeaTestFixtureFactory.getFixtureFactory().createFixtureBuilder(getName());
    myFixture = JavaTestFixtureFactory.getFixtureFactory().createCodeInsightFixture(projectBuilder.getFixture());
    JavaModuleFixtureBuilder moduleFixtureBuilder = projectBuilder.addModule(JavaModuleFixtureBuilder.class);
    File moduleRoot = new File(myFixture.getTempDirPath());
    if (!moduleRoot.exists()) {
        assertTrue(moduleRoot.mkdirs());
    }
    initializeModuleFixtureBuilderWithSrcAndGen(moduleFixtureBuilder, moduleRoot.toString());
    ArrayList<MyAdditionalModuleData> modules = new ArrayList<>();
    configureAdditionalModules(projectBuilder, modules);
    myFixture.setUp();
    myFixture.setTestDataPath(getTestDataPath());
    myModule = moduleFixtureBuilder.getFixture().getModule();
    // Must be done before addAndroidFacet, and must always be done, even if a test provides
    // its own custom manifest file. However, in that case, we will delete it shortly below.
    createManifest();
    myFacet = addAndroidFacet(myModule);
    LanguageLevel languageLevel = getLanguageLevel();
    if (languageLevel != null) {
        LanguageLevelProjectExtension extension = LanguageLevelProjectExtension.getInstance(myModule.getProject());
        if (extension != null) {
            extension.setLanguageLevel(languageLevel);
        }
    }
    myFixture.copyDirectoryToProject(getResDir(), "res");
    myAdditionalModules = new ArrayList<>();
    for (MyAdditionalModuleData data : modules) {
        Module additionalModule = data.myModuleFixtureBuilder.getFixture().getModule();
        myAdditionalModules.add(additionalModule);
        AndroidFacet facet = addAndroidFacet(additionalModule);
        facet.setProjectType(data.myProjectType);
        String rootPath = getAdditionalModulePath(data.myDirName);
        myFixture.copyDirectoryToProject(getResDir(), rootPath + "/res");
        myFixture.copyFileToProject(SdkConstants.FN_ANDROID_MANIFEST_XML, rootPath + '/' + SdkConstants.FN_ANDROID_MANIFEST_XML);
        if (data.myIsMainModuleDependency) {
            ModuleRootModificationUtil.addDependency(myModule, additionalModule);
        }
    }
    if (providesCustomManifest()) {
        deleteManifest();
    }
    if (RenderSecurityManager.RESTRICT_READS) {
        // Unit test class loader includes disk directories which security manager does not allow access to
        RenderSecurityManager.sEnabled = false;
    }
    ArrayList<String> allowedRoots = new ArrayList<>();
    collectAllowedRoots(allowedRoots);
    registerAllowedRoots(allowedRoots, getTestRootDisposable());
    mySettings = CodeStyleSettingsManager.getSettings(getProject()).clone();
    AndroidCodeStyleSettingsModifier.modify(mySettings);
    CodeStyleSettingsManager.getInstance(getProject()).setTemporarySettings(mySettings);
    myUseCustomSettings = getAndroidCodeStyleSettings().USE_CUSTOM_SETTINGS;
    getAndroidCodeStyleSettings().USE_CUSTOM_SETTINGS = true;
    // Layoutlib rendering thread will be shutdown when the app is closed so do not report it as a leak
    ThreadTracker.longRunningThreadCreated(ApplicationManager.getApplication(), "Layoutlib");
}
Also used : JavaModuleFixtureBuilder(com.intellij.testFramework.builders.JavaModuleFixtureBuilder) ArrayList(java.util.ArrayList) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) IdeaProjectTestFixture(com.intellij.testFramework.fixtures.IdeaProjectTestFixture) LanguageLevel(com.intellij.pom.java.LanguageLevel) LanguageLevelProjectExtension(com.intellij.openapi.roots.LanguageLevelProjectExtension) Module(com.intellij.openapi.module.Module) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Aggregations

LanguageLevel (com.intellij.pom.java.LanguageLevel)98 LanguageLevelProjectExtension (com.intellij.openapi.roots.LanguageLevelProjectExtension)21 Nullable (org.jetbrains.annotations.Nullable)14 Module (com.intellij.openapi.module.Module)13 NotNull (org.jetbrains.annotations.NotNull)9 Sdk (com.intellij.openapi.projectRoots.Sdk)8 JavaPsiFacade (com.intellij.psi.JavaPsiFacade)7 Project (com.intellij.openapi.project.Project)6 VirtualFile (com.intellij.openapi.vfs.VirtualFile)6 File (java.io.File)6 IOException (java.io.IOException)5 IncorrectOperationException (com.intellij.util.IncorrectOperationException)4 LocalInspectionToolWrapper (com.intellij.codeInspection.ex.LocalInspectionToolWrapper)3 Lexer (com.intellij.lexer.Lexer)3 LanguageLevelModuleExtension (com.intellij.openapi.roots.LanguageLevelModuleExtension)3 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 JavaProjectData (com.intellij.externalSystem.JavaProjectData)2 DisposeAwareProjectChange (com.intellij.openapi.externalSystem.util.DisposeAwareProjectChange)2 ConfigurationException (com.intellij.openapi.options.ConfigurationException)2