IDEA-138655 Defaults change: If bytecode target level is not explicitly set for a module, treat it equal to the source language level

This commit is contained in:
Eugene Zhuravlev
2015-04-01 20:07:00 +03:00
parent 423c56a514
commit 01e29230fc
3 changed files with 23 additions and 8 deletions
@@ -41,7 +41,7 @@ import java.util.List;
*/
public class TargetOptionsComponent extends JPanel {
private static final String[] KNOWN_TARGETS = new String[] {"1.1", "1.2", "1.3","1.4","1.5", "1.6", "1.7", "1.8"};
private static final String COMPILER_DEFAULT = "JDK default";
private static final String COMPILER_DEFAULT = "Same as language level";
private ComboBox myCbProjectTargetLevel;
private JBTable myTable;
@@ -312,7 +312,7 @@ public class TargetOptionsComponent extends JPanel {
combo.setEditor(new BasicComboBoxEditor() {
@Override
protected JTextField createEditorComponent() {
return new HintTextField(COMPILER_DEFAULT, 10);
return new HintTextField(COMPILER_DEFAULT, 12);
}
});
return combo;
@@ -138,13 +138,22 @@ public class ModuleChunk {
if (encoding != null) {
appendOption(options, "-encoding", encoding.name());
}
appendOption(options, "-source", getLanguageLevelOption(ApplicationManager.getApplication().runReadAction(new Computable<LanguageLevel>() {
final String languageLevel = getLanguageLevelOption(ApplicationManager.getApplication().runReadAction(new Computable<LanguageLevel>() {
@Override
public LanguageLevel compute() {
return EffectiveLanguageLevelUtil.getEffectiveLanguageLevel(myMainModule);
}
})));
appendOption(options, "-target", CompilerConfiguration.getInstance(getProject()).getBytecodeTargetLevel(myMainModule));
}));
appendOption(options, "-source", languageLevel);
String bytecodeTarget = CompilerConfiguration.getInstance(getProject()).getBytecodeTargetLevel(myMainModule);
if (StringUtil.isEmpty(bytecodeTarget)) {
// according to IDEA rule: if not specified explicitly, set target to be the same as source language level
bytecodeTarget = languageLevel;
}
appendOption(options, "-target", bytecodeTarget);
return options.toString();
}
@@ -676,9 +676,15 @@ public class JavaBuilder extends ModuleLevelBuilder {
}
if (bytecodeTarget == null) {
// last resort and backward compatibility:
// check if user explicitly defined bytecode target in additional compiler options
bytecodeTarget = USER_DEFINED_BYTECODE_TARGET.get(context);
if (!StringUtil.isEmpty(langLevel)) {
// according to IDEA rule: if not specified explicitly, set target to be the same as source language level
bytecodeTarget = langLevel;
}
else {
// last resort and backward compatibility:
// check if user explicitly defined bytecode target in additional compiler options
bytecodeTarget = USER_DEFINED_BYTECODE_TARGET.get(context);
}
}
final int compilerSdkVersion = getCompilerSdkVersion(context);