com.intellij.pom.java.LanguageLevel Java Examples

The following examples show how to use com.intellij.pom.java.LanguageLevel. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CamelLightCodeInsightFixtureTestCaseIT.java    From camel-idea-plugin with Apache License 2.0 6 votes vote down vote up
@NotNull
@Override
protected LightProjectDescriptor getProjectDescriptor() {
    LanguageLevel languageLevel = LanguageLevel.JDK_1_8;
    return new DefaultLightProjectDescriptor() {
        @Override
        public Sdk getSdk() {
            String compilerOption = JpsJavaSdkType.complianceOption(languageLevel.toJavaVersion());
            return JavaSdk.getInstance().createJdk( "java " + compilerOption, BUILD_MOCK_JDK_DIRECTORY + compilerOption, false );
        }

        @Override
        public void configureModule(@NotNull Module module, @NotNull ModifiableRootModel model, @NotNull ContentEntry contentEntry) {
            model.getModuleExtension( LanguageLevelModuleExtension.class ).setLanguageLevel( languageLevel );
        }
    };
}
 
Example #2
Source File: BlazeJavaSyncPlugin.java    From intellij with Apache License 2.0 6 votes vote down vote up
private static void updateJdk(
    Project project,
    BlazeContext context,
    ProjectViewSet projectViewSet,
    BlazeProjectData blazeProjectData) {

  LanguageLevel javaLanguageLevel =
      JavaLanguageLevelHelper.getJavaLanguageLevel(
          projectViewSet, blazeProjectData, LanguageLevel.JDK_1_8);

  final Sdk sdk = Jdks.chooseOrCreateJavaSdk(javaLanguageLevel);
  if (sdk == null) {
    String msg =
        String.format(
            "Unable to find a JDK %1$s installed.\n", javaLanguageLevel.getPresentableText());
    msg +=
        "After configuring a suitable JDK in the \"Project Structure\" dialog, "
            + "sync the project again.";
    IssueOutput.error(msg).submit(context);
    return;
  }
  setProjectSdkAndLanguageLevel(project, sdk, javaLanguageLevel);
}
 
Example #3
Source File: IntellijPluginSyncPlugin.java    From intellij with Apache License 2.0 6 votes vote down vote up
@Override
public void updateProjectSdk(
    Project project,
    BlazeContext context,
    ProjectViewSet projectViewSet,
    BlazeVersionData blazeVersionData,
    BlazeProjectData blazeProjectData) {
  if (!blazeProjectData
      .getWorkspaceLanguageSettings()
      .isWorkspaceType(WorkspaceType.INTELLIJ_PLUGIN)) {
    return;
  }

  LanguageLevel javaLanguageLevel =
      JavaLanguageLevelHelper.getJavaLanguageLevel(
          projectViewSet, blazeProjectData, LanguageLevel.JDK_1_8);

  // Leave the SDK, but set the language level
  Transactions.submitWriteActionTransactionAndWait(
      () -> {
        LanguageLevelProjectExtension ext = LanguageLevelProjectExtension.getInstance(project);
        ext.setLanguageLevel(javaLanguageLevel);
      });
}
 
Example #4
Source File: Jdks.java    From intellij with Apache License 2.0 6 votes vote down vote up
@Nullable
private static String getJdkHomePath(LanguageLevel langLevel) {
  Collection<String> jdkHomePaths = new ArrayList<>(JavaSdk.getInstance().suggestHomePaths());
  if (jdkHomePaths.isEmpty()) {
    return null;
  }
  // prefer jdk path of getJavaHome(), since we have to allow access to it in tests
  // see AndroidProjectDataServiceTest#testImportData()
  final List<String> list = new ArrayList<>();
  String javaHome = SystemProperties.getJavaHome();

  if (javaHome != null && !javaHome.isEmpty()) {
    for (Iterator<String> it = jdkHomePaths.iterator(); it.hasNext(); ) {
      final String path = it.next();

      if (path != null && javaHome.startsWith(path)) {
        it.remove();
        list.add(path);
      }
    }
  }
  list.addAll(jdkHomePaths);
  return getBestJdkHomePath(list, langLevel);
}
 
