Search in sources :

Example 21 with LanguageLevelProjectExtension

use of com.intellij.openapi.roots.LanguageLevelProjectExtension in project intellij by bazelbuild.

the class BlazeJavaSyncPlugin method setProjectSdkAndLanguageLevel.

private static void setProjectSdkAndLanguageLevel(final Project project, final Sdk sdk, final LanguageLevel javaLanguageLevel) {
    Transactions.submitWriteActionTransactionAndWait(() -> {
        ProjectRootManagerEx rootManager = ProjectRootManagerEx.getInstanceEx(project);
        rootManager.setProjectSdk(sdk);
        LanguageLevelProjectExtension ext = LanguageLevelProjectExtension.getInstance(project);
        ext.setLanguageLevel(javaLanguageLevel);
    });
}
Also used : ProjectRootManagerEx(com.intellij.openapi.roots.ex.ProjectRootManagerEx) LanguageLevelProjectExtension(com.intellij.openapi.roots.LanguageLevelProjectExtension)

Example 22 with LanguageLevelProjectExtension

use of com.intellij.openapi.roots.LanguageLevelProjectExtension 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)

Example 23 with LanguageLevelProjectExtension

use of com.intellij.openapi.roots.LanguageLevelProjectExtension in project intellij-community by JetBrains.

the class OptionalPostfixTemplateTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    LanguageLevelProjectExtension levelProjectExtension = LanguageLevelProjectExtension.getInstance(myFixture.getProject());
    myDefaultLanguageLevel = levelProjectExtension.getLanguageLevel();
    levelProjectExtension.setLanguageLevel(LanguageLevel.JDK_1_8);
}
Also used : LanguageLevelProjectExtension(com.intellij.openapi.roots.LanguageLevelProjectExtension)

Example 24 with LanguageLevelProjectExtension

use of com.intellij.openapi.roots.LanguageLevelProjectExtension in project intellij-community by JetBrains.

the class StreamPostfixTemplateTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    LanguageLevelProjectExtension levelProjectExtension = LanguageLevelProjectExtension.getInstance(myFixture.getProject());
    myDefaultLanguageLevel = levelProjectExtension.getLanguageLevel();
    levelProjectExtension.setLanguageLevel(LanguageLevel.JDK_1_8);
}
Also used : LanguageLevelProjectExtension(com.intellij.openapi.roots.LanguageLevelProjectExtension)

Example 25 with LanguageLevelProjectExtension

use of com.intellij.openapi.roots.LanguageLevelProjectExtension in project intellij-community by JetBrains.

the class ProjectConfigurable method apply.

@Override
public void apply() throws ConfigurationException {
    final CompilerProjectExtension compilerProjectExtension = CompilerProjectExtension.getInstance(myProject);
    assert compilerProjectExtension != null : myProject;
    if (myProjectName != null && StringUtil.isEmptyOrSpaces(myProjectName.getText())) {
        throw new ConfigurationException("Please, specify project name!");
    }
    ApplicationManager.getApplication().runWriteAction(() -> {
        // set the output path first so that handlers of RootsChanged event sent after JDK is set
        // would see the updated path
        String canonicalPath = myProjectCompilerOutput.getText();
        if (canonicalPath != null && canonicalPath.length() > 0) {
            try {
                canonicalPath = FileUtil.resolveShortWindowsName(canonicalPath);
            } catch (IOException e) {
            //file doesn't exist yet
            }
            canonicalPath = FileUtil.toSystemIndependentName(canonicalPath);
            compilerProjectExtension.setCompilerOutputUrl(VfsUtilCore.pathToUrl(canonicalPath));
        } else {
            compilerProjectExtension.setCompilerOutputPointer(null);
        }
        LanguageLevelProjectExtension extension = LanguageLevelProjectExtension.getInstance(myProject);
        LanguageLevel level = myLanguageLevelCombo.getSelectedLevel();
        if (level != null) {
            extension.setLanguageLevel(level);
        }
        extension.setDefault(myLanguageLevelCombo.isDefault());
        myProjectJdkConfigurable.apply();
        if (myProjectName != null) {
            ((ProjectEx) myProject).setProjectName(getProjectName());
            if (myDetailsComponent != null)
                myDetailsComponent.setText(getBannerSlogan());
        }
    });
}
Also used : ProjectEx(com.intellij.openapi.project.ex.ProjectEx) ConfigurationException(com.intellij.openapi.options.ConfigurationException) LanguageLevel(com.intellij.pom.java.LanguageLevel) CompilerProjectExtension(com.intellij.openapi.roots.CompilerProjectExtension) IOException(java.io.IOException) LanguageLevelProjectExtension(com.intellij.openapi.roots.LanguageLevelProjectExtension)

Aggregations

LanguageLevelProjectExtension (com.intellij.openapi.roots.LanguageLevelProjectExtension)31 LanguageLevel (com.intellij.pom.java.LanguageLevel)23 LocalInspectionToolWrapper (com.intellij.codeInspection.ex.LocalInspectionToolWrapper)3 DisposeAwareProjectChange (com.intellij.openapi.externalSystem.util.DisposeAwareProjectChange)3 ProjectRootManagerEx (com.intellij.openapi.roots.ex.ProjectRootManagerEx)3 JavaProjectData (com.intellij.externalSystem.JavaProjectData)2 Module (com.intellij.openapi.module.Module)2 JavaSdk (com.intellij.openapi.projectRoots.JavaSdk)2 Sdk (com.intellij.openapi.projectRoots.Sdk)2 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)1 ConfigurationException (com.intellij.openapi.options.ConfigurationException)1 ProjectEx (com.intellij.openapi.project.ex.ProjectEx)1 JavaSdkVersion (com.intellij.openapi.projectRoots.JavaSdkVersion)1 CompilerProjectExtension (com.intellij.openapi.roots.CompilerProjectExtension)1 LanguageLevelModuleExtension (com.intellij.openapi.roots.LanguageLevelModuleExtension)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 JavaModuleFixtureBuilder (com.intellij.testFramework.builders.JavaModuleFixtureBuilder)1 IdeaProjectTestFixture (com.intellij.testFramework.fixtures.IdeaProjectTestFixture)1 File (java.io.File)1 IOException (java.io.IOException)1