Example #5
Source File: BlazeAndroidSyncPluginTest.java    From intellij with Apache License 2.0 6 votes vote down vote up
@Test
public void testUpdateProjectSdkWithoutSyncDataDoesNotOverrideSdkIfOneAlreadyExists() {
  // Setup.
  BlazeProjectData blazeProjectData =
      MockBlazeProjectDataBuilder.builder(workspaceRoot)
          .setWorkspaceLanguageSettings(
              new WorkspaceLanguageSettings(WorkspaceType.ANDROID, ImmutableSet.of()))
          .build();
  ProjectRootManagerEx.getInstanceEx(project)
      .setProjectSdk(BlazeSdkProvider.getInstance().findSdk(MOCK_ANDROID_SDK_TARGET_HASH_26));

  // Perform.
  syncPlugin.updateProjectSdk(project, context, projectViewSet, null, blazeProjectData);

  // Verify.
  ProjectRootManagerEx rootManager = ProjectRootManagerEx.getInstanceEx(project);
  LanguageLevel languageLevel =
      LanguageLevelProjectExtension.getInstance(project).getLanguageLevel();

  // Even when sync data is null, the project sdk should still be available.  In this case
  // an sdk is already available, so it's not reset from project view.
  assertThat(rootManager.getProjectSdk().getName()).isEqualTo("android-sdk-26");
  assertThat(languageLevel).isNull();
}
 
Example #6
Source File: BlazeAndroidSyncPluginTest.java    From intellij with Apache License 2.0 6 votes vote down vote up
@Test
public void testUpdateProjectSdkWithoutSyncData() {
  // Setup.
  BlazeProjectData blazeProjectData =
      MockBlazeProjectDataBuilder.builder(workspaceRoot)
          .setWorkspaceLanguageSettings(
              new WorkspaceLanguageSettings(WorkspaceType.ANDROID, ImmutableSet.of()))
          .build();

  // Perform.
  syncPlugin.updateProjectSdk(project, context, projectViewSet, null, blazeProjectData);

  // Verify.
  ProjectRootManagerEx rootManager = ProjectRootManagerEx.getInstanceEx(project);
  LanguageLevel languageLevel =
      LanguageLevelProjectExtension.getInstance(project).getLanguageLevel();

  // Even when sync data is null, the project sdk should still be available.
  assertThat(rootManager.getProjectSdk().getName()).isEqualTo("android-sdk-28");
  assertThat(languageLevel).isEqualTo(LanguageLevel.JDK_1_8);
}
 
Example #7
Source File: BlazeAndroidSyncPlugin.java    From intellij with Apache License 2.0 6 votes vote down vote up
private static void setProjectSdkAndLanguageLevel(
    final Project project, final Sdk sdk, final LanguageLevel javaLanguageLevel) {
  UIUtil.invokeAndWaitIfNeeded(
      (Runnable)
          () ->
              ApplicationManager.getApplication()
                  .runWriteAction(
                      () -> {
                        ProjectRootManagerEx rootManager =
                            ProjectRootManagerEx.getInstanceEx(project);
                        rootManager.setProjectSdk(sdk);
                        LanguageLevelProjectExtension ext =
                            LanguageLevelProjectExtension.getInstance(project);
                        ext.setLanguageLevel(javaLanguageLevel);
                      }));
}
 
Example #8
Source File: CamelInspectionTestHelper.java    From camel-idea-plugin with Apache License 2.0 6 votes vote down vote up
@NotNull
@Override
protected LightProjectDescriptor getProjectDescriptor() {
    LanguageLevel languageLevel = LanguageLevel.JDK_1_8;
    return new DefaultLightProjectDescriptor() {
        @Override
        public Sdk getSdk() {
            String compilerOption = JpsJavaSdkType.complianceOption(languageLevel.toJavaVersion());
            return JavaSdk.getInstance().createJdk( "java " + compilerOption, BUILD_MOCK_JDK_DIRECTORY + compilerOption, false );
        }

        @Override
        public void configureModule(@NotNull Module module, @NotNull ModifiableRootModel model, @NotNull ContentEntry contentEntry) {
            model.getModuleExtension( LanguageLevelModuleExtension.class ).setLanguageLevel( languageLevel );
        }
    };
}
 
Example #9
Source File: FlutterModuleImporter.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void editBuildFile(@NotNull VirtualFile buildFile) throws IOException {
  if (doesFileContain(buildFile, ":flutter")) {
    return;
  }
  Project project = myModel.project().getValue();
  ProjectBuildModel projectBuildModel = ProjectBuildModel.get(project);
  GradleBuildModel buildModel = projectBuildModel.getModuleBuildModel(buildFile);
  AndroidModel android = buildModel.android();
  CompileOptionsModel options = android.compileOptions();
  LanguageLevelPropertyModel source = options.sourceCompatibility();
  source.setLanguageLevel(LanguageLevel.JDK_1_8);
  LanguageLevelPropertyModel target = options.targetCompatibility();
  target.setLanguageLevel(LanguageLevel.JDK_1_8);
  DependenciesModel deps = buildModel.dependencies();
  deps.addModule("implementation", ":flutter");
  runWriteCommandAction(project, "build", "import", buildModel::applyChanges);
}
 
Example #10
Source File: FlutterModuleImporter.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void editBuildFile(@NotNull VirtualFile buildFile) throws IOException {
  if (doesFileContain(buildFile, ":flutter")) {
    return;
  }
  Project project = myModel.project().getValue();
  ProjectBuildModel projectBuildModel = ProjectBuildModel.get(project);
  GradleBuildModel buildModel = projectBuildModel.getModuleBuildModel(buildFile);
  AndroidModel android = buildModel.android();
  CompileOptionsModel options = android.compileOptions();
  LanguageLevelPropertyModel source = options.sourceCompatibility();
  source.setLanguageLevel(LanguageLevel.JDK_1_8);
  LanguageLevelPropertyModel target = options.targetCompatibility();
  target.setLanguageLevel(LanguageLevel.JDK_1_8);
  DependenciesModel deps = buildModel.dependencies();
  deps.addModule("implementation", ":flutter");
  runWriteCommandAction(project, "build", "import", buildModel::applyChanges);
}
 
Example #11
Source File: LanguageLevelUtil.java    From ok-gradle with Apache License 2.0 6 votes vote down vote up
/**
 * Converts {@code languageLevel} to Gradle JavaVersion representation use the same format as {@code sampleGradleString}.
 */
@NotNull
public static Object convertToGradleString(@NotNull LanguageLevel languageLevel, @Nullable String sampleGradleString) {
  String underscoreVersion = languageLevel.name().substring("JDK_".length()); // in the format of 1_5, 1_6, etc
  String dotVersion = underscoreVersion.replace('_', '.');
  if (sampleGradleString != null) {
    if (sampleGradleString.startsWith("JavaVersion.VERSION_")) {
      return new ReferenceTo("JavaVersion.VERSION_" + underscoreVersion);
    }
    else if (sampleGradleString.startsWith("VERSION_")) {
      return new ReferenceTo("VERSION_" + underscoreVersion);
    }
    else if (sampleGradleString.startsWith("'")) {
      return "'" + dotVersion + "'";
    }
    else if (sampleGradleString.startsWith("\"")) {
      return "\"" + dotVersion + "\"";
    }
  }
  try {
    return new BigDecimal(dotVersion);
  }
  catch (NumberFormatException e) {
    return dotVersion;
  }
}
 
Example #12
Source File: JavaCodeFormatterFacade.java    From EclipseCodeFormatter with Apache License 2.0 6 votes vote down vote up
private EclipseFormatterAdapter getCodeFormatter(LanguageLevel level, PsiFile psiFile) throws FileDoesNotExistsException {
	if (settings.getProfileScheme() == Settings.ProfileScheme.PROJECT_SPECIFIC) {

		long start = System.currentTimeMillis();
		VirtualFile configFile = configFileLocator.traverseToFindConfigurationFileByConvention(psiFile, project);
		LOG.debug("config located in " + (System.currentTimeMillis() - start) + "ms (" + configFile + ")");

		if (configFile == null) {
			throw new FormattingFailedException("Formatter config file not resolved.", true);
		}
		if (javaPropertiesProvider == null || !javaPropertiesProvider.isSameFile(configFile) || javaPropertiesProvider.wasChanged()) {
			javaPropertiesProvider = new JavaPropertiesProvider(configFile.getCanonicalPath(), "");
			return newCodeFormatter(level, configFile);
		}
		return codeFormatter;
	}

	if (codeFormatter == null || configFileRefresh() || this.effectiveLanguageLevel != level) {
		return newCodeFormatter(level, null);
	}

	return codeFormatter;
}
 
Example #13
Source File: BlazeKotlinSyncPlugin.java    From intellij with Apache License 2.0 6 votes vote down vote up
private static void setJavaLanguageLevel(KotlinFacet kotlinFacet, LanguageLevel languageLevel) {
  Project project = kotlinFacet.getModule().getProject();
  K2JVMCompilerArguments k2JVMCompilerArguments =
      (K2JVMCompilerArguments)
          Kotlin2JvmCompilerArgumentsHolder.Companion.getInstance(project)
              .getSettings()
              .unfrozen();
  String javaVersion = languageLevel.toJavaVersion().toString();
  k2JVMCompilerArguments.setJvmTarget(javaVersion);
  Kotlin2JvmCompilerArgumentsHolder.Companion.getInstance(project)
      .setSettings(k2JVMCompilerArguments);

  CommonCompilerArguments commonArguments =
      kotlinFacet.getConfiguration().getSettings().getCompilerArguments();
  if (commonArguments instanceof K2JVMCompilerArguments) {
    ((K2JVMCompilerArguments) commonArguments).setJvmTarget(javaVersion);
  }
}
 
Example #14
Source File: BlazeKotlinSyncPlugin.java    From intellij with Apache License 2.0 5 votes vote down vote up
@Override
public void updateProjectStructure(
    Project project,
    BlazeContext context,
    WorkspaceRoot workspaceRoot,
    ProjectViewSet projectViewSet,
    BlazeProjectData blazeProjectData,
    @Nullable BlazeProjectData oldBlazeProjectData,
    ModuleEditor moduleEditor,
    Module workspaceModule,
    ModifiableRootModel workspaceModifiableModel) {
  if (!blazeProjectData.getWorkspaceLanguageSettings().isLanguageActive(LanguageClass.KOTLIN)) {
    return;
  }

  KotlinFacet kotlinFacet = getOrCreateKotlinFacet(workspaceModule);
  updatePluginOptions(
      kotlinFacet,
      Arrays.stream(KotlinPluginOptionsProvider.EP_NAME.getExtensions())
          .map(
              provider ->
                  provider.collectKotlinPluginOptions(blazeProjectData.getTargetMap().targets()))
          .flatMap(Collection::stream)
          .collect(Collectors.toList()));
  setJavaLanguageLevel(
      kotlinFacet,
      JavaLanguageLevelHelper.getJavaLanguageLevel(
          projectViewSet, blazeProjectData, LanguageLevel.JDK_1_8));
}
 
Example #15
Source File: OSSPantsIntegrationTest.java    From intellij-pants-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * Assert Project has the right JDK and language level (JVM project only).
 */
protected void assertProjectJdkAndLanguageLevel() {
  final String pantsExecutablePath = PantsUtil.findPantsExecutable(getProjectPath()).get().getPath();
  assertEquals(
    ProjectRootManager.getInstance(myProject).getProjectSdk().getHomePath(),
    getDefaultJavaSdk(pantsExecutablePath).get().getHomePath()
  );

  LanguageLevel projectLanguageLevel = LanguageLevelProjectExtension.getInstance(myProject).getLanguageLevel();
  LanguageLevel expectedLanguageLevel = LanguageLevel.JDK_1_8;
  assertTrue(
    String.format("Project Language Level should be %s, but is %s", expectedLanguageLevel, projectLanguageLevel),
    projectLanguageLevel.equals(LanguageLevel.JDK_1_8)
  );
}
 
Example #16
Source File: BlazeJavaSyncPlugin.java    From intellij with Apache License 2.0 5 votes vote down vote up
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);
      });
}
 
Example #17
Source File: JavaCodeFormatterFacade.java    From EclipseCodeFormatter with Apache License 2.0 5 votes vote down vote up
@NotNull
protected static String toEclipseLanguageLevel(LanguageLevel level) {
	int feature = level.toJavaVersion().feature;
	if (feature < 10) {
		return "1." + feature;
	}
	return String.valueOf(feature);
}
 
Example #18
Source File: KotlinSyncTest.java    From intellij with Apache License 2.0 5 votes vote down vote up
private void assertLanguageLevel(Module module, LanguageLevel languageLevel) {
  String javaVersion = languageLevel.toJavaVersion().toString();
  assertThat(
          Kotlin2JvmCompilerArgumentsHolder.Companion.getInstance(getProject())
              .getSettings()
              .getJvmTarget())
      .isEqualTo(javaVersion);
  CommonCompilerArguments commonArguments =
      KotlinFacet.Companion.get(module).getConfiguration().getSettings().getCompilerArguments();
  if (commonArguments instanceof K2JVMCompilerArguments) {
    assertThat(((K2JVMCompilerArguments) commonArguments).getJvmTarget()).isEqualTo(javaVersion);
  }
}
 
Example #19
Source File: Jdks.java    From intellij with Apache License 2.0 5 votes vote down vote up
@Nullable
@VisibleForTesting
static Sdk findClosestMatch(LanguageLevel langLevel) {
  return ProjectJdkTable.getInstance().getSdksOfType(JavaSdk.getInstance()).stream()
      .filter(
          sdk -> {
            LanguageLevel level = getJavaLanguageLevel(sdk);
            return level != null && level.isAtLeast(langLevel);
          })
      .filter(Jdks::isValid)
      .min(Comparator.comparing(Jdks::getJavaLanguageLevel))
      .orElse(null);
}
 
Example #20
Source File: Jdks.java    From intellij with Apache License 2.0 5 votes vote down vote up
/**
 * Returns null if the SDK is not a java JDK, or doesn't have a recognized java langauge level.
 */
@Nullable
private static LanguageLevel getJavaLanguageLevel(Sdk sdk) {
  if (!(sdk.getSdkType() instanceof JavaSdk)) {
    return null;
  }
  JavaSdkVersion version = JavaSdk.getInstance().getVersion(sdk);
  return version != null ? version.getMaxLanguageLevel() : null;
}
 
Example #21
Source File: LombokTestUtil.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static LightProjectDescriptor getProjectDescriptor() {
  return new DefaultLightProjectDescriptor() {
    @Override
    public Sdk getSdk() {
      return JavaSdk.getInstance().createJdk("java 1.8", "lib/mockJDK-1.8", false);
    }

    @Override
    public void configureModule(@NotNull Module module, @NotNull ModifiableRootModel model, @NotNull ContentEntry contentEntry) {
      model.getModuleExtension(LanguageLevelModuleExtension.class).setLanguageLevel(LanguageLevel.JDK_1_8);
    }
  };
}
 
Example #22
Source File: JavaLanguageLevelSectionTest.java    From intellij with Apache License 2.0 5 votes vote down vote up
@Test
public void testParseLanguageLevels() {
  int minLevelToTest = 5;
  int maxLevelToTest = LanguageLevel.HIGHEST.toJavaVersion().feature;
  for (int i = minLevelToTest; i <= maxLevelToTest; i++) {
    LanguageLevel level = JavaLanguageLevelSection.getLanguageLevel(i, null);
    assertThat(level).isNotNull();
    assertThat(level.toJavaVersion().feature).isEqualTo(i);
  }
}
 
Example #23
Source File: Jdks.java    From intellij with Apache License 2.0 5 votes vote down vote up
@Nullable
private static String getBestJdkHomePath(List<String> jdkHomePaths, LanguageLevel langLevel) {
  // Search for JDKs in both the suggest folder and all its sub folders.
  List<String> roots = Lists.newArrayList();
  for (String jdkHomePath : jdkHomePaths) {
    if (StringUtil.isNotEmpty(jdkHomePath)) {
      roots.add(jdkHomePath);
      roots.addAll(getChildrenPaths(jdkHomePath));
    }
  }
  return getBestJdk(roots, langLevel);
}
 
Example #24
Source File: JdksTest.java    From intellij with Apache License 2.0 5 votes vote down vote up
@Test
public void testClosestJdkOfAtLeastSpecifiedLevelChosen() {
  Sdk jdk7 = IdeaTestUtil.getMockJdk17();
  // Ordering retained in final list; add jdk7 last to ensure first Jdk of at least the specified
  // language level isn't automatically chosen.
  setJdks(ImmutableList.of(IdeaTestUtil.getMockJdk18(), IdeaTestUtil.getMockJdk14(), jdk7));
  assertThat(Jdks.findClosestMatch(LanguageLevel.JDK_1_6)).isEqualTo(jdk7);
}
 
Example #25
Source File: Jdks.java    From intellij with Apache License 2.0 5 votes vote down vote up
@Nullable
private static String getBestJdk(List<String> jdkRoots, LanguageLevel langLevel) {
  return jdkRoots
      .stream()
      .filter(root -> JavaSdk.getInstance().isValidSdkHome(root))
      .filter(root -> getVersion(root).getMaxLanguageLevel().isAtLeast(langLevel))
      .min(Comparator.comparing(o -> getVersion(o).getMaxLanguageLevel()))
      .orElse(null);
}
 
Example #26
Source File: GodClassTest.java    From IntelliJDeodorant with MIT License 5 votes vote down vote up
@NotNull
@Override
protected LightProjectDescriptor getProjectDescriptor() {
    return new ProjectDescriptor(LanguageLevel.JDK_1_8, false) {
        @Override
        public Sdk getSdk() {
            return JavaSdk.getInstance().createJdk("java 1.8", MOCK_JDK_HOME, false);
        }
    };
}
 
Example #27
Source File: JavaCodeFormatterFacade.java    From EclipseCodeFormatter with Apache License 2.0 5 votes vote down vote up
@NotNull
private Map<String, String> getEclipseProfileOptions(LanguageLevel level, VirtualFile configFile, ClassLoader classLoader) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException {
	Map<String, String> options = getEclipseProfileOptions(configFile, classLoader);

	if (options.size() < 100) {
		throw new FormattingFailedException("Invalid config file, it should contain 100+ properties.", true);
	}
	String languageLevel = toEclipseLanguageLevel(level);
	options.put("org.eclipse.jdt.core.compiler.source", languageLevel);
	options.put("org.eclipse.jdt.core.compiler.codegen.targetPlatform", languageLevel);
	options.put("org.eclipse.jdt.core.compiler.compliance", languageLevel);
	this.effectiveLanguageLevel = level;
	return options;
}
 
Example #28
Source File: JavaLanguageLevelHelper.java    From intellij with Apache License 2.0 5 votes vote down vote up
public static LanguageLevel getJavaLanguageLevel(
    ProjectViewSet projectViewSet,
    BlazeProjectData blazeProjectData,
    LanguageLevel defaultLanguageLevel) {
  LanguageLevel fromToolchain = getLanguageLevelFromToolchain(blazeProjectData);
  return JavaLanguageLevelSection.getLanguageLevel(
      projectViewSet, fromToolchain != null ? fromToolchain : defaultLanguageLevel);
}
 
Example #29
Source File: MavenTestCase.java    From intellij-quarkus with Eclipse Public License 2.0 5 votes vote down vote up
protected void setUpFixtures() throws Exception {
  //myTestFixture = IdeaTestFixtureFactory.getFixtureFactory().createFixtureBuilder(getName()).getFixture();
  //myTestFixture.setUp();
  myProjectBuilder = IdeaTestFixtureFactory.getFixtureFactory().createFixtureBuilder(getName());
  final JavaTestFixtureFactory factory = JavaTestFixtureFactory.getFixtureFactory();
  ModuleFixtureBuilder moduleBuilder = myProjectBuilder.addModule(JavaModuleFixtureBuilder.class);
  myTestFixture = factory.createCodeInsightFixture(myProjectBuilder.getFixture());
  myTestFixture.setUp();
  LanguageLevelProjectExtension.getInstance(myTestFixture.getProject()).setLanguageLevel(LanguageLevel.JDK_1_6);
}
 
Example #30
Source File: InitializrModuleBuilder.java    From intellij-spring-assistant with MIT License 5 votes vote down vote up
@Override
public void setupRootModel(ModifiableRootModel modifiableRootModel) {
  Sdk moduleOrProjectSdk = getModuleJdk() != null ?
      getModuleJdk() :
      getInstance(modifiableRootModel.getProject()).getProjectSdk();
  if (moduleOrProjectSdk != null) {
    modifiableRootModel.setSdk(moduleOrProjectSdk);
  }

  LanguageLevelModuleExtension languageLevelModuleExtension =
      modifiableRootModel.getModuleExtension(LanguageLevelModuleExtension.class);
  if (languageLevelModuleExtension != null && moduleOrProjectSdk != null) {
    if (safeGetProjectCreationRequest().isJavaVersionSet()) {
      LanguageLevel lastSelectedLanguageLevel =
          parse(safeGetProjectCreationRequest().getJavaVersion().getId());
      if (lastSelectedLanguageLevel != null) {
        JavaSdkVersion lastSelectedJavaSdkVersion = fromLanguageLevel(lastSelectedLanguageLevel);
        JavaSdkVersion moduleOrProjectLevelJavaSdkVersion =
            getInstance().getVersion(moduleOrProjectSdk);
        if (moduleOrProjectLevelJavaSdkVersion != null && moduleOrProjectLevelJavaSdkVersion
            .isAtLeast(lastSelectedJavaSdkVersion)) {
          languageLevelModuleExtension.setLanguageLevel(lastSelectedLanguageLevel);
        }
      }
    }
  }

  doAddContentEntry(modifiableRootModel);
}